Commit e695c59c authored by cellee's avatar cellee

解决权限模块大栏目与小栏目选择多带或者少带问题。

Signed-off-by: cellee's avatarcellee <893264950@qq.com>
parent 7f401616
import React, { useState, useEffect, useRef } from 'react';
import { Form, Input, Button, Spin, message, Descriptions, Modal, Tree, Radio } from 'antd';
import { Form, Input, Button, Spin, message, Descriptions, Tree, Radio } from 'antd';
import { connect, history } from 'umi';
import { SearchOutlined, PoweroffOutlined, EditOutlined, LeftOutlined } from '@ant-design/icons';
import { EditOutlined, LeftOutlined } from '@ant-design/icons';
import { getCookie } from '@/utils/method';
import './Account.less';
......@@ -12,8 +12,6 @@ import SelectCommunity from '@/components/SelectCommunity';
import { getNumber } from '@/utils/string'; // 正则
import { RA } from '@/utils/method';
import moment from 'moment';
const Account = (props: any) => {
const module = 'Account';
......@@ -24,7 +22,7 @@ const Account = (props: any) => {
const [expandedKeys, setExpandedKeys] = useState<string[]>([]); // 展开栏目
const [checkedKeys, setCheckedKeys] = useState<string[]>([]); // 默认已选栏目
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点
const [selectedKeys, setSelectedKeys] = useState<string[]>([]); // 设置选中的树节点
const [autoExpandParent, setAutoExpandParent] = useState<boolean>(true); // 树形菜单展开关闭
// 单选 二级还是三级管理员
......@@ -64,10 +62,6 @@ const Account = (props: any) => {
let _a = user.currentUser.permission; // 当前账户权限
let _p = treeDatas[0].children; // 所有权限列表
for (let i in _p) {
console.log(_p[i].key);
}
let arr: any = []; // 一级栏目权限
let erArr: any = []; // 一级栏目权限
// 循环一级 判断当前账户有没有权限修改增加
......@@ -86,8 +80,6 @@ const Account = (props: any) => {
}
}
}
console.log(_p);
// 赋值改变
treeDatas[0].children = _p;
setCheckedKeys(treeDatas as any); // 可勾选列表
......@@ -98,10 +90,37 @@ const Account = (props: any) => {
useEffect(() => {
if (Permission != null) {
let newPer = eval('(' + Permission + ')');
let data: any = [];
let data: any = []; // 编辑的账户的权限
for (let i in newPer) {
data[i] = newPer[i] + '';
}
// console.log(data); // 编辑的账户的权限
let _p = treeData[0].children; // 所有权限列表
// console.log(_p); // 所有权限列表
for (let i in _p) {
let arr = _p[i].children; // 每个权限
let newArr = []; // 每个权限下的子权限列表
for (let j in arr) {
newArr.push(arr[j].key);
}
// console.log(newArr);
if (!newArr.every((val) => data.includes(val))) {
// 判断数组是否包含另一个数组
// console.log('不包含' + _p[i].key);
// 不全部包含就删除数组的元素
var index = data.indexOf(_p[i].key);
if (index > -1) {
data.splice(index, 1);
}
} else {
// console.log('包含' + _p[i].key);
}
}
// console.log(data);
// 再赋值给列表
setCheckedKeys(data);
}
}, [Permission]);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment