解决按钮权限覆盖的问题,权限展示所有菜单,角色修改时回显子节点勾选的问题,统计分析生命周期获取数据接口问题

This commit is contained in:
ym1026
2025-11-12 14:13:10 +08:00
parent ac17c41900
commit 450aff0eff
8 changed files with 227 additions and 249 deletions

View File

@@ -53,6 +53,7 @@
:table-info="tableList[activeKey].tableInfo"
:table-data="tableList[activeKey].tableData"
@pagesizeChange="pagesizeChange"
>
</energyEchart>
</a-spin>
@@ -635,20 +636,24 @@ export default {
})
})
},
immediate: true // 添加立即执行
// immediate: true // 添加立即执行
}
},
async mounted() {
mounted() {
console.log('mounted')
// 优先加载第一个页面(activeKey=1)所需的数据
this.btnOptionList = this.$getBtns(['导出'])
await Promise.all([
this.getStationList(),
Promise.all([
this.getStationList()
]).then(()=>{
this.getEchartsListForActiveKey(),
this.getTableListForActiveKey()
])
this.getStatCharts()
this.startRealtimeRefresh()
})
// 初始化实时刷新
this.startRealtimeRefresh()
},
beforeUnmount() {
clearInterval(this.interval) // 组件销毁时清除定时器
@@ -731,6 +736,7 @@ export default {
},
// 专门获取当前激活页面的表格数据
async getTableListForActiveKey() {
console.log( this.stationId,'getTableListForActiveKey')
this.loading.table = true
if (!this.activeKey) return
@@ -771,6 +777,7 @@ export default {
},
async getStationList() {
console.log('getsStationList')
const params = {
page_size: 1000,
page: 1
@@ -807,7 +814,7 @@ export default {
this.paramsDate.start_date = data.time ? data.time[0] : ''
this.paramsDate.end_date = data.time ? data.time[1] : ''
this.tableList[this.activeKey].pageOption.page = 1
this.getStationList(), this.getEchartsListForActiveKey(), this.getTableListForActiveKey()
this.getStationList(), this.getStatCharts(),this.getEchartsListForActiveKey(), this.getTableListForActiveKey()
},
changeStation() {
this.getStatCharts()

View File

@@ -70,7 +70,8 @@ export default {
btnOptionList: [],
paramsDate: {},
tableOption: {
select: false
select: false,
scroll:{y:600}
}
}
},
@@ -110,7 +111,7 @@ export default {
this.$refs.comTable.loading = false
// this.tableData = res.data
this.tableData = JSON.parse(localStorage.getItem('permission')).map((item) => {
this.tableData = res.data.map((item) => {
return {
...item,
key: item.permission_id
@@ -203,6 +204,10 @@ export default {
padding: 20px 20px 0 20px;
.content-table {
height: calc(100% - 92px);
.treetable{
// overflow: scroll;
}
}
}
</style>

View File

@@ -151,7 +151,7 @@ export default {
is_edit: Boolean(+item.is_edit) || false,
is_view: Boolean(+item.is_view) || false,
// 确保子权限容器存在
children: item.children ? [...item.children] : []
children: item.children ? [...item.children] :undefined
}
permissionMap.set(item.permission_id, permissionItem)
@@ -183,7 +183,7 @@ export default {
...routeItem,
...permissionItem,
// 初始化子权限容器
children: routeItem.children ? buildTree(routeItem.children) : []
children: routeItem.children ? buildTree(routeItem.children) : undefined
}
// 特殊处理:父级权限的联动计算
@@ -204,52 +204,9 @@ export default {
node.is_del = node.children.some((child) => child.is_del === '1') ? true : false
}
},
async getPermissionList() {
let arr = []
const res = await getReq('/queryPermissionList', { page_size: 1000, page: 1 })
if (res.errcode === 0) {
arr = res.data
// const permissionData = JSON.parse(localStorage.getItem('permission'));
// const permissionData = res.data
// arr = permissionData.map((item) => ({
// ...item,
// key: item.permission_id,
// // 转换操作权限为布尔值
// ...this.getPerOperBoolean(item),
// // 递归处理children
// children: item.children
// ? item.children.map((child) => ({
// ...child,
// ...this.getPerOperBoolean(child),
// key: child.permission_id,
// // 继续递归处理子项
// children: child.children
// ? child.children.map((grandchild) => ({
// ...grandchild,
// ...this.getPerOperBoolean(grandchild)
// }))
// : []
// }))
// : []
// }))
}
return arr
},
// 新增专用方法处理操作权限转换
getPerOperBoolean(data) {
return {
is_add: data ? Boolean(+data.is_add) : false,
is_del: data ? Boolean(+data.is_del) : false,
is_edit: data ? Boolean(+data.is_edit) : false,
is_view: data ? Boolean(+data.is_view) : false
}
},
operateForm(type, record = {}) {
this.formStatus = type
switch (type) {
@@ -318,49 +275,70 @@ export default {
row = record
}
const perList = await this.getPermissionList()
function markCheckedPermissions(tree, rolePerms) {
return tree.map((perm) => {
// 深拷贝权限项,避免污染原始数据
const node = { ...perm };
// 检查当前权限是否被角色勾选
const isChecked = rolePerms.some(
(rp) => rp.permission_id === node.permission_id
);
console.log(isChecked,rolePerms,"isChecked")
node.checked = isChecked;
// 递归处理子权限
if (node.children && node.children.length > 0) {
// 找到角色权限中对应的子权限列表
const roleChildPerms = rolePerms.find(
(rp) => rp.permission_id === node.permission_id
)?.children || [];
node.children = markCheckedPermissions(node.children, roleChildPerms);
}else {
node.children =undefined
}
return node;
});
}
const newData = markCheckedPermissions(perList, record.permission);
this.processedData = this.mergePermissionData(
perList,
newData,
record && record.permission.length ? record.permission : []
)
const newData = JSON.parse(JSON.stringify(this.processedData))
// const newData = JSON.parse(JSON.stringify(this.processedData))
this.formModal = true
roleOptions.forEach((e, index) => {
e.list.forEach((i) => {
if (i.key == 'permission') {
i.tableData = newData
if (record && record.role_id) {
i.selectTableData = this.extractAllIds(record.permission)
} else {
i.selectTableData = []
}
i.tableData = this.processedData
} else {
e.ruleForm[i.key] = row ? row[i.key] : ''
}
})
})
this.formModal = true
},
// 定义提取所有ID的函数
extractAllIds(treeData) {
const idSet = new Set()
async getPermissionList() {
let arr = []
const res = await getReq('/queryPermissionList', { page_size: 1000, page: 1 })
// 递归遍历函数
const traverse = (node) => {
// 添加当前节点ID
if (node.permission_id) {
idSet.add(node.permission_id)
}
if (res.errcode === 0) {
arr = res.data
// 递归处理子节点
if (node.children && node.children.length > 0) {
node.children.forEach((child) => traverse(child))
}
}
// 处理所有根节点
treeData.forEach((node) => traverse(node))
return Array.from(idSet)
return arr
},
handlePagesizeChange(pageOption) {
this.pageOption.pageSize = pageOption.pageSize