优化后,再次提交

This commit is contained in:
王利强
2026-05-03 09:08:56 +08:00
parent 721ef0ad54
commit 805747d1d9
1243 changed files with 46213 additions and 221 deletions

View File

@@ -102,6 +102,12 @@
<up-upload :fileList="hazardFileList" @afterRead="afterRead" @delete="deletePic" name="1" multiple
:maxCount="10"></up-upload>
<view class="text-gray text-sm">必填请上传现场照片或者视频作为隐患证据</view>
<view class="ai-btn-wrapper margin-top">
<button class="ai-analyze-btn" :loading="aiAnalyzing" :disabled="aiAnalyzing" @click="handleAiAnalyze">
<text v-if="!aiAnalyzing" class="cuIcon-magic ai-btn-icon"></text>
{{ aiAnalyzing ? 'AI识别中...' : 'AI 识别隐患' }}
</button>
</view>
<view class="flex margin-bottom margin-top">
<view class="text-gray">隐患标题</view>
<view class="text-red">*</view>
@@ -112,8 +118,14 @@
<view class="text-gray">隐患等级</view>
<view class="text-red">*</view>
</view>
<up-choose v-model="hazardFormData.level" :options="levelOptions" :wrap="false" item-width="183rpx"
item-height="72rpx"></up-choose>
<up-choose
ref="levelChooseRef"
v-model="hazardFormData.level"
:options="levelOptions"
:wrap="false"
item-width="183rpx"
item-height="72rpx"
></up-choose>
<view class="flex margin-bottom margin-top">
<view class="text-gray">隐患来源</view>
<view class="text-red">*</view>
@@ -191,9 +203,9 @@
</template>
<script setup>
import { ref, reactive, computed } from 'vue';
import { ref, reactive, computed, nextTick } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { enterCheckPlan, submitCheckResult, addHiddenDanger, getHiddenDangerLabelList } from '@/request/api.js';
import { enterCheckPlan, submitCheckResult, addHiddenDanger, getHiddenDangerLabelList, analyzeHazardImage } from '@/request/api.js';
import { baseUrl, getToken } from '@/request/request.js';
import { getAreaList } from '@/request/three_one_api/area.js';
@@ -290,6 +302,12 @@
// 隐患附件列表
const hazardFileList = ref([]);
// up-choose 组件的 ref
const levelChooseRef = ref(null);
// AI 识别相关
const aiAnalyzing = ref(false);
// 是否已填写隐患数据
const hasHazardData = computed(() => {
return hazardFormData.title && hazardFileList.value.length > 0;
@@ -427,11 +445,13 @@
for (let i = 0; i < lists.length; i++) {
const result = await uploadFilePromise(lists[i].url);
let item = hazardFileList.value[fileListLen];
const serverPath = typeof result === 'string' ? result : (result?.url || result?.path || '');
hazardFileList.value.splice(fileListLen, 1, {
...item,
status: 'success',
message: '',
url: result,
url: baseUrl.replace('/prod-api', '') + serverPath,
serverPath: serverPath,
});
fileListLen++;
}
@@ -463,6 +483,57 @@
});
};
// AI 识别隐患
const handleAiAnalyze = async () => {
const imageFiles = hazardFileList.value.filter(f => {
return f.status === 'success' && f.url.toLowerCase().match(/\.(jpg|jpeg|png|gif|bmp|webp)$/);
});
if (imageFiles.length === 0) {
uni.showToast({ title: '请先上传隐患图片', icon: 'none' });
return;
}
const fullImageUrl = imageFiles[0].url;
aiAnalyzing.value = true;
try {
console.log('开始调用AI分析接口图片地址:', fullImageUrl);
const analyzeRes = await analyzeHazardImage({
imageUrl: fullImageUrl,
});
if (analyzeRes.code === 0 && analyzeRes.data) {
const aiData = analyzeRes.data;
console.log('AI分析结果:', aiData);
if (aiData.title) hazardFormData.title = aiData.title;
if (aiData.description) hazardFormData.description = aiData.description;
if (aiData.level) {
const levelMap = { '轻微': 0, '轻微隐患': 0, '一般': 1, '一般隐患': 1, '重大': 2, '重大隐患': 2 };
const levelIndex = levelMap[aiData.level];
if (levelIndex !== undefined) {
hazardFormData.level = levelIndex;
nextTick(() => {
if (levelChooseRef.value && levelChooseRef.value.$data) {
levelChooseRef.value.$data.currentIndex = levelIndex;
}
});
}
}
uni.showToast({ title: 'AI分析完成已自动填充', icon: 'success', duration: 2000 });
} else {
uni.showToast({ title: analyzeRes.msg || 'AI分析失败', icon: 'none' });
}
} catch (error) {
console.error('AI分析接口调用失败:', error);
uni.showToast({ title: 'AI分析失败请重试', icon: 'none' });
} finally {
aiAnalyzing.value = false;
}
};
// ==================== 提交逻辑 ====================
// 提交检查结果
@@ -836,6 +907,38 @@
.popup-body {
padding: 30rpx;
}
// AI 识别按钮样式
.ai-btn-wrapper {
display: flex;
justify-content: flex-end;
}
.ai-analyze-btn {
display: flex;
align-items: center;
justify-content: center;
height: 72rpx;
padding: 0 32rpx;
font-size: 28rpx;
color: #fff;
background: linear-gradient(135deg, #4facfe 0%, #2668EA 100%);
border-radius: 36rpx;
border: none;
&::after {
border: none;
}
.ai-btn-icon {
margin-right: 8rpx;
font-size: 30rpx;
}
&[disabled] {
opacity: 0.7;
}
}
.popup-footer {
display: flex;