From 4b417b264143d549eac9960879dbbeafdadd64fc Mon Sep 17 00:00:00 2001 From: liyuan Date: Fri, 27 Sep 2019 10:24:55 +0800 Subject: [PATCH 1/4] =?UTF-8?q?1=20=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/dev/framework/util/ShiroUtils.java | 2 +- .../dev/web/controller/BbsUserController.java | 58 +++++++++++++++---- .../controller/safe/SafeUserController.java | 25 ++++---- .../main/resources/static/fly/mods/user.js | 16 +++-- 4 files changed, 73 insertions(+), 28 deletions(-) diff --git a/dev-web/dev-web-bbs/src/main/java/com/dev/framework/util/ShiroUtils.java b/dev-web/dev-web-bbs/src/main/java/com/dev/framework/util/ShiroUtils.java index 8b7f58d..58cc4ff 100644 --- a/dev-web/dev-web-bbs/src/main/java/com/dev/framework/util/ShiroUtils.java +++ b/dev-web/dev-web-bbs/src/main/java/com/dev/framework/util/ShiroUtils.java @@ -47,7 +47,7 @@ public class ShiroUtils return user; } - public static void setSysUser(BbsUser user) + public static void setBbsUser(BbsUser user) { Subject subject = getSubject(); PrincipalCollection principalCollection = subject.getPrincipals(); diff --git a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java index 4d7a5bb..a64a3f6 100644 --- a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java +++ b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java @@ -1,8 +1,19 @@ package com.dev.web.controller; -import java.util.List; - +import com.dev.bbs.domain.BbsUser; +import com.dev.bbs.service.IBbsUserService; +import com.dev.common.annotation.Log; +import com.dev.common.config.Global; +import com.dev.common.core.controller.BaseController; +import com.dev.common.core.domain.AjaxResult; +import com.dev.common.core.page.TableDataInfo; +import com.dev.common.enums.BusinessType; +import com.dev.common.utils.file.FileUploadUtils; +import com.dev.common.utils.poi.ExcelUtil; +import com.dev.framework.util.ShiroUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -11,16 +22,11 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; -import com.dev.bbs.domain.BbsUser; -import com.dev.bbs.service.IBbsUserService; -import com.dev.common.annotation.Log; -import com.dev.common.core.controller.BaseController; -import com.dev.common.core.domain.AjaxResult; -import com.dev.common.core.page.TableDataInfo; -import com.dev.common.enums.BusinessType; -import com.dev.common.utils.poi.ExcelUtil; +import java.util.List; /** * 社区用户Controller @@ -32,6 +38,8 @@ import com.dev.common.utils.poi.ExcelUtil; @RequestMapping("user") public class BbsUserController extends BaseController { + private static final Logger log = LoggerFactory.getLogger(BbsUserController.class); + private String prefix = "user"; @Autowired @@ -133,4 +141,34 @@ public class BbsUserController extends BaseController { return toAjax(bbsUserService.deleteBbsUserByIds(ids)); } + + /** + * 保存头像 + */ + @Log(title = "个人信息", businessType = BusinessType.UPDATE) + @PostMapping("/upload") + @ResponseBody + public AjaxResult updateAvatar(@RequestParam("file") MultipartFile file) + { + BbsUser user = ShiroUtils.getBbsUser(); + try + { + if (!file.isEmpty()) + { + String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file); + user.setAvatar(avatar); + if (bbsUserService.updateBbsUser(user) > 0) + { + ShiroUtils.setBbsUser(bbsUserService.selectBbsUserById(user.getUserId())); + return success(); + } + } + return error(); + } + catch (Exception e) + { + log.error("修改头像失败!", e); + return error(e.getMessage()); + } + } } diff --git a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java index c9028e5..ecd7f25 100644 --- a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java +++ b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java @@ -5,17 +5,6 @@ */ package com.dev.web.controller.safe; -import javax.servlet.http.HttpServletRequest; - -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Controller; -import org.springframework.ui.Model; -import org.springframework.validation.annotation.Validated; -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.dev.bbs.bean.BbsSignInfo; import com.dev.bbs.domain.BbsUser; import com.dev.bbs.form.UserForm; @@ -28,6 +17,16 @@ import com.dev.common.core.domain.AjaxResult; import com.dev.common.enums.BusinessType; import com.dev.framework.shiro.service.BbsPasswordService; import com.dev.framework.util.ShiroUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Controller; +import org.springframework.ui.Model; +import org.springframework.validation.annotation.Validated; +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 javax.servlet.http.HttpServletRequest; /** *

File:SafeUserController.java

@@ -107,7 +106,7 @@ public class SafeUserController extends BaseController { bbsUser = bbsUserService.selectBbsUserById(bbsUser.getUserId()); request.getSession().setAttribute(ShiroConstants.CURRENT_USER, bbsUser); - ShiroUtils.setSysUser(bbsUser); + ShiroUtils.setBbsUser(bbsUser); return success(); } return error("更新失败"); @@ -136,7 +135,7 @@ public class SafeUserController extends BaseController passwordService.encryptPassword(bbsUser.getUsername(), userForm.getNewpass(), bbsUser.getSalt())); if (bbsUserService.resetUserPwd(bbsUser) > 0) { - ShiroUtils.setSysUser(bbsUserService.selectBbsUserById(bbsUser.getUserId())); + ShiroUtils.setBbsUser(bbsUserService.selectBbsUserById(bbsUser.getUserId())); return success(); } return error(); diff --git a/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js b/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js index 4282946..2b30e20 100644 --- a/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js +++ b/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js @@ -192,7 +192,6 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function(exports){ if($('.upload-img')[0]){ layui.use('upload', function(upload){ var avatarAdd = $('.avatar-add'); - upload.render({ elem: '.upload-img' ,url: '/user/upload/' @@ -201,12 +200,21 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function(exports){ avatarAdd.find('.loading').show(); } ,done: function(res){ - if(res.status == 0){ - $.post('/user/set/', { + if(res.code == 0){ + /*$.post('/user/set/', { avatar: res.url }, function(res){ location.reload(); - }); + });*/ + //$.operate.saveSuccess(res); + layer.msg("保存成功,正在刷新数据请稍后……", { + icon: 1, + time: 500, + shade: [0.1, '#8F8F8F'] + }, + function() { + location.reload(); + }); } else { layer.msg(res.msg, {icon: 5}); } -- Gitee From c72cb816c6328e6f5b4b18d47e015346c7bff55b Mon Sep 17 00:00:00 2001 From: liyuan Date: Fri, 27 Sep 2019 10:54:31 +0800 Subject: [PATCH 2/4] =?UTF-8?q?1=20=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=A4=B4=E5=83=8F=20=20=E5=86=99=E5=9C=A8safe=E9=87=8C?= =?UTF-8?q?=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/web/controller/BbsUserController.java | 39 +- .../controller/safe/SafeUserController.java | 38 ++ .../main/resources/static/fly/mods/user.js | 604 +++++++++--------- 3 files changed, 353 insertions(+), 328 deletions(-) diff --git a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java index a64a3f6..7e96403 100644 --- a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java +++ b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java @@ -3,17 +3,12 @@ package com.dev.web.controller; import com.dev.bbs.domain.BbsUser; import com.dev.bbs.service.IBbsUserService; import com.dev.common.annotation.Log; -import com.dev.common.config.Global; import com.dev.common.core.controller.BaseController; import com.dev.common.core.domain.AjaxResult; import com.dev.common.core.page.TableDataInfo; import com.dev.common.enums.BusinessType; -import com.dev.common.utils.file.FileUploadUtils; import com.dev.common.utils.poi.ExcelUtil; -import com.dev.framework.util.ShiroUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -22,9 +17,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -38,7 +31,7 @@ import java.util.List; @RequestMapping("user") public class BbsUserController extends BaseController { - private static final Logger log = LoggerFactory.getLogger(BbsUserController.class); + private String prefix = "user"; @@ -142,33 +135,5 @@ public class BbsUserController extends BaseController return toAjax(bbsUserService.deleteBbsUserByIds(ids)); } - /** - * 保存头像 - */ - @Log(title = "个人信息", businessType = BusinessType.UPDATE) - @PostMapping("/upload") - @ResponseBody - public AjaxResult updateAvatar(@RequestParam("file") MultipartFile file) - { - BbsUser user = ShiroUtils.getBbsUser(); - try - { - if (!file.isEmpty()) - { - String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file); - user.setAvatar(avatar); - if (bbsUserService.updateBbsUser(user) > 0) - { - ShiroUtils.setBbsUser(bbsUserService.selectBbsUserById(user.getUserId())); - return success(); - } - } - return error(); - } - catch (Exception e) - { - log.error("修改头像失败!", e); - return error(e.getMessage()); - } - } + } diff --git a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java index ecd7f25..f1709b8 100644 --- a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java +++ b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java @@ -11,12 +11,16 @@ import com.dev.bbs.form.UserForm; import com.dev.bbs.service.IBbsUserService; import com.dev.bbs.service.IBbsUserSignService; import com.dev.common.annotation.Log; +import com.dev.common.config.Global; import com.dev.common.constant.ShiroConstants; import com.dev.common.core.controller.BaseController; import com.dev.common.core.domain.AjaxResult; import com.dev.common.enums.BusinessType; +import com.dev.common.utils.file.FileUploadUtils; import com.dev.framework.shiro.service.BbsPasswordService; import com.dev.framework.util.ShiroUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -24,7 +28,9 @@ import org.springframework.validation.annotation.Validated; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; @@ -41,6 +47,8 @@ import javax.servlet.http.HttpServletRequest; @RequestMapping("safe/user") public class SafeUserController extends BaseController { + private static final Logger log = LoggerFactory.getLogger(SafeUserController.class); + private String prefix = "safe/user"; @Autowired @@ -146,4 +154,34 @@ public class SafeUserController extends BaseController { return prefix + "/message"; } + + /** + * 保存头像 + */ + @Log(title = "个人信息", businessType = BusinessType.UPDATE) + @PostMapping("/upload") + @ResponseBody + public AjaxResult updateAvatar(@RequestParam("file") MultipartFile file) + { + BbsUser user = ShiroUtils.getBbsUser(); + try + { + if (!file.isEmpty()) + { + String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file); + user.setAvatar(avatar); + if (bbsUserService.updateBbsUser(user) > 0) + { + ShiroUtils.setBbsUser(bbsUserService.selectBbsUserById(user.getUserId())); + return success(); + } + } + return error(); + } + catch (Exception e) + { + log.error("修改头像失败!", e); + return error(e.getMessage()); + } + } } diff --git a/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js b/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js index 2b30e20..61485c8 100644 --- a/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js +++ b/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js @@ -3,270 +3,297 @@ @Name: 用户模块 */ - -layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function(exports){ - var $ = layui.jquery; - var layer = layui.layer; - var util = layui.util; - var laytpl = layui.laytpl; - var form = layui.form; - var laypage = layui.laypage; - var fly = layui.fly; - var flow = layui.flow; - var element = layui.element; - var upload = layui.upload; - var table = layui.table; +layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) { - //我发的贴 - if($('#LAY_mySendCard')[0]){ - var uid=$('#LAY_mySendCard').data("uid"); - table.render({ - elem: '#LAY_mySendCard' - ,url: '/article/list' - ,method: 'post' - ,where: { - author:uid - } - ,cols: [[ - {field: 'title', title: '帖子标题', minWidth: 200, templet: '
{{ d.title }}
'} - ,{field: 'status', title: '状态', width: 100, align: 'center', templet: function(d){ - if(d.status == 9){ - return '已结'; - } else if(d.status == 0){ - return '审核中'; - } else { - return '未结' - } - }} - ,{field: 'rec', title: '加精', width: 100, align: 'center', templet: function(d){ - return d.rec ? '' : '' - }} - ,{field: 'top', title: '置顶', width: 100, align: 'center', templet: function(d){ - return d.top ? '' : '' - }} - ,{field: 'createTime', title: '发表时间', width: 120, align: 'center', templet: '
{{ layui.util.timeAgo(d.createTime, 1) }}
'} - ,{title: '数据', width: 150, templet: '
{{d.views}}阅/{{d.comment}}答
'} - ,{title: '操作', width: 100, templet: function(d){ - return d.status != 9 ? '编辑' : '' - }} - ]] - ,page: true - ,skin: 'line' - }); - } - + var $ = layui.jquery; + var layer = layui.layer; + var util = layui.util; + var laytpl = layui.laytpl; + var form = layui.form; + var laypage = layui.laypage; + var fly = layui.fly; + var flow = layui.flow; + var element = layui.element; + var upload = layui.upload; + var table = layui.table; - //我收藏的帖 - if($('#LAY_myCollectioncard')[0]){ - table.render({ - elem: '#LAY_myCollectioncard' - ,url:'/safe/collect/list' - ,method: 'post' - ,where: { - orderByColumn:'createTime', - isAsc:'desc' - } - ,cols: [[ - {field: 'title', title: '帖子标题', minWidth: 300, templet: '
{{ d.title }}
'} - ,{title: '收藏时间', width: 120, align: 'center', templet: '
{{ layui.util.timeAgo(d.createTime, 1) }}
'} - ]] - ,page: true - ,skin: 'line' - }); - } - - //最近发帖 - var tplRenjie = ['{{# layui.each(d.rows, function(index, item){ }}' - ,'
  • ' - ,'{{# if(item.rec) { }}' - ,'' - ,'{{# } }}' - ,'{{item.title}}' - ,'{{layui.util.timeAgo(item.createTime,1)}}' - ,'{{item.views}}阅/{{item.comment}}答' - ,'
  • ' - ,'{{# }); }}'].join('') - ,recentlyJie = $('#recently-jie'); - - if(recentlyJie[0]){ - var uid = recentlyJie.data('uid'); - fly.json('/article/list/',{author:uid,pageNum:1,pageSize:10}, function(res){ - if(res.rows.length>0){ - var html = laytpl(tplRenjie).render(res); - recentlyJie.html(html); - } - }); - } - //最近回答 - var tplRenda = ['{{# layui.each(d.rows, function(index, item){ }}' - ,'
  • ' - ,'

    ' - ,'{{layui.util.timeAgo(item.createTime,1)}}{{item.artTitle}}中回答:' - ,'

    ' - ,'
    ' - ,'{{item.content}}' - ,'
    ' - ,'
  • ' - ,'{{# }); }}'].join('') - - ,recentlyDa = $('#recently-jieda'); - if(recentlyDa[0]){ - var uid = recentlyDa.data('uid'); - fly.json('/comment/list/',{author:uid,pageNum:1,pageSize:10}, function(res){ - if(res.rows.length>0){ - var html = laytpl(tplRenda).render(res); - recentlyDa.html(html); - } - }); - } + //我发的贴 + if ($('#LAY_mySendCard')[0]) { + var uid = $('#LAY_mySendCard').data("uid"); + table.render({ + elem: '#LAY_mySendCard' + , url: '/article/list' + , method: 'post' + , where: { + author: uid + } + , cols: [[ + { + field: 'title', + title: '帖子标题', + minWidth: 200, + templet: '
    {{ d.title }}
    ' + } + , { + field: 'status', title: '状态', width: 100, align: 'center', templet: function (d) { + if (d.status == 9) { + return '已结'; + } else if (d.status == 0) { + return '审核中'; + } else { + return '未结' + } + } + } + , { + field: 'rec', title: '加精', width: 100, align: 'center', templet: function (d) { + return d.rec ? '' : '' + } + } + , { + field: 'top', title: '置顶', width: 100, align: 'center', templet: function (d) { + return d.top ? '' : '' + } + } + , { + field: 'createTime', + title: '发表时间', + width: 120, + align: 'center', + templet: '
    {{ layui.util.timeAgo(d.createTime, 1) }}
    ' + } + , { + title: '数据', + width: 150, + templet: '
    {{d.views}}阅/{{d.comment}}答
    ' + } + , { + title: '操作', width: 100, templet: function (d) { + return d.status != 9 ? '编辑' : '' + } + } + ]] + , page: true + , skin: 'line' + }); + } - //显示当前tab - if(location.hash){ - element.tabChange('user', location.hash.replace(/^#/, '')); - } - element.on('tab(user)', function(){ - var othis = $(this), layid = othis.attr('lay-id'); - if(layid){ - location.hash = layid; + //我收藏的帖 + if ($('#LAY_myCollectioncard')[0]) { + table.render({ + elem: '#LAY_myCollectioncard' + , url: '/safe/collect/list' + , method: 'post' + , where: { + orderByColumn: 'createTime', + isAsc: 'desc' + } + , cols: [[ + { + field: 'title', + title: '帖子标题', + minWidth: 300, + templet: '
    {{ d.title }}
    ' + } + , { + title: '收藏时间', + width: 120, + align: 'center', + templet: '
    {{ layui.util.timeAgo(d.createTime, 1) }}
    ' + } + ]] + , page: true + , skin: 'line' + }); } - }); + //最近发帖 + var tplRenjie = ['{{# layui.each(d.rows, function(index, item){ }}' + , '
  • ' + , '{{# if(item.rec) { }}' + , '' + , '{{# } }}' + , '{{item.title}}' + , '{{layui.util.timeAgo(item.createTime,1)}}' + , '{{item.views}}阅/{{item.comment}}答' + , '
  • ' + , '{{# }); }}'].join('') + , recentlyJie = $('#recently-jie'); - var gather = {}, dom = { - mine: $('#LAY_mine') - ,mineview: $('.mine-view') - ,minemsg: $('#LAY_minemsg') - ,infobtn: $('#LAY_btninfo') - }; + if (recentlyJie[0]) { + var uid = recentlyJie.data('uid'); + fly.json('/article/list/', {author: uid, pageNum: 1, pageSize: 10}, function (res) { + if (res.rows.length > 0) { + var html = laytpl(tplRenjie).render(res); + recentlyJie.html(html); + } + }); + } + //最近回答 + var tplRenda = ['{{# layui.each(d.rows, function(index, item){ }}' + , '
  • ' + , '

    ' + , '{{layui.util.timeAgo(item.createTime,1)}}{{item.artTitle}}中回答:' + , '

    ' + , '
    ' + , '{{item.content}}' + , '
    ' + , '
  • ' + , '{{# }); }}'].join('') - //根据ip获取城市 -/* if($('#L_city').val() === ''){ - $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function(){ - $('#L_city').val(remote_ip_info.city||''); - }); - }*/ - - // 修改用户信息 - form.on('submit(userInfo)', function(data){ - $.ajax({ - type: 'post', - url: '/safe/user/info/edit', - data: data.field, - dataType: 'json', - success: function (data) { - if(data.code==0){ - location.reload(); - }else{ - layer.msg(data.msg, {icon: 2}); - } - } - }); - return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 - }); - // 修改用户信息 - form.on('submit(repass)', function(data){ - $.ajax({ - type: 'post', - url: '/safe/user/repass', - data: data.field, - dataType: 'json', - success: function (data) { - if(data.code==0){ - layer.msg(data.msg, {icon: 1}); - form.val("repass",{ - nowpass:'', - newpass:'', - repass:'', - }) - }else{ - layer.msg(data.msg, {icon: 2}); - } - } - }); - return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 - }); + , recentlyDa = $('#recently-jieda'); + if (recentlyDa[0]) { + var uid = recentlyDa.data('uid'); + fly.json('/comment/list/', {author: uid, pageNum: 1, pageSize: 10}, function (res) { + if (res.rows.length > 0) { + var html = laytpl(tplRenda).render(res); + recentlyDa.html(html); + } + }); + } - //上传图片 - if($('.upload-img')[0]){ - layui.use('upload', function(upload){ - var avatarAdd = $('.avatar-add'); - upload.render({ - elem: '.upload-img' - ,url: '/user/upload/' - ,size: 50 - ,before: function(){ - avatarAdd.find('.loading').show(); - } - ,done: function(res){ - if(res.code == 0){ - /*$.post('/user/set/', { - avatar: res.url - }, function(res){ - location.reload(); - });*/ - //$.operate.saveSuccess(res); - layer.msg("保存成功,正在刷新数据请稍后……", { - icon: 1, - time: 500, - shade: [0.1, '#8F8F8F'] - }, - function() { - location.reload(); - }); - } else { - layer.msg(res.msg, {icon: 5}); - } - avatarAdd.find('.loading').hide(); - } - ,error: function(){ - avatarAdd.find('.loading').hide(); + //显示当前tab + if (location.hash) { + element.tabChange('user', location.hash.replace(/^#/, '')); + } + + element.on('tab(user)', function () { + var othis = $(this), layid = othis.attr('lay-id'); + if (layid) { + location.hash = layid; } - }); }); - } - //提交成功后刷新 - fly.form['set-mine'] = function(data, required){ - layer.msg('修改成功', { - icon: 1 - ,time: 1000 - ,shade: 0.1 - }, function(){ - location.reload(); + + var gather = {}, dom = { + mine: $('#LAY_mine') + , mineview: $('.mine-view') + , minemsg: $('#LAY_minemsg') + , infobtn: $('#LAY_btninfo') + }; + + //根据ip获取城市 + /* if($('#L_city').val() === ''){ + $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function(){ + $('#L_city').val(remote_ip_info.city||''); + }); + }*/ + + // 修改用户信息 + form.on('submit(userInfo)', function (data) { + $.ajax({ + type: 'post', + url: '/safe/user/info/edit', + data: data.field, + dataType: 'json', + success: function (data) { + if (data.code == 0) { + location.reload(); + } else { + layer.msg(data.msg, {icon: 2}); + } + } + }); + return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 }); - } + // 修改用户信息 + form.on('submit(repass)', function (data) { + $.ajax({ + type: 'post', + url: '/safe/user/repass', + data: data.field, + dataType: 'json', + success: function (data) { + if (data.code == 0) { + layer.msg(data.msg, {icon: 1}); + form.val("repass", { + nowpass: '', + newpass: '', + repass: '', + }) + } else { + layer.msg(data.msg, {icon: 2}); + } + } + }); + return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 + }); + + //上传图片 + if ($('.upload-img')[0]) { + layui.use('upload', function (upload) { + var avatarAdd = $('.avatar-add'); + upload.render({ + elem: '.upload-img' + , url: '/safe/user/upload/' + , size: 50 + , before: function () { + avatarAdd.find('.loading').show(); + } + , done: function (res) { + if (res.code == 0) { + layer.msg("保存成功,正在刷新数据请稍后……", { + icon: 1, + time: 500, + shade: [0.1, '#8F8F8F'] + }, + function () { + location.reload(); + }); + } else { + layer.msg(res.msg, {icon: 5}); + } + avatarAdd.find('.loading').hide(); + } + , error: function () { + avatarAdd.find('.loading').hide(); + } + }); + }); + } - //帐号绑定 - $('.acc-unbind').on('click', function(){ - var othis = $(this), type = othis.attr('type'); - layer.confirm('确定要解绑'+ ({ - qq_id: 'QQ' - ,weibo_id: '微博' - })[type] + '吗?', {icon: 5}, function(){ - fly.json('/api/unbind', { - type: type - }, function(res){ - if(res.status === 0){ - layer.alert('已成功解绑。', { + //提交成功后刷新 + fly.form['set-mine'] = function (data, required) { + layer.msg('修改成功', { icon: 1 - ,end: function(){ - location.reload(); - } - }); - } else { - layer.msg(res.msg); - } - }); + , time: 1000 + , shade: 0.1 + }, function () { + location.reload(); + }); + } + + //帐号绑定 + $('.acc-unbind').on('click', function () { + var othis = $(this), type = othis.attr('type'); + layer.confirm('确定要解绑' + ({ + qq_id: 'QQ' + , weibo_id: '微博' + })[type] + '吗?', {icon: 5}, function () { + fly.json('/api/unbind', { + type: type + }, function (res) { + if (res.status === 0) { + layer.alert('已成功解绑。', { + icon: 1 + , end: function () { + location.reload(); + } + }); + } else { + layer.msg(res.msg); + } + }); + }); }); - }); - //我的消息 - gather.minemsg = function(){ - var delAll = $('#LAY_delallmsg') - ,tpl = '{{# var len = d.rows.length;\ + //我的消息 + gather.minemsg = function () { + var delAll = $('#LAY_delallmsg') + , tpl = '{{# var len = d.rows.length;\ if(len === 0){ }}\
    您暂时没有最新消息
    \ {{# } else { }}\ @@ -279,60 +306,55 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function(exports){ {{# } }}\ \ {{# } }}' - ,delEnd = function(clear){ - if(clear || dom.minemsg.find('.mine-msg li').length === 0){ - dom.minemsg.html('
    您暂时没有最新消息
    '); - } - } - - - fly.json('/message/find/', {}, function(res){ - var html = laytpl(tpl).render(res); - dom.minemsg.html(html); - if(res.rows.length > 0){ - delAll.removeClass('layui-hide'); - } - }); - - //阅读后删除 - dom.minemsg.on('click', '.mine-msg li .fly-delete', function(){ - var othis = $(this).parents('li'), id = othis.data('id'); - fly.json('/message/remove/', { - id: id - }, function(res){ - if(res.status === 0){ - othis.remove(); - delEnd(); + , delEnd = function (clear) { + if (clear || dom.minemsg.find('.mine-msg li').length === 0) { + dom.minemsg.html('
    您暂时没有最新消息
    '); + } } - }); - }); - //删除全部 - $('#LAY_delallmsg').on('click', function(){ - var othis = $(this); - layer.confirm('确定清空吗?', function(index){ - fly.json('/message/remove/', { - all: true - }, function(res){ - if(res.status === 0){ - layer.close(index); - othis.addClass('layui-hide'); - delEnd(true); - } - }); - }); - }); - }; + fly.json('/message/find/', {}, function (res) { + var html = laytpl(tpl).render(res); + dom.minemsg.html(html); + if (res.rows.length > 0) { + delAll.removeClass('layui-hide'); + } + }); - dom.minemsg[0] && gather.minemsg(); + //阅读后删除 + dom.minemsg.on('click', '.mine-msg li .fly-delete', function () { + var othis = $(this).parents('li'), id = othis.data('id'); + fly.json('/message/remove/', { + id: id + }, function (res) { + if (res.status === 0) { + othis.remove(); + delEnd(); + } + }); + }); + //删除全部 + $('#LAY_delallmsg').on('click', function () { + var othis = $(this); + layer.confirm('确定清空吗?', function (index) { + fly.json('/message/remove/', { + all: true + }, function (res) { + if (res.status === 0) { + layer.close(index); + othis.addClass('layui-hide'); + delEnd(true); + } + }); + }); + }); + }; + dom.minemsg[0] && gather.minemsg(); - + exports('user', {}); - exports('user', {}); - }); \ No newline at end of file -- Gitee From e70305bdc323a564d72f58e8ba4a4d9acb1a8fd5 Mon Sep 17 00:00:00 2001 From: liyuan Date: Fri, 27 Sep 2019 12:54:12 +0800 Subject: [PATCH 3/4] =?UTF-8?q?1=20=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/static/fly/mods/user.js | 261 ++++++++---------- 1 file changed, 117 insertions(+), 144 deletions(-) diff --git a/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js b/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js index 61485c8..988fac0 100644 --- a/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js +++ b/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js @@ -4,7 +4,7 @@ */ -layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) { +layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function(exports){ var $ = layui.jquery; var layer = layui.layer; @@ -19,113 +19,80 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) var table = layui.table; //我发的贴 - if ($('#LAY_mySendCard')[0]) { - var uid = $('#LAY_mySendCard').data("uid"); + if($('#LAY_mySendCard')[0]){ + var uid=$('#LAY_mySendCard').data("uid"); table.render({ elem: '#LAY_mySendCard' - , url: '/article/list' - , method: 'post' - , where: { - author: uid + ,url: '/article/list' + ,method: 'post' + ,where: { + author:uid } - , cols: [[ - { - field: 'title', - title: '帖子标题', - minWidth: 200, - templet: '
    {{ d.title }}
    ' - } - , { - field: 'status', title: '状态', width: 100, align: 'center', templet: function (d) { - if (d.status == 9) { + ,cols: [[ + {field: 'title', title: '帖子标题', minWidth: 200, templet: '
    {{ d.title }}
    '} + ,{field: 'status', title: '状态', width: 100, align: 'center', templet: function(d){ + if(d.status == 9){ return '已结'; - } else if (d.status == 0) { + } else if(d.status == 0){ return '审核中'; } else { return '未结' } - } - } - , { - field: 'rec', title: '加精', width: 100, align: 'center', templet: function (d) { + }} + ,{field: 'rec', title: '加精', width: 100, align: 'center', templet: function(d){ return d.rec ? '' : '' - } - } - , { - field: 'top', title: '置顶', width: 100, align: 'center', templet: function (d) { + }} + ,{field: 'top', title: '置顶', width: 100, align: 'center', templet: function(d){ return d.top ? '' : '' - } - } - , { - field: 'createTime', - title: '发表时间', - width: 120, - align: 'center', - templet: '
    {{ layui.util.timeAgo(d.createTime, 1) }}
    ' - } - , { - title: '数据', - width: 150, - templet: '
    {{d.views}}阅/{{d.comment}}答
    ' - } - , { - title: '操作', width: 100, templet: function (d) { - return d.status != 9 ? '编辑' : '' - } - } + }} + ,{field: 'createTime', title: '发表时间', width: 120, align: 'center', templet: '
    {{ layui.util.timeAgo(d.createTime, 1) }}
    '} + ,{title: '数据', width: 150, templet: '
    {{d.views}}阅/{{d.comment}}答
    '} + ,{title: '操作', width: 100, templet: function(d){ + return d.status != 9 ? '编辑' : '' + }} ]] - , page: true - , skin: 'line' + ,page: true + ,skin: 'line' }); } //我收藏的帖 - if ($('#LAY_myCollectioncard')[0]) { + if($('#LAY_myCollectioncard')[0]){ table.render({ elem: '#LAY_myCollectioncard' - , url: '/safe/collect/list' - , method: 'post' - , where: { - orderByColumn: 'createTime', - isAsc: 'desc' + ,url:'/safe/collect/list' + ,method: 'post' + ,where: { + orderByColumn:'createTime', + isAsc:'desc' } - , cols: [[ - { - field: 'title', - title: '帖子标题', - minWidth: 300, - templet: '
    {{ d.title }}
    ' - } - , { - title: '收藏时间', - width: 120, - align: 'center', - templet: '
    {{ layui.util.timeAgo(d.createTime, 1) }}
    ' - } + ,cols: [[ + {field: 'title', title: '帖子标题', minWidth: 300, templet: '
    {{ d.title }}
    '} + ,{title: '收藏时间', width: 120, align: 'center', templet: '
    {{ layui.util.timeAgo(d.createTime, 1) }}
    '} ]] - , page: true - , skin: 'line' + ,page: true + ,skin: 'line' }); } //最近发帖 var tplRenjie = ['{{# layui.each(d.rows, function(index, item){ }}' - , '
  • ' - , '{{# if(item.rec) { }}' - , '' - , '{{# } }}' - , '{{item.title}}' - , '{{layui.util.timeAgo(item.createTime,1)}}' - , '{{item.views}}阅/{{item.comment}}答' - , '
  • ' - , '{{# }); }}'].join('') - , recentlyJie = $('#recently-jie'); - - if (recentlyJie[0]) { + ,'
  • ' + ,'{{# if(item.rec) { }}' + ,'' + ,'{{# } }}' + ,'{{item.title}}' + ,'{{layui.util.timeAgo(item.createTime,1)}}' + ,'{{item.views}}阅/{{item.comment}}答' + ,'
  • ' + ,'{{# }); }}'].join('') + ,recentlyJie = $('#recently-jie'); + + if(recentlyJie[0]){ var uid = recentlyJie.data('uid'); - fly.json('/article/list/', {author: uid, pageNum: 1, pageSize: 10}, function (res) { - if (res.rows.length > 0) { + fly.json('/article/list/',{author:uid,pageNum:1,pageSize:10}, function(res){ + if(res.rows.length>0){ var html = laytpl(tplRenjie).render(res); recentlyJie.html(html); } @@ -133,21 +100,21 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) } //最近回答 var tplRenda = ['{{# layui.each(d.rows, function(index, item){ }}' - , '
  • ' - , '

    ' - , '{{layui.util.timeAgo(item.createTime,1)}}{{item.artTitle}}中回答:' - , '

    ' - , '
    ' - , '{{item.content}}' - , '
    ' - , '
  • ' - , '{{# }); }}'].join('') - - , recentlyDa = $('#recently-jieda'); - if (recentlyDa[0]) { + ,'
  • ' + ,'

    ' + ,'{{layui.util.timeAgo(item.createTime,1)}}{{item.artTitle}}中回答:' + ,'

    ' + ,'
    ' + ,'{{item.content}}' + ,'
    ' + ,'
  • ' + ,'{{# }); }}'].join('') + + ,recentlyDa = $('#recently-jieda'); + if(recentlyDa[0]){ var uid = recentlyDa.data('uid'); - fly.json('/comment/list/', {author: uid, pageNum: 1, pageSize: 10}, function (res) { - if (res.rows.length > 0) { + fly.json('/comment/list/',{author:uid,pageNum:1,pageSize:10}, function(res){ + if(res.rows.length>0){ var html = laytpl(tplRenda).render(res); recentlyDa.html(html); } @@ -155,13 +122,13 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) } //显示当前tab - if (location.hash) { + if(location.hash){ element.tabChange('user', location.hash.replace(/^#/, '')); } - element.on('tab(user)', function () { + element.on('tab(user)', function(){ var othis = $(this), layid = othis.attr('lay-id'); - if (layid) { + if(layid){ location.hash = layid; } }); @@ -169,9 +136,9 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) var gather = {}, dom = { mine: $('#LAY_mine') - , mineview: $('.mine-view') - , minemsg: $('#LAY_minemsg') - , infobtn: $('#LAY_btninfo') + ,mineview: $('.mine-view') + ,minemsg: $('#LAY_minemsg') + ,infobtn: $('#LAY_btninfo') }; //根据ip获取城市 @@ -182,16 +149,16 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) }*/ // 修改用户信息 - form.on('submit(userInfo)', function (data) { + form.on('submit(userInfo)', function(data){ $.ajax({ type: 'post', url: '/safe/user/info/edit', data: data.field, dataType: 'json', success: function (data) { - if (data.code == 0) { + if(data.code==0){ location.reload(); - } else { + }else{ layer.msg(data.msg, {icon: 2}); } } @@ -199,21 +166,21 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) return false; //阻止表单跳转。如果需要表单跳转,去掉这段即可。 }); // 修改用户信息 - form.on('submit(repass)', function (data) { + form.on('submit(repass)', function(data){ $.ajax({ type: 'post', url: '/safe/user/repass', data: data.field, dataType: 'json', success: function (data) { - if (data.code == 0) { + if(data.code==0){ layer.msg(data.msg, {icon: 1}); - form.val("repass", { - nowpass: '', - newpass: '', - repass: '', + form.val("repass",{ + nowpass:'', + newpass:'', + repass:'', }) - } else { + }else{ layer.msg(data.msg, {icon: 2}); } } @@ -222,18 +189,19 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) }); //上传图片 - if ($('.upload-img')[0]) { - layui.use('upload', function (upload) { + if($('.upload-img')[0]){ + layui.use('upload', function(upload){ var avatarAdd = $('.avatar-add'); + upload.render({ elem: '.upload-img' - , url: '/safe/user/upload/' - , size: 50 - , before: function () { + ,url: '/safe/user/upload/' + ,size: 50 + ,before: function(){ avatarAdd.find('.loading').show(); } - , done: function (res) { - if (res.code == 0) { + ,done: function(res){ + if(res.code == 0){ layer.msg("保存成功,正在刷新数据请稍后……", { icon: 1, time: 500, @@ -247,7 +215,7 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) } avatarAdd.find('.loading').hide(); } - , error: function () { + ,error: function(){ avatarAdd.find('.loading').hide(); } }); @@ -255,30 +223,30 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) } //提交成功后刷新 - fly.form['set-mine'] = function (data, required) { + fly.form['set-mine'] = function(data, required){ layer.msg('修改成功', { icon: 1 - , time: 1000 - , shade: 0.1 - }, function () { + ,time: 1000 + ,shade: 0.1 + }, function(){ location.reload(); }); } //帐号绑定 - $('.acc-unbind').on('click', function () { + $('.acc-unbind').on('click', function(){ var othis = $(this), type = othis.attr('type'); - layer.confirm('确定要解绑' + ({ + layer.confirm('确定要解绑'+ ({ qq_id: 'QQ' - , weibo_id: '微博' - })[type] + '吗?', {icon: 5}, function () { + ,weibo_id: '微博' + })[type] + '吗?', {icon: 5}, function(){ fly.json('/api/unbind', { type: type - }, function (res) { - if (res.status === 0) { + }, function(res){ + if(res.status === 0){ layer.alert('已成功解绑。', { icon: 1 - , end: function () { + ,end: function(){ location.reload(); } }); @@ -291,9 +259,9 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) //我的消息 - gather.minemsg = function () { + gather.minemsg = function(){ var delAll = $('#LAY_delallmsg') - , tpl = '{{# var len = d.rows.length;\ + ,tpl = '{{# var len = d.rows.length;\ if(len === 0){ }}\
    您暂时没有最新消息
    \ {{# } else { }}\ @@ -306,28 +274,28 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) {{# } }}\ \ {{# } }}' - , delEnd = function (clear) { - if (clear || dom.minemsg.find('.mine-msg li').length === 0) { + ,delEnd = function(clear){ + if(clear || dom.minemsg.find('.mine-msg li').length === 0){ dom.minemsg.html('
    您暂时没有最新消息
    '); } } - fly.json('/message/find/', {}, function (res) { + fly.json('/message/find/', {}, function(res){ var html = laytpl(tpl).render(res); dom.minemsg.html(html); - if (res.rows.length > 0) { + if(res.rows.length > 0){ delAll.removeClass('layui-hide'); } }); //阅读后删除 - dom.minemsg.on('click', '.mine-msg li .fly-delete', function () { + dom.minemsg.on('click', '.mine-msg li .fly-delete', function(){ var othis = $(this).parents('li'), id = othis.data('id'); fly.json('/message/remove/', { id: id - }, function (res) { - if (res.status === 0) { + }, function(res){ + if(res.status === 0){ othis.remove(); delEnd(); } @@ -335,13 +303,13 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) }); //删除全部 - $('#LAY_delallmsg').on('click', function () { + $('#LAY_delallmsg').on('click', function(){ var othis = $(this); - layer.confirm('确定清空吗?', function (index) { + layer.confirm('确定清空吗?', function(index){ fly.json('/message/remove/', { all: true - }, function (res) { - if (res.status === 0) { + }, function(res){ + if(res.status === 0){ layer.close(index); othis.addClass('layui-hide'); delEnd(true); @@ -355,6 +323,11 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function (exports) dom.minemsg[0] && gather.minemsg(); + + + + + exports('user', {}); }); \ No newline at end of file -- Gitee From 4fbac1f6fdcfa061ae0e0c769a6276eca0d412b1 Mon Sep 17 00:00:00 2001 From: liyuan Date: Fri, 27 Sep 2019 13:04:38 +0800 Subject: [PATCH 4/4] =?UTF-8?q?1=20=E7=94=A8=E6=88=B7=E4=BF=AE=E6=94=B9?= =?UTF-8?q?=E5=A4=B4=E5=83=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/web/controller/BbsUserController.java | 39 +------------------ .../controller/safe/SafeUserController.java | 38 ++++++++++++++++++ .../main/resources/static/fly/mods/user.js | 8 +--- 3 files changed, 41 insertions(+), 44 deletions(-) diff --git a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java index a64a3f6..7e96403 100644 --- a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java +++ b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/BbsUserController.java @@ -3,17 +3,12 @@ package com.dev.web.controller; import com.dev.bbs.domain.BbsUser; import com.dev.bbs.service.IBbsUserService; import com.dev.common.annotation.Log; -import com.dev.common.config.Global; import com.dev.common.core.controller.BaseController; import com.dev.common.core.domain.AjaxResult; import com.dev.common.core.page.TableDataInfo; import com.dev.common.enums.BusinessType; -import com.dev.common.utils.file.FileUploadUtils; import com.dev.common.utils.poi.ExcelUtil; -import com.dev.framework.util.ShiroUtils; import org.apache.shiro.authz.annotation.RequiresPermissions; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -22,9 +17,7 @@ import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -38,7 +31,7 @@ import java.util.List; @RequestMapping("user") public class BbsUserController extends BaseController { - private static final Logger log = LoggerFactory.getLogger(BbsUserController.class); + private String prefix = "user"; @@ -142,33 +135,5 @@ public class BbsUserController extends BaseController return toAjax(bbsUserService.deleteBbsUserByIds(ids)); } - /** - * 保存头像 - */ - @Log(title = "个人信息", businessType = BusinessType.UPDATE) - @PostMapping("/upload") - @ResponseBody - public AjaxResult updateAvatar(@RequestParam("file") MultipartFile file) - { - BbsUser user = ShiroUtils.getBbsUser(); - try - { - if (!file.isEmpty()) - { - String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file); - user.setAvatar(avatar); - if (bbsUserService.updateBbsUser(user) > 0) - { - ShiroUtils.setBbsUser(bbsUserService.selectBbsUserById(user.getUserId())); - return success(); - } - } - return error(); - } - catch (Exception e) - { - log.error("修改头像失败!", e); - return error(e.getMessage()); - } - } + } diff --git a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java index ecd7f25..f1709b8 100644 --- a/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java +++ b/dev-web/dev-web-bbs/src/main/java/com/dev/web/controller/safe/SafeUserController.java @@ -11,12 +11,16 @@ import com.dev.bbs.form.UserForm; import com.dev.bbs.service.IBbsUserService; import com.dev.bbs.service.IBbsUserSignService; import com.dev.common.annotation.Log; +import com.dev.common.config.Global; import com.dev.common.constant.ShiroConstants; import com.dev.common.core.controller.BaseController; import com.dev.common.core.domain.AjaxResult; import com.dev.common.enums.BusinessType; +import com.dev.common.utils.file.FileUploadUtils; import com.dev.framework.shiro.service.BbsPasswordService; import com.dev.framework.util.ShiroUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; @@ -24,7 +28,9 @@ import org.springframework.validation.annotation.Validated; 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.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; import javax.servlet.http.HttpServletRequest; @@ -41,6 +47,8 @@ import javax.servlet.http.HttpServletRequest; @RequestMapping("safe/user") public class SafeUserController extends BaseController { + private static final Logger log = LoggerFactory.getLogger(SafeUserController.class); + private String prefix = "safe/user"; @Autowired @@ -146,4 +154,34 @@ public class SafeUserController extends BaseController { return prefix + "/message"; } + + /** + * 保存头像 + */ + @Log(title = "个人信息", businessType = BusinessType.UPDATE) + @PostMapping("/upload") + @ResponseBody + public AjaxResult updateAvatar(@RequestParam("file") MultipartFile file) + { + BbsUser user = ShiroUtils.getBbsUser(); + try + { + if (!file.isEmpty()) + { + String avatar = FileUploadUtils.upload(Global.getAvatarPath(), file); + user.setAvatar(avatar); + if (bbsUserService.updateBbsUser(user) > 0) + { + ShiroUtils.setBbsUser(bbsUserService.selectBbsUserById(user.getUserId())); + return success(); + } + } + return error(); + } + catch (Exception e) + { + log.error("修改头像失败!", e); + return error(e.getMessage()); + } + } } diff --git a/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js b/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js index 2b30e20..a646fd0 100644 --- a/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js +++ b/dev-web/dev-web-bbs/src/main/resources/static/fly/mods/user.js @@ -194,19 +194,13 @@ layui.define(['laypage', 'fly', 'element', 'flow', 'table'], function(exports){ var avatarAdd = $('.avatar-add'); upload.render({ elem: '.upload-img' - ,url: '/user/upload/' + ,url: '/safe/user/upload/' ,size: 50 ,before: function(){ avatarAdd.find('.loading').show(); } ,done: function(res){ if(res.code == 0){ - /*$.post('/user/set/', { - avatar: res.url - }, function(res){ - location.reload(); - });*/ - //$.operate.saveSuccess(res); layer.msg("保存成功,正在刷新数据请稍后……", { icon: 1, time: 500, -- Gitee