index.vue 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223
  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 'packages/js/utils'
  49. import DataSetting from './DataSetting.vue'
  50. import rightSetting from 'packages/js/utils/rightSettingImport'
  51. import CustomComponent from './G2CustomSetting.vue'
  52. import Svgs from 'packages/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. if (!_.isEqual(val, oldValue)) {
  118. this.$emit('updateSetting',{...val,type:this.config.type,code:this.config.code})
  119. this.saveTimeLine(`更新${val?.title}组件属性`)
  120. }
  121. },
  122. deep: true
  123. },
  124. // 更新数据源部分,需要调用接口
  125. configDataSource: {
  126. handler (val, oldValue) {
  127. if (!_.isEqual(val, oldValue)) {
  128. this.$emit('updateDataSetting', this.config)
  129. this.saveTimeLine(`更新${val?.title}组件属性`)
  130. }
  131. },
  132. deep: true
  133. }
  134. },
  135. mounted () {},
  136. methods: {
  137. ...mapMutations('bigScreen', [
  138. 'saveTimeLine'
  139. ]),
  140. close () {
  141. this.$emit('closeRightPanel')
  142. },
  143. handleClick (val) {
  144. this.$set(this, 'activeName', val.name)
  145. },
  146. resolveComponentType,
  147. // 多个表单校验
  148. getFormPromise (form) {
  149. return new Promise((resolve) => {
  150. form.validate((res) => {
  151. resolve(res)
  152. })
  153. })
  154. },
  155. // 更新
  156. update () {
  157. // 有数据配置也有自定义配置的组件
  158. if (this.config.option.displayOption.dataAllocation.enable) {
  159. // 获取子组件的表单元素
  160. const commonForm = this.$refs.dataSetting.$refs.form
  161. const customForm = this.$refs.customSetting.$refs.form
  162. Promise.all([commonForm, customForm].map(this.getFormPromise)).then(
  163. async (res) => {
  164. const vaildateResult = res.every((item) => !!item)
  165. if (vaildateResult) {
  166. if (this.$refs.dataSetting.params) {
  167. const params = this.$refs.dataSetting.params
  168. const paramsMap = params.reduce((obj, param) => {
  169. obj[param.name] = param.value
  170. return obj
  171. }, {})
  172. this.config.dataSource.params = paramsMap
  173. }
  174. this.$emit('updateDataSetting', this.config)
  175. } else {
  176. this.$message.warning('请完成数据配置')
  177. return false
  178. }
  179. }
  180. )
  181. } else {
  182. // 只有自定义配置的组件
  183. if (this.$refs.customSetting?.$refs?.form?.validate) {
  184. this.$refs.customSetting.$refs.form.validate((valid) => {
  185. if (valid) {
  186. this.$emit('updateSetting', this.config)
  187. this.$message.success('更新成功')
  188. } else {
  189. this.$message.warning('请完成配置')
  190. return false
  191. }
  192. })
  193. } else {
  194. // 边框装饰组件的右侧配置
  195. this.$refs.customSetting.$refs.form.$refs.form.validate((valid) => {
  196. if (valid) {
  197. this.$emit('updateSetting', this.config)
  198. this.$message.success('更新成功')
  199. } else {
  200. this.$message.warning('请完成配置')
  201. return false
  202. }
  203. })
  204. }
  205. }
  206. }
  207. }
  208. }
  209. </script>
  210. <style lang="scss" scoped>
  211. @import '~packages/assets/style/settingWrap.scss';
  212. .add-filter-box {
  213. position: relative;
  214. .add-filter {
  215. margin-left: 100px;
  216. }
  217. .add-filter-btn {
  218. position: absolute;
  219. top: 0;
  220. }
  221. }
  222. </style>