mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-09-17 10:56:39 +08:00
优化枚举与字典相关组件,增加禁用与隐藏选项属性
This commit is contained in:
parent
81b7b2a3a4
commit
e44b116184
@ -9,7 +9,11 @@
|
||||
*
|
||||
-->
|
||||
<template>
|
||||
<a-checkbox-group :style="`width: ${width}`" v-model:value="selectValue" :options="optionList" @change="handleChange" />
|
||||
<a-checkbox-group :style="`width: ${width}`" v-model:value="selectValue" @change="handleChange" :disabled="disabled">
|
||||
<a-checkbox v-for="item in valueDescList" :key="item.value" :value="item.value" :disabled="disabledOption.includes(item.value)">
|
||||
{{ item.desc }}
|
||||
</a-checkbox>
|
||||
</a-checkbox-group>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
@ -22,19 +26,32 @@
|
||||
type: String,
|
||||
default: '200px',
|
||||
},
|
||||
// 禁用整个多选框
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 需要禁用的选项枚举值
|
||||
disabledOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
// 需要隐藏的选项枚举值
|
||||
hiddenOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
// ------------ 枚举数据 加载和构建 ------------
|
||||
|
||||
const optionList = ref([]);
|
||||
function buildOptionList() {
|
||||
const valueDescList = ref([]);
|
||||
|
||||
onMounted(() => {
|
||||
const internalInstance = getCurrentInstance(); // 有效 全局
|
||||
const smartEnumPlugin = internalInstance.appContext.config.globalProperties.$smartEnumPlugin;
|
||||
const valueList = smartEnumPlugin.getValueDescList(props.enumName);
|
||||
optionList.value = valueList.map((e) => Object.assign({}, { value: e.value, label: e.desc }));
|
||||
}
|
||||
|
||||
onMounted(buildOptionList);
|
||||
valueDescList.value = smartEnumPlugin.getValueDescList(props.enumName).filter((item) => !props.hiddenOption.includes(item.value));
|
||||
});
|
||||
|
||||
// ------------ 数据选中 事件及其相关 ------------
|
||||
|
||||
@ -43,11 +60,14 @@
|
||||
watch(
|
||||
() => props.value,
|
||||
(newValue) => {
|
||||
selectValue.value = newValue;
|
||||
}
|
||||
// 如果传入的值是被禁用或被隐藏的选项,则移除这些选项
|
||||
selectValue.value = newValue.filter((item) => !props.hiddenOption.includes(item) && !props.disabledOption.includes(item));
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
|
||||
function handleChange(value) {
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
|
@ -10,15 +10,15 @@
|
||||
-->
|
||||
<template>
|
||||
<template v-if="isButton">
|
||||
<a-radio-group v-model:value="selectValue" @change="handleChange" button-style="solid">
|
||||
<a-radio-button v-for="item in $smartEnumPlugin.getValueDescList(props.enumName)" :key="item.value" :value="item.value">
|
||||
<a-radio-group v-model:value="selectValue" @change="handleChange" button-style="solid" :disabled="disabled">
|
||||
<a-radio-button v-for="item in valueDescList" :key="item.value" :value="item.value" :disabled="disabledOption.includes(item.value)">
|
||||
{{ item.desc }}
|
||||
</a-radio-button>
|
||||
</a-radio-group>
|
||||
</template>
|
||||
<template v-else>
|
||||
<a-radio-group v-model:value="selectValue" @change="handleChange">
|
||||
<a-radio v-for="item in $smartEnumPlugin.getValueDescList(props.enumName)" :key="item.value" :value="item.value">
|
||||
<a-radio-group v-model:value="selectValue" @change="handleChange" :disabled="disabled">
|
||||
<a-radio v-for="item in valueDescList" :key="item.value" :value="item.value" :disabled="disabledOption.includes(item.value)">
|
||||
{{ item.desc }}
|
||||
</a-radio>
|
||||
</a-radio-group>
|
||||
@ -26,7 +26,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { ref, watch, onMounted, getCurrentInstance } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
enumName: String,
|
||||
@ -43,19 +43,44 @@
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 禁用整个单选框
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 需要禁用的选项枚举值
|
||||
disabledOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
// 需要隐藏的选项枚举值
|
||||
hiddenOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
const valueDescList = ref([]);
|
||||
|
||||
onMounted(() => {
|
||||
const internalInstance = getCurrentInstance(); // 有效 全局
|
||||
const smartEnumPlugin = internalInstance.appContext.config.globalProperties.$smartEnumPlugin;
|
||||
valueDescList.value = smartEnumPlugin.getValueDescList(props.enumName).filter((item) => !props.hiddenOption.includes(item.value));
|
||||
});
|
||||
|
||||
const selectValue = ref(props.value);
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(newValue) => {
|
||||
selectValue.value = newValue;
|
||||
}
|
||||
// 如果传入的值是被禁用或被隐藏的选项,则移除该选项
|
||||
selectValue.value = props.disabledOption.includes(newValue) || props.hiddenOption.includes(newValue) ? undefined : newValue;
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
|
||||
function handleChange(e) {
|
||||
emit('update:value', e.target.value);
|
||||
emit('change', e.target.value);
|
||||
|
@ -19,18 +19,18 @@
|
||||
@change="handleChange"
|
||||
:disabled="disabled"
|
||||
>
|
||||
<a-select-option v-for="item in $smartEnumPlugin.getValueDescList(props.enumName)" :key="item.value" :value="item.value">
|
||||
<a-select-option v-for="item in valueDescList" :key="item.value" :value="item.value" :disabled="disabledOption.includes(item.value)">
|
||||
{{ item.desc }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, watch } from 'vue';
|
||||
import { ref, watch, onMounted, getCurrentInstance } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
enumName: String,
|
||||
value: [Number,String],
|
||||
value: [Number, String],
|
||||
width: {
|
||||
type: String,
|
||||
default: '100%',
|
||||
@ -43,23 +43,44 @@
|
||||
type: String,
|
||||
default: 'default',
|
||||
},
|
||||
// 禁用整个下拉选择框
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 需要禁用的选项枚举值
|
||||
disabledOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
// 需要隐藏的选项枚举值
|
||||
hiddenOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
const valueDescList = ref([]);
|
||||
|
||||
onMounted(() => {
|
||||
const internalInstance = getCurrentInstance(); // 有效 全局
|
||||
const smartEnumPlugin = internalInstance.appContext.config.globalProperties.$smartEnumPlugin;
|
||||
valueDescList.value = smartEnumPlugin.getValueDescList(props.enumName).filter((item) => !props.hiddenOption.includes(item.value));
|
||||
});
|
||||
|
||||
const selectValue = ref(props.value);
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(newValue) => {
|
||||
selectValue.value = newValue;
|
||||
}
|
||||
// 如果传入的值是被禁用或被隐藏的选项,则移除该选项
|
||||
selectValue.value = props.disabledOption.includes(newValue) || props.hiddenOption.includes(newValue) ? undefined : newValue;
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
|
||||
function handleChange(value) {
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
|
@ -18,6 +18,7 @@
|
||||
:allowClear="true"
|
||||
:size="size"
|
||||
@change="onChange"
|
||||
:disabled="disabled"
|
||||
>
|
||||
<a-select-option v-for="item in dictKeyCodeList" :key="item.keyCode" :value="item.keyCode">
|
||||
{{ item.keyName }}
|
||||
@ -27,7 +28,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, ref, watch, defineExpose } from 'vue';
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { dictApi } from '/@/api/support/dict-api';
|
||||
|
||||
defineExpose({
|
||||
@ -49,7 +50,7 @@
|
||||
default: 'default',
|
||||
},
|
||||
// 禁用标识
|
||||
disabledFlag: {
|
||||
disabled: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
|
@ -20,7 +20,12 @@
|
||||
@change="onChange"
|
||||
:disabled="disabled"
|
||||
>
|
||||
<a-select-option v-for="item in dictValueList" :key="item.valueCode" :value="item.valueCode">
|
||||
<a-select-option
|
||||
v-for="item in dictValueList"
|
||||
:key="item.valueCode"
|
||||
:value="item.valueCode"
|
||||
:disabled="disabledOption.includes(item.valueCode)"
|
||||
>
|
||||
{{ item.valueName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
@ -28,7 +33,7 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { dictApi } from '/@/api/support/dict-api';
|
||||
|
||||
const props = defineProps({
|
||||
@ -50,10 +55,21 @@
|
||||
type: String,
|
||||
default: 'default',
|
||||
},
|
||||
// 禁用整个下拉选择框
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 需要禁用的选项字典值编码
|
||||
disabledOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
// 需要隐藏的选项字典值编码
|
||||
hiddenOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
// -------------------------- 查询 字典数据 --------------------------
|
||||
@ -61,7 +77,7 @@
|
||||
const dictValueList = ref([]);
|
||||
async function queryDict() {
|
||||
let res = await dictApi.valueList(props.keyCode);
|
||||
dictValueList.value = res.data;
|
||||
dictValueList.value = res.data.filter((item) => !props.hiddenOption.includes(item.valueCode));
|
||||
}
|
||||
|
||||
onMounted(queryDict);
|
||||
@ -69,14 +85,22 @@
|
||||
// -------------------------- 选中 相关、事件 --------------------------
|
||||
|
||||
const selectValue = ref(props.value);
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(value) => {
|
||||
selectValue.value = value;
|
||||
}
|
||||
(newValue) => {
|
||||
// 如果传入的值是被禁用或被隐藏的选项,则移除这些选项
|
||||
if (Array.isArray(newValue)) {
|
||||
selectValue.value = newValue.filter((item) => !props.disabledOption.includes(item) && !props.hiddenOption.includes(item));
|
||||
} else {
|
||||
selectValue.value = props.hiddenOption.includes(newValue) || props.disabledOption.includes(newValue) ? undefined : newValue;
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
|
||||
function onChange(value) {
|
||||
if (!value) {
|
||||
emit('update:value', []);
|
||||
@ -87,8 +111,8 @@
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
} else {
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
emit('update:value', [value]);
|
||||
emit('change', [value]);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@ -9,7 +9,11 @@
|
||||
*
|
||||
-->
|
||||
<template>
|
||||
<a-checkbox-group :style="`width: ${width}`" v-model:value="selectValue" :options="optionList" @change="handleChange" />
|
||||
<a-checkbox-group :style="`width: ${width}`" v-model:value="selectValue" @change="handleChange" :disabled="disabled">
|
||||
<a-checkbox v-for="item in valueDescList" :key="item.value" :value="item.value" :disabled="disabledOption.includes(item.value)">
|
||||
{{ item.desc }}
|
||||
</a-checkbox>
|
||||
</a-checkbox-group>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
@ -22,19 +26,32 @@
|
||||
type: String,
|
||||
default: '200px',
|
||||
},
|
||||
// 禁用整个多选框
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 需要禁用的选项枚举值
|
||||
disabledOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
// 需要隐藏的选项枚举值
|
||||
hiddenOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
// ------------ 枚举数据 加载和构建 ------------
|
||||
|
||||
const optionList = ref([]);
|
||||
function buildOptionList() {
|
||||
const valueDescList = ref([]);
|
||||
|
||||
onMounted(() => {
|
||||
const internalInstance = getCurrentInstance(); // 有效 全局
|
||||
const smartEnumPlugin = internalInstance.appContext.config.globalProperties.$smartEnumPlugin;
|
||||
const valueList = smartEnumPlugin.getValueDescList(props.enumName);
|
||||
optionList.value = valueList.map((e) => Object.assign({}, { value: e.value, label: e.desc }));
|
||||
}
|
||||
|
||||
onMounted(buildOptionList);
|
||||
valueDescList.value = smartEnumPlugin.getValueDescList(props.enumName).filter((item) => !props.hiddenOption.includes(item.value));
|
||||
});
|
||||
|
||||
// ------------ 数据选中 事件及其相关 ------------
|
||||
|
||||
@ -43,11 +60,14 @@
|
||||
watch(
|
||||
() => props.value,
|
||||
(newValue) => {
|
||||
selectValue.value = newValue;
|
||||
}
|
||||
// 如果传入的值是被禁用或被隐藏的选项,则移除这些选项
|
||||
selectValue.value = newValue.filter((item) => !props.hiddenOption.includes(item) && !props.disabledOption.includes(item));
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
|
||||
function handleChange(value) {
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
|
@ -10,15 +10,15 @@
|
||||
-->
|
||||
<template>
|
||||
<template v-if="isButton">
|
||||
<a-radio-group v-model:value="selectValue" @change="handleChange" button-style="solid">
|
||||
<a-radio-button v-for="item in $smartEnumPlugin.getValueDescList(props.enumName)" :key="item.value" :value="item.value">
|
||||
<a-radio-group v-model:value="selectValue" @change="handleChange" button-style="solid" :disabled="disabled">
|
||||
<a-radio-button v-for="item in valueDescList" :key="item.value" :value="item.value" :disabled="disabledOption.includes(item.value)">
|
||||
{{ item.desc }}
|
||||
</a-radio-button>
|
||||
</a-radio-group>
|
||||
</template>
|
||||
<template v-else>
|
||||
<a-radio-group v-model:value="selectValue" @change="handleChange">
|
||||
<a-radio v-for="item in $smartEnumPlugin.getValueDescList(props.enumName)" :key="item.value" :value="item.value">
|
||||
<a-radio-group v-model:value="selectValue" @change="handleChange" :disabled="disabled">
|
||||
<a-radio v-for="item in valueDescList" :key="item.value" :value="item.value" :disabled="disabledOption.includes(item.value)">
|
||||
{{ item.desc }}
|
||||
</a-radio>
|
||||
</a-radio-group>
|
||||
@ -26,7 +26,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { ref, watch, onMounted, getCurrentInstance } from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
enumName: String,
|
||||
@ -43,17 +43,42 @@
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 禁用整个单选框
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 需要禁用的选项枚举值
|
||||
disabledOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
// 需要隐藏的选项枚举值
|
||||
hiddenOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
const valueDescList = ref([]);
|
||||
|
||||
const selectValue = ref(props.value);
|
||||
|
||||
onMounted(() => {
|
||||
const internalInstance = getCurrentInstance(); // 有效 全局
|
||||
const smartEnumPlugin = internalInstance.appContext.config.globalProperties.$smartEnumPlugin;
|
||||
valueDescList.value = smartEnumPlugin.getValueDescList(props.enumName).filter((item) => !props.hiddenOption.includes(item.value));
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
|
||||
const selectValue = ref(props.value);
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(newValue) => {
|
||||
selectValue.value = newValue;
|
||||
}
|
||||
// 如果传入的值是被禁用或被隐藏的选项,则移除该选项
|
||||
selectValue.value = props.disabledOption.includes(newValue) || props.hiddenOption.includes(newValue) ? undefined : newValue;
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
function handleChange(e) {
|
||||
|
@ -19,18 +19,18 @@
|
||||
@change="handleChange"
|
||||
:disabled="disabled"
|
||||
>
|
||||
<a-select-option v-for="item in $smartEnumPlugin.getValueDescList(props.enumName)" :key="item.value" :value="item.value">
|
||||
<a-select-option v-for="item in valueDescList" :key="item.value" :value="item.value" :disabled="disabledOption.includes(item.value)">
|
||||
{{ item.desc }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, watch } from 'vue';
|
||||
import { ref, watch, onMounted, getCurrentInstance} from 'vue';
|
||||
|
||||
const props = defineProps({
|
||||
enumName: String,
|
||||
value: [Number,String],
|
||||
value: [Number, String],
|
||||
width: {
|
||||
type: String,
|
||||
default: '100%',
|
||||
@ -43,21 +43,42 @@
|
||||
type: String,
|
||||
default: 'default',
|
||||
},
|
||||
// 禁用整个下拉选择框
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 需要禁用的选项枚举值
|
||||
disabledOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
// 需要隐藏的选项枚举值
|
||||
hiddenOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
const valueDescList = ref([]);
|
||||
|
||||
const selectValue = ref(props.value);
|
||||
|
||||
onMounted(() => {
|
||||
const internalInstance = getCurrentInstance(); // 有效 全局
|
||||
const smartEnumPlugin = internalInstance.appContext.config.globalProperties.$smartEnumPlugin;
|
||||
valueDescList.value = smartEnumPlugin.getValueDescList(props.enumName).filter((item) => !props.hiddenOption.includes(item.value));
|
||||
});
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
|
||||
const selectValue = ref(props.value);
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(newValue) => {
|
||||
selectValue.value = newValue;
|
||||
}
|
||||
// 如果传入的值是被禁用或被隐藏的选项,则移除该选项
|
||||
selectValue.value = props.disabledOption.includes(newValue) || props.hiddenOption.includes(newValue) ? undefined : newValue;
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
function handleChange(value) {
|
||||
|
@ -18,6 +18,7 @@
|
||||
:allowClear="true"
|
||||
:size="size"
|
||||
@change="onChange"
|
||||
:disabled="disabled"
|
||||
>
|
||||
<a-select-option v-for="item in dictKeyCodeList" :key="item.keyCode" :value="item.keyCode">
|
||||
{{ item.keyName }}
|
||||
@ -27,7 +28,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch, defineExpose } from 'vue';
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { dictApi } from '/@/api/support/dict-api';
|
||||
|
||||
defineExpose({
|
||||
@ -49,7 +50,7 @@
|
||||
default: 'default',
|
||||
},
|
||||
// 禁用标识
|
||||
disabledFlag: {
|
||||
disabled: {
|
||||
type: Number,
|
||||
default: null,
|
||||
},
|
||||
|
@ -20,7 +20,7 @@
|
||||
@change="onChange"
|
||||
:disabled="disabled"
|
||||
>
|
||||
<a-select-option v-for="item in dictValueList" :key="item.valueCode" :value="item.valueCode">
|
||||
<a-select-option v-for="item in dictValueList" :key="item.valueCode" :value="item.valueCode" :disabled="disabledOption.includes(item.valueCode)">
|
||||
{{ item.valueName }}
|
||||
</a-select-option>
|
||||
</a-select>
|
||||
@ -28,7 +28,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref, watch } from 'vue';
|
||||
import { onMounted, ref, watch } from 'vue';
|
||||
import { dictApi } from '/@/api/support/dict-api';
|
||||
|
||||
const props = defineProps({
|
||||
@ -50,10 +50,21 @@
|
||||
type: String,
|
||||
default: 'default',
|
||||
},
|
||||
// 禁用整个下拉选择框
|
||||
disabled: {
|
||||
type: Boolean,
|
||||
default: false,
|
||||
},
|
||||
// 需要禁用的选项字典值编码
|
||||
disabledOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
// 需要隐藏的选项字典值编码
|
||||
hiddenOption: {
|
||||
type: Array,
|
||||
default: () => [],
|
||||
},
|
||||
});
|
||||
|
||||
// -------------------------- 查询 字典数据 --------------------------
|
||||
@ -61,7 +72,7 @@
|
||||
const dictValueList = ref([]);
|
||||
async function queryDict() {
|
||||
let res = await dictApi.valueList(props.keyCode);
|
||||
dictValueList.value = res.data;
|
||||
dictValueList.value = res.data.filter((item) => !props.hiddenOption.includes(item.valueCode));
|
||||
}
|
||||
|
||||
onMounted(queryDict);
|
||||
@ -69,14 +80,22 @@
|
||||
// -------------------------- 选中 相关、事件 --------------------------
|
||||
|
||||
const selectValue = ref(props.value);
|
||||
|
||||
watch(
|
||||
() => props.value,
|
||||
(value) => {
|
||||
selectValue.value = value;
|
||||
}
|
||||
(newValue) => {
|
||||
// 如果传入的值是被禁用或被隐藏的选项,则移除这些选项
|
||||
if (Array.isArray(newValue)) {
|
||||
selectValue.value = newValue.filter((item) => !props.disabledOption.includes(item) && !props.hiddenOption.includes(item));
|
||||
} else {
|
||||
selectValue.value = props.hiddenOption.includes(newValue) || props.disabledOption.includes(newValue) ? undefined : newValue;
|
||||
}
|
||||
},
|
||||
{ immediate: true }
|
||||
);
|
||||
|
||||
const emit = defineEmits(['update:value', 'change']);
|
||||
|
||||
function onChange(value) {
|
||||
if (!value) {
|
||||
emit('update:value', []);
|
||||
@ -87,8 +106,8 @@
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
} else {
|
||||
emit('update:value', value);
|
||||
emit('change', value);
|
||||
emit('update:value', [value]);
|
||||
emit('change', [value]);
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user