Commit 671b2868 authored by 罗超's avatar 罗超

文件上传优化

parent dfeb0679
...@@ -687,6 +687,7 @@ page { ...@@ -687,6 +687,7 @@ page {
font-weight: bold; font-weight: bold;
background-color: #f1f2f4 !important; background-color: #f1f2f4 !important;
border-color: #f1f2f4 !important; border-color: #f1f2f4 !important;
font-family: pingfangr;
} }
.md-menu .el-menu-item:hover, .md-menu .el-menu-item:hover,
.md-menu .el-sub-menu .el-menu-item:hover, .md-menu .el-sub-menu .el-menu-item:hover,
......
...@@ -52,7 +52,7 @@ ...@@ -52,7 +52,7 @@
<FileInput @change="files => insertImageElement(files)"> <FileInput @change="files => insertImageElement(files)">
<div class="CloudDisk-R-Box"> <div class="CloudDisk-R-Box">
<div class="CloudDisk-R-Plus column items-center cusor-pointer"> <div class="CloudDisk-R-Plus column items-center cusor-pointer">
<el-icon class="el-input__icon" color="#CECECE" size="30px" title=""> <el-icon class="el-input__icon" size="30px" title="">
<Plus/> <Plus/>
</el-icon> </el-icon>
<span>添加图片</span> <span>添加图片</span>
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
<div class="CloudDisk-R-Box cursor-pointer" <div class="CloudDisk-R-Box cursor-pointer"
:class="[ImgId==item.DetailsId?'active':'active2']" @click="setImg(item)"> :class="[ImgId==item.DetailsId?'active':'active2']" @click="setImg(item)">
<div class="CloudDisk-R-Img"> <div class="CloudDisk-R-Img">
<el-image :src="item.FilePath" style="width: 80px; height: 80px;" <el-image :src="item.FilePath" style="width: 100%; height: 100%;"
fit="cover"/> fit="cover"/>
<!-- <el-image <!-- <el-image
style="width: 80px; height: 80px" style="width: 80px; height: 80px"
...@@ -130,7 +130,7 @@ ...@@ -130,7 +130,7 @@
import { Plus, Top, Bottom, Delete, Edit } from "@element-plus/icons-vue"; import { Plus, Top, Bottom, Delete, Edit } from "@element-plus/icons-vue";
import { reactive, ref, onMounted, watch} from "vue"; import { reactive, ref, onMounted, watch} from "vue";
import CloudDiskService from '@/services/CloudDiskService' import CloudDiskService from '@/services/CloudDiskService'
import { ElMessage } from "element-plus"; import { ElLoading, ElMessage, ElMessageBox } from "element-plus";
import FileInput from '@/components/FileInput.vue' import FileInput from '@/components/FileInput.vue'
import { getImageDataURL } from '@/utils/image' import { getImageDataURL } from '@/utils/image'
import AliyunUpload from '@/utils/upload/aliyun' import AliyunUpload from '@/utils/upload/aliyun'
...@@ -194,18 +194,50 @@ const insertImageElement = async (files: FileList) => { ...@@ -194,18 +194,50 @@ const insertImageElement = async (files: FileList) => {
text:'正在上传图', text:'正在上传图',
lock:true lock:true
}) })
const hash = await calculateFileHash(files[0])
if(!hash || hash=='') {
ElMessage.error({message:'文件校验失败,请重试'})
loadingObj.close()
return;
}
//TODO: 实现校验HASH值是否存在,如果不存在,才调用下面的这个方法。
await uoloadFileToService(files[0])
loadingObj.close()
}
const uoloadFileToService = async (file:File)=>{
let parms = { let parms = {
isppt: '1', isppt: '1',
uid: token.value, uid: token.value,
gid: queryObj.CloudGroupId gid: queryObj.CloudGroupId
} }
let filePath="tripImg/"; let filePath="tripImg/";
console.log("ssss"); let url = await AliyunUpload.UploadCloudDisk(file, filePath, parms);
let url = await AliyunUpload.UploadCloudDisk(files[0], filePath, parms);
if(url) Search() if(url) Search()
setTimeout(()=>{ }
loadingObj.close()
},300) const calculateFileHash = (file:File, algorithm = 'SHA-256') => {
return new Promise((resolve, reject) => {
const reader = new FileReader();
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));
}else{
reject('')
}
};
reader.onerror = reject;
reader.readAsArrayBuffer(file); // Read only the first 1MB of the file
});
} }
// 删除 // 删除
...@@ -313,7 +345,7 @@ const querySearchGroup = async () =>{ ...@@ -313,7 +345,7 @@ const querySearchGroup = async () =>{
const SearchImg = () =>{ const SearchImg = () =>{
if(queryObj.FileName=='') Search() if(queryObj.FileName=='') Search()
} }
const Search = (item:any) =>{ const Search = (item:any=null) =>{
if(item) { if(item) {
queryObj.CloudGroupId = item.Id queryObj.CloudGroupId = item.Id
GroupObj.value = item GroupObj.value = item
...@@ -441,16 +473,21 @@ onMounted(()=>{ ...@@ -441,16 +473,21 @@ onMounted(()=>{
width: 80px; width: 80px;
height: 80px; height: 80px;
border-radius: 8px; border-radius: 8px;
border: 2px dashed #000000; border: 2px dashed #CECECE;
color:#cecece;
}
.CloudDisk-R-Plus:hover{
border-color: #000000;
color:#000000;
} }
.CloudDisk-R-Plus .el-icon{ .CloudDisk-R-Plus .el-icon{
margin-top: 13px; margin-top: 13px;
} }
.CloudDisk-R-Plus span{ .CloudDisk-R-Plus span{
font-family: PingFang SC; // font-family: PingFang SC;
font-weight: 400; font-weight: 400;
font-size: 14px; font-size: 14px;
color: #000000; // color: #CECECE;
} }
.CloudDisk-R-Box{ .CloudDisk-R-Box{
width: 80px; width: 80px;
...@@ -464,10 +501,12 @@ onMounted(()=>{ ...@@ -464,10 +501,12 @@ onMounted(()=>{
margin-bottom: 9px; margin-bottom: 9px;
border-radius: 8px; border-radius: 8px;
overflow: hidden; overflow: hidden;
border:2px solid transparent;
} }
.CloudDisk-R-Img .el-image{ .CloudDisk-R-Img .el-image{
width: 76px; width: 76px;
} }
.title{ .title{
width: 80px; width: 80px;
...@@ -489,7 +528,7 @@ onMounted(()=>{ ...@@ -489,7 +528,7 @@ onMounted(()=>{
background: #8790F3; background: #8790F3;
box-shadow: 0px 0px 13px 0px #0D3EBC; box-shadow: 0px 0px 13px 0px #0D3EBC;
border-radius: 8px; border-radius: 8px;
border: 2px solid #3556F9; border-color:#3556F9;
} }
.CloudDisk-R-Box .close-btn{ .CloudDisk-R-Box .close-btn{
position: absolute; position: absolute;
......
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