1 line
7.8 KiB
JavaScript
1 line
7.8 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["BLEPages/adult/PCD01pro"],{"45f5":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 s(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){r(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 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 a=0,u={data:function(){return{text:"",height:"",weight:"",imp:0,type:1,uuid1:"",uuid2:"",uuid3:"",macAddr:"",deviceId:"",serviceId:"",Unload:!1,pageNav:!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(n),e.closeBLEConnection(),e.closeBluetoothAdapter(),console.log("测量页返回1"))},onLoad:function(t){var o=this;a=0,o.text="",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)}))},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;a=0,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(n);var o=e.advertisData.slice(-6);e.mac=new Uint8Array(o);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;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)}})},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)}))},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.isConnection=1,o.serviceId=i.uuid,o.getBLEDeviceCharacteristics(),console.log("设备的FFE0的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("FFE1")?t.uuid1=n.uuid:-1!=n.uuid.indexOf("FFE2")?(t.uuid2=n.uuid,t.notifyBLECharacteristicValue()):-1!=n.uuid.indexOf("FFE3")&&(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(o){var n=t.$tools.ab2hex(o.value,""),i=n.substring(18,19),c=n.substring(19,20),s=n.substring(8,10),r=n.substring(10,12);if(console.log("value",n),"10"==s){var u=parseInt(n.substring(13,18),16),l="kg",d="kg";"1"==c&&(l="斤",d="jin"),"4"==c&&(l="st:lb",d="st",u=1*u+5),"6"==c&&(l="lb",d="lb"),"1"==i&&(u=parseInt(n.substring(13,18),16)/10),"2"==i&&(u=parseInt(n.substring(13,18),16)/100),"3"==i&&(u=parseInt(n.substring(13,18),16)/1e3),"01"==r&&(t.text="您的实时体重是:"+u+l),"02"==r&&(t.text="您的体重是:"+u+l,t.weight=u+d,console.log("稳定体重:",n,t.weight))}"11"==s&&(t.type=2,"02"==r&&(a+=1),"03"==r&&(t.imp=parseInt(n.substring(17,22),16)),a>=2&&(console.log("阻抗值shibai",a),t.imp=0,e.showModal({title:"提示",content:"体脂测量失败,是否保存本次测量结果?",cancelText:"放弃",confirmText:"保存",success:function(o){o.confirm?(t.imp=0,t.handleGetMeasure()):(t.Unload=!0,t.closeBLEConnection(),t.closeBluetoothAdapter(),e.navigateBack({delta:1}))}}))),"30"==s&&(console.log("测量完成",t.weight),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.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(){var e=this;e.Unload=!0,clearTimeout(n),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=u}).call(this,o("543d")["default"])},8665:function(e,t,o){"use strict";(function(e){o("0d2f");n(o("66fd"));var t=n(o("cc6d"));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"])},cc6d:function(e,t,o){"use strict";o.r(t);var n=o("d165"),i=o("e3d0");for(var c in i)"default"!==c&&function(e){o.d(t,e,(function(){return i[e]}))}(c);var s,r=o("f0c5"),a=Object(r["a"])(i["default"],n["b"],n["c"],!1,null,"ef796f16",null,!1,n["a"],s);t["default"]=a.exports},d165: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=[]},e3d0:function(e,t,o){"use strict";o.r(t);var n=o("45f5"),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}},[["8665","common/runtime","common/vendor"]]]); |