index.vue 6.9 KB

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