@fecommunity/reactpress-toolkit 1.0.0-beta.1
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.
- package/LICENSE +21 -0
- package/demos/simple.ts +65 -0
- package/dist/api/Admin.d.ts +14 -0
- package/dist/api/Admin.js +32 -0
- package/dist/api/All.d.ts +14 -0
- package/dist/api/All.js +32 -0
- package/dist/api/Archives.d.ts +14 -0
- package/dist/api/Archives.js +32 -0
- package/dist/api/Article.d.ts +108 -0
- package/dist/api/Article.js +177 -0
- package/dist/api/Auth.d.ts +27 -0
- package/dist/api/Auth.js +56 -0
- package/dist/api/Book.d.ts +15 -0
- package/dist/api/Book.js +33 -0
- package/dist/api/Category.d.ts +44 -0
- package/dist/api/Category.js +81 -0
- package/dist/api/Chapter.d.ts +15 -0
- package/dist/api/Chapter.js +33 -0
- package/dist/api/Comment.d.ts +52 -0
- package/dist/api/Comment.js +93 -0
- package/dist/api/File.d.ts +36 -0
- package/dist/api/File.js +69 -0
- package/dist/api/Get.d.ts +14 -0
- package/dist/api/Get.js +32 -0
- package/dist/api/Github.d.ts +14 -0
- package/dist/api/Github.js +32 -0
- package/dist/api/Host.d.ts +14 -0
- package/dist/api/Host.js +32 -0
- package/dist/api/Id.d.ts +284 -0
- package/dist/api/Id.js +422 -0
- package/dist/api/Knowledge.d.ts +68 -0
- package/dist/api/Knowledge.js +118 -0
- package/dist/api/Login.d.ts +14 -0
- package/dist/api/Login.js +32 -0
- package/dist/api/Page.d.ts +52 -0
- package/dist/api/Page.js +93 -0
- package/dist/api/Password.d.ts +15 -0
- package/dist/api/Password.js +33 -0
- package/dist/api/Recommend.d.ts +14 -0
- package/dist/api/Recommend.js +32 -0
- package/dist/api/Register.d.ts +15 -0
- package/dist/api/Register.js +33 -0
- package/dist/api/Search.d.ts +27 -0
- package/dist/api/Search.js +56 -0
- package/dist/api/Setting.d.ts +20 -0
- package/dist/api/Setting.js +45 -0
- package/dist/api/Smtp.d.ts +28 -0
- package/dist/api/Smtp.js +57 -0
- package/dist/api/Tag.d.ts +52 -0
- package/dist/api/Tag.js +93 -0
- package/dist/api/Update.d.ts +15 -0
- package/dist/api/Update.js +33 -0
- package/dist/api/Upload.d.ts +15 -0
- package/dist/api/Upload.js +33 -0
- package/dist/api/Url.d.ts +14 -0
- package/dist/api/Url.js +32 -0
- package/dist/api/User.d.ts +36 -0
- package/dist/api/User.js +72 -0
- package/dist/api/View.d.ts +44 -0
- package/dist/api/View.js +81 -0
- package/dist/api/api-instance.d.ts +39 -0
- package/dist/api/api-instance.js +46 -0
- package/dist/api/http-client.d.ts +41 -0
- package/dist/api/http-client.js +94 -0
- package/dist/api/httpClient.d.ts +41 -0
- package/dist/api/httpClient.js +94 -0
- package/dist/api/index.d.ts +18 -0
- package/dist/api/index.js +43 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +46 -0
- package/dist/types/data-contracts.d.ts +177 -0
- package/dist/types/data-contracts.js +12 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +19 -0
- package/dist/utils/common.d.ts +23 -0
- package/dist/utils/common.js +78 -0
- package/dist/utils/http.d.ts +3 -0
- package/dist/utils/http.js +47 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +20 -0
- package/package.json +19 -0
- package/scripts/generate-api-types.js +571 -0
- package/scripts/generate-swagger.js +47 -0
- package/scripts/organize-api.js +136 -0
- package/src/api/Article.ts +186 -0
- package/src/api/Auth.ts +54 -0
- package/src/api/Category.ts +82 -0
- package/src/api/Comment.ts +95 -0
- package/src/api/File.ts +69 -0
- package/src/api/Knowledge.ts +122 -0
- package/src/api/Page.ts +95 -0
- package/src/api/Search.ts +54 -0
- package/src/api/Setting.ts +43 -0
- package/src/api/Smtp.ts +56 -0
- package/src/api/Tag.ts +95 -0
- package/src/api/User.ts +72 -0
- package/src/api/View.ts +82 -0
- package/src/api/api-instance.ts +69 -0
- package/src/api/httpClient.ts +140 -0
- package/src/api/index.ts +25 -0
- package/src/index.ts +18 -0
- package/src/types/data-contracts.ts +198 -0
- package/src/types/index.ts +4 -0
- package/src/utils/common.ts +108 -0
- package/src/utils/http.ts +52 -0
- package/src/utils/index.ts +5 -0
- package/test-final.js +56 -0
- package/test-import.js +34 -0
- package/tsconfig.json +20 -0
|
@@ -0,0 +1,78 @@
|
|
|
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;
|
|
@@ -0,0 +1,47 @@
|
|
|
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;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// 工具函数索引
|
|
3
|
+
// 自动生成,请勿手动修改
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
16
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
17
|
+
};
|
|
18
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
19
|
+
__exportStar(require("./http"), exports);
|
|
20
|
+
__exportStar(require("./common"), exports);
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fecommunity/reactpress-toolkit",
|
|
3
|
+
"version": "1.0.0-beta.1",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"keywords": [],
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "ISC",
|
|
8
|
+
"description": "",
|
|
9
|
+
"dependencies": {
|
|
10
|
+
"lodash": "^4.17.21",
|
|
11
|
+
"swagger-typescript-api": "^12.0.4",
|
|
12
|
+
"axios": "^1.12.2"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"generate": "node scripts/generate-swagger.js",
|
|
16
|
+
"build": "tsc",
|
|
17
|
+
"test": "node test-toolkit.js"
|
|
18
|
+
}
|
|
19
|
+
}
|