新增软件管理权限,包括申请,管理,删除,添加使用时间等

This commit is contained in:
2024-12-27 21:49:11 +08:00
parent ae15530766
commit 7781c6c95c
36 changed files with 728 additions and 74 deletions
@@ -0,0 +1,313 @@
import React, { useEffect, useState } from 'react';
import type { FC } from 'react';
import TemplateContainer from '@/pages/TemplateContainer';
import { useModel } from '@umijs/max';
import { Button, Dropdown, Form, Input, message, Modal, Select, Table, TableProps, Tag } from 'antd';
import { FilterValue, SorterResult, TableCurrentDataSource, TablePaginationConfig } from 'antd/es/table/interface';
import { Software, SoftwareControl } from '@/services/services/software';
import moment from 'moment';
import { DeleteOutlined, EditOutlined, MenuOutlined, PlusSquareOutlined } from '@ant-design/icons';
interface SoftwareControlManagementProps {
// Add your props here
}
const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
const { initialState } = useModel('@@initialState');
const [messageApi, messageHolder] = message.useMessage();
const [loading, setLoading] = React.useState<boolean>(false);
const [modalApi, modalHolder] = Modal.useModal();
const [form] = Form.useForm();
const [softwareBasicInfo, setSoftwareBasicInfo] = useState<SoftwareModel.SoftwareBasicInfo[]>();
const [softwareOptions, setSoftwareOptions] = useState<any>([]);
const [data, setData] = React.useState<SoftwareModel.SoftwareControlBase[]>([]);
const [tableParams, setTableParams] = useState<TableModel.TableParams>({
pagination: {
current: 1,
pageSize: 10,
showQuickJumper: true,
totalBoundaryShowSizeChanger: true,
},
});
const columns: TableProps<SoftwareModel.SoftwareControlBase>['columns'] = [
{
title: '软件代码',
dataIndex: 'software',
width: 100,
key: 'softwareCode',
render: (software) => <span> {software.softwareCode}</span >
},
{
title: '软件名称',
dataIndex: 'software',
key: 'softwareName',
render: (software) => <span>{software.softwareName}</span>,
},
{
title: '所属用户ID',
dataIndex: 'user',
key: 'userId',
render: (user) => <span>{user.id}</span>,
},
{
title: '所属用户名称',
dataIndex: 'user',
key: 'userName',
render: (user) => <span>{user.nickName}</span>,
},
{
title: '创建者',
dataIndex: 'createdUser',
key: 'createdUserNickName',
render: (createdUser) => <span>{createdUser.nickName}</span>,
},
{
title: '更新者',
dataIndex: 'updatedUser',
key: 'updatedUserNickName',
render: (updatedUser) => <span>{updatedUser.nickName}</span>,
},
{
title: '更新时间',
dataIndex: 'updatedTime',
key: 'updatedTime',
width: 200,
render: (updatedTime) => updatedTime ? moment(updatedTime).format('YYYY-MM-DD HH:mm:ss') : 'null',
},
{
title: '到期时间',
dataIndex: 'expirationTime',
key: 'expirationTime',
width: 200,
render: (expirationTime) => expirationTime ? moment(expirationTime).format('YYYY-MM-DD HH:mm:ss') : 'null',
},
{
title: '是否永久',
dataIndex: 'isForever',
key: 'isForever',
width: 100,
render: (isForever) => isForever ? <Tag color="green"></Tag> : <Tag color="red"></Tag>,
},
{
title: '操作',
key: 'action',
width: 100,
render: (_, record) => (
<Dropdown
menu={{
items: [
{
key: 'edit',
label: '编辑',
icon: <EditOutlined />,
onClick: () => {
// 编辑
messageApi.warning("暂不支持编辑");
}
},
{
key: 'addMouth',
label: '添加月付',
style: { color: '#38a2fc' },
icon: <PlusSquareOutlined />,
onClick: async () => {
// 延长到期时间
await AddSoftwareControlExpirationTime(record.id, 30);
}
},
{
key: 'addQuarterly',
label: '添加季付',
style: { color: '#38a2fc' },
icon: <PlusSquareOutlined />,
onClick: async () => {
// 延长到期时间
await AddSoftwareControlExpirationTime(record.id, 90);
}
},
{
key: 'addHalfYear',
label: '添加半年',
style: { color: '#38a2fc' },
icon: <PlusSquareOutlined />,
onClick: async () => {
// 延长到期时间
await AddSoftwareControlExpirationTime(record.id, 180);
}
},
{
key: 'addYear',
label: '添加年付',
style: { color: '#38a2fc' },
icon: <PlusSquareOutlined />,
onClick: async () => {
// 延长到期时间
await AddSoftwareControlExpirationTime(record.id, 365);
}
},
{
key: 'addForever',
label: '永久',
style: { color: '#38a2fc' },
icon: <PlusSquareOutlined />,
onClick: async () => {
// 延长到期时间
await AddSoftwareControlExpirationTime(record.id, 0);
}
},
{
key: 'delete',
label: '停用权限',
danger: true,
icon: <DeleteOutlined />,
onClick: async () => {
await DeleteSoftwareControl(record.id);
}
},
],
}}
>
<Button type="text" color="primary" variant="filled" icon={<MenuOutlined />} />
</Dropdown>
),
}
];
async function DeleteSoftwareControl(id: string) {
try {
const confirmed = await modalApi.confirm({
title: "确认停用",
content: "确定停用吗,重置到期时间和永久选项"
});
if (confirmed) {
setLoading(true);
await SoftwareControl.AddSoftwareControlExpirationTime(id, 0, false);
// 重新查询
await QueryUserSoftwareControlCollection();
messageApi.success("停用成功");
} else {
messageApi.info("取消停用");
}
} catch (error: any) {
messageApi.error(error.message);
} finally {
setLoading(false);
}
}
async function AddSoftwareControlExpirationTime(id: string, days: number) {
try {
const confirmed = await modalApi.confirm({
title: "确认添加",
content: `确认添加 ${days == 0 ? "永久" : days + " 天"} 吗?`
});
if (confirmed) {
setLoading(true);
await SoftwareControl.AddSoftwareControlExpirationTime(id, days, days == 0);
// 重新查询
await QueryUserSoftwareControlCollection();
if (days == 0) {
messageApi.success("添加永久成功");
} else {
messageApi.success("添加 " + days + " 天成功");
}
} else {
messageApi.info("取消添加");
}
} catch (error: any) {
messageApi.error(error.message);
} finally {
setLoading(false);
}
}
async function QueryUserSoftwareControlCollection(options?: SoftwareModel.SoftwareControlQueryParams) {
try {
setLoading(true);
let res = await SoftwareControl.GetUserSoftwareControlCollection(tableParams, options ?? {});
setData(res.collection);
setTableParams({
pagination: {
...tableParams.pagination,
total: res.total
}
});
} catch (error: any) {
messageApi.error(error.message);
} finally {
setLoading(false);
}
}
useEffect(() => {
QueryUserSoftwareControlCollection().then();
Software.GetSoftwareBaseCollection().then((res) => {
setSoftwareBasicInfo(res);
let options = []
for (let i = 0; i < res.length; i++) {
const element = res[i];
let option = {
label: element.isUse == false ? element.softwareName + "(未启用)" : element.softwareName,
value: element.id
}
options.push(option);
}
setSoftwareOptions(options);
}).catch((error) => {
messageApi.error(error.message);
})
}, []);
async function TableChangeHandle(pagination: TablePaginationConfig, filters: Record<string, FilterValue | null>, sorter: SorterResult<SoftwareModel.SoftwareControlBase> | SorterResult<SoftwareModel.SoftwareControlBase>[], extra: TableCurrentDataSource<SoftwareModel.SoftwareControlBase>): Promise<void> {
await QueryUserSoftwareControlCollection();
setTableParams({
pagination: {
...tableParams.pagination,
current: pagination.current,
pageSize: pagination.pageSize,
}
});
}
async function QuerySoftwareControlByCondition(values: any) {
await QueryUserSoftwareControlCollection(values);
}
return (
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "realDark"}>
<Form
layout='inline'
form={form}
onFinish={QuerySoftwareControlByCondition}
>
<Form.Item label="用户ID" name='userId' style={{ marginBottom: 5 }}>
<Input placeholder="请输入用户ID" />
</Form.Item>
<Form.Item label="软件" name='softwareId' style={{ marginBottom: 5 }}>
<Select placeholder="请选择用户名称" style={{ width: 200 }} options={softwareOptions} />
</Form.Item>
<Form.Item label="是否永久" name='IsForever' style={{ marginBottom: 5 }}>
<Select placeholder="请选择是否永久" style={{ width: 200 }} options={[{ label: "是", value: true }, { label: "否", value: false }]} />
</Form.Item>
<Form.Item label="备注" name='remark' style={{ marginBottom: 5 }}>
<Input placeholder="请输入备注" />
</Form.Item>
<Form.Item>
<Button type="primary" htmlType="submit"></Button>
</Form.Item>
</Form>
<div>
<Table<SoftwareModel.SoftwareControlBase> columns={columns} dataSource={data} rowKey={(record) => record.id} pagination={tableParams.pagination} onChange={TableChangeHandle} loading={loading} />
</div>
{messageHolder}
{modalHolder}
</TemplateContainer>
);
};
export default SoftwareControlManagement;