1 line
9.2 KiB
JavaScript
1 line
9.2 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["BLEPages/child/PCMeta20"],{"0fc1":function(e,t,i){"use strict";i.r(t);var n=i("6056"),o=i("619b");for(var s in o)["default"].indexOf(s)<0&&function(e){i.d(t,e,(function(){return o[e]}))}(s);var c=i("828b"),a=Object(c["a"])(o["default"],n["b"],n["c"],!1,null,"2a33b3f1",null,!1,n["a"],void 0);t["default"]=a.exports},6056: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=[]},"619b":function(e,t,i){"use strict";i.r(t);var n=i("6a98"),o=i.n(n);for(var s in n)["default"].indexOf(s)<0&&function(e){i.d(t,e,(function(){return n[e]}))}(s);t["default"]=o.a},"6a98":function(e,t,i){"use strict";(function(e){var n=i("47a9");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var o,s=n(i("7ca3")),c=i("8f59");function a(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 r(e){for(var t=1;t<arguments.length;t++){var i=null!=arguments[t]?arguments[t]:{};t%2?a(Object(i),!0).forEach((function(t){(0,s.default)(e,t,i[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(i)):a(Object(i)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(i,t))}))}return e}var u=requirePlugin("sdkPlugin").AiLink,l={data:function(){return{textW:"",textH:"",height:"",weight:"",imp:550,macAddr:"",deviceId:"",serviceId:"",readId:"",writeId:"",notifyId:"",isSend:!0,Unload:!1,devicesList:[],isConnection:0,data01:{},data02:{},BLEResult:{}}},computed:r(r({},(0,c.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("页面返回onUnload"))},watch:{isConnected:function(){this.isConnected||(this.handleBack(),this.isConnection=2)},isBluetoothTyle:function(){this.isBluetoothTyle||(this.handleBack(),this.isConnection=2)}},onLoad:function(t){var i=this;e.setNavigationBarColor({frontColor:"#ffffff",backgroundColor:this.appTheme}),i.textW="",i.textH="",console.log("options",t),t&&t.deviceId&&(i.macAddr=t.deviceId,i.deviceId=t.deviceId,i.closeBLEConnection(),i.closeBluetoothAdapter(),i.openBluetoothAdapter()),i.onBLEConnectionStateChange(),e.onBluetoothAdapterStateChange((function(e){i.$store.commit("changeBluetooth",e.available)}))},methods:{openBluetoothAdapter:function(){var t=this;t.textW="",t.textH="",t.isSend=!0,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("蓝牙连接状态",JSON.stringify(e)),e.connected||(t.Unload=!0,t.isConnection=2,clearTimeout(o),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_")||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)){t.stopBluetoothDevicesDiscovery(),t.deviceId=e.deviceId,t.macAddr=e.macAddr;var s=t.devicesList,c=t.$tools.inArray(s,"deviceId",e.deviceId);return-1===c?t.devicesList.push(e):t.devicesList[c]=e,void t.createBLEConnection()}}}))})),t.handleMyTime()},handleMyTime:function(){var e=this;o=setTimeout((function(){e.macAddr||(clearTimeout(o),e.Unload=!0,e.isConnection=2,e.devicesList=[],e.closeBLEConnection(),e.closeBluetoothAdapter())}),2e4)},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=[],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.serviceId=o.uuid,i.isConnection=1,i.getBLEDeviceCharacteristics(i.deviceId,o.uuid),console.log("设备的FFE0的serviceId: ",i.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(t,i){var n=[],o=this;e.getBLEDeviceCharacteristics({deviceId:t,serviceId:i,success:function(s){console.log("服务的特征值成功",s),n=s.characteristics;for(var c=0;c<n.length;c++){var a=n[c];-1!=a.uuid.indexOf("0000FFE1")?o.uuid1=a.uuid:-1!=a.uuid.indexOf("0000FFE2")?o.uuid2=a.uuid:-1!=a.uuid.indexOf("0000FFE3")&&(o.uuid3=a.uuid)}e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:i,characteristicId:o.uuid2,state:!0}),e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:i,characteristicId:o.uuid3,state:!0}),console.log("初始化插件",o.devicesList),o.devicesList[0].serviceId=o.serviceId,u.initPlugin(s.characteristics,o.devicesList[0]),e.onBLECharacteristicValueChange((function(e){var t=u.parseBleData(e.value),i="kg",n="kg";if(0==t.status){var s=1==o.info.sex?1:0,c="0x0"+s.toString(16),a="0x"+o.info.age.toString(16),r="0x"+o.info.height.toString(16),l=[1,parseInt(c),parseInt(a),parseInt(r),0];console.log("指令发送成功",l),u.sendDataOfA7(l),console.log("握手成功")}else if(1==t.status){var d=o.$tools.ab2hex(t.data,""),f=d.substring(0,2);if(console.log("开始测量",d,f),"10"==f||"30"==f||"40"==f){var h=parseInt(d.substring(6,12),16),v=d.substring(4,6),g=d.substring(12,13),p=d.substring(13,14);"1"==p&&(i="jin",n="斤"),"1"==g&&(h/=10),"2"==g&&(h/=100),"3"==g&&(h/=1e3),"01"==v&&(o.textW="您的实时体重是:"+h+n),"02"==v&&(o.textW="您的体重是:"+h+n,o.weight=h+i)}if("14"==f||"41"==f){var B=parseInt(d.substring(4,8),16);o.textH="您的身高是:"+B+"cm",o.height=B,console.log("身高模式:",o.height)}if("11"==f){var b=d.substring(4,6);"04"==b&&(o.imp=parseInt(d.substring(8,12),16)),console.log("阻抗:",o.imp)}if("15"==f){var m=d.substring(4,6);"01"==m&&(o.data01={bodyage:parseInt(d.substring(26,28),16),fat_r:parseInt(d.substring(6,10),16)/10,muscle:parseInt(d.substring(18,22),16)/10,kcal:parseInt(d.substring(22,26),16),visceral:parseInt(d.substring(14,18),16),sfr:parseInt(d.substring(10,14),16)/10}),"02"==m&&(o.data02={water:parseInt(d.substring(10,14),16)/10,bone:parseInt(d.substring(6,10),16)/10,fatlevlval:parseInt(d.substring(24,26),16)/10,protein:parseInt(d.substring(14,18),16)/10,bmi:parseInt(d.substring(18,22),16)/10}),console.log("体脂数据",o.data01,o.data02),o.BLEResult=Object.assign(o.data01,o.data02)}"80"==f&&(o.BLEResult.weight=o.weight,o.BLEResult.imp=550,o.BLEResult.ecode=o.macAddr,o.BLEResult.height=o.height?o.height:o.info.height,o.BLEResult.familyid=o.info.id,console.log("体脂成功:",o.BLEResult),o.handleGetMeasure(o.BLEResult))}}))},fail:function(e){console.log("获取特征值失败:",JSON.stringify(e))}})},handleGetMeasure:function(t){console.log("保存结果");var i=this;i.$model.getmeasuredata(t).then((function(t){0==t.code?(i.$store.dispatch("getUserInfo",{familyid:i.info.familyid}),i.$store.dispatch("getResult",{birthday:i.info.birthday,familyid:i.info.familyid,height:i.height?i.height:i.info.height,sex:i.info.sex}),i.$tools.msg("测量成功")):(console.log("测量失败",t.message),i.$tools.msg(t.message)),i.Unload=!0,setTimeout((function(){i.closeBLEConnection(),i.closeBluetoothAdapter(),e.switchTab({url:"/pages/index/index"})}),200)}))},closeBluetoothAdapter:function(){e.closeBluetoothAdapter({success:function(e){console.log("蓝牙模块关闭成功")}})},handleBack:function(){this.Unload=!0,this.stopBluetoothDevicesDiscovery(),this.closeBLEConnection(),this.closeBluetoothAdapter()},closeBLEConnection:function(){e.closeBLEConnection({deviceId:this.deviceId,success:function(e){console.log("断开蓝牙连接成功")}})}}};t.default=l}).call(this,i("df3c")["default"])},fbaa:function(e,t,i){"use strict";(function(e,t){var n=i("47a9");i("6846");n(i("3240"));var o=n(i("0fc1"));e.__webpack_require_UNI_MP_PLUGIN__=i,t(o.default)}).call(this,i("3223")["default"],i("df3c")["createPage"])}},[["fbaa","common/runtime","common/vendor"]]]); |