[AI Generated]: feat(*): 新增 OpenID 登录流程及启动自动跳转逻辑
This commit is contained in:
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"pages": [
|
"pages": [
|
||||||
"pages/addMember/addMember",
|
|
||||||
"pages/home/home",
|
|
||||||
"pages/login/login",
|
"pages/login/login",
|
||||||
|
"pages/home/home",
|
||||||
"pages/connectedDevice/connectedDevice",
|
"pages/connectedDevice/connectedDevice",
|
||||||
"pages/connectedWifi/connectedWifi",
|
"pages/connectedWifi/connectedWifi",
|
||||||
"pages/supplementPersonal/supplementPersonal",
|
"pages/supplementPersonal/supplementPersonal",
|
||||||
"pages/equipmentMember/equipmentMember",
|
"pages/equipmentMember/equipmentMember",
|
||||||
|
"pages/addMember/addMember",
|
||||||
"pages/equipment/equipment",
|
"pages/equipment/equipment",
|
||||||
"pages/measurementReport/measurementReport",
|
"pages/measurementReport/measurementReport",
|
||||||
"pages/data/data",
|
"pages/data/data",
|
||||||
|
|||||||
@@ -9,5 +9,15 @@ App<IAppOption>({
|
|||||||
onLaunch() {
|
onLaunch() {
|
||||||
// 初始化乐福蓝牙 SDK
|
// 初始化乐福蓝牙 SDK
|
||||||
lefuService.init()
|
lefuService.init()
|
||||||
|
|
||||||
|
// 已登录则跳过登录页
|
||||||
|
const userInfo = wx.getStorageSync('userInfo')
|
||||||
|
if (userInfo) {
|
||||||
|
const connectDeviceInfo = wx.getStorageSync('connectDeviceInfo')
|
||||||
|
const hasDevice = connectDeviceInfo && Object.keys(connectDeviceInfo).length > 0
|
||||||
|
wx.reLaunch({
|
||||||
|
url: hasDevice ? '/pages/home/home' : '/pages/connectedDevice/connectedDevice'
|
||||||
|
})
|
||||||
|
}
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,38 +1,93 @@
|
|||||||
/** 已配对设备模型 */
|
import { get } from '../../utils/request/index'
|
||||||
interface DeviceItem {
|
|
||||||
/** 设备唯一 id */
|
/** API 返回的设备记录 */
|
||||||
|
interface DeviceRecord {
|
||||||
id: string
|
id: string
|
||||||
/** 设备名称 */
|
userId: string
|
||||||
name: string
|
parentUserId: string | null
|
||||||
/** 是否已连接 */
|
scaleDeviceId: string
|
||||||
|
deviceId: string | null
|
||||||
|
deviceType: string
|
||||||
|
dataType: number
|
||||||
|
userType: number
|
||||||
|
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
|
||||||
|
updateTime: string
|
||||||
|
delFlag: number
|
||||||
|
sn: string | null
|
||||||
|
workNo: string
|
||||||
|
remark: string | null
|
||||||
|
relationType: string | null
|
||||||
|
sex_dictText: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** 展示用设备项 */
|
||||||
|
interface DeviceItem {
|
||||||
|
id: string
|
||||||
|
scaleDeviceId: string
|
||||||
|
realname: string
|
||||||
|
/** 蓝牙连接状态,接口不返回,由业务层更新 */
|
||||||
connected: boolean
|
connected: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
Page({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
/* 已配对设备 mock 列表(后续接入真实接口时替换) */
|
loading: false,
|
||||||
deviceList: [
|
deviceList: [] as DeviceItem[],
|
||||||
{ id: 'd1', name: '智能体重秤 Pro', connected: true },
|
|
||||||
{ id: 'd2', name: '体重秤 Basic', connected: false },
|
|
||||||
] as DeviceItem[],
|
|
||||||
},
|
},
|
||||||
|
|
||||||
onLoad() {
|
onLoad() {
|
||||||
/* 页面进入时无副作用,设备列表后续接入真实接口 */
|
this.loadData()
|
||||||
},
|
},
|
||||||
|
|
||||||
/* 点击「连接」:未连接卡片才会出现 —— 暂留空,待跳转逻辑接入 */
|
/** 拉取已绑定设备列表 */
|
||||||
|
loadData() {
|
||||||
|
this.setData({ loading: true })
|
||||||
|
get<DeviceRecord[]>('weighingScale/v3/list/device')
|
||||||
|
.then(res => {
|
||||||
|
const list: DeviceItem[] = res.result.map(item => ({
|
||||||
|
id: item.id,
|
||||||
|
scaleDeviceId: item.scaleDeviceId,
|
||||||
|
realname: item.realname,
|
||||||
|
connected: false,
|
||||||
|
}))
|
||||||
|
this.setData({ deviceList: list })
|
||||||
|
})
|
||||||
|
.finally(() => {
|
||||||
|
this.setData({ loading: false })
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
/* 点击「连接」→ 跳转设备搜索页 */
|
||||||
onTapConnect() {
|
onTapConnect() {
|
||||||
// TODO: 跳转设备搜索/绑定流程
|
wx.navigateTo({
|
||||||
|
url: '/pages/connectedDevice/connectedDevice'
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/* 点击「成员管理」:暂留空,待成员管理页接入 */
|
/* 点击「成员管理」→ 跳转成员管理页 */
|
||||||
onTapMember() {
|
onTapMember(e: WechatMiniprogram.TouchEvent) {
|
||||||
// TODO: 跳转成员管理页
|
const id = e.currentTarget.dataset.id as string
|
||||||
|
wx.navigateTo({
|
||||||
|
url: `/pages/equipmentMember/equipmentMember?id=${id}`
|
||||||
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
/* 点击「添加设备」:暂留空,待跳转逻辑接入 */
|
/* 点击「添加设备」→ 跳转设备搜索页 */
|
||||||
onTapAdd() {
|
onTapAdd() {
|
||||||
// TODO: 跳转设备搜索页
|
wx.navigateTo({
|
||||||
|
url: '/pages/connectedDevice/connectedDevice'
|
||||||
|
})
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -8,11 +8,12 @@
|
|||||||
<block wx:for="{{ deviceList }}" wx:key="id">
|
<block wx:for="{{ deviceList }}" wx:key="id">
|
||||||
<view class="device-card">
|
<view class="device-card">
|
||||||
|
|
||||||
<!-- 上半:图标 + 设备名 + 状态(色点 + 文字) -->
|
<!-- 上半:图标 + 设备信息 + 状态(色点 + 文字) -->
|
||||||
<view class="card-top">
|
<view class="card-top">
|
||||||
<view class="card-icon"></view>
|
<view class="card-icon"></view>
|
||||||
<view class="card-info">
|
<view class="card-info">
|
||||||
<view class="card-name">{{ item.name }}</view>
|
<view class="card-name">{{ item.scaleDeviceId }}</view>
|
||||||
|
<view class="card-user">{{ item.realname }}</view>
|
||||||
<view class="card-status">
|
<view class="card-status">
|
||||||
<!-- 已连接:绿点 + "已连接" -->
|
<!-- 已连接:绿点 + "已连接" -->
|
||||||
<block wx:if="{{ item.connected }}">
|
<block wx:if="{{ item.connected }}">
|
||||||
|
|||||||
@@ -40,6 +40,10 @@
|
|||||||
text-align: center;
|
text-align: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.login-btn--disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
}
|
||||||
|
|
||||||
.login-btn {
|
.login-btn {
|
||||||
color: #FFFFFF;
|
color: #FFFFFF;
|
||||||
width: 100%;
|
width: 100%;
|
||||||
|
|||||||
@@ -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({
|
Page({
|
||||||
data: {
|
data: {
|
||||||
loading: false,
|
loading: false,
|
||||||
@@ -13,8 +48,33 @@ Page({
|
|||||||
|
|
||||||
/* 微信一键登录 */
|
/* 微信一键登录 */
|
||||||
onLogin() {
|
onLogin() {
|
||||||
wx.navigateTo({
|
if (this.data.loading) return
|
||||||
url: '/pages/connectedDevice/connectedDevice'
|
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 })
|
||||||
|
},
|
||||||
|
})
|
||||||
|
},
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -5,5 +5,7 @@
|
|||||||
<view class="login">
|
<view class="login">
|
||||||
<view class="title">智能体重秤</view>
|
<view class="title">智能体重秤</view>
|
||||||
<view class="sub-title">设备智联 · 掌握健康</view>
|
<view class="sub-title">设备智联 · 掌握健康</view>
|
||||||
<view class="login-btn" bind:tap="onLogin">微信一键登录</view>
|
<view class="login-btn {{loading ? 'login-btn--disabled' : ''}}" bind:tap="onLogin">
|
||||||
|
{{loading ? '登录中...' : '微信一键登录'}}
|
||||||
|
</view>
|
||||||
</view>
|
</view>
|
||||||
@@ -2,8 +2,8 @@ import type { ApiResponse, HttpMethod, RequestOptions } from './types'
|
|||||||
|
|
||||||
export type { ApiResponse, RequestOptions }
|
export type { ApiResponse, RequestOptions }
|
||||||
|
|
||||||
const BASE_URL = 'http://192.168.1.31:8889' // 测试环境
|
const BASE_URL = 'http://192.168.1.31:8889/' // 测试环境
|
||||||
// const BASE_URL = 'https://device.shuziweidao.com/gateway' // 正式环境
|
// const BASE_URL = 'https://device.shuziweidao.com/gateway/' // 正式环境
|
||||||
|
|
||||||
let _loadingCount = 0
|
let _loadingCount = 0
|
||||||
|
|
||||||
|
|||||||
Vendored
+2
@@ -3,6 +3,8 @@
|
|||||||
interface IAppOption {
|
interface IAppOption {
|
||||||
globalData: {
|
globalData: {
|
||||||
userInfo?: WechatMiniprogram.UserInfo,
|
userInfo?: WechatMiniprogram.UserInfo,
|
||||||
|
/** 当前已连接设备的蓝牙状态 */
|
||||||
|
connectState: string,
|
||||||
}
|
}
|
||||||
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback,
|
userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback,
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user