import React, { useCallback, useEffect, useMemo, useRef, useState, } from "react"; import styles from "./index.module.scss"; import { Button, Input, Popconfirm, Table } from "antd"; import classNames from "classnames"; import { baseUpUrl } from "@/utils/http"; import A1ORenFile from "./A1ORenFile"; import A1OMove from "./A1OMove"; import { A1OFileType } from "@/types"; import { useDispatch, useSelector } from "react-redux"; import { RootState } from "@/store"; import { A1_APIOgetList, A1_APIOdel, A1_APIOdownload, } from "@/store/action/A1Project"; import { MessageFu } from "@/utils/message"; import A1OupFile from "./A1OupFile"; import { authFilesLookFu, urlChangeFu } from "@/utils/authFilesLook"; import AuthCom from "@/components/AuthCom"; type Props = { projectId: number; projectName: string; }; function A1Outer({ projectId, projectName }: Props) { const dispatch = useDispatch(); // 从仓库获取左侧写死列表 和 展示列表 const { A1OleftArr, A1OtableInfo } = useSelector( (state: RootState) => state.A1Project ); const [fromData, setFromData] = useState({ parentId: 1, searchKey: "", pageNum: 1, pageSize: 10, }); // 文件名的输入 const searchKeyTime = useRef(-1); const searchKeyChange = useCallback( (e: React.ChangeEvent) => { clearTimeout(searchKeyTime.current); searchKeyTime.current = window.setTimeout(() => { setFromData({ ...fromData, searchKey: e.target.value, pageNum: 1, }); }, 500); }, [fromData] ); // 封装发送请求的函数 const getListFu = useCallback(() => { dispatch(A1_APIOgetList({ ...fromData, projectId })); // 清空选中 setSelectedRowKeys([]); }, [dispatch, fromData, projectId]); useEffect(() => { getListFu(); }, [getListFu]); // 一级的高亮 const [tab1, setTab1] = useState({} as A1OFileType); useEffect(() => { setTab1(A1OleftArr[0]); }, [A1OleftArr]); // 二级的选择 const [tab2, setTab2] = useState({ id: 0, name: "" }); // 一级的切换 const cutTab1Fu = useCallback( (id: number, name: string) => { setTab2({ id: 0, name: "" }); setTab1({ id, name } as A1OFileType); if (id !== fromData.parentId) setFromData({ ...fromData, parentId: id, pageNum: 1 }); }, [fromData] ); // 点击表格里面的 文件夹 进入 2级 const toTowFilesFu = useCallback( (id: number, type: 0 | 1, name: string) => { if (type === 1) { setTab2({ id, name }); setFromData({ ...fromData, parentId: id, pageNum: 1 }); } }, [fromData] ); // 页码变化 const paginationChange = useCallback( () => (pageNum: number, pageSize: number) => { setFromData({ ...fromData, pageNum, pageSize }); }, [fromData] ); // 关于表格的多选 const [selectedRowKeys, setSelectedRowKeys] = useState([]); // 新建文件夹或者 重命名 const [renFile, setRenFile] = useState({} as A1OFileType); // 点击移动之后出来的数据 const [moveId, setMoveId] = useState({ id: 0, name: "" }); // 点击表格里面的删除 const delById = useCallback( async (id: number) => { const res = await A1_APIOdel(id); if (res.code === 0) { MessageFu.success("删除成功!"); getListFu(); } }, [getListFu] ); // 点击表格里面的 文件夹 的下载 const downFilesFu = useCallback(async (id: number, name: string) => { const res = await A1_APIOdownload(id); if (res.code === 0) { urlChangeFu(res.data, true, undefined, name); } }, []); // 点击批量下载 const downSelectFu = useCallback(async () => { const res = await A1_APIOdownload(selectedRowKeys.join(",")); if (res.code === 0) { urlChangeFu(res.data, true, undefined, projectName); // 清空选中 setSelectedRowKeys([]); } }, [projectName, selectedRowKeys]); // 点击-批量上传 const [upFileId, setUpFileId] = useState(0); const columns = useMemo(() => { return [ { title: "文件名", render: (item: A1OFileType) => item.name.length >= 30 ? ( toTowFilesFu(item.id, item.type, item.name)} className={classNames(item.type === 1 ? "A1OfilesTable" : "")} > {item.name.substring(0, 30) + "..."} ) : ( toTowFilesFu(item.id, item.type, item.name)} className={classNames(item.type === 1 ? "A1OfilesTable" : "")} > {item.name} ), }, { title: "创建用户", dataIndex: "creatorName", }, { title: "创建时间", dataIndex: "createTime", }, { title: "操作", render: (item: A1OFileType) => ( <> {authFilesLookFu(item.name,'') ? ( ) : null} {item.type === 1 ? ( ) : ( )} {item.type === 1 ? null : ( )} delById(item.id)} okButtonProps={{ loading: false }} > ), }, ]; }, [delById, downFilesFu, toTowFilesFu]); // 当前位置 const nowLoc = useMemo(() => { return { tag: ( <> cutTab1Fu(tab1.id, tab1.name)} > {tab1.name} {tab2.id ? / {tab2.name} : null} ), txt: tab1.name + (tab2.id ? ` / ${tab2.name}` : ""), }; }, [cutTab1Fu, tab1.id, tab1.name, tab2.id, tab2.name]); return (
文件名: searchKeyChange(e)} />    当前位置:{nowLoc.tag}
{tab2.id ? null : ( <> )}
{/* 表格主体 */}
目录
{A1OleftArr.map((v) => { // 子标题用 , 隔开 const temp = v.name.split(',') return (
cutTab1Fu(v.id, temp[0])} className={classNames( "A1OtableBox1_2", tab1.id === v.id ? "A1OtableBox1_2Ac" : "" )} key={v.id} >

{temp[0]}

{temp[1] && ( {temp[1]} )}
) })}
{ setSelectedRowKeys(selectedRowKeys); }, }} scroll={{ y: 560 }} dataSource={A1OtableInfo.list} columns={columns} rowKey="id" pagination={{ showQuickJumper: true, position: ["bottomCenter"], showSizeChanger: true, current: fromData.pageNum, pageSize: fromData.pageSize, total: A1OtableInfo.total, onChange: paginationChange(), }} /> {/* 点击 新建 文件夹 或者 重命名 */} {renFile.id ? ( setFromData({ ...fromData, searchKey: "", pageNum: 1 })} editFu={() => getListFu()} closeFu={() => setRenFile({ id: 0, name: "", type: 0 } as A1OFileType) } fileInfo={renFile} projectId={projectId} /> ) : null} {/* 点击移动 */} {moveId.id ? ( setMoveId({ id: 0, name: "" })} projectId={projectId} moveSuFu={() => getListFu()} /> ) : null} {/* 点击批量上传 */} {upFileId ? ( setUpFileId(0)} upFileFu={() => getListFu()} /> ) : null} ); } const MemoA1Outer = React.memo(A1Outer); export default MemoA1Outer;