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

163 lines
4.1 KiB
JavaScript
Raw Normal View History

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