Pārlūkot izejas kodu

优化导出数据操作

RuoYi 4 gadi atpakaļ
vecāks
revīzija
173c0e384f

+ 8 - 10
ruoyi-common/ruoyi-common-core/src/main/java/com/ruoyi/common/core/utils/poi/ExcelUtil.java

@@ -2,7 +2,6 @@ package com.ruoyi.common.core.utils.poi;
2 2
 
3 3
 import java.io.IOException;
4 4
 import java.io.InputStream;
5
-import java.io.OutputStream;
6 5
 import java.lang.reflect.Field;
7 6
 import java.lang.reflect.Method;
8 7
 import java.math.BigDecimal;
@@ -357,7 +356,7 @@ public class ExcelUtil<T>
357 356
      * @return 结果
358 357
      * @throws IOException
359 358
      */
360
-    public void exportExcel(HttpServletResponse response, List<T> list, String sheetName)throws IOException
359
+    public void exportExcel(HttpServletResponse response, List<T> list, String sheetName)
361 360
     {
362 361
         exportExcel(response, list, sheetName, StringUtils.EMPTY);
363 362
     }
@@ -372,12 +371,12 @@ public class ExcelUtil<T>
372 371
      * @return 结果
373 372
      * @throws IOException
374 373
      */
375
-    public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title) throws IOException
374
+    public void exportExcel(HttpServletResponse response, List<T> list, String sheetName, String title)
376 375
     {
377 376
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
378 377
         response.setCharacterEncoding("utf-8");
379 378
         this.init(list, sheetName, title, Type.EXPORT);
380
-        exportExcel(response.getOutputStream());
379
+        exportExcel(response);
381 380
     }
382 381
 
383 382
     /**
@@ -392,7 +391,7 @@ public class ExcelUtil<T>
392 391
      * @param sheetName 工作表的名称
393 392
      * @return 结果
394 393
      */
395
-    public void importTemplateExcel(HttpServletResponse response, String sheetName) throws IOException
394
+    public void importTemplateExcel(HttpServletResponse response, String sheetName)
396 395
     {
397 396
         importTemplateExcel(response, sheetName, StringUtils.EMPTY);
398 397
     }
@@ -404,12 +403,12 @@ public class ExcelUtil<T>
404 403
      * @param title 标题
405 404
      * @return 结果
406 405
      */
407
-    public void importTemplateExcel(HttpServletResponse response, String sheetName, String title) throws IOException
406
+    public void importTemplateExcel(HttpServletResponse response, String sheetName, String title)
408 407
     {
409 408
         response.setContentType("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
410 409
         response.setCharacterEncoding("utf-8");
411 410
         this.init(null, sheetName, title, Type.IMPORT);
412
-        exportExcel(response.getOutputStream());
411
+        exportExcel(response);
413 412
     }
414 413
 
415 414
     /**
@@ -417,12 +416,12 @@ public class ExcelUtil<T>
417 416
      * 
418 417
      * @return 结果
419 418
      */
420
-    public void exportExcel(OutputStream out)
419
+    public void exportExcel(HttpServletResponse response)
421 420
     {
422 421
         try
423 422
         {
424 423
             writeSheet();
425
-            wb.write(out);
424
+            wb.write(response.getOutputStream());
426 425
         }
427 426
         catch (Exception e)
428 427
         {
@@ -431,7 +430,6 @@ public class ExcelUtil<T>
431 430
         finally
432 431
         {
433 432
             IOUtils.closeQuietly(wb);
434
-            IOUtils.closeQuietly(out);
435 433
         }
436 434
     }
437 435
 

+ 1 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/java/controller.java.vm

@@ -64,7 +64,7 @@ public class ${ClassName}Controller extends BaseController
64 64
     @RequiresPermissions("${permissionPrefix}:export")
65 65
     @Log(title = "${functionName}", businessType = BusinessType.EXPORT)
66 66
     @PostMapping("/export")
67
-    public void export(HttpServletResponse response, ${ClassName} ${className}) throws IOException
67
+    public void export(HttpServletResponse response, ${ClassName} ${className})
68 68
     {
69 69
         List<${ClassName}> list = ${className}Service.select${ClassName}List(${className});
70 70
         ExcelUtil<${ClassName}> util = new ExcelUtil<${ClassName}>(${ClassName}.class);

+ 1 - 1
ruoyi-modules/ruoyi-gen/src/main/resources/vm/vue/index.vue.vm

@@ -561,7 +561,7 @@ export default {
561 561
     handleExport() {
562 562
       this.download('${moduleName}/${businessName}/export', {
563 563
         ...this.queryParams
564
-      }, `${moduleName}_${businessName}.xlsx`)
564
+      }, `${businessName}_#[[${new Date().getTime()}]]#.xlsx`)
565 565
     }
566 566
   }
567 567
 };

