From 7c5fbededd2868544fe821486d8e532fe0315d74 Mon Sep 17 00:00:00 2001 From: tamguo Date: Mon, 10 Dec 2018 19:12:35 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=9A=E5=91=98=E4=B8=AD=E5=BF=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/tamguo/web/AccountController.java | 107 ++++++++ .../src/main/resources/application.properties | 4 +- .../resources/static/css/member/account.css | 240 ++++++++++++------ .../resources/static/js/member/account.js | 68 +++++ .../src/main/resources/templates/account.html | 53 +++- 5 files changed, 394 insertions(+), 78 deletions(-) create mode 100644 tamguo-mms/src/main/resources/static/js/member/account.js diff --git a/tamguo-mms/src/main/java/com/tamguo/web/AccountController.java b/tamguo-mms/src/main/java/com/tamguo/web/AccountController.java index 548af56..2808dda 100644 --- a/tamguo-mms/src/main/java/com/tamguo/web/AccountController.java +++ b/tamguo-mms/src/main/java/com/tamguo/web/AccountController.java @@ -1,16 +1,123 @@ package com.tamguo.web; +import java.io.File; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.text.DecimalFormat; +import java.text.SimpleDateFormat; +import java.util.Date; + +import javax.servlet.http.HttpServletRequest; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.multipart.MultipartFile; import org.springframework.web.servlet.ModelAndView; +import com.tamguo.common.utils.DateUtils; +import com.tamguo.common.utils.Result; +import com.tamguo.common.utils.Status; +import com.tamguo.common.utils.UploaderMessage; +import com.tamguo.config.redis.CacheService; +import com.tamguo.modules.member.service.IMemberService; +import com.tamguo.utils.ShiroUtils; + @Controller public class AccountController { + @Value("${file.storage.path}") + String fileStoragePath; + @Value("${tamguo.domain.name}") + String tamguoDomainName; + @Autowired + IMemberService iMemberService; + @Autowired + CacheService cacheService; + + private static final String AVATOR_NO_FORMAT = "00000"; + private static final String AVATOR_PREFIX = "MTX"; + @RequestMapping(value = {"account.html"}, method = RequestMethod.GET) public ModelAndView list(ModelAndView model) { model.setViewName("account"); + model.addObject("member", iMemberService.findByUid(ShiroUtils.getMemberId())); return model; } + + @RequestMapping(value = {"getCurrentMember"}, method = RequestMethod.GET) + @ResponseBody + public Result getCurrentMember() { + return Result.result(0, iMemberService.findByUid(ShiroUtils.getMemberId()), "success"); + } + + @RequestMapping(value = "uploadFile", method = RequestMethod.POST) + @ResponseBody + public UploaderMessage uploadFileHandler(@RequestParam("file") MultipartFile file,HttpServletRequest request) throws IOException { + + if (!file.isEmpty()) { + InputStream in = null; + OutputStream out = null; + + try { + String path = fileStoragePath + DateUtils.format(new Date(), "yyyyMMdd"); + File dir = new File(path); + if (!dir.exists()) + dir.mkdirs(); + String avatorName = this.getAvatorNo() + file.getOriginalFilename().substring(file.getOriginalFilename().lastIndexOf(".")); + in = file.getInputStream(); + out = new FileOutputStream(path + "/" + avatorName); + byte[] b = new byte[1024]; + int len = 0; + while ((len = in.read(b)) > 0) { + out.write(b, 0, len); + } + out.close(); + in.close(); + + UploaderMessage msg = new UploaderMessage(); + msg.setStatus(Status.SUCCESS); + msg.setStatusMsg("File upload success"); + msg.setFilePath("files/" + DateUtils.format(new Date(), "yyyyMMdd") + "/" + avatorName); + msg.setFileDomain(tamguoDomainName); + return msg; + } catch (Exception e) { + UploaderMessage msg = new UploaderMessage(); + msg.setStatus(Status.ERROR); + msg.setError("File upload file"); + return msg; + } finally { + if (out != null) { + out.close(); + out = null; + } + + if (in != null) { + in.close(); + in = null; + } + } + } else { + UploaderMessage msg = new UploaderMessage(); + msg.setStatus(Status.ERROR); + msg.setError("File is empty"); + return msg; + } + } + + private String getAvatorNo() { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM"); + String format = sdf.format(new Date()); + DecimalFormat df = new DecimalFormat(AVATOR_NO_FORMAT); + String key = AVATOR_PREFIX + format; + Long incr = cacheService.incr(key); + String avatorNo = AVATOR_PREFIX + df.format(incr); + return avatorNo; + } } diff --git a/tamguo-mms/src/main/resources/application.properties b/tamguo-mms/src/main/resources/application.properties index 6b4fa54..57b825d 100644 --- a/tamguo-mms/src/main/resources/application.properties +++ b/tamguo-mms/src/main/resources/application.properties @@ -14,14 +14,14 @@ spring.datasource.maxPoolPreparedStatementPerConnectionSize=20 spring.datasource.maxWait=60000 spring.datasource.minEvictableIdleTimeMillis=300000 spring.datasource.minIdle=5 -spring.datasource.password=tanguo520pig +spring.datasource.password=123456 spring.datasource.poolPreparedStatements=true spring.datasource.testOnBorrow=false spring.datasource.testOnReturn=false spring.datasource.testWhileIdle=true spring.datasource.timeBetweenEvictionRunsMillis=60000 spring.datasource.type=com.alibaba.druid.pool.DruidDataSource -spring.datasource.url=jdbc:mysql://127.0.0.1:3306/tamguo?useUnicode=true&characterEncoding=UTF-8&useSSL=false +spring.datasource.url=jdbc:mysql://127.0.0.1:3306/tamguo_20181110?useUnicode=true&characterEncoding=UTF-8&useSSL=false spring.datasource.username=root spring.datasource.validationQuery=SELECT 1 FROM DUAL diff --git a/tamguo-mms/src/main/resources/static/css/member/account.css b/tamguo-mms/src/main/resources/static/css/member/account.css index 8d5b228..c21970b 100644 --- a/tamguo-mms/src/main/resources/static/css/member/account.css +++ b/tamguo-mms/src/main/resources/static/css/member/account.css @@ -1,23 +1,137 @@ @charset "utf-8"; -body { font-family: "Microsoft Yahei"; color: #333;background:#f5f5f6} -em, i { font-style: normal; } -.start{color: red} -.hide-text{ overflow: hidden;white-space: nowrap;text-overflow: ellipsis;} -.well{height: 10px;background: #f5f5f6;width: 340px;position: relative;left: -10px;} -.cnav { height: 98px; width: 100%; background: url(../../images/project-cnavbj.jpg) no-repeat; background-size: cover; } -.cnav_b { position: relative; } -.cnav_left { float: left; width: 162px; height: 54px; margin: 22px 0 0 46px; font-size: 18px; color: #fff; line-height: 54px; background: url(../../images/test-paper/top-kaos.png) no-repeat; padding-left: 55px; } -.cnav_right { float: left; width:728px; height: 5px; background: url(../../images/project-cnav.png) repeat-x; margin: 47px 0 0 0; } -.cnav_right ul { position: absolute; top: 30px; left: 230px; } -.cnav_right ul li { width: 120px; height: 50px; float: left; font-size: 14px; color: #fff; text-align: center; line-height: 12px; margin-left: 32px; } -.cnav_right ul li span { font-size: 12px; font-weight: bold; width: 27px; height: 27px; color: #29bdb9; display: block; margin: 5px auto 5px auto; text-align: center; line-height: 27px; background: url(../../images/project-candidate.png) no-repeat -26px 0; } -.cnavX { background: url(../../images/project-candidate.png) no-repeat -61px -39px; width: 17px; height: 17px; position: absolute; top: 12px; left: 1082px; cursor: pointer; } -.cnav_right ul li .Cnav_t { background: url(../../images/project-candidate.png) no-repeat -54px 0; width: 37px; height: 37px; line-height: 37px; margin: 0 auto; } -.contentBox{margin-top: 20px;font-size: 14px;overflow: hidden;} +.contentBox { + margin-top: 20px; + font-size: 14px; + overflow: hidden; +} +.infoCnt-box { + padding: 0px; +} +.cnt-box { + background: #FFFFFF; + padding: 10px; +} +.public { + width: 1098px; + margin: 0px auto; +} +.info-cnt { + padding-top: 0px; + padding-bottom: 0px; +} +.contentBox .navLeft { + float: left; + display: inline-block; + width: 16.4%; + background: rgb(41,186,185); +} +.contentBox .navLeft dl dt { + height: 40px; + line-height: 40px; + background: rgb(37,172,169); + padding-left: 10px; + font-size: 14px; + color: white; + cursor: pointer; +} +.icon-w { + float: right; + position: relative; + top: 50%; + transform: translateY(-50%); + margin-right: 10px; +} +.fa { + display: inline-block; + font: normal normal normal 14px/1 FontAwesome; + font-size: inherit; + text-rendering: auto; + -webkit-font-smoothing: antialiased; + -moz-osx-font-smoothing: grayscale; +} +.fa-minus:before { + content: "\f068"; +} +.contentBox .navLeft dl dd { + text-align: center; + color: white; + height: 40px; + line-height: 40px; + cursor: pointer; +} +.navLeft dl dd i { + width: 17px; + height: 14px; + display: inline-block; + background: url(../../images/member/account/icon-erro.png) no-repeat; + margin: 0px 4px; + position: relative; + top: 1px; + margin-left: 0px; +} +.contentBox .navLeft dl dd { + text-align: center; + color: white; + height: 40px; + line-height: 40px; + cursor: pointer; +} +.contentBox .newsRight { + float: left; + display: inline-block; + width: 83%; + background: white; + min-height: 279px; +} +.info-rBox { + padding-left: 76px; +} +.info-rBox { + padding-bottom: 40px!important; +} +.info-rBox { + padding-left: 80px; + position: relative; +} +.user_list { + padding: 0px; +} +.user_list { + padding: 20px 0px; + vertical-align: top; + width: 550px; +} +.info-table { + width: 100%; + margin-top: 28px; + font-size: 14px; +} +.info-table tr td { + padding-bottom: 20px; +} +.info-label { + position: relative; +} +.info-label span { + position: absolute; + left: -15px; + top: 0px; + color: #ff5a00; +} +* { + box-sizing: border-box; +} +.cvcadd-text { + height: 40px; + border: 1px solid #d4d7db; + font-size: 14px; + padding: 0px 12px; + width: 311px; +} .acphoto { display: inline-block; position: relative; - /*padding: 0 2em;*/ + /* padding: 0 2em; */ border: none; border-radius: 80px; height: 80px; @@ -30,11 +144,16 @@ em, i { font-style: normal; } cursor: pointer; float: left; } -.up_photo{ +.mybtn { + float: left; + margin-left: 10px; + padding-top: 10px; +} +.up_photo { display: inline-block; position: relative; padding: 0 2em; - /*border: none;*/ + /* border: none; */ border: 1px solid #29bdb9; border-radius: 0px; background: #29bdb9; @@ -45,62 +164,35 @@ em, i { font-style: normal; } cursor: pointer; margin-top: 15px; } -.mybtn{ - float: left; - margin-left: 10px; - padding-top: 10px; -} -.contentBox{margin-top: 20px;font-size: 14px;overflow: hidden;} -.contentBox .navLeft{float: left;display: inline-block;width: 16.4%;background:rgb(41,186,185);} -.contentBox .navLeft dl{} -.contentBox .navLeft dl dt{height: 40px;line-height: 40px;background:rgb(37,172,169);padding-left: 10px;font-size: 14px;color:white;cursor: pointer; } -.icon-w{float: right;position: relative;top: 50%;transform: translateY(-50%);margin-right: 10px;} -.icon-f{margin-right: 10px;} -.contentBox .navLeft dl dd{text-align: center;;color: white;height: 40px;line-height: 40px;cursor: pointer; } -.contentBox .navLeft dl dd a{color: white} -.contentBox .newsRight{float: left;display: inline-block;width:83%;background:white;min-height: 279px;} -.user_list{padding: 0px;} -.info-cnt{padding-top:0px;background: #f5f5f6; } -.photoBox{display: none;} -.navLeft dl dd i {width: 17px;height: 14px;display: inline-block;background: url(../../images/icon-erro.png) no-repeat;margin: 0px 4px;position: relative;top: 1px;margin-left: 0px; -} -.icon-h { - font-size: 14px; +.up_photo { + display: inline-block; position: relative; - margin-right: 10px; + padding: 0 2em; + /* border: none; */ + border: 1px solid #29bdb9; + border-radius: 0px; + background: #29bdb9; + color: #fff; + font-size: 14px; + line-height: 28px; + text-decoration: none; + cursor: pointer; + margin-top: 15px; } -.acm-container{/*position: relative;top: -20px;*/padding-bottom: 200px;} -.info-cnt { - padding-top:0px; - padding-bottom:0px; - -} -.footer{margin-top: 0px!important;} -.headlogotable{float: right;} -.info-rBox{padding-bottom: 40px!important;} -.navLeft .list a dd:hover{background:#52cdc8} -.contentBox .navLeft dl dt:hover{background:#52cdc8 } -.head .logo { - padding-top: 0px; - float: left; - display: -webkit-box; - line-height: 59px; +a.btn_ok { + display: inline-block; + position: relative; + padding: 0 2em; + border: none; + border-radius: 0px; + background: #29bdb9; + color: #fff; + font-size: 14px; + line-height: 28px; + text-decoration: none; + cursor: pointer; } - .head .logo a{ - max-width: 120px; - height: 55px; - line-height: 55px; - text-align: center; - display: block; - } - .head .logo img{ - float: none; - max-width: 100%; - max-height: 100% - } - .head .logo p { - float: none; - line-height: 59px; - padding-left: 12px; -} -.weixinPng:hover img:nth-child(2){display: block} \ No newline at end of file +.head .nav li:hover { + border-bottom: 2px solid #29bdb9; + font-weight: bold; +} \ No newline at end of file diff --git a/tamguo-mms/src/main/resources/static/js/member/account.js b/tamguo-mms/src/main/resources/static/js/member/account.js new file mode 100644 index 0000000..81c94cf --- /dev/null +++ b/tamguo-mms/src/main/resources/static/js/member/account.js @@ -0,0 +1,68 @@ +var vm = new Vue({ + el:'#app', + data() { + return { + loading:false, + courses:[], + member:{ + name:null + }, + rules: { + username: [ + { required: true, message: '请输入用户名', trigger: 'blur' } + ], + nickName: [ + { required: true, message: '请输入用户名', trigger: 'blur' } + ] + } + }; + }, + methods: { + handleAvatarSuccess(res, file) { + vm.member.avatar = res.filePath; + vm.member.imageUrl = res.fileDomain + res.filePath; + }, + beforeAvatarUpload(file) { + const isJPG = file.type === 'image/jpeg'; + const isLt2M = file.size / 1024 / 1024 < 2; + + if (!isJPG) { + this.$message.error('上传头像图片只能是 JPG 格式!'); + } + if (!isLt2M) { + this.$message.error('上传头像图片大小不能超过 2MB!'); + } + return isJPG && isLt2M; + }, + onSubmit:function(){ + loading = true; + this.$refs['member'].validate((valid) => { + if (valid) { + axios({method: 'post',url: mainHttp + 'account/update.html',data: vm.member}).then(function(response){ + if(response.data.code == 0){ + vm.loading = false; + vm.$message({message: "修改成功",duration:500,type: 'success',onClose:function(){ + window.location.reload(); + }}); + }else{ + vm.loading = false; + vm.$message.error(response.data.message); + vm.$refs['member'].validate(); + } + }); + } else { + console.log('error submit!!'); + return false; + } + }); + }, + getMember:function(){ + axios.get(mainHttp + 'getCurrentMember').then(function(response){ + vm.member = response.data.result; + console.log(vm.member.avatar); + vm.member.imageUrl = mainHttp + vm.member.avatar; + }); + } + } +}); +vm.getMember(); \ No newline at end of file diff --git a/tamguo-mms/src/main/resources/templates/account.html b/tamguo-mms/src/main/resources/templates/account.html index 0d432e8..cae3625 100644 --- a/tamguo-mms/src/main/resources/templates/account.html +++ b/tamguo-mms/src/main/resources/templates/account.html @@ -4,6 +4,7 @@ 个人信息 - 探果网 + @@ -79,8 +80,55 @@ -
- +
+
+
+ +
+
+
+ + + + + + + + + + + + + + + 立即修改 + + +
+
+
+
+
+
+
@@ -94,4 +142,5 @@ var mainHttp = [[${domainName}]]; var bookDomainName = [[${bookDomainName}]]; + \ No newline at end of file