2025-11-25 14:21:22 +08:00
|
|
|
|
(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("Chip
|