From 02a0ab6d6d3c833c125419b95699a86df347e3d7 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 17 Feb 2022 14:28:43 +0800 Subject: [PATCH] =?UTF-8?q?v3.8.0=20=E6=96=B0=E5=A2=9E=E9=80=9A=E7=94=A8?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E7=AE=80=E5=8C=96=E4=B8=8B=E8=BD=BD=E4=BD=BF?= =?UTF-8?q?=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../resources/codegen/vue/views/index.vue.vm | 2 +- yudao-ui-admin/src/main.js | 20 +------- yudao-ui-admin/src/plugins/download.js | 47 +++++++++++++++++++ yudao-ui-admin/src/plugins/index.js | 3 ++ yudao-ui-admin/src/utils/ruoyi.js | 44 ----------------- .../src/views/infra/apiAccessLog/index.vue | 2 +- .../src/views/infra/apiErrorLog/index.vue | 2 +- .../src/views/infra/config/index.vue | 2 +- yudao-ui-admin/src/views/infra/job/index.vue | 2 +- yudao-ui-admin/src/views/infra/job/log.vue | 2 +- yudao-ui-admin/src/views/pay/app/index.vue | 2 +- .../src/views/pay/merchant/index.vue | 2 +- yudao-ui-admin/src/views/pay/order/index.vue | 2 +- yudao-ui-admin/src/views/pay/refund/index.vue | 2 +- yudao-ui-admin/src/views/system/dict/data.vue | 2 +- .../src/views/system/dict/index.vue | 2 +- .../src/views/system/errorCode/index.vue | 2 +- .../src/views/system/loginlog/index.vue | 2 +- .../src/views/system/operatelog/index.vue | 2 +- .../src/views/system/post/index.vue | 2 +- .../src/views/system/role/index.vue | 2 +- .../src/views/system/sms/smsLog.vue | 2 +- .../src/views/system/sms/smsTemplate.vue | 2 +- .../src/views/system/tenant/index.vue | 2 +- .../src/views/system/user/index.vue | 4 +- .../src/views/tool/codegen/index.vue | 2 +- yudao-ui-admin/src/views/tool/dbDoc/index.vue | 6 +-- .../src/views/tool/testDemo/index.vue | 2 +- 28 files changed, 78 insertions(+), 90 deletions(-) create mode 100644 yudao-ui-admin/src/plugins/download.js diff --git a/yudao-module-tool/yudao-module-tool-impl/src/main/resources/codegen/vue/views/index.vue.vm b/yudao-module-tool/yudao-module-tool-impl/src/main/resources/codegen/vue/views/index.vue.vm index 494fe3bf..2f65f327 100644 --- a/yudao-module-tool/yudao-module-tool-impl/src/main/resources/codegen/vue/views/index.vue.vm +++ b/yudao-module-tool/yudao-module-tool-impl/src/main/resources/codegen/vue/views/index.vue.vm @@ -390,7 +390,7 @@ export default { this.exportLoading = true; return export${simpleClassName}Excel(params); }).then(response => { - this.downloadExcel(response, '${table.classComment}.xls'); + this.$download.excel(response, '${table.classComment}.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/main.js b/yudao-ui-admin/src/main.js index 77f671b5..a572d937 100644 --- a/yudao-ui-admin/src/main.js +++ b/yudao-ui-admin/src/main.js @@ -17,19 +17,7 @@ import './assets/icons' // icon import './permission' // permission control import { getDicts } from "@/api/system/dict/data"; import { getConfigKey } from "@/api/infra/config"; -import { - parseTime, - resetForm, - addDateRange, - addBeginAndEndTime, - download, - handleTree, - downloadExcel, - downloadWord, - downloadZip, - downloadHtml, - downloadMarkdown, -} from "@/utils/ruoyi"; +import { parseTime, resetForm, addDateRange, addBeginAndEndTime, handleTree} from "@/utils/ruoyi"; import Pagination from "@/components/Pagination"; // 自定义表格工具扩展 import RightToolbar from "@/components/RightToolbar" @@ -49,12 +37,6 @@ Vue.prototype.getDictDatas = getDictDatas Vue.prototype.getDictDatas2 = getDictDatas2 Vue.prototype.getDictDataLabel = getDictDataLabel Vue.prototype.DICT_TYPE = DICT_TYPE -Vue.prototype.download = download -Vue.prototype.downloadExcel = downloadExcel -Vue.prototype.downloadWord = downloadWord -Vue.prototype.downloadHtml = downloadHtml -Vue.prototype.downloadMarkdown = downloadMarkdown -Vue.prototype.downloadZip = downloadZip Vue.prototype.handleTree = handleTree // 全局组件挂载 diff --git a/yudao-ui-admin/src/plugins/download.js b/yudao-ui-admin/src/plugins/download.js new file mode 100644 index 00000000..353398e4 --- /dev/null +++ b/yudao-ui-admin/src/plugins/download.js @@ -0,0 +1,47 @@ +import { saveAs } from 'file-saver' +import axios from 'axios' +import { getToken } from '@/utils/auth' + +const baseURL = process.env.VUE_APP_BASE_API + +export default { + // 下载 Excel 方法 + excel(data, fileName) { + this.download0(data, fileName, 'application/vnd.ms-excel'); + }, + + // 下载 Word 方法 + word(data, fileName) { + this.download0(data, fileName, 'application/msword'); + }, + + // 下载 Zip 方法 + zip(data, fileName) { + this.download0(data, fileName, 'application/zip'); + }, + + // 下载 Html 方法 + html(data, fileName) { + this.download0(data, fileName, 'text/html'); + }, + + // 下载 Markdown 方法 + markdown(data, fileName) { + this.download0(data, fileName, 'text/markdown'); + }, + + download0(data, fileName, mineType) { + // 创建 blob + let blob = new Blob([data], {type: mineType}); + // 创建 href 超链接,点击进行下载 + window.URL = window.URL || window.webkitURL; + let href = URL.createObjectURL(blob); + let downA = document.createElement("a"); + downA.href = href; + downA.download = fileName; + downA.click(); + // 销毁超连接 + window.URL.revokeObjectURL(href); + } + +} diff --git a/yudao-ui-admin/src/plugins/index.js b/yudao-ui-admin/src/plugins/index.js index 6eba5109..f4698301 100644 --- a/yudao-ui-admin/src/plugins/index.js +++ b/yudao-ui-admin/src/plugins/index.js @@ -1,5 +1,6 @@ import cache from './cache' import modal from './modal' +import download from './download' export default { install(Vue) { @@ -7,5 +8,7 @@ export default { Vue.prototype.$cache = cache // 模态框对象 Vue.prototype.$modal = modal + // 下载文件 + Vue.prototype.$download = download } } diff --git a/yudao-ui-admin/src/utils/ruoyi.js b/yudao-ui-admin/src/utils/ruoyi.js index 90ad61ef..e96763e7 100644 --- a/yudao-ui-admin/src/utils/ruoyi.js +++ b/yudao-ui-admin/src/utils/ruoyi.js @@ -100,50 +100,6 @@ export function addBeginAndEndTime(params, dateRange, propName) { return params; } -// 通用下载方法 -export function download(fileName) { - window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true; -} - -// 下载 Excel 方法 -export function downloadExcel(data, fileName) { - download0(data, fileName, 'application/vnd.ms-excel'); -} - -// 下载 Word 方法 -export function downloadWord(data, fileName) { - download0(data, fileName, 'application/msword'); -} - -// 下载 Zip 方法 -export function downloadZip(data, fileName) { - download0(data, fileName, 'application/zip'); -} - -// 下载 Html 方法 -export function downloadHtml(data, fileName) { - download0(data, fileName, 'text/html'); -} - -// 下载 Markdown 方法 -export function downloadMarkdown(data, fileName) { - download0(data, fileName, 'text/markdown'); -} - -function download0(data, fileName, mineType) { - // 创建 blob - let blob = new Blob([data], {type: mineType}); - // 创建 href 超链接,点击进行下载 - window.URL = window.URL || window.webkitURL; - let href = URL.createObjectURL(blob); - let downA = document.createElement("a"); - downA.href = href; - downA.download = fileName; - downA.click(); - // 销毁超连接 - window.URL.revokeObjectURL(href); -} - // 字符串格式化(%s ) export function sprintf(str) { var args = arguments, flag = true, i = 1; diff --git a/yudao-ui-admin/src/views/infra/apiAccessLog/index.vue b/yudao-ui-admin/src/views/infra/apiAccessLog/index.vue index 0be2c5bf..ba2cc631 100644 --- a/yudao-ui-admin/src/views/infra/apiAccessLog/index.vue +++ b/yudao-ui-admin/src/views/infra/apiAccessLog/index.vue @@ -206,7 +206,7 @@ export default { this.exportLoading = true; return exportApiAccessLogExcel(params); }).then(response => { - this.downloadExcel(response, 'API 访问日志.xls'); + this.$download.excel(response, 'API 访问日志.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/infra/apiErrorLog/index.vue b/yudao-ui-admin/src/views/infra/apiErrorLog/index.vue index 09f68505..7d107157 100644 --- a/yudao-ui-admin/src/views/infra/apiErrorLog/index.vue +++ b/yudao-ui-admin/src/views/infra/apiErrorLog/index.vue @@ -224,7 +224,7 @@ export default { this.exportLoading = true; return exportApiErrorLogExcel(params); }).then(response => { - this.downloadExcel(response, 'API 错误日志.xls'); + this.$download.excel(response, 'API 错误日志.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/infra/config/index.vue b/yudao-ui-admin/src/views/infra/config/index.vue index aae43651..a3d06b23 100644 --- a/yudao-ui-admin/src/views/infra/config/index.vue +++ b/yudao-ui-admin/src/views/infra/config/index.vue @@ -268,7 +268,7 @@ export default { this.exportLoading = true; return exportConfig(queryParams); }).then(response => { - this.downloadExcel(response, '参数配置.xls'); + this.$download.excel(response, '参数配置.xls'); this.exportLoading = false; }).catch(() => {}); }, diff --git a/yudao-ui-admin/src/views/infra/job/index.vue b/yudao-ui-admin/src/views/infra/job/index.vue index fa24ab35..2f415413 100644 --- a/yudao-ui-admin/src/views/infra/job/index.vue +++ b/yudao-ui-admin/src/views/infra/job/index.vue @@ -367,7 +367,7 @@ export default { this.exportLoading = true; return exportJob(queryParams); }).then(response => { - this.downloadExcel(response, '定时任务.xls'); + this.$download.excel(response, '定时任务.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/infra/job/log.vue b/yudao-ui-admin/src/views/infra/job/log.vue index 5c304f4a..4de8c19b 100644 --- a/yudao-ui-admin/src/views/infra/job/log.vue +++ b/yudao-ui-admin/src/views/infra/job/log.vue @@ -169,7 +169,7 @@ export default { this.exportLoading = true; return exportJobLogExcel(params); }).then(response => { - this.downloadExcel(response, '定时任务日志.xls'); + this.$download.excel(response, '定时任务日志.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/pay/app/index.vue b/yudao-ui-admin/src/views/pay/app/index.vue index 3d40b933..6178d543 100644 --- a/yudao-ui-admin/src/views/pay/app/index.vue +++ b/yudao-ui-admin/src/views/pay/app/index.vue @@ -417,7 +417,7 @@ export default { this.$modal.confirm('是否确认导出所有支付应用信息数据项?').then(function () { return exportAppExcel(params); }).then(response => { - this.downloadExcel(response, '支付应用信息.xls'); + this.$download.excel(response, '支付应用信息.xls'); }).catch(() => {}); }, /** diff --git a/yudao-ui-admin/src/views/pay/merchant/index.vue b/yudao-ui-admin/src/views/pay/merchant/index.vue index fa881324..bcacb582 100644 --- a/yudao-ui-admin/src/views/pay/merchant/index.vue +++ b/yudao-ui-admin/src/views/pay/merchant/index.vue @@ -279,7 +279,7 @@ export default { this.exportLoading = true; return exportMerchantExcel(params); }).then(response => { - this.downloadExcel(response, '支付商户信息.xls'); + this.$download.excel(response, '支付商户信息.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/pay/order/index.vue b/yudao-ui-admin/src/views/pay/order/index.vue index 26357830..38e90998 100755 --- a/yudao-ui-admin/src/views/pay/order/index.vue +++ b/yudao-ui-admin/src/views/pay/order/index.vue @@ -423,7 +423,7 @@ export default { this.$modal.confirm('是否确认导出所有支付订单数据项?').then(function () { return exportOrderExcel(params); }).then(response => { - this.downloadExcel(response, '支付订单.xls'); + this.$download.excel(response, '支付订单.xls'); }).catch(() => {}); }, /** diff --git a/yudao-ui-admin/src/views/pay/refund/index.vue b/yudao-ui-admin/src/views/pay/refund/index.vue index 082b8089..2f5e518f 100755 --- a/yudao-ui-admin/src/views/pay/refund/index.vue +++ b/yudao-ui-admin/src/views/pay/refund/index.vue @@ -427,7 +427,7 @@ export default { this.$modal.confirm('是否确认导出所有退款订单数据项?').then(function () { return exportRefundExcel(params); }).then(response => { - this.downloadExcel(response, '退款订单.xls'); + this.$download.excel(response, '退款订单.xls'); }).catch(() => {}); }, /** diff --git a/yudao-ui-admin/src/views/system/dict/data.vue b/yudao-ui-admin/src/views/system/dict/data.vue index 388b60a4..3e51746b 100644 --- a/yudao-ui-admin/src/views/system/dict/data.vue +++ b/yudao-ui-admin/src/views/system/dict/data.vue @@ -297,7 +297,7 @@ export default { this.exportLoading = true; return exportData(queryParams); }).then(response => { - this.downloadExcel(response, '字典数据.xls'); + this.$download.excel(response, '字典数据.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/system/dict/index.vue b/yudao-ui-admin/src/views/system/dict/index.vue index 3f865ee7..7df03865 100644 --- a/yudao-ui-admin/src/views/system/dict/index.vue +++ b/yudao-ui-admin/src/views/system/dict/index.vue @@ -250,7 +250,7 @@ export default { this.exportLoading = true; return exportType(params); }).then(response => { - this.downloadExcel(response, '字典类型.xls'); + this.$download.excel(response, '字典类型.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/system/errorCode/index.vue b/yudao-ui-admin/src/views/system/errorCode/index.vue index 0aa26388..35739657 100644 --- a/yudao-ui-admin/src/views/system/errorCode/index.vue +++ b/yudao-ui-admin/src/views/system/errorCode/index.vue @@ -243,7 +243,7 @@ export default { this.exportLoading = true; return exportErrorCodeExcel(params); }).then(response => { - this.downloadExcel(response, '错误码.xls'); + this.$download.excel(response, '错误码.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/system/loginlog/index.vue b/yudao-ui-admin/src/views/system/loginlog/index.vue index 37edefa7..41e405ca 100644 --- a/yudao-ui-admin/src/views/system/loginlog/index.vue +++ b/yudao-ui-admin/src/views/system/loginlog/index.vue @@ -126,7 +126,7 @@ export default { this.exportLoading = true; return exportLoginLog(queryParams); }).then(response => { - this.downloadExcel(response, '登录日志.xls'); + this.$download.excel(response, '登录日志.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/system/operatelog/index.vue b/yudao-ui-admin/src/views/system/operatelog/index.vue index 7bf69115..2b70a0da 100644 --- a/yudao-ui-admin/src/views/system/operatelog/index.vue +++ b/yudao-ui-admin/src/views/system/operatelog/index.vue @@ -206,7 +206,7 @@ export default { this.exportLoading = true; return exportOperateLog(queryParams); }).then(response => { - this.downloadExcel(response, '操作日志.xls'); + this.$download.excel(response, '操作日志.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/system/post/index.vue b/yudao-ui-admin/src/views/system/post/index.vue index 86b1ee04..dab62397 100644 --- a/yudao-ui-admin/src/views/system/post/index.vue +++ b/yudao-ui-admin/src/views/system/post/index.vue @@ -236,7 +236,7 @@ export default { this.exportLoading = true; return exportPost(queryParams); }).then(response => { - this.downloadExcel(response, '岗位数据.xls'); + this.$download.excel(response, '岗位数据.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/system/role/index.vue b/yudao-ui-admin/src/views/system/role/index.vue index 9ccd755d..61657053 100644 --- a/yudao-ui-admin/src/views/system/role/index.vue +++ b/yudao-ui-admin/src/views/system/role/index.vue @@ -497,7 +497,7 @@ export default { this.exportLoading = true; return exportRole(queryParams); }).then(response => { - this.downloadExcel(response, '角色数据.xls'); + this.$download.excel(response, '角色数据.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/system/sms/smsLog.vue b/yudao-ui-admin/src/views/system/sms/smsLog.vue index e78a8f00..21763c9f 100644 --- a/yudao-ui-admin/src/views/system/sms/smsLog.vue +++ b/yudao-ui-admin/src/views/system/sms/smsLog.vue @@ -282,7 +282,7 @@ export default { this.exportLoading = true; return exportSmsLogExcel(params); }).then(response => { - this.downloadExcel(response, '短信日志.xls'); + this.$download.excel(response, '短信日志.xls'); this.exportLoading = false; }).catch(() => {}); }, diff --git a/yudao-ui-admin/src/views/system/sms/smsTemplate.vue b/yudao-ui-admin/src/views/system/sms/smsTemplate.vue index 9e7b7116..6fe02333 100644 --- a/yudao-ui-admin/src/views/system/sms/smsTemplate.vue +++ b/yudao-ui-admin/src/views/system/sms/smsTemplate.vue @@ -334,7 +334,7 @@ export default { this.exportLoading = true; return exportSmsTemplateExcel(params); }).then(response => { - this.downloadExcel(response, '短信模板.xls'); + this.$download.excel(response, '短信模板.xls'); this.exportLoading = false; }).catch(() => {}); }, diff --git a/yudao-ui-admin/src/views/system/tenant/index.vue b/yudao-ui-admin/src/views/system/tenant/index.vue index 5edbe7b3..3c4e176a 100755 --- a/yudao-ui-admin/src/views/system/tenant/index.vue +++ b/yudao-ui-admin/src/views/system/tenant/index.vue @@ -246,7 +246,7 @@ export default { this.exportLoading = true; return exportTenantExcel(params); }).then(response => { - this.downloadExcel(response, '租户.xls'); + this.$download.excel(response, '租户.xls'); this.exportLoading = false; }).catch(() => {}); } diff --git a/yudao-ui-admin/src/views/system/user/index.vue b/yudao-ui-admin/src/views/system/user/index.vue index be12d162..59f19ac3 100644 --- a/yudao-ui-admin/src/views/system/user/index.vue +++ b/yudao-ui-admin/src/views/system/user/index.vue @@ -585,7 +585,7 @@ export default { this.exportLoading = true; return exportUser(queryParams); }).then(response => { - this.downloadExcel(response, '用户数据.xls'); + this.$download.excel(response, '用户数据.xls'); this.exportLoading = false; }).catch(() => {}); }, @@ -597,7 +597,7 @@ export default { /** 下载模板操作 */ importTemplate() { importTemplate().then(response => { - this.downloadExcel(response, '用户导入模板.xls'); + this.$download.excel(response, '用户导入模板.xls'); }); }, // 文件上传中处理 diff --git a/yudao-ui-admin/src/views/tool/codegen/index.vue b/yudao-ui-admin/src/views/tool/codegen/index.vue index 97e08e95..4beb7d1f 100644 --- a/yudao-ui-admin/src/views/tool/codegen/index.vue +++ b/yudao-ui-admin/src/views/tool/codegen/index.vue @@ -192,7 +192,7 @@ export default { /** 生成代码操作 */ handleGenTable(row) { downloadCodegen(row.id).then(response => { - this.downloadZip(response, 'codegen-' + row.tableName + '.zip'); + this.$download.zip(response, 'codegen-' + row.tableName + '.zip'); }) }, /** 同步数据库操作 */ diff --git a/yudao-ui-admin/src/views/tool/dbDoc/index.vue b/yudao-ui-admin/src/views/tool/dbDoc/index.vue index c659df3a..a253b1c4 100644 --- a/yudao-ui-admin/src/views/tool/dbDoc/index.vue +++ b/yudao-ui-admin/src/views/tool/dbDoc/index.vue @@ -48,19 +48,19 @@ export default { /** 处理导出 HTML */ handleExportHtml() { exportHtml().then(response => { - this.downloadHtml(response, '数据库文档.html'); + this.$download.html(response, '数据库文档.html'); }) }, /** 处理导出 Word */ handleExportWord() { exportWord().then(response => { - this.downloadWord(response, '数据库文档.doc'); + this.$download.word(response, '数据库文档.doc'); }) }, /** 处理导出 Markdown */ handleExportMarkdown() { exportMarkdown().then(response => { - this.downloadMarkdown(response, '数据库文档.md'); + this.$download.markdown(response, '数据库文档.md'); }) } } diff --git a/yudao-ui-admin/src/views/tool/testDemo/index.vue b/yudao-ui-admin/src/views/tool/testDemo/index.vue index ae2dbfda..04ad668c 100755 --- a/yudao-ui-admin/src/views/tool/testDemo/index.vue +++ b/yudao-ui-admin/src/views/tool/testDemo/index.vue @@ -253,7 +253,7 @@ export default { this.exportLoading = true; return exportTestDemoExcel(params); }).then(response => { - this.downloadExcel(response, '字典类型.xls'); + this.$download.excel(response, '字典类型.xls'); this.exportLoading = false; }).catch(() => {}); } -- GitLab