index.vue 7.5 KB

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