提交 88c3606b 编写于 作者: E Evan

chore: daily optimization

上级 b68f770b
......@@ -40,12 +40,20 @@
<el-table-column
prop="email"
label="邮箱"
show-overflow-tooltip
fit>
</el-table-column>
<el-table-column
prop="status"
label="状态"
width="100">
<template slot-scope="scope">
<el-switch
v-model="scope.row.enabled"
active-color="#13ce66"
inactive-color="#ff4949"
@change="(value) => commitChange(value, scope.row.username)">
</el-switch>
</template>
</el-table-column>
<el-table-column
label="操作"
......@@ -98,6 +106,20 @@
_this.users = resp.data
}
})
},
commitChange (value, username) {
this.$axios.put('/admin/user', {
enabled: value,
username: username
}).then(resp => {
if (resp && resp.status === 200) {
if (value) {
this.$message('用户 [' + username + '] 已启用')
} else {
this.$message('用户 [' + username + '] 已禁用')
}
}
})
}
}
}
......
......@@ -53,19 +53,16 @@ public class LibraryController {
}
}
@PostMapping("api/covers")
public String coversUpload(MultipartFile file, HttpServletRequest request) throws Exception {
@PostMapping("/api/covers")
public String coversUpload(MultipartFile file) throws Exception {
String folder = "D:/workspace/img";
File imageFolder = new File(folder);
File f = new File(imageFolder, getRandomString(6) + file.getOriginalFilename()
.substring(file.getOriginalFilename().length() - 4));
String filename = file.getName();
if (!f.getParentFile().exists())
f.getParentFile().mkdirs();
try {
file.transferTo(f);
// System.out.println(file.getOriginalFilename());
// System.out.println("http://localhost:8443/api/file/" + f.getName());
String imgURL = "http://localhost:8443/api/file/" + f.getName();
return imgURL;
} catch (IOException e) {
......
......@@ -61,7 +61,7 @@ public class LoginController {
user.setSalt(salt);
user.setPassword(encodedPassword);
userService.add(user);
userService.addOrUpdate(user);
return ResultFactory.buildSuccessResult(user);
}
......
package com.gm.wj.controller;
import com.gm.wj.pojo.User;
import com.gm.wj.result.Result;
import com.gm.wj.result.ResultFactory;
import com.gm.wj.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import java.util.List;
......@@ -17,4 +18,13 @@ public class UserController {
public List<User> list() throws Exception {
return userService.list();
}
@PutMapping("/api/admin/user")
public Result updateUserStatus(@RequestBody User requestUser) {
User user = userService.getByUserName(requestUser.getUsername());
user.setEnabled(requestUser.isEnabled());
userService.addOrUpdate(user);
String message = "用户"+ requestUser.getUsername() + "状态更新成功";
return ResultFactory.buildSuccessResult(message);
}
}
......@@ -15,8 +15,11 @@ public class User {
int id;
String username;
String password;
String name;
String salt;
String name;
String phone;
String email;
boolean enabled;
public int getId() {
return id;
......@@ -58,5 +61,29 @@ public class User {
this.salt = salt;
}
public String getPhone() {
return phone;
}
public void setPhone(String phone) {
this.phone = phone;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
......@@ -31,7 +31,7 @@ public class UserService {
return userDAO.getByUsernameAndPassword(username, password);
}
public void add(User user) {
public void addOrUpdate(User user) {
userDAO.save(user);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册