diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataBaseVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataBaseVO.java index 2cefd83cb..b3e14e8b4 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataBaseVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataBaseVO.java @@ -38,6 +38,11 @@ public class DictDataBaseVO { // @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") private Integer status; + @ApiModelProperty(value = "颜色类型", example = "default", notes = "default、primary、success、info、warning、danger") + private String colorType; + @ApiModelProperty(value = "css 样式", example = "btn-visible") + private String cssClass; + @ApiModelProperty(value = "备注", example = "我是一个角色") private String remark; diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataSimpleRespVO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataSimpleRespVO.java index c3dd56052..4ea0c5f9b 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataSimpleRespVO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/controller/admin/dict/vo/data/DictDataSimpleRespVO.java @@ -17,4 +17,9 @@ public class DictDataSimpleRespVO { @ApiModelProperty(value = "字典标签", required = true, example = "男") private String label; + @ApiModelProperty(value = "颜色类型", example = "default", notes = "default、primary、success、info、warning、danger") + private String colorType; + @ApiModelProperty(value = "css 样式", example = "btn-visible") + private String cssClass; + } diff --git a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dict/DictDataDO.java b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dict/DictDataDO.java index 1b5cee4e4..787f2e98a 100644 --- a/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dict/DictDataDO.java +++ b/yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dict/DictDataDO.java @@ -46,6 +46,16 @@ public class DictDataDO extends BaseDO { * 枚举 {@link CommonStatusEnum} */ private Integer status; + /** + * 颜色类型 + * + * 对应到 element-ui 为 default、primary、success、info、warning、danger + */ + private String colorType; + /** + * css 样式 + */ + private String cssClass; /** * 备注 */ diff --git a/yudao-ui-admin/src/components/DictTag/index.vue b/yudao-ui-admin/src/components/DictTag/index.vue new file mode 100644 index 000000000..a63820ccf --- /dev/null +++ b/yudao-ui-admin/src/components/DictTag/index.vue @@ -0,0 +1,28 @@ + + + + diff --git a/yudao-ui-admin/src/main.js b/yudao-ui-admin/src/main.js index c36b83fce..f07b7d388 100644 --- a/yudao-ui-admin/src/main.js +++ b/yudao-ui-admin/src/main.js @@ -36,7 +36,7 @@ import RightToolbar from "@/components/RightToolbar" // 代码高亮插件 // import hljs from 'highlight.js' // import 'highlight.js/styles/github-gist.css' -import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict"; +import {DICT_TYPE, getDictDataLabel, getDictDatas, getDictDatas2} from "@/utils/dict"; // 全局方法挂载 Vue.prototype.getDicts = getDicts @@ -47,6 +47,7 @@ Vue.prototype.addDateRange = addDateRange Vue.prototype.addBeginAndEndTime = addBeginAndEndTime Vue.prototype.selectDictLabel = selectDictLabel Vue.prototype.getDictDatas = getDictDatas +Vue.prototype.getDictDatas2 = getDictDatas2 Vue.prototype.getDictDataLabel = getDictDataLabel Vue.prototype.DICT_TYPE = DICT_TYPE Vue.prototype.download = download @@ -70,8 +71,11 @@ Vue.prototype.msgInfo = function (msg) { } // 全局组件挂载 +Vue.component('DictTag', DictTag) Vue.component('Pagination', Pagination) Vue.component('RightToolbar', RightToolbar) +// 字典标签组件 +import DictTag from '@/components/DictTag' // 头部标签插件 import VueMeta from 'vue-meta' diff --git a/yudao-ui-admin/src/utils/dict.js b/yudao-ui-admin/src/utils/dict.js index 1c46aebe0..1bd72a695 100644 --- a/yudao-ui-admin/src/utils/dict.js +++ b/yudao-ui-admin/src/utils/dict.js @@ -68,10 +68,37 @@ export function getDictDatas(dictType) { // console.log(store.getters.dict_datas[dictType]); // debugger // } + // debugger return store.getters.dict_datas[dictType] || [] } -export function getDictDataLabel(dictType, value) { +/** + * 获取 dictType 对应的数据字典数组 + * + * @param dictType 数据类型 + * @param values 数组、单个元素 + * @returns {*|Array} 数据字典数组 + */ +export function getDictDatas2(dictType, values) { + if (values === undefined) { + return []; + } + // 如果是单个元素,则转换成数组 + if (!Array.isArray(values)) { + values = [this.value]; + } + // 获得字典数据 + const results = []; + for (const value of values) { + const dict = getDictData(dictType, value); + if (dict) { + results.push(dict); + } + } + return results; +} + +export function getDictData(dictType, value) { // 获取 dictType 对应的数据字典数组 const dictDatas = getDictDatas(dictType) if (!dictDatas || dictDatas.length === 0) { @@ -81,8 +108,14 @@ export function getDictDataLabel(dictType, value) { value = value + '' // 强制转换成字符串,因为 DictData 小类数值,是字符串 for (const dictData of dictDatas) { if (dictData.value === value) { - return dictData.label + return dictData; } } - return '' + return undefined } + +export function getDictDataLabel(dictType, value) { + const dict = getDictData(dictType, value); + return dict ? dict.label : ''; +} + diff --git a/yudao-ui-admin/src/views/system/dict/data.vue b/yudao-ui-admin/src/views/system/dict/data.vue index b4f30d178..f2562f0a9 100644 --- a/yudao-ui-admin/src/views/system/dict/data.vue +++ b/yudao-ui-admin/src/views/system/dict/data.vue @@ -37,7 +37,13 @@ - + + + + +