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

master
xiaozhi 4 months ago
parent bf5fccacce
commit d76f318a9c

@ -176,6 +176,13 @@
"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",
"style": {
@ -249,14 +256,8 @@
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
},
{
"path": "pages/homepages/homes/ai_recognize_fruit/ai_recognize_fruit",
"style": {
"navigationBarTitleText": "",
"enablePullDownRefresh": false
}
}
],
"uniIdRouter": {},
"tabBar": null

@ -1,17 +1,98 @@
<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>
</template>
<script>
export default {
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>
<style lang="scss">
@import "@/static/homepages/homes/ai_recognize_fruit/css/ai_recongnize_fruit.scss";
</style>

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