支持ai点评

This commit is contained in:
2025-12-02 16:00:58 +08:00
parent 3ace1a35ee
commit e0729ce600
4 changed files with 216 additions and 6 deletions

View File

@@ -674,7 +674,7 @@ export const generatePrioritizedStockRecipe = (pigTypeId) => {
* @returns {Promise<Response<ReviewRecipeResponse>>}
*/
export const aiDiagnoseRecipe = (id, pigTypeId) => {
return http.get(`/api/v1/feed/recipes/${id}/ai-diagnose`, {params: {pig_type_id: pigTypeId}});
return http.get(`/api/v1/feed/recipes/${id}/ai-diagnose`, {params: {pig_type_id: pigTypeId}, timeout: 0});
};

View File

@@ -0,0 +1,188 @@
<template>
<el-dialog
v-model="dialogVisible"
title="AI点评配方"
width="600px"
:before-close="handleClose"
destroy-on-close
>
<el-form label-width="100px">
<el-form-item label="配方名称:">
<span>{{ recipe ? recipe.name : 'N/A' }}</span>
</el-form-item>
<el-form-item label="目标猪类型:">
<el-select
v-model="selectedPigTypeId"
placeholder="请选择目标猪类型"
filterable
:loading="loadingPigTypes"
:disabled="loadingAIReview"
style="width: 100%;"
>
<el-option
v-for="item in pigTypes"
:key="item.id"
:label="item.label"
:value="item.id"
></el-option>
</el-select>
</el-form-item>
<el-form-item label="AI点评结果:" v-if="aiReviewResult || error">
<el-alert
v-if="error"
:title="error"
type="error"
show-icon
:closable="false"
></el-alert>
<el-input
v-else-if="aiReviewResult"
type="textarea"
:rows="8"
:value="`AI模型: ${aiReviewResult.ai_model}\n\n点评内容:\n${aiReviewResult.review_message}`"
readonly
></el-input>
</el-form-item>
</el-form>
<template #footer>
<span class="dialog-footer">
<el-button @click="handleClose" :disabled="loadingAIReview">取消</el-button>
<el-button
type="primary"
@click="handleConfirm"
:loading="loadingAIReview"
:disabled="!selectedPigTypeId || loadingPigTypes"
>
{{ aiReviewResult ? '重新点评' : '开始点评' }}
</el-button>
</span>
</template>
</el-dialog>
</template>
<script>
import { getPigTypes, aiDiagnoseRecipe } from '../../api/feed';
import { ElMessage } from 'element-plus';
export default {
name: 'AIRecipeReviewDialog',
props: {
visible: {
type: Boolean,
default: false,
},
recipe: {
type: Object,
default: null,
},
},
emits: ['update:visible', 'cancel'],
data() {
return {
dialogVisible: this.visible,
pigTypes: [], // 格式化后的猪类型列表
selectedPigTypeId: null,
aiReviewResult: null,
loadingPigTypes: false,
loadingAIReview: false,
error: null,
};
},
watch: {
visible(newVal) {
this.dialogVisible = newVal;
if (newVal) {
this.resetState();
this.loadPigTypes();
}
},
dialogVisible(newVal) {
this.$emit('update:visible', newVal);
},
},
methods: {
/**
* 重置组件内部状态
*/
resetState() {
this.selectedPigTypeId = null;
this.aiReviewResult = null;
this.error = null;
this.pigTypes = [];
},
/**
* 加载猪类型列表
*/
async loadPigTypes() {
this.loadingPigTypes = true;
this.error = null;
try {
// 获取所有猪类型,假设一次性获取足够的数据
const response = await getPigTypes({ page: 1, page_size: 1000 });
if (response.code === 2000 && response.data && response.data.list) {
this.pigTypes = response.data.list.map(type => ({
id: type.id,
label: `${type.breed_name} - ${type.age_stage_name}`,
}));
} else {
this.error = response.msg || '获取猪类型失败';
ElMessage.error(this.error);
}
} catch (err) {
this.error = '加载猪类型失败: ' + (err.message || '未知错误');
ElMessage.error(this.error);
console.error('加载猪类型失败:', err);
} finally {
this.loadingPigTypes = false;
}
},
/**
* 处理确认按钮点击调用AI点评接口
*/
async handleConfirm() {
if (!this.recipe || !this.recipe.id) {
ElMessage.warning('未选择配方');
return;
}
if (!this.selectedPigTypeId) {
ElMessage.warning('请选择目标猪类型');
return;
}
this.loadingAIReview = true;
this.aiReviewResult = null;
this.error = null;
try {
const response = await aiDiagnoseRecipe(this.recipe.id, this.selectedPigTypeId);
if (response.code === 2000 && response.data) {
this.aiReviewResult = response.data;
ElMessage.success('AI点评成功');
} else {
this.error = response.msg || 'AI点评失败';
ElMessage.error(this.error);
}
} catch (err) {
this.error = 'AI点评请求失败: ' + (err.message || '未知错误');
ElMessage.error(this.error);
console.error('AI点评请求失败:', err);
} finally {
this.loadingAIReview = false;
}
},
/**
* 处理对话框关闭
*/
handleClose() {
this.dialogVisible = false;
this.$emit('cancel');
},
},
};
</script>
<style scoped>
/* 可以根据需要添加样式 */
</style>

View File

@@ -24,8 +24,9 @@
</template>
</el-table-column>
<el-table-column prop="description" label="配方简介"/>
<el-table-column label="操作" width="150" align="center">
<el-table-column label="操作" width="250" align="center">
<template #default="scope">
<el-button size="small" type="primary" @click="$emit('ai-review', scope.row)">AI点评</el-button>
<el-button size="small" @click="$emit('edit', scope.row)">编辑</el-button>
<el-button size="small" type="danger" @click="$emit('delete', scope.row)">删除</el-button>
</template>
@@ -43,6 +44,7 @@ export default {
default: () => []
}
},
emits: ['edit', 'delete', 'show-details']
// 声明新的ai-review事件
emits: ['edit', 'delete', 'show-details', 'ai-review']
};
</script>

