adultDeviceApp/unpackage/dist/build/mp-weixin/BLEPages/child/H09B.js

1 line
8.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["BLEPages/child/H09B"],{6353:function(e,t,i){"use strict";i.r(t);var o=i("e3c6"),n=i("8016");for(var c in n)["default"].indexOf(c)<0&&function(e){i.d(t,e,(function(){return n[e]}))}(c);var s=i("828b"),r=Object(s["a"])(n["default"],o["b"],o["c"],!1,null,"0183c395",null,!1,o["a"],void 0);t["default"]=r.exports},"7e63":function(e,t,i){"use strict";(function(e){var o=i("47a9");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,c=o(i("7ca3")),s=i("8f59");function r(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,o)}return i}function a(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?r(Object(i),!0).forEach((function(t){(0,c.default)(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}var u={data:function(){return{text:"",textH:"",height:"",weight:"",imp:0,type:1,uuid1:"",uuid2:"",uuid3:"",macAddr:"",deviceId:"",serviceId:"",Unload:!1,isConnection:0}},computed:a(a({},(0,s.mapState)(["user","isConnected","isBluetoothTyle","appTheme"])),{},{info:function(){return this.user}}),onUnload:function(){this.Unload||(this.stopBluetoothDevicesDiscovery(),clearTimeout(n),this.closeBLEConnection(),this.closeBluetoothAdapter(),e.switchTab({url:"/pages/index/index"}),console.log("返回首页"))},onLoad:function(t){var i=this;e.setNavigationBarColor({frontColor:"#ffffff",backgroundColor:this.appTheme}),i.text="",i.textH="",i.imp=0,t&&t.deviceId&&(i.deviceId=t.deviceId,i.closeBLEConnection(),i.closeBluetoothAdapter(),i.openBluetoothAdapter()),i.onBLEConnectionStateChange(),e.onBluetoothAdapterStateChange((function(e){i.$store.commit("changeBluetooth",e.available)}))},watch:{isConnected:function(){this.isConnected||(this.handleBack(),this.isConnection=2)},isBluetoothTyle:function(){this.isBluetoothTyle||(this.handleBack(),this.isConnection=2)}},methods:{openBluetoothAdapter:function(){var t=this;t.type=1,t.text="",t.textH="",e.openBluetoothAdapter({success:function(e){t.isConnection=0,t.startBluetoothDeviceDiscovery()},fail:function(e){t.isConnection=2,t.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")}})},startBluetoothDeviceDiscovery:function(){var t=this;e.startBluetoothDevicesDiscovery({allowDuplicatesKey:!1,interval:500,services:["FFE0"],success:function(e){t.isConnection=0,t.onBluetoothDeviceFound()},fail:function(e){t.isConnection=2,t.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")}})},onBluetoothDeviceFound:function(){var t=this;t.isConnection=0,e.onBluetoothDeviceFound((function(e){e.devices.forEach((function(e){if((e.name||e.localName)&&(-1!=e.name.indexOf("AiLink_")||e.localName&&-1!=e.localName.indexOf("AiLink_"))){clearTimeout(n);var i=e.advertisData.slice(-6);e.mac=new Uint8Array(i);var o=Array.from(e.mac);if(o.reverse(),e.macAddr=t.$tools.ab2hex(o,":").toUpperCase(),-1!=e.deviceId.indexOf(t.deviceId)||-1!=e.macAddr.indexOf(t.deviceId))return t.stopBluetoothDevicesDiscovery(),t.macAddr=e.macAddr,t.deviceId=e.deviceId,void t.createBLEConnection()}}))})),t.handleMyTime()},handleMyTime:function(){var e=this;n=setTimeout((function(){e.macAddr||(clearTimeout(n),e.Unload=!0,e.isConnection=2,e.closeBLEConnection(),e.closeBluetoothAdapter())}),2e4)},stopBluetoothDevicesDiscovery:function(){e.stopBluetoothDevicesDiscovery({success:function(e){console.log("停止搜索蓝牙设备",e)}})},onBLEConnectionStateChange:function(){var t=this;e.onBLEConnectionStateChange((function(e){console.log("监听蓝牙连接状态",e.connected),e.connected||(t.Unload=!0,t.isConnection=2,clearTimeout(n),t.closeBLEConnection(),t.closeBluetoothAdapter()),t.$store.commit("changeConnected",e.connected)}))},createBLEConnection:function(){var t=this;e.createBLEConnection({deviceId:t.deviceId,success:function(e){t.isConnection=0,t.getBLEDeviceServices()},fail:function(e){t.isConnection=2,console.log("设备连接失败,请重新连接",e)}})},getBLEDeviceServices:function(){var t=[],i=this;e.getBLEDeviceServices({deviceId:i.deviceId,success:function(e){console.log("获取设备的UUID成功",e),t=e.services;for(var o=0;o<t.length;o++){var n=t[o];if(-1!=n.uuid.indexOf("FFE0")){i.isConnection=1,i.serviceId=n.uuid,i.getBLEDeviceCharacteristics(),console.log("设备的FFE0的serviceId "+i.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(){var t=this;e.getBLEDeviceCharacteristics({deviceId:t.deviceId,serviceId:t.serviceId,success:function(i){console.log("服务的特征值成功",i);for(var o=0;o<i.characteristics.length;o++){var n=i.characteristics[o];-1!=n.uuid.indexOf("0000FFE1")?t.uuid1=n.uuid:-1!=n.uuid.indexOf("0000FFE2")?t.uuid2=n.uuid:-1!=n.uuid.indexOf("0000FFE3")&&(t.uuid3=n.uuid)}e.notifyBLECharacteristicValueChange({deviceId:t.deviceId,serviceId:t.serviceId,characteristicId:t.uuid2,state:!0}),e.notifyBLECharacteristicValueChange({deviceId:t.deviceId,serviceId:t.serviceId,characteristicId:t.uuid3,state:!0}),t.sendData(),e.onBLECharacteristicValueChange((function(i){var o=t.$tools.ab2hex(i.value,""),n=o.substring(18,19),c=o.substring(19,20),s=o.substring(8,10),r=o.substring(10,12);if(console.log("单位",o,c),"10"==s){var a=parseInt(o.substring(13,18),16),u="kg",l="kg";"1"==c&&(u="斤",l="jin"),"4"==c&&(u="st:lb",l="st",a=1*a+5),"6"==c&&(u="lb",l="lb"),"1"==n&&(a=parseInt(o.substring(13,18),16)/10),"2"==n&&(a=parseInt(o.substring(13,18),16)/100),"3"==n&&(a=parseInt(o.substring(13,18),16)/1e3),"01"==r&&(t.text="您的实时体重是:"+a+u),"02"==r&&(t.text="您的体重是:"+a+u,t.weight=a+l,console.log("稳定体重:",o,t.weight))}"14"==s&&(t.height=parseInt(o.substring(10,14),16)/10,t.textH="您的身高是:"+t.height+"cm",t.type=2,console.log("稳定身高:",t.height)),"11"==s&&("03"!=r&&"04"!=r||(t.imp=parseInt(o.substring(17,22),16)),console.log("阻抗:",r,parseInt(o.substring(17,22),16))),"30"==s&&(console.log("测量完成",t.weight,t.imp,t.height),0==t.imp?e.showModal({title:"提示",content:"体脂测量失败,是否保存本次测量结果?",cancelText:"放弃",confirmText:"保存",success:function(i){i.confirm?(t.imp=0,t.handleGetMeasure()):(console.log("放弃保存"),t.Unload=!0,t.closeBLEConnection(),t.closeBluetoothAdapter(),e.switchTab({url:"/pages/index/index"}))}}):t.handleGetMeasure())}))},fail:function(e){console.log("获取特征值失败:",JSON.stringify(e))}})},sendData:function(){var t=Number(36).toString(16),i="A9002603060100"+t.substr(t.length-2,2)+"9A",o=new Uint8Array(i.match(/[\da-f]{2}/gi).map((function(e){return parseInt(e,16)})));e.writeBLECharacteristicValue({deviceId:this.deviceId,serviceId:this.serviceId,characteristicId:this.uuid1,value:o.buffer,success:function(e){console.log("下发指令成功",e.errMsg)},fail:function(e){console.log("下发指令失败",e)}})},handleGetMeasure:function(){var t=this;t.$model.getmeasure({weight:t.weight,imp:t.imp,ecode:t.macAddr,height:t.height,familyid:t.info.familyid}).then((function(i){0==i.code?(t.$store.dispatch("getUserInfo",{familyid:t.info.familyid}),t.$store.dispatch("getResult",{birthday:t.info.birthday,familyid:t.info.familyid,height:t.height,sex:t.info.sex}),t.$tools.msg("测量成功")):(console.log("测量失败",i.message),t.$tools.msg(i.message)),t.Unload=!0,setTimeout((function(){t.closeBLEConnection(),t.closeBluetoothAdapter(),e.switchTab({url:"/pages/index/index"})}),200)}))},handleBack:function(e){this.text="",this.textH="",this.Unload=!0,this.stopBluetoothDevicesDiscovery(),this.closeBLEConnection(),this.closeBluetoothAdapter()},closeBluetoothAdapter:function(){e.closeBluetoothAdapter({success:function(e){console.log("蓝牙模块关闭成功")}})},closeBLEConnection:function(){e.closeBLEConnection({deviceId:this.deviceId,success:function(e){console.log("断开蓝牙连接成功")}})}}};t.default=u}).call(this,i("df3c")["default"])},8016:function(e,t,i){"use strict";i.r(t);var o=i("7e63"),n=i.n(o);for(var c in o)["default"].indexOf(c)<0&&function(e){i.d(t,e,(function(){return o[e]}))}(c);t["default"]=n.a},"8a8b":function(e,t,i){"use strict";(function(e,t){var o=i("47a9");i("6846");o(i("3240"));var n=o(i("6353"));e.__webpack_require_UNI_MP_PLUGIN__=i,t(n.default)}).call(this,i("3223")["default"],i("df3c")["createPage"])},e3c6:function(e,t,i){"use strict";i.d(t,"b",(function(){return o})),i.d(t,"c",(function(){return n})),i.d(t,"a",(function(){}));var o=function(){var e=this.$createElement;this._self._c},n=[]}},[["8a8b","common/runtime","common/vendor"]]]);