Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Hooke
/
data-table
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Authored by
hookehuyr
2022-12-02 11:11:00 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
33bdfa249f5e8969acf42a32445d88d5d1129d1a
33bdfa24
1 parent
fd30b848
图片算法改成md5
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
7 deletions
src/components/ImageUploaderField/index.vue
src/components/ImageUploaderField/index.vue
View file @
33bdfa2
...
...
@@ -18,7 +18,7 @@
:after-read="afterRead"
:before-delete="beforeDelete"
v-model="fileList"
:multiple="
item.component_props.multipl
e"
:multiple="
tru
e"
/>
</div>
<div class="type-text">上传格式:{{ type_text }}</div>
...
...
@@ -133,20 +133,37 @@ const uploadQiniu = async (file, token, filename) => {
const handleUpload = async (files) => {
// 上传图片流程
loading.value = true;
// let imgUrl = "";
// 获取HASH值
const hash = getEtag(files.content);
// const hash = getEtag(files.content);
return new Promise((resolve, reject) => {
// 获取MD5值
const bmf = new BMF();
bmf.md5(
files.file,
async (err, md5) => {
if (err) {
console.log(err);
reject(err);
}
// 获取七牛token
const filename =
"uploadForm/" + formCode + "/" + uuid() + "." + files.file.name.split(".")[1];
const { token, key, code } = await qiniuTokenAPI({
name: filename,
hash
,
hash: md5
,
});
// 文件上传七牛云
files.status = "uploading";
files.message = "上传中...";
const imgUrl = await uploadQiniu(files.file, token, filename);
return { imgUrl };
resolve(imgUrl);
},
(process) => {
//计算进度
}
);
});
};
// 多选图片上传遍历
...
...
@@ -154,7 +171,7 @@ var muliUpload = async (files) => {
for (let item of files) {
const res = await handleUpload(item);
// 上传失败提示
if (!res.
imgUrl.
src) {
if (!res.src) {
item.status = "failed";
item.message = "上传失败";
loading.value = false;
...
...
@@ -162,7 +179,7 @@ var muliUpload = async (files) => {
item.status = "";
item.message = "";
fileList.value.push({
url: res.
imgUrl.
src,
url: res.src,
isImage: true,
});
loading.value = false;
...
...
@@ -175,7 +192,7 @@ const afterRead = async (files) => {
// 多张图片上传files是一个数组
muliUpload(files);
} else {
const
{ imgUrl }
= await handleUpload(files);
const
imgUrl
= await handleUpload(files);
// 上传失败提示
if (!imgUrl.src) {
files.status = "failed";
...
...
@@ -201,6 +218,7 @@ const afterRead = async (files) => {
value: fileList.value,
};
emit("active", props.item.value);
console.warn(fileList.value);
};
const beforeDelete = (files) => {
...
...
Please
register
or
login
to post a comment