|
@@ -39,7 +39,7 @@
|
|
|
</view>
|
|
|
</template>
|
|
|
|
|
|
-<script>
|
|
|
+<script>
|
|
|
var xBlufi = require("@/utils/blufi/xBlufi.js");
|
|
|
let _this = null;
|
|
|
export default {
|
|
@@ -54,25 +54,64 @@
|
|
|
}
|
|
|
},
|
|
|
onShow() {
|
|
|
- this.nodevice = false;
|
|
|
- this.show = false;
|
|
|
+ // this.nodevice = false;
|
|
|
+ // this.show = false;
|
|
|
+ // this.Search();
|
|
|
},
|
|
|
onLoad: function() {
|
|
|
- this.Search();
|
|
|
_this = this;
|
|
|
- xBlufi.initXBlufi(1);
|
|
|
+ this.Search();
|
|
|
+ // xBlufi.initXBlufi(1);
|
|
|
xBlufi.listenDeviceMsgEvent(true, this.funListenDeviceMsgEvent);
|
|
|
},
|
|
|
onUnload() {
|
|
|
xBlufi.listenDeviceMsgEvent(false, this.funListenDeviceMsgEvent);
|
|
|
},
|
|
|
methods:{
|
|
|
+ initBluetooth() {
|
|
|
+ let that = this;
|
|
|
+ try{
|
|
|
+ wx.openBluetoothAdapter({
|
|
|
+ success: (res) => {
|
|
|
+ // 监听连接状态变化
|
|
|
+ wx.onBLEConnectionStateChange((res2) => {
|
|
|
+ console.log(res2,'onBLEConnectionStateChange');
|
|
|
+ });
|
|
|
+ wx.startBluetoothDevicesDiscovery({
|
|
|
+ services: ['0000FFFF-0000-1000-8000-00805F9B34FB'], // Blufi服务UUID
|
|
|
+ success: (res3) => {
|
|
|
+ // 监听发现新设备
|
|
|
+ wx.onBluetoothDeviceFound((resu) => {
|
|
|
+ let ly = resu.devices.find(d=>d.name.indexOf('cx-')>-1);
|
|
|
+ if(ly){
|
|
|
+ that.lanya = ly;
|
|
|
+ that.nodevice = false;
|
|
|
+ that.show = true;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: (err2) => {
|
|
|
+ console.log(err2,'err2');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ fail: (err) => {
|
|
|
+ console.log(err,'初始化失败');
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }catch(e){
|
|
|
+ console.log(e,'e');
|
|
|
+ }
|
|
|
+ },
|
|
|
funListenDeviceMsgEvent: function(options) {
|
|
|
switch (options.type) {
|
|
|
+ case xBlufi.XBLUFI_TYPE.TYPE_STATUS_CONNECTED:
|
|
|
+ console.log(options)
|
|
|
+ break;
|
|
|
case xBlufi.XBLUFI_TYPE.TYPE_GET_DEVICE_LISTS:
|
|
|
if (options.result)
|
|
|
_this.devicesList = options.data;
|
|
|
- let ly = _this.devicesList.find(d=>d.name=='BLUFI_DEVICE');
|
|
|
+ let ly = _this.devicesList.find(d=>d.name.indexOf('cx-')>-1);
|
|
|
if(ly){
|
|
|
_this.lanya = ly;
|
|
|
_this.nodevice = false;
|
|
@@ -134,6 +173,20 @@
|
|
|
}
|
|
|
},
|
|
|
connectWiFi: function() {
|
|
|
+ // let that = this;
|
|
|
+ // wx.createBLEConnection({
|
|
|
+ // deviceId: that.lanya.deviceId,
|
|
|
+ // success: (res) => {
|
|
|
+ // wx.navigateTo({
|
|
|
+ // url: '/pagesMy/wifiSet?deviceId=' + that.lanya.deviceId + '&name=' + that.lanya.name
|
|
|
+ // })
|
|
|
+ // },
|
|
|
+ // fail: (err) => {
|
|
|
+ // console.log(err,'createBLEConnection-err');
|
|
|
+ // }
|
|
|
+ // });
|
|
|
+ // return
|
|
|
+
|
|
|
//停止搜索
|
|
|
xBlufi.notifyStartDiscoverBle({
|
|
|
'isStart': false
|