|
@@ -7,10 +7,13 @@ import classNmaes from "classnames";
|
|
|
import { MessageFu } from "@/utils/message";
|
|
|
|
|
|
export type UserListType = {
|
|
|
- authority: boolean;
|
|
|
id: number;
|
|
|
name: string;
|
|
|
- resourceType: string;
|
|
|
+ children: {
|
|
|
+ id: number;
|
|
|
+ name: string;
|
|
|
+ authority: boolean;
|
|
|
+ }[];
|
|
|
};
|
|
|
|
|
|
type Props = {
|
|
@@ -32,27 +35,39 @@ function Z1auth({ authInfo, closeFu }: Props) {
|
|
|
|
|
|
// 多选框变化
|
|
|
const onChange = useCallback(
|
|
|
- (val: boolean, id: number) => {
|
|
|
+ (val: boolean, id1: number, id2: number) => {
|
|
|
setList(
|
|
|
list.map((v) => ({
|
|
|
...v,
|
|
|
- authority: v.id === id ? val : v.authority,
|
|
|
+ children:
|
|
|
+ v.id === id1
|
|
|
+ ? v.children.map((c) => ({
|
|
|
+ ...c,
|
|
|
+ authority: c.id === id2 ? val : c.authority,
|
|
|
+ }))
|
|
|
+ : v.children,
|
|
|
}))
|
|
|
);
|
|
|
},
|
|
|
[list]
|
|
|
);
|
|
|
|
|
|
- // 至少选中一个
|
|
|
- const isOneRes = useMemo(() => {
|
|
|
- return list.filter((v) => v.authority).length <= 0;
|
|
|
+ // 二级选中的数组id集合
|
|
|
+ const checkIds = useMemo(() => {
|
|
|
+ const arr: number[] = [];
|
|
|
+ list.forEach((v) => {
|
|
|
+ v.children.forEach((c) => {
|
|
|
+ if (c.authority) arr.push(c.id);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ return arr;
|
|
|
}, [list]);
|
|
|
|
|
|
// 点击确定
|
|
|
const btnOkFu = useCallback(async () => {
|
|
|
const obj = {
|
|
|
userId: authInfo.id,
|
|
|
- resources: list.filter((c) => c.authority).map((v) => v.id),
|
|
|
+ resources: checkIds,
|
|
|
};
|
|
|
|
|
|
const res = await Z1_APIsetAuth(obj);
|
|
@@ -61,7 +76,7 @@ function Z1auth({ authInfo, closeFu }: Props) {
|
|
|
MessageFu.success("授权成功!");
|
|
|
closeFu();
|
|
|
}
|
|
|
- }, [authInfo.id, closeFu, list]);
|
|
|
+ }, [authInfo.id, checkIds, closeFu]);
|
|
|
|
|
|
return (
|
|
|
<Modal
|
|
@@ -75,21 +90,36 @@ function Z1auth({ authInfo, closeFu }: Props) {
|
|
|
<div className="Z1aEmain">
|
|
|
{list.map((v) => (
|
|
|
<div key={v.id} className="Z1aRow">
|
|
|
- <Checkbox
|
|
|
- checked={v.authority}
|
|
|
- onChange={(e) => onChange(e.target.checked, v.id)}
|
|
|
- >
|
|
|
- {v.name}
|
|
|
- </Checkbox>
|
|
|
+ <div className="Z1aRow1">{v.name}</div>
|
|
|
+ <div className="Z1aRow2">
|
|
|
+ {v.children.map((c) => (
|
|
|
+ <Checkbox
|
|
|
+ key={c.id}
|
|
|
+ checked={c.authority}
|
|
|
+ onChange={(e) => onChange(e.target.checked, v.id, c.id)}
|
|
|
+ >
|
|
|
+ {c.name}
|
|
|
+ </Checkbox>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
</div>
|
|
|
))}
|
|
|
|
|
|
- <div className={classNmaes("Z1aErr", isOneRes ? "Z1aErrAc" : "")}>
|
|
|
+ <div
|
|
|
+ className={classNmaes(
|
|
|
+ "Z1aErr",
|
|
|
+ checkIds.length <= 0 ? "Z1aErrAc" : ""
|
|
|
+ )}
|
|
|
+ >
|
|
|
至少选中一个
|
|
|
</div>
|
|
|
|
|
|
<div className="Z1aEbtn">
|
|
|
- <Button type="primary" onClick={btnOkFu} disabled={isOneRes}>
|
|
|
+ <Button
|
|
|
+ type="primary"
|
|
|
+ onClick={btnOkFu}
|
|
|
+ disabled={checkIds.length <= 0}
|
|
|
+ >
|
|
|
提交
|
|
|
</Button>
|
|
|
 
|