ReedawFoodApp/pages/index/index.vue

314 lines
7.1 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>
<!-- 蓝牙 -->
<view class="bluetooth" v-if="userList.length">
<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">
<view :class="{'active':toolsIndex==0}" class="toolsItem" @click="toolsIndex=0">身体数据</view>
<view :class="{'active':toolsIndex==1}" class="toolsItem" @click="toolsIndex=1">饮食数据</view>
<view :class="{'active':toolsIndex==2}" class="toolsItem" @click="toolsIndex=2">健康工具</view>
</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>
<!-- -->
<drawer></drawer>
</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: "",
toolsIndex: 0
}
},
components: {
food,
body,
card,
drawer,
},
computed: {
...mapState(["user", "familayList", 'MeasureResult', "configInfo", "bleValue"]),
info() {
return this.user
},
userList() {
return this.familayList
},
endDate() {
return this.$tools.getDate("start")
},
isConnection() {
return this.bleValue.isConnectStatus
},
bleTipsText() {
return this.bleValue.bleTipsText
}
},
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: {
isBluetoothTyle: function() {
let that = this
if (!that.isBluetoothTyle) {
that.handleBack()
}
},
},
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)
that.$ble.openBluetoothAdapter()
}
}).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
if (that.isConnection == 2) return
that.$store.commit('changeBluetoothValue', {
deviceId: "",
serviceId: "",
// notify: '',
// write: '',
// unit: "g",
// type: 1,
// unitList: that.$json.unitMinus,
// countWeight: "",
isBleLink: false, //是否可以点击
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("登录后查看更多")
}
},
handleLogin() {
uni.redirectTo({
url: "/pageTwo/login/login"
})
},
}
}
</script>
<style lang="scss" scoped>
.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>