@fecommunity/reactpress-toolkit 1.0.0-beta.1 → 1.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (121) hide show
  1. package/README.md +405 -0
  2. package/dist/api/Article.d.ts +44 -29
  3. package/dist/api/Article.js +42 -31
  4. package/dist/api/Auth.d.ts +11 -6
  5. package/dist/api/Auth.js +10 -8
  6. package/dist/api/Category.d.ts +20 -13
  7. package/dist/api/Category.js +18 -15
  8. package/dist/api/Comment.d.ts +22 -14
  9. package/dist/api/Comment.js +20 -16
  10. package/dist/api/File.d.ts +16 -10
  11. package/dist/api/File.js +14 -12
  12. package/dist/api/{http-client.d.ts → HttpClient.d.ts} +2 -2
  13. package/dist/api/{http-client.js → HttpClient.js} +4 -2
  14. package/dist/api/Knowledge.d.ts +29 -19
  15. package/dist/api/Knowledge.js +27 -22
  16. package/dist/api/Page.d.ts +23 -15
  17. package/dist/api/Page.js +21 -17
  18. package/dist/api/Search.d.ts +12 -7
  19. package/dist/api/Search.js +11 -9
  20. package/dist/api/Setting.d.ts +10 -6
  21. package/dist/api/Setting.js +8 -8
  22. package/dist/api/Smtp.d.ts +14 -9
  23. package/dist/api/Smtp.js +12 -11
  24. package/dist/api/Tag.d.ts +22 -14
  25. package/dist/api/Tag.js +20 -16
  26. package/dist/api/User.d.ts +15 -8
  27. package/dist/api/User.js +13 -13
  28. package/dist/api/View.d.ts +19 -12
  29. package/dist/api/View.js +17 -14
  30. package/dist/api/index.d.ts +13 -18
  31. package/dist/api/index.js +28 -41
  32. package/dist/api/instance.d.ts +47 -0
  33. package/dist/api/instance.js +71 -0
  34. package/dist/config/env.d.ts +1 -0
  35. package/dist/config/env.js +93 -0
  36. package/dist/config/global.d.ts +34 -0
  37. package/dist/config/global.js +382 -0
  38. package/dist/config/i18n.d.ts +5 -0
  39. package/dist/config/i18n.js +47 -0
  40. package/dist/config/index.d.ts +14 -0
  41. package/dist/config/index.js +30 -0
  42. package/dist/index.d.ts +8 -9
  43. package/dist/index.js +20 -18
  44. package/dist/locales/en.json +97 -0
  45. package/dist/locales/zh.json +97 -0
  46. package/dist/types/index.d.ts +245 -1
  47. package/dist/types/index.js +10 -17
  48. package/dist/utils/index.d.ts +33 -2
  49. package/dist/utils/index.js +57 -18
  50. package/package.json +15 -6
  51. package/demos/simple.ts +0 -65
  52. package/dist/api/Admin.d.ts +0 -14
  53. package/dist/api/Admin.js +0 -32
  54. package/dist/api/All.d.ts +0 -14
  55. package/dist/api/All.js +0 -32
  56. package/dist/api/Archives.d.ts +0 -14
  57. package/dist/api/Archives.js +0 -32
  58. package/dist/api/Book.d.ts +0 -15
  59. package/dist/api/Book.js +0 -33
  60. package/dist/api/Chapter.d.ts +0 -15
  61. package/dist/api/Chapter.js +0 -33
  62. package/dist/api/Get.d.ts +0 -14
  63. package/dist/api/Get.js +0 -32
  64. package/dist/api/Github.d.ts +0 -14
  65. package/dist/api/Github.js +0 -32
  66. package/dist/api/Host.d.ts +0 -14
  67. package/dist/api/Host.js +0 -32
  68. package/dist/api/Id.d.ts +0 -284
  69. package/dist/api/Id.js +0 -422
  70. package/dist/api/Login.d.ts +0 -14
  71. package/dist/api/Login.js +0 -32
  72. package/dist/api/Password.d.ts +0 -15
  73. package/dist/api/Password.js +0 -33
  74. package/dist/api/Recommend.d.ts +0 -14
  75. package/dist/api/Recommend.js +0 -32
  76. package/dist/api/Register.d.ts +0 -15
  77. package/dist/api/Register.js +0 -33
  78. package/dist/api/Update.d.ts +0 -15
  79. package/dist/api/Update.js +0 -33
  80. package/dist/api/Upload.d.ts +0 -15
  81. package/dist/api/Upload.js +0 -33
  82. package/dist/api/Url.d.ts +0 -14
  83. package/dist/api/Url.js +0 -32
  84. package/dist/api/api-instance.d.ts +0 -39
  85. package/dist/api/api-instance.js +0 -46
  86. package/dist/api/httpClient.d.ts +0 -41
  87. package/dist/api/httpClient.js +0 -94
  88. package/dist/types/data-contracts.d.ts +0 -177
  89. package/dist/types/data-contracts.js +0 -12
  90. package/dist/utils/common.d.ts +0 -23
  91. package/dist/utils/common.js +0 -78
  92. package/dist/utils/http.d.ts +0 -3
  93. package/dist/utils/http.js +0 -47
  94. package/scripts/generate-api-types.js +0 -571
  95. package/scripts/generate-swagger.js +0 -47
  96. package/scripts/organize-api.js +0 -136
  97. package/src/api/Article.ts +0 -186
  98. package/src/api/Auth.ts +0 -54
  99. package/src/api/Category.ts +0 -82
  100. package/src/api/Comment.ts +0 -95
  101. package/src/api/File.ts +0 -69
  102. package/src/api/Knowledge.ts +0 -122
  103. package/src/api/Page.ts +0 -95
  104. package/src/api/Search.ts +0 -54
  105. package/src/api/Setting.ts +0 -43
  106. package/src/api/Smtp.ts +0 -56
  107. package/src/api/Tag.ts +0 -95
  108. package/src/api/User.ts +0 -72
  109. package/src/api/View.ts +0 -82
  110. package/src/api/api-instance.ts +0 -69
  111. package/src/api/httpClient.ts +0 -140
  112. package/src/api/index.ts +0 -25
  113. package/src/index.ts +0 -18
  114. package/src/types/data-contracts.ts +0 -198
  115. package/src/types/index.ts +0 -4
  116. package/src/utils/common.ts +0 -108
  117. package/src/utils/http.ts +0 -52
  118. package/src/utils/index.ts +0 -5
  119. package/test-final.js +0 -56
  120. package/test-import.js +0 -34
  121. package/tsconfig.json +0 -20
