index.vue 6.0 KB

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