refactor: 项目重构,仅保留 login 和 supplementPersonal 页面
删除 11 个旧页面、组件、lefu SDK、旧资源文件。 新增 request 封装(GET/POST/PUT)、api 层、utils/common 身份证工具。 重写 login(登录流程提取到 app.ts) 和 supplementPersonal(简化表单逻辑)。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
439f560218
commit
83d909b95b
@@ -1,43 +1,6 @@
|
||||
import { post } from '../../utils/request/index'
|
||||
import { checkOpenIdLogin } from '../../api/index'
|
||||
|
||||
/** 通过 OpenID 登录的用户信息 */
|
||||
interface UserInfo {
|
||||
id: string
|
||||
userId: string
|
||||
parentUserId: string | null
|
||||
scaleDeviceId: string
|
||||
deviceId: string | null
|
||||
deviceType: string
|
||||
dataType: number
|
||||
userType: string | null
|
||||
idCard: string
|
||||
height: number
|
||||
weight: number
|
||||
birthday: string
|
||||
sex: number
|
||||
avatar: string | null
|
||||
phone: string | null
|
||||
thirdId: string
|
||||
realname: string
|
||||
bmi: number
|
||||
createBy: string
|
||||
createTime: string
|
||||
updateBy: string | null
|
||||
updateTime: string | null
|
||||
delFlag: number
|
||||
sn: string | null
|
||||
workNo: string | null
|
||||
remark: string | null
|
||||
relationType: string | null
|
||||
sex_dictText: string
|
||||
connectDeviceInfo: string
|
||||
}
|
||||
|
||||
/** 登录接口 result 结构 */
|
||||
interface CheckOpenIdLoginResult {
|
||||
user: UserInfo | null
|
||||
token: string
|
||||
}
|
||||
const app = getApp<IAppOption>()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -47,7 +10,7 @@ Page({
|
||||
onShareAppMessage(): WechatMiniprogram.Page.ICustomShareContent {
|
||||
return {
|
||||
title: '智能蓝牙秤',
|
||||
path: '/pages/home/home',
|
||||
path: '/pages/login/login',
|
||||
imageUrl: '/images/share/share.jpg',
|
||||
}
|
||||
},
|
||||
@@ -57,30 +20,25 @@ Page({
|
||||
if (this.data.loading) return
|
||||
this.setData({ loading: true })
|
||||
|
||||
wx.login({
|
||||
success: ({ code }) => {
|
||||
post<CheckOpenIdLoginResult>('weighingScale/v2/checkOpenIdLogin', { code })
|
||||
.then(({ result }) => {
|
||||
wx.setStorageSync('token', result.token)
|
||||
wx.setStorageSync('userInfo', result.user)
|
||||
|
||||
/* 上次连接设备不为空对象则直接进首页 */
|
||||
const connectDeviceInfo = result.user?.connectDeviceInfo
|
||||
if (connectDeviceInfo && connectDeviceInfo !== '{}') {
|
||||
wx.setStorageSync('connectDeviceInfo', JSON.parse(connectDeviceInfo))
|
||||
wx.reLaunch({ url: '/pages/home/home' })
|
||||
} else {
|
||||
wx.reLaunch({ url: '/pages/connectedDevice/connectedDevice' })
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
this.setData({ loading: false })
|
||||
})
|
||||
},
|
||||
fail: () => {
|
||||
wx.showToast({ title: '获取登录凭证失败', icon: 'none' })
|
||||
// 获取微信临时 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 })
|
||||
},
|
||||
})
|
||||
})
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user