这一版本优化了很多
This commit is contained in:
@@ -2,15 +2,18 @@
|
||||
const common_vendor = require("../../common/vendor.js");
|
||||
const request_api = require("../../request/api.js");
|
||||
const request_request = require("../../request/request.js");
|
||||
const utils_watermark = require("../../utils/watermark.js");
|
||||
if (!Array) {
|
||||
const _easycom_up_textarea2 = common_vendor.resolveComponent("up-textarea");
|
||||
const _easycom_up_upload2 = common_vendor.resolveComponent("up-upload");
|
||||
(_easycom_up_textarea2 + _easycom_up_upload2)();
|
||||
const _easycom_wd_signature2 = common_vendor.resolveComponent("wd-signature");
|
||||
(_easycom_up_textarea2 + _easycom_up_upload2 + _easycom_wd_signature2)();
|
||||
}
|
||||
const _easycom_up_textarea = () => "../../uni_modules/uview-plus/components/u-textarea/u-textarea.js";
|
||||
const _easycom_up_upload = () => "../../uni_modules/uview-plus/components/u-upload/u-upload.js";
|
||||
const _easycom_wd_signature = () => "../../node-modules/wot-design-uni/components/wd-signature/wd-signature.js";
|
||||
if (!Math) {
|
||||
(_easycom_up_textarea + _easycom_up_upload)();
|
||||
(_easycom_up_textarea + _easycom_up_upload + _easycom_wd_signature)();
|
||||
}
|
||||
const _sfc_main = {
|
||||
__name: "acceptance",
|
||||
@@ -30,6 +33,21 @@ const _sfc_main = {
|
||||
// 验收备注
|
||||
});
|
||||
const fileList1 = common_vendor.ref([]);
|
||||
const canvasWidth = common_vendor.ref(300);
|
||||
const canvasHeight = common_vendor.ref(300);
|
||||
const showCanvas = common_vendor.ref(true);
|
||||
const signatureUrl = common_vendor.ref("");
|
||||
const signatureServerPath = common_vendor.ref("");
|
||||
const signatureWidth = common_vendor.ref(340);
|
||||
const signatureRef = common_vendor.ref(null);
|
||||
const isSignatureEmpty = common_vendor.ref(true);
|
||||
const isSubmitting = common_vendor.ref(false);
|
||||
const hasDraft = common_vendor.ref(false);
|
||||
const showRestoreBanner = common_vendor.ref(false);
|
||||
const isRestoring = common_vendor.ref(false);
|
||||
const isInitialized = common_vendor.ref(false);
|
||||
const signaturePaths = common_vendor.ref([]);
|
||||
const getDraftKey = () => `draft_accept_${rectifyId.value || ""}`;
|
||||
const getFullPath = (filePath) => {
|
||||
if (!filePath)
|
||||
return "";
|
||||
@@ -59,15 +77,15 @@ const _sfc_main = {
|
||||
if (assign.rectify.attachments) {
|
||||
rectifyAttachments.value = assign.rectify.attachments;
|
||||
}
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:108", "整改记录:", rectifyData);
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:109", "整改附件:", rectifyAttachments.value);
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:167", "整改记录:", rectifyData);
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:168", "整改附件:", rectifyAttachments.value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
common_vendor.index.showToast({ title: res.msg || "获取详情失败", icon: "none" });
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:116", "获取隐患详情失败:", error);
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:175", "获取隐患详情失败:", error);
|
||||
common_vendor.index.showToast({ title: "请求失败", icon: "none" });
|
||||
}
|
||||
};
|
||||
@@ -81,7 +99,7 @@ const _sfc_main = {
|
||||
if (options.assignId) {
|
||||
assignId.value = options.assignId;
|
||||
}
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:131", "验收页面参数:", { rectifyId: rectifyId.value, hazardId: hazardId.value, assignId: assignId.value });
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:190", "验收页面参数:", { rectifyId: rectifyId.value, hazardId: hazardId.value, assignId: assignId.value });
|
||||
fetchDetail();
|
||||
});
|
||||
const handleCancel = () => {
|
||||
@@ -95,6 +113,31 @@ const _sfc_main = {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (showCanvas.value) {
|
||||
if (!signatureRef.value || isSignatureEmpty.value) {
|
||||
common_vendor.index.showToast({
|
||||
title: "请进行电子签名",
|
||||
icon: "none"
|
||||
});
|
||||
return;
|
||||
}
|
||||
isSubmitting.value = true;
|
||||
common_vendor.index.showLoading({ title: "正在提交...", mask: true });
|
||||
signatureRef.value.confirm();
|
||||
} else {
|
||||
if (!signatureServerPath.value) {
|
||||
common_vendor.index.showToast({
|
||||
title: "请进行电子签名",
|
||||
icon: "none"
|
||||
});
|
||||
return;
|
||||
}
|
||||
isSubmitting.value = true;
|
||||
common_vendor.index.showLoading({ title: "正在提交...", mask: true });
|
||||
await executeSubmit();
|
||||
}
|
||||
};
|
||||
const executeSubmit = async () => {
|
||||
const attachments = fileList1.value.map((file) => {
|
||||
let url = "";
|
||||
if (typeof file.url === "string") {
|
||||
@@ -102,6 +145,9 @@ const _sfc_main = {
|
||||
} 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(request_request.imageBaseUrl, "");
|
||||
}
|
||||
const fileName = typeof url === "string" && url ? url.split("/").pop() : file.name || "";
|
||||
return {
|
||||
fileName: fileName || "",
|
||||
@@ -114,12 +160,16 @@ const _sfc_main = {
|
||||
rectifyId: Number(rectifyId.value),
|
||||
result: formData.result,
|
||||
verifyRemark: formData.verifyRemark || "",
|
||||
attachments
|
||||
attachments,
|
||||
signPath: signatureServerPath.value || ""
|
||||
// 电子签名路径
|
||||
};
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:176", "提交验收参数:", params);
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:271", "提交验收参数:", params);
|
||||
try {
|
||||
const res = await request_api.acceptanceRectification(params);
|
||||
common_vendor.index.hideLoading();
|
||||
if (res.code === 0) {
|
||||
clearDraft(false);
|
||||
common_vendor.index.showToast({
|
||||
title: "验收成功",
|
||||
icon: "success"
|
||||
@@ -134,16 +184,29 @@ const _sfc_main = {
|
||||
});
|
||||
}
|
||||
} catch (error) {
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:195", "验收失败:", error);
|
||||
common_vendor.index.hideLoading();
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:293", "验收失败:", error);
|
||||
common_vendor.index.showToast({
|
||||
title: "请求失败",
|
||||
icon: "none"
|
||||
});
|
||||
} finally {
|
||||
isSubmitting.value = false;
|
||||
}
|
||||
};
|
||||
const deletePic = (event) => {
|
||||
fileList1.value.splice(event.index, 1);
|
||||
};
|
||||
const addWatermark = (tempFilePath) => {
|
||||
const instance = common_vendor.getCurrentInstance();
|
||||
return utils_watermark.addTimestampWatermark({
|
||||
tempFilePath,
|
||||
canvasId: "watermarkCanvas",
|
||||
canvasWidthRef: canvasWidth,
|
||||
canvasHeightRef: canvasHeight,
|
||||
instance
|
||||
});
|
||||
};
|
||||
const afterRead = async (event) => {
|
||||
let lists = [].concat(event.file);
|
||||
let fileListLen = fileList1.value.length;
|
||||
@@ -151,18 +214,29 @@ const _sfc_main = {
|
||||
fileList1.value.push({
|
||||
...item,
|
||||
status: "uploading",
|
||||
message: "上传中"
|
||||
message: "处理中..."
|
||||
});
|
||||
});
|
||||
for (let i = 0; i < lists.length; i++) {
|
||||
const result = await uploadFilePromise(lists[i].url);
|
||||
let item = fileList1.value[fileListLen];
|
||||
fileList1.value.splice(fileListLen, 1, {
|
||||
...item,
|
||||
status: "success",
|
||||
message: "",
|
||||
url: result
|
||||
});
|
||||
try {
|
||||
const watermarkedUrl = await addWatermark(lists[i].url);
|
||||
const result = await uploadFilePromise(watermarkedUrl);
|
||||
let item = fileList1.value[fileListLen];
|
||||
fileList1.value.splice(fileListLen, 1, {
|
||||
...item,
|
||||
status: "success",
|
||||
message: "",
|
||||
url: request_request.toImageUrl(result.url || result.filePath || result)
|
||||
});
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:352", "加水印或上传失败:", e);
|
||||
let item = fileList1.value[fileListLen];
|
||||
fileList1.value.splice(fileListLen, 1, {
|
||||
...item,
|
||||
status: "failed",
|
||||
message: "处理失败"
|
||||
});
|
||||
}
|
||||
fileListLen++;
|
||||
}
|
||||
};
|
||||
@@ -184,12 +258,173 @@ const _sfc_main = {
|
||||
}
|
||||
},
|
||||
fail: (err) => {
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:250", "上传失败:", err);
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:382", "上传失败:", err);
|
||||
reject(err);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
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) {
|
||||
common_vendor.index.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
|
||||
};
|
||||
common_vendor.index.setStorageSync(key, JSON.stringify(data));
|
||||
hasDraft.value = true;
|
||||
};
|
||||
const clearDraft = (showToast = true) => {
|
||||
const key = getDraftKey();
|
||||
common_vendor.index.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();
|
||||
}
|
||||
common_vendor.nextTick$1(() => {
|
||||
isRestoring.value = false;
|
||||
});
|
||||
if (showToast) {
|
||||
common_vendor.index.showToast({ title: "草稿已清空", icon: "none" });
|
||||
}
|
||||
};
|
||||
const restoreDraft = () => {
|
||||
const key = getDraftKey();
|
||||
const cached = common_vendor.index.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 !== void 0 ? 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 !== void 0 ? 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;
|
||||
}
|
||||
}, 450);
|
||||
}
|
||||
common_vendor.nextTick$1(() => {
|
||||
isRestoring.value = false;
|
||||
isInitialized.value = true;
|
||||
});
|
||||
common_vendor.index.showToast({
|
||||
title: "已自动恢复您上次未提交的内容",
|
||||
icon: "none",
|
||||
duration: 2500
|
||||
});
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:502", "解析草稿失败:", e);
|
||||
isRestoring.value = false;
|
||||
isInitialized.value = true;
|
||||
}
|
||||
} else {
|
||||
isInitialized.value = true;
|
||||
}
|
||||
};
|
||||
common_vendor.watch(
|
||||
() => [
|
||||
formData.result,
|
||||
formData.verifyRemark,
|
||||
fileList1.value,
|
||||
signatureServerPath.value,
|
||||
signaturePaths.value
|
||||
],
|
||||
() => {
|
||||
if (rectifyId.value) {
|
||||
saveDraft();
|
||||
}
|
||||
},
|
||||
{ deep: true }
|
||||
);
|
||||
const clearSignature = () => {
|
||||
isSignatureEmpty.value = true;
|
||||
if (signatureRef.value) {
|
||||
signatureRef.value.clear();
|
||||
}
|
||||
};
|
||||
const reSign = () => {
|
||||
isSignatureEmpty.value = true;
|
||||
showCanvas.value = true;
|
||||
signatureUrl.value = "";
|
||||
signatureServerPath.value = "";
|
||||
common_vendor.nextTick$1(() => {
|
||||
if (signatureRef.value) {
|
||||
signatureRef.value.clear();
|
||||
}
|
||||
});
|
||||
};
|
||||
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 : request_request.baseUrl.replace("/api", "") + path;
|
||||
if (isSubmitting.value) {
|
||||
await executeSubmit();
|
||||
}
|
||||
} catch (err) {
|
||||
isSubmitting.value = false;
|
||||
common_vendor.index.hideLoading();
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:573", "签名上传失败:", err);
|
||||
common_vendor.index.showToast({ title: "签名上传失败,请重试", icon: "none" });
|
||||
}
|
||||
};
|
||||
common_vendor.onLoad((options) => {
|
||||
try {
|
||||
const sysInfo = common_vendor.index.getSystemInfoSync();
|
||||
signatureWidth.value = sysInfo.windowWidth - 40;
|
||||
} catch (e) {
|
||||
common_vendor.index.__f__("error", "at pages/hiddendanger/acceptance.vue:584", "获取系统信息失败:", e);
|
||||
}
|
||||
if (options.rectifyId) {
|
||||
rectifyId.value = options.rectifyId;
|
||||
}
|
||||
if (options.hazardId) {
|
||||
hazardId.value = options.hazardId;
|
||||
}
|
||||
if (options.assignId) {
|
||||
assignId.value = options.assignId;
|
||||
}
|
||||
common_vendor.index.__f__("log", "at pages/hiddendanger/acceptance.vue:595", "验收页面参数:", { rectifyId: rectifyId.value, hazardId: hazardId.value, assignId: assignId.value });
|
||||
fetchDetail();
|
||||
restoreDraft();
|
||||
});
|
||||
return (_ctx, _cache) => {
|
||||
return common_vendor.e({
|
||||
a: common_vendor.t(rectifyData.rectifyPlan || "暂无"),
|
||||
@@ -219,11 +454,44 @@ const _sfc_main = {
|
||||
fileList: fileList1.value,
|
||||
name: "1",
|
||||
multiple: true,
|
||||
imageMode: "aspectFill",
|
||||
maxCount: 10
|
||||
}),
|
||||
n: common_vendor.o(handleCancel),
|
||||
o: common_vendor.o(handleSubmit),
|
||||
p: common_vendor.gei(_ctx, "")
|
||||
n: canvasWidth.value,
|
||||
o: canvasHeight.value,
|
||||
p: canvasWidth.value + "px",
|
||||
q: canvasHeight.value + "px",
|
||||
r: showCanvas.value
|
||||
}, showCanvas.value ? {
|
||||
s: common_vendor.o(clearSignature)
|
||||
} : {
|
||||
t: common_vendor.o(reSign)
|
||||
}, {
|
||||
v: !showCanvas.value
|
||||
}, !showCanvas.value ? {
|
||||
w: signatureUrl.value
|
||||
} : {}, {
|
||||
x: showCanvas.value
|
||||
}, showCanvas.value ? {
|
||||
y: common_vendor.sr(signatureRef, "39f9b795-2", {
|
||||
"k": "signatureRef"
|
||||
}),
|
||||
z: common_vendor.o((res) => onSignatureConfirm(res.tempFilePath)),
|
||||
A: common_vendor.o(($event) => isSignatureEmpty.value = false),
|
||||
B: common_vendor.o(($event) => isSignatureEmpty.value = false),
|
||||
C: common_vendor.o(($event) => isSignatureEmpty.value = true),
|
||||
D: common_vendor.p({
|
||||
width: signatureWidth.value,
|
||||
height: 160,
|
||||
backgroundColor: "#f8f8f8",
|
||||
penColor: "#000000",
|
||||
lineWidth: 3,
|
||||
enableHistory: false
|
||||
})
|
||||
} : {}, {
|
||||
E: common_vendor.o(handleCancel),
|
||||
F: common_vendor.o(handleSubmit),
|
||||
G: common_vendor.gei(_ctx, "")
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user