diff --git a/src/components/DictTag/src/DictTag.vue b/src/components/DictTag/src/DictTag.vue index 01bc6df3..81e1a9fb 100644 --- a/src/components/DictTag/src/DictTag.vue +++ b/src/components/DictTag/src/DictTag.vue @@ -2,7 +2,7 @@ import { defineComponent, PropType, ref } from 'vue' import { isHexColor } from '@/utils/color' import { Tag } from 'ant-design-vue' -import { DictDataType, getDictOptions } from '@/utils/dict' +import { DictDataType, getBoolDictOptions, getDictOptions, getStrDictOptions } from '@/utils/dict' export default defineComponent({ name: 'DictTag', @@ -14,12 +14,24 @@ export default defineComponent({ value: { type: [String, Number, Boolean] as PropType, required: true + }, + dictType: { + type: String as PropType, + required: false, + default: () => 'number' } }, setup(props) { const dictData = ref() const getDictObj = (dictType: string, value: string) => { - const dictOptions = getDictOptions(dictType) + let dictOptions: DictDataType[] = [] + if (props.dictType && props.dictType === 'boolean') { + dictOptions = getBoolDictOptions(dictType) + } else if (props.dictType && props.dictType === 'string') { + dictOptions = getStrDictOptions(dictType) + } else { + dictOptions = getDictOptions(dictType) + } dictOptions.forEach((dict: DictDataType) => { if (dict.value === value) { if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') { diff --git a/src/components/Table/src/hooks/useRender.ts b/src/components/Table/src/hooks/useRender.ts index 2d7b9d52..c4fdc8c5 100644 --- a/src/components/Table/src/hooks/useRender.ts +++ b/src/components/Table/src/hooks/useRender.ts @@ -28,11 +28,12 @@ export const useRender = { return dayjs(text).format(format) } }, - renderDict: (text, type) => { + renderDict: (text, type, dictType?) => { if (type) { return h(DictTag, { type: type, - value: text + value: text, + dictType: dictType || 'number' }) } }