1 line
9.7 KiB
JavaScript
1 line
9.7 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["BLEPages/child/F01PRO"],{"0f3a":function(e,t,i){"use strict";(function(e){var o=i("4ea4");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,s=o(i("9523")),c=i("26cb");function a(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 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 l=requirePlugin("sdkPlugin").AiLink,u={data:function(){return{textW:"",textH:"",height:"",weight:"",imp:0,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(n),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(n),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(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)){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;n=setTimeout((function(){e.macAddr||(clearTimeout(n),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 o=0;o<t.length;o++){var n=t[o];if(-1!=n.uuid.indexOf("FFE0")){i.serviceId=n.uuid,i.isConnection=1,i.getBLEDeviceCharacteristics(i.deviceId,n.uuid),console.log("设备的FFE0的serviceId: ",i.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(t,i){var o=[],n=this;e.getBLEDeviceCharacteristics({deviceId:t,serviceId:i,success:function(s){console.log("服务的特征值成功",s),o=s.characteristics;for(var c=0;c<o.length;c++){var a=o[c];-1!=a.uuid.indexOf("0000FFE1")?n.uuid1=a.uuid:-1!=a.uuid.indexOf("0000FFE2")?n.uuid2=a.uuid:-1!=a.uuid.indexOf("0000FFE3")&&(n.uuid3=a.uuid)}e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:i,characteristicId:n.uuid2,state:!0}),e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:i,characteristicId:n.uuid3,state:!0}),console.log("初始化插件",n.devicesList),n.devicesList[0].serviceId=n.serviceId,l.initPlugin(s.characteristics,n.devicesList[0]),e.onBLECharacteristicValueChange((function(t){var i=l.parseBleData(t.value);if(0==i.status){var o=1==n.info.sex?1:0,s="0x0"+o.toString(16),c="0x"+n.info.age.toString(16),a="0x"+n.info.height.toString(16),r=[1,parseInt(s),parseInt(c),parseInt(a),0];console.log("指令发送成功",r),l.sendDataOfA7(r),console.log("握手成功")}else if(1==i.status){var u=n.$tools.ab2hex(i.data,""),d=u.substring(4,6),f=u.substring(0,2);if(console.log("开始测量",u),"10"==f||"30"==f||"40"==f){var h=parseInt(u.substring(6,12),16),v=parseInt(u.substring(12,14),16).toString(2),g=n.$tools.PrefixZero(v,8).substring(4,8),p=n.$tools.PrefixZero(v,8).substring(0,4),B="kg",m="kg";"0001"==g&&(B="jin",m="斤"),"0110"==g&&(B="lb",m="lb"),"0001"==p&&(h/=10),"0010"==p&&(h/=100),"0011"==p&&(h/=1e3),"01"==d&&(n.textW="您的实时体重是:"+h+m),"02"==d&&(n.textW="您的体重是:"+h+m,n.weight=h+B)}if("14"==f||"41"==f){var b=parseInt(u.substring(4,8),16),I=parseInt(u.substring(10,12),16);"1"==I&&(b/=10),"2"==I&&(b/=100),n.textH="您的身高是:"+b+"cm",n.height=b,console.log("身高模式:",n.height)}"11"==f&&("02"==d&&(n.imp=0),"04"==d&&(n.imp=parseInt(u.substring(8,12),16)),console.log("阻抗:",n.imp)),"15"==f&&("01"==d&&(n.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"==d&&(n.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("体脂数据",n.data01,n.data02),n.BLEResult=Object.assign(n.data01,n.data02)),"80"==f&&(n.BLEResult.weight=n.weight,n.BLEResult.imp=n.imp?n.imp:0,n.BLEResult.ecode=n.macAddr,n.BLEResult.height=n.height?n.height:n.info.height,n.BLEResult.familyid=n.info.id,console.log("体脂成功:",n.BLEResult),0==n.BLEResult.imp?e.showModal({title:"提示",content:"体脂测量失败,是否保存本次测量结果?",cancelText:"放弃",confirmText:"保存",success:function(t){t.confirm?n.handleGetMeasure(n.BLEResult):(console.log("放弃保存"),n.Unload=!0,n.closeBLEConnection(),n.closeBluetoothAdapter(),e.switchTab({url:"/pages/index/index"}))}}):n.handleGetMeasure(n.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=u}).call(this,i("543d")["default"])},"31db":function(e,t,i){"use strict";i.r(t);var o=i("0f3a"),n=i.n(o);for(var s in o)["default"].indexOf(s)<0&&function(e){i.d(t,e,(function(){return o[e]}))}(s);t["default"]=n.a},8729:function(e,t,i){"use strict";i.r(t);var o=i("cb89"),n=i("31db");for(var s in n)["default"].indexOf(s)<0&&function(e){i.d(t,e,(function(){return n[e]}))}(s);var c=i("f0c5"),a=Object(c["a"])(n["default"],o["b"],o["c"],!1,null,"79652519",null,!1,o["a"],void 0);t["default"]=a.exports},"985b":function(e,t,i){"use strict";(function(e,t){var o=i("4ea4");i("6808");o(i("66fd"));var n=o(i("8729"));e.__webpack_require_UNI_MP_PLUGIN__=i,t(n.default)}).call(this,i("bc2e")["default"],i("543d")["createPage"])},cb89: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=[]}},[["985b","common/runtime","common/vendor"]]]); |