refactor: ♻️ 字典重构,系统权限模块优化

This commit is contained in:
hxr
2024-06-24 08:21:46 +08:00
parent 239989f4aa
commit d5dfcb978e
43 changed files with 1243 additions and 1821 deletions

View File

@@ -20,9 +20,9 @@ import DictAPI from "@/api/dict";
const props = defineProps({
/**
* 字典类型编码(eg: 性别-gender)
* 字典编码(eg: 性别-gender)
*/
typeCode: {
code: {
type: String,
required: true,
},
@@ -39,14 +39,17 @@ const props = defineProps({
},
});
const emits = defineEmits(["update:modelValue"]); // 父组件监听事件,同步子组件值的变化给父组件
const emits = defineEmits(["update:modelValue"]);
const options: Ref<OptionType[]> = ref([]); // 字典下拉数据源
const options: Ref<OptionType[]> = ref([]);
const selectedValue = ref<string | number | undefined>();
watch([options, () => props.modelValue], ([newOptions, newModelValue]) => {
if (newOptions.length === 0) return; // 下拉数据源加载未完成不回显
if (newOptions.length === 0) {
// 下拉数据源加载未完成不回显
return;
}
if (newModelValue == undefined) {
selectedValue.value = undefined;
return;
@@ -65,8 +68,8 @@ function handleChange(val?: string | number | undefined) {
}
onBeforeMount(() => {
// 根据字典类型编码(typeCode)获取字典
DictAPI.getDictOptions(props.typeCode).then((data) => {
// 根据字典编码获取字典项
DictAPI.getOptions(props.code).then((data) => {
options.value = data;
});
});