fix: resolve multiple miniprogram bugs and extend admin console
- fix manual bind stuck at BLE scan, redirect to bind-success - add 15s timeout and stopScan to ble-connect - add stopScan method to ble.js - add back-to-home button on bind-success page - fix field name in subscribe-plans (plan -> plan_type) - fix history.js to handle created_at field - fix index.js to handle device name field - add subscription route alias in request.js - extend admin cloud function from 1 to 9 actions - add mock mode to admin-console request.js - remove unused discover page and legacy record function Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
这个提交包含在:
@@ -13,5 +13,9 @@ Page({
|
||||
|
||||
onStart: function () {
|
||||
wx.redirectTo({ url: '/pages/wear-check/wear-check' })
|
||||
},
|
||||
|
||||
onGoHome: function () {
|
||||
wx.reLaunch({ url: '/pages/index/index' })
|
||||
}
|
||||
})
|
||||
|
||||
@@ -19,5 +19,6 @@
|
||||
</view>
|
||||
|
||||
<button class="btn-primary" bindtap="onStart">开始使用</button>
|
||||
<button class="btn-secondary" bindtap="onGoHome">返回首页</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
var ble = require('../../services/ble')
|
||||
var app = getApp()
|
||||
var SCAN_TIMEOUT = 15000
|
||||
|
||||
Page({
|
||||
data: {
|
||||
@@ -19,19 +20,32 @@ Page({
|
||||
this.startBleConnect()
|
||||
},
|
||||
|
||||
onUnload: function () {
|
||||
clearTimeout(this._scanTimer)
|
||||
ble.stopScan()
|
||||
},
|
||||
|
||||
startBleConnect: function () {
|
||||
var self = this
|
||||
self.setData({ state: 'scanning', error: '' })
|
||||
|
||||
self._scanTimer = setTimeout(function () {
|
||||
ble.stopScan()
|
||||
self.setData({ state: 'error', error: '搜索超时,请确认设备已开机并在附近' })
|
||||
}, SCAN_TIMEOUT)
|
||||
|
||||
ble.startScan({
|
||||
onFound: function (device) {
|
||||
clearTimeout(self._scanTimer)
|
||||
self.setData({ state: 'connecting' })
|
||||
},
|
||||
onConnected: function (device) {
|
||||
clearTimeout(self._scanTimer)
|
||||
self.setData({ state: 'binding' })
|
||||
self.doBind()
|
||||
},
|
||||
onError: function (err) {
|
||||
clearTimeout(self._scanTimer)
|
||||
self.setData({ state: 'error', error: err.msg || '连接失败' })
|
||||
}
|
||||
})
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
Page({
|
||||
data: {
|
||||
articles: []
|
||||
},
|
||||
|
||||
onLoad: function () {
|
||||
}
|
||||
})
|
||||
@@ -1,3 +0,0 @@
|
||||
{
|
||||
"navigationBarTitleText": "发现"
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
<view class="container">
|
||||
<view class="section-title">发现</view>
|
||||
<view class="text-center text-muted mt-20">暂无内容</view>
|
||||
</view>
|
||||
@@ -1 +0,0 @@
|
||||
{}
|
||||
@@ -54,7 +54,7 @@ Page({
|
||||
r.duration_text = durationMin + '分钟'
|
||||
r.region_names = ble.getRegionName(r.regions || 0).join('、')
|
||||
r.wavelength_name = ble.getWavelengthName(r.wavelength || 2)
|
||||
r.date_text = self.formatDate(r.start_time)
|
||||
r.date_text = self.formatDate(r.start_time || r.created_at)
|
||||
|
||||
if (r.start_time && new Date(r.start_time) >= monthStart) {
|
||||
monthCount++
|
||||
|
||||
@@ -44,7 +44,7 @@ Page({
|
||||
self.setData({ hasDevice: devices.length > 0 })
|
||||
if (devices.length > 0) {
|
||||
self.setData({
|
||||
deviceName: devices[0].device_name || '光子美容仪',
|
||||
deviceName: devices[0].name || devices[0].device_id || '我的光面膜',
|
||||
deviceInfo: devices[0]
|
||||
})
|
||||
}
|
||||
@@ -90,6 +90,45 @@ Page({
|
||||
wx.navigateTo({ url: '/pages/scan/scan' })
|
||||
},
|
||||
|
||||
onManageDevice: function () {
|
||||
var self = this
|
||||
wx.showActionSheet({
|
||||
itemList: ['解绑当前设备'],
|
||||
success: function (res) {
|
||||
if (res.tapIndex === 0) {
|
||||
wx.showModal({
|
||||
title: '确认解绑',
|
||||
content: '解绑后将无法使用该设备,确定要解绑吗?',
|
||||
success: function (modalRes) {
|
||||
if (modalRes.confirm) {
|
||||
self.doUnbind()
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
doUnbind: function () {
|
||||
var self = this
|
||||
wx.showLoading({ title: '解绑中...' })
|
||||
ble.disconnect()
|
||||
http.post('/api/v1/device/unbind', {}).then(function () {
|
||||
wx.hideLoading()
|
||||
self.setData({
|
||||
hasDevice: false,
|
||||
deviceName: '',
|
||||
deviceInfo: null,
|
||||
connected: false
|
||||
})
|
||||
wx.showToast({ title: '已解绑', icon: 'success' })
|
||||
}).catch(function (err) {
|
||||
wx.hideLoading()
|
||||
wx.showToast({ title: err.message || '解绑失败', icon: 'none' })
|
||||
})
|
||||
},
|
||||
|
||||
onStartTreatment: function () {
|
||||
if (!this.data.subscription || this.data.subscription.status === 0) {
|
||||
wx.navigateTo({ url: '/pages/subscribe-prompt/subscribe-prompt' })
|
||||
|
||||
@@ -20,6 +20,6 @@
|
||||
</view>
|
||||
|
||||
<button class="btn-primary" bindtap="onStartTreatment">开始护理</button>
|
||||
<button class="btn-secondary" bindtap="onAddDevice">设备管理</button>
|
||||
<button class="btn-secondary" bindtap="onManageDevice">设备管理</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -47,16 +47,22 @@ Page({
|
||||
|
||||
bindDevice: function (deviceId) {
|
||||
var self = this
|
||||
self.setData({ scanning: true, error: '' })
|
||||
http.post('/api/v1/device/bind', { device_id: deviceId }).then(function (data) {
|
||||
self.setData({ scanning: false })
|
||||
wx.navigateTo({
|
||||
url: '/pages/ble-connect/ble-connect?device_id=' + deviceId + '&bind_token=' + data.bind_token
|
||||
wx.redirectTo({
|
||||
url: '/pages/bind-success/bind-success?device_id=' + deviceId
|
||||
})
|
||||
}).catch(function (err) {
|
||||
self.setData({
|
||||
scanning: false,
|
||||
error: err.message || '绑定失败'
|
||||
})
|
||||
self.setData({ scanning: false })
|
||||
if (err && err.code === 2001) {
|
||||
wx.showToast({ title: '已绑定设备', icon: 'none' })
|
||||
setTimeout(function () {
|
||||
wx.navigateBack()
|
||||
}, 1500)
|
||||
} else {
|
||||
self.setData({ error: err.message || '绑定失败' })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
|
||||
@@ -29,12 +29,12 @@ Page({
|
||||
self.setData({ purchasing: true })
|
||||
|
||||
http.post('/api/v1/subscription/purchase', {
|
||||
plan: self.data.selected,
|
||||
plan_type: self.data.selected,
|
||||
payment_method: 'wechat'
|
||||
}).then(function (data) {
|
||||
return http.post('/api/v1/subscription/verify', {
|
||||
order_id: data.order_id,
|
||||
plan: self.data.selected
|
||||
plan_type: self.data.selected
|
||||
})
|
||||
}).then(function () {
|
||||
self.setData({ purchasing: false })
|
||||
|
||||
在新工单中引用
屏蔽一个用户