From 05dd2520b659b2958110ca7e3f24ade9f9345131 Mon Sep 17 00:00:00 2001 From: RuoYi Date: Thu, 8 Apr 2021 11:26:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E7=A4=BA=E4=BE=8B=EF=BC=88?= =?UTF-8?q?=E5=AF=BC=E5=87=BA=E9=80=89=E6=8B=A9=E5=88=97=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/controller/DemoTableController.java | 47 +++++++ .../templates/demo/table/exportSelected.html | 120 ++++++++++++++++++ .../resources/templates/index-topnav.html | 1 + .../src/main/resources/templates/index.html | 1 + 4 files changed, 169 insertions(+) create mode 100644 ruoyi-admin/src/main/resources/templates/demo/table/exportSelected.html diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoTableController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoTableController.java index 61cdcd73b..e110ec3c6 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoTableController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoTableController.java @@ -12,13 +12,17 @@ import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.fasterxml.jackson.annotation.JsonFormat; +import com.ruoyi.common.annotation.Excel; +import com.ruoyi.common.annotation.Excel.ColumnType; import com.ruoyi.common.core.controller.BaseController; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.page.PageDomain; import com.ruoyi.common.core.page.TableDataInfo; import com.ruoyi.common.core.page.TableSupport; +import com.ruoyi.common.core.text.Convert; import com.ruoyi.common.utils.DateUtils; import com.ruoyi.common.utils.StringUtils; +import com.ruoyi.common.utils.poi.ExcelUtil; /** * 表格相关 @@ -107,6 +111,44 @@ public class DemoTableController extends BaseController return prefix + "/export"; } + /** + * 表格导出选择列 + */ + @GetMapping("/exportSelected") + public String exportSelected() + { + return prefix + "/exportSelected"; + } + + /** + * 导出数据 + */ + @PostMapping("/exportData") + @ResponseBody + public AjaxResult exportSelected(UserTableModel userModel, String userIds) + { + List userList = new ArrayList(Arrays.asList(new UserTableModel[users.size()])); + Collections.copy(userList, users); + + // 条件过滤 + if (StringUtils.isNotEmpty(userIds)) + { + userList.clear(); + for (Long userId : Convert.toLongArray(userIds)) + { + for (UserTableModel user : users) + { + if (user.getUserId() == userId) + { + userList.add(user); + } + } + } + } + ExcelUtil util = new ExcelUtil(UserTableModel.class); + return util.exportExcel(userList, "用户数据"); + } + /** * 翻页记住选择 */ @@ -399,21 +441,26 @@ class UserTableModel private int userId; /** 用户编号 */ + @Excel(name = "用户编号", cellType = ColumnType.NUMERIC) private String userCode; /** 用户姓名 */ + @Excel(name = "用户姓名") private String userName; /** 用户性别 */ private String userSex; /** 用户手机 */ + @Excel(name = "用户手机") private String userPhone; /** 用户邮箱 */ + @Excel(name = "用户邮箱") private String userEmail; /** 用户余额 */ + @Excel(name = "用户余额", cellType = ColumnType.NUMERIC) private double userBalance; /** 用户状态(0正常 1停用) */ diff --git a/ruoyi-admin/src/main/resources/templates/demo/table/exportSelected.html b/ruoyi-admin/src/main/resources/templates/demo/table/exportSelected.html new file mode 100644 index 000000000..4aec88df4 --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/demo/table/exportSelected.html @@ -0,0 +1,120 @@ + + + + + + +
+
+
+
+
+ +
+
+
+
+ 勾选数据导出指定列,否则为全部 + + 导出 + +
+
+
+
+
+
+
+ + + \ No newline at end of file diff --git a/ruoyi-admin/src/main/resources/templates/index-topnav.html b/ruoyi-admin/src/main/resources/templates/index-topnav.html index b30a98668..7d361330a 100644 --- a/ruoyi-admin/src/main/resources/templates/index-topnav.html +++ b/ruoyi-admin/src/main/resources/templates/index-topnav.html @@ -123,6 +123,7 @@
  • 数据汇总
  • 组合表头
  • 表格导出
  • +
  • 导出选择列
  • 翻页记住选择
  • 跳转至指定页
  • 自定义查询参数
  • diff --git a/ruoyi-admin/src/main/resources/templates/index.html b/ruoyi-admin/src/main/resources/templates/index.html index 084dd9e48..7bb34e4fe 100644 --- a/ruoyi-admin/src/main/resources/templates/index.html +++ b/ruoyi-admin/src/main/resources/templates/index.html @@ -104,6 +104,7 @@
  • 数据汇总
  • 组合表头
  • 表格导出
  • +
  • 导出选择列
  • 翻页记住选择
  • 跳转至指定页
  • 自定义查询参数