Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
X
xxx_phase2_web
Project overview
Project overview
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
夏敏伟
xxx_phase2_web
Commits
3078b2e4
Commit
3078b2e4
authored
Dec 04, 2023
by
以墨为白
🎧
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
单文件上传的优化
parent
16fc2df3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
29 deletions
+40
-29
src/util/file_md5.js
src/util/file_md5.js
+15
-16
src/view/sjgl/wxk_public.vue
src/view/sjgl/wxk_public.vue
+25
-13
No files found.
src/util/file_md5.js
View file @
3078b2e4
...
@@ -19,21 +19,8 @@ var fileMd5Sum = (file) => {
...
@@ -19,21 +19,8 @@ var fileMd5Sum = (file) => {
});
});
}
}
const
getFileChunk
=
(
file
,
chunkSize
)
=>
{
const
chunks
=
[];
const
fileSize
=
file
.
size
;
let
currentChunkStart
=
0
;
while
(
currentChunkStart
<
fileSize
)
{
const
chunkEnd
=
currentChunkStart
+
chunkSize
;
const
chunk
=
file
.
slice
(
currentChunkStart
,
chunkEnd
);
chunks
.
push
(
chunk
);
currentChunkStart
=
chunkEnd
;
}
console
.
log
(
"
分片数量
"
+
chunks
.
length
);
return
chunks
;
};
const
getFileMD5
=
file
=>
{
const
getFileMD5
Progress
=
(
file
,
progress
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
return
new
Promise
((
resolve
,
reject
)
=>
{
const
chunkSize
=
2097152
;
// 每次读取2MB.
const
chunkSize
=
2097152
;
// 每次读取2MB.
const
chunks
=
getFileChunk
(
file
,
chunkSize
);
const
chunks
=
getFileChunk
(
file
,
chunkSize
);
...
@@ -42,7 +29,7 @@ const getFileMD5 = file => {
...
@@ -42,7 +29,7 @@ const getFileMD5 = file => {
const
loadNext
=
()
=>
{
const
loadNext
=
()
=>
{
const
reader
=
new
FileReader
();
const
reader
=
new
FileReader
();
reader
.
onload
=
e
=>
{
reader
.
onload
=
e
=>
{
console
.
log
(
currentChunkIndex
);
progress
&&
progress
(
Math
.
round
(
currentChunkIndex
/
chunks
.
length
*
100
)
+
"
%
"
);
currentChunkIndex
++
;
currentChunkIndex
++
;
spark
.
append
(
e
.
target
.
result
);
spark
.
append
(
e
.
target
.
result
);
if
(
currentChunkIndex
<
chunks
.
length
)
{
if
(
currentChunkIndex
<
chunks
.
length
)
{
...
@@ -58,8 +45,20 @@ const getFileMD5 = file => {
...
@@ -58,8 +45,20 @@ const getFileMD5 = file => {
});
});
};
};
const
getFileChunk
=
(
file
,
chunkSize
)
=>
{
const
chunks
=
[];
const
fileSize
=
file
.
size
;
let
currentChunkStart
=
0
;
while
(
currentChunkStart
<
fileSize
)
{
const
chunkEnd
=
currentChunkStart
+
chunkSize
;
const
chunk
=
file
.
slice
(
currentChunkStart
,
chunkEnd
);
chunks
.
push
(
chunk
);
currentChunkStart
=
chunkEnd
;
}
return
chunks
;
};
export
{
export
{
fileMd5Sum
,
fileMd5Sum
,
getFileMD5
getFileMD5
Progress
}
}
src/view/sjgl/wxk_public.vue
View file @
3078b2e4
...
@@ -299,7 +299,7 @@ import {
...
@@ -299,7 +299,7 @@ import {
}
from
"
../../util/http_util
"
;
}
from
"
../../util/http_util
"
;
import
{
uuid
}
from
"
../../util/data_util
"
;
import
{
uuid
}
from
"
../../util/data_util
"
;
import
BigfileUpload
from
"
../../components/common/bigfile_upload.vue
"
;
import
BigfileUpload
from
"
../../components/common/bigfile_upload.vue
"
;
import
{
fileMd5Sum
,
getFileMD5
}
from
'
../../util/file_md5.js
'
;
import
{
fileMd5Sum
,
getFileMD5Progress
}
from
'
../../util/file_md5.js
'
;
export
default
{
export
default
{
data
()
{
data
()
{
...
@@ -757,21 +757,33 @@ export default {
...
@@ -757,21 +757,33 @@ export default {
module
:
this
.
module_name
module
:
this
.
module_name
};
};
//单个文件上传
let
load
=
startLoadingProgress
(
"
0%
"
);
let
load
=
startLoadingProgress
(
"
0%
"
);
let
self
=
this
;
let
self
=
this
;
this
.
centerDialogVisible_add
=
false
;
this
.
centerDialogVisible_add
=
false
;
load
.
text
=
""
;
let
fd
=
new
FormData
();
let
md5
=
""
;
load
.
text
=
"
解析中
"
;
let
file
=
null
;
getFileMD5
(
this
.
form_add
.
fileList
[
0
].
raw
)
//获取md5
//获取md5
getFileMD5Progress
(
this
.
form_add
.
fileList
[
0
].
raw
,
(
progress
)
=>
{
load
.
text
=
"
解析中:
"
+
progress
;
}).
then
(
res
=>
{
md5
=
res
.
md5
;
file
=
res
.
file
;
return
this
.
checkFileExist
(
md5
);
//检查文件是否存在
})
.
then
(
result
=>
{
.
then
(
result
=>
{
fd
.
append
(
"
file
"
,
result
.
file
);
if
(
!
result
)
{
fd
.
append
(
"
filename
"
,
result
.
md5
);
let
fd
=
new
FormData
();
fd
.
append
(
"
file
"
,
file
);
fd
.
append
(
"
filename
"
,
md5
);
fd
.
append
(
"
bucket
"
,
"
MERGE
"
);
fd
.
append
(
"
bucket
"
,
"
MERGE
"
);
return
fileUploadProgress
(
"
api/rest/file/upload
"
,
fd
,
res
=>
{
//文件上传
return
fileUploadProgress
(
"
api/rest/file/upload
"
,
fd
,
res
=>
{
//文件上传
load
.
text
=
"
上传中:
"
+
res
;
load
.
text
=
"
上传中:
"
+
res
;
});
});
}
else
{
return
Promise
.
reject
({
message
:
"
文件已存在
"
});
}
})
})
.
then
(
res
=>
{
.
then
(
res
=>
{
let
fd1
=
new
FormData
();
let
fd1
=
new
FormData
();
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment