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

1 line
8.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/J01"],{"344d":function(e,t,o){"use strict";o.r(t);var i=o("35ce"),n=o.n(i);for(var c in i)["default"].indexOf(c)<0&&function(e){o.d(t,e,(function(){return i[e]}))}(c);t["default"]=n.a},"35ce":function(e,t,o){"use strict";(function(e){var i=o("47a9");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,c=i(o("7ca3")),s=o("8f59");function a(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);t&&(i=i.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,i)}return o}function r(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?a(Object(o),!0).forEach((function(t){(0,c.default)(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):a(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}var l=requirePlugin("sdkPlugin").AiLink,u={data:function(){return{textW:"",textH:"",height:"",weight:"",imp:0,macAddr:"",deviceId:"",serviceId:"",readId:"",writeId:"",notifyId:"",Unload:!1,devicesList:[],isConnection:0,data01:{},data02:{},BLEResult:{}}},computed:r(r({},(0,s.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 o=this;o.textW="",o.textH="",o.imp=0,e.setNavigationBarColor({frontColor:"#ffffff",backgroundColor:this.appTheme}),console.log("options",t),t&&t.deviceId&&(o.macAddr=t.deviceId,o.deviceId=t.deviceId,o.closeBLEConnection(),o.closeBluetoothAdapter(),o.openBluetoothAdapter()),o.onBLEConnectionStateChange(),e.onBluetoothAdapterStateChange((function(e){o.$store.commit("changeBluetooth",e.available)}))},methods:{openBluetoothAdapter:function(){var t=this;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.toLowerCase().indexOf("ailink")||e.localName&&-1!=e.localName.toLowerCase().indexOf("ailink"))){clearTimeout(n);var o=e.advertisData.slice(-6);e.mac=new Uint8Array(o);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;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=[],o=this;e.getBLEDeviceServices({deviceId:o.deviceId,success:function(e){console.log("获取设备的UUID成功",e),t=e.services;for(var i=0;i<t.length;i++){var n=t[i];if(-1!=n.uuid.indexOf("FFE0")){o.serviceId=n.uuid,o.isConnection=1,o.getBLEDeviceCharacteristics(o.deviceId,n.uuid),console.log("设备的FFE0的serviceId ",o.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(t,o){var i=[],n=this;e.getBLEDeviceCharacteristics({deviceId:t,serviceId:o,success:function(c){console.log("服务的特征值成功",c),i=c.characteristics;for(var s=0;s<i.length;s++){var a=i[s];-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:o,characteristicId:n.uuid2,state:!0}),e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:o,characteristicId:n.uuid3,state:!0}),n.devicesList[0].serviceId=n.serviceId,l.initPlugin(c.characteristics,n.devicesList[0]),e.onBLECharacteristicValueChange((function(t){var o=l.parseBleData(t.value);if(0==o.status){var i=[6,1,0];console.log("指令发送成功",i),l.sendDataOfA7(i),console.log("握手成功")}else if(1==o.status){var c=n.$tools.ab2hex(o.data,""),s=c.substring(0,2),a=c.substring(4,6);if(console.log("value",c),"10"==s||"30"==s||"40"==s){var r=parseInt(c.substring(6,12),16),u=parseInt(c.substring(12,14),16).toString(2),d=n.$tools.PrefixZero(u,8).substring(4,8),f=n.$tools.PrefixZero(u,8).substring(0,4),h="kg",v="kg";"0001"==d&&(h="jin",v="斤"),"0110"==d&&(h="lb",v="lb"),"0001"==f&&(r/=10),"0010"==f&&(r/=100),"0011"==f&&(r/=1e3),"01"==a&&(n.textW="您的实时体重是:"+r+v),"02"==a&&(n.textW="您的体重是:"+r+v,n.weight=r+h,console.log("体重",c,n.weight))}if("14"==s||"41"==s){var g=parseInt(c.substring(4,8),16),p=parseInt(c.substring(10,12),16);"1"==p&&(g/=10),"2"==p&&(g/=100),n.textH="您的身高是:"+g+"cm",n.height=g,console.log("身高模式:",n.height)}"11"==s&&("02"==a&&(n.imp=0),"03"!=a&&"04"!=a||(n.imp=parseInt(c.substring(8,16),16)),console.log("阻抗:",n.imp)),"80"==s&&(console.log("测量完成"),0==n.imp?e.showModal({title:"提示",content:"体脂测量失败,是否保存本次测量结果?",cancelText:"放弃",confirmText:"保存",success:function(t){t.confirm?(n.imp=0,n.handleGetMeasure()):(console.log("放弃保存"),n.Unload=!0,n.closeBLEConnection(),n.closeBluetoothAdapter(),e.switchTab({url:"/pages/index/index"}))}}):n.handleGetMeasure())}}))},fail:function(e){console.log("获取特征值失败:",JSON.stringify(e))}})},handleGetMeasure:function(){console.log("保存结果");var t=this;t.$model.getmeasure({weight:t.weight,imp:t.imp?t.imp:0,ecode:t.macAddr,height:t.height?t.height:t.info.height,familyid:t.info.familyid}).then((function(o){0==o.code?(t.$store.dispatch("getUserInfo",{familyid:t.info.familyid}),t.$store.dispatch("getResult",{birthday:t.info.birthday,familyid:t.info.familyid,height:t.height,sex:t.info.sex}),t.$tools.msg("测量成功")):(console.log("测量失败",o.message),t.$tools.msg(o.message)),t.Unload=!0,setTimeout((function(){t.closeBLEConnection(),t.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,o("df3c")["default"])},"43cf":function(e,t,o){},"4e6f":function(e,t,o){"use strict";o.d(t,"b",(function(){return i})),o.d(t,"c",(function(){return n})),o.d(t,"a",(function(){}));var i=function(){var e=this.$createElement;this._self._c},n=[]},"537a":function(e,t,o){"use strict";o.r(t);var i=o("4e6f"),n=o("344d");for(var c in n)["default"].indexOf(c)<0&&function(e){o.d(t,e,(function(){return n[e]}))}(c);o("b6b3");var s=o("828b"),a=Object(s["a"])(n["default"],i["b"],i["c"],!1,null,"5500a52a",null,!1,i["a"],void 0);t["default"]=a.exports},b6b3:function(e,t,o){"use strict";var i=o("43cf"),n=o.n(i);n.a},df78:function(e,t,o){"use strict";(function(e,t){var i=o("47a9");o("6846");i(o("3240"));var n=i(o("537a"));e.__webpack_require_UNI_MP_PLUGIN__=o,t(n.default)}).call(this,o("3223")["default"],o("df3c")["createPage"])}},[["df78","common/runtime","common/vendor"]]]);