53 lines
1.3 KiB
JavaScript
53 lines
1.3 KiB
JavaScript
const authApi = require('../../api/auth')
|
|
|
|
Page({
|
|
data: {
|
|
form: {
|
|
account: '',
|
|
password: ''
|
|
},
|
|
loading: false
|
|
},
|
|
|
|
onInput(event) {
|
|
const field = event.currentTarget.dataset.field
|
|
this.setData({
|
|
[`form.${field}`]: event.detail.value
|
|
})
|
|
},
|
|
|
|
async submit() {
|
|
if (!this.data.form.account || !this.data.form.password) {
|
|
wx.showToast({ title: '请填写手机号和密码', icon: 'none' })
|
|
return
|
|
}
|
|
this.setData({ loading: true })
|
|
try {
|
|
const data = await authApi.login({
|
|
account: this.data.form.account,
|
|
password: this.data.form.password
|
|
})
|
|
const app = getApp()
|
|
app.setSession({
|
|
...data,
|
|
accessToken: data.accessToken || data.token,
|
|
userInfo: data.userInfo || data.user || {},
|
|
shopName: data.shopName || (data.shop && data.shop.shopName)
|
|
})
|
|
wx.reLaunch({ url: '/pages/planning/index' })
|
|
} catch (error) {
|
|
wx.showToast({ title: error.message || '登录失败', icon: 'none' })
|
|
} finally {
|
|
this.setData({ loading: false })
|
|
}
|
|
},
|
|
|
|
goRegister() {
|
|
wx.navigateTo({ url: '/pages/register/index' })
|
|
},
|
|
|
|
wechatLogin() {
|
|
wx.showToast({ title: '请先使用账号登录', icon: 'none' })
|
|
}
|
|
})
|