1/* 上传文件 */
2beforeUpload(file) {
3 /* 0:文档文件(doc、docx、ppt、pptx)、1:视频文件(mp4)、2:压缩文件(zip、rar) */
4 let fileName = fileRename(String(file.name)); /* 文件重命名 */
5 let { accessKeyId, policy, signature, filePath } = oss;
6 Object.assign(this.upData, {
7 key: filePath[0] + fileName,
8 policy: policy,
9 OSSAccessKeyId: accessKeyId,
10 signature: signature,
11 name: fileName
12 });
13 this.loading = true;
14},
15/* 上传成功回调 */
16onSuccess(res, file, formName) {
17 this.loading = false;
18 let fileURI = this.upAction + "/" + this.upData.key;
19
20 if (formName === "popForm") {
21 this.popForm.filePath = fileURI;
22 } else if (formName === "upForm") {
23 this.upForm.url = fileURI;
24 }
25 this.$message.success("文件上传成功");
26},
27/* 移除文件 */
28onRemove(file, formName) {
29 if (formName === "popForm") {
30 this.popForm.filePath = "";
31 } else if (formName === "upForm") {
32 this.upForm.url = "";
33 }
34 this.$message.success("附件移除成功");
35},
36/* 上传失败 */
37onError(err, file) {
38 this.loading = false;
39 this.$message.error("文件上传失败,请稍后再试!");
40},