openxiangda 1.0.151 → 1.0.153
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/README.md +14 -0
- package/openxiangda-skills/SKILL.md +1 -0
- package/openxiangda-skills/references/component-guide.md +13 -0
- package/openxiangda-skills/references/pages/page-sdk.md +37 -3
- package/package.json +6 -2
- package/packages/sdk/dist/{ProcessPreview-BOCARAvP.d.mts → ProcessPreview-DMkzccq4.d.mts} +58 -2
- package/packages/sdk/dist/{ProcessPreview-BOCARAvP.d.ts → ProcessPreview-DMkzccq4.d.ts} +58 -2
- package/packages/sdk/dist/components/index.cjs +3518 -2279
- package/packages/sdk/dist/components/index.cjs.map +1 -1
- package/packages/sdk/dist/components/index.d.mts +92 -38
- package/packages/sdk/dist/components/index.d.ts +92 -38
- package/packages/sdk/dist/components/index.mjs +3266 -2022
- package/packages/sdk/dist/components/index.mjs.map +1 -1
- package/packages/sdk/dist/{dataManagementApi-CLMqf79O.d.mts → dataManagementApi-C9O-Bb0j.d.ts} +2 -2
- package/packages/sdk/dist/{dataManagementApi-DhpRKmlp.d.ts → dataManagementApi-gpZkgRDM.d.mts} +2 -2
- package/packages/sdk/dist/runtime/index.cjs +8220 -7071
- package/packages/sdk/dist/runtime/index.cjs.map +1 -1
- package/packages/sdk/dist/runtime/index.d.mts +5 -4
- package/packages/sdk/dist/runtime/index.d.ts +5 -4
- package/packages/sdk/dist/runtime/index.mjs +8153 -6999
- package/packages/sdk/dist/runtime/index.mjs.map +1 -1
- package/packages/sdk/dist/runtime/react.cjs +2899 -453
- package/packages/sdk/dist/runtime/react.cjs.map +1 -1
- package/packages/sdk/dist/runtime/react.d.mts +63 -4
- package/packages/sdk/dist/runtime/react.d.ts +63 -4
- package/packages/sdk/dist/runtime/react.mjs +2908 -439
- package/packages/sdk/dist/runtime/react.mjs.map +1 -1
- package/templates/openxiangda-react-spa/.cursor/rules/openxiangda.mdc +1 -0
- package/templates/openxiangda-react-spa/.qoder/rules/openxiangda.md +1 -0
- package/templates/openxiangda-react-spa/AGENTS.md +5 -1
|
@@ -30,7 +30,9 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
30
30
|
// packages/sdk/src/runtime/react/index.ts
|
|
31
31
|
var react_exports = {};
|
|
32
32
|
__export(react_exports, {
|
|
33
|
+
AttachmentPreviewList: () => AttachmentPreviewList,
|
|
33
34
|
AuthClientError: () => AuthClientError,
|
|
35
|
+
ImagePreviewGrid: () => ImagePreviewGrid,
|
|
34
36
|
InitiatorApproverSelector: () => InitiatorApproverSelector,
|
|
35
37
|
LoginPage: () => LoginPage,
|
|
36
38
|
OpenXiangdaPageProvider: () => OpenXiangdaPageProvider,
|
|
@@ -56,6 +58,7 @@ __export(react_exports, {
|
|
|
56
58
|
useCanAccessRoute: () => useCanAccessRoute,
|
|
57
59
|
useCurrentUser: () => useCurrentUser,
|
|
58
60
|
useDataSource: () => useDataSource,
|
|
61
|
+
useFilePreview: () => useFilePreview,
|
|
59
62
|
useFormViewPermissions: () => useFormViewPermissions,
|
|
60
63
|
useLoginMethods: () => useLoginMethods,
|
|
61
64
|
useMessage: () => useMessage,
|
|
@@ -767,14 +770,14 @@ var createPageSdk = (context) => {
|
|
|
767
770
|
throw toSdkError(error, payload);
|
|
768
771
|
}
|
|
769
772
|
};
|
|
770
|
-
const createFileAccessTicket = (bucketName, objectName, fileName,
|
|
773
|
+
const createFileAccessTicket = (bucketName, objectName, fileName, purpose = "preview", options = {}) => request({
|
|
771
774
|
path: "/file/access-ticket",
|
|
772
775
|
method: "post",
|
|
773
776
|
body: {
|
|
774
777
|
bucketName,
|
|
775
778
|
objectName,
|
|
776
779
|
fileName,
|
|
777
|
-
|
|
780
|
+
purpose,
|
|
778
781
|
appType: resolveAppType(context, options.appType)
|
|
779
782
|
}
|
|
780
783
|
});
|
|
@@ -2696,15 +2699,2520 @@ var usePageRoute = () => {
|
|
|
2696
2699
|
return usePageContext().route;
|
|
2697
2700
|
};
|
|
2698
2701
|
|
|
2702
|
+
// packages/sdk/src/runtime/react/filePreview.tsx
|
|
2703
|
+
var import_react10 = __toESM(require("react"));
|
|
2704
|
+
var import_antd5 = require("antd");
|
|
2705
|
+
|
|
2706
|
+
// packages/sdk/src/components/core/imageCompression.ts
|
|
2707
|
+
var DEFAULT_THUMB = {
|
|
2708
|
+
maxWidth: 320,
|
|
2709
|
+
maxHeight: 320,
|
|
2710
|
+
quality: 0.72,
|
|
2711
|
+
format: "source"
|
|
2712
|
+
};
|
|
2713
|
+
var DEFAULT_PREVIEW = {
|
|
2714
|
+
maxWidth: 1280,
|
|
2715
|
+
maxHeight: 1280,
|
|
2716
|
+
quality: 0.82,
|
|
2717
|
+
format: "source"
|
|
2718
|
+
};
|
|
2719
|
+
var COMPRESSIBLE_EXTENSIONS = /* @__PURE__ */ new Set(["jpg", "jpeg", "png", "webp", "bmp"]);
|
|
2720
|
+
function shouldCreateImageVariants(file, config) {
|
|
2721
|
+
if (!config || config.enabled === false) return false;
|
|
2722
|
+
if (!isCompressibleImageFile(file)) return false;
|
|
2723
|
+
if (config.skipBelowBytes && file.size <= config.skipBelowBytes) return false;
|
|
2724
|
+
return true;
|
|
2725
|
+
}
|
|
2726
|
+
async function createCompressedImageVariants(file, config) {
|
|
2727
|
+
if (!shouldCreateImageVariants(file, config)) return [];
|
|
2728
|
+
const variantConfigs = [];
|
|
2729
|
+
if (config?.thumb !== false) {
|
|
2730
|
+
variantConfigs.push(["thumb", { ...DEFAULT_THUMB, ...config?.thumb || {} }]);
|
|
2731
|
+
}
|
|
2732
|
+
if (config?.preview !== false) {
|
|
2733
|
+
variantConfigs.push(["preview", { ...DEFAULT_PREVIEW, ...config?.preview || {} }]);
|
|
2734
|
+
}
|
|
2735
|
+
if (variantConfigs.length === 0) return [];
|
|
2736
|
+
const source = await loadImageSource(file);
|
|
2737
|
+
if (!source) return [];
|
|
2738
|
+
try {
|
|
2739
|
+
const sourceWidth = Math.max(1, source.naturalWidth || source.width || 0);
|
|
2740
|
+
const sourceHeight = Math.max(1, source.naturalHeight || source.height || 0);
|
|
2741
|
+
if (!sourceWidth || !sourceHeight) return [];
|
|
2742
|
+
const results = [];
|
|
2743
|
+
for (const [kind, variantConfig] of variantConfigs) {
|
|
2744
|
+
const normalized = normalizeVariantConfig(kind, variantConfig);
|
|
2745
|
+
const target = getTargetSize(sourceWidth, sourceHeight, normalized);
|
|
2746
|
+
const mimeType = resolveOutputMimeType(file, normalized.format);
|
|
2747
|
+
const blob = await drawCompressedBlob(
|
|
2748
|
+
source,
|
|
2749
|
+
target.width,
|
|
2750
|
+
target.height,
|
|
2751
|
+
mimeType,
|
|
2752
|
+
normalized.quality
|
|
2753
|
+
);
|
|
2754
|
+
if (!blob || blob.size >= file.size) continue;
|
|
2755
|
+
const outputFile = new File([blob], buildVariantFileName(file.name, kind, mimeType), {
|
|
2756
|
+
type: blob.type || mimeType,
|
|
2757
|
+
lastModified: Date.now()
|
|
2758
|
+
});
|
|
2759
|
+
results.push({
|
|
2760
|
+
kind,
|
|
2761
|
+
file: outputFile,
|
|
2762
|
+
width: target.width,
|
|
2763
|
+
height: target.height,
|
|
2764
|
+
contentType: outputFile.type || mimeType,
|
|
2765
|
+
quality: normalized.quality
|
|
2766
|
+
});
|
|
2767
|
+
}
|
|
2768
|
+
return results;
|
|
2769
|
+
} finally {
|
|
2770
|
+
source.close?.();
|
|
2771
|
+
}
|
|
2772
|
+
}
|
|
2773
|
+
function isCompressibleImageFile(file) {
|
|
2774
|
+
const contentType = String(file.type || "").toLowerCase();
|
|
2775
|
+
if (contentType === "image/svg+xml" || contentType === "image/gif") return false;
|
|
2776
|
+
if (contentType.startsWith("image/")) {
|
|
2777
|
+
return ["image/jpeg", "image/png", "image/webp", "image/bmp"].includes(contentType);
|
|
2778
|
+
}
|
|
2779
|
+
const extension = getExtension(file.name);
|
|
2780
|
+
return COMPRESSIBLE_EXTENSIONS.has(extension);
|
|
2781
|
+
}
|
|
2782
|
+
async function loadImageSource(file) {
|
|
2783
|
+
if (typeof createImageBitmap === "function") {
|
|
2784
|
+
try {
|
|
2785
|
+
return await createImageBitmap(file);
|
|
2786
|
+
} catch {
|
|
2787
|
+
}
|
|
2788
|
+
}
|
|
2789
|
+
if (typeof Image === "undefined" || typeof URL === "undefined") return null;
|
|
2790
|
+
const objectUrl = URL.createObjectURL(file);
|
|
2791
|
+
try {
|
|
2792
|
+
const image = new Image();
|
|
2793
|
+
image.decoding = "async";
|
|
2794
|
+
image.src = objectUrl;
|
|
2795
|
+
if (typeof image.decode === "function") {
|
|
2796
|
+
await image.decode();
|
|
2797
|
+
} else {
|
|
2798
|
+
await new Promise((resolve, reject) => {
|
|
2799
|
+
image.onload = () => resolve();
|
|
2800
|
+
image.onerror = () => reject(new Error("\u56FE\u7247\u89E3\u7801\u5931\u8D25"));
|
|
2801
|
+
});
|
|
2802
|
+
}
|
|
2803
|
+
return image;
|
|
2804
|
+
} catch {
|
|
2805
|
+
return null;
|
|
2806
|
+
} finally {
|
|
2807
|
+
URL.revokeObjectURL(objectUrl);
|
|
2808
|
+
}
|
|
2809
|
+
}
|
|
2810
|
+
function normalizeVariantConfig(kind, config) {
|
|
2811
|
+
const fallback = kind === "thumb" ? DEFAULT_THUMB : DEFAULT_PREVIEW;
|
|
2812
|
+
const maxWidth = Number(config.maxWidth || fallback.maxWidth);
|
|
2813
|
+
const maxHeight = Number(config.maxHeight || fallback.maxHeight);
|
|
2814
|
+
const quality = Number(config.quality ?? fallback.quality);
|
|
2815
|
+
return {
|
|
2816
|
+
maxWidth: Number.isFinite(maxWidth) && maxWidth > 0 ? maxWidth : fallback.maxWidth,
|
|
2817
|
+
maxHeight: Number.isFinite(maxHeight) && maxHeight > 0 ? maxHeight : fallback.maxHeight,
|
|
2818
|
+
quality: Number.isFinite(quality) && quality > 0 && quality <= 1 ? quality : fallback.quality,
|
|
2819
|
+
format: config.format || fallback.format
|
|
2820
|
+
};
|
|
2821
|
+
}
|
|
2822
|
+
function getTargetSize(sourceWidth, sourceHeight, config) {
|
|
2823
|
+
const scale = Math.min(1, config.maxWidth / sourceWidth, config.maxHeight / sourceHeight);
|
|
2824
|
+
return {
|
|
2825
|
+
width: Math.max(1, Math.round(sourceWidth * scale)),
|
|
2826
|
+
height: Math.max(1, Math.round(sourceHeight * scale))
|
|
2827
|
+
};
|
|
2828
|
+
}
|
|
2829
|
+
function drawCompressedBlob(source, width, height, mimeType, quality) {
|
|
2830
|
+
if (typeof document === "undefined") return Promise.resolve(null);
|
|
2831
|
+
const canvas = document.createElement("canvas");
|
|
2832
|
+
canvas.width = width;
|
|
2833
|
+
canvas.height = height;
|
|
2834
|
+
const context = canvas.getContext("2d");
|
|
2835
|
+
if (!context || typeof canvas.toBlob !== "function") return Promise.resolve(null);
|
|
2836
|
+
context.drawImage(source, 0, 0, width, height);
|
|
2837
|
+
return new Promise((resolve) => {
|
|
2838
|
+
canvas.toBlob(resolve, mimeType, mimeType === "image/png" ? void 0 : quality);
|
|
2839
|
+
});
|
|
2840
|
+
}
|
|
2841
|
+
function resolveOutputMimeType(file, format) {
|
|
2842
|
+
if (format && format !== "source") {
|
|
2843
|
+
return format === "jpeg" ? "image/jpeg" : `image/${format}`;
|
|
2844
|
+
}
|
|
2845
|
+
const sourceType = String(file.type || "").toLowerCase();
|
|
2846
|
+
if (["image/jpeg", "image/png", "image/webp"].includes(sourceType)) return sourceType;
|
|
2847
|
+
const extension = getExtension(file.name);
|
|
2848
|
+
if (extension === "png") return "image/png";
|
|
2849
|
+
if (extension === "webp") return "image/webp";
|
|
2850
|
+
return "image/jpeg";
|
|
2851
|
+
}
|
|
2852
|
+
function buildVariantFileName(fileName, kind, mimeType) {
|
|
2853
|
+
const extension = extensionFromMimeType(mimeType);
|
|
2854
|
+
const baseName = String(fileName || "image").replace(/\.[^.]*$/, "").replace(/[^\w.-]+/g, "_").replace(/^_+|_+$/g, "");
|
|
2855
|
+
return `${baseName || "image"}.${kind}.${extension}`;
|
|
2856
|
+
}
|
|
2857
|
+
function extensionFromMimeType(mimeType) {
|
|
2858
|
+
if (mimeType === "image/png") return "png";
|
|
2859
|
+
if (mimeType === "image/webp") return "webp";
|
|
2860
|
+
return "jpg";
|
|
2861
|
+
}
|
|
2862
|
+
function getExtension(fileName) {
|
|
2863
|
+
return String(fileName || "").split(".").pop()?.toLowerCase() || "";
|
|
2864
|
+
}
|
|
2865
|
+
|
|
2866
|
+
// packages/sdk/src/components/core/runtimeApi.ts
|
|
2867
|
+
var DEFAULT_CHUNK_SIZE = 5 * 1024 * 1024;
|
|
2868
|
+
var CHUNK_UPLOAD_THRESHOLD = 10 * 1024 * 1024;
|
|
2869
|
+
var DEFAULT_PUBLIC_FILE_BUCKET = "public-assets";
|
|
2870
|
+
var trimTrailingSlash = (value) => String(value || "").replace(/\/$/, "");
|
|
2871
|
+
var getDefaultBaseUrl = () => {
|
|
2872
|
+
const globalEnv = globalThis.process?.env;
|
|
2873
|
+
const envBaseUrl = globalEnv?.FORM_API_BASE_URL || globalEnv?.BASE_API_URL;
|
|
2874
|
+
if (envBaseUrl) return trimTrailingSlash(envBaseUrl);
|
|
2875
|
+
const browserGlobal = typeof window !== "undefined" ? window : void 0;
|
|
2876
|
+
const windowBaseUrl = browserGlobal?.FORM_API_BASE_URL || browserGlobal?.BASE_API_URL || browserGlobal?.__FORM_API_BASE_URL__ || browserGlobal?.__LOWCODE_API_BASE_URL__;
|
|
2877
|
+
if (windowBaseUrl) return trimTrailingSlash(windowBaseUrl);
|
|
2878
|
+
return typeof window !== "undefined" ? "/service" : "";
|
|
2879
|
+
};
|
|
2880
|
+
var appendQuery = (url, params) => {
|
|
2881
|
+
if (!params) return url;
|
|
2882
|
+
const search = new URLSearchParams();
|
|
2883
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
2884
|
+
if (value === void 0 || value === null || value === "") return;
|
|
2885
|
+
if (Array.isArray(value)) {
|
|
2886
|
+
value.forEach((item) => search.append(key, String(item)));
|
|
2887
|
+
return;
|
|
2888
|
+
}
|
|
2889
|
+
search.append(key, String(value));
|
|
2890
|
+
});
|
|
2891
|
+
const query = search.toString();
|
|
2892
|
+
if (!query) return url;
|
|
2893
|
+
return `${url}${url.includes("?") ? "&" : "?"}${query}`;
|
|
2894
|
+
};
|
|
2895
|
+
var joinUrl = (baseUrl, url) => {
|
|
2896
|
+
if (/^https?:\/\//i.test(url)) return url;
|
|
2897
|
+
const normalizedBaseUrl = trimTrailingSlash(baseUrl);
|
|
2898
|
+
if (normalizedBaseUrl && (url === normalizedBaseUrl || url.startsWith(`${normalizedBaseUrl}/`))) {
|
|
2899
|
+
return url;
|
|
2900
|
+
}
|
|
2901
|
+
return `${normalizedBaseUrl}${url.startsWith("/") ? url : `/${url}`}`;
|
|
2902
|
+
};
|
|
2903
|
+
var isSuccessCode2 = (value) => {
|
|
2904
|
+
if (value === void 0 || value === null || value === "") return true;
|
|
2905
|
+
const code = Number(value);
|
|
2906
|
+
return Number.isFinite(code) ? code === 0 || code >= 200 && code < 300 : false;
|
|
2907
|
+
};
|
|
2908
|
+
var normalizeRuntimeFileUrl = (baseUrl, value) => {
|
|
2909
|
+
if (typeof value !== "string" || !value) return value;
|
|
2910
|
+
if (/^(https?:)?\/\//i.test(value) || /^(blob|data):/i.test(value)) return value;
|
|
2911
|
+
if (!value.startsWith("/file/")) return value;
|
|
2912
|
+
return joinUrl(baseUrl, value);
|
|
2913
|
+
};
|
|
2914
|
+
var normalizeFilePayloadUrls = (baseUrl, payload) => {
|
|
2915
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) return payload;
|
|
2916
|
+
return {
|
|
2917
|
+
...payload,
|
|
2918
|
+
url: normalizeRuntimeFileUrl(baseUrl, payload.url),
|
|
2919
|
+
downloadUrl: normalizeRuntimeFileUrl(baseUrl, payload.downloadUrl),
|
|
2920
|
+
publicUrl: normalizeRuntimeFileUrl(baseUrl, payload.publicUrl),
|
|
2921
|
+
relayUrl: normalizeRuntimeFileUrl(baseUrl, payload.relayUrl),
|
|
2922
|
+
previewUrl: normalizeRuntimeFileUrl(baseUrl, payload.previewUrl),
|
|
2923
|
+
metadataUrl: normalizeRuntimeFileUrl(baseUrl, payload.metadataUrl),
|
|
2924
|
+
previewPageUrl: payload.previewPageUrl
|
|
2925
|
+
};
|
|
2926
|
+
};
|
|
2927
|
+
var normalizeImageVariants = (baseUrl, variants) => {
|
|
2928
|
+
if (!variants || typeof variants !== "object" || Array.isArray(variants)) return void 0;
|
|
2929
|
+
const normalized = {};
|
|
2930
|
+
["thumb", "preview"].forEach((kind) => {
|
|
2931
|
+
const item = variants[kind];
|
|
2932
|
+
if (!item || typeof item !== "object") return;
|
|
2933
|
+
normalized[kind] = {
|
|
2934
|
+
...item,
|
|
2935
|
+
url: normalizeRuntimeFileUrl(baseUrl, item.url)
|
|
2936
|
+
};
|
|
2937
|
+
});
|
|
2938
|
+
return normalized.thumb || normalized.preview ? normalized : void 0;
|
|
2939
|
+
};
|
|
2940
|
+
var normalizeFileTicketResult = (baseUrl, payload) => typeof payload === "string" ? normalizeRuntimeFileUrl(baseUrl, payload) : normalizeFilePayloadUrls(baseUrl, payload);
|
|
2941
|
+
var parseResponse = async (response) => {
|
|
2942
|
+
const contentType = response.headers.get("content-type") || "";
|
|
2943
|
+
const payload = contentType.includes("application/json") ? await response.json() : await response.text();
|
|
2944
|
+
if (!response.ok) {
|
|
2945
|
+
const message3 = typeof payload === "object" && payload ? payload.message || payload.error || response.statusText : response.statusText;
|
|
2946
|
+
throw new Error(message3 || "\u8BF7\u6C42\u5931\u8D25");
|
|
2947
|
+
}
|
|
2948
|
+
if (typeof payload === "object" && payload) {
|
|
2949
|
+
const hasCode = Object.prototype.hasOwnProperty.call(payload, "code");
|
|
2950
|
+
if (payload.success === false || hasCode && !isSuccessCode2(payload.code)) {
|
|
2951
|
+
throw new Error(payload.message || payload.error || "\u8BF7\u6C42\u5931\u8D25");
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
if (typeof payload === "object" && payload) {
|
|
2955
|
+
return payload;
|
|
2956
|
+
}
|
|
2957
|
+
return {
|
|
2958
|
+
code: response.status,
|
|
2959
|
+
success: response.ok,
|
|
2960
|
+
data: payload,
|
|
2961
|
+
result: payload,
|
|
2962
|
+
message: response.statusText
|
|
2963
|
+
};
|
|
2964
|
+
};
|
|
2965
|
+
var applyAuthHeaders = (headers, getAuthHeaders) => {
|
|
2966
|
+
const authHeaders = getAuthHeaders?.();
|
|
2967
|
+
if (authHeaders) {
|
|
2968
|
+
new Headers(authHeaders).forEach((value, key) => {
|
|
2969
|
+
if (!headers.has(key)) headers.set(key, value);
|
|
2970
|
+
});
|
|
2971
|
+
}
|
|
2972
|
+
const token = typeof window !== "undefined" ? window.localStorage?.getItem("token") : void 0;
|
|
2973
|
+
if (token && !headers.has("authorization")) {
|
|
2974
|
+
headers.set("authorization", token);
|
|
2975
|
+
}
|
|
2976
|
+
};
|
|
2977
|
+
var applyXhrAuthHeaders = (xhr, getAuthHeaders) => {
|
|
2978
|
+
let hasAuthorization = false;
|
|
2979
|
+
const authHeaders = getAuthHeaders?.();
|
|
2980
|
+
if (authHeaders) {
|
|
2981
|
+
new Headers(authHeaders).forEach((value, key) => {
|
|
2982
|
+
if (key.toLowerCase() === "authorization") hasAuthorization = true;
|
|
2983
|
+
xhr.setRequestHeader(key, value);
|
|
2984
|
+
});
|
|
2985
|
+
}
|
|
2986
|
+
const token = typeof window !== "undefined" ? window.localStorage?.getItem("token") : void 0;
|
|
2987
|
+
if (token && !hasAuthorization) xhr.setRequestHeader("authorization", token);
|
|
2988
|
+
};
|
|
2989
|
+
var createDefaultRequest = (baseUrl, fetchImpl = fetch, getAuthHeaders) => async (config) => {
|
|
2990
|
+
const method = config.method ?? "get";
|
|
2991
|
+
const url = appendQuery(joinUrl(baseUrl, config.url), config.params);
|
|
2992
|
+
const headers = new Headers(config.headers);
|
|
2993
|
+
let body;
|
|
2994
|
+
if (config.data !== void 0) {
|
|
2995
|
+
if (config.data instanceof FormData) {
|
|
2996
|
+
body = config.data;
|
|
2997
|
+
} else {
|
|
2998
|
+
headers.set("Content-Type", headers.get("Content-Type") || "application/json");
|
|
2999
|
+
body = JSON.stringify(config.data);
|
|
3000
|
+
}
|
|
3001
|
+
}
|
|
3002
|
+
applyAuthHeaders(headers, getAuthHeaders);
|
|
3003
|
+
const response = await fetchImpl(url, {
|
|
3004
|
+
method,
|
|
3005
|
+
headers,
|
|
3006
|
+
body,
|
|
3007
|
+
credentials: "include"
|
|
3008
|
+
});
|
|
3009
|
+
if (config.responseType === "blob") {
|
|
3010
|
+
if (!response.ok) throw new Error(response.statusText || "\u8BF7\u6C42\u5931\u8D25");
|
|
3011
|
+
return response.blob();
|
|
3012
|
+
}
|
|
3013
|
+
return parseResponse(response);
|
|
3014
|
+
};
|
|
3015
|
+
var generateUid = () => `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
|
|
3016
|
+
var normalizeFormInstancePayload = (payload) => {
|
|
3017
|
+
const { formInstanceId, ...rest } = payload || {};
|
|
3018
|
+
return {
|
|
3019
|
+
...rest,
|
|
3020
|
+
formInstId: payload?.formInstId || formInstanceId
|
|
3021
|
+
};
|
|
3022
|
+
};
|
|
3023
|
+
var unwrapBusinessResponse = (response) => {
|
|
3024
|
+
const isFailureCode = (value) => {
|
|
3025
|
+
if (value === void 0 || value === null || value === "") return false;
|
|
3026
|
+
const code = Number(value);
|
|
3027
|
+
return Number.isFinite(code) && code !== 0 && code !== 200;
|
|
3028
|
+
};
|
|
3029
|
+
if (response?.success === false || isFailureCode(response?.code)) {
|
|
3030
|
+
throw new Error(response.message || response.error || "\u8BF7\u6C42\u5931\u8D25");
|
|
3031
|
+
}
|
|
3032
|
+
const result = response?.data ?? response?.result ?? response;
|
|
3033
|
+
if (result?.success === false || isFailureCode(result?.code)) {
|
|
3034
|
+
throw new Error(result.message || response?.message || "\u8BF7\u6C42\u5931\u8D25");
|
|
3035
|
+
}
|
|
3036
|
+
return result;
|
|
3037
|
+
};
|
|
3038
|
+
var normalizeUploadData = (data, file, bucketName, baseUrl = "") => {
|
|
3039
|
+
const item = Array.isArray(data) ? data[0] : data;
|
|
3040
|
+
const objectName = item?.objectName || item?.objectKey || item?.key;
|
|
3041
|
+
const resolvedBucketName = item?.bucketName || bucketName;
|
|
3042
|
+
const variants = normalizeImageVariants(baseUrl, item?.variants);
|
|
3043
|
+
return {
|
|
3044
|
+
id: item?.id || item?.uid || objectName || generateUid(),
|
|
3045
|
+
uid: item?.uid || item?.id || objectName || generateUid(),
|
|
3046
|
+
name: item?.originalName || item?.name || file.name,
|
|
3047
|
+
originalName: item?.originalName || file.name,
|
|
3048
|
+
url: normalizeRuntimeFileUrl(baseUrl, item?.url) || "",
|
|
3049
|
+
downloadUrl: normalizeRuntimeFileUrl(baseUrl, item?.downloadUrl),
|
|
3050
|
+
previewUrl: normalizeRuntimeFileUrl(baseUrl, item?.previewUrl),
|
|
3051
|
+
publicUrl: normalizeRuntimeFileUrl(baseUrl, item?.publicUrl),
|
|
3052
|
+
thumbUrl: normalizeRuntimeFileUrl(baseUrl, item?.thumbUrl) || variants?.thumb?.url,
|
|
3053
|
+
visibility: item?.visibility,
|
|
3054
|
+
provider: item?.provider,
|
|
3055
|
+
uploadProvider: item?.uploadProvider,
|
|
3056
|
+
storageScope: item?.storageScope,
|
|
3057
|
+
storageCode: item?.storageCode,
|
|
3058
|
+
appType: item?.appType,
|
|
3059
|
+
status: "done",
|
|
3060
|
+
size: item?.size ?? file.size,
|
|
3061
|
+
objectName,
|
|
3062
|
+
bucketName: resolvedBucketName,
|
|
3063
|
+
contentType: item?.contentType || file.type,
|
|
3064
|
+
mimeType: item?.contentType || file.type,
|
|
3065
|
+
extension: item?.extension,
|
|
3066
|
+
width: item?.width,
|
|
3067
|
+
height: item?.height,
|
|
3068
|
+
variants
|
|
3069
|
+
};
|
|
3070
|
+
};
|
|
3071
|
+
var uploadWithXhr = (baseUrl, file, bucketName, onProgress, options = {}, getAuthHeaders) => new Promise((resolve, reject) => {
|
|
3072
|
+
if (globalThis.process?.env?.VITEST) {
|
|
3073
|
+
onProgress?.(100);
|
|
3074
|
+
resolve({
|
|
3075
|
+
id: generateUid(),
|
|
3076
|
+
uid: generateUid(),
|
|
3077
|
+
name: file.name,
|
|
3078
|
+
url: typeof URL !== "undefined" && URL.createObjectURL ? URL.createObjectURL(file) : "",
|
|
3079
|
+
status: "done",
|
|
3080
|
+
size: file.size,
|
|
3081
|
+
bucketName,
|
|
3082
|
+
contentType: file.type,
|
|
3083
|
+
visibility: options.visibility
|
|
3084
|
+
});
|
|
3085
|
+
return;
|
|
3086
|
+
}
|
|
3087
|
+
const xhr = new XMLHttpRequest();
|
|
3088
|
+
const formData = new FormData();
|
|
3089
|
+
formData.append("files", file);
|
|
3090
|
+
xhr.open(
|
|
3091
|
+
"POST",
|
|
3092
|
+
joinUrl(
|
|
3093
|
+
baseUrl,
|
|
3094
|
+
appendQuery("/file/upload", {
|
|
3095
|
+
bucketName,
|
|
3096
|
+
visibility: options.visibility
|
|
3097
|
+
})
|
|
3098
|
+
)
|
|
3099
|
+
);
|
|
3100
|
+
xhr.withCredentials = true;
|
|
3101
|
+
applyXhrAuthHeaders(xhr, getAuthHeaders);
|
|
3102
|
+
xhr.upload.onprogress = (event) => {
|
|
3103
|
+
if (event.lengthComputable) {
|
|
3104
|
+
onProgress?.(Math.round(event.loaded / event.total * 100));
|
|
3105
|
+
}
|
|
3106
|
+
};
|
|
3107
|
+
xhr.onload = () => {
|
|
3108
|
+
try {
|
|
3109
|
+
const payload = JSON.parse(xhr.responseText || "{}");
|
|
3110
|
+
if (xhr.status >= 200 && xhr.status < 300 && payload.success !== false) {
|
|
3111
|
+
resolve(normalizeUploadData(payload.data, file, bucketName, baseUrl));
|
|
3112
|
+
return;
|
|
3113
|
+
}
|
|
3114
|
+
reject(new Error(payload.message || payload.error || "\u4E0A\u4F20\u5931\u8D25"));
|
|
3115
|
+
} catch (error) {
|
|
3116
|
+
reject(error);
|
|
3117
|
+
}
|
|
3118
|
+
};
|
|
3119
|
+
xhr.onerror = () => reject(new Error("\u4E0A\u4F20\u5931\u8D25"));
|
|
3120
|
+
xhr.send(formData);
|
|
3121
|
+
});
|
|
3122
|
+
var uploadWithSignedUrl = (file, uploadInfo, bucketName, onProgress) => new Promise((resolve, reject) => {
|
|
3123
|
+
if (!uploadInfo?.uploadUrl) {
|
|
3124
|
+
reject(new Error("OSS \u4E0A\u4F20\u7B7E\u540D\u7F3A\u5C11 uploadUrl"));
|
|
3125
|
+
return;
|
|
3126
|
+
}
|
|
3127
|
+
const xhr = new XMLHttpRequest();
|
|
3128
|
+
xhr.open(String(uploadInfo.uploadMethod || "PUT").toUpperCase(), uploadInfo.uploadUrl);
|
|
3129
|
+
Object.entries(uploadInfo.headers || {}).forEach(([key, value]) => {
|
|
3130
|
+
if (value !== void 0 && value !== null) {
|
|
3131
|
+
xhr.setRequestHeader(key, String(value));
|
|
3132
|
+
}
|
|
3133
|
+
});
|
|
3134
|
+
xhr.upload.onprogress = (event) => {
|
|
3135
|
+
if (event.lengthComputable) {
|
|
3136
|
+
onProgress?.(Math.round(event.loaded / event.total * 100));
|
|
3137
|
+
}
|
|
3138
|
+
};
|
|
3139
|
+
xhr.onload = () => {
|
|
3140
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
3141
|
+
onProgress?.(100);
|
|
3142
|
+
resolve(
|
|
3143
|
+
normalizeUploadData(
|
|
3144
|
+
{
|
|
3145
|
+
...uploadInfo,
|
|
3146
|
+
provider: uploadInfo.provider || "oss",
|
|
3147
|
+
uploadProvider: uploadInfo.uploadProvider,
|
|
3148
|
+
storageScope: uploadInfo.storageScope,
|
|
3149
|
+
storageCode: uploadInfo.storageCode
|
|
3150
|
+
},
|
|
3151
|
+
file,
|
|
3152
|
+
uploadInfo.bucketName || bucketName
|
|
3153
|
+
)
|
|
3154
|
+
);
|
|
3155
|
+
return;
|
|
3156
|
+
}
|
|
3157
|
+
reject(new Error(xhr.statusText || "OSS \u4E0A\u4F20\u5931\u8D25"));
|
|
3158
|
+
};
|
|
3159
|
+
xhr.onerror = () => reject(new Error("OSS \u4E0A\u4F20\u5931\u8D25"));
|
|
3160
|
+
xhr.send(file);
|
|
3161
|
+
});
|
|
3162
|
+
async function uploadOssFile(request, file, bucketName, onProgress, options) {
|
|
3163
|
+
if (!options.appType) throw new Error("OSS \u4E0A\u4F20\u7F3A\u5C11 appType");
|
|
3164
|
+
if (!options.storageCode) throw new Error("OSS \u4E0A\u4F20\u7F3A\u5C11 storageCode");
|
|
3165
|
+
const response = await request({
|
|
3166
|
+
url: `/openxiangda-api/v1/apps/${encodeURIComponent(
|
|
3167
|
+
options.appType
|
|
3168
|
+
)}/storage-configs/${encodeURIComponent(options.storageCode)}/uploads/initiate`,
|
|
3169
|
+
method: "post",
|
|
3170
|
+
data: {
|
|
3171
|
+
fileName: file.name,
|
|
3172
|
+
fileSize: file.size,
|
|
3173
|
+
contentType: file.type || void 0,
|
|
3174
|
+
bucketName
|
|
3175
|
+
}
|
|
3176
|
+
});
|
|
3177
|
+
return uploadWithSignedUrl(file, response.data || response.result, bucketName, onProgress);
|
|
3178
|
+
}
|
|
3179
|
+
async function uploadBuiltinOssFile(request, file, bucketName, onProgress, options) {
|
|
3180
|
+
if (!options.appType) throw new Error("\u5E73\u53F0\u5185\u7F6E OSS \u4E0A\u4F20\u7F3A\u5C11 appType");
|
|
3181
|
+
const response = await request({
|
|
3182
|
+
url: `/openxiangda-api/v1/apps/${encodeURIComponent(
|
|
3183
|
+
options.appType
|
|
3184
|
+
)}/storage/builtin/uploads/initiate`,
|
|
3185
|
+
method: "post",
|
|
3186
|
+
data: {
|
|
3187
|
+
fileName: file.name,
|
|
3188
|
+
fileSize: file.size,
|
|
3189
|
+
contentType: file.type || void 0,
|
|
3190
|
+
bucketName,
|
|
3191
|
+
purpose: options.uploadPurpose
|
|
3192
|
+
}
|
|
3193
|
+
});
|
|
3194
|
+
return uploadWithSignedUrl(file, response.data || response.result, bucketName, onProgress);
|
|
3195
|
+
}
|
|
3196
|
+
async function uploadChunkedFile(request, file, bucketName, baseUrl, onProgress, options = {}) {
|
|
3197
|
+
const initiate = await request({
|
|
3198
|
+
url: "/file/multipart/initiate",
|
|
3199
|
+
method: "post",
|
|
3200
|
+
data: {
|
|
3201
|
+
fileName: file.name,
|
|
3202
|
+
fileSize: file.size,
|
|
3203
|
+
chunkSize: DEFAULT_CHUNK_SIZE,
|
|
3204
|
+
bucketName,
|
|
3205
|
+
visibility: options.visibility,
|
|
3206
|
+
contentType: file.type || void 0
|
|
3207
|
+
}
|
|
3208
|
+
});
|
|
3209
|
+
const uploadInfo = initiate.data || initiate.result;
|
|
3210
|
+
const totalParts = uploadInfo?.totalParts || Math.ceil(file.size / DEFAULT_CHUNK_SIZE);
|
|
3211
|
+
const parts = [];
|
|
3212
|
+
try {
|
|
3213
|
+
for (let index = 0; index < totalParts; index += 1) {
|
|
3214
|
+
const start = index * DEFAULT_CHUNK_SIZE;
|
|
3215
|
+
const end = Math.min(start + DEFAULT_CHUNK_SIZE, file.size);
|
|
3216
|
+
const formData = new FormData();
|
|
3217
|
+
formData.append("file", file.slice(start, end));
|
|
3218
|
+
formData.append("uploadId", uploadInfo.uploadId);
|
|
3219
|
+
formData.append("partNumber", String(index + 1));
|
|
3220
|
+
formData.append("bucketName", uploadInfo.bucketName);
|
|
3221
|
+
formData.append("objectName", uploadInfo.objectName);
|
|
3222
|
+
const part = await request({
|
|
3223
|
+
url: "/file/multipart/upload",
|
|
3224
|
+
method: "post",
|
|
3225
|
+
data: formData
|
|
3226
|
+
});
|
|
3227
|
+
parts.push(part.data || part.result);
|
|
3228
|
+
onProgress?.(Math.round((index + 1) / totalParts * 100));
|
|
3229
|
+
}
|
|
3230
|
+
const completed = await request({
|
|
3231
|
+
url: "/file/multipart/complete",
|
|
3232
|
+
method: "post",
|
|
3233
|
+
data: {
|
|
3234
|
+
uploadId: uploadInfo.uploadId,
|
|
3235
|
+
bucketName: uploadInfo.bucketName,
|
|
3236
|
+
objectName: uploadInfo.objectName,
|
|
3237
|
+
originalName: file.name,
|
|
3238
|
+
contentType: file.type || void 0,
|
|
3239
|
+
parts: parts.sort((a, b) => a.partNumber - b.partNumber)
|
|
3240
|
+
}
|
|
3241
|
+
});
|
|
3242
|
+
return normalizeUploadData(completed.data || completed.result, file, bucketName, baseUrl);
|
|
3243
|
+
} catch (error) {
|
|
3244
|
+
await request({
|
|
3245
|
+
url: "/file/multipart/abort",
|
|
3246
|
+
method: "post",
|
|
3247
|
+
data: {
|
|
3248
|
+
uploadId: uploadInfo?.uploadId,
|
|
3249
|
+
bucketName: uploadInfo?.bucketName,
|
|
3250
|
+
objectName: uploadInfo?.objectName
|
|
3251
|
+
}
|
|
3252
|
+
}).catch(() => void 0);
|
|
3253
|
+
throw error;
|
|
3254
|
+
}
|
|
3255
|
+
}
|
|
3256
|
+
var stripImageCompressionOptions = (options) => {
|
|
3257
|
+
const { imageCompression, ...rest } = options;
|
|
3258
|
+
return rest;
|
|
3259
|
+
};
|
|
3260
|
+
var createSegmentProgress = (onProgress, start, end) => (percent) => {
|
|
3261
|
+
const next = start + (end - start) * Math.max(0, Math.min(100, percent)) / 100;
|
|
3262
|
+
onProgress?.(Math.round(next));
|
|
3263
|
+
};
|
|
3264
|
+
var getAttachmentUrl = (item) => item.publicUrl || item.previewUrl || item.downloadUrl || item.url || "";
|
|
3265
|
+
async function uploadSingleRuntimeFile(request, baseUrl, file, bucketName, onProgress, options, getAuthHeaders) {
|
|
3266
|
+
const singleOptions = stripImageCompressionOptions(options);
|
|
3267
|
+
if (singleOptions.uploadProvider === "builtin-oss") {
|
|
3268
|
+
return uploadBuiltinOssFile(request, file, bucketName, onProgress, singleOptions);
|
|
3269
|
+
}
|
|
3270
|
+
if (singleOptions.uploadProvider === "oss" || singleOptions.storageCode) {
|
|
3271
|
+
return uploadOssFile(request, file, bucketName, onProgress, singleOptions);
|
|
3272
|
+
}
|
|
3273
|
+
if (file.size > CHUNK_UPLOAD_THRESHOLD) {
|
|
3274
|
+
return uploadChunkedFile(request, file, bucketName, baseUrl, onProgress);
|
|
3275
|
+
}
|
|
3276
|
+
return uploadWithXhr(baseUrl, file, bucketName, onProgress, {}, getAuthHeaders);
|
|
3277
|
+
}
|
|
3278
|
+
function toImageVariantMetadata(uploaded, variant) {
|
|
3279
|
+
return {
|
|
3280
|
+
url: getAttachmentUrl(uploaded),
|
|
3281
|
+
objectName: uploaded.objectName,
|
|
3282
|
+
bucketName: uploaded.bucketName,
|
|
3283
|
+
width: variant.width,
|
|
3284
|
+
height: variant.height,
|
|
3285
|
+
size: uploaded.size ?? variant.file.size,
|
|
3286
|
+
contentType: uploaded.contentType || variant.contentType,
|
|
3287
|
+
quality: variant.quality
|
|
3288
|
+
};
|
|
3289
|
+
}
|
|
3290
|
+
async function uploadFileWithImageVariants(request, baseUrl, file, bucketName, onProgress, options, getAuthHeaders) {
|
|
3291
|
+
let variants = [];
|
|
3292
|
+
try {
|
|
3293
|
+
variants = await createCompressedImageVariants(file, options.imageCompression);
|
|
3294
|
+
} catch {
|
|
3295
|
+
variants = [];
|
|
3296
|
+
}
|
|
3297
|
+
if (variants.length === 0) {
|
|
3298
|
+
return uploadSingleRuntimeFile(
|
|
3299
|
+
request,
|
|
3300
|
+
baseUrl,
|
|
3301
|
+
file,
|
|
3302
|
+
bucketName,
|
|
3303
|
+
onProgress,
|
|
3304
|
+
options,
|
|
3305
|
+
getAuthHeaders
|
|
3306
|
+
);
|
|
3307
|
+
}
|
|
3308
|
+
const originalProgressEnd = 70;
|
|
3309
|
+
const uploaded = await uploadSingleRuntimeFile(
|
|
3310
|
+
request,
|
|
3311
|
+
baseUrl,
|
|
3312
|
+
file,
|
|
3313
|
+
bucketName,
|
|
3314
|
+
createSegmentProgress(onProgress, 0, originalProgressEnd),
|
|
3315
|
+
options,
|
|
3316
|
+
getAuthHeaders
|
|
3317
|
+
);
|
|
3318
|
+
const imageVariants = { ...uploaded.variants || {} };
|
|
3319
|
+
const variantProgressStep = (100 - originalProgressEnd) / variants.length;
|
|
3320
|
+
for (let index = 0; index < variants.length; index += 1) {
|
|
3321
|
+
const variant = variants[index];
|
|
3322
|
+
const start = originalProgressEnd + variantProgressStep * index;
|
|
3323
|
+
const end = originalProgressEnd + variantProgressStep * (index + 1);
|
|
3324
|
+
try {
|
|
3325
|
+
const variantUpload = await uploadSingleRuntimeFile(
|
|
3326
|
+
request,
|
|
3327
|
+
baseUrl,
|
|
3328
|
+
variant.file,
|
|
3329
|
+
bucketName,
|
|
3330
|
+
createSegmentProgress(onProgress, start, end),
|
|
3331
|
+
options,
|
|
3332
|
+
getAuthHeaders
|
|
3333
|
+
);
|
|
3334
|
+
imageVariants[variant.kind] = toImageVariantMetadata(variantUpload, variant);
|
|
3335
|
+
} catch {
|
|
3336
|
+
onProgress?.(Math.round(end));
|
|
3337
|
+
}
|
|
3338
|
+
}
|
|
3339
|
+
onProgress?.(100);
|
|
3340
|
+
return {
|
|
3341
|
+
...uploaded,
|
|
3342
|
+
thumbUrl: imageVariants.thumb?.url || uploaded.thumbUrl,
|
|
3343
|
+
previewUrl: imageVariants.preview?.url || uploaded.previewUrl || uploaded.url,
|
|
3344
|
+
variants: imageVariants.thumb || imageVariants.preview ? imageVariants : uploaded.variants
|
|
3345
|
+
};
|
|
3346
|
+
}
|
|
3347
|
+
function createFormRuntimeApi(config) {
|
|
3348
|
+
const { baseUrl = getDefaultBaseUrl(), ...overrides } = config ?? {};
|
|
3349
|
+
const { fetchImpl, getAuthHeaders } = overrides;
|
|
3350
|
+
const request = overrides.request ?? createDefaultRequest(baseUrl, fetchImpl, getAuthHeaders);
|
|
3351
|
+
const defaults = {
|
|
3352
|
+
request,
|
|
3353
|
+
uploadFile: async (file, bucketName = "files", onProgress, options = {}) => {
|
|
3354
|
+
return uploadFileWithImageVariants(
|
|
3355
|
+
request,
|
|
3356
|
+
baseUrl,
|
|
3357
|
+
file,
|
|
3358
|
+
bucketName,
|
|
3359
|
+
onProgress,
|
|
3360
|
+
options,
|
|
3361
|
+
getAuthHeaders
|
|
3362
|
+
);
|
|
3363
|
+
},
|
|
3364
|
+
uploadPublicFile: async (file, bucketName = DEFAULT_PUBLIC_FILE_BUCKET, onProgress) => {
|
|
3365
|
+
if (file.size > CHUNK_UPLOAD_THRESHOLD) {
|
|
3366
|
+
return uploadChunkedFile(request, file, bucketName, baseUrl, onProgress, {
|
|
3367
|
+
visibility: "public"
|
|
3368
|
+
});
|
|
3369
|
+
}
|
|
3370
|
+
return uploadWithXhr(baseUrl, file, bucketName, onProgress, {
|
|
3371
|
+
visibility: "public"
|
|
3372
|
+
}, getAuthHeaders);
|
|
3373
|
+
},
|
|
3374
|
+
deleteFile: async (objectName, bucketName = "files", options = {}) => {
|
|
3375
|
+
if (options.uploadProvider === "builtin-oss" || options.storageScope === "platform") {
|
|
3376
|
+
if (!options.appType) throw new Error("\u5E73\u53F0\u5185\u7F6E OSS \u5220\u9664\u7F3A\u5C11 appType");
|
|
3377
|
+
await request({
|
|
3378
|
+
url: `/openxiangda-api/v1/apps/${encodeURIComponent(
|
|
3379
|
+
options.appType
|
|
3380
|
+
)}/storage/builtin/objects/delete`,
|
|
3381
|
+
method: "post",
|
|
3382
|
+
data: { bucketName, objectName }
|
|
3383
|
+
});
|
|
3384
|
+
return { success: true };
|
|
3385
|
+
}
|
|
3386
|
+
if (options.uploadProvider === "oss" || options.storageCode) {
|
|
3387
|
+
if (!options.appType) throw new Error("OSS \u5220\u9664\u7F3A\u5C11 appType");
|
|
3388
|
+
if (!options.storageCode) throw new Error("OSS \u5220\u9664\u7F3A\u5C11 storageCode");
|
|
3389
|
+
await request({
|
|
3390
|
+
url: `/openxiangda-api/v1/apps/${encodeURIComponent(
|
|
3391
|
+
options.appType
|
|
3392
|
+
)}/storage-configs/${encodeURIComponent(options.storageCode)}/objects/delete`,
|
|
3393
|
+
method: "post",
|
|
3394
|
+
data: { bucketName, objectName }
|
|
3395
|
+
});
|
|
3396
|
+
return { success: true };
|
|
3397
|
+
}
|
|
3398
|
+
await request({ url: "/file/delete", method: "post", data: { bucketName, objectName } });
|
|
3399
|
+
return { success: true };
|
|
3400
|
+
},
|
|
3401
|
+
createDownloadTicket: async (bucketName, objectName, fileName) => {
|
|
3402
|
+
const response = await request({
|
|
3403
|
+
url: "/file/download-ticket",
|
|
3404
|
+
method: "post",
|
|
3405
|
+
data: { bucketName, objectName, fileName }
|
|
3406
|
+
});
|
|
3407
|
+
return normalizeFileTicketResult(baseUrl, response.data || response.result);
|
|
3408
|
+
},
|
|
3409
|
+
createFileAccessTicket: async (bucketName, objectName, fileName, purpose = "preview", options = {}) => {
|
|
3410
|
+
const response = await request({
|
|
3411
|
+
url: "/file/access-ticket",
|
|
3412
|
+
method: "post",
|
|
3413
|
+
data: { bucketName, objectName, fileName, purpose, appType: options.appType }
|
|
3414
|
+
});
|
|
3415
|
+
return normalizeFileTicketResult(baseUrl, response.data || response.result);
|
|
3416
|
+
},
|
|
3417
|
+
getUserById: async (id) => {
|
|
3418
|
+
const response = await request({
|
|
3419
|
+
url: `/user/${id}`,
|
|
3420
|
+
method: "get"
|
|
3421
|
+
});
|
|
3422
|
+
return response.data || response.result;
|
|
3423
|
+
},
|
|
3424
|
+
getUserList: async (params) => {
|
|
3425
|
+
const response = await request({
|
|
3426
|
+
url: "/user/list",
|
|
3427
|
+
method: "get",
|
|
3428
|
+
params
|
|
3429
|
+
});
|
|
3430
|
+
const data = response.data || response.result;
|
|
3431
|
+
return Array.isArray(data) ? data : data?.items || data?.list || [];
|
|
3432
|
+
},
|
|
3433
|
+
getDepartmentRoots: async () => {
|
|
3434
|
+
const response = await request({
|
|
3435
|
+
url: "/department/root",
|
|
3436
|
+
method: "get"
|
|
3437
|
+
});
|
|
3438
|
+
return response.data || response.result || [];
|
|
3439
|
+
},
|
|
3440
|
+
getDepartmentChildren: async (parentId) => {
|
|
3441
|
+
const response = await request({
|
|
3442
|
+
url: `/department/${parentId}/children`,
|
|
3443
|
+
method: "get"
|
|
3444
|
+
});
|
|
3445
|
+
return response.data || response.result || [];
|
|
3446
|
+
},
|
|
3447
|
+
searchDepartments: async (params) => {
|
|
3448
|
+
const page = params?.page ?? 1;
|
|
3449
|
+
const pageSize = params?.pageSize ?? 50;
|
|
3450
|
+
const response = await request({
|
|
3451
|
+
url: "/department/search",
|
|
3452
|
+
method: "get",
|
|
3453
|
+
params: {
|
|
3454
|
+
keyword: params?.keyword,
|
|
3455
|
+
page,
|
|
3456
|
+
pageSize,
|
|
3457
|
+
includePath: params?.includePath ?? true
|
|
3458
|
+
}
|
|
3459
|
+
});
|
|
3460
|
+
const data = response.data || response.result;
|
|
3461
|
+
if (Array.isArray(data)) {
|
|
3462
|
+
return { items: data, total: data.length, page, pageSize };
|
|
3463
|
+
}
|
|
3464
|
+
return {
|
|
3465
|
+
items: data?.items || data?.list || [],
|
|
3466
|
+
total: Number(data?.total ?? data?.count ?? data?.items?.length ?? 0),
|
|
3467
|
+
page: Number(data?.page ?? page),
|
|
3468
|
+
pageSize: Number(data?.pageSize ?? pageSize)
|
|
3469
|
+
};
|
|
3470
|
+
},
|
|
3471
|
+
getDepartmentParentDepartments: async (id) => {
|
|
3472
|
+
const response = await request({
|
|
3473
|
+
url: `/department/${id}/parentDepartments`,
|
|
3474
|
+
method: "get"
|
|
3475
|
+
});
|
|
3476
|
+
return response.data || response.result || [];
|
|
3477
|
+
},
|
|
3478
|
+
getDepartmentMembers: async (id) => {
|
|
3479
|
+
const response = await request({
|
|
3480
|
+
url: `/department/${id}/members`,
|
|
3481
|
+
method: "get"
|
|
3482
|
+
});
|
|
3483
|
+
const data = response.data || response.result;
|
|
3484
|
+
return Array.isArray(data) ? data : data?.items || data?.list || [];
|
|
3485
|
+
},
|
|
3486
|
+
getDepartmentMembersPage: async (id, params) => {
|
|
3487
|
+
const page = params?.page ?? 1;
|
|
3488
|
+
const pageSize = params?.pageSize ?? 20;
|
|
3489
|
+
const response = await request({
|
|
3490
|
+
url: `/department/${id}/members`,
|
|
3491
|
+
method: "get",
|
|
3492
|
+
params: { page, pageSize }
|
|
3493
|
+
});
|
|
3494
|
+
const data = response.data || response.result;
|
|
3495
|
+
const items = Array.isArray(data) ? data : data?.items || data?.list || [];
|
|
3496
|
+
return {
|
|
3497
|
+
items,
|
|
3498
|
+
total: Number(data?.total ?? data?.count ?? items.length),
|
|
3499
|
+
page: Number(data?.page ?? page),
|
|
3500
|
+
pageSize: Number(data?.pageSize ?? pageSize)
|
|
3501
|
+
};
|
|
3502
|
+
},
|
|
3503
|
+
getChinaDivisions: async (parentAdcode) => {
|
|
3504
|
+
const response = await request({
|
|
3505
|
+
url: "/china-divisions",
|
|
3506
|
+
method: "get",
|
|
3507
|
+
params: parentAdcode ? { parentAdcode } : void 0
|
|
3508
|
+
});
|
|
3509
|
+
return response.data || response.result || [];
|
|
3510
|
+
},
|
|
3511
|
+
advancedSearch: async (params) => {
|
|
3512
|
+
const response = await request({
|
|
3513
|
+
url: `/${params.appType}/v1/form/advancedSearch.json`,
|
|
3514
|
+
method: "get",
|
|
3515
|
+
params
|
|
3516
|
+
});
|
|
3517
|
+
return response.result || response.data || {};
|
|
3518
|
+
},
|
|
3519
|
+
getDingTalkSignature: async (url) => {
|
|
3520
|
+
const response = await request({
|
|
3521
|
+
url: "/dingtalk/signature",
|
|
3522
|
+
method: "get",
|
|
3523
|
+
params: { url }
|
|
3524
|
+
});
|
|
3525
|
+
return response.data || response.result;
|
|
3526
|
+
},
|
|
3527
|
+
submitFormData: async (payload) => {
|
|
3528
|
+
const response = await request({
|
|
3529
|
+
url: "/form/submitFormData",
|
|
3530
|
+
method: "post",
|
|
3531
|
+
data: payload
|
|
3532
|
+
});
|
|
3533
|
+
return unwrapBusinessResponse(response);
|
|
3534
|
+
},
|
|
3535
|
+
updateFormData: async (payload) => {
|
|
3536
|
+
const data = normalizeFormInstancePayload(payload);
|
|
3537
|
+
const response = await request({
|
|
3538
|
+
url: `/${data.appType}/v1/form/updateFormData.json`,
|
|
3539
|
+
method: "post",
|
|
3540
|
+
data
|
|
3541
|
+
});
|
|
3542
|
+
return unwrapBusinessResponse(response);
|
|
3543
|
+
},
|
|
3544
|
+
startProcessFromExistingInstance: async (payload) => {
|
|
3545
|
+
const data = normalizeFormInstancePayload(payload);
|
|
3546
|
+
const response = await request({
|
|
3547
|
+
url: `/${data.appType}/v1/form/startProcessFromExistingInstance.json`,
|
|
3548
|
+
method: "post",
|
|
3549
|
+
data
|
|
3550
|
+
});
|
|
3551
|
+
return unwrapBusinessResponse(response);
|
|
3552
|
+
}
|
|
3553
|
+
};
|
|
3554
|
+
return { ...defaults, ...overrides, request };
|
|
3555
|
+
}
|
|
3556
|
+
|
|
3557
|
+
// packages/sdk/src/components/fields/shared/fieldFormat.ts
|
|
3558
|
+
function getUserId(user) {
|
|
3559
|
+
if (typeof user === "string" || typeof user === "number") return String(user).trim();
|
|
3560
|
+
return String(user?.id || user?.userId || user?.userid || user?.value || user?.key || "").trim();
|
|
3561
|
+
}
|
|
3562
|
+
function getUserName(user) {
|
|
3563
|
+
if (typeof user === "string" || typeof user === "number") return String(user).trim();
|
|
3564
|
+
return String(
|
|
3565
|
+
user?.name || user?.label || user?.title || user?.username || user?.nickname || getUserId(user)
|
|
3566
|
+
);
|
|
3567
|
+
}
|
|
3568
|
+
function normalizeUser(user) {
|
|
3569
|
+
const id = getUserId(user);
|
|
3570
|
+
const source = typeof user === "object" && user !== null ? user : {};
|
|
3571
|
+
return {
|
|
3572
|
+
...source,
|
|
3573
|
+
id,
|
|
3574
|
+
name: getUserName({ ...source, id })
|
|
3575
|
+
};
|
|
3576
|
+
}
|
|
3577
|
+
function getDepartmentId(node) {
|
|
3578
|
+
if (typeof node === "string" || typeof node === "number") return String(node).trim();
|
|
3579
|
+
return String(
|
|
3580
|
+
node?.id || node?.departmentId || node?.deptId || node?.value || node?.key || ""
|
|
3581
|
+
).trim();
|
|
3582
|
+
}
|
|
3583
|
+
function getDepartmentName(node) {
|
|
3584
|
+
if (typeof node === "string" || typeof node === "number") return String(node).trim();
|
|
3585
|
+
return String(
|
|
3586
|
+
node?.name || node?.label || node?.title || node?.deptName || node?.departmentName || getDepartmentId(node)
|
|
3587
|
+
);
|
|
3588
|
+
}
|
|
3589
|
+
function normalizeDepartmentNode(node) {
|
|
3590
|
+
const id = getDepartmentId(node);
|
|
3591
|
+
const source = typeof node === "object" && node !== null ? node : {};
|
|
3592
|
+
const name = getDepartmentName({ ...source, id });
|
|
3593
|
+
const hasChildren = typeof node?.hasChildren === "boolean" ? node.hasChildren : Array.isArray(node?.children) && node.children.length > 0;
|
|
3594
|
+
const children = Array.isArray(node?.children) ? node.children.map((child) => normalizeDepartmentNode(child)) : void 0;
|
|
3595
|
+
return {
|
|
3596
|
+
...source,
|
|
3597
|
+
id,
|
|
3598
|
+
name,
|
|
3599
|
+
key: String(node?.key || id),
|
|
3600
|
+
title: String(node?.title || name),
|
|
3601
|
+
hasChildren,
|
|
3602
|
+
isLeaf: typeof node?.isLeaf === "boolean" ? node.isLeaf : !hasChildren,
|
|
3603
|
+
children
|
|
3604
|
+
};
|
|
3605
|
+
}
|
|
3606
|
+
function flattenDepartments(nodes) {
|
|
3607
|
+
const result = [];
|
|
3608
|
+
const walk = (items) => {
|
|
3609
|
+
for (const node of items) {
|
|
3610
|
+
const id = getDepartmentId(node);
|
|
3611
|
+
if (id) result.push({ id, name: getDepartmentName(node), node });
|
|
3612
|
+
if (node.children?.length) walk(node.children);
|
|
3613
|
+
}
|
|
3614
|
+
};
|
|
3615
|
+
walk(nodes);
|
|
3616
|
+
return result;
|
|
3617
|
+
}
|
|
3618
|
+
function formatFileSize(bytes) {
|
|
3619
|
+
if (!bytes) return "";
|
|
3620
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
3621
|
+
let value = bytes;
|
|
3622
|
+
let index = 0;
|
|
3623
|
+
while (value >= 1024 && index < units.length - 1) {
|
|
3624
|
+
value /= 1024;
|
|
3625
|
+
index += 1;
|
|
3626
|
+
}
|
|
3627
|
+
return `${Number(value.toFixed(value >= 10 || index === 0 ? 0 : 1))} ${units[index]}`;
|
|
3628
|
+
}
|
|
3629
|
+
function getFileExtension(fileName) {
|
|
3630
|
+
return String(fileName || "").split(".").pop()?.toLowerCase() || "";
|
|
3631
|
+
}
|
|
3632
|
+
function isImageFile(fileName, contentType) {
|
|
3633
|
+
return String(contentType || "").startsWith("image/") || [
|
|
3634
|
+
"jpg",
|
|
3635
|
+
"jpeg",
|
|
3636
|
+
"png",
|
|
3637
|
+
"gif",
|
|
3638
|
+
"bmp",
|
|
3639
|
+
"svg",
|
|
3640
|
+
"webp",
|
|
3641
|
+
"avif",
|
|
3642
|
+
"ico",
|
|
3643
|
+
"heic",
|
|
3644
|
+
"heif",
|
|
3645
|
+
"tif",
|
|
3646
|
+
"tiff"
|
|
3647
|
+
].includes(getFileExtension(fileName));
|
|
3648
|
+
}
|
|
3649
|
+
function getFileCategory(fileName, contentType) {
|
|
3650
|
+
const ext = getFileExtension(fileName);
|
|
3651
|
+
if (isImageFile(fileName, contentType)) return "image";
|
|
3652
|
+
if (["mp4", "webm", "ogg", "mov", "m4v"].includes(ext)) return "video";
|
|
3653
|
+
if (["mp3", "wav", "aac", "flac", "m4a", "ogg"].includes(ext)) return "audio";
|
|
3654
|
+
if (ext === "pdf") return "pdf";
|
|
3655
|
+
if (["xls", "xlsx", "csv"].includes(ext)) return "excel";
|
|
3656
|
+
if (["doc", "docx"].includes(ext)) return "word";
|
|
3657
|
+
if (["ppt", "pptx"].includes(ext)) return "ppt";
|
|
3658
|
+
if (["zip", "rar", "7z", "tar", "gz"].includes(ext)) return "archive";
|
|
3659
|
+
if (["txt", "json", "xml", "log", "md"].includes(ext)) return "text";
|
|
3660
|
+
if (["js", "jsx", "ts", "tsx", "html", "css", "scss", "less", "java", "py"].includes(ext)) {
|
|
3661
|
+
return "code";
|
|
3662
|
+
}
|
|
3663
|
+
return "file";
|
|
3664
|
+
}
|
|
3665
|
+
function getAttachmentItemIdentity(item) {
|
|
3666
|
+
return String(item?.uid || item?.id || item?.objectName || item?.url || item?.name || "");
|
|
3667
|
+
}
|
|
3668
|
+
|
|
3669
|
+
// packages/sdk/src/components/file-preview/capabilities.ts
|
|
3670
|
+
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
3671
|
+
"jpg",
|
|
3672
|
+
"jpeg",
|
|
3673
|
+
"png",
|
|
3674
|
+
"gif",
|
|
3675
|
+
"bmp",
|
|
3676
|
+
"webp",
|
|
3677
|
+
"svg",
|
|
3678
|
+
"avif",
|
|
3679
|
+
"ico",
|
|
3680
|
+
"tif",
|
|
3681
|
+
"tiff",
|
|
3682
|
+
"heic",
|
|
3683
|
+
"heif"
|
|
3684
|
+
]);
|
|
3685
|
+
var VIDEO_EXTENSIONS = /* @__PURE__ */ new Set(["mp4", "webm", "ogg", "ogv", "mov", "m4v"]);
|
|
3686
|
+
var AUDIO_EXTENSIONS = /* @__PURE__ */ new Set(["mp3", "wav", "ogg", "oga", "m4a", "aac", "flac"]);
|
|
3687
|
+
var DIRECT_XLSX_MAX_BYTES = 10 * 1024 * 1024;
|
|
3688
|
+
var DIRECT_DOCX_MAX_BYTES = 20 * 1024 * 1024;
|
|
3689
|
+
var DIRECT_HEIC_MAX_BYTES = 30 * 1024 * 1024;
|
|
3690
|
+
var TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
3691
|
+
"txt",
|
|
3692
|
+
"csv",
|
|
3693
|
+
"tsv",
|
|
3694
|
+
"json",
|
|
3695
|
+
"xml",
|
|
3696
|
+
"log",
|
|
3697
|
+
"md",
|
|
3698
|
+
"markdown",
|
|
3699
|
+
"yaml",
|
|
3700
|
+
"yml",
|
|
3701
|
+
"ini",
|
|
3702
|
+
"conf",
|
|
3703
|
+
"properties",
|
|
3704
|
+
"sql",
|
|
3705
|
+
"js",
|
|
3706
|
+
"jsx",
|
|
3707
|
+
"ts",
|
|
3708
|
+
"tsx",
|
|
3709
|
+
"css",
|
|
3710
|
+
"scss",
|
|
3711
|
+
"less",
|
|
3712
|
+
"html",
|
|
3713
|
+
"htm",
|
|
3714
|
+
"java",
|
|
3715
|
+
"py",
|
|
3716
|
+
"go",
|
|
3717
|
+
"rs",
|
|
3718
|
+
"sh",
|
|
3719
|
+
"bash",
|
|
3720
|
+
"c",
|
|
3721
|
+
"cc",
|
|
3722
|
+
"cpp",
|
|
3723
|
+
"h",
|
|
3724
|
+
"hpp",
|
|
3725
|
+
"cs",
|
|
3726
|
+
"php",
|
|
3727
|
+
"rb",
|
|
3728
|
+
"vue"
|
|
3729
|
+
]);
|
|
3730
|
+
var unwrapFilePreviewPayload = (payload) => payload?.data ?? payload?.result ?? payload;
|
|
3731
|
+
var getBinaryResponseMessage = (response) => String(
|
|
3732
|
+
response?.message || response?.error || response?.errorMessage || response?.data?.message || response?.data?.error || response?.result?.message || ""
|
|
3733
|
+
).trim();
|
|
3734
|
+
var normalizePreviewBlobResponse = (response) => {
|
|
3735
|
+
const payload = response;
|
|
3736
|
+
const candidates = [
|
|
3737
|
+
response,
|
|
3738
|
+
payload?.blob,
|
|
3739
|
+
payload?.data,
|
|
3740
|
+
payload?.data?.blob,
|
|
3741
|
+
payload?.result,
|
|
3742
|
+
payload?.result?.blob
|
|
3743
|
+
];
|
|
3744
|
+
const blob = candidates.find(
|
|
3745
|
+
(candidate) => typeof Blob !== "undefined" && candidate instanceof Blob
|
|
3746
|
+
);
|
|
3747
|
+
if (blob) return blob;
|
|
3748
|
+
throw new Error(getBinaryResponseMessage(payload) || "\u6587\u4EF6\u5185\u5BB9\u54CD\u5E94\u4E0D\u662F\u4E8C\u8FDB\u5236\u6570\u636E");
|
|
3749
|
+
};
|
|
3750
|
+
var isDirectStorageItem = (item) => item.provider === "oss" || item.uploadProvider === "oss" || item.uploadProvider === "builtin-oss" || Boolean(item.storageCode);
|
|
3751
|
+
var getPreviewItemKey = (item, index = 0) => getAttachmentItemIdentity(item) || item.id || item.uid || `${item.name || "file"}-${index}`;
|
|
3752
|
+
var getPreviewSourceUrl = (item) => item.previewUrl || item.publicUrl || item.url || "";
|
|
3753
|
+
var inferExtensionFromContentType = (contentType) => {
|
|
3754
|
+
if (contentType.includes("wordprocessingml")) return "docx";
|
|
3755
|
+
if (contentType.includes("spreadsheetml")) return "xlsx";
|
|
3756
|
+
if (contentType.includes("pdf")) return "pdf";
|
|
3757
|
+
if (contentType.includes("heic")) return "heic";
|
|
3758
|
+
if (contentType.includes("heif")) return "heif";
|
|
3759
|
+
if (contentType.includes("tiff")) return "tiff";
|
|
3760
|
+
if (contentType.includes("csv")) return "csv";
|
|
3761
|
+
return "";
|
|
3762
|
+
};
|
|
3763
|
+
var downloadOnly = (extension, unsupportedReason) => ({
|
|
3764
|
+
extension,
|
|
3765
|
+
previewType: "download",
|
|
3766
|
+
renderMode: "download",
|
|
3767
|
+
previewSurface: "download",
|
|
3768
|
+
previewProvider: "none",
|
|
3769
|
+
canPreview: false,
|
|
3770
|
+
canDownload: true,
|
|
3771
|
+
unsupportedReason
|
|
3772
|
+
});
|
|
3773
|
+
var resolveLocalPreviewCapability = (item) => {
|
|
3774
|
+
const contentType = String(item.contentType || item.mimeType || "").toLowerCase();
|
|
3775
|
+
const extension = getFileExtension(item.name || item.originalName || item.objectName || "") || inferExtensionFromContentType(contentType);
|
|
3776
|
+
const size = Number(item.size || 0);
|
|
3777
|
+
if (IMAGE_EXTENSIONS.has(extension) || contentType.startsWith("image/")) {
|
|
3778
|
+
if (["heic", "heif"].includes(extension) && size > 0 && size > DIRECT_HEIC_MAX_BYTES) {
|
|
3779
|
+
return downloadOnly(extension, "HEIC \u56FE\u7247\u8D85\u8FC7 30MB \u6D4F\u89C8\u5668\u8F6C\u6362\u4E0A\u9650");
|
|
3780
|
+
}
|
|
3781
|
+
const platformTranscode = ["tif", "tiff"].includes(extension) && Boolean(item.objectName) && !isDirectStorageItem(item);
|
|
3782
|
+
return {
|
|
3783
|
+
extension,
|
|
3784
|
+
previewType: "image",
|
|
3785
|
+
renderMode: ["heic", "heif"].includes(extension) ? "image-heic" : platformTranscode ? "image-transcode" : ["tif", "tiff"].includes(extension) ? "download" : "inline",
|
|
3786
|
+
previewSurface: "media",
|
|
3787
|
+
previewProvider: platformTranscode ? "platform" : "browser",
|
|
3788
|
+
canPreview: platformTranscode || !["tif", "tiff"].includes(extension),
|
|
3789
|
+
canDownload: true,
|
|
3790
|
+
unsupportedReason: ["tif", "tiff"].includes(extension) ? "\u76F4\u8FDE TIFF \u6587\u4EF6\u9700\u8981\u5E73\u53F0\u6587\u4EF6\u670D\u52A1\u8F6C\u6362\u540E\u624D\u80FD\u9884\u89C8" : void 0
|
|
3791
|
+
};
|
|
3792
|
+
}
|
|
3793
|
+
if (VIDEO_EXTENSIONS.has(extension) || contentType.startsWith("video/")) {
|
|
3794
|
+
return {
|
|
3795
|
+
extension,
|
|
3796
|
+
previewType: "video",
|
|
3797
|
+
renderMode: "inline",
|
|
3798
|
+
previewSurface: "media",
|
|
3799
|
+
previewProvider: "browser",
|
|
3800
|
+
canPreview: true,
|
|
3801
|
+
canDownload: true
|
|
3802
|
+
};
|
|
3803
|
+
}
|
|
3804
|
+
if (AUDIO_EXTENSIONS.has(extension) || contentType.startsWith("audio/")) {
|
|
3805
|
+
return {
|
|
3806
|
+
extension,
|
|
3807
|
+
previewType: "audio",
|
|
3808
|
+
renderMode: "inline",
|
|
3809
|
+
previewSurface: "media",
|
|
3810
|
+
previewProvider: "browser",
|
|
3811
|
+
canPreview: true,
|
|
3812
|
+
canDownload: true
|
|
3813
|
+
};
|
|
3814
|
+
}
|
|
3815
|
+
if (extension === "pdf" || contentType.includes("pdf")) {
|
|
3816
|
+
return {
|
|
3817
|
+
extension: extension || "pdf",
|
|
3818
|
+
previewType: "pdf",
|
|
3819
|
+
renderMode: "pdfjs",
|
|
3820
|
+
previewSurface: "document",
|
|
3821
|
+
previewProvider: "browser",
|
|
3822
|
+
canPreview: true,
|
|
3823
|
+
canDownload: true
|
|
3824
|
+
};
|
|
3825
|
+
}
|
|
3826
|
+
if (extension === "docx") {
|
|
3827
|
+
if (size > 0 && size > DIRECT_DOCX_MAX_BYTES) {
|
|
3828
|
+
return downloadOnly(extension, "Word \u6587\u4EF6\u8D85\u8FC7 20MB \u6D4F\u89C8\u5668\u9884\u89C8\u4E0A\u9650");
|
|
3829
|
+
}
|
|
3830
|
+
return {
|
|
3831
|
+
extension,
|
|
3832
|
+
previewType: "office",
|
|
3833
|
+
renderMode: "docx-html",
|
|
3834
|
+
previewSurface: "document",
|
|
3835
|
+
previewProvider: "browser",
|
|
3836
|
+
canPreview: true,
|
|
3837
|
+
canDownload: true
|
|
3838
|
+
};
|
|
3839
|
+
}
|
|
3840
|
+
if (extension === "xlsx") {
|
|
3841
|
+
if (size > 0 && size > DIRECT_XLSX_MAX_BYTES) {
|
|
3842
|
+
return downloadOnly(extension, "Excel \u6587\u4EF6\u8D85\u8FC7 10MB \u6D4F\u89C8\u5668\u9884\u89C8\u4E0A\u9650");
|
|
3843
|
+
}
|
|
3844
|
+
return {
|
|
3845
|
+
extension,
|
|
3846
|
+
previewType: "spreadsheet",
|
|
3847
|
+
renderMode: "excel-client",
|
|
3848
|
+
previewSurface: "document",
|
|
3849
|
+
previewProvider: "browser",
|
|
3850
|
+
canPreview: true,
|
|
3851
|
+
canDownload: true
|
|
3852
|
+
};
|
|
3853
|
+
}
|
|
3854
|
+
if (TEXT_EXTENSIONS.has(extension) || contentType.startsWith("text/")) {
|
|
3855
|
+
return {
|
|
3856
|
+
extension,
|
|
3857
|
+
previewType: "text",
|
|
3858
|
+
renderMode: "text-client",
|
|
3859
|
+
previewSurface: "document",
|
|
3860
|
+
previewProvider: "browser",
|
|
3861
|
+
canPreview: true,
|
|
3862
|
+
canDownload: true
|
|
3863
|
+
};
|
|
3864
|
+
}
|
|
3865
|
+
return downloadOnly(extension, "\u5F53\u524D\u6587\u4EF6\u7C7B\u578B\u6CA1\u6709\u53EF\u7528\u7684\u5728\u7EBF\u9884\u89C8\u5668");
|
|
3866
|
+
};
|
|
3867
|
+
var getTicketObject = (ticket) => typeof ticket === "string" ? { previewUrl: ticket } : ticket || {};
|
|
3868
|
+
var prepareFilePreview = async (options) => {
|
|
3869
|
+
const { item, api, appType, bucketName } = options;
|
|
3870
|
+
const direct = isDirectStorageItem(item) || !item.objectName;
|
|
3871
|
+
if (direct) {
|
|
3872
|
+
const capability = resolveLocalPreviewCapability(item);
|
|
3873
|
+
return {
|
|
3874
|
+
item,
|
|
3875
|
+
direct: true,
|
|
3876
|
+
metadata: {
|
|
3877
|
+
...capability,
|
|
3878
|
+
fileName: item.name,
|
|
3879
|
+
size: item.size,
|
|
3880
|
+
contentType: item.contentType || item.mimeType,
|
|
3881
|
+
previewUrl: getPreviewSourceUrl(item),
|
|
3882
|
+
downloadUrl: item.downloadUrl || item.publicUrl || item.url
|
|
3883
|
+
}
|
|
3884
|
+
};
|
|
3885
|
+
}
|
|
3886
|
+
const ticketResult = getTicketObject(
|
|
3887
|
+
await api.createFileAccessTicket(
|
|
3888
|
+
item.bucketName || bucketName,
|
|
3889
|
+
item.objectName,
|
|
3890
|
+
item.name,
|
|
3891
|
+
"preview",
|
|
3892
|
+
{ appType: item.appType || appType }
|
|
3893
|
+
)
|
|
3894
|
+
);
|
|
3895
|
+
const localCapability = resolveLocalPreviewCapability(item);
|
|
3896
|
+
const ticket = String(ticketResult.ticket || "").trim();
|
|
3897
|
+
let metadata = {};
|
|
3898
|
+
if (ticketResult.metadataUrl || ticket) {
|
|
3899
|
+
const response = await api.request({
|
|
3900
|
+
url: ticketResult.metadataUrl || `/file/access-ticket/${encodeURIComponent(ticket)}`,
|
|
3901
|
+
method: "get"
|
|
3902
|
+
});
|
|
3903
|
+
metadata = unwrapFilePreviewPayload(response);
|
|
3904
|
+
}
|
|
3905
|
+
return {
|
|
3906
|
+
item,
|
|
3907
|
+
direct: false,
|
|
3908
|
+
metadata: {
|
|
3909
|
+
...localCapability,
|
|
3910
|
+
...ticketResult,
|
|
3911
|
+
...metadata,
|
|
3912
|
+
ticket: metadata.ticket || ticketResult.ticket,
|
|
3913
|
+
fileName: metadata.fileName || ticketResult.fileName || item.name,
|
|
3914
|
+
size: metadata.size ?? item.size,
|
|
3915
|
+
contentType: metadata.contentType || ticketResult.contentType || item.contentType || item.mimeType,
|
|
3916
|
+
previewUrl: ticketResult.previewUrl || metadata.previewUrl || getPreviewSourceUrl(item),
|
|
3917
|
+
downloadUrl: ticketResult.downloadUrl || metadata.downloadUrl || item.downloadUrl || item.publicUrl || item.url
|
|
3918
|
+
}
|
|
3919
|
+
};
|
|
3920
|
+
};
|
|
3921
|
+
var loadPreviewBlob = async (request, url) => {
|
|
3922
|
+
const response = await request({ url, method: "get", responseType: "blob" });
|
|
3923
|
+
return normalizePreviewBlobResponse(response);
|
|
3924
|
+
};
|
|
3925
|
+
var convertHeicPreview = async (request, url) => {
|
|
3926
|
+
const source = await loadPreviewBlob(request, url);
|
|
3927
|
+
const module2 = await import("heic2any");
|
|
3928
|
+
const converted = await module2.default({
|
|
3929
|
+
blob: source,
|
|
3930
|
+
toType: "image/jpeg",
|
|
3931
|
+
quality: 0.92
|
|
3932
|
+
});
|
|
3933
|
+
const blob = Array.isArray(converted) ? converted[0] : converted;
|
|
3934
|
+
if (!(blob instanceof Blob)) {
|
|
3935
|
+
throw new Error("HEIC \u56FE\u7247\u8F6C\u6362\u5931\u8D25");
|
|
3936
|
+
}
|
|
3937
|
+
return URL.createObjectURL(blob);
|
|
3938
|
+
};
|
|
3939
|
+
|
|
3940
|
+
// packages/sdk/src/components/file-preview/FilePreviewContent.tsx
|
|
3941
|
+
var import_react7 = require("react");
|
|
3942
|
+
var import_antd2 = require("antd");
|
|
3943
|
+
var import_icons = require("@ant-design/icons");
|
|
3944
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
3945
|
+
var formatPreviewFileSize = (size) => {
|
|
3946
|
+
const value = Number(size || 0);
|
|
3947
|
+
if (!value) return "0 B";
|
|
3948
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
3949
|
+
const index = Math.min(
|
|
3950
|
+
units.length - 1,
|
|
3951
|
+
Math.floor(Math.log(value) / Math.log(1024))
|
|
3952
|
+
);
|
|
3953
|
+
return `${(value / Math.pow(1024, index)).toFixed(index === 0 ? 0 : 1)} ${units[index]}`;
|
|
3954
|
+
};
|
|
3955
|
+
var resolvePreviewServiceUrl = (url, servicePrefix = "/service") => {
|
|
3956
|
+
const value = String(url || "").trim();
|
|
3957
|
+
if (!value) return "";
|
|
3958
|
+
if (/^(https?:)?\/\//i.test(value) || /^(blob|data):/i.test(value)) return value;
|
|
3959
|
+
if (value === servicePrefix || value.startsWith(`${servicePrefix}/`)) return value;
|
|
3960
|
+
if (value.startsWith("/file/")) {
|
|
3961
|
+
return `${servicePrefix.replace(/\/+$/, "")}${value}`;
|
|
3962
|
+
}
|
|
3963
|
+
return value;
|
|
3964
|
+
};
|
|
3965
|
+
var toColumnName = (index) => {
|
|
3966
|
+
let value = index + 1;
|
|
3967
|
+
let name = "";
|
|
3968
|
+
while (value > 0) {
|
|
3969
|
+
const mod = (value - 1) % 26;
|
|
3970
|
+
name = String.fromCharCode(65 + mod) + name;
|
|
3971
|
+
value = Math.floor((value - mod) / 26);
|
|
3972
|
+
}
|
|
3973
|
+
return name;
|
|
3974
|
+
};
|
|
3975
|
+
var buildRowsTable = (rows = []) => {
|
|
3976
|
+
const maxColumns = rows.reduce(
|
|
3977
|
+
(count, row) => Math.max(count, Array.isArray(row) ? row.length : 0),
|
|
3978
|
+
0
|
|
3979
|
+
);
|
|
3980
|
+
const columns = [
|
|
3981
|
+
{
|
|
3982
|
+
title: "#",
|
|
3983
|
+
dataIndex: "__row",
|
|
3984
|
+
key: "__row",
|
|
3985
|
+
width: 58,
|
|
3986
|
+
fixed: "left",
|
|
3987
|
+
render: (value) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Typography.Text, { type: "secondary", children: value })
|
|
3988
|
+
},
|
|
3989
|
+
...Array.from({ length: maxColumns }).map((_, index) => ({
|
|
3990
|
+
title: toColumnName(index),
|
|
3991
|
+
dataIndex: `col_${index}`,
|
|
3992
|
+
key: `col_${index}`,
|
|
3993
|
+
width: 168,
|
|
3994
|
+
render: (value) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Typography.Text, { ellipsis: { tooltip: String(value ?? "") }, children: String(value ?? "") })
|
|
3995
|
+
}))
|
|
3996
|
+
];
|
|
3997
|
+
const dataSource = rows.map((row, rowIndex) => {
|
|
3998
|
+
const record = { key: rowIndex, __row: rowIndex + 1 };
|
|
3999
|
+
(Array.isArray(row) ? row : []).forEach((value, colIndex) => {
|
|
4000
|
+
record[`col_${colIndex}`] = value;
|
|
4001
|
+
});
|
|
4002
|
+
return record;
|
|
4003
|
+
});
|
|
4004
|
+
return { columns, dataSource };
|
|
4005
|
+
};
|
|
4006
|
+
var CenteredState = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4007
|
+
"div",
|
|
4008
|
+
{
|
|
4009
|
+
style: {
|
|
4010
|
+
minHeight: 280,
|
|
4011
|
+
height: "100%",
|
|
4012
|
+
display: "flex",
|
|
4013
|
+
alignItems: "center",
|
|
4014
|
+
justifyContent: "center",
|
|
4015
|
+
padding: 24
|
|
4016
|
+
},
|
|
4017
|
+
children
|
|
4018
|
+
}
|
|
4019
|
+
);
|
|
4020
|
+
var PayloadPreview = ({
|
|
4021
|
+
request,
|
|
4022
|
+
url,
|
|
4023
|
+
mode
|
|
4024
|
+
}) => {
|
|
4025
|
+
const [payload, setPayload] = (0, import_react7.useState)(null);
|
|
4026
|
+
const [loading, setLoading] = (0, import_react7.useState)(false);
|
|
4027
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4028
|
+
const [reloadKey, setReloadKey] = (0, import_react7.useState)(0);
|
|
4029
|
+
(0, import_react7.useEffect)(() => {
|
|
4030
|
+
let disposed = false;
|
|
4031
|
+
setPayload(null);
|
|
4032
|
+
setError("");
|
|
4033
|
+
if (!url) return () => {
|
|
4034
|
+
disposed = true;
|
|
4035
|
+
};
|
|
4036
|
+
setLoading(true);
|
|
4037
|
+
request({ url, method: "get" }).then((response) => {
|
|
4038
|
+
if (!disposed) setPayload(unwrapFilePreviewPayload(response));
|
|
4039
|
+
}).catch((currentError) => {
|
|
4040
|
+
if (!disposed) setError(currentError?.message || "\u6587\u4EF6\u9884\u89C8\u5185\u5BB9\u52A0\u8F7D\u5931\u8D25");
|
|
4041
|
+
}).finally(() => {
|
|
4042
|
+
if (!disposed) setLoading(false);
|
|
4043
|
+
});
|
|
4044
|
+
return () => {
|
|
4045
|
+
disposed = true;
|
|
4046
|
+
};
|
|
4047
|
+
}, [reloadKey, request, url]);
|
|
4048
|
+
if (loading) {
|
|
4049
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Spin, { description: mode === "excel" ? "\u6B63\u5728\u89E3\u6790\u5DE5\u4F5C\u7C3F..." : "\u6B63\u5728\u8BFB\u53D6\u6587\u672C..." }) });
|
|
4050
|
+
}
|
|
4051
|
+
if (error) {
|
|
4052
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4053
|
+
import_antd2.Alert,
|
|
4054
|
+
{
|
|
4055
|
+
type: "error",
|
|
4056
|
+
showIcon: true,
|
|
4057
|
+
title: error,
|
|
4058
|
+
action: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Button, { icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons.ReloadOutlined, {}), onClick: () => setReloadKey((value) => value + 1), children: "\u91CD\u8BD5" })
|
|
4059
|
+
}
|
|
4060
|
+
) });
|
|
4061
|
+
}
|
|
4062
|
+
if (mode === "excel") {
|
|
4063
|
+
const sheets = Array.isArray(payload?.sheets) ? payload.sheets : [];
|
|
4064
|
+
if (!sheets.length) {
|
|
4065
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Empty, { description: "\u6682\u65E0\u53EF\u9884\u89C8\u7684\u5DE5\u4F5C\u8868" }) });
|
|
4066
|
+
}
|
|
4067
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4068
|
+
import_antd2.Tabs,
|
|
4069
|
+
{
|
|
4070
|
+
style: { height: "100%", padding: "0 16px" },
|
|
4071
|
+
items: sheets.map((sheet) => {
|
|
4072
|
+
const table = buildRowsTable(sheet.rows || []);
|
|
4073
|
+
return {
|
|
4074
|
+
key: String(sheet.id || sheet.name),
|
|
4075
|
+
label: sheet.name || "Sheet",
|
|
4076
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
|
|
4077
|
+
sheet.truncatedRows || sheet.truncatedColumns ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4078
|
+
import_antd2.Alert,
|
|
4079
|
+
{
|
|
4080
|
+
type: "info",
|
|
4081
|
+
showIcon: true,
|
|
4082
|
+
title: `\u5DE5\u4F5C\u8868\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D ${payload.maxRows || 200} \u884C\u3001${payload.maxColumns || 60} \u5217\u3002`
|
|
4083
|
+
}
|
|
4084
|
+
) : null,
|
|
4085
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4086
|
+
import_antd2.Table,
|
|
4087
|
+
{
|
|
4088
|
+
bordered: true,
|
|
4089
|
+
size: "small",
|
|
4090
|
+
pagination: false,
|
|
4091
|
+
scroll: { x: "max-content", y: "min(66vh, 680px)" },
|
|
4092
|
+
columns: table.columns,
|
|
4093
|
+
dataSource: table.dataSource
|
|
4094
|
+
}
|
|
4095
|
+
)
|
|
4096
|
+
] })
|
|
4097
|
+
};
|
|
4098
|
+
})
|
|
4099
|
+
}
|
|
4100
|
+
);
|
|
4101
|
+
}
|
|
4102
|
+
const text = String(payload?.text || "");
|
|
4103
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { height: "100%", overflow: "auto", background: "#fff" }, children: [
|
|
4104
|
+
payload?.truncated ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4105
|
+
import_antd2.Alert,
|
|
4106
|
+
{
|
|
4107
|
+
type: "info",
|
|
4108
|
+
showIcon: true,
|
|
4109
|
+
banner: true,
|
|
4110
|
+
title: "\u6587\u4EF6\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D\u90E8\u5185\u5BB9\uFF1B\u5B8C\u6574\u5185\u5BB9\u8BF7\u4E0B\u8F7D\u67E5\u770B\u3002"
|
|
4111
|
+
}
|
|
4112
|
+
) : null,
|
|
4113
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4114
|
+
"pre",
|
|
4115
|
+
{
|
|
4116
|
+
style: {
|
|
4117
|
+
minHeight: 280,
|
|
4118
|
+
margin: 0,
|
|
4119
|
+
padding: 20,
|
|
4120
|
+
color: "#1f2328",
|
|
4121
|
+
background: "#fff",
|
|
4122
|
+
fontSize: 13,
|
|
4123
|
+
lineHeight: 1.7,
|
|
4124
|
+
whiteSpace: "pre-wrap",
|
|
4125
|
+
wordBreak: "break-word",
|
|
4126
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace'
|
|
4127
|
+
},
|
|
4128
|
+
children: text || "\u6682\u65E0\u6587\u672C\u5185\u5BB9"
|
|
4129
|
+
}
|
|
4130
|
+
)
|
|
4131
|
+
] });
|
|
4132
|
+
};
|
|
4133
|
+
var ClientTextPreview = ({
|
|
4134
|
+
request,
|
|
4135
|
+
url
|
|
4136
|
+
}) => {
|
|
4137
|
+
const [payload, setPayload] = (0, import_react7.useState)(null);
|
|
4138
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4139
|
+
(0, import_react7.useEffect)(() => {
|
|
4140
|
+
let disposed = false;
|
|
4141
|
+
let textLimit = 1024 * 1024;
|
|
4142
|
+
loadPreviewBlob(request, url).then(async (blob) => {
|
|
4143
|
+
const slice = blob.size > textLimit ? blob.slice(0, textLimit) : blob;
|
|
4144
|
+
const text = await slice.text();
|
|
4145
|
+
if (!disposed) setPayload({ text, truncated: blob.size > textLimit });
|
|
4146
|
+
}).catch((currentError) => {
|
|
4147
|
+
if (!disposed) setError(currentError?.message || "\u6587\u672C\u8BFB\u53D6\u5931\u8D25");
|
|
4148
|
+
});
|
|
4149
|
+
return () => {
|
|
4150
|
+
disposed = true;
|
|
4151
|
+
textLimit = 0;
|
|
4152
|
+
};
|
|
4153
|
+
}, [request, url]);
|
|
4154
|
+
if (error) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Alert, { type: "error", showIcon: true, title: error }) });
|
|
4155
|
+
if (!payload) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Spin, { description: "\u6B63\u5728\u8BFB\u53D6\u6587\u672C..." }) });
|
|
4156
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { height: "100%", overflow: "auto", background: "#fff" }, children: [
|
|
4157
|
+
payload.truncated ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Alert, { type: "info", showIcon: true, banner: true, title: "\u6587\u4EF6\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D\u90E8\u5185\u5BB9\u3002" }) : null,
|
|
4158
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4159
|
+
"pre",
|
|
4160
|
+
{
|
|
4161
|
+
style: {
|
|
4162
|
+
margin: 0,
|
|
4163
|
+
padding: 20,
|
|
4164
|
+
whiteSpace: "pre-wrap",
|
|
4165
|
+
wordBreak: "break-word",
|
|
4166
|
+
fontSize: 13,
|
|
4167
|
+
lineHeight: 1.7
|
|
4168
|
+
},
|
|
4169
|
+
children: payload.text || "\u6682\u65E0\u6587\u672C\u5185\u5BB9"
|
|
4170
|
+
}
|
|
4171
|
+
)
|
|
4172
|
+
] });
|
|
4173
|
+
};
|
|
4174
|
+
var DocxPreview = ({ request, url }) => {
|
|
4175
|
+
const containerRef = (0, import_react7.useRef)(null);
|
|
4176
|
+
const [loading, setLoading] = (0, import_react7.useState)(true);
|
|
4177
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4178
|
+
(0, import_react7.useEffect)(() => {
|
|
4179
|
+
let disposed = false;
|
|
4180
|
+
const container = containerRef.current;
|
|
4181
|
+
if (!container || !url) return () => {
|
|
4182
|
+
disposed = true;
|
|
4183
|
+
};
|
|
4184
|
+
container.innerHTML = "";
|
|
4185
|
+
setLoading(true);
|
|
4186
|
+
setError("");
|
|
4187
|
+
(async () => {
|
|
4188
|
+
try {
|
|
4189
|
+
const blob = await loadPreviewBlob(request, url);
|
|
4190
|
+
const { renderAsync } = await import("docx-preview");
|
|
4191
|
+
if (disposed || !containerRef.current) return;
|
|
4192
|
+
await renderAsync(blob, containerRef.current, containerRef.current, {
|
|
4193
|
+
className: "sy-docx-preview",
|
|
4194
|
+
inWrapper: true,
|
|
4195
|
+
breakPages: true,
|
|
4196
|
+
ignoreLastRenderedPageBreak: false,
|
|
4197
|
+
renderHeaders: true,
|
|
4198
|
+
renderFooters: true,
|
|
4199
|
+
renderFootnotes: true,
|
|
4200
|
+
renderEndnotes: true,
|
|
4201
|
+
useBase64URL: false
|
|
4202
|
+
});
|
|
4203
|
+
} catch (currentError) {
|
|
4204
|
+
if (!disposed) setError(currentError?.message || "Word \u6587\u6863\u89E3\u6790\u5931\u8D25");
|
|
4205
|
+
} finally {
|
|
4206
|
+
if (!disposed) setLoading(false);
|
|
4207
|
+
}
|
|
4208
|
+
})();
|
|
4209
|
+
return () => {
|
|
4210
|
+
disposed = true;
|
|
4211
|
+
if (container) container.innerHTML = "";
|
|
4212
|
+
};
|
|
4213
|
+
}, [request, url]);
|
|
4214
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4215
|
+
"div",
|
|
4216
|
+
{
|
|
4217
|
+
style: {
|
|
4218
|
+
minHeight: 360,
|
|
4219
|
+
height: "100%",
|
|
4220
|
+
overflow: "auto",
|
|
4221
|
+
position: "relative",
|
|
4222
|
+
background: "#e9edf2"
|
|
4223
|
+
},
|
|
4224
|
+
children: [
|
|
4225
|
+
loading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Spin, { description: "\u6B63\u5728\u8FD8\u539F Word \u7248\u5F0F..." }) }) : null,
|
|
4226
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { padding: 20 }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Alert, { type: "error", showIcon: true, title: error }) }) : null,
|
|
4227
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { ref: containerRef, style: { display: loading || error ? "none" : "block" } })
|
|
4228
|
+
]
|
|
4229
|
+
}
|
|
4230
|
+
);
|
|
4231
|
+
};
|
|
4232
|
+
var HeicImagePreview = ({
|
|
4233
|
+
request,
|
|
4234
|
+
url,
|
|
4235
|
+
fileName
|
|
4236
|
+
}) => {
|
|
4237
|
+
const [src, setSrc] = (0, import_react7.useState)("");
|
|
4238
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4239
|
+
(0, import_react7.useEffect)(() => {
|
|
4240
|
+
let disposed = false;
|
|
4241
|
+
let objectUrl = "";
|
|
4242
|
+
convertHeicPreview(request, url).then((result) => {
|
|
4243
|
+
objectUrl = result;
|
|
4244
|
+
if (!disposed) setSrc(result);
|
|
4245
|
+
}).catch((currentError) => {
|
|
4246
|
+
if (!disposed) setError(currentError?.message || "HEIC \u56FE\u7247\u8F6C\u6362\u5931\u8D25");
|
|
4247
|
+
});
|
|
4248
|
+
return () => {
|
|
4249
|
+
disposed = true;
|
|
4250
|
+
if (objectUrl) URL.revokeObjectURL?.(objectUrl);
|
|
4251
|
+
};
|
|
4252
|
+
}, [request, url]);
|
|
4253
|
+
if (error) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Alert, { type: "error", showIcon: true, title: error }) });
|
|
4254
|
+
if (!src) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Spin, { description: "\u6B63\u5728\u8F6C\u6362 HEIC \u56FE\u7247..." }) });
|
|
4255
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { minHeight: 320, textAlign: "center", padding: 20, background: "#f3f5f7" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4256
|
+
import_antd2.Image,
|
|
4257
|
+
{
|
|
4258
|
+
src,
|
|
4259
|
+
alt: fileName || "HEIC \u56FE\u7247\u9884\u89C8",
|
|
4260
|
+
style: { maxWidth: "100%", maxHeight: "72vh", objectFit: "contain" }
|
|
4261
|
+
}
|
|
4262
|
+
) });
|
|
4263
|
+
};
|
|
4264
|
+
var ClientSpreadsheetPreview = ({
|
|
4265
|
+
request,
|
|
4266
|
+
url
|
|
4267
|
+
}) => {
|
|
4268
|
+
const [payload, setPayload] = (0, import_react7.useState)(null);
|
|
4269
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4270
|
+
(0, import_react7.useEffect)(() => {
|
|
4271
|
+
let disposed = false;
|
|
4272
|
+
(async () => {
|
|
4273
|
+
try {
|
|
4274
|
+
const blob = await loadPreviewBlob(request, url);
|
|
4275
|
+
const XLSX = await import("xlsx");
|
|
4276
|
+
const workbook = XLSX.read(await blob.arrayBuffer(), {
|
|
4277
|
+
cellDates: true,
|
|
4278
|
+
dense: true
|
|
4279
|
+
});
|
|
4280
|
+
const maxRows = 500;
|
|
4281
|
+
const maxColumns = 100;
|
|
4282
|
+
const sheets = workbook.SheetNames.map((name, index) => {
|
|
4283
|
+
const allRows = XLSX.utils.sheet_to_json(workbook.Sheets[name], {
|
|
4284
|
+
header: 1,
|
|
4285
|
+
defval: "",
|
|
4286
|
+
raw: false
|
|
4287
|
+
});
|
|
4288
|
+
const columnCount = allRows.reduce(
|
|
4289
|
+
(count, row) => Math.max(count, Array.isArray(row) ? row.length : 0),
|
|
4290
|
+
0
|
|
4291
|
+
);
|
|
4292
|
+
return {
|
|
4293
|
+
id: index,
|
|
4294
|
+
name,
|
|
4295
|
+
rows: allRows.slice(0, maxRows).map(
|
|
4296
|
+
(row) => (Array.isArray(row) ? row : []).slice(0, maxColumns)
|
|
4297
|
+
),
|
|
4298
|
+
truncatedRows: allRows.length > maxRows,
|
|
4299
|
+
truncatedColumns: columnCount > maxColumns
|
|
4300
|
+
};
|
|
4301
|
+
});
|
|
4302
|
+
if (!disposed) setPayload({ sheets, maxRows, maxColumns });
|
|
4303
|
+
} catch (currentError) {
|
|
4304
|
+
if (!disposed) setError(currentError?.message || "Excel \u6587\u4EF6\u89E3\u6790\u5931\u8D25");
|
|
4305
|
+
}
|
|
4306
|
+
})();
|
|
4307
|
+
return () => {
|
|
4308
|
+
disposed = true;
|
|
4309
|
+
};
|
|
4310
|
+
}, [request, url]);
|
|
4311
|
+
if (error) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Alert, { type: "error", showIcon: true, title: error }) });
|
|
4312
|
+
if (!payload) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Spin, { description: "\u6B63\u5728\u89E3\u6790\u5DE5\u4F5C\u7C3F..." }) });
|
|
4313
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PayloadPreviewFromValue, { payload });
|
|
4314
|
+
};
|
|
4315
|
+
var PayloadPreviewFromValue = ({ payload }) => {
|
|
4316
|
+
const sheets = Array.isArray(payload?.sheets) ? payload.sheets : [];
|
|
4317
|
+
if (!sheets.length) return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Empty, { description: "\u6682\u65E0\u53EF\u9884\u89C8\u7684\u5DE5\u4F5C\u8868" }) });
|
|
4318
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4319
|
+
import_antd2.Tabs,
|
|
4320
|
+
{
|
|
4321
|
+
style: { height: "100%", padding: "0 16px" },
|
|
4322
|
+
items: sheets.map((sheet) => {
|
|
4323
|
+
const table = buildRowsTable(sheet.rows || []);
|
|
4324
|
+
return {
|
|
4325
|
+
key: String(sheet.id ?? sheet.name),
|
|
4326
|
+
label: sheet.name || "Sheet",
|
|
4327
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
|
|
4328
|
+
sheet.truncatedRows || sheet.truncatedColumns ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4329
|
+
import_antd2.Alert,
|
|
4330
|
+
{
|
|
4331
|
+
type: "info",
|
|
4332
|
+
showIcon: true,
|
|
4333
|
+
title: `\u5DE5\u4F5C\u8868\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D ${payload.maxRows} \u884C\u3001${payload.maxColumns} \u5217\u3002`
|
|
4334
|
+
}
|
|
4335
|
+
) : null,
|
|
4336
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4337
|
+
import_antd2.Table,
|
|
4338
|
+
{
|
|
4339
|
+
bordered: true,
|
|
4340
|
+
size: "small",
|
|
4341
|
+
pagination: false,
|
|
4342
|
+
scroll: { x: "max-content", y: "min(66vh, 680px)" },
|
|
4343
|
+
columns: table.columns,
|
|
4344
|
+
dataSource: table.dataSource
|
|
4345
|
+
}
|
|
4346
|
+
)
|
|
4347
|
+
] })
|
|
4348
|
+
};
|
|
4349
|
+
})
|
|
4350
|
+
}
|
|
4351
|
+
);
|
|
4352
|
+
};
|
|
4353
|
+
var scriptPromises = /* @__PURE__ */ new Map();
|
|
4354
|
+
var loadScriptOnce = (src) => {
|
|
4355
|
+
const existingPromise = scriptPromises.get(src);
|
|
4356
|
+
if (existingPromise) return existingPromise;
|
|
4357
|
+
const promise = new Promise((resolve, reject) => {
|
|
4358
|
+
if (!src || typeof document === "undefined") {
|
|
4359
|
+
reject(new Error("ONLYOFFICE \u811A\u672C\u5730\u5740\u4E0D\u53EF\u7528"));
|
|
4360
|
+
return;
|
|
4361
|
+
}
|
|
4362
|
+
const existed = document.querySelector(`script[src="${src}"]`);
|
|
4363
|
+
if (existed?.dataset.loaded === "true") {
|
|
4364
|
+
resolve();
|
|
4365
|
+
return;
|
|
4366
|
+
}
|
|
4367
|
+
const script = existed || document.createElement("script");
|
|
4368
|
+
script.src = src;
|
|
4369
|
+
script.async = true;
|
|
4370
|
+
script.onload = () => {
|
|
4371
|
+
script.dataset.loaded = "true";
|
|
4372
|
+
resolve();
|
|
4373
|
+
};
|
|
4374
|
+
script.onerror = () => reject(new Error("ONLYOFFICE \u811A\u672C\u52A0\u8F7D\u5931\u8D25"));
|
|
4375
|
+
if (!existed) document.body.appendChild(script);
|
|
4376
|
+
});
|
|
4377
|
+
scriptPromises.set(src, promise);
|
|
4378
|
+
promise.catch(() => scriptPromises.delete(src));
|
|
4379
|
+
return promise;
|
|
4380
|
+
};
|
|
4381
|
+
var OnlyOfficePreview = ({
|
|
4382
|
+
request,
|
|
4383
|
+
configUrl,
|
|
4384
|
+
ticket
|
|
4385
|
+
}) => {
|
|
4386
|
+
const editorId = (0, import_react7.useMemo)(
|
|
4387
|
+
() => `openxiangda-onlyoffice-${String(ticket || "editor").replace(/[^a-zA-Z0-9_-]/g, "")}`,
|
|
4388
|
+
[ticket]
|
|
4389
|
+
);
|
|
4390
|
+
const [loading, setLoading] = (0, import_react7.useState)(true);
|
|
4391
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4392
|
+
(0, import_react7.useEffect)(() => {
|
|
4393
|
+
let disposed = false;
|
|
4394
|
+
let editor;
|
|
4395
|
+
setLoading(true);
|
|
4396
|
+
setError("");
|
|
4397
|
+
(async () => {
|
|
4398
|
+
try {
|
|
4399
|
+
const response = await request({ url: configUrl, method: "get" });
|
|
4400
|
+
const payload = unwrapFilePreviewPayload(response);
|
|
4401
|
+
const scriptUrl = `${String(payload?.documentServerUrl || "").replace(
|
|
4402
|
+
/\/+$/,
|
|
4403
|
+
""
|
|
4404
|
+
)}/web-apps/apps/api/documents/api.js`;
|
|
4405
|
+
await loadScriptOnce(scriptUrl);
|
|
4406
|
+
if (!disposed && window.DocsAPI?.DocEditor) {
|
|
4407
|
+
editor = new window.DocsAPI.DocEditor(editorId, payload.config);
|
|
4408
|
+
}
|
|
4409
|
+
} catch (currentError) {
|
|
4410
|
+
if (!disposed) setError(currentError?.message || "ONLYOFFICE \u9884\u89C8\u52A0\u8F7D\u5931\u8D25");
|
|
4411
|
+
} finally {
|
|
4412
|
+
if (!disposed) setLoading(false);
|
|
4413
|
+
}
|
|
4414
|
+
})();
|
|
4415
|
+
return () => {
|
|
4416
|
+
disposed = true;
|
|
4417
|
+
editor?.destroyEditor?.();
|
|
4418
|
+
};
|
|
4419
|
+
}, [configUrl, editorId, request]);
|
|
4420
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { height: "100%", minHeight: 420, position: "relative", background: "#fff" }, children: [
|
|
4421
|
+
loading ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Spin, { description: "\u6B63\u5728\u52A0\u8F7D ONLYOFFICE..." }) }) : null,
|
|
4422
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { padding: 20 }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Alert, { type: "error", showIcon: true, title: error }) }) : null,
|
|
4423
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { id: editorId, style: { height: "100%", minHeight: 420, display: error ? "none" : "block" } })
|
|
4424
|
+
] });
|
|
4425
|
+
};
|
|
4426
|
+
var FilePreviewContent = ({
|
|
4427
|
+
metadata,
|
|
4428
|
+
request,
|
|
4429
|
+
servicePrefix = "/service",
|
|
4430
|
+
onDownload
|
|
4431
|
+
}) => {
|
|
4432
|
+
const renderMode = metadata.renderMode || "download";
|
|
4433
|
+
const previewUrl = resolvePreviewServiceUrl(metadata.previewUrl, servicePrefix);
|
|
4434
|
+
const imageUrl = resolvePreviewServiceUrl(
|
|
4435
|
+
renderMode === "image-transcode" ? metadata.imagePreviewUrl : metadata.previewUrl,
|
|
4436
|
+
servicePrefix
|
|
4437
|
+
);
|
|
4438
|
+
if (renderMode === "inline" && metadata.previewType === "image") {
|
|
4439
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4440
|
+
"div",
|
|
4441
|
+
{
|
|
4442
|
+
style: {
|
|
4443
|
+
height: "100%",
|
|
4444
|
+
minHeight: 320,
|
|
4445
|
+
display: "flex",
|
|
4446
|
+
alignItems: "center",
|
|
4447
|
+
justifyContent: "center",
|
|
4448
|
+
overflow: "auto",
|
|
4449
|
+
padding: 20,
|
|
4450
|
+
background: "#f3f5f7"
|
|
4451
|
+
},
|
|
4452
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4453
|
+
import_antd2.Image,
|
|
4454
|
+
{
|
|
4455
|
+
src: imageUrl,
|
|
4456
|
+
alt: metadata.fileName || "\u56FE\u7247\u9884\u89C8",
|
|
4457
|
+
style: { maxWidth: "100%", maxHeight: "72vh", objectFit: "contain" }
|
|
4458
|
+
}
|
|
4459
|
+
)
|
|
4460
|
+
}
|
|
4461
|
+
);
|
|
4462
|
+
}
|
|
4463
|
+
if (renderMode === "image-transcode") {
|
|
4464
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { minHeight: 320, textAlign: "center", padding: 20, background: "#f3f5f7" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4465
|
+
import_antd2.Image,
|
|
4466
|
+
{
|
|
4467
|
+
src: imageUrl,
|
|
4468
|
+
alt: metadata.fileName || "\u56FE\u7247\u9884\u89C8",
|
|
4469
|
+
style: { maxWidth: "100%", maxHeight: "72vh", objectFit: "contain" }
|
|
4470
|
+
}
|
|
4471
|
+
) });
|
|
4472
|
+
}
|
|
4473
|
+
if (renderMode === "image-heic") {
|
|
4474
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4475
|
+
HeicImagePreview,
|
|
4476
|
+
{
|
|
4477
|
+
request,
|
|
4478
|
+
url: previewUrl,
|
|
4479
|
+
fileName: metadata.fileName
|
|
4480
|
+
}
|
|
4481
|
+
);
|
|
4482
|
+
}
|
|
4483
|
+
if (renderMode === "inline" && metadata.previewType === "video") {
|
|
4484
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4485
|
+
"div",
|
|
4486
|
+
{
|
|
4487
|
+
style: {
|
|
4488
|
+
height: "100%",
|
|
4489
|
+
minHeight: 320,
|
|
4490
|
+
display: "flex",
|
|
4491
|
+
alignItems: "center",
|
|
4492
|
+
background: "#080a0d"
|
|
4493
|
+
},
|
|
4494
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4495
|
+
"video",
|
|
4496
|
+
{
|
|
4497
|
+
controls: true,
|
|
4498
|
+
playsInline: true,
|
|
4499
|
+
preload: "metadata",
|
|
4500
|
+
src: previewUrl,
|
|
4501
|
+
style: { width: "100%", maxHeight: "76vh" },
|
|
4502
|
+
children: "\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u89C6\u9891\u64AD\u653E\u3002"
|
|
4503
|
+
}
|
|
4504
|
+
)
|
|
4505
|
+
}
|
|
4506
|
+
);
|
|
4507
|
+
}
|
|
4508
|
+
if (renderMode === "inline" && metadata.previewType === "audio") {
|
|
4509
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("audio", { controls: true, preload: "metadata", src: previewUrl, style: { width: "min(680px, 100%)" }, children: "\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u97F3\u9891\u64AD\u653E\u3002" }) });
|
|
4510
|
+
}
|
|
4511
|
+
if (renderMode === "pdfjs") {
|
|
4512
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4513
|
+
"iframe",
|
|
4514
|
+
{
|
|
4515
|
+
title: metadata.fileName || "PDF \u9884\u89C8",
|
|
4516
|
+
src: previewUrl,
|
|
4517
|
+
style: { width: "100%", height: "100%", minHeight: 520, border: 0, background: "#fff" }
|
|
4518
|
+
}
|
|
4519
|
+
);
|
|
4520
|
+
}
|
|
4521
|
+
if (renderMode === "docx-html") {
|
|
4522
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DocxPreview, { request, url: previewUrl });
|
|
4523
|
+
}
|
|
4524
|
+
if (renderMode === "excel-client") {
|
|
4525
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ClientSpreadsheetPreview, { request, url: previewUrl });
|
|
4526
|
+
}
|
|
4527
|
+
if (renderMode === "excel-basic") {
|
|
4528
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4529
|
+
PayloadPreview,
|
|
4530
|
+
{
|
|
4531
|
+
request,
|
|
4532
|
+
url: metadata.excelPreviewUrl || "",
|
|
4533
|
+
mode: "excel"
|
|
4534
|
+
}
|
|
4535
|
+
);
|
|
4536
|
+
}
|
|
4537
|
+
if (renderMode === "text-client") {
|
|
4538
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ClientTextPreview, { request, url: previewUrl });
|
|
4539
|
+
}
|
|
4540
|
+
if (renderMode === "text" || renderMode === "office-text") {
|
|
4541
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4542
|
+
PayloadPreview,
|
|
4543
|
+
{
|
|
4544
|
+
request,
|
|
4545
|
+
url: renderMode === "office-text" ? metadata.officeTextPreviewUrl || "" : metadata.textPreviewUrl || "",
|
|
4546
|
+
mode: "text"
|
|
4547
|
+
}
|
|
4548
|
+
);
|
|
4549
|
+
}
|
|
4550
|
+
if (renderMode === "onlyoffice") {
|
|
4551
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4552
|
+
OnlyOfficePreview,
|
|
4553
|
+
{
|
|
4554
|
+
request,
|
|
4555
|
+
configUrl: metadata.onlyofficeConfigUrl || `/file/onlyoffice/config/${encodeURIComponent(metadata.ticket || "")}`,
|
|
4556
|
+
ticket: metadata.ticket
|
|
4557
|
+
}
|
|
4558
|
+
);
|
|
4559
|
+
}
|
|
4560
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4561
|
+
import_antd2.Empty,
|
|
4562
|
+
{
|
|
4563
|
+
image: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons.FileOutlined, { style: { fontSize: 52, color: "#8c8c8c" } }),
|
|
4564
|
+
description: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
|
|
4565
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Typography.Text, { strong: true, children: "\u5F53\u524D\u6587\u4EF6\u65E0\u6CD5\u5728\u7EBF\u9884\u89C8" }),
|
|
4566
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("br", {}),
|
|
4567
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Typography.Text, { type: "secondary", children: metadata.unsupportedReason || "\u8BF7\u4E0B\u8F7D\u540E\u4F7F\u7528\u672C\u5730\u5E94\u7528\u6253\u5F00\u3002" })
|
|
4568
|
+
] }),
|
|
4569
|
+
children: onDownload ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Button, { type: "primary", icon: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons.DownloadOutlined, {}), onClick: onDownload, children: "\u4E0B\u8F7D\u6587\u4EF6" }) : null
|
|
4570
|
+
}
|
|
4571
|
+
) });
|
|
4572
|
+
};
|
|
4573
|
+
|
|
4574
|
+
// packages/sdk/src/components/file-preview/FilePreviewPage.tsx
|
|
4575
|
+
var import_react8 = require("react");
|
|
4576
|
+
var import_antd3 = require("antd");
|
|
4577
|
+
var import_icons2 = require("@ant-design/icons");
|
|
4578
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
4579
|
+
|
|
4580
|
+
// packages/sdk/src/components/file-preview/useFilePreview.tsx
|
|
4581
|
+
var import_react9 = require("react");
|
|
4582
|
+
var import_antd4 = require("antd");
|
|
4583
|
+
var import_icons3 = require("@ant-design/icons");
|
|
4584
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
4585
|
+
var canActOnItem = (item) => item.status !== "uploading" && item.status !== "error";
|
|
4586
|
+
var revokeImageItems = (items) => {
|
|
4587
|
+
items.forEach((item) => {
|
|
4588
|
+
if (item.revokeOnClose && item.src.startsWith("blob:")) {
|
|
4589
|
+
URL.revokeObjectURL?.(item.src);
|
|
4590
|
+
}
|
|
4591
|
+
});
|
|
4592
|
+
};
|
|
4593
|
+
var buildCapabilityMap = (items, requireServerCapability) => {
|
|
4594
|
+
const result = {};
|
|
4595
|
+
items.forEach((item, index) => {
|
|
4596
|
+
const key = getPreviewItemKey(item, index);
|
|
4597
|
+
const local = resolveLocalPreviewCapability(item);
|
|
4598
|
+
result[key] = requireServerCapability && item.objectName && !isDirectStorageItem(item) ? { ...local, canPreview: false } : local;
|
|
4599
|
+
});
|
|
4600
|
+
return result;
|
|
4601
|
+
};
|
|
4602
|
+
var useFilePreviewController = ({
|
|
4603
|
+
items,
|
|
4604
|
+
api,
|
|
4605
|
+
appType,
|
|
4606
|
+
bucketName,
|
|
4607
|
+
enabled = true,
|
|
4608
|
+
requireServerCapability = true
|
|
4609
|
+
}) => {
|
|
4610
|
+
const itemSignature = (0, import_react9.useMemo)(
|
|
4611
|
+
() => items.map(
|
|
4612
|
+
(item, index) => [
|
|
4613
|
+
getPreviewItemKey(item, index),
|
|
4614
|
+
item.name,
|
|
4615
|
+
item.objectName,
|
|
4616
|
+
item.contentType,
|
|
4617
|
+
item.size,
|
|
4618
|
+
item.status
|
|
4619
|
+
].join(":")
|
|
4620
|
+
).join("|"),
|
|
4621
|
+
[items]
|
|
4622
|
+
);
|
|
4623
|
+
const [capabilities, setCapabilities] = (0, import_react9.useState)(
|
|
4624
|
+
() => buildCapabilityMap(items, requireServerCapability)
|
|
4625
|
+
);
|
|
4626
|
+
const [openingKey, setOpeningKey] = (0, import_react9.useState)("");
|
|
4627
|
+
const [dialogPreview, setDialogPreview] = (0, import_react9.useState)(null);
|
|
4628
|
+
const [imagePreview, setImagePreview] = (0, import_react9.useState)({
|
|
4629
|
+
open: false,
|
|
4630
|
+
current: 0,
|
|
4631
|
+
items: []
|
|
4632
|
+
});
|
|
4633
|
+
(0, import_react9.useEffect)(() => {
|
|
4634
|
+
let disposed = false;
|
|
4635
|
+
const initial = buildCapabilityMap(items, requireServerCapability);
|
|
4636
|
+
setCapabilities(initial);
|
|
4637
|
+
if (!enabled || !requireServerCapability) return () => {
|
|
4638
|
+
disposed = true;
|
|
4639
|
+
};
|
|
4640
|
+
const protectedItems = items.map((item, index) => ({ item, key: getPreviewItemKey(item, index) })).filter(
|
|
4641
|
+
({ item }) => canActOnItem(item) && Boolean(item.objectName) && !isDirectStorageItem(item)
|
|
4642
|
+
);
|
|
4643
|
+
if (!protectedItems.length) return () => {
|
|
4644
|
+
disposed = true;
|
|
4645
|
+
};
|
|
4646
|
+
api.request({
|
|
4647
|
+
url: "/file/preview-capabilities",
|
|
4648
|
+
method: "post",
|
|
4649
|
+
data: {
|
|
4650
|
+
files: protectedItems.map(({ item, key }) => ({
|
|
4651
|
+
key,
|
|
4652
|
+
fileName: item.name,
|
|
4653
|
+
objectName: item.objectName,
|
|
4654
|
+
contentType: item.contentType || item.mimeType,
|
|
4655
|
+
size: item.size
|
|
4656
|
+
}))
|
|
4657
|
+
}
|
|
4658
|
+
}).then((response) => {
|
|
4659
|
+
if (disposed) return;
|
|
4660
|
+
const payload = unwrapFilePreviewPayload(response);
|
|
4661
|
+
const next = { ...initial };
|
|
4662
|
+
(payload?.items || []).forEach((capability) => {
|
|
4663
|
+
if (capability.key) next[capability.key] = capability;
|
|
4664
|
+
});
|
|
4665
|
+
setCapabilities(next);
|
|
4666
|
+
}).catch(() => {
|
|
4667
|
+
if (disposed) return;
|
|
4668
|
+
const fallback = { ...initial };
|
|
4669
|
+
protectedItems.forEach(({ item, key }) => {
|
|
4670
|
+
fallback[key] = resolveLocalPreviewCapability(item);
|
|
4671
|
+
});
|
|
4672
|
+
setCapabilities(fallback);
|
|
4673
|
+
});
|
|
4674
|
+
return () => {
|
|
4675
|
+
disposed = true;
|
|
4676
|
+
};
|
|
4677
|
+
}, [api, enabled, itemSignature, requireServerCapability]);
|
|
4678
|
+
const getCapability = (0, import_react9.useCallback)(
|
|
4679
|
+
(item) => {
|
|
4680
|
+
const index = items.indexOf(item);
|
|
4681
|
+
return capabilities[getPreviewItemKey(item, Math.max(index, 0))];
|
|
4682
|
+
},
|
|
4683
|
+
[capabilities, items]
|
|
4684
|
+
);
|
|
4685
|
+
const canPreview = (0, import_react9.useCallback)(
|
|
4686
|
+
(item) => enabled && canActOnItem(item) && getCapability(item)?.canPreview === true,
|
|
4687
|
+
[enabled, getCapability]
|
|
4688
|
+
);
|
|
4689
|
+
const closeImagePreview = (0, import_react9.useCallback)(() => {
|
|
4690
|
+
setImagePreview((current) => {
|
|
4691
|
+
revokeImageItems(current.items);
|
|
4692
|
+
return { open: false, current: 0, items: [] };
|
|
4693
|
+
});
|
|
4694
|
+
}, []);
|
|
4695
|
+
(0, import_react9.useEffect)(
|
|
4696
|
+
() => () => revokeImageItems(imagePreview.items),
|
|
4697
|
+
[imagePreview.items]
|
|
4698
|
+
);
|
|
4699
|
+
const resolvePreparedImageItem = (0, import_react9.useCallback)(
|
|
4700
|
+
async (prepared, index) => {
|
|
4701
|
+
const item = prepared.item;
|
|
4702
|
+
const metadata = prepared.metadata;
|
|
4703
|
+
let src = resolvePreviewServiceUrl(
|
|
4704
|
+
metadata.renderMode === "image-transcode" ? metadata.imagePreviewUrl : metadata.previewUrl
|
|
4705
|
+
);
|
|
4706
|
+
let revokeOnClose = false;
|
|
4707
|
+
if (metadata.renderMode === "image-heic") {
|
|
4708
|
+
src = await convertHeicPreview(api.request, src);
|
|
4709
|
+
revokeOnClose = true;
|
|
4710
|
+
}
|
|
4711
|
+
if (!src) throw new Error(`${item.name || "\u56FE\u7247"}\u6CA1\u6709\u53EF\u7528\u7684\u9884\u89C8\u5730\u5740`);
|
|
4712
|
+
return {
|
|
4713
|
+
key: getPreviewItemKey(item, index),
|
|
4714
|
+
src,
|
|
4715
|
+
name: metadata.fileName || item.name,
|
|
4716
|
+
revokeOnClose
|
|
4717
|
+
};
|
|
4718
|
+
},
|
|
4719
|
+
[api]
|
|
4720
|
+
);
|
|
4721
|
+
const prepareImageItem = (0, import_react9.useCallback)(
|
|
4722
|
+
async (item, index) => {
|
|
4723
|
+
const prepared = await prepareFilePreview({ item, api, appType, bucketName });
|
|
4724
|
+
return resolvePreparedImageItem(prepared, index);
|
|
4725
|
+
},
|
|
4726
|
+
[api, appType, bucketName, resolvePreparedImageItem]
|
|
4727
|
+
);
|
|
4728
|
+
const openPreview = (0, import_react9.useCallback)(
|
|
4729
|
+
async (item) => {
|
|
4730
|
+
const itemIndex = Math.max(items.indexOf(item), 0);
|
|
4731
|
+
const key = getPreviewItemKey(item, itemIndex);
|
|
4732
|
+
setOpeningKey(key);
|
|
4733
|
+
try {
|
|
4734
|
+
const prepared = await prepareFilePreview({ item, api, appType, bucketName });
|
|
4735
|
+
if (prepared.metadata.canPreview === false || prepared.metadata.renderMode === "download") {
|
|
4736
|
+
setDialogPreview(prepared);
|
|
4737
|
+
return;
|
|
4738
|
+
}
|
|
4739
|
+
if (prepared.metadata.previewType === "image") {
|
|
4740
|
+
const galleryCandidates = items.map((candidate, index) => ({ candidate, index })).filter(({ candidate }) => {
|
|
4741
|
+
const capability = getCapability(candidate) || resolveLocalPreviewCapability(candidate);
|
|
4742
|
+
return canActOnItem(candidate) && capability.canPreview && capability.previewType === "image";
|
|
4743
|
+
});
|
|
4744
|
+
const results = await Promise.allSettled(
|
|
4745
|
+
galleryCandidates.map(
|
|
4746
|
+
({ candidate, index }) => candidate === item ? resolvePreparedImageItem(prepared, index) : prepareImageItem(candidate, index)
|
|
4747
|
+
)
|
|
4748
|
+
);
|
|
4749
|
+
const gallery = results.flatMap(
|
|
4750
|
+
(result) => result.status === "fulfilled" ? [result.value] : []
|
|
4751
|
+
);
|
|
4752
|
+
if (!gallery.length || !gallery.some((image) => image.key === key)) {
|
|
4753
|
+
const fallback = await resolvePreparedImageItem(prepared, itemIndex);
|
|
4754
|
+
gallery.push(fallback);
|
|
4755
|
+
}
|
|
4756
|
+
const current = Math.max(0, gallery.findIndex((image) => image.key === key));
|
|
4757
|
+
closeImagePreview();
|
|
4758
|
+
setImagePreview({ open: true, current, items: gallery });
|
|
4759
|
+
return;
|
|
4760
|
+
}
|
|
4761
|
+
setDialogPreview(prepared);
|
|
4762
|
+
} catch (error) {
|
|
4763
|
+
setDialogPreview({
|
|
4764
|
+
item,
|
|
4765
|
+
direct: isDirectStorageItem(item),
|
|
4766
|
+
metadata: {
|
|
4767
|
+
...resolveLocalPreviewCapability(item),
|
|
4768
|
+
fileName: item.name,
|
|
4769
|
+
size: item.size,
|
|
4770
|
+
renderMode: "download",
|
|
4771
|
+
canPreview: false,
|
|
4772
|
+
unsupportedReason: error?.message || "\u6587\u4EF6\u9884\u89C8\u52A0\u8F7D\u5931\u8D25",
|
|
4773
|
+
downloadUrl: item.downloadUrl || item.publicUrl || item.url
|
|
4774
|
+
}
|
|
4775
|
+
});
|
|
4776
|
+
} finally {
|
|
4777
|
+
setOpeningKey("");
|
|
4778
|
+
}
|
|
4779
|
+
},
|
|
4780
|
+
[
|
|
4781
|
+
api,
|
|
4782
|
+
appType,
|
|
4783
|
+
bucketName,
|
|
4784
|
+
closeImagePreview,
|
|
4785
|
+
getCapability,
|
|
4786
|
+
items,
|
|
4787
|
+
prepareImageItem,
|
|
4788
|
+
resolvePreparedImageItem
|
|
4789
|
+
]
|
|
4790
|
+
);
|
|
4791
|
+
const downloadItem = (0, import_react9.useCallback)(
|
|
4792
|
+
async (item, prepared) => {
|
|
4793
|
+
let url = prepared?.metadata.downloadUrl || item.downloadUrl || item.publicUrl || item.url;
|
|
4794
|
+
if (!isDirectStorageItem(item) && item.objectName && !prepared?.metadata.downloadUrl) {
|
|
4795
|
+
const ticket = await api.createDownloadTicket(
|
|
4796
|
+
item.bucketName || bucketName,
|
|
4797
|
+
item.objectName,
|
|
4798
|
+
item.name
|
|
4799
|
+
);
|
|
4800
|
+
url = typeof ticket === "string" ? ticket : ticket?.downloadUrl || ticket?.relayUrl || ticket?.url || url;
|
|
4801
|
+
}
|
|
4802
|
+
if (url && typeof window !== "undefined") window.location.assign(url);
|
|
4803
|
+
},
|
|
4804
|
+
[api, bucketName]
|
|
4805
|
+
);
|
|
4806
|
+
const previewHost = imagePreview.open || dialogPreview ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
4807
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4808
|
+
import_antd4.Image.PreviewGroup,
|
|
4809
|
+
{
|
|
4810
|
+
items: imagePreview.items.map((item) => ({ src: item.src, alt: item.name })),
|
|
4811
|
+
preview: {
|
|
4812
|
+
open: imagePreview.open,
|
|
4813
|
+
current: imagePreview.current,
|
|
4814
|
+
onChange: (current) => setImagePreview((value) => ({ ...value, current })),
|
|
4815
|
+
onOpenChange: (open) => {
|
|
4816
|
+
if (!open) closeImagePreview();
|
|
4817
|
+
},
|
|
4818
|
+
countRender: (current, total) => `${current}/${total}`
|
|
4819
|
+
},
|
|
4820
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "aria-hidden": "true", style: { display: "none" } })
|
|
4821
|
+
}
|
|
4822
|
+
),
|
|
4823
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4824
|
+
FilePreviewDialog,
|
|
4825
|
+
{
|
|
4826
|
+
preview: dialogPreview,
|
|
4827
|
+
request: api.request,
|
|
4828
|
+
onClose: () => setDialogPreview(null),
|
|
4829
|
+
onDownload: () => {
|
|
4830
|
+
if (dialogPreview) void downloadItem(dialogPreview.item, dialogPreview);
|
|
4831
|
+
}
|
|
4832
|
+
}
|
|
4833
|
+
)
|
|
4834
|
+
] }) : null;
|
|
4835
|
+
return {
|
|
4836
|
+
canPreview,
|
|
4837
|
+
getCapability,
|
|
4838
|
+
openPreview,
|
|
4839
|
+
openingKey,
|
|
4840
|
+
isOpening: (item) => {
|
|
4841
|
+
const index = Math.max(items.indexOf(item), 0);
|
|
4842
|
+
return openingKey === getPreviewItemKey(item, index);
|
|
4843
|
+
},
|
|
4844
|
+
downloadItem,
|
|
4845
|
+
previewHost
|
|
4846
|
+
};
|
|
4847
|
+
};
|
|
4848
|
+
var FilePreviewDialog = ({
|
|
4849
|
+
preview,
|
|
4850
|
+
request,
|
|
4851
|
+
onClose,
|
|
4852
|
+
onDownload
|
|
4853
|
+
}) => {
|
|
4854
|
+
const metadata = preview?.metadata;
|
|
4855
|
+
const title = metadata?.fileName || preview?.item.name || "\u9644\u4EF6\u9884\u89C8";
|
|
4856
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4857
|
+
import_antd4.Modal,
|
|
4858
|
+
{
|
|
4859
|
+
open: Boolean(preview),
|
|
4860
|
+
title: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { minWidth: 0, paddingRight: 16 }, children: [
|
|
4861
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd4.Typography.Text, { strong: true, ellipsis: true, style: { display: "block" }, children: title }),
|
|
4862
|
+
metadata ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd4.Typography.Text, { type: "secondary", style: { fontSize: 12 }, children: [
|
|
4863
|
+
(metadata.extension || "FILE").toUpperCase(),
|
|
4864
|
+
" \xB7 ",
|
|
4865
|
+
formatPreviewFileSize(metadata.size)
|
|
4866
|
+
] }) : null
|
|
4867
|
+
] }),
|
|
4868
|
+
width: "min(96vw, 1440px)",
|
|
4869
|
+
centered: true,
|
|
4870
|
+
destroyOnHidden: true,
|
|
4871
|
+
mask: { closable: false },
|
|
4872
|
+
closeIcon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_icons3.CloseOutlined, {}),
|
|
4873
|
+
onCancel: onClose,
|
|
4874
|
+
styles: {
|
|
4875
|
+
body: {
|
|
4876
|
+
height: "min(78vh, 900px)",
|
|
4877
|
+
minHeight: 360,
|
|
4878
|
+
padding: 0,
|
|
4879
|
+
overflow: "hidden",
|
|
4880
|
+
border: "1px solid #e5e7eb"
|
|
4881
|
+
}
|
|
4882
|
+
},
|
|
4883
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", justifyContent: "flex-end", gap: 8 }, children: [
|
|
4884
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd4.Button, { onClick: onClose, children: "\u5173\u95ED" }),
|
|
4885
|
+
metadata?.canDownload !== false ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd4.Button, { type: "primary", icon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_icons3.DownloadOutlined, {}), onClick: onDownload, children: "\u4E0B\u8F7D" }) : null
|
|
4886
|
+
] }),
|
|
4887
|
+
children: preview && metadata ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4888
|
+
FilePreviewContent,
|
|
4889
|
+
{
|
|
4890
|
+
metadata,
|
|
4891
|
+
request,
|
|
4892
|
+
onDownload
|
|
4893
|
+
}
|
|
4894
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("div", { style: { height: "100%", display: "grid", placeItems: "center" }, children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd4.Spin, { description: "\u6B63\u5728\u51C6\u5907\u9884\u89C8..." }) })
|
|
4895
|
+
}
|
|
4896
|
+
);
|
|
4897
|
+
};
|
|
4898
|
+
|
|
4899
|
+
// packages/sdk/src/components/fields/shared/FileDisplay.tsx
|
|
4900
|
+
var import_icons4 = require("@ant-design/icons");
|
|
4901
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
4902
|
+
function FileTypeIcon({
|
|
4903
|
+
item,
|
|
4904
|
+
className
|
|
4905
|
+
}) {
|
|
4906
|
+
const category = getFileCategory(item.name, item.contentType);
|
|
4907
|
+
const extension = getFileExtension(item.name);
|
|
4908
|
+
const icon = category === "image" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.FileImageOutlined, {}) : category === "video" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.VideoCameraOutlined, {}) : category === "audio" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.AudioOutlined, {}) : category === "pdf" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.FilePdfOutlined, {}) : category === "excel" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.FileExcelOutlined, {}) : category === "word" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.FileWordOutlined, {}) : category === "ppt" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.FilePptOutlined, {}) : category === "archive" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.FileZipOutlined, {}) : category === "text" || category === "code" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.FileTextOutlined, {}) : extension ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.FileOutlined, {}) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.FileUnknownOutlined, {});
|
|
4909
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: `sy-file-icon sy-file-icon-${category} ${className || ""}`, "aria-hidden": "true", children: [
|
|
4910
|
+
icon,
|
|
4911
|
+
category !== "image" && extension ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: extension.toUpperCase() }) : null
|
|
4912
|
+
] });
|
|
4913
|
+
}
|
|
4914
|
+
function FileActionButton({
|
|
4915
|
+
type,
|
|
4916
|
+
disabled,
|
|
4917
|
+
onClick,
|
|
4918
|
+
testId
|
|
4919
|
+
}) {
|
|
4920
|
+
const label = type === "preview" ? "\u9884\u89C8" : type === "download" ? "\u4E0B\u8F7D" : "\u5220\u9664";
|
|
4921
|
+
const icon = type === "preview" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.EyeOutlined, {}) : type === "download" ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.DownloadOutlined, {}) : /* @__PURE__ */ (0, import_jsx_runtime6.jsx)(import_icons4.CloseOutlined, {});
|
|
4922
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
4923
|
+
"button",
|
|
4924
|
+
{
|
|
4925
|
+
type: "button",
|
|
4926
|
+
className: `sy-file-action sy-file-action-${type}`,
|
|
4927
|
+
disabled,
|
|
4928
|
+
onClick,
|
|
4929
|
+
"data-testid": testId,
|
|
4930
|
+
"aria-label": label,
|
|
4931
|
+
title: label,
|
|
4932
|
+
children: [
|
|
4933
|
+
icon,
|
|
4934
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "sy-sr-only", children: label })
|
|
4935
|
+
]
|
|
4936
|
+
}
|
|
4937
|
+
);
|
|
4938
|
+
}
|
|
4939
|
+
function FileStatusText({
|
|
4940
|
+
item,
|
|
4941
|
+
showFileSize = true,
|
|
4942
|
+
showFileTypeBadge = true
|
|
4943
|
+
}) {
|
|
4944
|
+
const extension = getFileExtension(item.name);
|
|
4945
|
+
const text = item.status === "uploading" ? `\u4E0A\u4F20\u4E2D ${Math.round(item.percent ?? 0)}%` : item.status === "error" ? item.error || "\u4E0A\u4F20\u5931\u8D25" : [
|
|
4946
|
+
showFileTypeBadge && extension ? extension.toUpperCase() : "",
|
|
4947
|
+
showFileSize ? formatFileSize(item.size) : ""
|
|
4948
|
+
].filter(Boolean).join(" \xB7 ") || "\u5DF2\u4E0A\u4F20";
|
|
4949
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "sy-file-sub", children: text });
|
|
4950
|
+
}
|
|
4951
|
+
|
|
4952
|
+
// packages/sdk/src/runtime/react/filePreview.tsx
|
|
4953
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
4954
|
+
var EMPTY_ITEMS = [];
|
|
4955
|
+
var normalizeMethod2 = (method) => {
|
|
4956
|
+
const value = String(method || "get").toLowerCase();
|
|
4957
|
+
return ["get", "post", "put", "delete", "patch"].includes(value) ? value : "get";
|
|
4958
|
+
};
|
|
4959
|
+
var normalizeHeaders = (headers) => {
|
|
4960
|
+
if (!headers) return void 0;
|
|
4961
|
+
return Object.fromEntries(new Headers(headers).entries());
|
|
4962
|
+
};
|
|
4963
|
+
var toPageRequest = (config) => ({
|
|
4964
|
+
path: config.url,
|
|
4965
|
+
method: normalizeMethod2(config.method),
|
|
4966
|
+
query: config.params,
|
|
4967
|
+
body: config.data,
|
|
4968
|
+
headers: normalizeHeaders(config.headers)
|
|
4969
|
+
});
|
|
4970
|
+
var toRuntimeResponse = (response) => {
|
|
4971
|
+
if (response.raw && typeof response.raw === "object") {
|
|
4972
|
+
return response.raw;
|
|
4973
|
+
}
|
|
4974
|
+
return {
|
|
4975
|
+
code: Number(response.code) || 200,
|
|
4976
|
+
success: response.success,
|
|
4977
|
+
message: response.message,
|
|
4978
|
+
data: response.result,
|
|
4979
|
+
result: response.result
|
|
4980
|
+
};
|
|
4981
|
+
};
|
|
4982
|
+
var unwrapPageResult = (response) => response.result ?? response.data ?? null;
|
|
4983
|
+
var createPageFileRuntimeApi = (sdk) => {
|
|
4984
|
+
const request = async (config) => {
|
|
4985
|
+
const options = toPageRequest(config);
|
|
4986
|
+
if (config.responseType === "blob") {
|
|
4987
|
+
const response = await sdk.transport.download(options);
|
|
4988
|
+
return response.blob;
|
|
4989
|
+
}
|
|
4990
|
+
return toRuntimeResponse(await sdk.transport.request(options));
|
|
4991
|
+
};
|
|
4992
|
+
return createFormRuntimeApi({
|
|
4993
|
+
request,
|
|
4994
|
+
createFileAccessTicket: async (bucketName, objectName, fileName, purpose = "preview", options = {}) => unwrapPageResult(
|
|
4995
|
+
await sdk.createFileAccessTicket(
|
|
4996
|
+
bucketName,
|
|
4997
|
+
objectName,
|
|
4998
|
+
fileName,
|
|
4999
|
+
purpose,
|
|
5000
|
+
options
|
|
5001
|
+
)
|
|
5002
|
+
),
|
|
5003
|
+
createDownloadTicket: async (bucketName, objectName, fileName) => unwrapPageResult(
|
|
5004
|
+
await sdk.request({
|
|
5005
|
+
path: "/file/download-ticket",
|
|
5006
|
+
method: "post",
|
|
5007
|
+
body: { bucketName, objectName, fileName }
|
|
5008
|
+
})
|
|
5009
|
+
)
|
|
5010
|
+
});
|
|
5011
|
+
};
|
|
5012
|
+
var useFilePreview = ({
|
|
5013
|
+
items = EMPTY_ITEMS,
|
|
5014
|
+
appType,
|
|
5015
|
+
bucketName = "attachments",
|
|
5016
|
+
enabled = true,
|
|
5017
|
+
requireServerCapability = true
|
|
5018
|
+
}) => {
|
|
5019
|
+
const sdk = usePageSdk();
|
|
5020
|
+
const api = (0, import_react10.useMemo)(() => createPageFileRuntimeApi(sdk), [sdk]);
|
|
5021
|
+
const preview = useFilePreviewController({
|
|
5022
|
+
items,
|
|
5023
|
+
api,
|
|
5024
|
+
appType: appType || sdk.context.app.appType,
|
|
5025
|
+
bucketName,
|
|
5026
|
+
enabled,
|
|
5027
|
+
requireServerCapability
|
|
5028
|
+
});
|
|
5029
|
+
return {
|
|
5030
|
+
canPreview: preview.canPreview,
|
|
5031
|
+
getCapability: preview.getCapability,
|
|
5032
|
+
open: preview.openPreview,
|
|
5033
|
+
download: preview.downloadItem,
|
|
5034
|
+
isOpening: preview.isOpening,
|
|
5035
|
+
openingKey: preview.openingKey,
|
|
5036
|
+
host: preview.previewHost
|
|
5037
|
+
};
|
|
5038
|
+
};
|
|
5039
|
+
var AttachmentPreviewList = ({
|
|
5040
|
+
items = EMPTY_ITEMS,
|
|
5041
|
+
appType,
|
|
5042
|
+
bucketName = "attachments",
|
|
5043
|
+
showPreview = true,
|
|
5044
|
+
showDownload = true,
|
|
5045
|
+
showFileSize = true,
|
|
5046
|
+
showFileTypeBadge = false,
|
|
5047
|
+
emptyText = "\u6682\u65E0\u9644\u4EF6",
|
|
5048
|
+
className
|
|
5049
|
+
}) => {
|
|
5050
|
+
const preview = useFilePreview({
|
|
5051
|
+
items,
|
|
5052
|
+
appType,
|
|
5053
|
+
bucketName,
|
|
5054
|
+
enabled: showPreview,
|
|
5055
|
+
requireServerCapability: true
|
|
5056
|
+
});
|
|
5057
|
+
if (!items.length) {
|
|
5058
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_antd5.Empty, { description: emptyText, className });
|
|
5059
|
+
}
|
|
5060
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
5061
|
+
"div",
|
|
5062
|
+
{
|
|
5063
|
+
className: ["sy-readonly-files", "sy-readonly-attachments", className].filter(Boolean).join(" "),
|
|
5064
|
+
"data-testid": "openxiangda-attachment-preview-list",
|
|
5065
|
+
children: [
|
|
5066
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "sy-file-list", children: items.map((item, index) => {
|
|
5067
|
+
const key = getPreviewItemKey(item, index);
|
|
5068
|
+
const canAct = item.status !== "uploading" && item.status !== "error";
|
|
5069
|
+
const canDownload = preview.getCapability(item)?.canDownload !== false;
|
|
5070
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "sy-file-item", children: [
|
|
5071
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FileTypeIcon, { item }),
|
|
5072
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "sy-file-meta", children: [
|
|
5073
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "sy-file-name", title: item.name, children: item.name || "\u672A\u547D\u540D\u9644\u4EF6" }),
|
|
5074
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5075
|
+
FileStatusText,
|
|
5076
|
+
{
|
|
5077
|
+
item,
|
|
5078
|
+
showFileSize,
|
|
5079
|
+
showFileTypeBadge
|
|
5080
|
+
}
|
|
5081
|
+
)
|
|
5082
|
+
] }),
|
|
5083
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "sy-file-actions", children: [
|
|
5084
|
+
showPreview && preview.canPreview(item) ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5085
|
+
FileActionButton,
|
|
5086
|
+
{
|
|
5087
|
+
type: "preview",
|
|
5088
|
+
disabled: !canAct || preview.isOpening(item),
|
|
5089
|
+
onClick: () => void preview.open(item),
|
|
5090
|
+
testId: `attachment-preview-${key}`
|
|
5091
|
+
}
|
|
5092
|
+
) : null,
|
|
5093
|
+
showDownload && canDownload ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5094
|
+
FileActionButton,
|
|
5095
|
+
{
|
|
5096
|
+
type: "download",
|
|
5097
|
+
disabled: !canAct,
|
|
5098
|
+
onClick: () => void preview.download(item),
|
|
5099
|
+
testId: `attachment-download-${key}`
|
|
5100
|
+
}
|
|
5101
|
+
) : null
|
|
5102
|
+
] })
|
|
5103
|
+
] }, `${key}-${index}`);
|
|
5104
|
+
}) }),
|
|
5105
|
+
preview.host
|
|
5106
|
+
]
|
|
5107
|
+
}
|
|
5108
|
+
);
|
|
5109
|
+
};
|
|
5110
|
+
var PreviewImageThumb = ({ item }) => {
|
|
5111
|
+
const src = item.thumbUrl || item.previewUrl || item.url;
|
|
5112
|
+
const [failed, setFailed] = (0, import_react10.useState)(false);
|
|
5113
|
+
import_react10.default.useEffect(() => setFailed(false), [src]);
|
|
5114
|
+
return src && !failed ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("img", { src, alt: item.name || "\u56FE\u7247", onError: () => setFailed(true) }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "sy-image-state", children: item.name || "\u56FE\u7247" });
|
|
5115
|
+
};
|
|
5116
|
+
var ImagePreviewGrid = ({
|
|
5117
|
+
items = EMPTY_ITEMS,
|
|
5118
|
+
appType,
|
|
5119
|
+
bucketName = "images",
|
|
5120
|
+
showPreview = true,
|
|
5121
|
+
showDownload = true,
|
|
5122
|
+
showFileName = true,
|
|
5123
|
+
emptyText = "\u6682\u65E0\u56FE\u7247",
|
|
5124
|
+
className
|
|
5125
|
+
}) => {
|
|
5126
|
+
const preview = useFilePreview({
|
|
5127
|
+
items,
|
|
5128
|
+
appType,
|
|
5129
|
+
bucketName,
|
|
5130
|
+
enabled: showPreview,
|
|
5131
|
+
requireServerCapability: true
|
|
5132
|
+
});
|
|
5133
|
+
if (!items.length) {
|
|
5134
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_antd5.Empty, { description: emptyText, className });
|
|
5135
|
+
}
|
|
5136
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
5137
|
+
"div",
|
|
5138
|
+
{
|
|
5139
|
+
className: ["sy-readonly-files", "sy-readonly-images", className].filter(Boolean).join(" "),
|
|
5140
|
+
"data-testid": "openxiangda-image-preview-grid",
|
|
5141
|
+
children: [
|
|
5142
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5143
|
+
"div",
|
|
5144
|
+
{
|
|
5145
|
+
className: "sy-mobile-image-grid",
|
|
5146
|
+
style: { gridTemplateColumns: "repeat(auto-fill, minmax(112px, 160px))" },
|
|
5147
|
+
children: items.map((item, index) => {
|
|
5148
|
+
const key = getPreviewItemKey(item, index);
|
|
5149
|
+
const canAct = item.status !== "uploading" && item.status !== "error";
|
|
5150
|
+
const canOpen = showPreview && preview.canPreview(item);
|
|
5151
|
+
const canDownload = preview.getCapability(item)?.canDownload !== false;
|
|
5152
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "sy-mobile-image-card", children: [
|
|
5153
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "sy-mobile-image-thumb", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5154
|
+
"button",
|
|
5155
|
+
{
|
|
5156
|
+
type: "button",
|
|
5157
|
+
className: "sy-image-preview",
|
|
5158
|
+
disabled: !canAct || !canOpen || preview.isOpening(item),
|
|
5159
|
+
onClick: () => void preview.open(item),
|
|
5160
|
+
"aria-label": `\u9884\u89C8 ${item.name || "\u56FE\u7247"}`,
|
|
5161
|
+
"data-testid": `image-preview-${key}`,
|
|
5162
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PreviewImageThumb, { item })
|
|
5163
|
+
}
|
|
5164
|
+
) }),
|
|
5165
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
5166
|
+
"div",
|
|
5167
|
+
{
|
|
5168
|
+
style: {
|
|
5169
|
+
display: "flex",
|
|
5170
|
+
alignItems: "center",
|
|
5171
|
+
gap: 6,
|
|
5172
|
+
minWidth: 0
|
|
5173
|
+
},
|
|
5174
|
+
children: [
|
|
5175
|
+
showFileName ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "sy-mobile-image-name", title: item.name, style: { flex: 1 }, children: item.name || "\u56FE\u7247" }) : /* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { style: { flex: 1 } }),
|
|
5176
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "sy-file-actions", children: [
|
|
5177
|
+
canOpen ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5178
|
+
FileActionButton,
|
|
5179
|
+
{
|
|
5180
|
+
type: "preview",
|
|
5181
|
+
disabled: !canAct || preview.isOpening(item),
|
|
5182
|
+
onClick: () => void preview.open(item)
|
|
5183
|
+
}
|
|
5184
|
+
) : null,
|
|
5185
|
+
showDownload && canDownload ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5186
|
+
FileActionButton,
|
|
5187
|
+
{
|
|
5188
|
+
type: "download",
|
|
5189
|
+
disabled: !canAct,
|
|
5190
|
+
onClick: () => void preview.download(item)
|
|
5191
|
+
}
|
|
5192
|
+
) : null
|
|
5193
|
+
] })
|
|
5194
|
+
]
|
|
5195
|
+
}
|
|
5196
|
+
)
|
|
5197
|
+
] }, `${key}-${index}`);
|
|
5198
|
+
})
|
|
5199
|
+
}
|
|
5200
|
+
),
|
|
5201
|
+
preview.host
|
|
5202
|
+
]
|
|
5203
|
+
}
|
|
5204
|
+
);
|
|
5205
|
+
};
|
|
5206
|
+
|
|
2699
5207
|
// packages/sdk/src/runtime/react/workflow.tsx
|
|
2700
|
-
var
|
|
2701
|
-
var
|
|
2702
|
-
var
|
|
5208
|
+
var import_react16 = require("react");
|
|
5209
|
+
var import_antd10 = require("antd");
|
|
5210
|
+
var import_icons9 = require("@ant-design/icons");
|
|
2703
5211
|
|
|
2704
5212
|
// packages/sdk/src/components/modules/StickyActionBar.tsx
|
|
2705
|
-
var
|
|
2706
|
-
var
|
|
2707
|
-
var
|
|
5213
|
+
var import_react11 = require("react");
|
|
5214
|
+
var import_antd6 = require("antd");
|
|
5215
|
+
var import_icons5 = require("@ant-design/icons");
|
|
2708
5216
|
|
|
2709
5217
|
// packages/sdk/src/components/utils/confirmAction.ts
|
|
2710
5218
|
var confirmAction = (title, content) => {
|
|
@@ -2720,7 +5228,7 @@ var confirmAction = (title, content) => {
|
|
|
2720
5228
|
};
|
|
2721
5229
|
|
|
2722
5230
|
// packages/sdk/src/components/modules/StickyActionBar.tsx
|
|
2723
|
-
var
|
|
5231
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
2724
5232
|
var getActionPriority = (action) => {
|
|
2725
5233
|
const maybePriority = action.priority;
|
|
2726
5234
|
if (typeof maybePriority === "number") return maybePriority;
|
|
@@ -2738,14 +5246,14 @@ var StickyActionBar = ({
|
|
|
2738
5246
|
position = "sticky",
|
|
2739
5247
|
surface = "default"
|
|
2740
5248
|
}) => {
|
|
2741
|
-
const [isMobile, setIsMobile] = (0,
|
|
2742
|
-
(0,
|
|
5249
|
+
const [isMobile, setIsMobile] = (0, import_react11.useState)(false);
|
|
5250
|
+
(0, import_react11.useEffect)(() => {
|
|
2743
5251
|
const update = () => setIsMobile(typeof window !== "undefined" && window.innerWidth <= 768);
|
|
2744
5252
|
update();
|
|
2745
5253
|
window.addEventListener("resize", update);
|
|
2746
5254
|
return () => window.removeEventListener("resize", update);
|
|
2747
5255
|
}, []);
|
|
2748
|
-
const visibleActions = (0,
|
|
5256
|
+
const visibleActions = (0, import_react11.useMemo)(
|
|
2749
5257
|
() => actions.filter((action) => action.visible !== false).sort((left, right) => getActionPriority(left) - getActionPriority(right)),
|
|
2750
5258
|
[actions]
|
|
2751
5259
|
);
|
|
@@ -2766,8 +5274,8 @@ var StickyActionBar = ({
|
|
|
2766
5274
|
action.onClick();
|
|
2767
5275
|
};
|
|
2768
5276
|
const renderButton = (action, mobile = false) => {
|
|
2769
|
-
const button = /* @__PURE__ */ (0,
|
|
2770
|
-
|
|
5277
|
+
const button = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
5278
|
+
import_antd6.Button,
|
|
2771
5279
|
{
|
|
2772
5280
|
type: action.type === "danger" ? "primary" : action.type === "text" ? "text" : action.type || "default",
|
|
2773
5281
|
danger: action.type === "danger",
|
|
@@ -2781,17 +5289,17 @@ var StickyActionBar = ({
|
|
|
2781
5289
|
action.key
|
|
2782
5290
|
);
|
|
2783
5291
|
if (!action.disabled || !action.disabledReason) return button;
|
|
2784
|
-
return /* @__PURE__ */ (0,
|
|
5292
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_antd6.Tooltip, { title: action.disabledReason, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("span", { className: mobile ? "flex min-w-0 flex-1" : "inline-flex", children: button }) }, action.key);
|
|
2785
5293
|
};
|
|
2786
|
-
return /* @__PURE__ */ (0,
|
|
5294
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `${positionClass} z-20 ${spacingClass} ${surfaceClass} ${className}`, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2787
5295
|
"div",
|
|
2788
5296
|
{
|
|
2789
5297
|
className: `mx-auto flex w-full items-center gap-3 ${!isMobile ? desktopJustifyClass : "justify-end"}`,
|
|
2790
5298
|
style: { maxWidth: maxWidthStyle },
|
|
2791
|
-
children: isMobile ? /* @__PURE__ */ (0,
|
|
2792
|
-
/* @__PURE__ */ (0,
|
|
2793
|
-
moreMobile.length > 0 && /* @__PURE__ */ (0,
|
|
2794
|
-
|
|
5299
|
+
children: isMobile ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
5300
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex flex-1 gap-2", children: primaryMobile.map((action) => renderButton(action, true)) }),
|
|
5301
|
+
moreMobile.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
5302
|
+
import_antd6.Dropdown,
|
|
2795
5303
|
{
|
|
2796
5304
|
trigger: ["click"],
|
|
2797
5305
|
placement: "topRight",
|
|
@@ -2805,17 +5313,17 @@ var StickyActionBar = ({
|
|
|
2805
5313
|
onClick: () => runAction(action)
|
|
2806
5314
|
}))
|
|
2807
5315
|
},
|
|
2808
|
-
children: /* @__PURE__ */ (0,
|
|
5316
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_antd6.Button, { icon: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(import_icons5.MoreOutlined, {}), className: "rounded-md", children: "\u66F4\u591A" })
|
|
2809
5317
|
}
|
|
2810
5318
|
)
|
|
2811
|
-
] }) : layoutMode === "approval" ? /* @__PURE__ */ (0,
|
|
5319
|
+
] }) : layoutMode === "approval" ? /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex flex-wrap items-center justify-center gap-3", children: visibleActions.map((action) => renderButton(action)) }) : /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `flex flex-wrap items-center ${desktopJustifyClass} gap-3`, children: visibleActions.map((action) => renderButton(action)) })
|
|
2812
5320
|
}
|
|
2813
5321
|
) });
|
|
2814
5322
|
};
|
|
2815
5323
|
|
|
2816
5324
|
// packages/sdk/src/components/modules/ApprovalTimeline.tsx
|
|
2817
|
-
var
|
|
2818
|
-
var
|
|
5325
|
+
var import_react12 = require("react");
|
|
5326
|
+
var import_icons6 = require("@ant-design/icons");
|
|
2819
5327
|
|
|
2820
5328
|
// packages/sdk/src/components/core/constants.ts
|
|
2821
5329
|
var TASK_STATUS_META = {
|
|
@@ -2831,7 +5339,7 @@ var TASK_STATUS_META = {
|
|
|
2831
5339
|
};
|
|
2832
5340
|
|
|
2833
5341
|
// packages/sdk/src/components/modules/ApprovalTimeline.tsx
|
|
2834
|
-
var
|
|
5342
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2835
5343
|
var systemNodeTypes = /* @__PURE__ */ new Set([
|
|
2836
5344
|
"condition",
|
|
2837
5345
|
"condition_branch",
|
|
@@ -2925,37 +5433,37 @@ function getStatusMeta(task, state, compact) {
|
|
|
2925
5433
|
}
|
|
2926
5434
|
function getIcon(task, state) {
|
|
2927
5435
|
if (state === "current")
|
|
2928
|
-
return task.nodeType === "callback_wait" ? /* @__PURE__ */ (0,
|
|
5436
|
+
return task.nodeType === "callback_wait" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.ClockCircleOutlined, {}) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.LoadingOutlined, {});
|
|
2929
5437
|
if (state === "future" || state === "waiting")
|
|
2930
|
-
return task.nodeType === "approval" ? /* @__PURE__ */ (0,
|
|
2931
|
-
if (state === "rejected") return /* @__PURE__ */ (0,
|
|
2932
|
-
if (state === "returned") return /* @__PURE__ */ (0,
|
|
5438
|
+
return task.nodeType === "approval" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.UserOutlined, {}) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.ClockCircleOutlined, {});
|
|
5439
|
+
if (state === "rejected") return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.CloseCircleFilled, {});
|
|
5440
|
+
if (state === "returned") return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.RollbackOutlined, {});
|
|
2933
5441
|
switch (task.nodeType) {
|
|
2934
5442
|
case "start":
|
|
2935
|
-
return /* @__PURE__ */ (0,
|
|
5443
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.FileTextOutlined, {});
|
|
2936
5444
|
case "approval":
|
|
2937
|
-
return /* @__PURE__ */ (0,
|
|
5445
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.CheckCircleFilled, {});
|
|
2938
5446
|
case "originator_return":
|
|
2939
|
-
return /* @__PURE__ */ (0,
|
|
5447
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.EditOutlined, {});
|
|
2940
5448
|
case "copy":
|
|
2941
|
-
return /* @__PURE__ */ (0,
|
|
5449
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.CopyOutlined, {});
|
|
2942
5450
|
case "callback_wait":
|
|
2943
|
-
return /* @__PURE__ */ (0,
|
|
5451
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.ClockCircleOutlined, {});
|
|
2944
5452
|
case "js_code":
|
|
2945
|
-
return /* @__PURE__ */ (0,
|
|
5453
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.CodeOutlined, {});
|
|
2946
5454
|
case "connector_call":
|
|
2947
|
-
return /* @__PURE__ */ (0,
|
|
5455
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.ApiOutlined, {});
|
|
2948
5456
|
case "work_notification":
|
|
2949
5457
|
case "dingtalk_card":
|
|
2950
|
-
return /* @__PURE__ */ (0,
|
|
5458
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.NotificationOutlined, {});
|
|
2951
5459
|
case "data_retrieve_single":
|
|
2952
5460
|
case "data_retrieve_batch":
|
|
2953
5461
|
case "data_create":
|
|
2954
5462
|
case "data_update":
|
|
2955
5463
|
case "loop_container":
|
|
2956
|
-
return /* @__PURE__ */ (0,
|
|
5464
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.ReloadOutlined, {});
|
|
2957
5465
|
default:
|
|
2958
|
-
return /* @__PURE__ */ (0,
|
|
5466
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.CheckCircleFilled, {});
|
|
2959
5467
|
}
|
|
2960
5468
|
}
|
|
2961
5469
|
function getDotClass(state) {
|
|
@@ -2978,21 +5486,21 @@ var ApprovalTimeline = ({
|
|
|
2978
5486
|
compactMode = false,
|
|
2979
5487
|
showApproverInfo = true
|
|
2980
5488
|
}) => {
|
|
2981
|
-
const taskList = (0,
|
|
2982
|
-
const groups = (0,
|
|
5489
|
+
const taskList = (0, import_react12.useMemo)(() => Array.isArray(tasks) ? tasks : [], [tasks]);
|
|
5490
|
+
const groups = (0, import_react12.useMemo)(() => groupTasks(taskList), [taskList]);
|
|
2983
5491
|
if (taskList.length === 0) {
|
|
2984
|
-
return /* @__PURE__ */ (0,
|
|
5492
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2985
5493
|
"div",
|
|
2986
5494
|
{
|
|
2987
5495
|
className: `rounded-lg border border-ant-border-secondary bg-ant-bg-container p-6 ${className}`,
|
|
2988
|
-
children: /* @__PURE__ */ (0,
|
|
5496
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("p", { className: "m-0 text-center text-sm text-ant-text-tertiary", children: "\u6682\u65E0\u5BA1\u6279\u8BB0\u5F55" })
|
|
2989
5497
|
}
|
|
2990
5498
|
);
|
|
2991
5499
|
}
|
|
2992
5500
|
if (renderNode) {
|
|
2993
|
-
return /* @__PURE__ */ (0,
|
|
5501
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className, children: taskList.map((task, index) => /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { children: renderNode(task, index) }, task.taskId || task.id || index)) });
|
|
2994
5502
|
}
|
|
2995
|
-
return /* @__PURE__ */ (0,
|
|
5503
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: `approval-timeline ${className}`, children: groups.map((group, index) => {
|
|
2996
5504
|
const node = group[0];
|
|
2997
5505
|
const isLast = index === groups.length - 1;
|
|
2998
5506
|
const isFutureGroup = group.some((task) => task.isSimulated || task.status === "simulated");
|
|
@@ -3001,62 +5509,62 @@ var ApprovalTimeline = ({
|
|
|
3001
5509
|
const statusMeta = getStatusMeta(node, state, compact);
|
|
3002
5510
|
const title = getNodeTitle(node);
|
|
3003
5511
|
const time = node.actionAt || node.createdAt;
|
|
3004
|
-
return /* @__PURE__ */ (0,
|
|
5512
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
3005
5513
|
"div",
|
|
3006
5514
|
{
|
|
3007
5515
|
className: `relative flex gap-4 pb-5 ${isLast ? "pb-0" : ""}`,
|
|
3008
5516
|
children: [
|
|
3009
|
-
!isLast && /* @__PURE__ */ (0,
|
|
5517
|
+
!isLast && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3010
5518
|
"div",
|
|
3011
5519
|
{
|
|
3012
5520
|
className: `absolute bottom-0 left-[21px] top-11 w-px ${state === "future" ? "border-l border-dashed border-gray-300" : "bg-ant-border-secondary"}`
|
|
3013
5521
|
}
|
|
3014
5522
|
),
|
|
3015
|
-
/* @__PURE__ */ (0,
|
|
5523
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3016
5524
|
"div",
|
|
3017
5525
|
{
|
|
3018
5526
|
className: `relative z-10 flex h-11 w-11 shrink-0 items-center justify-center rounded-full border-2 shadow-[0_0_0_4px_var(--ant-color-bg-layout,#f5f5f5)] ${getDotClass(state)}`,
|
|
3019
5527
|
children: getIcon(node, state)
|
|
3020
5528
|
}
|
|
3021
5529
|
),
|
|
3022
|
-
/* @__PURE__ */ (0,
|
|
5530
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
3023
5531
|
"div",
|
|
3024
5532
|
{
|
|
3025
5533
|
className: `rounded-lg border p-4 ${state === "current" ? "border-blue-300 bg-blue-50/60" : state === "future" ? "border-dashed border-gray-200 bg-gray-50/70" : "border-ant-border-secondary bg-ant-bg-container"}`,
|
|
3026
5534
|
children: [
|
|
3027
|
-
/* @__PURE__ */ (0,
|
|
3028
|
-
/* @__PURE__ */ (0,
|
|
3029
|
-
/* @__PURE__ */ (0,
|
|
3030
|
-
/* @__PURE__ */ (0,
|
|
5535
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex flex-wrap items-start justify-between gap-2", children: [
|
|
5536
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [
|
|
5537
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "font-medium text-ant-text", children: title }),
|
|
5538
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3031
5539
|
"span",
|
|
3032
5540
|
{
|
|
3033
5541
|
className: `inline-flex min-h-6 items-center rounded-md border px-2 text-xs font-medium ${state === "future" ? toneClasses.future : toneClasses[statusMeta.tone]}`,
|
|
3034
5542
|
children: statusMeta.label
|
|
3035
5543
|
}
|
|
3036
5544
|
),
|
|
3037
|
-
node.nodeType === "originator_return" && /* @__PURE__ */ (0,
|
|
5545
|
+
node.nodeType === "originator_return" && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "rounded-md bg-amber-50 px-2 py-1 text-xs text-amber-700", children: "\u53D1\u8D77\u4EBA\u64CD\u4F5C" })
|
|
3038
5546
|
] }),
|
|
3039
|
-
!isFutureGroup && time && /* @__PURE__ */ (0,
|
|
5547
|
+
!isFutureGroup && time && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-xs text-ant-text-tertiary", children: time })
|
|
3040
5548
|
] }),
|
|
3041
|
-
showApproverInfo && !compact && group.length > 0 && /* @__PURE__ */ (0,
|
|
3042
|
-
/* @__PURE__ */ (0,
|
|
3043
|
-
group.map((assignee) => /* @__PURE__ */ (0,
|
|
5549
|
+
showApproverInfo && !compact && group.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "mt-3 flex flex-wrap gap-3", children: [
|
|
5550
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "w-full text-xs font-medium text-ant-text-tertiary", children: state === "current" || state === "waiting" ? "\u5F53\u524D\u5BA1\u6279\u4EBA" : "\u5904\u7406\u4EBA" }),
|
|
5551
|
+
group.map((assignee) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
3044
5552
|
"span",
|
|
3045
5553
|
{
|
|
3046
5554
|
className: "inline-flex min-w-0 items-center gap-2",
|
|
3047
5555
|
children: [
|
|
3048
|
-
/* @__PURE__ */ (0,
|
|
3049
|
-
/* @__PURE__ */ (0,
|
|
3050
|
-
/* @__PURE__ */ (0,
|
|
3051
|
-
/* @__PURE__ */ (0,
|
|
5556
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-full bg-blue-50 text-xs font-semibold text-blue-700", children: assignee.assigneeName?.slice(0, 1) || "?" }),
|
|
5557
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: "min-w-0", children: [
|
|
5558
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "block text-sm font-medium text-ant-text", children: assignee.assigneeName || "\u7CFB\u7EDF" }),
|
|
5559
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "block text-xs text-ant-text-tertiary", children: assignee.departmentName || assignee.actionAt || assignee.createdAt || "" })
|
|
3052
5560
|
] })
|
|
3053
5561
|
]
|
|
3054
5562
|
},
|
|
3055
5563
|
assignee.taskId || assignee.id
|
|
3056
5564
|
))
|
|
3057
5565
|
] }),
|
|
3058
|
-
showApproverInfo && compact && /* @__PURE__ */ (0,
|
|
3059
|
-
showRemarks && node.comments && /* @__PURE__ */ (0,
|
|
5566
|
+
showApproverInfo && compact && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "mt-2 text-sm text-ant-text-secondary", children: group.map((item) => item.assigneeName).filter(Boolean).join("\u3001") || (node.nodeType === "start" ? "\u63D0\u4EA4\u7533\u8BF7" : systemNodeTypes.has(node.nodeType) ? node.comments || "\u7CFB\u7EDF\u81EA\u52A8\u5904\u7406" : "") }),
|
|
5567
|
+
showRemarks && node.comments && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3060
5568
|
"div",
|
|
3061
5569
|
{
|
|
3062
5570
|
className: `mt-3 border-l-2 pl-3 text-sm leading-6 ${state === "rejected" ? "border-red-300 text-red-700" : state === "returned" ? "border-amber-300 text-amber-700" : "border-ant-border-secondary text-ant-text-secondary"}`,
|
|
@@ -3074,9 +5582,9 @@ var ApprovalTimeline = ({
|
|
|
3074
5582
|
};
|
|
3075
5583
|
|
|
3076
5584
|
// packages/sdk/src/components/modules/ProcessPreview.tsx
|
|
3077
|
-
var
|
|
3078
|
-
var
|
|
3079
|
-
var
|
|
5585
|
+
var import_antd7 = require("antd");
|
|
5586
|
+
var import_icons7 = require("@ant-design/icons");
|
|
5587
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
3080
5588
|
var ProcessPreview = ({
|
|
3081
5589
|
open,
|
|
3082
5590
|
onClose,
|
|
@@ -3085,30 +5593,30 @@ var ProcessPreview = ({
|
|
|
3085
5593
|
loading = false
|
|
3086
5594
|
}) => {
|
|
3087
5595
|
const routeList = Array.isArray(routes) ? routes : [];
|
|
3088
|
-
return /* @__PURE__ */ (0,
|
|
3089
|
-
|
|
5596
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
5597
|
+
import_antd7.Modal,
|
|
3090
5598
|
{
|
|
3091
5599
|
getContainer: false,
|
|
3092
5600
|
title: "\u6D41\u7A0B\u9884\u89C8",
|
|
3093
5601
|
open,
|
|
3094
5602
|
onCancel: onClose,
|
|
3095
5603
|
width: 520,
|
|
3096
|
-
footer: /* @__PURE__ */ (0,
|
|
3097
|
-
/* @__PURE__ */ (0,
|
|
3098
|
-
/* @__PURE__ */ (0,
|
|
5604
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex justify-end gap-3", children: [
|
|
5605
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_antd7.Button, { onClick: onClose, children: "\u53D6\u6D88" }),
|
|
5606
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_antd7.Button, { type: "primary", onClick: onConfirm, loading, children: "\u786E\u8BA4\u63D0\u4EA4" })
|
|
3099
5607
|
] }),
|
|
3100
|
-
children: loading && routeList.length === 0 ? /* @__PURE__ */ (0,
|
|
5608
|
+
children: loading && routeList.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_antd7.Skeleton, { active: true, paragraph: { rows: 4 } }) : routeList.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("p", { className: "text-sm text-gray-400 text-center py-8", children: "\u6682\u65E0\u6D41\u7A0B\u8282\u70B9" }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "py-2", children: routeList.map((route, index) => {
|
|
3101
5609
|
const isLast = index === routeList.length - 1;
|
|
3102
|
-
return /* @__PURE__ */ (0,
|
|
3103
|
-
/* @__PURE__ */ (0,
|
|
3104
|
-
/* @__PURE__ */ (0,
|
|
3105
|
-
!isLast && /* @__PURE__ */ (0,
|
|
5610
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex gap-3", children: [
|
|
5611
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex flex-col items-center", children: [
|
|
5612
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "w-6 h-6 rounded-full bg-blue-50 border-2 border-blue-400 flex items-center justify-center flex-shrink-0", children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_icons7.CheckCircleOutlined, { className: "text-blue-500 text-xs" }) }),
|
|
5613
|
+
!isLast && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "w-0.5 flex-1 bg-blue-200 mt-1" })
|
|
3106
5614
|
] }),
|
|
3107
|
-
/* @__PURE__ */ (0,
|
|
3108
|
-
/* @__PURE__ */ (0,
|
|
3109
|
-
route.assignees && route.assignees.length > 0 && /* @__PURE__ */ (0,
|
|
3110
|
-
/* @__PURE__ */ (0,
|
|
3111
|
-
route.assignees.map((assignee) => /* @__PURE__ */ (0,
|
|
5615
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: `flex-1 ${isLast ? "pb-0" : "pb-5"}`, children: [
|
|
5616
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "text-sm font-medium text-gray-900", children: route.nodeName }),
|
|
5617
|
+
route.assignees && route.assignees.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "mt-1 flex items-center gap-1.5 flex-wrap", children: [
|
|
5618
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_icons7.UserOutlined, { className: "text-gray-400 text-xs" }),
|
|
5619
|
+
route.assignees.map((assignee) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
3112
5620
|
"span",
|
|
3113
5621
|
{
|
|
3114
5622
|
className: "text-xs text-gray-500 bg-gray-100 px-1.5 py-0.5 rounded",
|
|
@@ -3125,20 +5633,20 @@ var ProcessPreview = ({
|
|
|
3125
5633
|
};
|
|
3126
5634
|
|
|
3127
5635
|
// packages/sdk/src/components/modules/InitiatorApproverSelector.tsx
|
|
3128
|
-
var
|
|
3129
|
-
var
|
|
5636
|
+
var import_react15 = require("react");
|
|
5637
|
+
var import_antd9 = require("antd");
|
|
3130
5638
|
|
|
3131
5639
|
// packages/sdk/src/components/core/processApi.ts
|
|
3132
5640
|
var hasOwn2 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
3133
5641
|
var isRuntimeEnvelope = (value) => !!value && typeof value === "object" && !Array.isArray(value) && (hasOwn2(value, "code") || hasOwn2(value, "success") || hasOwn2(value, "data") || hasOwn2(value, "result") || hasOwn2(value, "message") || hasOwn2(value, "error"));
|
|
3134
|
-
var
|
|
5642
|
+
var isSuccessCode3 = (code) => {
|
|
3135
5643
|
if (code === void 0 || code === null || code === "") return true;
|
|
3136
5644
|
const normalized = Number(code);
|
|
3137
5645
|
return Number.isFinite(normalized) ? normalized === 0 || normalized === 200 : false;
|
|
3138
5646
|
};
|
|
3139
5647
|
var unwrapRuntimeResponse = (response) => {
|
|
3140
5648
|
if (!isRuntimeEnvelope(response)) return response;
|
|
3141
|
-
if (response.success === false || !
|
|
5649
|
+
if (response.success === false || !isSuccessCode3(response.code)) {
|
|
3142
5650
|
throw new Error(response.message || response.error || "\u8BF7\u6C42\u5931\u8D25");
|
|
3143
5651
|
}
|
|
3144
5652
|
if (hasOwn2(response, "data")) return response.data;
|
|
@@ -3170,75 +5678,13 @@ async function getInitiatorSelectCandidates(request, params) {
|
|
|
3170
5678
|
}
|
|
3171
5679
|
|
|
3172
5680
|
// packages/sdk/src/components/fields/shared/UserPicker.tsx
|
|
3173
|
-
var
|
|
3174
|
-
var
|
|
3175
|
-
var
|
|
5681
|
+
var import_react14 = require("react");
|
|
5682
|
+
var import_antd8 = require("antd");
|
|
5683
|
+
var import_icons8 = require("@ant-design/icons");
|
|
3176
5684
|
var MobileAntd = __toESM(require("antd-mobile"));
|
|
3177
5685
|
|
|
3178
|
-
// packages/sdk/src/components/fields/shared/fieldFormat.ts
|
|
3179
|
-
function getUserId(user) {
|
|
3180
|
-
if (typeof user === "string" || typeof user === "number") return String(user).trim();
|
|
3181
|
-
return String(user?.id || user?.userId || user?.userid || user?.value || user?.key || "").trim();
|
|
3182
|
-
}
|
|
3183
|
-
function getUserName(user) {
|
|
3184
|
-
if (typeof user === "string" || typeof user === "number") return String(user).trim();
|
|
3185
|
-
return String(
|
|
3186
|
-
user?.name || user?.label || user?.title || user?.username || user?.nickname || getUserId(user)
|
|
3187
|
-
);
|
|
3188
|
-
}
|
|
3189
|
-
function normalizeUser(user) {
|
|
3190
|
-
const id = getUserId(user);
|
|
3191
|
-
const source = typeof user === "object" && user !== null ? user : {};
|
|
3192
|
-
return {
|
|
3193
|
-
...source,
|
|
3194
|
-
id,
|
|
3195
|
-
name: getUserName({ ...source, id })
|
|
3196
|
-
};
|
|
3197
|
-
}
|
|
3198
|
-
function getDepartmentId(node) {
|
|
3199
|
-
if (typeof node === "string" || typeof node === "number") return String(node).trim();
|
|
3200
|
-
return String(
|
|
3201
|
-
node?.id || node?.departmentId || node?.deptId || node?.value || node?.key || ""
|
|
3202
|
-
).trim();
|
|
3203
|
-
}
|
|
3204
|
-
function getDepartmentName(node) {
|
|
3205
|
-
if (typeof node === "string" || typeof node === "number") return String(node).trim();
|
|
3206
|
-
return String(
|
|
3207
|
-
node?.name || node?.label || node?.title || node?.deptName || node?.departmentName || getDepartmentId(node)
|
|
3208
|
-
);
|
|
3209
|
-
}
|
|
3210
|
-
function normalizeDepartmentNode(node) {
|
|
3211
|
-
const id = getDepartmentId(node);
|
|
3212
|
-
const source = typeof node === "object" && node !== null ? node : {};
|
|
3213
|
-
const name = getDepartmentName({ ...source, id });
|
|
3214
|
-
const hasChildren = typeof node?.hasChildren === "boolean" ? node.hasChildren : Array.isArray(node?.children) && node.children.length > 0;
|
|
3215
|
-
const children = Array.isArray(node?.children) ? node.children.map((child) => normalizeDepartmentNode(child)) : void 0;
|
|
3216
|
-
return {
|
|
3217
|
-
...source,
|
|
3218
|
-
id,
|
|
3219
|
-
name,
|
|
3220
|
-
key: String(node?.key || id),
|
|
3221
|
-
title: String(node?.title || name),
|
|
3222
|
-
hasChildren,
|
|
3223
|
-
isLeaf: typeof node?.isLeaf === "boolean" ? node.isLeaf : !hasChildren,
|
|
3224
|
-
children
|
|
3225
|
-
};
|
|
3226
|
-
}
|
|
3227
|
-
function flattenDepartments(nodes) {
|
|
3228
|
-
const result = [];
|
|
3229
|
-
const walk = (items) => {
|
|
3230
|
-
for (const node of items) {
|
|
3231
|
-
const id = getDepartmentId(node);
|
|
3232
|
-
if (id) result.push({ id, name: getDepartmentName(node), node });
|
|
3233
|
-
if (node.children?.length) walk(node.children);
|
|
3234
|
-
}
|
|
3235
|
-
};
|
|
3236
|
-
walk(nodes);
|
|
3237
|
-
return result;
|
|
3238
|
-
}
|
|
3239
|
-
|
|
3240
5686
|
// packages/sdk/src/components/fields/shared/useLazyDepartmentTree.ts
|
|
3241
|
-
var
|
|
5687
|
+
var import_react13 = require("react");
|
|
3242
5688
|
var toLazyNode = (node) => {
|
|
3243
5689
|
const normalized = normalizeDepartmentNode(node);
|
|
3244
5690
|
const id = getDepartmentId(normalized);
|
|
@@ -3288,15 +5734,15 @@ function buildIndexes(nodes) {
|
|
|
3288
5734
|
return { nodeMap, parentMap, flatNodes };
|
|
3289
5735
|
}
|
|
3290
5736
|
function useLazyDepartmentTree(api, configuredTreeData) {
|
|
3291
|
-
const [treeData, setTreeDataState] = (0,
|
|
5737
|
+
const [treeData, setTreeDataState] = (0, import_react13.useState)(
|
|
3292
5738
|
() => (configuredTreeData || []).map(toLazyNode)
|
|
3293
5739
|
);
|
|
3294
|
-
const [treeLoading, setTreeLoading] = (0,
|
|
3295
|
-
const treeDataRef = (0,
|
|
3296
|
-
const rootsLoadedRef = (0,
|
|
3297
|
-
const rootPromiseRef = (0,
|
|
3298
|
-
const childPromiseRef = (0,
|
|
3299
|
-
const setTreeData = (0,
|
|
5740
|
+
const [treeLoading, setTreeLoading] = (0, import_react13.useState)(false);
|
|
5741
|
+
const treeDataRef = (0, import_react13.useRef)(treeData);
|
|
5742
|
+
const rootsLoadedRef = (0, import_react13.useRef)(Boolean(configuredTreeData?.length));
|
|
5743
|
+
const rootPromiseRef = (0, import_react13.useRef)(null);
|
|
5744
|
+
const childPromiseRef = (0, import_react13.useRef)({});
|
|
5745
|
+
const setTreeData = (0, import_react13.useCallback)(
|
|
3300
5746
|
(next) => {
|
|
3301
5747
|
const resolved = typeof next === "function" ? next(treeDataRef.current) : next;
|
|
3302
5748
|
treeDataRef.current = resolved;
|
|
@@ -3305,13 +5751,13 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3305
5751
|
},
|
|
3306
5752
|
[]
|
|
3307
5753
|
);
|
|
3308
|
-
(0,
|
|
5754
|
+
(0, import_react13.useEffect)(() => {
|
|
3309
5755
|
if (!configuredTreeData) return;
|
|
3310
5756
|
const next = configuredTreeData.map(toLazyNode);
|
|
3311
5757
|
rootsLoadedRef.current = next.length > 0;
|
|
3312
5758
|
setTreeData(next);
|
|
3313
5759
|
}, [configuredTreeData, setTreeData]);
|
|
3314
|
-
const loadRootDepartments = (0,
|
|
5760
|
+
const loadRootDepartments = (0, import_react13.useCallback)(async () => {
|
|
3315
5761
|
if (rootsLoadedRef.current) return treeDataRef.current;
|
|
3316
5762
|
if (rootPromiseRef.current) return rootPromiseRef.current;
|
|
3317
5763
|
setTreeLoading(true);
|
|
@@ -3327,7 +5773,7 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3327
5773
|
rootPromiseRef.current = promise;
|
|
3328
5774
|
return promise;
|
|
3329
5775
|
}, [api, setTreeData]);
|
|
3330
|
-
const loadChildren = (0,
|
|
5776
|
+
const loadChildren = (0, import_react13.useCallback)(
|
|
3331
5777
|
async (parentId) => {
|
|
3332
5778
|
const id = String(parentId || "");
|
|
3333
5779
|
if (!id) return [];
|
|
@@ -3348,8 +5794,8 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3348
5794
|
},
|
|
3349
5795
|
[api, setTreeData]
|
|
3350
5796
|
);
|
|
3351
|
-
const indexes = (0,
|
|
3352
|
-
(0,
|
|
5797
|
+
const indexes = (0, import_react13.useMemo)(() => buildIndexes(treeData), [treeData]);
|
|
5798
|
+
(0, import_react13.useEffect)(() => {
|
|
3353
5799
|
void loadRootDepartments();
|
|
3354
5800
|
}, [loadRootDepartments]);
|
|
3355
5801
|
return {
|
|
@@ -3362,7 +5808,7 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3362
5808
|
}
|
|
3363
5809
|
|
|
3364
5810
|
// packages/sdk/src/components/fields/shared/UserPicker.tsx
|
|
3365
|
-
var
|
|
5811
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
3366
5812
|
var DEFAULT_MEMBER_PAGE_SIZE = 10;
|
|
3367
5813
|
var getMobileComponent = (name) => {
|
|
3368
5814
|
try {
|
|
@@ -3394,24 +5840,24 @@ function UserPickerPanel({
|
|
|
3394
5840
|
flatNodes,
|
|
3395
5841
|
loadChildren
|
|
3396
5842
|
} = useLazyDepartmentTree(api, treeData);
|
|
3397
|
-
const [departmentKeyword, setDepartmentKeyword] = (0,
|
|
3398
|
-
const [memberKeyword, setMemberKeyword] = (0,
|
|
3399
|
-
const [mobileKeyword, setMobileKeyword] = (0,
|
|
3400
|
-
const [currentDeptId, setCurrentDeptId] = (0,
|
|
3401
|
-
const [expandedKeys, setExpandedKeys] = (0,
|
|
3402
|
-
const [members, setMembers] = (0,
|
|
3403
|
-
const [memberPage, setMemberPage] = (0,
|
|
3404
|
-
const [memberPageSize, setMemberPageSize] = (0,
|
|
3405
|
-
const [memberTotal, setMemberTotal] = (0,
|
|
3406
|
-
const [memberReloadKey, setMemberReloadKey] = (0,
|
|
3407
|
-
const [loading, setLoading] = (0,
|
|
3408
|
-
const [selected, setSelected] = (0,
|
|
5843
|
+
const [departmentKeyword, setDepartmentKeyword] = (0, import_react14.useState)("");
|
|
5844
|
+
const [memberKeyword, setMemberKeyword] = (0, import_react14.useState)("");
|
|
5845
|
+
const [mobileKeyword, setMobileKeyword] = (0, import_react14.useState)("");
|
|
5846
|
+
const [currentDeptId, setCurrentDeptId] = (0, import_react14.useState)("");
|
|
5847
|
+
const [expandedKeys, setExpandedKeys] = (0, import_react14.useState)([]);
|
|
5848
|
+
const [members, setMembers] = (0, import_react14.useState)(() => normalizeUsers(dataSource));
|
|
5849
|
+
const [memberPage, setMemberPage] = (0, import_react14.useState)(1);
|
|
5850
|
+
const [memberPageSize, setMemberPageSize] = (0, import_react14.useState)(DEFAULT_MEMBER_PAGE_SIZE);
|
|
5851
|
+
const [memberTotal, setMemberTotal] = (0, import_react14.useState)(() => normalizeUsers(dataSource).length);
|
|
5852
|
+
const [memberReloadKey, setMemberReloadKey] = (0, import_react14.useState)(0);
|
|
5853
|
+
const [loading, setLoading] = (0, import_react14.useState)(false);
|
|
5854
|
+
const [selected, setSelected] = (0, import_react14.useState)(() => normalizeUsers(value));
|
|
3409
5855
|
const selectedIds = selected.map(getUserId);
|
|
3410
5856
|
const MobileSearchBar = getMobileComponent("SearchBar");
|
|
3411
5857
|
const activeMemberKeyword = (mobile ? mobileKeyword : memberKeyword).trim();
|
|
3412
|
-
const staticUsers = (0,
|
|
5858
|
+
const staticUsers = (0, import_react14.useMemo)(() => normalizeUsers(dataSource), [dataSource]);
|
|
3413
5859
|
const hasStaticUserSource = staticUsers.length > 0;
|
|
3414
|
-
(0,
|
|
5860
|
+
(0, import_react14.useEffect)(() => {
|
|
3415
5861
|
if (mobile) return;
|
|
3416
5862
|
if (currentDeptId || deptTreeData.length === 0) return;
|
|
3417
5863
|
setExpandedKeys(deptTreeData.map((node) => getDepartmentId(node)));
|
|
@@ -3419,17 +5865,17 @@ function UserPickerPanel({
|
|
|
3419
5865
|
setCurrentDeptId(getDepartmentId(deptTreeData[0]));
|
|
3420
5866
|
}
|
|
3421
5867
|
}, [currentDeptId, deptTreeData, loadAllWhenNoDepartment, mobile]);
|
|
3422
|
-
(0,
|
|
5868
|
+
(0, import_react14.useEffect)(() => {
|
|
3423
5869
|
setMemberPage(1);
|
|
3424
5870
|
}, [activeMemberKeyword, currentDeptId, dataSource, mobile]);
|
|
3425
|
-
const handleDepartmentSelect = (0,
|
|
5871
|
+
const handleDepartmentSelect = (0, import_react14.useCallback)((deptId) => {
|
|
3426
5872
|
const nextDeptId = String(deptId || "");
|
|
3427
5873
|
setCurrentDeptId(nextDeptId);
|
|
3428
5874
|
setMemberKeyword("");
|
|
3429
5875
|
setMemberPage(1);
|
|
3430
5876
|
setMemberReloadKey((current) => current + 1);
|
|
3431
5877
|
}, []);
|
|
3432
|
-
(0,
|
|
5878
|
+
(0, import_react14.useEffect)(() => {
|
|
3433
5879
|
let active = true;
|
|
3434
5880
|
const keyword = activeMemberKeyword;
|
|
3435
5881
|
if (hasStaticUserSource) {
|
|
@@ -3502,7 +5948,7 @@ function UserPickerPanel({
|
|
|
3502
5948
|
memberReloadKey,
|
|
3503
5949
|
staticUsers
|
|
3504
5950
|
]);
|
|
3505
|
-
const currentPath = (0,
|
|
5951
|
+
const currentPath = (0, import_react14.useMemo)(() => {
|
|
3506
5952
|
if (!currentDeptId) return [];
|
|
3507
5953
|
const path = [];
|
|
3508
5954
|
let cursor = currentDeptId;
|
|
@@ -3514,7 +5960,7 @@ function UserPickerPanel({
|
|
|
3514
5960
|
}
|
|
3515
5961
|
return path;
|
|
3516
5962
|
}, [currentDeptId, nodeMap, parentMap]);
|
|
3517
|
-
const mobileDepartments = (0,
|
|
5963
|
+
const mobileDepartments = (0, import_react14.useMemo)(() => {
|
|
3518
5964
|
const keyword = mobileKeyword.trim().toLowerCase();
|
|
3519
5965
|
if (keyword) {
|
|
3520
5966
|
return flatNodes.filter((item) => item.name.toLowerCase().includes(keyword)).map((item) => item.node);
|
|
@@ -3536,48 +5982,48 @@ function UserPickerPanel({
|
|
|
3536
5982
|
}
|
|
3537
5983
|
setSelected(checked ? [normalized] : []);
|
|
3538
5984
|
};
|
|
3539
|
-
const renderSelected = () => /* @__PURE__ */ (0,
|
|
3540
|
-
/* @__PURE__ */ (0,
|
|
3541
|
-
/* @__PURE__ */ (0,
|
|
5985
|
+
const renderSelected = () => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker-selected", children: [
|
|
5986
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-org-picker-selected-head", children: [
|
|
5987
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { children: [
|
|
3542
5988
|
"\u5DF2\u9009 ",
|
|
3543
5989
|
selected.length,
|
|
3544
5990
|
" \u4EBA"
|
|
3545
5991
|
] }),
|
|
3546
|
-
/* @__PURE__ */ (0,
|
|
5992
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: () => setSelected([]), disabled: !selected.length, children: "\u6E05\u7A7A" })
|
|
3547
5993
|
] }),
|
|
3548
|
-
selected.length ? /* @__PURE__ */ (0,
|
|
5994
|
+
selected.length ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "sy-org-picker-tags", children: selected.map((item) => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Tag, { closable: true, onClose: () => toggleUser(item, false), children: getUserName(item) }, getUserId(item))) }) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Empty, { image: import_antd8.Empty.PRESENTED_IMAGE_SIMPLE, description: "\u6682\u65E0\u9009\u62E9" })
|
|
3549
5995
|
] });
|
|
3550
|
-
const renderMemberList = () => /* @__PURE__ */ (0,
|
|
3551
|
-
/* @__PURE__ */ (0,
|
|
3552
|
-
|
|
5996
|
+
const renderMemberList = () => /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "sy-user-picker-member-panel", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_antd8.Spin, { spinning: loading, wrapperClassName: "sy-user-picker-member-spin", children: [
|
|
5997
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "sy-user-picker-list", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
5998
|
+
import_antd8.List,
|
|
3553
5999
|
{
|
|
3554
6000
|
dataSource: members,
|
|
3555
6001
|
locale: { emptyText: "\u6682\u65E0\u6210\u5458" },
|
|
3556
6002
|
renderItem: (user) => {
|
|
3557
6003
|
const id = getUserId(user);
|
|
3558
6004
|
const checked = selectedIds.includes(id);
|
|
3559
|
-
return /* @__PURE__ */ (0,
|
|
3560
|
-
/* @__PURE__ */ (0,
|
|
3561
|
-
|
|
6005
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.List.Item, { children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("label", { className: "sy-user-picker-row", children: [
|
|
6006
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6007
|
+
import_antd8.Checkbox,
|
|
3562
6008
|
{
|
|
3563
6009
|
checked,
|
|
3564
6010
|
onChange: (event) => toggleUser(user, event.target.checked)
|
|
3565
6011
|
}
|
|
3566
6012
|
),
|
|
3567
|
-
/* @__PURE__ */ (0,
|
|
3568
|
-
/* @__PURE__ */ (0,
|
|
6013
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Avatar, { size: 36, src: user.avatar, icon: !user.avatar && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons8.UserOutlined, {}) }),
|
|
6014
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { children: getUserName(user) })
|
|
3569
6015
|
] }) }, id);
|
|
3570
6016
|
}
|
|
3571
6017
|
}
|
|
3572
6018
|
) }),
|
|
3573
|
-
/* @__PURE__ */ (0,
|
|
3574
|
-
/* @__PURE__ */ (0,
|
|
6019
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker-pagination", children: [
|
|
6020
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { children: [
|
|
3575
6021
|
"\u5171 ",
|
|
3576
6022
|
memberTotal,
|
|
3577
6023
|
" \u4EBA"
|
|
3578
6024
|
] }),
|
|
3579
|
-
/* @__PURE__ */ (0,
|
|
3580
|
-
|
|
6025
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6026
|
+
import_antd8.Pagination,
|
|
3581
6027
|
{
|
|
3582
6028
|
size: "small",
|
|
3583
6029
|
current: memberPage,
|
|
@@ -3594,43 +6040,43 @@ function UserPickerPanel({
|
|
|
3594
6040
|
] })
|
|
3595
6041
|
] }) });
|
|
3596
6042
|
if (mobile) {
|
|
3597
|
-
return /* @__PURE__ */ (0,
|
|
3598
|
-
/* @__PURE__ */ (0,
|
|
3599
|
-
/* @__PURE__ */ (0,
|
|
3600
|
-
/* @__PURE__ */ (0,
|
|
3601
|
-
/* @__PURE__ */ (0,
|
|
6043
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker sy-user-picker-mobile", children: [
|
|
6044
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-org-picker-mobile-head", children: [
|
|
6045
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: onCancel, children: "\u53D6\u6D88" }),
|
|
6046
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("strong", { children: "\u9009\u62E9\u6210\u5458" }),
|
|
6047
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: () => onConfirm(selected), children: "\u786E\u5B9A" })
|
|
3602
6048
|
] }),
|
|
3603
|
-
MobileSearchBar ? /* @__PURE__ */ (0,
|
|
6049
|
+
MobileSearchBar ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3604
6050
|
MobileSearchBar,
|
|
3605
6051
|
{
|
|
3606
6052
|
placeholder: "\u641C\u7D22\u90E8\u95E8\u6216\u6210\u5458",
|
|
3607
6053
|
value: mobileKeyword,
|
|
3608
6054
|
onChange: setMobileKeyword
|
|
3609
6055
|
}
|
|
3610
|
-
) : /* @__PURE__ */ (0,
|
|
3611
|
-
/* @__PURE__ */ (0,
|
|
3612
|
-
/* @__PURE__ */ (0,
|
|
3613
|
-
currentPath.map((item) => /* @__PURE__ */ (0,
|
|
6056
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("input", { value: mobileKeyword, onChange: (event) => setMobileKeyword(event.target.value) }),
|
|
6057
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-org-picker-breadcrumb", children: [
|
|
6058
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: () => handleDepartmentSelect(""), children: "\u901A\u8BAF\u5F55" }),
|
|
6059
|
+
currentPath.map((item) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("button", { type: "button", onClick: () => handleDepartmentSelect(item.id), children: [
|
|
3614
6060
|
"/ ",
|
|
3615
6061
|
item.name
|
|
3616
6062
|
] }, item.id))
|
|
3617
6063
|
] }),
|
|
3618
|
-
/* @__PURE__ */ (0,
|
|
3619
|
-
|
|
6064
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Spin, { spinning: treeLoading, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6065
|
+
import_antd8.List,
|
|
3620
6066
|
{
|
|
3621
6067
|
dataSource: mobileDepartments,
|
|
3622
6068
|
locale: { emptyText: null },
|
|
3623
6069
|
renderItem: (node) => {
|
|
3624
6070
|
const id = getDepartmentId(node);
|
|
3625
|
-
return /* @__PURE__ */ (0,
|
|
3626
|
-
|
|
6071
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6072
|
+
import_antd8.List.Item,
|
|
3627
6073
|
{
|
|
3628
6074
|
onClick: async () => {
|
|
3629
6075
|
await loadChildren(id);
|
|
3630
6076
|
handleDepartmentSelect(id);
|
|
3631
6077
|
setMobileKeyword("");
|
|
3632
6078
|
},
|
|
3633
|
-
children: /* @__PURE__ */ (0,
|
|
6079
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.List.Item.Meta, { avatar: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons8.TeamOutlined, {}), title: getDepartmentName(node) })
|
|
3634
6080
|
},
|
|
3635
6081
|
id
|
|
3636
6082
|
);
|
|
@@ -3645,21 +6091,21 @@ function UserPickerPanel({
|
|
|
3645
6091
|
const filteredTreeData = lowerDepartmentKeyword ? deptTreeData.filter(
|
|
3646
6092
|
(node) => getDepartmentName(node).toLowerCase().includes(lowerDepartmentKeyword)
|
|
3647
6093
|
) : deptTreeData;
|
|
3648
|
-
return /* @__PURE__ */ (0,
|
|
3649
|
-
/* @__PURE__ */ (0,
|
|
3650
|
-
/* @__PURE__ */ (0,
|
|
3651
|
-
/* @__PURE__ */ (0,
|
|
3652
|
-
|
|
6094
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker", children: [
|
|
6095
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker-main", children: [
|
|
6096
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker-depts", children: [
|
|
6097
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6098
|
+
import_antd8.Input,
|
|
3653
6099
|
{
|
|
3654
6100
|
allowClear: true,
|
|
3655
|
-
prefix: /* @__PURE__ */ (0,
|
|
6101
|
+
prefix: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons8.SearchOutlined, {}),
|
|
3656
6102
|
placeholder: "\u641C\u7D22\u90E8\u95E8",
|
|
3657
6103
|
value: departmentKeyword,
|
|
3658
6104
|
onChange: (event) => setDepartmentKeyword(event.target.value)
|
|
3659
6105
|
}
|
|
3660
6106
|
),
|
|
3661
|
-
/* @__PURE__ */ (0,
|
|
3662
|
-
|
|
6107
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Spin, { spinning: treeLoading, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6108
|
+
import_antd8.Tree,
|
|
3663
6109
|
{
|
|
3664
6110
|
selectedKeys: currentDeptId ? [currentDeptId] : [],
|
|
3665
6111
|
expandedKeys,
|
|
@@ -3671,12 +6117,12 @@ function UserPickerPanel({
|
|
|
3671
6117
|
}
|
|
3672
6118
|
) })
|
|
3673
6119
|
] }),
|
|
3674
|
-
/* @__PURE__ */ (0,
|
|
3675
|
-
displaySearch && /* @__PURE__ */ (0,
|
|
3676
|
-
|
|
6120
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker-members", children: [
|
|
6121
|
+
displaySearch && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6122
|
+
import_antd8.Input,
|
|
3677
6123
|
{
|
|
3678
6124
|
allowClear: true,
|
|
3679
|
-
prefix: /* @__PURE__ */ (0,
|
|
6125
|
+
prefix: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons8.SearchOutlined, {}),
|
|
3680
6126
|
placeholder: "\u641C\u7D22\u6210\u5458",
|
|
3681
6127
|
value: memberKeyword,
|
|
3682
6128
|
onChange: (event) => setMemberKeyword(event.target.value)
|
|
@@ -3686,9 +6132,9 @@ function UserPickerPanel({
|
|
|
3686
6132
|
] }),
|
|
3687
6133
|
renderSelected()
|
|
3688
6134
|
] }),
|
|
3689
|
-
/* @__PURE__ */ (0,
|
|
3690
|
-
/* @__PURE__ */ (0,
|
|
3691
|
-
/* @__PURE__ */ (0,
|
|
6135
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "sy-org-picker-footer", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_antd8.Space, { children: [
|
|
6136
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Button, { onClick: onCancel, children: "\u53D6\u6D88" }),
|
|
6137
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Button, { type: "primary", onClick: () => onConfirm(selected), children: "\u786E\u5B9A" })
|
|
3692
6138
|
] }) })
|
|
3693
6139
|
] });
|
|
3694
6140
|
}
|
|
@@ -3703,7 +6149,7 @@ function UserPicker({
|
|
|
3703
6149
|
onOpenChange(false);
|
|
3704
6150
|
onCancel();
|
|
3705
6151
|
};
|
|
3706
|
-
const panel = /* @__PURE__ */ (0,
|
|
6152
|
+
const panel = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3707
6153
|
UserPickerPanel,
|
|
3708
6154
|
{
|
|
3709
6155
|
...panelProps,
|
|
@@ -3718,7 +6164,7 @@ function UserPicker({
|
|
|
3718
6164
|
if (mobile) {
|
|
3719
6165
|
const MobilePopup = getMobileComponent("Popup");
|
|
3720
6166
|
if (!MobilePopup) return open ? panel : null;
|
|
3721
|
-
return /* @__PURE__ */ (0,
|
|
6167
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3722
6168
|
MobilePopup,
|
|
3723
6169
|
{
|
|
3724
6170
|
visible: open,
|
|
@@ -3729,8 +6175,8 @@ function UserPicker({
|
|
|
3729
6175
|
}
|
|
3730
6176
|
);
|
|
3731
6177
|
}
|
|
3732
|
-
return /* @__PURE__ */ (0,
|
|
3733
|
-
|
|
6178
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6179
|
+
import_antd8.Modal,
|
|
3734
6180
|
{
|
|
3735
6181
|
title: "\u9009\u62E9\u6210\u5458",
|
|
3736
6182
|
open,
|
|
@@ -3744,7 +6190,7 @@ function UserPicker({
|
|
|
3744
6190
|
}
|
|
3745
6191
|
|
|
3746
6192
|
// packages/sdk/src/components/modules/InitiatorApproverSelector.tsx
|
|
3747
|
-
var
|
|
6193
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
3748
6194
|
var scopeText = {
|
|
3749
6195
|
all: "\u5168\u90E8\u6210\u5458",
|
|
3750
6196
|
members: "\u6307\u5B9A\u6210\u5458",
|
|
@@ -3778,19 +6224,19 @@ var RequirementSelect = ({
|
|
|
3778
6224
|
selectedUsers,
|
|
3779
6225
|
onChange
|
|
3780
6226
|
}) => {
|
|
3781
|
-
const [pickerOpen, setPickerOpen] = (0,
|
|
3782
|
-
const initialCandidates = (0,
|
|
6227
|
+
const [pickerOpen, setPickerOpen] = (0, import_react15.useState)(false);
|
|
6228
|
+
const initialCandidates = (0, import_react15.useMemo)(
|
|
3783
6229
|
() => (requirement.candidateUsers || []).map(normalizeCandidate).filter(Boolean),
|
|
3784
6230
|
[requirement.candidateUsers]
|
|
3785
6231
|
);
|
|
3786
|
-
const [optionsSource, setOptionsSource] = (0,
|
|
3787
|
-
const [loading, setLoading] = (0,
|
|
3788
|
-
(0,
|
|
6232
|
+
const [optionsSource, setOptionsSource] = (0, import_react15.useState)(initialCandidates);
|
|
6233
|
+
const [loading, setLoading] = (0, import_react15.useState)(false);
|
|
6234
|
+
(0, import_react15.useEffect)(() => {
|
|
3789
6235
|
setOptionsSource(
|
|
3790
6236
|
(current) => mergeUsers(initialCandidates, mergeUsers(current, selectedUsers))
|
|
3791
6237
|
);
|
|
3792
6238
|
}, [initialCandidates, selectedUsers]);
|
|
3793
|
-
const loadCandidates = (0,
|
|
6239
|
+
const loadCandidates = (0, import_react15.useCallback)(
|
|
3794
6240
|
async (keyword) => {
|
|
3795
6241
|
setLoading(true);
|
|
3796
6242
|
try {
|
|
@@ -3820,7 +6266,7 @@ var RequirementSelect = ({
|
|
|
3820
6266
|
)
|
|
3821
6267
|
);
|
|
3822
6268
|
} else if (initialCandidates.length === 0) {
|
|
3823
|
-
|
|
6269
|
+
import_antd9.message.error("\u52A0\u8F7D\u5BA1\u6279\u5019\u9009\u4EBA\u5931\u8D25");
|
|
3824
6270
|
}
|
|
3825
6271
|
} finally {
|
|
3826
6272
|
setLoading(false);
|
|
@@ -3828,12 +6274,12 @@ var RequirementSelect = ({
|
|
|
3828
6274
|
},
|
|
3829
6275
|
[api, appType, formUuid, initialCandidates.length, requirement.nodeId, requirement.scope]
|
|
3830
6276
|
);
|
|
3831
|
-
(0,
|
|
6277
|
+
(0, import_react15.useEffect)(() => {
|
|
3832
6278
|
if (requirement.scope !== "all" && open && formUuid && appType && requirement.nodeId) {
|
|
3833
6279
|
void loadCandidates();
|
|
3834
6280
|
}
|
|
3835
6281
|
}, [appType, formUuid, loadCandidates, open, requirement.nodeId, requirement.scope]);
|
|
3836
|
-
const options = (0,
|
|
6282
|
+
const options = (0, import_react15.useMemo)(
|
|
3837
6283
|
() => optionsSource.map((user) => ({
|
|
3838
6284
|
value: user.id,
|
|
3839
6285
|
label: getUserLabel(user)
|
|
@@ -3841,19 +6287,19 @@ var RequirementSelect = ({
|
|
|
3841
6287
|
[optionsSource]
|
|
3842
6288
|
);
|
|
3843
6289
|
if (requirement.scope === "all") {
|
|
3844
|
-
return /* @__PURE__ */ (0,
|
|
3845
|
-
/* @__PURE__ */ (0,
|
|
3846
|
-
/* @__PURE__ */ (0,
|
|
3847
|
-
/* @__PURE__ */ (0,
|
|
3848
|
-
/* @__PURE__ */ (0,
|
|
6290
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "rounded-lg border border-ant-border-secondary bg-ant-bg-container p-3", children: [
|
|
6291
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "mb-2 flex items-start justify-between gap-3", children: [
|
|
6292
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { children: [
|
|
6293
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Typography.Text, { strong: true, children: requirement.nodeName }),
|
|
6294
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "mt-1 text-xs text-ant-color-text-tertiary", children: [
|
|
3849
6295
|
"\u9009\u62E9\u8303\u56F4\uFF1A",
|
|
3850
6296
|
scopeText[requirement.scope] || "\u5168\u90E8\u6210\u5458"
|
|
3851
6297
|
] })
|
|
3852
6298
|
] }),
|
|
3853
|
-
/* @__PURE__ */ (0,
|
|
6299
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Button, { onClick: () => setPickerOpen(true), children: selectedUsers.length > 0 ? "\u91CD\u65B0\u9009\u62E9\u6210\u5458" : "\u9009\u62E9\u6210\u5458" })
|
|
3854
6300
|
] }),
|
|
3855
|
-
selectedUsers.length > 0 ? /* @__PURE__ */ (0,
|
|
3856
|
-
/* @__PURE__ */ (0,
|
|
6301
|
+
selectedUsers.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Space, { size: [4, 4], wrap: true, className: "mt-2", children: selectedUsers.map((user) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Tag, { children: getUserLabel(user) }, user.id)) }) : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Empty, { image: import_antd9.Empty.PRESENTED_IMAGE_SIMPLE, description: "\u8BF7\u4ECE\u7EC4\u7EC7\u67B6\u6784\u9009\u62E9\u6210\u5458" }),
|
|
6302
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3857
6303
|
UserPicker,
|
|
3858
6304
|
{
|
|
3859
6305
|
api,
|
|
@@ -3873,16 +6319,16 @@ var RequirementSelect = ({
|
|
|
3873
6319
|
)
|
|
3874
6320
|
] });
|
|
3875
6321
|
}
|
|
3876
|
-
return /* @__PURE__ */ (0,
|
|
3877
|
-
/* @__PURE__ */ (0,
|
|
3878
|
-
/* @__PURE__ */ (0,
|
|
3879
|
-
/* @__PURE__ */ (0,
|
|
6322
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "rounded-lg border border-ant-border-secondary bg-ant-bg-container p-3", children: [
|
|
6323
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "mb-2", children: [
|
|
6324
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Typography.Text, { strong: true, children: requirement.nodeName }),
|
|
6325
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "mt-1 text-xs text-ant-color-text-tertiary", children: [
|
|
3880
6326
|
"\u9009\u62E9\u8303\u56F4\uFF1A",
|
|
3881
6327
|
scopeText[requirement.scope] || "\u5168\u90E8\u6210\u5458"
|
|
3882
6328
|
] })
|
|
3883
6329
|
] }),
|
|
3884
|
-
/* @__PURE__ */ (0,
|
|
3885
|
-
|
|
6330
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
6331
|
+
import_antd9.Select,
|
|
3886
6332
|
{
|
|
3887
6333
|
mode: "multiple",
|
|
3888
6334
|
className: "w-full",
|
|
@@ -3893,7 +6339,7 @@ var RequirementSelect = ({
|
|
|
3893
6339
|
loading,
|
|
3894
6340
|
value: selectedUsers.map((user) => user.id),
|
|
3895
6341
|
options,
|
|
3896
|
-
notFoundContent: loading ? "\u52A0\u8F7D\u4E2D..." : /* @__PURE__ */ (0,
|
|
6342
|
+
notFoundContent: loading ? "\u52A0\u8F7D\u4E2D..." : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Empty, { image: import_antd9.Empty.PRESENTED_IMAGE_SIMPLE }),
|
|
3897
6343
|
onSearch: (keyword) => {
|
|
3898
6344
|
void loadCandidates(keyword);
|
|
3899
6345
|
},
|
|
@@ -3905,7 +6351,7 @@ var RequirementSelect = ({
|
|
|
3905
6351
|
}
|
|
3906
6352
|
}
|
|
3907
6353
|
),
|
|
3908
|
-
selectedUsers.length > 0 ? /* @__PURE__ */ (0,
|
|
6354
|
+
selectedUsers.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Space, { size: [4, 4], wrap: true, className: "mt-2", children: selectedUsers.map((user) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Tag, { children: getUserLabel(user) }, user.id)) }) : null
|
|
3909
6355
|
] });
|
|
3910
6356
|
};
|
|
3911
6357
|
var InitiatorApproverSelector = ({
|
|
@@ -3918,9 +6364,9 @@ var InitiatorApproverSelector = ({
|
|
|
3918
6364
|
onOk,
|
|
3919
6365
|
onCancel
|
|
3920
6366
|
}) => {
|
|
3921
|
-
const [selected, setSelected] = (0,
|
|
3922
|
-
const wasOpenRef = (0,
|
|
3923
|
-
(0,
|
|
6367
|
+
const [selected, setSelected] = (0, import_react15.useState)({});
|
|
6368
|
+
const wasOpenRef = (0, import_react15.useRef)(false);
|
|
6369
|
+
(0, import_react15.useEffect)(() => {
|
|
3924
6370
|
if (open && !wasOpenRef.current) {
|
|
3925
6371
|
setSelected(value || EMPTY_SELECTED_MAP);
|
|
3926
6372
|
}
|
|
@@ -3929,8 +6375,8 @@ var InitiatorApproverSelector = ({
|
|
|
3929
6375
|
const missingNodes = requirements.filter(
|
|
3930
6376
|
(requirement) => !(selected[requirement.nodeId] || []).length
|
|
3931
6377
|
);
|
|
3932
|
-
return /* @__PURE__ */ (0,
|
|
3933
|
-
|
|
6378
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
6379
|
+
import_antd9.Modal,
|
|
3934
6380
|
{
|
|
3935
6381
|
getContainer: false,
|
|
3936
6382
|
title: "\u9009\u62E9\u5BA1\u6279\u4EBA",
|
|
@@ -3941,13 +6387,13 @@ var InitiatorApproverSelector = ({
|
|
|
3941
6387
|
onCancel,
|
|
3942
6388
|
onOk: () => {
|
|
3943
6389
|
if (missingNodes.length > 0) {
|
|
3944
|
-
|
|
6390
|
+
import_antd9.message.error("\u8BF7\u4E3A\u6240\u6709\u53D1\u8D77\u4EBA\u81EA\u9009\u8282\u70B9\u9009\u62E9\u5BA1\u6279\u4EBA");
|
|
3945
6391
|
return;
|
|
3946
6392
|
}
|
|
3947
6393
|
onOk(selected);
|
|
3948
6394
|
},
|
|
3949
6395
|
destroyOnHidden: true,
|
|
3950
|
-
children: /* @__PURE__ */ (0,
|
|
6396
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Space, { direction: "vertical", size: 12, className: "w-full", children: requirements.map((requirement) => /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3951
6397
|
RequirementSelect,
|
|
3952
6398
|
{
|
|
3953
6399
|
open,
|
|
@@ -3965,7 +6411,7 @@ var InitiatorApproverSelector = ({
|
|
|
3965
6411
|
};
|
|
3966
6412
|
|
|
3967
6413
|
// packages/sdk/src/runtime/react/workflow.tsx
|
|
3968
|
-
var
|
|
6414
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
3969
6415
|
var getError = (error) => error instanceof Error ? error : new Error(String(error || "\u6D41\u7A0B\u80FD\u529B\u89E3\u6790\u5931\u8D25"));
|
|
3970
6416
|
var normalizeCapabilities = (value) => {
|
|
3971
6417
|
const raw = value || {};
|
|
@@ -3978,20 +6424,20 @@ var normalizeCapabilities = (value) => {
|
|
|
3978
6424
|
function useProcessCapabilities(options) {
|
|
3979
6425
|
const { enabled = true, refreshKey, onError, ...params } = options;
|
|
3980
6426
|
const sdk = usePageSdk();
|
|
3981
|
-
const [capabilities, setCapabilities] = (0,
|
|
6427
|
+
const [capabilities, setCapabilities] = (0, import_react16.useState)(
|
|
3982
6428
|
null
|
|
3983
6429
|
);
|
|
3984
|
-
const [loading, setLoading] = (0,
|
|
3985
|
-
const [error, setError] = (0,
|
|
3986
|
-
const mountedRef = (0,
|
|
6430
|
+
const [loading, setLoading] = (0, import_react16.useState)(false);
|
|
6431
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
6432
|
+
const mountedRef = (0, import_react16.useRef)(true);
|
|
3987
6433
|
const paramsKey = JSON.stringify({ ...params, refreshKey });
|
|
3988
|
-
(0,
|
|
6434
|
+
(0, import_react16.useEffect)(() => {
|
|
3989
6435
|
mountedRef.current = true;
|
|
3990
6436
|
return () => {
|
|
3991
6437
|
mountedRef.current = false;
|
|
3992
6438
|
};
|
|
3993
6439
|
}, []);
|
|
3994
|
-
const refresh = (0,
|
|
6440
|
+
const refresh = (0, import_react16.useCallback)(async () => {
|
|
3995
6441
|
if (!enabled) return capabilities;
|
|
3996
6442
|
setLoading(true);
|
|
3997
6443
|
setError(null);
|
|
@@ -4017,7 +6463,7 @@ function useProcessCapabilities(options) {
|
|
|
4017
6463
|
}
|
|
4018
6464
|
}
|
|
4019
6465
|
}, [capabilities, enabled, onError, paramsKey, sdk]);
|
|
4020
|
-
(0,
|
|
6466
|
+
(0, import_react16.useEffect)(() => {
|
|
4021
6467
|
if (!enabled) return;
|
|
4022
6468
|
void refresh();
|
|
4023
6469
|
}, [enabled, paramsKey, refresh]);
|
|
@@ -4042,8 +6488,8 @@ var requireValue = (value, message3) => {
|
|
|
4042
6488
|
function useProcessActions(options) {
|
|
4043
6489
|
const { capabilities, formUuid, appType, getFormValues, onActionComplete } = options;
|
|
4044
6490
|
const sdk = usePageSdk();
|
|
4045
|
-
const [loadingAction, setLoadingAction] = (0,
|
|
4046
|
-
const buildUpdateFormDataJson = (0,
|
|
6491
|
+
const [loadingAction, setLoadingAction] = (0, import_react16.useState)(null);
|
|
6492
|
+
const buildUpdateFormDataJson = (0, import_react16.useCallback)(
|
|
4047
6493
|
(input) => {
|
|
4048
6494
|
if (input?.updateFormDataJson !== void 0) return input.updateFormDataJson;
|
|
4049
6495
|
const values = getFormValues?.();
|
|
@@ -4051,7 +6497,7 @@ function useProcessActions(options) {
|
|
|
4051
6497
|
},
|
|
4052
6498
|
[getFormValues]
|
|
4053
6499
|
);
|
|
4054
|
-
const executeOperation = (0,
|
|
6500
|
+
const executeOperation = (0, import_react16.useCallback)(
|
|
4055
6501
|
async (operation, input = {}) => {
|
|
4056
6502
|
if (!operation.enabled) return false;
|
|
4057
6503
|
setLoadingAction(operation.key);
|
|
@@ -4161,7 +6607,7 @@ function useProcessActions(options) {
|
|
|
4161
6607
|
sdk
|
|
4162
6608
|
]
|
|
4163
6609
|
);
|
|
4164
|
-
const execute = (0,
|
|
6610
|
+
const execute = (0, import_react16.useCallback)(
|
|
4165
6611
|
async (action, input) => {
|
|
4166
6612
|
const operation = (capabilities?.operations || []).find(
|
|
4167
6613
|
(item) => item.key === action
|
|
@@ -4204,12 +6650,12 @@ var actionTone = (key) => {
|
|
|
4204
6650
|
return "default";
|
|
4205
6651
|
};
|
|
4206
6652
|
var actionIcon = (key) => {
|
|
4207
|
-
if (key === "startProcess" || key === "approve") return /* @__PURE__ */ (0,
|
|
4208
|
-
if (key === "reject") return /* @__PURE__ */ (0,
|
|
4209
|
-
if (key === "transfer" || key === "adminTransfer") return /* @__PURE__ */ (0,
|
|
4210
|
-
if (key === "return" || key === "withdraw") return /* @__PURE__ */ (0,
|
|
4211
|
-
if (key === "save") return /* @__PURE__ */ (0,
|
|
4212
|
-
if (key === "retryException" || key === "callback") return /* @__PURE__ */ (0,
|
|
6653
|
+
if (key === "startProcess" || key === "approve") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.CheckOutlined, {});
|
|
6654
|
+
if (key === "reject") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.CloseOutlined, {});
|
|
6655
|
+
if (key === "transfer" || key === "adminTransfer") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.SwapOutlined, {});
|
|
6656
|
+
if (key === "return" || key === "withdraw") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.RollbackOutlined, {});
|
|
6657
|
+
if (key === "save") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.SaveOutlined, {});
|
|
6658
|
+
if (key === "retryException" || key === "callback") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.ReloadOutlined, {});
|
|
4213
6659
|
return void 0;
|
|
4214
6660
|
};
|
|
4215
6661
|
var getModalTitle = (key) => {
|
|
@@ -4235,8 +6681,8 @@ var ProcessActionBar = ({
|
|
|
4235
6681
|
maxWidth,
|
|
4236
6682
|
position = "sticky"
|
|
4237
6683
|
}) => {
|
|
4238
|
-
const [form] =
|
|
4239
|
-
const [activeOperation, setActiveOperation] = (0,
|
|
6684
|
+
const [form] = import_antd10.Form.useForm();
|
|
6685
|
+
const [activeOperation, setActiveOperation] = (0, import_react16.useState)(null);
|
|
4240
6686
|
const autoCapabilities = useProcessCapabilities({
|
|
4241
6687
|
...capabilityParams || {},
|
|
4242
6688
|
enabled: Boolean(capabilityParams) && capabilityParams?.enabled !== false
|
|
@@ -4271,7 +6717,7 @@ var ProcessActionBar = ({
|
|
|
4271
6717
|
}
|
|
4272
6718
|
void actions.executeOperation(operation);
|
|
4273
6719
|
};
|
|
4274
|
-
const actionConfigs = (0,
|
|
6720
|
+
const actionConfigs = (0, import_react16.useMemo)(
|
|
4275
6721
|
() => operations.map((operation) => ({
|
|
4276
6722
|
key: operation.key,
|
|
4277
6723
|
label: operation.label || operation.key,
|
|
@@ -4303,8 +6749,8 @@ var ProcessActionBar = ({
|
|
|
4303
6749
|
label: String(node.nodeName || node.name || node.label || value)
|
|
4304
6750
|
};
|
|
4305
6751
|
});
|
|
4306
|
-
return /* @__PURE__ */ (0,
|
|
4307
|
-
/* @__PURE__ */ (0,
|
|
6752
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
6753
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
4308
6754
|
StickyActionBar,
|
|
4309
6755
|
{
|
|
4310
6756
|
actions: actionConfigs,
|
|
@@ -4316,8 +6762,8 @@ var ProcessActionBar = ({
|
|
|
4316
6762
|
position
|
|
4317
6763
|
}
|
|
4318
6764
|
),
|
|
4319
|
-
/* @__PURE__ */ (0,
|
|
4320
|
-
|
|
6765
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
6766
|
+
import_antd10.Modal,
|
|
4321
6767
|
{
|
|
4322
6768
|
getContainer: false,
|
|
4323
6769
|
title: modalKey ? getModalTitle(modalKey) : "\u6D41\u7A0B\u64CD\u4F5C",
|
|
@@ -4333,27 +6779,27 @@ var ProcessActionBar = ({
|
|
|
4333
6779
|
form.resetFields();
|
|
4334
6780
|
},
|
|
4335
6781
|
destroyOnHidden: true,
|
|
4336
|
-
children: /* @__PURE__ */ (0,
|
|
4337
|
-
(modalKey === "transfer" || modalKey === "adminTransfer") && /* @__PURE__ */ (0,
|
|
4338
|
-
|
|
6782
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_antd10.Form, { form, layout: "vertical", children: [
|
|
6783
|
+
(modalKey === "transfer" || modalKey === "adminTransfer") && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
6784
|
+
import_antd10.Form.Item,
|
|
4339
6785
|
{
|
|
4340
6786
|
name: "newAssignee",
|
|
4341
6787
|
label: "\u63A5\u6536\u4EBA",
|
|
4342
6788
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u63A5\u6536\u4EBA\u7528\u6237ID" }],
|
|
4343
|
-
children: /* @__PURE__ */ (0,
|
|
6789
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_antd10.Input, { placeholder: "\u8BF7\u8F93\u5165\u7528\u6237ID" })
|
|
4344
6790
|
}
|
|
4345
6791
|
),
|
|
4346
|
-
modalKey === "return" && /* @__PURE__ */ (0,
|
|
4347
|
-
|
|
6792
|
+
modalKey === "return" && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
6793
|
+
import_antd10.Form.Item,
|
|
4348
6794
|
{
|
|
4349
6795
|
name: "targetNodeId",
|
|
4350
6796
|
label: "\u9000\u56DE\u8282\u70B9",
|
|
4351
6797
|
rules: [{ required: true, message: "\u8BF7\u9009\u62E9\u9000\u56DE\u8282\u70B9" }],
|
|
4352
|
-
children: /* @__PURE__ */ (0,
|
|
6798
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_antd10.Select, { placeholder: "\u8BF7\u9009\u62E9\u9000\u56DE\u8282\u70B9", options: returnOptions })
|
|
4353
6799
|
}
|
|
4354
6800
|
),
|
|
4355
|
-
/* @__PURE__ */ (0,
|
|
4356
|
-
|
|
6801
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
6802
|
+
import_antd10.Form.Item,
|
|
4357
6803
|
{
|
|
4358
6804
|
name: modalKey === "reject" || modalKey === "resubmit" ? "comments" : "reason",
|
|
4359
6805
|
label: modalKey === "reject" ? "\u62D2\u7EDD\u7406\u7531" : modalKey === "resubmit" ? "\u63D0\u4EA4\u610F\u89C1" : "\u8BF4\u660E",
|
|
@@ -4363,7 +6809,7 @@ var ProcessActionBar = ({
|
|
|
4363
6809
|
message: "\u8BF7\u586B\u5199\u8BF4\u660E"
|
|
4364
6810
|
}
|
|
4365
6811
|
],
|
|
4366
|
-
children: /* @__PURE__ */ (0,
|
|
6812
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_antd10.Input.TextArea, { rows: 4, maxLength: 500, showCount: true })
|
|
4367
6813
|
}
|
|
4368
6814
|
)
|
|
4369
6815
|
] })
|
|
@@ -4375,7 +6821,7 @@ var ProcessTimeline = ({
|
|
|
4375
6821
|
capabilities,
|
|
4376
6822
|
tasks,
|
|
4377
6823
|
...props
|
|
4378
|
-
}) => /* @__PURE__ */ (0,
|
|
6824
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
4379
6825
|
ApprovalTimeline,
|
|
4380
6826
|
{
|
|
4381
6827
|
...props,
|
|
@@ -4385,7 +6831,7 @@ var ProcessTimeline = ({
|
|
|
4385
6831
|
var ProcessPreviewPanel = ProcessPreview;
|
|
4386
6832
|
|
|
4387
6833
|
// packages/sdk/src/runtime/react/openxiangdaProvider.tsx
|
|
4388
|
-
var
|
|
6834
|
+
var import_react18 = require("react");
|
|
4389
6835
|
|
|
4390
6836
|
// packages/sdk/src/runtime/core/fetch.ts
|
|
4391
6837
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -4421,24 +6867,24 @@ var createBoundFetch = (fetchImpl) => {
|
|
|
4421
6867
|
};
|
|
4422
6868
|
|
|
4423
6869
|
// packages/sdk/src/runtime/host/browserHost.ts
|
|
4424
|
-
var
|
|
4425
|
-
var getDefaultServicePrefix = () => typeof window !== "undefined" ?
|
|
6870
|
+
var trimTrailingSlash2 = (value) => value.replace(/\/+$/, "");
|
|
6871
|
+
var getDefaultServicePrefix = () => typeof window !== "undefined" ? trimTrailingSlash2(window.__OPENXIANGDA_SERVICE_PREFIX__ || "/service") : "/service";
|
|
4426
6872
|
var joinServicePath = (servicePrefix, path) => {
|
|
4427
6873
|
if (/^https?:\/\//i.test(path)) return path;
|
|
4428
|
-
const normalizedPrefix =
|
|
6874
|
+
const normalizedPrefix = trimTrailingSlash2(servicePrefix || "/service");
|
|
4429
6875
|
if (path.startsWith(normalizedPrefix)) return path;
|
|
4430
6876
|
return `${normalizedPrefix}${path.startsWith("/") ? path : `/${path}`}`;
|
|
4431
6877
|
};
|
|
4432
|
-
var
|
|
6878
|
+
var appendQuery2 = (url, query) => {
|
|
4433
6879
|
if (!query) return url;
|
|
4434
6880
|
return `${url}${url.includes("?") ? "&" : "?"}${query}`;
|
|
4435
6881
|
};
|
|
4436
|
-
var
|
|
6882
|
+
var normalizeMethod3 = (method) => {
|
|
4437
6883
|
const value = String(method || "get").toUpperCase();
|
|
4438
6884
|
return ["GET", "POST", "PUT", "DELETE", "PATCH"].includes(value) ? value : "GET";
|
|
4439
6885
|
};
|
|
4440
6886
|
var shouldRetryTransportRequest = (payload) => {
|
|
4441
|
-
const method =
|
|
6887
|
+
const method = normalizeMethod3(payload?.method);
|
|
4442
6888
|
if (method === "GET") return true;
|
|
4443
6889
|
const path = String(payload?.path || "").split("?")[0];
|
|
4444
6890
|
return method === "POST" && path === "/workflow/capabilities/resolve";
|
|
@@ -4448,7 +6894,7 @@ var normalizeEnvelopeCode2 = (value, fallback) => {
|
|
|
4448
6894
|
const normalized = Number(value);
|
|
4449
6895
|
return Number.isFinite(normalized) ? normalized : String(value);
|
|
4450
6896
|
};
|
|
4451
|
-
var
|
|
6897
|
+
var isSuccessCode4 = (value) => {
|
|
4452
6898
|
if (value === void 0 || value === null || value === "") return true;
|
|
4453
6899
|
const normalized = Number(value);
|
|
4454
6900
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -4463,7 +6909,7 @@ var parseJsonResponse = async (response) => {
|
|
|
4463
6909
|
const code = normalizeEnvelopeCode2(payload.code, response.status);
|
|
4464
6910
|
return {
|
|
4465
6911
|
code,
|
|
4466
|
-
success: payload.success !== false &&
|
|
6912
|
+
success: payload.success !== false && isSuccessCode4(code),
|
|
4467
6913
|
message: payload.message,
|
|
4468
6914
|
result: payload.result ?? payload.data ?? null,
|
|
4469
6915
|
data: payload.data,
|
|
@@ -4486,7 +6932,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4486
6932
|
if (!payload?.path) {
|
|
4487
6933
|
throw new Error("transport.request \u9700\u8981 path");
|
|
4488
6934
|
}
|
|
4489
|
-
const url =
|
|
6935
|
+
const url = appendQuery2(joinServicePath(servicePrefix, payload.path), payload.query);
|
|
4490
6936
|
const headers = new Headers(payload.headers);
|
|
4491
6937
|
let body;
|
|
4492
6938
|
if (payload.body !== void 0) {
|
|
@@ -4498,7 +6944,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4498
6944
|
}
|
|
4499
6945
|
}
|
|
4500
6946
|
const response = await fetchWithTransientRetry(fetchImpl, url, {
|
|
4501
|
-
method:
|
|
6947
|
+
method: normalizeMethod3(payload.method),
|
|
4502
6948
|
headers,
|
|
4503
6949
|
body,
|
|
4504
6950
|
credentials: "include"
|
|
@@ -4511,7 +6957,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4511
6957
|
if (!payload?.path) {
|
|
4512
6958
|
throw new Error("transport.download \u9700\u8981 path");
|
|
4513
6959
|
}
|
|
4514
|
-
const url =
|
|
6960
|
+
const url = appendQuery2(joinServicePath(servicePrefix, payload.path), payload.query);
|
|
4515
6961
|
const headers = new Headers(payload.headers);
|
|
4516
6962
|
let body;
|
|
4517
6963
|
if (payload.body !== void 0) {
|
|
@@ -4523,7 +6969,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4523
6969
|
}
|
|
4524
6970
|
}
|
|
4525
6971
|
const response = await fetchImpl(url, {
|
|
4526
|
-
method:
|
|
6972
|
+
method: normalizeMethod3(payload.method),
|
|
4527
6973
|
headers,
|
|
4528
6974
|
body,
|
|
4529
6975
|
credentials: "include"
|
|
@@ -4610,9 +7056,9 @@ var createBrowserPageContext = (bootstrap, options = {}) => {
|
|
|
4610
7056
|
};
|
|
4611
7057
|
|
|
4612
7058
|
// packages/sdk/src/runtime/react/auth.tsx
|
|
4613
|
-
var
|
|
4614
|
-
var
|
|
4615
|
-
var
|
|
7059
|
+
var import_react17 = require("react");
|
|
7060
|
+
var import_antd11 = require("antd");
|
|
7061
|
+
var import_icons10 = require("@ant-design/icons");
|
|
4616
7062
|
|
|
4617
7063
|
// packages/sdk/src/runtime/core/auth.ts
|
|
4618
7064
|
var AuthClientError = class extends Error {
|
|
@@ -4682,7 +7128,7 @@ var createAuthClient = ({
|
|
|
4682
7128
|
const payload = await readPayload(response);
|
|
4683
7129
|
const code = getRecordValue(payload, "code");
|
|
4684
7130
|
const success = getRecordValue(payload, "success");
|
|
4685
|
-
if (!response.ok || success === false || !
|
|
7131
|
+
if (!response.ok || success === false || !isSuccessCode5(code)) {
|
|
4686
7132
|
throw new AuthClientError(
|
|
4687
7133
|
String(getRecordValue(payload, "message") || `Auth request failed: ${response.status}`),
|
|
4688
7134
|
{
|
|
@@ -4761,7 +7207,7 @@ var readNumber = (value) => {
|
|
|
4761
7207
|
const numberValue = Number(value);
|
|
4762
7208
|
return Number.isFinite(numberValue) ? numberValue : void 0;
|
|
4763
7209
|
};
|
|
4764
|
-
var
|
|
7210
|
+
var isSuccessCode5 = (code) => {
|
|
4765
7211
|
if (code === void 0 || code === null || code === "") return true;
|
|
4766
7212
|
const normalized = Number(code);
|
|
4767
7213
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -4791,10 +7237,10 @@ var resolveLoginUrl = (appType, {
|
|
|
4791
7237
|
var getCurrentHref2 = () => typeof window === "undefined" ? "" : window.location.href;
|
|
4792
7238
|
|
|
4793
7239
|
// packages/sdk/src/runtime/react/auth.tsx
|
|
4794
|
-
var
|
|
7240
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
4795
7241
|
var useAuth = (options = {}) => {
|
|
4796
7242
|
const runtime = useOpenXiangda();
|
|
4797
|
-
const client = (0,
|
|
7243
|
+
const client = (0, import_react17.useMemo)(
|
|
4798
7244
|
() => createAuthClient({
|
|
4799
7245
|
appType: options.appType || runtime.appType,
|
|
4800
7246
|
servicePrefix: options.servicePrefix || runtime.servicePrefix,
|
|
@@ -4809,7 +7255,7 @@ var useAuth = (options = {}) => {
|
|
|
4809
7255
|
runtime.servicePrefix
|
|
4810
7256
|
]
|
|
4811
7257
|
);
|
|
4812
|
-
return (0,
|
|
7258
|
+
return (0, import_react17.useMemo)(
|
|
4813
7259
|
() => ({
|
|
4814
7260
|
client,
|
|
4815
7261
|
getMethods: client.getMethods,
|
|
@@ -4829,12 +7275,12 @@ var useAuth = (options = {}) => {
|
|
|
4829
7275
|
};
|
|
4830
7276
|
var useLoginMethods = (options = {}) => {
|
|
4831
7277
|
const auth = useAuth(options);
|
|
4832
|
-
const [state, setState] = (0,
|
|
7278
|
+
const [state, setState] = (0, import_react17.useState)({
|
|
4833
7279
|
data: null,
|
|
4834
7280
|
loading: true,
|
|
4835
7281
|
error: null
|
|
4836
7282
|
});
|
|
4837
|
-
const reload = (0,
|
|
7283
|
+
const reload = (0, import_react17.useCallback)(async () => {
|
|
4838
7284
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
4839
7285
|
try {
|
|
4840
7286
|
const data = await auth.getMethods();
|
|
@@ -4847,7 +7293,7 @@ var useLoginMethods = (options = {}) => {
|
|
|
4847
7293
|
});
|
|
4848
7294
|
}
|
|
4849
7295
|
}, [auth]);
|
|
4850
|
-
(0,
|
|
7296
|
+
(0, import_react17.useEffect)(() => {
|
|
4851
7297
|
let disposed = false;
|
|
4852
7298
|
const run = async () => {
|
|
4853
7299
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
@@ -4889,19 +7335,19 @@ var LoginPage = ({
|
|
|
4889
7335
|
const runtime = useOpenXiangda();
|
|
4890
7336
|
const auth = useAuth(authOptions);
|
|
4891
7337
|
const methodsState = useLoginMethods(authOptions);
|
|
4892
|
-
const [passwordForm] =
|
|
4893
|
-
const [phoneForm] =
|
|
4894
|
-
const [activeMethod, setActiveMethod] = (0,
|
|
7338
|
+
const [passwordForm] = import_antd11.Form.useForm();
|
|
7339
|
+
const [phoneForm] = import_antd11.Form.useForm();
|
|
7340
|
+
const [activeMethod, setActiveMethod] = (0, import_react17.useState)(
|
|
4895
7341
|
defaultMethod || "password"
|
|
4896
7342
|
);
|
|
4897
|
-
const [phonePurpose, setPhonePurpose] = (0,
|
|
7343
|
+
const [phonePurpose, setPhonePurpose] = (0, import_react17.useState)(
|
|
4898
7344
|
"login"
|
|
4899
7345
|
);
|
|
4900
|
-
const [phoneChallengeId, setPhoneChallengeId] = (0,
|
|
4901
|
-
const [passwordChallenge, setPasswordChallenge] = (0,
|
|
4902
|
-
const [submitting, setSubmitting] = (0,
|
|
4903
|
-
const [sendingCode, setSendingCode] = (0,
|
|
4904
|
-
const [error, setError] = (0,
|
|
7346
|
+
const [phoneChallengeId, setPhoneChallengeId] = (0, import_react17.useState)("");
|
|
7347
|
+
const [passwordChallenge, setPasswordChallenge] = (0, import_react17.useState)(null);
|
|
7348
|
+
const [submitting, setSubmitting] = (0, import_react17.useState)(false);
|
|
7349
|
+
const [sendingCode, setSendingCode] = (0, import_react17.useState)(false);
|
|
7350
|
+
const [error, setError] = (0, import_react17.useState)(null);
|
|
4905
7351
|
const methods = methodsState.methods.filter((method) => method.enabled !== false);
|
|
4906
7352
|
const passwordMethod = findMethod(methods, "password");
|
|
4907
7353
|
const phoneMethod = findMethod(methods, "phone_code");
|
|
@@ -4909,16 +7355,16 @@ var LoginPage = ({
|
|
|
4909
7355
|
const ssoMethod = findMethod(methods, "sso");
|
|
4910
7356
|
const guestMethod = findMethod(methods, "guest");
|
|
4911
7357
|
const allowRegister = methodsState.data?.registration?.mode !== "reject";
|
|
4912
|
-
const tabItems = (0,
|
|
7358
|
+
const tabItems = (0, import_react17.useMemo)(() => {
|
|
4913
7359
|
const items = [];
|
|
4914
7360
|
if (passwordMethod) {
|
|
4915
7361
|
items.push({
|
|
4916
7362
|
key: "password",
|
|
4917
|
-
label: /* @__PURE__ */ (0,
|
|
4918
|
-
/* @__PURE__ */ (0,
|
|
4919
|
-
/* @__PURE__ */ (0,
|
|
7363
|
+
label: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Space, { size: 6, children: [
|
|
7364
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.UserOutlined, {}),
|
|
7365
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: passwordMethod.label || "\u8D26\u53F7\u5BC6\u7801" })
|
|
4920
7366
|
] }),
|
|
4921
|
-
children: /* @__PURE__ */ (0,
|
|
7367
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
4922
7368
|
PasswordLoginForm,
|
|
4923
7369
|
{
|
|
4924
7370
|
challenge: passwordChallenge,
|
|
@@ -4960,11 +7406,11 @@ var LoginPage = ({
|
|
|
4960
7406
|
if (phoneMethod) {
|
|
4961
7407
|
items.push({
|
|
4962
7408
|
key: "phone_code",
|
|
4963
|
-
label: /* @__PURE__ */ (0,
|
|
4964
|
-
/* @__PURE__ */ (0,
|
|
4965
|
-
/* @__PURE__ */ (0,
|
|
7409
|
+
label: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Space, { size: 6, children: [
|
|
7410
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.MobileOutlined, {}),
|
|
7411
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: phoneMethod.label || "\u624B\u673A\u53F7" })
|
|
4966
7412
|
] }),
|
|
4967
|
-
children: /* @__PURE__ */ (0,
|
|
7413
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
4968
7414
|
PhoneCodeLoginForm,
|
|
4969
7415
|
{
|
|
4970
7416
|
allowRegister,
|
|
@@ -5028,7 +7474,7 @@ var LoginPage = ({
|
|
|
5028
7474
|
sendingCode,
|
|
5029
7475
|
submitting
|
|
5030
7476
|
]);
|
|
5031
|
-
(0,
|
|
7477
|
+
(0, import_react17.useEffect)(() => {
|
|
5032
7478
|
const firstKey = tabItems[0]?.key;
|
|
5033
7479
|
if (firstKey && !tabItems.some((item) => item.key === activeMethod)) {
|
|
5034
7480
|
setActiveMethod(firstKey);
|
|
@@ -5103,7 +7549,7 @@ var LoginPage = ({
|
|
|
5103
7549
|
);
|
|
5104
7550
|
}
|
|
5105
7551
|
}
|
|
5106
|
-
return /* @__PURE__ */ (0,
|
|
7552
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
5107
7553
|
"div",
|
|
5108
7554
|
{
|
|
5109
7555
|
className,
|
|
@@ -5115,8 +7561,8 @@ var LoginPage = ({
|
|
|
5115
7561
|
background: "#f6f8fb",
|
|
5116
7562
|
...style
|
|
5117
7563
|
},
|
|
5118
|
-
children: /* @__PURE__ */ (0,
|
|
5119
|
-
|
|
7564
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7565
|
+
import_antd11.Card,
|
|
5120
7566
|
{
|
|
5121
7567
|
style: {
|
|
5122
7568
|
width: "min(100%, 420px)",
|
|
@@ -5124,54 +7570,54 @@ var LoginPage = ({
|
|
|
5124
7570
|
boxShadow: "0 16px 48px rgba(15, 23, 42, 0.10)"
|
|
5125
7571
|
},
|
|
5126
7572
|
styles: { body: { padding: 28 } },
|
|
5127
|
-
children: /* @__PURE__ */ (0,
|
|
5128
|
-
/* @__PURE__ */ (0,
|
|
5129
|
-
/* @__PURE__ */ (0,
|
|
5130
|
-
subtitle ? /* @__PURE__ */ (0,
|
|
7573
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Space, { direction: "vertical", size: 20, style: { width: "100%" }, children: [
|
|
7574
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { children: [
|
|
7575
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Typography.Title, { level: 3, style: { margin: 0 }, children: title || "\u5E94\u7528\u767B\u5F55" }),
|
|
7576
|
+
subtitle ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Typography.Text, { type: "secondary", children: subtitle }) : null
|
|
5131
7577
|
] }),
|
|
5132
|
-
methodsState.error ? /* @__PURE__ */ (0,
|
|
5133
|
-
|
|
7578
|
+
methodsState.error ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7579
|
+
import_antd11.Alert,
|
|
5134
7580
|
{
|
|
5135
7581
|
showIcon: true,
|
|
5136
7582
|
type: "error",
|
|
5137
7583
|
message: methodsState.error.message
|
|
5138
7584
|
}
|
|
5139
7585
|
) : null,
|
|
5140
|
-
error ? /* @__PURE__ */ (0,
|
|
5141
|
-
methodsState.loading ? /* @__PURE__ */ (0,
|
|
5142
|
-
|
|
7586
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Alert, { showIcon: true, type: "error", message: error }) : null,
|
|
7587
|
+
methodsState.loading ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Button, { block: true, loading: true, children: "\u52A0\u8F7D\u4E2D" }) : tabItems.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7588
|
+
import_antd11.Tabs,
|
|
5143
7589
|
{
|
|
5144
7590
|
activeKey: activeMethod,
|
|
5145
7591
|
items: tabItems,
|
|
5146
7592
|
onChange: setActiveMethod
|
|
5147
7593
|
}
|
|
5148
|
-
) : /* @__PURE__ */ (0,
|
|
5149
|
-
/* @__PURE__ */ (0,
|
|
5150
|
-
dingtalkMethod ? /* @__PURE__ */ (0,
|
|
5151
|
-
|
|
7594
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Empty, { description: "\u672A\u542F\u7528\u767B\u5F55\u65B9\u5F0F" }),
|
|
7595
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Space, { direction: "vertical", size: 10, style: { width: "100%" }, children: [
|
|
7596
|
+
dingtalkMethod ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7597
|
+
import_antd11.Button,
|
|
5152
7598
|
{
|
|
5153
7599
|
block: true,
|
|
5154
|
-
icon: /* @__PURE__ */ (0,
|
|
7600
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.QrcodeOutlined, {}),
|
|
5155
7601
|
loading: submitting,
|
|
5156
7602
|
onClick: handleDingTalkLogin,
|
|
5157
7603
|
children: dingtalkMethod.label || "\u9489\u9489\u514D\u767B"
|
|
5158
7604
|
}
|
|
5159
7605
|
) : null,
|
|
5160
|
-
ssoMethod ? /* @__PURE__ */ (0,
|
|
5161
|
-
|
|
7606
|
+
ssoMethod ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7607
|
+
import_antd11.Button,
|
|
5162
7608
|
{
|
|
5163
7609
|
block: true,
|
|
5164
|
-
icon: /* @__PURE__ */ (0,
|
|
7610
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.SafetyCertificateOutlined, {}),
|
|
5165
7611
|
loading: submitting,
|
|
5166
7612
|
onClick: handleSsoLogin,
|
|
5167
7613
|
children: ssoMethod.label || "SSO \u767B\u5F55"
|
|
5168
7614
|
}
|
|
5169
7615
|
) : null,
|
|
5170
|
-
guestMethod ? /* @__PURE__ */ (0,
|
|
5171
|
-
|
|
7616
|
+
guestMethod ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7617
|
+
import_antd11.Button,
|
|
5172
7618
|
{
|
|
5173
7619
|
block: true,
|
|
5174
|
-
icon: /* @__PURE__ */ (0,
|
|
7620
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.LoginOutlined, {}),
|
|
5175
7621
|
loading: submitting,
|
|
5176
7622
|
onClick: handleGuestLogin,
|
|
5177
7623
|
children: guestMethod.label || "\u8BBF\u5BA2\u8BBF\u95EE"
|
|
@@ -5184,28 +7630,28 @@ var LoginPage = ({
|
|
|
5184
7630
|
}
|
|
5185
7631
|
);
|
|
5186
7632
|
};
|
|
5187
|
-
var PasswordLoginForm = ({ challenge, form, loading, onFinish }) => /* @__PURE__ */ (0,
|
|
5188
|
-
/* @__PURE__ */ (0,
|
|
5189
|
-
|
|
7633
|
+
var PasswordLoginForm = ({ challenge, form, loading, onFinish }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Form, { form, layout: "vertical", requiredMark: false, onFinish, children: [
|
|
7634
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7635
|
+
import_antd11.Form.Item,
|
|
5190
7636
|
{
|
|
5191
7637
|
label: "\u8D26\u53F7",
|
|
5192
7638
|
name: "username",
|
|
5193
7639
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u8D26\u53F7" }],
|
|
5194
|
-
children: /* @__PURE__ */ (0,
|
|
7640
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Input, { autoComplete: "username" })
|
|
5195
7641
|
}
|
|
5196
7642
|
),
|
|
5197
|
-
/* @__PURE__ */ (0,
|
|
5198
|
-
|
|
7643
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7644
|
+
import_antd11.Form.Item,
|
|
5199
7645
|
{
|
|
5200
7646
|
label: "\u5BC6\u7801",
|
|
5201
7647
|
name: "password",
|
|
5202
7648
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u5BC6\u7801" }],
|
|
5203
|
-
children: /* @__PURE__ */ (0,
|
|
7649
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Input.Password, { autoComplete: "current-password" })
|
|
5204
7650
|
}
|
|
5205
7651
|
),
|
|
5206
|
-
challenge ? /* @__PURE__ */ (0,
|
|
5207
|
-
/* @__PURE__ */ (0,
|
|
5208
|
-
|
|
7652
|
+
challenge ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
7653
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7654
|
+
import_antd11.Alert,
|
|
5209
7655
|
{
|
|
5210
7656
|
showIcon: true,
|
|
5211
7657
|
type: "warning",
|
|
@@ -5213,17 +7659,17 @@ var PasswordLoginForm = ({ challenge, form, loading, onFinish }) => /* @__PURE__
|
|
|
5213
7659
|
description: readChallengeQuestion(challenge) || "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801\u540E\u7EE7\u7EED\u767B\u5F55\u3002"
|
|
5214
7660
|
}
|
|
5215
7661
|
),
|
|
5216
|
-
/* @__PURE__ */ (0,
|
|
5217
|
-
|
|
7662
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7663
|
+
import_antd11.Form.Item,
|
|
5218
7664
|
{
|
|
5219
7665
|
label: "\u9A8C\u8BC1\u7B54\u6848",
|
|
5220
7666
|
name: "challengeAnswer",
|
|
5221
7667
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7B54\u6848" }],
|
|
5222
|
-
children: /* @__PURE__ */ (0,
|
|
7668
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Input, { autoComplete: "one-time-code" })
|
|
5223
7669
|
}
|
|
5224
7670
|
)
|
|
5225
7671
|
] }) : null,
|
|
5226
|
-
/* @__PURE__ */ (0,
|
|
7672
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Button, { block: true, htmlType: "submit", icon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.LoginOutlined, {}), loading, type: "primary", children: "\u767B\u5F55" })
|
|
5227
7673
|
] });
|
|
5228
7674
|
var PhoneCodeLoginForm = ({
|
|
5229
7675
|
allowRegister,
|
|
@@ -5234,9 +7680,9 @@ var PhoneCodeLoginForm = ({
|
|
|
5234
7680
|
onPurposeChange,
|
|
5235
7681
|
onSendCode,
|
|
5236
7682
|
onFinish
|
|
5237
|
-
}) => /* @__PURE__ */ (0,
|
|
5238
|
-
allowRegister ? /* @__PURE__ */ (0,
|
|
5239
|
-
|
|
7683
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Form, { form, layout: "vertical", requiredMark: false, onFinish, children: [
|
|
7684
|
+
allowRegister ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Form.Item, { style: { marginBottom: 12 }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7685
|
+
import_antd11.Tabs,
|
|
5240
7686
|
{
|
|
5241
7687
|
activeKey: phonePurpose,
|
|
5242
7688
|
items: [
|
|
@@ -5247,26 +7693,26 @@ var PhoneCodeLoginForm = ({
|
|
|
5247
7693
|
size: "small"
|
|
5248
7694
|
}
|
|
5249
7695
|
) }) : null,
|
|
5250
|
-
/* @__PURE__ */ (0,
|
|
5251
|
-
|
|
7696
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7697
|
+
import_antd11.Form.Item,
|
|
5252
7698
|
{
|
|
5253
7699
|
label: "\u624B\u673A\u53F7",
|
|
5254
7700
|
name: "phone",
|
|
5255
7701
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u624B\u673A\u53F7" }],
|
|
5256
|
-
children: /* @__PURE__ */ (0,
|
|
7702
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Input, { autoComplete: "tel" })
|
|
5257
7703
|
}
|
|
5258
7704
|
),
|
|
5259
|
-
/* @__PURE__ */ (0,
|
|
5260
|
-
|
|
7705
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7706
|
+
import_antd11.Form.Item,
|
|
5261
7707
|
{
|
|
5262
7708
|
label: "\u9A8C\u8BC1\u7801",
|
|
5263
7709
|
name: "code",
|
|
5264
7710
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801" }],
|
|
5265
|
-
children: /* @__PURE__ */ (0,
|
|
5266
|
-
|
|
7711
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7712
|
+
import_antd11.Input,
|
|
5267
7713
|
{
|
|
5268
|
-
addonAfter: /* @__PURE__ */ (0,
|
|
5269
|
-
|
|
7714
|
+
addonAfter: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7715
|
+
import_antd11.Button,
|
|
5270
7716
|
{
|
|
5271
7717
|
loading: sendingCode,
|
|
5272
7718
|
onClick: onSendCode,
|
|
@@ -5280,7 +7726,7 @@ var PhoneCodeLoginForm = ({
|
|
|
5280
7726
|
)
|
|
5281
7727
|
}
|
|
5282
7728
|
),
|
|
5283
|
-
/* @__PURE__ */ (0,
|
|
7729
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Button, { block: true, htmlType: "submit", icon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.MobileOutlined, {}), loading, type: "primary", children: phonePurpose === "register" ? "\u6CE8\u518C" : "\u767B\u5F55" })
|
|
5284
7730
|
] });
|
|
5285
7731
|
var findMethod = (methods, type) => methods.find((method) => method.type === type);
|
|
5286
7732
|
var normalizeError = (error) => error instanceof Error ? error : new Error(String(error || "\u8BF7\u6C42\u5931\u8D25"));
|
|
@@ -5357,7 +7803,7 @@ var getCallbackUrl = () => {
|
|
|
5357
7803
|
};
|
|
5358
7804
|
|
|
5359
7805
|
// packages/sdk/src/runtime/react/openxiangdaProvider.tsx
|
|
5360
|
-
var
|
|
7806
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
5361
7807
|
var RuntimeHttpError = class extends Error {
|
|
5362
7808
|
constructor(snapshot) {
|
|
5363
7809
|
super(snapshot.message);
|
|
@@ -5368,26 +7814,26 @@ var RuntimeHttpError = class extends Error {
|
|
|
5368
7814
|
this.payload = snapshot.payload;
|
|
5369
7815
|
}
|
|
5370
7816
|
};
|
|
5371
|
-
var OpenXiangdaRuntimeContext = (0,
|
|
7817
|
+
var OpenXiangdaRuntimeContext = (0, import_react18.createContext)(null);
|
|
5372
7818
|
var OpenXiangdaProvider = ({
|
|
5373
7819
|
appType,
|
|
5374
7820
|
servicePrefix = "/service",
|
|
5375
7821
|
fetchImpl,
|
|
5376
7822
|
children
|
|
5377
7823
|
}) => {
|
|
5378
|
-
const resolvedFetch = (0,
|
|
5379
|
-
const resolvedAppType = (0,
|
|
7824
|
+
const resolvedFetch = (0, import_react18.useMemo)(() => createBoundFetch(fetchImpl), [fetchImpl]);
|
|
7825
|
+
const resolvedAppType = (0, import_react18.useMemo)(
|
|
5380
7826
|
() => appType || resolveAppTypeFromLocation(),
|
|
5381
7827
|
[appType]
|
|
5382
7828
|
);
|
|
5383
|
-
const [, setAccessTokenState] = (0,
|
|
5384
|
-
const [authState, setAuthState] = (0,
|
|
7829
|
+
const [, setAccessTokenState] = (0, import_react18.useState)(null);
|
|
7830
|
+
const [authState, setAuthState] = (0, import_react18.useState)({
|
|
5385
7831
|
status: "unknown",
|
|
5386
7832
|
error: null
|
|
5387
7833
|
});
|
|
5388
|
-
const accessTokenRef = (0,
|
|
5389
|
-
const refreshRequestRef = (0,
|
|
5390
|
-
const applyAccessToken = (0,
|
|
7834
|
+
const accessTokenRef = (0, import_react18.useRef)(null);
|
|
7835
|
+
const refreshRequestRef = (0, import_react18.useRef)(null);
|
|
7836
|
+
const applyAccessToken = (0, import_react18.useCallback)(
|
|
5391
7837
|
(nextAccessToken, options = {}) => {
|
|
5392
7838
|
if (!nextAccessToken && options.clearIfToken && accessTokenRef.current?.token !== options.clearIfToken) {
|
|
5393
7839
|
return accessTokenRef.current;
|
|
@@ -5405,7 +7851,7 @@ var OpenXiangdaProvider = ({
|
|
|
5405
7851
|
},
|
|
5406
7852
|
[]
|
|
5407
7853
|
);
|
|
5408
|
-
const setAccessToken = (0,
|
|
7854
|
+
const setAccessToken = (0, import_react18.useCallback)(
|
|
5409
7855
|
(nextAccessToken, options = {}) => {
|
|
5410
7856
|
const previousState = accessTokenRef.current;
|
|
5411
7857
|
const nextState = applyAccessToken(nextAccessToken, options);
|
|
@@ -5421,7 +7867,7 @@ var OpenXiangdaProvider = ({
|
|
|
5421
7867
|
},
|
|
5422
7868
|
[applyAccessToken]
|
|
5423
7869
|
);
|
|
5424
|
-
const markUnauthenticated = (0,
|
|
7870
|
+
const markUnauthenticated = (0, import_react18.useCallback)(
|
|
5425
7871
|
(error) => {
|
|
5426
7872
|
const runtimeError = normalizeRuntimeError(error);
|
|
5427
7873
|
applyAccessToken(null);
|
|
@@ -5429,7 +7875,7 @@ var OpenXiangdaProvider = ({
|
|
|
5429
7875
|
},
|
|
5430
7876
|
[applyAccessToken]
|
|
5431
7877
|
);
|
|
5432
|
-
const refreshAccessToken = (0,
|
|
7878
|
+
const refreshAccessToken = (0, import_react18.useCallback)(async () => {
|
|
5433
7879
|
if (!resolvedAppType) return null;
|
|
5434
7880
|
if (!refreshRequestRef.current) {
|
|
5435
7881
|
setAuthState((prev) => ({ ...prev, status: "refreshing", error: null }));
|
|
@@ -5490,7 +7936,7 @@ var OpenXiangdaProvider = ({
|
|
|
5490
7936
|
}
|
|
5491
7937
|
return refreshRequestRef.current;
|
|
5492
7938
|
}, [applyAccessToken, resolvedAppType, resolvedFetch, servicePrefix]);
|
|
5493
|
-
const authorizedFetch = (0,
|
|
7939
|
+
const authorizedFetch = (0, import_react18.useMemo)(
|
|
5494
7940
|
() => createAuthorizedFetch({
|
|
5495
7941
|
appType: resolvedAppType,
|
|
5496
7942
|
baseFetch: resolvedFetch,
|
|
@@ -5500,18 +7946,18 @@ var OpenXiangdaProvider = ({
|
|
|
5500
7946
|
}),
|
|
5501
7947
|
[markUnauthenticated, refreshAccessToken, resolvedAppType, resolvedFetch]
|
|
5502
7948
|
);
|
|
5503
|
-
const getAuthHeaders = (0,
|
|
7949
|
+
const getAuthHeaders = (0, import_react18.useCallback)(() => {
|
|
5504
7950
|
const state2 = accessTokenRef.current;
|
|
5505
7951
|
if (!state2) return {};
|
|
5506
7952
|
const token = resolveAccessTokenForCurrentRoute(state2);
|
|
5507
7953
|
return token ? { authorization: `Bearer ${token}` } : {};
|
|
5508
7954
|
}, []);
|
|
5509
|
-
const [state, setState] = (0,
|
|
7955
|
+
const [state, setState] = (0, import_react18.useState)({
|
|
5510
7956
|
data: null,
|
|
5511
7957
|
loading: true,
|
|
5512
7958
|
error: null
|
|
5513
7959
|
});
|
|
5514
|
-
const reload = (0,
|
|
7960
|
+
const reload = (0, import_react18.useCallback)(async (options = {}) => {
|
|
5515
7961
|
if (!resolvedAppType) {
|
|
5516
7962
|
setState({
|
|
5517
7963
|
data: null,
|
|
@@ -5575,10 +8021,10 @@ var OpenXiangdaProvider = ({
|
|
|
5575
8021
|
}
|
|
5576
8022
|
}
|
|
5577
8023
|
}, [authorizedFetch, resolvedAppType, resolvedFetch, servicePrefix]);
|
|
5578
|
-
(0,
|
|
8024
|
+
(0, import_react18.useEffect)(() => {
|
|
5579
8025
|
void reload();
|
|
5580
8026
|
}, [reload]);
|
|
5581
|
-
const value = (0,
|
|
8027
|
+
const value = (0, import_react18.useMemo)(
|
|
5582
8028
|
() => ({
|
|
5583
8029
|
...state,
|
|
5584
8030
|
appType: resolvedAppType,
|
|
@@ -5601,10 +8047,10 @@ var OpenXiangdaProvider = ({
|
|
|
5601
8047
|
authState
|
|
5602
8048
|
]
|
|
5603
8049
|
);
|
|
5604
|
-
return /* @__PURE__ */ (0,
|
|
8050
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(OpenXiangdaRuntimeContext.Provider, { value, children });
|
|
5605
8051
|
};
|
|
5606
8052
|
var useOpenXiangda = () => {
|
|
5607
|
-
const context = (0,
|
|
8053
|
+
const context = (0, import_react18.useContext)(OpenXiangdaRuntimeContext);
|
|
5608
8054
|
if (!context) {
|
|
5609
8055
|
throw new Error("useOpenXiangda must be used inside OpenXiangdaProvider");
|
|
5610
8056
|
}
|
|
@@ -5621,7 +8067,7 @@ var OpenXiangdaPageProvider = ({
|
|
|
5621
8067
|
navigation
|
|
5622
8068
|
}) => {
|
|
5623
8069
|
const runtime = useOpenXiangda();
|
|
5624
|
-
const context = (0,
|
|
8070
|
+
const context = (0, import_react18.useMemo)(() => {
|
|
5625
8071
|
const bootstrap = runtime.data;
|
|
5626
8072
|
const app = toRuntimeRecord(bootstrap?.app);
|
|
5627
8073
|
const user = toRuntimeRecord(bootstrap?.user);
|
|
@@ -5701,7 +8147,7 @@ var OpenXiangdaPageProvider = ({
|
|
|
5701
8147
|
runtime.fetchImpl,
|
|
5702
8148
|
runtime.servicePrefix
|
|
5703
8149
|
]);
|
|
5704
|
-
return /* @__PURE__ */ (0,
|
|
8150
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(PageProvider, { context, children });
|
|
5705
8151
|
};
|
|
5706
8152
|
var useAppMenus = () => {
|
|
5707
8153
|
const runtime = useOpenXiangda();
|
|
@@ -5719,12 +8165,12 @@ var usePermission = () => {
|
|
|
5719
8165
|
};
|
|
5720
8166
|
var useCanAccessRoute = (input) => {
|
|
5721
8167
|
const runtime = useOpenXiangda();
|
|
5722
|
-
const [state, setState] = (0,
|
|
8168
|
+
const [state, setState] = (0, import_react18.useState)({
|
|
5723
8169
|
data: null,
|
|
5724
8170
|
loading: true,
|
|
5725
8171
|
error: null
|
|
5726
8172
|
});
|
|
5727
|
-
(0,
|
|
8173
|
+
(0, import_react18.useEffect)(() => {
|
|
5728
8174
|
let disposed = false;
|
|
5729
8175
|
const check = async () => {
|
|
5730
8176
|
const permissions = runtime.data?.permissions;
|
|
@@ -5846,16 +8292,16 @@ var PermissionBoundary = ({
|
|
|
5846
8292
|
const access = useCanAccessRoute({ routeCode, menuCode, path });
|
|
5847
8293
|
const fallbackState = createPermissionFallbackState(access, runtime);
|
|
5848
8294
|
if (access.loading) {
|
|
5849
|
-
return /* @__PURE__ */ (0,
|
|
8295
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: renderBoundaryFallback(loadingFallback, fallbackState) });
|
|
5850
8296
|
}
|
|
5851
8297
|
if (!access.canAccess) {
|
|
5852
|
-
return /* @__PURE__ */ (0,
|
|
8298
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: renderBoundaryFallback(fallback, fallbackState) });
|
|
5853
8299
|
}
|
|
5854
|
-
return /* @__PURE__ */ (0,
|
|
8300
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children });
|
|
5855
8301
|
};
|
|
5856
8302
|
var useRuntimeAuth = () => {
|
|
5857
8303
|
const runtime = useOpenXiangda();
|
|
5858
|
-
const resolveLoginUrl2 = (0,
|
|
8304
|
+
const resolveLoginUrl2 = (0, import_react18.useCallback)(
|
|
5859
8305
|
async (options = {}) => {
|
|
5860
8306
|
const redirectUri = options.redirectUri || getCurrentHref4();
|
|
5861
8307
|
const domain = options.domain || getCurrentHostname2();
|
|
@@ -5902,7 +8348,7 @@ var useRuntimeAuth = () => {
|
|
|
5902
8348
|
},
|
|
5903
8349
|
[runtime.baseFetchImpl, runtime.data?.app, runtime.servicePrefix]
|
|
5904
8350
|
);
|
|
5905
|
-
const redirectToLogin = (0,
|
|
8351
|
+
const redirectToLogin = (0, import_react18.useCallback)(
|
|
5906
8352
|
async (options = {}) => {
|
|
5907
8353
|
const loginUrl = await resolveLoginUrl2(options);
|
|
5908
8354
|
if (typeof window !== "undefined") {
|
|
@@ -5916,7 +8362,7 @@ var useRuntimeAuth = () => {
|
|
|
5916
8362
|
},
|
|
5917
8363
|
[resolveLoginUrl2]
|
|
5918
8364
|
);
|
|
5919
|
-
const logout = (0,
|
|
8365
|
+
const logout = (0, import_react18.useCallback)(async () => {
|
|
5920
8366
|
const response = await runtime.baseFetchImpl(
|
|
5921
8367
|
buildServiceUrl2(runtime.servicePrefix, "/api/auth/logout"),
|
|
5922
8368
|
{
|
|
@@ -5936,7 +8382,7 @@ var useRuntimeAuth = () => {
|
|
|
5936
8382
|
runtime.setAccessToken(null);
|
|
5937
8383
|
return payload;
|
|
5938
8384
|
}, [runtime.baseFetchImpl, runtime.servicePrefix, runtime.setAccessToken]);
|
|
5939
|
-
const logoutAndRedirect = (0,
|
|
8385
|
+
const logoutAndRedirect = (0, import_react18.useCallback)(
|
|
5940
8386
|
async (options = {}) => {
|
|
5941
8387
|
try {
|
|
5942
8388
|
await logout();
|
|
@@ -5947,7 +8393,7 @@ var useRuntimeAuth = () => {
|
|
|
5947
8393
|
},
|
|
5948
8394
|
[logout, redirectToLogin]
|
|
5949
8395
|
);
|
|
5950
|
-
return (0,
|
|
8396
|
+
return (0, import_react18.useMemo)(
|
|
5951
8397
|
() => ({
|
|
5952
8398
|
logout,
|
|
5953
8399
|
logoutAndRedirect,
|
|
@@ -5966,7 +8412,7 @@ var RuntimeAuthGuard = ({
|
|
|
5966
8412
|
}) => {
|
|
5967
8413
|
const runtime = useOpenXiangda();
|
|
5968
8414
|
const auth = useRuntimeAuth();
|
|
5969
|
-
const redirectedRef = (0,
|
|
8415
|
+
const redirectedRef = (0, import_react18.useRef)(false);
|
|
5970
8416
|
const currentPath = getCurrentPathname();
|
|
5971
8417
|
const excluded = isRuntimeAuthGuardExcluded(
|
|
5972
8418
|
currentPath,
|
|
@@ -5974,7 +8420,7 @@ var RuntimeAuthGuard = ({
|
|
|
5974
8420
|
excludedPaths
|
|
5975
8421
|
);
|
|
5976
8422
|
const shouldRedirect = !disabled && !excluded && !runtime.loading && (runtime.authState.status === "unauthenticated" || runtime.error?.type === "unauthenticated");
|
|
5977
|
-
(0,
|
|
8423
|
+
(0, import_react18.useEffect)(() => {
|
|
5978
8424
|
if (!shouldRedirect || redirectedRef.current) return;
|
|
5979
8425
|
redirectedRef.current = true;
|
|
5980
8426
|
void auth.redirectToLogin({
|
|
@@ -5991,9 +8437,9 @@ var RuntimeAuthGuard = ({
|
|
|
5991
8437
|
redirectOptions.replace,
|
|
5992
8438
|
shouldRedirect
|
|
5993
8439
|
]);
|
|
5994
|
-
if (excluded) return /* @__PURE__ */ (0,
|
|
5995
|
-
if (shouldRedirect) return /* @__PURE__ */ (0,
|
|
5996
|
-
return /* @__PURE__ */ (0,
|
|
8440
|
+
if (excluded) return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children });
|
|
8441
|
+
if (shouldRedirect) return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: fallback });
|
|
8442
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children });
|
|
5997
8443
|
};
|
|
5998
8444
|
var buildServiceUrl2 = (servicePrefix, path) => {
|
|
5999
8445
|
const prefix = servicePrefix.endsWith("/") ? servicePrefix.slice(0, -1) : servicePrefix;
|
|
@@ -6264,7 +8710,7 @@ var buildBrowserRouteInfo = (route) => {
|
|
|
6264
8710
|
hash
|
|
6265
8711
|
};
|
|
6266
8712
|
};
|
|
6267
|
-
var
|
|
8713
|
+
var isSuccessCode6 = (code) => {
|
|
6268
8714
|
if (code === void 0 || code === null || code === "") return true;
|
|
6269
8715
|
const normalized = Number(code);
|
|
6270
8716
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -6272,7 +8718,7 @@ var isSuccessCode5 = (code) => {
|
|
|
6272
8718
|
var isRuntimeEnvelopeFailure = (response, payload) => {
|
|
6273
8719
|
const code = getRecordValue2(payload, "code");
|
|
6274
8720
|
const success = getRecordValue2(payload, "success");
|
|
6275
|
-
return !response.ok || success === false || !
|
|
8721
|
+
return !response.ok || success === false || !isSuccessCode6(code);
|
|
6276
8722
|
};
|
|
6277
8723
|
var isServerErrorCode = (code) => {
|
|
6278
8724
|
const normalized = Number(code);
|
|
@@ -6317,7 +8763,7 @@ var resolveAppTypeFromLocation = () => {
|
|
|
6317
8763
|
};
|
|
6318
8764
|
|
|
6319
8765
|
// packages/sdk/src/runtime/react/publicAccess.tsx
|
|
6320
|
-
var
|
|
8766
|
+
var import_react19 = require("react");
|
|
6321
8767
|
|
|
6322
8768
|
// packages/sdk/src/runtime/core/publicAccess.ts
|
|
6323
8769
|
var PublicAccessClientError = class extends Error {
|
|
@@ -6367,7 +8813,7 @@ var createPublicAccessClient = ({
|
|
|
6367
8813
|
const payload = await readPayload2(response);
|
|
6368
8814
|
const code = getRecordValue3(payload, "code");
|
|
6369
8815
|
const success = getRecordValue3(payload, "success");
|
|
6370
|
-
if (!response.ok || success === false || !
|
|
8816
|
+
if (!response.ok || success === false || !isSuccessCode7(code)) {
|
|
6371
8817
|
throw new PublicAccessClientError(
|
|
6372
8818
|
String(
|
|
6373
8819
|
getRecordValue3(payload, "message") || `Public access session failed: ${response.status}`
|
|
@@ -6405,7 +8851,7 @@ var getRecordValue3 = (value, key) => {
|
|
|
6405
8851
|
if (!value || typeof value !== "object") return void 0;
|
|
6406
8852
|
return value[key];
|
|
6407
8853
|
};
|
|
6408
|
-
var
|
|
8854
|
+
var isSuccessCode7 = (code) => {
|
|
6409
8855
|
if (code === void 0 || code === null || code === "") return true;
|
|
6410
8856
|
const normalized = Number(code);
|
|
6411
8857
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -6433,7 +8879,7 @@ var createRandomIdentifier = (appType) => {
|
|
|
6433
8879
|
};
|
|
6434
8880
|
|
|
6435
8881
|
// packages/sdk/src/runtime/react/publicAccess.tsx
|
|
6436
|
-
var
|
|
8882
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
6437
8883
|
var usePublicAccess = (options = {}) => {
|
|
6438
8884
|
const runtime = useOpenXiangda();
|
|
6439
8885
|
const {
|
|
@@ -6450,14 +8896,14 @@ var usePublicAccess = (options = {}) => {
|
|
|
6450
8896
|
autoStart = true,
|
|
6451
8897
|
...sessionInput
|
|
6452
8898
|
} = options;
|
|
6453
|
-
const [session, setSession] = (0,
|
|
6454
|
-
const [error, setError] = (0,
|
|
6455
|
-
const [loading, setLoading] = (0,
|
|
6456
|
-
const activeSessionRef = (0,
|
|
6457
|
-
const mountedRef = (0,
|
|
8899
|
+
const [session, setSession] = (0, import_react19.useState)(null);
|
|
8900
|
+
const [error, setError] = (0, import_react19.useState)(null);
|
|
8901
|
+
const [loading, setLoading] = (0, import_react19.useState)(Boolean(autoStart));
|
|
8902
|
+
const activeSessionRef = (0, import_react19.useRef)(null);
|
|
8903
|
+
const mountedRef = (0, import_react19.useRef)(true);
|
|
6458
8904
|
const sessionInputKey = JSON.stringify(sessionInput);
|
|
6459
|
-
const stableSessionInput = (0,
|
|
6460
|
-
const client = (0,
|
|
8905
|
+
const stableSessionInput = (0, import_react19.useMemo)(() => sessionInput, [sessionInputKey]);
|
|
8906
|
+
const client = (0, import_react19.useMemo)(
|
|
6461
8907
|
() => createPublicAccessClient({
|
|
6462
8908
|
appType,
|
|
6463
8909
|
servicePrefix,
|
|
@@ -6465,7 +8911,7 @@ var usePublicAccess = (options = {}) => {
|
|
|
6465
8911
|
}),
|
|
6466
8912
|
[appType, fetchImpl, servicePrefix]
|
|
6467
8913
|
);
|
|
6468
|
-
const startSession = (0,
|
|
8914
|
+
const startSession = (0, import_react19.useCallback)(
|
|
6469
8915
|
async (input = {}) => {
|
|
6470
8916
|
setLoading(true);
|
|
6471
8917
|
setError(null);
|
|
@@ -6511,11 +8957,11 @@ var usePublicAccess = (options = {}) => {
|
|
|
6511
8957
|
},
|
|
6512
8958
|
[client, reloadRuntime, setAccessToken, stableSessionInput]
|
|
6513
8959
|
);
|
|
6514
|
-
(0,
|
|
8960
|
+
(0, import_react19.useEffect)(() => {
|
|
6515
8961
|
if (!autoStart) return;
|
|
6516
8962
|
void startSession().catch(() => void 0);
|
|
6517
8963
|
}, [autoStart, startSession]);
|
|
6518
|
-
(0,
|
|
8964
|
+
(0, import_react19.useEffect)(
|
|
6519
8965
|
() => {
|
|
6520
8966
|
mountedRef.current = true;
|
|
6521
8967
|
return () => {
|
|
@@ -6544,11 +8990,11 @@ var PublicAccessGate = ({
|
|
|
6544
8990
|
...options
|
|
6545
8991
|
}) => {
|
|
6546
8992
|
const state = usePublicAccess(options);
|
|
6547
|
-
if (state.loading) return /* @__PURE__ */ (0,
|
|
8993
|
+
if (state.loading) return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children: fallback });
|
|
6548
8994
|
if (state.error) {
|
|
6549
|
-
return /* @__PURE__ */ (0,
|
|
8995
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children: typeof errorFallback === "function" ? errorFallback(state.error) : errorFallback });
|
|
6550
8996
|
}
|
|
6551
|
-
return /* @__PURE__ */ (0,
|
|
8997
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children });
|
|
6552
8998
|
};
|
|
6553
8999
|
var readTicketFromLocation = () => {
|
|
6554
9000
|
if (typeof window === "undefined") return void 0;
|