浏览代码

判断文件类型

xiaohaizhao 1 年之前
父节点
当前提交
62cd5cd613
共有 1 个文件被更改,包括 5 次插入4 次删除
  1. 5 4
      utils/settleFiles.js

+ 5 - 4
utils/settleFiles.js

@@ -95,6 +95,7 @@ function viewFlies(item) {
 }
 
 function wxSaveFile(file) {
+    if (file.fileType == undefined) file = formattedFiles([file])[0]
     const fs = uni.getFileSystemManager(),
         basePath = String(`${uni.env.USER_DATA_PATH}/${file.postfix}`);
     fs.access({
@@ -124,7 +125,6 @@ function wxSaveFile(file) {
         filePath: basePath + '/' + file.document,
         timeout: 6000000,
         success(res) {
-            console.log("下载文件", res)
             if (file.fileType == "video") {
                 saveVideo(res.filePath)
             } else {
@@ -186,7 +186,7 @@ function wxSaveFile(file) {
                         } else {
                             clearFile(filePath)
                             uni.showToast({
-                                title: err,
+                                title: err.errMsg,
                                 icon: "none"
                             })
                         }
@@ -195,10 +195,11 @@ function wxSaveFile(file) {
             }
 
             function saveVideo(filePath) {
+                console.log('saveVideo', filePath)
                 uni.saveVideoToPhotosAlbum({
                     filePath,
                     success(res) {
-                        console.log("保存商品", res)
+                        console.log("保存视频", res)
                         uni.showModal({
                             title: '提示',
                             content: '视频已保存到系统相册',
@@ -235,7 +236,7 @@ function wxSaveFile(file) {
                         } else {
                             clearFile(filePath)
                             uni.showToast({
-                                title: err,
+                                title: err.errMsg,
                                 icon: "none"
                             })
                         }