已完成以下任务:

创建了 ItemAnalysis.vue 组件:

包含一个下拉选择框,列出了所有项目名称
实现了项目分析功能,可以针对选中的项目进行详细分析
使用AI模型对选中的项目进行专业分析
提供了分析结果的展示区域
修改了主组件 index.vue:

导入了 ItemAnalysis 组件
添加了 handleItemAnalysis 函数,点击"项目分析"按钮时切换到 ItemAnalysis 组件
修改了"修改"按钮为"项目分析"按钮,并绑定到 handleItemAnalysis 函数
现在系统有两个分析功能:

帕累托分析:显示所有项目的整体分析,并提供AI分析功能
项目分析:允许用户选择特定项目,并对该项目进行深入分析
用户可以通过点击不同的按钮在这两个分析界面之间切换,实现了功能的模块化和动态内容替换。
master
huangjinysf 3 months ago
parent 7dc2e72cb6
commit b81fe7b641

@ -0,0 +1,19 @@
// AI模型配置文件
export const AI_CONFIG = {
// AI模型配置
DEEPSEEK: {
BASE_URL: 'https://api.deepseek.com/v1',
MODEL: 'deepseek-chat',
API_KEY: 'sk-4fa66e674e57479d961e4ad2036cbc52'
},
// 其他AI模型配置示例可扩展
OPENAI: {
BASE_URL: 'https://api.openai.com/v1',
MODEL: 'gpt-3.5-turbo',
API_KEY: '' // 需要配置
}
}
// 当前使用的AI模型
export const CURRENT_AI_MODEL = 'DEEPSEEK'

