完成AI识别果蔬种类和热量模块,并成功和后端对接

master
Gary 3 months ago
parent d76f318a9c
commit 105503f15c

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

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

@ -14,7 +14,7 @@
</view>
<!-- 返回按钮 -->
<image class="button" @click="goBackToHome" src="@/static/homepages/homes/ai_recognize_fruit/pictures/button.png"></image>
<image class="button" @click="goBackToHome" src="/static/homepages/homes/ai_recognize_fruit/pictures/button.png"></image>
</view>
</template>
@ -36,49 +36,49 @@ export default {
selectAndUploadPicture() {
const app = getApp();
const serverAddress = app.globalData.fit_journey_ai_address;
console.log("后端服务器的地址是:"+serverAddress);
console.log("后端服务器的地址是:" + serverAddress);
// API
uni.file
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',
});
},
});
//
uni.uploadFile({
header: {
'Authorization': app.globalData.token // token
},
url: app.globalData.fit_journey_ai_address + `/ai/fruit`, //
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({

@ -0,0 +1,68 @@
.background {
background-image: url("@/static/homepages/homes/ai_recognize_fruit/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: 25%;
top: 45%; /* 距离底部 20% 的位置 */
left: 50%; /* 水平居中 */
transform: translateX(-50%); /* 通过 translateX 使其居中 */
}
.button {
position: absolute; /* 绝对定位 */
width: 13%;
height: 6%;
top: 0%;
left: 6%; /* 水平居中 */
transform: translateX(-50%); /* 通过 translateX 使其居中 */
}
.calorie_container {
background-image: url("@/static/homepages/homes/ai_recognize_fruit/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: 27%;
bottom: 3%;
left: 6%;
}
.calorie_text {
font-size: 23px;
color: #1b1313;
font-weight: bold;
margin-top: 100%; /* 向下移动 100% */
}
.name_container{
background-image: url("@/static/homepages/homes/ai_recognize_fruit/pictures/fruit.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: 3%;
left: 54%;
}
.name_text {
font-size: 23px;
color: #0c0b0b;
font-weight: 800;
margin-top: 100%; /* 向下移动 100% */
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 237 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 81 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 118 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Loading…
Cancel
Save