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

main
wu.jian2 2 years ago
parent ed475bc96f
commit 874ab066b0

@ -4,7 +4,7 @@
v-model="value" v-model="value"
:popper-class="'basic-component-select select-popper-' + config.code" :popper-class="'basic-component-select select-popper-' + config.code"
:class="['basic-component-select', `select-${config.code}`]" :class="['basic-component-select', `select-${config.code}`]"
:placeholder="`请选择${placeholder || newPlaceholder}`" :placeholder="config.customize.placeholder"
clearable clearable
:filterable="filterable" :filterable="filterable"
@visible-change="visibleChange" @visible-change="visibleChange"
@ -21,10 +21,8 @@
</template> </template>
<script> <script>
import { EventBus } from 'data-room-ui/js/utils/eventBus'
import commonMixins from 'data-room-ui/js/mixins/commonMixins' import commonMixins from 'data-room-ui/js/mixins/commonMixins'
import linkageMixins from 'data-room-ui/js/mixins/linkageMixins' 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 { settingToTheme } from 'data-room-ui/js/utils/themeFormatting'
import cloneDeep from 'lodash/cloneDeep' import cloneDeep from 'lodash/cloneDeep'
window.dataSetFields = [] window.dataSetFields = []
@ -44,53 +42,26 @@ export default {
value: '', value: '',
innerConfig: {}, innerConfig: {},
optionData: [], optionData: [],
newPlaceholder: '',
filterable: false filterable: false
} }
}, },
computed: { computed: {
isPreview () { isPreview () {
return (this.$route.path === window?.BS_CONFIG?.routers?.previewUrl) || (this.$route.path === '/big-screen/preview') 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: { }, watch: { },
created () { created () {
}, },
mounted () { mounted () {
window.dataSetFields = []
this.changeStyle(this.config) this.changeStyle(this.config)
EventBus.$on('changeBusinessKey', () => {
window.dataSetFields = []
})
if (this.isPreview) { if (this.isPreview) {
this.filterable = true 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 { } else {
document.querySelector(`.select-${this.config.code}`).style.pointerEvents = 'none' document.querySelector(`.select-${this.config.code}`).style.pointerEvents = 'none'
} }
}, },
beforeDestroy () { beforeDestroy () { },
EventBus.$off('changeBusinessKey')
},
methods: { methods: {
dataFormatting (config, data) { dataFormatting (config, data) {
// //
@ -105,20 +76,8 @@ export default {
console.info(e) console.info(e)
} }
} }
config.option.data = data
this.optionData = data this.optionData = data
config.customize.title = config.option.data[config.dataSource.dimensionField] || config.customize.title 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 { } else {
// //

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

@ -578,7 +578,6 @@
</template> </template>
<script> <script>
import ElDragSelect from './ElDragSelect.vue' import ElDragSelect from './ElDragSelect.vue'
import { EventBus } from 'data-room-ui/js/utils/eventBus'
// import { isEmpty, cloneDeep } from 'lodash' // import { isEmpty, cloneDeep } from 'lodash'
import isEmpty from 'lodash/isEmpty' import isEmpty from 'lodash/isEmpty'
import cloneDeep from 'lodash/cloneDeep' import cloneDeep from 'lodash/cloneDeep'
@ -703,6 +702,13 @@ export default {
} }
}, },
deep: true 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 () { mounted () {
@ -738,7 +744,6 @@ export default {
if (id) { if (id) {
this.config.dataSource.businessKey = id this.config.dataSource.businessKey = id
getDataSetDetails(id).then(res => { getDataSetDetails(id).then(res => {
EventBus.$emit('changeBusinessKey')
this.fieldsList = res.fields this.fieldsList = res.fields
// //
if (type === 'initial') { if (type === 'initial') {

Loading…
Cancel
Save