ReedawFoodApp/pages/index/index.vue

339 lines
7.7 KiB
Vue
Raw Normal View History

2026-03-23 16:23:40 +08:00
<template>
<view class="box">
<!-- 头部 -->
<view class="header" v-if="token">
<view class="top" v-if="userList.length">
<image :src="info.head_pic" class="headimg" @click="handleAddUser(1)"></image>
<view class="info" @click="handleAddUser(1)">
<view class="size18 bold">{{info.nickname}}</view>
<view class="mt-5">
<text class="mr-10">性别{{info.gender==1?'男':info.gender==2?'女':'未知'}}</text>
<text class="ml-10">年龄{{info.age}}</text>
</view>
</view>
<view class="t-icon t-icon-qiehuan1" @click="$store.commit('changeDrawe', true)"></view>
</view>
<view class="top" v-else @click="handleAddUser(2)">
<view class="info">
暂无成员请先添加~
</view>
<view class="add">
+
</view>
</view>
<!-- 蓝牙 -->
2026-03-25 17:27:29 +08:00
<view class="bluetooth" v-if="userList.length" :class="[bleValue.isConnectStatus==1?'activs':'']">
2026-03-23 16:23:40 +08:00
<view class="bleTips" @click="openBluetoothAdapter">
{{bleTipsText}}
</view>
</view>
</view>
<view class="header" v-else @click="handleLogin">
<view class="top top2">
登录后查看更多
</view>
</view>
<!-- 数据 -->
<view class="toggle">
2026-03-25 17:27:29 +08:00
<view :class="{'active':toolsIndex==0}" class="toolsItem" @click="handleToolsIndex(0)">身体数据</view>
<view :class="{'active':toolsIndex==1}" class="toolsItem" @click="handleToolsIndex(1)">饮食数据</view>
<view :class="{'active':toolsIndex==2}" class="toolsItem" @click="handleToolsIndex(2)">健康工具</view>
2026-03-23 16:23:40 +08:00
</view>
<view v-if="token">
<body v-if="toolsIndex==0"></body>
<food v-if="toolsIndex==1"></food>
<card v-if="toolsIndex==2"></card>
</view>
<view class="nolist" v-else>
<image src="/static/none.png"></image>
<text>暂无数据</text>
</view>
<!-- -->
2026-03-25 17:27:29 +08:00
<drawer @handleToolsIndex="handleToolsIndex(0)"></drawer>
2026-03-23 16:23:40 +08:00
</view>
</template>
<script>
import {
mapState
} from "vuex";
import body from "@/components/bodyIndex/bodyHome.vue"
import food from "@/components/foodIndex/foodHome.vue"
import card from "@/components/cardIndex/cardHome.vue"
import drawer from "@/components/bodyIndex/drawer.vue"
export default {
data() {
return {
token: "",
2026-03-25 17:27:29 +08:00
// toolsIndex: 0
2026-03-23 16:23:40 +08:00
}
},
components: {
food,
body,
card,
drawer,
},
computed: {
2026-03-25 17:27:29 +08:00
...mapState(["user", "familayList", 'MeasureResult', "configInfo", "bleValue", "homeCardIndex"]),
2026-03-23 16:23:40 +08:00
info() {
return this.user
},
userList() {
return this.familayList
},
endDate() {
return this.$tools.getDate("start")
},
isConnection() {
return this.bleValue.isConnectStatus
},
bleTipsText() {
return this.bleValue.bleTipsText
2026-03-25 17:27:29 +08:00
},
toolsIndex(){
return this.homeCardIndex
2026-03-23 16:23:40 +08:00
}
},
onLoad() {
let that = this
that.token = uni.getStorageSync("token")
that.$store.dispatch("getHomeConfig")
that.handleUserList()
that.$ble.onBLEConnectionStateChange()
uni.onBluetoothAdapterStateChange(function(res) {
that.$store.commit("changeBluetoothValue", {
isBluetoothTyle: res.available
});
})
},
onPullDownRefresh() {
let that = this
that.handleUserList()
that.$ble.onBLEConnectionStateChange()
uni.stopPullDownRefresh()
},
watch: {
2026-03-25 17:27:29 +08:00
'bleValue.isBluetoothTyle'() {
2026-03-23 16:23:40 +08:00
let that = this
2026-03-25 17:27:29 +08:00
if (!that.bleValue.isBluetoothTyle) {
2026-03-23 16:23:40 +08:00
that.handleBack()
}
},
2026-03-25 17:27:29 +08:00
'bleValue.isFood'() {
let that = this
if (that.bleValue.isFood) {
that.$store.commit("changehomeCard", 1);
}
},
// homeCardIndex: {
// handler(newVal, oldVal) {
// this.toolsIndex = newVal
// },
// deep: true,
// immediate: true
// }
2026-03-23 16:23:40 +08:00
},
methods: {
// 成员列表
handleUserList() {
let that = this
that.$model.getUserList({
type: 2
}).then(res => {
that.isShow = true
if (res.code != 0) {
that.$tools.msg(res.msg)
return
}
that.$store.commit('changeFamilay', res.data.user_list)
if (res.data.user_list.length) {
let userid = ""
if (uni.getStorageSync('userid')) {
let found = res.data.user_list.find(e => e.id == uni.getStorageSync('userid'));
if (found !== undefined) {
userid = found.id
} else {
userid = res.data.user_list[0].id
uni.setStorageSync('userid', res.data.user_list[0].id)
}
} else {
userid = res.data.user_list[0].id
uni.setStorageSync('userid', res.data.user_list[0].id)
}
// 用户信息接口
that.$store.dispatch('getUserInfo', {
aud_id: userid
})
// 厨房秤接口
that.$store.dispatch("getCountFoodInfo", {
aud_id: userid,
time: that.$tools.getDate("start")
})
// 全部卡片
that.$store.dispatch("getCardAllList", {
aud_id: userid
})
//
that.$store.dispatch("getResult", {
aud_id: userid
})
that.handlePublicRecord(userid)
2026-03-25 17:27:29 +08:00
if (that.bleValue.isConnectStatus != 2) {
that.$ble.openBluetoothAdapter()
}
2026-03-23 16:23:40 +08:00
}
}).catch(err => {})
},
// 公共手动记录内容
handlePublicRecord(id) {
let that = this
that.$model.getPublicRecord({
aud_id: id
}).then(res => {
console.log("公共手动记录", res)
if (res.code == 0) {
that.$store.commit('changePublicRecord', res.data)
}
})
},
// 初始化蓝牙
openBluetoothAdapter() {
let that = this
2026-03-25 17:27:29 +08:00
if (that.isConnection != 1) return
2026-03-23 16:23:40 +08:00
that.$store.commit('changeBluetoothValue', {
deviceId: "",
serviceId: "",
2026-03-25 17:27:29 +08:00
isFood: false,
foodWeight: 100,
foodUnit: "g",
foodNotify: "",
foodWrite: "",
unitList: that.$json.unitMinus,
foodType: 1,
2026-03-23 16:23:40 +08:00
bleTipsText: "蓝牙搜索中",
isConnectStatus: 0,
})
that.$ble.openBluetoothAdapter()
},
handleBack() {
let that = this
that.$store.commit("changeBluetoothValue", {
bleTipsText: "连接失败,点击重新连接",
isConnectStatus: 1,
})
that.$ble.stopBluetoothDevicesDiscovery() //取消蓝牙搜索
that.$ble.closeBLEConnection(that.bleValue.deviceId)
that.$ble.closeBluetoothAdapter()
},
// 添加成员
handleAddUser(ind) {
let that = this
if (uni.getStorageSync('token')) {
uni.navigateTo({
url: ind == 1 ? "/body/my/userInfo?info=" + JSON.stringify(this.user) : "/body/my/userInfo"
})
} else {
that.$tools("登录后查看更多")
}
},
2026-03-25 17:27:29 +08:00
handleToolsIndex(ind) {
this.$store.commit("changehomeCard", ind);
},
2026-03-23 16:23:40 +08:00
handleLogin() {
uni.redirectTo({
2026-03-25 17:27:29 +08:00
url: "/body/login/login"
2026-03-23 16:23:40 +08:00
})
},
}
}
</script>
<style lang="scss" scoped>
2026-03-25 17:27:29 +08:00
.activs {
background: #ffc800 !important;
}
2026-03-23 16:23:40 +08:00
.header {
width: 100%;
height: 240rpx;
background: $maincolor;
.top {
display: flex;
align-items: center;
}
.top2 {
color: #fff;
font-size: 16px;
font-weight: bold;
width: 100%;
justify-content: center;
padding-top: 15px;
}
.headimg {
width: 55px;
height: 55px;
border-radius: 50%;
margin: 0 10px;
float: left;
}
.info {
width: calc(100% - 120px);
float: left;
}
.t-icon-qiehuan1 {
float: right;
}
}
.bluetooth {
width: calc(100% - 20px);
background: #fff;
padding: 8px 0;
margin-top: 15px;
margin-left: 10px;
border-radius: 10px;
text-align: center;
}
.toggle {
display: flex;
width: calc(100% - 20px);
height: 40px;
line-height: 40px;
font-size: 16px;
font-weight: bold;
margin-bottom: 0;
margin-top: 8px;
.toolsItem {
color: #999;
margin: 0 10px;
}
.active {
color: #333;
position: relative
}
.active:before {
content: "";
position: absolute;
bottom: 0;
width: 20px;
height: 4px;
background: #54d87c;
border-radius: 5px;
left: calc(50% - 10px);
}
}
</style>