index.vue 6.4 KB

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