1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- <wxs module="utils">
- module.exports.max = function(n1, n2) {
- return Math.max(n1, n2)
- }
- module.exports.len = function(arr) {
- arr = arr || []
- return arr.length
- }
- module.exports.fill0 = function(num) {
- if (!num) {
- return '00'
- }
- return ('00' + num).slice(-2)
- }
- </wxs>
-
- <block wx:if="{{!connected}}">
- <button bindtap="openBluetoothAdapter">开始扫描</button>
- <button bindtap="stopBluetoothDevicesDiscovery">停止扫描</button>
- <button bindtap="closeBluetoothAdapter">结束流程</button>
- <button bindtap="clearDevices">清空列表</button>
- <view class="devices_summary">已发现 {{devices.length}} 个外围设备:</view>
- <view class="device_list">
- <view wx:for="{{devices}}" wx:key="index"
- class="device_item">
- <view style="font-size: 16px; color: #333;">{{item.name || item.localName}}</view>
- <view style="font-size: 10px">信号强度: {{item.RSSI}}dBm ({{utils.max(0, item.RSSI + 100)}}%)</view>
- <view style="font-size: 10px">mac地址: {{item.deviceId}}</view>
- <view
- class="device_item_btn"
- hover-class="btn_hover"
- data-device-id="{{item.deviceId}}"
- data-name="{{item.name || item.localName}}"
- data-index="{{index}}"
- bindtap="createBLEConnection"
- >连接</view>
- </view>
- </view>
- </block>
- <view class="wrap" wx:else>
- <view class="stopConnect">
- <view>{{mac}}</view>
- <view class="btn_connect" hover-class="btn_hover" bindtap="closeBLEConnection">断开连接</view>
- </view>
- <view class="weight_wrap">
- <view class="weight_title">WEIGHT</view>
- <view class="weight_value">
- <view class="value_item">{{weight}}</view>
- <view class="value_item">{{unit}}</view>
- </view>
- </view>
- <view class="timer_wrap">
- <view class="timer_title">TIMER</view>
- <view class="timer_value">
- <view class="value_item">{{utils.fill0(min)}}</view>
- <view>:</view>
- <view class="value_item">{{utils.fill0(second)}}</view>
- </view>
- </view>
- <view class="btn_wrap">
- <button bindtap="tare">TARE(去皮)</button>
- <button bindtap="getUnits">获取设备支持的单位</button>
- <button bindtap="countUp">正计时开始</button>
- <button bindtap="countUpPause">正计时暂停</button>
- <button bindtap="countDown">倒计时开始</button>
- <button bindtap="countDownPause">倒计时暂停</button>
- <button bindtap="resetTime">重置时间</button>
- <view class="btn_unitList_title">切换单位</view>
- <view class="btn_unitList">
- <view class="btn_unit" hover-class="btn_hover" wx:for="{{unitList}}" wx:key="index" bindtap="selectUnit" data-unit="{{item}}" data-index="{{index}}">{{item}}</view>
- </view>
- </view>
- <view class="btn_unitList_title">{{text}}</view>
- </view>
|