From 54fc0daf5a7d0652b87859c29a3c1c9ec624be54 Mon Sep 17 00:00:00 2001 From: 17792275749 <812100002@qq.com> Date: Thu, 14 May 2026 11:56:43 +0800 Subject: [PATCH] =?UTF-8?q?[AI=20Generated]:=20feat(*):=20=E6=96=B0?= =?UTF-8?q?=E5=A2=9E=20OpenID=20=E7=99=BB=E5=BD=95=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=E5=8F=8A=E5=90=AF=E5=8A=A8=E8=87=AA=E5=8A=A8=E8=B7=B3=E8=BD=AC?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- miniprogram/app.json | 4 +- miniprogram/app.ts | 10 ++ miniprogram/pages/equipment/equipment.ts | 113 +++++++++++++++------ miniprogram/pages/equipment/equipment.wxml | 5 +- miniprogram/pages/login/login.less | 4 + miniprogram/pages/login/login.ts | 66 +++++++++++- miniprogram/pages/login/login.wxml | 4 +- miniprogram/utils/request/index.ts | 4 +- typings/index.d.ts | 2 + 9 files changed, 173 insertions(+), 39 deletions(-) diff --git a/miniprogram/app.json b/miniprogram/app.json index db068c6..f54cf00 100644 --- a/miniprogram/app.json +++ b/miniprogram/app.json @@ -1,12 +1,12 @@ { "pages": [ - "pages/addMember/addMember", - "pages/home/home", "pages/login/login", + "pages/home/home", "pages/connectedDevice/connectedDevice", "pages/connectedWifi/connectedWifi", "pages/supplementPersonal/supplementPersonal", "pages/equipmentMember/equipmentMember", + "pages/addMember/addMember", "pages/equipment/equipment", "pages/measurementReport/measurementReport", "pages/data/data", diff --git a/miniprogram/app.ts b/miniprogram/app.ts index b18f25b..d03b92f 100644 --- a/miniprogram/app.ts +++ b/miniprogram/app.ts @@ -9,5 +9,15 @@ App({ onLaunch() { // 初始化乐福蓝牙 SDK 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' + }) + } }, }) diff --git a/miniprogram/pages/equipment/equipment.ts b/miniprogram/pages/equipment/equipment.ts index d956c5e..2076916 100644 --- a/miniprogram/pages/equipment/equipment.ts +++ b/miniprogram/pages/equipment/equipment.ts @@ -1,38 +1,93 @@ -/** 已配对设备模型 */ +import { get } from '../../utils/request/index' + +/** API 返回的设备记录 */ +interface DeviceRecord { + id: string + userId: 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 */ - id: string - /** 设备名称 */ - name: string - /** 是否已连接 */ - connected: boolean + id: string + scaleDeviceId: string + realname: string + /** 蓝牙连接状态,接口不返回,由业务层更新 */ + connected: boolean } Page({ - data: { - /* 已配对设备 mock 列表(后续接入真实接口时替换) */ - deviceList: [ - { id: 'd1', name: '智能体重秤 Pro', connected: true }, - { id: 'd2', name: '体重秤 Basic', connected: false }, - ] as DeviceItem[], - }, + data: { + loading: false, + deviceList: [] as DeviceItem[], + }, - onLoad() { - /* 页面进入时无副作用,设备列表后续接入真实接口 */ - }, + onLoad() { + this.loadData() + }, - /* 点击「连接」:未连接卡片才会出现 —— 暂留空,待跳转逻辑接入 */ - onTapConnect() { - // TODO: 跳转设备搜索/绑定流程 - }, + /** 拉取已绑定设备列表 */ + loadData() { + this.setData({ loading: true }) + get('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 }) + }) + }, - /* 点击「成员管理」:暂留空,待成员管理页接入 */ - onTapMember() { - // TODO: 跳转成员管理页 - }, + /* 点击「连接」→ 跳转设备搜索页 */ + onTapConnect() { + wx.navigateTo({ + url: '/pages/connectedDevice/connectedDevice' + }) + }, - /* 点击「添加设备」:暂留空,待跳转逻辑接入 */ - onTapAdd() { - // TODO: 跳转设备搜索页 - }, + /* 点击「成员管理」→ 跳转成员管理页 */ + onTapMember(e: WechatMiniprogram.TouchEvent) { + const id = e.currentTarget.dataset.id as string + wx.navigateTo({ + url: `/pages/equipmentMember/equipmentMember?id=${id}` + }) + }, + + /* 点击「添加设备」→ 跳转设备搜索页 */ + onTapAdd() { + wx.navigateTo({ + url: '/pages/connectedDevice/connectedDevice' + }) + }, }) diff --git a/miniprogram/pages/equipment/equipment.wxml b/miniprogram/pages/equipment/equipment.wxml index 9c42bb2..152da66 100644 --- a/miniprogram/pages/equipment/equipment.wxml +++ b/miniprogram/pages/equipment/equipment.wxml @@ -8,11 +8,12 @@ - + - {{ item.name }} + {{ item.scaleDeviceId }} + {{ item.realname }} diff --git a/miniprogram/pages/login/login.less b/miniprogram/pages/login/login.less index e052302..ecb22e8 100644 --- a/miniprogram/pages/login/login.less +++ b/miniprogram/pages/login/login.less @@ -40,6 +40,10 @@ text-align: center; } + .login-btn--disabled { + opacity: 0.6; + } + .login-btn { color: #FFFFFF; width: 100%; diff --git a/miniprogram/pages/login/login.ts b/miniprogram/pages/login/login.ts index 5d94cc5..f414167 100644 --- a/miniprogram/pages/login/login.ts +++ b/miniprogram/pages/login/login.ts @@ -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('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 }) + }, }) - } + }, }) diff --git a/miniprogram/pages/login/login.wxml b/miniprogram/pages/login/login.wxml index 652a664..f0b617d 100644 --- a/miniprogram/pages/login/login.wxml +++ b/miniprogram/pages/login/login.wxml @@ -5,5 +5,7 @@ \ No newline at end of file diff --git a/miniprogram/utils/request/index.ts b/miniprogram/utils/request/index.ts index 92b1445..3c02c6f 100644 --- a/miniprogram/utils/request/index.ts +++ b/miniprogram/utils/request/index.ts @@ -2,8 +2,8 @@ import type { ApiResponse, HttpMethod, RequestOptions } from './types' export type { ApiResponse, RequestOptions } -const BASE_URL = 'http://192.168.1.31:8889' // 测试环境 -// const BASE_URL = 'https://device.shuziweidao.com/gateway' // 正式环境 +const BASE_URL = 'http://192.168.1.31:8889/' // 测试环境 +// const BASE_URL = 'https://device.shuziweidao.com/gateway/' // 正式环境 let _loadingCount = 0 diff --git a/typings/index.d.ts b/typings/index.d.ts index 3ee60c8..b4002d8 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3,6 +3,8 @@ interface IAppOption { globalData: { userInfo?: WechatMiniprogram.UserInfo, + /** 当前已连接设备的蓝牙状态 */ + connectState: string, } userInfoReadyCallback?: WechatMiniprogram.GetUserInfoSuccessCallback, } \ No newline at end of file