Commit b2d79b62d1d411eead38d500cdae1dc3a58d84ac
1 parent
8a076e17
代码生成支持选择上级菜单
Showing
8 changed files
with
120 additions
and
19 deletions
ruoyi-common/src/main/java/com/ruoyi/common/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" }; | ... | ... |
ruoyi-generator/src/main/java/com/ruoyi/generator/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 | +} | |
| 272 | 298 | \ No newline at end of file | ... | ... |
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
| ... | ... | @@ -337,9 +337,14 @@ public class GenTableServiceImpl implements IGenTableService |
| 337 | 337 | String treeCode = paramsObj.getString(GenConstants.TREE_CODE); |
| 338 | 338 | String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE); |
| 339 | 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 | 343 | genTable.setTreeCode(treeCode); |
| 341 | 344 | genTable.setTreeParentCode(treeParentCode); |
| 342 | 345 | genTable.setTreeName(treeName); |
| 346 | + genTable.setParentMenuId(parentMenuId); | |
| 347 | + genTable.setParentMenuName(parentMenuName); | |
| 343 | 348 | } |
| 344 | 349 | } |
| 345 | -} | |
| 350 | +} | |
| 346 | 351 | \ No newline at end of file | ... | ... |
ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java
| ... | ... | @@ -11,18 +11,16 @@ import com.ruoyi.common.utils.StringUtils; |
| 11 | 11 | import com.ruoyi.generator.domain.GenTable; |
| 12 | 12 | import com.ruoyi.generator.domain.GenTableColumn; |
| 13 | 13 | |
| 14 | -/** | |
| 15 | - * 代码生成模板处理 | |
| 16 | - * | |
| 17 | - * @author ruoyi | |
| 18 | - */ | |
| 19 | 14 | public class VelocityUtils |
| 20 | 15 | { |
| 21 | 16 | /** 项目空间路径 */ |
| 22 | 17 | private static final String PROJECT_PATH = "main/java"; |
| 23 | 18 | |
| 24 | 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 | 53 | velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName)); |
| 56 | 54 | velocityContext.put("columns", genTable.getColumns()); |
| 57 | 55 | velocityContext.put("table", genTable); |
| 56 | + setMenuVelocityContext(velocityContext, genTable); | |
| 58 | 57 | if (GenConstants.TPL_TREE.equals(tplCategory)) |
| 59 | 58 | { |
| 60 | 59 | setTreeVelocityContext(velocityContext, genTable); |
| ... | ... | @@ -62,6 +61,14 @@ public class VelocityUtils |
| 62 | 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 | 72 | public static void setTreeVelocityContext(VelocityContext context, GenTable genTable) |
| 66 | 73 | { |
| 67 | 74 | String options = genTable.getOptions(); |
| ... | ... | @@ -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 | 252 | * @param options 生成其他选项 |
| ... | ... | @@ -236,7 +258,7 @@ public class VelocityUtils |
| 236 | 258 | { |
| 237 | 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 | 273 | { |
| 252 | 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 | 288 | { |
| 267 | 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 | 317 | } |
| 296 | 318 | return num; |
| 297 | 319 | } |
| 298 | -} | |
| 320 | +} | |
| 299 | 321 | \ No newline at end of file | ... | ... |
ruoyi-generator/src/main/resources/vm/sql/sql.vm
| 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(); | ... | ... |
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); | ... | ... |
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> | ... | ... |
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> | ... | ... |