|
@@ -26,17 +26,6 @@
|
|
|
:limit="20"
|
|
:limit="20"
|
|
|
@file-change="onFileChange"
|
|
@file-change="onFileChange"
|
|
|
></upload>
|
|
></upload>
|
|
|
- <template v-if="showList">
|
|
|
|
|
- <UploadList
|
|
|
|
|
- @close="
|
|
|
|
|
- () => {
|
|
|
|
|
- showList = false;
|
|
|
|
|
- }
|
|
|
|
|
- "
|
|
|
|
|
- :list="uploadList"
|
|
|
|
|
- @del="delUploadItem"
|
|
|
|
|
- />
|
|
|
|
|
- </template>
|
|
|
|
|
</button>
|
|
</button>
|
|
|
</div>
|
|
</div>
|
|
|
<div class="filter">
|
|
<div class="filter">
|
|
@@ -102,7 +91,7 @@
|
|
|
>
|
|
>
|
|
|
</div>
|
|
</div>
|
|
|
</tableList>
|
|
</tableList>
|
|
|
- <UploadListNew class="upload-list-new"></UploadListNew>
|
|
|
|
|
|
|
+ <UploadTaskList class="upload-list-new" v-show="uploadTaskList.length != 0" fileType="AUDIO" :taskList="uploadTaskList" @cancel-task="onCancelTask"></UploadTaskList>
|
|
|
<div class="total-number" v-if="list.length !== 0 || hasMoreData">已加载{{list.length}}条</div>
|
|
<div class="total-number" v-if="list.length !== 0 || hasMoreData">已加载{{list.length}}条</div>
|
|
|
<div class="nodata" v-if="list.length == 0 && !hasMoreData && lastestUsedSearchKey">
|
|
<div class="nodata" v-if="list.length == 0 && !hasMoreData && lastestUsedSearchKey">
|
|
|
<img :src="$noresult" alt="" />
|
|
<img :src="$noresult" alt="" />
|
|
@@ -134,8 +123,7 @@ import rename from "../popup/rename";
|
|
|
import vAudio from "@/components/audio";
|
|
import vAudio from "@/components/audio";
|
|
|
import Upload from "@/components/shared/uploads/UploadMultiple";
|
|
import Upload from "@/components/shared/uploads/UploadMultiple";
|
|
|
import { changeByteUnit } from "@/utils/file";
|
|
import { changeByteUnit } from "@/utils/file";
|
|
|
-import UploadList from "../components/uploadList.vue";
|
|
|
|
|
-import UploadListNew from "../components/uploadList1.1.0.vue";
|
|
|
|
|
|
|
+import UploadTaskList from "../components/uploadList1.1.0.vue";
|
|
|
import { debounce } from "@/utils/other.js"
|
|
import { debounce } from "@/utils/other.js"
|
|
|
|
|
|
|
|
import {
|
|
import {
|
|
@@ -154,8 +142,7 @@ export default {
|
|
|
rename,
|
|
rename,
|
|
|
Upload,
|
|
Upload,
|
|
|
vAudio,
|
|
vAudio,
|
|
|
- UploadList,
|
|
|
|
|
- UploadListNew,
|
|
|
|
|
|
|
+ UploadTaskList,
|
|
|
},
|
|
},
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
@@ -179,7 +166,8 @@ export default {
|
|
|
list: [],
|
|
list: [],
|
|
|
hasMoreData: true,
|
|
hasMoreData: true,
|
|
|
isRequestingMoreData: false,
|
|
isRequestingMoreData: false,
|
|
|
- uploadList: [],
|
|
|
|
|
|
|
+ uploadTaskList: [],
|
|
|
|
|
+ uploadHandlerList: [],
|
|
|
};
|
|
};
|
|
|
},
|
|
},
|
|
|
mounted() {
|
|
mounted() {
|
|
@@ -227,9 +215,6 @@ export default {
|
|
|
}
|
|
}
|
|
|
);
|
|
);
|
|
|
},
|
|
},
|
|
|
- delUploadItem(index) {
|
|
|
|
|
- ~index && this.uploadList.splice(index, 1);
|
|
|
|
|
- },
|
|
|
|
|
del(item) {
|
|
del(item) {
|
|
|
this.$confirm({
|
|
this.$confirm({
|
|
|
content: "确定要删除素材吗?",
|
|
content: "确定要删除素材吗?",
|
|
@@ -276,103 +261,88 @@ export default {
|
|
|
},
|
|
},
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
- onFileChange(file) {
|
|
|
|
|
- let canUploadList = [];
|
|
|
|
|
-
|
|
|
|
|
- // 对选中的文件按照格式限制和名称长度限制,做过滤,name存到this.uploadList,整个file对象存到canUploadList。
|
|
|
|
|
- file.files.forEach((item, i) => {
|
|
|
|
|
- let tmp = {
|
|
|
|
|
- statusStr: "上传中",
|
|
|
|
|
- status: 4,
|
|
|
|
|
- uid: `u_${this.$randomWord(true, 8, 8)}`,
|
|
|
|
|
- name: item.name,
|
|
|
|
|
- };
|
|
|
|
|
|
|
+ onFileChange(e) {
|
|
|
|
|
+ let uploadFileList = [];
|
|
|
|
|
|
|
|
- if (item.name.toLowerCase().indexOf("mp3") <= -1) {
|
|
|
|
|
|
|
+ e.files.forEach((eachFile, i) => {
|
|
|
|
|
+ if (eachFile.name.toLowerCase().indexOf("mp3") <= -1) {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
this.$msg({
|
|
this.$msg({
|
|
|
- message: `“${item.name}”格式错误,请上传20MB以内、mp3格式的音频`,
|
|
|
|
|
|
|
+ message: `“${eachFile.name}”格式错误,请上传20MB以内、mp3格式的音频`,
|
|
|
type: "error",
|
|
type: "error",
|
|
|
});
|
|
});
|
|
|
}, i * 100);
|
|
}, i * 100);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- let tname = item.name.substring(0, item.name.lastIndexOf("."));
|
|
|
|
|
-
|
|
|
|
|
- if (tname.length > 50) {
|
|
|
|
|
|
|
+ if (eachFile.name.substring(0, eachFile.name.lastIndexOf(".")).length > 50) {
|
|
|
setTimeout(() => {
|
|
setTimeout(() => {
|
|
|
this.$msg({
|
|
this.$msg({
|
|
|
- message: `“${item.name}”名称过长,请上传标题在50字以内的音频`,
|
|
|
|
|
|
|
+ message: `“${eachFile.name}”名称过长,请上传标题在50字以内的音频`,
|
|
|
type: "error",
|
|
type: "error",
|
|
|
});
|
|
});
|
|
|
}, i * 100);
|
|
}, i * 100);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- this.uploadList.push(tmp);
|
|
|
|
|
- canUploadList.push({
|
|
|
|
|
- file: item,
|
|
|
|
|
|
|
+ let tmp = {
|
|
|
|
|
+ title: eachFile.name,
|
|
|
|
|
+ ifKnowProgress: true,
|
|
|
|
|
+ progress: 0,
|
|
|
|
|
+ status: 'LOADING',
|
|
|
|
|
+ statusStr: "正在上传素材",
|
|
|
|
|
+ uid: `u_${this.$randomWord(true, 8, 8)}`,
|
|
|
|
|
+ };
|
|
|
|
|
+ this.uploadTaskList.push(tmp);
|
|
|
|
|
+ uploadFileList.push({
|
|
|
|
|
+ file: eachFile,
|
|
|
list: { ...tmp },
|
|
list: { ...tmp },
|
|
|
});
|
|
});
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
- // Promise对象数组,每个Promise都会马上被canUploadList里的元素resolve。
|
|
|
|
|
- let p = [];
|
|
|
|
|
- canUploadList.forEach((i) => {
|
|
|
|
|
- let promise = new Promise((resolve) => {
|
|
|
|
|
- resolve(i);
|
|
|
|
|
|
|
+ let uploadPromiseList = [];
|
|
|
|
|
+ uploadFileList.forEach((data, index) => {
|
|
|
|
|
+ let promise = new Promise((resolve, reject) => {
|
|
|
|
|
+ const handler = uploadMaterial(
|
|
|
|
|
+ {
|
|
|
|
|
+ file: data.file
|
|
|
|
|
+ },
|
|
|
|
|
+ {
|
|
|
|
|
+ type: TYPE,
|
|
|
|
|
+ uid: data.list.uid,
|
|
|
|
|
+ },
|
|
|
|
|
+ (response) => {
|
|
|
|
|
+ this.uploadTaskList[index].status = 'SUCCESS'
|
|
|
|
|
+ this.uploadTaskList[index].statusText = '素材上传成功'
|
|
|
|
|
+ resolve(response);
|
|
|
|
|
+ },
|
|
|
|
|
+ (err) => {
|
|
|
|
|
+ if (err.status === 0) { // 用户取消了上传任务。TODO:判断依据不够完美。
|
|
|
|
|
+ this.uploadTaskList[index].status = 'CANCELLED'
|
|
|
|
|
+ this.uploadTaskList[index].statusText = '已取消'
|
|
|
|
|
+ } else {
|
|
|
|
|
+ this.uploadTaskList[index].status = 'FAIL'
|
|
|
|
|
+ this.uploadTaskList[index].statusText = '素材上传失败'
|
|
|
|
|
+ }
|
|
|
|
|
+ reject(err);
|
|
|
|
|
+ },
|
|
|
|
|
+ (progress) => {
|
|
|
|
|
+ this.uploadTaskList[index].progress = progress
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ this.uploadHandlerList.push(handler)
|
|
|
});
|
|
});
|
|
|
- p.push(promise);
|
|
|
|
|
|
|
+ uploadPromiseList.push(promise);
|
|
|
});
|
|
});
|
|
|
-
|
|
|
|
|
- Promise.all(p).then((result) => {
|
|
|
|
|
- // pp保存了每个文件的上传任务的Promise对象。
|
|
|
|
|
- let pp = [];
|
|
|
|
|
- p.length > 0 &&
|
|
|
|
|
- result.forEach((data) => {
|
|
|
|
|
- let params = {};
|
|
|
|
|
- params["file"] = data.file;
|
|
|
|
|
- let promise = new Promise((resolve, reject) => {
|
|
|
|
|
- uploadMaterial(
|
|
|
|
|
- params,
|
|
|
|
|
- {
|
|
|
|
|
- type: TYPE,
|
|
|
|
|
- uid: data.list.uid,
|
|
|
|
|
- },
|
|
|
|
|
- (response) => {
|
|
|
|
|
- resolve(response);
|
|
|
|
|
- },
|
|
|
|
|
- (err) => {
|
|
|
|
|
- reject(err);
|
|
|
|
|
- }
|
|
|
|
|
- );
|
|
|
|
|
- });
|
|
|
|
|
- pp.push(promise);
|
|
|
|
|
- });
|
|
|
|
|
- pp.length > 0 &&
|
|
|
|
|
- // 上传任务都结束后,this.uploadList里记录的所有任务状态都更新到5,this.uploadList里删除那些结束了的任务,更新列表数据。
|
|
|
|
|
- Promise.all(pp).then((response) => {
|
|
|
|
|
- if (response.length > 0) {
|
|
|
|
|
- this.uploadList.forEach((item) => {
|
|
|
|
|
- item.status = 5;
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- response.forEach((item) => {
|
|
|
|
|
- let idx = this.uploadList.findIndex(
|
|
|
|
|
- (sub) => sub.uid == item.data.tempId
|
|
|
|
|
- );
|
|
|
|
|
- if (item.code == 0) {
|
|
|
|
|
- if (idx > -1) {
|
|
|
|
|
- this.uploadList.splice(idx, 1);
|
|
|
|
|
- }
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
- this.refreshListDebounced()
|
|
|
|
|
- }
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ Promise.allSettled(uploadPromiseList).then(() => {
|
|
|
|
|
+ this.uploadTaskList = []
|
|
|
|
|
+ this.uploadHandlerList = []
|
|
|
|
|
+ this.refreshListDebounced()
|
|
|
});
|
|
});
|
|
|
},
|
|
},
|
|
|
|
|
+ onCancelTask(index) {
|
|
|
|
|
+ this.uploadHandlerList[index].abort()
|
|
|
|
|
+ },
|
|
|
getMoreMaterialItem() {
|
|
getMoreMaterialItem() {
|
|
|
this.isRequestingMoreData = true
|
|
this.isRequestingMoreData = true
|
|
|
const lastestUsedSearchKey = this.searchKey
|
|
const lastestUsedSearchKey = this.searchKey
|