feat(equipment): 设备列表升级 v6 接口并接入取消配对
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.7
parent
5572c2212a
commit
2e07a7fcee
@@ -1,4 +1,4 @@
|
||||
import { get } from '../../utils/request/index'
|
||||
import { get, del } from '../../utils/request/index'
|
||||
import { leFuService } from '../../lefu/index'
|
||||
import type { UserInfo } from '../../api/index'
|
||||
|
||||
@@ -17,8 +17,12 @@ interface ScaleDevice {
|
||||
}
|
||||
|
||||
/** 获取体重设备列表 */
|
||||
const getDeviceList = (userId: string) =>
|
||||
get<ScaleDevice[]>('weighingScale/v3/list/device', { userId })
|
||||
const getDeviceList = () =>
|
||||
get<ScaleDevice[]>('weighingScale/v6/list/device')
|
||||
|
||||
/** 取消配对:id 不传则解除所有设备绑定 */
|
||||
const unbindDevice = (id?: string) =>
|
||||
del(`weighingScale/v6/unbind${id ? `?id=${id}` : ''}`, {}, { loading: false })
|
||||
|
||||
/** 展示用设备项 */
|
||||
interface DeviceItem {
|
||||
@@ -81,7 +85,7 @@ Page({
|
||||
const raw = wx.getStorageSync('userInfo') as UserInfo | null
|
||||
if (!raw?.userId) return
|
||||
try {
|
||||
const res = await getDeviceList(raw.userId)
|
||||
const res = await getDeviceList()
|
||||
this.setData({
|
||||
devices: res.result.map(item => {
|
||||
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({
|
||||
title: '取消配对',
|
||||
content: '是否确认取消配对当前设备?',
|
||||
cancelText: '取消',
|
||||
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() {
|
||||
wx.showModal({
|
||||
title: '取消全部配对',
|
||||
content: '是否确认取消全部设备的配对?',
|
||||
cancelText: '取消',
|
||||
confirmText: '确定',
|
||||
confirmColor: '#F24439'
|
||||
confirmColor: '#F24439',
|
||||
success: (res) => {
|
||||
if (!res.confirm) return
|
||||
unbindDevice()
|
||||
.then(() => {
|
||||
wx.removeStorageSync('connectDeviceInfo')
|
||||
wx.showToast({ title: '已取消全部配对', icon: 'success' })
|
||||
this.loadDevices()
|
||||
})
|
||||
.catch(() => {})
|
||||
},
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
@@ -39,7 +39,7 @@
|
||||
<view class="device-info">
|
||||
<view class="device-info_">
|
||||
<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 class="device-status" bind:tap="onTapStatus" data-item="{{ item }}">
|
||||
<view class="device-status_ {{item.status ? 'connected' : ''}}">
|
||||
|
||||
@@ -74,3 +74,12 @@ export const put = <T = any>(
|
||||
data?: Record<string, any>,
|
||||
options?: RequestOptions,
|
||||
): 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,
|
||||
})
|
||||
|
||||
@@ -6,7 +6,7 @@ export interface ApiResponse<T = any> {
|
||||
result: T
|
||||
}
|
||||
|
||||
export type HttpMethod = 'GET' | 'POST' | 'PUT'
|
||||
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE'
|
||||
|
||||
export interface RequestOptions {
|
||||
loading?: boolean
|
||||
|
||||
Reference in New Issue
Block a user