import React, { useCallback, useEffect, useState } from "react"; import styles from "./index.module.scss"; import { Button, Checkbox, Empty, Modal } from "antd"; import { A1_APIdownBtnOk, A1_APIgetDownList } from "@/store/action/A1Project"; import { A1getStorage, A1setStorage } from "@/utils/storage"; import { MessageFu } from "@/utils/message"; import { urlChangeFu } from "@/utils/authFilesLook"; type SelectType = { attrId: number; name: string; hasUpload: boolean; done: boolean; }; type Props = { downId: { id: number; txt: string }; closeFu: () => void; }; function A1Down({ downId, closeFu }: Props) { const getInfoFu = useCallback(async (id: number) => { const res = await A1_APIgetDownList(id); if (res.code === 0) { let arr: SelectType[] = res.data.filter((v: SelectType) => v.hasUpload); const storeIds = A1getStorage(); if (storeIds) { arr = arr.map((v) => ({ ...v, done: storeIds.includes(v.attrId) ? true : false, })); } setCheckedList(arr); } }, []); useEffect(() => { getInfoFu(downId.id); }, [getInfoFu, downId.id]); const [checkedList, setCheckedList] = useState([] as SelectType[]); // 全选的状态 const [indeterminate, setIndeterminate] = useState(false); const [checkAll, setCheckAll] = useState(false); const onCheckAllChange = useCallback( (val: boolean) => { const newArr = checkedList.map((v) => ({ ...v, done: val, })); setCheckedList(newArr); setCheckAll(val); }, [checkedList] ); const onChange = useCallback( (val: boolean, id: number) => { setCheckedList( checkedList.map((v) => ({ ...v, done: v.attrId === id ? val : v.done, })) ); }, [checkedList] ); useEffect(() => { const newArr = checkedList.filter((v) => v.done); setIndeterminate(!!newArr.length && newArr.length < checkedList.length); setCheckAll(newArr.length === checkedList.length); }, [checkedList]); // 点击提交 const btnOkFu = useCallback(async () => { const obj = { projectId: downId.id, attrId: checkedList.map((v) => v.attrId), }; const res = await A1_APIdownBtnOk(obj); if (res.code === 0) { urlChangeFu(res.data, true, undefined, downId.txt); // 清空所有选中状态 setCheckedList( checkedList.map((v) => ({ ...v, done: false, })) ); } }, [checkedList, downId.id, downId.txt]); // 点击保存设置 到 本地 const clickStoreFu = useCallback(() => { const arr = checkedList.filter((v) => v.done).map((v) => v.attrId); A1setStorage(arr); MessageFu.success("保存设置到本地成功!"); }, [checkedList]); return (
{checkedList.length ? ( <>

请选择下载的项目文件类型

onCheckAllChange(e.target.checked)} checked={checkAll} > 全选 ) : null} {checkedList.length ? (
{checkedList.map((v) => (
onChange(e.target.checked, v.attrId)} checked={v.done} > {v.name}
))}
) : ( <>
)}
{checkedList.length ? (
) : ( )}
); } const MemoA1Down = React.memo(A1Down); export default MemoA1Down;