sa2kit 1.6.43 → 1.6.45
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/dist/AliyunOSSProvider-2FARPAQD.js +15 -0
- package/dist/{AliyunOSSProvider-HCNGDJL7.js.map → AliyunOSSProvider-2FARPAQD.js.map} +1 -1
- package/dist/AliyunOSSProvider-UMVGVBDJ.mjs +9 -0
- package/dist/{AliyunOSSProvider-4W47OFEK.mjs.map → AliyunOSSProvider-UMVGVBDJ.mjs.map} +1 -1
- package/dist/CollisionBalls-BpHufX3H.d.mts +41 -0
- package/dist/CollisionBalls-BpHufX3H.d.ts +41 -0
- package/dist/ConfigService-QR67WYNK.mjs +4 -0
- package/dist/{ConfigService-V6ZK273Z.mjs.map → ConfigService-QR67WYNK.mjs.map} +1 -1
- package/dist/{ConfigService-3DIC6C3Q.js → ConfigService-UYC6ZTCM.js} +3 -3
- package/dist/{ConfigService-3DIC6C3Q.js.map → ConfigService-UYC6ZTCM.js.map} +1 -1
- package/dist/GenericOrderManager-e4WizpNf.d.mts +28 -0
- package/dist/GenericOrderManager-e4WizpNf.d.ts +28 -0
- package/dist/LocalStorageProvider-JQF5WK5H.js +15 -0
- package/dist/{LocalStorageProvider-PP7MA5OT.js.map → LocalStorageProvider-JQF5WK5H.js.map} +1 -1
- package/dist/LocalStorageProvider-PYOHETJV.mjs +9 -0
- package/dist/{LocalStorageProvider-3RVPCQB3.mjs.map → LocalStorageProvider-PYOHETJV.mjs.map} +1 -1
- package/dist/PMXParser-RLBDO7YK.mjs +4 -0
- package/dist/{PMXParser-RNVQL76A.mjs.map → PMXParser-RLBDO7YK.mjs.map} +1 -1
- package/dist/{PMXParser-2VTA737I.js → PMXParser-XHNO2KNI.js} +3 -3
- package/dist/{PMXParser-2VTA737I.js.map → PMXParser-XHNO2KNI.js.map} +1 -1
- package/dist/UniversalFileService-RBV6EN5J.js +15 -0
- package/dist/UniversalFileService-RBV6EN5J.js.map +1 -0
- package/dist/UniversalFileService-TNYKO6JN.mjs +9 -0
- package/dist/UniversalFileService-TNYKO6JN.mjs.map +1 -0
- package/dist/analytics/index.js +1 -1
- package/dist/analytics/index.mjs +1 -1
- package/dist/analytics/server/index.js +1 -1
- package/dist/analytics/server/index.mjs +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.mjs +1 -1
- package/dist/audioDetection/index.js +1 -1
- package/dist/audioDetection/index.mjs +1 -1
- package/dist/auth/client/index.js +1 -1
- package/dist/auth/client/index.mjs +1 -1
- package/dist/auth/components/index.js +1 -1
- package/dist/auth/components/index.mjs +1 -1
- package/dist/auth/hooks/index.js +1 -1
- package/dist/auth/hooks/index.mjs +1 -1
- package/dist/auth/index.js +1 -1
- package/dist/auth/index.mjs +1 -1
- package/dist/auth/middleware/index.js +1 -1
- package/dist/auth/middleware/index.mjs +1 -1
- package/dist/auth/routes/index.js +1 -1
- package/dist/auth/routes/index.mjs +1 -1
- package/dist/auth/schema/index.js +1 -1
- package/dist/auth/schema/index.mjs +1 -1
- package/dist/auth/services/index.js +1 -1
- package/dist/auth/services/index.mjs +1 -1
- package/dist/calendar/index.js +12 -12
- package/dist/calendar/index.mjs +5 -5
- package/dist/calendar/routes/index.js +1 -1
- package/dist/calendar/routes/index.mjs +1 -1
- package/dist/calendar/server.js +1 -1
- package/dist/calendar/server.mjs +1 -1
- package/dist/chunk-2PS5PIXV.mjs +443 -0
- package/dist/chunk-2PS5PIXV.mjs.map +1 -0
- package/dist/chunk-35CXIK5Y.js +277 -0
- package/dist/chunk-35CXIK5Y.js.map +1 -0
- package/dist/{chunk-GMIUSZXC.mjs → chunk-3JW4X3AC.mjs} +3 -3
- package/dist/{chunk-GMIUSZXC.mjs.map → chunk-3JW4X3AC.mjs.map} +1 -1
- package/dist/chunk-3M6T5KVD.js +453 -0
- package/dist/chunk-3M6T5KVD.js.map +1 -0
- package/dist/chunk-3TNR6IMC.js +168 -0
- package/dist/chunk-3TNR6IMC.js.map +1 -0
- package/dist/chunk-4NFOSCM6.js +34 -0
- package/dist/chunk-4NFOSCM6.js.map +1 -0
- package/dist/{chunk-3NHAT7D4.mjs → chunk-4VJQZSPU.mjs} +4 -3
- package/dist/chunk-4VJQZSPU.mjs.map +1 -0
- package/dist/{chunk-SCDDMIF6.js → chunk-4XXIBWCO.js} +66 -66
- package/dist/{chunk-SCDDMIF6.js.map → chunk-4XXIBWCO.js.map} +1 -1
- package/dist/chunk-6AHYPPUP.js +344 -0
- package/dist/chunk-6AHYPPUP.js.map +1 -0
- package/dist/{chunk-EGJPS7OL.mjs → chunk-6BJ76BYC.mjs} +3 -3
- package/dist/{chunk-EGJPS7OL.mjs.map → chunk-6BJ76BYC.mjs.map} +1 -1
- package/dist/chunk-76V7EKBX.mjs +796 -0
- package/dist/chunk-76V7EKBX.mjs.map +1 -0
- package/dist/chunk-ACLOJXXE.js +195 -0
- package/dist/chunk-ACLOJXXE.js.map +1 -0
- package/dist/chunk-AEXPAH7Z.mjs +32 -0
- package/dist/chunk-AEXPAH7Z.mjs.map +1 -0
- package/dist/chunk-CFGX3EKK.js +560 -0
- package/dist/chunk-CFGX3EKK.js.map +1 -0
- package/dist/{chunk-435LATLS.mjs → chunk-CX5GPCCO.mjs} +3 -4
- package/dist/chunk-CX5GPCCO.mjs.map +1 -0
- package/dist/chunk-D2HXMGXS.js +46 -0
- package/dist/chunk-D2HXMGXS.js.map +1 -0
- package/dist/chunk-DM2GUVUH.js +1201 -0
- package/dist/chunk-DM2GUVUH.js.map +1 -0
- package/dist/{chunk-ZWQJSZEY.js → chunk-DVENFCQY.js} +5 -4
- package/dist/chunk-DVENFCQY.js.map +1 -0
- package/dist/chunk-EONPKLEJ.mjs +163 -0
- package/dist/chunk-EONPKLEJ.mjs.map +1 -0
- package/dist/{chunk-L47ZOYHL.js → chunk-EUIXQPPU.js} +4 -4
- package/dist/{chunk-L47ZOYHL.js.map → chunk-EUIXQPPU.js.map} +1 -1
- package/dist/{chunk-33YOJBQB.js → chunk-JOSNXSA6.js} +3 -4
- package/dist/chunk-JOSNXSA6.js.map +1 -0
- package/dist/chunk-K7WNCB4V.mjs +554 -0
- package/dist/chunk-K7WNCB4V.mjs.map +1 -0
- package/dist/chunk-L4ZYBFB2.mjs +44 -0
- package/dist/chunk-L4ZYBFB2.mjs.map +1 -0
- package/dist/chunk-M4HGHTIC.js +820 -0
- package/dist/chunk-M4HGHTIC.js.map +1 -0
- package/dist/{chunk-HHVDOIPV.js → chunk-MZKATHB7.js} +4 -4
- package/dist/{chunk-HHVDOIPV.js.map → chunk-MZKATHB7.js.map} +1 -1
- package/dist/{chunk-UKT3PLON.mjs → chunk-NXQVTAOP.mjs} +3 -3
- package/dist/{chunk-UKT3PLON.mjs.map → chunk-NXQVTAOP.mjs.map} +1 -1
- package/dist/chunk-OBIPI4GU.mjs +266 -0
- package/dist/chunk-OBIPI4GU.mjs.map +1 -0
- package/dist/chunk-PAX4S7QM.mjs +94 -0
- package/dist/chunk-PAX4S7QM.mjs.map +1 -0
- package/dist/chunk-PXWDQFWV.mjs +192 -0
- package/dist/chunk-PXWDQFWV.mjs.map +1 -0
- package/dist/chunk-QROLPPXP.mjs +5797 -0
- package/dist/chunk-QROLPPXP.mjs.map +1 -0
- package/dist/chunk-TGNUEULF.mjs +1158 -0
- package/dist/chunk-TGNUEULF.mjs.map +1 -0
- package/dist/chunk-VBQFVXOW.mjs +2772 -0
- package/dist/chunk-VBQFVXOW.mjs.map +1 -0
- package/dist/chunk-VLZ5N6XZ.js +5888 -0
- package/dist/chunk-VLZ5N6XZ.js.map +1 -0
- package/dist/chunk-VTGPHE4Z.mjs +322 -0
- package/dist/chunk-VTGPHE4Z.mjs.map +1 -0
- package/dist/chunk-WMJKH4XE.mjs +30 -0
- package/dist/{chunk-BJTO5JO5.mjs.map → chunk-WMJKH4XE.mjs.map} +1 -1
- package/dist/chunk-XYQMAF7H.js +96 -0
- package/dist/chunk-XYQMAF7H.js.map +1 -0
- package/dist/chunk-Z3G3IXEF.js +2814 -0
- package/dist/chunk-Z3G3IXEF.js.map +1 -0
- package/dist/chunk-Z6ZWNWWR.js +35 -0
- package/dist/{chunk-DGUM43GV.js.map → chunk-Z6ZWNWWR.js.map} +1 -1
- package/dist/components/index.d.mts +378 -0
- package/dist/components/index.d.ts +378 -0
- package/dist/components/index.js +414 -0
- package/dist/components/index.js.map +1 -0
- package/dist/components/index.mjs +9 -0
- package/dist/components/index.mjs.map +1 -0
- package/dist/config/index.js +1 -1
- package/dist/config/index.mjs +1 -1
- package/dist/config/server/index.js +1 -1
- package/dist/config/server/index.mjs +1 -1
- package/dist/fileService-O3W6YXCI.mjs +4 -0
- package/dist/fileService-O3W6YXCI.mjs.map +1 -0
- package/dist/fileService-YUDIYOAS.js +13 -0
- package/dist/fileService-YUDIYOAS.js.map +1 -0
- package/dist/i18n/index.js +7 -7
- package/dist/i18n/index.mjs +1 -1
- package/dist/imageCrop/index.js +1 -1
- package/dist/imageCrop/index.mjs +1 -1
- package/dist/index.d.mts +9 -580
- package/dist/index.d.ts +9 -580
- package/dist/index.js +313 -972
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +104 -790
- package/dist/index.mjs.map +1 -1
- package/dist/logger/index.js +8 -8
- package/dist/logger/index.mjs +5 -2
- package/dist/mikuFireworks3D/index.js +17 -17
- package/dist/mikuFireworks3D/index.mjs +2 -2
- package/dist/mikuFireworks3D/server/index.js +1 -1
- package/dist/mikuFireworks3D/server/index.mjs +1 -1
- package/dist/mikuFusionGame/index.js +5 -5
- package/dist/mikuFusionGame/index.mjs +4 -4
- package/dist/mmd/admin/index.js +1 -1
- package/dist/mmd/admin/index.mjs +1 -1
- package/dist/mmd/index.js +2 -2
- package/dist/mmd/index.mjs +2 -2
- package/dist/mmd/server/index.js +1 -1
- package/dist/mmd/server/index.mjs +1 -1
- package/dist/music/index.js +1 -1
- package/dist/music/index.mjs +1 -1
- package/dist/music/server/index.js +1 -1
- package/dist/music/server/index.mjs +1 -1
- package/dist/navigation/index.d.mts +93 -0
- package/dist/navigation/index.d.ts +93 -0
- package/dist/navigation/index.js +29 -0
- package/dist/navigation/index.js.map +1 -0
- package/dist/navigation/index.mjs +4 -0
- package/dist/navigation/index.mjs.map +1 -0
- package/dist/popupConfig-BznThU1O.d.mts +330 -0
- package/dist/popupConfig-BznThU1O.d.ts +330 -0
- package/dist/portfolio/index.d.mts +57 -0
- package/dist/portfolio/index.d.ts +57 -0
- package/dist/portfolio/index.js +35 -0
- package/dist/portfolio/index.js.map +1 -0
- package/dist/portfolio/index.mjs +10 -0
- package/dist/portfolio/index.mjs.map +1 -0
- package/dist/request/index.js +1 -1
- package/dist/request/index.mjs +1 -1
- package/dist/showmasterpiece/index.d.mts +2524 -0
- package/dist/showmasterpiece/index.d.ts +2524 -0
- package/dist/showmasterpiece/index.js +9681 -0
- package/dist/showmasterpiece/index.js.map +1 -0
- package/dist/showmasterpiece/index.mjs +9631 -0
- package/dist/showmasterpiece/index.mjs.map +1 -0
- package/dist/showmasterpiece/migration/index.d.mts +120 -0
- package/dist/showmasterpiece/migration/index.d.ts +120 -0
- package/dist/showmasterpiece/migration/index.js +595 -0
- package/dist/showmasterpiece/migration/index.js.map +1 -0
- package/dist/showmasterpiece/migration/index.mjs +589 -0
- package/dist/showmasterpiece/migration/index.mjs.map +1 -0
- package/dist/showmasterpiece/scripts/index.d.mts +28 -0
- package/dist/showmasterpiece/scripts/index.d.ts +28 -0
- package/dist/showmasterpiece/scripts/index.js +327 -0
- package/dist/showmasterpiece/scripts/index.js.map +1 -0
- package/dist/showmasterpiece/scripts/index.mjs +325 -0
- package/dist/showmasterpiece/scripts/index.mjs.map +1 -0
- package/dist/showmasterpiece/server/index.d.mts +2698 -0
- package/dist/showmasterpiece/server/index.d.ts +2698 -0
- package/dist/showmasterpiece/server/index.js +179 -0
- package/dist/showmasterpiece/server/index.js.map +1 -0
- package/dist/showmasterpiece/server/index.mjs +6 -0
- package/dist/showmasterpiece/server/index.mjs.map +1 -0
- package/dist/storage/index.js +8 -8
- package/dist/storage/index.mjs +2 -2
- package/dist/testYourself/admin/index.js +1 -1
- package/dist/testYourself/admin/index.mjs +1 -1
- package/dist/testYourself/index.js +2 -2
- package/dist/testYourself/index.mjs +2 -2
- package/dist/testYourself/server/index.js +1 -1
- package/dist/testYourself/server/index.mjs +1 -1
- package/dist/universalExport/index.js +154 -1195
- package/dist/universalExport/index.js.map +1 -1
- package/dist/universalExport/index.mjs +2 -1157
- package/dist/universalExport/index.mjs.map +1 -1
- package/dist/universalExport/server/index.js +5 -3
- package/dist/universalExport/server/index.js.map +1 -1
- package/dist/universalExport/server/index.mjs +4 -2
- package/dist/universalExport/server/index.mjs.map +1 -1
- package/dist/universalFile/index.js +10 -7
- package/dist/universalFile/index.js.map +1 -1
- package/dist/universalFile/index.mjs +6 -2
- package/dist/universalFile/index.mjs.map +1 -1
- package/dist/universalFile/server/index.d.mts +592 -265
- package/dist/universalFile/server/index.d.ts +592 -265
- package/dist/universalFile/server/index.js +298 -5637
- package/dist/universalFile/server/index.js.map +1 -1
- package/dist/universalFile/server/index.mjs +8 -5559
- package/dist/universalFile/server/index.mjs.map +1 -1
- package/dist/utils/index.js +12 -12
- package/dist/utils/index.mjs +3 -3
- package/package.json +36 -1
- package/dist/AliyunOSSProvider-4W47OFEK.mjs +0 -6
- package/dist/AliyunOSSProvider-HCNGDJL7.js +0 -15
- package/dist/ConfigService-V6ZK273Z.mjs +0 -4
- package/dist/LocalStorageProvider-3RVPCQB3.mjs +0 -6
- package/dist/LocalStorageProvider-PP7MA5OT.js +0 -15
- package/dist/PMXParser-RNVQL76A.mjs +0 -4
- package/dist/chunk-25OFOKNF.js +0 -171
- package/dist/chunk-25OFOKNF.js.map +0 -1
- package/dist/chunk-33YOJBQB.js.map +0 -1
- package/dist/chunk-3DXPQ4YV.mjs +0 -165
- package/dist/chunk-3DXPQ4YV.mjs.map +0 -1
- package/dist/chunk-3NHAT7D4.mjs.map +0 -1
- package/dist/chunk-435LATLS.mjs.map +0 -1
- package/dist/chunk-BJTO5JO5.mjs +0 -10
- package/dist/chunk-CIVO4R6N.mjs +0 -37
- package/dist/chunk-CIVO4R6N.mjs.map +0 -1
- package/dist/chunk-DGUM43GV.js +0 -12
- package/dist/chunk-HDMIOOZY.mjs +0 -546
- package/dist/chunk-HDMIOOZY.mjs.map +0 -1
- package/dist/chunk-HJ6MH7J7.js +0 -552
- package/dist/chunk-HJ6MH7J7.js.map +0 -1
- package/dist/chunk-KH6RQ4J5.js +0 -28
- package/dist/chunk-KH6RQ4J5.js.map +0 -1
- package/dist/chunk-Q5EDCKQA.js +0 -336
- package/dist/chunk-Q5EDCKQA.js.map +0 -1
- package/dist/chunk-YOTQG4NP.mjs +0 -314
- package/dist/chunk-YOTQG4NP.mjs.map +0 -1
- package/dist/chunk-ZGVB35L2.mjs +0 -25
- package/dist/chunk-ZGVB35L2.mjs.map +0 -1
- package/dist/chunk-ZRAW3HXA.js +0 -43
- package/dist/chunk-ZRAW3HXA.js.map +0 -1
- package/dist/chunk-ZWQJSZEY.js.map +0 -1
|
@@ -0,0 +1,1158 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect } from 'react';
|
|
2
|
+
import { clsx } from 'clsx';
|
|
3
|
+
import { Settings, X, Eye, EyeOff, MoveUp, MoveDown, Trash2, Group, Save, Loader2, Download, ChevronDown, Type, Database, FileText, FileSpreadsheet } from 'lucide-react';
|
|
4
|
+
|
|
5
|
+
// src/universalExport/constants.ts
|
|
6
|
+
var UNIVERSAL_EXPORT_VERSION = "1.0.0";
|
|
7
|
+
var UNIVERSAL_EXPORT_NAME = "@lyricnote/universal-export";
|
|
8
|
+
var DEFAULT_EXPORT_FORMAT = "csv";
|
|
9
|
+
var DEFAULT_CSV_DELIMITER = ",";
|
|
10
|
+
var DEFAULT_ENCODING = "utf-8";
|
|
11
|
+
var DEFAULT_ADD_BOM = true;
|
|
12
|
+
var DEFAULT_MAX_FILE_SIZE = 100 * 1024 * 1024;
|
|
13
|
+
var DEFAULT_MAX_ROWS = 1e5;
|
|
14
|
+
var DEFAULT_MAX_CONCURRENT_EXPORTS = 5;
|
|
15
|
+
var DEFAULT_EXPORT_TIMEOUT = 3e5;
|
|
16
|
+
var DEFAULT_CONFIG_CACHE_TTL = 3600;
|
|
17
|
+
var DEFAULT_RESULT_CACHE_TTL = 1800;
|
|
18
|
+
var EXPORT_FORMAT_EXTENSIONS = {
|
|
19
|
+
csv: "csv",
|
|
20
|
+
excel: "xlsx",
|
|
21
|
+
json: "json"
|
|
22
|
+
};
|
|
23
|
+
var EXPORT_FORMAT_MIME_TYPES = {
|
|
24
|
+
csv: "text/csv; charset=utf-8",
|
|
25
|
+
excel: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
|
|
26
|
+
json: "application/json; charset=utf-8"
|
|
27
|
+
};
|
|
28
|
+
var API_BASE_PATH = "/api/universal-export";
|
|
29
|
+
var API_ENDPOINTS = {
|
|
30
|
+
/** 获取配置列表 */
|
|
31
|
+
GET_CONFIGS: API_BASE_PATH + "/configs",
|
|
32
|
+
/** 创建配置 */
|
|
33
|
+
CREATE_CONFIG: API_BASE_PATH + "/configs",
|
|
34
|
+
/** 更新配置 */
|
|
35
|
+
UPDATE_CONFIG: (configId) => API_BASE_PATH + "/configs/" + configId,
|
|
36
|
+
/** 删除配置 */
|
|
37
|
+
DELETE_CONFIG: (configId) => API_BASE_PATH + "/configs/" + configId,
|
|
38
|
+
/** 触发导出 */
|
|
39
|
+
EXPORT_DATA: API_BASE_PATH + "/export",
|
|
40
|
+
/** 查询导出进度 */
|
|
41
|
+
GET_PROGRESS: (exportId) => API_BASE_PATH + "/export/" + exportId + "/progress",
|
|
42
|
+
/** 下载导出文件 */
|
|
43
|
+
DOWNLOAD_FILE: (exportId) => API_BASE_PATH + "/export/" + exportId + "/download"
|
|
44
|
+
};
|
|
45
|
+
var ERROR_CODES = {
|
|
46
|
+
/** 导出配置错误 */
|
|
47
|
+
EXPORT_CONFIG_ERROR: "EXPORT_CONFIG_ERROR",
|
|
48
|
+
/** 导出数据错误 */
|
|
49
|
+
EXPORT_DATA_ERROR: "EXPORT_DATA_ERROR",
|
|
50
|
+
/** 导出文件错误 */
|
|
51
|
+
EXPORT_FILE_ERROR: "EXPORT_FILE_ERROR",
|
|
52
|
+
/** 网络错误 */
|
|
53
|
+
NETWORK_ERROR: "NETWORK_ERROR",
|
|
54
|
+
/** 超时错误 */
|
|
55
|
+
TIMEOUT_ERROR: "TIMEOUT_ERROR",
|
|
56
|
+
/** 未授权 */
|
|
57
|
+
UNAUTHORIZED: "UNAUTHORIZED",
|
|
58
|
+
/** 服务器错误 */
|
|
59
|
+
SERVER_ERROR: "SERVER_ERROR"
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// src/universalExport/utils.ts
|
|
63
|
+
function generateExportFileName(template, format) {
|
|
64
|
+
const now = /* @__PURE__ */ new Date();
|
|
65
|
+
const dateStr = now.toISOString().split("T")[0] || "";
|
|
66
|
+
const timeStr = (now.toTimeString().split(" ")[0] || "").replace(/:/g, "-");
|
|
67
|
+
const extension = EXPORT_FORMAT_EXTENSIONS[format];
|
|
68
|
+
return template.replace("{date}", dateStr).replace("{time}", timeStr).replace("{timestamp}", now.getTime().toString()) + "." + extension;
|
|
69
|
+
}
|
|
70
|
+
function validateFileName(fileName) {
|
|
71
|
+
const invalidChars = /[<>:"|?*\/\\]/;
|
|
72
|
+
if (invalidChars.test(fileName)) {
|
|
73
|
+
return false;
|
|
74
|
+
}
|
|
75
|
+
if (fileName.length === 0 || fileName.length > 255) {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
return true;
|
|
79
|
+
}
|
|
80
|
+
function sanitizeFileName(fileName) {
|
|
81
|
+
return fileName.replace(/[<>:"|?*\/\\]/g, "_").substring(0, 255);
|
|
82
|
+
}
|
|
83
|
+
function escapeCSVField(value, delimiter = ",") {
|
|
84
|
+
const valueStr = String(value || "");
|
|
85
|
+
if (valueStr.includes(delimiter) || valueStr.includes('"') || valueStr.includes("\n")) {
|
|
86
|
+
return '"' + valueStr.replace(/"/g, '""') + '"';
|
|
87
|
+
}
|
|
88
|
+
return valueStr;
|
|
89
|
+
}
|
|
90
|
+
function parseCSVField(field) {
|
|
91
|
+
if (field.startsWith('"') && field.endsWith('"')) {
|
|
92
|
+
return field.slice(1, -1).replace(/""/g, '"');
|
|
93
|
+
}
|
|
94
|
+
return field;
|
|
95
|
+
}
|
|
96
|
+
var DEFAULT_FORMATTERS = {
|
|
97
|
+
// 日期格式化
|
|
98
|
+
date: (value) => {
|
|
99
|
+
if (!value) return "";
|
|
100
|
+
const date = new Date(value);
|
|
101
|
+
if (isNaN(date.getTime())) return String(value);
|
|
102
|
+
return date.toISOString().split("T")[0] || "";
|
|
103
|
+
},
|
|
104
|
+
// 时间格式化
|
|
105
|
+
datetime: (value) => {
|
|
106
|
+
if (!value) return "";
|
|
107
|
+
const date = new Date(value);
|
|
108
|
+
if (isNaN(date.getTime())) return String(value);
|
|
109
|
+
return date.toLocaleString("zh-CN");
|
|
110
|
+
},
|
|
111
|
+
// 数字格式化
|
|
112
|
+
number: (value) => {
|
|
113
|
+
if (value === null || value === void 0) return "";
|
|
114
|
+
return String(value);
|
|
115
|
+
},
|
|
116
|
+
// 货币格式化
|
|
117
|
+
currency: (value) => {
|
|
118
|
+
if (value === null || value === void 0) return "";
|
|
119
|
+
return "\xA5" + Number(value).toFixed(2);
|
|
120
|
+
},
|
|
121
|
+
// 百分比格式化
|
|
122
|
+
percentage: (value) => {
|
|
123
|
+
if (value === null || value === void 0) return "";
|
|
124
|
+
return (Number(value) * 100).toFixed(2) + "%";
|
|
125
|
+
},
|
|
126
|
+
// 布尔值格式化
|
|
127
|
+
boolean: (value) => {
|
|
128
|
+
if (value === null || value === void 0) return "";
|
|
129
|
+
return value ? "\u662F" : "\u5426";
|
|
130
|
+
},
|
|
131
|
+
// 数组格式化
|
|
132
|
+
array: (value) => {
|
|
133
|
+
if (!Array.isArray(value)) return "";
|
|
134
|
+
return value.join(", ");
|
|
135
|
+
},
|
|
136
|
+
// 对象格式化
|
|
137
|
+
object: (value) => {
|
|
138
|
+
if (!value || typeof value !== "object") return "";
|
|
139
|
+
return JSON.stringify(value);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
function applyFormatter(value, formatter, type) {
|
|
143
|
+
if (formatter) {
|
|
144
|
+
return formatter(value);
|
|
145
|
+
}
|
|
146
|
+
if (type && DEFAULT_FORMATTERS[type]) {
|
|
147
|
+
return DEFAULT_FORMATTERS[type](value);
|
|
148
|
+
}
|
|
149
|
+
return String(value || "");
|
|
150
|
+
}
|
|
151
|
+
function validateExportConfig(config) {
|
|
152
|
+
const errors = [];
|
|
153
|
+
if (!config.name || config.name.trim() === "") {
|
|
154
|
+
errors.push("\u914D\u7F6E\u540D\u79F0\u4E0D\u80FD\u4E3A\u7A7A");
|
|
155
|
+
}
|
|
156
|
+
if (!config.fields || !Array.isArray(config.fields) || config.fields.length === 0) {
|
|
157
|
+
errors.push("\u81F3\u5C11\u9700\u8981\u5B9A\u4E49\u4E00\u4E2A\u5B57\u6BB5");
|
|
158
|
+
}
|
|
159
|
+
if (config.fields) {
|
|
160
|
+
const enabledFields = config.fields.filter((f) => f.enabled);
|
|
161
|
+
if (enabledFields.length === 0) {
|
|
162
|
+
errors.push("\u81F3\u5C11\u9700\u8981\u542F\u7528\u4E00\u4E2A\u5B57\u6BB5");
|
|
163
|
+
}
|
|
164
|
+
const keys = config.fields.map((f) => f.key);
|
|
165
|
+
const uniqueKeys = new Set(keys);
|
|
166
|
+
if (keys.length !== uniqueKeys.size) {
|
|
167
|
+
errors.push("\u5B57\u6BB5\u952E\u540D\u5FC5\u987B\u552F\u4E00");
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return {
|
|
171
|
+
valid: errors.length === 0,
|
|
172
|
+
errors
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function validateExportRequest(request) {
|
|
176
|
+
const errors = [];
|
|
177
|
+
if (!request.configId) {
|
|
178
|
+
errors.push("\u5BFC\u51FA\u914D\u7F6EID\u4E0D\u80FD\u4E3A\u7A7A");
|
|
179
|
+
}
|
|
180
|
+
if (!request.dataSource) {
|
|
181
|
+
errors.push("\u6570\u636E\u6E90\u4E0D\u80FD\u4E3A\u7A7A");
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
valid: errors.length === 0,
|
|
185
|
+
errors
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function formatFileSize(bytes) {
|
|
189
|
+
if (bytes === 0) return "0 B";
|
|
190
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
191
|
+
const k = 1024;
|
|
192
|
+
const i = Math.floor(Math.log(bytes) / Math.log(k));
|
|
193
|
+
return (bytes / Math.pow(k, i)).toFixed(2) + " " + units[i];
|
|
194
|
+
}
|
|
195
|
+
function formatDuration(milliseconds) {
|
|
196
|
+
if (milliseconds < 1e3) {
|
|
197
|
+
return milliseconds + "ms";
|
|
198
|
+
}
|
|
199
|
+
const seconds = Math.floor(milliseconds / 1e3);
|
|
200
|
+
if (seconds < 60) {
|
|
201
|
+
return seconds + "\u79D2";
|
|
202
|
+
}
|
|
203
|
+
const minutes = Math.floor(seconds / 60);
|
|
204
|
+
const remainingSeconds = seconds % 60;
|
|
205
|
+
if (minutes < 60) {
|
|
206
|
+
return remainingSeconds > 0 ? minutes + "\u5206" + remainingSeconds + "\u79D2" : minutes + "\u5206\u949F";
|
|
207
|
+
}
|
|
208
|
+
const hours = Math.floor(minutes / 60);
|
|
209
|
+
const remainingMinutes = minutes % 60;
|
|
210
|
+
return remainingMinutes > 0 ? hours + "\u5C0F\u65F6" + remainingMinutes + "\u5206\u949F" : hours + "\u5C0F\u65F6";
|
|
211
|
+
}
|
|
212
|
+
function estimateEndTime(startTime, processedRows, totalRows) {
|
|
213
|
+
if (processedRows === 0 || totalRows === 0) {
|
|
214
|
+
return void 0;
|
|
215
|
+
}
|
|
216
|
+
const elapsed = Date.now() - startTime.getTime();
|
|
217
|
+
const avgTimePerRow = elapsed / processedRows;
|
|
218
|
+
const remainingRows = totalRows - processedRows;
|
|
219
|
+
const remainingTime = avgTimePerRow * remainingRows;
|
|
220
|
+
return new Date(Date.now() + remainingTime);
|
|
221
|
+
}
|
|
222
|
+
function getNestedValue(obj, path) {
|
|
223
|
+
return path.split(".").reduce((current, key) => {
|
|
224
|
+
return current && current[key] !== void 0 ? current[key] : null;
|
|
225
|
+
}, obj);
|
|
226
|
+
}
|
|
227
|
+
function setNestedValue(obj, path, value) {
|
|
228
|
+
const keys = path.split(".");
|
|
229
|
+
const lastKey = keys.pop();
|
|
230
|
+
if (!lastKey) return;
|
|
231
|
+
const target = keys.reduce((current, key) => {
|
|
232
|
+
if (!current[key] || typeof current[key] !== "object") {
|
|
233
|
+
current[key] = {};
|
|
234
|
+
}
|
|
235
|
+
return current[key];
|
|
236
|
+
}, obj);
|
|
237
|
+
target[lastKey] = value;
|
|
238
|
+
}
|
|
239
|
+
function createExportError(code, message, details) {
|
|
240
|
+
return {
|
|
241
|
+
code,
|
|
242
|
+
message,
|
|
243
|
+
details,
|
|
244
|
+
timestamp: /* @__PURE__ */ new Date()
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function formatErrorMessage(error) {
|
|
248
|
+
if (error instanceof Error) {
|
|
249
|
+
return error.message;
|
|
250
|
+
}
|
|
251
|
+
if (typeof error === "string") {
|
|
252
|
+
return error;
|
|
253
|
+
}
|
|
254
|
+
return "\u672A\u77E5\u9519\u8BEF";
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
// src/universalExport/client.ts
|
|
258
|
+
var UniversalExportClient = class {
|
|
259
|
+
constructor(config = {}) {
|
|
260
|
+
this.config = {
|
|
261
|
+
baseUrl: config.baseUrl || "",
|
|
262
|
+
timeout: config.timeout || 3e4,
|
|
263
|
+
headers: config.headers || {}
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
// ============= 配置管理API =============
|
|
267
|
+
/**
|
|
268
|
+
* 获取模块的导出配置列表
|
|
269
|
+
*/
|
|
270
|
+
async getConfigsByModule(moduleId, businessId) {
|
|
271
|
+
const params = new URLSearchParams({ moduleId });
|
|
272
|
+
if (businessId) {
|
|
273
|
+
params.append("businessId", businessId);
|
|
274
|
+
}
|
|
275
|
+
const url = this.config.baseUrl + API_ENDPOINTS.GET_CONFIGS + "?" + params;
|
|
276
|
+
try {
|
|
277
|
+
const response = await this.fetchWithTimeout(url, {
|
|
278
|
+
method: "GET",
|
|
279
|
+
headers: this.getHeaders()
|
|
280
|
+
});
|
|
281
|
+
if (!response.ok) {
|
|
282
|
+
throw new Error("\u83B7\u53D6\u914D\u7F6E\u5931\u8D25: " + response.statusText);
|
|
283
|
+
}
|
|
284
|
+
const data = await response.json();
|
|
285
|
+
return this.transformConfigsFromAPI(data.configs || []);
|
|
286
|
+
} catch (error) {
|
|
287
|
+
throw createExportError(
|
|
288
|
+
ERROR_CODES.NETWORK_ERROR,
|
|
289
|
+
"\u83B7\u53D6\u5BFC\u51FA\u914D\u7F6E\u5931\u8D25: " + formatErrorMessage(error),
|
|
290
|
+
{ moduleId, businessId, originalError: error }
|
|
291
|
+
);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
/**
|
|
295
|
+
* 创建导出配置
|
|
296
|
+
*/
|
|
297
|
+
async createConfig(config) {
|
|
298
|
+
const url = this.config.baseUrl + API_ENDPOINTS.CREATE_CONFIG;
|
|
299
|
+
try {
|
|
300
|
+
const response = await this.fetchWithTimeout(url, {
|
|
301
|
+
method: "POST",
|
|
302
|
+
headers: {
|
|
303
|
+
...this.getHeaders(),
|
|
304
|
+
"Content-Type": "application/json"
|
|
305
|
+
},
|
|
306
|
+
body: JSON.stringify(config)
|
|
307
|
+
});
|
|
308
|
+
if (!response.ok) {
|
|
309
|
+
throw new Error("\u521B\u5EFA\u914D\u7F6E\u5931\u8D25: " + response.statusText);
|
|
310
|
+
}
|
|
311
|
+
const data = await response.json();
|
|
312
|
+
return this.transformConfigFromAPI(data.config);
|
|
313
|
+
} catch (error) {
|
|
314
|
+
throw createExportError(
|
|
315
|
+
ERROR_CODES.NETWORK_ERROR,
|
|
316
|
+
"\u521B\u5EFA\u5BFC\u51FA\u914D\u7F6E\u5931\u8D25: " + formatErrorMessage(error),
|
|
317
|
+
{ config, originalError: error }
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* 更新导出配置
|
|
323
|
+
*/
|
|
324
|
+
async updateConfig(configId, updates) {
|
|
325
|
+
const url = this.config.baseUrl + API_ENDPOINTS.UPDATE_CONFIG(configId);
|
|
326
|
+
try {
|
|
327
|
+
const response = await this.fetchWithTimeout(url, {
|
|
328
|
+
method: "PUT",
|
|
329
|
+
headers: {
|
|
330
|
+
...this.getHeaders(),
|
|
331
|
+
"Content-Type": "application/json"
|
|
332
|
+
},
|
|
333
|
+
body: JSON.stringify(updates)
|
|
334
|
+
});
|
|
335
|
+
if (!response.ok) {
|
|
336
|
+
throw new Error("\u66F4\u65B0\u914D\u7F6E\u5931\u8D25: " + response.statusText);
|
|
337
|
+
}
|
|
338
|
+
const data = await response.json();
|
|
339
|
+
return this.transformConfigFromAPI(data.config);
|
|
340
|
+
} catch (error) {
|
|
341
|
+
throw createExportError(
|
|
342
|
+
ERROR_CODES.NETWORK_ERROR,
|
|
343
|
+
"\u66F4\u65B0\u5BFC\u51FA\u914D\u7F6E\u5931\u8D25: " + formatErrorMessage(error),
|
|
344
|
+
{ configId, updates, originalError: error }
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* 删除导出配置
|
|
350
|
+
*/
|
|
351
|
+
async deleteConfig(configId) {
|
|
352
|
+
const url = this.config.baseUrl + API_ENDPOINTS.DELETE_CONFIG(configId);
|
|
353
|
+
try {
|
|
354
|
+
const response = await this.fetchWithTimeout(url, {
|
|
355
|
+
method: "DELETE",
|
|
356
|
+
headers: this.getHeaders()
|
|
357
|
+
});
|
|
358
|
+
if (!response.ok) {
|
|
359
|
+
throw new Error("\u5220\u9664\u914D\u7F6E\u5931\u8D25: " + response.statusText);
|
|
360
|
+
}
|
|
361
|
+
} catch (error) {
|
|
362
|
+
throw createExportError(
|
|
363
|
+
ERROR_CODES.NETWORK_ERROR,
|
|
364
|
+
"\u5220\u9664\u5BFC\u51FA\u914D\u7F6E\u5931\u8D25: " + formatErrorMessage(error),
|
|
365
|
+
{ configId, originalError: error }
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
// ============= 导出执行API =============
|
|
370
|
+
/**
|
|
371
|
+
* 触发数据导出
|
|
372
|
+
*/
|
|
373
|
+
async exportData(request) {
|
|
374
|
+
const url = this.config.baseUrl + API_ENDPOINTS.EXPORT_DATA;
|
|
375
|
+
try {
|
|
376
|
+
const isDataArray = Array.isArray(request.dataSource);
|
|
377
|
+
const requestBody = {
|
|
378
|
+
configId: request.configId,
|
|
379
|
+
queryParams: request.queryParams,
|
|
380
|
+
fieldMapping: request.fieldMapping,
|
|
381
|
+
filters: request.filters,
|
|
382
|
+
sortBy: request.sortBy,
|
|
383
|
+
pagination: request.pagination,
|
|
384
|
+
customFileName: request.customFileName
|
|
385
|
+
};
|
|
386
|
+
if (isDataArray) {
|
|
387
|
+
requestBody.data = request.dataSource;
|
|
388
|
+
} else {
|
|
389
|
+
requestBody.dataSource = request.dataSource;
|
|
390
|
+
}
|
|
391
|
+
const response = await this.fetchWithTimeout(url, {
|
|
392
|
+
method: "POST",
|
|
393
|
+
headers: {
|
|
394
|
+
...this.getHeaders(),
|
|
395
|
+
"Content-Type": "application/json"
|
|
396
|
+
},
|
|
397
|
+
body: JSON.stringify(requestBody)
|
|
398
|
+
});
|
|
399
|
+
if (!response.ok) {
|
|
400
|
+
const errorText = await response.text();
|
|
401
|
+
let errorData;
|
|
402
|
+
try {
|
|
403
|
+
errorData = JSON.parse(errorText);
|
|
404
|
+
} catch {
|
|
405
|
+
errorData = { message: errorText };
|
|
406
|
+
}
|
|
407
|
+
throw new Error(errorData.message || "\u5BFC\u51FA\u5931\u8D25: " + response.statusText);
|
|
408
|
+
}
|
|
409
|
+
const data = await response.json();
|
|
410
|
+
return this.transformExportResultFromAPI(data.result);
|
|
411
|
+
} catch (error) {
|
|
412
|
+
throw createExportError(
|
|
413
|
+
ERROR_CODES.EXPORT_DATA_ERROR,
|
|
414
|
+
"\u6570\u636E\u5BFC\u51FA\u5931\u8D25: " + formatErrorMessage(error),
|
|
415
|
+
{ request, originalError: error }
|
|
416
|
+
);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
/**
|
|
420
|
+
* 查询导出进度
|
|
421
|
+
*/
|
|
422
|
+
async getExportProgress(exportId) {
|
|
423
|
+
const url = this.config.baseUrl + API_ENDPOINTS.GET_PROGRESS(exportId);
|
|
424
|
+
try {
|
|
425
|
+
const response = await this.fetchWithTimeout(url, {
|
|
426
|
+
method: "GET",
|
|
427
|
+
headers: this.getHeaders()
|
|
428
|
+
});
|
|
429
|
+
if (!response.ok) {
|
|
430
|
+
throw new Error("\u83B7\u53D6\u5BFC\u51FA\u8FDB\u5EA6\u5931\u8D25: " + response.statusText);
|
|
431
|
+
}
|
|
432
|
+
const data = await response.json();
|
|
433
|
+
return this.transformProgressFromAPI(data.progress);
|
|
434
|
+
} catch (error) {
|
|
435
|
+
throw createExportError(
|
|
436
|
+
ERROR_CODES.NETWORK_ERROR,
|
|
437
|
+
"\u83B7\u53D6\u5BFC\u51FA\u8FDB\u5EA6\u5931\u8D25: " + formatErrorMessage(error),
|
|
438
|
+
{ exportId, originalError: error }
|
|
439
|
+
);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* 下载导出文件
|
|
444
|
+
*/
|
|
445
|
+
async downloadExportFile(exportId) {
|
|
446
|
+
const url = this.config.baseUrl + API_ENDPOINTS.DOWNLOAD_FILE(exportId);
|
|
447
|
+
try {
|
|
448
|
+
const response = await this.fetchWithTimeout(url, {
|
|
449
|
+
method: "GET",
|
|
450
|
+
headers: this.getHeaders()
|
|
451
|
+
});
|
|
452
|
+
if (!response.ok) {
|
|
453
|
+
throw new Error("\u4E0B\u8F7D\u6587\u4EF6\u5931\u8D25: " + response.statusText);
|
|
454
|
+
}
|
|
455
|
+
return await response.blob();
|
|
456
|
+
} catch (error) {
|
|
457
|
+
throw createExportError(
|
|
458
|
+
ERROR_CODES.NETWORK_ERROR,
|
|
459
|
+
"\u4E0B\u8F7D\u5BFC\u51FA\u6587\u4EF6\u5931\u8D25: " + formatErrorMessage(error),
|
|
460
|
+
{ exportId, originalError: error }
|
|
461
|
+
);
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
// ============= 私有辅助方法 =============
|
|
465
|
+
/**
|
|
466
|
+
* 获取请求头
|
|
467
|
+
*/
|
|
468
|
+
getHeaders() {
|
|
469
|
+
return {
|
|
470
|
+
...this.config.headers
|
|
471
|
+
};
|
|
472
|
+
}
|
|
473
|
+
/**
|
|
474
|
+
* 带超时的fetch请求
|
|
475
|
+
*/
|
|
476
|
+
async fetchWithTimeout(url, options) {
|
|
477
|
+
const controller = new AbortController();
|
|
478
|
+
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
479
|
+
try {
|
|
480
|
+
const response = await fetch(url, {
|
|
481
|
+
...options,
|
|
482
|
+
signal: controller.signal
|
|
483
|
+
});
|
|
484
|
+
return response;
|
|
485
|
+
} catch (error) {
|
|
486
|
+
if (error instanceof Error && error.name === "AbortError") {
|
|
487
|
+
throw createExportError(ERROR_CODES.TIMEOUT_ERROR, "\u8BF7\u6C42\u8D85\u65F6", {
|
|
488
|
+
url,
|
|
489
|
+
timeout: this.config.timeout
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
throw error;
|
|
493
|
+
} finally {
|
|
494
|
+
clearTimeout(timeoutId);
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* 转换API返回的配置数据
|
|
499
|
+
*/
|
|
500
|
+
transformConfigFromAPI(apiConfig) {
|
|
501
|
+
return {
|
|
502
|
+
id: apiConfig.id,
|
|
503
|
+
name: apiConfig.name,
|
|
504
|
+
description: apiConfig.description || void 0,
|
|
505
|
+
format: apiConfig.format,
|
|
506
|
+
fields: apiConfig.fields,
|
|
507
|
+
grouping: apiConfig.grouping,
|
|
508
|
+
fileNameTemplate: apiConfig.fileNameTemplate,
|
|
509
|
+
includeHeader: apiConfig.includeHeader,
|
|
510
|
+
delimiter: apiConfig.delimiter,
|
|
511
|
+
encoding: apiConfig.encoding,
|
|
512
|
+
addBOM: apiConfig.addBOM,
|
|
513
|
+
maxRows: apiConfig.maxRows || void 0,
|
|
514
|
+
createdAt: new Date(apiConfig.createdAt),
|
|
515
|
+
updatedAt: new Date(apiConfig.updatedAt),
|
|
516
|
+
moduleId: apiConfig.moduleId,
|
|
517
|
+
businessId: apiConfig.businessId || void 0,
|
|
518
|
+
createdBy: apiConfig.createdBy || void 0
|
|
519
|
+
};
|
|
520
|
+
}
|
|
521
|
+
/**
|
|
522
|
+
* 转换API返回的配置列表
|
|
523
|
+
*/
|
|
524
|
+
transformConfigsFromAPI(apiConfigs) {
|
|
525
|
+
return apiConfigs.map((config) => this.transformConfigFromAPI(config));
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* 转换API返回的导出结果
|
|
529
|
+
*/
|
|
530
|
+
transformExportResultFromAPI(apiResult) {
|
|
531
|
+
return {
|
|
532
|
+
exportId: apiResult.exportId,
|
|
533
|
+
fileName: apiResult.fileName,
|
|
534
|
+
fileSize: apiResult.fileSize,
|
|
535
|
+
fileUrl: apiResult.fileUrl,
|
|
536
|
+
exportedRows: apiResult.exportedRows,
|
|
537
|
+
startTime: new Date(apiResult.startTime),
|
|
538
|
+
endTime: new Date(apiResult.endTime),
|
|
539
|
+
duration: apiResult.duration,
|
|
540
|
+
statistics: apiResult.statistics
|
|
541
|
+
};
|
|
542
|
+
}
|
|
543
|
+
/**
|
|
544
|
+
* 转换API返回的进度数据
|
|
545
|
+
*/
|
|
546
|
+
transformProgressFromAPI(apiProgress) {
|
|
547
|
+
return {
|
|
548
|
+
exportId: apiProgress.exportId,
|
|
549
|
+
status: apiProgress.status,
|
|
550
|
+
progress: apiProgress.progress,
|
|
551
|
+
processedRows: apiProgress.processedRows,
|
|
552
|
+
totalRows: apiProgress.totalRows,
|
|
553
|
+
startTime: new Date(apiProgress.startTime),
|
|
554
|
+
estimatedEndTime: apiProgress.estimatedEndTime ? new Date(apiProgress.estimatedEndTime) : void 0,
|
|
555
|
+
currentData: apiProgress.currentData,
|
|
556
|
+
error: apiProgress.error
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
var universalExportClient = new UniversalExportClient();
|
|
561
|
+
function createExportClient(config) {
|
|
562
|
+
return new UniversalExportClient(config);
|
|
563
|
+
}
|
|
564
|
+
var FORMAT_ICONS = {
|
|
565
|
+
csv: /* @__PURE__ */ React.createElement(FileText, { className: "w-4 h-4" }),
|
|
566
|
+
excel: /* @__PURE__ */ React.createElement(FileSpreadsheet, { className: "w-4 h-4" }),
|
|
567
|
+
json: /* @__PURE__ */ React.createElement(Database, { className: "w-4 h-4" })
|
|
568
|
+
};
|
|
569
|
+
var FORMAT_DESCRIPTIONS = {
|
|
570
|
+
csv: "\u9017\u53F7\u5206\u9694\u503C\u6587\u4EF6\uFF0C\u517C\u5BB9\u6027\u6700\u597D",
|
|
571
|
+
excel: "Excel\u8868\u683C\u6587\u4EF6\uFF0C\u652F\u6301\u683C\u5F0F\u5316\u548C\u5355\u5143\u683C\u5408\u5E76",
|
|
572
|
+
json: "JSON\u6570\u636E\u6587\u4EF6\uFF0C\u9002\u5408\u5F00\u53D1\u8005\u4F7F\u7528"
|
|
573
|
+
};
|
|
574
|
+
var ExportConfigEditor = ({
|
|
575
|
+
initialConfig,
|
|
576
|
+
moduleId,
|
|
577
|
+
businessId,
|
|
578
|
+
availableFields,
|
|
579
|
+
onSave,
|
|
580
|
+
onCancel,
|
|
581
|
+
visible = false,
|
|
582
|
+
className = "",
|
|
583
|
+
onConfigChange
|
|
584
|
+
}) => {
|
|
585
|
+
const [config, setConfig] = useState(() => {
|
|
586
|
+
if (initialConfig) {
|
|
587
|
+
return { ...initialConfig };
|
|
588
|
+
}
|
|
589
|
+
return {
|
|
590
|
+
id: "",
|
|
591
|
+
name: "\u65B0\u5EFA\u5BFC\u51FA\u914D\u7F6E",
|
|
592
|
+
description: "",
|
|
593
|
+
format: "csv",
|
|
594
|
+
fields: availableFields.map((field, index) => ({
|
|
595
|
+
...field,
|
|
596
|
+
enabled: true,
|
|
597
|
+
sortOrder: index
|
|
598
|
+
})),
|
|
599
|
+
grouping: {
|
|
600
|
+
enabled: false,
|
|
601
|
+
fields: [],
|
|
602
|
+
preserveOrder: true,
|
|
603
|
+
nullValueHandling: "separate",
|
|
604
|
+
nullGroupName: "\u672A\u5206\u7EC4"
|
|
605
|
+
},
|
|
606
|
+
fileNameTemplate: "\u5BFC\u51FA\u6570\u636E_{date}",
|
|
607
|
+
includeHeader: true,
|
|
608
|
+
delimiter: ",",
|
|
609
|
+
encoding: "utf-8",
|
|
610
|
+
addBOM: true,
|
|
611
|
+
maxRows: void 0,
|
|
612
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
613
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
614
|
+
moduleId,
|
|
615
|
+
businessId
|
|
616
|
+
};
|
|
617
|
+
});
|
|
618
|
+
const [activeTab, setActiveTab] = useState("basic");
|
|
619
|
+
const [savedConfigs, setSavedConfigs] = useState([]);
|
|
620
|
+
const [loadingConfigs, setLoadingConfigs] = useState(false);
|
|
621
|
+
const [deletingConfigId, setDeletingConfigId] = useState(null);
|
|
622
|
+
const loadSavedConfigs = useCallback(async () => {
|
|
623
|
+
if (!visible || activeTab !== "manage") return;
|
|
624
|
+
setLoadingConfigs(true);
|
|
625
|
+
try {
|
|
626
|
+
const params = new URLSearchParams({ moduleId });
|
|
627
|
+
if (businessId) {
|
|
628
|
+
params.set("businessId", businessId);
|
|
629
|
+
}
|
|
630
|
+
const response = await fetch("/api/universal-export/configs?" + params.toString());
|
|
631
|
+
if (response.ok) {
|
|
632
|
+
const data = await response.json();
|
|
633
|
+
setSavedConfigs(data.configs || []);
|
|
634
|
+
}
|
|
635
|
+
} catch (error) {
|
|
636
|
+
console.error("\u52A0\u8F7D\u914D\u7F6E\u5F02\u5E38:", error);
|
|
637
|
+
} finally {
|
|
638
|
+
setLoadingConfigs(false);
|
|
639
|
+
}
|
|
640
|
+
}, [visible, activeTab, moduleId, businessId]);
|
|
641
|
+
const deleteConfig = useCallback(async (configId) => {
|
|
642
|
+
setDeletingConfigId(configId);
|
|
643
|
+
try {
|
|
644
|
+
const response = await fetch("/api/universal-export/configs/" + configId, {
|
|
645
|
+
method: "DELETE"
|
|
646
|
+
});
|
|
647
|
+
if (response.ok) {
|
|
648
|
+
setSavedConfigs((prev) => prev.filter((cfg) => cfg.id !== configId));
|
|
649
|
+
onConfigChange?.();
|
|
650
|
+
}
|
|
651
|
+
} catch (error) {
|
|
652
|
+
console.error("\u5220\u9664\u914D\u7F6E\u5931\u8D25:", error);
|
|
653
|
+
} finally {
|
|
654
|
+
setDeletingConfigId(null);
|
|
655
|
+
}
|
|
656
|
+
}, [onConfigChange]);
|
|
657
|
+
const loadConfigToEditor = useCallback((config2) => {
|
|
658
|
+
setConfig(config2);
|
|
659
|
+
setActiveTab("basic");
|
|
660
|
+
}, []);
|
|
661
|
+
useEffect(() => {
|
|
662
|
+
if (activeTab === "manage") {
|
|
663
|
+
loadSavedConfigs();
|
|
664
|
+
}
|
|
665
|
+
}, [activeTab, loadSavedConfigs]);
|
|
666
|
+
useEffect(() => {
|
|
667
|
+
if (!visible) return;
|
|
668
|
+
const scrollY = window.scrollY;
|
|
669
|
+
document.body.style.position = "fixed";
|
|
670
|
+
document.body.style.top = "-" + scrollY + "px";
|
|
671
|
+
document.body.style.left = "0";
|
|
672
|
+
document.body.style.right = "0";
|
|
673
|
+
document.body.style.overflow = "hidden";
|
|
674
|
+
const handleKeyDown = (e) => {
|
|
675
|
+
if (e.key === "Escape") {
|
|
676
|
+
onCancel?.();
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
680
|
+
return () => {
|
|
681
|
+
document.body.style.position = "";
|
|
682
|
+
document.body.style.top = "";
|
|
683
|
+
document.body.style.left = "";
|
|
684
|
+
document.body.style.right = "";
|
|
685
|
+
document.body.style.overflow = "";
|
|
686
|
+
window.scrollTo(0, scrollY);
|
|
687
|
+
document.removeEventListener("keydown", handleKeyDown);
|
|
688
|
+
};
|
|
689
|
+
}, [visible, onCancel]);
|
|
690
|
+
const toggleFieldEnabled = useCallback((fieldKey) => {
|
|
691
|
+
setConfig((prev) => ({
|
|
692
|
+
...prev,
|
|
693
|
+
fields: prev.fields.map(
|
|
694
|
+
(field) => field.key === fieldKey ? { ...field, enabled: !field.enabled } : field
|
|
695
|
+
)
|
|
696
|
+
}));
|
|
697
|
+
}, []);
|
|
698
|
+
useCallback((fieldKey, updates) => {
|
|
699
|
+
setConfig((prev) => ({
|
|
700
|
+
...prev,
|
|
701
|
+
fields: prev.fields.map(
|
|
702
|
+
(field) => field.key === fieldKey ? { ...field, ...updates } : field
|
|
703
|
+
)
|
|
704
|
+
}));
|
|
705
|
+
}, []);
|
|
706
|
+
const moveField = useCallback((fieldKey, direction) => {
|
|
707
|
+
setConfig((prev) => {
|
|
708
|
+
const fields = [...prev.fields];
|
|
709
|
+
const index = fields.findIndex((f) => f.key === fieldKey);
|
|
710
|
+
if (direction === "up" && index > 0) {
|
|
711
|
+
const temp = fields[index - 1];
|
|
712
|
+
fields[index - 1] = fields[index];
|
|
713
|
+
fields[index] = temp;
|
|
714
|
+
} else if (direction === "down" && index < fields.length - 1) {
|
|
715
|
+
const temp = fields[index + 1];
|
|
716
|
+
fields[index + 1] = fields[index];
|
|
717
|
+
fields[index] = temp;
|
|
718
|
+
}
|
|
719
|
+
return {
|
|
720
|
+
...prev,
|
|
721
|
+
fields: fields.map((field, idx) => ({ ...field, sortOrder: idx }))
|
|
722
|
+
};
|
|
723
|
+
});
|
|
724
|
+
}, []);
|
|
725
|
+
const removeField = useCallback((fieldKey) => {
|
|
726
|
+
setConfig((prev) => ({
|
|
727
|
+
...prev,
|
|
728
|
+
fields: prev.fields.filter((f) => f.key !== fieldKey)
|
|
729
|
+
}));
|
|
730
|
+
}, []);
|
|
731
|
+
const toggleGrouping = useCallback((enabled) => {
|
|
732
|
+
setConfig((prev) => ({
|
|
733
|
+
...prev,
|
|
734
|
+
grouping: {
|
|
735
|
+
...prev.grouping,
|
|
736
|
+
enabled
|
|
737
|
+
}
|
|
738
|
+
}));
|
|
739
|
+
}, []);
|
|
740
|
+
const addGroupingField = useCallback((fieldKey) => {
|
|
741
|
+
const field = config.fields.find((f) => f.key === fieldKey);
|
|
742
|
+
if (!field) return;
|
|
743
|
+
const groupField = {
|
|
744
|
+
key: field.key,
|
|
745
|
+
label: field.label,
|
|
746
|
+
mode: "merge",
|
|
747
|
+
valueProcessing: "first",
|
|
748
|
+
showGroupHeader: false,
|
|
749
|
+
mergeCells: true
|
|
750
|
+
};
|
|
751
|
+
setConfig((prev) => ({
|
|
752
|
+
...prev,
|
|
753
|
+
grouping: {
|
|
754
|
+
...prev.grouping,
|
|
755
|
+
fields: [...prev.grouping.fields, groupField]
|
|
756
|
+
}
|
|
757
|
+
}));
|
|
758
|
+
}, [config.fields]);
|
|
759
|
+
const removeGroupingField = useCallback((fieldKey) => {
|
|
760
|
+
setConfig((prev) => ({
|
|
761
|
+
...prev,
|
|
762
|
+
grouping: {
|
|
763
|
+
...prev.grouping,
|
|
764
|
+
fields: prev.grouping.fields.filter((f) => f.key !== fieldKey)
|
|
765
|
+
}
|
|
766
|
+
}));
|
|
767
|
+
}, []);
|
|
768
|
+
const updateGroupingField = useCallback((fieldKey, updates) => {
|
|
769
|
+
setConfig((prev) => ({
|
|
770
|
+
...prev,
|
|
771
|
+
grouping: {
|
|
772
|
+
...prev.grouping,
|
|
773
|
+
fields: prev.grouping.fields.map(
|
|
774
|
+
(field) => field.key === fieldKey ? { ...field, ...updates } : field
|
|
775
|
+
)
|
|
776
|
+
}
|
|
777
|
+
}));
|
|
778
|
+
}, []);
|
|
779
|
+
useCallback((fieldKey, direction) => {
|
|
780
|
+
setConfig((prev) => {
|
|
781
|
+
const fields = [...prev.grouping.fields];
|
|
782
|
+
const index = fields.findIndex((f) => f.key === fieldKey);
|
|
783
|
+
if (direction === "up" && index > 0) {
|
|
784
|
+
const temp = fields[index - 1];
|
|
785
|
+
fields[index - 1] = fields[index];
|
|
786
|
+
fields[index] = temp;
|
|
787
|
+
} else if (direction === "down" && index < fields.length - 1) {
|
|
788
|
+
const temp = fields[index + 1];
|
|
789
|
+
fields[index + 1] = fields[index];
|
|
790
|
+
fields[index] = temp;
|
|
791
|
+
}
|
|
792
|
+
return {
|
|
793
|
+
...prev,
|
|
794
|
+
grouping: {
|
|
795
|
+
...prev.grouping,
|
|
796
|
+
fields
|
|
797
|
+
}
|
|
798
|
+
};
|
|
799
|
+
});
|
|
800
|
+
}, []);
|
|
801
|
+
useCallback((updates) => {
|
|
802
|
+
setConfig((prev) => ({
|
|
803
|
+
...prev,
|
|
804
|
+
grouping: {
|
|
805
|
+
...prev.grouping,
|
|
806
|
+
...updates
|
|
807
|
+
}
|
|
808
|
+
}));
|
|
809
|
+
}, []);
|
|
810
|
+
const handleSave = useCallback(() => {
|
|
811
|
+
if (!config.name.trim()) {
|
|
812
|
+
alert("\u8BF7\u8F93\u5165\u914D\u7F6E\u540D\u79F0");
|
|
813
|
+
return;
|
|
814
|
+
}
|
|
815
|
+
const enabledFields = config.fields.filter((f) => f.enabled);
|
|
816
|
+
if (enabledFields.length === 0) {
|
|
817
|
+
alert("\u81F3\u5C11\u9700\u8981\u542F\u7528\u4E00\u4E2A\u5B57\u6BB5");
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
const updatedConfig = {
|
|
821
|
+
...config,
|
|
822
|
+
updatedAt: /* @__PURE__ */ new Date()
|
|
823
|
+
};
|
|
824
|
+
onSave?.(updatedConfig);
|
|
825
|
+
onConfigChange?.();
|
|
826
|
+
}, [config, onSave, onConfigChange]);
|
|
827
|
+
if (!visible) {
|
|
828
|
+
return null;
|
|
829
|
+
}
|
|
830
|
+
const tabs = [
|
|
831
|
+
{ id: "basic", label: "\u57FA\u672C\u914D\u7F6E", icon: /* @__PURE__ */ React.createElement(Settings, { className: "w-4 h-4" }), description: "\u914D\u7F6E\u540D\u79F0\u3001\u683C\u5F0F\u548C\u57FA\u672C\u9009\u9879" },
|
|
832
|
+
{ id: "fields", label: "\u5B57\u6BB5\u8BBE\u7F6E", icon: /* @__PURE__ */ React.createElement(Type, { className: "w-4 h-4" }), description: "\u9009\u62E9\u548C\u914D\u7F6E\u5BFC\u51FA\u5B57\u6BB5" },
|
|
833
|
+
{ id: "grouping", label: "\u5206\u7EC4\u8BBE\u7F6E", icon: /* @__PURE__ */ React.createElement(Group, { className: "w-4 h-4" }), description: "\u914D\u7F6E\u6570\u636E\u5206\u7EC4\u548C\u5408\u5E76\u9009\u9879" },
|
|
834
|
+
{ id: "manage", label: "\u914D\u7F6E\u7BA1\u7406", icon: /* @__PURE__ */ React.createElement(Database, { className: "w-4 h-4" }), description: "\u7BA1\u7406\u5DF2\u4FDD\u5B58\u7684\u5BFC\u51FA\u914D\u7F6E" }
|
|
835
|
+
];
|
|
836
|
+
return /* @__PURE__ */ React.createElement(
|
|
837
|
+
"div",
|
|
838
|
+
{
|
|
839
|
+
className: clsx("fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-[50] p-4", className),
|
|
840
|
+
onClick: onCancel
|
|
841
|
+
},
|
|
842
|
+
/* @__PURE__ */ React.createElement(
|
|
843
|
+
"div",
|
|
844
|
+
{
|
|
845
|
+
className: "bg-white rounded-lg shadow-xl w-full max-w-5xl max-h-[90vh] flex flex-col",
|
|
846
|
+
onClick: (e) => e.stopPropagation()
|
|
847
|
+
},
|
|
848
|
+
/* @__PURE__ */ React.createElement("div", { className: "flex items-center justify-between p-4 border-b flex-shrink-0" }, /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-3" }, /* @__PURE__ */ React.createElement(Settings, { className: "w-6 h-6 text-blue-600" }), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("h2", { className: "text-xl font-semibold text-gray-900" }, "\u5BFC\u51FA\u914D\u7F6E\u7F16\u8F91\u5668"), /* @__PURE__ */ React.createElement("p", { className: "text-sm text-gray-600" }, "\u914D\u7F6E\u5BFC\u51FA\u5B57\u6BB5\u548C\u683C\u5F0F\u9009\u9879"))), /* @__PURE__ */ React.createElement("button", { onClick: onCancel, className: "p-2 text-gray-400 hover:text-gray-600 hover:bg-gray-100 rounded-lg" }, /* @__PURE__ */ React.createElement(X, { className: "w-5 h-5" }))),
|
|
849
|
+
/* @__PURE__ */ React.createElement("div", { className: "border-b bg-gray-50 flex-shrink-0" }, /* @__PURE__ */ React.createElement("nav", { className: "flex space-x-1 p-2" }, tabs.map((tab) => /* @__PURE__ */ React.createElement(
|
|
850
|
+
"button",
|
|
851
|
+
{
|
|
852
|
+
key: tab.id,
|
|
853
|
+
onClick: () => setActiveTab(tab.id),
|
|
854
|
+
className: clsx("flex items-center gap-2 px-4 py-3 text-sm font-medium rounded-lg transition-colors", activeTab === tab.id ? "bg-white text-blue-600 shadow-sm border border-gray-200" : "text-gray-600 hover:text-gray-900")
|
|
855
|
+
},
|
|
856
|
+
tab.icon,
|
|
857
|
+
/* @__PURE__ */ React.createElement("span", null, tab.label)
|
|
858
|
+
)))),
|
|
859
|
+
/* @__PURE__ */ React.createElement("div", { className: "flex-1 overflow-hidden flex flex-col" }, /* @__PURE__ */ React.createElement("div", { className: "bg-blue-50 border-b border-blue-100 p-4 flex-shrink-0" }, /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-2 text-blue-800 text-sm font-medium" }, tabs.find((t) => t.id === activeTab)?.icon, tabs.find((t) => t.id === activeTab)?.description)), /* @__PURE__ */ React.createElement("div", { className: "flex-1 overflow-y-auto p-4 sm:p-6" }, activeTab === "basic" && /* @__PURE__ */ React.createElement("div", { className: "max-w-2xl mx-auto space-y-6" }, /* @__PURE__ */ React.createElement("div", { className: "space-y-4" }, /* @__PURE__ */ React.createElement("label", { className: "block text-sm font-medium text-gray-700" }, "\u914D\u7F6E\u540D\u79F0 *"), /* @__PURE__ */ React.createElement(
|
|
860
|
+
"input",
|
|
861
|
+
{
|
|
862
|
+
type: "text",
|
|
863
|
+
value: config.name,
|
|
864
|
+
onChange: (e) => setConfig((prev) => ({ ...prev, name: e.target.value })),
|
|
865
|
+
className: "w-full px-3 py-2 border border-gray-300 rounded-lg"
|
|
866
|
+
}
|
|
867
|
+
), /* @__PURE__ */ React.createElement("label", { className: "block text-sm font-medium text-gray-700" }, "\u63CF\u8FF0"), /* @__PURE__ */ React.createElement(
|
|
868
|
+
"textarea",
|
|
869
|
+
{
|
|
870
|
+
value: config.description,
|
|
871
|
+
onChange: (e) => setConfig((prev) => ({ ...prev, description: e.target.value })),
|
|
872
|
+
className: "w-full px-3 py-2 border border-gray-300 rounded-lg",
|
|
873
|
+
rows: 3
|
|
874
|
+
}
|
|
875
|
+
), /* @__PURE__ */ React.createElement("label", { className: "block text-sm font-medium text-gray-700" }, "\u5BFC\u51FA\u683C\u5F0F"), /* @__PURE__ */ React.createElement("div", { className: "space-y-3" }, ["csv", "excel", "json"].map((format) => /* @__PURE__ */ React.createElement("label", { key: format, className: "flex items-start gap-3 p-3 border rounded-lg cursor-pointer hover:border-blue-300" }, /* @__PURE__ */ React.createElement(
|
|
876
|
+
"input",
|
|
877
|
+
{
|
|
878
|
+
type: "radio",
|
|
879
|
+
checked: config.format === format,
|
|
880
|
+
onChange: () => setConfig((prev) => ({ ...prev, format })),
|
|
881
|
+
className: "mt-1"
|
|
882
|
+
}
|
|
883
|
+
), /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-2 font-medium" }, FORMAT_ICONS[format], " ", format.toUpperCase()), /* @__PURE__ */ React.createElement("p", { className: "text-sm text-gray-600" }, FORMAT_DESCRIPTIONS[format]))))))), activeTab === "fields" && /* @__PURE__ */ React.createElement("div", { className: "space-y-4" }, config.fields.map((field, index) => /* @__PURE__ */ React.createElement("div", { key: field.key, className: "flex items-center gap-3 p-3 border rounded-lg bg-white" }, /* @__PURE__ */ React.createElement("button", { onClick: () => toggleFieldEnabled(field.key), className: field.enabled ? "text-blue-600" : "text-gray-400" }, field.enabled ? /* @__PURE__ */ React.createElement(Eye, { className: "w-4 h-4" }) : /* @__PURE__ */ React.createElement(EyeOff, { className: "w-4 h-4" })), /* @__PURE__ */ React.createElement("div", { className: "flex-1" }, /* @__PURE__ */ React.createElement("div", { className: "font-medium" }, field.label), /* @__PURE__ */ React.createElement("div", { className: "text-xs text-gray-500" }, field.key)), /* @__PURE__ */ React.createElement("div", { className: "flex gap-1" }, /* @__PURE__ */ React.createElement("button", { onClick: () => moveField(field.key, "up"), disabled: index === 0, className: "disabled:opacity-30" }, /* @__PURE__ */ React.createElement(MoveUp, { className: "w-4 h-4" })), /* @__PURE__ */ React.createElement("button", { onClick: () => moveField(field.key, "down"), disabled: index === config.fields.length - 1, className: "disabled:opacity-30" }, /* @__PURE__ */ React.createElement(MoveDown, { className: "w-4 h-4" })), /* @__PURE__ */ React.createElement("button", { onClick: () => removeField(field.key), className: "text-red-600" }, /* @__PURE__ */ React.createElement(Trash2, { className: "w-4 h-4" })))))), activeTab === "grouping" && /* @__PURE__ */ React.createElement("div", { className: "space-y-6" }, /* @__PURE__ */ React.createElement("div", { className: "flex items-center justify-between" }, /* @__PURE__ */ React.createElement("h3", { className: "text-lg font-medium flex items-center gap-2" }, /* @__PURE__ */ React.createElement(Group, { className: "w-5 h-5 text-blue-600" }), " \u5206\u7EC4\u914D\u7F6E"), /* @__PURE__ */ React.createElement("label", { className: "flex items-center gap-2" }, /* @__PURE__ */ React.createElement("input", { type: "checkbox", checked: config.grouping?.enabled, onChange: (e) => toggleGrouping(e.target.checked) }), "\u542F\u7528\u5206\u7EC4")), config.grouping?.enabled && /* @__PURE__ */ React.createElement("div", { className: "space-y-4" }, config.grouping.fields.map((gf, index) => /* @__PURE__ */ React.createElement("div", { key: gf.key, className: "p-4 border rounded-lg bg-blue-50 border-blue-200" }, /* @__PURE__ */ React.createElement("div", { className: "flex justify-between items-center mb-4" }, /* @__PURE__ */ React.createElement("span", { className: "font-medium text-blue-900" }, gf.label), /* @__PURE__ */ React.createElement("button", { onClick: () => removeGroupingField(gf.key), className: "text-red-600" }, /* @__PURE__ */ React.createElement(Trash2, { className: "w-4 h-4" }))), /* @__PURE__ */ React.createElement("div", { className: "grid grid-cols-2 gap-4" }, /* @__PURE__ */ React.createElement("select", { value: gf.mode, onChange: (e) => updateGroupingField(gf.key, { mode: e.target.value }), className: "border rounded p-2" }, /* @__PURE__ */ React.createElement("option", { value: "merge" }, "\u5408\u5E76\u6A21\u5F0F"), /* @__PURE__ */ React.createElement("option", { value: "separate" }, "\u5206\u79BB\u6A21\u5F0F"), /* @__PURE__ */ React.createElement("option", { value: "nested" }, "\u5D4C\u5957\u6A21\u5F0F")), /* @__PURE__ */ React.createElement("select", { value: gf.valueProcessing, onChange: (e) => updateGroupingField(gf.key, { valueProcessing: e.target.value }), className: "border rounded p-2" }, /* @__PURE__ */ React.createElement("option", { value: "first" }, "\u9996\u503C"), /* @__PURE__ */ React.createElement("option", { value: "sum" }, "\u6C42\u548C"), /* @__PURE__ */ React.createElement("option", { value: "count" }, "\u8BA1\u6570"))))), /* @__PURE__ */ React.createElement("select", { onChange: (e) => e.target.value && addGroupingField(e.target.value), className: "w-full border rounded p-2" }, /* @__PURE__ */ React.createElement("option", { value: "" }, "\u6DFB\u52A0\u5206\u7EC4\u5B57\u6BB5..."), config.fields.filter((f) => f.enabled && !config.grouping?.fields.some((gf) => gf.key === f.key)).map((f) => /* @__PURE__ */ React.createElement("option", { key: f.key, value: f.key }, f.label))))), activeTab === "manage" && /* @__PURE__ */ React.createElement("div", { className: "space-y-4" }, loadingConfigs ? /* @__PURE__ */ React.createElement("div", { className: "text-center py-10" }, "\u52A0\u8F7D\u4E2D...") : savedConfigs.map((sc) => /* @__PURE__ */ React.createElement("div", { key: sc.id, className: "flex justify-between items-center p-4 border rounded-lg" }, /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement("div", { className: "font-medium" }, sc.name), /* @__PURE__ */ React.createElement("div", { className: "text-sm text-gray-500" }, sc.format)), /* @__PURE__ */ React.createElement("div", { className: "flex gap-2" }, /* @__PURE__ */ React.createElement("button", { onClick: () => loadConfigToEditor(sc), className: "text-blue-600 px-3 py-1 border rounded" }, "\u7F16\u8F91"), /* @__PURE__ */ React.createElement("button", { onClick: () => deleteConfig(sc.id), className: "text-red-600 px-3 py-1 border rounded" }, "\u5220\u9664"))))))),
|
|
884
|
+
/* @__PURE__ */ React.createElement("div", { className: "flex justify-end gap-3 p-4 border-t bg-gray-50" }, /* @__PURE__ */ React.createElement("button", { onClick: onCancel, className: "px-4 py-2 border rounded" }, "\u53D6\u6D88"), activeTab !== "manage" && /* @__PURE__ */ React.createElement("button", { onClick: handleSave, className: "px-4 py-2 bg-blue-600 text-white rounded flex items-center gap-2" }, /* @__PURE__ */ React.createElement(Save, { className: "w-4 h-4" }), " \u4FDD\u5B58\u914D\u7F6E"))
|
|
885
|
+
)
|
|
886
|
+
);
|
|
887
|
+
};
|
|
888
|
+
|
|
889
|
+
// src/universalExport/components/UniversalExportButton.tsx
|
|
890
|
+
var BUTTON_STYLES = {
|
|
891
|
+
primary: {
|
|
892
|
+
sm: "px-3 py-1.5 text-sm bg-blue-600 text-white hover:bg-blue-700",
|
|
893
|
+
md: "px-4 py-2 text-sm bg-blue-600 text-white hover:bg-blue-700",
|
|
894
|
+
lg: "px-6 py-3 text-base bg-blue-600 text-white hover:bg-blue-700"
|
|
895
|
+
},
|
|
896
|
+
secondary: {
|
|
897
|
+
sm: "px-3 py-1.5 text-sm bg-gray-600 text-white hover:bg-gray-700",
|
|
898
|
+
md: "px-4 py-2 text-sm bg-gray-600 text-white hover:bg-gray-700",
|
|
899
|
+
lg: "px-6 py-3 text-base bg-gray-600 text-white hover:bg-gray-700"
|
|
900
|
+
},
|
|
901
|
+
outline: {
|
|
902
|
+
sm: "px-3 py-1.5 text-sm border border-gray-300 text-gray-700 hover:bg-gray-50",
|
|
903
|
+
md: "px-4 py-2 text-sm border border-gray-300 text-gray-700 hover:bg-gray-50",
|
|
904
|
+
lg: "px-6 py-3 text-base border border-gray-300 text-gray-700 hover:bg-gray-50"
|
|
905
|
+
}
|
|
906
|
+
};
|
|
907
|
+
var UniversalExportButton = ({
|
|
908
|
+
exportService,
|
|
909
|
+
moduleId,
|
|
910
|
+
businessId,
|
|
911
|
+
availableFields,
|
|
912
|
+
dataSource,
|
|
913
|
+
defaultConfig,
|
|
914
|
+
buttonText = "\u5BFC\u51FA\u6570\u636E",
|
|
915
|
+
variant = "primary",
|
|
916
|
+
size = "md",
|
|
917
|
+
disabled = false,
|
|
918
|
+
className = "",
|
|
919
|
+
onExportSuccess,
|
|
920
|
+
onExportError,
|
|
921
|
+
onConfigSave
|
|
922
|
+
}) => {
|
|
923
|
+
const [showConfigEditor, setShowConfigEditor] = useState(false);
|
|
924
|
+
const [showDropdown, setShowDropdown] = useState(false);
|
|
925
|
+
const [isExporting, setIsExporting] = useState(false);
|
|
926
|
+
const [exportProgress, setExportProgress] = useState(null);
|
|
927
|
+
const [savedConfigs, setSavedConfigs] = useState([]);
|
|
928
|
+
const loadSavedConfigs = useCallback(async () => {
|
|
929
|
+
try {
|
|
930
|
+
if (exportService) {
|
|
931
|
+
const configs = await exportService.getConfigsByModule(moduleId, businessId);
|
|
932
|
+
setSavedConfigs(configs);
|
|
933
|
+
}
|
|
934
|
+
} catch (error) {
|
|
935
|
+
console.error("\u52A0\u8F7D\u4FDD\u5B58\u7684\u914D\u7F6E\u5931\u8D25:", error);
|
|
936
|
+
}
|
|
937
|
+
}, [exportService, moduleId, businessId]);
|
|
938
|
+
React.useEffect(() => {
|
|
939
|
+
loadSavedConfigs();
|
|
940
|
+
}, [loadSavedConfigs]);
|
|
941
|
+
const handleExport = useCallback(async (config) => {
|
|
942
|
+
console.log("\u{1F680} [UniversalExportButton] \u5F00\u59CB\u5BFC\u51FA:", {
|
|
943
|
+
configId: config.id,
|
|
944
|
+
configName: config.name,
|
|
945
|
+
format: config.format,
|
|
946
|
+
fieldsCount: config.fields.length
|
|
947
|
+
});
|
|
948
|
+
if (!exportService) {
|
|
949
|
+
console.error("\u274C [UniversalExportButton] \u5BFC\u51FA\u670D\u52A1\u672A\u521D\u59CB\u5316");
|
|
950
|
+
onExportError?.("\u5BFC\u51FA\u670D\u52A1\u672A\u521D\u59CB\u5316");
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
setIsExporting(true);
|
|
954
|
+
setExportProgress(null);
|
|
955
|
+
try {
|
|
956
|
+
console.log("\u{1F4CA} [UniversalExportButton] \u83B7\u53D6\u6570\u636E...");
|
|
957
|
+
const data = await dataSource();
|
|
958
|
+
console.log("\u2705 [UniversalExportButton] \u6570\u636E\u83B7\u53D6\u6210\u529F:", {
|
|
959
|
+
dataType: typeof data,
|
|
960
|
+
isArray: Array.isArray(data),
|
|
961
|
+
length: Array.isArray(data) ? data.length : "N/A"
|
|
962
|
+
});
|
|
963
|
+
const request = {
|
|
964
|
+
configId: config,
|
|
965
|
+
dataSource: data,
|
|
966
|
+
// 传递实际数据而不是函数
|
|
967
|
+
queryParams: void 0,
|
|
968
|
+
fieldMapping: void 0,
|
|
969
|
+
filters: void 0,
|
|
970
|
+
sortBy: void 0,
|
|
971
|
+
pagination: void 0,
|
|
972
|
+
customFileName: void 0
|
|
973
|
+
};
|
|
974
|
+
console.log("\u{1F4DE} [UniversalExportButton] \u8C03\u7528\u5BFC\u51FA\u670D\u52A1...");
|
|
975
|
+
const result = await exportService.exportData(request);
|
|
976
|
+
console.log("\u2705 [UniversalExportButton] \u5BFC\u51FA\u6210\u529F:", {
|
|
977
|
+
fileName: result.fileName,
|
|
978
|
+
fileSize: result.fileSize,
|
|
979
|
+
exportedRows: result.exportedRows
|
|
980
|
+
});
|
|
981
|
+
const progress = {
|
|
982
|
+
exportId: result.exportId,
|
|
983
|
+
status: "completed",
|
|
984
|
+
progress: 100,
|
|
985
|
+
processedRows: result.exportedRows,
|
|
986
|
+
totalRows: result.exportedRows,
|
|
987
|
+
startTime: result.startTime,
|
|
988
|
+
estimatedEndTime: result.endTime
|
|
989
|
+
};
|
|
990
|
+
setExportProgress(progress);
|
|
991
|
+
if (result.fileUrl) {
|
|
992
|
+
console.log("\u{1F4E5} [UniversalExportButton] \u4ECEURL\u4E0B\u8F7D\u6587\u4EF6...");
|
|
993
|
+
const link = document.createElement("a");
|
|
994
|
+
link.href = result.fileUrl;
|
|
995
|
+
link.download = result.fileName;
|
|
996
|
+
document.body.appendChild(link);
|
|
997
|
+
link.click();
|
|
998
|
+
document.body.removeChild(link);
|
|
999
|
+
console.log("\u2705 [UniversalExportButton] \u6587\u4EF6\u4E0B\u8F7D\u5B8C\u6210");
|
|
1000
|
+
} else if (result.fileBlob) {
|
|
1001
|
+
console.log("\u{1F4E5} [UniversalExportButton] \u4ECEBlob\u4E0B\u8F7D\u6587\u4EF6...");
|
|
1002
|
+
const url = window.URL.createObjectURL(result.fileBlob);
|
|
1003
|
+
const link = document.createElement("a");
|
|
1004
|
+
link.href = url;
|
|
1005
|
+
link.download = result.fileName;
|
|
1006
|
+
document.body.appendChild(link);
|
|
1007
|
+
link.click();
|
|
1008
|
+
document.body.removeChild(link);
|
|
1009
|
+
window.URL.revokeObjectURL(url);
|
|
1010
|
+
console.log("\u2705 [UniversalExportButton] \u6587\u4EF6\u4E0B\u8F7D\u5B8C\u6210");
|
|
1011
|
+
}
|
|
1012
|
+
setTimeout(() => {
|
|
1013
|
+
setIsExporting(false);
|
|
1014
|
+
setExportProgress(null);
|
|
1015
|
+
}, 1e3);
|
|
1016
|
+
onExportSuccess?.(result);
|
|
1017
|
+
} catch (error) {
|
|
1018
|
+
console.error("\u274C [UniversalExportButton] \u5BFC\u51FA\u5F02\u5E38:", error);
|
|
1019
|
+
setIsExporting(false);
|
|
1020
|
+
setExportProgress(null);
|
|
1021
|
+
let errorMessage = "\u5BFC\u51FA\u5931\u8D25";
|
|
1022
|
+
if (error && typeof error === "object") {
|
|
1023
|
+
if ("message" in error && typeof error.message === "string") {
|
|
1024
|
+
errorMessage = error.message;
|
|
1025
|
+
} else if ("code" in error && "message" in error) {
|
|
1026
|
+
errorMessage = error.code + ": " + error.message;
|
|
1027
|
+
}
|
|
1028
|
+
} else if (typeof error === "string") {
|
|
1029
|
+
errorMessage = error;
|
|
1030
|
+
}
|
|
1031
|
+
onExportError?.(errorMessage);
|
|
1032
|
+
}
|
|
1033
|
+
}, [exportService, dataSource, onExportSuccess, onExportError]);
|
|
1034
|
+
const handleQuickExport = useCallback(async () => {
|
|
1035
|
+
if (defaultConfig) {
|
|
1036
|
+
await handleExport(defaultConfig);
|
|
1037
|
+
} else {
|
|
1038
|
+
const config = {
|
|
1039
|
+
id: "quick_export",
|
|
1040
|
+
name: "\u5FEB\u901F\u5BFC\u51FA",
|
|
1041
|
+
description: "\u4F7F\u7528\u9ED8\u8BA4\u914D\u7F6E\u5FEB\u901F\u5BFC\u51FA",
|
|
1042
|
+
format: "csv",
|
|
1043
|
+
fields: availableFields.map((field, index) => ({
|
|
1044
|
+
...field,
|
|
1045
|
+
enabled: true,
|
|
1046
|
+
sortOrder: index
|
|
1047
|
+
})),
|
|
1048
|
+
fileNameTemplate: "\u5BFC\u51FA\u6570\u636E_{date}",
|
|
1049
|
+
includeHeader: true,
|
|
1050
|
+
delimiter: ",",
|
|
1051
|
+
encoding: "utf-8",
|
|
1052
|
+
addBOM: true,
|
|
1053
|
+
createdAt: /* @__PURE__ */ new Date(),
|
|
1054
|
+
updatedAt: /* @__PURE__ */ new Date(),
|
|
1055
|
+
moduleId,
|
|
1056
|
+
businessId
|
|
1057
|
+
};
|
|
1058
|
+
await handleExport(config);
|
|
1059
|
+
}
|
|
1060
|
+
}, [defaultConfig, availableFields, moduleId, businessId, handleExport]);
|
|
1061
|
+
const handleConfigSave = useCallback(async (config) => {
|
|
1062
|
+
try {
|
|
1063
|
+
if (exportService) {
|
|
1064
|
+
const savedConfig = await exportService.createConfig(config);
|
|
1065
|
+
await loadSavedConfigs();
|
|
1066
|
+
onConfigSave?.(savedConfig);
|
|
1067
|
+
}
|
|
1068
|
+
setShowConfigEditor(false);
|
|
1069
|
+
} catch (error) {
|
|
1070
|
+
onExportError?.(error instanceof Error ? error.message : "\u4FDD\u5B58\u914D\u7F6E\u5931\u8D25");
|
|
1071
|
+
}
|
|
1072
|
+
}, [exportService, onConfigSave, onExportError, loadSavedConfigs]);
|
|
1073
|
+
const renderProgress = () => {
|
|
1074
|
+
if (!exportProgress) return null;
|
|
1075
|
+
const { status, progress, processedRows, totalRows } = exportProgress;
|
|
1076
|
+
return /* @__PURE__ */ React.createElement("div", { className: "absolute top-full left-0 right-0 mt-2 bg-white border border-gray-200 rounded-lg shadow-lg p-4 z-[10]" }, /* @__PURE__ */ React.createElement("div", { className: "flex items-center gap-3 mb-2" }, /* @__PURE__ */ React.createElement(Loader2, { className: "w-4 h-4 animate-spin text-blue-600" }), /* @__PURE__ */ React.createElement("span", { className: "text-sm font-medium text-gray-900" }, status === "processing" ? "\u6B63\u5728\u5BFC\u51FA..." : "\u5BFC\u51FA\u5B8C\u6210")), /* @__PURE__ */ React.createElement("div", { className: "space-y-2" }, /* @__PURE__ */ React.createElement("div", { className: "flex justify-between text-xs text-gray-600" }, /* @__PURE__ */ React.createElement("span", null, "\u8FDB\u5EA6: ", progress, "%"), /* @__PURE__ */ React.createElement("span", null, processedRows, " / ", totalRows, " \u884C")), /* @__PURE__ */ React.createElement("div", { className: "w-full bg-gray-200 rounded-full h-2" }, /* @__PURE__ */ React.createElement(
|
|
1077
|
+
"div",
|
|
1078
|
+
{
|
|
1079
|
+
className: "bg-blue-600 h-2 rounded-full transition-all duration-300",
|
|
1080
|
+
style: { width: progress + "%" }
|
|
1081
|
+
}
|
|
1082
|
+
))));
|
|
1083
|
+
};
|
|
1084
|
+
const renderDropdown = () => {
|
|
1085
|
+
if (!showDropdown) return null;
|
|
1086
|
+
return /* @__PURE__ */ React.createElement("div", { className: "absolute top-full left-0 mt-2 bg-white border border-gray-200 rounded-lg shadow-lg py-2 z-[10] min-w-48" }, /* @__PURE__ */ React.createElement(
|
|
1087
|
+
"button",
|
|
1088
|
+
{
|
|
1089
|
+
onClick: () => {
|
|
1090
|
+
setShowDropdown(false);
|
|
1091
|
+
handleQuickExport();
|
|
1092
|
+
},
|
|
1093
|
+
disabled: isExporting,
|
|
1094
|
+
className: "w-full px-4 py-2 text-left text-sm text-gray-700 hover:bg-gray-50 flex items-center gap-2"
|
|
1095
|
+
},
|
|
1096
|
+
/* @__PURE__ */ React.createElement(Download, { className: "w-4 h-4" }),
|
|
1097
|
+
"\u5FEB\u901F\u5BFC\u51FA"
|
|
1098
|
+
), savedConfigs.length > 0 && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "border-t border-gray-200 my-1" }), savedConfigs.map((config) => /* @__PURE__ */ React.createElement(
|
|
1099
|
+
"button",
|
|
1100
|
+
{
|
|
1101
|
+
key: config.id,
|
|
1102
|
+
onClick: () => {
|
|
1103
|
+
setShowDropdown(false);
|
|
1104
|
+
handleExport(config);
|
|
1105
|
+
},
|
|
1106
|
+
disabled: isExporting,
|
|
1107
|
+
className: "w-full px-4 py-2 text-left text-sm text-gray-700 hover:bg-gray-50 flex items-center gap-2"
|
|
1108
|
+
},
|
|
1109
|
+
/* @__PURE__ */ React.createElement(FileText, { className: "w-4 h-4" }),
|
|
1110
|
+
config.name
|
|
1111
|
+
))), /* @__PURE__ */ React.createElement("div", { className: "border-t border-gray-200 my-1" }), /* @__PURE__ */ React.createElement(
|
|
1112
|
+
"button",
|
|
1113
|
+
{
|
|
1114
|
+
onClick: () => {
|
|
1115
|
+
setShowDropdown(false);
|
|
1116
|
+
setShowConfigEditor(true);
|
|
1117
|
+
},
|
|
1118
|
+
className: "w-full px-4 py-2 text-left text-sm text-gray-700 hover:bg-gray-50 flex items-center gap-2"
|
|
1119
|
+
},
|
|
1120
|
+
/* @__PURE__ */ React.createElement(Settings, { className: "w-4 h-4" }),
|
|
1121
|
+
"\u81EA\u5B9A\u4E49\u914D\u7F6E"
|
|
1122
|
+
));
|
|
1123
|
+
};
|
|
1124
|
+
const buttonStyle = BUTTON_STYLES[variant][size];
|
|
1125
|
+
const baseClasses = "inline-flex items-center gap-2 rounded-lg font-medium transition-colors focus:outline-none focus:ring-2 focus:ring-blue-500 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed " + buttonStyle;
|
|
1126
|
+
return /* @__PURE__ */ React.createElement("div", { className: clsx("relative", className) }, /* @__PURE__ */ React.createElement(
|
|
1127
|
+
"button",
|
|
1128
|
+
{
|
|
1129
|
+
onClick: () => setShowDropdown(!showDropdown),
|
|
1130
|
+
disabled: disabled || isExporting,
|
|
1131
|
+
className: clsx(baseClasses, isExporting ? "cursor-not-allowed" : "")
|
|
1132
|
+
},
|
|
1133
|
+
isExporting ? /* @__PURE__ */ React.createElement(Loader2, { className: "w-4 h-4 animate-spin" }) : /* @__PURE__ */ React.createElement(Download, { className: "w-4 h-4" }),
|
|
1134
|
+
/* @__PURE__ */ React.createElement("span", null, isExporting ? "\u5BFC\u51FA\u4E2D..." : buttonText),
|
|
1135
|
+
/* @__PURE__ */ React.createElement(ChevronDown, { className: "w-4 h-4" })
|
|
1136
|
+
), renderDropdown(), renderProgress(), /* @__PURE__ */ React.createElement(
|
|
1137
|
+
ExportConfigEditor,
|
|
1138
|
+
{
|
|
1139
|
+
moduleId,
|
|
1140
|
+
businessId,
|
|
1141
|
+
availableFields,
|
|
1142
|
+
onSave: handleConfigSave,
|
|
1143
|
+
onCancel: () => setShowConfigEditor(false),
|
|
1144
|
+
visible: showConfigEditor,
|
|
1145
|
+
onConfigChange: loadSavedConfigs
|
|
1146
|
+
}
|
|
1147
|
+
), showDropdown && /* @__PURE__ */ React.createElement(
|
|
1148
|
+
"div",
|
|
1149
|
+
{
|
|
1150
|
+
className: "fixed inset-0 z-[0]",
|
|
1151
|
+
onClick: () => setShowDropdown(false)
|
|
1152
|
+
}
|
|
1153
|
+
));
|
|
1154
|
+
};
|
|
1155
|
+
|
|
1156
|
+
export { API_BASE_PATH, API_ENDPOINTS, DEFAULT_ADD_BOM, DEFAULT_CONFIG_CACHE_TTL, DEFAULT_CSV_DELIMITER, DEFAULT_ENCODING, DEFAULT_EXPORT_FORMAT, DEFAULT_EXPORT_TIMEOUT, DEFAULT_FORMATTERS, DEFAULT_MAX_CONCURRENT_EXPORTS, DEFAULT_MAX_FILE_SIZE, DEFAULT_MAX_ROWS, DEFAULT_RESULT_CACHE_TTL, ERROR_CODES, EXPORT_FORMAT_EXTENSIONS, EXPORT_FORMAT_MIME_TYPES, ExportConfigEditor, UNIVERSAL_EXPORT_NAME, UNIVERSAL_EXPORT_VERSION, UniversalExportButton, UniversalExportClient, applyFormatter, createExportClient, createExportError, escapeCSVField, estimateEndTime, formatDuration, formatErrorMessage, formatFileSize, generateExportFileName, getNestedValue, parseCSVField, sanitizeFileName, setNestedValue, universalExportClient, validateExportConfig, validateExportRequest, validateFileName };
|
|
1157
|
+
//# sourceMappingURL=chunk-TGNUEULF.mjs.map
|
|
1158
|
+
//# sourceMappingURL=chunk-TGNUEULF.mjs.map
|