Просмотр исходного кода

⚙️ 修改文档查看问题

快乐的梦鱼 1 неделя назад
Родитель
Сommit
70a9c933d5

+ 1 - 1
src/pages/article/data/CommonCategoryGlobalLoader.ts

@@ -26,7 +26,7 @@ export function useCommonCategoryGlobalLoader() {
   async function loadCommonCategory() {
     uni.showLoading({ title: '加载中' });
     try {
-      if (isDev) {
+      if (uni.getSystemInfoSync().platform === 'devtools') {
         commonCategoryData.value = DefaultCofig as IHomeCommonCategoryDefine;
         return;
       }

+ 48 - 3
src/pages/article/details.vue

@@ -171,9 +171,54 @@ const recommendListLoader = useSimpleDataLoader(async () => {
 });
 
 function goArchive(id: number) {
-  navTo('/pages/document/details', { 
-    id,
-  });
+  const archiveUrl = loader.content.value?.archives || '';
+  if (!archiveUrl)
+    return;
+  const ext = StringUtils.path.getFileExt(archiveUrl);
+  switch (ext) {
+    case 'excel': 
+    case 'xls': 
+    case 'xlsx': 
+    case 'powerpoint': 
+    case 'ppt': 
+    case 'pptx': 
+    case 'word': 
+    case 'docx': 
+    case 'doc': 
+    case 'txt': 
+    case 'rtf': 
+    case 'pdf':  {
+      uni.showLoading({ title: '下载中...' })
+      uni.downloadFile({
+        url: archiveUrl,
+        success: (res) => {
+          uni.hideLoading()
+          uni.openDocument({
+            filePath: res.tempFilePath,
+          })
+        },
+        fail: (res) => {
+          uni.hideLoading()
+          uni.showToast({
+            title: '下载文件失败,请检查网络',
+            icon: 'none',
+          })
+        },
+      })
+      break;
+    }
+    case 'htm': 
+    case 'html': 
+      navTo('/pages/document/details', { 
+        id,
+      });
+    default:
+      uni.showToast({
+        title: '抱歉,不支持打开该文件',
+        icon: 'none',
+      })
+      break;
+  }
 }
 function goDetails(id: number) {
   navTo('/pages/article/details', {