index.vue 7.2 KB

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