前端AI识别果蔬种类和热量界面

master
xiaozhi 5 months ago
parent bf5fccacce
commit d76f318a9c

@ -176,6 +176,13 @@
"navigationStyle": "custom" "navigationStyle": "custom"
} }
},*/ },*/
{
"path": "pages/homepages/homes/ai_recognize_fruit/ai_recognize_fruit",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{ {
"path": "pages/homepages/homes/ai_recognize_recipe/ai_recognize_recipe", "path": "pages/homepages/homes/ai_recognize_recipe/ai_recognize_recipe",
"style": { "style": {
@ -249,14 +256,8 @@
"navigationBarTitleText": "", "navigationBarTitleText": "",
"enablePullDownRefresh": false "enablePullDownRefresh": false
} }
},
{
"path": "pages/homepages/homes/ai_recognize_fruit/ai_recognize_fruit",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
} }
], ],
"uniIdRouter": {}, "uniIdRouter": {},
"tabBar": null "tabBar": null

@ -1,17 +1,98 @@
<template> <template>
<view> <view class="background">
<!-- 点击上传图片按钮 -->
<image class="upload_picture" @click="selectAndUploadPicture" src="@/static/homepages/homes/ai_recognize_fruit/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_fruit/pictures/button.png"></image>
</view> </view>
</template> </template>
<script> <script>
export default { export default {
data() { data() {
return {}; 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> </script>
<style lang="scss"> <style lang="scss">
@import "@/static/homepages/homes/ai_recognize_fruit/css/ai_recongnize_fruit.scss";
</style> </style>

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