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,134 +0,0 @@
|
||||
import { lefuService } from '../../lefu/index'
|
||||
import type { LeFuWifiItem } from '../../lefu/index'
|
||||
|
||||
interface WifiItem {
|
||||
ssid: string
|
||||
connected: boolean
|
||||
}
|
||||
|
||||
type WifiStatus = 'idle' | 'searching' | 'list' | 'empty' | 'password' | 'configuring'
|
||||
type BleStatus = 'connected' | 'failed' | 'connecting'
|
||||
|
||||
Page({
|
||||
|
||||
data: {
|
||||
status: 'idle' as WifiStatus,
|
||||
deviceName: '智能体重秤',
|
||||
bleStatus: 'connecting' as BleStatus,
|
||||
wifiList: [] as WifiItem[],
|
||||
hasConnected: false,
|
||||
selectedSsid: '',
|
||||
selectWifiPWD: '',
|
||||
type: true,
|
||||
},
|
||||
|
||||
_toBleStatus(state: string): BleStatus {
|
||||
const bs = lefuService.BLUE_STATE
|
||||
if (state === bs.CONNECTSUCCESS || state === bs.WIFISUCCESS) return 'connected'
|
||||
if (state === bs.CONNECTFAILED || state === bs.UNAVAILABLE) return 'failed'
|
||||
return 'connecting'
|
||||
},
|
||||
|
||||
onLoad() {
|
||||
// 尽早注册 deviceInfo 回调,防止 onShow 前已触发而错过
|
||||
lefuService.onDeviceInfo((info) => {
|
||||
this.setData({ deviceName: info.modelNumber })
|
||||
})
|
||||
// 设备断开即退出配网页
|
||||
lefuService.onDisconnected(() => {
|
||||
wx.showToast({ title: '设备已断开连接', icon: 'none', duration: 1500 })
|
||||
setTimeout(() => wx.navigateBack(), 1500)
|
||||
})
|
||||
this.setData({
|
||||
bleStatus: this._toBleStatus(lefuService.connectState),
|
||||
deviceName: lefuService.deviceInfo?.modelNumber ?? '智能体重秤',
|
||||
})
|
||||
this.onStartSearch()
|
||||
},
|
||||
|
||||
onShow() {
|
||||
lefuService.onConnectState((state) => {
|
||||
this.setData({ bleStatus: this._toBleStatus(state) })
|
||||
})
|
||||
},
|
||||
|
||||
onUnload() {
|
||||
wx.hideLoading()
|
||||
lefuService.onDisconnected(() => {})
|
||||
if (this.data.status === 'configuring') {
|
||||
lefuService.disconnect()
|
||||
}
|
||||
},
|
||||
|
||||
onStartSearch() {
|
||||
this.setData({ status: 'searching', wifiList: [] })
|
||||
wx.showLoading({ title: '正在获取 WiFi 列表...', mask: true })
|
||||
lefuService.getWifiList()
|
||||
.then((items: LeFuWifiItem[]) => {
|
||||
wx.hideLoading()
|
||||
if (!items.length) {
|
||||
this.setData({ status: 'empty' })
|
||||
return
|
||||
}
|
||||
this.setData({
|
||||
status: 'list',
|
||||
wifiList: items.map(item => ({ ssid: item.ssid, connected: false })),
|
||||
})
|
||||
})
|
||||
.catch(() => {
|
||||
wx.hideLoading()
|
||||
this.setData({ status: 'empty' })
|
||||
})
|
||||
},
|
||||
|
||||
onRefresh() {
|
||||
this.onStartSearch()
|
||||
},
|
||||
|
||||
onTapWifi(e: WechatMiniprogram.TouchEvent) {
|
||||
const ssid = e.currentTarget.dataset.ssid as string
|
||||
const target = this.data.wifiList.find(item => item.ssid === ssid)
|
||||
if (!target || target.connected) return
|
||||
this.setData({ status: 'password', selectedSsid: ssid, selectWifiPWD: '', type: true })
|
||||
},
|
||||
|
||||
passwordInput(e: WechatMiniprogram.Input) {
|
||||
this.setData({ selectWifiPWD: e.detail.value })
|
||||
},
|
||||
|
||||
inputTypeChange() {
|
||||
this.setData({ type: !this.data.type })
|
||||
},
|
||||
|
||||
onCancelPwd() {
|
||||
this.setData({ status: 'list', selectedSsid: '', selectWifiPWD: '' })
|
||||
},
|
||||
|
||||
onConfirmPwd() {
|
||||
const { selectedSsid, selectWifiPWD } = this.data
|
||||
if (!selectedSsid) return
|
||||
this.setData({ status: 'configuring' })
|
||||
wx.showLoading({ title: '正在配网...', mask: true })
|
||||
lefuService.configWifi(selectedSsid, selectWifiPWD)
|
||||
.then(() => {
|
||||
wx.hideLoading()
|
||||
this.setData({
|
||||
status: 'list',
|
||||
wifiList: this.data.wifiList.map(item => ({ ...item, connected: item.ssid === selectedSsid })),
|
||||
hasConnected: true,
|
||||
selectedSsid: '',
|
||||
selectWifiPWD: '',
|
||||
})
|
||||
})
|
||||
.catch((err: Error) => {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: err.message || '配网失败,请重试', icon: 'none' })
|
||||
this.setData({ status: 'password' })
|
||||
})
|
||||
},
|
||||
|
||||
onConfirm() {
|
||||
if (!this.data.hasConnected) return
|
||||
wx.navigateTo({ url: '/pages/supplementPersonal/supplementPersonal' })
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user