refactor: 破坏性更新 dict 抽离

This commit is contained in:
xingyu4j
2025-09-05 12:00:24 +08:00
parent b79bebab18
commit 5ef57590e0
112 changed files with 397 additions and 518 deletions

View File

@@ -1,10 +1,10 @@
<script setup lang="ts">
import { computed } from 'vue';
import { ElTag } from 'element-plus';
// import { isHexColor } from '@/utils/color' // TODO @芋艿:【可优化】增加 cssClass 的处理 https://gitee.com/yudaocode/yudao-ui-admin-vben/blob/v2.4.1/src/components/DictTag/src/DictTag.vue#L60
import { getDictObj } from '#/utils';
import { getDictObj } from '@vben/hooks';
import { ElTag } from 'element-plus';
interface DictTagProps {
/**

View File

@@ -4,6 +4,8 @@ import type { DictSelectProps } from '../typing';
import { computed, useAttrs } from 'vue';
import { getDictOptions } from '@vben/hooks';
import {
ElCheckbox,
ElCheckboxGroup,
@@ -13,8 +15,6 @@ import {
ElSelect,
} from 'element-plus';
import { getDictObj, getIntDictOptions, getStrDictOptions } from '#/utils';
defineOptions({ name: 'DictSelect' });
const props = withDefaults(defineProps<DictSelectProps>(), {
@@ -25,17 +25,16 @@ const props = withDefaults(defineProps<DictSelectProps>(), {
const attrs = useAttrs();
// 获得字典配置
// TODO @dhb可以使用 getDictOptions 替代么?
const getDictOptions = computed(() => {
const dictOptions = computed(() => {
switch (props.valueType) {
case 'bool': {
return getDictObj(props.dictType, 'bool');
return getDictOptions(props.dictType, 'boolean');
}
case 'int': {
return getIntDictOptions(props.dictType);
return getDictOptions(props.dictType);
}
case 'str': {
return getStrDictOptions(props.dictType);
return getDictOptions(props.dictType);
}
default: {
return [];
@@ -47,7 +46,7 @@ const getDictOptions = computed(() => {
<template>
<ElSelect v-if="selectType === 'select'" class="w-1/1" v-bind="attrs">
<ElOption
v-for="(dict, index) in getDictOptions"
v-for="(dict, index) in dictOptions"
:key="index"
:value="dict.value"
:label="dict.label"
@@ -55,7 +54,7 @@ const getDictOptions = computed(() => {
</ElSelect>
<ElRadioGroup v-if="selectType === 'radio'" class="w-1/1" v-bind="attrs">
<ElRadio
v-for="(dict, index) in getDictOptions"
v-for="(dict, index) in dictOptions"
:key="index"
:label="dict.value"
>
@@ -68,7 +67,7 @@ const getDictOptions = computed(() => {
v-bind="attrs"
>
<ElCheckbox
v-for="(dict, index) in getDictOptions"
v-for="(dict, index) in dictOptions"
:key="index"
:label="dict.value"
>