用户新增,删除.

This commit is contained in:
许晓东
2023-05-07 22:55:01 +08:00
parent cc8f671fdb
commit 38ca2cfc52
10 changed files with 506 additions and 12 deletions

View File

@@ -0,0 +1,137 @@
<template>
<a-modal
title="新增用户"
:visible="show"
:width="800"
:mask="false"
:destroyOnClose="true"
:footer="null"
:maskClosable="false"
@cancel="handleCancel"
>
<div>
<a-spin :spinning="loading">
<a-form
:form="form"
:label-col="{ span: 5 }"
:wrapper-col="{ span: 12 }"
@submit="handleSubmit"
>
<a-form-item label="用户名">
<a-input
v-decorator="[
'username',
{ rules: [{ required: true, message: '输入用户名' }] },
]"
placeholder="输入用户名"
/>
</a-form-item>
<a-form-item label="角色">
<a-select
show-search
option-filter-prop="children"
v-decorator="[
'roleIds',
{ rules: [{ required: true, message: '请选择一个角色!' }] },
]"
placeholder="请选择一个角色"
>
<a-select-option
v-for="role in roles"
:key="role.id"
:value="role.id"
>
{{ role.roleName }}
</a-select-option>
</a-select>
</a-form-item>
<a-form-item :wrapper-col="{ span: 12, offset: 5 }">
<a-button type="primary" html-type="submit"> 提交</a-button>
</a-form-item>
</a-form>
</a-spin>
</div>
</a-modal>
</template>
<script>
import request from "@/utils/request";
import notification from "ant-design-vue/es/notification";
import { UserManageApi } from "@/utils/api";
export default {
name: "CreateUser",
props: {
visible: {
type: Boolean,
default: false,
},
},
data() {
return {
show: this.visible,
data: [],
loading: false,
form: this.$form.createForm(this, { name: "coordinated" }),
roles: [],
};
},
watch: {
visible(v) {
this.show = v;
},
},
methods: {
handleSubmit(e) {
e.preventDefault();
this.form.validateFields((err, values) => {
if (!err) {
this.loading = true;
request({
url: UserManageApi.addOrUpdateUser.url,
method: UserManageApi.addOrUpdateUser.method,
data: values,
}).then((res) => {
this.loading = false;
if (res.code == 0) {
this.$message.success(res.msg);
this.$emit("closeCreateUserDialog", { refresh: true });
} else {
notification.error({
message: "error",
description: res.msg,
});
}
});
}
});
},
getRoles() {
this.loading = true;
request({
url: UserManageApi.getRole.url,
method: UserManageApi.getRole.method,
}).then((res) => {
this.loading = false;
if (res.code == 0) {
this.roles = res.data;
} else {
notification.error({
message: "error",
description: res.msg,
});
}
});
},
handleCancel() {
this.data = [];
this.$emit("closeCreateUserDialog", { refresh: false });
},
},
created() {
this.getRoles();
},
};
</script>
<style scoped></style>

View File

