import { useEffect, useState } from "react"; import { Col, Row, Button, message, Table, Select, Space, Modal, Input, Checkbox, GetProp, Progress, Pagination, } from "antd"; import { PlusCircleOutlined, RedoOutlined } from "@ant-design/icons"; import styles from "./FileInfoEditer.module.less"; import { open } from "@tauri-apps/api/dialog"; import { appDataDir, homeDir } from "@tauri-apps/api/path"; /* 导入类型 */ import { FileInfoEditerType, FileInfoType } from "@/types/files"; import { fileTypeList, fileSizeList } from "./config"; export default function FileInfoEditer({ title, showModal = false, fileInfoSource = {}, onClickOk, onClickCancel, }: FileInfoEditerType) { const [isModalOpen, setIsModalOpen] = useState(showModal); const [fileInfo, setFileInfo] = useState({}); const { TextArea } = Input; useEffect(() => { setIsModalOpen(showModal); console.log(4040, fileInfoSource) if (JSON.stringify(fileInfoSource) !== "{}" && showModal) { setFileInfo(fileInfoSource); } if(!showModal) { setFileInfo({}); } }, [showModal, fileInfoSource]); async function getDir() { // 打开本地的系统目录,暂时不支持多选 const selected = await open({ directory: true, multiple: false, defaultPath: await homeDir(), }); console.log(55, selected); if (selected && selected.length) { setFileInfo({ ...fileInfo, path: `${selected}`, }); // setUsePath(`${selected}`); // 最多记录 100 条用户操作的历史数据 // const files = await File.getAllList(`${selected}`); } // await invoke("file_sort", { path: selected }); // setFile([...fileStr, await invoke("file_sort", { path: selected })]); } function handleOk() { if (!fileInfo?.path) { message.error("请选择文件路径"); } console.log(180, fileInfo); onClickOk && onClickOk(fileInfo); } function handleCancel() { setFileInfo({}); setIsModalOpen(false); onClickCancel && onClickCancel(); } const checkboxAll = () => { const otherTypes = [ "其他所有带扩展名的类型", "其他所有无扩展名的类型", // "指定", // "排除", ]; const checkedValues = fileTypeList.map((typeInfo) => typeInfo.name); setFileInfo({ ...fileInfo, checkboxAll: !fileInfo.checkboxAll, checkedTypeValues: fileInfo.checkboxAll ? [] : [...checkedValues, ...otherTypes], }); }; const checkboxSizeAll = () => { const checkedSizeValues = fileSizeList.map((typeInfo) => typeInfo.name); setFileInfo({ ...fileInfo, checkboxSizeAll: !fileInfo.checkboxSizeAll, checkedSizeValues: fileInfo.checkboxSizeAll ? [] : checkedSizeValues, }); }; const onTypesChange: GetProp = ( checkedValues ) => { console.log("checked = ", checkedValues); // TODO 全选、全不选的交互 等主体功能完善之后, 再开发 setFileInfo({ ...fileInfo, checkedTypeValues: checkedValues, }); }; const onAddTypeChange = (types: string) => { setFileInfo({ ...fileInfo, addType: types, }); }; const onPassTypeChange = (types: string) => { setFileInfo({ ...fileInfo, passType: types, }); }; const onSizesChange: GetProp = ( checkedValues ) => { console.log("checkedSizeValues = ", checkedValues); setFileInfo({ ...fileInfo, checkedSizeValues: checkedValues, }); }; return ( *文件路径: {fileInfo.path || ""} {fileInfo.path ? ( getDir()} /> ) : ( getDir()} /> )} *文件类型: checkboxAll()} value={"全选/不选"} > 全选/不选 {fileTypeList.map((typeInfo) => ( {typeInfo.name} ))} 其他所有带扩展名的类型 其他所有无扩展名的类型 指定