From b2d79b62d1d411eead38d500cdae1dc3a58d84ac Mon Sep 17 00:00:00 2001
From: RuoYi <yzz_ivy@163.com>
Date: 星期二, 21 七月 2020 11:21:20 +0800
Subject: [PATCH] 代码生成支持选择上级菜单
---
ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java | 7 ++
ruoyi-ui/src/views/tool/gen/genInfoForm.vue | 37 +++++++++++
ruoyi-generator/src/main/resources/vm/sql/sql.vm | 2
ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java | 6 ++
ruoyi-ui/src/views/tool/gen/editTable.vue | 13 +++
ruoyi-ui/src/views/tool/gen/importTable.vue | 4
ruoyi-generator/src/main/java/com/ruoyi/generator/util/VelocityUtils.java | 42 ++++++++++---
ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java | 28 +++++++++
8 files changed, 120 insertions(+), 19 deletions(-)
diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java b/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
index 0001785..8e95f37 100644
--- a/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
+++ b/ruoyi-common/src/main/java/com/ruoyi/common/constant/GenConstants.java
@@ -22,6 +22,12 @@
/** 鏍戝悕绉板瓧娈� */
public static final String TREE_NAME = "treeName";
+ /** 涓婄骇鑿滃崟ID瀛楁 */
+ public static final String PARENT_MENU_ID = "parentMenuId";
+
+ /** 涓婄骇鑿滃崟鍚嶇О瀛楁 */
+ public static final String PARENT_MENU_NAME = "parentMenuName";
+
/** 鏁版嵁搴撳瓧绗︿覆绫诲瀷 */
public static final String[] COLUMNTYPE_STR = { "char", "varchar", "narchar", "varchar2", "tinytext", "text",
"mediumtext", "longtext" };
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java
index 5123165..aa05e70 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/domain/GenTable.java
@@ -74,6 +74,12 @@
/** 鏍戝悕绉板瓧娈� */
private String treeName;
+ /** 涓婄骇鑿滃崟ID瀛楁 */
+ private String parentMenuId;
+
+ /** 涓婄骇鑿滃崟鍚嶇О瀛楁 */
+ private String parentMenuName;
+
public Long getTableId()
{
return tableId;
@@ -234,6 +240,26 @@
this.treeName = treeName;
}
+ public String getParentMenuId()
+ {
+ return parentMenuId;
+ }
+
+ public void setParentMenuId(String parentMenuId)
+ {
+ this.parentMenuId = parentMenuId;
+ }
+
+ public String getParentMenuName()
+ {
+ return parentMenuName;
+ }
+
+ public void setParentMenuName(String parentMenuName)
+ {
+ this.parentMenuName = parentMenuName;
+ }
+
public boolean isTree()
{
return isTree(this.tplCategory);
@@ -268,4 +294,4 @@
}
return StringUtils.equalsAnyIgnoreCase(javaField, GenConstants.BASE_ENTITY);
}
-}
+}
\ No newline at end of file
diff --git a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
index 955960f..e753184 100644
--- a/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
+++ b/ruoyi-generator/src/main/java/com/ruoyi/generator/service/GenTableServiceImpl.java
@@ -337,9 +337,14 @@
String treeCode = paramsObj.getString(GenConstants.TREE_CODE);
String treeParentCode = paramsObj.getString(GenConstants.TREE_PARENT_CODE);
String treeName = paramsObj.getString(GenConstants.TREE_NAME);
+ String parentMenuId = paramsObj.getString(GenConstants.PARENT_MENU_ID);
+ String parentMenuName = paramsObj.getString(GenConstants.PARENT_MENU_NAME);
+
genTable.setTreeCode(treeCode);
genTable.setTreeParentCode(treeParentCode);
genTable.setTreeName(treeName);
+ genTable.setParentMenuId(parentMenuId);
+ genTable.setParentMenuName(parentMenuName);
}
}
-}
+}
\ No newline at end of file
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 9ec14c3..8d17da0 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
@@ -11,18 +11,16 @@
import com.ruoyi.generator.domain.GenTable;
import com.ruoyi.generator.domain.GenTableColumn;
-/**
- * 浠g爜鐢熸垚妯℃澘澶勭悊
- *
- * @author ruoyi
- */
public class VelocityUtils
{
/** 椤圭洰绌洪棿璺緞 */
private static final String PROJECT_PATH = "main/java";
/** mybatis绌洪棿璺緞 */
- private static final String MYBATIS_PATH = "main/resources/mapper";
+ private static final String MYBATIS_PATH = "main/resources/mybatis";
+
+ /** 榛樿涓婄骇鑿滃崟锛岀郴缁熷伐鍏� */
+ private static final String DEFAULT_PARENT_MENU_ID = "3";
/**
* 璁剧疆妯℃澘鍙橀噺淇℃伅
@@ -55,11 +53,20 @@
velocityContext.put("permissionPrefix", getPermissionPrefix(moduleName, businessName));
velocityContext.put("columns", genTable.getColumns());
velocityContext.put("table", genTable);
+ setMenuVelocityContext(velocityContext, genTable);
if (GenConstants.TPL_TREE.equals(tplCategory))
{
setTreeVelocityContext(velocityContext, genTable);
}
return velocityContext;
+ }
+
+ public static void setMenuVelocityContext(VelocityContext context, GenTable genTable)
+ {
+ String options = genTable.getOptions();
+ JSONObject paramsObj = JSONObject.parseObject(options);
+ String parentMenuId = getParentMenuId(paramsObj);
+ context.put("parentMenuId", parentMenuId);
}
public static void setTreeVelocityContext(VelocityContext context, GenTable genTable)
@@ -225,6 +232,21 @@
}
/**
+ * 鑾峰彇涓婄骇鑿滃崟ID瀛楁
+ *
+ * @param options 鐢熸垚鍏朵粬閫夐」
+ * @return 涓婄骇鑿滃崟ID瀛楁
+ */
+ public static String getParentMenuId(JSONObject paramsObj)
+ {
+ if (paramsObj.containsKey(GenConstants.PARENT_MENU_ID))
+ {
+ return paramsObj.getString(GenConstants.PARENT_MENU_ID);
+ }
+ return DEFAULT_PARENT_MENU_ID;
+ }
+
+ /**
* 鑾峰彇鏍戠紪鐮�
*
* @param options 鐢熸垚鍏朵粬閫夐」
@@ -236,7 +258,7 @@
{
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_CODE));
}
- return "";
+ return StringUtils.EMPTY;
}
/**
@@ -251,7 +273,7 @@
{
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_PARENT_CODE));
}
- return "";
+ return StringUtils.EMPTY;
}
/**
@@ -266,7 +288,7 @@
{
return StringUtils.toCamelCase(paramsObj.getString(GenConstants.TREE_NAME));
}
- return "";
+ return StringUtils.EMPTY;
}
/**
@@ -295,4 +317,4 @@
}
return num;
}
-}
+}
\ No newline at end of file
diff --git a/ruoyi-generator/src/main/resources/vm/sql/sql.vm b/ruoyi-generator/src/main/resources/vm/sql/sql.vm
index ab17d1b..5e3c682 100644
--- a/ruoyi-generator/src/main/resources/vm/sql/sql.vm
+++ b/ruoyi-generator/src/main/resources/vm/sql/sql.vm
@@ -1,6 +1,6 @@
-- 鑿滃崟 SQL
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)
-values('${functionName}', '3', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '${functionName}鑿滃崟');
+values('${functionName}', '${parentMenuId}', '1', '${businessName}', '${moduleName}/${businessName}/index', 1, 'C', '0', '0', '${permissionPrefix}:list', '#', 'admin', '2018-03-01', 'ry', '2018-03-01', '${functionName}鑿滃崟');
-- 鎸夐挳鐖惰彍鍗旾D
SELECT @parentId := LAST_INSERT_ID();
diff --git a/ruoyi-ui/src/views/tool/gen/editTable.vue b/ruoyi-ui/src/views/tool/gen/editTable.vue
index fb1bba1..38cbd55 100644
--- a/ruoyi-ui/src/views/tool/gen/editTable.vue
+++ b/ruoyi-ui/src/views/tool/gen/editTable.vue
@@ -110,7 +110,7 @@
</el-table>
</el-tab-pane>
<el-tab-pane label="鐢熸垚淇℃伅" name="genInfo">
- <gen-info-form ref="genInfo" :info="info" />
+ <gen-info-form ref="genInfo" :info="info" :menus="menus"/>
</el-tab-pane>
</el-tabs>
<el-form label-width="100px">
@@ -124,9 +124,11 @@
<script>
import { getGenTable, updateGenTable } from "@/api/tool/gen";
import { optionselect as getDictOptionselect } from "@/api/system/dict/type";
+import { listMenu as getMenuTreeselect } from "@/api/system/menu";
import basicInfoForm from "./basicInfoForm";
import genInfoForm from "./genInfoForm";
import Sortable from 'sortablejs'
+
export default {
name: "GenEdit",
components: {
@@ -143,6 +145,8 @@
cloumns: [],
// 瀛楀吀淇℃伅
dictOptions: [],
+ // 鑿滃崟淇℃伅
+ menus: [],
// 琛ㄨ缁嗕俊鎭�
info: {}
};
@@ -159,6 +163,10 @@
getDictOptionselect().then(response => {
this.dictOptions = response.data;
});
+ /** 鏌ヨ鑿滃崟涓嬫媺鍒楄〃 */
+ getMenuTreeselect().then(response => {
+ this.menus = this.handleTree(response.data, "menuId");
+ });
}
},
methods: {
@@ -174,7 +182,8 @@
genTable.params = {
treeCode: genTable.treeCode,
treeName: genTable.treeName,
- treeParentCode: genTable.treeParentCode
+ treeParentCode: genTable.treeParentCode,
+ parentMenuId: genTable.parentMenuId
};
updateGenTable(genTable).then(res => {
this.msgSuccess(res.msg);
diff --git a/ruoyi-ui/src/views/tool/gen/genInfoForm.vue b/ruoyi-ui/src/views/tool/gen/genInfoForm.vue
index 41ad4e5..d535611 100644
--- a/ruoyi-ui/src/views/tool/gen/genInfoForm.vue
+++ b/ruoyi-ui/src/views/tool/gen/genInfoForm.vue
@@ -58,6 +58,18 @@
<el-input v-model="info.functionName" />
</el-form-item>
</el-col>
+
+ <el-col :span="12">
+ <el-form-item prop="functionName">
+ <span slot="label">
+ 涓婄骇鑿滃崟
+ <el-tooltip content="鍒嗛厤鍒版寚瀹氳彍鍗曚笅锛屼緥濡� 绯荤粺绠$悊" placement="top">
+ <i class="el-icon-question"></i>
+ </el-tooltip>
+ </span>
+ <treeselect :append-to-body="true" v-model="info.parentMenuId" :options="menus" :normalizer="normalizer" :show-count="true" placeholder="璇烽�夋嫨绯荤粺鑿滃崟"/>
+ </el-form-item>
+ </el-col>
</el-row>
<el-row v-show="info.tplCategory == 'tree'">
@@ -120,13 +132,21 @@
</el-form>
</template>
<script>
+import Treeselect from "@riophae/vue-treeselect";
+import "@riophae/vue-treeselect/dist/vue-treeselect.css";
+
export default {
name: "BasicInfoForm",
+ components: { Treeselect },
props: {
info: {
type: Object,
default: null
- }
+ },
+ menus: {
+ type: Array,
+ default: []
+ },
},
data() {
return {
@@ -149,6 +169,19 @@
}
};
},
- created() {}
+ created() {},
+ methods: {
+ /** 杞崲鑿滃崟鏁版嵁缁撴瀯 */
+ normalizer(node) {
+ if (node.children && !node.children.length) {
+ delete node.children;
+ }
+ return {
+ id: node.menuId,
+ label: node.menuName,
+ children: node.children
+ };
+ }
+ }
};
</script>
diff --git a/ruoyi-ui/src/views/tool/gen/importTable.vue b/ruoyi-ui/src/views/tool/gen/importTable.vue
index 6c56c77..e48a5f3 100644
--- a/ruoyi-ui/src/views/tool/gen/importTable.vue
+++ b/ruoyi-ui/src/views/tool/gen/importTable.vue
@@ -28,8 +28,8 @@
<el-row>
<el-table @row-click="clickRow" ref="table" :data="dbTableList" @selection-change="handleSelectionChange" height="260px">
<el-table-column type="selection" width="55"></el-table-column>
- <el-table-column prop="tableName" label="琛ㄥ悕绉�"></el-table-column>
- <el-table-column prop="tableComment" label="琛ㄦ弿杩�"></el-table-column>
+ <el-table-column prop="tableName" label="琛ㄥ悕绉�" :show-overflow-tooltip="true"></el-table-column>
+ <el-table-column prop="tableComment" label="琛ㄦ弿杩�" :show-overflow-tooltip="true"></el-table-column>
<el-table-column prop="createTime" label="鍒涘缓鏃堕棿"></el-table-column>
<el-table-column prop="updateTime" label="鏇存柊鏃堕棿"></el-table-column>
</el-table>
--
Gitblit v1.9.3