|
@@ -1,59 +1,120 @@
|
|
|
import { Avatar, List, message, Checkbox, Row, Col, Space, Button } from "antd";
|
|
|
import type { CheckboxProps } from "antd";
|
|
|
-import VirtualList from "rc-virtual-list";
|
|
|
import { useEffect, useState } from "react";
|
|
|
-
|
|
|
+import {
|
|
|
+ del_file_by_id,
|
|
|
+ get_fileInfo_by_id,
|
|
|
+ searchDuplicateFile,
|
|
|
+} from "@/services";
|
|
|
+import { message as tauriMessage } from "@tauri-apps/api/dialog";
|
|
|
import styles from "./CalculateListPage.module.less";
|
|
|
-import { UploadOutlined } from "@ant-design/icons";
|
|
|
+import { useParams } from "react-router";
|
|
|
+import { insertSearchFilesPasamsType } from "@/types/files";
|
|
|
+import type { GetProp } from "antd";
|
|
|
+import File from "@/plugins/tauri-plugin-file/file";
|
|
|
+
|
|
|
export default function CalculateListPage() {
|
|
|
- const [data, setData] = useState<UserItem[]>([]);
|
|
|
- interface UserItem {
|
|
|
- email: string;
|
|
|
- gender: string;
|
|
|
- name: {
|
|
|
- first: string;
|
|
|
- last: string;
|
|
|
- title: string;
|
|
|
- };
|
|
|
- nat: string;
|
|
|
- picture: {
|
|
|
- large: string;
|
|
|
- medium: string;
|
|
|
- thumbnail: string;
|
|
|
- };
|
|
|
+ let { fileId } = useParams();
|
|
|
+ const [data, setData] = useState<FileItem[]>([]);
|
|
|
+ const [removeList, setRemoveList] = useState<string[]>([]);
|
|
|
+ interface FileItem {
|
|
|
+ sourceId: number;
|
|
|
+ ids: string;
|
|
|
+ hash: string;
|
|
|
+ count: number;
|
|
|
+ firstItem: insertSearchFilesPasamsType;
|
|
|
+ otherItems: insertSearchFilesPasamsType[];
|
|
|
}
|
|
|
- const ContainerHeight = 600;
|
|
|
- const fakeDataUrl =
|
|
|
- "https://randomuser.me/api/?results=20&inc=name,gender,email,nat,picture&noinfo";
|
|
|
- const onScroll = (e: React.UIEvent<HTMLElement, UIEvent>) => {
|
|
|
- // Refer to: https://developer.mozilla.org/en-US/docs/Web/API/Element/scrollHeight#problems_and_solutions
|
|
|
- if (
|
|
|
- Math.abs(
|
|
|
- e.currentTarget.scrollHeight -
|
|
|
- e.currentTarget.scrollTop -
|
|
|
- ContainerHeight
|
|
|
- ) <= 1
|
|
|
- ) {
|
|
|
- appendData();
|
|
|
+ const appendData = async () => {
|
|
|
+ const [isError, searchDuplicateFileRes] = await searchDuplicateFile({
|
|
|
+ sourceId: `${fileId}`,
|
|
|
+ });
|
|
|
+ if (!isError) {
|
|
|
+ typeof searchDuplicateFileRes === "string" &&
|
|
|
+ (await tauriMessage(searchDuplicateFileRes, {
|
|
|
+ title: "查询失败",
|
|
|
+ type: "error",
|
|
|
+ }));
|
|
|
+ console.log(searchDuplicateFileRes);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (Array.isArray(searchDuplicateFileRes)) {
|
|
|
+ const newData: any[] = [];
|
|
|
+ await searchDuplicateFileRes.reduce(
|
|
|
+ async (prevPromise: any, currentFile: any) => {
|
|
|
+ // 等待上一个 Promise 完成
|
|
|
+ await prevPromise;
|
|
|
+ const ids = currentFile.ids.split(",");
|
|
|
+ const firstItem = await get_fileInfo_by_id(ids[0], `${fileId}`);
|
|
|
+ const otherItems = await Promise.allSettled(
|
|
|
+ ids
|
|
|
+ .map((id: string) => {
|
|
|
+ if (id === ids[0]) {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ return get_fileInfo_by_id(id, `${fileId}`);
|
|
|
+ })
|
|
|
+ .filter((elm: any) => elm)
|
|
|
+ );
|
|
|
+
|
|
|
+ newData.push({
|
|
|
+ ...currentFile,
|
|
|
+ firstItem: firstItem[0],
|
|
|
+ otherItems: otherItems
|
|
|
+ .map((elm) => {
|
|
|
+ if (elm.status === "fulfilled" && !elm.value[1]) {
|
|
|
+ return elm.value[0];
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ })
|
|
|
+ .filter((elm: any) => elm),
|
|
|
+ });
|
|
|
+ return Promise.resolve(0);
|
|
|
+ },
|
|
|
+ Promise.resolve(0)
|
|
|
+ );
|
|
|
+ setData(newData);
|
|
|
}
|
|
|
- };
|
|
|
- const appendData = () => {
|
|
|
- fetch(fakeDataUrl)
|
|
|
- .then((res) => res.json())
|
|
|
- .then((body) => {
|
|
|
- setData(data.concat(body.results));
|
|
|
- // message.success(`${body.results.length} more items loaded!`);
|
|
|
- });
|
|
|
};
|
|
|
|
|
|
useEffect(() => {
|
|
|
appendData();
|
|
|
}, []);
|
|
|
|
|
|
- const onChange: CheckboxProps["onChange"] = (e) => {
|
|
|
- console.log(`checked = ${e.target.checked}`);
|
|
|
+ const onChange: GetProp<typeof Checkbox.Group, "onChange"> = (
|
|
|
+ checkedValues
|
|
|
+ ) => {
|
|
|
+ console.log("checked = ", checkedValues);
|
|
|
+ if (Array.isArray(checkedValues)) {
|
|
|
+ // setRemoveList(checkedValues.filter(elm => typeof elm === 'string'));
|
|
|
+ // setRemoveList(checkedValues)
|
|
|
+ }
|
|
|
+ // value={removeList}
|
|
|
};
|
|
|
|
|
|
+ const CheckboxContent = (item: insertSearchFilesPasamsType) => (
|
|
|
+ <div>{item.path}</div>
|
|
|
+ );
|
|
|
+
|
|
|
+ async function removeFilesByDB() {
|
|
|
+ const filesRes = await File.rmFile(
|
|
|
+ "/Users/sysadmin/Pictures/test/欧洲4_副本5.jpeg"
|
|
|
+ );
|
|
|
+ console.log(9797, filesRes);
|
|
|
+ if (filesRes.code === 200) {
|
|
|
+ await del_file_by_id(
|
|
|
+ "/Users/sysadmin/Pictures/test/欧洲4_副本5.jpeg",
|
|
|
+ "24"
|
|
|
+ );
|
|
|
+ message.success('删除成功!')
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ await tauriMessage(filesRes.msg, {
|
|
|
+ title: "删除失败",
|
|
|
+ type: "error",
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
return (
|
|
|
<div className={styles.CalculateListPage}>
|
|
|
<div
|
|
@@ -62,28 +123,25 @@ export default function CalculateListPage() {
|
|
|
}}
|
|
|
>
|
|
|
<Space>
|
|
|
- <Button type="primary" danger>删除选中的文件</Button>
|
|
|
+ <Button type="primary" danger onClick={() => removeFilesByDB()}>
|
|
|
+ 删除选中的文件
|
|
|
+ </Button>
|
|
|
<Button type="primary">统一移动到指定目录</Button>
|
|
|
<Button type="primary">导出</Button>
|
|
|
</Space>
|
|
|
- <div style={{marginBottom: '12px'}}></div>
|
|
|
- <List>
|
|
|
- <VirtualList
|
|
|
- data={data}
|
|
|
- height={ContainerHeight}
|
|
|
- itemHeight={47}
|
|
|
- itemKey="email"
|
|
|
- onScroll={onScroll}
|
|
|
- >
|
|
|
- {(item: UserItem) => (
|
|
|
+ <div style={{ marginBottom: "12px" }}></div>
|
|
|
+ <Checkbox.Group onChange={onChange} style={{ width: "100%" }}>
|
|
|
+ <div style={{ width: "100%" }}>
|
|
|
+ {data.map((item: FileItem) => (
|
|
|
<div
|
|
|
+ key={item.hash}
|
|
|
style={{
|
|
|
marginBottom: "12px",
|
|
|
}}
|
|
|
>
|
|
|
<div>
|
|
|
- <Checkbox onChange={onChange}>
|
|
|
- /Users/sysadmin/Downloads/Android-SDK@3.6.18.81676_20230117.zip
|
|
|
+ <Checkbox value={item.firstItem.path}>
|
|
|
+ {CheckboxContent(item.firstItem)}
|
|
|
</Checkbox>
|
|
|
</div>
|
|
|
<div
|
|
@@ -92,27 +150,18 @@ export default function CalculateListPage() {
|
|
|
padding: "12px 3px",
|
|
|
}}
|
|
|
>
|
|
|
- <div>
|
|
|
- <Checkbox onChange={onChange}>重复的文件路径1</Checkbox>
|
|
|
- </div>
|
|
|
- <div>
|
|
|
- <Checkbox onChange={onChange}>重复的文件路径2</Checkbox>
|
|
|
- </div>
|
|
|
+ {item.otherItems.map((otherItem) => (
|
|
|
+ <div key={otherItem.path}>
|
|
|
+ <Checkbox value={otherItem.path}>
|
|
|
+ {CheckboxContent(otherItem)}
|
|
|
+ </Checkbox>
|
|
|
+ </div>
|
|
|
+ ))}
|
|
|
</div>
|
|
|
</div>
|
|
|
- // <List.Item key={item.email}>
|
|
|
- // <List.Item.Meta
|
|
|
- // avatar={
|
|
|
- // <Checkbox onChange={onChange}></Checkbox>
|
|
|
- // }
|
|
|
- // title={ <div>文件路径</div>}
|
|
|
- // // description={item.email}
|
|
|
- // />
|
|
|
- // <div>Content</div>
|
|
|
- // </List.Item>
|
|
|
- )}
|
|
|
- </VirtualList>
|
|
|
- </List>
|
|
|
+ ))}
|
|
|
+ </div>
|
|
|
+ </Checkbox.Group>
|
|
|
</div>
|
|
|
</div>
|
|
|
);
|