11 lines
9.1 KiB
JavaScript
11 lines
9.1 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["components/bluetooth_food"],{"18e1":function(t,e,i){"use strict";(function(t){var o=i("47a9");Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var n=o(i("7eb4")),s=o(i("ee10")),c=o(i("7ca3")),a=i("8f59");function r(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(t);e&&(o=o.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,o)}return i}var h={data:function(){return{dw:"g",kcal:0,weight:"",weightALL:"",unit:"",weight0:0,bleTipsText:"蓝牙搜索中",stopblue:!1,isConnection:0,units:["kg","斤","st:lb","lb","g","ml","Waterml","milkml","oz","floz","lboz"]}},props:{weightKcal:{type:Number,default:0},weightType:{type:Number,default:-1},isLast:{type:Boolean,default:!1}},computed:function(t){for(var e=1;e<arguments.length;e++){var i=null!=arguments[e]?arguments[e]:{};e%2?r(Object(i),!0).forEach((function(e){(0,c.default)(t,e,i[e])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(i)):r(Object(i)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(i,e))}))}return t}({},(0,a.mapState)(["user","isConnected","isBluetoothTyle"])),mounted:function(){var e=this;console.log("mounted_new",e.weightType),e.openBluetoothAdapter(),e.onBLEConnectionStateChange(),t.onBluetoothAdapterStateChange((function(t){e.$store.commit("changeBluetooth",t.available)}))},destroyed:function(){this.isConnection=1,this.closeBLEConnection(),this.closeBluetoothAdapter()},watch:{isBluetoothTyle:function(){this.isBluetoothTyle||this.handleBack()},isLast:function(){this.stopblue=this.isLast,console.log("最后",this.isLast)}},methods:{openBluetoothAdapter:function(){var e=this;e.weight="",e.kcal="",t.openBluetoothAdapter({success:function(t){e.isConnection=0,e.bleTipsText="蓝牙搜索中",e.startBluetoothDeviceDiscovery()},fail:function(t){e.isConnection=0,e.bleTipsText="请确定设备是开机状态、手机蓝牙权限已打开!",console.log("openBluetoothAdapter",t)}})},startBluetoothDeviceDiscovery:function(){var e=this;t.startBluetoothDevicesDiscovery({allowDuplicatesKey:!0,services:[],success:function(t){e.isConnection=0,e.onBluetoothDeviceFound()},fail:function(t){e.isConnection=0,e.bleTipsText="请确定设备是开机状态、手机蓝牙权限已打开!",console.log("startBluetoothDeviceDiscovery",t)}})},onBLEConnectionStateChange:function(){var e=this;t.onBLEConnectionStateChange((function(t){console.log("监听蓝牙连接状态",t.connected),t.connected||(e.isConnection=1,e.closeBLEConnection(),e.closeBluetoothAdapter()),e.$store.commit("changeConnected",t.connected)}))},stopBluetoothDevicesDiscovery:function(){t.stopBluetoothDevicesDiscovery({success:function(t){console.log("停止搜索蓝牙设备",t)}})},onBluetoothDeviceFound:function(){var e=this;e.isConnection=0,t.onBluetoothDeviceFound((function(t){t.devices.forEach((function(t){t.advertisData=t.advertisData?t.advertisData:"",t.advertisServiceUUIDs=t.advertisServiceUUIDs?t.advertisServiceUUIDs:"";var i=e.$tools.ab2hex(t.advertisData,""),o=i.substring(0,4);if(t.name||t.localName)if(-1!==t.name.indexOf("EL")&&""!=t.advertisServiceUUIDs){e.isConnection=0,e.bleTipsText="测量中,请将食物放到秤上";e.$tools.ab2hex(t.advertisData);var n=plugin.parseBroadcastData(t.advertisData),s=plugin.analyzeBroadcastScaleData(n);s.text,s.data;if(1==n.status){var c=n.payload,a=parseInt(c[3]).toString(16);console.log("data:"+a);var r=parseInt(c[4]).toString(16),h=parseInt(a+r,16),l=parseInt(c[5]).toString(16),u=l.length>1?l.substring(1,2):l,g=parseInt(l.substring(0,1),16).toString(8),d=g.toString().substring(0,1),f=0;g.toString().length>1&&(d=g.toString().substring(1,2),f=g.toString().substring(0,1)),"0"==u&&(e.dw="g"),"7"==u&&(e.dw="ml"),"3"==u&&(e.dw="oz"),"2"==u&&(e.dw="lb'oz"),"1"==d&&(h/=10),"2"==d&&(h/=100),"0"==f&&(h=h),"1"==f&&(h="-"+h),e.weight=h,e.kcal=(Number(e.weightKcal)/100*h).toFixed(2),e.$emit("realTimeWeight",h,e.dw)}}else-1==t.name.indexOf("Chipsea-BLE")&&-1==t.localName.indexOf("Chipsea-BLE")&&"a5fe"!=o||(e.stopBluetoothDevicesDiscovery(),e.connectDevice(t.deviceId))}))}))},connectDevice:function(e){var i=this;return(0,s.default)(n.default.mark((function o(){var s;return n.default.wrap((function(o){while(1)switch(o.prev=o.next){case 0:s=i,t.createBLEConnection({deviceId:e,success:function(t){setTimeout((function(){s.getBLEDeviceServices(e)}),200)},fail:function(t){console.log("设备连接失败,请重新连接",t)}});case 2:case"end":return o.stop()}}),o)})))()},getBLEDeviceServices:function(e){var i=[],o=this;t.getBLEDeviceServices({deviceId:e,success:function(t){console.log("获取设备的UUID成功",t),i=t.services;for(var n=0;n<i.length;n++){var s=i[n];if(-1!=s.uuid.indexOf("FFF0")){o.getBLEDeviceCharacteristics(e,s.uuid);break}}},fail:function(t){console.log("获取设备的UUID失败:",t)}})},getBLEDeviceCharacteristics:function(e,i){var o=this;t.getBLEDeviceCharacteristics({deviceId:e,serviceId:i,success:function(n){var s;console.log("服务的特征值成功",n);for(var c=0;c<n.characteristics.length;c++){var a=n.characteristics[c];-1!=a.uuid.indexOf("0000FFF2")?a.uuid:-1!=a.uuid.indexOf("0000FFF1")&&(s=a.uuid)}t.notifyBLECharacteristicValueChange({deviceId:e,serviceId:i,characteristicId:s,state:!0,success:function(){o.isConnection=0,o.bleTipsText="测量中,请将食物放到秤上",t.onBLECharacteristicValueChange((function(t){var e=t.value,i=new DataView(e),n=i.getUint8(0);if(199===n){var s=i.getUint8(2);switch(s){case 2:o.parseWeightData(i);break;case 3:break}}}))},fail:function(t){console.log("获取特征值失败:",JSON.stringify(t))}})},fail:function(t){console.log("获取特征值失败:",JSON.stringify(t))}})},parseWeightData:function(t){var e=t.getUint8(4),i=!!(128&e),o=t.getUint8(5)<<16|t.getUint8(6)<<8|t.getUint8(7),n=t.getUint8(8),s=(240&n)>>4,c=15&n,a=o/Math.pow(10,s);i&&(a=-a),this.weight=a,this.dw=this.units[c]||"g",this.kcal=(Number(this.weightKcal)/100*a).toFixed(2),this.$emit("realTimeWeight",a,this.dw)},handlesub:function(){console.log("weight",this.weight),Number(this.weight)>0?this.$emit("handleBle",this.weight,this.dw,this.kcal):this.$tools.msg("数据异常,请清零后重新测量!")},handleDetailSub:function(){1==this.weightType?(this.weight0=Number((Number(this.weight)-Number(this.weightALL)).toFixed(2)),this.weight0>0?this.weightALL=this.weight:this.$tools.msg("数据异常,请清零后重新测量!")):this.weight0=this.weight,Number(this.weight0)>0?(this.$emit("handleDetailSub",this.weight0,this.dw,this.kcal),this.weight=0,this.weight0=0):this.$tools.msg("数据异常,请重新测量!")},handleDetailNext:function(){1==this.weightType?(console.log("weight:"+this.weight),console.log("weight0:"+this.weight0),console.log("weightALL:"+this.weightALL),this.weight0=Number((Number(this.weight)-Number(this.weightALL)).toFixed(2)),this.weight0>0?this.weightALL=this.weight:this.$tools.msg("数据异常,请清零后重新测量!")):this.weight0=this.weight,Number(this.weight0)>0?(this.$emit("handleDetailNext",this.weight0,this.dw,this.kcal),this.weight=0,this.weight0=0):this.$tools.msg("数据异常,请清零后重新测量!")},handlechongzhi:function(t){console.log("当前总重:"+this.weightALL),console.log("重置重量:"+t),1==this.weightType&&(this.weightALL=Number((Number(this.weightALL)-Number(t)).toFixed(2)),console.log("剩余重量:"+this.weightALL))},handleBack:function(){this.isConnection=1,this.stopBluetoothDevicesDiscovery(),this.closeBLEConnection(),this.closeBluetoothAdapter()},closeBluetoothAdapter:function(){t.closeBluetoothAdapter({success:function(t){console.log("蓝牙模块关闭成功")}})},closeBLEConnection:function(){t.closeBLEConnection({deviceId:this.deviceId,success:function(t){console.log("断开蓝牙连接成功")}})},unitConversion:function(t){return"kcal"==t?"千卡":"g"==t?"克":"lb"==t?"磅":"oz"==t?"盎司":t}}};e.default=h}).call(this,i("df3c")["default"])},4433:function(t,e,i){"use strict";i.d(e,"b",(function(){return o})),i.d(e,"c",(function(){return n})),i.d(e,"a",(function(){}));var o=function(){var t=this.$createElement,e=(this._self._c,this.unitConversion(this.dw));this.$mp.data=Object.assign({},{$root:{m0:e}})},n=[]},"4ef7":function(t,e,i){"use strict";var o=i("e9ed"),n=i.n(o);n.a},6777:function(t,e,i){"use strict";i.r(e);var o=i("18e1"),n=i.n(o);for(var s in o)["default"].indexOf(s)<0&&function(t){i.d(e,t,(function(){return o[t]}))}(s);e["default"]=n.a},d025:function(t,e,i){"use strict";i.r(e);var o=i("4433"),n=i("6777");for(var s in n)["default"].indexOf(s)<0&&function(t){i.d(e,t,(function(){return n[t]}))}(s);i("4ef7");var c=i("828b"),a=Object(c["a"])(n["default"],o["b"],o["c"],!1,null,"3be1db68",null,!1,o["a"],void 0);e["default"]=a.exports},e9ed:function(t,e,i){}}]);
|
||
;(global["webpackJsonp"] = global["webpackJsonp"] || []).push([
|
||
'components/bluetooth_food-create-component',
|
||
{
|
||
'components/bluetooth_food-create-component':(function(module, exports, __webpack_require__){
|
||
__webpack_require__('df3c')['createComponent'](__webpack_require__("d025"))
|
||
})
|
||
},
|
||
[['components/bluetooth_food-create-component']]
|
||
]);
|