mirror of
				https://gitee.com/hhyykk/ipms-sjy.git
				synced 2025-10-31 02:08:43 +08:00 
			
		
		
		
	v3.8.0 新增通用方法简化下载使用
This commit is contained in:
		| @@ -390,7 +390,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return export${simpleClassName}Excel(params); |           return export${simpleClassName}Excel(params); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '${table.classComment}.xls'); |           this.$download.excel(response, '${table.classComment}.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|         }).catch(() => {}); |         }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -17,19 +17,7 @@ import './assets/icons' // icon | |||||||
| import './permission' // permission control | import './permission' // permission control | ||||||
| import { getDicts } from "@/api/system/dict/data"; | import { getDicts } from "@/api/system/dict/data"; | ||||||
| import { getConfigKey } from "@/api/infra/config"; | import { getConfigKey } from "@/api/infra/config"; | ||||||
| import { | import { parseTime, resetForm, addDateRange, addBeginAndEndTime, handleTree} from "@/utils/ruoyi"; | ||||||
|   parseTime, |  | ||||||
|   resetForm, |  | ||||||
|   addDateRange, |  | ||||||
|   addBeginAndEndTime, |  | ||||||
|   download, |  | ||||||
|   handleTree, |  | ||||||
|   downloadExcel, |  | ||||||
|   downloadWord, |  | ||||||
|   downloadZip, |  | ||||||
|   downloadHtml, |  | ||||||
|   downloadMarkdown, |  | ||||||
| } from "@/utils/ruoyi"; |  | ||||||
| import Pagination from "@/components/Pagination"; | import Pagination from "@/components/Pagination"; | ||||||
| // 自定义表格工具扩展 | // 自定义表格工具扩展 | ||||||
| import RightToolbar from "@/components/RightToolbar" | import RightToolbar from "@/components/RightToolbar" | ||||||
| @@ -49,12 +37,6 @@ Vue.prototype.getDictDatas = getDictDatas | |||||||
| Vue.prototype.getDictDatas2 = getDictDatas2 | Vue.prototype.getDictDatas2 = getDictDatas2 | ||||||
| Vue.prototype.getDictDataLabel = getDictDataLabel | Vue.prototype.getDictDataLabel = getDictDataLabel | ||||||
| Vue.prototype.DICT_TYPE = DICT_TYPE | 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 | Vue.prototype.handleTree = handleTree | ||||||
|  |  | ||||||
| // 全局组件挂载 | // 全局组件挂载 | ||||||
|   | |||||||
							
								
								
									
										47
									
								
								yudao-ui-admin/src/plugins/download.js
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								yudao-ui-admin/src/plugins/download.js
									
									
									
									
									
										Normal file
									
								
							| @@ -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); | ||||||
|  |   } | ||||||
|  |  | ||||||
|  | } | ||||||
| @@ -1,5 +1,6 @@ | |||||||
| import cache from './cache' | import cache from './cache' | ||||||
| import modal from './modal' | import modal from './modal' | ||||||
|  | import download from './download' | ||||||
|  |  | ||||||
| export default { | export default { | ||||||
|   install(Vue) { |   install(Vue) { | ||||||
| @@ -7,5 +8,7 @@ export default { | |||||||
|     Vue.prototype.$cache = cache |     Vue.prototype.$cache = cache | ||||||
|     // 模态框对象 |     // 模态框对象 | ||||||
|     Vue.prototype.$modal = modal |     Vue.prototype.$modal = modal | ||||||
|  |     // 下载文件 | ||||||
|  |     Vue.prototype.$download = download | ||||||
|   } |   } | ||||||
| } | } | ||||||
|   | |||||||
| @@ -100,50 +100,6 @@ export function addBeginAndEndTime(params, dateRange, propName) { | |||||||
|   return params; |   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 ) | // 字符串格式化(%s ) | ||||||
| export function sprintf(str) { | export function sprintf(str) { | ||||||
|   var args = arguments, flag = true, i = 1; |   var args = arguments, flag = true, i = 1; | ||||||
|   | |||||||
| @@ -206,7 +206,7 @@ export default { | |||||||
|         this.exportLoading = true; |         this.exportLoading = true; | ||||||
|         return exportApiAccessLogExcel(params); |         return exportApiAccessLogExcel(params); | ||||||
|       }).then(response => { |       }).then(response => { | ||||||
|         this.downloadExcel(response, 'API 访问日志.xls'); |         this.$download.excel(response, 'API 访问日志.xls'); | ||||||
|         this.exportLoading = false; |         this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -224,7 +224,7 @@ export default { | |||||||
|         this.exportLoading = true; |         this.exportLoading = true; | ||||||
|         return exportApiErrorLogExcel(params); |         return exportApiErrorLogExcel(params); | ||||||
|       }).then(response => { |       }).then(response => { | ||||||
|         this.downloadExcel(response, 'API 错误日志.xls'); |         this.$download.excel(response, 'API 错误日志.xls'); | ||||||
|         this.exportLoading = false; |         this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -268,7 +268,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportConfig(queryParams); |           return exportConfig(queryParams); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '参数配置.xls'); |           this.$download.excel(response, '参数配置.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     }, |     }, | ||||||
|   | |||||||
| @@ -367,7 +367,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportJob(queryParams); |           return exportJob(queryParams); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '定时任务.xls'); |           this.$download.excel(response, '定时任务.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -169,7 +169,7 @@ export default { | |||||||
|         this.exportLoading = true; |         this.exportLoading = true; | ||||||
|         return exportJobLogExcel(params); |         return exportJobLogExcel(params); | ||||||
|       }).then(response => { |       }).then(response => { | ||||||
|         this.downloadExcel(response, '定时任务日志.xls'); |         this.$download.excel(response, '定时任务日志.xls'); | ||||||
|         this.exportLoading = false; |         this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -417,7 +417,7 @@ export default { | |||||||
|       this.$modal.confirm('是否确认导出所有支付应用信息数据项?').then(function () { |       this.$modal.confirm('是否确认导出所有支付应用信息数据项?').then(function () { | ||||||
|         return exportAppExcel(params); |         return exportAppExcel(params); | ||||||
|       }).then(response => { |       }).then(response => { | ||||||
|         this.downloadExcel(response, '支付应用信息.xls'); |         this.$download.excel(response, '支付应用信息.xls'); | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     }, |     }, | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -279,7 +279,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportMerchantExcel(params); |           return exportMerchantExcel(params); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '支付商户信息.xls'); |           this.$download.excel(response, '支付商户信息.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -423,7 +423,7 @@ export default { | |||||||
|       this.$modal.confirm('是否确认导出所有支付订单数据项?').then(function () { |       this.$modal.confirm('是否确认导出所有支付订单数据项?').then(function () { | ||||||
|         return exportOrderExcel(params); |         return exportOrderExcel(params); | ||||||
|       }).then(response => { |       }).then(response => { | ||||||
|         this.downloadExcel(response, '支付订单.xls'); |         this.$download.excel(response, '支付订单.xls'); | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     }, |     }, | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -427,7 +427,7 @@ export default { | |||||||
|       this.$modal.confirm('是否确认导出所有退款订单数据项?').then(function () { |       this.$modal.confirm('是否确认导出所有退款订单数据项?').then(function () { | ||||||
|         return exportRefundExcel(params); |         return exportRefundExcel(params); | ||||||
|       }).then(response => { |       }).then(response => { | ||||||
|         this.downloadExcel(response, '退款订单.xls'); |         this.$download.excel(response, '退款订单.xls'); | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     }, |     }, | ||||||
|     /** |     /** | ||||||
|   | |||||||
| @@ -297,7 +297,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportData(queryParams); |           return exportData(queryParams); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '字典数据.xls'); |           this.$download.excel(response, '字典数据.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -250,7 +250,7 @@ export default { | |||||||
|         this.exportLoading = true; |         this.exportLoading = true; | ||||||
|         return exportType(params); |         return exportType(params); | ||||||
|       }).then(response => { |       }).then(response => { | ||||||
|         this.downloadExcel(response, '字典类型.xls'); |         this.$download.excel(response, '字典类型.xls'); | ||||||
|         this.exportLoading = false; |         this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -243,7 +243,7 @@ export default { | |||||||
|         this.exportLoading = true; |         this.exportLoading = true; | ||||||
|         return exportErrorCodeExcel(params); |         return exportErrorCodeExcel(params); | ||||||
|       }).then(response => { |       }).then(response => { | ||||||
|         this.downloadExcel(response, '错误码.xls'); |         this.$download.excel(response, '错误码.xls'); | ||||||
|         this.exportLoading = false; |         this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -126,7 +126,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportLoginLog(queryParams); |           return exportLoginLog(queryParams); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '登录日志.xls'); |           this.$download.excel(response, '登录日志.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -206,7 +206,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportOperateLog(queryParams); |           return exportOperateLog(queryParams); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '操作日志.xls'); |           this.$download.excel(response, '操作日志.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -236,7 +236,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportPost(queryParams); |           return exportPost(queryParams); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '岗位数据.xls'); |           this.$download.excel(response, '岗位数据.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -497,7 +497,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportRole(queryParams); |           return exportRole(queryParams); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '角色数据.xls'); |           this.$download.excel(response, '角色数据.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -282,7 +282,7 @@ export default { | |||||||
|         this.exportLoading = true; |         this.exportLoading = true; | ||||||
|         return exportSmsLogExcel(params); |         return exportSmsLogExcel(params); | ||||||
|       }).then(response => { |       }).then(response => { | ||||||
|         this.downloadExcel(response, '短信日志.xls'); |         this.$download.excel(response, '短信日志.xls'); | ||||||
|         this.exportLoading = false; |         this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     }, |     }, | ||||||
|   | |||||||
| @@ -334,7 +334,7 @@ export default { | |||||||
|         this.exportLoading = true; |         this.exportLoading = true; | ||||||
|         return exportSmsTemplateExcel(params); |         return exportSmsTemplateExcel(params); | ||||||
|       }).then(response => { |       }).then(response => { | ||||||
|         this.downloadExcel(response, '短信模板.xls'); |         this.$download.excel(response, '短信模板.xls'); | ||||||
|         this.exportLoading = false; |         this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     }, |     }, | ||||||
|   | |||||||
| @@ -246,7 +246,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportTenantExcel(params); |           return exportTenantExcel(params); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '租户.xls'); |           this.$download.excel(response, '租户.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
| @@ -585,7 +585,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportUser(queryParams); |           return exportUser(queryParams); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '用户数据.xls'); |           this.$download.excel(response, '用户数据.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     }, |     }, | ||||||
| @@ -597,7 +597,7 @@ export default { | |||||||
|     /** 下载模板操作 */ |     /** 下载模板操作 */ | ||||||
|     importTemplate() { |     importTemplate() { | ||||||
|       importTemplate().then(response => { |       importTemplate().then(response => { | ||||||
|         this.downloadExcel(response, '用户导入模板.xls'); |         this.$download.excel(response, '用户导入模板.xls'); | ||||||
|       }); |       }); | ||||||
|     }, |     }, | ||||||
|     // 文件上传中处理 |     // 文件上传中处理 | ||||||
|   | |||||||
| @@ -192,7 +192,7 @@ export default { | |||||||
|     /** 生成代码操作 */ |     /** 生成代码操作 */ | ||||||
|     handleGenTable(row) { |     handleGenTable(row) { | ||||||
|       downloadCodegen(row.id).then(response => { |       downloadCodegen(row.id).then(response => { | ||||||
|         this.downloadZip(response, 'codegen-' + row.tableName + '.zip'); |         this.$download.zip(response, 'codegen-' + row.tableName + '.zip'); | ||||||
|       }) |       }) | ||||||
|     }, |     }, | ||||||
|     /** 同步数据库操作 */ |     /** 同步数据库操作 */ | ||||||
|   | |||||||
| @@ -48,19 +48,19 @@ export default { | |||||||
|     /** 处理导出 HTML */ |     /** 处理导出 HTML */ | ||||||
|     handleExportHtml() { |     handleExportHtml() { | ||||||
|       exportHtml().then(response => { |       exportHtml().then(response => { | ||||||
|         this.downloadHtml(response, '数据库文档.html'); |         this.$download.html(response, '数据库文档.html'); | ||||||
|       }) |       }) | ||||||
|     }, |     }, | ||||||
|     /** 处理导出 Word */ |     /** 处理导出 Word */ | ||||||
|     handleExportWord() { |     handleExportWord() { | ||||||
|       exportWord().then(response => { |       exportWord().then(response => { | ||||||
|         this.downloadWord(response, '数据库文档.doc'); |         this.$download.word(response, '数据库文档.doc'); | ||||||
|       }) |       }) | ||||||
|     }, |     }, | ||||||
|     /** 处理导出 Markdown */ |     /** 处理导出 Markdown */ | ||||||
|     handleExportMarkdown() { |     handleExportMarkdown() { | ||||||
|       exportMarkdown().then(response => { |       exportMarkdown().then(response => { | ||||||
|         this.downloadMarkdown(response, '数据库文档.md'); |         this.$download.markdown(response, '数据库文档.md'); | ||||||
|       }) |       }) | ||||||
|     } |     } | ||||||
|   } |   } | ||||||
|   | |||||||
| @@ -253,7 +253,7 @@ export default { | |||||||
|           this.exportLoading = true; |           this.exportLoading = true; | ||||||
|           return exportTestDemoExcel(params); |           return exportTestDemoExcel(params); | ||||||
|         }).then(response => { |         }).then(response => { | ||||||
|           this.downloadExcel(response, '字典类型.xls'); |           this.$download.excel(response, '字典类型.xls'); | ||||||
|           this.exportLoading = false; |           this.exportLoading = false; | ||||||
|       }).catch(() => {}); |       }).catch(() => {}); | ||||||
|     } |     } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 YunaiV
					YunaiV