上传新增进度显示、环境变量新增默认上传地址配置

This commit is contained in:
不做码农 2021-12-19 12:36:16 +08:00
parent 9ae54c1799
commit ab6e99d721
6 changed files with 53 additions and 20 deletions

View File

@ -9,3 +9,6 @@ VUE_APP_BASE_API = '/dev-api'
# 路由前缀
VUE_APP_ROUTER_PREFIX = '/'
# 默认上传地址
VUE_APP_UPLOAD_URL = '/Common/UploadFile'

View File

@ -9,3 +9,6 @@ VUE_APP_BASE_API = '/prod-api'
# 路由前缀
VUE_APP_ROUTER_PREFIX = '/'
# 默认上传地址
VUE_APP_UPLOAD_URL = '/Common/UploadFile'

View File

@ -9,3 +9,6 @@ VUE_APP_BASE_API = '/stage-api'
# 路由前缀
VUE_APP_ROUTER_PREFIX = '/'
# 默认上传地址
VUE_APP_UPLOAD_URL = '/Common/UploadFile'

View File

@ -1,8 +1,8 @@
<template>
<div class="upload-file">
<el-upload :action="uploadFileUrl" :before-upload="handleBeforeUpload" :file-list="fileList" :limit="limit" :on-error="handleUploadError"
:on-exceed="handleExceed" :on-success="handleUploadSuccess" :show-file-list="false" :data="data" :headers="headers" class="upload-file-uploader"
ref="upload">
:on-exceed="handleExceed" :on-success="handleUploadSuccess" :on-progress="uploadProcess" :show-file-list="false" :data="data" :headers="headers"
class="upload-file-uploader" ref="upload">
<!-- 上传按钮 -->
<el-button size="mini" type="primary" icon="el-icon-upload">选取文件</el-button>
<!-- 上传提示 -->
@ -12,6 +12,7 @@
<template v-if="fileType"> 格式为 <b style="color: #f56c6c">{{ fileType.join("/") }}</b> </template>
的文件
</div>
<el-progress v-show="showProgress == true" :percentage="uploadPercent" style="margin-top:10px;"></el-progress>
</el-upload>
<!-- 文件列表 -->
@ -59,17 +60,19 @@ export default {
//
uploadUrl: {
type: String,
default: "/Common/UploadFile",
default: process.env.VUE_APP_UPLOAD_URL ?? "/Common/UploadFile",
},
// form
// form
column: [String],
//
data: {
type: Object
}
//
data: {
type: Object,
},
},
data() {
return {
showProgress: false,
uploadPercent: 0,
baseUrl: process.env.VUE_APP_BASE_API,
uploadFileUrl: process.env.VUE_APP_BASE_API + this.uploadUrl, //
headers: {
@ -137,6 +140,7 @@ export default {
return false;
}
}
this.showProgress = true;
return true;
},
//
@ -146,11 +150,17 @@ export default {
//
handleUploadError(err) {
this.msgError("上传失败, 请重试");
this.fileList = [];
this.showProgress = false;
this.uploadPercent = 0;
},
//
handleUploadSuccess(res, file) {
this.showProgress = false;
this.uploadPercent = 0;
if (res.code != 200) {
this.fileList = [];
this.fileList = [];
this.msgError(`上传失败,原因:${res.msg}!`);
return;
}
@ -158,6 +168,12 @@ export default {
this.fileList.push({ name: res.data.fileName, url: res.data.url });
this.$emit("input", this.column, this.listToString(this.fileList));
},
//
uploadProcess(event, file, fileList) {
this.showProgress = true;
this.videoUploadPercent = file.percentage.toFixed(0);
console.log("上传进度" + file.percentage);
},
//
handleDelete(index) {
this.fileList.splice(index, 1);

View File

@ -2,9 +2,10 @@
<div class="component-upload-image">
<el-upload list-type="picture-card" :action="uploadImgUrl" :on-success="handleUploadSuccess" :before-upload="handleBeforeUpload"
:on-exceed="handleExceed" :on-remove="handleRemove" :on-error="handleUploadError" name="file" :show-file-list="true" :limit="limit"
:file-list="fileList" :on-preview="handlePictureCardPreview" :class="{hide: this.fileList.length >= this.limit}" :headers="headers">
:file-list="fileList" :on-preview="handlePictureCardPreview" :on-progress="uploadProcess" :class="{hide: this.fileList.length >= this.limit}"
:headers="headers">
<i class="el-icon-plus"></i>
<el-progress v-if="showProgress == true" type="circle" :percentage="uploadPercent" style="margin-top:10px;"></el-progress>
<!-- 上传提示 -->
<div class="el-upload__tip" slot="tip" v-if="showTip">
请上传
@ -34,7 +35,7 @@ export default {
//
uploadUrl: {
type: String,
default: "/Common/UploadFile",
default: process.env.VUE_APP_UPLOAD_URL ?? "/Common/UploadFile",
},
// , ['png', 'jpg', 'jpeg']
fileType: {
@ -59,6 +60,8 @@ export default {
dialogImageUrl: "",
dialogVisible: false,
hideUpload: false,
showProgress: false,
uploadPercent: 0,
uploadImgUrl: process.env.VUE_APP_BASE_API + this.uploadUrl, //
headers: {
Authorization: "Bearer " + getToken(),
@ -112,7 +115,9 @@ export default {
//
handleUploadSuccess(res) {
console.log(res);
this.loading.close();
this.showProgress = false;
this.uploadPercent = 0;
if (res.code != 200) {
this.msgError(`上传失败,原因:${res.msg}!`);
return;
@ -150,11 +155,7 @@ export default {
return false;
}
}
this.loading = this.$loading({
lock: true,
text: "上传中",
background: "rgba(0, 0, 0, 0.7)",
});
this.showProgress = true;
},
//
handleExceed() {
@ -179,7 +180,14 @@ export default {
type: "error",
message: "上传失败",
});
this.loading.close();
this.showProgress = false;
this.uploadPercent = 0;
},
//
uploadProcess(event, file, fileList) {
this.showProgress = true;
this.videoUploadPercent = file.percentage.toFixed(0);
console.log("上传进度" + file.percentage);
},
},
};

View File

@ -77,4 +77,4 @@ new Vue({
store,
render: h => h(App)
})
console.log('后端地址:' + process.env.VUE_APP_BASE_API)
console.log('环境变量:', process.env)