1 line
7.9 KiB
JavaScript
1 line
7.9 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["BLEPages/adult/F01B"],{"574c":function(e,t,n){"use strict";(function(e){n("0d2f");o(n("66fd"));var t=o(n("9488"));function o(e){return e&&e.__esModule?e:{default:e}}wx.__webpack_require_UNI_MP_PLUGIN__=n,e(t.default)}).call(this,n("543d")["createPage"])},"6c2b":function(e,t,n){"use strict";n.r(t);var o=n("cde7"),i=n.n(o);for(var c in o)"default"!==c&&function(e){n.d(t,e,(function(){return o[e]}))}(c);t["default"]=i.a},9488:function(e,t,n){"use strict";n.r(t);var o=n("a0b6"),i=n("6c2b");for(var c in i)"default"!==c&&function(e){n.d(t,e,(function(){return i[e]}))}(c);var s,r=n("f0c5"),a=Object(r["a"])(i["default"],o["b"],o["c"],!1,null,"a5d69904",null,!1,o["a"],s);t["default"]=a.exports},a0b6:function(e,t,n){"use strict";var o;n.d(t,"b",(function(){return i})),n.d(t,"c",(function(){return c})),n.d(t,"a",(function(){return o}));var i=function(){var e=this,t=e.$createElement;e._self._c},c=[]},cde7:function(e,t,n){"use strict";(function(e){Object.defineProperty(t,"__esModule",{value:!0}),t.default=void 0;var o,i=n("26cb");function c(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,o)}return n}function s(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?c(Object(n),!0).forEach((function(t){r(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):c(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function r(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var a={data:function(){return{text:"",height:"",weight:"",imp:0,type:1,uuid1:"",uuid2:"",uuid3:"",macAddr:"",deviceId:"",serviceId:"",Unload:!1,isConnection:0}},computed:s(s({},(0,i.mapState)(["user","isConnected","isBluetoothTyle"])),{},{info:function(){return this.user}}),onUnload:function(){var e=this;e.Unload||(e.stopBluetoothDevicesDiscovery(),clearTimeout(o),e.closeBLEConnection(),e.closeBluetoothAdapter(),console.log("返回上一个页面"))},onLoad:function(t){var n=this;n.text="",t&&t.deviceId&&(n.macAddr=t.deviceId,n.deviceId=t.deviceId,n.createBLEConnection()),n.onBLEConnectionStateChange(),e.onBluetoothAdapterStateChange((function(e){n.$store.commit("changeBluetooth",e.available)}))},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)}},methods:{openBluetoothAdapter:function(){var t=this;t.type=1,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:500,services:["FFE0"],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.deviceId.indexOf(t.deviceId)){t.stopBluetoothDevicesDiscovery(),clearTimeout(o);var n=e.advertisData.slice(-6);e.mac=new Uint8Array(n);var i=Array.from(e.mac);return i.reverse(),e.macAddr=t.$tools.ab2hex(i,":").toUpperCase(),t.macAddr=e.macAddr,t.deviceId=e.deviceId,void t.createBLEConnection()}}))})),t.handleMyTime()},handleMyTime:function(){var e=this;o=setTimeout((function(){e.macAddr||(clearTimeout(o),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||(clearTimeout(o),t.Unload=!0,t.isConnection=2,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=[],n=this;e.getBLEDeviceServices({deviceId:n.deviceId,success:function(e){console.log("获取设备的UUID成功",e),t=e.services;for(var o=0;o<t.length;o++){var i=t[o];if(-1!=i.uuid.indexOf("FFE0")){n.isConnection=1,n.serviceId=i.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(e){console.log("服务的特征值成功",e);for(var n=0;n<e.characteristics.length;n++){var o=e.characteristics[n];-1!=o.uuid.indexOf("0000FFE1")?t.uuid1=o.uuid:-1!=o.uuid.indexOf("0000FFE2")?t.uuid2=o.uuid:-1!=o.uuid.indexOf("0000FFE3")&&(t.uuid3=o.uuid,t.notifyBLECharacteristicValue())}},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.uuid3,success:function(n){e.onBLECharacteristicValueChange((function(n){var o=t.$tools.ab2hex(n.value,""),i=o.substring(18,19),c=o.substring(19,20),s=o.substring(8,10),r=o.substring(10,12);if("10"==s){var a=parseInt(o.substring(13,18),16),u="kg",l="kg";"1"==c&&(u="斤",l="jin"),"4"==c&&(u="st:lb",l="st",a=1*a+5),"6"==c&&(u="lb",l="lb"),"1"==i&&(a=parseInt(o.substring(13,18),16)/10),"2"==i&&(a=parseInt(o.substring(13,18),16)/100),"3"==i&&(a=parseInt(o.substring(13,18),16)/1e3),"01"==r&&(t.text="您的实时体重是:"+a+u),"02"==r&&(t.text="您的体重是:"+a+u,t.weight=a+l,console.log("稳定体重:",o,t.weight))}"11"==s&&("03"==r&&(t.imp=parseInt(o.substring(17,22),16)),console.log("体脂:",t.imp)),"14"==s&&(t.height=parseInt(o.substring(10,14),16)/10,t.type=2,console.log("身高模式:",t.height)),"30"==s&&(console.log("测量完成",t.weight,t.height,t.imp),0==t.imp?e.showModal({title:"提示",content:"体脂测量失败,是否保存本次测量结果?",cancelText:"放弃",confirmText:"保存",success:function(n){n.confirm?(t.imp=0,t.handleGetMeasure()):(t.Unload=!0,t.closeBLEConnection(),t.closeBluetoothAdapter(),e.navigateBack({delta:1}))}}):t.handleGetMeasure())}))},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.height,familyid:t.info.familyid}).then((function(n){0==n.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,sex:t.info.sex})):(console.log("测量失败",n.message),t.$tools.msg(n.message)),t.Unload=!0,setTimeout((function(){t.closeBLEConnection(),t.closeBluetoothAdapter(),e.switchTab({url:"/pages/index/index"})}),200)}))},handleBack:function(e){var t=this;t.text="",t.Unload=!0,t.stopBluetoothDevicesDiscovery(),t.closeBLEConnection(),t.closeBluetoothAdapter(),clearTimeout(o)},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,n("543d")["default"])}},[["574c","common/runtime","common/vendor"]]]); |