Просмотр исходного кода

代码生成支持选择上级菜单

RuoYi лет назад: 5
Родитель
Сommit
8ae4f5e90b

+ 0 - 2
ruoyi-api/ruoyi-api-system/src/main/java/com/ruoyi/system/api/domain/SysUser.java

@@ -7,7 +7,6 @@ import javax.validation.constraints.NotBlank;
7 7
 import javax.validation.constraints.Size;
8 8
 import org.apache.commons.lang3.builder.ToStringBuilder;
9 9
 import org.apache.commons.lang3.builder.ToStringStyle;
10
-import com.fasterxml.jackson.annotation.JsonIgnore;
11 10
 import com.fasterxml.jackson.annotation.JsonProperty;
12 11
 import com.ruoyi.common.core.annotation.Excel;
13 12
 import com.ruoyi.common.core.annotation.Excel.ColumnType;
@@ -198,7 +197,6 @@ public class SysUser extends BaseEntity
198 197
         this.avatar = avatar;
199 198
     }
200 199
 
201
-    @JsonIgnore
202 200
     @JsonProperty
203 201
     public String getPassword()
204 202
     {

+ 6 - 0
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/constant/GenConstants.java

@@ -22,6 +22,12 @@ public class GenConstants
22 22
     /** 树名称字段 */
23 23
     public static final String TREE_NAME = "treeName";
24 24
 
25
+    /** 上级菜单ID字段 */
26
+    public static final String PARENT_MENU_ID = "parentMenuId";
27
+
28
+    /** 上级菜单名称字段 */
29
+    public static final String PARENT_MENU_NAME = "parentMenuName";
30
+
25 31
     /** 数据库字符串类型 */
26 32
     public static final String[] COLUMNTYPE_STR = { "char", "varchar", "narchar", "varchar2", "tinytext", "text",
27 33
             "mediumtext", "longtext" };

+ 1 - 1
ruoyi-gateway/src/main/java/com/ruoyi/gateway/RuoYiGatewayApplication.java

@@ -28,4 +28,4 @@ public class RuoYiGatewayApplication
28 28
                 " |  |  \\    /  \\      /           \n" +
29 29
                 " ''-'   `'-'    `-..-'              ");
30 30
     }
31
-}
31
+}

+ 27 - 1
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/domain/GenTable.java

@@ -74,6 +74,12 @@ public class GenTable extends BaseEntity
74 74
     /** 树名称字段 */
75 75
     private String treeName;
76 76
 
77
+    /** 上级菜单ID字段 */
78
+    private String parentMenuId;
79
+
80
+    /** 上级菜单名称字段 */
81
+    private String parentMenuName;
82
+
77 83
     public Long getTableId()
78 84
     {
79 85
         return tableId;
@@ -234,6 +240,26 @@ public class GenTable extends BaseEntity
234 240
         this.treeName = treeName;
235 241
     }
236 242
 
243
+    public String getParentMenuId()
244
+    {
245
+        return parentMenuId;
246
+    }
247
+
248
+    public void setParentMenuId(String parentMenuId)
249
+    {
250
+        this.parentMenuId = parentMenuId;
251
+    }
252
+
253
+    public String getParentMenuName()
254
+    {
255
+        return parentMenuName;
256
+    }
257
+
258
+    public void setParentMenuName(String parentMenuName)
259
+    {
260
+        this.parentMenuName = parentMenuName;
261
+    }
262
+
237 263
     public boolean isTree()
238 264
     {
239 265
         return isTree(this.tplCategory);
@@ -268,4 +294,4 @@ public class GenTable extends BaseEntity
268 294
         }
269 295
         return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
270 296
     }
271
-}
297
+}

+ 5 - 0
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/service/GenTableServiceImpl.java

@@ -336,9 +336,14 @@ public class GenTableServiceImpl implements IGenTableService
336 336
             String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
337 337
             String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
338 338
             String treeName = paramsObj.getString(GenConstants.TREE_NAME);
339
+            String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
340
+            String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
341
+            
339 342
             genTable.setTreeCode(treeCode);
340 343
             genTable.setTreeParentCode(treeParentCode);
341 344
             genTable.setTreeName(treeName);
345
+            genTable.setParentMenuId(parentMenuId);
346
+            genTable.setParentMenuName(parentMenuName);
342 347
         }
343 348
     }
344 349
 }

+ 30 - 4
ruoyi-modules/ruoyi-gen/src/main/java/com/ruoyi/gen/util/VelocityUtils.java

