完成拍照识别菜谱热量和菜品名称模块,并成功和后端对接

master
Gary 3 weeks ago
parent 7541b66d76
commit ba5fac606d

@ -17,9 +17,9 @@ export default {
//
fit_journey_basic_address: 'http://127.0.0.1:8081',
fit_journey_community_address: 'http://localhost:8082',
fit_journey_ai_address: 'http://localhost:8083',
fit_journey_ai_address: 'http://127.0.0.1:8085',
fit_journey_login_address: 'http://localhost:8084',
fit_journey_recipe_address: 'http://localhost:8085',
fit_journey_recipe_address: 'http://localhost:8083',
fit_journey_exercise_address: 'http://localhost:8086',
// TODO: token localStorage

@ -0,0 +1,13 @@
{
"name": "fitjourney前端代码",
"version": "1.0.0",
"description": "",
"main": "main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"private": true,
"dependencies": {
"echarts": "^5.5.1"
}
}

@ -71,15 +71,15 @@
}
},*/
/*------------------------------------------------------------------------------------------------------------------*/
/*
{
"path": "pages/information/sex/sex",
"style": {
"navigationStyle": "custom"
}
},
},*/
/*------------------------------------------------------------------------------------------------------------*/
/*
{
"path": "pages/information/boy_weight_start/boy_weight_start",
"style": {
@ -97,9 +97,9 @@
"style": {
"navigationStyle": "custom"
}
},
},*/
/*------------------------------------------------------------------------------------------------------------*/
{
/* {
"path": "pages/information/boy_height_start/boy_height_start",
"style": {
"navigationStyle": "custom"
@ -116,9 +116,9 @@
"style": {
"navigationStyle": "custom"
}
},
},*/
/*-----------------------------------------------------------------------------------------------------*/
{
/* {
"path": "pages/information/girl_height_start/girl_height_start",
"style": {
"navigationStyle": "custom"
@ -135,9 +135,9 @@
"style": {
"navigationStyle": "custom"
}
},
/*--------------------------------------------------------------------------------------------------------*/
{
},*/
/*------------------------------------------------------------------------------------------------------------------------------------------*/
/* {
"path": "pages/information/girl_weight_start/girl_weight_start",
"style": {
"navigationStyle": "custom"
@ -154,86 +154,89 @@
"style": {
"navigationStyle": "custom"
}
},
/*----------------------------------------------------------------------------------------------------------*/
{
},*/
/*--------------------------------------------------------------------------------------------------------------------------------------*/
/*{
"path": "pages/information/purpose/purpose",
"style": {
"navigationStyle": "custom"
}
}
/*-------------------------------------------------------------------------------------------------------------------*/
/* {
"path": "pages/homepages/home/home",
},*/
/*-------------------------------------------------------------------------------------------------------------------*/
/* {
"path": "pages/transition/page8/page8",
"style": {
"navigationStyle": "custom"
}
},*/
/*------------------------------------------------------------------------------------------------------------------------*/
/*{
"path": "pages/homepages/puppy_chat/puppy_chat",
/*--------------------------------------------------------------------------------------------------------------*/
/* {
"path": "pages/homepages/homes/home/home",
"style": {
"navigationStyle": "custom"
}
},*/
/*---------------------------------------------------------------------------------------------------------------------*/
{
"path": "pages/homepages/homes/ai_recognize_recipe/ai_recognize_recipe",
"style": {
"navigationStyle": "custom"
}
}
/*---------------------------------------------------------------------------------------------------------------------------------*/
/* {
"path": "pages/homepages/community/community",
"path": "pages/homepages/puppy_chat/puppy_chat",
"style": {
"navigationStyle": "custom"
}
},*/
/*-------------------------------------------------------------------------------------------------------------------*/
}*/
/*------------------------------------------------------------------------------------------------------------------------------*/
/* {
"path": "pages/homepages/user/user/user",
"path": "pages/homepages/community/community",
"style": {
"navigationStyle": "custom"
}
},*/
/*-------------------------------------------------------------------------------------------------------------------*/
/*---------------------------------------------------------------------------------------------------------------------------*/
/*{
"path": "pages/transition/page8/page8",
"path": "pages/homepages/user/user/user",
"style": {
"navigationStyle": "custom"
}
}*/
/*--------------------------------------------------------------------------------------------------------------*/,
/*-------------------------------------------------------------------------------------------------------------------------*/
/*
{
"path": "pages/homepages/user/user_information/user_information",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
"navigationStyle": "custom"
}
},
{
"path": "pages/homepages/user/bmi_imformation/bmi_imformation",
"path": "pages/homepages/user/bmi_information/bmi_information",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
"navigationStyle": "custom"
}
},
{
"path": "pages/homepages/user/basic_information/basic_information",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
"navigationStyle": "custom"
}
},
{
"path": "pages/homepages/user/exercise_plans/exercise_plans",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
"navigationStyle": "custom"
}
},
{
"path": "pages/homepages/user/recipe_and_calorie/recipe_and_calorie",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
"navigationStyle": "custom"
}
}
}*/
/*----------------------------------------------------------------------------------------------------------------*/
],
"uniIdRouter": {},
"tabBar": null

