Pārlūkot izejas kodu

feat: 优化选择器placeholder获取数据方式,去除选择器保存data逻辑

wu.jian2 1 gadu atpakaļ
vecāks
revīzija
874ab066b0

+ 2 - 43
data-room-ui/packages/BasicComponents/Select/index.vue

@@ -4,7 +4,7 @@
     v-model="value"
     :popper-class="'basic-component-select select-popper-' + config.code"
     :class="['basic-component-select', `select-${config.code}`]"
-    :placeholder="`请选择${placeholder || newPlaceholder}`"
+    :placeholder="config.customize.placeholder"
     clearable
     :filterable="filterable"
     @visible-change="visibleChange"
@@ -21,10 +21,8 @@
 </template>
 
 <script>
-import { EventBus } from 'data-room-ui/js/utils/eventBus'
 import commonMixins from 'data-room-ui/js/mixins/commonMixins'
 import linkageMixins from 'data-room-ui/js/mixins/linkageMixins'
-import { getDataSetDetails } from 'data-room-ui/js/api/bigScreenApi'
 import { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
 import cloneDeep from 'lodash/cloneDeep'
 window.dataSetFields = []
@@ -44,53 +42,26 @@ export default {
       value: '',
       innerConfig: {},
       optionData: [],
-      newPlaceholder: '',
       filterable: false
     }
   },
   computed: {
     isPreview () {
       return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview')
-    },
-    placeholder: {
-      get () {
-        return window.dataSetFields.find(field => field.value === this.config.dataSource.dimensionField)?.label || ''
-      },
-      set (val) {
-        this.newPlaceholder = val
-      }
     }
   },
   watch: { },
   created () {
   },
   mounted () {
-    window.dataSetFields = []
     this.changeStyle(this.config)
-    EventBus.$on('changeBusinessKey', () => {
-      window.dataSetFields = []
-    })
     if (this.isPreview) {
       this.filterable = true
-      document.querySelector(`.select-${this.config.code}`).style.pointerEvents = 'all'
-      if (this.config.dataSource.businessKey && window.dataSetFields.length === 0) {
-        getDataSetDetails(this.config.dataSource.businessKey).then(res => {
-          window.dataSetFields = res.fields.map(field => {
-            return {
-              label: field.comment || field.fieldDesc,
-              value: field.name || field.fieldName
-            }
-          })
-          this.placeholder = window.dataSetFields.find(field => field.value === this.config.dataSource.dimensionField)?.label || ''
-        })
-      }
     } else {
       document.querySelector(`.select-${this.config.code}`).style.pointerEvents = 'none'
     }
   },
-  beforeDestroy () {
-    EventBus.$off('changeBusinessKey')
-  },
+  beforeDestroy () { },
   methods: {
     dataFormatting (config, data) {
       // 数据返回成功则赋值
@@ -105,20 +76,8 @@ export default {
             console.info(e)
           }
         }
-        config.option.data = data
         this.optionData = data
         config.customize.title = config.option.data[config.dataSource.dimensionField] || config.customize.title
-        if (window.dataSetFields.length === 0) {
-          getDataSetDetails(this.config.dataSource.businessKey).then(res => {
-            window.dataSetFields = res.fields.map(field => {
-              return {
-                label: field.comment || field.fieldDesc,
-                value: field.name || field.fieldName
-              }
-            })
-            this.placeholder = window.dataSetFields.find(field => field.value === this.config.dataSource.dimensionField)?.label || ''
-          })
-        }
         // 语音播报
       } else {
         // 数据返回失败则赋前端的模拟数据

+ 1 - 0
data-room-ui/packages/BasicComponents/Select/settingConfig.js

@@ -30,6 +30,7 @@ const customConfig = {
   },
   // 自定义属性
   customize: {
+    placeholder: '请选择',
     // 输入框背景颜色
     backgroundColor: '#35393F',
     // 输入框字体大小

+ 7 - 2
data-room-ui/packages/BigScreenDesign/RightSetting/DataSetting.vue

@@ -578,7 +578,6 @@
 </template>
 <script>
 import ElDragSelect from './ElDragSelect.vue'
-import { EventBus } from 'data-room-ui/js/utils/eventBus'
 // import { isEmpty, cloneDeep } from 'lodash'
 import isEmpty from 'lodash/isEmpty'
 import cloneDeep from 'lodash/cloneDeep'
@@ -703,6 +702,13 @@ export default {
         }
       },
       deep: true
+    },
+    'config.dataSource.dimensionField' (val) {
+      if (['select'].includes(this.config.type)) {
+        if (this.config.customize?.placeholder) {
+          this.config.customize.placeholder = '请选择' + this.dataSourceDataList.find(item => item.fieldName === val).comment
+        }
+      }
     }
   },
   mounted () {
@@ -738,7 +744,6 @@ export default {
       if (id) {
         this.config.dataSource.businessKey = id
         getDataSetDetails(id).then(res => {
-          EventBus.$emit('changeBusinessKey')
           this.fieldsList = res.fields
           // 初始化时以组件本来的参数设置为主
           if (type === 'initial') {