!43 update src/components/Dict/index.vue.
Merge pull request !43 from 如今/N/A
This commit is contained in:
@@ -1,9 +1,10 @@
|
|||||||
<template>
|
<template>
|
||||||
<el-select
|
<el-select
|
||||||
v-if="type === 'select'"
|
v-if="type === 'select' || type === 'select-multiple'"
|
||||||
v-model="selectedValue"
|
v-model="selectedValue"
|
||||||
:placeholder="placeholder"
|
:placeholder="placeholder"
|
||||||
:disabled="disabled"
|
:disabled="disabled"
|
||||||
|
:multiple="type === 'select-multiple'"
|
||||||
clearable
|
clearable
|
||||||
:style="style"
|
:style="style"
|
||||||
@change="handleChange"
|
@change="handleChange"
|
||||||
@@ -93,28 +94,30 @@ const emit = defineEmits(["update:modelValue"]);
|
|||||||
const options = ref<Array<{ label: string; value: string | number }>>([]);
|
const options = ref<Array<{ label: string; value: string | number }>>([]);
|
||||||
|
|
||||||
const selectedValue = ref<any>(
|
const selectedValue = ref<any>(
|
||||||
typeof props.modelValue === "string" || typeof props.modelValue === "number"
|
["select-multiple", "checkbox"].includes(props.type)
|
||||||
? props.modelValue
|
? Array.isArray(props.modelValue)
|
||||||
: Array.isArray(props.modelValue)
|
? props.modelValue
|
||||||
|
: []
|
||||||
|
: typeof props.modelValue === "string" || typeof props.modelValue === "number"
|
||||||
? props.modelValue
|
? props.modelValue
|
||||||
: undefined
|
: undefined
|
||||||
);
|
);
|
||||||
|
|
||||||
// 监听 modelValue 和 options 的变化
|
// 监听 modelValue 和 options 的变化
|
||||||
watch(
|
watch(
|
||||||
[() => props.modelValue, () => options.value],
|
[() => props.modelValue, () => props.type, () => options.value],
|
||||||
([newValue, newOptions]) => {
|
([newValue, newType, newOptions]) => {
|
||||||
if (newOptions.length > 0 && newValue !== undefined) {
|
if (["select-multiple", "checkbox"].includes(newType)) {
|
||||||
if (props.type === "checkbox") {
|
selectedValue.value = Array.isArray(newValue) ? newValue : [];
|
||||||
selectedValue.value = Array.isArray(newValue) ? newValue : [];
|
} else {
|
||||||
} else {
|
if (newOptions.length > 0 && newValue !== undefined && newValue !== null) {
|
||||||
const matchedOption = newOptions.find(
|
const matchedOption = newOptions.find(
|
||||||
(option) => String(option.value) === String(newValue)
|
(option) => String(option.value) === String(newValue)
|
||||||
);
|
);
|
||||||
selectedValue.value = matchedOption?.value;
|
selectedValue.value = matchedOption?.value ?? undefined;
|
||||||
|
} else {
|
||||||
|
selectedValue.value = undefined;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
selectedValue.value = undefined;
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{ immediate: true }
|
{ immediate: true }
|
||||||
|
|||||||
Reference in New Issue
Block a user