Skip to content

Commit cba4a59

Browse files
committed
feat: 增加预览组件的刷新按钮
1 parent 924d82f commit cba4a59

9 files changed

Lines changed: 276 additions & 135 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sub-store-front-end",
3-
"version": "2.16.38",
3+
"version": "2.16.39",
44
"private": true,
55
"scripts": {
66
"dev": "vite --host",

src/components/FileListItem.vue

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,9 @@
222222
v-if="filePreviewIsVisible"
223223
:name="name"
224224
:previewData="previewData"
225+
:show-refresh="true"
225226
@closePreview="closePreview"
227+
@refresh="refreshPreview"
226228
/>
227229
</template>
228230

@@ -356,28 +358,51 @@
356358
router.back();
357359
};
358360
359-
const previewFile = async () => {
361+
const doPreview = async (fileData: any) => {
360362
Toast.loading('生成中...', { id: 'compare', cover: true, duration: 1500 });
361-
const res = await useSubsApi().compareSub(
362-
'file',
363-
props.file
364-
);
363+
try {
364+
const res = await subsApi.compareSub('file', fileData);
365+
if (res?.data?.status === 'success') {
366+
previewData.value = res.data.data;
367+
} else {
368+
previewData.value = null;
369+
}
370+
} catch (e) {
371+
console.error(e);
372+
previewData.value = null;
373+
}
374+
Toast.hide('compare');
375+
};
365376
366-
if (res?.data?.status === 'success') {
367-
previewData.value = res.data.data;
377+
const openPreviewPanel = () => {
378+
scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
379+
globalStore.setSavedPositions(route.path, { left: 0, top: scrollTop });
368380
369-
scrollTop = document.documentElement.scrollTop || document.body.scrollTop
381+
document.querySelector('html').style['overflow-y'] = 'hidden';
382+
document.querySelector('html').style.height = '100%';
383+
document.body.style.height = '100%';
384+
document.body.style['overflow-y'] = 'hidden';
385+
(document.querySelector('#app') as HTMLElement).style['overflow-y'] = 'hidden';
386+
(document.querySelector('#app') as HTMLElement).style.height = '100%';
370387
371-
globalStore.setSavedPositions(route.path, { left: 0, top: scrollTop })
388+
filePreviewIsVisible.value = true;
389+
};
372390
373-
document.querySelector('html').style['overflow-y'] = 'hidden';
374-
document.querySelector('html').style.height = '100%';
375-
document.body.style.height = '100%';
376-
document.body.style['overflow-y'] = 'hidden';
377-
(document.querySelector('#app') as HTMLElement).style['overflow-y'] = 'hidden';
378-
(document.querySelector('#app') as HTMLElement).style.height = '100%';
391+
const previewFile = async () => {
392+
await doPreview(props.file);
393+
openPreviewPanel();
394+
};
379395
380-
filePreviewIsVisible.value = true;
396+
const refreshPreview = async () => {
397+
try {
398+
const fileRes = await filesApi.getWholeFile(name);
399+
const latestFile = (fileRes?.data?.status === 'success' ? fileRes.data.data : null) ?? props.file;
400+
await doPreview(latestFile);
401+
// 同步更新 store,使进入编辑器时数据一致
402+
subsStore.setOneData('files', name, latestFile);
403+
} catch (e) {
404+
console.error(e);
405+
previewData.value = null;
381406
Toast.hide('compare');
382407
}
383408
};

src/components/SubListItem.vue

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,9 @@
295295
v-if="compareTableIsVisible"
296296
:name="name"
297297
:compare-data="compareData"
298+
:show-refresh="true"
298299
@closeCompare="closeCompare"
300+
@refresh="refreshCompare"
299301
/>
300302
</template>
301303

@@ -582,32 +584,60 @@ const openAppUrl = () => {
582584
}
583585
};
584586
585-
const compareSub = async () => {
587+
const fetchCompareData = async (data?: any) => {
586588
Toast.loading("生成节点对比中...", {
587589
id: "compare",
588590
cover: true,
589591
duration: 1500,
590592
});
591-
const res = await useSubsApi().compareSub(
592-
props.type,
593-
props.sub ?? props.collection,
594-
);
595-
if (res?.data?.status === "success") {
596-
compareData.value = res.data.data;
593+
try {
594+
const res = await subsApi.compareSub(
595+
props.type,
596+
data ?? props.sub ?? props.collection,
597+
);
598+
if (res?.data?.status === "success") {
599+
compareData.value = res.data.data;
600+
} else {
601+
compareData.value = null;
602+
}
603+
} catch (e) {
604+
console.error(e);
605+
compareData.value = null;
606+
}
607+
Toast.hide("compare");
608+
};
609+
610+
const openComparePanel = () => {
611+
scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
612+
globalStore.setSavedPositions(route.path, { left: 0, top: scrollTop });
597613
598-
scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
614+
document.querySelector("html").style["overflow-y"] = "hidden";
615+
document.querySelector("html").style.height = "100%";
616+
document.body.style.height = "100%";
617+
document.body.style["overflow-y"] = "hidden";
618+
(document.querySelector("#app") as HTMLElement).style["overflow-y"] = "hidden";
619+
(document.querySelector("#app") as HTMLElement).style.height = "100%";
599620
600-
globalStore.setSavedPositions(route.path, { left: 0, top: scrollTop });
621+
compareTableIsVisible.value = true;
622+
};
601623
602-
document.querySelector("html").style["overflow-y"] = "hidden";
603-
document.querySelector("html").style.height = "100%";
604-
document.body.style.height = "100%";
605-
document.body.style["overflow-y"] = "hidden";
606-
(document.querySelector("#app") as HTMLElement).style["overflow-y"] =
607-
"hidden";
608-
(document.querySelector("#app") as HTMLElement).style.height = "100%";
624+
const compareSub = async () => {
625+
await fetchCompareData();
626+
openComparePanel();
627+
};
609628
610-
compareTableIsVisible.value = true;
629+
const refreshCompare = async () => {
630+
try {
631+
// 重新获取最新订阅/组合订阅信息
632+
const type = props.type === 'collection' ? 'collection' : 'sub';
633+
const infoRes = await subsApi.getOne(type, name);
634+
const latestData = (infoRes?.data?.status === 'success' ? infoRes.data.data : null) ?? (props.sub ?? props.collection);
635+
await fetchCompareData(latestData);
636+
// 同步更新 store,使进入编辑器时数据一致
637+
subsStore.setOneData(props.type === 'collection' ? 'collections' : 'subs', name, latestData);
638+
} catch (e) {
639+
console.error(e);
640+
compareData.value = null;
611641
Toast.hide("compare");
612642
}
613643
};
@@ -904,6 +934,7 @@ const onClickRefresh = async () => {
904934
display: -webkit-box;
905935
-webkit-box-orient: vertical;
906936
-webkit-line-clamp: 1;
937+
line-clamp: 1;
907938
word-wrap: break-word;
908939
word-break: break-all;
909940
overflow: hidden;
@@ -961,6 +992,7 @@ const onClickRefresh = async () => {
961992
display: -webkit-box;
962993
-webkit-box-orient: vertical;
963994
-webkit-line-clamp: 3;
995+
line-clamp: 3;
964996
word-wrap: break-word;
965997
word-break: break-all;
966998
overflow: hidden;
@@ -977,6 +1009,7 @@ const onClickRefresh = async () => {
9771009
display: -webkit-box;
9781010
-webkit-box-orient: vertical;
9791011
-webkit-line-clamp: 2;
1012+
line-clamp: 2;
9801013
word-wrap: break-word;
9811014
word-break: break-all;
9821015
overflow: hidden;
@@ -994,6 +1027,7 @@ const onClickRefresh = async () => {
9941027
display: -webkit-box;
9951028
-webkit-box-orient: vertical;
9961029
-webkit-line-clamp: 1;
1030+
line-clamp: 1;
9971031
word-wrap: break-word;
9981032
word-break: break-all;
9991033
overflow: hidden;

src/plugin/awesomeIcon.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
faAnglesRight,
55
faAngleRight,
66
faArrowRotateRight,
7+
faArrowsRotate,
78
faArrowUpRightFromSquare,
89
faBan,
910
faCheck,
@@ -64,6 +65,7 @@ library.add(faXmark);
6465
library.add(faLocationArrow);
6566
library.add(faCode);
6667
library.add(faArrowRotateRight);
68+
library.add(faArrowsRotate);
6769
library.add(faAnglesRight);
6870
library.add(faAngleRight);
6971
library.add(faCloudArrowDown);

src/store/subs.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ export const useSubsStore = defineStore('subsStore', {
267267
console.log('fetchSubsData err', err);
268268
});
269269
},
270+
setOneData(type: string, name: string, data: any) {
271+
const index = this[type].findIndex(item => item.name === name);
272+
if (index !== -1) {
273+
this[type][index] = data;
274+
}
275+
},
270276
async updateOneData(type: string, name: string) {
271277
try {
272278
let res;

0 commit comments

Comments
 (0)