qa-education-exam-weapp/pages/login/login.js

47 lines
1.2 KiB
JavaScript

import {login} from "../../api/index";
import debounce from '../../utils/debounce'
const app = getApp()
Page({
data: {
userName: '',
password: '',
},
onLoad() {
if (!app.globalData.userInfo.USER_ID) {
wx.reLaunch({
url: 'pages/login/login'
})
} else {
wx.switchTab({
url: '/pages/index/index'
})
}
},
submitLogin() {
debounce(async () => {
if (!this.data.userName) {
wx.showToast({
title: '请输入用户名',
icon: 'none'
})
return
}
if (!this.data.password) {
wx.showToast({
title: '请输入密码',
icon: 'none'
})
return
}
let KEYDATA = `qdkjchina${this.data.userName},qd,${this.data.password}`
app.globalData.userInfo = await login({
KEYDATA
})
wx.switchTab({
url: '/pages/index/index'
})
})
}
})