From cc35627ab19de15c2b63c8e8b3a4123d856386d2 Mon Sep 17 00:00:00 2001 From: Ricky <11748854@qq.com> Date: Wed, 26 Aug 2020 16:33:19 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0Ajax=E5=B1=80=E9=83=A8?= =?UTF-8?q?=E5=88=B7=E6=96=B0demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../demo/controller/DemoFormController.java | 45 ++++++++++++++ .../templates/demo/form/localrefresh.html | 61 +++++++++++++++++++ .../src/main/resources/templates/index.html | 1 + 3 files changed, 107 insertions(+) create mode 100644 ruoyi-admin/src/main/resources/templates/demo/form/localrefresh.html diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoFormController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoFormController.java index 8c2f38bad..5ab862046 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoFormController.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/demo/controller/DemoFormController.java @@ -5,11 +5,15 @@ import java.util.List; import org.springframework.stereotype.Controller; import org.springframework.ui.ModelMap; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; import com.alibaba.fastjson.JSON; import com.ruoyi.common.core.domain.AjaxResult; import com.ruoyi.common.core.domain.CxSelect; +import com.ruoyi.common.json.JSONObject; +import com.ruoyi.common.json.JSONObject.JSONArray; +import com.ruoyi.common.utils.StringUtils; /** * 表单相关 @@ -217,6 +221,47 @@ public class DemoFormController return prefix + "/cxselect"; } + /** + * 局部刷新 + */ + @GetMapping("/localrefresh") + public String localRefresh(ModelMap mmap) + { + JSONArray list = new JSONArray(); + JSONObject item = new JSONObject(); + item.put("name", "这条任务数据是由ModelMap传递到页面的,点击添加按钮后会将这条数据替换为新数据"); + item.put("type", "默认"); + item.put("date", "2020.06.10"); + list.add(item); + mmap.put("tasks",list); + mmap.put("min",2); + mmap.put("max",10); + return prefix + "/localrefresh"; + } + + /** + * 局部刷新-添加任务 + * @param fragment 页面中的模板名称 + * @param taskName 任务名称 + */ + @PostMapping("/localrefresh/task") + public String localRefreshTask(String fragment,String taskName,ModelMap mmap) + { + JSONArray list = new JSONArray(); + JSONObject item = new JSONObject(); + item.put("name", StringUtils.defaultIfBlank(taskName, "通过电话销售过程中了解各盛市的设备仪器使用、采购情况及相关重要追踪人")); + item.put("type", "新增"); + item.put("date", "2018.06.10"); + list.add(item); + item = new JSONObject(); + item.put("name", "提高自己电话营销技巧,灵活专业地与客户进行电话交流"); + item.put("type", "新增"); + item.put("date", "2018.06.12"); + list.add(item); + mmap.put("tasks",list); + return prefix + "/localrefresh::" + fragment; + } + /** * 模拟数据 */ diff --git a/ruoyi-admin/src/main/resources/templates/demo/form/localrefresh.html b/ruoyi-admin/src/main/resources/templates/demo/form/localrefresh.html new file mode 100644 index 000000000..d919fe68d --- /dev/null +++ b/ruoyi-admin/src/main/resources/templates/demo/form/localrefresh.html @@ -0,0 +1,61 @@ + + + + + + +
+
+
+
+
+

任务列表

+

+ + 点击刷新按钮刷新数据到列表中 +

+ +
+ + + + +
+
+ +
+
+
+
+
+
+ + + + diff --git a/ruoyi-admin/src/main/resources/templates/index.html b/ruoyi-admin/src/main/resources/templates/index.html index df01bc3cc..7e868c851 100644 --- a/ruoyi-admin/src/main/resources/templates/index.html +++ b/ruoyi-admin/src/main/resources/templates/index.html @@ -93,6 +93,7 @@
  • 左右互选组件
  • 搜索自动补全
  • 多级联动下拉
  • +
  • Ajax局部刷新
  • 表格