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

1 line
8.0 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/L01A"],{"05d8":function(e,t,o){"use strict";o.r(t);var n=o("0de0"),i=o.n(n);for(var c in n)["default"].indexOf(c)<0&&function(e){o.d(t,e,(function(){return n[e]}))}(c);t["default"]=i.a},"0de0":function(e,t,o){"use strict";(function(e){var n=o("4ea4");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i,c=n(o("9523")),s=o("26cb");function a(e,t){var o=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),o.push.apply(o,n)}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 u={data:function(){return{text:"",height:"",weight:"",imp:0,type:1,uuid1:"",uuid2:"",uuid3:"",macAddr:"",deviceId:"",serviceId:"",Unload:!1,pageNav:!1,stopblue:!0,isConnection:0}},computed:r(r({},(0,s.mapState)(["user","isConnected","isBluetoothTyle","appTheme"])),{},{info:function(){return this.user}}),onUnload:function(){this.Unload||(this.stopBluetoothDevicesDiscovery(),clearTimeout(i),this.closeBLEConnection(),this.closeBluetoothAdapter(),e.switchTab({url:"/pages/index/index"}),console.log("测量页返回1"))},onLoad:function(t){var o=this;e.setNavigationBarColor({frontColor:"#ffffff",backgroundColor:this.appTheme}),o.text="",t&&t.deviceId&&(o.deviceId=t.deviceId,o.closeBLEConnection(),o.closeBluetoothAdapter(),o.openBluetoothAdapter()),o.onBLEConnectionStateChange(),e.onBluetoothAdapterStateChange((function(e){o.$store.commit("changeBluetooth",e.available)}))},watch:{isConnected:function(){this.isConnected||(this.handleBack(),this.isConnection=2)},isBluetoothTyle:function(){this.isBluetoothTyle||(this.handleBack(),this.isConnection=2)},stopblue:function(){var t=this;t.stopblue||(console.log("停止成功",t.weight,t.imp),0==t.imp?e.showModal({title:"提示",content:"体脂测量失败,是否保存本次测量结果?",cancelText:"放弃",confirmText:"保存",success:function(o){o.confirm?(t.imp=0,t.handleGetMeasure()):(t.Unload=!0,t.startBluetoothDeviceDiscovery(),t.closeBLEConnection(),t.closeBluetoothAdapter(),e.switchTab({url:"/pages/index/index"}))}}):t.handleGetMeasure())}},methods:{openBluetoothAdapter:function(){var t=this;t.text="",t.stopblue=!0,e.openBluetoothAdapter({success:function(e){t.isConnection=0,t.startBluetoothDeviceDiscovery()},fail:function(e){t.isConnection=2,t.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")}})},startBluetoothDeviceDiscovery:function(){var t=this;e.startBluetoothDevicesDiscovery({allowDuplicatesKey:!1,interval:100,services:[],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("FitTrack")||-1!==e.name.indexOf("SWAN"))){clearTimeout(i);var o=e.advertisData.slice(2,8);e.mac=new Uint8Array(o);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))return t.stopBluetoothDevicesDiscovery(),t.macAddr=e.macAddr,t.deviceId=e.deviceId,void t.createBLEConnection()}}))})),t.handleMyTime()},handleMyTime:function(){var e=this;i=setTimeout((function(){e.macAddr||(clearTimeout(i),e.Unload=!0,e.isConnection=2,e.closeBLEConnection(),e.closeBluetoothAdapter())}),2e4)},stopBluetoothDevicesDiscovery:function(){e.stopBluetoothDevicesDiscovery({success:function(e){console.log("停止搜索蓝牙设备",e)}})},onBLEConnectionStateChange:function(){var t=this;e.onBLEConnectionStateChange((function(e){console.log("监听蓝牙连接状态",e.connected),e.connected||(t.Unload=!0,t.isConnection=2,clearTimeout(i),t.closeBLEConnection(),t.closeBluetoothAdapter()),t.$store.commit("changeConnected",e.connected)}))},createBLEConnection:function(){var t=this;e.createBLEConnection({deviceId:t.deviceId,success:function(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 n=0;n<t.length;n++){var i=t[n];if(-1!=i.uuid.indexOf("FFB0")){o.isConnection=1,o.serviceId=i.uuid,o.getBLEDeviceCharacteristics(),console.log("设备的FFB0的serviceId "+o.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(){var t=this;e.getBLEDeviceCharacteristics({deviceId:t.deviceId,serviceId:t.serviceId,success:function(e){console.log("服务的特征值成功",e);for(var o=0;o<e.characteristics.length;o++){var n=e.characteristics[o];-1!=n.uuid.indexOf("FFB1")?t.uuid1=n.uuid:-1!=n.uuid.indexOf("FFB2")?(t.uuid2=n.uuid,t.notifyBLECharacteristicValue()):-1!=n.uuid.indexOf("FFB3")&&(t.uuid3=n.uuid)}},fail:function(e){console.log("获取特征值失败:",JSON.stringify(e))}})},notifyBLECharacteristicValue:function(){var t=this;e.notifyBLECharacteristicValueChange({state:!0,deviceId:t.deviceId,serviceId:t.serviceId,characteristicId:t.uuid2,success:function(o){e.onBLECharacteristicValueChange((function(e){var o=t.$tools.ab2hex(e.value,""),n=o.substring(4,6);console.log("数据",o),"ce"==o.substring(12,14)&&(t.text="您的实时体重是:"+parseInt(o.substring(4,8),16)/10+"kg"),"ca"==o.substring(12,14)&&(t.weight=parseInt(o.substring(4,8),16)/10+"kg",t.text="您的稳定体重是:"+parseInt(o.substring(4,8),16)/10+"kg"),"fd"==n&&("01"==o.substring(6,8)&&(t.imp=parseInt(o.substring(8,12),16),t.handleGetMeasure()),"ff"==o.substring(6,8)&&(t.imp=0)),"fe"==n&&"10"==o.substring(6,8)&&(console.log("测量完成",t.weight,t.imp),t.stopblue=!1)}))},fail:function(e){console.log("测量失败",e.value)}})},handleGetMeasure:function(){var t=this;t.$model.getmeasure({weight:t.weight,imp:t.imp,ecode:t.macAddr,height:t.info.height,familyid:t.info.familyid}).then((function(o){0==o.code?(t.$tools.msg("测量成功"),t.$store.dispatch("getUserInfo",{familyid:t.info.familyid}),t.$store.dispatch("getResult",{birthday:t.info.birthday,familyid:t.info.familyid,height:t.info.height,sex:t.info.sex})):(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)}))},handleBack:function(){this.Unload=!0,clearTimeout(i),this.stopBluetoothDevicesDiscovery(),this.closeBLEConnection(),this.closeBluetoothAdapter()},closeBluetoothAdapter:function(){e.closeBluetoothAdapter({success:function(e){console.log("蓝牙模块关闭成功")}})},closeBLEConnection:function(){e.closeBLEConnection({deviceId:this.deviceId,success:function(e){console.log("断开蓝牙连接成功")}})}}};t.default=u}).call(this,o("543d")["default"])},"2a12":function(e,t,o){"use strict";o.d(t,"b",(function(){return n})),o.d(t,"c",(function(){return i})),o.d(t,"a",(function(){}));var n=function(){var e=this.$createElement;this._self._c},i=[]},"636a":function(e,t,o){"use strict";o.r(t);var n=o("2a12"),i=o("05d8");for(var c in i)["default"].indexOf(c)<0&&function(e){o.d(t,e,(function(){return i[e]}))}(c);var s=o("f0c5"),a=Object(s["a"])(i["default"],n["b"],n["c"],!1,null,"68711b68",null,!1,n["a"],void 0);t["default"]=a.exports},a2c6:function(e,t,o){"use strict";(function(e,t){var n=o("4ea4");o("6808");n(o("66fd"));var i=n(o("636a"));e.__webpack_require_UNI_MP_PLUGIN__=o,t(i.default)}).call(this,o("bc2e")["default"],o("543d")["createPage"])}},[["a2c6","common/runtime","common/vendor"]]]);