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">
4052</template >
4153
4254<script lang="ts" setup>
55+ import axios from ' axios' ;
4356import { useSubsApi } from " @/api/subs" ;
4457import { useSubsStore } from " @/store/subs" ;
4558import { Toast } from " @nutui/nutui" ;
46- import { computed , ref , toRaw } from " vue" ;
59+ import { computed , ref , toRaw , watchEffect } from " vue" ;
4760import { useI18n } from " vue-i18n" ;
4861import { useClipboard } from " @vueuse/core" ;
4962import useV3Clipboard from " vue-clipboard3" ;
@@ -57,6 +70,28 @@ const { showNotify } = useAppNotifyStore();
5770
5871const { t } = useI18n ();
5972const 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+
6095const { previewData, name } = defineProps <{
6196 previewData: any ;
6297 name: string ;
@@ -68,26 +103,27 @@ const isOriginalVisible = ref(true);
68103const isProcessedVisible = ref (true );
69104
70105const 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
81117const 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