View File

@@ -41,6 +41,7 @@
@edit="editRecipe"
@delete="deleteRecipe"
@show-details="handleShowDetails"
@ai-review="openAIRecipeReviewDialog"
/>
</el-card>
@@ -65,6 +66,13 @@
@success="onGenerateRecipeSuccess"
@cancel="generateRecipeDialogVisible = false"
/>
<!-- AI点评配方对话框 -->
<AIRecipeReviewDialog
v-model:visible="aiReviewDialogVisible"
:recipe="selectedRecipeForAIReview"
@cancel="aiReviewDialogVisible = false"
/>
</div>
</template>
@@ -75,7 +83,8 @@ import RecipeTable from '../../components/feed/RecipeTable.vue';
import RecipeForm from '../../components/feed/RecipeForm.vue';
import RecipeDetailDialog from '../../components/feed/RecipeDetailDialog.vue';
import { ElMessage, ElMessageBox } from 'element-plus';
import GenerateRecipeDialog from '../../components/feed/GenerateRecipeDialog.vue'; // 引入新的组件
import GenerateRecipeDialog from '../../components/feed/GenerateRecipeDialog.vue';
import AIRecipeReviewDialog from '../../components/feed/AIRecipeReviewDialog.vue'; // 引入新的AI点评组件
export default {
name: 'RecipeList',
@@ -84,7 +93,8 @@ export default {
RecipeForm,
RecipeDetailDialog,
Refresh,
GenerateRecipeDialog, // 注册新的组件
GenerateRecipeDialog,
AIRecipeReviewDialog, // 注册新的AI点评组件
},
data() {
return {
@@ -97,6 +107,8 @@ export default {
detailDialogVisible: false,
selectedRecipe: null,
generateRecipeDialogVisible: false, // 控制一键生成配方弹窗的显示
aiReviewDialogVisible: false, // 控制AI点评弹窗的显示
selectedRecipeForAIReview: null, // 存储当前选择进行AI点评的配方
};
},
async mounted() {
@@ -165,7 +177,15 @@ export default {
ElMessage.success(`配方 "${recipeName}" 生成成功: ${recipeDescription}`);
this.generateRecipeDialogVisible = false;
this.loadRecipes(); // 刷新配方列表
}
},
/**
* 打开AI点评配方对话框
* @param {object} recipe - 需要AI点评的配方对象
*/
openAIRecipeReviewDialog(recipe) {
this.selectedRecipeForAIReview = recipe;
this.aiReviewDialogVisible = true;
},
}
};
</script>