Skip to content

Commit 2455b0c

Browse files
authored
Merge pull request #356 from guanweiwang/feature/toogle_ui
feat: 切换 ui
2 parents 26fff20 + 747f091 commit 2455b0c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1712
-1070
lines changed

ui/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
### UI框架与样式
4545
- **Material-UI (@mui)** - Google Material Design组件库
4646
- **Emotion** - CSS-in-JS样式库
47-
- **@c-x/ui** - 自定义组件库
47+
- **@ctzhian/ui** - 自定义组件库
4848

4949
### 状态管理与数据
5050
- **ahooks** - React Hooks工具库

ui/api-templates/http-client.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<%
22
const { apiConfig, generateResponses, config } = it;
33
%>
4-
import { message as Message } from '@c-x/ui'
4+
import { message as Message } from '@ctzhian/ui'
55
import type { AxiosInstance, AxiosRequestConfig, HeadersDefaults, ResponseType, AxiosResponse } from "axios";
66
import axios from "axios";
77

ui/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,13 @@
1111
"preview": "vite preview"
1212
},
1313
"dependencies": {
14-
"@c-x/ui": "^1.0.9",
14+
"@ctzhian/ui": "^7",
1515
"@emotion/react": "^11.14.0",
1616
"@emotion/styled": "^11.14.0",
1717
"@hookform/resolvers": "^5.2.1",
1818
"@monaco-editor/react": "4.7.0",
19-
"@mui/icons-material": "^6.4.12",
20-
"@mui/lab": "6.0.0-beta.19",
21-
"@mui/material": "^6.4.12",
19+
"@mui/icons-material": "^7",
20+
"@mui/material": "^7",
2221
"@yokowu/modelkit-ui": "2.0.6",
2322
"@tailwindcss/vite": "^4.1.12",
2423
"ahooks": "^3.8.4",

ui/pnpm-lock.yaml

Lines changed: 177 additions & 60 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ui/src/api/httpClient.ts

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,19 @@
1010
* ---------------------------------------------------------------
1111
*/
1212

13-
import { message as Message } from "@c-x/ui";
13+
import { message as Message } from '@ctzhian/ui';
1414
import type {
1515
AxiosInstance,
1616
AxiosRequestConfig,
1717
HeadersDefaults,
1818
ResponseType,
19-
} from "axios";
20-
import axios from "axios";
19+
} from 'axios';
20+
import axios from 'axios';
2121

2222
export type QueryParamsType = Record<string | number, any>;
2323

