作者 RuoYi

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

@@ -22,6 +22,12 @@ public class GenConstants @@ -22,6 +22,12 @@ public class GenConstants
22 /** 树名称字段 */ 22 /** 树名称字段 */
23 public static final String TREE_NAME = "treeName"; 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 public static final String[] COLUMNTYPE_STR = { "char", "varchar", "narchar", "varchar2", "tinytext", "text", 32 public static final String[] COLUMNTYPE_STR = { "char", "varchar", "narchar", "varchar2", "tinytext", "text",
27 "mediumtext", "longtext" }; 33 "mediumtext", "longtext" };
@@ -74,6 +74,12 @@ public class GenTable extends BaseEntity @@ -74,6 +74,12 @@ public class GenTable extends BaseEntity
74 /** 树名称字段 */ 74 /** 树名称字段 */
75 private String treeName; 75 private String treeName;
76 76
  77 + /** 上级菜单ID字段 */
  78 + private String parentMenuId;
  79 +
  80 + /** 上级菜单名称字段 */
  81 + private String parentMenuName;
  82 +
77 public Long getTableId() 83 public Long getTableId()
78 { 84 {
79 return tableId; 85 return tableId;
@@ -234,6 +240,26 @@ public class GenTable extends BaseEntity @@ -234,6 +240,26 @@ public class GenTable extends BaseEntity
234 this.treeName = treeName; 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 public boolean isTree() 263 public boolean isTree()
238 { 264 {
239 return isTree(this.tplCategory); 265 return isTree(this.tplCategory);
@@ -268,4 +294,4 @@ public class GenTable extends BaseEntity @@ -268,4 +294,4 @@ public class GenTable extends BaseEntity
268 } 294 }
269 return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY); 295 return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
270 } 296 }
271 -} 297 +}
@@ -337,9 +337,14 @@ public class GenTableServiceImpl implements IGenTableService @@ -337,9 +337,14 @@ public class GenTableServiceImpl implements IGenTableService
337 String treeCode = paramsObj.getString(GenConstants.TREE_CODE); 337 String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
338 String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); 338 String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
339 String treeName = paramsObj.getString(GenConstants.TREE_NAME); 339 String treeName = paramsObj.getString(GenConstants.TREE_NAME);
  340 + String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
  341 + String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
  342 +
340 genTable.setTreeCode(treeCode); 343 genTable.setTreeCode(treeCode);
341 genTable.setTreeParentCode(treeParentCode); 344 genTable.setTreeParentCode(treeParentCode);
342 genTable.setTreeName(treeName); 345 genTable.setTreeName(treeName);
  346 + genTable.setParentMenuId(parentMenuId);
  347 + genTable.setParentMenuName(parentMenuName);
