| | |
| | | const handleExport = async () => { |
| | | const hide = message.loading('正在导出'); |
| | | try { |
| | | await Http.doPost('api/role/export'); |
| | | const resp = await Http.doPostBlob('api/role/export'); |
| | | const blob = new Blob([resp], {type: 'application/vnd.ms-excel'}); |
| | | window.location.href = window.URL.createObjectURL(blob); |
| | | hide(); |
| | | message.success('导出成功'); |
| | | return true; |
| | |
| | | return res; |
| | | } |
| | | |
| | | const doPostBlob = async (url, params, fn) => { |
| | | const res = await request(url, { |
| | | method: 'POST', |
| | | headers: { |
| | | 'Content-Type': 'application/json' |
| | | }, |
| | | data: { ...params }, |
| | | responseType: 'blob' |
| | | }); |
| | | if (fn) { |
| | | fn(res); |
| | | } |
| | | return res; |
| | | } |
| | | |
| | | const doPostPromise = (url, params, fn) => { |
| | | return request(url, { |
| | | method: 'POST', |
| | |
| | | }); |
| | | } |
| | | |
| | | const Http = { doGet, doGetPromise, doPost, doPostForm, doPostPromise } |
| | | const Http = { doGet, doGetPromise, doPost, doPostForm, doPostPromise, doPostBlob } |
| | | |
| | | export default Http; |
| | |
| | | response.reset(); |
| | | Utils.cors(response); |
| | | response.setContentType("application/octet-stream; charset=utf-8"); |
| | | response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("Role.xls", "UTF-8")); |
| | | response.setHeader("Content-Disposition", "attachment; filename=" + URLEncoder.encode("export", "UTF-8")); |
| | | workbook.write(response.getOutputStream()); |
| | | } finally { |
| | | workbook.close(); |