新增管理员密码重置
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import TemplateContainer from '@/pages/TemplateContainer';
|
||||
import { GetUserAgentInfo, GetUserInfo } from '@/services/services/user';
|
||||
import { UserInfo } from '@/services/services/user';
|
||||
import { RedoOutlined } from '@ant-design/icons';
|
||||
import { useModel } from '@umijs/max';
|
||||
import { Avatar, Badge, Button, Card, Col, FloatButton, Input, message, Modal, Row, Spin, Tag } from 'antd';
|
||||
@@ -23,10 +23,10 @@ const UserCenter: React.FC = () => {
|
||||
// 初始化加载用户信息
|
||||
setTopSpinning(true);
|
||||
setTopSpinTip("正在获取用户信息。。。");
|
||||
GetUserInfo(initialState?.currentUser?.id).then(async (res) => {
|
||||
UserInfo.GetUserInfo(initialState?.currentUser?.id).then(async (res) => {
|
||||
setInitialState({ ...initialState, currentUser: res });
|
||||
localStorage.setItem('userInfo', JSON.stringify(res));
|
||||
let agentInfo = await GetUserAgentInfo();
|
||||
let agentInfo = await UserInfo.GetUserAgentInfo();
|
||||
setUserAgentUserInfo(agentInfo);
|
||||
}).catch((error) => {
|
||||
messageApi.error(error.message);
|
||||
|
||||
@@ -5,7 +5,7 @@ import renderTitle from '../UserRenderList';
|
||||
import { isEmpty } from 'lodash';
|
||||
import { useModel } from '@umijs/max';
|
||||
import { useSoftStore } from '@/store/software';
|
||||
import { EnableAgent, GetUserAgentInfo, GetUserInfo } from '@/services/services/user';
|
||||
import { UserInfo } from '@/services/services/user';
|
||||
|
||||
type UserCenterAgentMessageProps = {
|
||||
userAgentUserInfo: UserModel.UserAgentInfo | undefined;
|
||||
@@ -28,15 +28,15 @@ const UserCenterAgentMessage: React.FC<UserCenterAgentMessageProps> = ({ userAge
|
||||
setTopSpinTip("正在启用代理。。。");
|
||||
// 开始调用启用代理的接口
|
||||
try {
|
||||
await EnableAgent();
|
||||
await UserInfo.EnableAgent();
|
||||
messageApi.success("启用代理成功");
|
||||
// 冲i性能加载用户信息
|
||||
if (initialState?.currentUser?.id) {
|
||||
let res = await GetUserInfo(initialState?.currentUser?.id);
|
||||
let res = await UserInfo.GetUserInfo(initialState?.currentUser?.id);
|
||||
localStorage.setItem('userInfo', JSON.stringify(res));
|
||||
setInitialState({ ...initialState, currentUser: res });
|
||||
// 重新加载代理信息
|
||||
let agentInfo = await GetUserAgentInfo();
|
||||
let agentInfo = await UserInfo.GetUserAgentInfo();
|
||||
setUserAgentUserInfo(agentInfo);
|
||||
}
|
||||
} catch (error: any) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { QueryRoleOption } from '@/services/services/role';
|
||||
import { GetUserInfo, UpdatedUserInfo } from '@/services/services/user';
|
||||
import { UserInfo } from '@/services/services/user';
|
||||
import { FormatDate } from '@/util/time';
|
||||
import { useModel } from '@umijs/max';
|
||||
import { Button, Col, Form, FormInstance, Input, InputNumber, message, Row, Select, SelectProps, Spin, Tag } from 'antd';
|
||||
@@ -38,7 +38,7 @@ const ModifyUser: React.FC<ModifyUserProps> = ({ userId, setFormRef, open }) =>
|
||||
setLoading(false);
|
||||
})
|
||||
|
||||
GetUserInfo(userId).then((res) => {
|
||||
UserInfo.GetUserInfo(userId).then((res) => {
|
||||
let tempRes = {
|
||||
...res,
|
||||
createdDate: FormatDate(res.createdDate)
|
||||
@@ -55,7 +55,7 @@ const ModifyUser: React.FC<ModifyUserProps> = ({ userId, setFormRef, open }) =>
|
||||
setLoading(true);
|
||||
setSpinTip("修改中...");
|
||||
try {
|
||||
await UpdatedUserInfo(values);
|
||||
await UserInfo.UpdatedUserInfo(values);
|
||||
messageApi.success("用户修改成功");
|
||||
} catch (error: any) {
|
||||
messageApi.error(error.message);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Form, Input, Button, message, Tooltip } from 'antd';
|
||||
import DiceIcon from '@/components/Icon/DiceIcon';
|
||||
import { generateRandomPassword } from '@/util/password';
|
||||
import { set, toArray } from 'lodash';
|
||||
import { useSoftStore } from '@/store/software';
|
||||
import { UserInfo } from '@/services/services/user';
|
||||
|
||||
interface ResetUserPasswordProps {
|
||||
userId: number;
|
||||
}
|
||||
|
||||
const ResetUserPassword: React.FC<ResetUserPasswordProps> = ({ userId }) => {
|
||||
const [newPassword, setNewPassword] = useState<string>('');
|
||||
const [messageApi, messageHolder] = message.useMessage();
|
||||
const { setTopSpinning, setTopSpinTip } = useSoftStore();
|
||||
|
||||
return (
|
||||
<div style={{ display: 'flex', alignItems: 'center', gap: '8px', marginTop: '16px' }}>
|
||||
<Input
|
||||
value={newPassword}
|
||||
onChange={(e) => setNewPassword(e.target.value)}
|
||||
placeholder="请输入新密码"
|
||||
/>
|
||||
<Button
|
||||
icon={<DiceIcon />}
|
||||
color="primary"
|
||||
variant="filled"
|
||||
onClick={() => {
|
||||
let newPw = generateRandomPassword();
|
||||
console.log(newPw);
|
||||
setNewPassword(newPw);
|
||||
}}
|
||||
/>
|
||||
<Tooltip title="确认重置用户密码">
|
||||
<Button type="primary" onClick={async () => {
|
||||
setTopSpinning(true);
|
||||
setTopSpinTip('正在重置密码。。。');
|
||||
// 调用重置密码的方法
|
||||
try {
|
||||
await UserInfo.ResetUserPassword(userId, newPassword);
|
||||
} catch (error: any) {
|
||||
messageApi.error('密码重置失败, ' + error.message);
|
||||
} finally {
|
||||
setTopSpinning(false);
|
||||
}
|
||||
messageApi.success('密码重置成功 ' + newPassword);
|
||||
// setPasswordModel(false);
|
||||
}}>
|
||||
确认重置
|
||||
</Button>
|
||||
</Tooltip>
|
||||
{messageHolder}
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default ResetUserPassword;
|
||||
@@ -1,7 +1,7 @@
|
||||
import { useFormReset } from "@/hooks/useFormReset";
|
||||
import TemplateContainer from "@/pages/TemplateContainer";
|
||||
import { QueryRoleOption } from "@/services/services/role";
|
||||
import { QueryUserList } from "@/services/services/user";
|
||||
import { UserInfo } from "@/services/services/user";
|
||||
import { FormatDate } from "@/util/time";
|
||||
import { useAccess, useModel } from "@umijs/max";
|
||||
import { Button, Dropdown, Form, Input, InputNumber, message, Modal, Select, SelectProps, Table, Tag, Tooltip } from "antd";
|
||||
@@ -9,8 +9,12 @@ import { ColumnsType, TablePaginationConfig } from "antd/es/table";
|
||||
import { FilterValue, SorterResult, TableCurrentDataSource } from "antd/es/table/interface";
|
||||
import { useEffect, useState } from "react";
|
||||
import ModifyUser from "../ModifyUser";
|
||||
import { DeleteOutlined, EditOutlined, MenuOutlined, SyncOutlined } from "@ant-design/icons";
|
||||
import Icon, { DeleteOutlined, EditOutlined, KeyOutlined, MenuOutlined, SyncOutlined } from "@ant-design/icons";
|
||||
import { SoftwareControl } from "@/services/services/software";
|
||||
import { CustomIconComponentProps } from "@ant-design/icons/lib/components/Icon";
|
||||
import DiceIcon from "@/components/Icon/DiceIcon";
|
||||
import { generateRandomPassword } from "@/util/password";
|
||||
import ResetUserPassword from "./ResetUserPassword";
|
||||
|
||||
const UserManagement: React.FC = () => {
|
||||
type TagRender = SelectProps['tagRender'];
|
||||
@@ -33,6 +37,7 @@ const UserManagement: React.FC = () => {
|
||||
const [userId, setUserId] = useState<number>(0);
|
||||
const [openModal, setOpenModal] = useState<boolean>(false);
|
||||
const [roleNames, setRoleNames] = useState<SelectProps['options']>([]);
|
||||
const [modal, modaltHolder] = Modal.useModal();
|
||||
|
||||
|
||||
|
||||
@@ -48,7 +53,7 @@ const UserManagement: React.FC = () => {
|
||||
messageApi.error(error.message);
|
||||
})
|
||||
|
||||
QueryUserList(tableParams, form.getFieldsValue())
|
||||
UserInfo.QueryUserList(tableParams, form.getFieldsValue())
|
||||
.then((res) => {
|
||||
setData(res.collection);
|
||||
setTableParams({
|
||||
@@ -71,7 +76,7 @@ const UserManagement: React.FC = () => {
|
||||
setLoading(true);
|
||||
try {
|
||||
let tableParamsParams = pagination ? { pagination } : tableParams;
|
||||
let res = await QueryUserList(tableParamsParams, params ?? form.getFieldsValue());
|
||||
let res = await UserInfo.QueryUserList(tableParamsParams, params ?? form.getFieldsValue());
|
||||
setData(res.collection);
|
||||
setTableParams({
|
||||
pagination: {
|
||||
@@ -89,7 +94,7 @@ const UserManagement: React.FC = () => {
|
||||
async function handleTableChange(pagination: TablePaginationConfig, filters: Record<string, FilterValue | null>, sorter: SorterResult<UserModel.UserCollection> | SorterResult<UserModel.UserCollection>[], extra: TableCurrentDataSource<UserModel.UserCollection>): Promise<void> {
|
||||
setLoading(true);
|
||||
try {
|
||||
let queryUser = await QueryUserList({ pagination }, form.getFieldsValue());
|
||||
let queryUser = await UserInfo.QueryUserList({ pagination }, form.getFieldsValue());
|
||||
setData(queryUser.collection);
|
||||
setTableParams({
|
||||
pagination: {
|
||||
@@ -136,6 +141,17 @@ const UserManagement: React.FC = () => {
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
async function ResetUserPasswordFunc(userId: number) {
|
||||
modal.info({
|
||||
title: '重置密码',
|
||||
width: 500,
|
||||
closable: true,
|
||||
content: <ResetUserPassword userId={userId} />,
|
||||
footer: null
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 给指定用户申请软件控制权限
|
||||
* @param userId 用户ID
|
||||
@@ -246,6 +262,15 @@ const UserManagement: React.FC = () => {
|
||||
setOpenModal(true);
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'resetPassword',
|
||||
label: '重置密码',
|
||||
icon: <KeyOutlined />,
|
||||
hidden: !access.isSuperAdmin,
|
||||
onClick: async () => {
|
||||
await ResetUserPasswordFunc(record.id);
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'apply',
|
||||
label: '初始化权限',
|
||||
@@ -344,6 +369,7 @@ const UserManagement: React.FC = () => {
|
||||
<ModifyUser setFormRef={setFormRef} open={openModal} userId={userId} />
|
||||
</Modal>
|
||||
{messageHolder}
|
||||
{modaltHolder}
|
||||
</TemplateContainer>
|
||||
);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user