From 9d0c07f6bdfaefa8a4b604c17d5f74c4e026a233 Mon Sep 17 00:00:00 2001 From: wuqilewuqile <11627406+wuqilewuqile@user.noreply.gitee.com> Date: Mon, 3 Jul 2023 11:45:28 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E4=BB=B6=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/wuqile/views/AddComp.vue | 33 ++++++++++++++++++++--- src/wuqile/views/AddOccupation.vue | 43 +++++++++++++++++------------- vue.config.js | 2 +- 3 files changed, 55 insertions(+), 23 deletions(-) diff --git a/src/wuqile/views/AddComp.vue b/src/wuqile/views/AddComp.vue index 825d66f..b4bb1f0 100644 --- a/src/wuqile/views/AddComp.vue +++ b/src/wuqile/views/AddComp.vue @@ -56,7 +56,7 @@ { + const url = window.URL.createObjectURL(new Blob([response.data])); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', this.form.fileUrl); // 这里的 'file.txt' 是下载后的文件名,你可以根据实际情况修改 + document.body.appendChild(link); + link.click(); + // handle your response here + }) + .catch(error => { + console.error('Download failed:', error); + this.$message.error('未上传证明文件') + // handle your error here + }); + + }, +/* onPreview(){ getFile(this.form.fileUrl).then((response)=> { console.log(response) const url = window.URL.createObjectURL(new Blob([response.data])); @@ -188,9 +212,10 @@ document.body.appendChild(link); link.click(); }) - }, + }, */ handleUploadSuccess(response) { // TODO: replace with your actual code + console.log(response) this.form.fileUrl = response; updateComp(this.form) console.log(this.form) diff --git a/src/wuqile/views/AddOccupation.vue b/src/wuqile/views/AddOccupation.vue index cae284d..816c94a 100644 --- a/src/wuqile/views/AddOccupation.vue +++ b/src/wuqile/views/AddOccupation.vue @@ -47,7 +47,7 @@ response.blob()) - .then(blob => { - // 创建URL - let url = URL.createObjectURL(blob); + onPreview(){ + /* axios.get(`http://43.142.90.238:20235/api/downloadFiles/${encodeURIComponent(this.form.fileUrl)}`) */ + axios({ + url: `http://43.142.90.238:20235/api/downloadFiles/${encodeURIComponent(this.form.fileUrl)}`, + method: 'GET', + responseType: 'blob', // important + }) + .then(response => { + const url = window.URL.createObjectURL(new Blob([response.data])); + const link = document.createElement('a'); + link.href = url; + link.setAttribute('download', this.form.fileUrl); // 这里的 'file.txt' 是下载后的文件名,你可以根据实际情况修改 + document.body.appendChild(link); + link.click(); + // handle your response here + }) + .catch(error => { + console.error('Download failed:', error); + this.$message.error('未上传证明文件') + // handle your error here + }); - // 这里,我们假设你将在一个新窗口中预览图像 - window.open(url, '_blank'); - }) - .catch(error => { - console.error('Error:', error); - }); - }, + }, handleUploadSuccess(response) { // TODO: replace with your actual code this.form.fileUrl = response; diff --git a/vue.config.js b/vue.config.js index de35761..832431e 100644 --- a/vue.config.js +++ b/vue.config.js @@ -6,7 +6,7 @@ module.exports = defineConfig({ // 设置代理 proxy: { '/api': { - target: 'http://localhost:20235', + target: 'http://43.142.90.238:20235', changeOrigin: true, // 跨域 pathRewrite: { '^/api': '' -- Gitee