Skip to content

Commit 1b9aa37

Browse files
authored
Merge pull request #236 from safe1ine/main
增加了前端授权激活的功能
2 parents f99b87a + 4608a5e commit 1b9aa37

File tree

8 files changed

+361
-55
lines changed

8 files changed

+361
-55
lines changed

ui/src/api/License.ts

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/* eslint-disable */
2+
/* tslint:disable */
3+
// @ts-nocheck
4+
/*
5+
* ---------------------------------------------------------------
6+
* ## THIS FILE WAS GENERATED VIA SWAGGER-TYPESCRIPT-API ##
7+
* ## ##
8+
* ## AUTHOR: acacode ##
9+
* ## SOURCE: https://github.com/acacode/swagger-typescript-api ##
10+
* ---------------------------------------------------------------
11+
*/
12+
13+
import request, { ContentType, RequestParams } from "./httpClient";
14+
import {
15+
GithubComChaitinMonkeyCodeBackendProDomainLicenseResp,
16+
V1LicenseCreatePayload,
17+
WebResp,
18+
} from "./types";
19+
20+
/**
21+
* @description Get license
22+
*
23+
* @tags license
24+
* @name V1LicenseList
25+
* @summary Get license
26+
* @request GET:/api/v1/license
27+
* @response `200` `(WebResp & {
28+
data?: GithubComChaitinMonkeyCodeBackendProDomainLicenseResp,
29+
30+
})` OK
31+
*/
32+
33+
export const v1LicenseList = (params: RequestParams = {}) =>
34+
request<
35+
WebResp & {
36+
data?: GithubComChaitinMonkeyCodeBackendProDomainLicenseResp;
37+
}
38+
>({
39+
path: `/api/v1/license`,
40+
method: "GET",
41+
type: ContentType.Json,
42+
format: "json",
43+
...params,
44+
});
45+
46+
/**
47+
* @description Upload license
48+
*
49+
* @tags license
50+
* @name V1LicenseCreate
51+
* @summary Upload license
52+
* @request POST:/api/v1/license
53+
* @response `200` `(WebResp & {
54+
data?: GithubComChaitinMonkeyCodeBackendProDomainLicenseResp,
55+
56+
})` OK
57+
*/
58+
59+
export const v1LicenseCreate = (
60+
data: V1LicenseCreatePayload,
61+
params: RequestParams = {},
62+
) =>
63+
request<
64+
WebResp & {
65+
data?: GithubComChaitinMonkeyCodeBackendProDomainLicenseResp;
66+
}
67+
>({
68+
path: `/api/v1/license`,
69+
method: "POST",
70+
body: data,
71+
type: ContentType.FormData,
72+
format: "json",
73+
...params,
74+
});

ui/src/api/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './Billing'
33
export * from './Cli'
44
export * from './CodeSnippet'
55
export * from './Dashboard'
6+
export * from './License'
67
export * from './Model'
78
export * from './OpenAiv1'
89
export * from './SecurityScanning'

ui/src/api/types.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1179,6 +1179,13 @@ export interface GithubComChaitinMonkeyCodeBackendEntTypesPosition {
11791179
offset?: number;
11801180
}
11811181

