From 891e4e3f94a51786da022e7d8d9a6b9eeda8ec5d Mon Sep 17 00:00:00 2001 From: fengshuonan Date: Fri, 1 Jan 2021 22:42:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B4=E7=90=86=E4=B8=AA=E4=BA=BA=E4=BF=A1?= =?UTF-8?q?=E6=81=AF=E7=95=8C=E9=9D=A2=E7=9A=84=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../expand/module/HttpRequest/HttpRequest.js | 13 +++++++++- .../frame/{user_info.js => personal_info.js} | 26 +++++++++---------- .../pages/modular/index/personal_info.html | 6 ++--- 3 files changed, 28 insertions(+), 17 deletions(-) rename src/main/webapp/assets/modular/frame/{user_info.js => personal_info.js} (55%) diff --git a/src/main/webapp/assets/expand/module/HttpRequest/HttpRequest.js b/src/main/webapp/assets/expand/module/HttpRequest/HttpRequest.js index 4704dabb..a550d304 100644 --- a/src/main/webapp/assets/expand/module/HttpRequest/HttpRequest.js +++ b/src/main/webapp/assets/expand/module/HttpRequest/HttpRequest.js @@ -107,11 +107,22 @@ layui.define(['jquery'], function (exports) { * * 此参数组装的是param方式传参的参数,如需传递json请用 setJsonData(data) * + * 如果只传了一个key,则key可以是object类型,会将object所有属性都set上 + * * @param key 参数的key * @param value 参数值 */ set: function (key, value) { - this.dataObject[key] = (typeof value === "undefined") ? $("#" + key).val() : value; + if (typeof key === "object") { + // 遍历object的属性 + for (var item in key) { + if (typeof item != "function") { + this.dataObject[item] = key[item]; + } + } + } else { + this.dataObject[key] = (typeof value === "undefined") ? $("#" + key).val() : value; + } return this; }, diff --git a/src/main/webapp/assets/modular/frame/user_info.js b/src/main/webapp/assets/modular/frame/personal_info.js similarity index 55% rename from src/main/webapp/assets/modular/frame/user_info.js rename to src/main/webapp/assets/modular/frame/personal_info.js index 764d73e8..20107fa0 100644 --- a/src/main/webapp/assets/modular/frame/user_info.js +++ b/src/main/webapp/assets/modular/frame/personal_info.js @@ -1,9 +1,9 @@ -layui.use(['form', 'upload', 'element', 'ax', 'laydate'], function () { +layui.use(['form', 'upload', 'element', 'HttpRequest', 'laydate'], function () { var $ = layui.jquery; var form = layui.form; var upload = layui.upload; var element = layui.element; - var $ax = layui.ax; + var HttpRequest = layui.HttpRequest; var laydate = layui.laydate; //渲染时间选择框 @@ -12,21 +12,21 @@ layui.use(['form', 'upload', 'element', 'ax', 'laydate'], function () { }); //获取用户详情 - var ajax = new $ax(Feng.ctxPath + "/system/currentUserInfo"); - var result = ajax.start(); + var request = new HttpRequest(Feng.ctxPath + "/sysUser/currentUserInfo", 'get'); + var result = request.start(); //用这个方法必须用在class有layui-form的元素上 form.val('userInfoForm', result.data); //表单提交事件 form.on('submit(userInfoSubmit)', function (data) { - var ajax = new $ax(Feng.ctxPath + "/mgr/edit", function (data) { + var updateUserInfoRequest = new HttpRequest(Feng.ctxPath + "/sysUser/updateInfo", 'post', function (data) { Feng.success("修改成功!"); - }, function (data) { - Feng.error("修改失败!" + data.responseJSON.message + "!"); + }, function (response) { + Feng.error("修改失败!" + response.message + "!"); }); - ajax.set(data.field); - ajax.start(); + updateUserInfoRequest.set(data.field); + updateUserInfoRequest.start(true); }); upload.render({ @@ -38,13 +38,13 @@ layui.use(['form', 'upload', 'element', 'ax', 'laydate'], function () { }); } , done: function (res) { - var ajax = new $ax(Feng.ctxPath + "/system/updateAvatar", function (data) { + var updateAvatarRequest = new HttpRequest(Feng.ctxPath + "/system/updateAvatar", function (data) { Feng.success(res.message); }, function (data) { - Feng.error("修改失败!" + data.responseJSON.message + "!"); + Feng.error("修改失败!" + data.message + "!"); }); - ajax.set("fileId", res.data.fileId); - ajax.start(); + updateAvatarRequest.set("fileId", res.data.fileId); + updateAvatarRequest.start(); } , error: function () { Feng.error("上传头像失败!"); diff --git a/src/main/webapp/pages/modular/index/personal_info.html b/src/main/webapp/pages/modular/index/personal_info.html index b32b079e..8fc30214 100644 --- a/src/main/webapp/pages/modular/index/personal_info.html +++ b/src/main/webapp/pages/modular/index/personal_info.html @@ -1,4 +1,4 @@ -@layout("/layout/_container.html", {title:"个人中心", css:["/assets/modular/frame/user_info.css"], js:["/assets/modular/frame/user_info.js"]}){ +@layout("/layout/_container.html", {title:"个人中心", css:["/assets/modular/frame/user_info.css"], js:["/assets/modular/frame/personal_info.js"]}){
个人信息 @@ -66,7 +66,7 @@
- +
@@ -81,7 +81,7 @@
- +