feat: naive dict

pull/99/head^2
xingyu4j 2025-05-09 13:52:50 +08:00
parent c19c6a7faf
commit 0e326a1e57
2 changed files with 74 additions and 0 deletions

View File

@ -0,0 +1,73 @@
<script setup lang="ts">
// TODO color
import { computed } from 'vue';
import { NTag } from 'naive-ui';
// 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 {
/**
* 字典类型
*/
type: string;
/**
* 字典值
*/
value: any;
/**
* 图标
*/
icon?: string;
}
const props = defineProps<DictTagProps>();
/** 获取字典标签 */
const dictTag = computed(() => {
//
if (!props.type || props.value === undefined || props.value === null) {
return null;
}
//
const dict = getDictObj(props.type, String(props.value));
if (!dict) {
return null;
}
//
let colorType = dict.colorType;
switch (colorType) {
case 'danger': {
colorType = 'error';
break;
}
case 'info': {
colorType = 'default';
break;
}
case 'primary': {
colorType = 'processing';
break;
}
default: {
if (!colorType) {
colorType = 'default';
}
}
}
return {
label: dict.label || '',
colorType,
};
});
</script>
<template>
<NTag v-if="dictTag">
{{ dictTag.label }}
</NTag>
</template>

View File

@ -0,0 +1 @@
export { default as DictTag } from './dict-tag.vue';