v1.2.1版本,优化调整了很多,整改验收阶段新加字段
This commit is contained in:
@@ -8,9 +8,33 @@
|
||||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.rectifyPlan || '暂无' }}</view>
|
||||
</view>
|
||||
<view class="margin-top">
|
||||
<view style="color: #999; margin-bottom: 10rpx;">完成情况:</view>
|
||||
<view style="color: #999; margin-bottom: 10rpx;">整改措施:</view>
|
||||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.rectificationMeasures || '暂无' }}</view>
|
||||
</view>
|
||||
<view class="margin-top">
|
||||
<view style="color: #999; margin-bottom: 10rpx;">管控措施:</view>
|
||||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.controlMeasures || '暂无' }}</view>
|
||||
</view>
|
||||
<view class="margin-top">
|
||||
<view style="color: #999; margin-bottom: 10rpx;">整改完成情况:</view>
|
||||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.rectifyResult || '暂无' }}</view>
|
||||
</view>
|
||||
<view class="margin-top">
|
||||
<view style="color: #999; margin-bottom: 10rpx;">计划投资资金:</view>
|
||||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ formatMoney(rectifyData.planCost) }}</view>
|
||||
</view>
|
||||
<view class="margin-top">
|
||||
<view style="color: #999; margin-bottom: 10rpx;">实际投资资金:</view>
|
||||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ formatMoney(rectifyData.actualCost) }}</view>
|
||||
</view>
|
||||
<view class="margin-top">
|
||||
<view style="color: #999; margin-bottom: 10rpx;">整改责任人:</view>
|
||||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.rectifierName || '暂无' }}</view>
|
||||
</view>
|
||||
<view class="margin-top">
|
||||
<view style="color: #999; margin-bottom: 10rpx;">完成情况:</view>
|
||||
<view style="word-break: break-all; line-height: 1.6; color: #333;">{{ rectifyData.rectifyStatusName || '暂无' }}</view>
|
||||
</view>
|
||||
<view class="margin-top-sm">
|
||||
<view>整改附件:</view>
|
||||
<view class="flex margin-top-xs" style="flex-wrap: wrap; gap: 10rpx;" v-if="rectifyAttachments.length > 0">
|
||||
@@ -84,8 +108,12 @@
|
||||
import { ref, reactive, watch, nextTick, getCurrentInstance } from 'vue';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import { acceptanceRectification, getHiddenDangerDetail } from '@/request/api.js';
|
||||
import { baseUrl, getToken, toImageUrl, imageBaseUrl } from '@/request/request.js';
|
||||
import { addTimestampWatermark } from '@/utils/watermark.js';
|
||||
import { toImageUrl } from '@/request/request.js';
|
||||
import {
|
||||
createUploadListHandlers,
|
||||
buildAttachmentItem,
|
||||
uploadToCloud
|
||||
} from '@/utils/upload.js';
|
||||
|
||||
// 页面参数
|
||||
const rectifyId = ref('');
|
||||
@@ -95,9 +123,26 @@
|
||||
// 整改记录数据
|
||||
const rectifyData = reactive({
|
||||
rectifyPlan: '',
|
||||
rectifyResult: ''
|
||||
rectificationMeasures: '',
|
||||
controlMeasures: '',
|
||||
rectifyResult: '',
|
||||
planCost: null,
|
||||
actualCost: null,
|
||||
rectifierName: '',
|
||||
rectifyStatusName: ''
|
||||
});
|
||||
|
||||
const formatMoney = (value) => {
|
||||
if (value === null || value === undefined || value === '') {
|
||||
return '暂无';
|
||||
}
|
||||
const num = Number(value);
|
||||
if (Number.isNaN(num)) {
|
||||
return '暂无';
|
||||
}
|
||||
return `${num.toFixed(2)} 元`;
|
||||
};
|
||||
|
||||
// 整改附件
|
||||
const rectifyAttachments = ref([]);
|
||||
|
||||
@@ -148,25 +193,52 @@
|
||||
});
|
||||
};
|
||||
|
||||
// 从 assigns 中找到包含整改记录的那一项
|
||||
const resolveAssignWithRectify = (assigns) => {
|
||||
if (!assigns?.length) return null;
|
||||
if (rectifyId.value) {
|
||||
const byRectifyId = assigns.find(
|
||||
(item) => item.rectify && String(item.rectify.rectifyId) === String(rectifyId.value)
|
||||
);
|
||||
if (byRectifyId) return byRectifyId;
|
||||
}
|
||||
if (assignId.value) {
|
||||
const byAssignId = assigns.find(
|
||||
(item) => String(item.assignId) === String(assignId.value) && item.rectify
|
||||
);
|
||||
if (byAssignId) return byAssignId;
|
||||
}
|
||||
return assigns.find((item) => item.rectify) || null;
|
||||
};
|
||||
|
||||
const applyRectifyData = (rectify) => {
|
||||
if (!rectify) return;
|
||||
rectifyData.rectifyPlan = rectify.rectifyPlan || '';
|
||||
rectifyData.rectificationMeasures = rectify.rectificationMeasures || '';
|
||||
rectifyData.controlMeasures = rectify.controlMeasures || '';
|
||||
rectifyData.rectifyResult = rectify.rectifyResult || '';
|
||||
rectifyData.planCost = rectify.planCost ?? null;
|
||||
rectifyData.actualCost = rectify.actualCost ?? null;
|
||||
rectifyData.rectifierName = rectify.rectifierName || '';
|
||||
rectifyData.rectifyStatusName = rectify.rectifyStatusName || '';
|
||||
rectifyAttachments.value = rectify.attachments || [];
|
||||
};
|
||||
|
||||
// 获取隐患详情
|
||||
const fetchDetail = async () => {
|
||||
if (!hazardId.value || !assignId.value) return;
|
||||
|
||||
if (!hazardId.value) return;
|
||||
|
||||
try {
|
||||
const res = await getHiddenDangerDetail({ hazardId: hazardId.value, assignId: assignId.value });
|
||||
const res = await getHiddenDangerDetail({
|
||||
hazardId: hazardId.value,
|
||||
assignId: assignId.value
|
||||
});
|
||||
if (res.code === 0 && res.data) {
|
||||
// 提取整改信息:assigns[0].rectify
|
||||
if (res.data.assigns && res.data.assigns.length > 0) {
|
||||
const assign = res.data.assigns[0];
|
||||
if (assign.rectify) {
|
||||
rectifyData.rectifyPlan = assign.rectify.rectifyPlan || '';
|
||||
rectifyData.rectifyResult = assign.rectify.rectifyResult || '';
|
||||
if (assign.rectify.attachments) {
|
||||
rectifyAttachments.value = assign.rectify.attachments;
|
||||
}
|
||||
console.log('整改记录:', rectifyData);
|
||||
console.log('整改附件:', rectifyAttachments.value);
|
||||
}
|
||||
const assign = resolveAssignWithRectify(res.data.assigns);
|
||||
if (assign?.rectify) {
|
||||
applyRectifyData(assign.rectify);
|
||||
console.log('整改记录:', rectifyData);
|
||||
console.log('整改附件:', rectifyAttachments.value);
|
||||
}
|
||||
} else {
|
||||
uni.showToast({ title: res.msg || '获取详情失败', icon: 'none' });
|
||||
@@ -176,23 +248,7 @@
|
||||
uni.showToast({ title: '请求失败', icon: 'none' });
|
||||
}
|
||||
};
|
||||
|
||||
onLoad((options) => {
|
||||
if (options.rectifyId) {
|
||||
rectifyId.value = options.rectifyId;
|
||||
}
|
||||
if (options.hazardId) {
|
||||
hazardId.value = options.hazardId;
|
||||
}
|
||||
if (options.assignId) {
|
||||
assignId.value = options.assignId;
|
||||
}
|
||||
console.log('验收页面参数:', { rectifyId: rectifyId.value, hazardId: hazardId.value, assignId: assignId.value });
|
||||
|
||||
// 获取隐患详情
|
||||
fetchDetail();
|
||||
});
|
||||
|
||||
|
||||
// 取消
|
||||
const handleCancel = () => {
|
||||
uni.navigateBack();
|
||||
@@ -240,25 +296,9 @@
|
||||
// 真正调取后台接口提交验收
|
||||
const executeSubmit = async () => {
|
||||
// 构建附件列表
|
||||
const attachments = fileList1.value.map(file => {
|
||||
let url = '';
|
||||
if (typeof file.url === 'string') {
|
||||
url = file.url;
|
||||
} 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 || '',
|
||||
filePath: url || '',
|
||||
fileType: file.type || 'image/png',
|
||||
fileSize: file.size || 0
|
||||
};
|
||||
});
|
||||
const attachments = fileList1.value
|
||||
.filter((f) => f.status === 'success')
|
||||
.map((file) => buildAttachmentItem(file));
|
||||
|
||||
const params = {
|
||||
rectifyId: Number(rectifyId.value),
|
||||
@@ -300,91 +340,15 @@
|
||||
}
|
||||
};
|
||||
|
||||
// 删除图片
|
||||
const deletePic = (event) => {
|
||||
fileList1.value.splice(event.index, 1);
|
||||
};
|
||||
|
||||
// 新增图片
|
||||
/**
|
||||
* 在前端为图片进行实时渲染,添加当前系统时间戳水印(防作弊)
|
||||
* @param {string} tempFilePath 原始选择的图片临时路径
|
||||
* @returns {Promise<string>} 渲染后的带水印图片临时文件路径
|
||||
*/
|
||||
const addWatermark = (tempFilePath) => {
|
||||
const instance = getCurrentInstance();
|
||||
return addTimestampWatermark({
|
||||
tempFilePath,
|
||||
const acceptUploadInstance = getCurrentInstance();
|
||||
const { afterRead, deletePic } = createUploadListHandlers(fileList1, {
|
||||
watermark: {
|
||||
canvasId: 'watermarkCanvas',
|
||||
canvasWidthRef: canvasWidth,
|
||||
canvasHeightRef: canvasHeight,
|
||||
instance
|
||||
});
|
||||
};
|
||||
|
||||
// 新增图片(自动加入实时前端水印渲染防作弊功能)
|
||||
const afterRead = async (event) => {
|
||||
let lists = [].concat(event.file);
|
||||
let fileListLen = fileList1.value.length;
|
||||
lists.map((item) => {
|
||||
fileList1.value.push({
|
||||
...item,
|
||||
status: 'uploading',
|
||||
message: '处理中...',
|
||||
});
|
||||
});
|
||||
for (let i = 0; i < lists.length; i++) {
|
||||
try {
|
||||
// 1. 进行前端实时渲染绘制水印,得到新图片临时路径
|
||||
const watermarkedUrl = await addWatermark(lists[i].url);
|
||||
|
||||
// 2. 将加完水印的新图片进行服务器上传
|
||||
const result = await uploadFilePromise(watermarkedUrl);
|
||||
|
||||
let item = fileList1.value[fileListLen];
|
||||
fileList1.value.splice(fileListLen, 1, {
|
||||
...item,
|
||||
status: 'success',
|
||||
message: '',
|
||||
url: toImageUrl(result.url || result.filePath || result),
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('加水印或上传失败:', e);
|
||||
let item = fileList1.value[fileListLen];
|
||||
fileList1.value.splice(fileListLen, 1, {
|
||||
...item,
|
||||
status: 'failed',
|
||||
message: '处理失败',
|
||||
});
|
||||
}
|
||||
fileListLen++;
|
||||
}
|
||||
};
|
||||
|
||||
const uploadFilePromise = (filePath) => {
|
||||
return new Promise((resolve, reject) => {
|
||||
uni.uploadFile({
|
||||
url: baseUrl + '/frontend/attachment/upload',
|
||||
filePath: filePath,
|
||||
name: 'file',
|
||||
header: {
|
||||
'Authorization': getToken()
|
||||
},
|
||||
success: (res) => {
|
||||
const data = JSON.parse(res.data);
|
||||
if (data.code === 0) {
|
||||
resolve(data.data);
|
||||
} else {
|
||||
reject(data.msg || '上传失败');
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('上传失败:', err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
instance: acceptUploadInstance
|
||||
}
|
||||
});
|
||||
|
||||
// 电子签名画布手写线条变动回调
|
||||
const onSignatureChange = () => {
|
||||
@@ -557,13 +521,12 @@
|
||||
// 签名导出成功回调
|
||||
const onSignatureConfirm = async (tempFilePath) => {
|
||||
try {
|
||||
// 上传签名
|
||||
const res = await uploadFilePromise(tempFilePath);
|
||||
// 兼容后端返回对象或者单纯字符串路径
|
||||
const path = (res && typeof res === 'object') ? (res.url || res.filePath || '') : (res || '');
|
||||
signatureServerPath.value = path;
|
||||
signatureUrl.value = path.startsWith('http') ? path : (baseUrl.replace('/api', '') + path);
|
||||
|
||||
const { url } = await uploadToCloud(tempFilePath);
|
||||
signatureServerPath.value = url;
|
||||
signatureUrl.value = url;
|
||||
showCanvas.value = false;
|
||||
isSignatureEmpty.value = false;
|
||||
|
||||
if (isSubmitting.value) {
|
||||
await executeSubmit();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user