feat: init project with miniprogram, cloud functions and admin console
这个提交包含在:
@@ -0,0 +1,106 @@
|
||||
var ble = require('../../services/ble')
|
||||
var mqtt = require('../../services/mqtt')
|
||||
var http = require('../../utils/request')
|
||||
var app = getApp()
|
||||
|
||||
Page({
|
||||
data: {
|
||||
connected: false,
|
||||
deviceName: '',
|
||||
battery: 0,
|
||||
subscription: null,
|
||||
subRemaining: 0,
|
||||
modeState: '空闲',
|
||||
bleState: 'disconnected',
|
||||
hasDevice: false,
|
||||
deviceInfo: null
|
||||
},
|
||||
|
||||
onShow: function () {
|
||||
this.checkState()
|
||||
ble.on('status', this.onBleStatus.bind(this))
|
||||
},
|
||||
|
||||
onHide: function () {
|
||||
ble.off('status')
|
||||
},
|
||||
|
||||
onUnload: function () {
|
||||
ble.off('status')
|
||||
},
|
||||
|
||||
checkState: function () {
|
||||
var self = this
|
||||
var token = wx.getStorageSync('token')
|
||||
if (!token) {
|
||||
wx.reLaunch({ url: '/pages/login/login' })
|
||||
return
|
||||
}
|
||||
|
||||
self.setData({ connected: ble.isConnected() })
|
||||
|
||||
http.get('/api/v1/device/list').then(function (data) {
|
||||
var devices = data.devices || []
|
||||
self.setData({ hasDevice: devices.length > 0 })
|
||||
if (devices.length > 0) {
|
||||
self.setData({
|
||||
deviceName: devices[0].device_name || '光子美容仪',
|
||||
deviceInfo: devices[0]
|
||||
})
|
||||
}
|
||||
}).catch(function () {})
|
||||
|
||||
http.get('/api/v1/subscription').then(function (sub) {
|
||||
self.setData({
|
||||
subscription: sub,
|
||||
subRemaining: sub.remaining_days || 0
|
||||
})
|
||||
}).catch(function () {})
|
||||
},
|
||||
|
||||
onBleStatus: function (status) {
|
||||
this.setData({
|
||||
battery: status.battery || 0,
|
||||
modeState: ble.getModeStateName(status.mode_state),
|
||||
connected: true,
|
||||
bleState: 'connected'
|
||||
})
|
||||
},
|
||||
|
||||
onConnectBle: function () {
|
||||
var self = this
|
||||
self.setData({ bleState: 'scanning' })
|
||||
|
||||
ble.startScan({
|
||||
onFound: function () {
|
||||
self.setData({ bleState: 'connecting' })
|
||||
},
|
||||
onConnected: function () {
|
||||
self.setData({ connected: true, bleState: 'connected' })
|
||||
ble.queryStatus().catch(function () {})
|
||||
},
|
||||
onError: function (err) {
|
||||
self.setData({ connected: false, bleState: 'error' })
|
||||
wx.showToast({ title: err.msg || '连接失败', icon: 'none' })
|
||||
}
|
||||
})
|
||||
},
|
||||
|
||||
onAddDevice: function () {
|
||||
wx.navigateTo({ url: '/pages/scan/scan' })
|
||||
},
|
||||
|
||||
onStartTreatment: function () {
|
||||
if (!this.data.subscription || this.data.subscription.status === 0) {
|
||||
wx.navigateTo({ url: '/pages/subscribe-prompt/subscribe-prompt' })
|
||||
return
|
||||
}
|
||||
wx.navigateTo({ url: '/pages/wear-check/wear-check' })
|
||||
},
|
||||
|
||||
onViewSubscription: function () {
|
||||
if (!this.data.subscription || this.data.subscription.status === 0) {
|
||||
wx.navigateTo({ url: '/pages/subscribe-plans/subscribe-plans' })
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"navigationBarTitleText": "首页"
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
<view class="container">
|
||||
<view class="card device-card" wx:if="{{!hasDevice}}">
|
||||
<view class="text-center">
|
||||
<view class="section-title">添加设备</view>
|
||||
<view class="text-muted mb-30">您还没有绑定设备</view>
|
||||
<view class="btn-primary" bindtap="onAddDevice">扫码添加设备</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card device-card" wx:if="{{hasDevice}}">
|
||||
<view class="flex-between mb-20">
|
||||
<view>
|
||||
<view class="device-name">{{deviceName}}</view>
|
||||
<view class="device-status">
|
||||
<text class="{{connected ? 'text-success' : 'text-muted'}}">
|
||||
{{connected ? '已连接' : bleState === 'scanning' ? '扫描中...' : bleState === 'connecting' ? '连接中...' : '未连接'}}
|
||||
</text>
|
||||
</view>
|
||||
</view>
|
||||
<view wx:if="{{connected}}" class="battery-area">
|
||||
<text>{{battery}}%</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{!connected && bleState !== 'scanning' && bleState !== 'connecting'}}" class="mt-20">
|
||||
<view class="btn-secondary" bindtap="onConnectBle">连接设备</view>
|
||||
</view>
|
||||
|
||||
<view wx:if="{{connected}}" class="mt-20">
|
||||
<view class="text-muted">设备状态: {{modeState}}</view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card sub-card" bindtap="onViewSubscription">
|
||||
<view class="flex-between">
|
||||
<view>
|
||||
<view class="section-title">订阅状态</view>
|
||||
<view class="text-muted">
|
||||
<block wx:if="{{subscription && subscription.status > 0}}">
|
||||
{{subscription.status === 1 ? '试用中' : '已订阅'}} · 剩余 {{subRemaining}} 天
|
||||
</block>
|
||||
<block wx:else>未订阅</block>
|
||||
</view>
|
||||
</view>
|
||||
<text class="arrow">❯</text>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<view class="card" wx:if="{{connected && subscription && subscription.status > 0}}">
|
||||
<view class="btn-primary text-center" bindtap="onStartTreatment">开始护理</view>
|
||||
</view>
|
||||
</view>
|
||||
@@ -0,0 +1,23 @@
|
||||
.device-name {
|
||||
font-size: 32rpx;
|
||||
font-weight: 600;
|
||||
margin-bottom: 8rpx;
|
||||
}
|
||||
|
||||
.device-status {
|
||||
font-size: 24rpx;
|
||||
}
|
||||
|
||||
.battery-area {
|
||||
font-size: 28rpx;
|
||||
color: #333333;
|
||||
}
|
||||
|
||||
.arrow {
|
||||
font-size: 28rpx;
|
||||
color: #cccccc;
|
||||
}
|
||||
|
||||
.sub-card:active {
|
||||
background-color: #f9f9f9;
|
||||
}
|
||||
在新工单中引用
屏蔽一个用户