Browse Source

feat: fix

gemercheung 6 tháng trước cách đây
mục cha
commit
0a83606fc8

+ 6 - 3
packages/backend/src/modules/web/web.service.ts

@@ -66,14 +66,16 @@ export class WebService {
         },
       },
     });
-    return article.translate(lang);
+    return article ? article.translate(lang) : false;
   }
 
   async setArticleCount(id: number) {
     const article = await this.articleRepo.findOne({
       where: { id },
     });
-    if (!article) throw new BadRequestException('不存在或者已删除');
+    if (!article) {
+      return false;
+    };
     article.readCount = article.readCount + 1;
     // console.log('article', article);
     await this.articleRepo.save(article);
@@ -174,7 +176,8 @@ export class WebService {
     const lang = this.sharedService.handleValidLang(locale);
     const currentEntity = await this.articleRepo.findOne({ where: { id: currentId } });
     if (!currentEntity) {
-      throw new CustomException(ErrorCode.ERR_4000, '当前数据不存在');
+      // throw new CustomException(ErrorCode.ERR_4000, '当前数据不存在');
+      return [];
     }
 
     const prevEntity = await this.articleRepo.findOne({

+ 4 - 1
packages/web/src/locales/json/en.json

@@ -32,5 +32,8 @@
   "developer": "Developer",
   "recommend_reading": "Recommend Reading",
   "prev_article": " < PREVIOUS",
-  "next_article": " NEXT >"
+  "next_article": " NEXT >",
+  "no_data": " No Data",
+  "no_data_article": "others",
+  "go_home": "Go Homepage"
 }

+ 4 - 1
packages/web/src/locales/json/zh.json

@@ -33,5 +33,8 @@
   "developer": "开发者",
   "recommend_reading": "推荐阅读",
   "prev_article": " < 上一篇",
-  "next_article": " 下一篇 >"
+  "next_article": " 下一篇 >",
+  "no_data": "无数据",
+  "no_data_article": "看看别的",
+  "go_home": "回首页"
 }

+ 14 - 2
packages/web/src/pages/showdoc/[id].vue

@@ -1,5 +1,6 @@
 <template>
-  <div class="max-w-screen-xl content my-0 mx-auto text-size-base overflow-hidden">
+  <div class="max-w-screen-xl content my-0 mx-auto text-size-base overflow-hidden"
+    :class="!detail ? 'flex flex-column justify-center items-center h-full' : ''">
     <div v-if="detail">
       <div class="breadcrumb my-[30px] pb-[20px] bb-1px_#EBEBEB" role="navigation">
         <n-breadcrumb separator=">" v-if="breadcrumb">
@@ -67,6 +68,17 @@
         </div>
       </div>
     </div>
+    <div else class="">
+
+      <n-empty :description="$t('no_data')">
+        <template #extra>
+          {{ $t('no_data_article') }}
+          <n-button size="small" type="tertiary" @click="router.push('/')">
+            {{ $t('go_home') }}
+          </n-button>
+        </template>
+      </n-empty>
+    </div>
   </div>
 </template>
 
@@ -91,7 +103,7 @@ import {
   getNearArticles,
 } from '@/api'
 import { htmlToTree, createAnchorNames, dayjs, findNodeById, findBreadcrumbPath, type TreeNode } from '@/utils'
-import { NH1, NH2, NH4, NBreadcrumb, NBreadcrumbItem, NTree, NAnchor, NAnchorLink } from 'naive-ui'
+import { NH1, NH2, NH4, NEmpty, NButton, NBreadcrumb, NBreadcrumbItem, NTree, NAnchor, NAnchorLink } from 'naive-ui'
 import type { TreeOption } from 'naive-ui'
 
 const route = useRoute()

+ 1 - 1
packages/web/src/utils/themeOverides.ts

@@ -9,7 +9,7 @@ export const themeOverrides: GlobalThemeOverrides = {
   },
 
   Button: {
-    colorHover:"#0661C9"
+    // colorHover:"#0661C9"
     // textColor: '#FF0000',
   },
   Tree: {