提交 c2448a72 编写于 作者: 江南一点雨

完善个人中心

上级 01c2e1c6
package org.javaboy.vhr.config; package org.javaboy.vhr.config;
import org.csource.common.MyException; import org.csource.common.MyException;
import org.csource.fastdfs.*; import org.csource.fastdfs.ClientGlobal;
import org.csource.fastdfs.StorageClient1;
import org.csource.fastdfs.TrackerClient;
import org.csource.fastdfs.TrackerServer;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import java.io.IOException; import java.io.IOException;
...@@ -13,7 +16,7 @@ import java.io.IOException; ...@@ -13,7 +16,7 @@ import java.io.IOException;
* @GitHub https://github.com/lenve * @GitHub https://github.com/lenve
* @博客 http://wangsong.blog.csdn.net * @博客 http://wangsong.blog.csdn.net
* @网站 http://www.javaboy.org * @网站 http://www.javaboy.org
* @时间 2020-03-01 22:49 * @时间 2020-03-02 23:26
*/ */
public class FastDFSUtils { public class FastDFSUtils {
private static StorageClient1 client1; private static StorageClient1 client1;
...@@ -23,8 +26,7 @@ public class FastDFSUtils { ...@@ -23,8 +26,7 @@ public class FastDFSUtils {
ClientGlobal.initByProperties("fastdfs-client.properties"); ClientGlobal.initByProperties("fastdfs-client.properties");
TrackerClient trackerClient = new TrackerClient(); TrackerClient trackerClient = new TrackerClient();
TrackerServer trackerServer = trackerClient.getConnection(); TrackerServer trackerServer = trackerClient.getConnection();
StorageServer storageServer = null; client1 = new StorageClient1(trackerServer, null);
client1 = new StorageClient1(trackerServer, storageServer);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (MyException e) { } catch (MyException e) {
...@@ -33,16 +35,15 @@ public class FastDFSUtils { ...@@ -33,16 +35,15 @@ public class FastDFSUtils {
} }
public static String upload(MultipartFile file) { public static String upload(MultipartFile file) {
String name = file.getOriginalFilename(); String oldName = file.getOriginalFilename();
String s = null;
try { try {
s = client1.upload_file1(file.getBytes(), name.substring(name.lastIndexOf(".") + 1), null); return client1.upload_file1(file.getBytes(), oldName.substring(oldName.lastIndexOf(".") + 1), null);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} catch (MyException e) { } catch (MyException e) {
e.printStackTrace(); e.printStackTrace();
} }
return s; return null;
} }
} }
...@@ -6,7 +6,9 @@ import org.javaboy.vhr.model.RespBean; ...@@ -6,7 +6,9 @@ import org.javaboy.vhr.model.RespBean;
import org.javaboy.vhr.service.HrService; import org.javaboy.vhr.service.HrService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.Authentication; import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
...@@ -27,7 +29,7 @@ public class HrInfoController { ...@@ -27,7 +29,7 @@ public class HrInfoController {
@Autowired @Autowired
HrService hrService; HrService hrService;
@Value("${javaboy.nginx.host}") @Value("${fastdfs.nginx.host}")
String nginxHost; String nginxHost;
@GetMapping("/hr/info") @GetMapping("/hr/info")
...@@ -36,8 +38,9 @@ public class HrInfoController { ...@@ -36,8 +38,9 @@ public class HrInfoController {
} }
@PutMapping("/hr/info") @PutMapping("/hr/info")
public RespBean updateHyById(@RequestBody Hr hr) { public RespBean updateHr(@RequestBody Hr hr, Authentication authentication) {
if (hrService.updateHyById(hr) == 1) { if (hrService.updateHr(hr) == 1) {
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(hr, authentication.getCredentials(), authentication.getAuthorities()));
return RespBean.ok("更新成功!"); return RespBean.ok("更新成功!");
} }
return RespBean.error("更新失败!"); return RespBean.error("更新失败!");
...@@ -55,11 +58,14 @@ public class HrInfoController { ...@@ -55,11 +58,14 @@ public class HrInfoController {
} }
@PostMapping("/hr/userface") @PostMapping("/hr/userface")
public RespBean updateUserface(MultipartFile file, Integer id) { public RespBean updateHrUserface(MultipartFile file, Integer id,Authentication authentication) {
String upload = FastDFSUtils.upload(file); String fileId = FastDFSUtils.upload(file);
String url = nginxHost + upload; String url = nginxHost + fileId;
if (hrService.updateUserface(url, id) == 1) { if (hrService.updateUserface(url, id) == 1) {
return RespBean.ok("更新成功!",url); Hr hr = (Hr) authentication.getPrincipal();
hr.setUserface(url);
SecurityContextHolder.getContext().setAuthentication(new UsernamePasswordAuthenticationToken(hr, authentication.getCredentials(), authentication.getAuthorities()));
return RespBean.ok("更新成功!", url);
} }
return RespBean.error("更新失败!"); return RespBean.error("更新失败!");
} }
......
...@@ -17,5 +17,5 @@ spring.redis.database=0 ...@@ -17,5 +17,5 @@ spring.redis.database=0
spring.redis.port=6379 spring.redis.port=6379
spring.redis.password=123 spring.redis.password=123
spring.cache.cache-names=menus_cache spring.cache.cache-names=menus_cache
# FastDFS 文件地址
javaboy.nginx.host=http://192.168.91.128/ fastdfs.nginx.host=http://192.168.91.128/
\ No newline at end of file \ No newline at end of file
...@@ -51,12 +51,15 @@ ...@@ -51,12 +51,15 @@
name: "Home", name: "Home",
data() { data() {
return { return {
user: JSON.parse(window.sessionStorage.getItem("user")) // user: JSON.parse(window.sessionStorage.getItem("user"))
} }
}, },
computed: { computed: {
routes() { routes() {
return this.$store.state.routes; return this.$store.state.routes;
},
user() {
return this.$store.state.currentHr;
} }
}, },
methods: { methods: {
......
...@@ -7,14 +7,13 @@ ...@@ -7,14 +7,13 @@
<div> <div>
<div style="display: flex;justify-content: center"> <div style="display: flex;justify-content: center">
<el-upload <el-upload
:data="hr"
:show-file-list="false" :show-file-list="false"
:on-success="onSuccess" :on-success="onSuccess"
:data="hr"
action="/hr/userface"> action="/hr/userface">
<img title="点击修改用户图像" :src="hr.userface" style="width: 100px;height: 100px;border-radius: 50px" <img title="点击修改用户图像" :src="hr.userface" style="width: 100px;height: 100px;border-radius: 50px"
alt=""> alt="">
</el-upload> </el-upload>
</div> </div>
<div>电话号码: <div>电话号码:
<el-tag>{{hr.telephone}}</el-tag> <el-tag>{{hr.telephone}}</el-tag>
...@@ -36,29 +35,6 @@ ...@@ -36,29 +35,6 @@
</div> </div>
</div> </div>
</el-card> </el-card>
<el-dialog
title="修改密码"
:visible.sync="passwdDialogVisible"
width="30%">
<div>
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"
class="demo-ruleForm">
<el-form-item label="请输入旧密码" prop="oldpass">
<el-input type="password" v-model="ruleForm.oldpass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="请输入新密码" prop="pass">
<el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="新确认密码" prop="checkPass">
<el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
<el-button @click="resetForm('ruleForm')">重置</el-button>
</el-form-item>
</el-form>
</div>
</el-dialog>
<el-dialog <el-dialog
title="修改用户信息" title="修改用户信息"
:visible.sync="dialogVisible" :visible.sync="dialogVisible"
...@@ -67,7 +43,7 @@ ...@@ -67,7 +43,7 @@
<table> <table>
<tr> <tr>
<td> <td>
<el-tag>用户姓名</el-tag> <el-tag>用户昵称</el-tag>
</td> </td>
<td> <td>
<el-input v-model="hr2.name"></el-input> <el-input v-model="hr2.name"></el-input>
...@@ -104,6 +80,29 @@ ...@@ -104,6 +80,29 @@
<el-button type="primary" @click="updateHrInfo">确 定</el-button> <el-button type="primary" @click="updateHrInfo">确 定</el-button>
</span> </span>
</el-dialog> </el-dialog>
<el-dialog
title="修改密码"
:visible.sync="passwdDialogVisible"
width="30%">
<div>
<el-form :model="ruleForm" status-icon :rules="rules" ref="ruleForm" label-width="100px"
class="demo-ruleForm">
<el-form-item label="请输入旧密码" prop="oldpass">
<el-input type="password" v-model="ruleForm.oldpass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="请输入新密码" prop="pass">
<el-input type="password" v-model="ruleForm.pass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item label="新确认密码" prop="checkPass">
<el-input type="password" v-model="ruleForm.checkPass" autocomplete="off"></el-input>
</el-form-item>
<el-form-item>
<el-button type="primary" @click="submitForm('ruleForm')">提交</el-button>
<el-button @click="resetForm('ruleForm')">重置</el-button>
</el-form-item>
</el-form>
</div>
</el-dialog>
</div> </div>
</template> </template>
...@@ -149,8 +148,8 @@ ...@@ -149,8 +148,8 @@
}, },
hr: null, hr: null,
hr2: null, hr2: null,
passwdDialogVisible: false, dialogVisible: false,
dialogVisible: false passwdDialogVisible: false
} }
}, },
mounted() { mounted() {
...@@ -158,10 +157,18 @@ ...@@ -158,10 +157,18 @@
}, },
methods: { methods: {
onSuccess() { onSuccess() {
this.getRequest("/logout"); this.initHr();
window.sessionStorage.removeItem("user") },
this.$store.commit('initRoutes', []); updateHrInfo() {
this.$router.replace("/"); this.putRequest("/hr/info", this.hr2).then(resp => {
if (resp) {
this.dialogVisible = false;
this.initHr();
}
})
},
showUpdateHrInfoView() {
this.dialogVisible = true;
}, },
submitForm(formName) { submitForm(formName) {
this.$refs[formName].validate((valid) => { this.$refs[formName].validate((valid) => {
...@@ -186,24 +193,13 @@ ...@@ -186,24 +193,13 @@
showUpdatePasswdView() { showUpdatePasswdView() {
this.passwdDialogVisible = true; this.passwdDialogVisible = true;
}, },
updateHrInfo() {
this.putRequest("/hr/info", this.hr2).then(resp => {
if (resp) {
this.getRequest("/logout");
window.sessionStorage.removeItem("user")
this.$store.commit('initRoutes', []);
this.$router.replace("/");
}
})
},
showUpdateHrInfoView() {
this.dialogVisible = true;
},
initHr() { initHr() {
this.getRequest('/hr/info').then(resp => { this.getRequest('/hr/info').then(resp => {
if (resp) { if (resp) {
this.hr = resp; this.hr = resp;
this.hr2 = Object.assign({}, this.hr); this.hr2 = Object.assign({}, this.hr);
window.sessionStorage.setItem("user", JSON.stringify(resp));
this.$store.commit('INIT_CURRENTHR', resp);
} }
}) })
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册