adultDeviceApp/unpackage/dist/build/mp-weixin/BLEPages/adult/H01pro.js

1 line
7.5 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/adult/H01pro"],{"0d79":function(e,t,o){"use strict";o.r(t);var n=o("2e77"),i=o.n(n);for(var c in n)"default"!==c&&function(e){o.d(t,e,(function(){return n[e]}))}(c);t["default"]=i.a},"276b":function(e,t,o){"use strict";o.r(t);var n=o("a875"),i=o("0d79");for(var c in i)"default"!==c&&function(e){o.d(t,e,(function(){return i[e]}))}(c);var r,s=o("f0c5"),a=Object(s["a"])(i["default"],n["b"],n["c"],!1,null,"56eb894e",null,!1,n["a"],r);t["default"]=a.exports},"2e77":function(e,t,o){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var n,i=o("26cb");function c(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?c(Object(o),!0).forEach((function(t){s(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):c(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function s(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var a={data:function(){return{textW:"",textH:"",height:"",weight:"",imp:0,macAddr:"",deviceId:"",serviceId:"",readId:"",writeId:"",notifyId:"",Unload:!1,isConnection:0}},computed:r(r({},(0,i.mapState)(["user","isConnected","isBluetoothTyle"])),{},{info:function(){return this.user}}),onUnload:function(){var e=this;e.Unload||(e.stopBluetoothDevicesDiscovery(),clearTimeout(n),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 o=this;o.textW="",o.textH="",t&&t.deviceId&&(o.macAddr=t.deviceId,o.deviceId=t.deviceId,o.createBLEConnection()),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()},fail:function(e){t.isConnection=2,t.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")}})},onBLEConnectionStateChange:function(){var t=this;e.onBLEConnectionStateChange((function(e){console.log("监听蓝牙连接状态",e.connected),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){console.log("开始监听寻找到新设备的事件",e),e.devices.forEach((function(e){if((e.name||e.localName)&&-1!=e.deviceId.indexOf(t.deviceId)){t.stopBluetoothDevicesDiscovery(),clearTimeout(n);var o=e.advertisData.slice(-6);e.mac=new Uint8Array(o);var i=Array.from(e.mac);return e.macAddr=t.$tools.ab2hex(i,":").toUpperCase(),t.deviceId=e.macAddr,t.macAddr=e.macAddr,void t.createBLEConnection()}}))})),t.handleMyTime()},handleMyTime:function(){var e=this;n=setTimeout((function(){e.macAddr||(clearTimeout(n),e.Unload=!0,e.isConnection=2,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){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("FFE0")){o.serviceId=i.uuid,o.isConnection=1,o.getBLEDeviceCharacteristics(o.deviceId,i.uuid),console.log("设备的FFE0的serviceId ",o.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(t,o){var n=[],i=this;e.getBLEDeviceCharacteristics({deviceId:t,serviceId:o,success:function(c){console.log("服务的特征值成功",c),n=c.characteristics;for(var r=0;r<n.length;r++){var s=n[r];-1!=s.uuid.indexOf("FFE1")&&(1==s.properties.notify&&(i.notifyId=s.uuid),1==s.properties.write&&(i.writeId=s.uuid),s.properties.read&&(i.readId=s.uuid))}e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:o,characteristicId:i.notifyId,state:!0}),e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:o,characteristicId:i.writeId,state:!0}),e.onBLECharacteristicValueChange((function(t){var o=i.$tools.ab2hex(t.value,""),n=parseInt(o.substring(4,8),16)/100,c=parseInt(o.substring(30,34),16)/10,r=o.substring(28,30)+o.substring(34,36),s=parseInt(r,16);i.imp=s,i.textW="您的体重是:"+n+"kg",i.textH="您的身高是:"+c+"cm",i.weight=n+"kg",i.height=c,console.log("测量完成",i.weight,i.height,i.imp),0==s?e.showModal({title:"提示",content:"体脂测量失败,是否保存本次测量结果?",cancelText:"放弃",confirmText:"保存",success:function(t){t.confirm?i.handleGetMeasure():(i.Unload=!0,i.closeBLEConnection(),i.closeBluetoothAdapter(),e.navigateBack({delta:1}))}}):i.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,ecode:t.macAddr,height:t.height?t.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.height?t.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(){var e=this;e.textW="",e.textH="",e.Unload=!0,e.Unload=!0,e.stopBluetoothDevicesDiscovery(),e.closeBLEConnection(),e.closeBluetoothAdapter()},closeBluetoothAdapter:function(){e.closeBluetoothAdapter({success:function(e){console.log("蓝牙模块关闭成功")}})},closeBLEConnection:function(){var t=this;e.closeBLEConnection({deviceId:t.deviceId,success:function(e){console.log("断开蓝牙连接成功")}})}}};t.default=a}).call(this,o("543d")["default"])},9586:function(e,t,o){"use strict";(function(e){o("0d2f");n(o("66fd"));var t=n(o("276b"));function n(e){return e&&e.__esModule?e:{default:e}}wx.__webpack_require_UNI_MP_PLUGIN__=o,e(t.default)}).call(this,o("543d")["createPage"])},a875:function(e,t,o){"use strict";var n;o.d(t,"b",(function(){return i})),o.d(t,"c",(function(){return c})),o.d(t,"a",(function(){return n}));var i=function(){var e=this,t=e.$createElement;e._self._c},c=[]}},[["9586","common/runtime","common/vendor"]]]);