1182+
export interface GithubComChaitinMonkeyCodeBackendProDomainLicenseResp {
1183+
edition?: number;
1184+
expired_at?: number;
1185+
started_at?: number;
1186+
state?: number;
1187+
}
1188+
11821189
export interface InternalCodesnippetHandlerHttpV1GetContextReq {
11831190
/** 返回结果数量限制,默认10 */
11841191
limit?: number;
@@ -1372,6 +1379,18 @@ export interface GetUserStatDashboardParams {
13721379
user_id?: string;
13731380
}
13741381

1382+
export interface V1LicenseCreatePayload {
1383+
/** license type */
1384+
license_type: "file" | "code";
1385+
/**
1386+
* license file
1387+
* @format binary
1388+
*/
1389+
license_file: File;
1390+
/** license code */
1391+
license_code: string;
1392+
}
1393+
13751394
export interface DeleteDeleteModelParams {
13761395
/** 模型ID */
13771396
id: string;
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import dayjs from 'dayjs';
2+
import { useState } from 'react';
3+
import { Ellipsis, Modal } from '@c-x/ui';
4+
import { Box, Button, Link, Stack } from '@mui/material';
5+
import { GithubComChaitinMonkeyCodeBackendProDomainLicenseResp } from '@/api/types';
6+
import ChangeLicense from './changeLicense';
7+
8+
interface LicenseModalProps {
9+
open: boolean;
10+
onClose: () => void;
11+
curVersion: string;
12+
latestVersion: string;
13+
license: GithubComChaitinMonkeyCodeBackendProDomainLicenseResp | undefined;
14+
}
15+
16+
const AboutModal = ({
17+
open,
18+
onClose,
19+
curVersion,
20+
latestVersion,
21+
license
22+
}: LicenseModalProps) => {
23+
24+
const [openChangeLicense, setOpenChangeLicense] = useState(false);
25+
26+
const editionText = (edition: any) => {
27+
if (edition === 0) {
28+
return '开源版'
29+
} else if (edition === 1) {
30+
return '联创版'
31+
} else if (edition === 2) {
32+
return '企业版'
33+
} else {
34+
return '未知'
35+
}
36+
}
37+
38+
return (
39+
<Modal
40+
title='关于 MonkeyCode'
41+
width={600}
42+
open={open}
43+
onCancel={onClose}
44+
footer={null}>
45+
<Stack direction={'column'} gap={2} sx={{
46+
fontSize: '14px'
47+
}}>
48+
<Stack direction={'row'}>
49+
<Box sx={{
50+
width: '120px'
51+
}}>当前版本</Box>
52+
<Box sx={{
53+
width: '120px',
54+
fontWeight: 700
55+
}}>{curVersion}</Box>
56+
</Stack>
57+
<Stack direction={'row'}>
58+
<Box sx={{
59+
width: '120px',
60+
}}>产品型号</Box>
61+
<Box sx={{
62+
mr: '20px'
63+
}}>{editionText(license?.edition)}</Box>
64+
<Link href="#" sx={{
65+
color: 'info.main',
66+
'&:hover': {
67+
fontWeight: 700
68+
}
69+
}}
70+
onClick={() => {
71+
setOpenChangeLicense(true);
72+
}}>切换授权</Link>
73+
</Stack>
74+
{license && license?.edition !== 0 && <Stack direction={'row'}>
75+
<Box sx={{
76+
width: '120px'
77+
}}>授权时间</Box>
78+
<Box sx={{
79+
}}>{dayjs.unix(license.started_at!).format('YYYY-MM-DD')} ~ {dayjs.unix(license.expired_at!).format('YYYY-MM-DD')}</Box>
80+
</Stack>}
81+
</Stack>
82+
<ChangeLicense
83+
open={openChangeLicense}
84+
onClose={() => {setOpenChangeLicense(false)}} />
85+
</Modal>
86+
);
87+
};
88+
89+
export default AboutModal;
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import dayjs from 'dayjs';
2+
import { useState } from 'react';
3+
import { Ellipsis, message, Modal } from '@c-x/ui';
4+
import { Box, Button, Link, Stack, TextField } from '@mui/material';
5+
import { GithubComChaitinMonkeyCodeBackendProDomainLicenseResp } from '@/api/types';
6+
import { v1LicenseCreate } from '@/api';
7+
8+
interface LicenseModalProps {
9+
open: boolean;
10+
onClose: () => void;
11+
}
12+
13+
const ChangeLicense = ({
14+
open,
15+
onClose
16+
}: LicenseModalProps) => {
17+
const [code, setCode] = useState('');
18+
const [verifing, setVerifing] = useState(false);
19+
20+
const updateLicense = () => {
21+
if (code.length === 0) {
22+
message.error("授权码不能为空");
23+
return;
24+
}
25+
setVerifing(true);
26+
v1LicenseCreate({
27+
license_type: 'code',
28+
license_code: code,
29+
license_file: '' as any
30+
}).then((resp: GithubComChaitinMonkeyCodeBackendProDomainLicenseResp) => {
31+
message.success("切换授权成功");
32+
console.log(resp)
33+
setVerifing(false);
34+
onClose();
35+
setTimeout(() => {
36+
location.reload();
37+
}, 1000)
38+
}).catch(() => {
39+
message.error("遇到一点意外,无法激活");
40+
setVerifing(false);
41+
})
42+
}
43+
44+
return (
45+
<Modal
46+
title='切换 MonkeyCode 授权'
47+
width={400}
48+
open={open}
49+
onCancel={onClose}
50+
footer={null}>
51+
<Stack direction={'column'} gap={2} sx={{
52+
fontSize: '14px'
53+
}}>
54+
<Stack direction={'row'} gap={2} sx={{
55+
fontSize: '14px'
56+
}}>
57+
<TextField label="授权码" variant="outlined" sx={{
58+
width: '100%'
59+
}}
60+
onChange={(e) => {
61+
setCode(e.target.value);
62+
}} />
63+
64+
</Stack>
65+
<Stack direction={'row'} gap={2} sx={{
66+
fontSize: '14px'
67+
}}>
68+
<Button variant="contained"
69+
loading={verifing}
70+
sx={{
71+
width: '100%'
72+
}}
73+
onClick={() => {
74+
updateLicense()
75+
}}>在线激活</Button>
76+
</Stack>
77+
</Stack>
78+
</Modal>
79+
);
80+
};
81+
82+
export default ChangeLicense;

0 commit comments

Comments
 (0)