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 01:36:21 +0800
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
2a6b4f7d1323055d10e148596c4d3130386276cc
2a6b4f7d
1 parent
b8477185
新增上传多张图片功能
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
4 deletions
src/components/ImageUploaderField/index.vue
src/components/ImageUploaderField/index.vue
View file @
2a6b4f7
...
...
@@ -130,7 +130,8 @@ const uploadQiniu = async (file, token, filename) => {
};
/****************** END *******************/
const afterRead = async (files) => {
const handleUpload = async (files) => {
// 上传图片流程
loading.value = true;
// 获取HASH值
const hash = getEtag(files.content);
...
...
@@ -144,6 +145,37 @@ const afterRead = async (files) => {
files.status = "uploading";
files.message = "上传中...";
const imgUrl = await uploadQiniu(files.file, token, filename);
return { imgUrl };
};
var muliUpload = async (files) => {
for (let item of files) {
const res = await handleUpload(item);
console.warn(res.imgUrl.src);
// 上传失败提示
if (!res.imgUrl.src) {
item.status = "failed";
item.message = "上传失败";
loading.value = false;
} else {
item.status = "";
item.message = "";
// fileList.value.pop();
fileList.value.push({
url: res.imgUrl.src,
isImage: true,
});
loading.value = false;
}
}
};
const afterRead = async (files) => {
if (Array.isArray(files)) {
// 多张图片上传files是一个数组
muliUpload(files);
} else {
const { imgUrl } = await handleUpload(files);
// 上传失败提示
if (!imgUrl.src) {
files.status = "failed";
...
...
@@ -157,15 +189,19 @@ const afterRead = async (files) => {
url: imgUrl.src,
isImage: true,
});
loading.value = false;
}
}
fileList.value = fileList.value.filter((item) => {
if (item.url) return item;
});
props.item.value = {
key: "image_uploader",
filed_name: props.item.key,
value: fileList.value,
};
emit("active", props.item.value);
loading.value = false;
}
console.warn(fileList.value);
};
const beforeDelete = (files) => {
...
...
Please
register
or
login
to post a comment