@@ -24,7 +24,7 @@
title="确定删除角色?"
ok-text="确认"
cancel-text="取消"
@confirm="deleteRole(item.id)"
@confirm="deleteRole(item)"
>
<a :style="{ display: 'flex' }">
<a-icon type="delete" />
@@ -35,7 +35,7 @@
<span
:style="{ margin: '25px', fontSize: '15px', display: 'block' }"
>
<a><a-icon type="plus" /> 新增角色</a>
<a @click="addRole()"><a-icon type="plus" /> 新增角色</a>
</span>
</a-col>
<a-col :md="20">
@@ -212,16 +212,23 @@ export default {
this.selectedPermissions.push(menu);
});
},
deleteRole(id) {
deleteRole(role) {
if (role.adding) {
this.roles.pop();
return;
}
this.loading = true;
request({
url: UserManageApi.deleteRole.url + "?id=" + id,
url: UserManageApi.deleteRole.url + "?id=" + role.id,
method: UserManageApi.deleteRole.method,
}).then((res) => {
this.loading = false;
if (res.code == 0) {
this.$message.success(res.msg);
this.getRoles();
if (role.id == this.selectedRole.id) {
this.selectedRole = {};
}
} else {
notification.error({
message: "error",
@@ -230,6 +237,15 @@ export default {
}
});
},
addRole() {
const role = {
roleName: "角色名称",
description: "角色描述",
adding: true,
};
this.roles.push(role);
this.selected(role);
},
onSave() {
this.form.validateFields((err, values) => {
if (!err) {

225
ui/src/views/user/User.vue Normal file
View File

@@ -0,0 +1,225 @@
<template>
<div class="tab-content">
<a-spin :spinning="loading">
<div id="search-offset-form-advanced-search">
<a-form
class="ant-advanced-search-form"
:form="form"
@submit="handleSearch"
>
<a-row :gutter="24">
<a-col :span="16">
<a-form-item label="用户名">
<a-input
v-decorator="['username']"
placeholder="请输入用户名!"
@change="onUsernameChange"
/>
</a-form-item>
</a-col>
<a-col :span="2" :style="{ textAlign: 'right' }">
<a-form-item>
<a-button
type="primary"
html-type="submit"
@click="handleSearch()"
>
刷新</a-button
>
</a-form-item>
</a-col>
</a-row>
</a-form>
</div>
<div class="operation-row-button">
<a-button type="primary" @click="openCreateUserDialog()"
>新增用户</a-button
>
</div>
<a-table
:columns="columns"
:data-source="filteredData"
bordered
row-key="id"
>
<div slot="operation" slot-scope="record" v-show="!record.internal">
<a-popconfirm
:title="'删除用户: ' + record.username + ''"
ok-text="确认"
cancel-text="取消"
@confirm="deleteUser(record)"
>
<a-button size="small" href="javascript:;" class="operation-btn"
>删除
</a-button>
</a-popconfirm>
<a-button size="small" href="javascript:;" class="operation-btn"
>重置密码
</a-button>
</div>
</a-table>
<CreateUser
@closeCreateUserDialog="closeCreateUserDialog"
:visible="showCreateUserDialog"
></CreateUser>
</a-spin>
</div>
</template>
<script>
import request from "@/utils/request";
import notification from "ant-design-vue/lib/notification";
import { UserManageApi } from "@/utils/api";
import CreateUser from "@/views/user/CreateUser.vue";
export default {
name: "User",
components: { CreateUser },
props: {
topicList: {
type: Array,
},
},
data() {
return {
loading: false,
form: this.$form.createForm(this, { name: "user" }),
data: [],
filteredData: [],
filterUsername: "",
showCreateUserDialog: false,
columns: [
{
title: "用户名",
dataIndex: "username",
key: "username",
},
{
title: "角色",
dataIndex: "roleIds",
key: "roleIds",
},
{
title: "操作",
key: "operation",
scopedSlots: { customRender: "operation" },
},
],
};
},
methods: {
handleSearch() {
this.form.validateFields((err) => {
if (!err) {
this.loading = true;
request({
url: UserManageApi.getUsers.url,
method: UserManageApi.getUsers.method,
}).then((res) => {
this.loading = false;
if (res.code == 0) {
this.data = res.data;
this.filter();
} else {
notification.error({
message: "error",
description: res.msg,
});
}
});
}
});
},
refresh() {
this.handleSearch();
},
filter() {
this.filteredData = this.data.filter(
(e) => e.username.indexOf(this.filterUsername) != -1
);
},
onUsernameChange(input) {
this.filterUsername = input.target.value;
this.filter();
},
openCreateUserDialog() {
this.showCreateUserDialog = true;
},
closeCreateUserDialog(p) {
this.showCreateUserDialog = false;
if (p.refresh) {
this.refresh();
}
},
deleteUser(user) {
this.loading = true;
request({
url: UserManageApi.deleteUser.url + "?id=" + user.id,
method: UserManageApi.deleteUser.method,
}).then((res) => {
this.loading = false;
if (res.code == 0) {
this.refresh();
} else {
notification.error({
message: "error",
description: res.msg,
});
}
});
},
},
created() {
this.handleSearch();
},
};
</script>
<style scoped>
.tab-content {
width: 100%;
height: 100%;
}
.ant-advanced-search-form {
padding: 24px;
background: #fbfbfb;
border: 1px solid #d9d9d9;
border-radius: 6px;
}
.ant-advanced-search-form .ant-form-item {
display: flex;
}
.ant-advanced-search-form input {
width: 400px;
}
.ant-advanced-search-form .ant-form-item-control-wrapper {
flex: 1;
}
#components-form-topic-advanced-search .ant-form {
max-width: none;
margin-bottom: 1%;
}
#search-offset-form-advanced-search .search-result-list {
margin-top: 16px;
border: 1px dashed #e9e9e9;
border-radius: 6px;
background-color: #fafafa;
min-height: 200px;
text-align: center;
padding-top: 80px;
}
.operation-row-button {
height: 4%;
text-align: left;
margin-bottom: 5px;
margin-top: 5px;
}
</style>

View File

@@ -2,7 +2,9 @@
<div class="content">
<a-spin :spinning="loading">
<a-tabs default-active-key="1" size="large" tabPosition="top">
<a-tab-pane key="1" tab="用户列表"> </a-tab-pane>
<a-tab-pane key="1" tab="用户列表">
<User></User>
</a-tab-pane>
<a-tab-pane key="2" tab="角色列表">
<Role></Role>
</a-tab-pane>
@@ -18,9 +20,10 @@
<script>
import Permission from "@/views/user/Permission.vue";
import Role from "@/views/user/Role.vue";
import User from "@/views/user/User.vue";
export default {
name: "UserManage",
components: { Permission, Role },
components: { Permission, Role, User },
data() {
return {
loading: false,