343 } 348 }
344 } 349 }
345 -} 350 +}
@@ -11,18 +11,16 @@ import com.ruoyi.common.utils.StringUtils; @@ -11,18 +11,16 @@ import com.ruoyi.common.utils.StringUtils;
11 import com.ruoyi.generator.domain.GenTable; 11 import com.ruoyi.generator.domain.GenTable;
12 import com.ruoyi.generator.domain.GenTableColumn; 12 import com.ruoyi.generator.domain.GenTableColumn;
13 13
14 -/**  
15 - * 代码生成模板处理  
16 - *  
17 - * @author ruoyi  
18 - */  
19 public class VelocityUtils 14 public class VelocityUtils
20 { 15 {
21 /** 项目空间路径 */ 16 /** 项目空间路径 */
22 private static final String PROJECT_PATH = "main/java"; 17 private static final String PROJECT_PATH = "main/java";
23 18
24 /** mybatis空间路径 */ 19 /** mybatis空间路径 */
25 - private static final String MYBATIS_PATH = "main/resources/mapper"; 20 + private static final String MYBATIS_PATH = "main/resources/mybatis";
  21 +
  22 + /** 默认上级菜单,系统工具 */
  23 + private static final String DEFAULT_PARENT_MENU_ID = "3";
26 24
27 /** 25 /**
28 * 设置模板变量信息 26 * 设置模板变量信息
@@ -55,6 +53,7 @@ public class VelocityUtils @@ -55,6 +53,7 @@ public class VelocityUtils
55 velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); 53 velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
56 velocityContext.put("columns", genTable.getColumns()); 54 velocityContext.put("columns", genTable.getColumns());
57 velocityContext.put("table", genTable); 55 velocityContext.put("table", genTable);
  56 + setMenuVelocityContext(velocityContext, genTable);
58 if (GenConstants.TPL_TREE.equals(tplCategory)) 57 if (GenConstants.TPL_TREE.equals(tplCategory))
59 { 58 {
60 setTreeVelocityContext(velocityContext, genTable); 59 setTreeVelocityContext(velocityContext, genTable);
@@ -62,6 +61,14 @@ public class VelocityUtils @@ -62,6 +61,14 @@ public class VelocityUtils
62 return velocityContext; 61 return velocityContext;
63 } 62 }
64 63
  64 + public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
  65 + {
  66 + String options = genTable.getOptions();
  67 + JSONObject paramsObj = JSONObject.parseObject(options);
  68 + String parentMenuId = getParentMenuId(paramsObj);
  69 + context.put("parentMenuId", parentMenuId);
  70 + }
  71 +
65 public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) 72 public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
66 { 73 {
67 String options = genTable.getOptions(); 74 String options = genTable.getOptions();
@@ -225,6 +232,21 @@ public class VelocityUtils @@ -225,6 +232,21 @@ public class VelocityUtils
225 } 232 }
226 233
227 /** 234 /**
  235 + * 获取上级菜单ID字段
  236 + *
  237 + * @param options 生成其他选项
  238 + * @return 上级菜单ID字段
  239 + */
  240 + public static String getParentMenuId(JSONObject paramsObj)
  241 + {
  242 + if (paramsObj.containsKey(GenConstants.PARENT_MENU_ID))
  243 + {
  244 + return paramsObj.getString(GenConstants.PARENT_MENU_ID);
  245 + }
  246 + return DEFAULT_PARENT_MENU_ID;
  247 + }
  248 +
  249 + /**
228 * 获取树编码 250 * 获取树编码
229 * 251 *
230 * @param options 生成其他选项 252 * @param options 生成其他选项
@@ -236,7 +258,7 @@ public class VelocityUtils @@ -236,7 +258,7 @@ public class VelocityUtils
236 { 258 {
237 return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE)); 259 return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
238 } 260 }
239 - return ""; 261 + return StringUtils.EMPTY;
240 } 262 }
241 263
242 /** 264 /**
@@ -251,7 +273,7 @@ public class VelocityUtils @@ -251,7 +273,7 @@ public class VelocityUtils
251 { 273 {
252 return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE)); 274 return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
253 } 275 }
254 - return ""; 276 + return StringUtils.EMPTY;
255 } 277 }
256 278
257 /** 279 /**
@@ -266,7 +288,7 @@ public class VelocityUtils @@ -266,7 +288,7 @@ public class VelocityUtils
266 { 288 {
267 return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME)); 289 return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
268 } 290 }
269 - return ""; 291 + return StringUtils.EMPTY;
270 } 292 }
271 293
272 /** 294 /**
@@ -295,4 +317,4 @@ public class VelocityUtils @@ -295,4 +317,4 @@ public class VelocityUtils
295 } 317 }
296 return num; 318 return num;
297 } 319 }
298 -} 320 +}
1 -- 菜单 SQL 1 -- 菜单 SQL
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) 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 -- 按钮父菜单ID 5 -- 按钮父菜单ID
6 SELECT @parentId := LAST_INSERT_ID(); 6 SELECT @parentId := LAST_INSERT_ID();
@@ -110,7 +110,7 @@ @@ -110,7 +110,7 @@
110 </el-table> 110 </el-table>
111 </el-tab-pane> 111 </el-tab-pane>
112 <el-tab-pane label="生成信息" name="genInfo"> 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 </el-tab-pane> 114 </el-tab-pane>
115 </el-tabs> 115 </el-tabs>
116 <el-form label-width="100px"> 116 <el-form label-width="100px">
@@ -124,9 +124,11 @@ @@ -124,9 +124,11 @@
124 <script> 124 <script>
125 import { getGenTable, updateGenTable } from "@/api/tool/gen"; 125 import { getGenTable, updateGenTable } from "@/api/tool/gen";
126 import { optionselect as getDictOptionselect } from "@/api/system/dict/type"; 126 import { optionselect as getDictOptionselect } from "@/api/system/dict/type";
  127 +import { listMenu as getMenuTreeselect } from "@/api/system/menu";
127 import basicInfoForm from "./basicInfoForm"; 128 import basicInfoForm from "./basicInfoForm";
128 import genInfoForm from "./genInfoForm"; 129 import genInfoForm from "./genInfoForm";
129 import Sortable from 'sortablejs' 130 import Sortable from 'sortablejs'
  131 +
130 export default { 132 export default {
131 name: "GenEdit", 133 name: "GenEdit",
132 components: { 134 components: {
@@ -143,6 +145,8 @@ export default { @@ -143,6 +145,8 @@ export default {
143 cloumns: [], 145 cloumns: [],
144 // 字典信息 146 // 字典信息
145 dictOptions: [], 147 dictOptions: [],
  148 + // 菜单信息
  149 + menus: [],
146 // 表详细信息 150 // 表详细信息
147 info: {} 151 info: {}
148 }; 152 };
@@ -159,6 +163,10 @@ export default { @@ -159,6 +163,10 @@ export default {
159 getDictOptionselect().then(response => { 163 getDictOptionselect().then(response => {
160 this.dictOptions = response.data; 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 methods: { 172 methods: {
@@ -174,7 +182,8 @@ export default { @@ -174,7 +182,8 @@ export default {
174 genTable.params = { 182 genTable.params = {
175 treeCode: genTable.treeCode, 183 treeCode: genTable.treeCode,
176 treeName: genTable.treeName, 184 treeName: genTable.treeName,
177 - treeParentCode: genTable.treeParentCode 185 + treeParentCode: genTable.treeParentCode,
  186 + parentMenuId: genTable.parentMenuId
178 }; 187 };
179 updateGenTable(genTable).then(res => { 188 updateGenTable(genTable).then(res => {
180 this.msgSuccess(res.msg); 189 this.msgSuccess(res.msg);
@@ -58,6 +58,18 @@ @@ -58,6 +58,18 @@
58 <el-input v-model="info.functionName" /> 58 <el-input v-model="info.functionName" />
59 </el-form-item> 59 </el-form-item>
60 </el-col> 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 </el-row> 73 </el-row>
62 74
63 <el-row v-show="info.tplCategory == 'tree'"> 75 <el-row v-show="info.tplCategory == 'tree'">
@@ -120,13 +132,21 @@ @@ -120,13 +132,21 @@
120 </el-form> 132 </el-form>
121 </template> 133 </template>
122 <script> 134 <script>
  135 +import Treeselect from "@riophae/vue-treeselect";
  136 +import "@riophae/vue-treeselect/dist/vue-treeselect.css";
  137 +
123 export default { 138 export default {
124 name: "BasicInfoForm", 139 name: "BasicInfoForm",
  140 + components: { Treeselect },
125 props: { 141 props: {
126 info: { 142 info: {
127 type: Object, 143 type: Object,
128 default: null 144 default: null
129 - } 145 + },
  146 + menus: {
  147 + type: Array,
  148 + default: []
  149 + },
130 }, 150 },
131 data() { 151 data() {
132 return { 152 return {
@@ -149,6 +169,19 @@ export default { @@ -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 </script> 187 </script>
@@ -28,8 +28,8 @@ @@ -28,8 +28,8 @@
28 <el-row> 28 <el-row>
29 <el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px"> 29 <el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
30 <el-table-column type="selection" width="55"></el-table-column> 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 <el-table-column prop="createTime" label="创建时间"></el-table-column> 33 <el-table-column prop="createTime" label="创建时间"></el-table-column>
34 <el-table-column prop="updateTime" label="更新时间"></el-table-column> 34 <el-table-column prop="updateTime" label="更新时间"></el-table-column>
35 </el-table> 35 </el-table>