feat(@vben/common-ui): 重置用户密码功能并优化用户相关操作
This commit is contained in:
parent
250b319c89
commit
d9383868d6
@ -40,6 +40,10 @@ export namespace UserApi {
|
|||||||
confirmPassword: string;
|
confirmPassword: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface PasswordModel {
|
||||||
|
password: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface RoleCreateRecord {
|
export interface RoleCreateRecord {
|
||||||
name: string;
|
name: string;
|
||||||
dataScope: string;
|
dataScope: string;
|
||||||
@ -95,7 +99,7 @@ export namespace UserApi {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface UserUpdateRecord {
|
export interface UserUpdateRecord {
|
||||||
username?: string;
|
name?: string;
|
||||||
email?: string;
|
email?: string;
|
||||||
phone?: string;
|
phone?: string;
|
||||||
address?: string;
|
address?: string;
|
||||||
@ -115,6 +119,17 @@ export function resetPassword(data: UserApi.PasswordReSetModel) {
|
|||||||
return requestClient.patch('/rest/user/self/update-password', data);
|
return requestClient.patch('/rest/user/self/update-password', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 重置密码
|
||||||
|
export function resetPasswordApi(id: any, data: UserApi.PasswordModel) {
|
||||||
|
return requestClient.patch(
|
||||||
|
`/rest/user/${id}/update-password`,
|
||||||
|
{},
|
||||||
|
{
|
||||||
|
params: data,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// 注册用户
|
// 注册用户
|
||||||
export function register(data: UserApi.CreateRecord) {
|
export function register(data: UserApi.CreateRecord) {
|
||||||
return requestClient.post('/rest/user/register', data);
|
return requestClient.post('/rest/user/register', data);
|
||||||
|
@ -22,7 +22,7 @@ const { userInfo } = toRefs(props);
|
|||||||
// 表单提交方法
|
// 表单提交方法
|
||||||
const handleSubmit = async () => {
|
const handleSubmit = async () => {
|
||||||
const res = await selfUpdate({
|
const res = await selfUpdate({
|
||||||
username: userInfo.value.username,
|
name: userInfo.value.name,
|
||||||
phone: userInfo.value.phone,
|
phone: userInfo.value.phone,
|
||||||
email: userInfo.value.email,
|
email: userInfo.value.email,
|
||||||
address: userInfo.value.address,
|
address: userInfo.value.address,
|
||||||
@ -51,7 +51,7 @@ const handleSubmit = async () => {
|
|||||||
style="max-width: 500px; margin: 0 auto"
|
style="max-width: 500px; margin: 0 auto"
|
||||||
>
|
>
|
||||||
<Form.Item label="用户名">
|
<Form.Item label="用户名">
|
||||||
<Input v-model:value="userInfo.username" />
|
<Input v-model:value="userInfo.name" />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item label="邮箱" name="email">
|
<Form.Item label="邮箱" name="email">
|
||||||
<Input v-model:value="userInfo.email" />
|
<Input v-model:value="userInfo.email" />
|
||||||
|
@ -188,6 +188,10 @@ export function useColumns<T = UserApi.User>(
|
|||||||
onClick: onActionClick,
|
onClick: onActionClick,
|
||||||
},
|
},
|
||||||
options: [
|
options: [
|
||||||
|
{
|
||||||
|
code: 'resetPassword',
|
||||||
|
text: '重置密码',
|
||||||
|
},
|
||||||
{
|
{
|
||||||
code: 'edit',
|
code: 'edit',
|
||||||
text: '修改',
|
text: '修改',
|
||||||
@ -202,7 +206,7 @@ export function useColumns<T = UserApi.User>(
|
|||||||
field: 'operation',
|
field: 'operation',
|
||||||
fixed: 'right',
|
fixed: 'right',
|
||||||
title: '操作',
|
title: '操作',
|
||||||
width: 130,
|
width: 200,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,10 @@ import type {
|
|||||||
} from '#/adapter/vxe-table';
|
} from '#/adapter/vxe-table';
|
||||||
import type { UserApi } from '#/api';
|
import type { UserApi } from '#/api';
|
||||||
|
|
||||||
import { Page, useVbenDrawer } from '@vben/common-ui';
|
import { Page, useVbenDrawer, useVbenModal } from '@vben/common-ui';
|
||||||
import { Plus } from '@vben/icons';
|
import { Plus } from '@vben/icons';
|
||||||
|
|
||||||
import { Button, message, Modal } from 'ant-design-vue';
|
import { Button, message } from 'ant-design-vue';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
import { useVbenVxeGrid } from '#/adapter/vxe-table';
|
||||||
@ -19,12 +19,18 @@ import { $t } from '#/locales';
|
|||||||
|
|
||||||
import { useColumns, useGridFormSchema } from './data';
|
import { useColumns, useGridFormSchema } from './data';
|
||||||
import Form from './modules/form.vue';
|
import Form from './modules/form.vue';
|
||||||
|
import ResetModal from './modules/reset-form.vue';
|
||||||
|
|
||||||
const [FormDrawer, formDrawerApi] = useVbenDrawer({
|
const [FormDrawer, formDrawerApi] = useVbenDrawer({
|
||||||
connectedComponent: Form,
|
connectedComponent: Form,
|
||||||
destroyOnClose: true,
|
destroyOnClose: true,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const [ResetPasswordModal, modalApi] = useVbenModal({
|
||||||
|
connectedComponent: ResetModal,
|
||||||
|
destroyOnClose: true,
|
||||||
|
});
|
||||||
|
|
||||||
const [Grid, gridApi] = useVbenVxeGrid({
|
const [Grid, gridApi] = useVbenVxeGrid({
|
||||||
formOptions: {
|
formOptions: {
|
||||||
fieldMappingTime: [['createTime', ['startTime', 'endTime']]],
|
fieldMappingTime: [['createTime', ['startTime', 'endTime']]],
|
||||||
@ -73,6 +79,10 @@ function onActionClick(e: OnActionClickParams<UserApi.User>) {
|
|||||||
onEdit(e.row);
|
onEdit(e.row);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case 'resetPassword': {
|
||||||
|
onResetPassword(e.row);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,6 +133,10 @@ function onEdit(row: UserApi.User) {
|
|||||||
formDrawerApi.setData(row).open();
|
formDrawerApi.setData(row).open();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function onResetPassword(row: UserApi.User) {
|
||||||
|
modalApi.setData(row).open();
|
||||||
|
}
|
||||||
|
|
||||||
function onDelete(row: UserApi.User) {
|
function onDelete(row: UserApi.User) {
|
||||||
const hideLoading = message.loading({
|
const hideLoading = message.loading({
|
||||||
content: $t('ui.actionMessage.deleting', [row.name]),
|
content: $t('ui.actionMessage.deleting', [row.name]),
|
||||||
@ -152,6 +166,7 @@ function onCreate() {
|
|||||||
</script>
|
</script>
|
||||||
<template>
|
<template>
|
||||||
<Page auto-content-height>
|
<Page auto-content-height>
|
||||||
|
<ResetPasswordModal />
|
||||||
<FormDrawer />
|
<FormDrawer />
|
||||||
<Grid table-title="用户列表">
|
<Grid table-title="用户列表">
|
||||||
<template #toolbar-tools>
|
<template #toolbar-tools>
|
||||||
|
@ -21,7 +21,7 @@ import { useFormSchema } from '../data';
|
|||||||
const emits = defineEmits(['success']);
|
const emits = defineEmits(['success']);
|
||||||
|
|
||||||
const formData = ref<UserApi.User>();
|
const formData = ref<UserApi.User>();
|
||||||
|
const id = ref();
|
||||||
const [Form, formApi] = useVbenForm({
|
const [Form, formApi] = useVbenForm({
|
||||||
schema: useFormSchema(),
|
schema: useFormSchema(),
|
||||||
showDefaultActions: false,
|
showDefaultActions: false,
|
||||||
@ -30,7 +30,6 @@ const [Form, formApi] = useVbenForm({
|
|||||||
const permissions = ref<DataNode[]>([]);
|
const permissions = ref<DataNode[]>([]);
|
||||||
const loadingPermissions = ref(false);
|
const loadingPermissions = ref(false);
|
||||||
|
|
||||||
const id = ref();
|
|
||||||
const [Drawer, drawerApi] = useVbenDrawer({
|
const [Drawer, drawerApi] = useVbenDrawer({
|
||||||
async onConfirm() {
|
async onConfirm() {
|
||||||
const { valid } = await formApi.validate();
|
const { valid } = await formApi.validate();
|
||||||
|
51
apps/web-antd/src/views/user/modules/reset-form.vue
Normal file
51
apps/web-antd/src/views/user/modules/reset-form.vue
Normal file
@ -0,0 +1,51 @@
|
|||||||
|
<script setup lang="ts">
|
||||||
|
import type { UserApi } from '#/api';
|
||||||
|
|
||||||
|
import { ref } from 'vue';
|
||||||
|
|
||||||
|
import { useVbenModal } from '@vben/common-ui';
|
||||||
|
|
||||||
|
import { Input } from 'ant-design-vue';
|
||||||
|
|
||||||
|
import { resetPasswordApi } from '#/api';
|
||||||
|
|
||||||
|
const emits = defineEmits(['success']);
|
||||||
|
const userId = ref();
|
||||||
|
const resetpasswordData = ref();
|
||||||
|
const formData = ref();
|
||||||
|
|
||||||
|
const [Modal, modalApi] = useVbenModal({
|
||||||
|
async onConfirm() {
|
||||||
|
if (!resetpasswordData.value) return;
|
||||||
|
|
||||||
|
modalApi.lock();
|
||||||
|
try {
|
||||||
|
await resetPasswordApi(userId.value, {
|
||||||
|
password: resetpasswordData.value,
|
||||||
|
});
|
||||||
|
emits('success');
|
||||||
|
modalApi.close();
|
||||||
|
} finally {
|
||||||
|
modalApi.lock(false);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
onOpenChange(isOpen) {
|
||||||
|
if (isOpen) {
|
||||||
|
formData.value = modalApi.getData<UserApi.User>();
|
||||||
|
userId.value = formData.value.id;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<template>
|
||||||
|
<Modal title="重置密码">
|
||||||
|
<Input.Password
|
||||||
|
class="my-4"
|
||||||
|
placeholder="请输入密码"
|
||||||
|
v-model:value="resetpasswordData"
|
||||||
|
/>
|
||||||
|
</Modal>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<style scoped></style>
|
Loading…
Reference in New Issue
Block a user