Merge pull request #8490 from dataease/pr@dev-v2_empty_data

fix(查询组件): 文本下拉组件的选项新增空数据选项
This commit is contained in:
dataeaseShu 2024-03-14 10:08:34 +08:00 committed by GitHub
commit 2f197e8024
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 39 additions and 6 deletions

View File

@ -635,6 +635,7 @@ const parameterCompletion = () => {
aroundRange: 'f', aroundRange: 'f',
arbitraryTimeRange: new Date(), arbitraryTimeRange: new Date(),
setTimeRange: false, setTimeRange: false,
showEmpty: false,
timeRange: { timeRange: {
intervalType: 'none', intervalType: 'none',
dynamicWindow: false, dynamicWindow: false,
@ -1405,6 +1406,11 @@ defineExpose({
> >
</div> </div>
</div> </div>
<div class="list-item" v-if="+curComponent.displayType === 0">
<div class="label">
<el-checkbox v-model="curComponent.showEmpty" label="选项值包含空数据" />
</div>
</div>
<div class="list-item"> <div class="list-item">
<div class="label"> <div class="label">
<el-checkbox v-model="curComponent.parametersCheck" label="绑定参数" /> <el-checkbox v-model="curComponent.parametersCheck" label="绑定参数" />

View File

@ -8,6 +8,7 @@ interface SelectConfig {
defaultValue: any defaultValue: any
checkedFieldsMap: object checkedFieldsMap: object
displayType: string displayType: string
showEmpty: boolean
id: string id: string
checkedFields: string[] checkedFields: string[]
field: { field: {
@ -71,7 +72,9 @@ const handleFieldIdChange = (val: string[]) => {
loading.value = true loading.value = true
getEnumValue(val) getEnumValue(val)
.then(res => { .then(res => {
options.value = (res || []).map(ele => { options.value = (res || [])
.filter(ele => ele !== null)
.map(ele => {
return { return {
label: ele, label: ele,
value: ele value: ele
@ -89,6 +92,7 @@ const handleFieldIdChange = (val: string[]) => {
? [...selectValue.value] ? [...selectValue.value]
: selectValue.value : selectValue.value
} }
setEmptyData()
}) })
} }
@ -99,6 +103,28 @@ const visibleChange = (val: boolean) => {
}, 50) }, 50)
} }
watch(
() => config.value.showEmpty,
() => {
setEmptyData()
}
)
const setEmptyData = () => {
const { showEmpty, displayType } = config.value
if (+displayType !== 0) return
const [s] = options.value
if (showEmpty) {
if (s?.value !== '_empty_$') {
options.value = [{ label: '空数据', value: '_empty_$' }, ...options.value]
}
} else {
if (s?.value === '_empty_$') {
options.value = options.value.slice(1)
}
}
}
watch( watch(
() => config.value.defaultValue, () => config.value.defaultValue,
val => { val => {
@ -214,6 +240,7 @@ const setOptions = (num: number) => {
} }
}) })
) )
setEmptyData()
break break
default: default:
break break