FileInfoEditer.tsx 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  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, homeDir } 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 homeDir(),
  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. // TODO 全选、全不选的交互 等主体功能完善之后, 再开发
  105. setFileInfo({
  106. ...fileInfo,
  107. checkedTypeValues: checkedValues,
  108. });
  109. };
  110. const onAddTypeChange = (types: string) => {
  111. setFileInfo({
  112. ...fileInfo,
  113. addType: types,
  114. });
  115. };
  116. const onPassTypeChange = (types: string) => {
  117. setFileInfo({
  118. ...fileInfo,
  119. passType: types,
  120. });
  121. };
  122. const onSizesChange: GetProp<typeof Checkbox.Group, "onChange"> = (
  123. checkedValues
  124. ) => {
  125. console.log("checkedSizeValues = ", checkedValues);
  126. setFileInfo({
  127. ...fileInfo,
  128. checkedSizeValues: checkedValues,
  129. });
  130. };
  131. return (
  132. <Modal
  133. title={title}
  134. open={isModalOpen}
  135. onOk={handleOk}
  136. onCancel={handleCancel}
  137. >
  138. <Row align="middle">
  139. <span>
  140. <span style={{ color: "red" }}>*</span>文件路径:
  141. </span>
  142. <Row justify="space-around" align="middle">
  143. <span className={styles.filePath}>{fileInfo.path || ""}</span>
  144. <Col>
  145. {fileInfo.path ? (
  146. <RedoOutlined
  147. className={styles.iconHover}
  148. onClick={() => getDir()}
  149. />
  150. ) : (
  151. <PlusCircleOutlined
  152. className={styles.iconHover}
  153. onClick={() => getDir()}
  154. />
  155. )}
  156. </Col>
  157. </Row>
  158. </Row>
  159. <Row align="top">
  160. <span>
  161. <span style={{ color: "transparent" }}>*</span>文件类型:
  162. </span>
  163. <Row
  164. style={{
  165. flex: 1,
  166. padding: "2px 12px",
  167. }}
  168. >
  169. <Row style={{ flex: 1 }}>
  170. <Checkbox
  171. checked={fileInfo.checkboxAll}
  172. onChange={() => checkboxAll()}
  173. value={"全选/不选"}
  174. >
  175. 全选/不选
  176. </Checkbox>
  177. </Row>
  178. <Checkbox.Group
  179. onChange={onTypesChange}
  180. value={fileInfo.checkedTypeValues}
  181. >
  182. {fileTypeList.map((typeInfo) => (
  183. <Col span={7} key={typeInfo.name}>
  184. <Checkbox value={typeInfo.name}>{typeInfo.name}</Checkbox>
  185. </Col>
  186. ))}
  187. <Col span={24}>
  188. <Checkbox value={"其他所有带扩展名的类型"}>
  189. 其他所有带扩展名的类型
  190. </Checkbox>
  191. </Col>
  192. <Col span={24}>
  193. <Checkbox value={"其他所有无扩展名的类型"}>
  194. 其他所有无扩展名的类型
  195. </Checkbox>
  196. </Col>
  197. <Col span={24}>
  198. <Row style={{ flex: 1, marginTop: "8px" }}>
  199. <Col span={4}>
  200. <Checkbox value={"指定"}>指定</Checkbox>
  201. </Col>
  202. <Col span={20}>
  203. <TextArea
  204. value={fileInfo.addType}
  205. onChange={(e) => onAddTypeChange(e.target.value)}
  206. placeholder="格式:.扩展名1.扩展名2…"
  207. autoSize={{ minRows: 3, maxRows: 5 }}
  208. />
  209. </Col>
  210. </Row>
  211. </Col>
  212. <Col span={24}>
  213. <Row style={{ flex: 1, marginTop: "8px" }}>
  214. <Col span={4}>
  215. <Checkbox value={"排除"}>排除</Checkbox>
  216. </Col>
  217. <Col span={20}>
  218. <TextArea
  219. value={fileInfo.passType}
  220. onChange={(e) => onPassTypeChange(e.target.value)}
  221. placeholder="格式:.扩展名1.扩展名2…"
  222. autoSize={{ minRows: 3, maxRows: 5 }}
  223. />
  224. </Col>
  225. </Row>
  226. </Col>
  227. </Checkbox.Group>
  228. </Row>
  229. </Row>
  230. <Row align="top">
  231. <span>
  232. <span style={{ color: "transparent" }}>*</span>文件大小:
  233. </span>
  234. <Row
  235. style={{
  236. flex: 1,
  237. padding: "2px 12px",
  238. }}
  239. >
  240. <Col span={11} key={"全选/不选"}>
  241. <Checkbox
  242. checked={fileInfo.checkboxSizeAll}
  243. onChange={() => checkboxSizeAll()}
  244. >
  245. 全选/不选
  246. </Checkbox>
  247. </Col>
  248. <Checkbox.Group
  249. onChange={onSizesChange}
  250. value={fileInfo.checkedSizeValues}
  251. >
  252. {fileSizeList.map((typeInfo) => (
  253. <Col span={11} key={typeInfo.name}>
  254. <Checkbox value={typeInfo.name}>{typeInfo.name}</Checkbox>
  255. </Col>
  256. ))}
  257. </Checkbox.Group>
  258. </Row>
  259. </Row>
  260. </Modal>
  261. );
  262. }