123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- // pages/permissions/permissions.js
- import { bindCar } from '../../api/permission'
- import util from '../../utils/util'
- Page({
- /**
- * 页面的初始数据
- */
- data: {
- scanFlag: false,
- scanTimer: null,
- reloadPage: false
- },
- /**
- * 生命周期函数--监听页面显示
- */
- onShow() {
- wx.hideHomeButton()
- const accessToken = wx.getStorageSync('accessToken')
- const tokenExpireTime = wx.getStorageSync('tokenExpireTime')
- if (util.getDate() !== tokenExpireTime) {
- wx.clearStorageSync()
- wx.reLaunch({
- url: '/pages/login/login'
- })
- } else {
- if (!accessToken) {
- wx.showModal({
- content: '请先登录',
- confirmColor: '#333',
- showCancel: false,
- success (scanres) {
- if (scanres.confirm) {
- wx.redirectTo({
- url: '/pages/login/login'
- })
- }
- }
- })
- } else {
- if (this.data.reloadPage) {
- wx.redirectTo({
- url: '/pages/login/login'
- })
- } else {
- this.setData({
- scanFlag: true
- })
- }
- }
- }
- },
- bindscancode(e) {
- const that = this
- if (that.data.scanFlag) {
- that.setData({
- scanFlag: false
- })
- var response = e.detail.result
- var scodeType = response.split('|')[0].trim() == 'DEVICE' ? true : false
- if (!scodeType) {
- wx.showModal({
- content: '请扫描正确的设备二维码',
- confirmColor: '#333',
- showCancel: false,
- success (scanres) {
- if (scanres.confirm) {
- var stimer = setTimeout(() => {
- that.setData({
- scanFlag: true
- })
- clearTimeout(stimer)
- }, 300);
- }
- }
- })
- } else {
- // DEVICE|deviceCode|nonceCode|timeStamp
- var deviceCode = response.split('|')[1].trim()
- var nonceCode = response.split('|')[2].trim()
- var timeStamp = response.split('|')[3].trim()
- 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 => {
- // 绑定成功到扫描档案页面
- wx.hideLoading()
- wx.setStorageSync('device', scanres.data)
- wx.showModal({
- content: '权限登录成功',
- confirmColor: '#333',
- showCancel: false,
- success (pres) {
- if (pres.confirm) {
- wx.redirectTo({
- url: '/pages/workbench/workbench?form=peimission&deviceName=' + scanres.data.deviceName + '&deviceCode=' + scanres.data.deviceCode,
- success () {
- that.setData({
- scanFlag: true
- })
- }
- })
- }
- }
- })
- }).catch(e => {
- wx.hideLoading()
- wx.showModal({
- content: e.msg,
- confirmColor: '#333',
- showCancel: false,
- confirmText: '重新扫描',
- success (res) {
- if (res.confirm) {
- var timer = setTimeout(() => {
- that.setData({
- scanFlag: true
- })
- clearTimeout(timer)
- }, 300);
- }
- }
- })
- })
- },
- bindscanerror () {
- var that = this
- wx.showModal({
- content: '请打开相机权限',
- confirmColor: '#333',
- showCancel: false,
- success (auth) {
- if (auth.confirm) {
- wx.openSetting({
- success (res) {
- console.log(res.authSetting)
- that.setData({
- reloadPage: true
- })
- }
- })
- }
- }
- })
- }
- })
|