From 14aa13e71869540388cf84069827c5807632dc86 Mon Sep 17 00:00:00 2001 From: dqjdda <201507802@qq.com> Date: Mon, 26 Aug 2019 17:38:31 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=90=8E=E7=AB=AF=E5=B8=A6?= =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E5=AF=BC=E5=87=BA=E5=8A=9F=E8=83=BD=EF=BC=88?= =?UTF-8?q?=E7=A4=BA=E4=BE=8B=E8=A7=81=E7=94=A8=E6=88=B7=E7=AE=A1=E7=90=86?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E5=99=A8=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/user.js | 7 +++++++ src/utils/index.js | 12 ++++++++++++ src/views/system/user/index.vue | 19 +++++++------------ 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/api/user.js b/src/api/user.js index a928986..49e2777 100644 --- a/src/api/user.js +++ b/src/api/user.js @@ -7,6 +7,13 @@ export function add(data) { data }) } +export function downloadUser() { + return request({ + url: 'api/users/download', + method: 'get', + responseType: 'blob' + }) +} export function del(id) { return request({ diff --git a/src/utils/index.js b/src/utils/index.js index 2514e9a..d12da2f 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -147,3 +147,15 @@ export function removeClass(ele, cls) { ele.className = ele.className.replace(reg, ' ') } } + +export function downloadFile(obj, name, suffix) { + const url = window.URL.createObjectURL(new Blob([obj])) + const link = document.createElement('a') + link.style.display = 'none' + link.href = url + const fileName = parseTime(new Date()) + '-' + name + '.' + suffix + link.setAttribute('download', fileName) + document.body.appendChild(link) + link.click() + document.body.removeChild(link) +} diff --git a/src/views/system/user/index.vue b/src/views/system/user/index.vue index 51a43ba..8dba217 100644 --- a/src/views/system/user/index.vue +++ b/src/views/system/user/index.vue @@ -32,7 +32,7 @@