FileInfoEditer.tsx 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. import { useEffect, useState } from "react";
  2. import {
  3. Col,
  4. Row,
  5. Button,
  6. message,
  7. Table,
  8. Select,
  9. Space,
  10. Modal,
  11. Input,
  12. Checkbox,
  13. GetProp,
  14. Progress,
  15. Pagination,
  16. } from "antd";
  17. import { PlusCircleOutlined, RedoOutlined } from "@ant-design/icons";
  18. import styles from "./FileInfoEditer.module.less";
  19. import { open } from "@tauri-apps/api/dialog";
  20. import { appDataDir } from "@tauri-apps/api/path";
  21. /* 导入类型 */
  22. import { FileInfoEditerType, FileInfoType } from "@/types/files";
  23. import { fileTypeList, fileSizeList } from "./config";
  24. export default function FileInfoEditer({
  25. title,
  26. showModal = false,
  27. fileInfoSource = {},
  28. onClickOk,
  29. onClickCancel,
  30. }: FileInfoEditerType) {
  31. const [isModalOpen, setIsModalOpen] = useState<boolean>(showModal);
  32. const [fileInfo, setFileInfo] = useState<FileInfoType>({});
  33. const { TextArea } = Input;
  34. useEffect(() => {
  35. setIsModalOpen(showModal);
  36. if (JSON.stringify(fileInfoSource) !== "{}" && showModal) {
  37. setFileInfo(fileInfoSource);
  38. }
  39. if(!showModal) {
  40. setFileInfo({});
  41. }
  42. }, [showModal, fileInfoSource]);
  43. async function getDir() {
  44. // 打开本地的系统目录,暂时不支持多选
  45. const selected = await open({
  46. directory: true,
  47. multiple: false,
  48. defaultPath: await appDataDir(),
  49. });
  50. if (selected && selected.length) {
  51. setFileInfo({
  52. ...fileInfo,
  53. path: selected[0],
  54. });
  55. // setUsePath(`${selected}`);
  56. // 最多记录 100 条用户操作的历史数据
  57. // const files = await File.getAllList(`${selected}`);
  58. }
  59. // await invoke("file_sort", { path: selected });
  60. // setFile([...fileStr, await invoke("file_sort", { path: selected })]);
  61. }
  62. function handleOk() {
  63. if (!fileInfo?.path) {
  64. message.error("请选择文件路径");
  65. }
  66. console.log(180, fileInfo);
  67. onClickOk && onClickOk(fileInfo);
  68. }
  69. function handleCancel() {
  70. setFileInfo({});
  71. setIsModalOpen(false);
  72. onClickCancel && onClickCancel();
  73. }
  74. const checkboxAll = () => {
  75. const otherTypes = [
  76. "其他所有带扩展名的类型",
  77. "其他所有无扩展名的类型",
  78. "指定",
  79. "排除",
  80. ];
  81. const checkedValues = fileTypeList.map((typeInfo) => typeInfo.name);
  82. setFileInfo({
  83. ...fileInfo,
  84. checkboxAll: !fileInfo.checkboxAll,
  85. checkedTypeValues: fileInfo.checkboxAll
  86. ? []
  87. : [...checkedValues, ...otherTypes],
  88. });
  89. };
  90. const checkboxSizeAll = () => {
  91. const checkedSizeValues = fileSizeList.map((typeInfo) => typeInfo.name);
  92. setFileInfo({
  93. ...fileInfo,
  94. checkboxSizeAll: !fileInfo.checkboxSizeAll,
  95. checkedSizeValues: fileInfo.checkboxSizeAll ? [] : checkedSizeValues,
  96. });
  97. };
  98. const onTypesChange: GetProp<typeof Checkbox.Group, "onChange"> = (
  99. checkedValues
  100. ) => {
  101. console.log("checked = ", checkedValues);
  102. setFileInfo({
  103. ...fileInfo,
  104. checkedTypeValues: checkedValues,
  105. });
  106. };
  107. const onAddTypeChange = (types: string) => {
  108. setFileInfo({
  109. ...fileInfo,
  110. addType: types,
  111. });
  112. };
  113. const onPassTypeChange = (types: string) => {
  114. setFileInfo({
  115. ...fileInfo,
  116. passType: types,
  117. });
  118. };
  119. const onSizesChange: GetProp<typeof Checkbox.Group, "onChange"> = (
  120. checkedValues
  121. ) => {
  122. console.log("checkedSizeValues = ", checkedValues);
  123. setFileInfo({
  124. ...fileInfo,
  125. checkedSizeValues: checkedValues,
  126. });
  127. };
  128. return (
  129. <Modal
  130. title={title}
  131. open={isModalOpen}
  132. onOk={handleOk}
  133. onCancel={handleCancel}
  134. >
  135. <Row align="middle">
  136. <span>
  137. <span style={{ color: "red" }}>*</span>文件路径:
  138. </span>
  139. <Row justify="space-around" align="middle">
  140. <span className={styles.filePath}>{fileInfo.path || ""}</span>
  141. <Col>
  142. {fileInfo.path ? (
  143. <RedoOutlined
  144. className={styles.iconHover}
  145. onClick={() => getDir()}
  146. />
  147. ) : (
  148. <PlusCircleOutlined
  149. className={styles.iconHover}
  150. onClick={() => getDir()}
  151. />
  152. )}
  153. </Col>
  154. </Row>
  155. </Row>
  156. <Row align="top">
  157. <span>
  158. <span style={{ color: "transparent" }}>*</span>文件类型:
  159. </span>
  160. <Row
  161. style={{
  162. flex: 1,
  163. padding: "2px 12px",
  164. }}
  165. >
  166. <Row style={{ flex: 1 }}>
  167. <Checkbox
  168. checked={fileInfo.checkboxAll}
  169. onChange={() => checkboxAll()}
  170. value={"全选/不选"}
  171. >
  172. 全选/不选
  173. </Checkbox>
  174. </Row>
  175. <Checkbox.Group
  176. onChange={onTypesChange}
  177. value={fileInfo.checkedTypeValues}
  178. >
  179. {fileTypeList.map((typeInfo) => (
  180. <Col span={7} key={typeInfo.name}>
  181. <Checkbox value={typeInfo.name}>{typeInfo.name}</Checkbox>
  182. </Col>
  183. ))}
  184. <Col span={24}>
  185. <Checkbox value={"其他所有带扩展名的类型"}>
  186. 其他所有带扩展名的类型
  187. </Checkbox>
  188. </Col>
  189. <Col span={24}>
  190. <Checkbox value={"其他所有无扩展名的类型"}>
  191. 其他所有无扩展名的类型
  192. </Checkbox>
  193. </Col>
  194. <Col span={24}>
  195. <Row style={{ flex: 1, marginTop: "8px" }}>
  196. <Col span={4}>
  197. <Checkbox value={"指定"}>指定</Checkbox>
  198. </Col>
  199. <Col span={20}>
  200. <TextArea
  201. value={fileInfo.addType}
  202. onChange={(e) => onAddTypeChange(e.target.value)}
  203. placeholder="格式:.扩展名1.扩展名2…"
  204. autoSize={{ minRows: 3, maxRows: 5 }}
  205. />
  206. </Col>
  207. </Row>
  208. </Col>
  209. <Col span={24}>
  210. <Row style={{ flex: 1, marginTop: "8px" }}>
  211. <Col span={4}>
  212. <Checkbox value={"排除"}>排除</Checkbox>
  213. </Col>
  214. <Col span={20}>
  215. <TextArea
  216. value={fileInfo.passType}
  217. onChange={(e) => onPassTypeChange(e.target.value)}
  218. placeholder="格式:.扩展名1.扩展名2…"
  219. autoSize={{ minRows: 3, maxRows: 5 }}
  220. />
  221. </Col>
  222. </Row>
  223. </Col>
  224. </Checkbox.Group>
  225. </Row>
  226. </Row>
  227. <Row align="top">
  228. <span>
  229. <span style={{ color: "transparent" }}>*</span>文件大小:
  230. </span>
  231. <Row
  232. style={{
  233. flex: 1,
  234. padding: "2px 12px",
  235. }}
  236. >
  237. <Col span={11} key={"全选/不选"}>
  238. <Checkbox
  239. checked={fileInfo.checkboxSizeAll}
  240. onChange={() => checkboxSizeAll()}
  241. >
  242. 全选/不选
  243. </Checkbox>
  244. </Col>
  245. <Checkbox.Group
  246. onChange={onSizesChange}
  247. value={fileInfo.checkedSizeValues}
  248. >
  249. {fileSizeList.map((typeInfo) => (
  250. <Col span={11} key={typeInfo.name}>
  251. <Checkbox value={typeInfo.name}>{typeInfo.name}</Checkbox>
  252. </Col>
  253. ))}
  254. </Checkbox.Group>
  255. </Row>
  256. </Row>
  257. </Modal>
  258. );
  259. }