<template>
|
<div ref="container" class="page-list-container">
|
<split-pane :max-width="500" :default-width="260" split="vertical">
|
<div slot="paneL" class="left-container">
|
<el-form class="form-tool">
|
<el-form-item class="margin-bottom-0">
|
<el-input v-model="filterText" placeholder="搜索名称" prefix-icon="el-icon-search" class="search-input">
|
</el-input>
|
<el-button title="刷新" class="btn-refresh" icon="el-icon-yrt-shuaxin" @click.native="treeRefresh"></el-button>
|
</el-form-item>
|
<el-form-item class="padding-right-0 margin-bottom-0">
|
<el-scrollbar :noresize="false" :native="false" wrap-class="tree scrollbar-wrap">
|
<!--数据tree-->
|
<el-tree ref="tree" :data="dataTree" :expand-on-click-node="false" :load="(node, resolve)=>{loadTreeNode(node, resolve)}" :filter-node-method="filterTreeNode" :props="props" :default-expand-all="false" highlight-current lazy node-key="menu_Id" @node-click="nodeClick">
|
<span slot-scope="{ node, data }" class="custom-tree-node">
|
<span>
|
<i v-if="data.hasChild" class="el-icon-menu"></i>
|
<i v-else class="el-icon-tickets"></i>
|
{{ node.label }}
|
</span>
|
</span>
|
</el-tree>
|
</el-scrollbar>
|
</el-form-item>
|
</el-form>
|
</div>
|
|
<!--右侧主区-->
|
<div slot="paneR" class="right-container">
|
<!--数据编辑器Editor-->
|
<yrt-editor :ref="editorRef" :edit-type="'inner'" :data-list-ref="dataListRef" v-bind="editorOptions" :data-options="dataOptions" :action.sync="editorOptions.action" :visible.sync="editorOptions.config.visible" :detail-button-click="detailButtonClick" :auth-nodes="authNodes" @on-save-after="onSaveAfter">
|
<!--自定义按钮插槽-->
|
<template slot="footer-button-region" slot-scope="{ formData, details }">
|
<el-button type="success" icon="el-icon-yrt-tianjia" @click.native="createBrotherNode(formData, details)">添加同级</el-button>
|
<el-button type="success" icon="el-icon-yrt-addplus" @click.native="createSonNode(formData, details)">添加下级</el-button>
|
<el-button type="success" icon="el-icon-yrt-fuzhi2" @click.native="copyNode(formData, details)">复制</el-button>
|
<el-button type="success" icon="el-icon-yrt-shanchu1" @click.native="deleteNode(formData, details)">删除</el-button>
|
<!--生成菜单文件-->
|
<el-button type="success" icon="el-icon-yrt-wenjian1" @click.native="createMenuTree(formData, details)">生成菜单</el-button>
|
<!--缓存菜单-->
|
<el-button type="success" icon="el-icon-yrt-ruku1" @click.native="createMenuTreeCustom(formData, details)">生成自定义菜单</el-button>
|
</template>
|
</yrt-editor>
|
</div>
|
</split-pane>
|
</div>
|
</template>
|
|
<script>
|
import baseLayout from "@/components/common/base-layout.vue";
|
import splitPane from "@/components/splitPane";
|
|
export default {
|
name: "sys-dev-menu-app",
|
components: {
|
splitPane // 分割器
|
},
|
mixins: [baseLayout],
|
data() {
|
return {
|
filterText: "",
|
dataTree: [],
|
props: {
|
label: "label",
|
children: "children",
|
isLeaf: "isLeaf"
|
},
|
// 当前选中项
|
currentNode: null
|
};
|
},
|
methods: {
|
// 获得左侧类目导航节点数据
|
loadTreeNode(node, resolve) {
|
var the = this;
|
the.$nextTick(() => {
|
var where = "";
|
// var userInfo = this.common.getUserInfo();
|
if (node.level === 0) {
|
where = { parentId: 0 };
|
} else {
|
where = { parentId: node.data.menu_Id };
|
}
|
|
var url = "/api/common/loadTreeNode";
|
var params = {
|
DBServer: "Sys",
|
tableName: "Sys_MenuApp",
|
tableView: "Sys_MenuApp",
|
keyName: "menu_Id",
|
nodeName: "menuName",
|
fixHasChild: false,
|
isBreakWay: false,
|
displayBreakWay: false,
|
parentName: "parentId",
|
orderBy: { orderNo: "DESC", menu_Id: "ASC" },
|
where: where,
|
extendColumns: "",
|
folder: "sys/core"
|
};
|
the.common.ajax(
|
url,
|
params,
|
res => {
|
if (res.result) {
|
if (node.level === 0) {
|
res.data.push({
|
menu_Id: -1,
|
hasChild: "1",
|
menuName: "[未使用节点]"
|
});
|
}
|
res.data.forEach(element => {
|
element.label = element["menuName"];
|
element.isLeaf = !element.hasChild;
|
});
|
resolve(res.data);
|
} else {
|
the.$message.error(res.msg);
|
}
|
},
|
true
|
);
|
});
|
},
|
// 搜索导航
|
filterTreeNode(value, data) {
|
if (!value) return true;
|
return data.label.indexOf(value) !== -1;
|
},
|
// 点击tree导航节点
|
nodeClick(data, node, el) {
|
this.editor.editData(data.menu_Id);
|
},
|
|
// 刷新tree
|
treeRefresh() {
|
this.filterText = "";
|
var root = this.$refs.tree.store.root;
|
while (root.childNodes.length) {
|
this.$refs.tree.remove(root.childNodes[0]);
|
}
|
this.loadTreeNode(root, data => {
|
root.doCreateChildren(data);
|
});
|
},
|
// 生成菜单树
|
createMenuTree(formData, details) {
|
const url = "/api/sysmvc/createMenuTree";
|
const params = {
|
openNodeApi: true // 启用node api接口
|
};
|
this.common.ajax(
|
url,
|
params,
|
res => {
|
this.common.showMsg(res);
|
},
|
true
|
);
|
},
|
// 生成自定义菜单树
|
createMenuTreeCustom(formData, details) {
|
const url = "/api/sysmvc/createMenuTreeCustom";
|
const params = {};
|
this.common.ajax(
|
url,
|
params,
|
res => {
|
this.common.showMsg(res);
|
},
|
true
|
);
|
},
|
// 保存后事件
|
onSaveAfter(formData) {
|
var node = this.$refs.tree.getCurrentNode();
|
if (node.menu_Id !== formData.menu_Id) {
|
var parentNode = this.$refs.tree.getNode(node.parentId);
|
if (this.addLevel === "son") {
|
parentNode = this.$refs.tree.getNode(node.menu_Id);
|
} else {
|
node.menuName = formData.menuName;
|
node.label = formData.menuName;
|
}
|
this.$refs.tree.append(
|
{
|
hasChild: "0",
|
isLeaf: true,
|
menu_Id: formData.menu_Id,
|
sql: formData.sql,
|
menuName: formData.menuName,
|
label: formData.menuName
|
},
|
parentNode
|
);
|
this.$refs.tree.setCurrentKey(formData.menu_Id);
|
this.nodeClick(formData);
|
} else {
|
node.menuName = formData.menuName;
|
node.label = formData.menuName;
|
}
|
},
|
// 创建同级
|
createBrotherNode(formData, details) {
|
formData.menu_Id = 0;
|
formData.menuName = null;
|
formData.sql = null;
|
this.addLevel = "brother";
|
},
|
// 创建子级同级
|
createSonNode(formData, details) {
|
formData.parentId = formData.menu_Id;
|
formData.menu_Id = 0;
|
formData.menuName = null;
|
this.addLevel = "son";
|
},
|
// 删除节点
|
deleteNode(formData, details) {
|
const _deleteNode = () => {
|
var url = "/api/common/deleteTreeData";
|
var params = {
|
DBServer: "Sys",
|
tableName: "Sys_MenuApp",
|
tableView: "Sys_MenuApp",
|
keyName: "menu_Id",
|
keyValue: formData.menu_Id,
|
nodeName: "menuName",
|
parentName: "parentId",
|
extendColumns: "",
|
folder: "sys/core"
|
};
|
this.common.ajax(
|
url,
|
params,
|
res => {
|
this.common.showMsg(res);
|
if (res.result) {
|
this.$refs.tree.remove(formData.menu_Id);
|
}
|
},
|
true
|
);
|
};
|
this.$confirm("此操作将永久删除该节点, 是否继续?", "提示", {
|
confirmButtonText: "确定",
|
cancelButtonText: "取消",
|
type: "warning"
|
})
|
.then(() => {
|
_deleteNode();
|
})
|
.catch(() => {
|
this.$message({
|
type: "info",
|
message: "已取消删除"
|
});
|
});
|
},
|
// 复制节点
|
copyNode(formData, details) {
|
var url = "/api/common/copy";
|
var params = {
|
tableName: "Sys_MenuApp",
|
keyName: "menu_Id",
|
keyValue: formData.menu_Id,
|
nodeName: "menuName",
|
parentName: "parentId",
|
folder: "sys/core",
|
where: {
|
menu_Id: formData.menu_Id
|
}
|
};
|
this.common.ajax(
|
url,
|
params,
|
res => {
|
this.common.showMsg(res);
|
if (res.result) {
|
var node = this.$refs.tree.getCurrentNode();
|
var parentNode = this.$refs.tree.getNode(node.parentId);
|
var dataInfo = res.data[0];
|
this.$refs.tree.append(
|
{
|
hasChild: "0",
|
isLeaf: true,
|
menu_Id: dataInfo.menu_Id,
|
sql: formData.sql,
|
menuName: dataInfo.menuName,
|
label: dataInfo.menuName
|
},
|
parentNode
|
);
|
this.$refs.tree.setCurrentKey(dataInfo.menu_Id);
|
this.nodeClick(dataInfo);
|
}
|
},
|
true
|
);
|
}
|
}
|
};
|
</script>
|
|
<style lang="scss" scoped>
|
.page-list-container {
|
position: relative;
|
margin: 0px;
|
min-height: calc(100vh - 165px);
|
overflow-x: hidden;
|
|
.left-container {
|
width: 100%;
|
height: 100%;
|
background-color: white;
|
border-radius: 4px;
|
.form-tool {
|
padding-top: 10px;
|
.el-form-item {
|
padding: 0 10px;
|
}
|
.search-input {
|
width: calc(100% - 40px);
|
}
|
.btn-search,
|
.btn-refresh {
|
padding: 10px;
|
}
|
.btn-refresh {
|
margin-left: 0px;
|
}
|
}
|
::v-deep .el-tree-node.is-current > .el-tree-node__content {
|
background-color: #a7ccf7;
|
color: white;
|
.el-button--text {
|
color: white;
|
}
|
}
|
.custom-tree-node {
|
flex: 1;
|
display: flex;
|
align-items: center;
|
justify-content: space-between;
|
font-size: 14px;
|
padding-right: 8px;
|
}
|
::v-deep .tree.scrollbar-wrap {
|
max-height: calc(100vh - 138px);
|
overflow-x: hidden;
|
padding: 10px 10px 20px;
|
.el-tree {
|
margin-bottom: 10px;
|
}
|
}
|
}
|
|
.right-container {
|
border-radius: 4px;
|
min-height: 100%;
|
background-color: white;
|
padding: 0 10px;
|
}
|
}
|
</style>
|