You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
210 lines
7.7 KiB
210 lines
7.7 KiB
// pages/administ/index.js
|
|
import Dialog from '../../components/dialog/dialog'
|
|
import { config, getUserInfo, verifyCode } from "../api/user"
|
|
// import { loginToken, cconfig } from "../api/cloud"
|
|
// import { mconfig } from "../api/mall"
|
|
import { pconfig } from "../api/payment"
|
|
const storage = require('../../utils/storage')
|
|
const event = require('../../utils/event')
|
|
const util = require('../../utils/util')
|
|
const app = getApp()
|
|
|
|
Page({
|
|
/**
|
|
* 页面的初始数据
|
|
*/
|
|
data: {
|
|
safeBottom: app.globalData.safeBottom,
|
|
fragment: app.globalData.safeFragmentHeight,
|
|
tabList: [
|
|
{ index: 0, value: 'mall', badge: 0, name: '商城', blue: '/assets/image/tabbar/mall-blue.png', gray: '/assets/image/tabbar/mall-gray.png' },
|
|
{ index: 1, value: 'work', badge: 0, name: '工作台', blue: '/assets/image/tabbar/process-blue.png', gray: '/assets/image/tabbar/process-gray.png' },
|
|
{ index: 2, value: 'home', badge: 0, name: '我的', blue: '/assets/image/tabbar/home-blue.png', gray: '/assets/image/tabbar/home-gray.png' }
|
|
],
|
|
tabIndex: 0,
|
|
inited: false,
|
|
authorization: null,
|
|
code: null,
|
|
// code: '?mark=cloudprint&QrCodeRecordId=541755014083907584'
|
|
},
|
|
/************************************** 初始化流程 ********************************************/
|
|
onLoad: function (options) {
|
|
const updateManager = wx.getUpdateManager()
|
|
updateManager.onCheckForUpdate()
|
|
updateManager.onUpdateReady(function () {
|
|
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
|
updateManager.applyUpdate()
|
|
})
|
|
if(options.q){
|
|
//扫二维码进入的,
|
|
let q = decodeURIComponent(options.q)
|
|
this.data.code = q.substring(q.indexOf('?'))
|
|
}
|
|
event.on('EventMessage', this, this.onEvent)
|
|
},
|
|
onReady: function () {
|
|
wx.showLoading({ title: '获取中', mask: true })
|
|
wx.getSystemInfo({
|
|
success: e => {
|
|
app.globalData.isIPhoneX = this.checkIPhoneX(e)
|
|
app.globalData.isIos = this.checkIos(e)
|
|
app.globalData.dev = e.platform == 'devtools'
|
|
|
|
let custom = wx.getMenuButtonBoundingClientRect()
|
|
app.globalData.Custom = custom
|
|
// 顶部操作栏高度
|
|
app.globalData.CustomBar = custom.bottom + custom.top - e.statusBarHeight + (app.globalData.isIos ? 4 : 0)
|
|
let windowHeight = e.windowHeight * (750 / e.windowWidth)
|
|
|
|
let safeBottom = e.windowHeight - e.safeArea.bottom
|
|
if(safeBottom > e.windowHeight){
|
|
safeBottom = 34
|
|
}
|
|
app.globalData.safeBottom = safeBottom * (750 / e.windowWidth)
|
|
// 状态栏高度
|
|
app.globalData.StatusBar = e.statusBarHeight * (750 / e.windowWidth)
|
|
let statusBarHeight = app.globalData.CustomBar * (750 / e.windowWidth)
|
|
app.globalData.statusBarHeight = statusBarHeight
|
|
// fragmentHeight:指的是整个页面statusBarHeight以下的高度
|
|
app.globalData.fragmentHeight = windowHeight - statusBarHeight
|
|
app.globalData.safeFragmentHeight = windowHeight - statusBarHeight - app.globalData.safeBottom
|
|
app.globalData.windowWidth = e.windowWidth
|
|
|
|
this.data.inited = true
|
|
const fheght = (app.globalData.safeFragmentHeight + app.globalData.statusBarHeight) - 100
|
|
event.emit('InitMessage', { what: 8, desc: 'Inited' })
|
|
this.setData({fragment: fheght, safeBottom: app.globalData.safeBottom, inited: true })
|
|
this.data.authorization = app.globalData.token || storage.get('Authorization')
|
|
if(this.data.code){
|
|
// 进入登录绑定页面
|
|
this.fetchCode(this.data.code)
|
|
} else if(this.data.authorization){
|
|
app.globalData.token = this.data.authorization
|
|
this.fetchUserInfo()
|
|
} else {
|
|
wx.hideLoading()
|
|
this.onResume()
|
|
}
|
|
}
|
|
})
|
|
},
|
|
checkIos: function (e) {
|
|
if ('ios' === e.platform) {
|
|
return true
|
|
}
|
|
if (e.system.startsWith('iOS')) {
|
|
return true
|
|
}
|
|
return false
|
|
},
|
|
checkIPhoneX: function (e) {
|
|
var t = e.model
|
|
return (/iPhone 11/.test(t) || /iPhone X/.test(t) || /iPhone 12/.test(t)) && this.checkIos(e)
|
|
},
|
|
/************************************** 登录流程 ********************************************/
|
|
onEvent: function (message) {
|
|
if (message.what == 888) {
|
|
if(!app.accountInfo){
|
|
this.setData({ tabIndex: 0 })
|
|
} else if(app.accountInfo && app.accountInfo.applicationStatus == 0){
|
|
this.setData({ tabIndex: 1 })
|
|
}
|
|
}
|
|
},
|
|
fetchUserInfo: function(){
|
|
if(!app.globalData.token){
|
|
wx.hideLoading()
|
|
this.onResume()
|
|
return
|
|
}
|
|
config.header = { 'Authorization': 'QNT ' + app.globalData.token }
|
|
getUserInfo().then(result => {
|
|
if (result.data.token) {
|
|
storage.put('Authorization', result.data.token)
|
|
app.globalData.token = result.data.token
|
|
}
|
|
app.accountInfo = result.data
|
|
loginToken({loginToken: app.globalData.token}).then(result => {
|
|
mconfig.header = { 'Authorization': 'QNT ' + result.data }
|
|
cconfig.header = { 'Authorization': 'QNT ' + result.data }
|
|
pconfig.header = { 'Authorization': 'QNT ' + result.data }
|
|
// 登录流程完成;
|
|
wx.hideLoading()
|
|
// 如果是员工,或者
|
|
if(app.accountInfo && app.accountInfo.applicationStatus == 0){
|
|
this.setData({ tabIndex: 1 })
|
|
}
|
|
this.onResume()
|
|
// event.emit('EventMessage', { what: 888, desc: 'Logined' })
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
this.onResume()
|
|
})
|
|
}).catch(err => {
|
|
wx.hideLoading()
|
|
this.onResume()
|
|
})
|
|
},
|
|
// 根据二维码的code获取相关的内容;
|
|
fetchCode: function(code){
|
|
verifyCode(code).then(result => {
|
|
this.data.code = null
|
|
if(result.data.redirectUrl == '/login'){
|
|
// 根据userId来获取用户信息;并且直接登录
|
|
app.globalData.token = result.data.metaData.token
|
|
storage.put('Authorization', app.globalData.token)
|
|
this.fetchUserInfo()
|
|
} else if('/page/index/yaoqing' == result.data.redirectUrl || '/page/index/shenqing' == result.data.redirectUrl){
|
|
storage.put('metaData', JSON.stringify(result.data), 1)
|
|
wx.hideLoading()
|
|
// 进入login页面;
|
|
wx.navigateTo({ url: '/pages/index/index?code=11' })
|
|
} else {
|
|
wx.hideLoading()
|
|
if(!result.data.message){
|
|
result.data.message = '二维码解析失败,请重新扫码'
|
|
}
|
|
util.showToast(result.data.message)
|
|
}
|
|
}).catch(err => {
|
|
//异常回调
|
|
wx.hideLoading()
|
|
if(this.data.authorization){
|
|
Dialog.alert({ title: '温馨提示', message: '二维码解析失败,以当前账号进行登录!' }).then(() => {
|
|
wx.showLoading({ title: '登录中', mask: true })
|
|
app.globalData.token = this.data.authorization
|
|
this.fetchUserInfo()
|
|
})
|
|
} else {
|
|
util.showToast(err)
|
|
this.onResume()
|
|
}
|
|
})
|
|
},
|
|
/************************************** 生命周期函数--监听页面初次渲染完成 ********************************************/
|
|
onShow: function () {
|
|
if(this.data.inited){
|
|
this.onResume()
|
|
}
|
|
},
|
|
onResume: function(){
|
|
var pageView = this.selectComponent('#' + this.data.tabList[this.data.tabIndex].value)
|
|
if (pageView && this.data.inited) {
|
|
pageView.onRestart()
|
|
}
|
|
},
|
|
onChange: function ({detail}) {
|
|
if(detail == 2 && !app.accountInfo){
|
|
wx.navigateTo({ url: '/pages/login/index' })
|
|
return
|
|
}
|
|
this.setData({ tabIndex: detail })
|
|
this.onResume()
|
|
},
|
|
stopTouchMove: function(e){
|
|
return false
|
|
},
|
|
onUnload: function(){
|
|
event.remove('EventMessage', this)
|
|
}
|
|
})
|