1 line
9.4 KiB
JavaScript
1 line
9.4 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["pageTwo/devices/F01PRO"],{"1b04":function(e,t,o){"use strict";o.d(t,"b",(function(){return n})),o.d(t,"c",(function(){return i})),o.d(t,"a",(function(){}));var n=function(){var e=this.$createElement;this._self._c},i=[]},"65dc":function(e,t,o){"use strict";o.r(t);var n=o("e9d1"),i=o.n(n);for(var s in n)["default"].indexOf(s)<0&&function(e){o.d(t,e,(function(){return n[e]}))}(s);t["default"]=i.a},ad58:function(e,t,o){"use strict";o.r(t);var n=o("1b04"),i=o("65dc");for(var s in i)["default"].indexOf(s)<0&&function(e){o.d(t,e,(function(){return i[e]}))}(s);var c=o("828b"),r=Object(c["a"])(i["default"],n["b"],n["c"],!1,null,"5409745b",null,!1,n["a"],void 0);t["default"]=r.exports},ccd9:function(e,t,o){"use strict";(function(e,t){var n=o("47a9");o("bad8");n(o("3240"));var i=n(o("ad58"));e.__webpack_require_UNI_MP_PLUGIN__=o,t(i.default)}).call(this,o("3223")["default"],o("df3c")["createPage"])},e9d1:function(e,t,o){"use strict";(function(e){var n=o("47a9");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i=n(o("7ca3")),s=o("8f59");function c(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}return o}function r(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?c(Object(o),!0).forEach((function(t){(0,i.default)(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):c(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}var a=requirePlugin("sdkPlugin").AiLink,u={data:function(){return{textW:"",textH:"",textImp:"",height:"",weight:"",imp:0,macAddr:"",deviceId:"",serviceId:"",readId:"",writeId:"",notifyId:"",isSend:!0,Unload:!1,isConnection:0,data01:{},data02:{},BLEResult:{}}},computed:r(r({},(0,s.mapState)(["user","isConnected","isBluetoothTyle"])),{},{userInfo:function(){return this.user}}),onUnload:function(){console.log("F01PRO:onUnload-"+this.Unload),this.Unload||(clearTimeout(void 0),this.closeBLEConnection(),this.closeBluetoothAdapter(),this.$store.state.devicesList2=[],console.log("页面返回onUnload"))},watch:{isConnected:function(){this.isConnected||(console.log("F01PRO:isConnected-"+this.isConnected),this.handleBack(),this.isConnection=2)},isBluetoothTyle:function(){this.isBluetoothTyle||(console.log("F01PRO:isBluetoothTyle-"+this.isBluetoothTyle),this.handleBack(),this.isConnection=2)}},onLoad:function(t){var o=this;o.textW="",o.textH="",console.log("options",t),t&&t.deviceId&&(o.deviceId=t.deviceId,o.createBLEConnection()),o.onBLEConnectionStateChange(),e.onBluetoothAdapterStateChange((function(e){o.$store.commit("changeBluetooth",e.available)}))},methods:{openBluetoothAdapter:function(){var t=this;t.textW="",t.textH="",t.isSend=!0,t.Unload=!1,e.openBluetoothAdapter({success:function(e){t.isConnection=0,t.startBluetoothDeviceDiscovery(),console.log("初始化蓝牙成功:"+e.errMsg)},fail:function(e){t.isConnection=2,t.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")}})},onBLEConnectionStateChange:function(){var t=this;e.onBLEConnectionStateChange((function(e){console.log("F01PRO:onBLEConnectionStateChange-"+t.Unload),e.connected||(t.Unload=!0,t.isConnection=2,clearTimeout(void 0),t.closeBLEConnection(),t.closeBluetoothAdapter()),t.$store.commit("changeConnected",e.connected)}))},startBluetoothDeviceDiscovery:function(){var t=this;e.startBluetoothDevicesDiscovery({allowDuplicatesKey:!1,interval:500,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_")||-1!=e.name.indexOf("PCF01")||e.localName&&(-1!=e.localName.indexOf("AiLink_")||-1!=e.localName.indexOf("PCF01")))&&(clearTimeout(void 0),-1!=e.deviceId.indexOf(t.deviceId))){t.stopBluetoothDevicesDiscovery(),t.deviceId=e.deviceId;var o=t.$store.state.devicesList2,n=t.$tools.inArray(o,"deviceId",e.deviceId);return-1===n?t.$store.state.devicesList2.push(e):t.$store.state.devicesList2[n]=e,void t.createBLEConnection()}}))}))},stopBluetoothDevicesDiscovery:function(){e.stopBluetoothDevicesDiscovery({success:function(e){console.log("停止搜索蓝牙设备",e)}})},createBLEConnection:function(){var t=this;e.createBLEConnection({deviceId:t.deviceId,success:function(e){console.log("设备连接成功,获取设备的services",e),t.isConnection=0,t.getBLEDeviceServices()},fail:function(e){t.isConnection=2,console.log("设备连接失败,请重新连接",e)}})},getBLEDeviceServices:function(){var t=[],o=this;e.getBLEDeviceServices({deviceId:o.deviceId,success:function(e){console.log("获取设备的UUID成功",e),t=e.services;for(var n=0;n<t.length;n++){var i=t[n];if(-1!=i.uuid.indexOf("FFE0")){o.serviceId=i.uuid,o.isConnection=1,o.getBLEDeviceCharacteristics(o.deviceId,i.uuid),console.log("设备的FFE0的serviceId: ",o.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(t,o){var n=[],i=this;e.getBLEDeviceCharacteristics({deviceId:t,serviceId:o,success:function(s){console.log("服务的特征值成功",s),n=s.characteristics;for(var c=0;c<n.length;c++){var r=n[c];-1!=r.uuid.indexOf("0000FFE1")?i.uuid1=r.uuid:-1!=r.uuid.indexOf("0000FFE2")?i.uuid2=r.uuid:-1!=r.uuid.indexOf("0000FFE3")&&(i.uuid3=r.uuid)}e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:o,characteristicId:i.uuid2,state:!0}),e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:o,characteristicId:i.uuid3,state:!0}),console.log("初始化插件",i.$store.state.devicesList2),i.$store.state.devicesList2[0].serviceId=i.serviceId,a.initPlugin(s.characteristics,i.$store.state.devicesList2[0]),e.onBLECharacteristicValueChange((function(e){var t=a.parseBleData(e.value);if(console.log("bleData",t),0==t.status){var o=1==i.userInfo.gender?1:0,n="0x0"+o.toString(16),s="0x"+i.userInfo.age.toString(16),c="0x"+i.userInfo.height.toString(16),r=[1,parseInt(n),parseInt(s),parseInt(c),0];a.sendDataOfA7(r),console.log("握手成功",r)}else if(1==t.status){var u=i.$tools.ab2hex(t.data,""),l=u.substring(4,6),d=u.substring(0,2);if(console.log("开始测量",u),"03"==d){console.log("MCU主动请求用户数据");var f=1==i.userInfo.gender?1:0,h="0x0"+f.toString(16),g="0x"+i.userInfo.age.toString(16),v="0x"+i.userInfo.height.toString(16),p=[1,parseInt(h),parseInt(g),parseInt(v),0];a.sendDataOfA7(p)}if("10"==d||"30"==d||"40"==d){var I=parseInt(u.substring(6,12),16),B=parseInt(u.substring(12,14),16).toString(2),b=i.$tools.PrefixZero(B,8).substring(4,8),m=i.$tools.PrefixZero(B,8).substring(0,4),C="kg";"0001"==b&&(C="斤"),"0110"==b&&(C="lb"),"0001"==m&&(I/=10),"0010"==m&&(I/=100),"0011"==m&&(I/=1e3),"01"==l&&(i.textW="您的实时体重是:"+I+C),"02"==l&&(i.textW="您的体重是:"+I+C,i.weight=I+C)}if("14"==d||"41"==d){var L=parseInt(u.substring(4,8),16),O=parseInt(u.substring(10,12),16);"1"==O&&(L/=10),"2"==O&&(L/=100),i.textH="您的身高是:"+L+"cm",i.height=L,console.log("身高模式:",i.height)}"11"==d&&("01"==l&&(i.textImp="正在测量体脂:请双手紧握扶手"),"02"==l&&(i.imp=0,i.textImp=""),"04"==l&&(i.textImp="",i.imp=parseInt(u.substring(8,12),16)),console.log("阻抗:",i.imp)),"15"==d&&("01"==l&&(i.data01={bodyage:parseInt(u.substring(26,28),16),fat_r:parseInt(u.substring(6,10),16)/10,muscle:parseInt(u.substring(18,22),16)/10,kcal:parseInt(u.substring(22,26),16),visceral:parseInt(u.substring(14,18),16),sfr:parseInt(u.substring(10,14),16)/10}),"02"==l&&(i.data02={water:parseInt(u.substring(10,14),16)/10,bone:parseInt(u.substring(6,10),16)/10,fatlevlval:parseInt(u.substring(24,26),16)/10,protein:parseInt(u.substring(14,18),16)/10,bmi:parseInt(u.substring(18,22),16)/10}),console.log("体脂数据",i.data01,i.data02),i.BLEResult.info=Object.assign(i.data01,i.data02)),"80"==d&&(i.BLEResult.weight=i.weight,i.BLEResult.adc=i.imp?i.imp:0,i.BLEResult.height=(i.height?i.height:i.userInfo.height)+"cm",i.BLEResult.aud_id=i.userInfo.id,console.log("体脂成功:",i.BLEResult),i.handleGetMeasure(i.BLEResult))}}))},fail:function(e){console.log("获取特征值失败:",JSON.stringify(e))}})},handleGetMeasure:function(t){console.log("保存结果");var o=this;o.$model.getmeasurefunit(t).then((function(t){0==t.code?(o.$store.dispatch("getUserInfo",{aud_id:e.getStorageSync("userid")}),o.$store.dispatch("getResult",{aud_id:e.getStorageSync("userid")}),setTimeout((function(){e.showToast({title:"测量成功"})}),500)):e.showToast({title:t.message,icon:"error"}),o.Unload=!0,setTimeout((function(){o.closeBLEConnection(),o.closeBluetoothAdapter(),o.$store.state.devicesList2=[],e.switchTab({url:"/pages/home/home"})}),1e3)}))},closeBluetoothAdapter:function(){e.closeBluetoothAdapter({success:function(e){console.log("F01PRO:蓝牙模块关闭成功")}})},handleBack:function(){this.Unload=!0,console.log("F01PRO:handleBack"),this.stopBluetoothDevicesDiscovery(),this.closeBLEConnection(),this.closeBluetoothAdapter(),this.$store.state.devicesList2=[]},closeBLEConnection:function(){e.closeBLEConnection({deviceId:this.deviceId,success:function(e){console.log("F01PRO:断开蓝牙连接成功")}})}}};t.default=u}).call(this,o("df3c")["default"])}},[["ccd9","common/runtime","common/vendor"]]]); |