文件
jw-beauty/miniprogram/pages/auto-scan/auto-scan.js
T
Guoguo f0fdb285b5 chore: remove all mock/debug code for production release
Miniprogram:
- ENV switched to 'prod' (disables __DEV__ flag)
- Deleted mock.js and test-ble-frame.js
- Removed mockBind/mockPurchase from api.js
- Removed all debug UI panels and onMock* handlers from 6 pages
- Removed mock purchase fallback in subscribe-plans
- Removed SIMPLE PERIPHERAL dev board from BLE scan

Server:
- Removed /device/mock-bind route
- Removed /subscription/mock-purchase route
- Removed dev_openid fallback in wechat.js
- Removed mockBind() from binding.dao.js
- Removed mock fallback in purchase endpoint
- NODE_ENV default changed to 'production'

Admin:
- ENV switched to 'prod'

All mock code preserved in 'test' branch for future development use.
2026-05-20 07:19:26 -07:00

93 行
2.4 KiB
JavaScript

var ble = require('../../services/ble')
Page({
data: {
statusBarHeight: 44,
scanning: true,
scanProgress: 0,
regions: 0x7F,
regionData: [],
timeout: false,
error: ''
},
onBack: function () {
wx.navigateBack({
fail: function () {
wx.reLaunch({ url: '/pages/index/index' })
}
})
},
onLoad: function (options) {
var app = getApp()
this.setData({
statusBarHeight: app.globalData.statusBarHeight,
regions: parseInt(options.regions) || 0x7F
})
this.startScan()
},
startScan: function () {
var self = this
self.setData({ scanning: true, scanProgress: 0, timeout: false })
this._progressTimer = setInterval(function () {
var p = self.data.scanProgress + 2
if (p > 98) p = 98
self.setData({ scanProgress: p })
}, 100)
this._onStatus = function (status) {
if (status.mode_state === 0x01) {
self.setData({ scanProgress: 50 })
} else if (status.mode_state === 0x04 || status.mode_state === 0x00) {
clearInterval(self._progressTimer)
self.setData({ scanning: false, scanProgress: 100 })
var names = ble.getRegionName(status.region_mask || 0x7F)
self.setData({ regionData: self.parseScanResults(names) })
}
}
ble.on('status', this._onStatus)
ble.queryStatus().catch(function () {})
setTimeout(function () {
clearInterval(self._progressTimer)
if (!self.data.scanning) return
self.setData({ scanning: false, timeout: true })
wx.showToast({ title: '扫描超时,请重试', icon: 'none' })
}, 5000)
},
parseScanResults: function (regions) {
return regions.map(function (name) {
return { region: name, pd: '待检测' }
})
},
onUnload: function () {
if (this._progressTimer) clearInterval(this._progressTimer)
if (this._onStatus) ble.off('status', this._onStatus)
},
onNext: function () {
var mask = this.data.regions || 0x7F
ble.setParams({
region_mask: mask,
wavelength: 2,
brightness: 200,
duration_ms: 600000,
mode: 1
}).then(function () {
return ble.startTreatment(mask)
}).then(function () {
wx.redirectTo({
url: '/pages/treating/treating?regions=' + mask + '&wavelength=2&duration=600000&mode=1'
})
}).catch(function (err) {
wx.showToast({ title: err.error_msg || '启动失败', icon: 'none' })
})
},
})