1 line
8.6 KiB
JavaScript
1 line
8.6 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["BLEPages/child/H09B"],{2198:function(e,t,i){"use strict";i.d(t,"b",(function(){return n})),i.d(t,"c",(function(){return o})),i.d(t,"a",(function(){}));var n=function(){var e=this.$createElement;this._self._c},o=[]},6406:function(e,t,i){"use strict";i.r(t);var n=i("c3af"),o=i.n(n);for(var c in n)["default"].indexOf(c)<0&&function(e){i.d(t,e,(function(){return n[e]}))}(c);t["default"]=o.a},b0e1:function(e,t,i){"use strict";i.r(t);var n=i("2198"),o=i("6406");for(var c in o)["default"].indexOf(c)<0&&function(e){i.d(t,e,(function(){return o[e]}))}(c);var s=i("f0c5"),r=Object(s["a"])(o["default"],n["b"],n["c"],!1,null,"dd62eda8",null,!1,n["a"],void 0);t["default"]=r.exports},c3af:function(e,t,i){"use strict";(function(e){var n=i("4ea4");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var o,c=n(i("9523")),s=i("26cb");function r(e,t){var i=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),i.push.apply(i,n)}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(o),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(o);var i=e.advertisData.slice(-6);e.mac=new Uint8Array(i);var n=Array.from(e.mac);if(n.reverse(),e.macAddr=t.$tools.ab2hex(n,":").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;o=setTimeout((function(){e.macAddr||(clearTimeout(o),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(o),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 n=0;n<t.length;n++){var o=t[n];if(-1!=o.uuid.indexOf("FFE0")){i.isConnection=1,i.serviceId=o.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 n=0;n<i.characteristics.length;n++){var o=i.characteristics[n];-1!=o.uuid.indexOf("0000FFE1")?t.uuid1=o.uuid:-1!=o.uuid.indexOf("0000FFE2")?t.uuid2=o.uuid:-1!=o.uuid.indexOf("0000FFE3")&&(t.uuid3=o.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 n=t.$tools.ab2hex(i.value,""),o=n.substring(18,19),c=n.substring(19,20),s=n.substring(8,10),r=n.substring(10,12);if("10"==s){var a=parseInt(n.substring(13,18),16),u="kg",d="kg";"1"==c&&(u="斤",d="jin"),"4"==c&&(u="st:lb",d="st",a=1*a+5),"6"==c&&(u="lb",d="lb"),"1"==o&&(a=parseInt(n.substring(13,18),16)/10),"2"==o&&(a=parseInt(n.substring(13,18),16)/100),"3"==o&&(a=parseInt(n.substring(13,18),16)/1e3),"01"==r&&(t.text="您的实时体重是:"+a+u),"02"==r&&(t.text="您的体重是:"+a+u,t.weight=a+d,console.log("稳定体重:",n,t.weight))}"14"==s&&(t.height=parseInt(n.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(n.substring(17,22),16)),console.log("阻抗:",r,parseInt(n.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",n=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:n.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("543d")["default"])},e91e:function(e,t,i){"use strict";(function(e,t){var n=i("4ea4");i("6808");n(i("66fd"));var o=n(i("b0e1"));e.__webpack_require_UNI_MP_PLUGIN__=i,t(o.default)}).call(this,i("bc2e")["default"],i("543d")["createPage"])}},[["e91e","common/runtime","common/vendor"]]]); |