152 lines
5.8 KiB
JavaScript
152 lines
5.8 KiB
JavaScript
const SYS_MENU_RECOMMEND_SETTING_COMPONENT = {
|
|
template: `
|
|
<el-dialog title="推荐配置" :visible.sync="dialogVisible" width="50%">
|
|
<el-row :gutter="20">
|
|
<el-col :span="12">
|
|
<el-input
|
|
v-model="menuKeyword"
|
|
clearable
|
|
prefix-icon="el-icon-search"
|
|
placeholder="请输入菜单名称搜索"
|
|
style="margin-bottom: 10px">
|
|
</el-input>
|
|
<el-tree ref="menuTree"
|
|
style="max-height: 450px;overflow-y: auto"
|
|
:data="menuData"
|
|
:check-on-click-node="true"
|
|
:filter-node-method="filterMenuNode"
|
|
node-key="id"
|
|
show-checkbox
|
|
@check-change="checkChange"
|
|
:props="defaultProps">
|
|
<span class="custom-tree-node" slot-scope="scope">
|
|
<span>{{ scope.node.label }}</span>
|
|
</span>
|
|
</el-tree>
|
|
</el-col>
|
|
<el-col :span="12">
|
|
<el-table :data="checkedNodes" max-height="500px">
|
|
<el-table-column type="index"></el-table-column>
|
|
<el-table-column label="名称" prop="name"></el-table-column>
|
|
<el-table-column label="图标" prop="icon">
|
|
<template scope="{row}">
|
|
<svg-icon :name="row.icon" v-if="platform==='PC'"></svg-icon>
|
|
<img v-else :src="row.icon" alt="" style="width: 30px;height: 30px">
|
|
</template>
|
|
</el-table-column>
|
|
</el-table>
|
|
</el-col>
|
|
</el-row>
|
|
<span slot="footer" class="dialog-footer">
|
|
<el-button @click="dialogVisible = false">取 消</el-button>
|
|
<el-button type="primary" @click="submit">确 定</el-button>
|
|
</span>
|
|
</el-dialog>
|
|
`,
|
|
data() {
|
|
return {
|
|
platform: null,
|
|
dialogVisible: false,
|
|
menuData: [],
|
|
menuKeyword: '',
|
|
defaultProps: {
|
|
children: "children",
|
|
label: "label"
|
|
},
|
|
|
|
checkedNodes: [],
|
|
checkedKeys: [],
|
|
|
|
type: '',
|
|
}
|
|
},
|
|
watch: {
|
|
menuKeyword(value) {
|
|
if (this.$refs.menuTree) {
|
|
this.$refs.menuTree.filter(value)
|
|
}
|
|
}
|
|
},
|
|
methods: {
|
|
onOpen(platform, type) {
|
|
this.platform = platform
|
|
this.type = type
|
|
this.checkedKeys = []
|
|
this.$set(this, 'menuKeyword', '')
|
|
this.dialogVisible = true
|
|
this.listTree()
|
|
},
|
|
|
|
// 仅过滤左侧菜单树的显示,不修改节点勾选状态,保证搜索前的选择仍能提交。
|
|
filterMenuNode(value, data) {
|
|
if (!value) {
|
|
return true
|
|
}
|
|
return (data.label || data.name || '').indexOf(value) !== -1
|
|
},
|
|
|
|
listTree() {
|
|
this.$axios.post("/platform/sys/menu/menuAll", { platform: this.platform }).then((res) => {
|
|
if (res.code === 0) {
|
|
this.setTreeDisabled(res.data)
|
|
this.menuData = res.data
|
|
console.log(this.checkedKeys)
|
|
//设置选中的节点
|
|
this.$refs.menuTree.setCheckedKeys(this.checkedKeys)
|
|
//获取选中的节点
|
|
this.$nextTick(() => {
|
|
this.checkedNodes = this.$refs.menuTree.getCheckedNodes(true, false)
|
|
})
|
|
}
|
|
})
|
|
},
|
|
|
|
setTreeDisabled(data) {
|
|
data.forEach((item) => {
|
|
if ((this.type === 'service' && item.isRecommendService) || (this.type === 'app' && item.isRecommendApp)) {
|
|
this.checkedKeys.push(item.id)
|
|
}
|
|
if (!item.href && item.type === "menu" && this.type === 'service') {
|
|
item.disabled = true
|
|
}
|
|
if (this.type === 'app') {
|
|
delete item.children
|
|
}
|
|
if (item.children && item.children.length) {
|
|
this.setTreeDisabled(item.children)
|
|
}
|
|
})
|
|
},
|
|
|
|
checkChange(currObj, isChecked) {
|
|
this.checkedNodes = this.$refs.menuTree.getCheckedNodes(true, false)
|
|
},
|
|
|
|
submit() {
|
|
this.$confirm("您确定要提交吗?", "提示", {
|
|
type: "warning"
|
|
}).then(() => {
|
|
// 提交时从完整菜单树读取选中节点,搜索隐藏的已选节点也必须保留。
|
|
const selectedNodes = this.$refs.menuTree
|
|
? this.$refs.menuTree.getCheckedNodes(true, false)
|
|
: this.checkedNodes
|
|
this.$axios
|
|
.post("/platform/sys/menu/updateRecommendSetting", {
|
|
menuIds: JSON.stringify(selectedNodes.map((item) => item.id)),
|
|
platform: this.platform,
|
|
type: this.type
|
|
})
|
|
.then((resp) => {
|
|
if (resp.code === 0) {
|
|
this.checkedKeys = []
|
|
this.listTree()
|
|
this.$message.success(resp.msg)
|
|
this.$emit("refresh", null)
|
|
}
|
|
})
|
|
})
|
|
}
|
|
},
|
|
created() {}
|
|
}
|