1 line
9.2 KiB
JavaScript
1 line
9.2 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["BLEPages/adult/F01PRO"],{"4ac6":function(e,t,n){"use strict";n.r(t);var o=n("5448"),i=n.n(o);for(var c in o)"default"!==c&&function(e){n.d(t,e,(function(){return o[e]}))}(c);t["default"]=i.a},5448:function(e,t,n){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var o,i=n("26cb");function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function s(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a=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:s(s({},(0,i.mapState)(["user","isConnected","isBluetoothTyle","appTheme"])),{},{info:function(){return this.user}}),onUnload:function(){var e=this;e.Unload||(e.stopBluetoothDevicesDiscovery(),clearTimeout(o),e.closeBLEConnection(),e.closeBluetoothAdapter(),console.log("页面返回onUnload"))},watch:{isConnected:function(){var e=this;e.isConnected||(e.handleBack(),e.isConnection=2)},isBluetoothTyle:function(){var e=this;e.isBluetoothTyle||(e.handleBack(),e.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.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_")){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 c=t.devicesList,s=t.$tools.inArray(c,"deviceId",e.deviceId);return-1===s?t.devicesList.push(e):t.devicesList[s]=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 o=0;o<t.length;o++){var i=t[o];if(-1!=i.uuid.indexOf("FFE0")){n.serviceId=i.uuid,n.isConnection=1,n.getBLEDeviceCharacteristics(n.deviceId,i.uuid),console.log("设备的FFE0的serviceId: ",n.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(t,n){var o=[],i=this;e.getBLEDeviceCharacteristics({deviceId:t,serviceId:n,success:function(c){console.log("服务的特征值成功",c),o=c.characteristics;for(var s=0;s<o.length;s++){var r=o[s];-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:n,characteristicId:i.uuid2,state:!0}),e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:n,characteristicId:i.uuid3,state:!0}),console.log("初始化插件",i.devicesList),i.devicesList[0].serviceId=i.serviceId,a.initPlugin(c.characteristics,i.devicesList[0]),e.onBLECharacteristicValueChange((function(e){var t=a.parseBleData(e.value),n="kg",o="kg";if(0==t.status){var c=1==i.info.sex?1:0,s="0x0"+c.toString(16),r="0x"+i.info.age.toString(16),u="0x"+i.info.height.toString(16),l=[1,parseInt(s),parseInt(r),parseInt(u),0];console.log("指令发送成功",l),a.sendDataOfA7(l),console.log("握手成功")}else if(1==t.status){var d=i.$tools.ab2hex(t.data,""),f=d.substring(0,2);if(console.log("开始测量",d),"10"==f||"30"==f||"40"==f){var v=parseInt(d.substring(6,12),16),h=d.substring(4,6),g=d.substring(12,13),p=d.substring(13,14);"1"==p&&(n="jin",o="斤"),"1"==g&&(v/=10),"2"==g&&(v/=100),"3"==g&&(v/=1e3),"01"==h&&(i.textW="您的实时体重是:"+v+o),"02"==h&&(i.textW="您的体重是:"+v+o,i.weight=v+n)}if("14"==f||"41"==f){var B=parseInt(d.substring(4,8),16);i.textH="您的身高是:"+B+"cm",i.height=B,console.log("身高模式:",i.height)}if("11"==f){var m=d.substring(4,6);"02"==m&&(i.imp=0),"04"==m&&(i.imp=parseInt(d.substring(8,12),16)),console.log("阻抗:",i.imp)}if("15"==f){var b=d.substring(4,6);"01"==b&&(i.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"==b&&(i.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("体脂数据",i.data01,i.data02),i.BLEResult=Object.assign(i.data01,i.data02)}"80"==f&&(i.BLEResult.weight=i.weight,i.BLEResult.imp=i.imp?i.imp:0,i.BLEResult.ecode=i.macAddr,i.BLEResult.height=i.height?i.height:i.info.height,i.BLEResult.familyid=i.info.id,console.log("体脂成功:",i.BLEResult),i.handleGetMeasure(i.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(){var e=this;e.Unload=!0,e.stopBluetoothDevicesDiscovery(),e.closeBLEConnection(),e.closeBluetoothAdapter()},closeBLEConnection:function(){var t=this;e.closeBLEConnection({deviceId:t.deviceId,success:function(e){console.log("断开蓝牙连接成功")}})}}};t.default=u}).call(this,n("543d")["default"])},"88c8":function(e,t,n){"use strict";(function(e){n("e568");o(n("66fd"));var t=o(n("9924"));function o(e){return e&&e.__esModule?e:{default:e}}wx.__webpack_require_UNI_MP_PLUGIN__=n,e(t.default)}).call(this,n("543d")["createPage"])},"95e9":function(e,t,n){"use strict";var o;n.d(t,"b",(function(){return i})),n.d(t,"c",(function(){return c})),n.d(t,"a",(function(){return o}));var i=function(){var e=this,t=e.$createElement;e._self._c},c=[]},9924:function(e,t,n){"use strict";n.r(t);var o=n("95e9"),i=n("4ac6");for(var c in i)"default"!==c&&function(e){n.d(t,e,(function(){return i[e]}))}(c);var s,r=n("f0c5"),a=Object(r["a"])(i["default"],o["b"],o["c"],!1,null,"7048df86",null,!1,o["a"],s);t["default"]=a.exports}},[["88c8","common/runtime","common/vendor"]]]); |