增加上传文件取消提示

This commit is contained in:
2024-09-06 13:37:14 +08:00
parent 10ae05ce75
commit e6d421dfb1
4 changed files with 45 additions and 17 deletions

View File

@@ -3,13 +3,13 @@ ENV = 'production'
# 如果使用 Nginx 代理后端接口,那么此处需要改为 '/',文件查看 Docker 部署篇Nginx 配置 # 如果使用 Nginx 代理后端接口,那么此处需要改为 '/',文件查看 Docker 部署篇Nginx 配置
# 接口地址,注意协议,如果你没有配置 ssl需要将 https 改为 http # 接口地址,注意协议,如果你没有配置 ssl需要将 https 改为 http
# 测试 # 测试
# VUE_APP_BASE_API = 'https://admintestpapi.sxczgkj.cn' VUE_APP_BASE_API = 'https://admintestpapi.sxczgkj.cn'
# 生产 # 生产
# VUE_APP_BASE_API = 'https://cashieradmin.sxczgkj.cn' # VUE_APP_BASE_API = 'https://cashieradmin.sxczgkj.cn'
# 预发布接口 # 预发布接口
VUE_APP_BASE_API = 'https://pre-cashieradmin.sxczgkj.cn' # VUE_APP_BASE_API = 'https://pre-cashieradmin.sxczgkj.cn'
# VUE_APP_BASE_API = 'http://192.168.2.98:8000' # VUE_APP_BASE_API = 'http://192.168.2.98:8000'
# 如果接口是 http 形式, wss 需要改为 ws # 如果接口是 http 形式, wss 需要改为 ws

View File