@@ -1,33 +0,0 @@
1
- "use strict";
2
- /* eslint-disable */
3
- /* tslint:disable */
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
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.Upload = void 0;
14
- class Upload {
15
- constructor(http) {
16
- /**
17
- * No description
18
- *
19
- * @tags File
20
- * @name FileControllerUploadFile
21
- * @request POST:/file/upload
22
- * @response `200` `(IFile)[]` 上传文件
23
- */
24
- this.fileControllerUploadFile = (params = {}) => this.http.request({
25
- path: `/file/upload`,
26
- method: 'POST',
27
- format: 'json',
28
- ...params,
29
- });
30
- this.http = http;
31
- }
32
- }
33
- exports.Upload = Upload;
package/dist/api/Url.d.ts DELETED
@@ -1,14 +0,0 @@
1
- import { HttpClient, RequestParams } from './http-client';
2
- export declare class Url<SecurityDataType = unknown> {
3
- http: HttpClient<SecurityDataType>;
4
- constructor(http: HttpClient<SecurityDataType>);
5
- /**
6
- * No description
7
- *
8
- * @tags View
9
- * @name ViewControllerFindByUrl
10
- * @request GET:/view/url
11
- * @response `200` `void`
12
- */
13
- viewControllerFindByUrl: (params?: RequestParams) => Promise<import("axios").AxiosResponse<void, any, {}>>;
14
- }
package/dist/api/Url.js DELETED
@@ -1,32 +0,0 @@
1
- "use strict";
2
- /* eslint-disable */
3
- /* tslint:disable */
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
- Object.defineProperty(exports, "__esModule", { value: true });
13
- exports.Url = void 0;
14
- class Url {
15
- constructor(http) {
16
- /**
17
- * No description
18
- *
19
- * @tags View
20
- * @name ViewControllerFindByUrl
21
- * @request GET:/view/url
22
- * @response `200` `void`
23
- */
24
- this.viewControllerFindByUrl = (params = {}) => this.http.request({
25
- path: `/view/url`,
26
- method: 'GET',
27
- ...params,
28
- });
29
- this.http = http;
30
- }
31
- }
32
- exports.Url = Url;
@@ -1,39 +0,0 @@
1
- import { HttpClientConfig } from './httpClient';
2
- import { Article } from './Article';
3
- import { Auth } from './Auth';
4
- import { Category } from './Category';
5
- import { Comment } from './Comment';
6
- import { File } from './File';
7
- import { Knowledge } from './Knowledge';
8
- import { Page } from './Page';
9
- import { Search } from './Search';
10
- import { Setting } from './Setting';
11
- import { Smtp } from './Smtp';
12
- import { Tag } from './Tag';
13
- import { User } from './User';
14
- import { View } from './View';
15
- export interface ApiConfig<SecurityDataType = unknown> extends HttpClientConfig<SecurityDataType> {
16
- }
17
- export interface ApiInstance<SecurityDataType = unknown> {
18
- article: Article<SecurityDataType>;
19
- auth: Auth<SecurityDataType>;
20
- category: Category<SecurityDataType>;
21
- comment: Comment<SecurityDataType>;
22
- file: File<SecurityDataType>;
23
- knowledge: Knowledge<SecurityDataType>;
24
- page: Page<SecurityDataType>;
25
- search: Search<SecurityDataType>;
26
- setting: Setting<SecurityDataType>;
27
- smtp: Smtp<SecurityDataType>;
28
- tag: Tag<SecurityDataType>;
29
- user: User<SecurityDataType>;
30
- view: View<SecurityDataType>;
31
- }
32
- /**
33
- * 创建 API 实例
34
- * @param config API 配置
35
- * @returns API 实例对象
36
- */
37
- export declare function createApiInstance<SecurityDataType = unknown>(config?: ApiConfig<SecurityDataType>): ApiInstance<SecurityDataType>;
38
- export declare const api: ApiInstance<unknown>;
39
- export default api;
@@ -1,46 +0,0 @@
1
- "use strict";
2
- // API 实例化文件
3
- // 自动生成,请勿手动修改
4
- Object.defineProperty(exports, "__esModule", { value: true });
5
- exports.api = exports.createApiInstance = void 0;
6
- const httpClient_1 = require("./httpClient");
7
- const Article_1 = require("./Article");
8
- const Auth_1 = require("./Auth");
9
- const Category_1 = require("./Category");
10
- const Comment_1 = require("./Comment");
11
- const File_1 = require("./File");
12
- const Knowledge_1 = require("./Knowledge");
13
- const Page_1 = require("./Page");
14
- const Search_1 = require("./Search");
15
- const Setting_1 = require("./Setting");
16
- const Smtp_1 = require("./Smtp");
17
- const Tag_1 = require("./Tag");
18
- const User_1 = require("./User");
19
- const View_1 = require("./View");
20
- /**
21
- * 创建 API 实例
22
- * @param config API 配置
23
- * @returns API 实例对象
24
- */
25
- function createApiInstance(config = {}) {
26
- const httpClient = new httpClient_1.HttpClient(config);
27
- return {
28
- article: new Article_1.Article(config),
29
- auth: new Auth_1.Auth(config),
30
- category: new Category_1.Category(config),
31
- comment: new Comment_1.Comment(config),
32
- file: new File_1.File(config),
33
- knowledge: new Knowledge_1.Knowledge(config),
34
- page: new Page_1.Page(config),
35
- search: new Search_1.Search(config),
36
- setting: new Setting_1.Setting(config),
37
- smtp: new Smtp_1.Smtp(config),
38
- tag: new Tag_1.Tag(config),
39
- user: new User_1.User(config),
40
- view: new View_1.View(config),
41
- };
42
- }
43
- exports.createApiInstance = createApiInstance;
44
- // 默认 API 实例
45
- exports.api = createApiInstance();
46
- exports.default = exports.api;
@@ -1,41 +0,0 @@
1
- import { AxiosInstance, AxiosRequestConfig, AxiosResponse, ResponseType } from 'axios';
2
- export declare type QueryParamsType = Record<string | number, any>;
3
- export interface FullRequestParams extends Omit<AxiosRequestConfig, 'data' | 'params' | 'url' | 'responseType'> {
4
- /** set parameter to `true` for call `securityWorker` for this request */
5
- secure?: boolean;
6
- /** request path */
7
- path: string;
8
- /** content type of request body */
9
- type?: ContentType;
10
- /** query params */
11
- query?: QueryParamsType;
12
- /** format of response (i.e. response.json() -> format: "json") */
13
- format?: ResponseType;
14
- /** request body */
15
- body?: unknown;
16
- }
17
- export declare type RequestParams = Omit<FullRequestParams, 'body' | 'method' | 'query' | 'path'>;
18
- export interface HttpClientConfig<SecurityDataType = unknown> extends Omit<AxiosRequestConfig, 'data' | 'cancelToken'> {
19
- securityWorker?: (securityData: SecurityDataType | null) => Promise<AxiosRequestConfig | void> | AxiosRequestConfig | void;
20
- secure?: boolean;
21
- format?: ResponseType;
22
- }
23
- export declare enum ContentType {
24
- Json = "application/json",
25
- FormData = "multipart/form-data",
26
- UrlEncoded = "application/x-www-form-urlencoded",
27
- Text = "text/plain"
28
- }
29
- export declare class HttpClient<SecurityDataType = unknown> {
30
- instance: AxiosInstance;
31
- private securityData;
32
- securityWorker?: HttpClientConfig<SecurityDataType>['securityWorker'];
33
- private secure?;
34
- private format?;
35
- constructor({ securityWorker, secure, format, ...axiosConfig }?: HttpClientConfig<SecurityDataType>);
36
- setSecurityData: (data: SecurityDataType | null) => void;
37
- protected mergeRequestParams(params1: AxiosRequestConfig, params2?: AxiosRequestConfig): AxiosRequestConfig;
38
- protected stringifyFormItem(formItem: unknown): string;
39
- protected createFormData(input: Record<string, unknown>): FormData;
40
- request: <T = any, _E = any>({ secure, path, type, query, format, body, ...params }: FullRequestParams) => Promise<AxiosResponse<T, any, {}>>;
41
- }
@@ -1,94 +0,0 @@
1
- "use strict";
2
- /* eslint-disable */
3
- /* tslint:disable */
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
- var __importDefault = (this && this.__importDefault) || function (mod) {
13
- return (mod && mod.__esModule) ? mod : { "default": mod };
14
- };
15
- Object.defineProperty(exports, "__esModule", { value: true });
16
- exports.HttpClient = exports.ContentType = void 0;
17
- const axios_1 = __importDefault(require("axios"));
18
- var ContentType;
19
- (function (ContentType) {
20
- ContentType["Json"] = "application/json";
21
- ContentType["FormData"] = "multipart/form-data";
22
- ContentType["UrlEncoded"] = "application/x-www-form-urlencoded";
23
- ContentType["Text"] = "text/plain";
24
- })(ContentType = exports.ContentType || (exports.ContentType = {}));
25
- class HttpClient {
26
- constructor({ securityWorker, secure, format, ...axiosConfig } = {}) {
27
- this.securityData = null;
28
- this.setSecurityData = (data) => {
29
- this.securityData = data;
30
- };
31
- this.request = async ({ secure, path, type, query, format, body, ...params }) => {
32
- const secureParams = ((typeof secure === 'boolean' ? secure : this.secure) &&
33
- this.securityWorker &&
34
- (await this.securityWorker(this.securityData))) ||
35
- {};
36
- const requestParams = this.mergeRequestParams(params, secureParams);
37
- const responseFormat = format || this.format || undefined;
38
- if (type === ContentType.FormData && body && body !== null && typeof body === 'object') {
39
- body = this.createFormData(body);
40
- }
41
- if (type === ContentType.Text && body && body !== null && typeof body !== 'string') {
42
- body = JSON.stringify(body);
43
- }
44
- return this.instance.request({
45
- ...requestParams,
46
- headers: {
47
- ...(requestParams.headers || {}),
48
- ...(type && type !== ContentType.FormData ? { 'Content-Type': type } : {}),
49
- },
50
- params: query,
51
- responseType: responseFormat,
52
- data: body,
53
- url: path,
54
- });
55
- };
56
- this.instance = axios_1.default.create({ ...axiosConfig, baseURL: axiosConfig.baseURL || 'http://localhost:3002' });
57
- this.secure = secure;
58
- this.format = format;
59
- this.securityWorker = securityWorker;
60
- }
61
- mergeRequestParams(params1, params2) {
62
- const method = params1.method || (params2 && params2.method);
63
- return {
64
- ...this.instance.defaults,
65
- ...params1,
66
- ...(params2 || {}),
67
- headers: {
68
- ...((method && this.instance.defaults.headers[method.toLowerCase()]) || {}),
69
- ...(params1.headers || {}),
70
- ...((params2 && params2.headers) || {}),
71
- },
72
- };
73
- }
74
- stringifyFormItem(formItem) {
75
- if (typeof formItem === 'object' && formItem !== null) {
76
- return JSON.stringify(formItem);
77
- }
78
- else {
79
- return `${formItem}`;
80
- }
81
- }
82
- createFormData(input) {
83
- return Object.keys(input || {}).reduce((formData, key) => {
84
- const property = input[key];
85
- const propertyContent = property instanceof Array ? property : [property];
86
- for (const formItem of propertyContent) {
87
- const isFileType = formItem instanceof Blob || formItem instanceof File;
88
- formData.append(key, isFileType ? formItem : this.stringifyFormItem(formItem));
89
- }
90
- return formData;
91
- }, new FormData());
92
- }
93
- }
94
- exports.HttpClient = HttpClient;
@@ -1,177 +0,0 @@
1
- export interface IUser {
2
- name: string;
3
- password: string;
4
- avatar: string;
5
- email: string;
6
- role: string;
7
- status: string;
8
- type: string;
9
- /** @format date-time */
10
- createAt: string;
11
- /** @format date-time */
12
- updateAt: string;
13
- }
14
- export interface ISetting {
15
- id: string;
16
- i18n: string;
17
- globalSetting: string;
18
- systemUrl: string;
19
- systemTitle: string;
20
- systemSubTitle: string;
21
- systemLogo: string;
22
- systemBg: string;
23
- systemFavicon: string;
24
- systemNoticeInfo: string;
25
- systemFooterInfo: string;
26
- adminSystemUrl: string;
27
- baiduAnalyticsId: string;
28
- googleAnalyticsId: string;
29
- seoKeyword: string;
30
- seoDesc: string;
31
- oss: string;
32
- smtpHost: string;
33
- smtpPort: string;
34
- smtpUser: string;
35
- smtpPass: string;
36
- smtpFromUser: string;
37
- /** @format date-time */
38
- createAt: string;
39
- /** @format date-time */
40
- updateAt: string;
41
- }
42
- export interface I_SMTP {
43
- id: string;
44
- from: string;
45
- to: string;
46
- subject: string;
47
- text: string;
48
- html: string;
49
- /** @format date-time */
50
- createAt: string;
51
- }
52
- export interface IFile {
53
- id: string;
54
- originalname: string;
55
- filename: string;
56
- type: string;
57
- size: number;
58
- url: string;
59
- /** @format date-time */
60
- createAt: string;
61
- }
62
- export interface ITag {
63
- label: string;
64
- value: string;
65
- articles: string[];
66
- /** @format date-time */
67
- createAt: string;
68
- /** @format date-time */
69
- updateAt: string;
70
- }
71
- export interface ICategory {
72
- id: string;
73
- label: string;
74
- value: string;
75
- articles: string[];
76
- /** @format date-time */
77
- createAt: string;
78
- /** @format date-time */
79
- updateAt: string;
80
- }
81
- export interface IArticle {
82
- id: string;
83
- title: string;
84
- cover: string;
85
- summary: string;
86
- content: string;
87
- html: string;
88
- toc: string;
89
- category: ICategory;
90
- tags: string[];
91
- status: string;
92
- views: number;
93
- likes: number;
94
- isRecommended: boolean;
95
- password: string;
96
- needPassword: boolean;
97
- isCommentable: boolean;
98
- /** @format date-time */
99
- publishAt: string;
100
- /** @format date-time */
101
- createAt: string;
102
- /** @format date-time */
103
- updateAt: string;
104
- }
105
- export interface IKnowledge {
106
- id: string;
107
- parentId: string;
108
- order: number;
109
- title: string;
110
- cover: string;
111
- summary: string;
112
- content: string;
113
- html: string;
114
- toc: string;
115
- status: string;
116
- views: number;
117
- likes: number;
118
- isCommentable: boolean;
119
- /** @format date-time */
120
- publishAt: string;
121
- /** @format date-time */
122
- createAt: string;
123
- /** @format date-time */
124
- updateAt: string;
125
- }
126
- export interface IComment {
127
- id: string;
128
- name: string;
129
- email: string;
130
- avatar: string;
131
- content: string;
132
- html: string;
133
- pass: boolean;
134
- userAgent: string;
135
- hostId: string;
136
- url: string;
137
- parentCommentId: string;
138
- replyUserName: string;
139
- replyUserEmail: string;
140
- /** @format date-time */
141
- createAt: string;
142
- /** @format date-time */
143
- updateAt: string;
144
- }
145
- export interface IPage {
146
- id: string;
147
- cover: string;
148
- name: string;
149
- path: string;
150
- order: number;
151
- content: string;
152
- html: string;
153
- toc: string;
154
- status: string;
155
- /** @format date-time */
156
- publishAt: string;
157
- views: number;
158
- /** @format date-time */
159
- createAt: string;
160
- /** @format date-time */
161
- updateAt: string;
162
- }
163
- export interface IView {
164
- ip: string;
165
- userAgent: string;
166
- url: string;
167
- count: number;
168
- address: string;
169
- browser: string;
170
- engine: string;
171
- os: string;
172
- device: string;
173
- /** @format date-time */
174
- createAt: string;
175
- /** @format date-time */
176
- updateAt: string;
177
- }
@@ -1,12 +0,0 @@
1
- "use strict";
2
- /* eslint-disable */
3
- /* tslint:disable */
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
- Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,23 +0,0 @@
1
- export declare const formatDate: (date: Date, format?: string) => string;
2
- export declare const deepClone: <T>(obj: T) => T;
3
- export declare const debounce: <T extends (...args: any[]) => any>(func: T, wait: number) => (...args: Parameters<T>) => void;
4
- export declare const throttle: <T extends (...args: any[]) => any>(func: T, limit: number) => (...args: Parameters<T>) => void;
5
- export declare const isApiError: (error: any) => error is ApiError;
6
- export interface ApiResponse<T = any> {
7
- code: number;
8
- message: string;
9
- data: T;
10
- timestamp: number;
11
- }
12
- export interface PaginatedResponse<T = any> {
13
- items: T[];
14
- total: number;
15
- page: number;
16
- limit: number;
17
- totalPages: number;
18
- }
19
- export declare class ApiError extends Error {
20
- code: number;
21
- details?: any;
22
- constructor(code: number, message: string, details?: any);
23
- }
@@ -1,78 +0,0 @@
1
- "use strict";
2
- // 通用工具函数
3
- Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.ApiError = exports.isApiError = exports.throttle = exports.debounce = exports.deepClone = exports.formatDate = void 0;
5
- // 日期格式化
6
- const formatDate = (date, format = 'YYYY-MM-DD') => {
7
- const year = date.getFullYear();
8
- const month = String(date.getMonth() + 1).padStart(2, '0');
9
- const day = String(date.getDate()).padStart(2, '0');
10
- return format
11
- .replace('YYYY', String(year))
12
- .replace('MM', month)
13
- .replace('DD', day);
14
- };
15
- exports.formatDate = formatDate;
16
- // 深度克隆
17
- const deepClone = (obj) => {
18
- if (obj === null || typeof obj !== 'object') {
19
- return obj;
20
- }
21
- if (obj instanceof Date) {
22
- return new Date(obj.getTime());
23
- }
24
- if (Array.isArray(obj)) {
25
- return obj.map(item => (0, exports.deepClone)(item));
26
- }
27
- if (typeof obj === 'object') {
28
- const cloned = {};
29
- for (const key in obj) {
30
- if (obj.hasOwnProperty(key)) {
31
- cloned[key] = (0, exports.deepClone)(obj[key]);
32
- }
33
- }
34
- return cloned;
35
- }
36
- return obj;
37
- };
38
- exports.deepClone = deepClone;
39
- // 防抖函数
40
- const debounce = (func, wait) => {
41
- let timeout = null;
42
- return (...args) => {
43
- if (timeout) {
44
- clearTimeout(timeout);
45
- }
46
- timeout = setTimeout(() => {
47
- func(...args);
48
- }, wait);
49
- };
50
- };
51
- exports.debounce = debounce;
52
- // 节流函数
53
- const throttle = (func, limit) => {
54
- let inThrottle = false;
55
- return (...args) => {
56
- if (!inThrottle) {
57
- func(...args);
58
- inThrottle = true;
59
- setTimeout(() => (inThrottle = false), limit);
60
- }
61
- };
62
- };
63
- exports.throttle = throttle;
64
- // 检查是否为ApiError
65
- const isApiError = (error) => {
66
- return error instanceof ApiError || (error && typeof error === 'object' && 'code' in error && 'message' in error);
67
- };
68
- exports.isApiError = isApiError;
69
- // 错误处理
70
- class ApiError extends Error {
71
- constructor(code, message, details) {
72
- super(message);
73
- this.code = code;
74
- this.details = details;
75
- this.name = 'ApiError';
76
- }
77
- }
78
- exports.ApiError = ApiError;
@@ -1,3 +0,0 @@
1
- export declare const createHttpClient: (baseURL?: string) => import("axios").AxiosInstance;
2
- export declare const httpClient: import("axios").AxiosInstance;
3
- export default httpClient;
@@ -1,47 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.httpClient = exports.createHttpClient = void 0;
7
- const axios_1 = __importDefault(require("axios"));
8
- // 创建自定义 axios 实例
9
- const createHttpClient = (baseURL) => {
10
- const instance = axios_1.default.create({
11
- baseURL: baseURL || process.env.API_BASE_URL || 'http://localhost:3002',
12
- timeout: 30000,
13
- headers: {
14
- 'Content-Type': 'application/json',
15
- },
16
- });
17
- // 请求拦截器
18
- instance.interceptors.request.use((config) => {
19
- // 添加认证令牌
20
- const token = typeof window !== 'undefined' ? localStorage.getItem('auth_token') : null;
21
- if (token && config.headers) {
22
- config.headers.Authorization = `Bearer ${token}`;
23
- }
24
- return config;
25
- }, (error) => {
26
- return Promise.reject(error);
27
- });
28
- // 响应拦截器
29
- instance.interceptors.response.use((response) => {
30
- return response.data;
31
- }, (error) => {
32
- // 统一错误处理
33
- if (error.response?.status === 401) {
34
- // 未授权处理
35
- if (typeof window !== 'undefined') {
36
- localStorage.removeItem('auth_token');
37
- window.location.href = '/login';
38
- }
39
- }
40
- return Promise.reject(error.response?.data || error);
41
- });
42
- return instance;
43
- };
44
- exports.createHttpClient = createHttpClient;
45
- // 默认 HTTP 客户端实例
46
- exports.httpClient = (0, exports.createHttpClient)();
47
- exports.default = exports.httpClient;