@@ -23,6 +23,9 @@ public class VelocityUtils
23 23
 
24 24
     /** mybatis空间路径 */
25 25
     private static final String MYBATIS_PATH = "main/resources/mapper";
26
+    
27
+    /** 默认上级菜单,系统工具 */
28
+    private static final String DEFAULT_PARENT_MENU_ID = "3";
26 29
 
27 30
     /**
28 31
      * 设置模板变量信息
@@ -55,12 +58,21 @@ public class VelocityUtils
55 58
         velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
56 59
         velocityContext.put("columns", genTable.getColumns());
57 60
         velocityContext.put("table", genTable);
61
+        setMenuVelocityContext(velocityContext, genTable);
58 62
         if (GenConstants.TPL_TREE.equals(tplCategory))
59 63
         {
60 64
             setTreeVelocityContext(velocityContext, genTable);
61 65
         }
62 66
         return velocityContext;
63 67
     }
68
+    
69
+    public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
70
+    {
71
+        String options = genTable.getOptions();
72
+        JSONObject paramsObj = JSONObject.parseObject(options);
73
+        String parentMenuId = getParentMenuId(paramsObj);
74
+        context.put("parentMenuId", parentMenuId);
75
+    }
64 76
 
65 77
     public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
66 78
     {
@@ -221,7 +233,21 @@ public class VelocityUtils
221 233
     public static String getPermissionPrefix(String moduleName, String businessName)
222 234
     {
223 235
         return StringUtils.format("{}:{}", moduleName, businessName);
236
+    }
224 237
 
238
+    /**
239
+     * 获取上级菜单ID字段
240
+     * 
241
+     * @param options 生成其他选项
242
+     * @return 上级菜单ID字段
243
+     */
244
+    public static String getParentMenuId(JSONObject paramsObj)
245
+    {
246
+        if (StringUtils.isNotEmpty(paramsObj) && paramsObj.containsKey(GenConstants.PARENT_MENU_ID))
247
+        {
248
+            return paramsObj.getString(GenConstants.PARENT_MENU_ID);
249
+        }
250
+        return DEFAULT_PARENT_MENU_ID;
225 251
     }
226 252
 
227 253
     /**
@@ -236,7 +262,7 @@ public class VelocityUtils
236 262
         {
237 263
             return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
238 264
         }
239
-        return "";
265
+        return StringUtils.EMPTY;
240 266
     }
241 267
 
242 268
     /**
@@ -251,7 +277,7 @@ public class VelocityUtils
251 277
         {
252 278
             return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
253 279
         }
254
-        return "";
280
+        return StringUtils.EMPTY;
255 281
     }
256 282
 
257 283
     /**
@@ -266,7 +292,7 @@ public class VelocityUtils
266 292
         {
267 293
             return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
268 294
         }
269
-        return "";
295
+        return StringUtils.EMPTY;
270 296
     }
271 297
 
272 298
     /**
@@ -295,4 +321,4 @@ public class VelocityUtils
295 321
         }
296 322
         return num;
297 323
     }
298
-}
324
+}

+ 1 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/sql/sql.vm

@@ -1,6 +1,6 @@
1 1
 -- 菜单 SQL
2 2
 insert into sys_menu (menu_name, parent_id, order_num, path, component, is_frame, menu_type, visible, status, perms, icon, create_by, create_time, update_by, update_time, remark)
3
-values('${functionName}', '3', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '${functionName}菜单');
3
+values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '${functionName}菜单');
4 4
 
5 5
 -- 按钮父菜单ID
6 6
 SELECT @parentId := LAST_INSERT_ID();

+ 11 - 2
ruoyi-ui/src/views/tool/gen/editTable.vue

@@ -110,7 +110,7 @@
110 110
         </el-table>
111 111
       </el-tab-pane>
112 112
       <el-tab-pane label="生成信息" name="genInfo">
113
-        <gen-info-form ref="genInfo" :info="info" />
113
+        <gen-info-form ref="genInfo" :info="info" :menus="menus"/>
114 114
       </el-tab-pane>
115 115
     </el-tabs>
116 116
     <el-form label-width="100px">
@@ -124,9 +124,11 @@
124 124
 <script>
125 125
 import { getGenTable, updateGenTable } from "@/api/tool/gen";
126 126
 import { optionselect as getDictOptionselect } from "@/api/system/dict/type";
127
+import { listMenu as getMenuTreeselect } from "@/api/system/menu";
127 128
 import basicInfoForm from "./basicInfoForm";
128 129
 import genInfoForm from "./genInfoForm";
129 130
 import Sortable from 'sortablejs'
131
+
130 132
 export default {
131 133
   name: "GenEdit",
132 134
   components: {
@@ -143,6 +145,8 @@ export default {
143 145
       cloumns: [],
144 146
       // 字典信息
145 147
       dictOptions: [],
148
+      // 菜单信息
149
+      menus: [],
146 150
       // 表详细信息
147 151
       info: {}
148 152
     };
@@ -159,6 +163,10 @@ export default {
159 163
       getDictOptionselect().then(response => {
160 164
         this.dictOptions = response.data;
161 165
       });
166
+      /** 查询菜单下拉列表 */
167
+      getMenuTreeselect().then(response => {
168
+        this.menus = this.handleTree(response.data, "menuId");
169
+      });
162 170
     }