@@ -10,6 +10,8 @@ const $config = {
accessKeySecret: "", accessKeySecret: "",
bucket: "cashier-oss" bucket: "cashier-oss"
} }
import { Notification } from 'element-ui'
async function uploadAndDownloadFile(name, file, headers) { async function uploadAndDownloadFile(name, file, headers) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
try { try {
@@ -39,16 +41,16 @@ class ossClient {
refreshSTSTokenInterval: 3600 * 1000 refreshSTSTokenInterval: 3600 * 1000
}); });
} }
async upload(name, file, progressCallback) { async upload(name, file, progressCallback) {
try { try {
let options = { let options = {
// 获取分片上传进度、断点和返回值。 // 获取分片上传进度、断点和返回值。
progress: progressCallback, progress: progressCallback,
headers:$headers headers: $headers
} }
const { const {
res: resp res: resp
} = await this.ossClient.put(name, file,options).catch(error => { } = await this.ossClient.put(name, file, options).catch(error => {
reject(error); reject(error);
}) })
return resp.requestUrls return resp.requestUrls
@@ -81,10 +83,21 @@ class ossClient {
res: resp res: resp
} = await this.ossClient.multipartUpload(name ? name : file.name, file, options) } = await this.ossClient.multipartUpload(name ? name : file.name, file, options)
// return resp.requestUrls // return resp.requestUrls
console.log('------resp---');
console.log(resp) console.log(resp)
return `${resp.requestUrls[0]}`.split('?')[0] return `${resp.requestUrls[0]}`.split('?')[0]
} catch (e) { } catch (e) {
console.log('------e---');
console.log(e); console.log(e);
if (e.name == 'cancel') {
Notification.error({
title: '上传已取消',
duration: 3000
})
return e
}
} }
} }
@@ -94,8 +107,15 @@ class ossClient {
* @param {Object} uploadId * @param {Object} uploadId
* @param {Object} name * @param {Object} name
*/ */
abortUpload(uploadId, name) { async abortUpload(uploadId, name) {
this.client.abortMultipartUpload(name, uploadId) try {
const res=await this.ossClient.abortMultipartUpload(name, uploadId)
return res
} catch (error) {
console.log(error)
return error
}
} }

View File

@@ -40,7 +40,7 @@
</el-table-column> </el-table-column>
</el-table> </el-table>
</div> </div>
<el-pagination :total="tableData.total" :current-page="tableData.page + 1" :page-size="tableData.size" <el-pagination :total="tableData.total" :current-page="tableData.page + 1" :page-size="tableData.size" @size-change="sizeChange"
@current-change="paginationChange" layout="total, sizes, prev, pager, next, jumper"></el-pagination> @current-change="paginationChange" layout="total, sizes, prev, pager, next, jumper"></el-pagination>
</div> </div>
</template> </template>
@@ -76,6 +76,10 @@ export default {
}, },
methods: { methods: {
sizeChange(e){
this.tableData.size = e
this.getTableData()
},
saleEndTimeFilter: (a, b) => { saleEndTimeFilter: (a, b) => {
var currentDate = new Date(); // 当前日期对象 var currentDate = new Date(); // 当前日期对象

View File

@@ -4,11 +4,9 @@
width="500px" width="500px"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
@close="diaClose" @close="diaClose"
:close-on-click-modal="false" :close-on-click-modal="true"
> >
<div class="progress" v-if="loading">
<el-progress type="circle" :percentage="progress"></el-progress>
</div>
<el-form <el-form
:element-loading-text="loadingText" :element-loading-text="loadingText"
element-loading-spinner="el-icon-loading" element-loading-spinner="el-icon-loading"
@@ -18,6 +16,9 @@
label-width="120px" label-width="120px"
label-position="left" label-position="left"
> >
<div class="progress" v-if="loading">
<el-progress type="circle" :percentage="progress"></el-progress>
</div>
<el-form-item label="平台"> <el-form-item label="平台">
<el-select <el-select
v-model="form.source" v-model="form.source"
@@ -133,7 +134,8 @@ export default {
diaClose() { diaClose() {
this.$refs.uploadFile.clearFiles(); this.$refs.uploadFile.clearFiles();
this.restForm(); this.restForm();
cancelToken(); // cancelToken();
this.ossClient.abortUpload()
}, },
uploadSuccess(res) { uploadSuccess(res) {
this.form.img = res[0]; this.form.img = res[0];
@@ -152,7 +154,7 @@ export default {
let fileRes = ""; let fileRes = "";
const file = this.$refs.uploadFile.getFileList(); const file = this.$refs.uploadFile.getFileList();
console.log(file); console.log(file);
if (!this.hasUpload && file && file.status != "finished") { if (Object.prototype.toString.call(file)=== '[object File]') {
this.loadingText = "文件上传中,请耐心等待..."; this.loadingText = "文件上传中,请耐心等待...";
this.loading = true; this.loading = true;
// fileRes = await $uploadVersionFile(file, { name: version }); // fileRes = await $uploadVersionFile(file, { name: version });
@@ -161,13 +163,13 @@ export default {
file, file,
(p) => { (p) => {
this.progress = Math.floor(p * 100); this.progress = Math.floor(p * 100);
console.log("Progress: " + p * 100 + "%");
// 这里可以根据进度做相应的处理例如更新UI等 // 这里可以根据进度做相应的处理例如更新UI等
} }
); );
console.log(fileRes); console.log(fileRes);
if (!fileRes) { if (!fileRes) {
this.loading = false; this.loading = false;
this.progress = 0;
this.$notify({ this.$notify({
title: "失败", title: "失败",
message: `上传阿里云失败`, message: `上传阿里云失败`,
@@ -175,9 +177,11 @@ export default {
}); });
return; return;
} }
if(fileRes.name=='cancel'){
return
}
} }
this.progress = 0;
let res = ""; let res = "";
if (this.form.id) { if (this.form.id) {
//编辑 //编辑
@@ -206,7 +210,7 @@ export default {
}); });
} }
this.loading = false; this.loading = false;
this.progress = 0;
this.close(); this.close();
this.$emit("success", res); this.$emit("success", res);