2424
export interface FullRequestParams
25-
extends Omit<AxiosRequestConfig, "data" | "params" | "url" | "responseType"> {
25+
extends Omit<AxiosRequestConfig, 'data' | 'params' | 'url' | 'responseType'> {
2626
/** set parameter to `true` for call `securityWorker` for this request */
2727
secure?: boolean;
2828
/** request path */
@@ -39,34 +39,34 @@ export interface FullRequestParams
3939

4040
export type RequestParams = Omit<
4141
FullRequestParams,
42-
"body" | "method" | "query" | "path"
42+
'body' | 'method' | 'query' | 'path'
4343
>;
4444

4545
export interface ApiConfig<SecurityDataType = unknown>
46-
extends Omit<AxiosRequestConfig, "data" | "cancelToken"> {
46+
extends Omit<AxiosRequestConfig, 'data' | 'cancelToken'> {
4747
securityWorker?: (
48-
securityData: SecurityDataType | null,
48+
securityData: SecurityDataType | null
4949
) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
5050
secure?: boolean;
5151
format?: ResponseType;
5252
}
5353

5454
export enum ContentType {
55-
Json = "application/json",
56-
FormData = "multipart/form-data",
57-
UrlEncoded = "application/x-www-form-urlencoded",
58-
Text = "text/plain",
55+
Json = 'application/json',
56+
FormData = 'multipart/form-data',
57+
UrlEncoded = 'application/x-www-form-urlencoded',
58+
Text = 'text/plain',
5959
}
6060

61-
const whitePathnameList = ["/user/login", "/login", "/auth", "/invite"];
62-
const whiteApiList = ["/api/v1/user/profile", "/api/v1/admin/profile"];
61+
const whitePathnameList = ['/user/login', '/login', '/auth', '/invite'];
62+
const whiteApiList = ['/api/v1/user/profile', '/api/v1/admin/profile'];
6363

6464
const redirectToLogin = () => {
6565
const redirectAfterLogin = encodeURIComponent(location.href);
6666
const search = `redirect=${redirectAfterLogin}`;
67-
const pathname = location.pathname.startsWith("/user")
68-
? "/login"
69-
: "/login/admin";
67+
const pathname = location.pathname.startsWith('/user')
68+
? '/login'
69+
: '/login/admin';
7070
window.location.href = `${pathname}`;
7171
};
7272

@@ -75,7 +75,7 @@ type ExtractDataProp<T> = T extends { data?: infer U } ? U : never;
7575
export class HttpClient<SecurityDataType = unknown> {
7676
public instance: AxiosInstance;
7777
private securityData: SecurityDataType | null = null;
78-
private securityWorker?: ApiConfig<SecurityDataType>["securityWorker"];
78+
private securityWorker?: ApiConfig<SecurityDataType>['securityWorker'];
7979
private secure?: boolean;
8080
private format?: ResponseType;
8181

@@ -88,7 +88,7 @@ export class HttpClient<SecurityDataType = unknown> {
8888
this.instance = axios.create({
8989
withCredentials: true,
9090
...axiosConfig,
91-
baseURL: axiosConfig.baseURL || "",
91+
baseURL: axiosConfig.baseURL || '',
9292
});
9393
this.secure = secure;
9494
this.format = format;
@@ -107,20 +107,20 @@ export class HttpClient<SecurityDataType = unknown> {
107107
if (
108108
whitePathnameList.find((item) => location.pathname.startsWith(item))
109109
) {
110-
return Promise.reject("尚未登录");
110+
return Promise.reject('尚未登录');
111111
}
112-
Message.error("尚未登录");
112+
Message.error('尚未登录');
113113
redirectToLogin();
114-
return Promise.reject("尚未登录");
114+
return Promise.reject('尚未登录');
115115
}
116116
// 手动取消请求
117-
if (err.code === "ERR_CANCELED") {
117+
if (err.code === 'ERR_CANCELED') {
118118
return;
119119
}
120120
const msg = err?.response?.data?.message || err?.message;
121121
Message.error(msg);
122122
return Promise.reject(msg);
123-
},
123+
}
124124
);
125125
}
126126

@@ -130,7 +130,7 @@ export class HttpClient<SecurityDataType = unknown> {
130130

131131
protected mergeRequestParams(
132132
params1: AxiosRequestConfig,
133-
params2?: AxiosRequestConfig,
133+
params2?: AxiosRequestConfig
134134
): AxiosRequestConfig {
135135
const method = params1.method || (params2 && params2.method);
136136

@@ -151,7 +151,7 @@ export class HttpClient<SecurityDataType = unknown> {
151151
}
152152

153153
protected stringifyFormItem(formItem: unknown) {
154-
if (typeof formItem === "object" && formItem !== null) {
154+
if (typeof formItem === 'object' && formItem !== null) {
155155
return JSON.stringify(formItem);
156156
} else {
157157
return `${formItem}`;
@@ -168,7 +168,7 @@ export class HttpClient<SecurityDataType = unknown> {
168168
const isFileType = formItem instanceof Blob || formItem instanceof File;
169169
formData.append(
170170
key,
171-
isFileType ? formItem : this.stringifyFormItem(formItem),
171+
isFileType ? formItem : this.stringifyFormItem(formItem)
172172
);
173173
}
174174

@@ -186,7 +186,7 @@ export class HttpClient<SecurityDataType = unknown> {
186186
...params
187187
}: FullRequestParams): Promise<ExtractDataProp<T>> => {
188188
const secureParams =
189-
((typeof secure === "boolean" ? secure : this.secure) &&
189+
((typeof secure === 'boolean' ? secure : this.secure) &&
190190
this.securityWorker &&
191191
(await this.securityWorker(this.securityData))) ||
192192
{};
@@ -197,7 +197,7 @@ export class HttpClient<SecurityDataType = unknown> {
197197
type === ContentType.FormData &&
198198
body &&
199199
body !== null &&
200-
typeof body === "object"
200+
typeof body === 'object'
201201
) {
202202
body = this.createFormData(body as Record<string, unknown>);
203203
}
@@ -206,7 +206,7 @@ export class HttpClient<SecurityDataType = unknown> {
206206
type === ContentType.Text &&
207207
body &&
208208
body !== null &&
209-
typeof body !== "string"
209+
typeof body !== 'string'
210210
) {
211211
body = JSON.stringify(body);
212212
}
@@ -216,7 +216,7 @@ export class HttpClient<SecurityDataType = unknown> {
216216
headers: {
217217
...(requestParams.headers || {}),
218218
...(type && type !== ContentType.FormData
219-
? { "Content-Type": type }
219+
? { 'Content-Type': type }
220220
: {}),
221221
},
222222
params: query,
@@ -226,4 +226,4 @@ export class HttpClient<SecurityDataType = unknown> {
226226
});
227227
};
228228
}
229-
export default new HttpClient({ format: "json" }).request;
229+
export default new HttpClient({ format: 'json' }).request;

ui/src/components/card/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { styled } from '@mui/material';
22

33
const StyledCard = styled('div')(({ theme }) => ({
44
padding: theme.spacing(2),
5-
borderRadius: theme.shape.borderRadius * 2.5,
5+
borderRadius: (theme.shape.borderRadius as number) * 2.5,
66
backgroundColor: theme.palette.background.default,
77
}));
88

0 commit comments

Comments
 (0)