index.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <template>
  2. <div
  3. class="bs-setting-wrap"
  4. @click.stop
  5. >
  6. <el-tabs
  7. v-if="config.option.displayOption.dataAllocation.enable"
  8. v-model="activeName"
  9. @tab-click="handleClick"
  10. >
  11. <el-tab-pane
  12. label="数据"
  13. name="data"
  14. >
  15. <DataSetting
  16. ref="dataSetting"
  17. :key="config.code"
  18. >
  19. <template #dataSetSelect="{value}">
  20. <slot
  21. name="dataSetSelect"
  22. :value="value"
  23. />
  24. </template>
  25. </DataSetting>
  26. </el-tab-pane>
  27. <el-tab-pane
  28. label="样式"
  29. name="second"
  30. >
  31. <component
  32. :is="resolveComponentType(config.type)"
  33. ref="customSetting"
  34. :key="config.code"
  35. :config="config"
  36. @closeRightPanel="close"
  37. />
  38. </el-tab-pane>
  39. </el-tabs>
  40. <el-scrollbar
  41. v-else
  42. class="bs-setting-wrap bs-scrollbar"
  43. >
  44. <component
  45. :is="resolveComponentType(config.type)"
  46. ref="customSetting"
  47. :key="config.code"
  48. :config="config"
  49. @closeRightPanel="close"
  50. />
  51. </el-scrollbar>
  52. </div>
  53. </template>
  54. <script>
  55. import { resolveComponentType } from 'data-room-ui/js/utils'
  56. import DataSetting from './DataSetting.vue'
  57. import rightSetting from 'data-room-ui/js/utils/rightSettingImport'
  58. import CustomComponent from './G2CustomSetting.vue'
  59. import Svgs from 'data-room-ui/Svgs/setting.vue'
  60. import { mapState, mapMutations } from 'vuex'
  61. import _ from 'lodash'
  62. // 整体动态导入右侧设置组件,不用手动注册
  63. const components = {}
  64. for (const key in rightSetting) {
  65. if (Object.hasOwnProperty.call(rightSetting, key)) {
  66. const component = rightSetting[key]
  67. components[key] = component
  68. }
  69. }
  70. export default {
  71. name: 'RightSetting',
  72. components: {
  73. ...components,
  74. DataSetting,
  75. CustomComponent,
  76. Svgs,
  77. // 远程组件的样式配置也和g2Plot的样式配置一样,采用属性配置, 故使用一个组件
  78. RemoteComponent: CustomComponent
  79. },
  80. data () {
  81. return {
  82. activeName: 'data'
  83. }
  84. },
  85. computed: {
  86. ...mapState({
  87. activeCode: (state) => state.bigScreen.activeCode,
  88. hoverCode: (state) => state.bigScreen.hoverCode,
  89. config: (state) => state.bigScreen.activeItemConfig,
  90. chartList: (state) => state.bigScreen.pageInfo.chartList
  91. }),
  92. pageCode () {
  93. return this.$route.query.code
  94. },
  95. configDataSource () {
  96. return {
  97. dataSource: _.cloneDeep(this.config.dataSource),
  98. linkage: _.cloneDeep(this.config?.linkage),
  99. dataHandler: this.config?.dataHandler,
  100. dataSourceSetting: _.cloneDeep(this.config?.setting?.filter(item => item.tabName === 'data')) || []
  101. }
  102. },
  103. configStyle () {
  104. return {
  105. showTitle: this.config.showTitle,
  106. title: _.cloneDeep(this.config?.title),
  107. w: this.config?.w,
  108. h: this.config?.h,
  109. x: this.config?.x,
  110. y: this.config?.y,
  111. z: this.config?.z,
  112. setting: _.cloneDeep(this.config?.setting),
  113. customize: _.cloneDeep(this.config?.customize),
  114. url: this.config?.url,
  115. dateFormat: this.config?.dateFormat,
  116. endTime: this.config?.endTime
  117. }
  118. }
  119. },
  120. watch: {
  121. // 只更新样式部分,不调用接口
  122. configStyle: {
  123. handler (val, oldValue) {
  124. this.handleConfigChange(val, oldValue, 'configStyle')
  125. },
  126. deep: true
  127. },
  128. // 更新数据源部分,需要调用接口
  129. configDataSource: {
  130. handler (val, oldValue) {
  131. this.handleConfigChange(val, oldValue, 'configDataSource')
  132. },
  133. deep: true
  134. }
  135. },
  136. mounted () {},
  137. methods: {
  138. ...mapMutations('bigScreen', [
  139. 'saveTimeLine'
  140. ]),
  141. debounce (delay, obj) {
  142. if (this.timeout) {
  143. clearTimeout(this.timeout)
  144. }
  145. this.timeout = setTimeout(() => {
  146. this.$emit('updateSetting', { ...obj })
  147. }, delay)
  148. },
  149. handleConfigChange (val, oldValue, type) {
  150. if (!_.isEqual(val, oldValue)) {
  151. if (type === 'configStyle') {
  152. if (this.config.type === 'iframeChart') {
  153. this.debounce(500, { ...val, type: this.config.type, code: this.config.code })
  154. } else {
  155. this.$emit('updateSetting', { ...val, type: this.config.type, code: this.config.code })
  156. }
  157. } else {
  158. this.$emit('updateDataSetting', this.config)
  159. }
  160. this.saveTimeLine(`更新${val?.title ?? this.config.title}组件属性`)
  161. }
  162. },
  163. close () {
  164. this.$emit('closeRightPanel')
  165. },
  166. handleClick (val) {
  167. this.$set(this, 'activeName', val.name)
  168. },
  169. resolveComponentType,
  170. // 多个表单校验
  171. getFormPromise (form) {
  172. return new Promise((resolve) => {
  173. form.validate((res) => {
  174. resolve(res)
  175. })
  176. })
  177. },
  178. // 更新
  179. update () {
  180. // 有数据配置也有自定义配置的组件
  181. if (this.config.option.displayOption.dataAllocation.enable) {
  182. // 获取子组件的表单元素
  183. const commonForm = this.$refs.dataSetting.$refs.form
  184. const customForm = this.$refs.customSetting.$refs.form
  185. Promise.all([commonForm, customForm].map(this.getFormPromise)).then(
  186. async (res) => {
  187. const vaildateResult = res.every((item) => !!item)
  188. if (vaildateResult) {
  189. if (this.$refs.dataSetting.params) {
  190. const params = this.$refs.dataSetting.params
  191. const paramsMap = params.reduce((obj, param) => {
  192. obj[param.name] = param.value
  193. return obj
  194. }, {})
  195. this.config.dataSource.params = paramsMap
  196. }
  197. this.$emit('updateDataSetting', this.config)
  198. } else {
  199. this.$message.warning('请完成数据配置')
  200. return false
  201. }
  202. }
  203. )
  204. } else {
  205. // 只有自定义配置的组件
  206. if (this.$refs.customSetting?.$refs?.form?.validate) {
  207. this.$refs.customSetting.$refs.form.validate((valid) => {
  208. if (valid) {
  209. this.$emit('updateSetting', this.config)
  210. this.$message.success('更新成功')
  211. } else {
  212. this.$message.warning('请完成配置')
  213. return false
  214. }
  215. })
  216. } else {
  217. // 边框装饰组件的右侧配置
  218. this.$refs.customSetting.$refs.form.$refs.form.validate((valid) => {
  219. if (valid) {
  220. this.$emit('updateSetting', this.config)
  221. this.$message.success('更新成功')
  222. } else {
  223. this.$message.warning('请完成配置')
  224. return false
  225. }
  226. })
  227. }
  228. }
  229. }
  230. }
  231. }
  232. </script>
  233. <style lang="scss" scoped>
  234. @import '../../assets/style/settingWrap.scss';
  235. .add-filter-box {
  236. position: relative;
  237. .add-filter {
  238. margin-left: 100px;
  239. }
  240. .add-filter-btn {
  241. position: absolute;
  242. top: 0;
  243. }
  244. }
  245. </style>