@ -0,0 +1,188 @@
<template>
<div class="item-analysis-container">
<div class="item-select-section">
<el-form :model="analysisForm" label-width="100px">
<el-form-item label="项目名称">
<el-select
v-model="analysisForm.selectedItem"
placeholder="请选择要分析的项目"
style="width: 300px"
clearable
>
<el-option
v-for="item in itemList"
:key="item"
:label="item"
:value="item"
/>
</el-select>
<el-button
type="primary"
style="margin-left: 10px"
:disabled="!analysisForm.selectedItem"
@click="handleAnalyzeItem"
>
分析
</el-button>
</el-form-item>
</el-form>
</div>
<!-- 分析结果显示区域 -->
<div v-if="analysisResult" class="analysis-result">
<h3>{{ analysisForm.selectedItem }} - 分析结果</h3>
<el-input
v-model="analysisResult"
type="textarea"
:rows="10"
readonly
/>
</div>
</div>
</template>
<script setup>
import { ref, reactive } from 'vue'
import { AI_CONFIG, CURRENT_AI_MODEL } from "@/config/ai"
const props = defineProps({
paretoData: {
type: Array,
default: () => []
},
dateRange: {
type: Object,
default: () => ({
start_date: '',
end_date: ''
})
}
})
const emit = defineEmits(['ai-analysis-complete'])
//
const analysisForm = reactive({
selectedItem: ''
})
//
const analysisResult = ref('')
//
const itemList = ref([
'漆膜厚度',
'击穿电压2(kv)',
'击穿电压5(kv)',
'击穿电压4(kv)',
'击穿电压3(kv)',
'回弹角(°)1',
'回弹角(°)2',
'击穿电压1(kv)',
'漆膜连续性(个)',
'最大外径',
'伸长率(%)1',
'导体f值',
'电阻值',
'预置伸长率',
'伸长率(%)2',
'平均单刮(N)',
'单向刮漆min(N)'
])
//
async function handleAnalyzeItem() {
if (!analysisForm.selectedItem) {
emit('ai-analysis-complete', '请先选择要分析的项目')
return
}
//
const selectedItemData = props.paretoData.find(item => item.item_name === analysisForm.selectedItem)
//
const prompt = `请对以下质检项目进行详细分析:
项目名称: ${analysisForm.selectedItem}
数据范围: ${props.dateRange.start_date} ${props.dateRange.end_date}
该项目相关数据:
${selectedItemData ?
`- 缺陷数量: ${selectedItemData.defect_count}\n- 缺陷占比: ${selectedItemData.defect_percentage}%\n- 累计占比: ${selectedItemData.cumulative_percentage}%` :
'该项目在当前帕累托分析数据中不存在'}
请从以下角度进行分析
1. 该项目缺陷对整体质量的影响
2. 产生缺陷的可能原因分析
3. 针对该项目的改进建议
4. 该项目与其他项目的关联性分析`
try {
// AI
const currentAIConfig = AI_CONFIG[CURRENT_AI_MODEL]
// AIAPI
const response = await fetch(`${currentAIConfig.BASE_URL}/chat/completions`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${currentAIConfig.API_KEY}`
},
body: JSON.stringify({
model: currentAIConfig.MODEL,
messages: [
{
role: 'system',
content: '你是一位专业的质量控制专家,擅长分析具体质检项目并提供针对性的改进建议。'
},
{
role: 'user',
content: prompt
}
],
temperature: 0.3,
max_tokens: 1500
})
})
if (!response.ok) {
throw new Error(`API调用失败: ${response.status}`)
}
const data = await response.json()
const result = data.choices[0].message.content
analysisResult.value = result
//
emit('ai-analysis-complete', result)
} catch (error) {
console.error('项目分析失败:', error)
const errorMessage = `项目分析失败: ${error.message}\n\n请检查网络连接或稍后再试。`
analysisResult.value = errorMessage
//
emit('ai-analysis-complete', errorMessage)
}
}
</script>
<style scoped>
.item-analysis-container {
width: 100%;
padding: 20px;
}
.item-select-section {
margin-bottom: 20px;
padding: 15px;
background-color: #f5f7fa;
border-radius: 4px;
}
.analysis-result {
margin-top: 20px;
}
.analysis-result h3 {
margin-bottom: 15px;
color: #409eff;
}
</style>

@ -72,6 +72,7 @@
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
import { API_CONFIG } from "@/config/api" import { API_CONFIG } from "@/config/api"
import { AI_CONFIG, CURRENT_AI_MODEL } from "@/config/ai"
const props = defineProps({ const props = defineProps({
selectedTimeRange: { selectedTimeRange: {
@ -91,7 +92,7 @@ const props = defineProps({
}, },
apiKey: { apiKey: {
type: String, type: String,
default: 'sk-4fa66e674e57479d961e4ad2036cbc52' default: AI_CONFIG[CURRENT_AI_MODEL].API_KEY
} }
}) })
@ -125,29 +126,32 @@ async function handleAIAnalysis() {
// //
const prompt = `请分析以下帕累托分析数据,提供专业的质量控制见解: const prompt = `请分析以下帕累托分析数据,提供专业的质量控制见解:
数据范围: ${props.dateRange.start_date} ${props.dateRange.end_date} 数据范围: ${props.dateRange.start_date} ${props.dateRange.end_date}
检测项目总数: ${props.paretoData.length} 检测项目总数: ${props.paretoData.length}
详细数据: 详细数据:
${props.paretoData.map(item => ${props.paretoData.map(item =>
`- ${item.item_name}: 缺陷数 ${item.defect_count}, 缺陷占比 ${item.defect_percentage}%, 累计占比 ${item.cumulative_percentage}%` `- ${item.item_name}: 缺陷数 ${item.defect_count}, 缺陷占比 ${item.defect_percentage}%, 累计占比 ${item.cumulative_percentage}%`
).join('\n')} ).join('\n')}
请从以下角度进行分析 请从以下角度进行分析
1. 主要缺陷项及其影响程度 1. 主要缺陷项及其影响程度
2. 帕累托原理(80/20法则)在此数据中的体现 2. 帕累托原理(80/20法则)在此数据中的体现
3. 针对高缺陷率项的改进建议 3. 针对高缺陷率项的改进建议
4. 质量控制重点优化方向` 4. 质量控制重点优化方向`
// DeepSeek API // AI
const response = await fetch('https://api.deepseek.com/v1/chat/completions', { const currentAIConfig = AI_CONFIG[CURRENT_AI_MODEL]
// AIAPI
const response = await fetch(`${currentAIConfig.BASE_URL}/chat/completions`, {
method: 'POST', method: 'POST',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'Authorization': `Bearer ${props.apiKey}` 'Authorization': `Bearer ${currentAIConfig.API_KEY}`
}, },
body: JSON.stringify({ body: JSON.stringify({
model: 'deepseek-chat', model: currentAIConfig.MODEL,
messages: [ messages: [
{ {
role: 'system', role: 'system',
@ -158,8 +162,8 @@ ${props.paretoData.map(item =>
content: prompt content: prompt
} }
], ],
temperature: 0.7, temperature: 0.1,
max_tokens: 1500 max_tokens: 2000
}) })
}) })

@ -41,7 +41,7 @@
type="success" type="success"
plain plain
icon="Edit" icon="Edit"
@click="handleUpdate" @click="handleItemAnalysis"
v-hasPermi="['warehouse:WmsImportResult:edit']" v-hasPermi="['warehouse:WmsImportResult:edit']"
>项目分析</el-button> >项目分析</el-button>
</el-col> </el-col>
@ -50,7 +50,6 @@
<el-button <el-button
type="danger" type="danger"
plain plain
icon="Delete"
:disabled="multiple" :disabled="multiple"
@click="handleDelete" @click="handleDelete"
v-hasPermi="['warehouse:WmsImportResult:remove']" v-hasPermi="['warehouse:WmsImportResult:remove']"
@ -60,10 +59,9 @@
<el-button <el-button
type="warning" type="warning"
plain plain
icon="Download"
@click="handleExport" @click="handleExport"
v-hasPermi="['warehouse:WmsImportResult:export']" v-hasPermi="['warehouse:WmsImportResult:export']"
>导出</el-button> >产品特征分析</el-button>
</el-col> </el-col>
<right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar> <right-toolbar v-model:showSearch="showSearch" @queryTable="getList"></right-toolbar>
</el-row> </el-row>
@ -104,6 +102,7 @@
import { ref, reactive, shallowRef } from 'vue' import { ref, reactive, shallowRef } from 'vue'
import { API_CONFIG } from "@/config/api" import { API_CONFIG } from "@/config/api"
import ParetoAnalysis from './ParetoAnalysis.vue' import ParetoAnalysis from './ParetoAnalysis.vue'
import ItemAnalysis from './ItemAnalysis.vue'
import EmptyContent from './EmptyContent.vue' import EmptyContent from './EmptyContent.vue'
const showSearch = ref(true) const showSearch = ref(true)
@ -198,6 +197,12 @@ function handleAIAnalysisComplete(result) {
} }
//
function handleItemAnalysis() {
//
currentComponent.value = ItemAnalysis;
}
</script> </script>
<style> <style>

Loading…
Cancel
Save