fix: bug#11218

This commit is contained in:
xieyonghong 2023-04-01 14:22:54 +08:00
parent 8d2c2133dd
commit 83b9cc8dfc
4 changed files with 25 additions and 9 deletions

View File

@ -65,12 +65,12 @@ const handleOptions = computed(() => {
{
label: _item.trueText || true,
value: _item.trueValue || true,
id: _item.trueValue || true,
id: String(_item.trueValue || true),
},
{
label: _item.falseText || false,
value: _item.falseValue || false,
id: _item.falseValue || false,
id: String(_item.falseValue || false),
},
];
}

View File

@ -135,13 +135,15 @@ const handleOptions = computed(() => {
return [
{
label: _item.trueText || true,
name: _item.trueText || true,
value: _item.trueValue || true,
id: _item.trueValue || true,
id: String(_item.trueValue || true),
},
{
label: _item.falseText || false,
name: _item.falseText || false,
value: _item.falseValue || false,
id: _item.falseValue || false,
id: String(_item.falseValue || false),
},
];
}
@ -149,6 +151,7 @@ const handleOptions = computed(() => {
return _item?.elements.map((i: any) => {
return {
label: i.text,
name: i.text,
value: i.value,
id: i.value,
};
@ -168,7 +171,7 @@ const onChange = () => {
});
};
const onValueChange = (val: any) => {
const onValueChange = (val: any, label: string) => {
const obj = {
[`${propertyModelRef.properties}`]: {
value: propertyModelRef?.propertiesValue,
@ -176,7 +179,7 @@ const onValueChange = (val: any) => {
},
};
emit('update:value', obj);
emit('change', val?.name || val)
emit('change', label || val)
};
watch(

View File

@ -11,7 +11,7 @@
</template>
<script lang='ts' setup name='DropdownMenus'>
import { isBoolean, isUndefined } from 'lodash-es'
import { isArray, isBoolean, isString, isUndefined } from 'lodash-es'
import { getOption } from '../DropdownButton/util'
type ValueType = string| number | boolean
@ -45,6 +45,9 @@ const myOptions = computed(() => {
_label = _value === true ? '是' : '否'
_value = String(_value)
}
if (isArray(_value)) {
_value = JSON.stringify(_value)
}
return {
...item,
label: _label,
@ -60,7 +63,10 @@ const handleBoolean = (key: string) => {
}
const click = (e: any) => {
const _key = ['true', 'false'].includes(e.key) ? handleBoolean(e.key) : e.key
let _key = ['true', 'false'].includes(e.key) ? handleBoolean(e.key) : e.key
if (isString(_key) && _key.startsWith('[') && _key.endsWith(']')) {
_key = JSON.parse(_key)
}
const option = getOption(myOptions.value, _key, props.valueName)
myValue.value = e.key
emit('update:value', _key)
@ -71,7 +77,13 @@ const click = (e: any) => {
}
watch(() => props.value, () => {
myValue.value = isBoolean(props.value) ? String(props.value) : props.value
if (isBoolean(props.value)) {
myValue.value = isBoolean(props.value)
} else if (isArray(props.value)) {
myValue.value = JSON.stringify(props.value)
} else {
myValue.value = props.value
}
}, { immediate: true})
</script>

View File

@ -38,6 +38,7 @@
<DropdownMenus
v-if='(["metric", "upper"].includes(item.key) ? metricOptions : options).length'
:options='["metric", "upper"].includes(item.key) ? metricOptions : options'
:value='myValue'
:valueName='valueName'
@click='onSelect'
/>