Procházet zdrojové kódy

更新 新版体验/注册逻辑

wzh před 4 roky
rodič
revize
ea81497559

+ 177 - 75
miniprogram/pages/newCachePage/newCachePage.js

@@ -20,13 +20,105 @@ Page({
     shipName: "",
     shipMmsi: "",
     agreeModal: false,
-    agreeText: false
+    agreeText: false,
+    isWxRegister: false
   },
   goBack() {
     wx.redirectTo({
       url: '/pages/index/index',
     })
   },
+  async register() {
+    if (!this.checkout()) return
+    let res = await postApi('/user/wx/register', {
+      userId: wx.getStorageSync('userId'),
+      shipName: this.data.shipName,
+      shipMmsi: this.data.shipMmsi,
+    })
+    console.log(res)
+    if (res.data.status == 0) {
+      let {
+        shipInfo,
+        userInfo
+      } = res.data.result
+
+      let data = {
+        ...shipInfo,
+        ...userInfo
+      }
+      Object.keys(data).forEach(function (key) {
+        wx.setStorageSync(key, data[key])
+      })
+      wx.compressImage({
+        src: wx.getStorageSync('file'),
+        quality: 80, // 压缩质量
+        success: async e => {
+          console.log("图片压缩成功!", e)
+          wx.hideLoading({
+            success: (res) => {},
+          })
+          wx.showLoading({
+            title: '正在上传...',
+          })
+          let res = await uploadFile(e.tempFilePath, {
+            type: 3,
+            userId: wx.getStorageSync('userId'),
+            location: `${this.data.longitude},${this.data.latitude}`
+          })
+          console.log("上传结束", res)
+          if (res.status == 0) {
+            wx.showToast({
+              title: res.msg
+            })
+            wx.setStorageSync('shareImageUrl', res.result.viewUrl)
+            console.log(wx.getStorageSync('shareImageUrl'))
+            wx.downloadFile({
+              url: res.result.viewUrl,
+              success: e => {
+                console.log("下载调用!", e)
+                wx.setStorageSync('cacheImage', e.tempFilePath)
+                wx.saveImageToPhotosAlbum({
+                  filePath: e.tempFilePath,
+                  success: e => {
+                    if (e.errMsg == "saveImageToPhotosAlbum:ok") {
+                      wx.showToast({
+                        title: '保存成功!',
+                      })
+                      wx.removeStorageSync('cacheImage')
+                    }
+                  },
+                  fail: e => {
+                    console.log("失败44", e)
+                    this.setData({
+                      authModal: true,
+                      modalText: "文件存储"
+                    })
+                  }
+                })
+                wx.navigateTo({
+                  url: '/pages/takePhoto/success/success',
+                })
+              },
+              fail: e => {
+                console.log("失败3", e)
+              }
+            })
+
+
+          } else {
+            wx.showToast({
+              title: res.msg
+            })
+          }
+        },
+        fail: e => {
+          console.log("失败22", e)
+        }
+      })
+    } else {
+
+    }
+  },
   checkout() {
     if (!this.data.shipName) {
       wx.showToast({
@@ -91,25 +183,17 @@ Page({
         } = result
         if (phone) {
           wx.setStorageSync('phone', phone)
-          let {
-            shipName,
-            shipMmsi
-          } = this.data
           try {
-            let res = await uploadFile(wx.getStorageSync('file'), {
+            let res = await postApi('/user/wx/login', {
               openId: wx.getStorageSync('openId'),
-              phone,
-              shipName,
-              shipMmsi,
-              type: wx.getStorageSync('type'),
-              location: `${this.data.longitude},${this.data.latitude}`
-            }, 1)
-            if (res.status == 0) {
-              wx.setStorageSync('shareImageUrl', res.result.mediaInfo.viewUrl)
+              phone
+            })
+            console.log(res)
+            if (res.data.status == 0) {
               let {
                 shipInfo,
                 userInfo
-              } = res.result
+              } = res.data.result
 
               let data = {
                 ...shipInfo,
@@ -118,78 +202,96 @@ Page({
               Object.keys(data).forEach(function (key) {
                 wx.setStorageSync(key, data[key])
               })
-              wx.showToast({
-                title: res.msg,
-              })
-              wx.downloadFile({
-                url: res.result.mediaInfo.viewUrl,
-                success: e => {
-                  console.log("下载调用!", e)
-                  wx.setStorageSync('cacheImage', e.tempFilePath)
-                  wx.saveImageToPhotosAlbum({
-                    filePath: e.tempFilePath,
-                    success: e => {
-                      console.log(5, e)
-
-                      if (e.errMsg == "saveImageToPhotosAlbum:ok") {
-                        wx.showToast({
-                          title: '保存成功!',
-                        })
-                        wx.removeStorageSync('cacheImage')
-                      }
-                    },
-                    fail: async e => {
-                      console.log("6", e)
-                      wx.hideLoading({})
-                      wx.showToast({
-                        title: '保存失败!',
-                        duration: 5000
-                      })
-                      await cloudApi('sendError', {
-                        e,
-                        flag: 4,
-                        msg: "保存失败"
-                      })
-                      this.setData({
-                        authModal: true,
-                        modalText: "文件存储"
-                      })
-                    }
-                  })
-                  wx.navigateTo({
-                    url: '/pages/takePhoto/success/success',
+              wx.compressImage({
+                src: wx.getStorageSync('file'),
+                quality: 80, // 压缩质量
+                success: async e => {
+                  console.log("图片压缩成功!", e)
+                  wx.hideLoading({
+                    success: (res) => {},
                   })
-                },
-                fail: async e => {
-                  wx.hideLoading({})
-                  wx.showToast({
-                    title: '下载失败!',
-                    duration: 5000
+                  wx.showLoading({
+                    title: '正在上传...',
                   })
-                  await cloudApi('sendError', {
-                    e,
-                    msg: "下载失败",
-                    flag: 3
+                  let res = await uploadFile(e.tempFilePath, {
+                    type: 3,
+                    userId: wx.getStorageSync('userId'),
+                    location: `${this.data.longitude},${this.data.latitude}`
                   })
+                  console.log("上传结束", res)
+                  if (res.status == 0) {
+                    wx.showToast({
+                      title: res.msg
+                    })
+                    wx.setStorageSync('shareImageUrl', res.result.viewUrl)
+                    console.log(wx.getStorageSync('shareImageUrl'))
+                    wx.downloadFile({
+                      url: res.result.viewUrl,
+                      success: e => {
+                        console.log("下载调用!", e)
+                        wx.setStorageSync('cacheImage', e.tempFilePath)
+                        wx.saveImageToPhotosAlbum({
+                          filePath: e.tempFilePath,
+                          success: e => {
+                            if (e.errMsg == "saveImageToPhotosAlbum:ok") {
+                              wx.showToast({
+                                title: '保存成功!',
+                              })
+                              wx.removeStorageSync('cacheImage')
+                            }
+                          },
+                          fail: e => {
+                            console.log("失败4", e)
+                            this.setData({
+                              authModal: true,
+                              modalText: "文件存储"
+                            })
+                          }
+                        })
+                        wx.navigateTo({
+                          url: '/pages/takePhoto/success/success',
+                        })
+                      },
+                      fail: e => {
+                        console.log("失败33", e)
+                      }
+                    })
+
+
+                  } else {
+                    wx.showToast({
+                      title: res.msg
+                    })
+                  }
+                },
+                fail: e => {
+                  console.log("失败2", e)
                 }
               })
             } else {
-              wx.hideLoading({})
-              await cloudApi('sendError', {
-                res,
-                flag: 2
+              let {
+                userInfo
+              } = res.data.result
+
+              let data = {
+                ...userInfo
+              }
+              Object.keys(data).forEach(function (key) {
+                wx.setStorageSync(key, data[key])
               })
-              wx.showToast({
-                title: res.msg,
-                icon: "error"
+              this.setData({
+                isWxRegister: true,
+                agreeModal: false
               })
             }
           } catch (error) {
-            await cloudApi('sendError', {
-              error,
-              flag: 1
+            console.log(error)
+          } finally {
+            wx.hideLoading({
+              success: (res) => {},
             })
           }
+
         } else {
           wx.hideLoading({})
           wx.showToast({

+ 9 - 6
miniprogram/pages/newCachePage/newCachePage.wxml

@@ -2,14 +2,17 @@
   <image class="media-container" mode="aspectFit" wx:if="{{type==1}}" src="{{file}}"> </image>
   <video class="media-container" autoplay="{{true}}" wx:else src="{{file}}"></video>
 </view>
-<!-- <view class="line mb30">
-  <view class="ship-name">船舶名称 : </view><input class="ship-name-ipt" model:value="{{shipName}}" type="text" placeholder="请输入船舶名称" />
+<view wx:if="{{isWxRegister}}">
+  <view class="line mb30">
+    <view class="ship-name">船舶名称 : </view><input class="ship-name-ipt" model:value="{{shipName}}" type="text" placeholder="请输入船舶名称" />
+  </view>
+  <view class="line">
+    <view class="ship-mmsi">MMSI : </view><input class="ship-mmsi-ipt" model:value="{{shipMmsi}}" type="text" placeholder="请输入MMSI" />
+  </view>
 </view>
-<view class="line">
-  <view class="ship-mmsi">MMSI : </view><input class="ship-mmsi-ipt" model:value="{{shipMmsi}}" type="text" placeholder="请输入MMSI" />
-</view> -->
 <view>
-  <button style="width: 600rpx;height: 90rpx;line-height: 90rpx;background: #3e94f6;border-radius: 45rpx;padding: 0;margin-top: 30rpx;" bindtap="showAgreeModal" type="primary">手机号登录</button>
+  <button wx:if="{{isWxRegister}}" style="width: 600rpx;height: 90rpx;line-height: 90rpx;background: #3e94f6;border-radius: 45rpx;padding: 0;margin-top: 30rpx;" bindtap="register" type="primary">完成</button>
+  <button wx:else style="width: 600rpx;height: 90rpx;line-height: 90rpx;background: #3e94f6;border-radius: 45rpx;padding: 0;margin-top: 30rpx;" bindtap="showAgreeModal" type="primary">手机号登录</button>
   <button style="width: 500rpx;height: 60rpx;line-height: 60rpx;background: #777;border-radius: 30rpx;padding: 0;margin-top: 30rpx;font-size: 24rpx;" bindtap="goBack" type="primary">返回继续体验</button>
 </view>
 <view wx:if="{{agreeText}}" style="position: absolute;top: 0;left: 0;right: 0;bottom: 0;background-color: rgba(000, 000, 000, 0.5);z-index: 10;">