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 098a91892..38762275d 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 @@ -16,7 +16,7 @@ import java.util.Map; /** * 模板处理工具类 - * + * * @author ruoyi */ public class VelocityUtils @@ -61,6 +61,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)) { @@ -245,7 +246,7 @@ public class VelocityUtils /** * 根据列类型获取导入包 - * + * * @param genTable 业务表对象 * @return 返回需要导入的包列表 */ @@ -273,6 +274,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 89852509d..0d83a3c58 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 && "" != $column.dictType) #elseif($column.list && "" != $javaField) @@ -183,10 +183,10 @@ @@ -201,10 +201,10 @@ - {{dict.dictLabel}} + v-for="dict in dict.type.${dictType}" + :key="dict.value" + :label="dict.value"> + {{dict.label}} @@ -218,11 +218,11 @@ {{dict.dictLabel}} + >{{dict.label}} #elseif($column.htmlType == "radio" && $dictType) @@ -263,6 +263,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} && ${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} && ${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 4b055faa0..7e67021cd 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 && "" != $column.dictType) #elseif($column.list && "" != $javaField) @@ -163,7 +163,7 @@ - + @@ -223,10 +223,10 @@ - {{dict.dictLabel}} + v-for="dict in dict.type.${dictType}" + :key="dict.value" + :label="dict.value"> + {{dict.label}} @@ -240,11 +240,11 @@ {{dict.dictLabel}} + >{{dict.label}} #elseif($column.htmlType == "radio" && $dictType) @@ -315,6 +315,9 @@ import { list${BusinessName}, get${BusinessName}, del${BusinessName}, add${Busin export default { name: "${BusinessName}", +#if(${dicts} != '') + dicts: [${dicts}], +#end data() { return { // 按钮loading @@ -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} && ${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} && ${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 000000000..24e3e9c83 --- /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 b0484bc15..4c196c489 100644 --- a/ruoyi-ui/src/components/DictTag/index.vue +++ b/ruoyi-ui/src/components/DictTag/index.vue @@ -1,23 +1,23 @@