From 12ab8b03d9acb77848c4db9bb0451e77af60acb6 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Fri, 17 Sep 2021 15:36:54 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8vue-data-dict=EF=BC=8C?= =?UTF-8?q?=E7=AE=80=E5=8C=96=E6=95=B0=E6=8D=AE=E5=AD=97=E5=85=B8=E4=BD=BF?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ruoyi/generator/util/VelocityUtils.java | 22 +++++ .../main/resources/vm/vue/index-tree.vue.vm | 55 +++++-------- .../src/main/resources/vm/vue/index.vue.vm | 55 +++++-------- ruoyi-ui/src/components/DictData/index.js | 21 +++++ ruoyi-ui/src/components/DictTag/index.vue | 20 ++--- ruoyi-ui/src/main.js | 3 + ruoyi-ui/src/utils/dict/Dict.js | 82 +++++++++++++++++++ ruoyi-ui/src/utils/dict/DictConverter.js | 17 ++++ ruoyi-ui/src/utils/dict/DictData.js | 13 +++ ruoyi-ui/src/utils/dict/DictMeta.js | 38 +++++++++ ruoyi-ui/src/utils/dict/DictOptions.js | 51 ++++++++++++ ruoyi-ui/src/utils/dict/index.js | 33 ++++++++ ruoyi-ui/src/utils/ruoyi.js | 20 ++++- ruoyi-ui/src/views/monitor/job/index.vue | 47 +++++------ ruoyi-ui/src/views/monitor/job/log.vue | 31 +++---- .../src/views/monitor/logininfor/index.vue | 16 ++-- ruoyi-ui/src/views/monitor/operlog/index.vue | 33 +++----- ruoyi-ui/src/views/system/config/index.vue | 24 +++--- ruoyi-ui/src/views/system/dept/index.vue | 24 +++--- ruoyi-ui/src/views/system/dict/data.vue | 24 +++--- ruoyi-ui/src/views/system/dict/index.vue | 24 +++--- ruoyi-ui/src/views/system/menu/index.vue | 37 ++++----- ruoyi-ui/src/views/system/notice/index.vue | 39 ++++----- ruoyi-ui/src/views/system/post/index.vue | 24 +++--- ruoyi-ui/src/views/system/role/authUser.vue | 8 +- ruoyi-ui/src/views/system/role/index.vue | 22 ++--- ruoyi-ui/src/views/system/role/selectUser.vue | 10 +-- ruoyi-ui/src/views/system/user/index.vue | 35 +++----- 28 files changed, 503 insertions(+), 325 deletions(-) create mode 100644 ruoyi-ui/src/components/DictData/index.js create mode 100644 ruoyi-ui/src/utils/dict/Dict.js create mode 100644 ruoyi-ui/src/utils/dict/DictConverter.js create mode 100644 ruoyi-ui/src/utils/dict/DictData.js create mode 100644 ruoyi-ui/src/utils/dict/DictMeta.js create mode 100644 ruoyi-ui/src/utils/dict/DictOptions.js create mode 100644 ruoyi-ui/src/utils/dict/index.js diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java index 6481057..2683ec8 100644 --- a/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java +++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java @@ -58,6 +58,7 @@ public class VelocityUtils velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); velocityContext.put("columns", genTable.getColumns()); velocityContext.put("table", genTable); + velocityContext.put("dicts", getDicts(genTable)); setMenuVelocityContext(velocityContext, genTable); if (GenConstants.TPL_TREE.equals(tplCategory)) { @@ -260,6 +261,27 @@ public class VelocityUtils return importList; } + /** + * 根据列类型获取字典组 + * + * @param genTable 业务表对象 + * @return 返回字典组 + */ + public static String getDicts(GenTable genTable) + { + List columns = genTable.getColumns(); + List dicts = new ArrayList(); + for (GenTableColumn column : columns) + { + if (!column.isSuperColumn() && StringUtils.isNotEmpty(column.getDictType()) && StringUtils.equalsAny( + column.getHtmlType(), new String[] { GenConstants.HTML_SELECT, GenConstants.HTML_RADIO })) + { + dicts.add("'" + column.getDictType() + "'"); + } + } + return StringUtils.join(dicts, ", "); + } + /** * 获取权限前缀 * diff --git a/ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm b/ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm index 51c447e..c2383c0 100644 --- a/ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm +++ b/ruoyi-generator/src/main/resources/vm/vue/index-tree.vue.vm @@ -25,10 +25,10 @@ @@ -108,7 +108,7 @@ #elseif($column.list && "" != $column.dictType) #elseif($column.list && "" != $javaField) @@ -184,10 +184,10 @@ @@ -202,10 +202,10 @@ - {{dict.dictLabel}} + v-for="dict in dict.type.${dictType}" + :key="dict.value" + :label="dict.value"> + {{dict.label}} @@ -219,11 +219,11 @@ {{dict.dictLabel}} + >{{dict.label}} #elseif($column.htmlType == "radio" && $dictType) @@ -265,6 +265,9 @@ import "@riophae/vue-treeselect/dist/vue-treeselect.css"; export default { name: "${BusinessName}", +#if(${dicts} != '') + dicts: [${dicts}], +#end components: { Treeselect }, @@ -283,16 +286,7 @@ export default { // 是否显示弹出层 open: false, #foreach ($column in $columns) -#set($parentheseIndex=$column.columnComment.indexOf("(")) -#if($parentheseIndex != -1) -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) -#else -#set($comment=$column.columnComment) -#end -#if(${column.dictType} != '') - // $comment字典 - ${column.javaField}Options: [], -#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN") +#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) // $comment时间范围 daterange${AttrName}: [], @@ -330,13 +324,6 @@ export default { }, created() { this.getList(); -#foreach ($column in $columns) -#if(${column.dictType} != '') - this.getDicts("${column.dictType}").then(response => { - this.${column.javaField}Options = response.data; - }); -#end -#end }, methods: { /** 查询${functionName}列表 */ diff --git a/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm b/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm index 0086559..67d72b1 100644 --- a/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm +++ b/ruoyi-generator/src/main/resources/vm/vue/index.vue.vm @@ -25,10 +25,10 @@ @@ -137,7 +137,7 @@ #elseif($column.list && "" != $column.dictType) #elseif($column.list && "" != $javaField) @@ -206,10 +206,10 @@ @@ -224,10 +224,10 @@ - {{dict.dictLabel}} + v-for="dict in dict.type.${dictType}" + :key="dict.value" + :label="dict.value"> + {{dict.label}} @@ -241,11 +241,11 @@ {{dict.dictLabel}} + >{{dict.label}} #elseif($column.htmlType == "radio" && $dictType) @@ -317,6 +317,9 @@ import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${Busin export default { name: "${BusinessName}", +#if(${dicts} != '') + dicts: [${dicts}], +#end data() { return { // 遮罩层 @@ -348,16 +351,7 @@ export default { // 是否显示弹出层 open: false, #foreach ($column in $columns) -#set($parentheseIndex=$column.columnComment.indexOf("(")) -#if($parentheseIndex != -1) -#set($comment=$column.columnComment.substring(0, $parentheseIndex)) -#else -#set($comment=$column.columnComment) -#end -#if(${column.dictType} != '') - // $comment字典 - ${column.javaField}Options: [], -#elseif($column.htmlType == "datetime" && $column.queryType == "BETWEEN") +#if($column.htmlType == "datetime" && $column.queryType == "BETWEEN") #set($AttrName=$column.javaField.substring(0,1).toUpperCase() + ${column.javaField.substring(1)}) // $comment时间范围 daterange${AttrName}: [], @@ -397,13 +391,6 @@ export default { }, created() { this.getList(); -#foreach ($column in $columns) -#if(${column.dictType} != '') - this.getDicts("${column.dictType}").then(response => { - this.${column.javaField}Options = response.data; - }); -#end -#end }, methods: { /** 查询${functionName}列表 */ diff --git a/ruoyi-ui/src/components/DictData/index.js b/ruoyi-ui/src/components/DictData/index.js new file mode 100644 index 0000000..24e3e9c --- /dev/null +++ b/ruoyi-ui/src/components/DictData/index.js @@ -0,0 +1,21 @@ +import Vue from 'vue' +import DataDict from '@/utils/dict' +import { getDicts as getDicts } from '@/api/system/dict/data' + +function install() { + Vue.use(DataDict, { + metas: { + '*': { + labelField: 'dictLabel', + valueField: 'dictValue', + request(dictMeta) { + return getDicts(dictMeta.type).then(res => res.data) + }, + }, + }, + }) +} + +export default { + install, +} \ No newline at end of file diff --git a/ruoyi-ui/src/components/DictTag/index.vue b/ruoyi-ui/src/components/DictTag/index.vue index b0484bc..4c196c4 100644 --- a/ruoyi-ui/src/components/DictTag/index.vue +++ b/ruoyi-ui/src/components/DictTag/index.vue @@ -1,23 +1,23 @@