Browse Source

优化打印页: 选择文件的异常提示

“shengjie.huang” 1 năm trước cách đây
mục cha
commit
10c1625dd0
1 tập tin đã thay đổi với 30 bổ sung4 xóa
  1. 30 4
      src/pages/print/index.vue

+ 30 - 4
src/pages/print/index.vue

@@ -369,6 +369,8 @@ function selectFile() {
               }
             })
             if (failList.length > 0) toast.warning(`文件大小限制为10MB, 文件格式仅支持 ${allowType.join('、')}, 所选文件有 ${failList.length} 格式不符合`)
+          } else {
+            toast.warning("选择微信图片异常, 请重试")
           }
         },
         fail () {
@@ -396,6 +398,8 @@ function selectFile() {
               }
             })
             if (failList.length > 0) toast.warning(`文件大小限制为10MB, 文件格式仅支持 ${allowType.join('、')}, 所选文件有 ${failList.length} 格式不符合`)
+          } else {
+            toast.warning("选择微信文件异常, 请重试")
           }
         },
         fail () {
@@ -426,6 +430,8 @@ function selectFile() {
               }
             })
             if (failList.length > 0) toast.warning(`文件大小限制为10MB, 所选文件有 ${failList.length} 格式不符合`)
+          } else {
+            toast.warning("选择相册图片异常, 请重试")
           }
         },
         fail () {
@@ -436,6 +442,7 @@ function selectFile() {
     case "invoice":
       uni.chooseInvoice({
         success (res) {
+          console.log('chooseInvoice res: ', res);
           if (res.errMsg == "chooseInvoice:ok") {
             let list = JSON.parse(res.invoiceInfo)
             if (list && list.length > 0) {
@@ -445,18 +452,37 @@ function selectFile() {
               }
               getInvoiceBatch(params).then(res => {
                 if (res.code == 0 && res.body) {
-                  console.log('InvoiceBatch res.body: ', res.body);
                   // 遍历下载pdf 存储在 fileList 打印
                   res.body.forEach(item => {
-                    downloadFile(`发票-${item.payee}.png`, item.userInfo.pdfUrl)
+                    if (item.userInfo.pdfUrl) {
+                      downloadFile(`发票-${item.payee}.png`, item.userInfo.pdfUrl)
+                    } else {
+                      toast.warning(`发票-${item.payee} PDF地址异常`)
+                    }
                   });
                 }
+              }).catch(() => {
+                toast.warning("获取发票信息异常")
               })
             }
+          } else {
+            toast.warning("选择微信发票异常, 请重试")
           }
         },
-        fail () {
-          toast.warning("选择微信发票失败, 请重试")
+        fail (err) {
+          let tips = "选择微信发票失败, 请重试"
+          switch (err.errMsg) {
+            case "chooseInvoice:fail cancel":
+              tips = "已取消选择发票"
+              break;
+            case "chooseInvoice:fail auth deny":
+              tips = "已拒绝授权,无法访问发票信息"
+              break;
+            case "chooseInvoice:fail system error":
+              tips = "系统错误"
+              break;
+          }
+          toast.warning(tips)
         }
       })
       break;