DuplicateFile.tsx 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. import styles from "./DuplicateFile.module.less";
  2. import {
  3. Col,
  4. Row,
  5. Button,
  6. message,
  7. Table,
  8. Select,
  9. Space,
  10. Input,
  11. Progress,
  12. Pagination,
  13. PaginationProps,
  14. } from "antd";
  15. import { useEffect, useState } from "react";
  16. const { Option } = Select;
  17. import { historyListType, insertSearchFilesPasamsType } from "@/types/files";
  18. import { CopyText } from "@/components/Table/CopyText";
  19. import type { FixedType } from "rc-table/lib/interface";
  20. import FileInfoEditer from "./FileInfoEditer";
  21. import { FileInfoType } from "@/types/files";
  22. import { get_all_history, get_info_by_path, insertSeletedFileHistory } from "@/services";
  23. import dayjs from "dayjs";
  24. import { DEFAULT_TIME_FORMAT } from "@/config";
  25. import Database from "tauri-plugin-sql-api";
  26. import { createSql } from "@/databases/createTableSql";
  27. const db = await Database.load("sqlite:test.db");
  28. const { Search } = Input;
  29. const { TextArea } = Input;
  30. export default function DuplicateFile() {
  31. const [total, setTotal] = useState(20); // 页数
  32. const [current, setCurrent] = useState(1); // 页码
  33. const [usePath, setUsePath] = useState<string>();
  34. const [historyList, setHistoryList] = useState<historyListType[]>([]);
  35. const [fileList, setFileList] = useState<insertSearchFilesPasamsType[]>([
  36. {
  37. id: 1,
  38. path: "D:/code/wb_project/bar_association_app",
  39. time: "2024-01-23",
  40. progress: 80,
  41. },
  42. {
  43. id: 2,
  44. path: "D:/code/wb_project/bar_association_app",
  45. time: "2024-01-23",
  46. progress: 20,
  47. },
  48. {
  49. id: 3,
  50. path: "D:/code/wb_project/bar_association_app",
  51. time: "2024-01-23",
  52. progress: 90,
  53. },
  54. ]);
  55. const [isModalOpen, setIsModalOpen] = useState(false);
  56. const [fileInfo, setFileInfo] = useState<any>({});
  57. const [fileInfoSource, setFileInfoSource] = useState<FileInfoType>({});
  58. const columns = [
  59. {
  60. title: "ID",
  61. dataIndex: "id",
  62. key: "id",
  63. width: 30,
  64. render: (text: string, record: { id: number }) => (
  65. <CopyText width="30px" color="#333" name={record.id}></CopyText>
  66. ),
  67. },
  68. {
  69. title: "路径",
  70. dataIndex: "path",
  71. key: "path",
  72. width: 300,
  73. render: (text: string, record: { path: string }) => (
  74. <CopyText
  75. width="300px"
  76. ellipsisLine={1}
  77. color="#333"
  78. name={record.path}
  79. ></CopyText>
  80. ),
  81. },
  82. {
  83. title: "时间",
  84. dataIndex: "time",
  85. key: "time",
  86. width: 100,
  87. render: (text: string, record: { time: string }) => (
  88. <CopyText
  89. width="100px"
  90. ellipsisLine={1}
  91. color="#333"
  92. name={record.time}
  93. ></CopyText>
  94. ),
  95. },
  96. {
  97. title: "进度",
  98. dataIndex: "time",
  99. key: "time",
  100. with: 200,
  101. render: (text: string, record: { progress: number }) => (
  102. <div style={{ width: "200px" }}>
  103. <Progress percent={record.progress} />
  104. </div>
  105. ),
  106. },
  107. {
  108. title: "操作",
  109. dataIndex: "actions",
  110. key: "actions",
  111. fixed: "right" as FixedType,
  112. width: 220,
  113. render: () => (
  114. <Space size="middle" style={{ width: "220px" }} align="baseline">
  115. <Button onClick={() => setIsModalOpen(true)} type="default">
  116. 修改
  117. </Button>
  118. <Button type="primary">运行</Button>
  119. <Button type="primary" danger>
  120. 删除
  121. </Button>
  122. </Space>
  123. ),
  124. },
  125. ];
  126. useEffect(() => {
  127. getFileList()
  128. }, [])
  129. async function handleOk(newFileInfo: FileInfoType) {
  130. console.log(180, newFileInfo);
  131. const res = await insertSeletedFileHistory(newFileInfo.path, newFileInfo);
  132. console.log(133, res);
  133. }
  134. function handleCancel() {
  135. setFileInfo({});
  136. setIsModalOpen(false);
  137. }
  138. async function openModal(info?: FileInfoType) {
  139. initDB()
  140. // setIsModalOpen(true);
  141. // const res = await insertSeletedFileHistory('/Users/sysadmin/Downloads');
  142. // console.log(133, res);
  143. // const res = await get_info_by_path('/Users/sysadmin/Downloads')
  144. // console.log(135, res)
  145. /* setIsModalOpen(true);
  146. setFileInfoSource({
  147. path: "/Users/sysadmin/Downloads",
  148. checkedTypeValues: ["音频", "图片"],
  149. checkedSizeValues: ["巨大(4GB+)", "大(128MB ~ 1GB-)"],
  150. addType: "2131231231231"
  151. }); */
  152. /*
  153. {path: "/Users/sysadmin/Downloads", checkedTypeValues: ["音频", "图片"], checkedSizeValues: ["巨大(4GB+)", "大(128MB ~ 1GB-)"]}
  154. [Log] 180 (FileInfoEditer.tsx, line 69)
  155. Object
  156. addType: "2131231231231"
  157. checkedSizeValues: ["巨大(4GB+)", "大(128MB ~ 1GB-)", "中(1MB ~ 128MB-)"] (3)
  158. checkedTypeValues: ["音频", "图片"] (2)
  159. path: "/Users/sysadmin/Downloads"
  160. Object Prototype
  161. */
  162. }
  163. async function getFileList() {
  164. const {data, total: localeTotal} = await get_all_history(current, total);
  165. console.log(173, data);
  166. const newFileList = data.map(item => {
  167. return {
  168. ...item,
  169. time: dayjs(item.time).format(DEFAULT_TIME_FORMAT)
  170. }
  171. })
  172. setFileList(newFileList)
  173. setTotal(localeTotal)
  174. }
  175. async function initDB() {
  176. try {
  177. const result = await db.execute(createSql.search_files);
  178. console.log(179, result);
  179. } catch (error) {
  180. console.log(182, error);
  181. }
  182. }
  183. const onPaginationChange: PaginationProps['onChange'] = (page) => {
  184. console.log(page);
  185. setCurrent(page);
  186. };
  187. return (
  188. <div className={styles.DuplicateFileBox}>
  189. <FileInfoEditer
  190. title="添加目录"
  191. showModal={isModalOpen}
  192. fileInfoSource={fileInfoSource}
  193. onClickOk={handleOk}
  194. onClickCancel={handleCancel}
  195. ></FileInfoEditer>
  196. <Row className={styles.searchBox}>
  197. <Col span={8}>
  198. <Search placeholder="请输入" allowClear />
  199. </Col>
  200. <Col offset={8} span={8} style={{ textAlign: "right" }}>
  201. <Button type="primary" onClick={() => openModal()}>
  202. 新增
  203. </Button>
  204. </Col>
  205. </Row>
  206. <br />
  207. <Row
  208. style={{
  209. width: "100%",
  210. overflow: "scroll",
  211. }}
  212. >
  213. <Table
  214. style={{
  215. width: "100%",
  216. }}
  217. rowKey={"id"}
  218. dataSource={fileList}
  219. columns={columns}
  220. pagination={false}
  221. />
  222. </Row>
  223. <Row justify="end" style={{ width: "100%", marginTop: "12px" }}>
  224. <Pagination current={current} total={total} onChange={onPaginationChange} />
  225. </Row>
  226. </div>
  227. );
  228. }