48 lines
No EOL
888 B
JavaScript
48 lines
No EOL
888 B
JavaScript
// login.js
|
|
import { wxLogin } from '../../services/auth';
|
|
|
|
Page({
|
|
data: {
|
|
loading: false
|
|
},
|
|
|
|
onLoad() {
|
|
// 页面加载时检查是否已经登录
|
|
const token = wx.getStorageSync('token');
|
|
if (token) {
|
|
this.redirectToHome();
|
|
}
|
|
},
|
|
|
|
// 处理登录按钮点击
|
|
handleLogin() {
|
|
if (this.data.loading) return;
|
|
|
|
this.setData({ loading: true });
|
|
|
|
wxLogin()
|
|
.then(() => {
|
|
wx.showToast({
|
|
title: '登录成功',
|
|
icon: 'success'
|
|
});
|
|
this.redirectToHome();
|
|
})
|
|
.catch(err => {
|
|
wx.showToast({
|
|
title: err.message || '登录失败',
|
|
icon: 'none'
|
|
});
|
|
})
|
|
.finally(() => {
|
|
this.setData({ loading: false });
|
|
});
|
|
},
|
|
|
|
// 跳转到首页
|
|
redirectToHome() {
|
|
wx.reLaunch({
|
|
url: '/pages/otp-list/index'
|
|
});
|
|
}
|
|
}); |