[AI Generated]: feat(*): 新增 OpenID 登录流程及启动自动跳转逻辑
This commit is contained in:
@@ -1,3 +1,38 @@
|
||||
import { post } from '../../utils/request/index'
|
||||
|
||||
/** 通过 OpenID 登录的用户信息 */
|
||||
interface CheckOpenIdLoginResult {
|
||||
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
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
@@ -13,8 +48,33 @@ Page({
|
||||
|
||||
/* 微信一键登录 */
|
||||
onLogin() {
|
||||
wx.navigateTo({
|
||||
url: '/pages/connectedDevice/connectedDevice'
|
||||
if (this.data.loading) return
|
||||
this.setData({ loading: true })
|
||||
|
||||
wx.login({
|
||||
success: ({ code }) => {
|
||||
post<CheckOpenIdLoginResult>('weighingScale/v2/checkOpenIdLogin', { code })
|
||||
.then(({ result }) => {
|
||||
/* 存储用户信息 */
|
||||
wx.setStorageSync('userInfo', result)
|
||||
|
||||
/* 上次连接设备不为空对象则直接进首页 */
|
||||
const connectDeviceInfo = result.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' })
|
||||
this.setData({ loading: false })
|
||||
},
|
||||
})
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user