FileInfoEditer.tsx 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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. console.log(55, selected);
  51. if (selected && selected.length) {
  52. setFileInfo({
  53. ...fileInfo,
  54. path: `${selected}`,
  55. });
  56. // setUsePath(`${selected}`);
  57. // 最多记录 100 条用户操作的历史数据
  58. // const files = await File.getAllList(`${selected}`);
  59. }
  60. // await invoke("file_sort", { path: selected });
  61. // setFile([...fileStr, await invoke("file_sort", { path: selected })]);
  62. }
  63. function handleOk() {
  64. if (!fileInfo?.path) {
  65. message.error("请选择文件路径");
  66. }
  67. console.log(180, fileInfo);
  68. onClickOk && onClickOk(fileInfo);
  69. }
  70. function handleCancel() {
  71. setFileInfo({});
  72. setIsModalOpen(false);
  73. onClickCancel && onClickCancel();
  74. }
  75. const checkboxAll = () => {
  76. const otherTypes = [
  77. "其他所有带扩展名的类型",
  78. "其他所有无扩展名的类型",
  79. "指定",
  80. "排除",
  81. ];
  82. const checkedValues = fileTypeList.map((typeInfo) => typeInfo.name);
  83. setFileInfo({
  84. ...fileInfo,
  85. checkboxAll: !fileInfo.checkboxAll,
  86. checkedTypeValues: fileInfo.checkboxAll
  87. ? []
  88. : [...checkedValues, ...otherTypes],
  89. });
  90. };
  91. const checkboxSizeAll = () => {
  92. const checkedSizeValues = fileSizeList.map((typeInfo) => typeInfo.name);
  93. setFileInfo({
  94. ...fileInfo,
  95. checkboxSizeAll: !fileInfo.checkboxSizeAll,
  96. checkedSizeValues: fileInfo.checkboxSizeAll ? [] : checkedSizeValues,
  97. });
  98. };
  99. const onTypesChange: GetProp<typeof Checkbox.Group, "onChange"> = (
  100. checkedValues
  101. ) => {
  102. console.log("checked = ", checkedValues);
  103. setFileInfo({
  104. ...fileInfo,
  105. checkedTypeValues: checkedValues,
  106. });
  107. };
  108. const onAddTypeChange = (types: string) => {
  109. setFileInfo({
  110. ...fileInfo,
  111. addType: types,
  112. });
  113. };
  114. const onPassTypeChange = (types: string) => {
  115. setFileInfo({
  116. ...fileInfo,
  117. passType: types,
  118. });
  119. };
  120. const onSizesChange: GetProp<typeof Checkbox.Group, "onChange"> = (
  121. checkedValues
  122. ) => {
  123. console.log("checkedSizeValues = ", checkedValues);
  124. setFileInfo({
  125. ...fileInfo,
  126. checkedSizeValues: checkedValues,
  127. });
  128. };
  129. return (
  130. <Modal
  131. title={title}
  132. open={isModalOpen}
  133. onOk={handleOk}
  134. onCancel={handleCancel}
  135. >
  136. <Row align="middle">
  137. <span>
  138. <span style={{ color: "red" }}>*</span>文件路径:
  139. </span>
  140. <Row justify="space-around" align="middle">
  141. <span className={styles.filePath}>{fileInfo.path || ""}</span>
  142. <Col>
  143. {fileInfo.path ? (
  144. <RedoOutlined
  145. className={styles.iconHover}
  146. onClick={() => getDir()}
  147. />
  148. ) : (
  149. <PlusCircleOutlined
  150. className={styles.iconHover}
  151. onClick={() => getDir()}
  152. />
  153. )}
  154. </Col>
  155. </Row>
  156. </Row>
  157. <Row align="top">
  158. <span>
  159. <span style={{ color: "transparent" }}>*</span>文件类型:
  160. </span>
  161. <Row
  162. style={{
  163. flex: 1,
  164. padding: "2px 12px",
  165. }}
  166. >
  167. <Row style={{ flex: 1 }}>
  168. <Checkbox
  169. checked={fileInfo.checkboxAll}
  170. onChange={() => checkboxAll()}
  171. value={"全选/不选"}
  172. >
  173. 全选/不选
  174. </Checkbox>
  175. </Row>
  176. <Checkbox.Group
  177. onChange={onTypesChange}
  178. value={fileInfo.checkedTypeValues}
  179. >
  180. {fileTypeList.map((typeInfo) => (
  181. <Col span={7} key={typeInfo.name}>
  182. <Checkbox value={typeInfo.name}>{typeInfo.name}</Checkbox>
  183. </Col>
  184. ))}
  185. <Col span={24}>
  186. <Checkbox value={"其他所有带扩展名的类型"}>
  187. 其他所有带扩展名的类型
  188. </Checkbox>
  189. </Col>
  190. <Col span={24}>
  191. <Checkbox value={"其他所有无扩展名的类型"}>
  192. 其他所有无扩展名的类型
  193. </Checkbox>
  194. </Col>
  195. <Col span={24}>
  196. <Row style={{ flex: 1, marginTop: "8px" }}>
  197. <Col span={4}>
  198. <Checkbox value={"指定"}>指定</Checkbox>
  199. </Col>
  200. <Col span={20}>
  201. <TextArea
  202. value={fileInfo.addType}
  203. onChange={(e) => onAddTypeChange(e.target.value)}
  204. placeholder="格式:.扩展名1.扩展名2…"
  205. autoSize={{ minRows: 3, maxRows: 5 }}
  206. />
  207. </Col>
  208. </Row>
  209. </Col>
  210. <Col span={24}>
  211. <Row style={{ flex: 1, marginTop: "8px" }}>
  212. <Col span={4}>
  213. <Checkbox value={"排除"}>排除</Checkbox>
  214. </Col>
  215. <Col span={20}>
  216. <TextArea
  217. value={fileInfo.passType}
  218. onChange={(e) => onPassTypeChange(e.target.value)}
  219. placeholder="格式:.扩展名1.扩展名2…"
  220. autoSize={{ minRows: 3, maxRows: 5 }}
  221. />
  222. </Col>
  223. </Row>
  224. </Col>
  225. </Checkbox.Group>
  226. </Row>
  227. </Row>
  228. <Row align="top">
  229. <span>
  230. <span style={{ color: "transparent" }}>*</span>文件大小:
  231. </span>
  232. <Row
  233. style={{
  234. flex: 1,
  235. padding: "2px 12px",
  236. }}
  237. >
  238. <Col span={11} key={"全选/不选"}>
  239. <Checkbox
  240. checked={fileInfo.checkboxSizeAll}
  241. onChange={() => checkboxSizeAll()}
  242. >
  243. 全选/不选
  244. </Checkbox>
  245. </Col>
  246. <Checkbox.Group
  247. onChange={onSizesChange}
  248. value={fileInfo.checkedSizeValues}
  249. >
  250. {fileSizeList.map((typeInfo) => (
  251. <Col span={11} key={typeInfo.name}>
  252. <Checkbox value={typeInfo.name}>{typeInfo.name}</Checkbox>
  253. </Col>
  254. ))}
  255. </Checkbox.Group>
  256. </Row>
  257. </Row>
  258. </Modal>
  259. );
  260. }