删除 11 个旧页面、组件、lefu SDK、旧资源文件。 新增 request 封装(GET/POST/PUT)、api 层、utils/common 身份证工具。 重写 login(登录流程提取到 app.ts) 和 supplementPersonal(简化表单逻辑)。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
45 lines
1.3 KiB
TypeScript
45 lines
1.3 KiB
TypeScript
import { checkOpenIdLogin } from '../../api/index'
|
|
|
|
const app = getApp<IAppOption>()
|
|
|
|
Page({
|
|
data: {
|
|
loading: false,
|
|
},
|
|
|
|
onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent {
|
|
return {
|
|
title: '智能蓝牙秤',
|
|
path: '/pages/login/login',
|
|
imageUrl: '/images/share/share.jpg',
|
|
}
|
|
},
|
|
|
|
/* 微信一键登录 */
|
|
onLogin() {
|
|
if (this.data.loading) return
|
|
this.setData({ loading: true })
|
|
|
|
// 获取微信临时 code → 调用 OpenID 登录接口
|
|
app.getWxLoginCode()
|
|
.then((code) => checkOpenIdLogin(code))
|
|
.then((res) => {
|
|
const { token, user } = res.data
|
|
// 持久化登录凭证和用户信息
|
|
wx.setStorageSync('token', token)
|
|
if (user) {
|
|
wx.setStorageSync('userInfo', user)
|
|
wx.reLaunch({ url: '/pages/home/home' })
|
|
} else {
|
|
wx.reLaunch({ url: '/pages/supplementPersonal/supplementPersonal' })
|
|
}
|
|
})
|
|
.catch((err) => {
|
|
wx.showToast({ title: err.msg || '登录失败,请重试', icon: 'none' })
|
|
})
|
|
.finally(() => {
|
|
this.setData({ loading: false })
|
|
})
|
|
},
|
|
})
|