Commit 6e49b19952f00694729736153bc97f52c0ff2582

Authored by xingyu
1 parent cccf8d81

feat: 字典标签 自定义颜色

yudao-ui-admin-vue3/src/components/DictTag/src/DictTag.vue
... ... @@ -17,6 +17,9 @@ const getDictObj = (dictType: string, value: string) => {
17 17 const dictOptions = getDictOptions(dictType)
18 18 dictOptions.forEach((dict: DictDataType) => {
19 19 if (dict.value === value) {
  20 + if (dict.colorType + '' === 'primary' || dict.colorType + '' === 'default') {
  21 + dict.colorType = ''
  22 + }
20 23 dictData.value = dict
21 24 }
22 25 })
... ... @@ -31,25 +34,11 @@ onUpdated(() => {
31 34 })
32 35 </script>
33 36 <template>
34   - <!-- 默认样式 -->
35   - <span
36   - v-if="
37   - dictData?.colorType === 'default' ||
38   - dictData?.colorType === '' ||
39   - dictData?.colorType === undefined
40   - "
41   - :key="dictData?.value.toString()"
42   - :class="dictData?.cssClass"
43   - >
44   - {{ dictData?.label }}
45   - </span>
46   - <!-- Tag 样式 -->
47 37 <ElTag
48   - v-else
49 38 :disable-transitions="true"
50 39 :key="dictData?.value + ''"
51   - :type="dictData?.colorType === 'primary' ? 'success' : dictData?.colorType"
52   - :class="dictData?.cssClass"
  40 + :type="dictData?.colorType"
  41 + :color="dictData?.cssClass"
53 42 >
54 43 {{ dictData?.label }}
55 44 </ElTag>
... ...
yudao-ui-admin-vue3/src/store/modules/dict.ts
... ... @@ -65,6 +65,29 @@ export const useDictStore = defineStore(&#39;dict&#39;, {
65 65 this.isSetDict = true
66 66 wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期
67 67 }
  68 + },
  69 + async resetDict() {
  70 + wsCache.delete(CACHE_KEY.DICT_CACHE)
  71 + const res = await listSimpleDictDataApi()
  72 + // 设置数据
  73 + const dictDataMap = new Map<string, any>()
  74 + res.forEach((dictData: DictDataVO) => {
  75 + // 获得 dictType 层级
  76 + const enumValueObj = dictDataMap[dictData.dictType]
  77 + if (!enumValueObj) {
  78 + dictDataMap[dictData.dictType] = []
  79 + }
  80 + // 处理 dictValue 层级
  81 + dictDataMap[dictData.dictType].push({
  82 + value: dictData.value,
  83 + label: dictData.label,
  84 + colorType: dictData.colorType,
  85 + cssClass: dictData.cssClass
  86 + })
  87 + })
  88 + this.dictMap = dictDataMap
  89 + this.isSetDict = true
  90 + wsCache.set(CACHE_KEY.DICT_CACHE, dictDataMap, { exp: 60 }) // 60 秒 过期
68 91 }
69 92 }
70 93 })
... ...
yudao-ui-admin-vue3/src/utils/dict.ts
... ... @@ -16,7 +16,7 @@ export interface DictDataType {
16 16 dictType: string
17 17 label: string
18 18 value: string | number | boolean
19   - colorType: ElementPlusInfoType | '' | 'default' | 'primary'
  19 + colorType: ElementPlusInfoType | ''
20 20 cssClass: string
21 21 }
22 22  
... ...
yudao-ui-admin-vue3/src/views/system/dict/dict.data.ts
... ... @@ -7,7 +7,7 @@ import { VxeCrudSchema, useVxeCrudSchemas } from &#39;@/hooks/web/useVxeCrudSchemas&#39;
7 7 const { t } = useI18n()
8 8 // 表单校验
9 9 export const dictDataRules = reactive({
10   - title: [required],
  10 + label: [required],
11 11 value: [required],
12 12 sort: [required]
13 13 })
... ... @@ -35,7 +35,7 @@ export const crudSchemas = reactive&lt;VxeCrudSchema&gt;({
35 35 field: 'value'
36 36 },
37 37 {
38   - title: '颜色类型',
  38 + title: '标签类型',
39 39 field: 'colorType',
40 40 form: {
41 41 component: 'Select',
... ... @@ -67,9 +67,12 @@ export const crudSchemas = reactive&lt;VxeCrudSchema&gt;({
67 67 isTable: false
68 68 },
69 69 {
70   - title: 'CSS Class',
  70 + title: '颜色',
71 71 field: 'cssClass',
72   - isTable: false
  72 + isTable: false,
  73 + form: {
  74 + component: 'ColorPicker'
  75 + }
73 76 },
74 77 {
75 78 title: '显示排序',
... ...
yudao-ui-admin-vue3/src/views/system/dict/dict.type.ts
... ... @@ -7,7 +7,8 @@ const { t } = useI18n() // 国际化
7 7  
8 8 // 表单校验
9 9 export const dictTypeRules = reactive({
10   - name: [required]
  10 + name: [required],
  11 + type: [required]
11 12 })
12 13 // 新增 + 修改
13 14 const crudSchemas = reactive<VxeCrudSchema>({
... ... @@ -41,9 +42,7 @@ const crudSchemas = reactive&lt;VxeCrudSchema&gt;({
41 42 field: 'createTime',
42 43 formatter: 'formatDate',
43 44 isForm: false,
44   - table: {
45   - width: 150
46   - },
  45 + isTable: false,
47 46 search: {
48 47 show: true,
49 48 itemRender: {
... ...