@ -0,0 +1,98 @@
<template>
<view class="background">
<!-- 点击上传图片按钮 -->
<image class="upload_picture" @click="selectAndUploadPicture" src="@/static/homepages/homes/ai_recognize_recipe/pictures/photo.png"></image>
<!-- 所含卡路里显示窗口 -->
<view class="calorie_container">
<text class="calorie_text">{{ calorie }}J</text>
</view>
<!-- 所含菜品名称显示窗口 -->
<view class="name_container">
<text class="name_text">{{ name }}</text>
</view>
<!-- 返回按钮 -->
<image class="button" @click="goBackToHome" src="@/static/homepages/homes/ai_recognize_recipe/pictures/button.png"></image>
</view>
</template>
<script>
export default {
data() {
return {
calorie: 0,
name: '',
};
},
methods: {
goBackToHome() {
uni.navigateTo({
url: '/pages/homepages/homes/home/home', //
});
},
//
selectAndUploadPicture() {
const app = getApp();
const serverAddress = app.globalData.fit_journey_ai_address;
console.log("后端服务器的地址是:"+serverAddress);
// API
uni.file
uni.chooseImage({
count: 1, // 1
sizeType: ['compressed'], // compressed
sourceType: ['album', 'camera'], //
success: (chooseImageRes) => {
const filePath = chooseImageRes.tempFilePaths[0]; //
console.log('选择的图片路径:', filePath);
console.log("图片上传成功!");
//
uni.uploadFile({
header: {
'Authorization': app.globalData.token // token
},
url: app.globalData.fit_journey_ai_address+`/ai/recipe`, //
filePath: filePath,
name: 'file', //
success: (uploadFileRes) => {
console.log('上传结果:', uploadFileRes);
const response = JSON.parse(uploadFileRes.data); //
if (response && response.data) {
//
this.calorie = response.data.calorie || 0;
this.name = response.data.name || '识别失败,请重新上传图片';
} else {
uni.showToast({
title: '识别失败,请重新上传图片',
icon: 'none',
});
}
},
fail: () => {
uni.showToast({
title: '图片上传失败',
icon: 'none',
});
},
});
},
fail: () => {
uni.showToast({
title: '图片选择失败',
icon: 'none',
});
},
});
}
},
};
</script>
<style lang="scss">
@import "@/static/homepages/homes/ai_recognize_recipe/css/ai_recongnize_recipe.scss";
</style>

@ -2,6 +2,8 @@
<view>
<text>这个是puppy_chat界面</text>
<tarbar_puppy_chat></tarbar_puppy_chat>
</view>
</template>

