feat(equipment): 设备列表升级 v6 接口并接入取消配对

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
17792275749
2026-08-25 13:51:15 +08:00
co-authored by Claude Opus 4.7
parent 5572c2212a
commit 2e07a7fcee
4 changed files with 48 additions and 11 deletions
+37 -9
View File
@@ -1,4 +1,4 @@
import { get } from '../../utils/request/index' import { get, del } from '../../utils/request/index'
import { leFuService } from '../../lefu/index' import { leFuService } from '../../lefu/index'
import type { UserInfo } from '../../api/index' import type { UserInfo } from '../../api/index'
@@ -17,8 +17,12 @@ interface ScaleDevice {
} }
/** 获取体重设备列表 */ /** 获取体重设备列表 */
const getDeviceList = (userId: string) => const getDeviceList = () =>
get<ScaleDevice[]>('weighingScale/v3/list/device', { userId }) get<ScaleDevice[]>('weighingScale/v6/list/device')
/** 取消配对:id 不传则解除所有设备绑定 */
const unbindDevice = (id?: string) =>
del(`weighingScale/v6/unbind${id ? `?id=${id}` : ''}`, {}, { loading: false })
/** 展示用设备项 */ /** 展示用设备项 */
interface DeviceItem { interface DeviceItem {
@@ -81,7 +85,7 @@ Page({
const raw = wx.getStorageSync('userInfo') as UserInfo | null const raw = wx.getStorageSync('userInfo') as UserInfo | null
if (!raw?.userId) return if (!raw?.userId) return
try { try {
const res = await getDeviceList(raw.userId) const res = await getDeviceList()
this.setData({ this.setData({
devices: res.result.map(item => { devices: res.result.map(item => {
let info: Record<string, any> = {} let info: Record<string, any> = {}
@@ -104,14 +108,28 @@ Page({
} }
}, },
/** 取消配对:使用小程序自带 showModal */ /** 取消配对:解除指定设备绑定 */
onTapUnpair() { onTapUnpair(e: WechatMiniprogram.TouchEvent) {
const item = e.currentTarget.dataset.item as DeviceItem
wx.showModal({ wx.showModal({
title: '取消配对', title: '取消配对',
content: '是否确认取消配对当前设备?', content: '是否确认取消配对当前设备?',
cancelText: '取消', cancelText: '取消',
confirmText: '确定', confirmText: '确定',
confirmColor: '#F24439' confirmColor: '#F24439',
success: (res) => {
if (!res.confirm) return
unbindDevice(item.id)
.then(() => {
const cached = wx.getStorageSync('connectDeviceInfo') as Record<string, any> | null
if (cached?.deviceId === item.deviceId) {
wx.removeStorageSync('connectDeviceInfo')
}
wx.showToast({ title: '已取消配对', icon: 'success' })
this.loadDevices()
})
.catch(() => {})
},
}) })
}, },
@@ -227,14 +245,24 @@ Page({
// 关闭运维模式(待接入) // 关闭运维模式(待接入)
}, },
/** 取消全部配对 */ /** 取消全部配对:解除所有设备绑定 */
onUnpairAll() { onUnpairAll() {
wx.showModal({ wx.showModal({
title: '取消全部配对', title: '取消全部配对',
content: '是否确认取消全部设备的配对?', content: '是否确认取消全部设备的配对?',
cancelText: '取消', cancelText: '取消',
confirmText: '确定', confirmText: '确定',
confirmColor: '#F24439' confirmColor: '#F24439',
success: (res) => {
if (!res.confirm) return
unbindDevice()
.then(() => {
wx.removeStorageSync('connectDeviceInfo')
wx.showToast({ title: '已取消全部配对', icon: 'success' })
this.loadDevices()
})
.catch(() => {})
},
}) })
} }
}) })
+1 -1
View File
@@ -39,7 +39,7 @@
<view class="device-info"> <view class="device-info">
<view class="device-info_"> <view class="device-info_">
<view class="device-name">{{ item.name }}</view> <view class="device-name">{{ item.name }}</view>
<view class="device-unpair" bind:tap="onTapUnpair">取消配对</view> <view class="device-unpair" bind:tap="onTapUnpair" data-item="{{ item }}">取消配对</view>
</view> </view>
<view class="device-status" bind:tap="onTapStatus" data-item="{{ item }}"> <view class="device-status" bind:tap="onTapStatus" data-item="{{ item }}">
<view class="device-status_ {{item.status ? 'connected' : ''}}"> <view class="device-status_ {{item.status ? 'connected' : ''}}">
+9
View File
@@ -74,3 +74,12 @@ export const put = <T = any>(
data?: Record<string, any>, data?: Record<string, any>,
options?: RequestOptions, options?: RequestOptions,
): Promise<ApiResponse<T>> => request<T>(url, data, 'PUT', options) ): Promise<ApiResponse<T>> => request<T>(url, data, 'PUT', options)
export const del = <T = any>(
url: string,
data?: Record<string, any>,
options?: RequestOptions,
): Promise<ApiResponse<T>> => request<T>(url, data, 'DELETE', {
contentType: 'application/x-www-form-urlencoded',
...options,
})
+1 -1
View File
@@ -6,7 +6,7 @@ export interface ApiResponse<T = any> {
result: T result: T
} }
export type HttpMethod = 'GET' | 'POST' | 'PUT' export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'
export interface RequestOptions { export interface RequestOptions {
loading?: boolean loading?: boolean