163 171
   },
164 172
   methods: {
@@ -174,7 +182,8 @@ export default {
174 182
           genTable.params = {
175 183
             treeCode: genTable.treeCode,
176 184
             treeName: genTable.treeName,
177
-            treeParentCode: genTable.treeParentCode
185
+            treeParentCode: genTable.treeParentCode,
186
+            parentMenuId: genTable.parentMenuId
178 187
           };
179 188
           updateGenTable(genTable).then(res => {
180 189
             this.msgSuccess(res.msg);

+ 35 - 2
ruoyi-ui/src/views/tool/gen/genInfoForm.vue

@@ -58,6 +58,18 @@
58 58
           <el-input v-model="info.functionName" />
59 59
         </el-form-item>
60 60
       </el-col>
61
+
62
+      <el-col :span="12">
63
+        <el-form-item prop="functionName">
64
+          <span slot="label">
65
+            上级菜单
66
+            <el-tooltip content="分配到指定菜单下,例如 系统管理" placement="top">
67
+              <i class="el-icon-question"></i>
68
+            </el-tooltip>
69
+          </span>
70
+          <treeselect :append-to-body="true" v-model="info.parentMenuId" :options="menus" :normalizer="normalizer" :show-count="true" placeholder="请选择系统菜单"/>
71
+        </el-form-item>
72
+      </el-col>
61 73
     </el-row>
62 74
 
63 75
     <el-row v-show="info.tplCategory == 'tree'">
@@ -120,13 +132,21 @@
120 132
   </el-form>
121 133
 </template>
122 134
 <script>
135
+import Treeselect from "@riophae/vue-treeselect";
136
+import "@riophae/vue-treeselect/dist/vue-treeselect.css";
137
+
123 138
 export default {
124 139
   name: "BasicInfoForm",
140
+  components: { Treeselect },
125 141
   props: {
126 142
     info: {
127 143
       type: Object,
128 144
       default: null
129
-    }
145
+    },
146
+    menus: {
147
+      type: Array,
148
+      default: []
149
+    },
130 150
   },
131 151
   data() {
132 152
     return {
@@ -149,6 +169,19 @@ export default {
149 169
       }
150 170
     };
151 171
   },
152
-  created() {}
172
+  created() {},
173
+  methods: {
174
+    /** 转换菜单数据结构 */
175
+    normalizer(node) {
176
+      if (node.children && !node.children.length) {
177
+        delete node.children;
178
+      }
179
+      return {
180
+        id: node.menuId,
181
+        label: node.menuName,
182
+        children: node.children
183
+      };
184
+    }
185
+  }
153 186
 };
154 187
 </script>

+ 2 - 2
ruoyi-ui/src/views/tool/gen/importTable.vue

@@ -28,8 +28,8 @@
28 28
     <el-row>
29 29
       <el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
30 30
         <el-table-column type="selection" width="55"></el-table-column>
31
-        <el-table-column prop="tableName" label="表名称"></el-table-column>
32
-        <el-table-column prop="tableComment" label="表描述"></el-table-column>
31
+        <el-table-column prop="tableName" label="表名称" :show-overflow-tooltip="true"></el-table-column>
32
+        <el-table-column prop="tableComment" label="表描述" :show-overflow-tooltip="true"></el-table-column>
33 33
         <el-table-column prop="createTime" label="创建时间"></el-table-column>
34 34
         <el-table-column prop="updateTime" label="更新时间"></el-table-column>
35 35
       </el-table>