refactor: 项目重构,仅保留 login 和 supplementPersonal 页面
删除 11 个旧页面、组件、lefu SDK、旧资源文件。 新增 request 封装(GET/POST/PUT)、api 层、utils/common 身份证工具。 重写 login(登录流程提取到 app.ts) 和 supplementPersonal(简化表单逻辑)。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 4.6
parent
439f560218
commit
83d909b95b
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"navigationBarTitleText": "设备管理",
|
||||
"usingComponents": {}
|
||||
}
|
||||
@@ -1,196 +0,0 @@
|
||||
/* 设备管理页 —— 已配对设备列表 + 添加设备主按钮 */
|
||||
.equipment {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
box-sizing: border-box;
|
||||
background-color: #F7F8FA;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
/* 副标题:已配对设备 */
|
||||
.section-title {
|
||||
color: #808080;
|
||||
height: 80rpx;
|
||||
font-size: 26rpx;
|
||||
padding: 0 30rpx;
|
||||
line-height: 80rpx;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* 卡片列表(scroll-view) */
|
||||
.device-list {
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
width: 100%;
|
||||
|
||||
.scroll-view-content {
|
||||
width: 100%;
|
||||
padding: 0 30rpx;
|
||||
box-sizing: border-box;
|
||||
|
||||
.device-card {
|
||||
background-color: #FFFFFF;
|
||||
border-radius: 16rpx;
|
||||
padding: 30rpx;
|
||||
box-sizing: border-box;
|
||||
margin-bottom: 24rpx;
|
||||
// margin: 0 30rpx 24rpx;
|
||||
|
||||
&:last-child {
|
||||
margin-bottom: 30rpx;
|
||||
}
|
||||
|
||||
/* 上半:图标 + 设备名 + 状态 */
|
||||
.card-top {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.card-icon {
|
||||
width: 90rpx;
|
||||
height: 90rpx;
|
||||
border-radius: 24rpx;
|
||||
margin-right: 24rpx;
|
||||
}
|
||||
|
||||
.card-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
justify-content: center;
|
||||
|
||||
.card-name {
|
||||
color: #252535;
|
||||
height: 32rpx;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
line-height: 32rpx;
|
||||
margin-bottom: 16rpx;
|
||||
}
|
||||
|
||||
.card-status {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
.card-dot {
|
||||
width: 12rpx;
|
||||
height: 12rpx;
|
||||
border-radius: 50%;
|
||||
margin-right: 14rpx;
|
||||
}
|
||||
|
||||
.card-dot-on {
|
||||
background-color: #2AC79F;
|
||||
}
|
||||
|
||||
.card-dot-off {
|
||||
background-color: #F24439;
|
||||
}
|
||||
|
||||
.card-status-text {
|
||||
height: 28rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: 500;
|
||||
line-height: 28rpx;
|
||||
}
|
||||
|
||||
.card-status-on {
|
||||
color: #2AC79F;
|
||||
}
|
||||
|
||||
.card-status-off {
|
||||
color: #F24439;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 分隔线 */
|
||||
.card-divider {
|
||||
width: 100%;
|
||||
height: 2rpx;
|
||||
background-color: #EAECF1;
|
||||
border-radius: 1rpx;
|
||||
margin: 30rpx 0 30rpx;
|
||||
}
|
||||
|
||||
/* 操作按钮区:单/双形态共用 */
|
||||
.card-actions {
|
||||
width: 100%;
|
||||
padding: 0 24rpx;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
|
||||
/* 单按钮:已连接态 */
|
||||
&.card-actions-single {
|
||||
|
||||
.btn-ghost-full {
|
||||
width: 100%;
|
||||
height: 82rpx;
|
||||
line-height: 78rpx;
|
||||
text-align: center;
|
||||
color: #77849E;
|
||||
font-size: 28rpx;
|
||||
background-color: #FFFFFF;
|
||||
border: 2rpx solid #E6E6EA;
|
||||
border-radius: 39rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
|
||||
/* 双按钮:未连接态 */
|
||||
&.card-actions-double {
|
||||
justify-content: space-between;
|
||||
|
||||
.btn-ghost-half {
|
||||
width: 280rpx;
|
||||
height: 82rpx;
|
||||
line-height: 78rpx;
|
||||
text-align: center;
|
||||
color: #77849E;
|
||||
font-size: 28rpx;
|
||||
background-color: #FFFFFF;
|
||||
border: 2rpx solid #E6E6EA;
|
||||
border-radius: 39rpx;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* 底部「添加设备」主按钮 */
|
||||
.add-btn {
|
||||
width: 580rpx;
|
||||
height: 88rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background-color: #1385FA;
|
||||
border-radius: 44rpx;
|
||||
margin: 20rpx auto;
|
||||
flex-shrink: 0;
|
||||
|
||||
.add-btn-icon {
|
||||
color: #FFFFFF;
|
||||
width: 32rpx;
|
||||
font-size: 28rpx;
|
||||
font-weight: bold;
|
||||
height: 32rpx;
|
||||
line-height: 30rpx;
|
||||
border-radius: 50%;
|
||||
text-align: center;
|
||||
margin-right: 15rpx;
|
||||
border: 2rpx solid #ffffff;
|
||||
}
|
||||
|
||||
.add-btn-text {
|
||||
color: #FFFFFF;
|
||||
font-size: 32rpx;
|
||||
font-weight: bold;
|
||||
line-height: 32rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,199 +0,0 @@
|
||||
import { get } from '../../utils/request/index'
|
||||
import { lefuService } from '../../lefu/index'
|
||||
import type { RawDevice } from '../../lefu/types'
|
||||
|
||||
/** 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
|
||||
/** 设备连接信息 JSON 字符串,与登录接口返回格式一致 */
|
||||
connectDeviceInfo: string
|
||||
}
|
||||
|
||||
/** 展示用设备项 */
|
||||
interface DeviceItem {
|
||||
id: string
|
||||
scaleDeviceId: string
|
||||
scaleDeviceName: string
|
||||
connectDeviceInfo: string
|
||||
realname: string
|
||||
/** 蓝牙连接状态,接口不返回,由业务层更新 */
|
||||
connected: boolean
|
||||
userId: string
|
||||
sex: number
|
||||
height: number
|
||||
birthday: string
|
||||
avatar: string | null
|
||||
relationType: string | null
|
||||
sex_dictText: string
|
||||
}
|
||||
|
||||
Page({
|
||||
data: {
|
||||
loading: false,
|
||||
deviceList: [] as DeviceItem[],
|
||||
},
|
||||
|
||||
onShow() {
|
||||
this.loadData()
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
lefuService.stopScan()
|
||||
lefuService.onDeviceConnect(() => {})
|
||||
lefuService.onDeviceInfo(() => {})
|
||||
lefuService.onDisconnected(() => {})
|
||||
},
|
||||
|
||||
/** 拉取已绑定设备列表,加载完成后检查缓存自动连接 */
|
||||
loadData() {
|
||||
this.setData({ loading: true })
|
||||
const userInfo = wx.getStorageSync('userInfo')
|
||||
get<DeviceRecord[]>('weighingScale/v3/list/device', { userId: userInfo?.userId })
|
||||
.then(res => {
|
||||
const list: DeviceItem[] = res.result.map(item => {
|
||||
let scaleDeviceName = ''
|
||||
try {
|
||||
const info = JSON.parse(item.connectDeviceInfo || '{}')
|
||||
scaleDeviceName = info.name ?? ''
|
||||
} catch {}
|
||||
return {
|
||||
id: item.id,
|
||||
scaleDeviceId: item.scaleDeviceId,
|
||||
scaleDeviceName,
|
||||
connectDeviceInfo: item.connectDeviceInfo ?? '',
|
||||
realname: item.realname,
|
||||
connected: false,
|
||||
userId: item.userId,
|
||||
sex: item.sex,
|
||||
height: item.height,
|
||||
birthday: item.birthday,
|
||||
avatar: item.avatar,
|
||||
relationType: item.relationType,
|
||||
sex_dictText: item.sex_dictText,
|
||||
}
|
||||
})
|
||||
this.setData({ deviceList: list }, () => {
|
||||
this._checkAndAutoConnect()
|
||||
})
|
||||
})
|
||||
.finally(() => {
|
||||
this.setData({ loading: false })
|
||||
})
|
||||
},
|
||||
|
||||
/** 每次进入页面都走真实扫描连接,确保状态最新 */
|
||||
_checkAndAutoConnect() {
|
||||
lefuService.onDeviceInfo((info) => {
|
||||
this._markConnected(info.serialNumber as string)
|
||||
})
|
||||
lefuService.onDisconnected(() => {
|
||||
this._markAllDisconnected()
|
||||
})
|
||||
lefuService.autoConnect()
|
||||
},
|
||||
|
||||
/** 将 serialNumber 对应的列表项标记为已连接,其余置为未连接 */
|
||||
_markConnected(serialNumber: string) {
|
||||
const list = this.data.deviceList.map(item => ({
|
||||
...item,
|
||||
connected: item.scaleDeviceId === serialNumber,
|
||||
}))
|
||||
this.setData({ deviceList: list })
|
||||
},
|
||||
|
||||
/** 将所有设备标记为未连接 */
|
||||
_markAllDisconnected() {
|
||||
const list = this.data.deviceList.map(item => ({ ...item, connected: false }))
|
||||
this.setData({ deviceList: list })
|
||||
},
|
||||
|
||||
/** 点击「连接」:扫描周边设备,找到 deviceId 匹配的设备后连接 */
|
||||
onTapConnect(e: WechatMiniprogram.TouchEvent) {
|
||||
const userInfo = e.currentTarget.dataset.userInfo as DeviceItem
|
||||
const connectDeviceInfoStr = e.currentTarget.dataset.connectDeviceInfo as string
|
||||
let cachedDevice: RawDevice | null = null
|
||||
try {
|
||||
cachedDevice = JSON.parse(connectDeviceInfoStr || '{}')
|
||||
} catch {}
|
||||
const targetDeviceId = cachedDevice?.deviceId as string | undefined
|
||||
if (!targetDeviceId) return
|
||||
|
||||
if (lefuService.isConnected) lefuService.disconnect()
|
||||
this.setData({ deviceList: this.data.deviceList.map(item => ({ ...item, connected: false })) })
|
||||
|
||||
let scanTimer: number | null = null
|
||||
|
||||
wx.showLoading({ title: '扫描中...', mask: true })
|
||||
wx.openBluetoothAdapter({
|
||||
success: () => {
|
||||
scanTimer = setTimeout(() => {
|
||||
lefuService.stopScan()
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '未找到设备', icon: 'none' })
|
||||
}, 15000)
|
||||
|
||||
lefuService.onDevicesList((devices) => {
|
||||
const matched = devices.find(d => d.raw.deviceId === targetDeviceId)
|
||||
if (!matched) return
|
||||
if (scanTimer !== null) { clearTimeout(scanTimer); scanTimer = null }
|
||||
lefuService.stopScan()
|
||||
wx.showLoading({ title: '连接中...', mask: true })
|
||||
lefuService.connect(matched.raw)
|
||||
lefuService.onDeviceConnect(() => {
|
||||
wx.hideLoading()
|
||||
wx.setStorageSync('connectDeviceInfo', matched.raw)
|
||||
// 连接成功后缓存当前设备关联的用户信息
|
||||
if (userInfo) {
|
||||
wx.setStorageSync('userInfo', userInfo)
|
||||
}
|
||||
})
|
||||
lefuService.onDeviceInfo((info) => {
|
||||
this._markConnected(info.serialNumber as string)
|
||||
})
|
||||
})
|
||||
lefuService.startScan()
|
||||
},
|
||||
fail: () => {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: '蓝牙未开启', icon: 'none' })
|
||||
},
|
||||
})
|
||||
},
|
||||
|
||||
/* 点击「用户管理」→ 跳转用户管理页,sn 由目标页从缓存读取 */
|
||||
onTapMember() {
|
||||
wx.navigateTo({ url: '/pages/equipmentMember/equipmentMember' })
|
||||
},
|
||||
|
||||
/* 点击「添加设备」→ 跳转设备搜索页 */
|
||||
onTapAdd() {
|
||||
wx.navigateTo({ url: '/pages/connectedDevice/connectedDevice' })
|
||||
},
|
||||
})
|
||||
@@ -1,61 +0,0 @@
|
||||
<view class="equipment">
|
||||
|
||||
<!-- 副标题:已配对设备 -->
|
||||
<view class="section-title">已配对设备</view>
|
||||
|
||||
<!-- 设备卡片列表 -->
|
||||
<view class="device-list">
|
||||
<scroll-view class="scrollView" scroll-y>
|
||||
<view class="scroll-view-content">
|
||||
<block wx:for="{{ deviceList }}" wx:key="id">
|
||||
<view class="device-card">
|
||||
|
||||
<!-- 上半:图标 + 设备信息 + 状态(色点 + 文字) -->
|
||||
<view class="card-top">
|
||||
<image class="card-icon" src="/images/device/{{ item.scaleDeviceName }}.png" mode="aspectFit"></image>
|
||||
<view class="card-info">
|
||||
<view class="card-name">{{ item.scaleDeviceName }}</view>
|
||||
<view class="card-status">
|
||||
<!-- 已连接:绿点 + "已连接" -->
|
||||
<block wx:if="{{ item.connected }}">
|
||||
<view class="card-dot card-dot-on"></view>
|
||||
<text class="card-status-text card-status-on">已连接</text>
|
||||
</block>
|
||||
<!-- 未连接:红点 + "未连接" -->
|
||||
<block wx:else>
|
||||
<view class="card-dot card-dot-off"></view>
|
||||
<text class="card-status-text card-status-off">未连接</text>
|
||||
</block>
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 分隔线 -->
|
||||
<view class="card-divider"></view>
|
||||
|
||||
<!-- 下半:操作按钮(单/双形态) -->
|
||||
<block wx:if="{{ item.connected }}">
|
||||
<!-- 已连接:单按钮居中 -->
|
||||
<view class="card-actions card-actions-single">
|
||||
<view class="btn-ghost-full" bind:tap="onTapMember">用户管理</view>
|
||||
</view>
|
||||
</block>
|
||||
<block wx:else>
|
||||
<!-- 未连接:双按钮 连接 / 用户管理 -->
|
||||
<view class="card-actions card-actions-single">
|
||||
<view class="btn-ghost-full" data-connect-device-info="{{ item.connectDeviceInfo }}" data-user-info="{{ item }}" bind:tap="onTapConnect">连接</view>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</block>
|
||||
</view>
|
||||
</scroll-view>
|
||||
</view>
|
||||
|
||||
<!-- 底部「添加设备」主按钮 -->
|
||||
<view class="add-btn" bind:tap="onTapAdd">
|
||||
<view class="add-btn-icon">+</view>
|
||||
<text class="add-btn-text">添加设备</text>
|
||||
</view>
|
||||
|
||||
</view>
|
||||
Reference in New Issue
Block a user