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 @@