tanyanfei 4 年 前
コミット
2aad4c8725
2 ファイル変更26 行追加17 行削除
  1. 1 1
      app.json
  2. 25 16
      pages/upload/upload.js

+ 1 - 1
app.json

@@ -39,7 +39,7 @@
         "pagePath": "pages/upload/upload",
         "iconPath": "pages/images/up_0.png",
         "selectedIconPath": "pages/images/up_1.png",
-        "text": "上传"
+        "text": "交作业"
       },
       {
         "pagePath": "pages/user/user",

+ 25 - 16
pages/upload/upload.js

@@ -173,23 +173,32 @@ Page({
     var today_stock_img = this.data.today_stock_img;
     wx.chooseImage({
       success: res=> {
-        const tempFilePaths = res.tempFilePaths
+        console.log(res)
+        const tempFilePaths = res.tempFiles
         for (let i = 0; i < tempFilePaths.length;i++){
-          wx.uploadFile({
-            url: host + '/api/wx/uploadfile',
-            filePath: tempFilePaths[i],
-            name: 'file',
-            header: {
-              'Authorization': this.data.userInfo.token
-            },
-            success: res => {
-              const data = JSON.parse(res.data)
-              today_stock_img.push(data.data.url)
-              this.setData({
-                today_stock_img: today_stock_img
-              })
-            }
-          })
+          if(tempFilePaths[i].size > 1024){
+            wx.showToast({
+              icon: 'none',
+              title: '图片大小不能超过1M'
+            })
+          }else{
+            wx.uploadFile({
+              url: host + '/api/wx/uploadfile',
+              filePath: tempFilePaths[i].path,
+              name: 'file',
+              header: {
+                'Authorization': this.data.userInfo.token
+              },
+              success: res => {
+                const data = JSON.parse(res.data)
+                today_stock_img.push(data.data.url)
+                this.setData({
+                  today_stock_img: today_stock_img
+                })
+              }
+            })
+          }
+          
         }
         
       }