修改选择书籍部分

master
Gary 3 weeks ago
parent d5e35e6dbb
commit 340d0f760f

@ -28,13 +28,13 @@ export default {
globalData: {
//
fit_journey_basic_address: 'http://127.0.0.1:8086',//TODO:
fit_journey_community_address: 'http://47.122.61.54:8082',//TODO:
fit_journey_community_address: 'http://127.0.0.1:8082',//TODO:
fit_journey_ai_address: 'http://47.122.61.54:8081',//TODO
fit_journey_login_address: 'http://47.122.61.54:8084',//TODO:
fit_journey_login_address: 'http://127.0.0.1:8084',//TODO:
fit_journey_recipe_address: 'http://47.122.61.54:8087',//TODO:
fit_journey_exercise_address: 'http://47.122.61.54:8080',//TODO:
fit_journey_admin_address: 'http://47.122.61.54:8085',//TODO:
message_count: 0,
// TODO: token localStorage
token: 'eyJhbGciOiJIUzI1NiJ9.eyJzdW' +
'IiOiIxODU5MDU4ODM2NDQ3NDk4MjQyIiwiaXNz' +

@ -26,7 +26,7 @@ export default {
methods: {
go_to_page() {
uni.navigateTo({
url: '/pages/homepages/homes/my_exercise_plan/my_exercise_plan'
url: '/pages/homepages/homes/my_recipe_plan/my_recipe_plan'
})
uni.showToast({
title: '跳转成功',

@ -186,5 +186,5 @@ export default {
</script>
<style lang="scss">
@import "@/static/homepages/community/community/scss/community.scss"
@import "@/static/homepages/community/community/scss/community.scss";
</style>

@ -1,5 +1,20 @@
<template>
<view>
<view class="background">
<image class="go_back_button" @click="go_back" src="@/static/homepages/homes/knowledge_dictionary/pictures/go_back_button.png" ></image>
<image class="search_area" src="@/static/homepages/homes/choice_book/pictures/search_area.png"></image>
<input
class="input_area"
v-model="searchText"
placeholder="请输入搜索内容"
placeholder-style="color: #999999;"
@input="onSearch"
></input>
<image class="book" src="@/static/homepages/homes/choice_book/pictures/book.png"></image>
<image class="book1" src="@/static/homepages/homes/choice_book/pictures/book1.png"></image>
<image class="book2" src="@/static/homepages/homes/choice_book/pictures/book2.png"></image>
<image class="book3" src="@/static/homepages/homes/choice_book/pictures/book3.png"></image>
<image class="book4" src="@/static/homepages/homes/choice_book/pictures/book4.png"></image>
</view>
</template>
@ -8,47 +23,101 @@
export default {
data() {
return {
token: uni.getStorageSync("access_token")
token: uni.getStorageSync("access_token"),
searchText: ''
};
},
methods:{
go_to_apple()//
{
uni.navigateTo({
url: "/pages/homepages/homes//pages/homepages/homes/dictionary/apple/apple"
})
},
go_to_orange()//
{
uni.navigateTo({
url: "/pages/homepages/homes/dictionary/orange/orange"
go_back(){
uni.navigateTo({
url: '/pages/homepages/homes/home/home'
})
},
go_to_peach()//
{
uni.navigateTo({
url: "/pages/homepages/homes/choice_book/choice_book"
})
},
go_to_watermelon()//西
{
uni.navigateTo({
url: "/pages/homepages/homes//pages/homepages/homes/dictionary/apple/apple"
uni.showToast({
title: '正在返回主页面',
icon: 'none',
duration: 2000
})
},
onSearch() {
console.log('搜索内容:', this.searchText)
}
}
}
</script>
<style lang="scss">
.background{
position: absolute;
height: 100%;
width: 100%;
background: #98AED1;
}
.go_back_button{
position: absolute;
height: 8%;
width: 15%;
top: 5%;
left: 5%;
}
.book{
position: absolute;
height: 50%;
width: 90%;
top: 45%;
left: 5%;
}
.book1{
position: absolute;
height: 18%;
width: 30%;
top: 55%;
left: 10%;
}
.book2{
position: absolute;
height: 18%;
width: 30%;
top: 55%;
left: 59%;
}
.book3{
position: absolute;
height: 18%;
width: 30%;
left: 10%;
top: 76%;
}
}
.book4{
position: absolute;
height: 18%;
width: 30%;
left: 59%;
top: 76%;
}
</script>
.search_area{
position: absolute;
height: 20%;
width: 90%;
top: 15%;
left: 5%;
}
.input_area{
position: absolute;
height: 8%;
width: 70%;
left: 21%;
top: 27%;
background: transparent;
padding: 0 20rpx;
font-size: 32rpx;
color: #333;
z-index: 2;
}
<style lang="scss">
</style>

@ -4,16 +4,20 @@
<!--轮播图 -->
<swiper :autoplay="true" interval="3000" duration="500" class="swiper" :current="current" circular="true" @change="onSwiperChange">
<swiper-item>
<puppy_chat class="swiper_item"></puppy_chat>
<image class="swiper_item_background" src="@/static/components/swiper/puppy_chat/background.png"></image>
<image class="puppy_chat_button" @click="go_to_puppy_chat" src="@/static/components/swiper/puppy_chat/button.png"></image>
</swiper-item>
<swiper-item>
<read_center class="swiper_item"></read_center>
<image class="swiper_item_background" src="@/static/components/swiper/community/background.png"></image>
<image class="puppy_chat_button" @click="go_to_community" src="@/static/components/swiper/puppy_chat/button.png"></image>
</swiper-item>
<swiper-item>
<exercise class="swiper_item"></exercise>
<image class="swiper_item_background" src="@/static/components/swiper/read/background.png"></image>
<image class="puppy_chat_button" @click="go_to_read" src="@/static/components/swiper/puppy_chat/button.png"></image>
</swiper-item>
<swiper-item>
<community class="swiper_item"></community>
<image class="swiper_item_background" src="@/static/components/swiper/exercise/background.png"></image>
<image class="exercise_button" @click="go_to_exercise" src="@/static/components/swiper/puppy_chat/button.png"></image>
</swiper-item>
</swiper>
<!-- 动态切换的轮播点 -->
@ -71,6 +75,40 @@ export default {
};
},
methods:{
go_to_exercise(){
uni.navigateTo({
url: '/pages/homepages/homes/my_exercise_plan/my_exercise_plan'
});
uni.showToast({
title: '跳转成功',
})
},
go_to_read(){
uni.navigateTo({
url: '/pages/homepages/homes/choice_book/choice_book'
});
uni.showToast({
title: '跳转成功',
})
},
go_to_community(){
uni.navigateTo({
url: '/pages/homepages/community/community/community'
});
uni.showToast({
title: '跳转成功',
})
},
go_to_puppy_chat(){
uni.navigateTo({
url: '/pages/homepages/puppy_chat/puppy_chat'
});
uni.showToast({
title: '跳转成功',
})
},
go_to_choice_book(){
uni.navigateTo({
url: '/pages/homepages/homes/choice_book/choice_book'

@ -5,8 +5,6 @@
<image class="search_button" @click="search" src="@/static/homepages/homes/knowledge_dictionary/pictures/search_button.png"></image>
<image class="strawberry_image" @click="go_to_strawberry" src="@/static/homepages/homes/knowledge_dictionary/pictures/strawberry.png"></image>
<image class="peach_image" @click="go_to_peach" src="@/static/homepages/homes/knowledge_dictionary/pictures/peach.png"></image>
<image class="carrot_image" @click="go_to_carrot" src="@/static/homepages/homes/knowledge_dictionary/pictures/carrot.png"></image>

@ -1,17 +1,287 @@
<template>
<view>
<view class="recipe-plan">
<image class="go_back_button" @click="go_back_to_home" src="@/static/homepages/homes/my_recipe_plan/pictures/button.png"></image>
<view class="date">{{ currentDate }}</view>
<text class ="today_recipe_and_calories">今日饮食和热量</text>
<view class="divider_line"></view>
<image class="time_line" src="@/static/homepages/homes/my_recipe_plan/pictures/time_line.png"></image>
<view class="input_box_breakfast">
<input
v-model="meals[0].food"
class="food_input"
placeholder="请输入食物名称"
@input="calculateCalories(0)"
/>
<view class="calories_text">
<text class="icon"></text>
<text>热量{{ meals[0].calories }}J</text>
</view>
<view
class="check_button"
:class="{ active: meals[0].checked }"
@click="toggleCheck(0)"
></view>
</view>
<view class="input_box_lunch">
<input
v-model="meals[1].food"
class="food_input"
placeholder="请输入食物名称"
@input="calculateCalories(1)"
/>
<view class="calories_text">
<text class="icon"></text>
<text>热量{{ meals[1].calories }}J</text>
</view>
<view
class="check_button"
:class="{ active: meals[1].checked }"
@click="toggleCheck(1)"
></view>
</view>
<view class="input_box_dinner">
<input
v-model="meals[2].food"
class="food_input"
placeholder="请输入食物名称"
@input="calculateCalories(2)"
/>
<view class="calories_text">
<text class="icon"></text>
<text>热量{{ meals[2].calories }}J</text>
</view>
<view
class="check_button"
:class="{ active: meals[2].checked }"
@click="toggleCheck(2)"
></view>
</view>
<view class="input_box_midnight_snack">
<input
v-model="meals[3].food"
class="food_input"
placeholder="请输入食物名称"
@input="calculateCalories(3)"
/>
<view class="calories_text">
<text class="icon"></text>
<text>热量{{ meals[3].calories }}J</text>
</view>
<view
class="check_button"
:class="{ active: meals[3].checked }"
@click="toggleCheck(3)"
></view>
</view>
</view>
</template>
<script>
import { getFoodCalories } from '@/static/homepages/homes/my_recipe_plan/js/database.js'
export default {
data() {
return {};
return {
meals: [
{ time: '早餐', food: '', calories: 0, dotColor: 'yellow', checked: false },
{ time: '午餐', food: '', calories: 0, dotColor: 'yellow', checked: false },
{ time: '晚餐', food: '', calories: 0, dotColor: 'red', checked: false },
{ time: '夜宵', food: '', calories: 0, dotColor: 'blue', checked: false }
]
}
},
computed: {
currentDate() {
const date = new Date()
return `${date.getFullYear()}${date.getMonth() + 1}${date.getDate()}`
}
},
methods: {
go_back_to_home(){
uni.navigateTo({
url:"/pages/homepages/homes/home/home"
})
},
calculateCalories(index) {
//
if (!this.meals[index].food.trim()) {
return
}
// loading
this.meals[index].loading = true
this.meals[index].calories = 0
// 2
setTimeout(() => {
const calories = getFoodCalories(this.meals[index].food)
if (calories) {
uni.showToast({
title: '计算食物卡路里成功!!',
icon: 'none',
duration: 2000
})
this.meals[index].calories = calories
this.meals[index].recordTime = this.getCurrentTime()
this.saveMealsData()
} else {
uni.showToast({
title: '未找到该食物的卡路里信息',
icon: 'none',
duration: 2000
})
}
this.meals[index].loading = false
}, 2000)
},
toggleCheck(index) {
this.meals[index].checked = !this.meals[index].checked
}
}
}
</script>
<style lang="scss">
.recipe-plan {
position: relative;
width: 100%;
height: 100vh;
background-color: #B6D1E0;
.go_back_button{
position:absolute;
width: 20%;
height: 8%;
left: 2%;
top: 3%;
}
.date {
position: absolute;
width: 50%;
height: 2%;
left: 6%;
top: 11%;
font-size: 1.4em; //
font-weight: 700; //
display: flex; // 使flex
align-items: center; //
justify-content: center; //
padding: 2% 0;
}
.today_recipe_and_calories{
position: absolute;
width: 75%;
height: 4%;
left: 6%;
top: 16%;
font-size: 2.5em; //
font-weight: 700; //
display: flex; // 使flex
align-items: center; //
justify-content: center; //
padding: 2% 0;
}
.divider_line {
position: absolute;
width: 88%; // 线
height: 2px; // 线
background-color: #0c0b0b;
left: 6%;
top: 24%; // today_recipe_and_calories
}
.time_line{
position: absolute;
width: 15%;
height: 61%;
top: 27%;
left: 5%;
}
.input_box_breakfast{
position: absolute;
width: 70%;
height: 15%;
top: 27%;
left: 25%;
background-color: #ffffff;
border-radius: 30px;
}
.input_box_lunch{
position: absolute;
width: 70%;
height: 15%;
top: 45%;
left: 25%;
background-color: #ffffff;
border-radius: 30px;
}
.input_box_dinner{
position: absolute;
width: 70%;
height: 15%;
top: 63%;
left: 25%;
background-color: #ffffff;
border-radius: 30px;
}
.input_box_midnight_snack{
position: absolute;
width: 70%;
height: 15%;
top: 81%;
left: 25%;
background-color: #ffffff;
border-radius: 30px;
}
.input_box_breakfast,
.input_box_lunch,
.input_box_dinner,
.input_box_midnight_snack {
.food_input {
position: absolute;
left: 5%;
top: 20%;
width: 70%;
height: 30%;
border: none;
font-size: 1.2em;
}
.calories_text {
position: absolute;
left: 5%;
bottom: 20%;
color: #666;
font-size: 1em;
.icon {
margin-right: 8px;
}
}
.check_button {
position: absolute;
right: 5%;
top: 30%;
width: 30px;
height: 30px;
border-radius: 50%;
background-color: #e0e0e0;
color: white;
display: flex;
align-items: center;
justify-content: center;
transition: background-color 0.3s;
&.active {
background-color: #4285f4; //
}
}
}
}
</style>

@ -1,28 +1,28 @@
<template>
<!-- 背景图片-->
<image class="background" src="@/static/homepages/puppy_chat/pictures/chat_image.png"></image>
<scroll-view scroll-y="true" id="chat_scroll" :scroll-top="scrollTop" scroll-with-animation="true">
<view class="chat">
<!-- 渲染聊天消息气泡 -->
<view v-for="(message, index) in send_messages" :key="index" :class="['chat_area', message.sender === 'user' ? 'user_message' : 'ai_message']">
<!-- 头像部分放在气泡外部 -->
<view v-if="message.sender === 'ai'" class="avatar_container ai_avatar_container">
<image class="ai_avatar" src="@/static/homepages/puppy_chat/pictures/ai_avatar.png"></image>
</view>
<!-- 消息内容 -->
<view :class="['message_content', message.sender === 'user' ? 'user_message_content' : 'ai_message_content']">
<!-- <text>{{ message.message }}</text> -->
<zero-markdown-view :markdown="message.message"></zero-markdown-view>
</view>
<view v-if="message.sender === 'user'" class="avatar_container user_avatar_container">
<image class="user_avatar" src="@/static/homepages/puppy_chat/pictures/user_avatar.png"></image>
</view>
</view>
</view>
</scroll-view>
<!-- 背景图片-->
<image class="background" src="@/static/homepages/puppy_chat/pictures/chat_image.png"></image>
<scroll-view scroll-y="true" id="chat_scroll" :scroll-top="scrollTop" scroll-with-animation="true">
<view class="chat">
<!-- 渲染聊天消息气泡 -->
<view v-for="(message, index) in send_messages" :key="index" :class="['chat_area', message.sender === 'user' ? 'user_message' : 'ai_message']">
<!-- 头像部分放在气泡外部 -->
<view v-if="message.sender === 'ai'" class="avatar_container ai_avatar_container">
<image class="ai_avatar" src="@/static/homepages/puppy_chat/pictures/ai_avatar.png"></image>
</view>
<!-- 消息内容 -->
<view :class="['message_content', message.sender === 'user' ? 'user_message_content' : 'ai_message_content']">
<!-- <text>{{ message.message }}</text> -->
<zero-markdown-view :markdown="message.message"></zero-markdown-view>
</view>
<view v-if="message.sender === 'user'" class="avatar_container user_avatar_container">
<image class="user_avatar" src="@/static/homepages/puppy_chat/pictures/user_avatar.png"></image>
</view>
</view>
</view>
</scroll-view>
@ -47,9 +47,9 @@ export default {
send_messages: [], //
conversation_id: 'e97ec0f2-2a94-42e7-b6db-b04883d349e8',//id
answer: '', // AI
scrollTop : 0, //
totalHeight:0,
scrollViewHeight:0,
scrollTop : 0, //
totalHeight:0,
scrollViewHeight:0,
};
},
onLoad() {
@ -82,34 +82,34 @@ export default {
message:"我是fit journey的专属AI小助手有什么问题都可以问我哦~"
});
},
mounted() {
//
const that = this
const query = uni.createSelectorQuery().in(that)
query.select('#chat_scroll').boundingClientRect()
query.exec((res)=>{
that.scrollViewHeight = res[0].height
})
//
const that = this
const query = uni.createSelectorQuery().in(that)
query.select('#chat_scroll').boundingClientRect()
query.exec((res)=>{
that.scrollViewHeight = res[0].height
})
},
methods: {
setScrollTop(){
//
setTimeout(()=>{ //
const that = this
const query = uni.createSelectorQuery().in(that)
query.selectAll('.chat_area').boundingClientRect()
query.exec((res)=>{
res[0].forEach((item)=>{
that.totalHeight = that.totalHeight+item.height
})
if (that.totalHeight > that.scrollViewHeight) { //
that.scrollTop = that.totalHeight - that.scrollViewHeight
}
})
},100)
},
setScrollTop(){
//
setTimeout(()=>{ //
const that = this
const query = uni.createSelectorQuery().in(that)
query.selectAll('.chat_area').boundingClientRect()
query.exec((res)=>{
res[0].forEach((item)=>{
that.totalHeight = that.totalHeight+item.height
})
if (that.totalHeight > that.scrollViewHeight) { //
that.scrollTop = that.totalHeight - that.scrollViewHeight
}
})
},100)
},
handleSendMessage() {
//
const userMessageCount = this.send_messages.filter(msg => msg.sender === 'user').length;
@ -135,9 +135,9 @@ export default {
this.send_message=this.input_message;
this.input_message = ""; //
this.setScrollTop() //
this.setScrollTop() //
// AI
this.fetchAIResponse();
} else {
@ -176,7 +176,7 @@ export default {
sender: 'ai', // AI
message:this.answer
});
this.setScrollTop() //
this.setScrollTop() //
},
error: (res) => {
console.log("请求失败!请求数据是", res);

@ -1,17 +0,0 @@
<template>
<view>
</view>
</template>
<script>
export default {
data() {
return {};
}
}
</script>
<style lang="scss">
</style>

@ -80,7 +80,8 @@
</template>
<script setup>
import { ref, computed } from 'vue';
import { ref, computed , onMounted } from 'vue';
import app from "@/App.vue";
const isSendCaptcha = ref(false); //
@ -88,10 +89,12 @@ var codeTime = ref(0); //验证码的倒计时
const captchaButtonBackgroundColor = computed(() => isSendCaptcha.value ? "#ABCBFF" : "#ffffff"); //
const captchaButtonColor = computed(() => isSendCaptcha.value ? "#ffffff" : "#000364");//
const captchaButtonText = computed(() => isSendCaptcha.value ? (codeTime.value+"s后重新发送"):"发送验证码")
const phone_number=ref("");
const password=ref("");
const code=ref("");//
const phone_number=ref("");//
const password=ref("");//
const code=ref("");//
const which_way_to_login = ref("0"); // 使0 使1
const access_token = ref("0"); //token
@ -110,17 +113,15 @@ const eyesStateIcon = ref("../../../static/login/account_login/login_part/closed
const isPhoneError = ref(false);
const isPassageError = ref(false);
const isCaptchaError = ref(false);
onMounted(() => {//
which_way_to_login.value= 0;
console.log(which_way_to_login.value);
});
//
function toCaptchaEvent(){
isPassagePage.value = false;
which_way_to_login.value=1;//
}
function sendCaptchaEvent(){
//
const isChinaPhone = /^1[3-9]\d{9}$/.test(phone_number.value);
@ -172,12 +173,30 @@ function sendCaptchaEvent(){
}
});
}
function login() {
//
uni.request({
url:app.globalData.fit_journey_login_address+'/common/isPhoneRegistered',
header: {
'content-type': 'application/x-www-form-urlencoded',
},
method:'GET',
data:{
phone:phone_number.value,
},
success:(res)=>{
console.log(res);
if(res.data.code===200){
uni.showToast({
title: '手机号未注册或输入错误~',
icon: "none"
});
return 0;
}
},
})
console.log(which_way_to_login.value);
if (which_way_to_login.value === 0) { //
console.log("这里开始运行了");
//
const serverAddress = app.globalData.fit_journey_login_address + '/AccountLogin/PhonePasswordLogin';
@ -308,19 +327,6 @@ function login() {
})
}
}
/*
//TODO:
console.log("login");
uni.navigateTo({
url: '/pages/information/sex/sex'//
})*/
//
function toPassageEvent(){
isPassagePage.value = true;
@ -349,9 +355,7 @@ function forgetPassageClick(){
animationDuration: 200
})
}
</script>
<style lang="scss">
@import "@/static/login/account_login/css/acccount_login.scss";
</style>

@ -26,7 +26,7 @@
{{captchaButtonText}}
</button>
</view>
<view class="error_tip" v-if="isCaptchaError">*</view>
<view class="error_tip" v-if="isCaptchaError"></view>
</view>
<!-- 密码输入 -->
<view class="passage_box register_form_item">
@ -99,6 +99,13 @@ const title = computed(()=>isRegisterSuccess.value? '成功':'错误'); //弹窗
const content = computed(()=>isRegisterSuccess.value? '注册成功':'注册失败'); //
const isOpenPopUp = ref(false);//
const is_phone_registered = ref();//0 1
/*正则表达式相关变量*/
const pMatch = /^1(3[0-9]|4[01456879]|5[0-35-9]|6[2567]|7[0-8]|8[0-9]|9[0-35-9])\d{8}$/
@ -184,7 +191,7 @@ function sendCaptchaEvent(){
/*-----密码码相关函数-----*/
function openEyesEvent_1(){
//TODO:
if (isOpened_1.value)
{
isOpened_1.value = false;
@ -197,7 +204,7 @@ function openEyesEvent_1(){
}
}
function openEyesEvent_2(){
//TODO:
if (isOpened_2.value)
{
isOpened_2.value = false;
@ -214,6 +221,12 @@ function openEyesEvent_2(){
function checkSubmit(){
var flag = true
if(code.data===undefined){
uni.showToast({
title: '验证码不能为空',
icon: "error",
})
}//
//
if (phone_number.value===undefined){
flag = false
@ -284,6 +297,35 @@ function registerEvent(){
console.log(code.value);
console.log(phone_number.value);
console.log(passagenum.value);
//
uni.request({
url:app.globalData.fit_journey_login_address+'/common/isPhoneRegistered',
header: {
'content-type': 'application/x-www-form-urlencoded',
},
method:'GET',
data:{
phone:phone_number.value,
},
success:(res)=>{
console.log(res);
if(res.data.code===400) {
is_phone_registered.value=1;
}
},
})
if(is_phone_registered.value===1){//
uni.showToast({
title: '手机号已经被注册了~',
icon: "error",
});
}
if (checkSubmit()){
//
console.log("服务器地址是:"+app.globalData.fit_journey_login_address);

Binary file not shown.

After

Width:  |  Height:  |  Size: 158 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 191 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 112 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 181 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 93 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 150 KiB

@ -22,6 +22,43 @@
width: 98%;
left: 1%;
}
.swiper_item_background{
justify-content: center;
align-items: center;
height: 100%;
width: 100%;
}
.puppy_chat_button{
position: absolute;
height: 20%;
width: 38%;
left: 6%;
top: 63%;
z-index: 1000;
}
.exercise_button{
position: absolute;
height: 18%;
width: 38%;
left: 6%;
top: 69%;
z-index: 1000;
}
.swiper_item {
justify-content: center;
align-items: center;

@ -0,0 +1,133 @@
export const foodCaloriesDB = {
// 主食类
'米饭': 116,
'馒头': 223,
'面条': 110,
'包子': 200,
'饺子': 220,
'油条': 389,
'面包': 265,
'粥': 50,
'炒面': 260,
'炒饭': 290,
// 肉类
'猪肉': 143,
'牛肉': 106,
'鸡肉': 167,
'鸭肉': 240,
'羊肉': 203,
'鱼肉': 100,
'虾': 85,
'蛋': 155,
// 蔬菜类
'西红柿': 20,
'黄瓜': 16,
'胡萝卜': 36,
'白菜': 20,
'菠菜': 23,
'生菜': 15,
'茄子': 24,
'土豆': 81,
'青椒': 20,
// 水果类
'苹果': 52,
'香蕉': 89,
'橙子': 47,
'葡萄': 69,
'西瓜': 32,
'梨': 51,
'草莓': 32,
'柚子': 39,
// 饮品类
'牛奶': 79,
'豆浆': 31,
'可乐': 42,
'果汁': 54,
'咖啡': 1,
'奶茶': 150,
// 常见菜品
'西红柿炒鸡蛋': 100,
'宫保鸡丁': 260,
'鱼香肉丝': 195,
'红烧肉': 425,
'糖醋里脊': 290,
'麻婆豆腐': 174,
'青椒炒肉': 180,
'回锅肉': 327,
'蒜蓉炒菜心': 45,
'炒青菜': 30,
'土豆炖牛肉': 215,
'红烧排骨': 289,
'清炒白菜': 35,
'炸鸡': 260,
'水煮鱼': 180,
'酸菜鱼': 168,
// 零食类
'薯片': 536,
'巧克力': 546,
'饼干': 435,
'爆米花': 382,
'坚果': 607,
'冰淇淋': 267,
'蛋糕': 257,
// 快餐类
'汉堡': 295,
'披萨': 266,
'炸薯条': 312,
'炸鸡翅': 246,
'热狗': 290
}
// 模糊搜索函数
export const searchFood = (keyword) => {
keyword = keyword.toLowerCase()
const results = []
for (const [food, calories] of Object.entries(foodCaloriesDB)) {
if (food.toLowerCase().includes(keyword)) {
results.push({
name: food,
calories: calories
})
}
}
return results
}
// 获取单个食物的卡路里
export const getFoodCalories = (foodName) => {
// 直接匹配
if (foodCaloriesDB[foodName]) {
return foodCaloriesDB[foodName]
}
// 模糊匹配
const results = searchFood(foodName)
if (results.length > 0) {
return results[0].calories
}
return null
}
// 获取食物分类列表
export const getFoodCategories = () => {
return {
'主食类': ['米饭', '馒头', '面条', '包子', '饺子', '油条', '面包', '粥'],
'肉类': ['猪肉', '牛肉', '鸡肉', '鸭肉', '羊肉', '鱼肉', '虾', '蛋'],
'蔬菜类': ['西红柿', '黄瓜', '胡萝卜', '白菜', '菠菜', '生菜', '茄子', '土豆', '青椒'],
'水果类': ['苹果', '香蕉', '橙子', '葡萄', '西瓜', '梨', '草莓', '柚子'],
'饮品类': ['牛奶', '豆浆', '可乐', '果汁', '咖啡', '奶茶'],
'常见菜品': ['西红柿炒鸡蛋', '宫保鸡丁', '鱼香肉丝', '红烧肉', '糖醋里脊', '麻婆豆腐'],
'零食类': ['薯片', '巧克力', '饼干', '爆米花', '坚果', '冰淇淋', '蛋糕'],
'快餐类': ['汉堡', '披萨', '炸薯条', '炸鸡翅', '热狗']
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 128 KiB

@ -1,8 +1,8 @@
{
"hash": "70943268",
"configHash": "c265b382",
"lockfileHash": "e3b0c442",
"browserHash": "d782de90",
"hash": "0aaf698d",
"configHash": "cc60d382",
"lockfileHash": "22a0e42d",
"browserHash": "89d9bfb2",
"optimized": {},
"chunks": {}
}
Loading…
Cancel
Save