@ -1,18 +1,77 @@
<template>
<view>
<text>这个是User界面</text>
<!-- ECharts 图表 -->
<view style="width: 100%; height: 400px;">
<canvas ref="myChart" style="width: 100%; height: 100%;"></canvas>
</view>
<tarbar_user></tarbar_user>
</view>
</template>
<script>
import * as echarts from 'echarts';
export default {
data() {
return {};
},
onReady() {
this.initChart();
},
methods: {
initChart() {
const chartDom = this.$refs.myChart;
const myChart = echarts.init(chartDom);
const option = {
legend: {
top: 'bottom'
},
toolbox: {
show: true,
feature: {
mark: { show: true },
dataView: { show: true, readOnly: false },
restore: { show: true },
saveAsImage: { show: true }
}
},
series: [
{
name: 'Nightingale Chart',
type: 'pie',
radius: [50, 250],
center: ['50%', '50%'],
roseType: 'area',
itemStyle: {
borderRadius: 8
},
data: [
{ value: 40, name: 'rose 1' },
{ value: 38, name: 'rose 2' },
{ value: 32, name: 'rose 3' },
{ value: 30, name: 'rose 4' },
{ value: 28, name: 'rose 5' },
{ value: 26, name: 'rose 6' },
{ value: 22, name: 'rose 7' },
{ value: 18, name: 'rose 8' }
]
}
]
};
myChart.setOption(option);
},
onResize() {
this.myChart.resize();
}
}
}
</script>
<style lang="scss">
/* 添加样式 */
</style>

@ -0,0 +1,68 @@
.background {
background-image: url("@/static/homepages/homes/ai_recognize_recipe/pictures/background.png");
background-size: cover;
background-position: center;
height: 100vh;
display: flex;
flex-direction: column; /* 纵向排列 */
align-items: center; /* 水平居中 */
justify-content: flex-end; /* 使内容向底部对齐 */
position: relative; /* 为绝对定位子元素提供相对定位的上下文 */
}
.upload_picture{
position: absolute; /* 绝对定位 */
width: 90%;
height: 30%;
top: 43%; /* 距离底部 20% 的位置 */
left: 50%; /* 水平居中 */
transform: translateX(-50%); /* 通过 translateX 使其居中 */
}
.button {
position: absolute; /* 绝对定位 */
width: 15%;
height: 7%;
top: 1%; /* 距离底部 20% 的位置 */
left: 8%; /* 水平居中 */
transform: translateX(-50%); /* 通过 translateX 使其居中 */
}
.calorie_container {
background-image: url("@/static/homepages/homes/ai_recognize_recipe/pictures/calorie.png");
background-size: cover;
background-position: center;
display: flex; /* 使用 flex 布局 */
flex-direction: column;
align-items: center; /* 水平居中 */
justify-content: center; /* 垂直居中 */
position: absolute;
width: 40%;
height: 25%;
bottom: 2%;
left: 6%;
}
.calorie_text {
font-size: 23px;
color: #c63030;
font-weight: bold;
margin-top: 100%; /* 向下移动 100% */
}
.name_container{
background-image: url("@/static/homepages/homes/ai_recognize_recipe/pictures/name.png");
background-size: cover;
background-position: center;
display: flex; /* 使用 flex 布局 */
flex-direction: column;
align-items: center; /* 水平居中 */
justify-content: center; /* 垂直居中 */
position: absolute;
width: 40%;
height: 26%;
bottom: 2%;
left: 54%;
}
.name_text {
font-size: 23px;
color: #c63030;
font-weight: 800;
margin-top: 100%; /* 向下移动 100% */
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 161 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 37 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

@ -1,8 +1,15 @@
{
"hash": "3dcffc29",
"hash": "0aaf698d",
"configHash": "cc60d382",
"lockfileHash": "e3b0c442",
"browserHash": "e601f541",
"optimized": {},
"lockfileHash": "22a0e42d",
"browserHash": "eed84a77",
"optimized": {
"echarts": {
"src": "../../../../../node_modules/echarts/index.js",
"file": "echarts.js",
"fileHash": "12ff8916",
"needsInterop": false
}
},
"chunks": {}
}
Loading…
Cancel
Save