Bladeren bron

feat: permissions such as adding a camera

wangyuan 2 jaren geleden
bovenliggende
commit
815768db9f

+ 11 - 0
api/permission.js

@@ -0,0 +1,11 @@
+
+import { wxRequest } from './request'
+
+// 微信扫车辆码-绑定车辆设备
+const bindCarURL = '/bind/car'
+
+export const bindCar =  (data) => wxRequest(bindCarURL, data)
+
+
+
+

+ 16 - 0
api/workbench.js

@@ -0,0 +1,16 @@
+
+import { wxRequest } from './request'
+
+// 创建订单、工作人员扫描二维码
+const writeOffOrderURL = '/write/off/order'
+
+const confirmOrderURL = '/confirm/order'
+
+export const writeOffOrder =  (data) => wxRequest(writeOffOrderURL, data)
+
+export const confirmOrder =  (data) => wxRequest(confirmOrderURL, data)
+
+
+
+
+

+ 1 - 1
app.json

@@ -1,5 +1,5 @@
 {
-  "entryPagePath": "pages/login/login",
+  "entryPagePath": "pages/workbench/workbench",
   "pages": [
     "pages/login/login",
     "pages/workbench/workbench",

+ 7 - 3
pages/login/login.js

@@ -24,7 +24,6 @@ Page({
     var that = this
     wx.login({
       success (res) {
-        console.log(res, 'wx.login');
         if (res.code) {
           //发起网络请求
           wx.showLoading({
@@ -36,9 +35,11 @@ Page({
           })
           workerLogin({code: res.code}).then(res => {
             // 登录成功 进入首页 todo
-            console.log(res, 'workerLogin');
             wx.hideLoading()
             that.setAppGlobalData(res.data)
+            wx.redirectTo({
+              url: '/pages/permissions/permissions?form=login',
+            })
           }).catch(e => {
             // e.code == 403 未绑定微信 进入账户密码登录页面
             wx.hideLoading()
@@ -115,7 +116,7 @@ Page({
       pwdLogin(data).then(res => {
         wx.hideLoading()
         that.setAppGlobalData(res.data)
-        if (!res.isBindWechat) { // 界面加一个微信绑定的按钮
+        if (!res.data.isBindWechat) { // 界面加一个微信绑定的按钮
           wx.showModal({
             content: '请绑定微信',
             confirmColor: '#333',
@@ -154,6 +155,9 @@ Page({
             })
             app.globalData.isBindWechat = true
             // 进入首页 todo
+            wx.redirectTo({
+              url: '/pages/permissions/permissions',
+            })
           }).catch(e => {
             wx.hideLoading()
             wx.showModal({

+ 1 - 0
pages/login/login.wxss

@@ -2,6 +2,7 @@
 .login {
   width: 100%;
   height: 100%;
+  overflow: hidden;
   background-color: #fff;
 }
 .itt_bg {

+ 104 - 49
pages/permissions/permissions.js

@@ -1,4 +1,6 @@
 // pages/permissions/permissions.js
+import { bindCar } from '../../api/permission'
+const app = getApp()
 Page({
 
   /**
@@ -9,10 +11,24 @@ Page({
   },
 
   /**
-   * 生命周期函数--监听页面加载
+   * 生命周期函数--监听页面显示
    */
-  onLoad(options) {
-
+  onShow() {
+    console.log('permission show');
+    if (!app.globalData.accessToken) {
+      wx.showModal({
+        content: '请先登录',
+        confirmColor: '#333',
+        showCancel: false,
+        success (scanres) {
+          if (scanres.confirm) {
+            wx.redirectTo({
+              url: '/pages/login/login'
+            })
+          }
+        } 
+      })
+    }
   },
 
   bindscancode(e) {
@@ -20,60 +36,99 @@ Page({
     if (that.data.scanFlag) {
       var response = e.detail.result
       console.log(response, 'response');
+      var scodeType = response.split('|')[0] == 'DEVICE' ? true : false
+      if (!scodeType) {
+        that.setData({
+          scanFlag: false
+        })
+        wx.showModal({
+          content: '请扫描正确的设备二维码',
+          confirmColor: '#333',
+          showCancel: false,
+          success (scanres) {
+            if (scanres.confirm) {
+              that.setData({
+                scanFlag: true
+              })
+            }
+          } 
+        })
+      } else {
+        // DEVICE|deviceCode|nonceCode|timeStamp
+        var deviceCode = response.split('|')[1]
+        var nonceCode = response.split('|')[2]
+        var timeStamp = response.split('|')[3]
+        that.bindCarFn(deviceCode, nonceCode, timeStamp)
+      }
+    }
+  },
+
+  bindCarFn (deviceCode = '', nonceCode = '', timeStamp = '') {
+    var that = this
+    var data = {
+      deviceCode: deviceCode,
+      nonceCode: nonceCode,
+      timeStamp: timeStamp
+    }
+    wx.showLoading({
+      title: '绑定中...',
+      mask: true
+    })
+    bindCar(data).then(scanres => {
       that.setData({
-        scanFlag: false
+        scanFlag: true
       })
+      // 绑定成功到扫描档案页面
+      wx.hideLoading()
       wx.showModal({
         content: '权限登录成功',
         confirmColor: '#333',
-        showCancel: false
+        showCancel: false,
+        success (pres) {
+          if (pres.confirm) {
+            wx.navigateTo({
+              url: '/pages/workbench/workbench?form=peimission&deviceName=' + scanres.data.deviceName + '&deviceCode=' + scanres.data.deviceCode
+            })
+          }
+        }
       })
-    }
+    }).catch(e => {
+      that.setData({
+        scanFlag: false
+      })
+      wx.hideLoading()
+      wx.showModal({
+        content: e.msg,
+        confirmColor: '#333',
+        showCancel: false,
+        confirmText: '重新扫描',
+        success (res) {
+          if (res.confirm) {
+            setTimeout(() => {
+              that.setData({
+                scanFlag: true
+              })
+            }, 400);
+          }
+        }
+      })
+    })
   },
 
   bindscanerror () {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面显示
-   */
-  onShow() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面隐藏
-   */
-  onHide() {
-
-  },
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
-
-  },
-
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
-  },
-
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
-  },
-
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
+    wx.showModal({
+      content: '请打开相机权限',
+      confirmColor: '#333',
+      showCancel: false,
+      success (auth) {
+        if (auth.confirm) {
+          wx.openSetting({
+            success (res) {
+              console.log(res.authSetting)
+            }
+          })
+        }
+      }
+    })
   }
 })

+ 141 - 41
pages/workbench/workbench.js

@@ -1,4 +1,6 @@
 // pages/workbench/workbench.js
+import { writeOffOrder, confirmOrder } from '../../api/workbench'
+const app = getApp()
 Page({
 
   /**
@@ -6,25 +8,30 @@ Page({
    */
   data: {
     scanFlag: true,
-    overlayShow: false
+    overlayShow: false,
+    deviceName: '',
+    userName: '',
+    headImg: '',
+    workerId: '',
+    personName: '',
+    personSex: true,
+    birthday: '',
+    orderId: '',
+    orderNo: ''
   },
 
-  bindscancode (e) {
-    var that = this
-    if (that.data.scanFlag) {
-      var response = e.detail.result
-      console.log(response, 'response');
-      that.setData({
-        scanFlag: false
-      })
-    }
-  },
 
-  /**
-   * 生命周期函数--监听页面加载
-   */
-  onLoad(options) {
+  onLoad (options) {
+    this.getInitData(options)
+  },
 
+  getInitData (data) {
+    this.setData({
+      deviceName: data.deviceName ? data.deviceName : '',
+      userName: app.globalData.userName,
+      headImg: app.globalData.headImg,
+      workerId: app.globalData.workerId
+    })
   },
 
   handlecancel() {
@@ -34,45 +41,138 @@ Page({
   },
 
   handlesubmit() {
-    /* wx.showLoading({
+    var data = {
+      orderId: this.data.orderId
+    }
+    wx.showLoading({
       title: '加载中...',
       mask: true
-    }) */
+    })
+    confirmOrder(data).then(res => {
+      wx.hideLoading()
+      wx.showToast({
+        title: res.msg,
+        icon: 'success'
+      })
+    }).catch(e => {
+      wx.hideLoading()
+      wx.showModal({
+        content: e.msg,
+        confirmColor: '#333',
+        showCancel: false
+      })
+    })
   },
 
   /**
    * 生命周期函数--监听页面显示
    */
   onShow() {
-
-  },
-  
-
-  /**
-   * 生命周期函数--监听页面卸载
-   */
-  onUnload() {
-
+    if (!app.globalData.accessToken) {
+      wx.showModal({
+        content: '请先登录',
+        confirmColor: '#333',
+        showCancel: false,
+        success (scanres) {
+          if (scanres.confirm) {
+            wx.redirectTo({
+              url: '/pages/login/login'
+            })
+          }
+        } 
+      })
+    }
   },
 
-  /**
-   * 页面相关事件处理函数--监听用户下拉动作
-   */
-  onPullDownRefresh() {
-
+  bindscancode (e) {
+    var that = this
+    if (that.data.scanFlag) {
+      var response = e.detail.result
+      console.log(response, 'response');
+      var scodeType = response.split('|')[0] == 'DOCUMENT' ? true : false
+      if (!scodeType) {
+        that.setData({
+          scanFlag: false
+        })
+        wx.showModal({
+          content: '请扫描正确的二维码',
+          confirmColor: '#333',
+          showCancel: false,
+          success (scanres) {
+            if (scanres.confirm) {
+              that.setData({
+                scanFlag: true
+              })
+            }
+          } 
+        })
+      } else {
+        // DOCUMENT|documentId|uuid
+        var documentId = response.split('|')[1]
+        var uuid = response.split('|')[2]
+        that.writeOffOrderFn(documentId, uuid)
+      }
+    }
   },
 
-  /**
-   * 页面上拉触底事件的处理函数
-   */
-  onReachBottom() {
-
+  writeOffOrderFn (documentId = '', uuid = '') {
+    var that = this
+    var data = {
+      documentId: documentId,
+      uuid: uuid
+    }
+    wx.showLoading({
+      title: '加载中...',
+      mask: true
+    })
+    writeOffOrder(data).then(res => {
+      console.log(res, 'writeOffOrder');
+      that.setData({
+        scanFlag: true,
+        orderNo: res.data.orderNo,
+        orderId: res.data.orderId,
+        personName: res.data.personName,
+        personSex: res.data.personSex,
+        birthday: res.data.birthday,
+        overlayShow: true
+      })
+    }).catch(e => {
+      that.setData({
+        scanFlag: false
+      })
+      wx.hideLoading()
+      wx.showModal({
+        content: e.msg,
+        confirmColor: '#333',
+        showCancel: false,
+        confirmText: '重新扫描',
+        success (res) {
+          if (res.confirm) {
+            setTimeout(() => {
+              that.setData({
+                scanFlag: true
+              })
+            }, 400);
+          }
+        }
+      })
+    })
   },
 
-  /**
-   * 用户点击右上角分享
-   */
-  onShareAppMessage() {
-
+  bindscanerror () {
+    wx.showModal({
+      content: '请打开相机权限',
+      confirmColor: '#333',
+      showCancel: false,
+      success (auth) {
+        if (auth.confirm) {
+          wx.openSetting({
+            success (res) {
+              console.log(res.authSetting)
+            }
+          })
+        }
+      }
+    })
   }
 })

+ 10 - 8
pages/workbench/workbench.wxml

@@ -2,16 +2,18 @@
 <view class="work-content wh">
   <view class="account-info  ittflex-jcs">
     <view class="left half ittflex-jcs">
-      <view class="head-img"></view>
+      <view class="head-img">
+        <image class="wh" src="{{headImg}}"></image>
+      </view>
       <view class="userinfo">
-        <view class="username">范一岚</view>
-        <view class="usernum">18626576880</view>
+        <view class="username">{{userName}}</view>
+        <view class="usernum">{{workerId}}</view>
       </view>
     </view>
     <view class="right half">
       <view class="text">
         <view class="basetext">当前已获得</view>
-        <view class="basetext">测试测试测试检测车权限</view>
+        <view class="basetext">{{deviceName}}检测车权限</view>
       </view>
       <view class="arror">
         <image class="wh" src="../../images/you.png"></image>
@@ -20,22 +22,22 @@
   </view>
   <view class="tips">核销用户检测次数</view>
   <view class="camera">
-    <camera device-position="back" flash="off" mode="scanCode" bindscancode="bindscancode" binderror="error" style="width: 100%; height: 100%;"></camera>
+    <camera device-position="back" flash="off" mode="scanCode" bindscancode="bindscancode" binderror="bindscanerror" style="width: 100%; height: 100%;"></camera>
   </view>
   <view class="overlay wh" wx:if="{{overlayShow}}">
     <view class="modal">
       <view class="title">用户信息</view>
       <view class="username info">
         <text>姓名:</text>
-        <text class="codename">测试用户</text>
+        <text class="codename">{{personName}}</text>
       </view>
       <view class="info sex">
         <text>性别:</text>
-        <text>男</text>
+        <text>{{personSex ? '' : '女'}}</text>
       </view>
       <view class="info day">
         <text>出生年月:</text>
-        <text>2022-09</text>
+        <text>{{birthday}}</text>
       </view>
       <view class="info age">
         <text>年龄:</text>

+ 1 - 2
pages/workbench/workbench.wxss

@@ -19,7 +19,6 @@
   width: 80rpx;
   height: 80rpx;
   border-radius: 50%;
-  background-color: #f66;
   margin: 0 14rpx 0 20rpx;
 }
 .username {
@@ -57,7 +56,7 @@
 }
 .camera {
   width: 100%;
-  height: 700rpx;
+  height: calc(100% - 200rpx);
 }
 .overlay {
   position: absolute;

+ 13 - 0
project.private.config.json

@@ -4,5 +4,18 @@
   "setting": {
     "compileHotReLoad": true,
     "urlCheck": true
+  },
+  "condition": {
+    "miniprogram": {
+      "list": [
+        {
+          "name": "",
+          "pathName": "pages/workbench/workbench",
+          "query": "form=permission&deviceCode=100010",
+          "launchMode": "default",
+          "scene": null
+        }
+      ]
+    }
   }
 }