feat: dict support cssClass

pull/153/head
xingyu4j 2025-06-21 14:39:50 +08:00
parent 9283d58ce9
commit d2e4a26c84
1 changed files with 7 additions and 13 deletions

View File

@ -1,9 +1,10 @@
<script setup lang="ts">
import { computed } from 'vue';
import { isValidColor, TinyColor } from '@vben/utils';
import { Tag } from 'ant-design-vue';
// 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';
interface DictTagProps {
@ -23,11 +24,6 @@ interface DictTagProps {
const props = defineProps<DictTagProps>();
function isHexColor(color: string) {
const reg = /^#(?:[0-9a-f]{3}|[0-9a-f]{6})$/i;
return reg.test(color);
}
/** 获取字典标签 */
const dictTag = computed(() => {
//
@ -63,6 +59,10 @@ const dictTag = computed(() => {
}
}
if (isValidColor(dict.cssClass)) {
colorType = new TinyColor(dict.cssClass).toHexString();
}
return {
label: dict.label || '',
colorType,
@ -74,13 +74,7 @@ const dictTag = computed(() => {
<template>
<Tag
v-if="dictTag"
:color="
dictTag.colorType
? dictTag.colorType
: dictTag.cssClass && isHexColor(dictTag.cssClass)
? dictTag.cssClass
: ''
"
:color="dictTag.colorType ? dictTag.colorType : dictTag.cssClass"
>
{{ dictTag.label }}
</Tag>