index.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 EchartsCustomSetting from './EchartsCustomSetting.vue'
  60. import Svgs from 'data-room-ui/Svgs/setting.vue'
  61. import { mapState, mapMutations } from 'vuex'
  62. // import _ from 'lodash'
  63. import isEqual from 'lodash/isEqual'
  64. import cloneDeep from 'lodash/cloneDeep'
  65. import { EventBus } from 'data-room-ui/js/utils/eventBus'
  66. // 整体动态导入右侧设置组件,不用手动注册
  67. const components = {}
  68. for (const key in rightSetting) {
  69. if (Object.hasOwnProperty.call(rightSetting, key)) {
  70. const component = rightSetting[key]
  71. components[key] = component
  72. }
  73. }
  74. export default {
  75. name: 'RightSetting',
  76. components: {
  77. ...components,
  78. DataSetting,
  79. CustomComponent,
  80. Svgs,
  81. // 远程组件的样式配置也和g2Plot的样式配置一样,采用属性配置, 故使用一个组件
  82. RemoteComponent: CustomComponent,
  83. EchartsComponent: EchartsCustomSetting
  84. },
  85. data () {
  86. return {
  87. activeName: 'data',
  88. isOperationRollback: false
  89. }
  90. },
  91. computed: {
  92. ...mapState({
  93. activeCode: (state) => state.bigScreen.activeCode,
  94. hoverCode: (state) => state.bigScreen.hoverCode,
  95. config: (state) => state.bigScreen.activeItemConfig,
  96. chartList: (state) => state.bigScreen.pageInfo.chartList
  97. }),
  98. pageCode () {
  99. return this.$route.query.code
  100. },
  101. configDataSource () {
  102. return {
  103. dataSource: cloneDeep(this.config.dataSource),
  104. linkage: cloneDeep(this.config?.linkage),
  105. dataHandler: this.config?.dataHandler,
  106. dataSourceSetting: cloneDeep(this.config?.setting?.filter(item => item.tabName === 'data')) || [],
  107. code: this.config?.code
  108. }
  109. },
  110. configStyle () {
  111. return {
  112. showTitle: this.config.showTitle,
  113. title: cloneDeep(this.config?.title),
  114. border: cloneDeep(this.config?.border),
  115. w: this.config?.w,
  116. h: this.config?.h,
  117. x: this.config?.x,
  118. y: this.config?.y,
  119. z: this.config?.z,
  120. rotateX: this.config?.rotateX,
  121. rotateY: this.config?.rotateY,
  122. rotateZ: this.config?.rotateZ,
  123. perspective: this.config?.perspective,
  124. skewX: this.config?.skewX,
  125. skewY: this.config?.skewY,
  126. setting: cloneDeep(this.config?.setting),
  127. customize: cloneDeep(this.config?.customize),
  128. url: this.config?.url,
  129. dateFormat: this.config?.dateFormat,
  130. endTime: this.config?.endTime
  131. }
  132. }
  133. },
  134. watch: {
  135. // 只更新样式部分,不调用接口
  136. configStyle: {
  137. handler (val, oldValue) {
  138. this.handleConfigChange(val, oldValue, 'configStyle')
  139. },
  140. deep: true
  141. },
  142. // 更新数据源部分,需要调用接口
  143. configDataSource: {
  144. handler (val, oldValue) {
  145. this.handleConfigChange(val, oldValue, 'configDataSource')
  146. },
  147. deep: true
  148. }
  149. },
  150. mounted () {
  151. EventBus.$on('operationRollback', val => {
  152. this.isOperationRollback = val
  153. })
  154. },
  155. beforeDestroy () {
  156. EventBus.$off('operationRollback')
  157. },
  158. methods: {
  159. ...mapMutations('bigScreen', [
  160. 'saveTimeLine'
  161. ]),
  162. debounce (delay, obj) {
  163. if (this.timeout) {
  164. clearTimeout(this.timeout)
  165. }
  166. this.timeout = setTimeout(() => {
  167. this.$emit('updateSetting', { ...obj })
  168. }, delay)
  169. },
  170. handleConfigChange (val, oldValue, type) {
  171. if (val.code === oldValue.code) {
  172. if (!isEqual(val, oldValue)) {
  173. if (type === 'configStyle') {
  174. if (this.config.type === 'iframeChart') {
  175. this.debounce(500, { ...val, type: this.config.type, code: this.config.code, parentCode: this.config?.parentCode })
  176. } else {
  177. this.$emit('updateSetting', { ...val, type: this.config.type, code: this.config.code, theme: this.config.theme, parentCode: this.config?.parentCode })
  178. }
  179. } else {
  180. this.$emit('updateDataSetting', this.config)
  181. }
  182. if (!this.isOperationRollback) {
  183. this.saveTimeLine(`更新${val?.title ?? this.config.title}组件属性`)
  184. this.isOperationRollback = false
  185. }
  186. }
  187. }
  188. },
  189. close () {
  190. this.$emit('closeRightPanel')
  191. },
  192. handleClick (val) {
  193. this.$set(this, 'activeName', val.name)
  194. },
  195. resolveComponentType,
  196. // 多个表单校验
  197. getFormPromise (form) {
  198. return new Promise((resolve) => {
  199. form.validate((res) => {
  200. resolve(res)
  201. })
  202. })
  203. },
  204. // 更新
  205. update () {
  206. // 有数据配置也有自定义配置的组件
  207. if (this.config.option.displayOption.dataAllocation.enable) {
  208. // 获取子组件的表单元素
  209. const commonForm = this.$refs.dataSetting.$refs.form
  210. const customForm = this.$refs.customSetting.$refs.form
  211. Promise.all([commonForm, customForm].map(this.getFormPromise)).then(
  212. async (res) => {
  213. const vaildateResult = res.every((item) => !!item)
  214. if (vaildateResult) {
  215. if (this.$refs.dataSetting.params) {
  216. const params = this.$refs.dataSetting.params
  217. const paramsMap = params.reduce((obj, param) => {
  218. obj[param.name] = param.value
  219. return obj
  220. }, {})
  221. this.config.dataSource.params = paramsMap
  222. }
  223. this.$emit('updateDataSetting', this.config)
  224. } else {
  225. this.$message.warning('请完成数据配置')
  226. return false
  227. }
  228. }
  229. )
  230. } else {
  231. // 只有自定义配置的组件
  232. if (this.$refs.customSetting?.$refs?.form?.validate) {
  233. this.$refs.customSetting.$refs.form.validate((valid) => {
  234. if (valid) {
  235. this.$emit('updateSetting', this.config)
  236. this.$message.success('更新成功')
  237. } else {
  238. this.$message.warning('请完成配置')
  239. return false
  240. }
  241. })
  242. } else {
  243. // 边框装饰组件的右侧配置
  244. this.$refs.customSetting.$refs.form.$refs.form.validate((valid) => {
  245. if (valid) {
  246. this.$emit('updateSetting', this.config)
  247. this.$message.success('更新成功')
  248. } else {
  249. this.$message.warning('请完成配置')
  250. return false
  251. }
  252. })
  253. }
  254. }
  255. }
  256. }
  257. }
  258. </script>
  259. <style lang="scss" scoped>
  260. @import '../../assets/style/settingWrap.scss';
  261. .add-filter-box {
  262. position: relative;
  263. .add-filter {
  264. margin-left: 100px;
  265. }
  266. .add-filter-btn {
  267. position: absolute;
  268. top: 0;
  269. }
  270. }
  271. </style>