1 line
7.9 KiB
JavaScript
1 line
7.9 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["BLEPages/child/H01pro"],{"1abe":function(e,t,o){"use strict";var i;o.d(t,"b",(function(){return n})),o.d(t,"c",(function(){return c})),o.d(t,"a",(function(){return i}));var n=function(){var e=this,t=e.$createElement;e._self._c},c=[]},"60a0":function(e,t,o){"use strict";o.r(t);var i=o("1abe"),n=o("e563");for(var c in n)"default"!==c&&function(e){o.d(t,e,(function(){return n[e]}))}(c);var s,a=o("f0c5"),r=Object(a["a"])(n["default"],i["b"],i["c"],!1,null,"86c31068",null,!1,i["a"],s);t["default"]=r.exports},"9aea":function(e,t,o){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var i,n,c=o("26cb");function s(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 a(e){for(var t=1;t<arguments.length;t++){var o=null!=arguments[t]?arguments[t]:{};t%2?s(Object(o),!0).forEach((function(t){r(e,t,o[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(o)):s(Object(o)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(o,t))}))}return e}function r(e,t,o){return t in e?Object.defineProperty(e,t,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[t]=o,e}var u={data:function(){return{textW:"",textH:"",height:"",weight:"",imp:0,type:1,deviceId:"",serviceId:"",uuid1:"",uuid2:"",uuid3:"",devicesList:[],Unload:!1,isConnection:null}},computed:a(a({},(0,c.mapState)(["user","isConnected","isBluetoothTyle"])),{},{info:function(){return this.user}}),onUnload:function(){var e=this;e.Unload||(e.stopBluetoothDevicesDiscovery(),clearTimeout(n),clearTimeout(i),e.closeBLEConnection(),e.closeBluetoothAdapter(),console.log("页面返回onUnload"))},watch:{isConnected:function(){var e=this;e.isConnected||e.handleBack()},isBluetoothTyle:function(){var e=this;e.isBluetoothTyle||e.handleBack()}},onLoad:function(t){var o=this;o.textW="",o.textH="",t&&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.startBluetoothDeviceDiscovery(),console.log("初始化蓝牙成功:"+e.errMsg)},fail:function(o){t.$tools.msg("请打开蓝牙!安卓系统需打开蓝牙、定位权限;ios系统需打开设置——>应用——>微信里的蓝牙权限!"),setTimeout((function(){e.navigateBack({delta:1})}),500)}})},onBLEConnectionStateChange:function(){var t=this;e.onBLEConnectionStateChange((function(e){console.log("蓝牙连接状态",JSON.stringify(e)),t.$store.commit("changeConnected",e.connected)}))},startBluetoothDeviceDiscovery:function(){var t=this;e.startBluetoothDevicesDiscovery({allowDuplicatesKey:!0,interval:1e3,success:function(e){t.onBluetoothDeviceFound()},fail:function(t){setTimeout((function(){e.navigateBack({delta:1})}),500)}})},onBluetoothDeviceFound:function(){var t=this;e.onBluetoothDeviceFound((function(e){console.log("开始监听寻找到新设备的事件",e),e.devices.forEach((function(e){if((e.name||e.localName)&&-1!=e.name.indexOf("My")){console.log("deviceId",e),clearTimeout(n),t.stopBluetoothDevicesDiscovery();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,void t.createBLEConnection()}}))})),t.handleMyTime()},handleMyTime:function(){var t=this;n=setTimeout((function(){t.deviceId||(clearTimeout(n),t.stopBluetoothDevicesDiscovery(),e.showModal({title:"提示",content:"请确定蓝牙和手机位置信息已打开!请确定设备已开机;ios系统需打开设置——>应用——>微信里的蓝牙权限!是否继续?",cancelText:"取消",confirmText:"继续",success:function(o){o.confirm?(console.log("连接设备重新测量"),t.startBluetoothDeviceDiscovery()):(t.Unload=!0,e.navigateBack({delta:1}))}}))}),3e4)},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=!1,console.log("设备连接失败,请重新连接",e)}})},getBLEDeviceServices:function(){var t=[],o=this;e.getBLEDeviceServices({deviceId:o.deviceId,success:function(e){console.log("获取设备的UUID成功",e),o.type=3,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.getBLEDeviceCharacteristics(o.deviceId,n.uuid),console.log("设备的FFE0的serviceId: ",o.serviceId);break}}},fail:function(e){console.log("获取设备的UUID失败:",e)}})},getBLEDeviceCharacteristics:function(t,o){var n=[],c=this;e.getBLEDeviceCharacteristics({deviceId:t,serviceId:o,success:function(s){console.log("服务的特征值成功",s),n=s.characteristics;for(var a=0;a<n.length;a++){var r=n[a];-1!=r.uuid.indexOf("0000FFE1")?c.uuid1=r.uuid:-1!=r.uuid.indexOf("0000FFE2")?c.uuid2=r.uuid:-1!=r.uuid.indexOf("0000FFE3")&&(c.uuid3=r.uuid)}e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:o,characteristicId:c.uuid2,state:!0}),e.notifyBLECharacteristicValueChange({deviceId:t,serviceId:o,characteristicId:c.uuid3,state:!0}),e.onBLECharacteristicValueChange((function(e){clearTimeout(i);var t=c.$tools.ab2hex(e.value,""),o=parseInt(t.substring(4,8),16)/100,n=parseInt(t.substring(30,34),16)/10,s=t.substring(28,30)+t.substring(34,36),a=parseInt(s,16);c.textW="您的体重是:"+o+"kg",c.textH="您的身高是:"+n+"cm",c.weight=o+"kg",c.height=n,console.log("测量完成",o,"imp",a,s,"height",n),c.handleGetMeasure()}))},fail:function(e){console.log("获取特征值失败:",JSON.stringify(e))}})},handleGetMeasure:function(){console.log("保存结果");var t=this,o={weight:t.weight,imp:t.imp,ecode:t.macAddr,height:t.height?t.height:t.user.height,familyid:t.info.id?t.info.id:t.user.familyid,devtype:e.getStorageSync("devtype")};t.$model.GetMeasureListUnit(o).then((function(o){0==o.code?(t.$store.commit("changeEcode",!1),t.$store.dispatch("getChildInfo",{familyid:t.info.id?t.info.id:t.user.familyid,devtype:e.getStorageSync("devtype")}),t.info.id&&t.child.id!=t.user.familyid||(t.$store.dispatch("getMeasure",{familyid:t.user.familyid,devtype:e.getStorageSync("devtype")}),t.$store.dispatch("gethistoryList",{keyword:t.user.familyid,page:1,pagesize:5,devtype:e.getStorageSync("devtype")})),t.$tools.msg("测量成功")):(console.log("测量失败",o.message),t.$tools.msg(o.message)),t.Unload=!1}))},closeBluetoothAdapter:function(){var t=this;e.closeBluetoothAdapter({success:function(e){t.discoveryStarted=!1,console.log("蓝牙模块关闭成功")}})},handleBack:function(){var t=this;t.Unload=!0,t.stopBluetoothDevicesDiscovery(),t.closeBLEConnection(),t.closeBluetoothAdapter(),e.navigateBack({delta:1})},closeBLEConnection:function(){var t=this;e.closeBLEConnection({deviceId:t.deviceId,success:function(e){console.log("断开蓝牙连接成功")}})},changeTimeout:function(){var e=this;i=setTimeout((function(){""==e.weight&&(e.$tools.msg("由于长时间未操作,已断开蓝牙连接!"),e.closeBLEConnection(),e.closeBluetoothAdapter(),console.log("由于长时间未操作,蓝牙连接已断开!",e.isConnected))}),6e4)}}};t.default=u}).call(this,o("543d")["default"])},deec:function(e,t,o){"use strict";(function(e){o("3609");i(o("66fd"));var t=i(o("60a0"));function i(e){return e&&e.__esModule?e:{default:e}}wx.__webpack_require_UNI_MP_PLUGIN__=o,e(t.default)}).call(this,o("543d")["createPage"])},e563:function(e,t,o){"use strict";o.r(t);var i=o("9aea"),n=o.n(i);for(var c in i)"default"!==c&&function(e){o.d(t,e,(function(){return i[e]}))}(c);t["default"]=n.a}},[["deec","common/runtime","common/vendor"]]]); |