feat: init project with miniprogram, cloud functions and admin console

这个提交包含在:
Guoguo
2026-04-22 21:24:20 +08:00
当前提交 a84e37a6e2
修改 106 个文件,包含 5902 行新增0 行删除
@@ -0,0 +1,61 @@
var ble = require('../../services/ble')
var app = getApp()
Page({
data: {
deviceId: '',
bindToken: '',
state: 'scanning',
error: ''
},
onLoad: function (options) {
this.setData({
deviceId: options.device_id || '',
bindToken: options.bind_token || ''
})
this.startBleConnect()
},
startBleConnect: function () {
var self = this
self.setData({ state: 'scanning', error: '' })
ble.startScan({
onFound: function (device) {
self.setData({ state: 'connecting' })
},
onConnected: function (device) {
self.setData({ state: 'binding' })
self.doBind()
},
onError: function (err) {
self.setData({ state: 'error', error: err.msg || '连接失败' })
}
})
},
doBind: function () {
var self = this
var userId = app.globalData.userId || ''
ble.on('bind_result', function (result) {
if (result.success) {
self.setData({ state: 'done' })
wx.redirectTo({
url: '/pages/bind-success/bind-success?device_id=' + self.data.deviceId
})
} else {
self.setData({ state: 'error', error: '设备绑定失败' })
}
})
ble.bindDevice(userId, self.data.bindToken).catch(function (err) {
self.setData({ state: 'error', error: err.error_msg || '绑定命令失败' })
})
},
onRetry: function () {
ble.disconnect()
this.startBleConnect()
}
})
@@ -0,0 +1,3 @@
{
"navigationBarTitleText": "蓝牙连接"
}
@@ -0,0 +1,28 @@
<view class="container">
<view class="card text-center">
<view class="section-title">
{{state === 'scanning' ? '正在扫描设备...' : state === 'connecting' ? '正在连接设备...' : state === 'binding' ? '正在绑定设备...' : '连接失败'}}
</view>
<view wx:if="{{state === 'scanning'}}" class="text-muted mb-30">
请确保设备已开机且在附近
</view>
<view wx:if="{{state === 'connecting'}}" class="text-muted mb-30">
设备ID: {{deviceId}}
</view>
<view wx:if="{{state === 'binding'}}" class="text-muted mb-30">
正在写入绑定信息...
</view>
<view wx:if="{{state === 'error'}}" class="mb-30">
<text class="text-error">{{error}}</text>
</view>
<view wx:if="{{state === 'scanning' || state === 'connecting' || state === 'binding'}}" class="loading-spinner">
<view class="spinner"></view>
</view>
<view wx:if="{{state === 'error'}}">
<view class="btn-primary" bindtap="onRetry">重试</view>
</view>
</view>
</view>
@@ -0,0 +1,18 @@
.loading-spinner {
padding: 40rpx 0;
display: flex;
justify-content: center;
}
.spinner {
width: 64rpx;
height: 64rpx;
border: 6rpx solid #eeeeee;
border-top-color: #333333;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}