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

1 line
9.9 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/F01PRO"],{"15cf":function(e,t,n){"use strict";(function(e){var i=n("47a9");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var o,s=i(n("7ca3")),c=n("8f59");function a(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,i)}return n}function r(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?a(Object(n),!0).forEach((function(t){(0,s.default)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):a(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,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(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 n=this;e.setNavigationBarColor({frontColor:"#ffffff",backgroundColor:this.appTheme}),n.textW="",n.textH="",console.log("options",t),t&&t.deviceId&&(n.macAddr=t.deviceId,n.deviceId=t.deviceId,n.closeBLEConnection(),n.closeBluetoothAdapter(),n.openBluetoothAdapter()),n.onBLEConnectionStateChange(),e.onBluetoothAdapterStateChange((function(e){n.$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_")||-1!=e.name.indexOf("PCF01")||e.localName&&(-1!=e.localName.indexOf("AiLink_")||-1!=e.localName.indexOf("PCF01")))){clearTimeout(o);var n=e.advertisData.slice(-6);e.mac=new Uint8Array(n);var i=Array.from(e.mac);if(i.reverse(),e.macAddr=t.$tools.ab2hex(i,":").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=[],n=this;e.getBLEDeviceServices({deviceId:n.deviceId,success:function(e){console.log("获取设备的UUID成功",e),t=e.services;for(var i=0;i<t.length;i++){var o=t[i];if(-1!=o.uuid.indexOf("FFE0")){n.serviceId=o.uuid,n.isConnection=1,n.getBLEDeviceCharacteristics(n.deviceId,o.uuid),console.log("设备的FFE0的serviceId ",n.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(t,n){var i=[],o=this;e.getBLEDeviceCharacteristics({deviceId:t,serviceId:n,success:function(s){console.log("服务的特征值成功",s),i=s.characteristics;for(var c=0;c<i.length;c++){var a=i[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:n,characteristicId:o.uuid2,state:!0}),e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:n,characteristicId:o.uuid3,state:!0}),console.log("初始化插件",o.devicesList),o.devicesList[0].serviceId=o.serviceId,l.initPlugin(s.characteristics,o.devicesList[0]),e.onBLECharacteristicValueChange((function(t){var n=l.parseBleData(t.value);if(console.log("bleData",n),0==n.status){var i=1==o.info.sex?1:0,s="0x0"+i.toString(16),c="0x"+o.info.age.toString(16),a="0x"+o.info.height.toString(16),r=[1,parseInt(s),parseInt(c),parseInt(a),0];l.sendDataOfA7(r),console.log("握手成功",r)}else if(1==n.status){var u=o.$tools.ab2hex(n.data,""),d=u.substring(4,6),f=u.substring(0,2);if(console.log("开始测量",u),"03"==f){console.log("MCU主动请求用户数据");var h=1==o.info.sex?1:0,g="0x0"+h.toString(16),v="0x"+o.info.age.toString(16),p="0x"+o.info.height.toString(16),m=[1,parseInt(g),parseInt(v),parseInt(p),0];l.sendDataOfA7(m)}if("10"==f||"30"==f||"40"==f){var B=parseInt(u.substring(6,12),16),I=parseInt(u.substring(12,14),16).toString(2),b=o.$tools.PrefixZero(I,8).substring(4,8),C=o.$tools.PrefixZero(I,8).substring(0,4),L="kg",E="kg";"0001"==b&&(L="jin",E="斤"),"0110"==b&&(L="lb",E="lb"),"0001"==C&&(B/=10),"0010"==C&&(B/=100),"0011"==C&&(B/=1e3),"01"==d&&(o.textW="您的实时体重是:"+B+E),"02"==d&&(o.textW="您的体重是:"+B+E,o.weight=B+L)}if("14"==f||"41"==f){var x=parseInt(u.substring(4,8),16),y=parseInt(u.substring(10,12),16);"1"==y&&(x/=10),"2"==y&&(x/=100),o.textH="您的身高是:"+x+"cm",o.height=x,console.log("身高模式:",o.height)}"11"==f&&("02"==d&&(o.imp=0),"04"==d&&(o.imp=parseInt(u.substring(8,12),16)),console.log("阻抗:",o.imp)),"15"==f&&("01"==d&&(o.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&&(o.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("体脂数据",o.data01,o.data02),o.BLEResult=Object.assign(o.data01,o.data02)),"80"==f&&(o.BLEResult.weight=o.weight,o.BLEResult.imp=o.imp?o.imp:0,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),0==o.BLEResult.imp?e.showModal({title:"提示",content:"体脂测量失败,是否保存本次测量结果?",cancelText:"放弃",confirmText:"保存",success:function(t){t.confirm?o.handleGetMeasure(o.BLEResult):(console.log("放弃保存"),o.Unload=!0,o.closeBLEConnection(),o.closeBluetoothAdapter(),e.switchTab({url:"/pages/index/index"}))}}):o.handleGetMeasure(o.BLEResult))}}))},fail:function(e){console.log("获取特征值失败:",JSON.stringify(e))}})},handleGetMeasure:function(t){console.log("保存结果");var n=this;n.$model.getmeasuredata(t).then((function(t){0==t.code?(n.$store.dispatch("getUserInfo",{familyid:n.info.familyid}),n.$store.dispatch("getResult",{birthday:n.info.birthday,familyid:n.info.familyid,height:n.height?n.height:n.info.height,sex:n.info.sex}),n.$tools.msg("测量成功")):(console.log("测量失败",t.message),n.$tools.msg(t.message)),n.Unload=!0,setTimeout((function(){n.closeBLEConnection(),n.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,n("df3c")["default"])},2449:function(e,t,n){"use strict";n.d(t,"b",(function(){return i})),n.d(t,"c",(function(){return o})),n.d(t,"a",(function(){}));var i=function(){var e=this.$createElement;this._self._c},o=[]},4166:function(e,t,n){"use strict";(function(e,t){var i=n("47a9");n("6846");i(n("3240"));var o=i(n("ca80"));e.__webpack_require_UNI_MP_PLUGIN__=n,t(o.default)}).call(this,n("3223")["default"],n("df3c")["createPage"])},c101:function(e,t,n){"use strict";n.r(t);var i=n("15cf"),o=n.n(i);for(var s in i)["default"].indexOf(s)<0&&function(e){n.d(t,e,(function(){return i[e]}))}(s);t["default"]=o.a},ca80:function(e,t,n){"use strict";n.r(t);var i=n("2449"),o=n("c101");for(var s in o)["default"].indexOf(s)<0&&function(e){n.d(t,e,(function(){return o[e]}))}(s);var c=n("828b"),a=Object(c["a"])(o["default"],i["b"],i["c"],!1,null,"a4310f7e",null,!1,i["a"],void 0);t["default"]=a.exports}},[["4166","common/runtime","common/vendor"]]]);