mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 10:18:42 +08:00 
			
		
		
		
	feat: 字典标签 自定义颜色
This commit is contained in:
		| @@ -17,6 +17,9 @@ const getDictObj = (dictType: string, value: string) => { | ||||
|   const dictOptions = getDictOptions(dictType) | ||||
|   dictOptions.forEach((dict: DictDataType) => { | ||||
|     if (dict.value === value) { | ||||
|       if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') { | ||||
|         dict.colorType = '' | ||||
|       } | ||||
|       dictData.value = dict | ||||
|     } | ||||
|   }) | ||||
| @@ -31,25 +34,11 @@ onUpdated(() => { | ||||
| }) | ||||
| </script> | ||||
| <template> | ||||
|   <!-- 默认样式 --> | ||||
|   <span | ||||
|     v-if=" | ||||
|       dictData?.colorType === 'default' || | ||||
|       dictData?.colorType === '' || | ||||
|       dictData?.colorType === undefined | ||||
|     " | ||||
|     :key="dictData?.value.toString()" | ||||
|     :class="dictData?.cssClass" | ||||
|   > | ||||
|     {{ dictData?.label }} | ||||
|   </span> | ||||
|   <!-- Tag 样式 --> | ||||
|   <ElTag | ||||
|     v-else | ||||
|     :disable-transitions="true" | ||||
|     :key="dictData?.value + ''" | ||||
|     :type="dictData?.colorType === 'primary' ? 'success' : dictData?.colorType" | ||||
|     :class="dictData?.cssClass" | ||||
|     :type="dictData?.colorType" | ||||
|     :color="dictData?.cssClass" | ||||
|   > | ||||
|     {{ dictData?.label }} | ||||
|   </ElTag> | ||||
|   | ||||
| @@ -65,6 +65,29 @@ export const useDictStore = defineStore('dict', { | ||||
|         this.isSetDict = true | ||||
|         wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期 | ||||
|       } | ||||
|     }, | ||||
|     async resetDict() { | ||||
|       wsCache.delete(CACHE_KEY.DICT_CACHE) | ||||
|       const res = await listSimpleDictDataApi() | ||||
|       // 设置数据 | ||||
|       const dictDataMap = new Map<string, any>() | ||||
|       res.forEach((dictData: DictDataVO) => { | ||||
|         // 获得 dictType 层级 | ||||
|         const enumValueObj = dictDataMap[dictData.dictType] | ||||
|         if (!enumValueObj) { | ||||
|           dictDataMap[dictData.dictType] = [] | ||||
|         } | ||||
|         // 处理 dictValue 层级 | ||||
|         dictDataMap[dictData.dictType].push({ | ||||
|           value: dictData.value, | ||||
|           label: dictData.label, | ||||
|           colorType: dictData.colorType, | ||||
|           cssClass: dictData.cssClass | ||||
|         }) | ||||
|       }) | ||||
|       this.dictMap = dictDataMap | ||||
|       this.isSetDict = true | ||||
|       wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期 | ||||
|     } | ||||
|   } | ||||
| }) | ||||
|   | ||||
| @@ -16,7 +16,7 @@ export interface DictDataType { | ||||
|   dictType: string | ||||
|   label: string | ||||
|   value: string | number | boolean | ||||
|   colorType: ElementPlusInfoType | '' | 'default' | 'primary' | ||||
|   colorType: ElementPlusInfoType | '' | ||||
|   cssClass: string | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -7,7 +7,7 @@ import { VxeCrudSchema, useVxeCrudSchemas } from '@/hooks/web/useVxeCrudSchemas' | ||||
| const { t } = useI18n() | ||||
| // 表单校验 | ||||
| export const dictDataRules = reactive({ | ||||
|   title: [required], | ||||
|   label: [required], | ||||
|   value: [required], | ||||
|   sort: [required] | ||||
| }) | ||||
| @@ -35,7 +35,7 @@ export const crudSchemas = reactive<VxeCrudSchema>({ | ||||
|       field: 'value' | ||||
|     }, | ||||
|     { | ||||
|       title: '颜色类型', | ||||
|       title: '标签类型', | ||||
|       field: 'colorType', | ||||
|       form: { | ||||
|         component: 'Select', | ||||
| @@ -67,9 +67,12 @@ export const crudSchemas = reactive<VxeCrudSchema>({ | ||||
|       isTable: false | ||||
|     }, | ||||
|     { | ||||
|       title: 'CSS Class', | ||||
|       title: '颜色', | ||||
|       field: 'cssClass', | ||||
|       isTable: false | ||||
|       isTable: false, | ||||
|       form: { | ||||
|         component: 'ColorPicker' | ||||
|       } | ||||
|     }, | ||||
|     { | ||||
|       title: '显示排序', | ||||
|   | ||||
| @@ -7,7 +7,8 @@ const { t } = useI18n() // 国际化 | ||||
|  | ||||
| // 表单校验 | ||||
| export const dictTypeRules = reactive({ | ||||
|   name: [required] | ||||
|   name: [required], | ||||
|   type: [required] | ||||
| }) | ||||
| // 新增 + 修改 | ||||
| const crudSchemas = reactive<VxeCrudSchema>({ | ||||
| @@ -41,9 +42,7 @@ const crudSchemas = reactive<VxeCrudSchema>({ | ||||
|       field: 'createTime', | ||||
|       formatter: 'formatDate', | ||||
|       isForm: false, | ||||
|       table: { | ||||
|         width: 150 | ||||
|       }, | ||||
|       isTable: false, | ||||
|       search: { | ||||
|         show: true, | ||||
|         itemRender: { | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 xingyu
					xingyu