From c7e524ad249a760bb5b9f455611bdf63c16ae43a Mon Sep 17 00:00:00 2001 From: smallchill Date: Tue, 22 Mar 2022 16:07:13 +0800 Subject: [PATCH] =?UTF-8?q?:zap:=20=E6=8F=90=E5=8D=87excel=E5=AF=BC?= =?UTF-8?q?=E5=87=BA=E5=8A=9F=E8=83=BD=E7=9A=84=E7=94=A8=E6=88=B7=E4=BD=93?= =?UTF-8?q?=E9=AA=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/common.js | 13 +++++++++++++ src/util/date.js | 7 +++++++ src/util/util.js | 24 ++++++++++++++++++++++++ src/views/base/region.vue | 15 +++++++++++++-- src/views/system/user.vue | 37 ++++++++++++++++++++++++------------- 5 files changed, 81 insertions(+), 15 deletions(-) create mode 100644 src/api/common.js diff --git a/src/api/common.js b/src/api/common.js new file mode 100644 index 0000000..743dc69 --- /dev/null +++ b/src/api/common.js @@ -0,0 +1,13 @@ +import request from "@/router/axios"; + +/** + * 文件流返回 + * @param url 接口地址 + */ +export const exportBlob = (url) => { + return request({ + url: url, + method: 'get', + responseType: 'blob' + }) +} diff --git a/src/util/date.js b/src/util/date.js index 4c1f250..88b9e6a 100644 --- a/src/util/date.js +++ b/src/util/date.js @@ -49,3 +49,10 @@ export function dateFormat(date, format) { return ''; } + +/** + * 当前时间戳 + */ +export function dateNow() { + return dateFormat(new Date(), "yyyyMMddhhmmss"); +} diff --git a/src/util/util.js b/src/util/util.js index 6634ab1..9df90d0 100644 --- a/src/util/util.js +++ b/src/util/util.js @@ -365,3 +365,27 @@ export const downloadFileBase64 = (path, name) => { } }; } + +/** + * 下载excel + * @param {blob} fileArrayBuffer 文件流 + * @param {String} filename 文件名称 + */ +export const downloadXls = (fileArrayBuffer, filename) => { + let data = new Blob([fileArrayBuffer], {type: 'application/vnd.ms-excel,charset=utf-8'}); + if (typeof window.chrome !== 'undefined') { + // Chrome + var link = document.createElement('a'); + link.href = window.URL.createObjectURL(data); + link.download = filename; + link.click(); + } else if (typeof window.navigator.msSaveBlob !== 'undefined') { + // IE + var blob = new Blob([data], {type: 'application/force-download'}); + window.navigator.msSaveBlob(blob, filename); + } else { + // Firefox + var file = new File([data], filename, {type: 'application/force-download'}); + window.open(URL.createObjectURL(file)); + } +} diff --git a/src/views/base/region.vue b/src/views/base/region.vue index 2027d70..ff3691c 100644 --- a/src/views/base/region.vue +++ b/src/views/base/region.vue @@ -52,9 +52,14 @@