Commit 986d1328e0a0d37e2de2fb9d937faeed9d9bee7b

Authored by YunaiV
1 parent 4a8129bf

v3.6.0 增加字典标签样式回显

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 { @@ -38,6 +38,11 @@ public class DictDataBaseVO {
38 // @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") 38 // @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}")
39 private Integer status; 39 private Integer status;
40 40
  41 + @ApiModelProperty(value = "颜色类型", example = "default", notes = "default、primary、success、info、warning、danger")
  42 + private String colorType;
  43 + @ApiModelProperty(value = "css 样式", example = "btn-visible")
  44 + private String cssClass;
  45 +
41 @ApiModelProperty(value = "备注", example = "我是一个角色") 46 @ApiModelProperty(value = "备注", example = "我是一个角色")
42 private String remark; 47 private String remark;
43 48
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 { @@ -17,4 +17,9 @@ public class DictDataSimpleRespVO {
17 @ApiModelProperty(value = "字典标签", required = true, example = "男") 17 @ApiModelProperty(value = "字典标签", required = true, example = "男")
18 private String label; 18 private String label;
19 19
  20 + @ApiModelProperty(value = "颜色类型", example = "default", notes = "default、primary、success、info、warning、danger")
  21 + private String colorType;
  22 + @ApiModelProperty(value = "css 样式", example = "btn-visible")
  23 + private String cssClass;
  24 +
20 } 25 }
yudao-module-system/yudao-module-system-impl/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/dict/DictDataDO.java
@@ -47,6 +47,16 @@ public class DictDataDO extends BaseDO { @@ -47,6 +47,16 @@ public class DictDataDO extends BaseDO {
47 */ 47 */
48 private Integer status; 48 private Integer status;
49 /** 49 /**
  50 + * 颜色类型
  51 + *
  52 + * 对应到 element-ui 为 default、primary、success、info、warning、danger
  53 + */
  54 + private String colorType;
  55 + /**
  56 + * css 样式
  57 + */
  58 + private String cssClass;
  59 + /**
50 * 备注 60 * 备注
51 */ 61 */
52 private String remark; 62 private String remark;
yudao-ui-admin/src/components/DictTag/index.vue 0 → 100644
  1 +<template>
  2 + <div>
  3 + <template v-for="(dict, index) in this.getDictDatas2(type, value)">
  4 + <!-- 默认样式 -->
  5 + <span v-if="dict.colorType === 'default' || dict.colorType === '' || dict.color === undefined" :key="dict.value" :index="index"
  6 + :class="dict.cssClass">{{ dict.label }}</span>
  7 + <!-- Tag 样式 -->
  8 + <el-tag v-else :key="dict.value" :index="index" :type="dict.colorType" :class="dict.cssClass">
  9 + {{ dict.label }}
  10 + </el-tag>
  11 + </template>
  12 + </div>
  13 +</template>
  14 +
  15 +<script>
  16 +export default {
  17 + name: "DictTag",
  18 + props: {
  19 + type: String,
  20 + value: [Number, String, Array],
  21 + },
  22 +};
  23 +</script>
  24 +<style scoped>
  25 +.el-tag + .el-tag {
  26 + margin-left: 10px;
  27 +}
  28 +</style>
yudao-ui-admin/src/main.js
@@ -36,7 +36,7 @@ import RightToolbar from &quot;@/components/RightToolbar&quot; @@ -36,7 +36,7 @@ import RightToolbar from &quot;@/components/RightToolbar&quot;
36 // 代码高亮插件 36 // 代码高亮插件
37 // import hljs from 'highlight.js' 37 // import hljs from 'highlight.js'
38 // import 'highlight.js/styles/github-gist.css' 38 // import 'highlight.js/styles/github-gist.css'
39 -import {DICT_TYPE, getDictDataLabel, getDictDatas} from "@/utils/dict"; 39 +import {DICT_TYPE, getDictDataLabel, getDictDatas, getDictDatas2} from "@/utils/dict";
40 40
41 // 全局方法挂载 41 // 全局方法挂载
42 Vue.prototype.getDicts = getDicts 42 Vue.prototype.getDicts = getDicts
@@ -47,6 +47,7 @@ Vue.prototype.addDateRange = addDateRange @@ -47,6 +47,7 @@ Vue.prototype.addDateRange = addDateRange
47 Vue.prototype.addBeginAndEndTime = addBeginAndEndTime 47 Vue.prototype.addBeginAndEndTime = addBeginAndEndTime
48 Vue.prototype.selectDictLabel = selectDictLabel 48 Vue.prototype.selectDictLabel = selectDictLabel
49 Vue.prototype.getDictDatas = getDictDatas 49 Vue.prototype.getDictDatas = getDictDatas
  50 +Vue.prototype.getDictDatas2 = getDictDatas2
50 Vue.prototype.getDictDataLabel = getDictDataLabel 51 Vue.prototype.getDictDataLabel = getDictDataLabel
51 Vue.prototype.DICT_TYPE = DICT_TYPE 52 Vue.prototype.DICT_TYPE = DICT_TYPE
52 Vue.prototype.download = download 53 Vue.prototype.download = download
@@ -70,8 +71,11 @@ Vue.prototype.msgInfo = function (msg) { @@ -70,8 +71,11 @@ Vue.prototype.msgInfo = function (msg) {
70 } 71 }
71 72
72 // 全局组件挂载 73 // 全局组件挂载
  74 +Vue.component('DictTag', DictTag)
73 Vue.component('Pagination', Pagination) 75 Vue.component('Pagination', Pagination)
74 Vue.component('RightToolbar', RightToolbar) 76 Vue.component('RightToolbar', RightToolbar)
  77 +// 字典标签组件
  78 +import DictTag from '@/components/DictTag'
75 // 头部标签插件 79 // 头部标签插件
76 import VueMeta from 'vue-meta' 80 import VueMeta from 'vue-meta'
77 81
yudao-ui-admin/src/utils/dict.js
@@ -68,10 +68,37 @@ export function getDictDatas(dictType) { @@ -68,10 +68,37 @@ export function getDictDatas(dictType) {
68 // console.log(store.getters.dict_datas[dictType]); 68 // console.log(store.getters.dict_datas[dictType]);
69 // debugger 69 // debugger
70 // } 70 // }
  71 + // debugger
71 return store.getters.dict_datas[dictType] || [] 72 return store.getters.dict_datas[dictType] || []
72 } 73 }
73 74
74 -export function getDictDataLabel(dictType, value) { 75 +/**
  76 + * 获取 dictType 对应的数据字典数组
  77 + *
  78 + * @param dictType 数据类型
  79 + * @param values 数组、单个元素
  80 + * @returns {*|Array} 数据字典数组
  81 + */
  82 +export function getDictDatas2(dictType, values) {
  83 + if (values === undefined) {
  84 + return [];
  85 + }
  86 + // 如果是单个元素,则转换成数组
  87 + if (!Array.isArray(values)) {
  88 + values = [this.value];
  89 + }
  90 + // 获得字典数据
  91 + const results = [];
  92 + for (const value of values) {
  93 + const dict = getDictData(dictType, value);
  94 + if (dict) {
  95 + results.push(dict);
  96 + }
  97 + }
  98 + return results;
  99 +}
  100 +
  101 +export function getDictData(dictType, value) {
75 // 获取 dictType 对应的数据字典数组 102 // 获取 dictType 对应的数据字典数组
76 const dictDatas = getDictDatas(dictType) 103 const dictDatas = getDictDatas(dictType)
77 if (!dictDatas || dictDatas.length === 0) { 104 if (!dictDatas || dictDatas.length === 0) {
@@ -81,8 +108,14 @@ export function getDictDataLabel(dictType, value) { @@ -81,8 +108,14 @@ export function getDictDataLabel(dictType, value) {
81 value = value + '' // 强制转换成字符串,因为 DictData 小类数值,是字符串 108 value = value + '' // 强制转换成字符串,因为 DictData 小类数值,是字符串
82 for (const dictData of dictDatas) { 109 for (const dictData of dictDatas) {
83 if (dictData.value === value) { 110 if (dictData.value === value) {
84 - return dictData.label 111 + return dictData;
85 } 112 }
86 } 113 }
87 - return '' 114 + return undefined
88 } 115 }
  116 +
  117 +export function getDictDataLabel(dictType, value) {
  118 + const dict = getDictData(dictType, value);
  119 + return dict ? dict.label : '';
  120 +}
  121 +
yudao-ui-admin/src/views/system/dict/data.vue
@@ -37,7 +37,13 @@ @@ -37,7 +37,13 @@
37 <el-table-column label="字典标签" align="center" prop="label" /> 37 <el-table-column label="字典标签" align="center" prop="label" />
38 <el-table-column label="字典键值" align="center" prop="value" /> 38 <el-table-column label="字典键值" align="center" prop="value" />
39 <el-table-column label="字典排序" align="center" prop="sort" /> 39 <el-table-column label="字典排序" align="center" prop="sort" />
40 - <el-table-column label="状态" align="center" prop="status" :formatter="statusFormat" /> 40 + <el-table-column label="状态" align="center" prop="status">
  41 + <template slot-scope="scope">
  42 + <dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status"/>
  43 + </template>
  44 + </el-table-column>
  45 + <el-table-column label="颜色类型" align="center" prop="colorType" />
  46 + <el-table-column label="CSS Class" align="center" prop="cssClass" />
41 <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" /> 47 <el-table-column label="备注" align="center" prop="remark" :show-overflow-tooltip="true" />
42 <el-table-column label="创建时间" align="center" prop="createTime" width="180"> 48 <el-table-column label="创建时间" align="center" prop="createTime" width="180">
43 <template slot-scope="scope"> 49 <template slot-scope="scope">
@@ -59,7 +65,7 @@ @@ -59,7 +65,7 @@
59 65
60 <!-- 添加或修改参数配置对话框 --> 66 <!-- 添加或修改参数配置对话框 -->
61 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body> 67 <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
62 - <el-form ref="form" :model="form" :rules="rules" label-width="80px"> 68 + <el-form ref="form" :model="form" :rules="rules" label-width="90px">
63 <el-form-item label="字典类型"> 69 <el-form-item label="字典类型">
64 <el-input v-model="form.dictType" :disabled="true" /> 70 <el-input v-model="form.dictType" :disabled="true" />
65 </el-form-item> 71 </el-form-item>
@@ -77,6 +83,14 @@ @@ -77,6 +83,14 @@
77 <el-radio v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="parseInt(dict.value)">{{dict.label}}</el-radio> 83 <el-radio v-for="dict in statusDictDatas" :key="parseInt(dict.value)" :label="parseInt(dict.value)">{{dict.label}}</el-radio>
78 </el-radio-group> 84 </el-radio-group>
79 </el-form-item> 85 </el-form-item>
  86 + <el-form-item label="颜色类型" prop="colorType">
  87 + <el-select v-model="form.colorType">
  88 + <el-option v-for="item in colorTypeOptions" :key="item.value" :label="item.label + '(' + item.value + ')'" :value="item.value" />
  89 + </el-select>
  90 + </el-form-item>
  91 + <el-form-item label="CSS Class" prop="cssClass">
  92 + <el-input v-model="form.cssClass" placeholder="请输入 CSS Class" />
  93 + </el-form-item>
80 <el-form-item label="备注" prop="remark"> 94 <el-form-item label="备注" prop="remark">
81 <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input> 95 <el-input v-model="form.remark" type="textarea" placeholder="请输入内容"></el-input>
82 </el-form-item> 96 </el-form-item>
@@ -142,6 +156,27 @@ export default { @@ -142,6 +156,27 @@ export default {
142 { required: true, message: "数据顺序不能为空", trigger: "blur" } 156 { required: true, message: "数据顺序不能为空", trigger: "blur" }
143 ] 157 ]
144 }, 158 },
  159 + // 数据标签回显样式
  160 + colorTypeOptions: [{
  161 + value: "default",
  162 + label: "默认"
  163 + }, {
  164 + value: "primary",
  165 + label: "主要"
  166 + }, {
  167 + value: "success",
  168 + label: "成功"
  169 + }, {
  170 + value: "info",
  171 + label: "信息"
  172 + }, {
  173 + value: "warning",
  174 + label: "警告"
  175 + }, {
  176 + value: "danger",
  177 + label: "危险"
  178 + }
  179 + ],
145 180
146 // 枚举 181 // 枚举
147 CommonStatusEnum: CommonStatusEnum, 182 CommonStatusEnum: CommonStatusEnum,
@@ -178,10 +213,6 @@ export default { @@ -178,10 +213,6 @@ export default {
178 this.loading = false; 213 this.loading = false;
179 }); 214 });
180 }, 215 },
181 - // 数据状态字典翻译  
182 - statusFormat(row, column) {  
183 - return getDictDataLabel(DICT_TYPE.COMMON_STATUS, row.status)  
184 - },  
185 // 取消按钮 216 // 取消按钮
186 cancel() { 217 cancel() {
187 this.open = false; 218 this.open = false;
@@ -195,6 +226,8 @@ export default { @@ -195,6 +226,8 @@ export default {
195 value: undefined, 226 value: undefined,
196 sort: 0, 227 sort: 0,
197 status: CommonStatusEnum.ENABLE, 228 status: CommonStatusEnum.ENABLE,
  229 + colorType: 'default',
  230 + cssClass: undefined,
198 remark: undefined 231 remark: undefined
199 }; 232 };
200 this.resetForm("form"); 233 this.resetForm("form");
更新日志.md
@@ -35,7 +35,7 @@ @@ -35,7 +35,7 @@
35 * 【新增】前端的表格右侧工具栏组件支持显隐列,具体可见【用户管理】功能 [commit](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/20e34e35a3bdc48e6a4c58e3849aa729bd18efe5) 35 * 【新增】前端的表格右侧工具栏组件支持显隐列,具体可见【用户管理】功能 [commit](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/20e34e35a3bdc48e6a4c58e3849aa729bd18efe5)
36 * 【新增】前端的菜单导航显示风格 TopNav(false 为 左侧导航菜单,true 为顶部导航菜单),支持布局的保存与重置 [commit1](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/4bf5b04d542014a49c5a41b20935cef35033a518) [commit2](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/cff4391f2d7830770731c0034085c0f77ea8c68e) 36 * 【新增】前端的菜单导航显示风格 TopNav(false 为 左侧导航菜单,true 为顶部导航菜单),支持布局的保存与重置 [commit1](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/4bf5b04d542014a49c5a41b20935cef35033a518) [commit2](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/cff4391f2d7830770731c0034085c0f77ea8c68e)
37 * 【新增】前端的网页标题支持根据选择的菜单,动态展示标题 [commit](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/7bf9a85263e0c44b2bc88485b83557c129583f5c) 37 * 【新增】前端的网页标题支持根据选择的菜单,动态展示标题 [commit](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/7bf9a85263e0c44b2bc88485b83557c129583f5c)
38 -* 【新增】前端的 iframe 组件,方便内嵌网页 [commit]() 38 +* 【新增】前端的 iframe 组件,方便内嵌网页 [commit](https://gitee.com/zhijiantianya/ruoyi-vue-pro/commit/4a8129bffa9e3928c56333e29f5874f55a079764)
39 39
40 ### 🐞 Bug Fixes 40 ### 🐞 Bug Fixes
41 41