|
|
@@ -1,12 +1,13 @@
|
|
|
import {useContextSection, useQueryTableList} from '@hooks';
|
|
|
import {useMutation} from '@tanstack/react-query';
|
|
|
import {context, pageContext, searchContext} from '../context';
|
|
|
-import {deleteUser, getUserList} from '@apis';
|
|
|
+import {deleteUser, getUserList, resetUserPassword} from '@apis';
|
|
|
import {UserListData} from '@models';
|
|
|
import {ColumnsType} from 'antd/es/table';
|
|
|
import {useState} from 'react';
|
|
|
import {Button, Modal, message} from 'antd';
|
|
|
import {useBoolean} from 'ahooks';
|
|
|
+import {deleteConfirm} from '@utils';
|
|
|
|
|
|
export function useList() {
|
|
|
const params = useContextSection(
|
|
|
@@ -26,6 +27,29 @@ export function useList() {
|
|
|
return [{data, isFetching, count}, {refetch}] as const;
|
|
|
}
|
|
|
|
|
|
+export function useResetPassword() {
|
|
|
+ const {isLoading, mutate} = useMutation({
|
|
|
+ mutationFn: resetUserPassword,
|
|
|
+ onSuccess({msg}) {
|
|
|
+ msg === '200' && message.success('密码重置成功');
|
|
|
+ },
|
|
|
+ });
|
|
|
+
|
|
|
+ function onClick(name: string, id: string) {
|
|
|
+ return function() {
|
|
|
+ Modal.confirm({
|
|
|
+ title: '重置密码',
|
|
|
+ content: `你确定要重置${name}的密码吗?`,
|
|
|
+ onOk() {
|
|
|
+ mutate(id);
|
|
|
+ },
|
|
|
+ });
|
|
|
+ };
|
|
|
+ }
|
|
|
+
|
|
|
+ return [isLoading, onClick] as const;
|
|
|
+}
|
|
|
+
|
|
|
export function useHandle(onFetch: () => void) {
|
|
|
const [visible, {setTrue, setFalse}] = useBoolean();
|
|
|
|
|
|
@@ -45,13 +69,9 @@ export function useHandle(onFetch: () => void) {
|
|
|
);
|
|
|
function onDelte(id: string) {
|
|
|
return function() {
|
|
|
- Modal.confirm({
|
|
|
- title: '删除用户',
|
|
|
- content: '你确定要删除当前用户吗?',
|
|
|
- onOk() {
|
|
|
- setPendingId(id);
|
|
|
- mutate(id);
|
|
|
- },
|
|
|
+ deleteConfirm('用户', function() {
|
|
|
+ setPendingId(id);
|
|
|
+ mutate(id);
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
@@ -70,6 +90,7 @@ export function useHandle(onFetch: () => void) {
|
|
|
setEditId('');
|
|
|
}
|
|
|
|
|
|
+ const [isReseting, onResetClick] = useResetPassword();
|
|
|
const columns: ColumnsType<UserListData> = [
|
|
|
{title: '用户编号', dataIndex: 'code', key: 'code', width: 150},
|
|
|
{title: '用户名称', dataIndex: 'userName', key: 'userName', width: 250},
|
|
|
@@ -84,9 +105,9 @@ export function useHandle(onFetch: () => void) {
|
|
|
title: '操作',
|
|
|
dataIndex: 'id',
|
|
|
key: 'id',
|
|
|
- width: 200,
|
|
|
+ width: 260,
|
|
|
fixed: 'right',
|
|
|
- render(_, {id}) {
|
|
|
+ render(_, {id, realName}) {
|
|
|
return (
|
|
|
<>
|
|
|
<Button
|
|
|
@@ -104,6 +125,14 @@ export function useHandle(onFetch: () => void) {
|
|
|
>
|
|
|
删除
|
|
|
</Button>
|
|
|
+ <Button
|
|
|
+ type='text'
|
|
|
+ disabled={String(id) === pendingId}
|
|
|
+ loading={isReseting}
|
|
|
+ onClick={onResetClick(realName, String(id))}
|
|
|
+ >
|
|
|
+ 重置密码
|
|
|
+ </Button>
|
|
|
</>
|
|
|
);
|
|
|
},
|