+ 1 - 2
ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/controller/SysJobController.java

@@ -1,6 +1,5 @@
1 1
 package com.ruoyi.job.controller;
2 2
 
3
-import java.io.IOException;
4 3
 import java.util.List;
5 4
 import javax.servlet.http.HttpServletResponse;
6 5
 import org.quartz.SchedulerException;
@@ -58,7 +57,7 @@ public class SysJobController extends BaseController
58 57
     @RequiresPermissions("monitor:job:export")
59 58
     @Log(title = "定时任务", businessType = BusinessType.EXPORT)
60 59
     @PostMapping("/export")
61
-    public void export(HttpServletResponse response, SysJob sysJob) throws IOException
60
+    public void export(HttpServletResponse response, SysJob sysJob)
62 61
     {
63 62
         List<SysJob> list = jobService.selectJobList(sysJob);
64 63
         ExcelUtil<SysJob> util = new ExcelUtil<SysJob>(SysJob.class);

+ 1 - 2
ruoyi-modules/ruoyi-job/src/main/java/com/ruoyi/job/controller/SysJobLogController.java

@@ -1,6 +1,5 @@
1 1
 package com.ruoyi.job.controller;
2 2
 
3
-import java.io.IOException;
4 3
 import java.util.List;
5 4
 import javax.servlet.http.HttpServletResponse;
6 5
 import org.springframework.beans.factory.annotation.Autowired;
@@ -50,7 +49,7 @@ public class SysJobLogController extends BaseController
50 49
     @RequiresPermissions("monitor:job:export")
51 50
     @Log(title = "任务调度日志", businessType = BusinessType.EXPORT)
52 51
     @PostMapping("/export")
53
-    public void export(HttpServletResponse response, SysJobLog sysJobLog) throws IOException
52
+    public void export(HttpServletResponse response, SysJobLog sysJobLog)
54 53
     {
55 54
         List<SysJobLog> list = jobLogService.selectJobLogList(sysJobLog);
56 55
         ExcelUtil<SysJobLog> util = new ExcelUtil<SysJobLog>(SysJobLog.class);

+ 1 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysConfigController.java

@@ -1,6 +1,5 @@
1 1
 package com.ruoyi.system.controller;
2 2
 
3
-import java.io.IOException;
4 3
 import java.util.List;
5 4
 import javax.servlet.http.HttpServletResponse;
6 5
 import org.springframework.beans.factory.annotation.Autowired;
@@ -52,7 +51,7 @@ public class SysConfigController extends BaseController
52 51
     @Log(title = "参数管理", businessType = BusinessType.EXPORT)
53 52
     @RequiresPermissions("system:config:export")
54 53
     @PostMapping("/export")
55
-    public void export(HttpServletResponse response, SysConfig config) throws IOException
54
+    public void export(HttpServletResponse response, SysConfig config)
56 55
     {
57 56
         List<SysConfig> list = configService.selectConfigList(config);
58 57
         ExcelUtil<SysConfig> util = new ExcelUtil<SysConfig>(SysConfig.class);

+ 1 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDictDataController.java

@@ -1,6 +1,5 @@
1 1
 package com.ruoyi.system.controller;
2 2
 
3
-import java.io.IOException;
4 3
 import java.util.ArrayList;
5 4
 import java.util.List;
6 5
 import javax.servlet.http.HttpServletResponse;
@@ -54,7 +53,7 @@ public class SysDictDataController extends BaseController
54 53
     @Log(title = "字典数据", businessType = BusinessType.EXPORT)
55 54
     @RequiresPermissions("system:dict:export")
56 55
     @PostMapping("/export")
57
-    public void export(HttpServletResponse response, SysDictData dictData) throws IOException
56
+    public void export(HttpServletResponse response, SysDictData dictData)
58 57
     {
59 58
         List<SysDictData> list = dictDataService.selectDictDataList(dictData);
60 59
         ExcelUtil<SysDictData> util = new ExcelUtil<SysDictData>(SysDictData.class);

+ 1 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysDictTypeController.java

@@ -1,6 +1,5 @@
1 1
 package com.ruoyi.system.controller;
2 2
 
3
-import java.io.IOException;
4 3
 import java.util.List;
5 4
 import javax.servlet.http.HttpServletResponse;
6 5
 import org.springframework.beans.factory.annotation.Autowired;
@@ -49,7 +48,7 @@ public class SysDictTypeController extends BaseController
49 48
     @Log(title = "字典类型", businessType = BusinessType.EXPORT)
50 49
     @RequiresPermissions("system:dict:export")
51 50
     @PostMapping("/export")
52
-    public void export(HttpServletResponse response, SysDictType dictType) throws IOException
51
+    public void export(HttpServletResponse response, SysDictType dictType)
53 52
     {
54 53
         List<SysDictType> list = dictTypeService.selectDictTypeList(dictType);
55 54
         ExcelUtil<SysDictType> util = new ExcelUtil<SysDictType>(SysDictType.class);

+ 1 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysLogininforController.java

@@ -1,6 +1,5 @@
1 1
 package com.ruoyi.system.controller;
2 2
 
3
-import java.io.IOException;
4 3
 import java.util.List;
5 4
 import javax.servlet.http.HttpServletResponse;
6 5
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,7 +45,7 @@ public class SysLogininforController extends BaseController
46 45
     @Log(title = "登录日志", businessType = BusinessType.EXPORT)
47 46
     @RequiresPermissions("system:logininfor:export")
48 47
     @PostMapping("/export")
49
-    public void export(HttpServletResponse response, SysLogininfor logininfor) throws IOException
48
+    public void export(HttpServletResponse response, SysLogininfor logininfor)
50 49
     {
51 50
         List<SysLogininfor> list = logininforService.selectLogininforList(logininfor);
52 51
         ExcelUtil<SysLogininfor> util = new ExcelUtil<SysLogininfor>(SysLogininfor.class);

+ 1 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysOperlogController.java

@@ -1,6 +1,5 @@
1 1
 package com.ruoyi.system.controller;
2 2
 
3
-import java.io.IOException;
4 3
 import java.util.List;
5 4
 import javax.servlet.http.HttpServletResponse;
6 5
 import org.springframework.beans.factory.annotation.Autowired;
@@ -46,7 +45,7 @@ public class SysOperlogController extends BaseController
46 45
     @Log(title = "操作日志", businessType = BusinessType.EXPORT)
47 46
     @RequiresPermissions("system:operlog:export")
48 47
     @PostMapping("/export")
49
-    public void export(HttpServletResponse response, SysOperLog operLog) throws IOException
48
+    public void export(HttpServletResponse response, SysOperLog operLog)
50 49
     {
51 50
         List<SysOperLog> list = operLogService.selectOperLogList(operLog);
52 51
         ExcelUtil<SysOperLog> util = new ExcelUtil<SysOperLog>(SysOperLog.class);

+ 1 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysPostController.java

@@ -1,6 +1,5 @@
1 1
 package com.ruoyi.system.controller;
2 2
 
3
-import java.io.IOException;
4 3
 import java.util.List;
5 4
 import javax.servlet.http.HttpServletResponse;
6 5
 import org.springframework.beans.factory.annotation.Autowired;
@@ -52,7 +51,7 @@ public class SysPostController extends BaseController
52 51
     @Log(title = "岗位管理", businessType = BusinessType.EXPORT)
53 52
     @RequiresPermissions("system:post:export")
54 53
     @PostMapping("/export")
55
-    public void export(HttpServletResponse response, SysPost post) throws IOException
54
+    public void export(HttpServletResponse response, SysPost post)
56 55
     {
57 56
         List<SysPost> list = postService.selectPostList(post);
58 57
         ExcelUtil<SysPost> util = new ExcelUtil<SysPost>(SysPost.class);

+ 1 - 2
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysRoleController.java

@@ -1,6 +1,5 @@
1 1
 package com.ruoyi.system.controller;
2 2
 
3
-import java.io.IOException;
4 3
 import java.util.List;
5 4
 import javax.servlet.http.HttpServletResponse;
6 5
 import org.springframework.beans.factory.annotation.Autowired;
@@ -55,7 +54,7 @@ public class SysRoleController extends BaseController
55 54
     @Log(title = "角色管理", businessType = BusinessType.EXPORT)
56 55
     @RequiresPermissions("system:role:export")
57 56
     @PostMapping("/export")
58
-    public void export(HttpServletResponse response, SysRole role) throws IOException
57
+    public void export(HttpServletResponse response, SysRole role)
59 58
     {
60 59
         List<SysRole> list = roleService.selectRoleList(role);
61 60
         ExcelUtil<SysRole> util = new ExcelUtil<SysRole>(SysRole.class);

+ 1 - 1
ruoyi-modules/ruoyi-system/src/main/java/com/ruoyi/system/controller/SysUserController.java

@@ -77,7 +77,7 @@ public class SysUserController extends BaseController
77 77
     @Log(title = "用户管理", businessType = BusinessType.EXPORT)
78 78
     @RequiresPermissions("system:user:export")
79 79
     @PostMapping("/export")
80
-    public void export(HttpServletResponse response, SysUser user) throws IOException
80
+    public void export(HttpServletResponse response, SysUser user)
81 81
     {
82 82
         List<SysUser> list = userService.selectUserList(user);
83 83
         ExcelUtil<SysUser> util = new ExcelUtil<SysUser>(SysUser.class);

+ 10 - 7
ruoyi-ui/src/utils/request.js

@@ -8,7 +8,7 @@ import { saveAs } from 'file-saver'
8 8
 
9 9
 let downloadLoadingInstance;
10 10
 
11
-axios.defaults.headers['Conntent-Type'] = 'application/json;charset=utf-8'
11
+axios.defaults.headers['Content-Type'] = 'application/json;charset=utf-8'
12 12
 // 创建axios实例
13 13
 const service = axios.create({
14 14
   // axios中请求配置有baseURL选项,表示请求URL公共部分
@@ -48,16 +48,19 @@ service.interceptors.response.use(res => {
48 48
       return res.data
49 49
     }
50 50
     if (code === 401) {
51
-      MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
51
+      let doms = document.getElementsByClassName('el-message-box')[0]
52
+      if(doms === undefined){
53
+        MessageBox.confirm('登录状态已过期,您可以继续留在该页面,或者重新登录', '系统提示', {
52 54
           confirmButtonText: '重新登录',
53 55
           cancelButtonText: '取消',
54 56
           type: 'warning'
55 57
         }
56
-      ).then(() => {
57
-        store.dispatch('LogOut').then(() => {
58
-          location.href = '/index';
59
-        })
60
-      }).catch(() => {});
58
+        ).then(() => {
59
+          store.dispatch('LogOut').then(() => {
60
+            location.href = '/index';
61
+          })
62
+        }).catch(() => {});
63
+      }
61 64
       return Promise.reject('无效的会话,或者会话已过期,请重新登录。')
62 65
     } else if (code === 500) {
63 66
       Message({

+ 0 - 7
ruoyi-ui/src/utils/ruoyi.js

@@ -3,8 +3,6 @@
3 3
  * Copyright (c) 2019 ruoyi
4 4
  */
5 5
 
6
-const baseURL = process.env.VUE_APP_BASE_API
7
-
8 6
 // 日期格式化
9 7
 export function parseTime(time, pattern) {
10 8
 	if (arguments.length === 0 || !time) {
@@ -95,11 +93,6 @@ export function selectDictLabels(datas, value, separator) {
95 93
 	return actions.join('').substring(0, actions.join('').length - 1);
96 94
 }
97 95
 
98
-// 通用下载方法
99
-export function download(fileName) {
100
-	window.location.href = baseURL + "/common/download?fileName=" + encodeURI(fileName) + "&delete=" + true;
101
-}
102
-
103 96
 // 字符串格式化(%s )
104 97
 export function sprintf(str) {
105 98
 	var args = arguments, flag = true, i = 1;

+ 1 - 1
ruoyi-ui/src/views/system/user/index.vue

@@ -653,7 +653,7 @@ export default {
653 653
     importTemplate() {
654 654
       this.download('system/user/importTemplate', {
655 655
         ...this.queryParams
656
-      }, `user_${new Date().getTime()}.xlsx`)
656
+      }, `user_template_${new Date().getTime()}.xlsx`)
657 657
     },
658 658
     // 文件上传中处理
659 659
     handleFileUploadProgress(event, file, fileList) {