add User.vue and User delete,list

This commit is contained in:
shiziyuan9527 2020-02-11 17:24:30 +08:00
parent eb9767c2d1
commit 8b227c09ac
5 changed files with 213 additions and 6 deletions

View File

@ -3,13 +3,10 @@ package io.metersphere.controller;
import io.metersphere.base.domain.User;
import io.metersphere.dto.UserDTO;
import io.metersphere.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;
@RequestMapping("user")
@RestController
@ -22,4 +19,13 @@ public class UserController {
public UserDTO insertUser(@RequestBody User user) {
return userService.insert(user);
}
@GetMapping("/list")
public List<User> getUserList() { return userService.getUserList(); }
@GetMapping("/delete/{userId}")
public void deleteUser(@PathVariable(value = "userId") String userId) { userService.deleteUser(userId); }
@PostMapping("/update")
public void updateUser(@RequestBody User user) { userService.updateUser(user); }
}

View File

@ -87,6 +87,16 @@ public class UserService {
return userDTO;
}
public List<User> getUserList() {
UserExample userExample = new UserExample();
return userMapper.selectByExample(userExample);
}
public void deleteUser(String userId) {
userMapper.deleteByPrimaryKey(userId);
}
public void updateUser(User user) {
userMapper.updateByPrimaryKey(user);
}
}

View File

@ -3,6 +3,7 @@ import VueRouter from 'vue-router'
import RouterSidebar from "./RouterSidebar";
import Setting from "../settings/Setting";
import Workspace from "../settings/Workspace";
import User from "../settings/User";
Vue.use(VueRouter);
@ -20,6 +21,10 @@ const router = new VueRouter({
{
path: 'workspace',
component: Workspace
},
{
path: 'user',
component: User
}
]
}]

View File

@ -5,7 +5,7 @@
<font-awesome-icon class="icon account" :icon="['far', 'address-card']" size="lg"/>
<span>账号</span>
</template>
<el-menu-item>用户</el-menu-item>
<el-menu-item index="/content/user">用户</el-menu-item>
<el-menu-item index="/content/workspace">工作空间</el-menu-item>
<el-menu-item>API Keys</el-menu-item>
</el-submenu>

View File

@ -0,0 +1,186 @@
<template>
<div v-loading="loading">
<el-card>
<div slot="header">
<el-row type="flex" justify="space-between" align="middle">
<span class="title">用户</span>
<span class="search">
<el-input type="text" size="small" placeholder="根据ID名称搜索" prefix-icon="el-icon-search"
maxlength="60" v-model="condition" clearable/>
</span>
</el-row>
</div>
<el-table :data="items" style="width: 100%">
<el-table-column prop="id" label="ID" width="180"/>
<el-table-column prop="name" label="用户名"/>
<el-table-column prop="email" label="邮箱"/>
<el-table-column prop="phone" label="电话"/>
<el-table-column prop="status" label="状态"/>
<el-table-column prop="createTime" label="创建时间"/>
<el-table-column>
<template slot-scope="scope">
<el-button @click="edit(scope.row)" type="primary" icon="el-icon-edit" size="mini" circle/>
<el-button @click="del(scope.row)" type="danger" icon="el-icon-delete" size="mini" circle/>
</template>
</el-table-column>
</el-table>
</el-card>
<ms-create-box :tips="btnTips" :exec="create"/>
<el-dialog title="创建用户" :visible.sync="createVisible" width="30%">
<el-form :model="form" label-position="left" label-width="100px" size="small" :rules="rule" ref="validateForm">
<el-form-item label="ID" prop="id">
<el-input v-model="form.id" autocomplete="off"/>
</el-form-item>
<el-form-item label="用户名" prop="name">
<el-input v-model="form.name" autocomplete="off"/>
</el-form-item>
<el-form-item label="邮箱" prop="email">
<el-input v-model="form.email" autocomplete="off"/>
</el-form-item>
<el-form-item label="电话" prop="phone">
<el-input v-model="form.phone" autocomplete="off"/>
</el-form-item>
<el-form-item label="启用">
<el-switch v-model="form.enable"/>
</el-form-item>
</el-form>
<span slot="footer" class="dialog-footer">
<el-button type="primary" @click="createUser('validateForm')" size="medium">创建</el-button>
</span>
</el-dialog>
</div>
</template>
<script>
import MsCreateBox from "./CreateBox";
export default {
name: "MsUser",
components: {MsCreateBox},
created() {
this.getUserList();
},
methods: {
create() {
this.createVisible = true;
this.$get("/test/list");
},
edit(row) {
window.console.log(row);
this.loading = true;
let self = this;
let getUser1 = this.$get("/test/user");
let getUser2 = this.$get("/test/sleep");
this.$all([getUser1, getUser2], function (r1, r2) {
window.console.log(r1.data.data, r2.data.data);
self.loading = false;
});
/*this.$post("/update", row).then(()=>{
this.getUserList()
})*/
},
del(row) {
window.console.log(row);
this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
confirmButtonText: '确定',
cancelButtonText: '取消',
type: 'warning'
}).then(() => {
this.$get(`/user/delete/${row.id}`).then(() => {
this.getUserList()
}),
this.$message({
type: 'success',
message: '删除成功!'
});
}).catch(() => {
this.$message({
type: 'info',
message: '已取消删除'
});
});
},
createUser: function (validateForm) {
this.$refs[validateForm].validate(valide => {
if (valide) {
this.$post("/user/add", this.form)
.then(() => {
this.$message({
type: 'success',
message: '添加成功!'
},
this.createVisible = false,
this.getUserList())
});
} else {
return false;
}
})
},
getUserList() {
this.$get("/user/list").then(response => {
this.items = response.data;
})
}
},
data() {
return {
loading: false,
createVisible: false,
btnTips: "添加用户",
condition: "",
items: [],
form: {},
rule: {
id: [
{required: true, message: '请输入ID', trigger: 'blur'},
{ min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' },
{
required: true,
pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9.·-]+$/,
message: 'ID不支持特殊字符',
trigger: 'blur'
}
],
name: [
{required: true, message: '请输入姓名', trigger: 'blur'},
{ min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' },
{
required: true,
pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9.·-]+$/,
message: '姓名不支持特殊字符',
trigger: 'blur'
}
],
phone: [
{
required: false,
pattern: '^1(3|4|5|7|8)\\d{9}$',
message: '手机号码格式不正确!',
trigger: 'blur'
}
],
email: [
{required: true, message: '请输入邮箱', trigger: 'blur'},
{
required: true,
pattern: /^([A-Za-z0-9_\-.])+@(163.com|qq.com|42du.cn)$/,
message: '邮箱格式不正确!',
trigger: 'blur'
}
]
}
}
}
}
</script>
<style scoped>
.search {
width: 240px;
}
</style>