| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 | <wxs module="utils">
module.exports.max = function(n1, n2) {
  return Math.max(n1, n2)
}
module.exports.len = function(arr) {
  arr = arr || []
  return arr.length
}
</wxs>
<view class="container">
  <view class="header">
    <button bindtap="openBluetoothAdapter" style="font-size: 32rpx;line-height:100rpx;width: 100%;">开始扫描</button>
    <button bindtap="stopBluetoothDevicesDiscovery" style="font-size: 32rpx;line-height:100rpx;width: 100%;">停止扫描</button>
    <button bindtap="closeBluetoothAdapter" style="font-size: 32rpx;line-height:100rpx;width: 100%;">结束流程</button>
  </view>
  <view class="devices_summary">已发现 {{devices.length}} 个外围设备:</view>
  <scroll-view class="device_list" scroll-y scroll-with-animation>
    <view wx:for="{{devices}}" wx:key="index"
     data-device-id="{{item.deviceId}}"
     data-name="{{item.name || item.localName}}"
     data-mac="{{item.mac}}"
     data-index="{{index}}"
     bindtap="createBLEConnection" 
     class="device_item"
     hover-class="device_item_hover">
      <view style="font-size: 32rpx;">
        <text style="color:#000;font-weight:bold">{{item.name}}</text>
        <text style="font-size:26rpx">(信号强度: {{item.RSSI}}dBm)</text>
      </view> 
      <view style="font-size: 26rpx">mac地址: {{item.macAddr || item.deviceId}}</view>
      <!-- <view style="font-size: 10px">Service数量: {{utils.len(item.advertisServiceUUIDs)}}</view> -->
      <view style="font-size: 26rpx">广播数据:{{item.analyzeDataText}}</view>
    </view>
  </scroll-view>
  
  <view class="connected_info" wx:if="{{connected}}">
    <view>
      <text>已连接到 {{name}}</text>
      <view class="operation">
        <!-- <button wx:if="{{canWrite}}" size="mini" bindtap="writeBLECharacteristicValue">写数据</button> -->
        <button size="mini" bindtap="showWriteInputView" style="line-height:54rpx; font-size:28rpx;padding:0 20rpx;margin-right:10rpx">写入指令</button>
        <button size="mini" bindtap="closeBLEConnection" style="line-height:54rpx; font-size:28rpx;padding:0 20rpx;">断开连接</button>
      </view>
    </view>
    <view wx:for="{{chs}}" wx:key="index" style="font-size: 26rpx; margin-top: 20rpx;">
      <view>特性值: {{item.value}}</view>
    </view>
  </view>
  <view class="writeInputView" wx:if="{{showWriteInput}}">
      <view class="writeInput">
        <input type="text" model:value="{{cmd}}"></input>
      </view>
      <view class="hint">请输入16进制数,Byte之间用空格或英文逗号分隔</view>
      <view class="btns">
        <button bindtap="submitCmd" style="line-height:70rpx; font-size:30rpx;padding:0 50rpx;margin-right:30rpx;">发送</button>
        <button bindtap="hideWriteInputView" style="line-height:70rpx; font-size:30rpx;padding:0 50rpx;">取消</button>
      </view>
    <view class="history">
      <view class="history_title">历史记录:</view>
      <scroll-view class="history_wrap" scroll-y="true">
        <view class="history_item" wx:for="{{historyList}}" wx:key="index">
          <view class="history_cmd">{{item.cmd}}</view>
          <view class="history_btns">
            <button size="mini" bindtap="history_send" data-index="{{index}}" style="line-height:54rpx; font-size:24rpx;padding:0 30rpx;">发送</button>
            <button size="mini" bindtap="history_delete" data-index="{{index}}" style="line-height:54rpx; font-size:24rpx;padding:0 30rpx;margin-left:20rpx">删除</button>
          </view>
        </view>
      </scroll-view>
    </view>
  </view>
</view>
 |