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:
17792275749
2026-08-10 14:21:00 +08:00
co-authored by Claude Sonnet 4.6
parent 439f560218
commit 83d909b95b
96 changed files with 370 additions and 9040 deletions
@@ -1,4 +0,0 @@
{
"navigationBarTitleText": "搜索设备",
"usingComponents": {}
}
@@ -1,285 +0,0 @@
/* 连接设备页 —— 三态(idle / searching / found / empty)共用 */
.connected-device {
width: 100%;
height: 100%;
padding: 48rpx 30rpx 0;
box-sizing: border-box;
background-color: #ffffff;
/* 三层同心圆波纹动画 */
.ripple {
position: relative;
width: 300rpx;
height: 300rpx;
margin: 0 auto 48rpx;
display: flex;
align-items: center;
justify-content: center;
/* 波纹圆环:默认隐藏,仅在 .ripple--active 时播放动画 */
.ripple-ring {
position: absolute;
width: 300rpx;
height: 300rpx;
border-radius: 50%;
background-color: #1385FA;
opacity: 0;
}
&.ripple--active {
.ripple-ring {
animation: ripple-expand 2.4s ease-out infinite;
}
.ripple-ring--delay1 {
animation-delay: 0.8s;
}
.ripple-ring--delay2 {
animation-delay: 1.6s;
}
}
/* 中心实心圆 + 图标 */
.ripple-core {
position: relative;
z-index: 1;
width: 140rpx;
height: 140rpx;
padding: 30rpx;
box-sizing: border-box;
border-radius: 50%;
background-color: #1385FA;
display: flex;
align-items: center;
justify-content: center;
image {
width: 80rpx;
height: 80rpx;
}
}
}
@keyframes ripple-expand {
0% {
transform: scale(0.46);
opacity: 1;
}
100% {
transform: scale(1);
opacity: 0;
}
}
.title {
color: #252535;
width: 100%;
height: 36rpx;
font-size: 36rpx;
font-weight: bold;
line-height: 36rpx;
text-align: center;
margin-bottom: 22rpx;
}
.sub-title {
color: #808080;
width: 100%;
height: 30rpx;
font-size: 30rpx;
text-align: center;
line-height: 30rpx;
margin-bottom: 40rpx;
}
.search-btn {
color: #FFFFFF;
width: 580rpx;
height: 88rpx;
font-size: 32rpx;
font-weight: bold;
text-align: center;
line-height: 88rpx;
border-radius: 44rpx;
margin: 0 auto 32rpx;
background-color: #1385FA;
}
// .help {
// width: 100%;
// height: 30rpx;
// text-align: center;
// line-height: 30rpx;
// margin-bottom: 60rpx;
// .help-text {
// color: #808080;
// font-size: 30rpx;
// line-height: 30rpx;
// margin-right: 8rpx;
// }
// .help-link {
// color: #1385FA;
// font-size: 30rpx;
// line-height: 30rpx;
// }
// }
.search-device {
width: 100%;
.search-device-header {
width: 100%;
height: 32rpx;
display: flex;
flex-wrap: nowrap;
justify-content: space-between;
margin-bottom: 38rpx;
.search-device-title {
color: #252535;
height: 32rpx;
font-size: 32rpx;
font-weight: bold;
line-height: 32rpx;
}
.search-device-count {
height: 32rpx;
display: flex;
flex-wrap: nowrap;
.count-text {
color: #808080;
height: 32rpx;
font-size: 28rpx;
line-height: 32rpx;
}
.count-num {
color: #1385FA;
height: 32rpx;
font-size: 28rpx;
font-weight: bold;
line-height: 32rpx;
padding: 0 6rpx;
}
}
}
.empty {
width: 100%;
display: flex;
flex-direction: column;
align-items: center;
margin-top: 160rpx;
.empty-image {
width: 193rpx;
height: 138rpx;
margin-bottom: 40rpx;
background-color: #F5F5F5;
}
.empty-text {
color: #808080;
width: 100%;
height: 30rpx;
font-size: 30rpx;
line-height: 30rpx;
text-align: center;
}
}
.device-list {
width: 100%;
display: flex;
flex-direction: column;
.device-card {
width: 100%;
height: 150rpx;
display: flex;
align-items: center;
padding: 0 30rpx;
background-color: #FFFFFF;
border: 2rpx solid #E6E6EA;
border-radius: 16rpx;
box-sizing: border-box;
margin-bottom: 24rpx;
.card-icon {
width: 90rpx;
height: 90rpx;
overflow: hidden;
border-radius: 24rpx;
margin-right: 24rpx;
}
.card-info {
flex: 1;
display: flex;
flex-direction: column;
justify-content: center;
.card-name {
color: #252535;
font-size: 32rpx;
font-weight: bold;
height: 32rpx;
line-height: 32rpx;
}
.card-status {
margin-top: 18rpx;
display: flex;
align-items: center;
.card-dot {
width: 12rpx;
height: 12rpx;
border-radius: 50%;
background-color: #2AC79F;
margin-right: 15rpx;
}
.card-status-text {
color: #2AC79F;
height: 28rpx;
font-size: 28rpx;
font-weight: 500;
line-height: 28rpx;
}
}
}
.card-btn-primary {
color: #FFFFFF;
font-size: 24rpx;
font-weight: 500;
width: 88rpx;
height: 48rpx;
line-height: 48rpx;
text-align: center;
border-radius: 8rpx;
background-color: #2AC79F;
}
.card-btn-danger {
color: #F24439;
font-size: 24rpx;
font-weight: 500;
width: 120rpx;
height: 48rpx;
line-height: 44rpx;
text-align: center;
border: 2rpx solid #F24439;
border-radius: 8rpx;
box-sizing: border-box;
}
}
}
}
}
@@ -1,264 +0,0 @@
import { lefuService } from '../../lefu/index'
import type { ScannedDevice } from '../../lefu/index'
import type { RawDevice } from '../../lefu/types'
/** 展示用设备项(仅存入 setData,不含复杂对象) */
interface DeviceItem {
name: string
connected: boolean
}
/** 页面状态 */
type DeviceStatus = 'idle' | 'searching' | 'found' | 'empty'
/** 页面级原始设备缓存,不进入 setData 避免序列化异常 */
let _rawDevices: ScannedDevice[] = []
const TAG = '[connectedDevice]'
Page({
data: {
status: 'idle' as DeviceStatus,
deviceList: [] as DeviceItem[],
/** 防止权限弹框重入 */
_modalLock: false,
/** 自动连接缓存设备的一次性标记,防止扫描回调反复触发 */
_autoConnectTried: false,
},
onShow() {
console.log(TAG, 'onShow')
// 回到页面时同步实际连接状态,避免回调被其他页面覆盖导致状态不同步
if (!lefuService.isConnected) {
const list = this.data.deviceList.map(item => ({ ...item, connected: false }))
this.setData({ deviceList: list })
}
},
onHide() {
console.log(TAG, 'onHide, 停止扫描')
// _rawDevices = []
// this.setData({ status: 'idle', deviceList: [] })
lefuService.stopScan()
},
onUnload() {
console.log(TAG, 'onUnload, 停止扫描')
lefuService.stopScan()
},
/** 点击「开始搜索 / 重新搜索」按钮:先验权限,再扫描 */
async onStartSearch() {
console.log(TAG, 'onStartSearch, _modalLock:', this.data._modalLock)
if (this.data._modalLock) return
_rawDevices = []
this.setData({ status: 'searching', deviceList: [], _autoConnectTried: false })
await this._checkPermissionAndScan()
},
/** 检查蓝牙 + 位置权限,通过后开始扫描 */
async _checkPermissionAndScan() {
console.log(TAG, '_checkPermissionAndScan 开始')
try {
const { authSetting } = await wx.getSetting()
const setting = authSetting as Record<string, boolean | undefined>
const hasBle = setting['scope.bluetooth']
const hasLoc = setting['scope.userLocation']
console.log(TAG, '权限状态 → 蓝牙:', hasBle, '位置:', hasLoc)
if (hasBle && hasLoc) {
await this._openAdapterAndScan()
return
}
// 逐个申请缺失权限
const missing: Array<{ scope: string; label: string }> = []
if (!hasBle) missing.push({ scope: 'scope.bluetooth', label: '蓝牙' })
if (!hasLoc) missing.push({ scope: 'scope.userLocation', label: '位置' })
console.log(TAG, '缺失权限:', missing.map(m => m.label))
try {
for (const item of missing) {
console.log(TAG, '申请权限:', item.scope)
await wx.authorize({ scope: item.scope })
console.log(TAG, '权限申请成功:', item.scope)
}
await this._openAdapterAndScan()
} catch (err) {
console.warn(TAG, '权限申请被拒绝:', err)
this._showPermissionModal(missing.map(m => m.label).join('和'))
}
} catch (err) {
console.error(TAG, 'getSetting 失败:', err)
wx.showToast({ title: '获取权限设置失败', icon: 'none' })
this.setData({ status: 'idle' })
}
},
/** 引导用户去设置页开启权限 */
_showPermissionModal(permissionNames: string) {
console.log(TAG, '弹出权限引导框, 缺失:', permissionNames)
this.setData({ _modalLock: true })
wx.showModal({
title: '需要授权',
content: `小程序需要您的${permissionNames}权限才能搜索蓝牙设备,请前往手机设置开启。`,
confirmText: '去开启',
cancelText: '取消',
success: (res) => {
console.log(TAG, '权限弹框结果:', res.confirm ? '去开启' : '取消')
this.setData({ _modalLock: false, status: 'idle' })
if (res.confirm) {
wx.openSetting({
success: () => this.onStartSearch(),
})
}
},
fail: () => {
this.setData({ _modalLock: false, status: 'idle' })
},
})
},
/** 打开蓝牙适配器,成功后启动扫描 */
async _openAdapterAndScan() {
console.log(TAG, 'wx.openBluetoothAdapter() 开始')
try {
await wx.openBluetoothAdapter()
console.log(TAG, 'wx.openBluetoothAdapter() 成功')
this._startScan()
} catch (err: any) {
console.error(TAG, 'wx.openBluetoothAdapter() 失败, errCode:', err?.errCode, err?.errMsg)
if (err?.errCode === 10001) {
wx.showModal({
title: '蓝牙未开启',
content: '请先开启手机蓝牙后重试',
showCancel: false,
confirmText: '知道了',
success: () => this.setData({ status: 'idle' }),
})
} else {
wx.showToast({ title: '蓝牙初始化失败', icon: 'none' })
this.setData({ status: 'idle' })
}
}
},
/** 权限已就绪,注册设备列表回调并启动扫描 */
_startScan() {
console.log(TAG, '_startScan 启动')
lefuService.onDevicesList((devices) => {
console.log(TAG, 'onDevicesList 回调, 设备数:', devices.length, devices.map(d => d.name))
if (!devices.length) {
_rawDevices = []
this.setData({ status: 'empty', deviceList: [] })
return
}
_rawDevices = devices
// 保留已连接设备的状态,避免扫描刷新时把 connected 重置为 false
const connectedName = this.data.deviceList.find(d => d.connected)?.name
const list: DeviceItem[] = devices.map(d => ({
name: d.name,
connected: d.name === connectedName,
}))
this.setData({ status: 'found', deviceList: list })
// 缓存设备命中:自动连接一次
if (this.data._autoConnectTried) return
const cached = wx.getStorageSync('connectDeviceInfo') as RawDevice | null
const cachedDeviceId = cached?.deviceId
if (!cachedDeviceId) return
const matchedIndex = devices.findIndex(d => d.raw.deviceId === cachedDeviceId)
if (matchedIndex < 0) return
console.log(TAG, '命中缓存设备, deviceId:', cachedDeviceId, 'index:', matchedIndex)
this.setData({ _autoConnectTried: true })
this._autoConnectByIndex(matchedIndex)
})
lefuService.onDisconnected(() => {
const list = this.data.deviceList.map(item => ({ ...item, connected: false }))
this.setData({ deviceList: list })
})
lefuService.startScan()
console.log(TAG, 'lefuService.startScan() 已调用')
},
/** 缓存设备自动连接(与 onConnect 共享连接流程) */
_autoConnectByIndex(index: number) {
const raw = _rawDevices[index]
if (!raw) return
wx.showLoading({ title: '连接中...', mask: true })
lefuService.stopScan()
lefuService.connect(raw.raw)
lefuService.onConnectState((state) => {
if (state === lefuService.BLUE_STATE.CONNECTFAILED) {
wx.hideLoading()
wx.showToast({ title: '连接失败,请重试', icon: 'none' })
}
})
lefuService.onDeviceConnect(() => {
wx.setStorageSync('connectDeviceInfo', { ...raw.raw, scaleDeviceName: raw.raw.name })
const list = this.data.deviceList.map((item, i) => ({
...item,
connected: i === index,
}))
this.setData({ deviceList: list })
wx.hideLoading()
console.log(TAG, '缓存设备已自动连接(不跳转)')
})
},
/** 点击整张卡片:已连接 → 跳转配网页;未连接 → 走手动连接流程 */
onTapCard(e: WechatMiniprogram.TouchEvent) {
const connected = e.currentTarget.dataset.connected as boolean
console.log(TAG, 'onTapCard, connected:', connected)
if (connected) {
wx.navigateTo({ url: '/pages/connectedWifi/connectedWifi' })
return
}
this.onConnect(e)
},
/** 连接指定设备 */
onConnect(e: WechatMiniprogram.TouchEvent) {
const index = e.currentTarget.dataset.index as number
const raw = _rawDevices[index]
console.log(TAG, 'onConnect, index:', index, 'device:', raw)
if (!raw) {
console.warn(TAG, 'onConnect: 找不到对应 raw device, index:', index)
return
}
wx.showLoading({ title: '连接中...', mask: true })
lefuService.connect(raw.raw)
lefuService.onConnectState((state) => {
if (state === lefuService.BLUE_STATE.CONNECTFAILED) {
wx.hideLoading()
wx.showToast({ title: '连接失败,请重试', icon: 'none' })
}
})
lefuService.onDeviceConnect(() => {
wx.setStorageSync('connectDeviceInfo', { ...raw.raw, scaleDeviceName: raw.raw.name })
const list = this.data.deviceList.map((item, i) => ({
...item,
connected: i === index,
}))
this.setData({ deviceList: list })
wx.hideLoading()
console.log(TAG, '设备连接就绪,跳转配网页')
wx.navigateTo({ url: '/pages/connectedWifi/connectedWifi' })
})
},
/** 断开当前连接 */
onDisconnect() {
console.log(TAG, 'onDisconnect')
const list = this.data.deviceList.map(item => ({ ...item, connected: false }))
this.setData({ deviceList: list })
lefuService.disconnect()
},
/** 查看帮助 */
onOpenHelp() {
wx.showToast({ title: '请确保设备已开机且在附近', icon: 'none' })
},
})
@@ -1,83 +0,0 @@
<view class="connected-device">
<!-- 三层同心圆波纹动画:仅在非 idle(已点击开始搜索)时播放 -->
<view class="ripple {{ status === 'idle' ? '' : 'ripple--active' }}">
<view class="ripple-ring"></view>
<view class="ripple-ring ripple-ring--delay1"></view>
<view class="ripple-ring ripple-ring--delay2"></view>
<view class="ripple-core">
<image src="/images/connectedDevice/icon.png" mode=""/>
</view>
</view>
<!-- 主标题 -->
<view class="title">
{{ status === 'idle' ? '搜索附近设备' : '搜索附近设备中...' }}
</view>
<!-- 副标题 -->
<view class="sub-title">请确保蓝牙已开启,设备处于待机状态</view>
<!-- 主按钮:idle 显示开始搜索,其他显示重新搜索 -->
<view class="search-btn" bind:tap="onStartSearch">
{{ status === 'idle' ? '开始搜索' : '重新搜索' }}
</view>
<!-- 帮助文案 -->
<!-- <view class="help">
<text class="help-text">无法配对设备?</text>
<text class="help-link" bind:tap="onOpenHelp">查看帮助</text>
</view> -->
<!-- 搜索结果模块:found / empty 时整体显示 -->
<block wx:if="{{ status === 'found' || status === 'empty' }}">
<view class="search-device">
<!-- 头部:标题 + 计数 -->
<view class="search-device-header">
<text class="search-device-title">搜索结果</text>
<view class="search-device-count">
<text class="count-text">发现</text>
<text class="count-num">{{ deviceList.length }}</text>
<text class="count-text">台设备</text>
</view>
</view>
<!-- 空状态 -->
<block wx:if="{{ status === 'empty' }}">
<view class="empty">
<view class="empty-image"></view>
<view class="empty-text">暂未搜索到可用设备,请重新搜索</view>
</view>
</block>
<!-- 找到设备:统一循环,内部按 connected 切换 UI -->
<block wx:if="{{ status === 'found' }}">
<view class="device-list">
<block wx:for="{{ deviceList }}" wx:key="name">
<view class="device-card" data-index="{{ index }}" data-connected="{{ item.connected }}" bind:tap="onTapCard">
<view class="card-icon">
<image src="/images/device/{{ item.name }}.png" mode="aspectFit" style="width:100%;height:100%;"></image>
</view>
<view class="card-info">
<view class="card-name">{{ item.name }}</view>
<block wx:if="{{ item.connected }}">
<view class="card-status">
<view class="card-dot"></view>
<text class="card-status-text">已连接</text>
</view>
</block>
</view>
<block wx:if="{{ item.connected }}">
<view class="card-btn-danger" catch:tap="onDisconnect">断开连接</view>
</block>
<block wx:else>
<view class="card-btn-primary" data-index="{{ index }}" catch:tap="onConnect">连接</view>
</block>
</view>
</block>
</view>
</block>
</view>
</block>
</view>