Commit 0639e6ec authored by 陈前坚's avatar 陈前坚

perf: 角色全选/全不选

parent d14f9c98
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Spin, Button, Empty } from 'antd'; import { Spin, Checkbox, Button, Empty } from 'antd';
import _ from 'lodash'; import _ from 'lodash';
import ListCardItem from './ItemCard'; import ListCardItem from './ItemCard';
import styles from './ItemCard.less'; import styles from './ItemCard.less';
...@@ -60,6 +60,32 @@ const ListCard = props => { ...@@ -60,6 +60,32 @@ const ListCard = props => {
// console.timeEnd('updateValueList:'); // console.timeEnd('updateValueList:');
}; };
const checkAll = e => {
if (e.target.checked) {
const result = dataList.map(item => getAllID(item)).flat(Infinity);
setValueList(result);
// eslint-disable-next-line no-unused-expressions
onChange && onChange(result);
} else {
setValueList([]);
// eslint-disable-next-line no-unused-expressions
onChange && onChange([]);
}
};
const getAllID = item => {
let result = [];
const haveChildren =
Array.isArray(item.children) && item.children.length > 0;
// 统一使用 getId
result.push(getId(item));
if (haveChildren) {
// 每次递归result被置空,所以要另外保存
result = [...item.children.map(i => getAllID(i)), ...result];
}
return result;
};
return ( return (
<div> <div>
{loading ? ( {loading ? (
...@@ -77,6 +103,7 @@ const ListCard = props => { ...@@ -77,6 +103,7 @@ const ListCard = props => {
/> />
) : ( ) : (
<> <>
<Checkbox onChange={checkAll}>全选/全不选</Checkbox>
{dataList && dataList.length > 0 ? ( {dataList && dataList.length > 0 ? (
dataList dataList
.filter(d => d.type === 'widgetGroup' || 'widget') .filter(d => d.type === 'widgetGroup' || 'widget')
......
...@@ -185,6 +185,7 @@ ...@@ -185,6 +185,7 @@
.ant-tree-switcher{ .ant-tree-switcher{
line-height: 1; line-height: 1;
color:#1890FF; color:#1890FF;
margin-right: 0px !important;
} }
.ant-checkbox-group .ant-checkbox-group-item { .ant-checkbox-group .ant-checkbox-group-item {
margin-right: 0px !important; margin-right: 0px !important;
......
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