这一版本优化了很多

This commit is contained in:
王利强
2026-06-03 10:16:37 +08:00
parent 8046316216
commit 2af9f1fd59
954 changed files with 58194 additions and 1609 deletions

View File

@@ -88,19 +88,29 @@
<button class="bg-blue round margin-top-xl" @click="handleSubmit">提交</button>
<!-- 新增隐患弹窗 -->
<u-popup :show="showHazardPopup" mode="center" round="20" @close="showHazardPopup = false">
<u-popup :show="showHazardPopup" mode="center" round="20" :safeAreaInsetBottom="false" @close="showHazardPopup = false">
<view class="popup-content">
<view class="popup-header">
<view class="popup-title text-bold">填写隐患信息</view>
<view class="popup-close" @click="showHazardPopup = false">×</view>
</view>
<scroll-view class="popup-body" scroll-y :style="{ height: '60vh' }">
<!-- 草稿恢复提示 -->
<view v-if="showRestoreBanner" class="bg-orange-light text-orange padding-sm radius margin-bottom flex justify-between align-center" style="font-size: 24rpx; background-color: #FFF7EB; border: 1rpx solid #FFE4CC; width: 100%; box-sizing: border-box; display: flex; flex-direction: row; justify-content: space-between; align-items: center; margin-bottom: 20rpx;">
<view class="flex align-center" style="display: flex; flex-direction: row; align-items: center;">
<text class="cuIcon-info margin-right-xs" style="margin-right: 10rpx;"></text>
<text>已自动恢复您上次未提交的内容</text>
</view>
<text class="text-blue text-bold" style="cursor: pointer; padding: 0 10rpx; color: #2667E9; font-weight: bold;" @click="clearDraft(true)">清空草稿</text>
</view>
<view class="flex margin-bottom">
<view class="text-gray">隐患图片</view>
<view class="text-red">*</view>
</view>
<up-upload :fileList="hazardFileList" @afterRead="afterRead" @delete="deletePic" name="1" multiple
<up-upload :fileList="hazardFileList" @afterRead="afterRead" @delete="deletePic" name="1" multiple imageMode="aspectFill"
:maxCount="10"></up-upload>
<!-- 隐藏的 Canvas用于渲染防作弊时间戳水印 -->
<canvas canvas-id="watermarkCanvas" :width="canvasWidth" :height="canvasHeight" :style="{ width: canvasWidth + 'px', height: canvasHeight + 'px', position: 'fixed', left: '-9999px', top: '-9999px' }"></canvas>
<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">
@@ -143,6 +153,17 @@
</view>
<view class="text-gray text-sm margin-top-xs">办公楼3层东侧消防通道生产车间A区设备旁等</view>
<!-- 法律依据 -->
<view class="flex margin-bottom margin-top">
<view class="text-gray">法律依据</view>
</view>
<view class="select-trigger" @click="openLawPopup">
<view class="select-value" :class="{ 'placeholder': !hazardFormData.regulationName }">
{{ hazardFormData.regulationName || '请选择法律依据' }}
</view>
<text class="cuIcon-unfold"></text>
</view>
<!-- 隐患区域选择 -->
<view class="flex margin-bottom margin-top">
<view class="text-gray">隐患区域</view>
@@ -162,7 +183,7 @@
<view class="text-gray text-sm margin-top-xs">请详细说明隐患现状潜在风险及影响范围</view>
<view class="text-gray margin-bottom margin-top">隐患标签</view>
<up-choose v-model="hazardFormData.tagIndex" :options="tagOptions"></up-choose>
<view class="text-gray text-sm">可选择多个相关标签对隐患进行分类</view>
<view class="text-gray text-sm"></view>
</scroll-view>
<view class="popup-footer">
<button class="btn-cancel" @click="showHazardPopup = false">取消</button>
@@ -171,6 +192,45 @@
</view>
</u-popup>
<!-- 选择法规弹出框 -->
<u-popup :show="showLawPopup" mode="center" round="20" :safeAreaInsetBottom="false" @close="showLawPopup = false">
<view class="law-popup">
<view class="popup-header">
<view class="popup-title">选择法律依据</view>
<view class="popup-close" @click="showLawPopup = false">×</view>
</view>
<view class="search-box">
<text class="cuIcon-search search-icon"></text>
<input class="search-input" v-model="lawKeyword" placeholder="请输入关键词搜索" @confirm="searchRegulation" />
<text class="search-btn" @click="searchRegulation">搜索</text>
</view>
<scroll-view class="law-list" scroll-y @scrolltolower="loadMoreLaw">
<view v-if="lawLoading && lawList.length === 0" class="loading-tip">加载中...</view>
<view v-else-if="!lawLoading && lawList.length === 0" class="empty-tip">暂无数据</view>
<template v-else>
<view
class="law-item"
:class="{ 'law-item-active': selectedLawId === item.id }"
v-for="item in lawList"
:key="item.id"
@click="selectLaw(item)"
>
<view class="law-title">{{ item.depict }}</view>
<view class="law-basis text-gray">{{ item.legalBasis }}</view>
</view>
<view v-if="lawLoading" class="loading-tip">加载中...</view>
</template>
</scroll-view>
<view class="popup-footer">
<button class="btn-cancel" @click="showLawPopup = false">取消</button>
<button class="btn-confirm bg-blue" @click="confirmLaw">确定</button>
</view>
</view>
</u-popup>
<!-- 区域选择弹窗 -->
<u-popup :show="showAreaPicker" mode="bottom" round="20" @close="showAreaPicker = false">
<view class="picker-popup">
@@ -203,14 +263,19 @@
</template>
<script setup>
import { ref, reactive, computed, nextTick } from 'vue';
import { ref, reactive, computed, nextTick, watch, getCurrentInstance } from 'vue';
import { onLoad } from '@dcloudio/uni-app';
import { enterCheckPlan, submitCheckResult, addHiddenDanger, getHiddenDangerLabelList, analyzeHazardImage } from '@/request/api.js';
import { baseUrl, getToken } from '@/request/request.js';
import { enterCheckPlan, submitCheckResult, addHiddenDanger, getHiddenDangerLabelList, getRegulationList, analyzeHazardImage } from '@/request/api.js';
import { baseUrl, getToken, toImageUrl, imageBaseUrl } from '@/request/request.js';
import { addTimestampWatermark } from '@/utils/watermark.js';
import { getAreaList } from '@/request/three_one_api/area.js';
// 页面参数
const oneTableId = ref('');
// 防作弊时间戳水印 Canvas 大小配置
const canvasWidth = ref(300);
const canvasHeight = ref(300);
// 检查项数据
const checkData = ref(null);
@@ -262,7 +327,9 @@
level: 0,
source: 0,
description: '',
tagIndex: 0
tagIndex: 0,
regulationId: null, // 法律依据ID
regulationName: '' // 法律依据名称(显示用)
});
// 隐患地址和经纬度
@@ -277,6 +344,87 @@
const selectedAreaName = ref('');
const tempAreaId = ref('');
// 选择法规(法律依据)相关
const showLawPopup = ref(false);
const lawKeyword = ref('');
const selectedLawId = ref(null);
const selectedLawName = ref('');
const lawList = ref([]);
const lawLoading = ref(false);
const lawPageNum = ref(1);
const lawPageSize = ref(10);
const hasMoreLaw = ref(true);
// 打开法规选择弹窗
const openLawPopup = () => {
showLawPopup.value = true;
if (lawList.value.length === 0) {
fetchRegulationList();
}
};
// 获取法规列表
const fetchRegulationList = async (isLoadMore = false) => {
if (lawLoading.value) return;
lawLoading.value = true;
try {
const params = {
pageNum: lawPageNum.value,
pageSize: lawPageSize.value,
status: 1 // 启用状态
};
if (lawKeyword.value && lawKeyword.value.trim()) {
params.keyword = lawKeyword.value.trim();
}
const res = await getRegulationList(params);
if (res.code === 0) {
const records = res.data.records || res.data || [];
if (isLoadMore) {
lawList.value = [...lawList.value, ...records];
} else {
lawList.value = records;
}
const total = res.data.total || 0;
hasMoreLaw.value = lawList.value.length < total;
}
} catch (error) {
console.error('获取法规列表失败:', error);
} finally {
lawLoading.value = false;
}
};
// 搜索法规
const searchRegulation = () => {
lawPageNum.value = 1;
lawList.value = [];
hasMoreLaw.value = true;
fetchRegulationList();
};
// 加载更多法规
const loadMoreLaw = () => {
if (!hasMoreLaw.value || lawLoading.value) return;
lawPageNum.value++;
fetchRegulationList(true);
};
// 选择法规
const selectLaw = (item) => {
selectedLawId.value = item.id;
selectedLawName.value = item.depict || item.keyword || '';
};
// 确认选择法规
const confirmLaw = () => {
if (selectedLawId.value) {
hazardFormData.regulationId = selectedLawId.value;
hazardFormData.regulationName = selectedLawName.value;
}
showLawPopup.value = false;
};
// 获取区域列表
const fetchAreaList = async () => {
try {
@@ -323,7 +471,7 @@
// 隐患等级选项
const levelOptions = ref([
{ id: 1, title: '轻微隐患' },
// { id: 1, title: '轻微隐患' },
{ id: 2, title: '一般隐患' },
{ id: 3, title: '重大隐患' }
]);
@@ -366,6 +514,10 @@
// 清除隐患信息
const clearHazard = () => {
hazardFormData.regulationId = null;
hazardFormData.regulationName = '';
selectedLawId.value = null;
selectedLawName.value = '';
hazardFormData.title = '';
hazardFormData.level = 0;
hazardFormData.source = 0;
@@ -443,14 +595,27 @@
});
});
for (let i = 0; i < lists.length; i++) {
const result = await uploadFilePromise(lists[i].url);
let watermarkedUrl = lists[i].url;
try {
const instance = getCurrentInstance();
watermarkedUrl = await addTimestampWatermark({
tempFilePath: lists[i].url,
canvasId: 'watermarkCanvas',
canvasWidthRef: canvasWidth,
canvasHeightRef: canvasHeight,
instance
});
} catch (e) {
console.error('加水印失败,将使用原图上传:', e);
}
const result = await uploadFilePromise(watermarkedUrl);
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: baseUrl.replace('/prod-api', '') + serverPath,
url: toImageUrl(serverPath),
serverPath: serverPath,
});
fileListLen++;
@@ -572,6 +737,9 @@
} else if (file.url && typeof file.url === 'object') {
url = file.url.url || file.url.path || '';
}
if (typeof url === 'string' && url.startsWith('http')) {
url = url.replace(imageBaseUrl, '');
}
const fileName = (typeof url === 'string' && url) ? url.split('/').pop() : (file.name || '');
return {
fileName: fileName || '',
@@ -598,7 +766,8 @@
description: hazardFormData.description || '',
source: sourceOptions.value[hazardFormData.source]?.title || '',
tagId: tagId,
attachments: attachments
attachments: attachments,
regulationId: hazardFormData.regulationId || null
};
console.log('隐患参数:', hazardParams);
@@ -625,6 +794,7 @@
uni.hideLoading();
if (res.code === 0) {
clearDraft(false);
// 判断是否全部完成
if (res.data && res.data.allFinished === true) {
// 全部完成,退出页面
@@ -675,6 +845,8 @@
console.log('检查项数据:', res);
if (res.code === 0) {
checkData.value = res.data;
// 拿到题目后,安全触发恢复草稿
restoreDraft();
}
} catch (error) {
console.error(error);
@@ -682,6 +854,171 @@
};
// 页面加载时获取参数并调用接口
// 草稿缓存与恢复逻辑 (已深度适配,排除区域选择器列表缓存,仅缓存文字、单选、备注、图片等输入信息)
const hasDraft = ref(false);
const showRestoreBanner = ref(false); // 独立控制提示 Banner仅在初次确实从本地恢复了内容时才显示
const isRestoring = ref(false); // 正在恢复标志避免触发冗余watch
const isInitialized = ref(false); // 初始化标识,防止初期空值覆盖已有草稿
const getDraftKey = () => `draft_inspection_result_${oneTableId.value || ''}_${checkData.value?.currentIndex || ''}`;
// 保存草稿
const saveDraft = () => {
if (isRestoring.value || !isInitialized.value) {
console.log('【草稿Debug - 巡检】saveDraft 被跳过:', { isRestoring: isRestoring.value, isInitialized: isInitialized.value });
return;
}
const key = getDraftKey();
const hasContent = radiovalue1.value ||
value1.value ||
hazardFormData.title ||
hazardFormData.description ||
hazardFileList.value.length > 0;
console.log('【草稿Debug - 巡检】尝试自动保存草稿. Key:', key, '是否有实质内容:', !!hasContent, '当前数据:', {
radiovalue1: radiovalue1.value,
value1: value1.value,
title: hazardFormData.title,
description: hazardFormData.description,
fileCount: hazardFileList.value.length
});
if (!hasContent) {
uni.removeStorageSync(key);
console.log('【草稿Debug - 巡检】当前表单为空,自动删除本地缓存 Key:', key);
hasDraft.value = false;
return;
}
const data = {
radiovalue1: radiovalue1.value,
value1: value1.value,
hazardFormData: {
title: hazardFormData.title,
level: hazardFormData.level,
source: hazardFormData.source,
description: hazardFormData.description,
tagIndex: hazardFormData.tagIndex
},
hazardFileList: hazardFileList.value,
hazardAddress: hazardAddress.value,
hazardLng: hazardLng.value,
hazardLat: hazardLat.value
};
uni.setStorageSync(key, JSON.stringify(data));
console.log('【草稿Debug - 巡检】成功保存草稿到 LocalStorage, Key:', key);
hasDraft.value = true;
};
// 清空草稿
const clearDraft = (showToast = true) => {
const key = getDraftKey();
console.log('【草稿Debug - 巡检】手动清空草稿, Key:', key);
uni.removeStorageSync(key);
hasDraft.value = false;
showRestoreBanner.value = false;
isRestoring.value = true;
radiovalue1.value = '';
value1.value = '';
hazardFormData.title = '';
hazardFormData.level = 0;
hazardFormData.source = 0;
hazardFormData.description = '';
hazardFormData.tagIndex = 0;
hazardFileList.value = [];
hazardAddress.value = '';
hazardLng.value = 0;
hazardLat.value = 0;
nextTick(() => {
isRestoring.value = false;
});
if (showToast) {
uni.showToast({ title: '草稿已清空', icon: 'none' });
}
};
// 恢复草稿
const restoreDraft = () => {
const key = getDraftKey();
const cached = uni.getStorageSync(key);
console.log('【草稿Debug - 巡检】尝试恢复草稿, Key:', key, '获取本地缓存结果:', !!cached);
if (cached) {
try {
const data = JSON.parse(cached);
const hasContent = data.radiovalue1 ||
data.value1 ||
data.hazardFormData.title ||
data.hazardFormData.description ||
(data.hazardFileList && data.hazardFileList.length > 0);
console.log('【草稿Debug - 巡检】解析本地缓存成功, 是否有实质内容:', !!hasContent, '缓存数据:', data);
if (!hasContent) {
isInitialized.value = true;
return;
}
isRestoring.value = true;
radiovalue1.value = data.radiovalue1 || '';
value1.value = data.value1 || '';
hazardFormData.title = data.hazardFormData.title || '';
hazardFormData.level = data.hazardFormData.level || 0;
hazardFormData.source = data.hazardFormData.source || 0;
hazardFormData.description = data.hazardFormData.description || '';
hazardFormData.tagIndex = data.hazardFormData.tagIndex || 0;
hazardFileList.value = data.hazardFileList || [];
hazardAddress.value = data.hazardAddress || '';
hazardLng.value = data.hazardLng || 0;
hazardLat.value = data.hazardLat || 0;
hasDraft.value = true;
showRestoreBanner.value = true; // 确实存在内容并恢复了,才亮起提示 Banner
nextTick(() => {
isRestoring.value = false;
isInitialized.value = true;
if (levelChooseRef.value && levelChooseRef.value.$data) {
levelChooseRef.value.$data.currentIndex = hazardFormData.level;
}
console.log('【草稿Debug - 巡检】UI与多选组件状态同步重绘完毕');
});
uni.showToast({
title: '已自动恢复您上次未提交的内容',
icon: 'none',
duration: 2500
});
} catch (e) {
console.error('【草稿Debug - 巡检】解析草稿异常:', e);
isRestoring.value = false;
isInitialized.value = true;
}
} else {
console.log('【草稿Debug - 巡检】本地无任何缓存, 页面已安全标记为 initialized');
isInitialized.value = true;
}
};
// 监听变量变化,自动保存草稿
watch(
() => [
radiovalue1.value,
value1.value,
hazardFormData.title,
hazardFormData.level,
hazardFormData.source,
hazardFormData.description,
hazardFormData.tagIndex,
hazardAddress.value,
hazardFileList.value
],
() => {
if (oneTableId.value) {
saveDraft();
}
},
{ deep: true }
);
onLoad((options) => {
console.log('接收到的参数:', options);
if (options.id) {
@@ -947,6 +1284,8 @@
button {
flex: 1;
height: 90rpx;
margin: 0 !important;
padding: 0 !important;
line-height: 90rpx;
border-radius: 0;
font-size: 30rpx;
@@ -1064,6 +1403,106 @@
}
// 区域颜色圆点
// 选择法规(法律依据)弹出框样式
.law-popup {
width: 600rpx;
background: #fff;
border-radius: 20rpx;
overflow: hidden;
max-height: 80vh;
.popup-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 30rpx;
border-bottom: 1rpx solid #eee;
.popup-title {
font-size: 32rpx;
font-weight: bold;
color: #333;
}
.popup-close {
font-size: 40rpx;
color: #999;
cursor: pointer;
}
}
}
.search-box {
display: flex;
align-items: center;
background: #F5F5F5;
border-radius: 40rpx;
padding: 16rpx 24rpx;
margin: 20rpx 30rpx;
.search-icon {
font-size: 28rpx;
color: #999;
margin-right: 12rpx;
}
.search-input {
flex: 1;
font-size: 28rpx;
background: transparent;
border: none;
}
.search-btn {
color: #2667E9;
font-size: 26rpx;
margin-left: 16rpx;
cursor: pointer;
}
}
.loading-tip, .empty-tip {
text-align: center;
padding: 40rpx;
color: #999;
font-size: 26rpx;
}
.law-list {
max-height: 500rpx;
padding: 0 30rpx;
}
.law-item {
padding: 24rpx;
border: 2rpx solid #E5E5E5;
border-radius: 12rpx;
margin-bottom: 16rpx;
font-size: 28rpx;
color: #333;
text-align: left;
.law-title {
line-height: 1.5;
margin-bottom: 8rpx;
font-weight: bold;
}
.law-basis {
font-size: 24rpx;
line-height: 1.4;
display: -webkit-box;
-webkit-line-clamp: 2;
-webkit-box-orient: vertical;
overflow: hidden;
}
}
.law-item-active {
border-color: #2667E9;
background: #F0F6FF;
}
.area-color-dot {
width: 24rpx;
height: 24rpx;