Skip to content

Commit 0fbcd28

Browse files
authored
feat: add deleteSnapshot api
feat: /device 远端删除快照
2 parents ca43400 + cf56c90 commit 0fbcd28

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

src/utils/api.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,9 @@ export const useDeviceApi = (initOrigin?: string) => {
100100
data,
101101
);
102102
},
103+
deleteSnapshot: async (data: Reqid) => {
104+
return jsonRpc<{ message: string }>(`deleteSnapshot`, data);
105+
},
103106
};
104107
return { origin, api, serverInfo };
105108
};

src/views/DevicePage.vue

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ import type { DataTableColumns, PaginationProps } from 'naive-ui';
1111
import type { SortState } from 'naive-ui/es/data-table/src/interface';
1212
import pLimit from 'p-limit';
1313
import JSON5 from 'json5';
14+
import SvgIcon from '@/components/SvgIcon.vue';
15+
import { dialog } from '@/utils/discrete';
1416
1517
const router = useRouter();
1618
const { api, origin, serverInfo } = useDeviceApi();
@@ -137,7 +139,7 @@ const columns: DataTableColumns<Snapshot> = [
137139
key: `actions`,
138140
title: `操作`,
139141
fixed: 'right',
140-
width: `120px`,
142+
width: `180px`, // 搞宽点要不然装不下
141143
render(row) {
142144
return (
143145
<NSpace size="small">
@@ -148,12 +150,49 @@ const columns: DataTableColumns<Snapshot> = [
148150
>
149151
查看
150152
</NButton>
153+
<NButton
154+
size="small"
155+
type="error"
156+
secondary
157+
loading={deleteSnapshot.loading[row.id]}
158+
onClick={() => deleteSnapshot.invoke(row)}
159+
>
160+
{{
161+
icon: () => <SvgIcon name="delete" />,
162+
default: () => '删除',
163+
}}
164+
</NButton>
151165
</NSpace>
152166
);
153167
},
154168
},
155169
];
156170
171+
const deleteSnapshot = useBatchTask(
172+
async (row: Snapshot) => {
173+
const confirmed = await new Promise<boolean>((res) => {
174+
dialog.warning({
175+
title: '删除快照',
176+
content: `是否确认删除快照 ID: ${row.id}?此操作不可恢复。`,
177+
positiveText: '确认删除',
178+
negativeText: '取消',
179+
onPositiveClick: () => res(true),
180+
onNegativeClick: () => res(false),
181+
onClose: () => res(false),
182+
});
183+
});
184+
if (!confirmed) return;
185+
await api.deleteSnapshot({ id: row.id });
186+
await Promise.all([
187+
snapshotStorage.removeItem(row.id),
188+
screenshotStorage.removeItem(row.id),
189+
]);
190+
snapshots.value = snapshots.value.filter((s) => s.id !== row.id);
191+
message.success('删除成功');
192+
},
193+
(r) => r.id,
194+
);
195+
157196
const pagination = shallowReactive<PaginationProps>({
158197
page: 1,
159198
pageSize: 50,

0 commit comments

Comments
 (0)