V1.0.9
修改请求重试,修改所有的request方法 添加部分权限控制 完善软件授权码设置
This commit is contained in:
parent
e448cf6c6b
commit
79479bfdc5
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "lms",
|
||||
"version": "1.0.6",
|
||||
"version": "1.0.8",
|
||||
"private": true,
|
||||
"description": "An out-of-box UI solution for enterprise applications",
|
||||
"scripts": {
|
||||
|
||||
@ -14,20 +14,32 @@ export default function access(initialState: { currentUser?: API.CurrentUser } |
|
||||
isAdmin: false,
|
||||
isSuperAdmin: false,
|
||||
isAdminOrSuperAdmin: false,
|
||||
isAgentUser: false,
|
||||
|
||||
canOptions: false,
|
||||
canLaiToolOptions : false,
|
||||
canSystemOptions : false,
|
||||
|
||||
canApplySoftwareControl: false,
|
||||
canSofrwareControlManagement: false,
|
||||
canLaiToolOptions: false,
|
||||
canSystemOptions: false,
|
||||
|
||||
canMachineManagement: false,
|
||||
canAddMachine: true,
|
||||
canEditMachine: false,
|
||||
canDeleteMachine: false,
|
||||
canUpgradeMachine: true,
|
||||
canDisableMachine: true
|
||||
canDisableMachine: true,
|
||||
|
||||
|
||||
canApplySoftwareControl: false,
|
||||
canSofrwareControlManagement: false,
|
||||
canEditSoftwareControl: false,
|
||||
canAddTrailSoftwareControl: false,
|
||||
canAddMouthSoftwareControl: false,
|
||||
canAddQuarterlySoftwareControl: false,
|
||||
canAddHalfYearSoftwareControl: false,
|
||||
canAddYearSoftwareControl: false,
|
||||
canAddForeverSoftwareControl: false,
|
||||
canDeleteSoftwareControl: false,
|
||||
|
||||
|
||||
} as AccessType.AccessType;
|
||||
|
||||
// 更具用户角色返回权限
|
||||
@ -54,7 +66,20 @@ export default function access(initialState: { currentUser?: API.CurrentUser } |
|
||||
canMachineManagement: true,
|
||||
canUpgradeMachine: true,
|
||||
|
||||
isAgentUser: true,
|
||||
|
||||
canSofrwareControlManagement: true,
|
||||
canApplySoftwareControl: true,
|
||||
|
||||
canEditSoftwareControl: false,
|
||||
canAddTrailSoftwareControl: false,
|
||||
canAddMouthSoftwareControl: true,
|
||||
canAddQuarterlySoftwareControl: false,
|
||||
canAddHalfYearSoftwareControl: false,
|
||||
canAddYearSoftwareControl: false,
|
||||
canAddForeverSoftwareControl: true,
|
||||
canDeleteSoftwareControl: false,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -70,8 +95,8 @@ export default function access(initialState: { currentUser?: API.CurrentUser } |
|
||||
isAdminOrSuperAdmin: true,
|
||||
|
||||
canOptions: true,
|
||||
canLaiToolOptions : true,
|
||||
canSystemOptions : false,
|
||||
canLaiToolOptions: true,
|
||||
canSystemOptions: false,
|
||||
|
||||
canMachineManagement: true,
|
||||
canEditMachine: true,
|
||||
@ -79,11 +104,19 @@ export default function access(initialState: { currentUser?: API.CurrentUser } |
|
||||
canUpgradeMachine: true,
|
||||
|
||||
canApplySoftwareControl: true,
|
||||
canSofrwareControlManagement: true
|
||||
canSofrwareControlManagement: true,
|
||||
canEditSoftwareControl: true,
|
||||
canAddTrailSoftwareControl: true,
|
||||
canAddMouthSoftwareControl: true,
|
||||
canAddQuarterlySoftwareControl: true,
|
||||
canAddHalfYearSoftwareControl: true,
|
||||
canAddYearSoftwareControl: true,
|
||||
canAddForeverSoftwareControl: true,
|
||||
canDeleteSoftwareControl: true,
|
||||
}
|
||||
}
|
||||
|
||||
if (currentUser?.roleNames?.includes("Super Admin")) {
|
||||
if (currentUser?.roleNames?.includes("Super Admin") || currentUser?.id == "4") {
|
||||
return {
|
||||
...access,
|
||||
canPrompt: true,
|
||||
@ -97,8 +130,8 @@ export default function access(initialState: { currentUser?: API.CurrentUser } |
|
||||
isAdminOrSuperAdmin: true,
|
||||
|
||||
canOptions: true,
|
||||
canLaiToolOptions : true,
|
||||
canSystemOptions : true,
|
||||
canLaiToolOptions: true,
|
||||
canSystemOptions: true,
|
||||
|
||||
canMachineManagement: true,
|
||||
canEditMachine: true,
|
||||
@ -106,7 +139,15 @@ export default function access(initialState: { currentUser?: API.CurrentUser } |
|
||||
canUpgradeMachine: true,
|
||||
|
||||
canApplySoftwareControl: true,
|
||||
canSofrwareControlManagement: true
|
||||
canSofrwareControlManagement: true,
|
||||
canEditSoftwareControl: true,
|
||||
canAddTrailSoftwareControl: true,
|
||||
canAddMouthSoftwareControl: true,
|
||||
canAddQuarterlySoftwareControl: true,
|
||||
canAddHalfYearSoftwareControl: true,
|
||||
canAddYearSoftwareControl: true,
|
||||
canAddForeverSoftwareControl: true,
|
||||
canDeleteSoftwareControl: true,
|
||||
};
|
||||
}
|
||||
console.log("accsee", access);
|
||||
|
||||
@ -3,13 +3,14 @@ import { LinkOutlined } from '@ant-design/icons';
|
||||
import type { Settings as LayoutSettings } from '@ant-design/pro-components';
|
||||
import { SettingDrawer } from '@ant-design/pro-components';
|
||||
import type { RunTimeLayoutConfig } from '@umijs/max';
|
||||
import { history, Link, request as q } from '@umijs/max';
|
||||
import { history, Link } from '@umijs/max';
|
||||
import defaultSettings from '../config/defaultSettings';
|
||||
import { errorConfig } from './requestErrorConfig';
|
||||
import { UserInfo, getCurrentUser as queryCurrentUser } from './services/services/user';
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { TokenStorage } from './services/define/tokenStorage';
|
||||
import { App, ConfigProvider } from 'antd';
|
||||
import cusRequest from './request';
|
||||
|
||||
const isDev = process.env.NODE_ENV === 'development';
|
||||
const loginPath = '/user/login';
|
||||
@ -37,7 +38,11 @@ export async function getInitialState(): Promise<{
|
||||
const msg = await queryCurrentUser(id, {
|
||||
skipErrorHandler: true,
|
||||
});
|
||||
if (msg.code != 1) {
|
||||
console.log('获取用户信息失败: ', msg.message);
|
||||
} else {
|
||||
return msg.data;
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('获取用户信息失败: ', error);
|
||||
history.push(loginPath);
|
||||
@ -195,7 +200,7 @@ const validateToken = async () => {
|
||||
|
||||
try {
|
||||
if (location.href.includes('/user/login')) return;
|
||||
await q('/api/Login/Validate', {
|
||||
await cusRequest('/api/Login/Validate', {
|
||||
method: 'GET',
|
||||
});
|
||||
} catch (error) {
|
||||
|
||||
@ -243,7 +243,7 @@ const MachineManagement: React.FC = () => {
|
||||
];
|
||||
|
||||
return (
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "realDark"}>
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "light"}>
|
||||
<Spin spinning={spinning} tip={spinTip}>
|
||||
<Form
|
||||
layout='inline'
|
||||
|
||||
@ -28,6 +28,7 @@ const ModifyMachine: React.FC<ModifyMachineProps> = ({ id, setFormRef, open }) =
|
||||
setSpinning(true);
|
||||
setSpinTip("加载中。。。");
|
||||
GetMachineInfo(id).then((res) => {
|
||||
debugger
|
||||
// 对一些数据做处理
|
||||
form.setFieldsValue({
|
||||
...res,
|
||||
@ -37,6 +38,7 @@ const ModifyMachine: React.FC<ModifyMachineProps> = ({ id, setFormRef, open }) =
|
||||
ownUserName: res.ownUser?.userName,
|
||||
updatedUserName: res.updatedUser?.userName,
|
||||
deactivationTime: res.deactivationTime ? moment(res.deactivationTime) : undefined,
|
||||
id: id
|
||||
});
|
||||
|
||||
}).catch((error: any) => {
|
||||
|
||||
@ -24,7 +24,7 @@ const LaitoolOptions: React.FC = () => {
|
||||
}]
|
||||
|
||||
return (
|
||||
<TemplateContainer title={false} navTheme={initialState?.settings?.navTheme ?? "realDark"}>
|
||||
<TemplateContainer title={false} navTheme={initialState?.settings?.navTheme ?? "light"}>
|
||||
<Tabs defaultActiveKey="1" destroyInactiveTabPane={true} items={items} />
|
||||
</TemplateContainer>
|
||||
);
|
||||
|
||||
@ -4,7 +4,7 @@ import { MailOutlined } from '@ant-design/icons';
|
||||
import { useSoftStore } from '@/store/software';
|
||||
import { GetOptions, getOptionsValue, GetSimpleOptions, SaveOptions } from '@/services/services/options/optionsTool';
|
||||
import { AllOptionKeyName, OptionKeyName } from '@/services/enum/optionEnum';
|
||||
import { request } from '@umijs/max';
|
||||
import cusRequest from '@/request';
|
||||
|
||||
interface MailSettingProps {
|
||||
visible?: boolean;
|
||||
@ -94,7 +94,7 @@ const MailSettingOption: React.FC<MailSettingProps> = ({ visible }) => {
|
||||
setTopSpinTip('正在发送测试邮件');
|
||||
|
||||
|
||||
let res = await request<ApiResponse.SuccessItem<string>>('/lms/LaitoolOptions/TestSendMail', {
|
||||
let res = await cusRequest<string>('/lms/LaitoolOptions/TestSendMail', {
|
||||
method: 'POST',
|
||||
});
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ const LaitoolOptions: React.FC = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<TemplateContainer title={false} navTheme={initialState?.settings?.navTheme ?? "realDark"}>
|
||||
<TemplateContainer title={false} navTheme={initialState?.settings?.navTheme ?? "light"}>
|
||||
<Tabs defaultActiveKey="1" destroyInactiveTabPane={true} items={items} onChange={onChange} />
|
||||
</TemplateContainer>
|
||||
);
|
||||
|
||||
@ -1,12 +1,13 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Table, Button, message, Space, Spin, Form, Input, Select, Modal } from 'antd';
|
||||
import TemplateContainer from '@/pages/TemplateContainer';
|
||||
import { request, useModel } from '@umijs/max';
|
||||
import { useModel } from '@umijs/max';
|
||||
import { objectToQueryString } from '@/services/services/common';
|
||||
import { GetDataInfoTypeOption, GetDataInfoTypeOptions } from '@/services/enum/dataInfo';
|
||||
import { SearchOutlined } from '@ant-design/icons';
|
||||
import { ColumnsType } from 'antd/lib/table';
|
||||
import JsonView from '@uiw/react-json-view';
|
||||
import cusRequest from '@/request';
|
||||
|
||||
const DataInfo: React.FC = () => {
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
@ -37,13 +38,17 @@ const DataInfo: React.FC = () => {
|
||||
pageSize: tableParams.pagination?.pageSize,
|
||||
};
|
||||
let query = objectToQueryString(data);
|
||||
let res = await request<ApiResponse.SuccessItem<DataInfoModel.QueryDataInfoData>>(`/lms/Other/QueryDataInfoCollection?${query}`, {
|
||||
let res = await cusRequest<DataInfoModel.QueryDataInfoData>(`/lms/Other/QueryDataInfoCollection?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
let resData = res.data;
|
||||
if (resData?.collection == undefined) {
|
||||
messageApi.error('请求获取数据为空,请重试!');
|
||||
return;
|
||||
}
|
||||
setDataList(resData.collection);
|
||||
setTableParams({
|
||||
pagination: {
|
||||
@ -140,7 +145,7 @@ const DataInfo: React.FC = () => {
|
||||
];
|
||||
|
||||
return (
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? 'realDark'}>
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? 'light'}>
|
||||
<Spin spinning={loading}>
|
||||
<Form
|
||||
form={form}
|
||||
|
||||
@ -1,20 +1,20 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Form, Input, DatePicker, Select, Button, message, FormInstance } from 'antd';
|
||||
import { Form, Input, DatePicker, Select, Button, message, FormInstance, Space } from 'antd';
|
||||
import moment from 'moment';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { GetMachineAuthorizationTypeOptions } from '@/services/enum/machineAuthorizationEnum';
|
||||
const { TextArea } = Input;
|
||||
import CryptoJS from 'crypto-js'; // 添加这一行导入
|
||||
import * as LZString from 'lz-string';
|
||||
import { request } from '@umijs/max';
|
||||
import cusRequest from '@/request';
|
||||
import { AddMachineIdAuthorizationFunc } from '@/services/services/other';
|
||||
|
||||
|
||||
interface AddMachineIdAuthorizationProps {
|
||||
setFormRef: (form: FormInstance) => void;
|
||||
id: string;
|
||||
}
|
||||
|
||||
const AddMachineIdAuthorization: React.FC<AddMachineIdAuthorizationProps> = ({ setFormRef, id }) => {
|
||||
const AddMachineIdAuthorization: React.FC<AddMachineIdAuthorizationProps> = ({ setFormRef }) => {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [messageApi, messageHolder] = message.useMessage();
|
||||
@ -22,33 +22,21 @@ const AddMachineIdAuthorization: React.FC<AddMachineIdAuthorizationProps> = ({ s
|
||||
useEffect(() => {
|
||||
setFormRef(form);
|
||||
form.setFieldsValue({
|
||||
authorizedDate: moment(),
|
||||
expiryDate: moment().add(1, 'year'),
|
||||
type: 0,
|
||||
authorizationCode: '123'
|
||||
useType: 0,
|
||||
expiryTime: 365,
|
||||
authorizationCode: ""
|
||||
})
|
||||
}, [form, setFormRef, id]);
|
||||
}, [form, setFormRef]);
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
setLoading(true);
|
||||
// TODO: Implement API call to save the authorization
|
||||
let values = form.getFieldsValue();
|
||||
console.log('Form values:', values);
|
||||
|
||||
let res = await request<ApiResponse.SuccessItem<string>>('lms/Other/AddMachineAuthorization', {
|
||||
method: "POST",
|
||||
data: {
|
||||
...values,
|
||||
authorizedDate: values.authorizedDate.toISOString(),
|
||||
expiryDate: values.expiryDate.toISOString()
|
||||
}
|
||||
})
|
||||
if (res.code !== 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
await AddMachineIdAuthorizationFunc(values);
|
||||
messageApi.success('Machine ID authorization added successfully');
|
||||
} catch (error : any) {
|
||||
} catch (error: any) {
|
||||
messageApi.error(error.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
@ -167,13 +155,7 @@ const AddMachineIdAuthorization: React.FC<AddMachineIdAuthorizationProps> = ({ s
|
||||
onFinish={handleSubmit}
|
||||
autoComplete="off"
|
||||
>
|
||||
<Form.Item
|
||||
name="machineId"
|
||||
label="机器码/唯一授权码"
|
||||
rules={[{ required: true, message: '请输入 machine ID' }]}
|
||||
>
|
||||
<Input placeholder="输入 machine ID" />
|
||||
</Form.Item>
|
||||
|
||||
|
||||
<Form.Item
|
||||
name="type"
|
||||
@ -183,12 +165,23 @@ const AddMachineIdAuthorization: React.FC<AddMachineIdAuthorizationProps> = ({ s
|
||||
<Select placeholder="选择授权软件类型" options={GetMachineAuthorizationTypeOptions()}></Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="useType"
|
||||
label="授权使用类型"
|
||||
rules={[{ required: true, message: '请输入授权软件类型' }]}
|
||||
>
|
||||
<Select placeholder="选择授权软件类型" options={[
|
||||
{ label: '基础', value: 0 },
|
||||
{ label: '专业', value: 1 },
|
||||
]}></Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="authorizedDate"
|
||||
label="授权时间"
|
||||
rules={[{ required: true, message: '请选择授权时间' }]}
|
||||
>
|
||||
<DatePicker
|
||||
disabled
|
||||
showTime
|
||||
style={{ width: '100%' }}
|
||||
placeholder="选择授权日期和时间"
|
||||
@ -199,9 +192,9 @@ const AddMachineIdAuthorization: React.FC<AddMachineIdAuthorizationProps> = ({ s
|
||||
<Form.Item
|
||||
name="expiryDate"
|
||||
label="到期时间"
|
||||
rules={[{ required: true, message: '请选择到期时间' }]}
|
||||
>
|
||||
<DatePicker
|
||||
disabled
|
||||
showTime
|
||||
style={{ width: '100%' }}
|
||||
placeholder="选择到期日期和时间"
|
||||
@ -209,18 +202,44 @@ const AddMachineIdAuthorization: React.FC<AddMachineIdAuthorizationProps> = ({ s
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="authorizationCode" label="请输入授权码">
|
||||
<TextArea rows={4} placeholder="请输入授权码" />
|
||||
<Form.Item
|
||||
name="expiryTime"
|
||||
label="授权到期时间"
|
||||
rules={[{ required: true, message: '请选择授权到期时间' }]}
|
||||
>
|
||||
<Select
|
||||
placeholder="请选择授权时间"
|
||||
showSearch
|
||||
allowClear
|
||||
optionFilterProp="children"
|
||||
options={[
|
||||
{ label: '0天', value: 0 },
|
||||
{ label: '30天', value: 30 },
|
||||
{ label: '90天', value: 90 },
|
||||
{ label: '180天', value: 180 },
|
||||
{ label: '365天', value: 365 },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item style={{ textAlign: 'right' }}>
|
||||
<Form.Item name="authorizationCode" label="授权码"
|
||||
rules={[{ required: true, message: '请先生成授权码' }]}
|
||||
>
|
||||
<Space.Compact style={{ width: '100%' }}>
|
||||
<Input
|
||||
placeholder="授权码将显示在这里"
|
||||
/>
|
||||
<Button
|
||||
style={{ marginRight: 8 }}
|
||||
type="primary"
|
||||
onClick={GenerateAuthorizationCode}
|
||||
>
|
||||
计算授权码
|
||||
</Button>
|
||||
|
||||
</Space.Compact>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item style={{ textAlign: 'right' }}>
|
||||
<Button
|
||||
style={{ marginRight: 8 }}
|
||||
type="primary"
|
||||
|
||||
@ -0,0 +1,283 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Form, Input, DatePicker, Select, Button, message, FormInstance, Space } from 'antd';
|
||||
import moment from 'moment';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { GetMachineAuthorizationTypeOptions } from '@/services/enum/machineAuthorizationEnum';
|
||||
const { TextArea } = Input;
|
||||
import CryptoJS from 'crypto-js'; // 添加这一行导入
|
||||
import * as LZString from 'lz-string';
|
||||
import cusRequest from '@/request';
|
||||
import { FormatDate } from '@/util/time';
|
||||
import { GetMachineAuthorizationById, ModifyMachineAuthorization } from '@/services/services/other';
|
||||
|
||||
|
||||
interface ModifyMachineIdAuthorizationProps {
|
||||
setFormRef: (form: FormInstance) => void;
|
||||
id: string;
|
||||
}
|
||||
|
||||
const ModifyMachineIdAuthorization: React.FC<ModifyMachineIdAuthorizationProps> = ({ setFormRef, id }) => {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [messageApi, messageHolder] = message.useMessage();
|
||||
|
||||
useEffect(() => {
|
||||
setFormRef(form);
|
||||
|
||||
getMachineAuthorizationById(id);
|
||||
}, [form, setFormRef, id]);
|
||||
|
||||
// 先获取数据
|
||||
const getMachineAuthorizationById = async (id: string) => {
|
||||
try {
|
||||
debugger
|
||||
let data = await GetMachineAuthorizationById(id);
|
||||
form.setFieldsValue({
|
||||
...data,
|
||||
// 使用 moment 对象而不是格式化字符串
|
||||
authorizedDate: data.authorizedDate ? moment(data.authorizedDate) : null,
|
||||
expiryDate: data.expiryDate ? moment(data.expiryDate) : null,
|
||||
});
|
||||
} catch (error) {
|
||||
messageApi.error('获取数据失败');
|
||||
}
|
||||
}
|
||||
|
||||
const handleSubmit = async () => {
|
||||
try {
|
||||
debugger
|
||||
setLoading(true);
|
||||
let values = form.getFieldsValue();
|
||||
await ModifyMachineAuthorization(id, values);
|
||||
messageApi.success('Machine ID authorization added successfully');
|
||||
} catch (error: any) {
|
||||
messageApi.error(error.message);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function GenerateAuthorizationCode() {
|
||||
const values = form.getFieldsValue();
|
||||
const { machineId, type, authorizedDate, expiryDate } = values;
|
||||
|
||||
if (!machineId || type === undefined || !authorizedDate || !expiryDate) {
|
||||
messageApi.error('请先填写必要信息(机器码、类型和日期)');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
// Format dates to strings
|
||||
const authDate = moment(authorizedDate).format('YYYY-MM-DD HH:mm:ss');
|
||||
const expDate = moment(expiryDate).format('YYYY-MM-DD HH:mm:ss');
|
||||
let obj = {
|
||||
machineId: machineId,
|
||||
type: type,
|
||||
authorizedDate: authDate,
|
||||
expiryDate: expDate
|
||||
}
|
||||
|
||||
// Create the string to encrypt
|
||||
const dataToEncrypt = JSON.stringify(obj);
|
||||
|
||||
// Assuming CryptoJS is imported
|
||||
const secretKey = machineId;
|
||||
|
||||
// Generate a secure encryption key from machineId
|
||||
const key = CryptoJS.enc.Utf8.parse(CryptoJS.SHA256(secretKey).toString());
|
||||
|
||||
// Generate a random initialization vector
|
||||
const iv = CryptoJS.lib.WordArray.random(16);
|
||||
|
||||
// Encrypt the data using AES encryption
|
||||
const encrypted = CryptoJS.AES.encrypt(dataToEncrypt, key, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
});
|
||||
|
||||
// Convert IV to base64 for storage
|
||||
const ivBase64 = CryptoJS.enc.Base64.stringify(iv);
|
||||
|
||||
// Get the encrypted data in base64 format
|
||||
const encryptedBase64 = encrypted.toString();
|
||||
|
||||
// Combine IV and encrypted data with a delimiter for future decryption
|
||||
const authCode = ivBase64 + ':' + encryptedBase64;
|
||||
|
||||
// 使用LZString压缩
|
||||
const compressedCode = LZString.compressToEncodedURIComponent(authCode);
|
||||
// Set the encrypted value in the form
|
||||
form.setFieldsValue({ authorizationCode: compressedCode });
|
||||
|
||||
messageApi.success('授权码已生成');
|
||||
} catch (error) {
|
||||
console.error('生成授权码时出错:', error);
|
||||
messageApi.error('生成授权码失败');
|
||||
}
|
||||
}
|
||||
|
||||
function DecryptAuthorizationCode(authCode: string, machineId: string) {
|
||||
try {
|
||||
// 解压缩
|
||||
const originalAuthCode = LZString.decompressFromEncodedURIComponent(authCode);
|
||||
// 拆分授权码,获取IV和加密数据
|
||||
const [ivBase64, encryptedBase64] = originalAuthCode.split(':');
|
||||
|
||||
if (!ivBase64 || !encryptedBase64) {
|
||||
throw new Error('无效的授权码格式');
|
||||
}
|
||||
|
||||
// 从Base64转换回IV
|
||||
const iv = CryptoJS.enc.Base64.parse(ivBase64);
|
||||
|
||||
// 使用相同的方法生成密钥
|
||||
const secretKey = machineId;
|
||||
const key = CryptoJS.enc.Utf8.parse(CryptoJS.SHA256(secretKey).toString());
|
||||
|
||||
// 解密数据
|
||||
const decrypted = CryptoJS.AES.decrypt(encryptedBase64, key, {
|
||||
iv: iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
});
|
||||
|
||||
// 将解密后的数据转换为字符串
|
||||
const decryptedData = decrypted.toString(CryptoJS.enc.Utf8);
|
||||
|
||||
// 将JSON字符串解析为对象
|
||||
const decodedObject = JSON.parse(decryptedData);
|
||||
|
||||
return {
|
||||
success: true,
|
||||
data: decodedObject
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('解密授权码时出错:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error instanceof Error ? error.message : '未知错误'
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (
|
||||
<Form
|
||||
form={form}
|
||||
layout="vertical"
|
||||
onFinish={handleSubmit}
|
||||
autoComplete="off"
|
||||
>
|
||||
|
||||
|
||||
<Form.Item
|
||||
name="type"
|
||||
label="授权软件类型"
|
||||
rules={[{ required: true, message: '请输入授权软件类型' }]}
|
||||
>
|
||||
<Select placeholder="选择授权软件类型" options={GetMachineAuthorizationTypeOptions()}></Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="useType"
|
||||
label="授权使用类型"
|
||||
rules={[{ required: true, message: '请输入授权软件类型' }]}
|
||||
>
|
||||
<Select placeholder="选择授权软件类型" options={[
|
||||
{ label: '基础', value: 0 },
|
||||
{ label: '专业', value: 1 },
|
||||
]}></Select>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="authorizedDate"
|
||||
label="授权时间"
|
||||
>
|
||||
<DatePicker
|
||||
disabled
|
||||
showTime
|
||||
style={{ width: '100%' }}
|
||||
placeholder="选择授权日期和时间"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="expiryDate"
|
||||
label="到期时间"
|
||||
>
|
||||
<DatePicker
|
||||
|
||||
showTime
|
||||
style={{ width: '100%' }}
|
||||
placeholder="选择到期日期和时间"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item
|
||||
name="expiryTime"
|
||||
label="授权到期时间"
|
||||
rules={[{ required: true, message: '请选择授权到期时间' }]}
|
||||
>
|
||||
<Select
|
||||
placeholder="请选择授权时间"
|
||||
showSearch
|
||||
allowClear
|
||||
optionFilterProp="children"
|
||||
options={[
|
||||
{ label: '0天', value: 0 },
|
||||
{ label: '30天', value: 30 },
|
||||
{ label: '90天', value: 90 },
|
||||
{ label: '180天', value: 180 },
|
||||
{ label: '365天', value: 365 },
|
||||
]}
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="authorizationCode" label="授权码"
|
||||
rules={[{ required: true, message: '请先生成授权码' }]}
|
||||
>
|
||||
<Input
|
||||
placeholder="授权码将显示在这里"
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item name="machineID" label="机器码/唯一标识"
|
||||
>
|
||||
<Input
|
||||
placeholder="授权码将显示在这里"
|
||||
/>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item style={{ textAlign: 'right' }}>
|
||||
<Button
|
||||
style={{ marginRight: 8 }}
|
||||
type="primary"
|
||||
onClick={() => {
|
||||
const values = form.getFieldsValue();
|
||||
const { machineId, authorizationCode } = values;
|
||||
if (!machineId || !authorizationCode) {
|
||||
messageApi.error('请先填写机器码和授权码');
|
||||
return;
|
||||
}
|
||||
const result = DecryptAuthorizationCode(authorizationCode, machineId);
|
||||
if (result.success) {
|
||||
messageApi.success('授权码解密成功');
|
||||
console.log('解密结果:', result.data);
|
||||
} else {
|
||||
messageApi.error(`解密失败: ${result.error}`);
|
||||
}
|
||||
}}
|
||||
>
|
||||
解密授权码
|
||||
</Button>
|
||||
|
||||
<Button type="primary" htmlType="submit" loading={loading}>
|
||||
保存
|
||||
</Button>
|
||||
</Form.Item>
|
||||
{messageHolder}
|
||||
</Form >
|
||||
);
|
||||
};
|
||||
|
||||
export default ModifyMachineIdAuthorization;
|
||||
@ -1,14 +1,18 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Table, Button, Space, Input, Form, Modal, message, Popconfirm, Tooltip, Select } from 'antd';
|
||||
import { Table, Button, Space, Input, Form, Modal, message, Popconfirm, Tooltip, Select, Checkbox, Tag } from 'antd';
|
||||
import { PlusOutlined, SearchOutlined } from '@ant-design/icons';
|
||||
import TemplateContainer from '@/pages/TemplateContainer';
|
||||
import { request, useModel } from '@umijs/max';
|
||||
import { useModel } from '@umijs/max';
|
||||
import { ColumnsType, FilterValue, SorterResult, TableCurrentDataSource, TablePaginationConfig } from 'antd/es/table/interface';
|
||||
import { objectToQueryString } from '@/services/services/common';
|
||||
import { FormatDate } from '@/util/time';
|
||||
import { GetMachineAuthorizationTypeOption, GetMachineAuthorizationTypeOptions } from '@/services/enum/machineAuthorizationEnum';
|
||||
import { useFormReset } from '@/hooks/useFormReset';
|
||||
import AddMachineIdAuthorization from './AddMachineIdAuthorization';
|
||||
import cusRequest from '@/request';
|
||||
import { isEmpty } from 'lodash';
|
||||
import ModifyMachineIdAuthorization from './ModifyMachineIdAuthorization';
|
||||
import { BatchDeleteMachine, DeleteMachineAuthorization, QueryMachineAuthorization } from '@/services/services/other';
|
||||
|
||||
|
||||
const MachineIdAuthorization: React.FC = () => {
|
||||
@ -17,7 +21,8 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
const [loading, setLoading] = useState<boolean>(false);
|
||||
const [modalVisible, setModalVisible] = useState<boolean>(false);
|
||||
const [form] = Form.useForm();
|
||||
const [messageApi, messageHolder] = message.useMessage();
|
||||
const [messageApi, messageHolder,] = message.useMessage();
|
||||
const [modalApi, modalHolder] = Modal.useModal();
|
||||
const { setFormRef, resetForm } = useFormReset();
|
||||
const [id, setId] = useState<string>('');
|
||||
const [tableParams, setTableParams] = useState<TableModel.TableParams>({
|
||||
@ -33,23 +38,11 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
QueryMachineAuthorizationCollection(tableParams, form.getFieldsValue());
|
||||
}, []);
|
||||
|
||||
// 查询数据
|
||||
async function QueryMachineAuthorizationCollection(tableParams: TableModel.TableParams, options?: any) {
|
||||
try {
|
||||
setLoading(true);
|
||||
|
||||
let data = {
|
||||
...options,
|
||||
page: tableParams.pagination?.current,
|
||||
pageSize: tableParams.pagination?.pageSize,
|
||||
}
|
||||
let query = objectToQueryString(data)
|
||||
let res = await request<ApiResponse.SuccessItem<MachineAuthorizationModel.QueryMachineAuthorizationData>>(`/lms/Other/QueryMachineAuthorizationCollection?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
let resData = res.data;
|
||||
let resData = await QueryMachineAuthorization(tableParams, options);
|
||||
setDataSource(resData.collection);
|
||||
setTableParams({
|
||||
pagination: {
|
||||
@ -57,6 +50,7 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
total: resData.total
|
||||
}
|
||||
})
|
||||
console.log('获取数据成功', resData);
|
||||
messageApi.success('Data fetched successfully');
|
||||
} catch (error: any) {
|
||||
messageApi.error(error.message);
|
||||
@ -67,6 +61,17 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
|
||||
const columns: ColumnsType<MachineAuthorizationModel.MachineAuthorizationBase> = [
|
||||
{
|
||||
title: 'ID',
|
||||
dataIndex: 'id',
|
||||
key: 'id',
|
||||
width: '120px',
|
||||
render: (text) => (
|
||||
<Tooltip title={text}>
|
||||
<span>{text?.length > 10 ? `${text.substring(0, 10)}...` : text}</span>
|
||||
</Tooltip>
|
||||
),
|
||||
fixed: 'left',
|
||||
}, {
|
||||
title: '机器码/唯一授权码',
|
||||
dataIndex: 'machineID',
|
||||
key: 'machineId',
|
||||
@ -77,34 +82,59 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
</Tooltip>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '授权类型',
|
||||
dataIndex: 'type',
|
||||
key: 'type',
|
||||
render: (text, record) => GetMachineAuthorizationTypeOption(record.type),
|
||||
},
|
||||
{
|
||||
title: '授权时间',
|
||||
dataIndex: 'authorizedDate',
|
||||
key: 'authorizedDate',
|
||||
render: (text) => FormatDate(text),
|
||||
},
|
||||
{
|
||||
title: '授权到期时间',
|
||||
dataIndex: 'expiryDate',
|
||||
key: 'expiryDate',
|
||||
render: (text) => FormatDate(text),
|
||||
},
|
||||
{
|
||||
title: '授权码',
|
||||
dataIndex: 'authorizationCode',
|
||||
key: 'authorizationCode',
|
||||
width: '300px',
|
||||
render: (text) => (
|
||||
<Tooltip title={text}>
|
||||
<span>{text?.length > 30 ? `${text.substring(0, 30)}...` : text}</span>
|
||||
</Tooltip>
|
||||
),
|
||||
},
|
||||
{
|
||||
title: '授权类型',
|
||||
dataIndex: 'type',
|
||||
key: 'type',
|
||||
width: '80px',
|
||||
render: (text, record) => GetMachineAuthorizationTypeOption(record.type),
|
||||
},
|
||||
{
|
||||
title: '使用类型',
|
||||
dataIndex: 'useType',
|
||||
key: 'useType',
|
||||
width: '80px',
|
||||
render: (text, record) => {
|
||||
return <Tag color={record.useType == 0 ? 'green' : 'blue'}>
|
||||
{record.useType == 0 ? '基础' : '专业'}
|
||||
</Tag>
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '授权时间',
|
||||
dataIndex: 'expiryTime',
|
||||
key: 'expiryTime',
|
||||
width: '80px',
|
||||
render: (text, record) => <Tag color='success'>
|
||||
{record.expiryTime + '天'}
|
||||
</Tag>
|
||||
},
|
||||
{
|
||||
title: '授权时间',
|
||||
dataIndex: 'authorizedDate',
|
||||
key: 'authorizedDate',
|
||||
width: '160px',
|
||||
render: (text) => FormatDate(text),
|
||||
},
|
||||
{
|
||||
title: '授权到期时间',
|
||||
dataIndex: 'expiryDate',
|
||||
key: 'expiryDate',
|
||||
width: '160px',
|
||||
render: (text) => FormatDate(text),
|
||||
},
|
||||
|
||||
{
|
||||
title: '创建人',
|
||||
dataIndex: 'createdUser',
|
||||
@ -113,53 +143,49 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
const userName = text?.userName || '';
|
||||
return (
|
||||
<Tooltip title={userName}>
|
||||
<span>{userName.length > 10 ? `${userName.substring(0, 10)}...` : userName}</span>
|
||||
<span>{userName.length > 20 ? `${userName.substring(0, 20)}...` : userName}</span>
|
||||
</Tooltip>
|
||||
);
|
||||
}
|
||||
},
|
||||
{
|
||||
title: '创建时间',
|
||||
dataIndex: 'createdDate',
|
||||
key: 'createdDate',
|
||||
render: (text, record) => FormatDate(record.createdDate),
|
||||
},
|
||||
{
|
||||
title: 'Actions',
|
||||
key: 'actions',
|
||||
render: (_, record) => (
|
||||
<Space>
|
||||
<Button type="link" onClick={() => handleEdit(record)}>
|
||||
Edit
|
||||
<Button color="primary" variant="text" onClick={() => handleEdit(record)}>
|
||||
编辑
|
||||
</Button>
|
||||
<Popconfirm
|
||||
title="Are you sure you want to revoke this authorization?"
|
||||
onConfirm={() => handleRevoke(record.id)}
|
||||
okText="Yes"
|
||||
cancelText="No"
|
||||
title="确定要删除当前的授权吗?"
|
||||
description="删除后将无法恢复,请谨慎操作!"
|
||||
onConfirm={() => handleDelete(record.id)}
|
||||
okText="继续"
|
||||
cancelText="取消"
|
||||
>
|
||||
<Button type="link" danger>
|
||||
Revoke
|
||||
<Button color="danger" variant="text">
|
||||
删除
|
||||
</Button>
|
||||
</Popconfirm>
|
||||
</Space>
|
||||
),
|
||||
fixed: 'right',
|
||||
},
|
||||
];
|
||||
|
||||
const handleEdit = (record: MachineAuthorizationModel.MachineAuthorizationBase) => {
|
||||
setModalVisible(true);
|
||||
setId(record.id);
|
||||
};
|
||||
|
||||
const handleRevoke = async (id: string) => {
|
||||
// 单个删除
|
||||
const handleDelete = async (id: string) => {
|
||||
try {
|
||||
const newData = dataSource.map(item =>
|
||||
item.id === id ? { ...item, status: 'revoked' as const } : item
|
||||
);
|
||||
setDataSource(newData);
|
||||
messageApi.success('Authorization revoked successfully');
|
||||
} catch (error) {
|
||||
messageApi.error('Failed to revoke authorization');
|
||||
await DeleteMachineAuthorization(id);
|
||||
await QueryMachineAuthorizationCollection(tableParams, form.getFieldsValue());
|
||||
messageApi.success('删除成功');
|
||||
} catch (error: any) {
|
||||
messageApi.error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
@ -168,6 +194,28 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
setModalVisible(true);
|
||||
};
|
||||
|
||||
//
|
||||
const handleBatchDelete = async () => {
|
||||
try {
|
||||
const confirmed = await modalApi.confirm({
|
||||
title: "确认批量删除",
|
||||
content: "确定需要批量删除?该操作会删除所有授权到期的机器码授权,请谨慎操作!",
|
||||
okText: "继续",
|
||||
});
|
||||
if (!confirmed) {
|
||||
messageApi.warning('取消操作');
|
||||
return;
|
||||
}
|
||||
// 开始删除
|
||||
await BatchDeleteMachine();
|
||||
messageApi.success('批量删除成功');
|
||||
// 重新加载数据\
|
||||
await QueryMachineAuthorizationCollection(tableParams, form.getFieldsValue());
|
||||
} catch (error: any) {
|
||||
messageApi.error(error.message);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
async function TableChangeHandle(pagination: TablePaginationConfig, filters: Record<string, FilterValue | null>, sorter: SorterResult<MachineAuthorizationModel.MachineAuthorizationBase> | SorterResult<MachineAuthorizationModel.MachineAuthorizationBase>[], extra: TableCurrentDataSource<MachineAuthorizationModel.MachineAuthorizationBase>): Promise<void> {
|
||||
await QueryMachineAuthorizationCollection({ pagination }, form.getFieldsValue());
|
||||
@ -189,20 +237,27 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "realDark"}>
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "light"}>
|
||||
<Form
|
||||
form={form}
|
||||
layout="inline"
|
||||
onFinish={(values) => QueryMachineAuthorizationCollection(tableParams, values)}
|
||||
style={{ marginBottom: 16 }}
|
||||
style={{ marginBottom: 8 }}
|
||||
>
|
||||
<div style={{ display: 'flex', flexWrap: 'wrap', gap: '16px', alignItems: 'flex-end' }}>
|
||||
<Form.Item name="ID" label="id">
|
||||
<Input placeholder="ID" style={{ width: 200 }} />
|
||||
</Form.Item>
|
||||
<Form.Item name="machineID" label="机器码">
|
||||
<Input placeholder="Machine ID" style={{ width: 200 }} />
|
||||
</Form.Item>
|
||||
<Form.Item name="emptyMachineId" valuePropName="checked">
|
||||
<Checkbox>空机器码</Checkbox>
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="authorizationCode" label="授权码">
|
||||
<Input placeholder="Authorization Code" style={{ width: 200 }} />
|
||||
</Form.Item>
|
||||
|
||||
<Form.Item name="type" label="授权类型">
|
||||
<Select
|
||||
placeholder="Authorization Type"
|
||||
@ -211,12 +266,18 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
options={GetMachineAuthorizationTypeOptions()}
|
||||
/>
|
||||
</Form.Item>
|
||||
<Form.Item>
|
||||
|
||||
<Form.Item >
|
||||
<Space>
|
||||
<Button type="primary" htmlType="submit" icon={<SearchOutlined />}>
|
||||
搜索
|
||||
</Button>
|
||||
<Button onClick={() => form.resetFields()}>
|
||||
<Button onClick={() => {
|
||||
form.resetFields();
|
||||
QueryMachineAuthorizationCollection(tableParams, form.getFieldsValue())
|
||||
}
|
||||
|
||||
}>
|
||||
重置
|
||||
</Button>
|
||||
<Button
|
||||
@ -226,8 +287,16 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
>
|
||||
添加机器码授权
|
||||
</Button>
|
||||
|
||||
<Button
|
||||
danger
|
||||
onClick={handleBatchDelete}
|
||||
>
|
||||
批量删除
|
||||
</Button>
|
||||
</Space>
|
||||
</Form.Item>
|
||||
</div>
|
||||
</Form>
|
||||
|
||||
<Table
|
||||
@ -237,12 +306,18 @@ const MachineIdAuthorization: React.FC = () => {
|
||||
loading={loading}
|
||||
pagination={tableParams.pagination}
|
||||
onChange={TableChangeHandle}
|
||||
scroll={{ x: 1500 }} // 添加这一行,设置表格的最小宽度
|
||||
/>
|
||||
|
||||
<Modal width={600} title="新增机器码" maskClosable={false} open={modalVisible} footer={null} onCancel={modalCancel}>
|
||||
<AddMachineIdAuthorization setFormRef={setFormRef} id={id} />
|
||||
{
|
||||
isEmpty(id) ? <AddMachineIdAuthorization setFormRef={setFormRef} /> :
|
||||
<ModifyMachineIdAuthorization setFormRef={setFormRef} id={id} />
|
||||
}
|
||||
|
||||
</Modal>
|
||||
{messageHolder}
|
||||
{modalHolder}
|
||||
</TemplateContainer>
|
||||
);
|
||||
};
|
||||
|
||||
@ -203,7 +203,7 @@ const PromptManagement: React.FC = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "realDark"}>
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "light"}>
|
||||
<Card
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
@ -211,7 +211,7 @@ const PromptManagement: React.FC = () => {
|
||||
styles={{
|
||||
body: {
|
||||
backgroundImage:
|
||||
initialState?.settings?.navTheme === 'realDark'
|
||||
initialState?.settings?.navTheme === 'light'
|
||||
? 'background-image: linear-gradient(75deg, #1A1B1F 0%, #191C1F 100%)'
|
||||
: 'background-image: linear-gradient(75deg, #FBFDFF 0%, #F5F7FF 100%)',
|
||||
}
|
||||
|
||||
@ -180,7 +180,7 @@ const PromptManagement: React.FC = () => {
|
||||
};
|
||||
|
||||
return (
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "realDark"}>
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "light"}>
|
||||
<Card
|
||||
style={{
|
||||
borderRadius: 8,
|
||||
@ -188,7 +188,7 @@ const PromptManagement: React.FC = () => {
|
||||
styles={{
|
||||
body: {
|
||||
backgroundImage:
|
||||
initialState?.settings?.navTheme === 'realDark'
|
||||
initialState?.settings?.navTheme === 'light'
|
||||
? 'background-image: linear-gradient(75deg, #1A1B1F 0%, #191C1F 100%)'
|
||||
: 'background-image: linear-gradient(75deg, #FBFDFF 0%, #F5F7FF 100%)',
|
||||
}
|
||||
|
||||
@ -196,7 +196,7 @@ const RoleManagement: React.FC = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "realDark"}>
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "light"}>
|
||||
<div>
|
||||
<Form
|
||||
layout='inline'
|
||||
|
||||
@ -14,9 +14,11 @@ import { AllOptionKeyName } from '@/services/enum/optionEnum';
|
||||
|
||||
interface SoftwareControlManagementProps {
|
||||
// Add your props here
|
||||
userId?: number;
|
||||
cantModify?: boolean;
|
||||
}
|
||||
|
||||
const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
const SoftwareControlManagement: FC<SoftwareControlManagementProps> = ({ userId, cantModify }) => {
|
||||
const { initialState } = useModel('@@initialState');
|
||||
const [messageApi, messageHolder] = message.useMessage();
|
||||
const [loading, setLoading] = React.useState<boolean>(false);
|
||||
@ -101,7 +103,7 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
title: '操作',
|
||||
key: 'action',
|
||||
width: 100,
|
||||
hidden: !access.isAdminOrSuperAdmin,
|
||||
hidden: !access.isAdminOrSuperAdmin && !access.canSofrwareControlManagement,
|
||||
render: (_, record) => (
|
||||
<Dropdown
|
||||
menu={{
|
||||
@ -109,6 +111,7 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
{
|
||||
key: 'edit',
|
||||
label: '编辑',
|
||||
hidden: !access.canEditSoftwareControl,
|
||||
icon: <EditOutlined />,
|
||||
onClick: () => {
|
||||
// 编辑
|
||||
@ -119,6 +122,7 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
key: 'addTrail',
|
||||
label: '添加试用',
|
||||
style: { color: '#faad14' },
|
||||
hidden: !access.canAddTrailSoftwareControl,
|
||||
icon: <PlusSquareOutlined />,
|
||||
onClick: async () => {
|
||||
// 添加试用
|
||||
@ -128,6 +132,7 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
{
|
||||
key: 'addMouth',
|
||||
label: '添加月付',
|
||||
hidden: !access.canAddMouthSoftwareControl,
|
||||
style: { color: '#38a2fc' },
|
||||
icon: <PlusSquareOutlined />,
|
||||
onClick: async () => {
|
||||
@ -139,6 +144,7 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
key: 'addQuarterly',
|
||||
label: '添加季付',
|
||||
style: { color: '#38a2fc' },
|
||||
hidden: !access.canAddQuarterlySoftwareControl,
|
||||
icon: <PlusSquareOutlined />,
|
||||
onClick: async () => {
|
||||
// 延长到期时间
|
||||
@ -148,6 +154,7 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
{
|
||||
key: 'addHalfYear',
|
||||
label: '添加半年',
|
||||
hidden: !access.canAddHalfYearSoftwareControl,
|
||||
style: { color: '#38a2fc' },
|
||||
icon: <PlusSquareOutlined />,
|
||||
onClick: async () => {
|
||||
@ -158,6 +165,7 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
{
|
||||
key: 'addYear',
|
||||
label: '添加年付',
|
||||
hidden: !access.canAddYearSoftwareControl,
|
||||
style: { color: '#38a2fc' },
|
||||
icon: <PlusSquareOutlined />,
|
||||
onClick: async () => {
|
||||
@ -168,6 +176,7 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
{
|
||||
key: 'addForever',
|
||||
label: '永久',
|
||||
hidden: !access.canAddForeverSoftwareControl,
|
||||
style: { color: '#38a2fc' },
|
||||
icon: <PlusSquareOutlined />,
|
||||
onClick: async () => {
|
||||
@ -179,12 +188,13 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
key: 'delete',
|
||||
label: '停用权限',
|
||||
danger: true,
|
||||
hidden: !access.canDeleteSoftwareControl,
|
||||
icon: <DeleteOutlined />,
|
||||
onClick: async () => {
|
||||
await DeleteSoftwareControl(record.id);
|
||||
}
|
||||
},
|
||||
],
|
||||
].filter(item => !item.hidden)
|
||||
}}
|
||||
>
|
||||
<Button type="text" color="primary" variant="filled" icon={<MenuOutlined />} />
|
||||
@ -272,6 +282,11 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
if (userId) {
|
||||
form.setFieldsValue({
|
||||
userId: userId
|
||||
})
|
||||
}
|
||||
QueryUserSoftwareControlCollection(tableParams, form.getFieldsValue()).then();
|
||||
Software.GetSoftwareBaseCollection().then((res) => {
|
||||
setSoftwareBasicInfo(res);
|
||||
@ -307,10 +322,11 @@ const SoftwareControlManagement: FC<SoftwareControlManagementProps> = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "realDark"}>
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "light"}>
|
||||
<Form
|
||||
layout='inline'
|
||||
form={form}
|
||||
disabled={cantModify}
|
||||
onFinish={QuerySoftwareControlByCondition}
|
||||
>
|
||||
<Form.Item label="用户ID" name='userId' style={{ marginBottom: 5 }}>
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Form, Input, Button, Spin, message, Row, Col } from 'antd';
|
||||
import { UserRegistr } from '@/services/services/login';
|
||||
import { history, request } from '@umijs/max';
|
||||
import { history } from '@umijs/max';
|
||||
import cusRequest from '@/request';
|
||||
|
||||
const Register: React.FC = () => {
|
||||
const [form] = Form.useForm();
|
||||
@ -36,7 +37,7 @@ const Register: React.FC = () => {
|
||||
|
||||
// 开始请求发送的接口
|
||||
|
||||
let res = await request<ApiResponse.SuccessItem<string>>(`/lms/User/SendVerificationCode`, {
|
||||
let res = await cusRequest<string>(`/lms/User/SendVerificationCode`, {
|
||||
method: 'POST',
|
||||
data: { email }
|
||||
});
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Form, Input, Button, message, Row, Col } from 'antd';
|
||||
import { request } from '@umijs/max';
|
||||
import cusRequest from '@/request';
|
||||
|
||||
|
||||
interface ResetPasswordProps {
|
||||
onCancel: () => void;
|
||||
@ -31,7 +32,7 @@ const ResetPassword: React.FC<ResetPasswordProps> = ({ onCancel, onSuccess }) =>
|
||||
|
||||
setLoading(true);
|
||||
// 发送验证码请求
|
||||
const res = await request<ApiResponse.SuccessItem<string>>('/lms/User/SendResetPasswordCode', {
|
||||
const res = await cusRequest<string>('/lms/User/SendResetPasswordCode', {
|
||||
method: 'POST',
|
||||
data: { email: emailValue }
|
||||
});
|
||||
@ -67,7 +68,7 @@ const ResetPassword: React.FC<ResetPasswordProps> = ({ onCancel, onSuccess }) =>
|
||||
|
||||
setLoading(true);
|
||||
// 发送重置密码请求
|
||||
const res = await request<ApiResponse.SuccessItem<string>>(`/lms/User/ResetPassword/${values.email}/${values.verificationCode}`, {
|
||||
const res = await cusRequest<string>(`/lms/User/ResetPassword/${values.email}/${values.verificationCode}`, {
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import React, { useState } from 'react';
|
||||
import { Form, Input, Button, message, Card, Typography } from 'antd';
|
||||
import { LockOutlined } from '@ant-design/icons';
|
||||
import { request, useModel } from '@umijs/max';
|
||||
import { useModel } from '@umijs/max';
|
||||
import { isEmpty } from 'lodash';
|
||||
import cusRequest from '@/request';
|
||||
|
||||
const { Title } = Typography;
|
||||
|
||||
@ -33,7 +34,7 @@ const ResetPassword: React.FC = () => {
|
||||
|
||||
setLoading(true);
|
||||
// 发送重置密码请求
|
||||
const res = await request<ApiResponse.SuccessItem<string>>(`/lms/User/ResetPassword/${initialState?.currentUser?.id}`, {
|
||||
const res = await cusRequest<string>(`/lms/User/ResetPassword/${initialState?.currentUser?.id}`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
"newPassword": values.newPassword,
|
||||
|
||||
@ -110,7 +110,7 @@ const UserCenter: React.FC = () => {
|
||||
}
|
||||
|
||||
return (
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "realDark"} style={{ minWidth: 600 }}>
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "light"} style={{ minWidth: 600 }}>
|
||||
<div>
|
||||
<Card hoverable title={renderTitie()} style={{ width: "100%" }}>
|
||||
<Row justify="start" wrap>
|
||||
|
||||
@ -9,12 +9,13 @@ 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 Icon, { DeleteOutlined, EditOutlined, KeyOutlined, MenuOutlined, SyncOutlined } from "@ant-design/icons";
|
||||
import Icon, { DeleteOutlined, EditOutlined, KeyOutlined, MenuOutlined, SyncOutlined, ToolOutlined } 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";
|
||||
import SofrwareControlManagement from "@/pages/Software/SofrwareControl/SofrwareControlManagement";
|
||||
|
||||
const UserManagement: React.FC = () => {
|
||||
type TagRender = SelectProps['tagRender'];
|
||||
@ -158,7 +159,7 @@ const UserManagement: React.FC = () => {
|
||||
* @returns
|
||||
*/
|
||||
async function ApplySoftwareControlHandle(userId: number) {
|
||||
if (!access.isAdminOrSuperAdmin) {
|
||||
if (!access.isAdminOrSuperAdmin && !access.isAgentUser) {
|
||||
messageApi.error("您没有权限执行此操作");
|
||||
return;
|
||||
}
|
||||
@ -246,7 +247,7 @@ const UserManagement: React.FC = () => {
|
||||
{
|
||||
title: '操作',
|
||||
width: '80px',
|
||||
hidden: !access.isAdminOrSuperAdmin,
|
||||
hidden: !(access.isAdminOrSuperAdmin || access.isAdmin || access.isSuperAdmin || access.isAgentUser),
|
||||
render: (text, record) => (
|
||||
<Dropdown
|
||||
menu={{
|
||||
@ -281,6 +282,22 @@ const UserManagement: React.FC = () => {
|
||||
await ApplySoftwareControlHandle(record.id);
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'modifySoftwareControl',
|
||||
label: '修改软件控制权限',
|
||||
icon: <ToolOutlined />,
|
||||
hidden: !access.canApplySoftwareControl,
|
||||
primary: true,
|
||||
onClick: async () => {
|
||||
modal.info({
|
||||
title: '修改软件控制权限',
|
||||
width: window.innerWidth * 0.8,
|
||||
closable: true,
|
||||
content: <SofrwareControlManagement userId={record.id} cantModify={true} />,
|
||||
footer: null
|
||||
});
|
||||
}
|
||||
},
|
||||
{
|
||||
key: 'delete',
|
||||
label: '删除',
|
||||
@ -301,7 +318,7 @@ const UserManagement: React.FC = () => {
|
||||
];
|
||||
|
||||
return (
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "realDark"}>
|
||||
<TemplateContainer navTheme={initialState?.settings?.navTheme ?? "light"}>
|
||||
<div>
|
||||
<Form
|
||||
layout='inline'
|
||||
|
||||
@ -96,7 +96,7 @@ const Welcome: React.FC = () => {
|
||||
body: {
|
||||
|
||||
backgroundImage:
|
||||
initialState?.settings?.navTheme === 'realDark'
|
||||
initialState?.settings?.navTheme === 'light'
|
||||
? 'background-image: linear-gradient(75deg, #1A1B1F 0%, #191C1F 100%)'
|
||||
: 'background-image: linear-gradient(75deg, #FBFDFF 0%, #F5F7FF 100%)',
|
||||
}
|
||||
|
||||
82
src/request.ts
Normal file
82
src/request.ts
Normal file
@ -0,0 +1,82 @@
|
||||
import { request as umiRequest } from '@umijs/max';
|
||||
import { message } from 'antd';
|
||||
import { history } from 'umi';
|
||||
import { errorMessage, successMessage } from './services/services/response';
|
||||
|
||||
// 刷新token函数
|
||||
export const refreshToken = async () => {
|
||||
try {
|
||||
let refreshTokenId = localStorage.getItem('refreshToken');
|
||||
if (!refreshTokenId) {
|
||||
return false;
|
||||
}
|
||||
let userId = JSON.parse(localStorage.getItem('userInfo') ?? "{}").id;
|
||||
const response = await umiRequest('/lms/User/RefreshToken', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
data: {
|
||||
refreshToken: refreshTokenId,
|
||||
"userId": userId,
|
||||
"deviceInfo": "2"
|
||||
},
|
||||
skipErrorHandler: true, // 跳过默认错误处理
|
||||
});
|
||||
|
||||
if (response.code == 1) {
|
||||
localStorage.setItem('token', response.data);
|
||||
console.log('刷新token成功', response.data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error('刷新token失败', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* @name 增强的请求函数
|
||||
* @description 该函数在请求失败时会尝试刷新token,并在刷新成功后重试请求。
|
||||
* @param url 请求的URL
|
||||
* @param options 请求的选项
|
||||
* @returns 返回请求的结果
|
||||
*/
|
||||
export const cusRequest = async <T>(url: string, options?: any): Promise<ApiResponse.SuccessItem<T> | ApiResponse.ErrorItem> => {
|
||||
try {
|
||||
let res = await umiRequest<T>(url, options) as any;
|
||||
if (res.code != 1) {
|
||||
return errorMessage("请求失败: " + res.message);
|
||||
} else {
|
||||
return successMessage(res.data, "请求成功");
|
||||
}
|
||||
} catch (error: any) {
|
||||
if (error?.response?.status === 401 && !url.toLowerCase().includes('/refreshtoken')) {
|
||||
// 尝试刷新token
|
||||
const refreshSuccess = await refreshToken();
|
||||
if (refreshSuccess) {
|
||||
// 刷新成功,重试请求
|
||||
let res = await umiRequest<T>(url, {
|
||||
...options,
|
||||
headers: {
|
||||
...options.headers,
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
||||
}
|
||||
});
|
||||
debugger
|
||||
return successMessage(res.data, "请求成功");
|
||||
} else { // 刷新失败,跳转登录页
|
||||
message.error('授权已过期,请重新登录');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('refreshToken');
|
||||
localStorage.removeItem('userInfo');
|
||||
history.push('/user/login');
|
||||
}
|
||||
}
|
||||
return errorMessage("请求失败: " + error.message);
|
||||
}
|
||||
};
|
||||
|
||||
export default cusRequest;
|
||||
@ -1,5 +1,5 @@
|
||||
import type { RequestOptions } from '@@/plugin-request/request';
|
||||
import { RequestConfig, request } from '@umijs/max';
|
||||
import { RequestConfig } from '@umijs/max';
|
||||
import { message } from 'antd';
|
||||
import { history } from 'umi';
|
||||
|
||||
@ -18,58 +18,6 @@ interface ResponseStructure {
|
||||
message?: string;
|
||||
}
|
||||
|
||||
// 添加一个刷新 token 的函数
|
||||
const refreshToken = async () => {
|
||||
try {
|
||||
let refreshTokenId = localStorage.getItem('refreshToken');
|
||||
if (!refreshTokenId) {
|
||||
return false;
|
||||
}
|
||||
let userId = JSON.parse(localStorage.getItem('userInfo') ?? "{}").id;
|
||||
// 这里实现刷新 token 的逻辑
|
||||
const response = await request('/lms/User/RefreshToken', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
"Content-Type": "application/json"
|
||||
},
|
||||
data: {
|
||||
refreshToken: refreshTokenId,
|
||||
"userId": userId,
|
||||
"deviceInfo": "2"
|
||||
},
|
||||
});
|
||||
|
||||
if (response.code == 1) {
|
||||
localStorage.setItem('token', response.data);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error('刷新 token 失败', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
const retryRequest = async (url: string, opts: RequestOptions) => {
|
||||
if (url) {
|
||||
try {
|
||||
|
||||
const response = await request(url, {
|
||||
...opts,
|
||||
headers: {
|
||||
...opts.headers,
|
||||
'Authorization': `Bearer ${localStorage.getItem('token')}`,
|
||||
},
|
||||
});
|
||||
return response;
|
||||
} catch (error) {
|
||||
console.error('重试请求失败', error);
|
||||
throw error;
|
||||
}
|
||||
} else {
|
||||
throw new Error('url is required for retryRequest');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* @name 错误处理
|
||||
@ -92,6 +40,7 @@ export const errorConfig: RequestConfig = {
|
||||
},
|
||||
// 错误接收及处理
|
||||
errorHandler: async (error: any, opts: any) => {
|
||||
debugger
|
||||
let url = error.config.url;
|
||||
if (opts?.skipErrorHandler) throw error;
|
||||
// 我们的 errorThrower 抛出的错误。
|
||||
@ -99,47 +48,7 @@ export const errorConfig: RequestConfig = {
|
||||
|
||||
} else if (error.response) {
|
||||
// 请求成功发出且服务器也响应了状态码,但状态代码超出了 2xx 的范围
|
||||
const { status } = error.response;
|
||||
if (status === 401) {
|
||||
if (url.toLowerCase().includes('/refreshtoken')) {
|
||||
message.error('登录已过期,请重新登录');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('refreshToken');
|
||||
localStorage.removeItem('userInfo');
|
||||
history.push('/user/login');
|
||||
} else {
|
||||
// 尝试刷新 token
|
||||
const refreshSuccess = await refreshToken();
|
||||
if (refreshSuccess) {
|
||||
// 刷新成功,重试原请求
|
||||
// 这里需要实现重试逻辑,可能需要修改您的请求库
|
||||
message.success('已重新获取授权,正在重试请求');
|
||||
// 刷新成功,重试原请求
|
||||
try {
|
||||
const retryResponse = await retryRequest(url, opts);
|
||||
// 如果重试成功,返回重试的响应
|
||||
return retryResponse;
|
||||
} catch (retryError) {
|
||||
message.error('重试请求失败,请重新登录');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('refreshToken');
|
||||
localStorage.removeItem('userInfo');
|
||||
history.push('/user/login');
|
||||
}
|
||||
// 重试原请求的逻辑
|
||||
} else {
|
||||
// 刷新失败,重定向到登录页面
|
||||
message.error('授权已过期,请重新登录');
|
||||
localStorage.removeItem('token');
|
||||
localStorage.removeItem('refreshToken');
|
||||
localStorage.removeItem('userInfo');
|
||||
history.push('/user/login');
|
||||
}
|
||||
}
|
||||
// 这边要判断是不是刷新token的时候401,如果是刷新token的时候401,就不跳转到登录页面
|
||||
// message.error('未授权,请重新登录');
|
||||
// history.push('/user/login'); // 重定向到登录页面
|
||||
}
|
||||
|
||||
} else if (error.request) {
|
||||
|
||||
// 请求已经成功发起,但没有收到响应
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
// @ts-ignore
|
||||
/* eslint-disable */
|
||||
import { request, useModel } from '@umijs/max';
|
||||
|
||||
import cusRequest from '@/request';
|
||||
import { TokenStorage } from '../define/tokenStorage';
|
||||
import { getCurrentUser } from './user';
|
||||
import forge from 'node-forge';
|
||||
@ -16,7 +17,7 @@ export async function getFakeCaptcha(
|
||||
},
|
||||
options?: { [key: string]: any },
|
||||
) {
|
||||
return request<API.FakeCaptcha>('/api/login/captcha', {
|
||||
return cusRequest<API.FakeCaptcha>('/api/login/captcha', {
|
||||
method: 'GET',
|
||||
params: {
|
||||
...params,
|
||||
@ -32,7 +33,7 @@ export async function getFakeCaptcha(
|
||||
export async function getPublicKey(): Promise<UserModel.UserPublicKeyResPonse> {
|
||||
try {
|
||||
// 获取加密的公钥
|
||||
let publicKey = await request<ApiResponse.SuccessItem<UserModel.UserPublicKeyResPonse>>("/lms/User/GetPublicKey", {
|
||||
let publicKey = await cusRequest<UserModel.UserPublicKeyResPonse>("/lms/User/GetPublicKey", {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -41,6 +42,9 @@ export async function getPublicKey(): Promise<UserModel.UserPublicKeyResPonse> {
|
||||
if (publicKey.code != 1) {
|
||||
throw new Error(publicKey.message);
|
||||
}
|
||||
if (publicKey.data == undefined || publicKey.data == null) {
|
||||
throw new Error("获取公钥失败");
|
||||
}
|
||||
return publicKey.data;
|
||||
} catch (error: any) {
|
||||
throw new Error(error.toString());
|
||||
@ -86,7 +90,7 @@ export async function login(body: API.LoginParams, options?: { [key: string]: an
|
||||
loginType: 1,
|
||||
tokenId: publicKey.token
|
||||
}
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.UserLoginResponse>>('/lms/User/Login', {
|
||||
let res = await cusRequest<UserModel.UserLoginResponse>('/lms/User/Login', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -106,6 +110,9 @@ export async function login(body: API.LoginParams, options?: { [key: string]: an
|
||||
} else {
|
||||
throw new Error(userInfo.message);
|
||||
}
|
||||
if (userInfo.data == null) {
|
||||
throw new Error("获取用户信息失败");
|
||||
}
|
||||
return userInfo.data
|
||||
} else {
|
||||
throw new Error(res.message);
|
||||
@ -132,7 +139,7 @@ export async function UserRegistr(params: UserModel.UserRegisterParams): Promise
|
||||
affiliateCode: params.affiliateCode,
|
||||
verificationCode: params.verificationCode
|
||||
}
|
||||
let res = await request<ApiResponse.SuccessItem<string>>('/lms/User/Register', {
|
||||
let res = await cusRequest<string>('/lms/User/Register', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { request } from "@umijs/max";
|
||||
import cusRequest from "@/request";
|
||||
import { objectToQueryString } from "./common"
|
||||
|
||||
/**
|
||||
@ -14,13 +14,13 @@ async function QueryMachineList(tableParams: TableModel.TableParams, userParams:
|
||||
pageSize: tableParams.pagination?.pageSize,
|
||||
}
|
||||
let query = objectToQueryString(data)
|
||||
let res = await request<ApiResponse.SuccessItem<MachineModel.QueryMachineData>>(`/lms/Machine/QueryMachineCollection?${query}`, {
|
||||
let res = await cusRequest<MachineModel.QueryMachineData>(`/lms/Machine/QueryMachineCollection?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as MachineModel.QueryMachineData;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -28,7 +28,7 @@ async function QueryMachineList(tableParams: TableModel.TableParams, userParams:
|
||||
* @param id
|
||||
*/
|
||||
async function MachinePermanent(id: String): Promise<void> {
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/Machine/UpgradeMachine/${id}`, {
|
||||
let res = await cusRequest<null>(`/lms/Machine/UpgradeMachine/${id}`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
@ -41,7 +41,7 @@ async function MachinePermanent(id: String): Promise<void> {
|
||||
* @param id
|
||||
*/
|
||||
async function DeactivationMachine(id: string): Promise<void> {
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/Machine/DeactivateMachine/${id}`, {
|
||||
let res = await cusRequest<null>(`/lms/Machine/DeactivateMachine/${id}`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
@ -55,12 +55,15 @@ async function DeactivationMachine(id: string): Promise<void> {
|
||||
* @returns
|
||||
*/
|
||||
async function GetMachineInfo(id: string): Promise<MachineModel.MachineInfo> {
|
||||
let res = await request<ApiResponse.SuccessItem<MachineModel.MachineInfo>>(`/lms/Machine/GetMachineDetail/${id}`, {
|
||||
let res = await cusRequest<MachineModel.MachineInfo>(`/lms/Machine/GetMachineDetail/${id}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
if (res.data == null) {
|
||||
throw new Error("获取机器码信息失败");
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
@ -75,7 +78,7 @@ async function ModifyMachineData(id: string, params: MachineModel.ModifyMachineP
|
||||
...params,
|
||||
deactivationTime: deactivationTimeString
|
||||
}
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/Machine/ModifyMachine/${id}`, {
|
||||
let res = await cusRequest<null>(`/lms/Machine/ModifyMachine/${id}`, {
|
||||
method: 'POST',
|
||||
data: data
|
||||
});
|
||||
@ -97,7 +100,7 @@ async function AddMachineData(params: MachineModel.AddMachineParams) {
|
||||
status: 1,
|
||||
}
|
||||
console.log(data)
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/Machine/AddMachine`, {
|
||||
let res = await cusRequest<null>(`/lms/Machine/AddMachine`, {
|
||||
method: 'POST',
|
||||
data: data
|
||||
});
|
||||
|
||||
@ -1,3 +1,4 @@
|
||||
import cusRequest from "@/request";
|
||||
import { AllOptionKeyName, OptionKeyName, OptionType } from "@/services/enum/optionEnum";
|
||||
import { isEmpty } from "lodash";
|
||||
|
||||
@ -89,7 +90,6 @@ export function getOptionsStringValue(options: OptionModel.Option[], keyName: st
|
||||
}
|
||||
}
|
||||
|
||||
import { request } from "@umijs/max";
|
||||
|
||||
/**
|
||||
* 获取指定的选项,会校验权限
|
||||
@ -97,7 +97,7 @@ import { request } from "@umijs/max";
|
||||
* @throws {Error} 如果响应代码不是 1,则抛出错误
|
||||
*/
|
||||
export async function GetOptions(optionsKey: AllOptionKeyName): Promise<OptionModel.Option[]> {
|
||||
let res = await request<ApiResponse.SuccessItem<OptionModel.Option[]>>(`/lms/LaitoolOptions/GetAllOptions/${optionsKey}`, {
|
||||
let res = await cusRequest<OptionModel.Option[]>(`/lms/LaitoolOptions/GetAllOptions/${optionsKey}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -106,7 +106,7 @@ export async function GetOptions(optionsKey: AllOptionKeyName): Promise<OptionMo
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as OptionModel.Option[];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -115,7 +115,7 @@ export async function GetOptions(optionsKey: AllOptionKeyName): Promise<OptionMo
|
||||
* @returns
|
||||
*/
|
||||
export async function GetSimpleOptions(optionsKey: OptionKeyName): Promise<OptionModel.Option[]> {
|
||||
let res = await request<ApiResponse.SuccessItem<OptionModel.Option[]>>(`/lms/LaitoolOptions/GetSimpleOptions/${optionsKey}`, {
|
||||
let res = await cusRequest<OptionModel.Option[]>(`/lms/LaitoolOptions/GetSimpleOptions/${optionsKey}`, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
@ -124,7 +124,7 @@ export async function GetSimpleOptions(optionsKey: OptionKeyName): Promise<Optio
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as OptionModel.Option[];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -141,7 +141,7 @@ export async function SaveOptions(options: object): Promise<void> {
|
||||
return "";
|
||||
}, {});
|
||||
|
||||
let res = await request<ApiResponse.SuccessItem<boolean>>('/lms/LaitoolOptions/ModifyOptions', {
|
||||
let res = await cusRequest<boolean>('/lms/LaitoolOptions/ModifyOptions', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
|
||||
105
src/services/services/other.ts
Normal file
105
src/services/services/other.ts
Normal file
@ -0,0 +1,105 @@
|
||||
import cusRequest from "@/request";
|
||||
import { objectToQueryString } from "./common";
|
||||
|
||||
|
||||
/**
|
||||
* 添加机器码授权
|
||||
* @param values
|
||||
*/
|
||||
export async function AddMachineIdAuthorizationFunc(values: any) {
|
||||
let res = await cusRequest<string>('lms/Other/AddMachineAuthorization', {
|
||||
method: "POST",
|
||||
data: {
|
||||
...values
|
||||
}
|
||||
})
|
||||
if (res.code !== 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改机器授权码
|
||||
* @param values
|
||||
*/
|
||||
export async function ModifyMachineAuthorization(id: string, values: any) {
|
||||
debugger
|
||||
let expiryDateString = values.expiryDate ? values.expiryDate.toISOString() : undefined;
|
||||
let res = await cusRequest<string>('lms/Other/ModifyMachineAuthorization/' + id, {
|
||||
method: "POST",
|
||||
data: {
|
||||
...values,
|
||||
expiryDate: expiryDateString
|
||||
}
|
||||
})
|
||||
if (res.code !== 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取机器码授权列表
|
||||
* @param tableParams 分页参数
|
||||
* @param options 查询参数
|
||||
* @returns
|
||||
*/
|
||||
export async function QueryMachineAuthorization(tableParams: TableModel.TableParams, options?: any) {
|
||||
let data = {
|
||||
...options,
|
||||
page: tableParams.pagination?.current,
|
||||
pageSize: tableParams.pagination?.pageSize,
|
||||
}
|
||||
let query = objectToQueryString(data)
|
||||
let res = await cusRequest<MachineAuthorizationModel.QueryMachineAuthorizationData>(`/lms/Other/QueryMachineAuthorizationCollection?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
|
||||
let resData = res.data;
|
||||
if (resData?.collection == undefined) {
|
||||
throw new Error('请求获取数据为空,请重试!');
|
||||
}
|
||||
return resData as MachineAuthorizationModel.QueryMachineAuthorizationData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除指定ID的机器码授权
|
||||
* @param id
|
||||
*/
|
||||
export async function DeleteMachineAuthorization(id: string) {
|
||||
let res = await cusRequest<string>(`/lms/Other/DeleteMachineAuthorization/${id}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 删除到期的机器码授权
|
||||
*/
|
||||
export async function BatchDeleteMachine() {
|
||||
// 开始删除
|
||||
let res = await cusRequest<string>(`/lms/Other/BatchDeleteMachine`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定ID的机器码授权
|
||||
* @param id
|
||||
*/
|
||||
export async function GetMachineAuthorizationById(id: string) {
|
||||
const res = await cusRequest<MachineAuthorizationModel.MachineAuthorizationBase>(`lms/Other/GetMachineAuthorization/${id}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code !== 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data as MachineAuthorizationModel.MachineAuthorizationBase;
|
||||
}
|
||||
@ -1,5 +1,5 @@
|
||||
import { request } from '@umijs/max';
|
||||
import { errorMessage } from './response';
|
||||
|
||||
import cusRequest from '@/request';
|
||||
import { objectToQueryString } from './common';
|
||||
|
||||
//#region 提示词数据相关
|
||||
@ -11,12 +11,15 @@ import { objectToQueryString } from './common';
|
||||
*/
|
||||
export async function QueryPromptCollection(param: Prompt.PromptQueryCondition): Promise<Prompt.PromptResponse> {
|
||||
let query = objectToQueryString(param)
|
||||
let res = await request<ApiResponse.SuccessItem<Prompt.PromptResponse>>(`/lms/Prompt/QueryPromptStringCollection/?${query}`, {
|
||||
let res = await cusRequest<Prompt.PromptResponse>(`/lms/Prompt/QueryPromptStringCollection/?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
if (res.data == null) {
|
||||
throw new Error("获取提示词数据失败");
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
@ -25,12 +28,15 @@ export async function QueryPromptCollection(param: Prompt.PromptQueryCondition):
|
||||
* @param id 指定的提示词ID
|
||||
*/
|
||||
export async function GetPromptInfo(id: string): Promise<Prompt.PromptItem> {
|
||||
let res = await request<ApiResponse.SuccessItem<Prompt.PromptItem>>(`/lms/Prompt/GetPromptInfo/${id}`, {
|
||||
let res = await cusRequest<Prompt.PromptItem>(`/lms/Prompt/GetPromptInfo/${id}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
if (res.data == null) {
|
||||
throw new Error("获取提示词数据失败");
|
||||
}
|
||||
return res.data;
|
||||
}
|
||||
|
||||
@ -41,7 +47,7 @@ export async function GetPromptInfo(id: string): Promise<Prompt.PromptItem> {
|
||||
* @returns
|
||||
*/
|
||||
export async function AddPrompt(data: Prompt.PromptItem): Promise<string> {
|
||||
let res = await request('/lms/Prompt/AddPrompt', {
|
||||
let res = await cusRequest<string>('/lms/Prompt/AddPrompt', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
name: data.name,
|
||||
@ -65,7 +71,7 @@ export async function AddPrompt(data: Prompt.PromptItem): Promise<string> {
|
||||
* @param params 参数
|
||||
*/
|
||||
export async function ModifyPrompt(id: string, params: Prompt.PromptItem): Promise<void> {
|
||||
let res = await request(`/lms/Prompt/ModifyPrompt/${id}`, {
|
||||
let res = await cusRequest<void>(`/lms/Prompt/ModifyPrompt/${id}`, {
|
||||
method: "POST",
|
||||
data: {
|
||||
...params
|
||||
@ -81,7 +87,7 @@ export async function ModifyPrompt(id: string, params: Prompt.PromptItem): Promi
|
||||
* @param id 要删除的提示词ID
|
||||
*/
|
||||
export async function DeletePrompt(id: string): Promise<void> {
|
||||
let res = await request(`/lms/Prompt/DeletePrompt/${id}`, {
|
||||
let res = await cusRequest<void>(`/lms/Prompt/DeletePrompt/${id}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
if (res.code != 1) {
|
||||
@ -102,13 +108,13 @@ export async function DeletePrompt(id: string): Promise<void> {
|
||||
*/
|
||||
export async function QueryPromptypeCollection(param: Prompt.PromptTypeQueryCondition): Promise<Prompt.PromptTypeResponse> {
|
||||
let query = objectToQueryString(param)
|
||||
let res = await request<ApiResponse.SuccessItem<Prompt.PromptTypeResponse>>(`/lms/Prompt/QueryPromptypeCollection/?${query}`, {
|
||||
let res = await cusRequest<Prompt.PromptTypeResponse>(`/lms/Prompt/QueryPromptypeCollection/?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as Prompt.PromptTypeResponse;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -116,13 +122,13 @@ export async function QueryPromptypeCollection(param: Prompt.PromptTypeQueryCond
|
||||
* @returns
|
||||
*/
|
||||
export async function GetPromptTypeOptions(): Promise<Prompt.PromptTypeOptions[]> {
|
||||
let res = await request<ApiResponse.SuccessItem<Prompt.PromptTypeOptions[]>>(`/lms/Prompt/GetPromptTypeOptions`, {
|
||||
let res = await cusRequest<Prompt.PromptTypeOptions[]>(`/lms/Prompt/GetPromptTypeOptions`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as Prompt.PromptTypeOptions[];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -131,13 +137,13 @@ export async function GetPromptTypeOptions(): Promise<Prompt.PromptTypeOptions[]
|
||||
* @returns
|
||||
*/
|
||||
export async function GetPromptTypeInfo(id: string): Promise<Prompt.PromptTypeItem> {
|
||||
let res = await request<ApiResponse.SuccessItem<Prompt.PromptTypeItem>>(`/lms/Prompt/GetPromptTypeInfo/${id}`, {
|
||||
let res = await cusRequest<Prompt.PromptTypeItem>(`/lms/Prompt/GetPromptTypeInfo/${id}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as Prompt.PromptTypeItem;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -145,7 +151,7 @@ export async function GetPromptTypeInfo(id: string): Promise<Prompt.PromptTypeIt
|
||||
* @param data 添加的类型
|
||||
*/
|
||||
export async function AddPromptType(data: Prompt.AddPromptType): Promise<string> {
|
||||
let res = await request('/lms/Prompt/AddPromptType', {
|
||||
let res = await cusRequest<string>('/lms/Prompt/AddPromptType', {
|
||||
method: 'POST',
|
||||
data: {
|
||||
name: data.name,
|
||||
@ -169,7 +175,7 @@ export async function EditPromptType(data: Prompt.AddPromptType): Promise<string
|
||||
if (id == null || id == undefined) {
|
||||
throw new Error("修改提示词类型的ID不能为空")
|
||||
}
|
||||
let res = await request(`/lms/Prompt/ModityPromptType/${id}`, {
|
||||
let res = await cusRequest<string>(`/lms/Prompt/ModityPromptType/${id}`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
name: data.name,
|
||||
@ -190,8 +196,8 @@ export async function EditPromptType(data: Prompt.AddPromptType): Promise<string
|
||||
* @param deletePrompt 是不是删除对应的提示词数据
|
||||
* @returns
|
||||
*/
|
||||
export async function DeletePromptType(id: string, deletePrompt: boolean): Promise<API.SuccessItem> {
|
||||
let res = await request(`/lms/Prompt/DeletePromptType/${id}/${deletePrompt}`, {
|
||||
export async function DeletePromptType(id: string, deletePrompt: boolean): Promise<ApiResponse.SuccessItem<any>> {
|
||||
let res = await cusRequest<any>(`/lms/Prompt/DeletePromptType/${id}/${deletePrompt}`, {
|
||||
method: 'DELETE',
|
||||
})
|
||||
return res;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
* @param {*} message 成功消息
|
||||
* @returns
|
||||
*/
|
||||
export function successMessage(data: any, message: string): API.SuccessItem {
|
||||
export function successMessage<T>(data: T, message: string): ApiResponse.SuccessItem<T> {
|
||||
return {
|
||||
code: 1,
|
||||
data: data,
|
||||
@ -17,9 +17,10 @@ export function successMessage(data: any, message: string): API.SuccessItem {
|
||||
* @param {*} message 错误信息
|
||||
* @returns
|
||||
*/
|
||||
export function errorMessage(message: string): API.ErrorItem {
|
||||
export function errorMessage(message: string): ApiResponse.ErrorItem {
|
||||
return {
|
||||
code: 0,
|
||||
message: message
|
||||
message: message,
|
||||
data: undefined
|
||||
}
|
||||
}
|
||||
@ -1,4 +1,5 @@
|
||||
import { request } from "@umijs/max";
|
||||
|
||||
import cusRequest from "@/request";
|
||||
import { isEmpty } from "lodash";
|
||||
|
||||
/**
|
||||
@ -18,26 +19,26 @@ export async function QueryRoleList(tableParams: TableModel.TableParams, rolePar
|
||||
delete data.current;
|
||||
delete data.total;
|
||||
let query = new URLSearchParams(data).toString();
|
||||
let res = await request<ApiResponse.SuccessItem<RoleModel.QueryRoleData>>(`/lms/Role/QueryRoleCollection?${query}`, {
|
||||
let res = await cusRequest<RoleModel.QueryRoleData>(`/lms/Role/QueryRoleCollection?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as RoleModel.QueryRoleData;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的角色名称
|
||||
*/
|
||||
export async function QueryRoleOption() {
|
||||
let res = await request<ApiResponse.SuccessItem<string[]>>(`/lms/Role/QueryRoleOption`, {
|
||||
let res = await cusRequest<string[]>(`/lms/Role/QueryRoleOption`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as string[];
|
||||
}
|
||||
|
||||
|
||||
@ -47,13 +48,13 @@ export async function QueryRoleOption() {
|
||||
* @returns
|
||||
*/
|
||||
export async function GetRoleById(roleId: number): Promise<RoleModel.Collection> {
|
||||
let res = await request<ApiResponse.SuccessItem<RoleModel.Collection>>(`/lms/Role/QueryRoleById/${roleId}`, {
|
||||
let res = await cusRequest<RoleModel.Collection>(`/lms/Role/QueryRoleById/${roleId}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as RoleModel.Collection;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -63,7 +64,7 @@ export async function GetRoleById(roleId: number): Promise<RoleModel.Collection>
|
||||
* @param roleRemark 角色的备注
|
||||
*/
|
||||
export async function UpdeteRole(roleId: number, roleName: string, roleRemark: string): Promise<void> {
|
||||
let res = await request<ApiResponse.SuccessItem<void>>(`/lms/Role/UpdateRole/${roleId}`, {
|
||||
let res = await cusRequest<void>(`/lms/Role/UpdateRole/${roleId}`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
name: roleName,
|
||||
@ -81,7 +82,7 @@ export async function UpdeteRole(roleId: number, roleName: string, roleRemark: s
|
||||
* @param roleId 角色ID
|
||||
*/
|
||||
export async function DeleteRoleById(roleId: number): Promise<void> {
|
||||
let res = await request<ApiResponse.SuccessItem<void>>(`/lms/Role/DeleteRole/${roleId}`, {
|
||||
let res = await cusRequest<void>(`/lms/Role/DeleteRole/${roleId}`, {
|
||||
method: 'DELETE',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
@ -98,7 +99,7 @@ export async function AddRole(roleNmae: string, roleRemark: string): Promise<voi
|
||||
if (isEmpty(roleNmae)) {
|
||||
throw new Error("角色名称不能为空");
|
||||
}
|
||||
let res = await request<ApiResponse.SuccessItem<void>>(`/lms/Role/AddRole`, {
|
||||
let res = await cusRequest<void>(`/lms/Role/AddRole`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
name: roleNmae,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
import cusRequest from '@/request';
|
||||
import { objectToQueryString } from './common';
|
||||
|
||||
/**
|
||||
@ -8,11 +9,11 @@ import { objectToQueryString } from './common';
|
||||
* @returns
|
||||
*/
|
||||
async function GetUserSoftwareControlCount(userId: number) {
|
||||
let res = await request<ApiResponse.SuccessItem<number>>(`/lms/SoftWare/GetUserSoftwareControlCount/${userId}`, {
|
||||
let res = await cusRequest<number>(`/lms/SoftWare/GetUserSoftwareControlCount/${userId}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code == 1) {
|
||||
return res.data;
|
||||
return res.data as number;
|
||||
}
|
||||
throw new Error(res.message);
|
||||
}
|
||||
@ -23,7 +24,7 @@ async function GetUserSoftwareControlCount(userId: number) {
|
||||
* @returns
|
||||
*/
|
||||
async function ApplyUserSoftwareControl(userId: number) {
|
||||
let res = await request<ApiResponse.SuccessItem<boolean>>(`/lms/SoftWare/ApplySoftwareControl/${userId}`, {
|
||||
let res = await cusRequest<boolean>(`/lms/SoftWare/ApplySoftwareControl/${userId}`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (res.code == 1) {
|
||||
@ -45,17 +46,17 @@ async function GetUserSoftwareControlCollection(tableParams: TableModel.TablePar
|
||||
pageSize: tableParams.pagination?.pageSize,
|
||||
}
|
||||
let query = objectToQueryString(data)
|
||||
let res = await request<ApiResponse.SuccessItem<SoftwareModel.QuerySoftwareControlData>>(`/lms/SoftWare/GetSoftwareControlCollection?${query}`, {
|
||||
let res = await cusRequest<SoftwareModel.QuerySoftwareControlData>(`/lms/SoftWare/GetSoftwareControlCollection?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as SoftwareModel.QuerySoftwareControlData;
|
||||
}
|
||||
|
||||
async function AddSoftwareControlExpirationTime(id: string, days: number, isForever: boolean, isTry = false) {
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/SoftWare/ModifySoftwareControlValidity/${id}`, {
|
||||
let res = await cusRequest<null>(`/lms/SoftWare/ModifySoftwareControlValidity/${id}`, {
|
||||
method: 'POST',
|
||||
data: {
|
||||
expirationTime: days,
|
||||
@ -81,11 +82,11 @@ export const SoftwareControl = {
|
||||
* @returns
|
||||
*/
|
||||
async function GetSoftwareBaseCollection() {
|
||||
let res = await request<ApiResponse.SuccessItem<SoftwareModel.SoftwareBasicInfo[]>>(`/lms/SoftWare/GetSoftwareBaseCollection`, {
|
||||
let res = await cusRequest<SoftwareModel.SoftwareBasicInfo[]>(`/lms/SoftWare/GetSoftwareBaseCollection`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code == 1) {
|
||||
return res.data;
|
||||
return res.data as SoftwareModel.SoftwareBasicInfo[];
|
||||
}
|
||||
throw new Error(res.message);
|
||||
}
|
||||
|
||||
@ -1,9 +1,10 @@
|
||||
import { request } from '@umijs/max';
|
||||
|
||||
import cusRequest from '@/request';
|
||||
import { objectToQueryString } from './common';
|
||||
|
||||
/** 获取当前的用户 GET /api/currentUser */
|
||||
export async function getCurrentUser(id: number, options?: { [key: string]: any }) {
|
||||
return request<ApiResponse.SuccessItem<UserModel.UserInfo>>(`/lms/User/GetUserInfo/${id}`, {
|
||||
return cusRequest<UserModel.UserInfo>(`/lms/User/GetUserInfo/${id}`, {
|
||||
method: 'GET',
|
||||
...(options || {}),
|
||||
});
|
||||
@ -15,13 +16,13 @@ export async function getCurrentUser(id: number, options?: { [key: string]: any
|
||||
* @returns
|
||||
*/
|
||||
async function GetUserInfo(id: number): Promise<UserModel.UserInfo> {
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.UserInfo>>(`/lms/User/GetUserInfo/${id}`, {
|
||||
let res = await cusRequest<UserModel.UserInfo>(`/lms/User/GetUserInfo/${id}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as UserModel.UserInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -46,7 +47,7 @@ async function UpdatedUserInfo(userData: UserModel.UserInfo) {
|
||||
}
|
||||
}
|
||||
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.UserInfo>>(`/lms/User/UpdatedUser/${userData.id}`, {
|
||||
let res = await cusRequest<UserModel.UserInfo>(`/lms/User/UpdatedUser/${userData.id}`, {
|
||||
method: 'POST',
|
||||
data: data,
|
||||
});
|
||||
@ -68,13 +69,13 @@ async function QueryUserList(tableParams: TableModel.TableParams, userParams: Us
|
||||
pageSize: tableParams.pagination?.pageSize,
|
||||
}
|
||||
let query = objectToQueryString(data)
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.QueryUserData>>(`/lms/User/QueryUserCollection?${query}`, {
|
||||
let res = await cusRequest<UserModel.QueryUserData>(`/lms/User/QueryUserCollection?${query}`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as UserModel.QueryUserData;
|
||||
|
||||
}
|
||||
|
||||
@ -83,7 +84,7 @@ async function QueryUserList(tableParams: TableModel.TableParams, userParams: Us
|
||||
* @param id
|
||||
*/
|
||||
async function EnableAgent() {
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.UserInfo>>(`/lms/User/EnableAgent`, {
|
||||
let res = await cusRequest<UserModel.UserInfo>(`/lms/User/EnableAgent`, {
|
||||
method: 'POST',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
@ -96,13 +97,13 @@ async function EnableAgent() {
|
||||
* @returns
|
||||
*/
|
||||
async function GetUserAgentInfo(): Promise<UserModel.UserAgentInfo> {
|
||||
let res = await request<ApiResponse.SuccessItem<UserModel.UserAgentInfo>>(`/lms/User/GetUserAgentInfo`, {
|
||||
let res = await cusRequest<UserModel.UserAgentInfo>(`/lms/User/GetUserAgentInfo`, {
|
||||
method: 'GET',
|
||||
});
|
||||
if (res.code != 1) {
|
||||
throw new Error(res.message);
|
||||
}
|
||||
return res.data;
|
||||
return res.data as UserModel.UserAgentInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -111,7 +112,7 @@ async function GetUserAgentInfo(): Promise<UserModel.UserAgentInfo> {
|
||||
* @param newPassword
|
||||
*/
|
||||
async function ResetUserPassword(userId: number, newPassword: string): Promise<void> {
|
||||
let res = await request<ApiResponse.SuccessItem<null>>(`/lms/User/ResetPassword/${userId}`, {
|
||||
let res = await cusRequest<null>(`/lms/User/ResetPassword/${userId}`, {
|
||||
method: 'post',
|
||||
data: {
|
||||
newPassword: newPassword,
|
||||
|
||||
21
src/services/typing/access.d.ts
vendored
21
src/services/typing/access.d.ts
vendored
@ -14,6 +14,8 @@ declare namespace AccessType {
|
||||
isAdmin: boolean;
|
||||
/**是不是超级管理员 */
|
||||
isSuperAdmin: boolean;
|
||||
/** 是不是代理 */
|
||||
isAgentUser: boolean;
|
||||
/**是不是管理员或者超级管理员 */
|
||||
isAdminOrSuperAdmin: boolean;
|
||||
//#endregion
|
||||
@ -26,7 +28,7 @@ declare namespace AccessType {
|
||||
canLaiToolOptions: boolean;
|
||||
|
||||
/** 是不是显示系统配置项的菜单 */
|
||||
canSystemOptions : boolean;
|
||||
canSystemOptions: boolean;
|
||||
//#endregion
|
||||
|
||||
//#region 机器权限
|
||||
@ -51,6 +53,23 @@ declare namespace AccessType {
|
||||
canApplySoftwareControl: boolean;
|
||||
/** 是否可以查看软件控制管理 */
|
||||
canSofrwareControlManagement: boolean;
|
||||
|
||||
/** 是否可以编辑软件控制权限 */
|
||||
canEditSoftwareControl: boolean;
|
||||
/** 是否可以添加使用软件控制权限 */
|
||||
canAddTrailSoftwareControl: boolean;
|
||||
/** 是否可以添加月付软件控制权限 */
|
||||
canAddMouthSoftwareControl: boolean;
|
||||
/** 是否可以添加季付软件控制权限 */
|
||||
canAddQuarterlySoftwareControl: boolean;
|
||||
/** 是否可以添加半年付软件控制权限 */
|
||||
canAddHalfYearSoftwareControl: boolean;
|
||||
/** 是否可以添加年付软件控制权限 */
|
||||
canAddYearSoftwareControl: boolean;
|
||||
/** 是否可以添加永久软件控制权限 */
|
||||
canAddForeverSoftwareControl: boolean;
|
||||
/** 是否可以删除软件控制权限 */
|
||||
canDeleteSoftwareControl: boolean;
|
||||
//#endregion
|
||||
}
|
||||
}
|
||||
6
src/services/typing/apiResponse.d.ts
vendored
6
src/services/typing/apiResponse.d.ts
vendored
@ -5,9 +5,9 @@ declare namespace ApiResponse {
|
||||
data: T
|
||||
}
|
||||
|
||||
type ErrorItem<T> = {
|
||||
type ErrorItem = {
|
||||
code: number
|
||||
message: string
|
||||
data?: T
|
||||
message: string,
|
||||
data: undefined
|
||||
}
|
||||
}
|
||||
@ -11,6 +11,8 @@ declare namespace MachineAuthorizationModel {
|
||||
id: string;
|
||||
machineID: string;
|
||||
type: number;
|
||||
useType: number;
|
||||
expiryTime: number;
|
||||
authorizedDate: Date;
|
||||
expiryDate: Date;
|
||||
authorizationCode: string;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user