Commit 02a0ab6d6d3c833c125419b95699a86df347e3d7
1 parent
fee6d00e
v3.8.0 新增通用方法简化下载使用
Showing
28 changed files
with
78 additions
and
90 deletions
yudao-module-tool/yudao-module-tool-impl/src/main/resources/codegen/vue/views/index.vue.vm
| ... | ... | @@ -390,7 +390,7 @@ export default { |
| 390 | 390 | this.exportLoading = true; |
| 391 | 391 | return export${simpleClassName}Excel(params); |
| 392 | 392 | }).then(response => { |
| 393 | - this.downloadExcel(response, '${table.classComment}.xls'); | |
| 393 | + this.$download.excel(response, '${table.classComment}.xls'); | |
| 394 | 394 | this.exportLoading = false; |
| 395 | 395 | }).catch(() => {}); |
| 396 | 396 | } | ... | ... |
yudao-ui-admin/src/main.js
| ... | ... | @@ -17,19 +17,7 @@ import './assets/icons' // icon |
| 17 | 17 | import './permission' // permission control |
| 18 | 18 | import { getDicts } from "@/api/system/dict/data"; |
| 19 | 19 | import { getConfigKey } from "@/api/infra/config"; |
| 20 | -import { | |
| 21 | - parseTime, | |
| 22 | - resetForm, | |
| 23 | - addDateRange, | |
| 24 | - addBeginAndEndTime, | |
| 25 | - download, | |
| 26 | - handleTree, | |
| 27 | - downloadExcel, | |
| 28 | - downloadWord, | |
| 29 | - downloadZip, | |
| 30 | - downloadHtml, | |
| 31 | - downloadMarkdown, | |
| 32 | -} from "@/utils/ruoyi"; | |
| 20 | +import { parseTime, resetForm, addDateRange, addBeginAndEndTime, handleTree} from "@/utils/ruoyi"; | |
| 33 | 21 | import Pagination from "@/components/Pagination"; |
| 34 | 22 | // 自定义表格工具扩展 |
| 35 | 23 | import RightToolbar from "@/components/RightToolbar" |
| ... | ... | @@ -49,12 +37,6 @@ Vue.prototype.getDictDatas = getDictDatas |
| 49 | 37 | Vue.prototype.getDictDatas2 = getDictDatas2 |
| 50 | 38 | Vue.prototype.getDictDataLabel = getDictDataLabel |
| 51 | 39 | Vue.prototype.DICT_TYPE = DICT_TYPE |
| 52 | -Vue.prototype.download = download | |
| 53 | -Vue.prototype.downloadExcel = downloadExcel | |
| 54 | -Vue.prototype.downloadWord = downloadWord | |
| 55 | -Vue.prototype.downloadHtml = downloadHtml | |
| 56 | -Vue.prototype.downloadMarkdown = downloadMarkdown | |
| 57 | -Vue.prototype.downloadZip = downloadZip | |
| 58 | 40 | Vue.prototype.handleTree = handleTree |
| 59 | 41 | |
| 60 | 42 | // 全局组件挂载 | ... | ... |
yudao-ui-admin/src/plugins/download.js
0 → 100644
| 1 | +import { saveAs } from 'file-saver' | |
| 2 | +import axios from 'axios' | |
| 3 | +import { getToken } from '@/utils/auth' | |
| 4 | + | |
| 5 | +const baseURL = process.env.VUE_APP_BASE_API | |
| 6 | + | |
| 7 | +export default { | |
| 8 | + // 下载 Excel 方法 | |
| 9 | + excel(data, fileName) { | |
| 10 | + this.download0(data, fileName, 'application/vnd.ms-excel'); | |
| 11 | + }, | |
| 12 | + | |
| 13 | + // 下载 Word 方法 | |
| 14 | + word(data, fileName) { | |
| 15 | + this.download0(data, fileName, 'application/msword'); | |
| 16 | + }, | |
| 17 | + | |
| 18 | + // 下载 Zip 方法 | |
| 19 | + zip(data, fileName) { | |
| 20 | + this.download0(data, fileName, 'application/zip'); | |
| 21 | + }, | |
| 22 | + | |
| 23 | + // 下载 Html 方法 | |
| 24 | + html(data, fileName) { | |
| 25 | + this.download0(data, fileName, 'text/html'); | |
| 26 | + }, | |
| 27 | + | |
| 28 | + // 下载 Markdown 方法 | |
| 29 | + markdown(data, fileName) { | |
| 30 | + this.download0(data, fileName, 'text/markdown'); | |
| 31 | + }, | |
| 32 | + | |
| 33 | + download0(data, fileName, mineType) { | |
| 34 | + // 创建 blob | |
| 35 | + let blob = new Blob([data], {type: mineType}); | |
| 36 | + // 创建 href 超链接,点击进行下载 | |
| 37 | + window.URL = window.URL || window.webkitURL; | |
| 38 | + let href = URL.createObjectURL(blob); | |
| 39 | + let downA = document.createElement("a"); | |
| 40 | + downA.href = href; | |
| 41 | + downA.download = fileName; | |
| 42 | + downA.click(); | |
| 43 | + // 销毁超连接 | |
| 44 | + window.URL.revokeObjectURL(href); | |
| 45 | + } | |
| 46 | + | |
| 47 | +} | ... | ... |
yudao-ui-admin/src/plugins/index.js
| 1 | 1 | import cache from './cache' |
| 2 | 2 | import modal from './modal' |
| 3 | +import download from './download' | |
| 3 | 4 | |
| 4 | 5 | export default { |
| 5 | 6 | install(Vue) { |
| ... | ... | @@ -7,5 +8,7 @@ export default { |
| 7 | 8 | Vue.prototype.$cache = cache |
| 8 | 9 | // 模态框对象 |
| 9 | 10 | Vue.prototype.$modal = modal |
| 11 | + // 下载文件 | |
| 12 | + Vue.prototype.$download = download | |
| 10 | 13 | } |
| 11 | 14 | } | ... | ... |
yudao-ui-admin/src/utils/ruoyi.js
| ... | ... | @@ -100,50 +100,6 @@ export function addBeginAndEndTime(params, dateRange, propName) { |
| 100 | 100 | return params; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | -// 通用下载方法 | |
| 104 | -export function download(fileName) { | |
| 105 | - window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true; | |
| 106 | -} | |
| 107 | - | |
| 108 | -// 下载 Excel 方法 | |
| 109 | -export function downloadExcel(data, fileName) { | |
| 110 | - download0(data, fileName, 'application/vnd.ms-excel'); | |
| 111 | -} | |
| 112 | - | |
| 113 | -// 下载 Word 方法 | |
| 114 | -export function downloadWord(data, fileName) { | |
| 115 | - download0(data, fileName, 'application/msword'); | |
| 116 | -} | |
| 117 | - | |
| 118 | -// 下载 Zip 方法 | |
| 119 | -export function downloadZip(data, fileName) { | |
| 120 | - download0(data, fileName, 'application/zip'); | |
| 121 | -} | |
| 122 | - | |
| 123 | -// 下载 Html 方法 | |
| 124 | -export function downloadHtml(data, fileName) { | |
| 125 | - download0(data, fileName, 'text/html'); | |
| 126 | -} | |
| 127 | - | |
| 128 | -// 下载 Markdown 方法 | |
| 129 | -export function downloadMarkdown(data, fileName) { | |
| 130 | - download0(data, fileName, 'text/markdown'); | |
| 131 | -} | |
| 132 | - | |
| 133 | -function download0(data, fileName, mineType) { | |
| 134 | - // 创建 blob | |
| 135 | - let blob = new Blob([data], {type: mineType}); | |
| 136 | - // 创建 href 超链接,点击进行下载 | |
| 137 | - window.URL = window.URL || window.webkitURL; | |
| 138 | - let href = URL.createObjectURL(blob); | |
| 139 | - let downA = document.createElement("a"); | |
| 140 | - downA.href = href; | |
| 141 | - downA.download = fileName; | |
| 142 | - downA.click(); | |
| 143 | - // 销毁超连接 | |
| 144 | - window.URL.revokeObjectURL(href); | |
| 145 | -} | |
| 146 | - | |
| 147 | 103 | // 字符串格式化(%s ) |
| 148 | 104 | export function sprintf(str) { |
| 149 | 105 | var args = arguments, flag = true, i = 1; | ... | ... |
yudao-ui-admin/src/views/infra/apiAccessLog/index.vue
| ... | ... | @@ -206,7 +206,7 @@ export default { |
| 206 | 206 | this.exportLoading = true; |
| 207 | 207 | return exportApiAccessLogExcel(params); |
| 208 | 208 | }).then(response => { |
| 209 | - this.downloadExcel(response, 'API 访问日志.xls'); | |
| 209 | + this.$download.excel(response, 'API 访问日志.xls'); | |
| 210 | 210 | this.exportLoading = false; |
| 211 | 211 | }).catch(() => {}); |
| 212 | 212 | } | ... | ... |
yudao-ui-admin/src/views/infra/apiErrorLog/index.vue
| ... | ... | @@ -224,7 +224,7 @@ export default { |
| 224 | 224 | this.exportLoading = true; |
| 225 | 225 | return exportApiErrorLogExcel(params); |
| 226 | 226 | }).then(response => { |
| 227 | - this.downloadExcel(response, 'API 错误日志.xls'); | |
| 227 | + this.$download.excel(response, 'API 错误日志.xls'); | |
| 228 | 228 | this.exportLoading = false; |
| 229 | 229 | }).catch(() => {}); |
| 230 | 230 | } | ... | ... |
yudao-ui-admin/src/views/infra/config/index.vue
| ... | ... | @@ -268,7 +268,7 @@ export default { |
| 268 | 268 | this.exportLoading = true; |
| 269 | 269 | return exportConfig(queryParams); |
| 270 | 270 | }).then(response => { |
| 271 | - this.downloadExcel(response, '参数配置.xls'); | |
| 271 | + this.$download.excel(response, '参数配置.xls'); | |
| 272 | 272 | this.exportLoading = false; |
| 273 | 273 | }).catch(() => {}); |
| 274 | 274 | }, | ... | ... |
yudao-ui-admin/src/views/infra/job/index.vue
| ... | ... | @@ -367,7 +367,7 @@ export default { |
| 367 | 367 | this.exportLoading = true; |
| 368 | 368 | return exportJob(queryParams); |
| 369 | 369 | }).then(response => { |
| 370 | - this.downloadExcel(response, '定时任务.xls'); | |
| 370 | + this.$download.excel(response, '定时任务.xls'); | |
| 371 | 371 | this.exportLoading = false; |
| 372 | 372 | }).catch(() => {}); |
| 373 | 373 | } | ... | ... |
yudao-ui-admin/src/views/infra/job/log.vue
| ... | ... | @@ -169,7 +169,7 @@ export default { |
| 169 | 169 | this.exportLoading = true; |
| 170 | 170 | return exportJobLogExcel(params); |
| 171 | 171 | }).then(response => { |
| 172 | - this.downloadExcel(response, '定时任务日志.xls'); | |
| 172 | + this.$download.excel(response, '定时任务日志.xls'); | |
| 173 | 173 | this.exportLoading = false; |
| 174 | 174 | }).catch(() => {}); |
| 175 | 175 | } | ... | ... |
yudao-ui-admin/src/views/pay/app/index.vue
| ... | ... | @@ -417,7 +417,7 @@ export default { |
| 417 | 417 | this.$modal.confirm('是否确认导出所有支付应用信息数据项?').then(function () { |
| 418 | 418 | return exportAppExcel(params); |
| 419 | 419 | }).then(response => { |
| 420 | - this.downloadExcel(response, '支付应用信息.xls'); | |
| 420 | + this.$download.excel(response, '支付应用信息.xls'); | |
| 421 | 421 | }).catch(() => {}); |
| 422 | 422 | }, |
| 423 | 423 | /** | ... | ... |
yudao-ui-admin/src/views/pay/merchant/index.vue
| ... | ... | @@ -279,7 +279,7 @@ export default { |
| 279 | 279 | this.exportLoading = true; |
| 280 | 280 | return exportMerchantExcel(params); |
| 281 | 281 | }).then(response => { |
| 282 | - this.downloadExcel(response, '支付商户信息.xls'); | |
| 282 | + this.$download.excel(response, '支付商户信息.xls'); | |
| 283 | 283 | this.exportLoading = false; |
| 284 | 284 | }).catch(() => {}); |
| 285 | 285 | } | ... | ... |
yudao-ui-admin/src/views/pay/order/index.vue
| ... | ... | @@ -423,7 +423,7 @@ export default { |
| 423 | 423 | this.$modal.confirm('是否确认导出所有支付订单数据项?').then(function () { |
| 424 | 424 | return exportOrderExcel(params); |
| 425 | 425 | }).then(response => { |
| 426 | - this.downloadExcel(response, '支付订单.xls'); | |
| 426 | + this.$download.excel(response, '支付订单.xls'); | |
| 427 | 427 | }).catch(() => {}); |
| 428 | 428 | }, |
| 429 | 429 | /** | ... | ... |
yudao-ui-admin/src/views/pay/refund/index.vue
| ... | ... | @@ -427,7 +427,7 @@ export default { |
| 427 | 427 | this.$modal.confirm('是否确认导出所有退款订单数据项?').then(function () { |
| 428 | 428 | return exportRefundExcel(params); |
| 429 | 429 | }).then(response => { |
| 430 | - this.downloadExcel(response, '退款订单.xls'); | |
| 430 | + this.$download.excel(response, '退款订单.xls'); | |
| 431 | 431 | }).catch(() => {}); |
| 432 | 432 | }, |
| 433 | 433 | /** | ... | ... |
yudao-ui-admin/src/views/system/dict/data.vue
| ... | ... | @@ -297,7 +297,7 @@ export default { |
| 297 | 297 | this.exportLoading = true; |
| 298 | 298 | return exportData(queryParams); |
| 299 | 299 | }).then(response => { |
| 300 | - this.downloadExcel(response, '字典数据.xls'); | |
| 300 | + this.$download.excel(response, '字典数据.xls'); | |
| 301 | 301 | this.exportLoading = false; |
| 302 | 302 | }).catch(() => {}); |
| 303 | 303 | } | ... | ... |
yudao-ui-admin/src/views/system/dict/index.vue
| ... | ... | @@ -250,7 +250,7 @@ export default { |
| 250 | 250 | this.exportLoading = true; |
| 251 | 251 | return exportType(params); |
| 252 | 252 | }).then(response => { |
| 253 | - this.downloadExcel(response, '字典类型.xls'); | |
| 253 | + this.$download.excel(response, '字典类型.xls'); | |
| 254 | 254 | this.exportLoading = false; |
| 255 | 255 | }).catch(() => {}); |
| 256 | 256 | } | ... | ... |
yudao-ui-admin/src/views/system/errorCode/index.vue
| ... | ... | @@ -243,7 +243,7 @@ export default { |
| 243 | 243 | this.exportLoading = true; |
| 244 | 244 | return exportErrorCodeExcel(params); |
| 245 | 245 | }).then(response => { |
| 246 | - this.downloadExcel(response, '错误码.xls'); | |
| 246 | + this.$download.excel(response, '错误码.xls'); | |
| 247 | 247 | this.exportLoading = false; |
| 248 | 248 | }).catch(() => {}); |
| 249 | 249 | } | ... | ... |
yudao-ui-admin/src/views/system/loginlog/index.vue
| ... | ... | @@ -126,7 +126,7 @@ export default { |
| 126 | 126 | this.exportLoading = true; |
| 127 | 127 | return exportLoginLog(queryParams); |
| 128 | 128 | }).then(response => { |
| 129 | - this.downloadExcel(response, '登录日志.xls'); | |
| 129 | + this.$download.excel(response, '登录日志.xls'); | |
| 130 | 130 | this.exportLoading = false; |
| 131 | 131 | }).catch(() => {}); |
| 132 | 132 | } | ... | ... |
yudao-ui-admin/src/views/system/operatelog/index.vue
| ... | ... | @@ -206,7 +206,7 @@ export default { |
| 206 | 206 | this.exportLoading = true; |
| 207 | 207 | return exportOperateLog(queryParams); |
| 208 | 208 | }).then(response => { |
| 209 | - this.downloadExcel(response, '操作日志.xls'); | |
| 209 | + this.$download.excel(response, '操作日志.xls'); | |
| 210 | 210 | this.exportLoading = false; |
| 211 | 211 | }).catch(() => {}); |
| 212 | 212 | } | ... | ... |
yudao-ui-admin/src/views/system/post/index.vue
| ... | ... | @@ -236,7 +236,7 @@ export default { |
| 236 | 236 | this.exportLoading = true; |
| 237 | 237 | return exportPost(queryParams); |
| 238 | 238 | }).then(response => { |
| 239 | - this.downloadExcel(response, '岗位数据.xls'); | |
| 239 | + this.$download.excel(response, '岗位数据.xls'); | |
| 240 | 240 | this.exportLoading = false; |
| 241 | 241 | }).catch(() => {}); |
| 242 | 242 | } | ... | ... |
yudao-ui-admin/src/views/system/role/index.vue
| ... | ... | @@ -497,7 +497,7 @@ export default { |
| 497 | 497 | this.exportLoading = true; |
| 498 | 498 | return exportRole(queryParams); |
| 499 | 499 | }).then(response => { |
| 500 | - this.downloadExcel(response, '角色数据.xls'); | |
| 500 | + this.$download.excel(response, '角色数据.xls'); | |
| 501 | 501 | this.exportLoading = false; |
| 502 | 502 | }).catch(() => {}); |
| 503 | 503 | } | ... | ... |
yudao-ui-admin/src/views/system/sms/smsLog.vue
| ... | ... | @@ -282,7 +282,7 @@ export default { |
| 282 | 282 | this.exportLoading = true; |
| 283 | 283 | return exportSmsLogExcel(params); |
| 284 | 284 | }).then(response => { |
| 285 | - this.downloadExcel(response, '短信日志.xls'); | |
| 285 | + this.$download.excel(response, '短信日志.xls'); | |
| 286 | 286 | this.exportLoading = false; |
| 287 | 287 | }).catch(() => {}); |
| 288 | 288 | }, | ... | ... |
yudao-ui-admin/src/views/system/sms/smsTemplate.vue
| ... | ... | @@ -334,7 +334,7 @@ export default { |
| 334 | 334 | this.exportLoading = true; |
| 335 | 335 | return exportSmsTemplateExcel(params); |
| 336 | 336 | }).then(response => { |
| 337 | - this.downloadExcel(response, '短信模板.xls'); | |
| 337 | + this.$download.excel(response, '短信模板.xls'); | |
| 338 | 338 | this.exportLoading = false; |
| 339 | 339 | }).catch(() => {}); |
| 340 | 340 | }, | ... | ... |
yudao-ui-admin/src/views/system/tenant/index.vue
| ... | ... | @@ -246,7 +246,7 @@ export default { |
| 246 | 246 | this.exportLoading = true; |
| 247 | 247 | return exportTenantExcel(params); |
| 248 | 248 | }).then(response => { |
| 249 | - this.downloadExcel(response, '租户.xls'); | |
| 249 | + this.$download.excel(response, '租户.xls'); | |
| 250 | 250 | this.exportLoading = false; |
| 251 | 251 | }).catch(() => {}); |
| 252 | 252 | } | ... | ... |
yudao-ui-admin/src/views/system/user/index.vue
| ... | ... | @@ -585,7 +585,7 @@ export default { |
| 585 | 585 | this.exportLoading = true; |
| 586 | 586 | return exportUser(queryParams); |
| 587 | 587 | }).then(response => { |
| 588 | - this.downloadExcel(response, '用户数据.xls'); | |
| 588 | + this.$download.excel(response, '用户数据.xls'); | |
| 589 | 589 | this.exportLoading = false; |
| 590 | 590 | }).catch(() => {}); |
| 591 | 591 | }, |
| ... | ... | @@ -597,7 +597,7 @@ export default { |
| 597 | 597 | /** 下载模板操作 */ |
| 598 | 598 | importTemplate() { |
| 599 | 599 | importTemplate().then(response => { |
| 600 | - this.downloadExcel(response, '用户导入模板.xls'); | |
| 600 | + this.$download.excel(response, '用户导入模板.xls'); | |
| 601 | 601 | }); |
| 602 | 602 | }, |
| 603 | 603 | // 文件上传中处理 | ... | ... |
yudao-ui-admin/src/views/tool/codegen/index.vue
| ... | ... | @@ -192,7 +192,7 @@ export default { |
| 192 | 192 | /** 生成代码操作 */ |
| 193 | 193 | handleGenTable(row) { |
| 194 | 194 | downloadCodegen(row.id).then(response => { |
| 195 | - this.downloadZip(response, 'codegen-' + row.tableName + '.zip'); | |
| 195 | + this.$download.zip(response, 'codegen-' + row.tableName + '.zip'); | |
| 196 | 196 | }) |
| 197 | 197 | }, |
| 198 | 198 | /** 同步数据库操作 */ | ... | ... |
yudao-ui-admin/src/views/tool/dbDoc/index.vue
| ... | ... | @@ -48,19 +48,19 @@ export default { |
| 48 | 48 | /** 处理导出 HTML */ |
| 49 | 49 | handleExportHtml() { |
| 50 | 50 | exportHtml().then(response => { |
| 51 | - this.downloadHtml(response, '数据库文档.html'); | |
| 51 | + this.$download.html(response, '数据库文档.html'); | |
| 52 | 52 | }) |
| 53 | 53 | }, |
| 54 | 54 | /** 处理导出 Word */ |
| 55 | 55 | handleExportWord() { |
| 56 | 56 | exportWord().then(response => { |
| 57 | - this.downloadWord(response, '数据库文档.doc'); | |
| 57 | + this.$download.word(response, '数据库文档.doc'); | |
| 58 | 58 | }) |
| 59 | 59 | }, |
| 60 | 60 | /** 处理导出 Markdown */ |
| 61 | 61 | handleExportMarkdown() { |
| 62 | 62 | exportMarkdown().then(response => { |
| 63 | - this.downloadMarkdown(response, '数据库文档.md'); | |
| 63 | + this.$download.markdown(response, '数据库文档.md'); | |
| 64 | 64 | }) |
| 65 | 65 | } |
| 66 | 66 | } | ... | ... |
yudao-ui-admin/src/views/tool/testDemo/index.vue
| ... | ... | @@ -253,7 +253,7 @@ export default { |
| 253 | 253 | this.exportLoading = true; |
| 254 | 254 | return exportTestDemoExcel(params); |
| 255 | 255 | }).then(response => { |
| 256 | - this.downloadExcel(response, '字典类型.xls'); | |
| 256 | + this.$download.excel(response, '字典类型.xls'); | |
| 257 | 257 | this.exportLoading = false; |
| 258 | 258 | }).catch(() => {}); |
| 259 | 259 | } | ... | ... |