feat: dict tag

pull/1/MERGE
xingyuv 2023-03-20 16:42:02 +08:00
parent 9481c5f309
commit 70dda58448
2 changed files with 17 additions and 4 deletions

View File

@ -2,7 +2,7 @@
import { defineComponent, PropType, ref } from 'vue' import { defineComponent, PropType, ref } from 'vue'
import { isHexColor } from '@/utils/color' import { isHexColor } from '@/utils/color'
import { Tag } from 'ant-design-vue' import { Tag } from 'ant-design-vue'
import { DictDataType, getDictOptions } from '@/utils/dict' import { DictDataType, getBoolDictOptions, getDictOptions, getStrDictOptions } from '@/utils/dict'
export default defineComponent({ export default defineComponent({
name: 'DictTag', name: 'DictTag',
@ -14,12 +14,24 @@ export default defineComponent({
value: { value: {
type: [String, Number, Boolean] as PropType<string | number | boolean>, type: [String, Number, Boolean] as PropType<string | number | boolean>,
required: true required: true
},
dictType: {
type: String as PropType<string>,
required: false,
default: () => 'number'
} }
}, },
setup(props) { setup(props) {
const dictData = ref<DictDataType>() const dictData = ref<DictDataType>()
const getDictObj = (dictType: string, value: string) => { 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) => { dictOptions.forEach((dict: DictDataType) => {
if (dict.value === value) { if (dict.value === value) {
if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') { if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') {

View File

@ -28,11 +28,12 @@ export const useRender = {
return dayjs(text).format(format) return dayjs(text).format(format)
} }
}, },
renderDict: (text, type) => { renderDict: (text, type, dictType?) => {
if (type) { if (type) {
return h(DictTag, { return h(DictTag, {
type: type, type: type,
value: text value: text,
dictType: dictType || 'number'
}) })
} }
} }