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