首页搜索蓝牙

This commit is contained in:
qcl_123 2025-11-26 17:32:18 +08:00
parent f2c0fcff4c
commit 895d663039
83 changed files with 1129 additions and 1077 deletions

View File

@ -3,8 +3,7 @@
<view class="table">
<view class="text">
<image src="/static/zhong.png"></image>
<text v-if="isConnection == 0">{{bleTipsText}}</text>
<text v-if="isConnection == 1" @click="openBluetoothAdapter">连接失败点击重新连接</text>
<text @click="openBluetoothAdapter">{{bleTipsText}}</text>
</view>
<view class="duan" @click="handleBack" v-if="isShow&&isConnection == 0">
断开连接
@ -15,17 +14,8 @@
<!-- 蓝牙称重 -->
<view class="weight" @click="inputDialogToggle">
<text class="val">{{weight == '' ? '--':weight}}</text>
<text class="unit">{{dw}}</text>
<text class="unit">{{unit}}</text>
</view>
<!-- <view class="weight" v-else>
<input type="digit" v-model="activeType.weight" placeholder="请输入" @input="replaceInput" />
<text class="unit"></text>
</view>
<view class="more" @click="handleToggleBle">
<image class="keybordIcon" :src="isBle?'/static/chengIcon.png':'/static/keybordIcon.png'"
mode="widthFix">
</image>
</view> -->
</view>
<!-- -->
<view class="groupbtn">
@ -64,13 +54,10 @@
export default {
data() {
return {
dw: "克",
kcal: 0,
unit: '',
isShow: false,
bleTipsText: "",
inputDialog: false,
isConnection: 0, //
unitList: [{
name: "克",
id: '00',
@ -103,17 +90,20 @@
computed: {
...mapState(["bleValue", "isBluetoothTyle", "countFoodInfo"]),
weight() {
this.unit = this.unitConversion(this.bleValue.unit)
return this.bleValue.countWeight
},
isConnection() {
this.bleTipsText = this.bleValue.bleTipsText
return this.bleValue.isConnectStatus
},
isShow(){
return this.bleValue.serviceId != '' ? true : false
}
},
mounted() {
let that = this
if (that.bleValue.serviceId != '') {
that.getBLECharacteristicValueChange(that.bleValue.deviceId, that.bleValue.serviceId, that.bleValue.notify)
} else {
that.openBluetoothAdapter()
}
that.onBLEConnectionStateChange()
uni.onBluetoothAdapterStateChange(function(res) {
that.$store.commit("changeBluetooth", res.available);
})
@ -135,269 +125,31 @@
//
openBluetoothAdapter() {
let that = this
if (that.isConnection == 0) return
that.kcal = ""
that.isShow = false
that.bleTipsText = "蓝牙搜索中"
uni.openBluetoothAdapter({
success: e => {
that.isConnection = 0
that.startBluetoothDeviceDiscovery()
},
fail: e => {
that.isConnection = 0
that.bleTipsText = "请确定设备和手机蓝牙已打开!"
console.log('openBluetoothAdapter', e)
}
});
},
//
startBluetoothDeviceDiscovery() {
let that = this
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
services: [
// "F0A0",
// "A5FE"
],
success: res => {
that.isConnection = 0
that.onBluetoothDeviceFound();
},
fail: res => {
that.isConnection = 0
that.bleTipsText = "请确定设备和手机蓝牙已打开!"
console.log('startBluetoothDeviceDiscovery', res)
}
});
},
//
onBLEConnectionStateChange() {
let that = this
uni.onBLEConnectionStateChange(function(res) {
console.log("监听蓝牙连接状态", res.connected)
if (!res.connected) {
that.isConnection = 1
that.closeBLEConnection()
that.closeBluetoothAdapter()
}
that.$store.commit("changeBluetooth", res.connected);
})
},
/**
* 停止搜索蓝牙设备
*/
stopBluetoothDevicesDiscovery() {
uni.stopBluetoothDevicesDiscovery({
success: e => {
console.log("停止搜索蓝牙设备", e)
},
});
},
/**
* 发现外围设备
*/
onBluetoothDeviceFound() {
var that = this;
that.isConnection = 0
uni.onBluetoothDeviceFound(res => {
res.devices.forEach(device => {
device.advertisData = device.advertisData ? device.advertisData : ''
device.advertisServiceUUIDs = device.advertisServiceUUIDs ? device
.advertisServiceUUIDs : ""
let value = that.$tools.ab2hex(device.advertisData, "")
let id = value.substring(0, 4)
if (!device.name && !device.localName) {
return
}
if (device.name.indexOf("EL") !== -1 && device.advertisServiceUUIDs != '') {
that.isConnection = 0
that.bleTipsText = "测量中,请将食物放到秤上"
let value = that.$tools.ab2hex(device.advertisData)
let parseDataRes = plugin.parseBroadcastData(device.advertisData)
let analyzeData = plugin.analyzeBroadcastScaleData(parseDataRes)
let analyzeDataText = analyzeData.text
let data = analyzeData.data
if (parseDataRes.status == 1) {
let data0 = parseDataRes.payload
let data = parseInt(data0[3]).toString(16)
console.log('data' + data)
let data1 = parseInt(data0[4]).toString(16)
let data2 = parseInt((data + data1), 16) //
//
let unit0 = parseInt(data0[5]).toString(16) //
let unit = unit0.length > 1 ? unit0.substring(1, 2) : unit0 //
let num = parseInt(unit0.substring(0, 1), 16).toString(8)
let dot = num.toString().substring(0, 1) //
let zfz = 0 //
if (num.toString().length > 1) {
dot = num.toString().substring(1, 2)
zfz = num.toString().substring(0, 1)
}
if (unit == '0') {
that.dw = 'g'
}
if (unit == "7") {
that.dw = "ml"
}
if (unit == "3") {
that.dw = "oz"
}
if (unit == "2") {
that.dw = "lb'oz"
}
if (dot == "1") {
data2 = data2 / 10
}
if (dot == "2") {
data2 = data2 / 100
}
if (zfz == "0") {
data2 = data2
}
if (zfz == "1") {
data2 = "-" + data2
}
that.weight = data2
that.kcal = (Number(that.weightKcal) / 100 * data2).toFixed(2)
that.$emit('realTimeWeight', data2, that.dw)
}
return
}
if (device.name.indexOf('Chipsea-BLE') != -1 || (device.localName && device
.localName.indexOf('Chipsea-BLE') != -1) || id == 'a5fe') {
that.stopBluetoothDevicesDiscovery()
that.connectDevice(device.deviceId)
return
}
})
});
},
//
async connectDevice(device_id) {
let that = this;
uni.createBLEConnection({
deviceId: device_id,
success: res => {
setTimeout(function() {
that.getBLEDeviceServices(device_id)
}, 200)
},
fail: res => {
console.log("设备连接失败,请重新连接", res);
}
});
},
/**
* 获取设备的UUID
*/
getBLEDeviceServices(device_id) {
let serviceList = [];
let that = this;
uni.getBLEDeviceServices({
deviceId: device_id,
success: res => {
console.log("获取设备的UUID成功", res)
serviceList = res.services;
for (let i = 0; i < serviceList.length; i++) {
let service = serviceList[i];
if (service.uuid.indexOf("FFF0") != -1) {
that.getBLEDeviceCharacteristics(device_id, service.uuid);
break;
}
}
},
fail: res => {
console.log('获取设备的UUID失败:', res)
}
});
},
/**
* 获取指定服务的特征值
*/
getBLEDeviceCharacteristics(deviceId, serviceId) {
let characteristicsList = [];
let that = this;
uni.getBLEDeviceCharacteristics({
deviceId: deviceId,
serviceId: serviceId,
success: res => {
console.log("服务的特征值成功", res)
let write, notify
for (let i = 0; i < res.characteristics.length; i++) {
let item = res.characteristics[i];
if (item.uuid.indexOf('0000FFF2') != -1) {
write = item.uuid
} else if (item.uuid.indexOf('0000FFF1') != -1) {
notify = item.uuid
}
}
let info = {
deviceId: deviceId,
serviceId: serviceId,
notify: notify,
write: write,
}
that.handletoggleUnit(0x04)
that.$store.commit('changeBluetoothValue', info)
setTimeout(function() {
that.getBLECharacteristicValueChange(deviceId, serviceId, notify)
}, 300)
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
})
},
getBLECharacteristicValueChange(deviceId, serviceId, notify) {
let that = this
uni.notifyBLECharacteristicValueChange({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: notify,
state: true,
success: () => {
that.isShow = true
that.isConnection = 0
that.bleTipsText = "测量中,请将食物放到秤上"
uni.onBLECharacteristicValueChange(function(res) {
const value = res.value
const dataView = new DataView(value)
const header = dataView.getUint8(0)
console.log("value", that.$tools.ab2hex(res.value, ""))
// MCU
if (header === 0xC7) {
const cmd = dataView.getUint8(2)
switch (cmd) {
case 0x02:
that.parseWeightData(dataView)
break
case 0x03:
break
}
}
})
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
that.$store.commit('changeBluetoothValue', {
deviceId: "",
serviceId: "",
notify: '',
write: '',
unit: "g",
countWeight: 0,
bleTipsText: "蓝牙搜索中",
isConnectStatus: 0,
})
that.$ble.openBluetoothAdapter()
},
changleUnits(e) {
let that = this
let name = that.unitList[e.detail.value].name
if (that.isShow && that.dw != name) {
console.log("单位切换", name, that.unit)
if (that.isShow && that.unit != name) {
that.handletoggleUnit(name == '盎司' ? 0x08 : 0x04)
that.$store.commit("changeBluetoothValue", {
countWeight: finalWeight,
unit: that.unitList[e.detail.value].unit
})
}
that.unitListIndex = [e.detail.value]
that.dw = that.unitList[e.detail.value].name
that.$store.commit('changeBluetoothValue', {
unit: that.unitList[e.detail.value].unit
})
},
handletoggleUnit(unit) {
@ -434,97 +186,27 @@
},
})
},
parseWeightData(dataView) {
const statusByte = dataView.getUint8(4)
const isNegative = !!(statusByte & 0x80) //
const statusType = statusByte & 0x0F //
// 24 ()
const weightValue =
(dataView.getUint8(5) << 16) |
(dataView.getUint8(6) << 8) |
dataView.getUint8(7)
//
const unitByte = dataView.getUint8(8)
const precision = (unitByte & 0xF0) >> 4 // 4
const unitIndex = unitByte & 0x0F // 4
//
let finalWeight = weightValue / Math.pow(10, precision)
if (isNegative) finalWeight = -finalWeight
if (this.units[unitIndex] == 'kcal') {
this.dw = '千卡'
} else if (this.units[unitIndex] == 'g') {
this.dw = '克'
} else if (this.units[unitIndex] == 'lb') {
this.dw = '磅'
} else if (this.units[unitIndex] == 'oz') {
this.dw = '盎司'
}
this.$store.commit("changeBluetoothValue", {
countWeight: finalWeight,
unit: this.units[unitIndex]
})
// this.$emit('realTimeWeight', finalWeight, this.dw)
//
// if (statusType === 0x02) {
// this.$emit('handleBle', finalWeight,this.unit,0)
// }
},
//
handlesub() {
let that = this
console.log("weight", that.weight)
if (Number(that.weight) > 0) {
that.$emit("handleBle", that.weight, that.dw, that.kcal)
that.$emit("handleBle", that.weight, that.unit, that.kcal)
} else {
that.$tools.msg("数据异常,请清零后重新测量!")
}
},
handleBack() {
let that = this
that.isConnection = 1
that.stopBluetoothDevicesDiscovery() //
that.closeBLEConnection()
that.closeBluetoothAdapter()
},
/**
* 断开蓝牙模块
*/
closeBluetoothAdapter() {
let that = this;
uni.closeBluetoothAdapter({
success: res => {
that.isConnection = 1
that.$store.commit("changeBluetoothValue", {
deviceId: "",
serviceId: "",
notify: "",
write: "",
unit: "",
countWeight: 0,
})
console.log('蓝牙模块关闭成功');
}
bleTipsText: "连接失败,点击重新连接",
isConnectStatus: 1
})
that.$ble.stopBluetoothDevicesDiscovery() //
that.$ble.closeBLEConnection(that.bleValue.deviceId)
that.$ble.closeBluetoothAdapter()
},
/**
* 断开蓝牙连接
*/
closeBLEConnection() {
var that = this;
uni.closeBLEConnection({
deviceId: that.bleValue.deviceId,
success: res => {
that.isConnection = 1
console.log('断开蓝牙连接成功');
}
});
},
unitConversion(unit) {
if (unit == 'kcal') {
return '千卡'

View File

@ -1,13 +1,12 @@
import App from './App'
// import './uni.scss';
// import './assets/common.scss'
// import './assets/iconfont.css'
// import './assets/iconfont-weapp-icon.css'
import store from './store'
Vue.prototype.$store = store;
// js
import tools from '@/tools/tools.js'
Vue.prototype.$tools = tools;
// 蓝牙
import bluetooth from '@/tools/bluetooth.js'
Vue.prototype.$ble = bluetooth;
//请求
import http from '@/tools/https.js'
Vue.prototype.$http = http;

View File

@ -194,7 +194,6 @@
data: chart_data
}]
}));
for (let key in that.details) {
if (that.details.hasOwnProperty(key)) {
that.opts2.color.push(that.details[key].color)
@ -206,7 +205,7 @@
}
that.chartData2 = JSON.parse(JSON.stringify({
series: [{
data: chart_data
data: chart_data2
}]
}));
},

View File

@ -233,13 +233,15 @@
aud_id: that.user.aud_id,
eat_log_id: item.id
}).then(res => {
//
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo")
} else {
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.time
})
//
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo")
}
})
}

