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

fix: 调整到期时间显示逻辑

Signed-off-by: tangshizhe <48740614+tangshizhe@users.noreply.github.com>
tangshizhe 1 éve
szülő
commit
0efa037bbb
1 módosított fájl, 47 hozzáadás és 2 törlés
  1. 47 2
      jydocs-pc/src/views/Content.vue

+ 47 - 2
jydocs-pc/src/views/Content.vue

@@ -267,10 +267,12 @@ export default {
           const surplus = parseInt(val.docsInfo?.endDate - date)
           if (surplus <= sevenDay && val.docsInfo.docStatus === 1) {
             this.redShow = true
-            this.surplusDay = Math.ceil(surplus / oneDay) + '天后'
+            this.surplusDay = (surplus / oneDay)
             // 如果剩余天数不到1天,则显示今天到期
             if (this.surplusDay < 1) {
               this.surplusDay = '今天'
+            } else {
+              this.surplusDay = this.surplusDay.toFixed(0) + '天后'
             }
           }
         }
@@ -581,6 +583,41 @@ export default {
         this.loadFile()
       }
     },
+   txt2utf8(file, callback) {
+      let newBlob = null;
+      const reader = new FileReader();
+
+      reader.readAsText(file, 'utf-8');
+      reader.onload = (e) => {
+        const txtString = e.target.result;
+        // 这里使用了一个更广泛的中文字符正则表达式
+        const patrn = /[\u4E00-\u9FA5]/gi;
+
+        if (!patrn.test(txtString)) {
+          // 尝试以GB2312编码读取文件
+          const reader_gb2312 = new FileReader();
+          reader_gb2312.readAsText(file, 'gb2312');
+          reader_gb2312.onload = (e2) => {
+            newBlob = new Blob([e2.target.result], { type: 'text/plain;charset=gb2312' });
+            callback && callback(newBlob);
+          };
+          reader_gb2312.onerror = (err) => {
+            console.error('GB2312 reading failed:', err);
+            // 处理错误,或者回退到UTF-8
+            newBlob = new Blob([txtString], { type: 'text/plain;charset=utf-8' });
+            callback && callback(newBlob);
+          };
+        } else {
+          newBlob = new Blob([txtString], { type: 'text/plain;charset=utf-8' });
+          callback && callback(newBlob);
+        }
+      };
+
+      reader.onerror = (err) => {
+        console.error('UTF-8 reading failed:', err);
+        // 处理错误,这里可以根据需要决定如何处理
+      };
+    },
     loadFile () {
       if (!this.islogin) {
         try {
@@ -594,7 +631,15 @@ export default {
       if (this.buyed === 1) {
         getDown({ docId: this.datas.docId }).then(res => {
           if (res.data.error_code === 0) {
-            window.location.href = res.data.data
+            if(this.datas.docFileType === 5) {
+              this.txt2utf8(res.data.data, (newURL) => {
+                window.open(newURL)
+              })
+              // var newUrl= "data:text/html;charset=utf-8,"+ encodeURI(res.data.data).replace(/#/g,"%23");
+              // window.open(newUrl)
+            } else {
+              window.location.href = res.data.data
+            }
           }
         })
         return