Skip to content

Commit 24d0d87

Browse files
committed
feat: 预览界面
1 parent f157955 commit 24d0d87

File tree

8 files changed

+94
-33
lines changed

8 files changed

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

src/components/PreviewPanel.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
<div class="actions">
2222
<a
23-
:href="getUrl(platform.path)"
23+
:href="getUrl(platform.path, true)"
2424
target="_blank"
2525
>
2626
<svg-icon
@@ -70,8 +70,9 @@
7070
const { copy, isSupported } = useClipboard();
7171
const { toClipboard: copyFallback } = useV3Clipboard();
7272
const { showNotify } = useAppNotifyStore();
73-
const { name, type, url, general, notify, tipsTitle, tipsContent, desc,tipsCancelText, tipsOkText } = defineProps<{
73+
const { name, displayName, type, url, general, notify, tipsTitle, tipsContent, desc,tipsCancelText, tipsOkText } = defineProps<{
7474
name: string;
75+
displayName?: string;
7576
type: 'sub' | 'collection';
7677
general: string;
7778
notify: string;
@@ -102,21 +103,23 @@
102103
return `${url}${hasQueryParams ? '&' : '?'}${queryString}`;
103104
};
104105
105-
const getUrl = (path: string) => {
106+
const getUrl = (path: string, preview: boolean = false) => {
106107
const query = {} as Record<string, string | boolean>;
107108
if (path !== null) {
108109
query.target = path;
109110
}
110111
if (includeUnsupportedProxy.value) {
111112
query.includeUnsupportedProxy = true;
112113
}
114+
let previewUrl
113115
if (url) {
114-
return buildUrlWithQuery(url, query);
116+
previewUrl = buildUrlWithQuery(url, query);
115117
} else {
116-
return `${host.value}/download/${
118+
previewUrl = `${host.value}/download/${
117119
type === "sub" ? "" : "collection/"
118120
}${encodeURIComponent(name)}${Object.keys(query).length > 0 ? `?${Object.entries(query).map(([key, value]) => `${key}=${encodeURIComponent(value)}`).join('&')}` : ''}`;
119121
}
122+
return preview ? `/preview?url=${encodeURIComponent(previewUrl)}&name=${encodeURIComponent(displayName || name)}` : previewUrl
120123
}
121124
const targetCopy = async (path: string) => {
122125
const url = getUrl(path);

src/components/ShareListItem.vue

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,12 @@ const onClickPreviews = () => {
356356
swipeController();
357357
const url = getShareUrl();
358358
console.log('url', url);
359+
359360
Dialog({
360361
title: t("subPage.previewTitle"),
361362
content: createVNode(PreviewPanel, {
362-
name,
363+
name: name.value,
364+
displayName: displayName.value,
363365
type: "share",
364366
url,
365367
general: t("subPage.panel.general"),

src/components/SubListItem.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ const onClickPreviews = () => {
656656
title: t("subPage.previewTitle"),
657657
content: createVNode(PreviewPanel, {
658658
name,
659+
displayName,
659660
type: props.type,
660661
general: t("subPage.panel.general"),
661662
notify: t("subPage.copyNotify.succeed"),

src/locales/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ export default {
3535
editScript: "Script Edit",
3636
subEditor: "Subscription Editor",
3737
fileEditor: "File Editor",
38+
preview: 'Preview',
3839
shareManage: "Share Manage",
3940
iconCollection: "Icon Collection",
4041
themeSetting: "Theme Setting",

src/locales/zh.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export default {
6363
editScript: '脚本编辑',
6464
subEditor: '订阅编辑',
6565
fileEditor: '文件编辑',
66+
preview: '预览',
6667
shareManage: '分享管理',
6768
iconCollection: '图标仓库',
6869
themeSetting: '主题设置',

src/router/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import NotFound from '@/views/NotFound.vue';
1111

1212
import File from '@/views/File.vue';
1313
import FileEditor from '@/views/FileEditor.vue';
14+
import FilePreview from '@/views/FilePreview.vue';
1415
// import editScript from '@/views/editCode/editScript.vue';
1516
import IconCollection from '@/views/icon/IconCollection.vue';
1617

@@ -134,6 +135,15 @@ const router = createRouter({
134135
// needNavBack: true,
135136
// },
136137
// },
138+
{
139+
path: '/preview',
140+
component: FilePreview,
141+
meta: {
142+
title: 'preview',
143+
needTabBar: false,
144+
needNavBack: false,
145+
},
146+
},
137147
{
138148
path: '/edit/:editType(files)/:id',
139149
component: FileEditor,
@@ -247,6 +257,7 @@ router.afterEach(async (to, from) => {
247257
}
248258
});
249259
router.beforeEach((to, from) => {
260+
document.title = 'Sub Store';
250261
// console.log(`beforeEach ${from.path} => ${to.path}`)
251262
if (!globalStore) {
252263
globalStore = useGlobalStore();

src/views/FilePreview.vue

Lines changed: 68 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,24 +2,36 @@
22
<Teleport to="#app">
33
<div class="compare-page-wrapper">
44
<header class="compare-page-header">
5-
<h1>
6-
<font-awesome-icon icon="fa-solid fa-eye" />
7-
<span class="title">{{ $t(`comparePage.title`) }}</span>
8-
<span class="displayName">
9-
<font-awesome-icon icon="fa-solid fa-angles-right" />
10-
{{ displayName }}
11-
</span>
12-
</h1>
13-
<!-- <button class="copy" @click.stop="copyContent">
14-
<svg-icon
15-
name="copy"
16-
class="action-icon"
17-
color="var(--comment-text-color)"
18-
/>
19-
</button> -->
20-
<button @click="clickClose">
21-
<font-awesome-icon icon="fa-solid fa-circle-xmark" />
22-
</button>
5+
<template v-if="url">
6+
<h1>
7+
<span class="title">外部资源中使用, 请复制: </span>
8+
<span class="displayName">
9+
<font-awesome-icon class="copy" icon="fa-solid fa-clone" @click="copyUrl" />
10+
<!-- <font-awesome-icon icon="fa-solid fa-angles-right" /> -->
11+
<a class="url" :href="url" target="_blank">{{ url }}</a>
12+
</span>
13+
</h1>
14+
</template>
15+
<template v-else>
16+
<h1>
17+
<font-awesome-icon icon="fa-solid fa-eye" />
18+
<span class="title">{{ $t(`comparePage.title`) }}</span>
19+
<span class="displayName">
20+
<font-awesome-icon icon="fa-solid fa-angles-right" />
21+
{{ displayName }}
22+
</span>
23+
</h1>
24+
<!-- <button class="copy" @click.stop="copyContent">
25+
<svg-icon
26+
name="copy"
27+
class="action-icon"
28+
color="var(--comment-text-color)"
29+
/>
30+
</button> -->
31+
<button @click="clickClose">
32+
<font-awesome-icon icon="fa-solid fa-circle-xmark" />
33+
</button>
34+
</template>
2335
</header>
2436
<cmView :isReadOnly="false" id="filePreview" />
2537
<!-- <div class="compare-page-body">
@@ -40,10 +52,11 @@
4052
</template>
4153

4254
<script lang="ts" setup>
55+
import axios from 'axios';
4356
import { useSubsApi } from "@/api/subs";
4457
import { useSubsStore } from "@/store/subs";
4558
import { Toast } from "@nutui/nutui";
46-
import { computed, ref, toRaw } from "vue";
59+
import { computed, ref, toRaw, watchEffect } from "vue";
4760
import { useI18n } from "vue-i18n";
4861
import { useClipboard } from "@vueuse/core";
4962
import useV3Clipboard from "vue-clipboard3";
@@ -57,6 +70,28 @@ const { showNotify } = useAppNotifyStore();
5770
5871
const { t } = useI18n();
5972
const subsStore = useSubsStore();
73+
import { useRoute } from 'vue-router';
74+
75+
const route = useRoute();
76+
const { url } = route.query as { url: string };
77+
78+
const processedData = ref('')
79+
80+
watchEffect(async () => {
81+
if (url) {
82+
try {
83+
const response = await axios.get(url as string)
84+
processedData.value = response.data
85+
cmStore.setEditCode('filePreview', processedData.value)
86+
} catch (error) {
87+
console.error('Error fetching URL:', error)
88+
}
89+
}
90+
if (route.query.name) {
91+
document.title = `${route.query.name} - Sub Store`
92+
}
93+
})
94+
6095
const { previewData, name } = defineProps<{
6196
previewData: any;
6297
name: string;
@@ -68,26 +103,27 @@ const isOriginalVisible = ref(true);
68103
const isProcessedVisible = ref(true);
69104
70105
const displayName = computed(() => {
106+
if(route.query.name) return route.query.name
71107
const sub = subsStore.getOneFile(name);
72108
return sub?.displayName || sub?.["display-name"] || name;
73109
});
74110
75-
const originalData = previewData.original;
76-
const processedData = previewData.processed;
111+
const originalData = previewData?.original;
112+
if(!url) processedData.value = previewData?.processed;
77113
// cmStore.setCmCode(processedData)
78-
cmStore.setEditCode('filePreview',processedData)
114+
cmStore.setEditCode('filePreview',processedData.value )
79115
80116
81117
const clickClose = () => {
82118
emit("closePreview");
83119
};
84-
const copyContent = async () => {
120+
const copyUrl = async () => {
85121
if (isSupported) {
86-
await copy(processedData);
122+
await copy(url);
87123
} else {
88-
await copyFallback(processedData);
124+
await copyFallback(url);
89125
}
90-
showNotify({ title: "已复制预览内容" });
126+
showNotify({ title: `已复制链接: ${url}` });
91127
};
92128
</script>
93129

@@ -250,6 +286,12 @@ const copyContent = async () => {
250286
text-overflow: ellipsis;
251287
white-space: nowrap;
252288
max-width: 40vw;
289+
.copy {
290+
cursor: pointer;
291+
}
292+
.url {
293+
text-decoration: underline;
294+
}
253295
}
254296
h1 {
255297
display: flex;

0 commit comments

Comments
 (0)