128 lines
3.5 KiB
JavaScript
128 lines
3.5 KiB
JavaScript
// pages/loading/loading.js
|
||
const $api = require('../../utils/api').API;
|
||
import Dialog from '@vant/weapp/dialog/dialog';
|
||
const $app = getApp();
|
||
Page({
|
||
|
||
/**
|
||
* 页面的初始数据
|
||
*/
|
||
data: {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面加载
|
||
*/
|
||
onLoad(options) {
|
||
//测试版本更新
|
||
const updateManager = wx.getUpdateManager()
|
||
|
||
updateManager.onCheckForUpdate(function (res) {
|
||
// 请求完新版本信息的回调
|
||
console.log(res,'是否打印?');
|
||
})
|
||
|
||
updateManager.onUpdateReady(function () {
|
||
wx.showModal({
|
||
title: '更新提示',
|
||
content: '新版本已经准备好,是否重启应用?',
|
||
success: function (res) {
|
||
if (res.confirm) {
|
||
// 新的版本已经下载好,调用 applyUpdate 应用新版本并重启
|
||
updateManager.applyUpdate()
|
||
}
|
||
}
|
||
})
|
||
})
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面初次渲染完成
|
||
*/
|
||
onReady() {
|
||
//登录
|
||
const _this = this;
|
||
wx.login({
|
||
success: res => {
|
||
$api.getUserInfo({
|
||
"code": res.code
|
||
}).then(obj => {
|
||
if (obj.code == 200) {
|
||
//保存openId
|
||
wx.setStorageSync("openId", obj.data.openId);
|
||
//判断绑定状态,跳转页面
|
||
if (obj.data.status == "UNBIND") {
|
||
wx.reLaunch({
|
||
url: '/pages/bind/bind'
|
||
})
|
||
} else {
|
||
wx.setStorageSync("token", obj.data.token);
|
||
wx.setStorageSync("sourceCow", obj.data.loginUser.sourceCow);
|
||
wx.setStorageSync("userInfo", obj.data.loginUser);
|
||
wx.setStorageSync("sourceCow", obj.data.loginUser.sourceCow);
|
||
wx.setStorageSync("farmName", obj.data.loginUser.name);
|
||
let roles = obj.data.loginUser.roles;
|
||
//拼接角色字符串
|
||
var roleStr = "";
|
||
roles.forEach(element => {
|
||
roleStr += element.roleKey;
|
||
});
|
||
wx.setStorageSync("roleStr",roleStr);
|
||
//保存用户信息
|
||
wx.reLaunch({
|
||
url: '/pages/work/work'
|
||
});
|
||
}
|
||
}
|
||
}).catch(err => {
|
||
Dialog.alert({
|
||
message:'服务器错误:404,请联系管理员!'
|
||
})
|
||
})
|
||
},
|
||
})
|
||
},
|
||
/**
|
||
* 生命周期函数--监听页面显示
|
||
*/
|
||
onShow() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面隐藏
|
||
*/
|
||
onHide() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 生命周期函数--监听页面卸载
|
||
*/
|
||
onUnload() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面相关事件处理函数--监听用户下拉动作
|
||
*/
|
||
onPullDownRefresh() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 页面上拉触底事件的处理函数
|
||
*/
|
||
onReachBottom() {
|
||
|
||
},
|
||
|
||
/**
|
||
* 用户点击右上角分享
|
||
*/
|
||
onShareAppMessage() {
|
||
|
||
}
|
||
})
|