文件上传组件 FileUpload 上传报错的问题

This commit is contained in:
YunaiV 2022-05-11 12:40:54 +08:00
parent b6cb6469f1
commit 1f36af8e6a
2 changed files with 11 additions and 11 deletions

View File

@ -28,7 +28,7 @@
<!-- 文件列表 --> <!-- 文件列表 -->
<transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul"> <transition-group class="upload-file-list el-upload-list el-upload-list--text" name="el-fade-in-linear" tag="ul">
<li :key="file.url" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in fileList"> <li :key="file.url" class="el-upload-list__item ele-upload-list__item-content" v-for="(file, index) in fileList">
<el-link :href="`${baseUrl}${file.url}`" :underline="false" target="_blank"> <el-link :href="`${file.url}`" :underline="false" target="_blank">
<span class="el-icon-document"> {{ getFileName(file.name) }} </span> <span class="el-icon-document"> {{ getFileName(file.name) }} </span>
</el-link> </el-link>
<div class="ele-upload-list__item-content-action"> <div class="ele-upload-list__item-content-action">
@ -72,11 +72,8 @@ export default {
return { return {
number: 0, number: 0,
uploadList: [], uploadList: [],
baseUrl: process.env.VUE_APP_BASE_API, uploadFileUrl: process.env.VUE_APP_BASE_API + "/admin-api/infra/file/upload", //
uploadFileUrl: process.env.VUE_APP_BASE_API + "/common/upload", // headers: { Authorization: "Bearer " + getAccessToken() }, //
headers: {
Authorization: "Bearer " + getAccessToken(),
},
fileList: [], fileList: [],
}; };
}, },
@ -121,8 +118,7 @@ export default {
} }
const isTypeOk = this.fileType.some((type) => { const isTypeOk = this.fileType.some((type) => {
if (file.type.indexOf(type) > -1) return true; if (file.type.indexOf(type) > -1) return true;
if (fileExtension && fileExtension.indexOf(type) > -1) return true; return !!(fileExtension && fileExtension.indexOf(type) > -1);
return false;
}); });
if (!isTypeOk) { if (!isTypeOk) {
this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`); this.$modal.msgError(`文件格式不正确, 请上传${this.fileType.join("/")}格式文件!`);
@ -152,7 +148,8 @@ export default {
}, },
// //
handleUploadSuccess(res) { handleUploadSuccess(res) {
this.uploadList.push({ name: res.fileName, url: res.fileName }); // edit by
this.uploadList.push({ name: res.data, url: res.data });
if (this.uploadList.length === this.number) { if (this.uploadList.length === this.number) {
this.fileList = this.fileList.concat(this.uploadList); this.fileList = this.fileList.concat(this.uploadList);
this.uploadList = []; this.uploadList = [];
@ -181,7 +178,7 @@ export default {
for (let i in list) { for (let i in list) {
strs += list[i].url + separator; strs += list[i].url + separator;
} }
return strs != '' ? strs.substr(0, strs.length - 1) : ''; return strs !== '' ? strs.substr(0, strs.length - 1) : '';
} }
} }
}; };

View File

@ -70,7 +70,8 @@
<el-input v-model="form.name" placeholder="请输入应用名" /> <el-input v-model="form.name" placeholder="请输入应用名" />
</el-form-item> </el-form-item>
<el-form-item label="应用图标"> <el-form-item label="应用图标">
<imageUpload v-model="form.logo" :limit="1"/> <!-- <imageUpload v-model="form.logo" :limit="1"/>-->
<file-upload v-model="form.logo" :limit="1"/>
</el-form-item> </el-form-item>
<el-form-item label="应用描述"> <el-form-item label="应用描述">
<el-input type="textarea" v-model="form.description" placeholder="请输入应用名" /> <el-input type="textarea" v-model="form.description" placeholder="请输入应用名" />
@ -104,10 +105,12 @@ import { createOAuth2Client, updateOAuth2Client, deleteOAuth2Client, getOAuth2Cl
import ImageUpload from '@/components/ImageUpload'; import ImageUpload from '@/components/ImageUpload';
import Editor from '@/components/Editor'; import Editor from '@/components/Editor';
import {CommonStatusEnum} from "@/utils/constants"; import {CommonStatusEnum} from "@/utils/constants";
import FileUpload from "@/components/FileUpload";
export default { export default {
name: "OAuth2Client", name: "OAuth2Client",
components: { components: {
FileUpload,
ImageUpload, ImageUpload,
Editor, Editor,
}, },