系统设置-签名-功能完成

main
ysn 4 days ago
parent 907edbf56c
commit 6767c048f0
  1. 152
      src/layout/components/ESignatureDialog.vue

@ -359,43 +359,88 @@ export default {
}, },
// //
async uploadSignatureToServer(blob) { async uploadSignatureToServer(blob) {
// MinIO try {
await this.ensureMinioInitialized(); // MinIO
const config = this.$store.getters.config; await this.ensureMinioInitialized();
const config = this.$store.getters.config;
// MINIO_BUCKET_KERNEL/esign/_esign_.png
const bucket = config.MINIO_BUCKET_KERNEL || "remote-kernel-test"; // MINIO_BUCKET_KERNEL/esign/_esign_.png
const loginInfo = this.$store.state.user.loginInfo; const bucket = config.MINIO_BUCKET_KERNEL || "remote-kernel-test";
const username = loginInfo?.username || "unknown"; const loginInfo = this.$store.state.user.loginInfo;
const timestamp = Date.now(); const username = loginInfo?.username || "unknown";
const objectName = `esign/${username}_esign_${timestamp}.png`; const timestamp = Date.now();
const objectName = `esign/${username}_esign_${timestamp}.png`;
console.log(`Uploading signature to bucket: ${bucket}, object: ${objectName}`);
// 使 MinIO
const result = await uploadFile(
bucket,
objectName,
blob,
{},
(percent) => {}
);
console.log("MinIO 上传成功:", result);
// console.log(`[ESignature] Uploading signature to bucket: ${bucket}, object: ${objectName}`);
const signature = `${bucket}/${result.objectName}`; console.log(`[ESignature] Blob size: ${blob.size} bytes, type: ${blob.type}`);
// // 使 MinIO
const signHash = await this.calculateFileHash(blob); const result = await uploadFile(
bucket,
objectName,
blob,
{},
(percent) => {}
);
console.log("[ESignature] MinIO 上传成功:", result);
//
const signature = `${bucket}/${result.objectName}`;
console.log("[ESignature] Signature path:", signature);
//
let signHash = '';
try {
signHash = await this.calculateFileHash(blob);
console.log("[ESignature] Sign hash:", signHash);
} catch (hashError) {
console.warn("[ESignature] Failed to calculate hash, using fallback:", hashError.message);
signHash = signature; // 使退
}
// //
await postUpdateOpsSignatureUpdate({ console.log("[ESignature] Calling update signature API...");
signature: signature, let apiResult = null;
sign_hash: signHash, try {
}); apiResult = await postUpdateOpsSignatureUpdate({
signature: signature,
sign_hash: signHash,
});
console.log("[ESignature] API 调用成功:", apiResult);
} catch (apiError) {
console.error("[ESignature] API 调用失败:", apiError);
// API
console.warn("[ESignature] File uploaded but API failed, updating local state only");
// loginInfo
this.updateLoginInfoSignature(signature);
// API
throw new Error("签名上传失败:文件已上传但更新接口调用失败,请联系管理员");
}
// loginInfo // loginInfo
this.updateLoginInfoSignature(signature); this.updateLoginInfoSignature(signature);
console.log("[ESignature] LoginInfo updated successfully");
} catch (error) {
console.error("[ESignature] 签名上传失败:", error);
console.error("[ESignature] 错误详情:", error.stack);
//
let errorMessage = "签名上传失败";
if (error.message) {
if (error.message.includes('MinIO client not initialized')) {
errorMessage = "签名上传失败:文件服务器客户端未初始化";
} else if (error.message.includes('Network error')) {
errorMessage = "签名上传失败:网络连接异常,请检查网络";
} else if (error.message.includes('CORS')) {
errorMessage = "签名上传失败:跨域限制,请联系管理员";
} else {
errorMessage = "签名上传失败:" + error.message;
}
}
throw new Error(errorMessage);
}
}, },
// loginInfo // loginInfo
updateLoginInfoSignature(signature) { updateLoginInfoSignature(signature) {
@ -414,11 +459,42 @@ export default {
}, },
// SHA-256 // SHA-256
async calculateFileHash(blob) { async calculateFileHash(blob) {
const arrayBuffer = await blob.arrayBuffer(); try {
const hashBuffer = await crypto.subtle.digest("SHA-256", arrayBuffer); const arrayBuffer = await blob.arrayBuffer();
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join(""); // crypto.subtle HTTPS
return hashHex; if (typeof crypto !== 'undefined' && crypto.subtle) {
const hashBuffer = await crypto.subtle.digest("SHA-256", arrayBuffer);
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map((b) => b.toString(16).padStart(2, "0")).join("");
console.log("[ESignature] Hash calculated using crypto.subtle:", hashHex);
return hashHex;
} else {
// 退使
console.warn("[ESignature] crypto.subtle not available, using fallback hash");
return this.fallbackHash(arrayBuffer);
}
} catch (error) {
console.error("[ESignature] Failed to calculate hash:", error);
// 退
return this.fallbackHash(await blob.arrayBuffer());
}
},
// 退 crypto.subtle 使
fallbackHash(arrayBuffer) {
const bytes = new Uint8Array(arrayBuffer);
let hash = 0;
for (let i = 0; i < bytes.length; i++) {
hash = ((hash << 5) - hash) + bytes[i];
hash = hash & hash; // Convert to 32bit integer
}
// SHA-256
const timestamp = Date.now().toString(16);
const size = arrayBuffer.byteLength.toString(16);
const hashStr = Math.abs(hash).toString(16).padStart(8, '0');
// 64
return (timestamp + size + hashStr).padEnd(64, '0').substring(0, 64);
}, },
handleClose() { handleClose() {

Loading…
Cancel
Save