修改Laitool的软件控制权限
This commit is contained in:
parent
6512858af4
commit
ece7c82a80
@ -25,7 +25,7 @@ export default function access(initialState: { currentUser?: API.CurrentUser } |
|
||||
canAddMachine: true,
|
||||
canEditMachine: false,
|
||||
canDeleteMachine: false,
|
||||
canUpgradeMachine: false,
|
||||
canUpgradeMachine: true,
|
||||
canDisableMachine: true
|
||||
} as AccessType.AccessType;
|
||||
|
||||
|
||||
@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react';
|
||||
import { Form, Input, Button, FormInstance, Spin, message, Select, DatePicker, InputNumber } from 'antd';
|
||||
import moment from 'moment';
|
||||
import { AddMachineData } from '@/services/services/machine';
|
||||
import { useModel } from '@umijs/max';
|
||||
import { useAccess, useModel } from '@umijs/max';
|
||||
|
||||
interface AddMachineModalProps {
|
||||
setFormRef: (form: FormInstance) => void;
|
||||
@ -13,6 +13,7 @@ const AddMachineForm: React.FC<AddMachineModalProps> = ({ setFormRef }) => {
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [messageApi, messageHolder] = message.useMessage();
|
||||
const { initialState } = useModel('@@initialState');
|
||||
const access = useAccess();
|
||||
|
||||
useEffect(() => {
|
||||
setFormRef(form);
|
||||
@ -28,9 +29,8 @@ const AddMachineForm: React.FC<AddMachineModalProps> = ({ setFormRef }) => {
|
||||
}, [form, setFormRef]);
|
||||
|
||||
const onFinish = async (values: MachineModel.AddMachineParams) => {
|
||||
if (values.useStatus == 0 && !values.deactivationTime) {
|
||||
messageApi.error("试用机器码需要设置停用时间")
|
||||
return;
|
||||
if (values.userId == null) {
|
||||
messageApi.error("请填写所属用户ID");
|
||||
}
|
||||
setLoading(true);
|
||||
try {
|
||||
@ -60,48 +60,12 @@ const AddMachineForm: React.FC<AddMachineModalProps> = ({ setFormRef }) => {
|
||||
>
|
||||
<Input />
|
||||
</Form.Item>
|
||||
<Form.Item<MachineModel.AddMachineParams>
|
||||
label="使用状态"
|
||||
name="useStatus"
|
||||
rules={[{ required: true, message: 'Please input the role name!' }]}
|
||||
>
|
||||
<Select onChange={(value) => {
|
||||
if (value == 1) {
|
||||
form.setFieldsValue({ deactivationTime: null })
|
||||
} else {
|
||||
const currentDate = new Date();
|
||||
const nextDayDate = new Date(currentDate);
|
||||
nextDayDate.setDate(currentDate.getDate() + 1);
|
||||
form.setFieldsValue({ deactivationTime: moment(nextDayDate) })
|
||||
}
|
||||
}}>
|
||||
<Select.Option value={0}>试用</Select.Option>
|
||||
<Select.Option value={1}>永久</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
<Form.Item<MachineModel.AddMachineParams>
|
||||
label="状态"
|
||||
name="status"
|
||||
rules={[{ required: true, message: 'Please input the role name!' }]}
|
||||
>
|
||||
<Select >
|
||||
<Select.Option value={0}>冻结</Select.Option>
|
||||
<Select.Option value={1}>激活</Select.Option>
|
||||
</Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item<MachineModel.AddMachineParams>
|
||||
label="停用时间"
|
||||
name="deactivationTime"
|
||||
>
|
||||
<DatePicker showTime />
|
||||
</Form.Item>
|
||||
<Form.Item<MachineModel.AddMachineParams>
|
||||
label="所属用户ID"
|
||||
name="userId"
|
||||
rules={[{ required: true, message: 'Please input the role name!' }]}
|
||||
>
|
||||
<InputNumber style={{ width: 200 }} keyboard={false} min={0} changeOnWheel={false} controls={false} />
|
||||
<InputNumber disabled={!access.isAdminOrSuperAdmin} style={{ width: 200 }} keyboard={false} min={0} changeOnWheel={false} controls={false} />
|
||||
</Form.Item>
|
||||
<Form.Item<MachineModel.AddMachineParams>
|
||||
label="备注"
|
||||
|
||||
@ -4,13 +4,13 @@ import TemplateContainer from "@/pages/TemplateContainer";
|
||||
import { DeactivationMachine, MachinePermanent, QueryMachineList } from "@/services/services/machine";
|
||||
import { FormatDate } from "@/util/time";
|
||||
import { useAccess, useModel } from "@umijs/max";
|
||||
import { Button, Form, Input, message, Modal, Select, SelectProps, Spin, Table, Tag } from "antd";
|
||||
import { Button, Dropdown, Form, Input, Menu, message, Modal, Select, SelectProps, Spin, Table, Tag } from "antd";
|
||||
import { ColumnsType, TablePaginationConfig } from "antd/es/table";
|
||||
import { FilterValue, SorterResult, TableCurrentDataSource } from "antd/es/table/interface";
|
||||
import { delay, set } from "lodash";
|
||||
import { useEffect, useState } from "react";
|
||||
import ModifyMachine from "../ModifyMachine";
|
||||
import { PlusOutlined } from "@ant-design/icons";
|
||||
import { DownOutlined, EditOutlined, MenuOutlined, MoreOutlined, PlusOutlined, SafetyCertificateOutlined, StopOutlined } from "@ant-design/icons";
|
||||
import AddMachineForm from "../AddMachineForm";
|
||||
|
||||
const MachineManagement: React.FC = () => {
|
||||
@ -35,6 +35,7 @@ const MachineManagement: React.FC = () => {
|
||||
const [openAddModal, setOpenAddModal] = useState<boolean>(false);
|
||||
const [spinning, setSpinning] = useState<boolean>(false);
|
||||
const [spinTip, setSpinTip] = useState<string>('');
|
||||
const [modal, modalHolder] = Modal.useModal();
|
||||
|
||||
useEffect(() => {
|
||||
QueryMachineList(tableParams, form.getFieldsValue())
|
||||
@ -57,12 +58,23 @@ const MachineManagement: React.FC = () => {
|
||||
}, []);
|
||||
|
||||
async function SetMachinePermanent(id: string): Promise<void> {
|
||||
setSpinning(true);
|
||||
setSpinTip('正在设置为永久。。。');
|
||||
|
||||
try {
|
||||
//
|
||||
let cofirmRes = await modal.confirm({
|
||||
title: '激活提示',
|
||||
content: '即将同步软件控制权限信息至绑定机器码,会消耗一次授权次数,是否继续?',
|
||||
okText: '确定',
|
||||
cancelText: '取消',
|
||||
});
|
||||
if (!cofirmRes) {
|
||||
messageApi.warning("取消操作");
|
||||
return;
|
||||
}
|
||||
|
||||
setSpinning(true);
|
||||
setSpinTip('正在激活/同步。。。');
|
||||
await MachinePermanent(id);
|
||||
messageApi.success('设置为永久成功');
|
||||
messageApi.success('激活同步信息成功');
|
||||
setSpinning(false);
|
||||
// 重新加载数据
|
||||
await QueryMachineBasic(form.getFieldsValue(), tableParams.pagination);
|
||||
@ -166,16 +178,14 @@ const MachineManagement: React.FC = () => {
|
||||
render: (text) => FormatDate(text),
|
||||
width: '160px',
|
||||
},
|
||||
{
|
||||
title: '使用状态',
|
||||
dataIndex: 'useStatus',
|
||||
render: (text, record) => <Tag color={record.useStatus === 1 ? 'green' : 'red'}>{record.useStatus === 1 ? '永久' : '试用'}</Tag>,
|
||||
width: '100px',
|
||||
},
|
||||
{
|
||||
title: '状态',
|
||||
dataIndex: 'status',
|
||||
render: (text, record) => <Tag color={record.status === 1 ? 'blue' : 'red'}>{record.status === 1 ? '激活' : '冻结'}</Tag>,
|
||||
render: (text, record) => (
|
||||
<Tag color={record.status === 1 ? 'blue' : 'red'}>
|
||||
{record.status === 1 ? '激活' : '冻结'}
|
||||
</Tag>
|
||||
),
|
||||
width: '100px',
|
||||
},
|
||||
{
|
||||
@ -190,17 +200,45 @@ const MachineManagement: React.FC = () => {
|
||||
},
|
||||
{
|
||||
title: '操作',
|
||||
width: '200px',
|
||||
render: (text, record) => (
|
||||
<div>
|
||||
<Button hidden={!access.canEditMachine} style={{ marginRight: 5 }} type="primary" size="small"
|
||||
onClick={() => { setOpenModal(true); setFormRef(form); setId(record.id) }}>编辑</Button>
|
||||
<Button hidden={!access.canUpgradeMachine} type="primary" style={{ marginRight: 5 }} size="small"
|
||||
onClick={async () => await SetMachinePermanent(record.id)}>永久</Button>
|
||||
<Button hidden={!access.canDisableMachine} type="primary" danger size="small"
|
||||
onClick={async () => await ChangeDeactivationMachine(record.id)}>停用</Button>
|
||||
</div>
|
||||
),
|
||||
width: 100,
|
||||
render: (text, record) => {
|
||||
const menuItems = [
|
||||
{
|
||||
key: "edit",
|
||||
icon: <EditOutlined />,
|
||||
hidden: !access.isAdminOrSuperAdmin,
|
||||
label: "编辑",
|
||||
onClick: () => {
|
||||
setOpenModal(true);
|
||||
setFormRef(form);
|
||||
setId(record.id);
|
||||
},
|
||||
},
|
||||
{
|
||||
key: "permanent",
|
||||
icon: <SafetyCertificateOutlined />,
|
||||
hidden: !access.canUpgradeMachine,
|
||||
style: {
|
||||
color: '#4caaff'
|
||||
},
|
||||
label: "激活",
|
||||
onClick: async () => await SetMachinePermanent(record.id),
|
||||
},
|
||||
{
|
||||
key: "disable",
|
||||
icon: <StopOutlined />,
|
||||
hidden: !access.canDisableMachine,
|
||||
danger: true,
|
||||
label: "停用",
|
||||
onClick: async () => await ChangeDeactivationMachine(record.id),
|
||||
},
|
||||
].filter(Boolean);
|
||||
return (
|
||||
<Dropdown menu={{ items: menuItems }} trigger={["hover"]}>
|
||||
<Button type="text" color="primary" variant="filled" icon={<MenuOutlined />} />
|
||||
</Dropdown>
|
||||
);
|
||||
},
|
||||
},
|
||||
];
|
||||
|
||||
@ -268,6 +306,7 @@ const MachineManagement: React.FC = () => {
|
||||
<AddMachineForm setFormRef={setFormRef} />
|
||||
</Modal>
|
||||
{messageHolder}
|
||||
{modalHolder}
|
||||
</TemplateContainer>
|
||||
);
|
||||
};
|
||||
|
||||
@ -108,7 +108,7 @@ const ModifyMachine: React.FC<ModifyMachineProps> = ({ id, setFormRef, open }) =
|
||||
name="useStatus"
|
||||
rules={[{ required: true, message: 'Please input your username!' }]}
|
||||
>
|
||||
<Select>
|
||||
<Select disabled>
|
||||
<Select.Option value={0}>试用</Select.Option>
|
||||
<Select.Option value={1}>永久</Select.Option>
|
||||
</Select>
|
||||
@ -120,7 +120,7 @@ const ModifyMachine: React.FC<ModifyMachineProps> = ({ id, setFormRef, open }) =
|
||||
name="status"
|
||||
rules={[{ required: true, message: 'Please input your username!' }]}
|
||||
>
|
||||
<Select>
|
||||
<Select disabled>
|
||||
<Select.Option value={0}>冻结</Select.Option>
|
||||
<Select.Option value={1}>激活</Select.Option>
|
||||
</Select>
|
||||
@ -142,7 +142,7 @@ const ModifyMachine: React.FC<ModifyMachineProps> = ({ id, setFormRef, open }) =
|
||||
name="deactivationTime"
|
||||
>
|
||||
<DatePicker
|
||||
showTime
|
||||
showTime disabled
|
||||
onChange={(value, dateString) => {
|
||||
}}
|
||||
onOk={onOk}
|
||||
|
||||
@ -92,8 +92,12 @@ async function AddMachineData(params: MachineModel.AddMachineParams) {
|
||||
let deactivationTimeString = params.deactivationTime ? params.deactivationTime.toISOString() : undefined;
|
||||
let data = {
|
||||
...params,
|
||||
deactivationTime: deactivationTimeString
|
||||
deactivationTime: deactivationTimeString,
|
||||
useStatus: 0, // 这边设置默认就是试用,然后状态时激活,不需要用户再次设置
|
||||
status: 1,
|
||||
}
|
||||
debugger
|
||||
console.log(data)
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/Machine/AddMachine`, {
|
||||
method: 'POST',
|
||||
data: data
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user