cyx-ament-wechat/miniprogram/pages/loading/loading.js

163 lines
4.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/loading/loading.js
const $api = require('../../utils/api').API;
import Dialog from '@vant/weapp/dialog/dialog';
const $app = getApp();
Page({
/**
* 页面的初始数据
*/
data: {
username:'',
password:''
},
/**
* 生命周期函数--监听页面加载
*/
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() {
var username = wx.getStorageSync('loginName')
var password = wx.getStorageSync('password')
console.log(username)
console.log(password)
if (username && password){
this.autoLogin(username,password)
}
},
autoLogin(username,password){
this.setData({
username:username,
password:password
})
const _this = this;
$api.getUserInfo({
"loginName": _this.data.username,
"password": _this.data.password,
}).then(obj => {
if (obj.code === 0){
wx.setStorageSync("loginName", _this.data.username);
wx.setStorageSync("password", _this.data.password);
wx.setStorageSync("userInfo", obj.data.userInfo);
wx.setStorageSync("perInfo", obj.data.perInfo);
wx.reLaunch({
url: '/pages/evaluation/evaluation'
});
}else {
Dialog.alert({
message:'用户名或密码错误'
})
}
}).catch(err => {
Dialog.alert({
message:'服务器错误404请联系管理员'
})
})
},
login(){
const _this = this;
if (!_this.data.username){
Dialog.alert({
message:'请输入用户名'
})
return false
}
if (!_this.data.password){
Dialog.alert({
message:'请输入密码'
})
return false
}
$api.getUserInfo({
"loginName": _this.data.username,
"password": _this.data.password,
}).then(obj => {
if (obj.code === 0){
wx.setStorageSync("loginName", _this.data.username);
wx.setStorageSync("password", _this.data.password);
wx.setStorageSync("userInfo", obj.data.userInfo);
wx.setStorageSync("perInfo", obj.data.perInfo);
wx.reLaunch({
url: '/pages/evaluation/evaluation'
});
}else {
Dialog.alert({
message:'用户名或密码错误'
})
}
}).catch(err => {
Dialog.alert({
message:'服务器错误404请联系管理员'
})
})
},
/**
* 生命周期函数--监听页面显示
*/
onShow() {
},
/**
* 生命周期函数--监听页面隐藏
*/
onHide() {
},
/**
* 生命周期函数--监听页面卸载
*/
onUnload() {
},
/**
* 页面相关事件处理函数--监听用户下拉动作
*/
onPullDownRefresh() {
},
/**
* 页面上拉触底事件的处理函数
*/
onReachBottom() {
},
/**
* 用户点击右上角分享
*/
onShareAppMessage() {
}
})