隐患详情重新设计,检查计划重新设计成做题排查式
This commit is contained in:
@@ -74,7 +74,14 @@
|
||||
</view>
|
||||
<view class="signature-box margin-bottom">
|
||||
<view v-if="!showCanvas" class="signature-display flex align-center justify-center" style="width: 100%; height: 160px; background-color: #f8f8f8; display: flex; align-items: center; justify-content: center;">
|
||||
<image :src="signatureUrl" class="signature-img" mode="aspectFit" style="width: 100%; height: 100%;"></image>
|
||||
<image
|
||||
v-if="signatureUrl"
|
||||
:src="signatureUrl"
|
||||
class="signature-img"
|
||||
mode="aspectFit"
|
||||
style="width: 100%; height: 100%;"
|
||||
></image>
|
||||
<text v-else class="signature-placeholder">暂无签名,请点击重新签名</text>
|
||||
</view>
|
||||
<!-- 改为 v-if 解决小程序原生 canvas 真机渲染与生命周期挂载残留问题 -->
|
||||
<view v-if="showCanvas" class="signature-pad-wrap" style="border: 1px dashed #dcdfe6; border-radius: 8rpx; overflow: hidden; background-color: #f8f8f8;">
|
||||
@@ -87,9 +94,10 @@
|
||||
:lineWidth="3"
|
||||
:enableHistory="false"
|
||||
@confirm="(res) => onSignatureConfirm(res.tempFilePath)"
|
||||
@start="isSignatureEmpty = false"
|
||||
@signing="isSignatureEmpty = false"
|
||||
@clear="isSignatureEmpty = true"
|
||||
@start="onSignatureStart"
|
||||
@signing="onSignatureSigning"
|
||||
@end="onSignatureEnd"
|
||||
@clear="onSignatureClear"
|
||||
>
|
||||
<template #footer></template>
|
||||
</wd-signature>
|
||||
@@ -105,14 +113,17 @@
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref, reactive, watch, nextTick, getCurrentInstance } from 'vue';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import { ref, reactive, nextTick, getCurrentInstance } from 'vue';
|
||||
import { onLoad, onHide } from '@dcloudio/uni-app';
|
||||
import { acceptanceRectification, getHiddenDangerDetail } from '@/request/api.js';
|
||||
import { toImageUrl } from '@/request/request.js';
|
||||
import { buildDraftKey, buildDraftKeyCompact, DRAFT_NS } from '@/utils/draftCache.js';
|
||||
import { useDraftCache } from '@/utils/useDraftCache.js';
|
||||
import {
|
||||
createUploadListHandlers,
|
||||
buildAttachmentItem,
|
||||
uploadToCloud
|
||||
uploadToCloud,
|
||||
toSubmitFileUrl
|
||||
} from '@/utils/upload.js';
|
||||
|
||||
// 页面参数
|
||||
@@ -166,14 +177,133 @@
|
||||
const signatureRef = ref(null); // 签名组件 ref
|
||||
const isSignatureEmpty = ref(true); // 签名是否为空
|
||||
const isSubmitting = ref(false); // 是否正在提交表单
|
||||
|
||||
const hasDraft = ref(false);
|
||||
const showRestoreBanner = ref(false); // 独立控制提示 Banner
|
||||
const isRestoring = ref(false); // 正在恢复标志
|
||||
const isInitialized = ref(false); // 初始化标识
|
||||
const signaturePaths = ref([]); // 缓存手写签名的绘制路径
|
||||
|
||||
const getDraftKey = () => `draft_accept_${rectifyId.value || ''}`;
|
||||
const signatureLocalPath = ref(''); // 未上传云端的本地签名临时图
|
||||
const isDraftExporting = ref(false); // 是否为草稿导出(非提交上传)
|
||||
let signatureExportTimer = null;
|
||||
|
||||
/** 将已上传的签名地址应用到预览区 */
|
||||
const applySignatureFromServer = (signPath) => {
|
||||
const url = signPath ? toSubmitFileUrl(signPath) : '';
|
||||
if (!url) {
|
||||
showCanvas.value = true;
|
||||
signatureServerPath.value = '';
|
||||
signatureUrl.value = '';
|
||||
signatureLocalPath.value = '';
|
||||
isSignatureEmpty.value = true;
|
||||
return;
|
||||
}
|
||||
signatureServerPath.value = url;
|
||||
signatureUrl.value = url;
|
||||
signatureLocalPath.value = '';
|
||||
showCanvas.value = false;
|
||||
isSignatureEmpty.value = false;
|
||||
};
|
||||
|
||||
/** 将本地临时签名图应用到预览区(草稿回显) */
|
||||
const applySignatureFromLocal = (localPath) => {
|
||||
if (!localPath) return;
|
||||
signatureLocalPath.value = localPath;
|
||||
signatureUrl.value = localPath;
|
||||
signatureServerPath.value = '';
|
||||
showCanvas.value = false;
|
||||
isSignatureEmpty.value = false;
|
||||
};
|
||||
|
||||
const acceptDraftHasContent = (data) => {
|
||||
const form = data.formData || {};
|
||||
return !!(
|
||||
form.verifyRemark ||
|
||||
(data.fileList1 && data.fileList1.length > 0) ||
|
||||
data.signatureServerPath ||
|
||||
data.signatureLocalPath ||
|
||||
(data.signaturePaths && data.signaturePaths.length > 0)
|
||||
);
|
||||
};
|
||||
|
||||
const {
|
||||
showRestoreBanner,
|
||||
clear: clearDraft,
|
||||
restore: restoreDraft,
|
||||
save: saveDraft,
|
||||
bindAutoSave
|
||||
} = useDraftCache({
|
||||
getKey: () => buildDraftKey(DRAFT_NS.ACCEPT, rectifyId.value),
|
||||
getFallbackKeys: () => {
|
||||
const primary = buildDraftKey(DRAFT_NS.ACCEPT, rectifyId.value);
|
||||
const compact = buildDraftKeyCompact(DRAFT_NS.ACCEPT, rectifyId.value);
|
||||
return compact !== primary ? [compact] : [];
|
||||
},
|
||||
getPayload: () => ({
|
||||
formData: {
|
||||
result: formData.result,
|
||||
verifyRemark: formData.verifyRemark
|
||||
},
|
||||
fileList1: fileList1.value,
|
||||
signatureServerPath: signatureServerPath.value,
|
||||
signatureUrl: signatureUrl.value,
|
||||
signatureLocalPath: signatureLocalPath.value,
|
||||
showCanvas: showCanvas.value,
|
||||
signaturePaths: signaturePaths.value
|
||||
}),
|
||||
hasContent: acceptDraftHasContent,
|
||||
applyPayload: (data) => {
|
||||
const form = data.formData || {};
|
||||
formData.result = form.result !== undefined ? form.result : 1;
|
||||
formData.verifyRemark = form.verifyRemark || '';
|
||||
fileList1.value = data.fileList1 || [];
|
||||
signaturePaths.value = data.signaturePaths || [];
|
||||
if (data.signatureServerPath || data.signatureUrl) {
|
||||
applySignatureFromServer(data.signatureServerPath || data.signatureUrl);
|
||||
} else if (data.signatureLocalPath) {
|
||||
applySignatureFromLocal(data.signatureLocalPath);
|
||||
} else {
|
||||
showCanvas.value = data.showCanvas !== undefined ? data.showCanvas : true;
|
||||
signatureServerPath.value = '';
|
||||
signatureUrl.value = '';
|
||||
signatureLocalPath.value = '';
|
||||
isSignatureEmpty.value = true;
|
||||
}
|
||||
},
|
||||
clearForm: () => {
|
||||
formData.result = 1;
|
||||
formData.verifyRemark = '';
|
||||
fileList1.value = [];
|
||||
signatureServerPath.value = '';
|
||||
signatureUrl.value = '';
|
||||
signatureLocalPath.value = '';
|
||||
showCanvas.value = true;
|
||||
signaturePaths.value = [];
|
||||
if (signatureRef.value) {
|
||||
signatureRef.value.clear();
|
||||
}
|
||||
},
|
||||
canSave: () => !!rectifyId.value,
|
||||
requireInitialized: true,
|
||||
onAfterRestore: (data) => {
|
||||
if (data.signatureServerPath || data.signatureUrl || data.signatureLocalPath) {
|
||||
return;
|
||||
}
|
||||
if (data.signaturePaths?.length > 0) {
|
||||
setTimeout(() => {
|
||||
if (signatureRef.value) {
|
||||
isSignatureEmpty.value = false;
|
||||
}
|
||||
}, 450);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
bindAutoSave(() => [
|
||||
formData.result,
|
||||
formData.verifyRemark,
|
||||
fileList1.value,
|
||||
signatureServerPath.value,
|
||||
signatureUrl.value,
|
||||
signatureLocalPath.value,
|
||||
showCanvas.value,
|
||||
signaturePaths.value
|
||||
]);
|
||||
|
||||
// 获取完整图片路径
|
||||
const getFullPath = (filePath) => {
|
||||
@@ -279,8 +409,8 @@
|
||||
// 触发组件导出,导出成功会回调 onSignatureConfirm
|
||||
signatureRef.value.confirm();
|
||||
} else {
|
||||
// 已经有回显的签名
|
||||
if (!signatureServerPath.value) {
|
||||
// 已经有回显的签名(云端或本地草稿)
|
||||
if (!signatureServerPath.value && !signatureLocalPath.value) {
|
||||
uni.showToast({
|
||||
title: '请进行电子签名',
|
||||
icon: 'none'
|
||||
@@ -289,7 +419,18 @@
|
||||
}
|
||||
isSubmitting.value = true;
|
||||
uni.showLoading({ title: '正在提交...', mask: true });
|
||||
await executeSubmit();
|
||||
try {
|
||||
if (!signatureServerPath.value && signatureLocalPath.value) {
|
||||
const { url } = await uploadToCloud(signatureLocalPath.value);
|
||||
applySignatureFromServer(url);
|
||||
}
|
||||
await executeSubmit();
|
||||
} catch (err) {
|
||||
isSubmitting.value = false;
|
||||
uni.hideLoading();
|
||||
console.error('签名上传失败:', err);
|
||||
uni.showToast({ title: '签名上传失败,请重试', icon: 'none' });
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -350,148 +491,47 @@
|
||||
}
|
||||
});
|
||||
|
||||
// 电子签名画布手写线条变动回调
|
||||
const onSignatureChange = () => {
|
||||
// 电子签名:手写过程中自动导出本地预览图写入草稿
|
||||
const onSignatureStart = () => {
|
||||
isSignatureEmpty.value = false;
|
||||
signaturePaths.value = [];
|
||||
if (rectifyId.value) {
|
||||
saveDraft();
|
||||
}
|
||||
};
|
||||
|
||||
// 保存草稿
|
||||
const saveDraft = () => {
|
||||
if (isRestoring.value || !isInitialized.value) return;
|
||||
const key = getDraftKey();
|
||||
const hasContent = formData.verifyRemark ||
|
||||
fileList1.value.length > 0 ||
|
||||
signatureServerPath.value ||
|
||||
signaturePaths.value.length > 0;
|
||||
if (!hasContent) {
|
||||
uni.removeStorageSync(key);
|
||||
hasDraft.value = false;
|
||||
return;
|
||||
}
|
||||
|
||||
const data = {
|
||||
formData: {
|
||||
result: formData.result,
|
||||
verifyRemark: formData.verifyRemark
|
||||
},
|
||||
fileList1: fileList1.value,
|
||||
signatureServerPath: signatureServerPath.value,
|
||||
signatureUrl: signatureUrl.value,
|
||||
showCanvas: showCanvas.value,
|
||||
signaturePaths: signaturePaths.value
|
||||
};
|
||||
uni.setStorageSync(key, JSON.stringify(data));
|
||||
hasDraft.value = true;
|
||||
const onSignatureSigning = () => {
|
||||
isSignatureEmpty.value = false;
|
||||
};
|
||||
|
||||
// 清空草稿
|
||||
const clearDraft = (showToast = true) => {
|
||||
const key = getDraftKey();
|
||||
uni.removeStorageSync(key);
|
||||
hasDraft.value = false;
|
||||
showRestoreBanner.value = false;
|
||||
|
||||
isRestoring.value = true;
|
||||
formData.result = 1;
|
||||
formData.verifyRemark = '';
|
||||
fileList1.value = [];
|
||||
signatureServerPath.value = '';
|
||||
signatureUrl.value = '';
|
||||
showCanvas.value = true;
|
||||
signaturePaths.value = [];
|
||||
if (signatureRef.value) {
|
||||
signatureRef.value.clear();
|
||||
}
|
||||
|
||||
nextTick(() => {
|
||||
isRestoring.value = false;
|
||||
});
|
||||
if (showToast) {
|
||||
uni.showToast({ title: '草稿已清空', icon: 'none' });
|
||||
}
|
||||
const onSignatureClear = () => {
|
||||
isSignatureEmpty.value = true;
|
||||
signatureLocalPath.value = '';
|
||||
};
|
||||
|
||||
// 恢复草稿
|
||||
const restoreDraft = () => {
|
||||
const key = getDraftKey();
|
||||
const cached = uni.getStorageSync(key);
|
||||
if (cached) {
|
||||
try {
|
||||
const data = JSON.parse(cached);
|
||||
const hasContent = data.formData.verifyRemark ||
|
||||
(data.fileList1 && data.fileList1.length > 0) ||
|
||||
data.signatureServerPath ||
|
||||
(data.signaturePaths && data.signaturePaths.length > 0);
|
||||
if (!hasContent) {
|
||||
isInitialized.value = true;
|
||||
return;
|
||||
}
|
||||
|
||||
isRestoring.value = true;
|
||||
formData.result = data.formData.result !== undefined ? data.formData.result : 1;
|
||||
formData.verifyRemark = data.formData.verifyRemark || '';
|
||||
fileList1.value = data.fileList1 || [];
|
||||
signatureServerPath.value = data.signatureServerPath || '';
|
||||
signatureUrl.value = data.signatureUrl || '';
|
||||
showCanvas.value = data.showCanvas !== undefined ? data.showCanvas : true;
|
||||
signaturePaths.value = data.signaturePaths || [];
|
||||
hasDraft.value = true;
|
||||
showRestoreBanner.value = true;
|
||||
|
||||
// 延迟恢复签名画布线条重绘
|
||||
if (signaturePaths.value.length > 0) {
|
||||
setTimeout(() => {
|
||||
if (signatureRef.value) {
|
||||
isSignatureEmpty.value = false;
|
||||
// wot-design-uni auto rendering
|
||||
}
|
||||
}, 450);
|
||||
}
|
||||
|
||||
nextTick(() => {
|
||||
isRestoring.value = false;
|
||||
isInitialized.value = true;
|
||||
});
|
||||
|
||||
uni.showToast({
|
||||
title: '已自动恢复您上次未提交的内容',
|
||||
icon: 'none',
|
||||
duration: 2500
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('解析草稿失败:', e);
|
||||
isRestoring.value = false;
|
||||
isInitialized.value = true;
|
||||
const scheduleSignatureDraftExport = () => {
|
||||
clearTimeout(signatureExportTimer);
|
||||
signatureExportTimer = setTimeout(() => {
|
||||
if (
|
||||
!showCanvas.value ||
|
||||
isSignatureEmpty.value ||
|
||||
!signatureRef.value ||
|
||||
isSubmitting.value ||
|
||||
isDraftExporting.value
|
||||
) {
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
isInitialized.value = true;
|
||||
}
|
||||
isDraftExporting.value = true;
|
||||
signatureRef.value.confirm();
|
||||
}, 600);
|
||||
};
|
||||
|
||||
// 深度监听验收项和签名笔画变化,自动保存草稿
|
||||
watch(
|
||||
() => [
|
||||
formData.result,
|
||||
formData.verifyRemark,
|
||||
fileList1.value,
|
||||
signatureServerPath.value,
|
||||
signaturePaths.value
|
||||
],
|
||||
() => {
|
||||
if (rectifyId.value) {
|
||||
saveDraft();
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
const onSignatureEnd = () => {
|
||||
isSignatureEmpty.value = false;
|
||||
scheduleSignatureDraftExport();
|
||||
};
|
||||
|
||||
// 清除画布
|
||||
const clearSignature = () => {
|
||||
clearTimeout(signatureExportTimer);
|
||||
isSignatureEmpty.value = true;
|
||||
signatureLocalPath.value = '';
|
||||
if (signatureRef.value) {
|
||||
signatureRef.value.clear();
|
||||
}
|
||||
@@ -499,10 +539,12 @@
|
||||
|
||||
// 重新签字
|
||||
const reSign = () => {
|
||||
clearTimeout(signatureExportTimer);
|
||||
isSignatureEmpty.value = true;
|
||||
showCanvas.value = true;
|
||||
signatureUrl.value = '';
|
||||
signatureServerPath.value = '';
|
||||
signatureLocalPath.value = '';
|
||||
nextTick(() => {
|
||||
if (signatureRef.value) {
|
||||
signatureRef.value.clear();
|
||||
@@ -520,12 +562,17 @@
|
||||
|
||||
// 签名导出成功回调
|
||||
const onSignatureConfirm = async (tempFilePath) => {
|
||||
if (isDraftExporting.value) {
|
||||
isDraftExporting.value = false;
|
||||
applySignatureFromLocal(tempFilePath);
|
||||
saveDraft();
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
const { url } = await uploadToCloud(tempFilePath);
|
||||
signatureServerPath.value = url;
|
||||
signatureUrl.value = url;
|
||||
showCanvas.value = false;
|
||||
isSignatureEmpty.value = false;
|
||||
applySignatureFromServer(url);
|
||||
saveDraft();
|
||||
|
||||
if (isSubmitting.value) {
|
||||
await executeSubmit();
|
||||
@@ -538,6 +585,14 @@
|
||||
}
|
||||
};
|
||||
|
||||
onHide(() => {
|
||||
if (showCanvas.value && !isSignatureEmpty.value && signatureRef.value && !isDraftExporting.value) {
|
||||
isDraftExporting.value = true;
|
||||
signatureRef.value.confirm();
|
||||
}
|
||||
saveDraft();
|
||||
});
|
||||
|
||||
onLoad((options) => {
|
||||
// 计算签名画布宽度
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user