11 lines
9.2 KiB
JavaScript
11 lines
9.2 KiB
JavaScript
(global["webpackJsonp"]=global["webpackJsonp"]||[]).push([["components/bluetooth_food"],{"014f":function(t,e,i){},"0442":function(t,e,i){"use strict";i.d(e,"b",(function(){return o})),i.d(e,"c",(function(){return s})),i.d(e,"a",(function(){return n}));var n={uniIcons:function(){return Promise.all([i.e("common/vendor"),i.e("uni_modules/uni-icons/components/uni-icons/uni-icons")]).then(i.bind(null,"6c3a"))}},o=function(){var t=this.$createElement,e=(this._self._c,3==this.isConnection?this.unitConversion(this.dw):null);this.$mp.data=Object.assign({},{$root:{m0:e}})},s=[]},"1bb8":function(t,e,i){"use strict";i.r(e);var n=i("0442"),o=i("749a");for(var s in o)["default"].indexOf(s)<0&&function(t){i.d(e,t,(function(){return o[t]}))}(s);i("e0be");var c=i("828b"),a=Object(c["a"])(o["default"],n["b"],n["c"],!1,null,"134d4a82",null,!1,n["a"],void 0);e["default"]=a.exports},"749a":function(t,e,i){"use strict";i.r(e);var n=i("99e4"),o=i.n(n);for(var s in n)["default"].indexOf(s)<0&&function(t){i.d(e,t,(function(){return n[t]}))}(s);e["default"]=o.a},"99e4":function(t,e,i){"use strict";(function(t){var n=i("47a9");Object.defineProperty(e,"__esModule",{value:!0}),e.default=void 0;var o=n(i("7eb4")),s=n(i("ee10")),c=n(i("7ca3")),a=i("8f59");function r(t,e){var i=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),i.push.apply(i,n)}return i}var h=requirePlugin("sdkPlugin").AiLink,u={data:function(){return{dw:"g",kcal:0,weight:"",weightALL:"",unit:"",weight0:0,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.startBluetoothDeviceDiscovery()},fail:function(t){e.isConnection=1,console.log("openBluetoothAdapter",t),e.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")}})},startBluetoothDeviceDiscovery:function(){var e=this;t.startBluetoothDevicesDiscovery({allowDuplicatesKey:!0,services:[],success:function(t){e.isConnection=0,e.onBluetoothDeviceFound()},fail:function(t){e.isConnection=1,console.log("startBluetoothDeviceDiscovery",t),e.$tools.msg("请确定设备是开机状态、手机蓝牙权限已打开!")}})},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,""),n=i.substring(0,4);if(t.name||t.localName)if(-1!==t.name.indexOf("EL")&&""!=t.advertisServiceUUIDs){e.isConnection=3;e.$tools.ab2hex(t.advertisData);var o=h.parseBroadcastData(t.advertisData),s=h.analyzeBroadcastScaleData(o);s.text,s.data;if(1==o.status){var c=o.payload,a=parseInt(c[3]).toString(16);console.log("data:"+a);var r=parseInt(c[4]).toString(16),u=parseInt(a+r,16),l=parseInt(c[5]).toString(16),g=l.length>1?l.substring(1,2):l,d=parseInt(l.substring(0,1),16).toString(8),f=d.toString().substring(0,1),v=0;d.toString().length>1&&(f=d.toString().substring(1,2),v=d.toString().substring(0,1)),"0"==g&&(e.dw="g"),"7"==g&&(e.dw="ml"),"3"==g&&(e.dw="oz"),"2"==g&&(e.dw="lb'oz"),"1"==f&&(u/=10),"2"==f&&(u/=100),"0"==v&&(u=u),"1"==v&&(u="-"+u),e.weight=u,e.kcal=(Number(e.weightKcal)/100*u).toFixed(2),e.$emit("realTimeWeight",u,e.dw)}}else-1==t.name.indexOf("Chipsea-BLE")&&-1==t.localName.indexOf("Chipsea-BLE")&&"a5fe"!=n||(e.stopBluetoothDevicesDiscovery(),e.connectDevice(t.deviceId))}))}))},connectDevice:function(e){var i=this;return(0,s.default)(o.default.mark((function n(){var s;return o.default.wrap((function(n){while(1)switch(n.prev=n.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 n.stop()}}),n)})))()},getBLEDeviceServices:function(e){var i=[],n=this;t.getBLEDeviceServices({deviceId:e,success:function(t){console.log("获取设备的UUID成功",t),i=t.services;for(var o=0;o<i.length;o++){var s=i[o];if(-1!=s.uuid.indexOf("FFF0")){n.getBLEDeviceCharacteristics(e,s.uuid);break}}},fail:function(t){console.log("获取设备的UUID失败:",t)}})},getBLEDeviceCharacteristics:function(e,i){var n=this;t.getBLEDeviceCharacteristics({deviceId:e,serviceId:i,success:function(o){var s;console.log("服务的特征值成功",o);for(var c=0;c<o.characteristics.length;c++){var a=o.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(){n.isConnection=3,n.$emit("connect_success"),t.onBLECharacteristicValueChange((function(t){var e=t.value,i=new DataView(e),o=i.getUint8(0);if(199===o){var s=i.getUint8(2);switch(s){case 2:n.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),n=t.getUint8(5)<<16|t.getUint8(6)<<8|t.getUint8(7),o=t.getUint8(8),s=(240&o)>>4,c=15&o,a=n/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=u}).call(this,i("df3c")["default"])},e0be:function(t,e,i){"use strict";var n=i("014f"),o=i.n(n);o.a}}]);
|
||
;(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__("1bb8"))
|
||
})
|
||
},
|
||
[['components/bluetooth_food-create-component']]
|
||
]);
|