浏览代码

新增 拍摄单据;更新 获取openid逻辑

wzh 3 年之前
父节点
当前提交
a5dacbabcf

+ 0 - 6
miniprogram/pages/index/index.js

@@ -16,12 +16,6 @@ Page({
     loginStatus: false
   },
 
-  goToExperience() {
-    wx.redirectTo({
-      url: `${this.data.loginStatus?'/pages/takePhoto/takePhoto':'/pages/newCachePage/newCachePage'}`,
-    })
-  },
-
   async login() {
     let {
       openId,

+ 43 - 26
miniprogram/pages/takePhoto/takePhoto.js

@@ -5,6 +5,7 @@ Page({
   data: {
     avatar: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/avatar-icon.jpg?sign=f5c66c94d189436f82353eb48cb01f08&t=1634538864",
     cameraIcon: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/camera-icon.png?sign=11a65871a2800cd04ecaa8991687fccd&t=1634607415",
+    newCameraIcon: "https://6875-huihenduo-2gx127w7f837b584-1255802371.tcb.qcloud.la/miniapp-static/camera.png?sign=ad0fe8bead6a46cb20f45f792d4bed67&t=1645502416",
     userName: "",
     phone: "",
     shipName: "",
@@ -39,7 +40,10 @@ Page({
       }
     })
   },
-  takePhoto() {
+  takePhoto(e) {
+    let {
+      mediatype
+    } = e.currentTarget.dataset
     wx.getLocation({
       type: 'gcj02',
       isHighAccuracy: true,
@@ -84,7 +88,7 @@ Page({
                       wx.showToast({
                         title: res.msg
                       })
-                      wx.navigateTo({
+                      wx.redirectTo({
                         url: '/pages/takePhoto/success/success',
                       })
                     } else {
@@ -100,7 +104,7 @@ Page({
                     console.log("新用户视频", e)
                     wx.setStorageSync('type', 2)
                     wx.setStorageSync('file', e.tempFilePath)
-                    wx.navigateTo({
+                    wx.redirectTo({
                       url: `/pages/newCachePage/newCachePage`,
                     })
                   }
@@ -123,11 +127,17 @@ Page({
                     wx.showLoading({
                       title: '正在上传...',
                     })
-                    let res = await uploadFile(e.tempFilePath, {
-                      type: 3,
+                    let postData = {
+                      type: mediatype,
                       userId: wx.getStorageSync('userId'),
-                      location: `${this.data.longitude},${this.data.latitude}`
-                    })
+                    }
+
+                    if (mediatype == 3) {
+                      postData.location = `${this.data.longitude},${this.data.latitude}`
+                    } else {
+                      postData.location = ''
+                    }
+                    let res = await uploadFile(e.tempFilePath, postData)
                     console.log("上传结束", res)
                     if (res.status == 0) {
                       wx.showToast({
@@ -140,25 +150,28 @@ Page({
                         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: '保存成功!',
+                          if (mediatype == 3) {
+                            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.removeStorageSync('cacheImage')
                               }
-                            },
-                            fail: e => {
-                              console.log("失败4", e)
-                              this.setData({
-                                authModal: true,
-                                modalText: "文件存储"
-                              })
-                            }
-                          })
-                          wx.navigateTo({
+                            })
+                          }
+
+                          wx.redirectTo({
                             url: '/pages/takePhoto/success/success',
                           })
                         },
@@ -178,7 +191,7 @@ Page({
                     console.log("新用户图片", e)
                     wx.setStorageSync('type', 1)
                     wx.setStorageSync('file', e.tempFilePath)
-                    wx.navigateTo({
+                    wx.redirectTo({
                       url: `/pages/newCachePage/newCachePage`,
                     })
                   }
@@ -205,10 +218,14 @@ Page({
   },
   onLoad() {
     let userName = wx.getStorageSync('userName')
+    let userId = wx.getStorageSync('userId')
     let phone = wx.getStorageSync('phone')
+    let shipId = wx.getStorageSync('shipId')
     this.setData({
       userName,
-      phone
+      phone,
+      userId,
+      shipId
     })
   }
 })

+ 10 - 1
miniprogram/pages/takePhoto/takePhoto.wxml

@@ -2,8 +2,17 @@
   <image class="avatar-icon" src="{{avatar}}"></image>
   <view class="text" style="text-align: center;">{{userName?"":"体验用户"}}<text wx:if="{{userName}}" class="user-name">{{userName}}</text><text wx:if="{{phone}}" class="phone">{{phone}}</text></view>
 </view>
-<image class="camera-icon" bindtap="takePhoto" src="{{cameraIcon}}"></image>
+<view wx:if="{{userId&&shipId}}" class="new-camera camera-cargo">
+  <image class="icon" bindtap="takePhoto" data-mediatype="{{3}}" src="{{newCameraIcon}}"></image>
+  <view>拍货物</view>
 
+</view>
+<view wx:if="{{userId&&shipId}}" class="new-camera camera-bill">
+  <image class="icon" data-mediatype="{{0}}" bindtap="takePhoto" src="{{newCameraIcon}}"></image>
+  <view> 拍单据
+  </view>
+</view>
+<image wx:else class="camera-icon" bindtap="takePhoto" data-mediatype="{{3}}" src="{{cameraIcon}}"></image>
 <view class="auth-modal" wx:if="{{authModal}}">
   <view class="modal">
     <view class="service">为了更好的提供服务</view>

+ 22 - 0
miniprogram/pages/takePhoto/takePhoto.wxss

@@ -88,4 +88,26 @@
   margin: 0 auto;
   margin-top: 55rpx;
   text-align: center;
+}
+
+.icon {
+  width: 160rpx;
+  height: 160rpx;
+}
+
+.camera-cargo {
+  height: 32vh;
+  background: #006ebd;
+}
+
+.camera-bill {
+  height: 33vh;
+  background: #3bb1da;
+}
+
+.new-camera {
+  text-align: center;
+  padding-top: 6vh;
+  color: #fff;
+  font-size: 42rpx;
 }

+ 2 - 2
miniprogram/utils/upload.js

@@ -2,10 +2,10 @@ import {
   apiUrl
 } from "../apis/apiConfig"
 
-function uploadFile(filePath, formData, type) {
+function uploadFile(filePath, formData) {
   return new Promise((resolve, reject) => {
     wx.uploadFile({
-      url: `${apiUrl}${type?"/user/wx/oneStepLogin":"/cos/upload"}`,
+      url: `${apiUrl}/cos/upload`,
       filePath,
       name: 'file',
       formData,

+ 17 - 1
project.config.json

@@ -1,4 +1,5 @@
 {
+  "description": "项目配置文件,详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html",
   "miniprogramRoot": "miniprogram/",
   "cloudfunctionRoot": "cloudfunctions/",
   "setting": {
@@ -42,7 +43,7 @@
   "appid": "wxf22759845920b6f3",
   "projectname": "%E6%B1%9F%E8%BF%90%E9%9A%8F%E6%89%8B%E6%8B%8D2.0",
   "libVersion": "2.19.6",
-  "cloudfunctionTemplateRoot": "cloudfunctionTemplate",
+  "cloudfunctionTemplateRoot": "cloudfunctionTemplate/",
   "condition": {
     "search": {
       "list": []
@@ -65,5 +66,20 @@
         }
       ]
     }
+  },
+  "compileType": "miniprogram",
+  "scripts": {},
+  "packOptions": {
+    "ignore": [],
+    "include": []
+  },
+  "watchOptions": {
+    "ignore": []
+  },
+  "debugOptions": {
+    "hidedInDevtools": []
+  },
+  "staticServerOptions": {
+    "servePath": ""
   }
 }

+ 40 - 11
project.private.config.json

@@ -1,15 +1,36 @@
 {
-  "setting": {},
-  "condition": {
-    "plugin": {
-      "list": []
-    },
-    "game": {
-      "list": []
-    },
-    "gamePlugin": {
-      "list": []
+  "setting": {
+    "urlCheck": true,
+    "es6": true,
+    "enhance": true,
+    "postcss": true,
+    "preloadBackgroundData": false,
+    "minified": true,
+    "coverView": true,
+    "autoAudits": false,
+    "showShadowRootInWxmlPanel": true,
+    "uglifyFileName": false,
+    "checkInvalidKey": true,
+    "uploadWithSourceMap": true,
+    "compileHotReLoad": false,
+    "lazyloadPlaceholderEnable": false,
+    "useMultiFrameRuntime": false,
+    "babelSetting": {
+      "ignore": [],
+      "disablePlugins": [],
+      "outputPath": ""
     },
+    "packNpmManually": false,
+    "packNpmRelationList": [],
+    "minifyWXSS": true,
+    "disableUseStrict": false,
+    "showES6CompileOption": false,
+    "useCompilerPlugins": false,
+    "ignoreUploadUnusedFiles": true,
+    "useStaticServer": true,
+    "minifyWXML": true
+  },
+  "condition": {
     "miniprogram": {
       "list": [
         {
@@ -47,8 +68,16 @@
           "pathName": "pages/newCachePage/newCachePage",
           "query": "",
           "scene": null
+        },
+        {
+          "name": "",
+          "pathName": "pages/takePhoto/takePhoto",
+          "query": "",
+          "scene": null,
+          "launchMode": "default"
         }
       ]
     }
-  }
+  },
+  "description": "项目私有配置文件。此文件中的内容将覆盖 project.config.json 中的相同字段。项目的改动优先同步到此文件中。详见文档:https://developers.weixin.qq.com/miniprogram/dev/devtools/projectconfig.html"
 }