Skip to content

Commit 15b4c27

Browse files
committed
feat: 新增分享管理中订阅项的复制预览面板
1 parent b7aee26 commit 15b4c27

File tree

3 files changed

+140
-26
lines changed

3 files changed

+140
-26
lines changed

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.14.326",
3+
"version": "2.14.327",
44
"private": true,
55
"scripts": {
66
"dev": "vite --host",

src/components/PreviewPanel.vue

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,26 +70,53 @@
7070
const { copy, isSupported } = useClipboard();
7171
const { toClipboard: copyFallback } = useV3Clipboard();
7272
const { showNotify } = useAppNotifyStore();
73-
const { name, type, general, notify, tipsTitle, tipsContent, desc,tipsCancelText, tipsOkText } = defineProps<{
73+
const { name, type, url, general, notify, tipsTitle, tipsContent, desc,tipsCancelText, tipsOkText } = defineProps<{
7474
name: string;
7575
type: 'sub' | 'collection';
7676
general: string;
7777
notify: string;
7878
desc: string;
79+
url?: string;
7980
tipsTitle?: string;
8081
tipsContent?: string;
8182
tipsCancelText?: string;
8283
tipsOkText?: string;
8384
}>();
8485
8586
const { currentUrl: host } = useHostAPI();
87+
88+
const buildUrlWithQuery = (url: string, query: Record<string, string | boolean>): string => {
89+
if (!url) {
90+
return '';
91+
}
92+
const queryString = Object.entries(query)
93+
.filter(([_, value]) => value !== undefined && value !== null)
94+
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
95+
.join('&');
96+
97+
if (!queryString) {
98+
return url;
99+
}
100+
101+
const hasQueryParams = url.includes('?');
102+
return `${url}${hasQueryParams ? '&' : '?'}${queryString}`;
103+
};
104+
86105
const getUrl = (path: string) => {
87-
const query = {} as Record<string, string | boolean>
88-
if(path !== null) query.target = path;
89-
if(includeUnsupportedProxy.value) query.includeUnsupportedProxy = true;
90-
return `${host.value}/download/${
91-
type === 'sub' ? '' : 'collection/'
92-
}${encodeURIComponent(name)}${Object.keys(query).length > 0 ? `?${Object.entries(query).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&')}` : ''}`;
106+
const query = {} as Record<string, string | boolean>;
107+
if (path !== null) {
108+
query.target = path;
109+
}
110+
if (includeUnsupportedProxy.value) {
111+
query.includeUnsupportedProxy = true;
112+
}
113+
if (url) {
114+
return buildUrlWithQuery(url, query);
115+
} else {
116+
return `${host.value}/download/${
117+
type === "sub" ? "" : "collection/"
118+
}${encodeURIComponent(name)}${Object.keys(query).length > 0 ? `?${Object.entries(query).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&')}` : ''}`;
119+
}
93120
}
94121
const targetCopy = async (path: string) => {
95122
const url = getUrl(path);

src/components/ShareListItem.vue

Lines changed: 105 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
<template>
22
<!-- 滚动内容 -->
3-
<nut-swipe ref="swipe" class="sub-item-swipe" :disabled="props.disabled">
3+
<nut-swipe
4+
ref="swipe"
5+
class="sub-item-swipe"
6+
:disabled="props.disabled"
7+
@close="setIsMoveClose()"
8+
@open="setIsMoveOpen()"
9+
@click="onClickPreviews()"
10+
>
411
<div
512
class="sub-item-wrapper"
613
:style="{ padding: appearanceSetting.isSimpleMode ? '9px' : '16px' }"
@@ -123,6 +130,7 @@ import { computed, createVNode, ref } from "vue";
123130
import { useI18n } from "vue-i18n";
124131
import logoIcon from "@/assets/icons/logo.png";
125132
import logoRedIcon from "@/assets/icons/logo-red.png";
133+
import PreviewPanel from "@/components/PreviewPanel.vue";
126134
import { useBackend } from "@/hooks/useBackend";
127135
import { useHostAPI } from "@/hooks/useHostAPI";
128136
import { usePopupRoute } from "@/hooks/usePopupRoute";
@@ -157,7 +165,7 @@ const name = computed(() => {
157165
158166
const displayName = computed(() => {
159167
return props?.data?.displayName;
160-
})
168+
});
161169
const remark = computed(() => {
162170
return props?.data?.remark;
163171
});
@@ -236,23 +244,26 @@ const getOneShareOrigin = async (keyName: string) => {
236244
case "file":
237245
return subsStore.getOneFile(keyName);
238246
}
239-
}
247+
};
248+
240249
const onClickShareLink = async () => {
241-
console.log("props", props);
242-
const keyName = encodeURIComponent(name.value);
243-
const item = await getOneShareOrigin(keyName);
244-
console.log('item', item)
245-
if (!item) {
246-
return Toast.text(t("sharePage.noOriginalTips"));
247-
}
248-
if (type.value === 'file') {
249-
router.push(`/edit/files/${keyName}`);
250-
}
251-
if (type.value === 'sub') {
252-
router.push(`/edit/subs/${keyName}`);
253-
}
254-
if (type.value === 'col') {
255-
router.push(`/edit/collections/${keyName}`);
250+
try {
251+
const keyName = encodeURIComponent(name.value);
252+
const item = await getOneShareOrigin(keyName);
253+
if (!item) {
254+
return Toast.text(t("sharePage.noOriginalTips"));
255+
}
256+
if (type.value === "file") {
257+
router.push(`/edit/files/${keyName}`);
258+
}
259+
if (type.value === "sub") {
260+
router.push(`/edit/subs/${keyName}`);
261+
}
262+
if (type.value === "col") {
263+
router.push(`/edit/collections/${keyName}`);
264+
}
265+
} catch (error) {
266+
console.error(error);
256267
}
257268
};
258269
@@ -276,6 +287,82 @@ const onClickDelete = () => {
276287
});
277288
};
278289
290+
const ismove = ref(false);
291+
292+
// 增加延迟防止打开时 触发不了
293+
const setTimeoutTF = () => {
294+
setTimeout(() => {
295+
ismove.value = false;
296+
}, 200);
297+
};
298+
299+
const setIsMoveOpen = () => {
300+
ismove.value = true;
301+
setTimeoutTF();
302+
};
303+
304+
const setIsMoveClose = () => {
305+
ismove.value = true;
306+
setTimeoutTF();
307+
};
308+
309+
const secretPath = computed(() => {
310+
return env.value?.meta?.node?.env?.SUB_STORE_FRONTEND_BACKEND_PATH || "";
311+
});
312+
313+
const getShareUrl = () => {
314+
try {
315+
const { type, name, token } = props.data;
316+
const shareUrl = `${host.value.replace(
317+
new RegExp(`${secretPath.value}$`),
318+
"",
319+
)}/share/${type}/${encodeURIComponent(name)}?token=${encodeURIComponent(
320+
token,
321+
)}`;
322+
return shareUrl;
323+
} catch (error) {
324+
console.error(error);
325+
return "";
326+
}
327+
};
328+
const onClickPreviews = () => {
329+
console.log('name', name.value);
330+
console.log('props', props.data);
331+
if (type.value === "file") {
332+
return;
333+
}
334+
if (ismove.value) {
335+
return false;
336+
}
337+
swipeController();
338+
const url = getShareUrl();
339+
console.log('url', url);
340+
Dialog({
341+
title: t("subPage.previewTitle"),
342+
content: createVNode(PreviewPanel, {
343+
name,
344+
type: "share",
345+
url,
346+
general: t("subPage.panel.general"),
347+
notify: t("subPage.copyNotify.succeed"),
348+
tipsTitle: t(`subPage.panel.tips.title`),
349+
tipsContent: `${t("subPage.panel.tips.content")}\n${t(
350+
"syncPage.addArtForm.includeUnsupportedProxy.tips.content",
351+
)}`,
352+
desc: t(`subPage.panel.tips.desc`),
353+
tipsOkText: t(`subPage.panel.tips.ok`),
354+
tipsCancelText: t(`subPage.panel.tips.cancel`),
355+
}),
356+
onOpened: () => swipe.value.close(),
357+
popClass: "auto-dialog",
358+
// @ts-ignore
359+
closeOnClickOverlay: true,
360+
noOkBtn: true,
361+
noCancelBtn: true,
362+
closeOnPopstate: true,
363+
lockScroll: false,
364+
});
365+
};
279366
</script>
280367

281368
<style lang="scss" scoped>

0 commit comments

Comments
 (0)