|
@@ -1,97 +1,97 @@
|
|
-import React, { useCallback, useEffect, useMemo, useState } from "react";
|
|
|
|
-import styles from "./index.module.scss";
|
|
|
|
-import { Button, Checkbox, Modal } from "antd";
|
|
|
|
-import MyPopconfirm from "@/components/MyPopconfirm";
|
|
|
|
-import { Z1_APIgetAuthByUserId, Z1_APIsetAuth } from "@/store/action/Z1user";
|
|
|
|
-import classNmaes from "classnames";
|
|
|
|
-import { MessageFu } from "@/utils/message";
|
|
|
|
|
|
+import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
|
|
+import styles from './index.module.scss'
|
|
|
|
+import { Button, Checkbox, Modal } from 'antd'
|
|
|
|
+import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
|
+import { Z1_APIgetAuthByUserId, Z1_APIsetAuth } from '@/store/action/Z1user'
|
|
|
|
+import classNmaes from 'classnames'
|
|
|
|
+import { MessageFu } from '@/utils/message'
|
|
|
|
|
|
export type UserListType = {
|
|
export type UserListType = {
|
|
- id: number;
|
|
|
|
- name: string;
|
|
|
|
|
|
+ id: number
|
|
|
|
+ name: string
|
|
children: {
|
|
children: {
|
|
- id: number;
|
|
|
|
- name: string;
|
|
|
|
- authority: boolean;
|
|
|
|
- }[];
|
|
|
|
-};
|
|
|
|
|
|
+ id: number
|
|
|
|
+ name: string
|
|
|
|
+ authority: boolean
|
|
|
|
+ }[]
|
|
|
|
+}
|
|
|
|
|
|
type Props = {
|
|
type Props = {
|
|
- authInfo: { id: number; name: string };
|
|
|
|
- closeFu: () => void;
|
|
|
|
-};
|
|
|
|
|
|
+ authInfo: { id: number; name: string }
|
|
|
|
+ closeFu: () => void
|
|
|
|
+}
|
|
|
|
|
|
function Z1auth({ authInfo, closeFu }: Props) {
|
|
function Z1auth({ authInfo, closeFu }: Props) {
|
|
const getAuthByUserIdFu = useCallback(async () => {
|
|
const getAuthByUserIdFu = useCallback(async () => {
|
|
- const res = await Z1_APIgetAuthByUserId(authInfo.id);
|
|
|
|
|
|
+ const res = await Z1_APIgetAuthByUserId(authInfo.id)
|
|
|
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
// 这里后台返回的一层的数据。懒得改逻辑,手动修改成2级的数据
|
|
// 这里后台返回的一层的数据。懒得改逻辑,手动修改成2级的数据
|
|
|
|
|
|
- setList([
|
|
|
|
- {
|
|
|
|
- id: Date.now(),
|
|
|
|
- name: "",
|
|
|
|
- children: res.data,
|
|
|
|
- },
|
|
|
|
- ]);
|
|
|
|
|
|
+ // setList([
|
|
|
|
+ // {
|
|
|
|
+ // id: Date.now(),
|
|
|
|
+ // name: "",
|
|
|
|
+ // children: res.data,
|
|
|
|
+ // },
|
|
|
|
+ // ]);
|
|
|
|
|
|
- // setList(res.data)
|
|
|
|
|
|
+ setList(res.data)
|
|
}
|
|
}
|
|
- }, [authInfo.id]);
|
|
|
|
|
|
+ }, [authInfo.id])
|
|
|
|
|
|
useEffect(() => {
|
|
useEffect(() => {
|
|
- getAuthByUserIdFu();
|
|
|
|
- }, [getAuthByUserIdFu]);
|
|
|
|
|
|
+ getAuthByUserIdFu()
|
|
|
|
+ }, [getAuthByUserIdFu])
|
|
|
|
|
|
- const [list, setList] = useState<UserListType[]>([]);
|
|
|
|
|
|
+ const [list, setList] = useState<UserListType[]>([])
|
|
|
|
|
|
// 多选框变化
|
|
// 多选框变化
|
|
const onChange = useCallback(
|
|
const onChange = useCallback(
|
|
(val: boolean, id1: number, id2: number) => {
|
|
(val: boolean, id1: number, id2: number) => {
|
|
setList(
|
|
setList(
|
|
- list.map((v) => ({
|
|
|
|
|
|
+ list.map(v => ({
|
|
...v,
|
|
...v,
|
|
children:
|
|
children:
|
|
v.id === id1
|
|
v.id === id1
|
|
- ? v.children.map((c) => ({
|
|
|
|
|
|
+ ? v.children.map(c => ({
|
|
...c,
|
|
...c,
|
|
- authority: c.id === id2 ? val : c.authority,
|
|
|
|
|
|
+ authority: c.id === id2 ? val : c.authority
|
|
}))
|
|
}))
|
|
- : v.children,
|
|
|
|
|
|
+ : v.children
|
|
}))
|
|
}))
|
|
- );
|
|
|
|
|
|
+ )
|
|
},
|
|
},
|
|
[list]
|
|
[list]
|
|
- );
|
|
|
|
|
|
+ )
|
|
|
|
|
|
// 二级选中的数组id集合
|
|
// 二级选中的数组id集合
|
|
const checkIds = useMemo(() => {
|
|
const checkIds = useMemo(() => {
|
|
- const arr: number[] = [];
|
|
|
|
- list.forEach((v) => {
|
|
|
|
|
|
+ const arr: number[] = []
|
|
|
|
+ list.forEach(v => {
|
|
if (v.children) {
|
|
if (v.children) {
|
|
- v.children.forEach((c) => {
|
|
|
|
- if (c.authority) arr.push(c.id);
|
|
|
|
- });
|
|
|
|
|
|
+ v.children.forEach(c => {
|
|
|
|
+ if (c.authority) arr.push(c.id)
|
|
|
|
+ })
|
|
}
|
|
}
|
|
- });
|
|
|
|
- return arr;
|
|
|
|
- }, [list]);
|
|
|
|
|
|
+ })
|
|
|
|
+ return arr
|
|
|
|
+ }, [list])
|
|
|
|
|
|
// 点击确定
|
|
// 点击确定
|
|
const btnOkFu = useCallback(async () => {
|
|
const btnOkFu = useCallback(async () => {
|
|
const obj = {
|
|
const obj = {
|
|
userId: authInfo.id,
|
|
userId: authInfo.id,
|
|
- resources: checkIds,
|
|
|
|
- };
|
|
|
|
|
|
+ resources: checkIds
|
|
|
|
+ }
|
|
|
|
|
|
- const res = await Z1_APIsetAuth(obj);
|
|
|
|
|
|
+ const res = await Z1_APIsetAuth(obj)
|
|
|
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
- MessageFu.success("授权成功!");
|
|
|
|
- closeFu();
|
|
|
|
|
|
+ MessageFu.success('授权成功!')
|
|
|
|
+ closeFu()
|
|
}
|
|
}
|
|
- }, [authInfo.id, checkIds, closeFu]);
|
|
|
|
|
|
+ }, [authInfo.id, checkIds, closeFu])
|
|
|
|
|
|
return (
|
|
return (
|
|
<Modal
|
|
<Modal
|
|
@@ -102,19 +102,19 @@ function Z1auth({ authInfo, closeFu }: Props) {
|
|
[] // 设置footer为空,去掉 取消 确定默认按钮
|
|
[] // 设置footer为空,去掉 取消 确定默认按钮
|
|
}
|
|
}
|
|
>
|
|
>
|
|
- <div className="Z1aEmain">
|
|
|
|
- {list.map((v) => (
|
|
|
|
- <div key={v.id} className="Z1aRow">
|
|
|
|
|
|
+ <div className='Z1aEmain'>
|
|
|
|
+ {list.map(v => (
|
|
|
|
+ <div key={v.id} className='Z1aRow'>
|
|
{/* 隐藏一级数据 */}
|
|
{/* 隐藏一级数据 */}
|
|
- {/* <div className="Z1aRow1">{v.name}</div> */}
|
|
|
|
- <div className="Z1aRow2">
|
|
|
|
- {v.children.map((c) => (
|
|
|
|
|
|
+ <div className='Z1aRow1'>{v.name}</div>
|
|
|
|
+ <div className='Z1aRow2'>
|
|
|
|
+ {v.children.map(c => (
|
|
<div key={c.id}>
|
|
<div key={c.id}>
|
|
<Checkbox
|
|
<Checkbox
|
|
checked={c.authority}
|
|
checked={c.authority}
|
|
- onChange={(e) => onChange(e.target.checked, v.id, c.id)}
|
|
|
|
|
|
+ onChange={e => onChange(e.target.checked, v.id, c.id)}
|
|
>
|
|
>
|
|
- {c.name}
|
|
|
|
|
|
+ <div dangerouslySetInnerHTML={{ __html: c.name }}></div>
|
|
</Checkbox>
|
|
</Checkbox>
|
|
</div>
|
|
</div>
|
|
))}
|
|
))}
|
|
@@ -122,31 +122,22 @@ function Z1auth({ authInfo, closeFu }: Props) {
|
|
</div>
|
|
</div>
|
|
))}
|
|
))}
|
|
|
|
|
|
- <div
|
|
|
|
- className={classNmaes(
|
|
|
|
- "Z1aErr",
|
|
|
|
- checkIds.length <= 0 ? "Z1aErrAc" : ""
|
|
|
|
- )}
|
|
|
|
- >
|
|
|
|
|
|
+ <div className={classNmaes('Z1aErr', checkIds.length <= 0 ? 'Z1aErrAc' : '')}>
|
|
至少选中一个
|
|
至少选中一个
|
|
</div>
|
|
</div>
|
|
|
|
|
|
- <div className="Z1aEbtn">
|
|
|
|
- <Button
|
|
|
|
- type="primary"
|
|
|
|
- onClick={btnOkFu}
|
|
|
|
- disabled={checkIds.length <= 0}
|
|
|
|
- >
|
|
|
|
|
|
+ <div className='Z1aEbtn'>
|
|
|
|
+ <Button type='primary' onClick={btnOkFu} disabled={checkIds.length <= 0}>
|
|
提交
|
|
提交
|
|
</Button>
|
|
</Button>
|
|
 
|
|
 
|
|
- <MyPopconfirm txtK="取消" onConfirm={closeFu} />
|
|
|
|
|
|
+ <MyPopconfirm txtK='取消' onConfirm={closeFu} />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</Modal>
|
|
</Modal>
|
|
- );
|
|
|
|
|
|
+ )
|
|
}
|
|
}
|
|
|
|
|
|
-const MemoZ1auth = React.memo(Z1auth);
|
|
|
|
|
|
+const MemoZ1auth = React.memo(Z1auth)
|
|
|
|
|
|
-export default MemoZ1auth;
|
|
|
|
|
|
+export default MemoZ1auth
|