Ver Fonte

优化 错误提示

wzg há 1 ano atrás
pai
commit
075d297782
1 ficheiros alterados com 77 adições e 91 exclusões
  1. 77 91
      miniprogram/pages/securityCheck/securityCheck.js

+ 77 - 91
miniprogram/pages/securityCheck/securityCheck.js

@@ -1,158 +1,144 @@
 // pages/securityCheck/securityCheck.js
-import {
-  postApi
-} from "../../apis/api"
-import {
-  apiUrl
-} from "../../apis/apiConfig"
+import { postApi } from "../../apis/api";
+import { apiUrl } from "../../apis/apiConfig";
 
-import {
-  isImage
-} from "../../utils/utils"
+import { isImage } from "../../utils/utils";
 Page({
   data: {
     list: [],
-    loginStatus: wx.getStorageSync('userId')
+    loginStatus: wx.getStorageSync("userId"),
   },
   async login() {
-    if (!wx.getStorageSync('openId')) return
+    if (!wx.getStorageSync("openId")) return;
     let res1 = await postApi("/user/wx/openId/login", {
-      openId: wx.getStorageSync('openId')
-    })
+      openId: wx.getStorageSync("openId"),
+    });
     if (res1.data.status == 0) {
       let data = {
         ...res1.data.result.userInfo,
         ...res1.data.result.shipInfo,
-      }
+      };
       Object.keys(data).forEach(function (key) {
-        wx.setStorageSync(key, data[key])
-      })
+        wx.setStorageSync(key, data[key]);
+      });
       this.setData({
-        loginStatus: true
-      })
-      this.getList()
+        loginStatus: true,
+      });
+      this.getList();
     } else {
       wx.switchTab({
-        url: '/pages/takePhoto/takePhoto',
-      })
+        url: "/pages/takePhoto/takePhoto",
+      });
     }
   },
   async getList() {
-    if (!wx.getStorageSync('userId')) {
+    if (!wx.getStorageSync("userId")) {
       wx.showToast({
-        title: '尚未登录',
-        icon: 'error'
-      })
-      return
+        title: "尚未登录",
+        icon: "none",
+      });
+      return;
     }
-    let {
-      data
-    } = await postApi('/security/check/list', {
-      userId: wx.getStorageSync('userId'),
-      shipId: wx.getStorageSync('shipId')
-    })
-    wx.stopPullDownRefresh()
+    let { data } = await postApi("/security/check/list", {
+      userId: wx.getStorageSync("userId"),
+      shipId: wx.getStorageSync("shipId"),
+    });
+    wx.stopPullDownRefresh();
     if (data.status == 0) {
       for (let i of data.result) {
-        i.isImage = isImage(i.fileKey)
+        i.isImage = isImage(i.fileKey);
       }
       this.setData({
-        list: data.result
-      })
+        list: data.result,
+      });
     } else {
       this.setData({
-        list: []
-      })
+        list: [],
+      });
     }
   },
   uploadMedia(e) {
-    let {
-      id: itemId
-    } = e.currentTarget.dataset
+    let { id: itemId } = e.currentTarget.dataset;
     wx.showLoading({
-      title: '高精度定位中...'
-    })
+      title: "高精度定位中...",
+    });
     wx.getLocation({
-      type: 'gcj02',
+      type: "gcj02",
       isHighAccuracy: true,
-      success: e => {
-        let {
-          latitude,
-          longitude
-        } = e
+      success: (e) => {
+        let { latitude, longitude } = e;
         wx.chooseMedia({
           count: 1,
-          mediaType: ['image', 'video'],
-          sourceType: ['album', 'camera'],
-          sizeType: ['original', 'compressed'],
-          success: e => {
-            console.log("获取媒体成功!", e)
-            let filePath = e.tempFiles[0].tempFilePath
+          mediaType: ["image", "video"],
+          sourceType: ["album", "camera"],
+          sizeType: ["original", "compressed"],
+          success: (e) => {
+            console.log("获取媒体成功!", e);
+            let filePath = e.tempFiles[0].tempFilePath;
             wx.showLoading({
-              title: '正在上传...'
-            })
+              title: "正在上传...",
+            });
             wx.uploadFile({
               url: `${apiUrl}/security/check/upload/file`,
               filePath,
-              name: 'file',
+              name: "file",
               formData: {
                 itemId,
-                userId: wx.getStorageSync('userId'),
-                location: `${longitude},${latitude}`
+                userId: wx.getStorageSync("userId"),
+                location: `${longitude},${latitude}`,
               },
-              success: async e => {
-                let data = JSON.parse(e.data)
+              success: async (e) => {
+                let data = JSON.parse(e.data);
                 if (data.status == 0) {
-                  this.getList()
+                  this.getList();
                   wx.showToast({
                     title: data.msg,
-                    duration: 1500
-                  })
+                    duration: 1500,
+                  });
                 } else {
                   wx.showToast({
                     title: data.msg,
-                    icon: "error",
-                    duration: 2000
-                  })
+                    icon: "none",
+                    duration: 2000,
+                  });
                 }
-
               },
-              fail: err => {
+              fail: (err) => {
                 wx.showToast({
                   title: data.msg,
-                  icon: "error",
-                  duration: 2000
-                })
-              }
-            })
+                  icon: "none",
+                  duration: 2000,
+                });
+              },
+            });
           },
-          fail: e => {
-            console.log("失败1", e)
-          }
-        })
+          fail: (e) => {
+            console.log("失败1", e);
+          },
+        });
       },
-      fail: e => {
+      fail: (e) => {
         this.setData({
           authModal: true,
-          modalText: "位置信息"
-        })
+          modalText: "位置信息",
+        });
       },
-      complete: e => {
+      complete: (e) => {
         wx.hideLoading({
           success: (res) => {},
-        })
-      }
-    })
+        });
+      },
+    });
   },
   onPullDownRefresh() {
-    this.getList()
+    this.getList();
   },
   onShow() {
     this.setData({
-      loginStatus: wx.getStorageSync('userId')
-    })
+      loginStatus: wx.getStorageSync("userId"),
+    });
   },
   onLoad(options) {
-    this.getList()
+    this.getList();
   },
-})
+});