Commit 2f961453 authored by 罗超's avatar 罗超

修复ERP 无法使用加密函数问题

parent c9a3731b
......@@ -195,33 +195,29 @@ const insertImageElement = async (files: FileList) => {
text:'正在上传图',
lock:true
})
let hash =''
try{
hash = await calculateFileHash(files[0])
}catch(error){}
if(!hash || hash=='') {
ElMessage.error({message:'文件校验失败,请重试'})
loadingObj.close()
return;
const hash = await calculateFileHash(files[0])
if(hash!='') {
await checkedUploadFileExsit(files[0],hash)
}else{
await uoloadFileToService(files[0])
}
loadingObj.close()
}
const checkedUploadFileExsit = async (file:File,hash:any)=>{
let parms = {
fname: files[0].name,
fname: file.name,
gid: queryObj.CloudGroupId,
hi: hash
}
let dataRes = await CloudDiskService.CheckCloudInfo(parms)
const dataRes = await CloudDiskService.CheckCloudInfo(parms)
if (dataRes.data.resultCode==ApiResult.SUCCESS) {
queryObj.CloudGroupId = ''
queryObj.FileName = dataRes.data.data.SourceFileName
Search()
}else{
//TODO: 实现校验HASH值是否存在,如果不存在,才调用下面的这个方法。
if(dataRes.data.message=='不存在此文件!') await uoloadFileToService(files[0])
} else {
if(dataRes.data.message=='不存在此文件!') await uoloadFileToService(file)
}
// await uoloadFileToService(files[0])
loadingObj.close()
}
const uoloadFileToService = async (file:File)=>{
let parms = {
isppt: '1',
......@@ -239,15 +235,19 @@ const calculateFileHash = (file:File, algorithm = 'SHA-256') => {
reader.onload = (event) => {
if(event && event.target && event.target.result){
const buffer:any = event.target.result;
crypto.subtle.digest(algorithm, buffer)
.then(hashBuffer => {
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
resolve(hashHex);
})
.catch(error => reject(error));
if(crypto && crypto.subtle && crypto.subtle.digest){
crypto.subtle.digest(algorithm, buffer)
.then(hashBuffer => {
const hashArray = Array.from(new Uint8Array(hashBuffer));
const hashHex = hashArray.map(b => b.toString(16).padStart(2, '0')).join('');
resolve(hashHex);
})
.catch(error => resolve(''));
}else{
resolve('')
}
}else{
reject('')
resolve('')
}
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment