2023-12-18 17:16:47 +08:00
|
|
|
|
<template>
|
|
|
|
|
<el-dialog v-model="dialogVisible" width="30%">
|
|
|
|
|
<template #header>
|
|
|
|
|
<span class="el-dialog__title" style="margin-right: 50px;">授权权限</span>
|
|
|
|
|
<el-checkbox v-model="toggleExpand" @change="toggleExpandChange">展开 / 折叠</el-checkbox>
|
|
|
|
|
<el-checkbox v-model="toggleSelectAll" @change="toggleSelectAllChange">全选 / 全不选</el-checkbox>
|
|
|
|
|
</template>
|
2023-12-27 16:49:37 +08:00
|
|
|
|
<div style="min-height: 200px;max-height: 500px;overflow-y: auto;">
|
|
|
|
|
<el-tree ref="treeRef" :key="treeKey" :props="props" :data="treeData" :default-expanded-keys="expandedKey" node-key="id"
|
|
|
|
|
show-checkbox @check-change="checkChange" />
|
|
|
|
|
</div>
|
2023-12-18 17:16:47 +08:00
|
|
|
|
<div style="text-align: right;margin-top: 20px;">
|
|
|
|
|
<el-button class="f18" @click="dialogVisible = false">取消</el-button>
|
|
|
|
|
<el-button class="f18" type="primary" @click="updateData">更新</el-button>
|
|
|
|
|
</div>
|
|
|
|
|
</el-dialog>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang='ts' setup>
|
|
|
|
|
import { onMounted, reactive, ref, toRefs, watch } from 'vue'
|
|
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
2023-12-28 14:26:39 +08:00
|
|
|
|
import { getMenuData } from '@/static-data/menu'
|
2023-12-18 17:16:47 +08:00
|
|
|
|
|
|
|
|
|
const props = {
|
2023-12-28 14:26:39 +08:00
|
|
|
|
label: 'menuName',
|
2023-12-18 17:16:47 +08:00
|
|
|
|
children: 'children'
|
|
|
|
|
}
|
|
|
|
|
let treeIds: Array<string> = []
|
|
|
|
|
let checkDatas: Array<any> = []
|
|
|
|
|
|
|
|
|
|
const treeRef = ref()
|
|
|
|
|
const treeKey = ref(0)
|
|
|
|
|
const dialogVisible = ref(false)
|
|
|
|
|
const toggleExpand = ref(false)
|
|
|
|
|
const toggleSelectAll = ref(false)
|
|
|
|
|
const treeData = ref()
|
|
|
|
|
const expandedKey = ref<Array<string>>([])
|
|
|
|
|
|
|
|
|
|
initTree()
|
|
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
|
open,
|
|
|
|
|
close,
|
|
|
|
|
initTree,
|
|
|
|
|
})
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
function open() {
|
|
|
|
|
dialogVisible.value = true
|
|
|
|
|
setTimeout(() => {
|
2023-12-28 14:26:39 +08:00
|
|
|
|
setTreeChecked(['0'])
|
2023-12-18 17:16:47 +08:00
|
|
|
|
}, 0)
|
|
|
|
|
}
|
|
|
|
|
function close() {
|
|
|
|
|
dialogVisible.value = false
|
|
|
|
|
}
|
|
|
|
|
function initTree() {
|
|
|
|
|
treeData.value = [
|
|
|
|
|
{
|
|
|
|
|
id: '1', label: '权限管理', children: [
|
|
|
|
|
{
|
|
|
|
|
id: '1-1', label: '医生管理', children: [
|
|
|
|
|
{ id: '1-1-1', label: '医生新增' },
|
|
|
|
|
{ id: '1-1-2', label: '医生删除' }
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: '2', label: '患者管理', children: [
|
|
|
|
|
{
|
|
|
|
|
id: '2-1', label: '医生管理', children: [
|
|
|
|
|
{ id: '2-1-1', label: '医生新增' }
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
|
|
|
|
}
|
|
|
|
|
]
|
2023-12-28 14:26:39 +08:00
|
|
|
|
treeData.value = getMenuData()
|
2023-12-18 17:16:47 +08:00
|
|
|
|
treeIds = []
|
2023-12-28 14:26:39 +08:00
|
|
|
|
const setTreeIds = (ary: any) => {
|
|
|
|
|
for (let i = 0; i < ary.length; i++) {
|
|
|
|
|
const obj = ary[i]
|
|
|
|
|
treeIds.push(obj.id)
|
|
|
|
|
if(obj.children && obj.children.length > 0) setTreeIds(obj.children)
|
2023-12-18 17:16:47 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2023-12-28 14:26:39 +08:00
|
|
|
|
// 储存所有节点id,全选、展开使用
|
|
|
|
|
setTreeIds(treeData.value)
|
2023-12-18 17:16:47 +08:00
|
|
|
|
}
|
|
|
|
|
function setTreeChecked(e?: Array<any>) {
|
|
|
|
|
e && treeRef.value.setCheckedKeys(e)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const toggleExpandChange = (e: boolean) => {
|
|
|
|
|
if (e) expandedKey.value = JSON.parse(JSON.stringify(treeIds))
|
|
|
|
|
else {
|
|
|
|
|
expandedKey.value = []
|
|
|
|
|
const storeCheck = JSON.parse(JSON.stringify(checkDatas)) // 储存上次更新的值
|
|
|
|
|
treeKey.value++ // 刷新组件
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
setTreeChecked(storeCheck)
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const toggleSelectAllChange = (e: boolean) => {
|
2023-12-28 17:58:59 +08:00
|
|
|
|
// console.log(e)
|
2023-12-18 17:16:47 +08:00
|
|
|
|
if (!e) treeRef.value.setCheckedNodes(treeIds)
|
|
|
|
|
else treeRef.value.setCheckedKeys(treeIds)
|
|
|
|
|
}
|
|
|
|
|
const checkChange = () => {
|
|
|
|
|
checkDatas = treeRef.value.getCheckedKeys()
|
|
|
|
|
}
|
|
|
|
|
const updateData = () => {
|
|
|
|
|
ElMessage.success('更新成功')
|
|
|
|
|
close()
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style lang='scss' scoped></style>
|