examTeamApp/unpackage/dist/build/mp-weixin/pageTwo/devices/PCV02.js

1 line
9.2 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([["pageTwo/devices/PCV02"],{"5d72":function(e,t,n){"use strict";n.r(t);var i=n("aa6c"),o=n.n(i);for(var c in i)["default"].indexOf(c)<0&&function(e){n.d(t,e,(function(){return i[e]}))}(c);t["default"]=o.a},"61a8":function(e,t,n){"use strict";(function(e,t){var i=n("47a9");n("30b7");i(n("3240"));var o=i(n("9b8c"));e.__webpack_require_UNI_MP_PLUGIN__=n,t(o.default)}).call(this,n("3223")["default"],n("df3c")["createPage"])},"65f7":function(e,t,n){},"921e":function(e,t,n){"use strict";var i=n("65f7"),o=n.n(i);o.a},"9b8c":function(e,t,n){"use strict";n.r(t);var i=n("d6f9"),o=n("5d72");for(var c in o)["default"].indexOf(c)<0&&function(e){n.d(t,e,(function(){return o[e]}))}(c);n("921e");var s=n("828b"),r=Object(s["a"])(o["default"],i["b"],i["c"],!1,null,"dcbb8bce",null,!1,i["a"],void 0);t["default"]=r.exports},aa6c:function(e,t,n){"use strict";(function(e){var i=n("47a9");Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var o,c=i(n("7ca3")),s=n("8f59");function r(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 a(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?r(Object(n),!0).forEach((function(t){(0,c.default)(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):r(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}var u=0,l=0,d=null,f={data:function(){return{isEnd:!1,isstart:!1,number1:0,number2:0,number3:0,level1:"",level2:"",level3:"",average:"",averageS:"",text:0,LiuS:"",macAddr:"",serviceId:"",deviceId:"",Unload:!1,notify:"",write:"",second:5,standard:"",offset:0,listS:[]}},computed:a(a({},(0,s.mapState)(["user","isConnected","isBluetoothTyle","lungLevel"])),{},{info:function(){return this.user},list:function(){var e="";return this.lungLevel.forEach((function(t){"及格"==t.text&&(e=t.min_val)})),this.standard=e,this.lungLevel}}),onUnload:function(){this.Unload||(clearTimeout(o),this.stopBluetoothDevicesDiscovery(),this.closeBLEConnection(),this.closeBluetoothAdapter(),console.log("页面返回onUnload"))},onLoad:function(t){var n=this;t&&t.deviceId&&(n.deviceId=t.deviceId,n.openBluetoothAdapter()),n.openBluetoothAdapter(),n.onBLEConnectionStateChange(),e.onBluetoothAdapterStateChange((function(e){n.$store.commit("changeBluetooth",e.available)}))},watch:{isConnected:function(){this.isConnected||this.handleBack()},isBluetoothTyle:function(){this.isBluetoothTyle||this.handleBack()},second:function(){this.second<=0&&(u++,this.isstart=!0,this.sendData("FA02A29E"),this.offset=0,this.text=0)},isEnd:function(){if(console.log("结束测量",this.isEnd),this.isEnd){console.log("结束测量2",this.isEnd),this.isstart=!1,this.sendData("FA02A39F"),this.level3=this.handlelenver(this.number2),this.average=(Number(this.number3)+Number(this.number2)+Number(this.number1))/3;for(var e=0,t=0;t<this.listS.length;t++)e+=Number(this.listS[t]);this.averageS=(e/this.listS.length).toFixed(2),console.log(e/this.listS.length)}}},methods:{openBluetoothAdapter:function(){var t=this;u=0,l=0,d=null,t.isEnd=!1,t.text=0,t.number1=0,t.number2=0,t.number3=0,t.level1="",t.level2="",t.level3="",t.average="",t.LiuS="",t.second=5,t.standard="",t.offset=0,e.openBluetoothAdapter({success:function(e){console.log("初始化设备"),t.startBluetoothDeviceDiscovery()},fail:function(e){t.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")}})},startBluetoothDeviceDiscovery:function(){var t=this;e.startBluetoothDevicesDiscovery({allowDuplicatesKey:!0,success:function(e){console.log("开始搜索"),t.onBluetoothDeviceFound()},fail:function(e){t.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")}})},onBluetoothDeviceFound:function(){var t=this;e.onBluetoothDeviceFound((function(e){e.devices.forEach((function(e){if(e.name||e.localName)return-1!=e.name.indexOf("Yihejia_Lung")&&(clearTimeout(o),e.macAddr=e.deviceId,-1!=e.deviceId.indexOf(t.deviceId))?(t.stopBluetoothDevicesDiscovery(),t.createBLEConnection(),void console.log("that.deviceId",t.deviceId,e.deviceId)):void 0}))})),t.handleMyTime()},createBLEConnection:function(){var t=this;e.createBLEConnection({deviceId:t.deviceId,success:function(e){t.countdown(),setTimeout((function(){t.getBLEDeviceServices()}),1500)},fail:function(e){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.getBLEDeviceCharacteristics(),console.log("设备的FFE0的serviceId "+n.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(){var t=this;e.getBLEDeviceCharacteristics({deviceId:t.deviceId,serviceId:t.serviceId,success:function(n){console.log("服务的特征值成功",n);for(var i=0;i<n.characteristics.length;i++){var o=n.characteristics[i];-1!=o.uuid.indexOf("0000FFE9")?t.write=o.uuid:-1!=o.uuid.indexOf("0000FFE4")&&(t.notify=o.uuid)}e.notifyBLECharacteristicValueChange({deviceId:t.deviceId,serviceId:t.serviceId,characteristicId:t.notify,state:!0}),e.notifyBLECharacteristicValueChange({deviceId:t.deviceId,serviceId:t.serviceId,characteristicId:t.write,state:!0}),e.onBLECharacteristicValueChange((function(e){var n=t.$tools.ab2hex(e.value,""),i=n.substring(14,16)+n.substring(10,14),o=parseInt(i,16)/1e3,c=parseInt(n.substring(22,26),16)+parseInt(n.substring(18,22),16),s=c/1e3;if(Number(o)>0){if(t.text=o.toFixed(0),t.LiuS=s.toFixed(1),t.offset=t.handleoffset(t.text),1==u)if(t.text==d){if(l++,l>=30)return t.isstart=!1,t.sendData("FA02A39F"),t.number1=o.toFixed(0),t.level1=t.handlelenver(t.number1),t.second=5,t.countdown(),void(t.LiuS=0)}else l=0,d=t.text;if(2==u)if(t.text==d){if(l++,l>=30)return t.isstart=!1,t.sendData("FA02A39F"),t.number2=o.toFixed(0),t.level2=t.handlelenver(t.number2),t.second=5,t.countdown(),void(t.LiuS=0)}else l=0,d=t.text;if(3==u){if(0==t.LiuS&&0==t.LiuS||t.listS.push(t.LiuS),t.text==d){if(l++,l>=15)return t.number3=o.toFixed(0),void(t.isEnd=!0)}else l=0,d=t.text;console.log("流量3",u,l)}}}))},fail:function(e){console.log("获取特征值失败:",JSON.stringify(e))}})},sendData:function(t){var n=new Uint8Array(t.match(/[\da-f]{2}/gi).map((function(e){return parseInt(e,16)})));e.writeBLECharacteristicValue({deviceId:this.deviceId,serviceId:this.serviceId,characteristicId:this.write,value:n.buffer,success:function(e){console.log("下发指令成功",e.errMsg)},fail:function(e){console.log("下发指令失败",e)}})},handleMyTime:function(){var e=this;o=setTimeout((function(){e.macAddr||(clearTimeout(o),e.Unload=!0,e.startBluetoothDeviceDiscovery(),e.closeBluetoothAdapter())}),3e4)},handlelenver:function(e){var t="";return this.list.forEach((function(n){Number(e)<=Number(n.max_val)&&Number(e)>=Number(n.min_val)&&(t=n.text)})),t},handleoffset:function(e){var t=0,n=this.list.length;return t=e/(this.list[0].max_val-this.list[n-1].min_val)*100,t.toFixed(0)},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||(clearTimeout(o),t.Unload=!0,t.closeBLEConnection(),t.closeBluetoothAdapter()),t.$store.commit("changeConnected",e.connected)}))},handleGetMeasure:function(){var t=this;t.$model.getMeasureLung({aud_id:e.getStorageSync("userid"),one:t.number1,two:t.number2,three:t.number3,flow:t.averageS}).then((function(n){0==n.code&&(t.$store.dispatch("getUserInfo",{aud_id:e.getStorageSync("userid")}),t.$store.dispatch("getLungResult",{aud_id:e.getStorageSync("userid")})),t.Unload=!0,setTimeout((function(){t.closeBLEConnection(),t.closeBluetoothAdapter(),e.switchTab({url:"/pages/home/home"})}),200)}))},handleBack:function(t){this.text="",this.Unload=!0,this.stopBluetoothDevicesDiscovery(),this.closeBluetoothAdapter(),this.closeBLEConnection(),1==t&&e.switchTab({url:"/pages/home/home"})},countdown:function(){var e=this;l=0,d=null;var t=setInterval((function(){e.second--}),1e3);setTimeout((function(){clearInterval(t),e.second=0}),5e3)},closeBluetoothAdapter:function(){e.closeBluetoothAdapter({success:function(e){console.log("蓝牙模块关闭成功")}})},closeBLEConnection:function(){e.closeBLEConnection({deviceId:this.deviceId,success:function(e){console.log("断开蓝牙连接成功")}})}}};t.default=f}).call(this,n("df3c")["default"])},d6f9: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,t=e.$createElement,n=(e._self._c,!e.isstart&&e.number3?e.average.toFixed(2):null),i=!e.isstart&&e.number3?e.average.toFixed(2):null,o=e.isstart?Number(100-e.offset):null;e._isMounted||(e.e0=function(t){e.isstart=!0}),e.$mp.data=Object.assign({},{$root:{g0:n,g1:i,m0:o}})},o=[]}},[["61a8","common/runtime","common/vendor"]]]);