first commit
This commit is contained in:
@@ -0,0 +1,350 @@
|
||||
<!--#
|
||||
layout("/layouts/platform.html"){
|
||||
#-->
|
||||
<style>
|
||||
.context-menu {
|
||||
position: fixed;
|
||||
background: #fff;
|
||||
border: 1px solid #dcdfe6;
|
||||
border-radius: 4px;
|
||||
box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
|
||||
z-index: 3000;
|
||||
list-style: none;
|
||||
padding: 5px 0;
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
}
|
||||
.context-menu li {
|
||||
padding: 7px 20px;
|
||||
cursor: pointer;
|
||||
}
|
||||
.context-menu li:hover {
|
||||
background: #f2f6fc;
|
||||
}
|
||||
</style>
|
||||
<div id="app" v-cloak>
|
||||
<el-card shadow="never">
|
||||
<search @search="doSearch">
|
||||
<search-item label="平台">
|
||||
<el-select v-model="pageForm.platform" :clearable="false" @change="listModule();doSearch();">
|
||||
<el-option v-for="item in dict.type.SYS_MENU_PLATFORM" :value="item.code" :key="item.value" :label="item.label"></el-option>
|
||||
</el-select>
|
||||
</search-item>
|
||||
<search-item label="模块">
|
||||
<el-select v-model="pageForm.moduleId" clearable placeholder="请选择模块">
|
||||
<el-option v-for="item in moduleOptions" :value="item.id" :key="item.id" :label="item.name"></el-option>
|
||||
</el-select>
|
||||
</search-item>
|
||||
<search-item label="菜单名称">
|
||||
<el-input v-model="pageForm.menuName" clearable placeholder="请填写名称查询" style="width: 100%"></el-input>
|
||||
</search-item>
|
||||
</search>
|
||||
</el-card>
|
||||
<el-card class="mt10" shadow="never">
|
||||
<table-tool>
|
||||
<el-button @click="$refs.basicFormRef.onOpen(null,pageForm.platform)" size="small" type="primary" icon="el-icon-plus">新建菜单</el-button>
|
||||
<el-button @click="$refs.sortRef.onOpen(pageForm.platform)" size="small" type="primary" icon="el-icon-sort">排序</el-button>
|
||||
<el-button @click="$refs.recommendSettingRef.onOpen(pageForm.platform, 'app')" size="small" type="primary" icon="el-icon-monitor">
|
||||
首页推荐应用
|
||||
</el-button>
|
||||
<el-button @click="$refs.recommendSettingRef.onOpen(pageForm.platform, 'service')" size="small" type="primary" icon="el-icon-monitor">
|
||||
首页推荐服务
|
||||
</el-button>
|
||||
</table-tool>
|
||||
<el-table
|
||||
:data="tableData"
|
||||
:highlight-current-row="true"
|
||||
:key="tableKey"
|
||||
:load="loadChild"
|
||||
@row-contextmenu="openMenu"
|
||||
:expand-row-keys="expandedRowKeysRenew"
|
||||
@expand-change="handleExpandChange"
|
||||
ref="tableData"
|
||||
style="width: 100%"
|
||||
lazy
|
||||
row-key="id"
|
||||
>
|
||||
<el-table-column align="left" header-align="left" label="菜单名称" prop="name" width="200"></el-table-column>
|
||||
<el-table-column align="center" header-align="center" label="菜单图标" prop="icon" width="100">
|
||||
<template slot-scope="scope">
|
||||
<template v-if="pageForm.platform==='PC'">
|
||||
<svg-icon :name="scope.row.icon" v-if="scope.row.icon" :size="20"></svg-icon>
|
||||
</template>
|
||||
<template v-else-if="pageForm.platform==='H5'">
|
||||
<el-image :src="scope.row.icon" v-if="scope.row.icon" style="width: 30px; height: 30px"></el-image>
|
||||
</template>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :show-overflow-tooltip="true" header-align="center" label="URL" prop="href"></el-table-column>
|
||||
<el-table-column :show-overflow-tooltip="true" align="center" header-align="center" label="资源类型" prop="type">
|
||||
<template slot-scope="scope">
|
||||
<i style="font-weight: bold" v-if="scope.row.type=='menu'">菜单</i>
|
||||
<i v-if="scope.row.type=='data'">数据</i>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" header-align="center" label="所属模块" prop="moduleId">
|
||||
<template slot-scope="scope">
|
||||
<i style="font-weight: bold">{{moduleOptions.find(item=>item.id==scope.row.moduleId)?.name}}</i>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column align="center" header-align="center" label="权限标识" prop="permission"></el-table-column>
|
||||
<el-table-column align="center" header-align="center" label="启用状态" prop="disabled">
|
||||
<template slot-scope="scope">
|
||||
<i class="fa fa-circle text-danger ml5" v-if="scope.row.disabled"></i>
|
||||
<i class="fa fa-circle text-success ml5" v-if="!scope.row.disabled"></i>
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column :show-overflow-tooltip="true" align="center" header-align="center" label="操作" prop="website" width="120">
|
||||
<template slot-scope="scope">
|
||||
<el-dropdown @command="dropdownCommand">
|
||||
<el-button size="mini">
|
||||
<i class="ti-settings"></i>
|
||||
<span class="ti-angle-down"></span>
|
||||
</el-button>
|
||||
<el-dropdown-menu slot="dropdown">
|
||||
<!-- <el-dropdown-item :command="{type:'add',id:scope.row.id,name:scope.row.name}" v-if="scope.row.type=='menu'">-->
|
||||
<!-- 添加子菜单-->
|
||||
<!-- </el-dropdown-item>-->
|
||||
<el-dropdown-item :command="{type:'enable',id:scope.row.id,name:scope.row.name,row:scope.row}" divided>
|
||||
启用
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'disable',id:scope.row.id,name:scope.row.name,row:scope.row}">禁用</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'editMenu',id:scope.row.id,name:scope.row.name}" divided v-if="scope.row.type=='menu'">
|
||||
修改
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'editData',id:scope.row.id,name:scope.row.name}" divided v-if="scope.row.type=='data'">
|
||||
修改
|
||||
</el-dropdown-item>
|
||||
<el-dropdown-item :command="{type:'delete',id:scope.row.id,name:scope.row.name}" v-if="scope.row.path!='0001'">
|
||||
删除
|
||||
</el-dropdown-item>
|
||||
</el-dropdown-menu>
|
||||
</el-dropdown>
|
||||
</template>
|
||||
</el-table-column>
|
||||
</el-table>
|
||||
|
||||
<!-- 右键菜单 -->
|
||||
<ul v-show="menuVisible" class="context-menu" :style="{left: menuLeft + 'px', top: menuTop + 'px'}">
|
||||
<li @click="handleAddMenu(currentRow)">新建菜单</li>
|
||||
<li v-if="showAddMenu" @click="handleAddChildMenu(currentRow)">添加子菜单</li>
|
||||
<li @click="handleEdit(currentRow)">编辑</li>
|
||||
<li @click="handleDelete(currentRow)">删除</li>
|
||||
</ul>
|
||||
|
||||
</el-card>
|
||||
|
||||
|
||||
<basic-form ref="basicFormRef" @refresh="loadChildByExpandedKeys"></basic-form>
|
||||
<permission-form ref="permissionFormRef" @load-child="loadChildByExpandedKeys"></permission-form>
|
||||
<sort ref="sortRef" @refresh="doSearch"></sort>
|
||||
<recommend-setting ref="recommendSettingRef" @refresh="doSearch"></recommend-setting>
|
||||
</div>
|
||||
<script nonce="${cspNonce!}">
|
||||
<!--#include("permissionForm.js"){}#-->
|
||||
<!--#include("basicForm.js"){}#-->
|
||||
<!--#include("sort.js"){}#-->
|
||||
<!--#include("recommendSetting.js"){}#-->
|
||||
new Vue({
|
||||
el: "#app",
|
||||
dicts: ["SYS_MENU_PLATFORM"],
|
||||
components: {
|
||||
"basic-form": SYS_MENU_BASIC_FORM_COMPONENT,
|
||||
"permission-form": SYS_MENU_PERMISSION_FORM_COMPONENT,
|
||||
sort: SYS_MENU_SORT_COMPONENT,
|
||||
"recommend-setting": SYS_MENU_RECOMMEND_SETTING_COMPONENT
|
||||
},
|
||||
|
||||
data: function () {
|
||||
return {
|
||||
pageForm: {},
|
||||
tableData: [],
|
||||
tableKey: "",
|
||||
moduleOptions: [],
|
||||
// 保存展开状态的数组
|
||||
expandedRowKeysRenew: [],
|
||||
tableTreeRefreshTool: [],
|
||||
|
||||
// 右键打开菜单相关
|
||||
currentRow: null,
|
||||
menuVisible: false,
|
||||
menuLeft: 0,
|
||||
menuTop: 0,
|
||||
showAddMenu: false,
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
/* 右键行 */
|
||||
openMenu(row, column, event) {
|
||||
this.showAddMenu = row.type === 'menu';
|
||||
// 阻止浏览器默认菜单
|
||||
event.preventDefault();
|
||||
this.currentRow = row;
|
||||
|
||||
this.menuVisible = true;
|
||||
this.$nextTick(() => {
|
||||
const menu = this.$el.querySelector('.context-menu');
|
||||
const h = menu.offsetHeight || 100;
|
||||
const sh = document.documentElement.clientHeight;
|
||||
let top = event.clientY;
|
||||
if (top + h > sh) top -= h;
|
||||
this.menuLeft = event.clientX;
|
||||
this.menuTop = top;
|
||||
});
|
||||
},
|
||||
// 新建菜单
|
||||
handleAddMenu(row) {
|
||||
console.log(row)
|
||||
this.$refs.basicFormRef.onOpen(null, this.pageForm.platform)
|
||||
},
|
||||
handleAddChildMenu(row) {
|
||||
this.$refs.basicFormRef.addChildMenu(row, this.pageForm.platform)
|
||||
},
|
||||
handleEdit(row) {
|
||||
// 判断子菜单的type是权限还是菜单
|
||||
if (row.type === 'menu') {
|
||||
this.$refs.basicFormRef.onOpen(row.id, this.pageForm.platform)
|
||||
} else {
|
||||
this.$refs.permissionFormRef.onOpen(row.id)
|
||||
}
|
||||
},
|
||||
handleDelete(row) {
|
||||
// 删除逻辑
|
||||
console.log(row)
|
||||
this.$confirm("此操作将删除 " + row.name, "提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(() => {
|
||||
this.$axios.post("/platform/sys/menu/delete/" + row.id).then((res) => {
|
||||
if (res.code === 0) {
|
||||
this.$message.success(res.msg)
|
||||
this.loadChildByExpandedKeys()
|
||||
}
|
||||
})
|
||||
})
|
||||
},
|
||||
doSearch() {
|
||||
this.initTreeTable()
|
||||
},
|
||||
initTreeTable() {
|
||||
this.$axios
|
||||
.post("/platform/sys/menu/child", {
|
||||
pid: "",
|
||||
...this.pageForm
|
||||
})
|
||||
.then((res) => {
|
||||
if (res.code === 0) {
|
||||
this.tableData = res.data
|
||||
this.tableKey = +new Date()
|
||||
}
|
||||
})
|
||||
},
|
||||
loadChild: function (tree, treeNode, resolve) {
|
||||
// 在之前声明的全局变量中,增加一个key为 本条数据的id,id可替换为你数据中的任意唯一值
|
||||
this.tableTreeRefreshTool[tree.id] = {}
|
||||
// 重要!保存resolve方法,以便后续使用
|
||||
this.tableTreeRefreshTool[tree.id].resolve = resolve
|
||||
// 记录展开次数,具体作用后续介绍
|
||||
this.tableTreeRefreshTool[tree.id].expandCount = 0
|
||||
const url = "/platform/sys/menu/child"
|
||||
this.$axios.post(url, { pid: tree.id }).then((res) => {
|
||||
if (res.code === 0) {
|
||||
resolve(res.data)
|
||||
}
|
||||
})
|
||||
},
|
||||
dropdownCommand(command) {
|
||||
//监听下拉框事件
|
||||
// if ("add" === command.type) {
|
||||
// this.$refs.basicFormRef.onOpenAdd(command.id, this.pageForm.platform)
|
||||
// }
|
||||
if ("editMenu" === command.type) {
|
||||
this.$refs.basicFormRef.onOpen(command.id, this.pageForm.platform)
|
||||
}
|
||||
if ("editData" === command.type) {
|
||||
this.$refs.permissionFormRef.onOpen(command.id)
|
||||
}
|
||||
if ("enable" === command.type || "disable" === command.type) {
|
||||
this.$axios.post("/platform/sys/menu/" + command.type + "/" + command.id).then((res) => {
|
||||
if (res.code === 0) {
|
||||
this.$message.success(res.msg)
|
||||
if ("disable" === command.type) {
|
||||
command.row.disabled = true
|
||||
}
|
||||
if ("enable" === command.type) {
|
||||
command.row.disabled = false
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
if ("delete" === command.type) {
|
||||
this.$confirm("此操作将删除 " + command.name, "提示", {
|
||||
confirmButtonText: "确定",
|
||||
cancelButtonText: "取消",
|
||||
type: "warning"
|
||||
}).then(() => {
|
||||
this.$axios.post("/platform/sys/menu/delete/" + command.id).then((res) => {
|
||||
if (res.code === 0) {
|
||||
this.$message.success(res.msg)
|
||||
this.loadChildByExpandedKeys()
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
},
|
||||
handleExpandChange(row, expanded) {
|
||||
if ((row.parentId === "" || row.parentId == null) && !expanded) {
|
||||
this.expandedRowKeysRenew = []
|
||||
return
|
||||
}
|
||||
if (expanded) {
|
||||
this.expandedRowKeysRenew.push(row.id)
|
||||
} else {
|
||||
const index = this.expandedRowKeysRenew.findIndex((v) => v === row.id)
|
||||
this.expandedRowKeysRenew.splice(index, 1)
|
||||
}
|
||||
},
|
||||
loadChildByExpandedKeys() {
|
||||
if (this.expandedRowKeysRenew && this.expandedRowKeysRenew.length > 0) {
|
||||
this.expandedRowKeysRenew.forEach((v) => {
|
||||
const curr = this.tableTreeRefreshTool[v]
|
||||
// api请求
|
||||
$.get("/platform/sys/menu/child", { pid: v }).then((res) => {
|
||||
curr.resolve(res.data)
|
||||
})
|
||||
})
|
||||
} else {
|
||||
this.initTreeTable()
|
||||
}
|
||||
},
|
||||
|
||||
listModule() {
|
||||
this.$axios.post(loc() + "/listModule", { platform: this.pageForm.platform }).then((res) => {
|
||||
if (res.code === 0) {
|
||||
this.moduleOptions = res.data
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
// 点击任意处关闭菜单
|
||||
document.addEventListener('click', () => (this.menuVisible = false));
|
||||
},
|
||||
beforeDestroy() {
|
||||
document.removeEventListener('click', () => (this.menuVisible = false));
|
||||
},
|
||||
created() {
|
||||
setTimeout(() => {
|
||||
if (this.dict.type.SYS_MENU_PLATFORM) {
|
||||
this.pageForm.platform = this.dict.type.SYS_MENU_PLATFORM[0].code
|
||||
this.listModule()
|
||||
this.initTreeTable()
|
||||
}
|
||||
}, 500)
|
||||
}
|
||||
})
|
||||
</script>
|
||||
<!--#
|
||||
}
|
||||
#-->
|
||||
Reference in New Issue
Block a user