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.
|
|
|
import { login } from '../../api/index'
|
|
|
|
Page({
|
|
|
|
data: {
|
|
|
|
userName: '',
|
|
|
|
password: ''
|
|
|
|
},
|
|
|
|
// @ts-ignore
|
|
|
|
handleLogin: function () {
|
|
|
|
let that = this
|
|
|
|
if (that.data.userName == '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请输入用户名',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 2000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (that.data.password == '') {
|
|
|
|
wx.showToast({
|
|
|
|
title: '请输入密码',
|
|
|
|
icon: 'none',
|
|
|
|
duration: 2000
|
|
|
|
})
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
wx.login({
|
|
|
|
success(res) {
|
|
|
|
wx.showLoading({
|
|
|
|
title: '登录中,请稍后',
|
|
|
|
})
|
|
|
|
let code = res.code
|
|
|
|
console.log(code)
|
|
|
|
if (code) {
|
|
|
|
let params = {
|
|
|
|
username: that.data.userName,
|
|
|
|
password: that.data.password,
|
|
|
|
wxCode: code
|
|
|
|
}
|
|
|
|
login(params).then((res: any) => {
|
|
|
|
// console.log(res)
|
|
|
|
if (res.code == '0') {
|
|
|
|
wx.setStorageSync('token', res.data.token)
|
|
|
|
wx.setStorageSync('userTagKey', res.data.userTagKey)
|
|
|
|
wx.setStorageSync('deptDataScopeList', JSON.stringify(res.data.deptDataScopeList))
|
|
|
|
|
|
|
|
wx.redirectTo({
|
|
|
|
url: '/pages/index/index'
|
|
|
|
})
|
|
|
|
} else {
|
|
|
|
wx.showToast({
|
|
|
|
title: res.msg,
|
|
|
|
icon: 'none',
|
|
|
|
duration: 2000
|
|
|
|
})
|
|
|
|
}
|
|
|
|
wx.hideLoading()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
// console.log('222222')
|
|
|
|
},
|
|
|
|
getUserName(e: { detail: { value: any } }) {
|
|
|
|
this.setData({
|
|
|
|
userName: e.detail.value
|
|
|
|
})
|
|
|
|
// console.log('userName', this.data.userName)
|
|
|
|
},
|
|
|
|
getPassword(e: { detail: { value: any } }) {
|
|
|
|
this.setData({
|
|
|
|
password: e.detail.value
|
|
|
|
})
|
|
|
|
// console.log('password', this.data.password)
|
|
|
|
},
|
|
|
|
onShow () {
|
|
|
|
// console.log('显示')
|
|
|
|
},
|
|
|
|
onLoad () {
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|