Forráskód Böngészése

📦 修改链接问题

快乐的梦鱼 2 hete
szülő
commit
78d22b104a

+ 15 - 0
src/components/link/PageLink.vue

@@ -0,0 +1,15 @@
+<template>
+  <a v-if="article.outlink" :href="article.outlink" target="_blank">{{ article.title }}</a>
+  <router-link v-else :to="'/page/' + article.id" class="title">{{ article.title }}</router-link>
+</template>
+
+<script setup lang="ts">
+import type { IArticle } from '~~/server/api/ecms/article/[id]';
+
+const props = defineProps({
+  article: {
+    type: Object as PropType<IArticle>,
+    required: true,
+  }
+});
+</script>

+ 2 - 2
src/pages/channel/[id].vue

@@ -49,8 +49,7 @@
               <img v-if="item.image" :src="item.image" />
               <div v-else-if="anyItemHasImage" class="no-image">暂无图片</div>
               <div class="desc">
-                <a v-if="item.outlink" :href="item.outlink" target="_blank">{{ item.title }}</a>
-                <router-link v-else :to="'/page/' + item.id" class="title">{{ item.title }}</router-link>
+                <PageLink :article="item" class="title" />
                 <p class="desc">{{ item.description }}</p>
               </div>
             </div>
@@ -78,6 +77,7 @@ import { DateUtils } from '@imengyu/imengyu-utils';
 import type { IChannel } from '~~/server/api/ecms/channel/[id]';
 import SimplePagination from '~/components/content/SimplePagination.vue';
 import { getNeedJumpToInternalPage, solveChannelData } from '~/composeable/InternalData';
+import PageLink from '~/components/link/PageLink.vue';
 
 const carouselConfig : (typeof Carousel['props']) = {
   itemsToShow: 1,

+ 2 - 8
src/pages/channel/laws.vue

@@ -59,14 +59,7 @@
                     :key="key" 
                     class="news-item dark"
                   >
-                    <a v-if="item.outlink" :href="item.outlink" target="_blank">{{ item.title }}</a>
-                    <router-link 
-                      v-else
-                      :to="'/page/' + item.id"
-                      class="title"
-                    >
-                      {{ item.title }}
-                    </router-link>
+                    <PageLink :article="item" class="title" />
                     <span class="date">
                       {{ DateUtils.formatDate(new Date((item.publishtime || item.createtime) * 1000), 'yyyy-MM-dd') }}
                     </span>
@@ -100,6 +93,7 @@ import { useSSrSimpleDataLoader } from '@/composeable/SimpleDataLoader';
 import { DateUtils } from '@imengyu/imengyu-utils';
 import type { IChannel } from '~~/server/api/ecms/channel/[id]';
 import SimplePagination from '~/components/content/SimplePagination.vue';
+import PageLink from '~/components/link/PageLink.vue';
 
 const route = useRoute();
 const router = useRouter();

+ 5 - 5
src/pages/index.vue

@@ -85,7 +85,7 @@
               <SimplePageContentLoader :loader="notices" :showEmpty="!notices.content.value?.items?.length">
                 <div v-for="notice in notices.content.value?.items" :key="notice.id" class="notice-item">
                   <div>
-                    <router-link :to="'/page/' + notice.id" class="notice-title">{{ notice.title }}</router-link>
+                    <PageLink :article="notice" class="notice-title" />
                     <p>{{ notice.description }}</p>
                   </div>
                   <span class="notice-publishtime">{{ DataDateUtils.formatDate(new Date((notice.createtime || notice.publishtime) * 1000), 'yyyy-MM-dd') }}</span>
@@ -95,7 +95,7 @@
             <div v-if="currentTab === 'hot'" id="hot-news-list" class="news-content flex-one flex-grow-1">
               <SimplePageContentLoader :loader="hot" :showEmpty="!hot.content.value?.items?.length">
                 <div v-for="item in hot.content.value?.items" :key="item.id" class="news-item">
-                  <router-link :to="'/page/' + item.id" class="title">{{ item.title }}</router-link>
+                  <PageLink :article="item" class="title" />
                   <span class="publishtime">{{ DataDateUtils.formatDate(new Date((item.createtime ||item.publishtime) * 1000), 'yyyy-MM-dd') }}</span>
                 </div>
               </SimplePageContentLoader>
@@ -111,7 +111,7 @@
             <div class="news-content">
               <SimplePageContentLoader :loader="workUppublishtimes" :showEmpty="!workUppublishtimes.content.value?.items?.length">
                 <div v-for="uppublishtime in workUppublishtimes.content.value?.items" :key="uppublishtime.id" class="news-item">
-                  <router-link :to="'/page/' + uppublishtime.id" class="title">{{ uppublishtime.title }}</router-link>
+                  <PageLink :article="uppublishtime" class="title" />
                   <span class="publishtime">{{ DataDateUtils.formatDate(new Date(uppublishtime.publishtime * 1000), 'yyyy-MM-dd') }}</span>
                 </div>
               </SimplePageContentLoader>
@@ -174,7 +174,7 @@
               <div class="news-content">
                 <SimplePageContentLoader :loader="workUppublishtimes" :showEmpty="!workUppublishtimes.content.value?.items?.length">
                   <div v-for="uppublishtime in workUppublishtimes.content.value?.items" :key="uppublishtime.id" class="news-item">
-                    <router-link :to="'/page/' + uppublishtime.id" class="title">{{ uppublishtime.title }}</router-link>
+                    <PageLink :article="uppublishtime" class="title" />
                     <span class="publishtime">{{ DataDateUtils.formatDate(new Date(uppublishtime.publishtime * 1000), 'yyyy-MM-dd') }}</span>
                   </div>
                 </SimplePageContentLoader>
@@ -194,7 +194,7 @@
                 <SimplePageContentLoader :loader="notices" :showEmpty="!notices.content.value?.items?.length">
                   <div v-for="notice in notices.content.value?.items" :key="notice.id" class="notice-item">
                     <div>
-                      <router-link :to="'/page/' + notice.id" class="notice-title">{{ notice.title }}</router-link>
+                      <PageLink :article="notice" class="notice-title" />
                       <p>{{ notice.description }}</p>
                     </div>
                     <span class="notice-publishtime">{{ DataDateUtils.formatDate(new Date((notice.createtime || notice.publishtime) * 1000), 'yyyy-MM-dd') }}</span>