FileInfoEditer.tsx 7.5 KB

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