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

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

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