View File

@ -63,20 +63,6 @@
</view>
<view class="endtext" v-if="!lastPage || page >= lastPage"> 到底了看看别的吧 </view>
</view>
<!-- 底部购物车 -->
<view class="groupbtn">
<view @click="isShop =! isShop" class="left">
<view class="che">
<text>{{ActiveList.filter(ite => ite.meals_type == foodName).length||0}}</text>
<icon class="t-icon t-icon-canpan"></icon>
</view>
<view class="type">
{{foodName}}
<image src="/static/arrow-down.png"></image>
</view>
</view>
<view class="subbtn" @click="handlesubbtn"> 完成</view>
</view>
<!-- 购物车列表 -->
<view class="wrapper activeList" v-if="isShop">
<view class="bg" @click='isShop=false'>
@ -90,13 +76,14 @@
<view class="list" v-if="ActiveList.length">
<view class="length">{{ActiveList.filter(ite => ite.meals_type == foodName).length}}条记录</view>
<view class="item" v-for="(ite,ind) in ActiveList" :key="ind" v-if="ite.meals_type==foodName">
<view class="item-left">
<image :src="ite.pic_url"></image>
<view class="name">
<text>{{ite.name}}</text>
<text class="weight">{{ite.weight}}{{ite.unit}} / {{ite.kcal}}kcal</text>
</view>
<icon class="iconfont icon-ashbin" color="red" size="26" @click="handledelactive(ite)">
</icon>
</view>
<icon class="iconfont icon-ashbin" color="red" size="26" @click="handledelactive(ite)"></icon>
</view>
</view>
<view v-else class="nolist list">
@ -121,11 +108,6 @@
<view class="kcal">{{activeType.kcal}}千卡/100</view>
</view>
</view>
<!-- <view class="more" @click="handleToggleBle">
<image class="keybordIcon"
:src="isBle?'/static/chengIcon.png':'/static/keybordIcon.png'" mode="widthFix">
</image>
</view> -->
</view>
<view class="foodInfo">
<view class="foodInfoItem" v-for="(item,index) in activeType.nutrients_four"
@ -144,39 +126,10 @@
<blue-tooth @handleBle="handleBle" :weightType="'2'" :weightKcal="weightKcal"
@realTimeWeight="realTimeWeight" :btnType="'2'"></blue-tooth>
</view>
<!-- 手动输入 -->
<!-- <view v-else>
<view class="val">
<input type="digit" v-model="activeType.weight" placeholder="请输入"
@input="replaceInput" />
<text class="unit"></text>
</view>
<view class="btn" @click="Next()">确认添加</view>
</view> -->
</view>
<!-- 营养分析 -->
<view class="foodDetail">
<view class="foodContent">
<!-- <view class="title">热量和营养</view>
<view class="progress">
<div class="chart-wrap">
<qiun-data-charts type="ring" :opts="opts" :chartData="chartData" :cHeight="280"
:cWidth="280" />
</div>
<view class="info" v-if="activeType.nutrients_four">
<view class="info-item"
v-for="(item,index) in activeType.nutrients_four.slice(1)" :key="index">
<view class="name">
<text class="color"
:style="{'background-color':`${item.color}`}"></text>
{{item.name}}
</view>
<view class="weight">
<text>{{item.value}}{{item.unit}}</text>|<text>{{item.proportion}}%</text>
</view>
</view>
</view>
</view> -->
<view class="tips">
<text>营养素</text>
<text>{{Math.floor(activeType.weight)}}含量</text>
@ -196,12 +149,23 @@
</view>
</view>
</view>
<!-- 语音 -->
<view class="footBtn">
<!-- 底部购物车 -->
<view class="groupbtn">
<view @click="isShop =! isShop" class="left">
<view class="che">
<text>{{ActiveList.filter(ite => ite.meals_type == foodName).length||0}}</text>
<icon class="t-icon t-icon-canpan"></icon>
</view>
<view class="type">
{{foodName}}
<image src="/static/arrow-down.png"></image>
</view>
</view>
<view class="mic-icon" @touchstart="onVoiceTouchStart" @touchend="onVoiceTouchEnd">
<uni-icons type="mic-filled" size="20" :color="mic_touch ? '#777777' : '#fff'"></uni-icons>
语音搜索
</view>
<!-- <view class="subbtn" @click="handlesubbtn"> 完成</view> -->
</view>
</view>
</template>
@ -244,7 +208,7 @@
};
},
computed: {
...mapState(["configInfo", "user", 'bleValue']),
...mapState(["configInfo", "user", 'bleValue', "countFoodInfo"]),
popular_food() {
return this.configInfo.search_guess.food_data
},
@ -274,6 +238,7 @@
},
bleValue: {
handler(newVal, oldVal) {
console.log("实时bleValue", newVal)
this.realTimeWeight(newVal.countWeight, newVal.unit)
},
deep: true
@ -317,34 +282,12 @@
that.mic_touch = false
that.voiceManager.stop()
},
//
handleBle(weight, unit, kcal) {
let that = this
that.isBle = false
that.activeType.weight = weight
that.activeType.unit = unit
that.activeType.kcal = kcal
that.Next()
},
//
handleToggle(name) {
this.search_value = ""
this.search_list = []
this.foodName = name
},
handleToggleBle() {
let that = this
that.isBle = !that.isBle
if (!that.isBle) {
that.activeType.weight = that.activeType.weight != 0 ? that.activeType.weight : ''
}
},
//
replaceInput(event) {
let weight = event.target.value
this.activeType = Object.assign({}, this.activeType, {
weight: weight
})
},
//
realTimeWeight(weight, unit) {
this.activeType = Object.assign({}, this.activeType, {
@ -398,24 +341,44 @@
}]
}));
},
//
Next() {
//
handleBle(weight, unit, kcal) {
let that = this
let ite = that.activeType
let list = []
that.activeType.unit = unit
that.activeType.kcal = kcal
that.activeType.weight = weight
that.activeType.meals_type = that.foodName
list.push(that.activeType)
that.$model.getAddIntakeFood({
aud_id: that.user.aud_id,
food_list: list,
time: that.time
}).then(res => {
if (res.code != 0) return
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo")
} else {
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.time
})
}
that.activeType.food_id = res.data.id
if (that.activeType.weight <= 0) {
that.$tools.msg("请输入重量")
return
}
that.isBle = false
that.IsWeight = false
if (that.ActiveList.indexOf(ite) == -1) {
that.ActiveList.push(ite);
if (that.ActiveList.indexOf(that.activeType) == -1) {
that.ActiveList.push(that.activeType);
} else {
let index = that.ActiveList.indexOf(ite)
let index = that.ActiveList.indexOf(that.activeType)
that.ActiveList[index].weight = that.activeType.weight;
that.ActiveList[index].unit = that.activeType.unit;
}
console.log("保存", that.ActiveList)
})
},
//
handleSerach() {
@ -466,44 +429,37 @@
that.mic_touch = false
that.voiceManager.stop()
},
//
changeClickType(e) {
this.search_value = ""
this.search_list = []
this.foodName = this.foodItem[e.target.value].name
},
//
handlesubbtn() {
//
handledelactive(ite) {
let that = this
if (that.ActiveList.length <= 0) {
that.$tools.msg("请添加食物")
return
}
that.$model.getAddIntakeFood({
uni.showModal({
content: `是否删除[${ite.name}]`,
success: (res) => {
if (res.confirm) {
this.$model.delCEatAction({
aud_id: that.user.aud_id,
food_list: that.ActiveList,
time: that.time
eat_log_id: ite.food_id
}).then(res => {
if (res.code != 0) return
that.ActiveList.splice(that.ActiveList.indexOf(ite), 1);
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo")
} else {
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.time
})
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo")
}
setTimeout(function() {
uni.navigateBack({
delta: 1
})
}, 200)
}
}
})
},
//
handledelactive(ite) {
let that = this
that.ActiveList.splice(that.ActiveList.indexOf(ite), 1);
},
}
}
</script>
@ -832,10 +788,11 @@
justify-content: space-between;
padding: 0 20rpx;
position: fixed;
bottom: 150rpx;
bottom: 0rpx;
left: 0;
right: 0;
height: 55px;
height: 60px;
padding-bottom: 15px;
z-index: 15;
background-color: #fff;
overflow: hidden;
@ -852,10 +809,10 @@
}
.left {
width: 50%;
width: 110px;
display: flex;
align-items: center;
}
.che {
width: 80rpx;
@ -893,6 +850,18 @@
}
}
.mic-icon {
color: #fff;
width: calc(100% - 120px);
padding: 8px 0;
background: $maincolor;
display: flex;
align-items: center;
justify-content: center;
border-radius: 20rpx;
}
}
.wrapper {
.box {
top: 40px;
@ -1169,11 +1138,19 @@
}
.item {
width: 100%;
height: 45px;
display: flex;
position: relative;
justify-content: end;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #f7f7f7;
.item-left {
width: 80%;
display: flex;
align-items: center;
image {
width: 90rpx;
height: 90rpx;
@ -1185,6 +1162,7 @@
display: flex;
flex-direction: column;
margin-left: 10px;
height: 40px;
justify-content: space-between;
text {
@ -1197,6 +1175,7 @@
color: #999;
}
}
}
.icon-ashbin {
position: absolute;

View File

@ -122,7 +122,8 @@
"path": "count/setting",
"style": {
"navigationBarTitleText": "设置",
"enablePullDownRefresh": false
"enablePullDownRefresh": false,
"disableSwipeBack": true
}
}, {

View File

@ -13,7 +13,7 @@
<blue-tooth :weightType="'2'" :btnType="'1'"></blue-tooth>
</view>
<!-- 每日摄入 -->
<view class="box" v-if="userinfo">
<view class="box" v-if="user.aud_id!=''">
<!-- 日期选择 -->
<view class="data">
<picker mode="date" :end="endDate" @change="changeClickDate"
@ -132,7 +132,7 @@
<view class="progress">
<div class="chart-wrap">
<qiun-data-charts type="ring" :opts="opts" :chartData="chartData2" :cHeight="280"
:cWidth="280" :canvas2d="true" />
:cWidth="280" :canvas2d="true" canvasId="count2"/>
</div>
<view class="info" v-if="activeFoodDetail.nutrients_four">
<view class="info-item" v-for="(item,index) in activeFoodDetail.nutrients_four.slice(1)"
@ -204,9 +204,6 @@
},
computed: {
...mapState(["user", "countFoodInfo"]),
userinfo() {
return this.user.aud_id
},
foodInfo() {
let that = this
that.chartData.series[0].data = that.countFoodInfo.nutrients_four[0].proportion / 100

View File

@ -7,15 +7,15 @@
</view>
<!-- 个人资料 -->
<view v-if="token" class="content-box">
<view class="box" v-if="info.aud_id">
<view class="box" v-if="info.aud_id!=''">
<view class="info">
<!-- /pageTwo/me/userEdit -->
<view class="name" @click="navTo('/pageTwo/count/setting')">
<view class="name" @click="navTo('/pageTwo/me/userEdit')">
<image :src="info.head_pic"></image>
<text class="bold">{{info.nickname}}</text>
<text>{{info.gender=='1'?'男':'女'}}</text>
</view>
<view class="edit">
<view class="edit" @click="navTo('/pageTwo/me/userEdit')">
<image src="/static/26.png"></image>
</view>
</view>
@ -48,8 +48,8 @@
</view>
<view class="left">
<view class="chart-wrap">
<qiun-data-charts type="arcbar" :chartData="chartData" :cHeight="280" :cWidth="280"
:canvas2d="true" canvasId="home1"/>
<qiun-data-charts type="arcbar" :chartData="chartData" :cHeight="280" :cWidth="280" :canvas2d="true"
canvasId="home1" />
<view class="center">
摄入
<text>{{foodInfo.nutrients_four[0].today_intake}}</text>
@ -132,6 +132,7 @@
data() {
return {
token: "",
foodInfo: [],
chartData: {
series: [{
data: 0,
@ -144,24 +145,53 @@
qiunDataCharts
},
computed: {
...mapState(["configInfo", "user", "countFoodInfo"]),
...mapState(["configInfo", "user", "countFoodInfo", "bleValue"]),
info() {
return this.user
},
kcalVal() {
return this.configInfo.kcal_data
},
foodInfo() {
let that = this
that.chartData.series[0].data = that.user.aud_id ? that.user.food_count.nutrients_four[0].proportion /
100 : 0
return uni.getStorageSync('token') ? that.user.food_count : that.configInfo.food_count
},
// foodInfo() {
// let that = this
// return that.user.aud_id != "" ? that.user.food_count : that.configInfo.default_count_foot
// },
},
onLoad() {
let that = this
that.token = uni.getStorageSync('token')
that.$store.dispatch("getHomeConfig")
if (that.token) {
that.$ble.openBluetoothAdapter()
}
that.$ble.onBLEConnectionStateChange()
uni.onBluetoothAdapterStateChange(function(res) {
that.$store.commit("changeBluetooth", res.available);
})
},
watch: {
user: {
handler(newVal, oldVal) {
let that = this
that.foodInfo = newVal.aud_id != "" ? that.user.food_count : that.configInfo.default_count_foot
that.chartData.series[0].data = newVal.aud_id != "" ? newVal.food_count.nutrients_four[0].proportion /
100 : 0
},
immediate: true,
deep: true
},
bleValue: {
handler(newVal, oldVal) {
console.log("实时bleValue", newVal)
if (newVal.serviceId != '' && newVal.oldCountWeight != newVal.countWeight) {
uni.switchTab({
url: "/pages/count/count"
})
newVal.oldCountWeight = newVal.countWeight
}
},
deep: true
}
},
onPullDownRefresh() {
let that = this

View File

@ -41,7 +41,7 @@
</view>
<uni-icons type="forward" size="20" color="#666"></uni-icons>
</view>
<view class="item" @click="navTo('/pageTwo/webview/webview?url=' + configInfo.business_cooperation)">
<view class="item" @click="navTo('/pageTwo/webview/webview?url=' + configInfo.business_cooperation.jump_url)">
<view>
<image src="/static/14.png" mode=""></image>商务合作
</view>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB

View File

@ -21,7 +21,9 @@ export default {
}) {
return model.getHomeUserInfo({}).then(res => {
if (res.code != 0) {
commit('changeUserInfo', {})
commit('changeUserInfo', {
aud_id: ""
})
return
}
commit('changeUserInfo', res.data)

View File

@ -55,8 +55,11 @@ export default new Vuex.Store({
serviceId: "",
notify: "",
write: "",
unit: "",
unit: "g",
oldCountWeight: 0,
countWeight: 100,
bleTipsText: "",
isConnectStatus: null,
},
isBluetoothTyle: false,
},

306
tools/bluetooth.js Normal file
View File

@ -0,0 +1,306 @@
import $store from '@/store'
let searchTimer = null
let devicesList = []
// 初始化蓝牙
function openBluetoothAdapter() {
uni.openBluetoothAdapter({
success: e => {
$store.commit("changeBluetoothValue", {
bleTipsText: "蓝牙搜索中",
isConnectStatus: 0
})
startBluetoothDeviceDiscovery()
},
fail: e => {
$store.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1
})
}
});
}
// 开始搜寻附近的蓝牙外围设备
function startBluetoothDeviceDiscovery() {
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
services: [],
success: res => {
onBluetoothDeviceFound();
searchTimer = setTimeout(() => {
uni.stopBluetoothDevicesDiscovery()
if (!devicesList.length) {
clearTimeout(searchTimer);
$store.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1
});
}
}, 30000); // 30秒超时
},
fail: res => {
$store.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1
})
}
});
}
/**
* 发现外围设备
*/
function onBluetoothDeviceFound() {
uni.onBluetoothDeviceFound(res => {
res.devices.forEach(device => {
device.advertisData = device.advertisData ? device.advertisData : ''
let value = ab2hex(device.advertisData, "")
let id = value.substring(0, 4)
if (!device.name && !device.localName) {
return
}
if (device.name.indexOf('Chipsea-BLE') != -1 || (device.localName && device
.localName.indexOf('Chipsea-BLE') != -1) || id == 'a5fe') {
clearTimeout(searchTimer);
stopBluetoothDevicesDiscovery()
Bluetoothfilter(device.deviceId)
return
}
})
});
}
// 过滤蓝牙
function Bluetoothfilter(device_id) {
const foundDevices = devicesList
const idx = inArray(foundDevices, "deviceId", device_id)
if (idx === -1) {
devicesList.push(device_id);
connectDevice(device_id)
}
}
//连接设备
function connectDevice(device_id) {
uni.createBLEConnection({
deviceId: device_id,
success: res => {
setTimeout(function() {
getBLEDeviceServices(device_id)
}, 200)
},
fail: res => {
console.log("连接失败,点击重新连接", res);
}
});
}
/**
* 获取设备的UUID
*/
function getBLEDeviceServices(device_id) {
let serviceList = [];
uni.getBLEDeviceServices({
deviceId: device_id,
success: res => {
console.log("获取设备的UUID成功", res)
serviceList = res.services;
for (let i = 0; i < serviceList.length; i++) {
let service = serviceList[i];
if (service.uuid.indexOf("FFF0") != -1) {
getBLEDeviceCharacteristics(device_id, service.uuid);
break;
}
}
},
fail: res => {
console.log('获取设备的UUID失败:', res)
}
});
}
/**
* 获取指定服务的特征值
*/
function getBLEDeviceCharacteristics(deviceId, serviceId) {
let characteristicsList = [];
uni.getBLEDeviceCharacteristics({
deviceId: deviceId,
serviceId: serviceId,
success: res => {
let write, notify
for (let i = 0; i < res.characteristics.length; i++) {
let item = res.characteristics[i];
if (item.uuid.indexOf('0000FFF2') != -1) {
write = item.uuid
} else if (item.uuid.indexOf('0000FFF1') != -1) {
notify = item.uuid
}
}
$store.commit('changeBluetoothValue', {
deviceId: deviceId,
serviceId: serviceId,
notify: notify,
write: write,
unit: "g",
countWeight: 0,
})
getBLECharacteristicValueChange(deviceId, serviceId, notify)
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
})
}
function getBLECharacteristicValueChange(deviceId, serviceId, notify) {
let that = this
uni.notifyBLECharacteristicValueChange({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: notify,
state: true,
success: () => {
$store.commit("changeBluetoothValue", {
bleTipsText: "测量中,请将食物放到秤上",
isConnectStatus: 0
})
uni.onBLECharacteristicValueChange(function(res) {
const value = res.value
const dataView = new DataView(value)
const header = dataView.getUint8(0)
// MCU主动上报数据
if (header === 0xC7) {
const cmd = dataView.getUint8(2)
switch (cmd) {
case 0x02:
let units = ['kg', '斤', 'st:lb', 'lb', 'g', 'ml', 'Waterml',
'milkml', 'oz', 'floz', 'lboz'
]
const statusByte = dataView.getUint8(4)
const isNegative = !!(statusByte & 0x80) // 最高位表示正负
const statusType = statusByte & 0x0F // 状态类型
// 组合24位重量值 (大端序)
const weightValue =
(dataView.getUint8(5) << 16) |
(dataView.getUint8(6) << 8) |
dataView.getUint8(7)
// 精度和单位
const unitByte = dataView.getUint8(8)
const precision = (unitByte & 0xF0) >> 4 // 高4位精度
const unitIndex = unitByte & 0x0F // 低4位单位
// 计算实际重量
let finalWeight = weightValue / Math.pow(10, precision)
if (isNegative) finalWeight = -finalWeight
$store.commit("changeBluetoothValue", {
countWeight: finalWeight,
unit: units[unitIndex]
})
break
case 0x03:
break
}
}
})
},
fail: res => {
console.log('获取特征值失败:', JSON.stringify(res))
}
})
}
function inArray(arr, key, val) {
if (!arr || !arr.length || typeof arr != 'object' || !Array.isArray(arr)) {
return -1
}
for (let i = 0; i < arr.length; i++) {
if (!key) {
if (arr[i] == val) {
return i
}
} else if (arr[i][key] === val) {
return i
}
}
return -1;
}
function ab2hex(buffer, split) {
var hexArr = Array.prototype.map.call(
new Uint8Array(buffer),
function(bit) {
return ('00' + bit.toString(16)).slice(-2)
}
)
return hexArr.join(split);
}
/**
* 断开蓝牙模块
*/
function closeBluetoothAdapter() {
uni.closeBluetoothAdapter({
success: res => {
$store.commit("changeBluetoothValue", {
deviceId: "",
serviceId: "",
notify: "",
write: "",
unit: "g",
countWeight: 0,
})
console.log('蓝牙模块关闭成功');
}
})
}
/**
* 断开蓝牙连接
*/
function closeBLEConnection(deviceId) {
uni.closeBLEConnection({
deviceId: deviceId,
success: res => {
console.log('断开蓝牙连接成功');
}
});
}
// 监听蓝牙连接状态
function onBLEConnectionStateChange() {
uni.onBLEConnectionStateChange(function(res) {
console.log("监听蓝牙连接状态", res.connected)
if (!res.connected) {
$store.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1
})
closeBLEConnection()
closeBluetoothAdapter()
}
$store.commit("changeBluetooth", res.connected);
})
}
/**
* 停止搜索蓝牙设备
*/
function stopBluetoothDevicesDiscovery() {
uni.stopBluetoothDevicesDiscovery({
success: e => {
console.log("停止搜索蓝牙设备", e)
},
});
}
export default {
ab2hex,
inArray,
openBluetoothAdapter,
startBluetoothDeviceDiscovery,
onBluetoothDeviceFound,
Bluetoothfilter,
connectDevice,
getBLEDeviceServices,
getBLEDeviceCharacteristics,
closeBluetoothAdapter,
closeBLEConnection,
onBLEConnectionStateChange,
stopBluetoothDevicesDiscovery
}

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -16,6 +16,7 @@ __webpack_require__(/*! uni-pages */ 26);
var _App = _interopRequireDefault(__webpack_require__(/*! ./App */ 27));
var _store = _interopRequireDefault(__webpack_require__(/*! ./store */ 33));
var _tools = _interopRequireDefault(__webpack_require__(/*! @/tools/tools.js */ 38));
var _bluetooth = _interopRequireDefault(__webpack_require__(/*! @/tools/bluetooth.js */ 417));
var _https = _interopRequireDefault(__webpack_require__(/*! @/tools/https.js */ 37));
var _model = _interopRequireDefault(__webpack_require__(/*! @/tools/model.js */ 36));
var _content = _interopRequireDefault(__webpack_require__(/*! @/content.json */ 40));
@ -28,6 +29,9 @@ _vue.default.prototype.$store = _store.default;
// js
_vue.default.prototype.$tools = _tools.default;
// 蓝牙
_vue.default.prototype.$ble = _bluetooth.default;
//请求
_vue.default.prototype.$http = _https.default;

View File

@ -18485,7 +18485,8 @@ var _default = {
"path": "count/setting",
"style": {
"navigationBarTitleText": "设置",
"enablePullDownRefresh": false
"enablePullDownRefresh": false,
"disableSwipeBack": true
}
}, {
"path": "count/KcalEdit",
@ -26828,8 +26829,11 @@ var _default = new _vuex.default.Store({
serviceId: "",
notify: "",
write: "",
unit: "",
countWeight: 100
unit: "g",
oldCountWeight: 0,
countWeight: 100,
bleTipsText: "",
isConnectStatus: null
},
isBluetoothTyle: false
},
@ -28155,7 +28159,9 @@ var _default = {
dispatch = _ref2.dispatch;
return _model.default.getHomeUserInfo({}).then(function (res) {
if (res.code != 0) {
commit('changeUserInfo', {});
commit('changeUserInfo', {
aud_id: ""
});
return;
}
commit('changeUserInfo', res.data);
@ -29079,6 +29085,320 @@ module.exports = JSON.parse("{\"addfoodList\":[{\"name\":\"早加餐\",\"id\":3}
/***/ }),
/***/ 417:
/*!*****************************************************************!*\
!*** E:/qiaocongli///kitchendDevice/tools/bluetooth.js ***!
\*****************************************************************/
/*! no static exports found */
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/* WEBPACK VAR INJECTION */(function(uni) {
var _interopRequireDefault = __webpack_require__(/*! @babel/runtime/helpers/interopRequireDefault */ 4);
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _typeof2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/typeof */ 13));
var _store = _interopRequireDefault(__webpack_require__(/*! @/store */ 33));
var searchTimer = null;
var devicesList = [];
// 初始化蓝牙
function openBluetoothAdapter() {
uni.openBluetoothAdapter({
success: function success(e) {
_store.default.commit("changeBluetoothValue", {
bleTipsText: "蓝牙搜索中",
isConnectStatus: 0
});
startBluetoothDeviceDiscovery();
},
fail: function fail(e) {
_store.default.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1
});
}
});
}
// 开始搜寻附近的蓝牙外围设备
function startBluetoothDeviceDiscovery() {
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
services: [],
success: function success(res) {
onBluetoothDeviceFound();
searchTimer = setTimeout(function () {
uni.stopBluetoothDevicesDiscovery();
if (!devicesList.length) {
clearTimeout(searchTimer);
_store.default.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1
});
}
}, 30000); // 30秒超时
},
fail: function fail(res) {
_store.default.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1
});
}
});
}
/**
* 发现外围设备
*/
function onBluetoothDeviceFound() {
uni.onBluetoothDeviceFound(function (res) {
res.devices.forEach(function (device) {
device.advertisData = device.advertisData ? device.advertisData : '';
var value = ab2hex(device.advertisData, "");
var id = value.substring(0, 4);
if (!device.name && !device.localName) {
return;
}
if (device.name.indexOf('Chipsea-BLE') != -1 || device.localName && device.localName.indexOf('Chipsea-BLE') != -1 || id == 'a5fe') {
clearTimeout(searchTimer);
stopBluetoothDevicesDiscovery();
Bluetoothfilter(device.deviceId);
return;
}
});
});
}
// 过滤蓝牙
function Bluetoothfilter(device_id) {
var foundDevices = devicesList;
var idx = inArray(foundDevices, "deviceId", device_id);
if (idx === -1) {
devicesList.push(device_id);
connectDevice(device_id);
}
}
//连接设备
function connectDevice(device_id) {
uni.createBLEConnection({
deviceId: device_id,
success: function success(res) {
setTimeout(function () {
getBLEDeviceServices(device_id);
}, 200);
},
fail: function fail(res) {
console.log("连接失败,点击重新连接", res);
}
});
}
/**
* 获取设备的UUID
*/
function getBLEDeviceServices(device_id) {
var serviceList = [];
uni.getBLEDeviceServices({
deviceId: device_id,
success: function success(res) {
console.log("获取设备的UUID成功", res);
serviceList = res.services;
for (var i = 0; i < serviceList.length; i++) {
var service = serviceList[i];
if (service.uuid.indexOf("FFF0") != -1) {
getBLEDeviceCharacteristics(device_id, service.uuid);
break;
}
}
},
fail: function fail(res) {
console.log('获取设备的UUID失败:', res);
}
});
}
/**
* 获取指定服务的特征值
*/
function getBLEDeviceCharacteristics(deviceId, serviceId) {
var characteristicsList = [];
uni.getBLEDeviceCharacteristics({
deviceId: deviceId,
serviceId: serviceId,
success: function success(res) {
var write, notify;
for (var i = 0; i < res.characteristics.length; i++) {
var item = res.characteristics[i];
if (item.uuid.indexOf('0000FFF2') != -1) {
write = item.uuid;
} else if (item.uuid.indexOf('0000FFF1') != -1) {
notify = item.uuid;
}
}
_store.default.commit('changeBluetoothValue', {
deviceId: deviceId,
serviceId: serviceId,
notify: notify,
write: write,
unit: "g",
countWeight: 0
});
getBLECharacteristicValueChange(deviceId, serviceId, notify);
},
fail: function fail(res) {
console.log('获取特征值失败:', JSON.stringify(res));
}
});
}
function getBLECharacteristicValueChange(deviceId, serviceId, notify) {
var that = this;
uni.notifyBLECharacteristicValueChange({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: notify,
state: true,
success: function success() {
_store.default.commit("changeBluetoothValue", {
bleTipsText: "测量中,请将食物放到秤上",
isConnectStatus: 0
});
uni.onBLECharacteristicValueChange(function (res) {
var value = res.value;
var dataView = new DataView(value);
var header = dataView.getUint8(0);
// MCU主动上报数据
if (header === 0xC7) {
var cmd = dataView.getUint8(2);
switch (cmd) {
case 0x02:
var units = ['kg', '斤', 'st:lb', 'lb', 'g', 'ml', 'Waterml', 'milkml', 'oz', 'floz', 'lboz'];
var statusByte = dataView.getUint8(4);
var isNegative = !!(statusByte & 0x80); // 最高位表示正负
var statusType = statusByte & 0x0F; // 状态类型
// 组合24位重量值 (大端序)
var weightValue = dataView.getUint8(5) << 16 | dataView.getUint8(6) << 8 | dataView.getUint8(7);
// 精度和单位
var unitByte = dataView.getUint8(8);
var precision = (unitByte & 0xF0) >> 4; // 高4位精度
var unitIndex = unitByte & 0x0F; // 低4位单位
// 计算实际重量
var finalWeight = weightValue / Math.pow(10, precision);
if (isNegative) finalWeight = -finalWeight;
_store.default.commit("changeBluetoothValue", {
countWeight: finalWeight,
unit: units[unitIndex]
});
break;
case 0x03:
break;
}
}
});
},
fail: function fail(res) {
console.log('获取特征值失败:', JSON.stringify(res));
}
});
}
function inArray(arr, key, val) {
if (!arr || !arr.length || (0, _typeof2.default)(arr) != 'object' || !Array.isArray(arr)) {
return -1;
}
for (var i = 0; i < arr.length; i++) {
if (!key) {
if (arr[i] == val) {
return i;
}
} else if (arr[i][key] === val) {
return i;
}
}
return -1;
}
function ab2hex(buffer, split) {
var hexArr = Array.prototype.map.call(new Uint8Array(buffer), function (bit) {
return ('00' + bit.toString(16)).slice(-2);
});
return hexArr.join(split);
}
/**
* 断开蓝牙模块
*/
function closeBluetoothAdapter() {
uni.closeBluetoothAdapter({
success: function success(res) {
_store.default.commit("changeBluetoothValue", {
deviceId: "",
serviceId: "",
notify: "",
write: "",
unit: "g",
countWeight: 0
});
console.log('蓝牙模块关闭成功');
}
});
}
/**
* 断开蓝牙连接
*/
function closeBLEConnection(deviceId) {
uni.closeBLEConnection({
deviceId: deviceId,
success: function success(res) {
console.log('断开蓝牙连接成功');
}
});
}
// 监听蓝牙连接状态
function onBLEConnectionStateChange() {
uni.onBLEConnectionStateChange(function (res) {
console.log("监听蓝牙连接状态", res.connected);
if (!res.connected) {
_store.default.commit("changeBluetoothValue", {
bleTipsText: "连接超时,点击重新连接",
isConnectStatus: 1
});
closeBLEConnection();
closeBluetoothAdapter();
}
_store.default.commit("changeBluetooth", res.connected);
});
}
/**
* 停止搜索蓝牙设备
*/
function stopBluetoothDevicesDiscovery() {
uni.stopBluetoothDevicesDiscovery({
success: function success(e) {
console.log("停止搜索蓝牙设备", e);
}
});
}
var _default = {
ab2hex: ab2hex,
inArray: inArray,
openBluetoothAdapter: openBluetoothAdapter,
startBluetoothDeviceDiscovery: startBluetoothDeviceDiscovery,
onBluetoothDeviceFound: onBluetoothDeviceFound,
Bluetoothfilter: Bluetoothfilter,
connectDevice: connectDevice,
getBLEDeviceServices: getBLEDeviceServices,
getBLEDeviceCharacteristics: getBLEDeviceCharacteristics,
closeBluetoothAdapter: closeBluetoothAdapter,
closeBLEConnection: closeBLEConnection,
onBLEConnectionStateChange: onBLEConnectionStateChange,
stopBluetoothDevicesDiscovery: stopBluetoothDevicesDiscovery
};
exports.default = _default;
/* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./node_modules/@dcloudio/uni-mp-weixin/dist/index.js */ 2)["default"]))
/***/ }),
/***/ 5:
/*!**************************************************************!*\
!*** ./node_modules/@babel/runtime/helpers/slicedToArray.js ***!

View File

@ -147,8 +147,6 @@ Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _regenerator = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/regenerator */ 269));
var _asyncToGenerator2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/asyncToGenerator */ 272));
var _defineProperty2 = _interopRequireDefault(__webpack_require__(/*! @babel/runtime/helpers/defineProperty */ 11));
var _vuex = __webpack_require__(/*! vuex */ 34);
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
@ -158,14 +156,10 @@ var nextCnt = 0;
var _default = {
data: function data() {
return {
dw: "克",
kcal: 0,
unit: '',
isShow: false,
bleTipsText: "",
inputDialog: false,
isConnection: 0,
//是否连接成功
unitList: [{
name: "克",
id: '00',
@ -198,17 +192,19 @@ var _default = {
computed: _objectSpread(_objectSpread({}, (0, _vuex.mapState)(["bleValue", "isBluetoothTyle", "countFoodInfo"])), {}, {
weight: function weight() {
this.unit = this.unitConversion(this.bleValue.unit);
return this.bleValue.countWeight;
},
isConnection: function isConnection() {
this.bleTipsText = this.bleValue.bleTipsText;
return this.bleValue.isConnectStatus;
},
isShow: function isShow() {
return this.bleValue.serviceId != '' ? true : false;
}
}),
mounted: function mounted() {
var that = this;
if (that.bleValue.serviceId != '') {
that.getBLECharacteristicValueChange(that.bleValue.deviceId, that.bleValue.serviceId, that.bleValue.notify);
} else {
that.openBluetoothAdapter();
}
that.onBLEConnectionStateChange();
uni.onBluetoothAdapterStateChange(function (res) {
that.$store.commit("changeBluetooth", res.available);
});
@ -230,278 +226,31 @@ var _default = {
// 初始化蓝牙
openBluetoothAdapter: function openBluetoothAdapter() {
var that = this;
if (that.isConnection == 0) return;
that.kcal = "";
that.isShow = false;
that.bleTipsText = "蓝牙搜索中";
uni.openBluetoothAdapter({
success: function success(e) {
that.isConnection = 0;
that.startBluetoothDeviceDiscovery();
},
fail: function fail(e) {
that.isConnection = 0;
that.bleTipsText = "请确定设备和手机蓝牙已打开!";
console.log('openBluetoothAdapter', e);
}
});
},
// 开始搜寻附近的蓝牙外围设备
startBluetoothDeviceDiscovery: function startBluetoothDeviceDiscovery() {
var that = this;
uni.startBluetoothDevicesDiscovery({
allowDuplicatesKey: true,
services: [
// "F0A0",
// "A5FE"
],
success: function success(res) {
that.isConnection = 0;
that.onBluetoothDeviceFound();
},
fail: function fail(res) {
that.isConnection = 0;
that.bleTipsText = "请确定设备和手机蓝牙已打开!";
console.log('startBluetoothDeviceDiscovery', res);
}
});
},
// 监听蓝牙连接状态
onBLEConnectionStateChange: function onBLEConnectionStateChange() {
var that = this;
uni.onBLEConnectionStateChange(function (res) {
console.log("监听蓝牙连接状态", res.connected);
if (!res.connected) {
that.isConnection = 1;
that.closeBLEConnection();
that.closeBluetoothAdapter();
}
that.$store.commit("changeBluetooth", res.connected);
});
},
/**
* 停止搜索蓝牙设备
*/
stopBluetoothDevicesDiscovery: function stopBluetoothDevicesDiscovery() {
uni.stopBluetoothDevicesDiscovery({
success: function success(e) {
console.log("停止搜索蓝牙设备", e);
}
});
},
/**
* 发现外围设备
*/
onBluetoothDeviceFound: function onBluetoothDeviceFound() {
var that = this;
that.isConnection = 0;
uni.onBluetoothDeviceFound(function (res) {
res.devices.forEach(function (device) {
device.advertisData = device.advertisData ? device.advertisData : '';
device.advertisServiceUUIDs = device.advertisServiceUUIDs ? device.advertisServiceUUIDs : "";
var value = that.$tools.ab2hex(device.advertisData, "");
var id = value.substring(0, 4);
if (!device.name && !device.localName) {
return;
}
if (device.name.indexOf("EL") !== -1 && device.advertisServiceUUIDs != '') {
that.isConnection = 0;
that.bleTipsText = "测量中,请将食物放到秤上";
var _value = that.$tools.ab2hex(device.advertisData);
var parseDataRes = plugin.parseBroadcastData(device.advertisData);
var analyzeData = plugin.analyzeBroadcastScaleData(parseDataRes);
var analyzeDataText = analyzeData.text;
var data = analyzeData.data;
if (parseDataRes.status == 1) {
var data0 = parseDataRes.payload;
var _data = parseInt(data0[3]).toString(16);
console.log('data' + _data);
var data1 = parseInt(data0[4]).toString(16);
var data2 = parseInt(_data + data1, 16); //重量
//
var unit0 = parseInt(data0[5]).toString(16); //单位小数点
var unit = unit0.length > 1 ? unit0.substring(1, 2) : unit0; //单位
var num = parseInt(unit0.substring(0, 1), 16).toString(8);
var dot = num.toString().substring(0, 1); //小数点
var zfz = 0; //正负值
if (num.toString().length > 1) {
dot = num.toString().substring(1, 2);
zfz = num.toString().substring(0, 1);
}
if (unit == '0') {
that.dw = 'g';
}
if (unit == "7") {
that.dw = "ml";
}
if (unit == "3") {
that.dw = "oz";
}
if (unit == "2") {
that.dw = "lb'oz";
}
if (dot == "1") {
data2 = data2 / 10;
}
if (dot == "2") {
data2 = data2 / 100;
}
if (zfz == "0") {
data2 = data2;
}
if (zfz == "1") {
data2 = "-" + data2;
}
that.weight = data2;
that.kcal = (Number(that.weightKcal) / 100 * data2).toFixed(2);
that.$emit('realTimeWeight', data2, that.dw);
}
return;
}
if (device.name.indexOf('Chipsea-BLE') != -1 || device.localName && device.localName.indexOf('Chipsea-BLE') != -1 || id == 'a5fe') {
that.stopBluetoothDevicesDiscovery();
that.connectDevice(device.deviceId);
return;
}
});
});
},
//连接设备
connectDevice: function connectDevice(device_id) {
var _this = this;
return (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
var that;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
that = _this;
uni.createBLEConnection({
deviceId: device_id,
success: function success(res) {
setTimeout(function () {
that.getBLEDeviceServices(device_id);
}, 200);
},
fail: function fail(res) {
console.log("设备连接失败,请重新连接", res);
}
});
case 2:
case "end":
return _context.stop();
}
}
}, _callee);
}))();
},
/**
* 获取设备的UUID
*/
getBLEDeviceServices: function getBLEDeviceServices(device_id) {
var serviceList = [];
var that = this;
uni.getBLEDeviceServices({
deviceId: device_id,
success: function success(res) {
console.log("获取设备的UUID成功", res);
serviceList = res.services;
for (var i = 0; i < serviceList.length; i++) {
var service = serviceList[i];
if (service.uuid.indexOf("FFF0") != -1) {
that.getBLEDeviceCharacteristics(device_id, service.uuid);
break;
}
}
},
fail: function fail(res) {
console.log('获取设备的UUID失败:', res);
}
});
},
/**
* 获取指定服务的特征值
*/
getBLEDeviceCharacteristics: function getBLEDeviceCharacteristics(deviceId, serviceId) {
var characteristicsList = [];
var that = this;
uni.getBLEDeviceCharacteristics({
deviceId: deviceId,
serviceId: serviceId,
success: function success(res) {
console.log("服务的特征值成功", res);
var write, notify;
for (var i = 0; i < res.characteristics.length; i++) {
var item = res.characteristics[i];
if (item.uuid.indexOf('0000FFF2') != -1) {
write = item.uuid;
} else if (item.uuid.indexOf('0000FFF1') != -1) {
notify = item.uuid;
}
}
var info = {
deviceId: deviceId,
serviceId: serviceId,
notify: notify,
write: write
};
that.handletoggleUnit(0x04);
that.$store.commit('changeBluetoothValue', info);
setTimeout(function () {
that.getBLECharacteristicValueChange(deviceId, serviceId, notify);
}, 300);
},
fail: function fail(res) {
console.log('获取特征值失败:', JSON.stringify(res));
}
});
},
getBLECharacteristicValueChange: function getBLECharacteristicValueChange(deviceId, serviceId, notify) {
var that = this;
uni.notifyBLECharacteristicValueChange({
deviceId: deviceId,
serviceId: serviceId,
characteristicId: notify,
state: true,
success: function success() {
that.isShow = true;
that.isConnection = 0;
that.bleTipsText = "测量中,请将食物放到秤上";
uni.onBLECharacteristicValueChange(function (res) {
var value = res.value;
var dataView = new DataView(value);
var header = dataView.getUint8(0);
console.log("value", that.$tools.ab2hex(res.value, ""));
// MCU主动上报数据
if (header === 0xC7) {
var cmd = dataView.getUint8(2);
switch (cmd) {
case 0x02:
that.parseWeightData(dataView);
break;
case 0x03:
break;
}
}
});
},
fail: function fail(res) {
console.log('获取特征值失败:', JSON.stringify(res));
}
that.$store.commit('changeBluetoothValue', {
deviceId: "",
serviceId: "",
notify: '',
write: '',
unit: "g",
countWeight: 0,
bleTipsText: "蓝牙搜索中",
isConnectStatus: 0
});
that.$ble.openBluetoothAdapter();
},
changleUnits: function changleUnits(e) {
var that = this;
var name = that.unitList[e.detail.value].name;
if (that.isShow && that.dw != name) {
console.log("单位切换", name, that.unit);
if (that.isShow && that.unit != name) {
that.handletoggleUnit(name == '盎司' ? 0x08 : 0x04);
that.$store.commit("changeBluetoothValue", {
countWeight: finalWeight,
unit: that.unitList[e.detail.value].unit
});
}
that.unitListIndex = [e.detail.value];
that.dw = that.unitList[e.detail.value].name;
that.$store.commit('changeBluetoothValue', {
unit: that.unitList[e.detail.value].unit
});
},
handletoggleUnit: function handletoggleUnit(unit) {
var that = this;
@ -537,91 +286,25 @@ var _default = {
}
});
},
parseWeightData: function parseWeightData(dataView) {
var statusByte = dataView.getUint8(4);
var isNegative = !!(statusByte & 0x80); // 最高位表示正负
var statusType = statusByte & 0x0F; // 状态类型
// 组合24位重量值 (大端序)
var weightValue = dataView.getUint8(5) << 16 | dataView.getUint8(6) << 8 | dataView.getUint8(7);
// 精度和单位
var unitByte = dataView.getUint8(8);
var precision = (unitByte & 0xF0) >> 4; // 高4位精度
var unitIndex = unitByte & 0x0F; // 低4位单位
// 计算实际重量
var finalWeight = weightValue / Math.pow(10, precision);
if (isNegative) finalWeight = -finalWeight;
if (this.units[unitIndex] == 'kcal') {
this.dw = '千卡';
} else if (this.units[unitIndex] == 'g') {
this.dw = '克';
} else if (this.units[unitIndex] == 'lb') {
this.dw = '磅';
} else if (this.units[unitIndex] == 'oz') {
this.dw = '盎司';
}
this.$store.commit("changeBluetoothValue", {
countWeight: finalWeight,
unit: this.units[unitIndex]
});
// this.$emit('realTimeWeight', finalWeight, this.dw)
// 状态处理
// if (statusType === 0x02) {
// this.$emit('handleBle', finalWeight,this.unit,0)
// }
},
// 保存测量结果
handlesub: function handlesub() {
var that = this;
console.log("weight", that.weight);
if (Number(that.weight) > 0) {
that.$emit("handleBle", that.weight, that.dw, that.kcal);
that.$emit("handleBle", that.weight, that.unit, that.kcal);
} else {
that.$tools.msg("数据异常,请清零后重新测量!");
}
},
handleBack: function handleBack() {
var that = this;
that.isConnection = 1;
that.stopBluetoothDevicesDiscovery(); //取消蓝牙搜索
that.closeBLEConnection();
that.closeBluetoothAdapter();
},
/**
* 断开蓝牙模块
*/
closeBluetoothAdapter: function closeBluetoothAdapter() {
var that = this;
uni.closeBluetoothAdapter({
success: function success(res) {
that.isConnection = 1;
that.$store.commit("changeBluetoothValue", {
deviceId: "",
serviceId: "",
notify: "",
write: "",
unit: "",
countWeight: 0
});
console.log('蓝牙模块关闭成功');
}
});
},
/**
* 断开蓝牙连接
*/
closeBLEConnection: function closeBLEConnection() {
var that = this;
uni.closeBLEConnection({
deviceId: that.bleValue.deviceId,
success: function success(res) {
that.isConnection = 1;
console.log('断开蓝牙连接成功');
}
bleTipsText: "连接失败,点击重新连接",
isConnectStatus: 1
});
that.$ble.stopBluetoothDevicesDiscovery(); //取消蓝牙搜索
that.$ble.closeBLEConnection(that.bleValue.deviceId);
that.$ble.closeBluetoothAdapter();
},
unitConversion: function unitConversion(unit) {
if (unit == 'kcal') {

View File

@ -1 +1 @@
<view class="weightPages data-v-5fc22dca"><view class="table data-v-5fc22dca"><view class="text data-v-5fc22dca"><image src="/static/zhong.png" class="data-v-5fc22dca"></image><block wx:if="{{isConnection==0}}"><text class="data-v-5fc22dca">{{bleTipsText}}</text></block><block wx:if="{{isConnection==1}}"><text data-event-opts="{{[['tap',[['openBluetoothAdapter',['$event']]]]]}}" bindtap="__e" class="data-v-5fc22dca">连接失败,点击重新连接</text></block></view><block wx:if="{{isShow&&isConnection==0}}"><view data-event-opts="{{[['tap',[['handleBack',['$event']]]]]}}" class="duan data-v-5fc22dca" bindtap="__e">断开连接</view></block></view><view class="weight-wrap data-v-5fc22dca"><view data-event-opts="{{[['tap',[['inputDialogToggle',['$event']]]]]}}" class="weight data-v-5fc22dca" bindtap="__e"><text class="val data-v-5fc22dca">{{weight==''?'--':weight}}</text><text class="unit data-v-5fc22dca">{{dw}}</text></view></view><view class="groupbtn data-v-5fc22dca"><view class="btn danwei data-v-5fc22dca"><view class="lan border-bottom data-v-5fc22dca"><view class="right data-v-5fc22dca"><picker mode="selector" range="{{unitList}}" range-key="name" value="{{unitListIndex}}" data-event-opts="{{[['change',[['changleUnits',['$event']]]]]}}" bindchange="__e" class="data-v-5fc22dca"><view class="uni-input data-v-5fc22dca">单位</view></picker></view></view></view><block wx:if="{{weightType==2&&btnType==2}}"><view data-event-opts="{{[['tap',[['handlesub',['$event']]]]]}}" class="btn addbtn size14 data-v-5fc22dca" bindtap="__e">保存</view></block><block wx:if="{{weightType==2&&btnType==1}}"><view data-event-opts="{{[['tap',[['handleAddFood',['$event']]]]]}}" class="btn addbtn data-v-5fc22dca" bindtap="__e">+</view></block><view data-event-opts="{{[['tap',[['handleqingling',['$event']]]]]}}" class="btn qingling data-v-5fc22dca" bindtap="__e">清零</view></view><view class="data-v-5fc22dca"><uni-popup vue-id="cef7e708-1" type="dialog" data-ref="popup" class="data-v-5fc22dca vue-ref" bind:__l="__l" vue-slots="{{['default']}}"><uni-popup-dialog vue-id="{{('cef7e708-2')+','+('cef7e708-1')}}" mode="input" title="重量" placeholder="请输入食物重量" data-event-opts="{{[['^close',[['close']]],['^confirm',[['confirm']]]]}}" bind:close="__e" bind:confirm="__e" class="data-v-5fc22dca" bind:__l="__l"></uni-popup-dialog></uni-popup></view></view>
<view class="weightPages data-v-5fc22dca"><view class="table data-v-5fc22dca"><view class="text data-v-5fc22dca"><image src="/static/zhong.png" class="data-v-5fc22dca"></image><text data-event-opts="{{[['tap',[['openBluetoothAdapter',['$event']]]]]}}" bindtap="__e" class="data-v-5fc22dca">{{bleTipsText}}</text></view><block wx:if="{{isShow&&isConnection==0}}"><view data-event-opts="{{[['tap',[['handleBack',['$event']]]]]}}" class="duan data-v-5fc22dca" bindtap="__e">断开连接</view></block></view><view class="weight-wrap data-v-5fc22dca"><view data-event-opts="{{[['tap',[['inputDialogToggle',['$event']]]]]}}" class="weight data-v-5fc22dca" bindtap="__e"><text class="val data-v-5fc22dca">{{weight==''?'--':weight}}</text><text class="unit data-v-5fc22dca">{{unit}}</text></view></view><view class="groupbtn data-v-5fc22dca"><view class="btn danwei data-v-5fc22dca"><view class="lan border-bottom data-v-5fc22dca"><view class="right data-v-5fc22dca"><picker mode="selector" range="{{unitList}}" range-key="name" value="{{unitListIndex}}" data-event-opts="{{[['change',[['changleUnits',['$event']]]]]}}" bindchange="__e" class="data-v-5fc22dca"><view class="uni-input data-v-5fc22dca">单位</view></picker></view></view></view><block wx:if="{{weightType==2&&btnType==2}}"><view data-event-opts="{{[['tap',[['handlesub',['$event']]]]]}}" class="btn addbtn size14 data-v-5fc22dca" bindtap="__e">保存</view></block><block wx:if="{{weightType==2&&btnType==1}}"><view data-event-opts="{{[['tap',[['handleAddFood',['$event']]]]]}}" class="btn addbtn data-v-5fc22dca" bindtap="__e">+</view></block><view data-event-opts="{{[['tap',[['handleqingling',['$event']]]]]}}" class="btn qingling data-v-5fc22dca" bindtap="__e">清零</view></view><view class="data-v-5fc22dca"><uni-popup vue-id="cef7e708-1" type="dialog" data-ref="popup" class="data-v-5fc22dca vue-ref" bind:__l="__l" vue-slots="{{['default']}}"><uni-popup-dialog vue-id="{{('cef7e708-2')+','+('cef7e708-1')}}" mode="input" title="重量" placeholder="请输入食物重量" data-event-opts="{{[['^close',[['close']]],['^confirm',[['confirm']]]]}}" bind:close="__e" bind:confirm="__e" class="data-v-5fc22dca" bind:__l="__l"></uni-popup-dialog></uni-popup></view></view>

View File

@ -215,7 +215,7 @@ var _default = {
}
that.chartData2 = JSON.parse(JSON.stringify({
series: [{
data: chart_data
data: chart_data2
}]
}));
}

View File

@ -312,13 +312,14 @@ var _default = {
aud_id: that.user.aud_id,
eat_log_id: item.id
}).then(function (res) {
// 删除最新一天食物
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo");
} else {
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.time
});
// 删除最新一天食物
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo");
}
});
}

View File

@ -130,13 +130,9 @@ var render = function () {
var g2 = !g0 && g1 ? _vm.history_food.length : null
var g3 = !g0 && g1 && !_vm.showAll ? _vm.history_food.slice(0, 10) : null
var g4 = _vm.search_list.length
var g5 =
_vm.ActiveList.filter(function (ite) {
return ite.meals_type == _vm.foodName
}).length || 0
var g6 = _vm.isShop ? _vm.ActiveList.length : null
var g7 =
_vm.isShop && g6
var g5 = _vm.isShop ? _vm.ActiveList.length : null
var g6 =
_vm.isShop && g5
? _vm.ActiveList.filter(function (ite) {
return ite.meals_type == _vm.foodName
}).length
@ -145,25 +141,29 @@ var render = function () {
? _vm.__map(_vm.activeType.nutrients_four, function (item, index) {
var $orig = _vm.__get_orig(item)
var m0 = _vm.unitConversion(item.unit)
var g8 = Number((_vm.activeType.weight / 100) * item.value).toFixed(1)
var g7 = Number((_vm.activeType.weight / 100) * item.value).toFixed(1)
return {
$orig: $orig,
m0: m0,
g8: g8,
g7: g7,
}
})
: null
var g9 = _vm.IsWeight ? Math.floor(_vm.activeType.weight) : null
var g8 = _vm.IsWeight ? Math.floor(_vm.activeType.weight) : null
var l1 = _vm.IsWeight
? _vm.__map(_vm.activeType.nutrients_list, function (item, index) {
var $orig = _vm.__get_orig(item)
var g10 = Number((item.value * _vm.activeType.weight) / 100).toFixed(2)
var g9 = Number((item.value * _vm.activeType.weight) / 100).toFixed(2)
return {
$orig: $orig,
g10: g10,
g9: g9,
}
})
: null
var g10 =
_vm.ActiveList.filter(function (ite) {
return ite.meals_type == _vm.foodName
}).length || 0
if (!_vm._isMounted) {
_vm.e0 = function ($event) {
_vm.showAll = !_vm.showAll
@ -176,16 +176,16 @@ var render = function () {
return _vm.handleSearchHistory(item.keyword)
}
_vm.e2 = function ($event) {
_vm.isShop = !_vm.isShop
_vm.isShop = false
}
_vm.e3 = function ($event) {
_vm.isShop = false
_vm.IsWeight = false
}
_vm.e4 = function ($event) {
_vm.IsWeight = false
}
_vm.e5 = function ($event) {
_vm.IsWeight = false
_vm.isShop = !_vm.isShop
}
}
_vm.$mp.data = Object.assign(
@ -199,10 +199,10 @@ var render = function () {
g4: g4,
g5: g5,
g6: g6,
g7: g7,
l0: l0,
g9: g9,
g8: g8,
l1: l1,
g10: g10,
},
}
)
@ -258,7 +258,7 @@ var search = function search() {
}).bind(null, __webpack_require__)).catch(__webpack_require__.oe);
};
var blueTooth = function blueTooth() {
Promise.all(/*! require.ensure | components/bluetooth_food */[__webpack_require__.e("common/vendor"), __webpack_require__.e("components/bluetooth_food")]).then((function () {
__webpack_require__.e(/*! require.ensure | components/bluetooth_food */ "components/bluetooth_food").then((function () {
return resolve(__webpack_require__(/*! ../../components/bluetooth_food.vue */ 324));
}).bind(null, __webpack_require__)).catch(__webpack_require__.oe);
};
@ -296,7 +296,7 @@ var _default = {
showAutoSearchDlg: false
};
},
computed: _objectSpread(_objectSpread({}, (0, _vuex.mapState)(["configInfo", "user", 'bleValue'])), {}, {
computed: _objectSpread(_objectSpread({}, (0, _vuex.mapState)(["configInfo", "user", 'bleValue', "countFoodInfo"])), {}, {
popular_food: function popular_food() {
return this.configInfo.search_guess.food_data;
},
@ -326,6 +326,7 @@ var _default = {
},
bleValue: {
handler: function handler(newVal, oldVal) {
console.log("实时bleValue", newVal);
this.realTimeWeight(newVal.countWeight, newVal.unit);
},
deep: true
@ -369,34 +370,12 @@ var _default = {
that.mic_touch = false;
that.voiceManager.stop();
},
//测量返回
handleBle: function handleBle(weight, unit, kcal) {
var that = this;
that.isBle = false;
that.activeType.weight = weight;
that.activeType.unit = unit;
that.activeType.kcal = kcal;
that.Next();
},
// 购物车早午晚餐切换
handleToggle: function handleToggle(name) {
this.search_value = "";
this.search_list = [];
this.foodName = name;
},
handleToggleBle: function handleToggleBle() {
var that = this;
that.isBle = !that.isBle;
if (!that.isBle) {
that.activeType.weight = that.activeType.weight != 0 ? that.activeType.weight : '';
}
},
// 手动输入
replaceInput: function replaceInput(event) {
var weight = event.target.value;
this.activeType = Object.assign({}, this.activeType, {
weight: weight
});
},
//实时重量
realTimeWeight: function realTimeWeight(weight, unit) {
this.activeType = Object.assign({}, this.activeType, {
@ -451,24 +430,44 @@ var _default = {
}]
}));
},
// 保存
Next: function Next() {
//测量返回
handleBle: function handleBle(weight, unit, kcal) {
var that = this;
var ite = that.activeType;
var list = [];
that.activeType.unit = unit;
that.activeType.kcal = kcal;
that.activeType.weight = weight;
that.activeType.meals_type = that.foodName;
list.push(that.activeType);
that.$model.getAddIntakeFood({
aud_id: that.user.aud_id,
food_list: list,
time: that.time
}).then(function (res) {
if (res.code != 0) return;
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo");
} else {
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.time
});
}
that.activeType.food_id = res.data.id;
if (that.activeType.weight <= 0) {
that.$tools.msg("请输入重量");
return;
}
that.isBle = false;
that.IsWeight = false;
if (that.ActiveList.indexOf(ite) == -1) {
that.ActiveList.push(ite);
if (that.ActiveList.indexOf(that.activeType) == -1) {
that.ActiveList.push(that.activeType);
} else {
var index = that.ActiveList.indexOf(ite);
var index = that.ActiveList.indexOf(that.activeType);
that.ActiveList[index].weight = that.activeType.weight;
that.ActiveList[index].unit = that.activeType.unit;
}
console.log("保存", that.ActiveList);
});
},
// 搜索
handleSerach: function handleSerach() {
@ -519,34 +518,30 @@ var _default = {
this.search_value = "";
this.search_list = [];
this.foodName = this.foodItem[e.target.value].name;
}), (0, _defineProperty2.default)(_methods, "handlesubbtn", function handlesubbtn() {
}), (0, _defineProperty2.default)(_methods, "handledelactive", function handledelactive(ite) {
var _this = this;
var that = this;
if (that.ActiveList.length <= 0) {
that.$tools.msg("请添加食物");
return;
}
that.$model.getAddIntakeFood({
uni.showModal({
content: "\u662F\u5426\u5220\u9664[".concat(ite.name, "]\uFF1F"),
success: function success(res) {
if (res.confirm) {
_this.$model.delCEatAction({
aud_id: that.user.aud_id,
food_list: that.ActiveList,
time: that.time
eat_log_id: ite.food_id
}).then(function (res) {
if (res.code != 0) return;
that.ActiveList.splice(that.ActiveList.indexOf(ite), 1);
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo");
} else {
that.$store.dispatch("getCountFoodInfo", {
aud_id: that.user.aud_id,
time: that.time
});
if (that.time == that.user.food_count.date) {
that.$store.dispatch("getUserInfo");
}
setTimeout(function () {
uni.navigateBack({
delta: 1
});
}, 200);
}
}
});
}), (0, _defineProperty2.default)(_methods, "handledelactive", function handledelactive(ite) {
var that = this;
that.ActiveList.splice(that.ActiveList.indexOf(ite), 1);
}), _methods)
};
exports.default = _default;

File diff suppressed because one or more lines are too long

View File

@ -304,10 +304,11 @@
justify-content: space-between;
padding: 0 20rpx;
position: fixed;
bottom: 150rpx;
bottom: 0rpx;
left: 0;
right: 0;
height: 55px;
height: 60px;
padding-bottom: 15px;
z-index: 15;
background-color: #fff;
overflow: hidden;
@ -323,16 +324,16 @@
background-color: #f0ae43;
}
.groupbtn .left.data-v-d4f38c70 {
width: 50%;
width: 110px;
display: flex;
align-items: center;
}
.groupbtn .che.data-v-d4f38c70 {
.groupbtn .left .che.data-v-d4f38c70 {
width: 80rpx;
height: 80rpx;
position: relative;
}
.groupbtn .che text.data-v-d4f38c70 {
.groupbtn .left .che text.data-v-d4f38c70 {
position: absolute;
height: 30rpx;
background: red;
@ -346,16 +347,26 @@
right: 0;
top: 5px;
}
.groupbtn .che image.data-v-d4f38c70,
.groupbtn .che .t-icon.data-v-d4f38c70 {
.groupbtn .left .che image.data-v-d4f38c70,
.groupbtn .left .che .t-icon.data-v-d4f38c70 {
width: 100%;
height: 100%;
border-radius: 50%;
}
.groupbtn .type image.data-v-d4f38c70 {
.groupbtn .left .type image.data-v-d4f38c70 {
width: 15px;
height: 15px;
}
.groupbtn .mic-icon.data-v-d4f38c70 {
color: #fff;
width: calc(100% - 120px);
padding: 8px 0;
background: #3CB383;
display: flex;
align-items: center;
justify-content: center;
border-radius: 20rpx;
}
.wrapper .box.data-v-d4f38c70 {
top: 40px;
background-color: #dfdfdf;
@ -590,27 +601,36 @@
margin-top: -5px;
}
.wrapper .box2 .list .item.data-v-d4f38c70 {
width: 100%;
height: 45px;
display: flex;
position: relative;
justify-content: end;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid #f7f7f7;
}
.wrapper .box2 .list .item image.data-v-d4f38c70 {
.wrapper .box2 .list .item .item-left.data-v-d4f38c70 {
width: 80%;
display: flex;
align-items: center;
}
.wrapper .box2 .list .item .item-left image.data-v-d4f38c70 {
width: 90rpx;
height: 90rpx;
border-radius: 50%;
border: 1px solid #f7f7f7;
}
.wrapper .box2 .list .item .name.data-v-d4f38c70 {
.wrapper .box2 .list .item .item-left .name.data-v-d4f38c70 {
display: flex;
flex-direction: column;
margin-left: 10px;
height: 40px;
justify-content: space-between;
}
.wrapper .box2 .list .item .name text.data-v-d4f38c70 {
.wrapper .box2 .list .item .item-left .name text.data-v-d4f38c70 {
width: 100%;
}
.wrapper .box2 .list .item .weight.data-v-d4f38c70 {
.wrapper .box2 .list .item .item-left .weight.data-v-d4f38c70 {
font-size: 24rpx;
color: #999;
}

View File

@ -1,6 +1,7 @@
{
"navigationBarTitleText": "设置",
"enablePullDownRefresh": false,
"disableSwipeBack": true,
"usingComponents": {
"uni-icons": "/uni_modules/uni-icons/components/uni-icons/uni-icons",
"llt-slider-range": "/uni_modules/llt-slider-range/components/llt-slider-range/llt-slider-range"

View File

@ -135,7 +135,9 @@ var render = function () {
var _h = _vm.$createElement
var _c = _vm._self._c || _h
var l0 =
!!_vm.token && _vm.userinfo ? _vm.foodInfo.nutrients_four.slice(1) : null
!!_vm.token && _vm.user.aud_id != ""
? _vm.foodInfo.nutrients_four.slice(1)
: null
var l1 = _vm.activeFoodDetail.nutrients_four
? _vm.activeFoodDetail.nutrients_four.slice(1)
: null
@ -193,7 +195,7 @@ var _vuex = __webpack_require__(/*! vuex */ 34);
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var blueTooth = function blueTooth() {
Promise.all(/*! require.ensure | components/bluetooth_food */[__webpack_require__.e("common/vendor"), __webpack_require__.e("components/bluetooth_food")]).then((function () {
__webpack_require__.e(/*! require.ensure | components/bluetooth_food */ "components/bluetooth_food").then((function () {
return resolve(__webpack_require__(/*! ../../components/bluetooth_food.vue */ 324));
}).bind(null, __webpack_require__)).catch(__webpack_require__.oe);
};
@ -237,9 +239,6 @@ var _default = {
qiunDataCharts: qiunDataCharts
},
computed: _objectSpread(_objectSpread({}, (0, _vuex.mapState)(["user", "countFoodInfo"])), {}, {
userinfo: function userinfo() {
return this.user.aud_id;
},
foodInfo: function foodInfo() {
var that = this;
that.chartData.series[0].data = that.countFoodInfo.nutrients_four[0].proportion / 100;

File diff suppressed because one or more lines are too long

View File

@ -175,6 +175,7 @@ var _default = {
data: function data() {
return {
token: "",
foodInfo: [],
chartData: {
series: [{
data: 0,
@ -186,23 +187,51 @@ var _default = {
components: {
qiunDataCharts: qiunDataCharts
},
computed: _objectSpread(_objectSpread({}, (0, _vuex.mapState)(["configInfo", "user", "countFoodInfo"])), {}, {
computed: _objectSpread(_objectSpread({}, (0, _vuex.mapState)(["configInfo", "user", "countFoodInfo", "bleValue"])), {}, {
info: function info() {
return this.user;
},
kcalVal: function kcalVal() {
return this.configInfo.kcal_data;
},
foodInfo: function foodInfo() {
var that = this;
that.chartData.series[0].data = that.user.aud_id ? that.user.food_count.nutrients_four[0].proportion / 100 : 0;
return uni.getStorageSync('token') ? that.user.food_count : that.configInfo.food_count;
}
} // foodInfo() {
// let that = this
// return that.user.aud_id != "" ? that.user.food_count : that.configInfo.default_count_foot
// },
}),
onLoad: function onLoad() {
var that = this;
that.token = uni.getStorageSync('token');
that.$store.dispatch("getHomeConfig");
if (that.token) {
that.$ble.openBluetoothAdapter();
}
that.$ble.onBLEConnectionStateChange();
uni.onBluetoothAdapterStateChange(function (res) {
that.$store.commit("changeBluetooth", res.available);
});
},
watch: {
user: {
handler: function handler(newVal, oldVal) {
var that = this;
that.foodInfo = newVal.aud_id != "" ? that.user.food_count : that.configInfo.default_count_foot;
that.chartData.series[0].data = newVal.aud_id != "" ? newVal.food_count.nutrients_four[0].proportion / 100 : 0;
},
immediate: true,
deep: true
},
bleValue: {
handler: function handler(newVal, oldVal) {
console.log("实时bleValue", newVal);
if (newVal.serviceId != '' && newVal.oldCountWeight != newVal.countWeight) {
uni.switchTab({
url: "/pages/count/count"
});
newVal.oldCountWeight = newVal.countWeight;
}
},
deep: true
}
},
onPullDownRefresh: function onPullDownRefresh() {
var that = this;

File diff suppressed because one or more lines are too long

View File

@ -1 +1 @@
<view class="content data-v-259fb574"><block wx:if="{{token}}"><view style="width:100%;" class="data-v-259fb574"><block wx:if="{{info.aud_id}}"><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/setting/setting']]]]]}}" class="head data-v-259fb574" bindtap="__e"><view class="left data-v-259fb574"><image src="{{info.head_pic}}" class="data-v-259fb574"></image><text class="data-v-259fb574">{{info.nickname}}</text></view><view class="right data-v-259fb574"><uni-icons vue-id="8e55f700-1" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view></view></block><block wx:else><view data-event-opts="{{[['tap',[['handleUserEdit',['$event']]]]]}}" class="head data-v-259fb574" bindtap="__e"><text class="size22 data-v-259fb574">完善资料后,记录更准确哦!</text></view></block></view></block><view class="list data-v-259fb574"><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/me/userEdit']]]]]}}" class="item data-v-259fb574" bindtap="__e"><view class="data-v-259fb574"><image src="/static/11.png" mode class="data-v-259fb574"></image>个人资料</view><uni-icons vue-id="8e55f700-2" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/me/mymenu?pageName=我的菜谱']]]]]}}" class="item data-v-259fb574" bindtap="__e"><view class="data-v-259fb574"><image src="/static/12.png" mode class="data-v-259fb574"></image>我的菜谱</view><uni-icons vue-id="8e55f700-3" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/me/mymenu?pageName=我的收藏']]]]]}}" class="item data-v-259fb574" bindtap="__e"><view class="data-v-259fb574"><image src="/static/27.png" mode class="data-v-259fb574"></image>我的收藏</view><uni-icons vue-id="8e55f700-4" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/me/record']]]]]}}" class="item data-v-259fb574" bindtap="__e"><view class="data-v-259fb574"><image src="/static/13.png" mode class="data-v-259fb574"></image>饮食记录</view><uni-icons vue-id="8e55f700-5" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/webview/webview?url='+configInfo.business_cooperation]]]]]}}" class="item data-v-259fb574" bindtap="__e"><view class="data-v-259fb574"><image src="/static/14.png" mode class="data-v-259fb574"></image>商务合作</view><uni-icons vue-id="8e55f700-6" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view></view><block wx:if="{{!token}}"><view data-event-opts="{{[['tap',[['handleLogin',['$event']]]]]}}" class="btn data-v-259fb574" bindtap="__e">登录后查看更多</view></block><block wx:if="{{token}}"><view data-event-opts="{{[['tap',[['handleOutLogin',['$event']]]]]}}" class="btn data-v-259fb574" bindtap="__e">退出登录</view></block></view>
<view class="content data-v-259fb574"><block wx:if="{{token}}"><view style="width:100%;" class="data-v-259fb574"><block wx:if="{{info.aud_id}}"><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/setting/setting']]]]]}}" class="head data-v-259fb574" bindtap="__e"><view class="left data-v-259fb574"><image src="{{info.head_pic}}" class="data-v-259fb574"></image><text class="data-v-259fb574">{{info.nickname}}</text></view><view class="right data-v-259fb574"><uni-icons vue-id="8e55f700-1" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view></view></block><block wx:else><view data-event-opts="{{[['tap',[['handleUserEdit',['$event']]]]]}}" class="head data-v-259fb574" bindtap="__e"><text class="size22 data-v-259fb574">完善资料后,记录更准确哦!</text></view></block></view></block><view class="list data-v-259fb574"><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/me/userEdit']]]]]}}" class="item data-v-259fb574" bindtap="__e"><view class="data-v-259fb574"><image src="/static/11.png" mode class="data-v-259fb574"></image>个人资料</view><uni-icons vue-id="8e55f700-2" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/me/mymenu?pageName=我的菜谱']]]]]}}" class="item data-v-259fb574" bindtap="__e"><view class="data-v-259fb574"><image src="/static/12.png" mode class="data-v-259fb574"></image>我的菜谱</view><uni-icons vue-id="8e55f700-3" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/me/mymenu?pageName=我的收藏']]]]]}}" class="item data-v-259fb574" bindtap="__e"><view class="data-v-259fb574"><image src="/static/27.png" mode class="data-v-259fb574"></image>我的收藏</view><uni-icons vue-id="8e55f700-4" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/me/record']]]]]}}" class="item data-v-259fb574" bindtap="__e"><view class="data-v-259fb574"><image src="/static/13.png" mode class="data-v-259fb574"></image>饮食记录</view><uni-icons vue-id="8e55f700-5" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view><view data-event-opts="{{[['tap',[['navTo',['/pageTwo/webview/webview?url='+configInfo.business_cooperation.jump_url]]]]]}}" class="item data-v-259fb574" bindtap="__e"><view class="data-v-259fb574"><image src="/static/14.png" mode class="data-v-259fb574"></image>商务合作</view><uni-icons vue-id="8e55f700-6" type="forward" size="20" color="#666" class="data-v-259fb574" bind:__l="__l"></uni-icons></view></view><block wx:if="{{!token}}"><view data-event-opts="{{[['tap',[['handleLogin',['$event']]]]]}}" class="btn data-v-259fb574" bindtap="__e">登录后查看更多</view></block><block wx:if="{{token}}"><view data-event-opts="{{[['tap',[['handleOutLogin',['$event']]]]]}}" class="btn data-v-259fb574" bindtap="__e">退出登录</view></block></view>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.0 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

After

Width:  |  Height:  |  Size: 4.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.5 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.6 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB