mirror of
https://gitee.com/js-yhsec/energy_storage.git
synced 2026-05-27 18:59:26 +08:00
修改菜单+权限+图表渲染
This commit is contained in:
@@ -13,7 +13,6 @@
|
||||
ref="comTable"
|
||||
:table-option="tableOption"
|
||||
:page-option="pageOption"
|
||||
:table-h="tableH"
|
||||
>
|
||||
<template #type="record">
|
||||
<span>{{ ['其它','系统日志','操作日志','设备日志'][record.type] }}</span>
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
ref="comTable"
|
||||
:table-option="tableOption"
|
||||
:page-option="pageOption"
|
||||
:table-h="tableH"
|
||||
>
|
||||
<template #gender="record">
|
||||
<!-- 0:女; 1:男 -->
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
ref="comTable"
|
||||
:table-option="tableOption"
|
||||
:page-option="pageOption"
|
||||
:table-h="tableH"
|
||||
>
|
||||
<template #is_open="record">
|
||||
<!-- 0:禁用; 1:启用 -->
|
||||
@@ -104,8 +103,14 @@ export default {
|
||||
if (res.errcode === 0) {
|
||||
this.$refs.comTable.loading = false
|
||||
|
||||
this.tableData = res.data
|
||||
|
||||
// this.tableData = res.data
|
||||
this.tableData =JSON.parse( localStorage.getItem('permission')).map((item)=>{
|
||||
return {
|
||||
...item,
|
||||
key:item.permission_id,
|
||||
}
|
||||
})
|
||||
console.log( this.tableData," this.tableData")
|
||||
this.pageOption = {
|
||||
page: res.page,
|
||||
pageSize: res.page_size,
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
ref="comTable"
|
||||
:table-option="tableOption"
|
||||
:page-option="pageOption"
|
||||
:table-h="tableH"
|
||||
>
|
||||
<template #type="record">
|
||||
<div>{{ getPolicyType(record.type) }}</div>
|
||||
@@ -117,7 +116,6 @@ export default {
|
||||
pageSize: 10,
|
||||
count: 0
|
||||
},
|
||||
tableH: '',
|
||||
formState: {},
|
||||
formStatus: 'add', //表单状态辑状态 add:新增 edit:编辑
|
||||
operateList:[]
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
ref="comTable"
|
||||
:table-option="tableOption"
|
||||
:page-option="pageOption"
|
||||
:table-h="tableH"
|
||||
>
|
||||
<template #is_open="record">
|
||||
<!-- 0:禁用; 1:启用 -->
|
||||
@@ -31,10 +30,10 @@
|
||||
</template>
|
||||
</ComTable>
|
||||
</div>
|
||||
<a-modal v-model:open="formModal" width="750px" style="top: 20px" :footer="null">
|
||||
<a-modal v-model:open="formModal" width="950px" style="top: 20px" :footer="null" :destroy-on-close="true">
|
||||
<!-- action:edit add -->
|
||||
<EditCom
|
||||
:show-flag="formModal"
|
||||
:show-flag="formModal"
|
||||
:record="record"
|
||||
@operateForm="operateForm"
|
||||
type="role"
|
||||
@@ -50,7 +49,7 @@ import { getReq, postReq } from '@/request/api.js'
|
||||
import ComTable from '@/components/ComTable'
|
||||
import OperateCom from '@/components/OperateCom'
|
||||
import EditCom from '@/components/EditCom.vue'
|
||||
import { ExclamationCircleOutlined } from '@ant-design/icons-vue'
|
||||
import { ConsoleSqlOutlined, ExclamationCircleOutlined } from '@ant-design/icons-vue'
|
||||
import { createVNode } from 'vue'
|
||||
import { Modal } from 'ant-design-vue'
|
||||
import searchBox from '@/components/SearchBox.vue'
|
||||
@@ -73,7 +72,10 @@ export default {
|
||||
page: 1
|
||||
},
|
||||
btnOptionList: [],
|
||||
paramsDate: {}
|
||||
paramsDate: {},
|
||||
tableOption: {
|
||||
select:false
|
||||
},
|
||||
}
|
||||
},
|
||||
computed: {},
|
||||
@@ -126,24 +128,123 @@ export default {
|
||||
//统一处理报错提示
|
||||
}
|
||||
},
|
||||
mergePermissionData(routeData, permissionData) {
|
||||
// 创建权限ID快速索引
|
||||
const permissionMap = new Map()
|
||||
|
||||
// 构建权限配置映射表(含子权限处理)
|
||||
const flattenPermissions = (data) => {
|
||||
data.forEach((item) => {
|
||||
// 初始化权限项的默认值(关键修改)
|
||||
const permissionItem = {
|
||||
...item,
|
||||
key: item.permission_id,
|
||||
is_add: Boolean(+item.is_add) || false,
|
||||
is_del: Boolean(+item.is_del )|| false,
|
||||
is_edit: Boolean(+item.is_edit )|| false,
|
||||
is_view: Boolean(+item.is_view )|| false,
|
||||
// 确保子权限容器存在
|
||||
children: item.children ? [...item.children] : []
|
||||
}
|
||||
|
||||
permissionMap.set(item.permission_id, permissionItem)
|
||||
|
||||
// 递归处理子权限
|
||||
if (item.children?.length) {
|
||||
flattenPermissions(item.children)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
// 初始化扁平化处理
|
||||
flattenPermissions(permissionData)
|
||||
|
||||
// 递归构建合并后的树形结构
|
||||
const buildTree = (data) => {
|
||||
return data
|
||||
.map((routeItem) => {
|
||||
const permissionItem = permissionMap.get(routeItem.permission_id) || {
|
||||
key: routeItem.permission_id,
|
||||
is_add: false,
|
||||
is_del: false,
|
||||
is_edit: false,
|
||||
is_view: false
|
||||
}
|
||||
|
||||
// 基础合并:路由结构+权限配置
|
||||
const mergedItem = {
|
||||
...routeItem,
|
||||
...permissionItem,
|
||||
// 初始化子权限容器
|
||||
children: routeItem.children ? buildTree(routeItem.children) : []
|
||||
}
|
||||
|
||||
// 特殊处理:父级权限的联动计算
|
||||
this.calculateParentPermissions(mergedItem)
|
||||
|
||||
return mergedItem
|
||||
})
|
||||
.filter(Boolean) // 过滤无效节点
|
||||
}
|
||||
|
||||
return buildTree(routeData)
|
||||
},
|
||||
calculateParentPermissions(node) {
|
||||
if (node.children?.length) {
|
||||
node.is_view = node.children.some((child) => child.is_view === '1') ? true:false
|
||||
node.is_add = node.children.some((child) => child.is_add === '1') ? true:false
|
||||
node.is_edit = node.children.some((child) => child.is_edit === '1') ? true:false
|
||||
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 })
|
||||
|
||||
const params = {
|
||||
page_size: 1000,
|
||||
page: 1
|
||||
}
|
||||
|
||||
const res = await getReq('/queryPermissionList', params)
|
||||
if (res.errcode === 0) {
|
||||
arr = res.data
|
||||
} else {
|
||||
arr = []
|
||||
|
||||
// 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 = {}) {
|
||||
console.log(record, record.id, 'rrrrrrrrrr')
|
||||
console.log(record, 'rrrrrrrrrr')
|
||||
this.formStatus = type
|
||||
switch (type) {
|
||||
case 'add':
|
||||
@@ -199,6 +300,7 @@ export default {
|
||||
})
|
||||
},
|
||||
async getRuleFormInfo(record) {
|
||||
|
||||
function getInfo(data, url) {
|
||||
return new Promise((reslove, reject) => {
|
||||
getReq(data, url).then((res) => {
|
||||
@@ -209,42 +311,53 @@ export default {
|
||||
|
||||
let row = {}
|
||||
if (record && record.role_id) {
|
||||
// row = await getInfo({ id: record.id },'/queryroleList')
|
||||
this.record = record
|
||||
row = record
|
||||
// this.type='edit'
|
||||
}
|
||||
const perList = await this.getPermissionList()
|
||||
const permissionList=perList.map((item)=>{
|
||||
return{
|
||||
key:+item.permission_id,
|
||||
...item
|
||||
}
|
||||
})
|
||||
console.log(permissionList, 'permissionList')
|
||||
|
||||
this.processedData = this.mergePermissionData(
|
||||
perList,
|
||||
record && record.permission.length ? record.permission : []
|
||||
)
|
||||
const newData=JSON.parse(JSON.stringify( this.processedData))
|
||||
|
||||
roleOptions.forEach((e, index) => {
|
||||
e.list.forEach((i) => {
|
||||
if (i.key == 'permission') {
|
||||
i.tableData=permissionList
|
||||
// .forEach((item)=>{
|
||||
// .push({...item,key:item.permission_id})
|
||||
// })
|
||||
if (record && record.role_id) {
|
||||
i.selectTableData = row.permission
|
||||
? row.permissionList.map((item) => item.permission_id)
|
||||
: []
|
||||
} else {
|
||||
i.selectTableData = []
|
||||
i.tableData = newData
|
||||
if(record&&record.role_id){
|
||||
i.selectTableData=this.extractAllIds( record.permission)
|
||||
}else {
|
||||
i.selectTableData=[]
|
||||
}
|
||||
} else {
|
||||
e.ruleForm[i.key] = row ? row[i.key] : ''
|
||||
}
|
||||
})
|
||||
})
|
||||
console.log(permissionList,"permissionList")
|
||||
this.formModal = true
|
||||
|
||||
},
|
||||
// 定义提取所有ID的函数
|
||||
extractAllIds(treeData) {
|
||||
const idSet = new Set();
|
||||
|
||||
// 递归遍历函数
|
||||
const traverse = (node) => {
|
||||
// 添加当前节点ID
|
||||
if (node.permission_id) {
|
||||
idSet.add(node.permission_id);
|
||||
}
|
||||
|
||||
// 递归处理子节点
|
||||
if (node.children && node.children.length > 0) {
|
||||
node.children.forEach((child) => traverse(child));
|
||||
}
|
||||
};
|
||||
|
||||
// 处理所有根节点
|
||||
treeData.forEach((node) => traverse(node));
|
||||
|
||||
return Array.from(idSet);
|
||||
},
|
||||
handlePagesizeChange(pageOption) {
|
||||
this.pageOption.pageSize = pageOption.pageSize
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
ref="comTable"
|
||||
:table-option="tableOption"
|
||||
:page-option="pageOption"
|
||||
:table-h="tableH"
|
||||
>
|
||||
<template #is_open="record">
|
||||
<span>{{ ['禁用', '启用'][record.is_open] }}</span>
|
||||
@@ -56,6 +55,9 @@ export default {
|
||||
props: {},
|
||||
data() {
|
||||
return {
|
||||
tableOption: {
|
||||
select:false
|
||||
},
|
||||
formModal: false,
|
||||
formState: {},
|
||||
formStatus: 'add', //表单状态辑状态 add:新增 edit:编辑
|
||||
|
||||
@@ -15,16 +15,15 @@
|
||||
ref="comTable"
|
||||
:table-option="tableOption"
|
||||
:page-option="pageOption"
|
||||
:table-h="tableH"
|
||||
>
|
||||
<template #status="record">
|
||||
<span>{{ ['未启用', '启用'][record.status] }}</span>
|
||||
</template>
|
||||
<template #work_mode="record">
|
||||
<span>{{workModeList.find(item=>record.value==item.value)?.label|| '' }}</span>
|
||||
<span>{{ workModeList.find((item) => record.value == item.value)?.label || '' }}</span>
|
||||
</template>
|
||||
<template #policy_id="record">
|
||||
<span>{{policyList.find(item=>record.value==item.value)?.label|| ''}}</span>
|
||||
<span>{{ policyList.find((item) => record.value == item.value)?.label || '' }}</span>
|
||||
</template>
|
||||
|
||||
<template #action="record">
|
||||
@@ -65,6 +64,9 @@ export default {
|
||||
props: {},
|
||||
data() {
|
||||
return {
|
||||
tableOption: {
|
||||
select:false
|
||||
},
|
||||
formModal: false,
|
||||
formState: {},
|
||||
formStatus: 'add', //表单状态辑状态 add:新增 edit:编辑
|
||||
@@ -74,33 +76,33 @@ export default {
|
||||
},
|
||||
btnOptionList: [],
|
||||
paramsDate: {},
|
||||
workModeList:[
|
||||
workModeList: [
|
||||
{
|
||||
label:'最优经济化',
|
||||
value:1
|
||||
label: '最优经济化',
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
label:'支撑电网稳定',
|
||||
value:2
|
||||
label: '支撑电网稳定',
|
||||
value: 2
|
||||
},
|
||||
{
|
||||
label:'自定义',
|
||||
value:3
|
||||
},
|
||||
label: '自定义',
|
||||
value: 3
|
||||
}
|
||||
],
|
||||
policyList:[
|
||||
policyList: [
|
||||
{
|
||||
label:'削峰套利',
|
||||
value:1
|
||||
label: '削峰套利',
|
||||
value: 1
|
||||
},
|
||||
{
|
||||
label:'需求响应',
|
||||
value:2
|
||||
label: '需求响应',
|
||||
value: 2
|
||||
},
|
||||
{
|
||||
label:'自发自用',
|
||||
value:3
|
||||
},
|
||||
label: '自发自用',
|
||||
value: 3
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
@@ -155,7 +157,7 @@ export default {
|
||||
}
|
||||
},
|
||||
operateForm(type, record = {}) {
|
||||
console.log(record,record.id,'rrrrrrrrrr')
|
||||
console.log(record, record.id, 'rrrrrrrrrr')
|
||||
this.formStatus = type
|
||||
switch (type) {
|
||||
case 'add':
|
||||
@@ -170,9 +172,9 @@ export default {
|
||||
this.formState = record
|
||||
this.getRuleFormInfo(record)
|
||||
break
|
||||
|
||||
|
||||
case 'del':
|
||||
this.handleDelete([record.station_id],this.getList)
|
||||
this.handleDelete([record.station_id], this.getList)
|
||||
|
||||
break
|
||||
|
||||
@@ -186,7 +188,7 @@ export default {
|
||||
}
|
||||
},
|
||||
// 删除操作
|
||||
async handleDelete(id,callback) {
|
||||
async handleDelete(id, callback) {
|
||||
const that = this
|
||||
Modal.confirm({
|
||||
title: '你确认删除数据吗?',
|
||||
@@ -194,10 +196,10 @@ export default {
|
||||
|
||||
async onOk() {
|
||||
try {
|
||||
const res = await getReq('/deleteStation',{station_id:id})
|
||||
const res = await getReq('/deleteStation', { station_id: id })
|
||||
if (res.errcode === 0) {
|
||||
this.$message.success(res.errmsg)
|
||||
this.pageOption.page=1
|
||||
this.pageOption.page = 1
|
||||
callback()
|
||||
} else {
|
||||
throw res
|
||||
@@ -230,7 +232,6 @@ export default {
|
||||
}
|
||||
stationOptions.forEach((e, index) => {
|
||||
e.list.forEach((i) => {
|
||||
|
||||
e.ruleForm[i.key] = row ? row[i.key] : ''
|
||||
e.ruleForm.id = row.id
|
||||
})
|
||||
|
||||
@@ -15,7 +15,6 @@
|
||||
ref="comTable"
|
||||
:table-option="tableOption"
|
||||
:page-option="pageOption"
|
||||
:table-h="tableH"
|
||||
>
|
||||
<template #gender="record">
|
||||
<!-- 0:女; 1:男 -->
|
||||
@@ -60,6 +59,9 @@ export default {
|
||||
props: {},
|
||||
data() {
|
||||
return {
|
||||
tableOption: {
|
||||
select:false
|
||||
},
|
||||
formModal: false,
|
||||
formState: {},
|
||||
formStatus: 'add', //表单状态辑状态 add:新增 edit:编辑
|
||||
|
||||
Reference in New Issue
Block a user