openxiangda 1.0.152 → 1.0.154
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 +13 -1
- package/openxiangda-skills/SKILL.md +1 -1
- package/openxiangda-skills/references/component-guide.md +10 -1
- package/openxiangda-skills/references/pages/page-sdk.md +35 -2
- package/openxiangda-skills/references/troubleshooting.md +18 -5
- package/package.json +1 -1
- package/packages/sdk/dist/{ProcessPreview-B_HqjU7v.d.mts → ProcessPreview-DMkzccq4.d.mts} +55 -1
- package/packages/sdk/dist/{ProcessPreview-B_HqjU7v.d.ts → ProcessPreview-DMkzccq4.d.ts} +55 -1
- package/packages/sdk/dist/components/index.cjs +73 -12
- package/packages/sdk/dist/components/index.cjs.map +1 -1
- package/packages/sdk/dist/components/index.d.mts +7 -59
- package/packages/sdk/dist/components/index.d.ts +7 -59
- package/packages/sdk/dist/components/index.mjs +73 -12
- package/packages/sdk/dist/components/index.mjs.map +1 -1
- package/packages/sdk/dist/{dataManagementApi-CEDsA3tT.d.ts → dataManagementApi-C9O-Bb0j.d.ts} +1 -1
- package/packages/sdk/dist/{dataManagementApi-quq3Zhgo.d.mts → dataManagementApi-gpZkgRDM.d.mts} +1 -1
- package/packages/sdk/dist/runtime/index.cjs +10528 -10211
- package/packages/sdk/dist/runtime/index.cjs.map +1 -1
- package/packages/sdk/dist/runtime/index.d.mts +3 -3
- package/packages/sdk/dist/runtime/index.d.ts +3 -3
- package/packages/sdk/dist/runtime/index.mjs +9892 -9575
- package/packages/sdk/dist/runtime/index.mjs.map +1 -1
- package/packages/sdk/dist/runtime/react.cjs +2936 -451
- package/packages/sdk/dist/runtime/react.cjs.map +1 -1
- package/packages/sdk/dist/runtime/react.d.mts +57 -3
- package/packages/sdk/dist/runtime/react.d.ts +57 -3
- package/packages/sdk/dist/runtime/react.mjs +2945 -437
- 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 +4 -2
|
@@ -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,
|
|
@@ -2696,15 +2699,2559 @@ 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 isZipBytes = (bytes) => bytes.length >= 4 && bytes[0] === 80 && bytes[1] === 75 && (bytes[2] === 3 && bytes[3] === 4 || bytes[2] === 5 && bytes[3] === 6 || bytes[2] === 7 && bytes[3] === 8);
|
|
3751
|
+
var decodeBase64ZipBlob = async (blob) => {
|
|
3752
|
+
const prefix = (await blob.slice(0, 96).text()).replace(/^\uFEFF/, "").replace(/\s+/g, "");
|
|
3753
|
+
if (!prefix.startsWith("UEsDB")) return blob;
|
|
3754
|
+
if (blob.size > 32 * 1024 * 1024) {
|
|
3755
|
+
throw new Error("Base64 \u6587\u4EF6\u8D85\u8FC7\u6D4F\u89C8\u5668\u517C\u5BB9\u89E3\u7801\u4E0A\u9650");
|
|
3756
|
+
}
|
|
3757
|
+
const base64 = (await blob.text()).replace(/^\uFEFF/, "").replace(/\s+/g, "");
|
|
3758
|
+
if (!/^[A-Za-z0-9+/]+={0,2}$/.test(base64)) {
|
|
3759
|
+
throw new Error("\u6587\u4EF6\u5185\u5BB9\u662F\u65E0\u6548\u7684 Base64 \u4E8C\u8FDB\u5236\u6570\u636E");
|
|
3760
|
+
}
|
|
3761
|
+
let binary = "";
|
|
3762
|
+
try {
|
|
3763
|
+
binary = globalThis.atob(base64);
|
|
3764
|
+
} catch {
|
|
3765
|
+
throw new Error("\u6587\u4EF6\u5185\u5BB9\u662F\u65E0\u6548\u7684 Base64 \u4E8C\u8FDB\u5236\u6570\u636E");
|
|
3766
|
+
}
|
|
3767
|
+
const bytes = new Uint8Array(binary.length);
|
|
3768
|
+
for (let index = 0; index < binary.length; index += 1) {
|
|
3769
|
+
bytes[index] = binary.charCodeAt(index);
|
|
3770
|
+
}
|
|
3771
|
+
if (!isZipBytes(bytes)) {
|
|
3772
|
+
throw new Error("Base64 \u6587\u4EF6\u89E3\u7801\u540E\u4E0D\u662F\u6709\u6548\u7684 Office \u6587\u6863");
|
|
3773
|
+
}
|
|
3774
|
+
if (globalThis.btoa(binary).replace(/=+$/, "") !== base64.replace(/=+$/, "")) {
|
|
3775
|
+
throw new Error("\u6587\u4EF6\u5185\u5BB9\u662F\u65E0\u6548\u7684 Base64 \u4E8C\u8FDB\u5236\u6570\u636E");
|
|
3776
|
+
}
|
|
3777
|
+
return new Blob([bytes], { type: blob.type || "application/zip" });
|
|
3778
|
+
};
|
|
3779
|
+
var normalizePreviewBlobContent = async (response) => {
|
|
3780
|
+
const blob = normalizePreviewBlobResponse(response);
|
|
3781
|
+
if (String(blob.type || "").toLowerCase().includes("application/json")) {
|
|
3782
|
+
const payload = await blob.text().then((value) => JSON.parse(value)).catch(() => null);
|
|
3783
|
+
if (payload) {
|
|
3784
|
+
throw new Error(getBinaryResponseMessage(payload) || "\u6587\u4EF6\u5185\u5BB9\u8BF7\u6C42\u5931\u8D25");
|
|
3785
|
+
}
|
|
3786
|
+
}
|
|
3787
|
+
return decodeBase64ZipBlob(blob);
|
|
3788
|
+
};
|
|
3789
|
+
var isDirectStorageItem = (item) => item.provider === "oss" || item.uploadProvider === "oss" || item.uploadProvider === "builtin-oss" || Boolean(item.storageCode);
|
|
3790
|
+
var getPreviewItemKey = (item, index = 0) => getAttachmentItemIdentity(item) || item.id || item.uid || `${item.name || "file"}-${index}`;
|
|
3791
|
+
var getPreviewSourceUrl = (item) => item.previewUrl || item.publicUrl || item.url || "";
|
|
3792
|
+
var inferExtensionFromContentType = (contentType) => {
|
|
3793
|
+
if (contentType.includes("wordprocessingml")) return "docx";
|
|
3794
|
+
if (contentType.includes("spreadsheetml")) return "xlsx";
|
|
3795
|
+
if (contentType.includes("pdf")) return "pdf";
|
|
3796
|
+
if (contentType.includes("heic")) return "heic";
|
|
3797
|
+
if (contentType.includes("heif")) return "heif";
|
|
3798
|
+
if (contentType.includes("tiff")) return "tiff";
|
|
3799
|
+
if (contentType.includes("csv")) return "csv";
|
|
3800
|
+
return "";
|
|
3801
|
+
};
|
|
3802
|
+
var downloadOnly = (extension, unsupportedReason) => ({
|
|
3803
|
+
extension,
|
|
3804
|
+
previewType: "download",
|
|
3805
|
+
renderMode: "download",
|
|
3806
|
+
previewSurface: "download",
|
|
3807
|
+
previewProvider: "none",
|
|
3808
|
+
canPreview: false,
|
|
3809
|
+
canDownload: true,
|
|
3810
|
+
unsupportedReason
|
|
3811
|
+
});
|
|
3812
|
+
var resolveLocalPreviewCapability = (item) => {
|
|
3813
|
+
const contentType = String(item.contentType || item.mimeType || "").toLowerCase();
|
|
3814
|
+
const extension = getFileExtension(item.name || item.originalName || item.objectName || "") || inferExtensionFromContentType(contentType);
|
|
3815
|
+
const size = Number(item.size || 0);
|
|
3816
|
+
if (IMAGE_EXTENSIONS.has(extension) || contentType.startsWith("image/")) {
|
|
3817
|
+
if (["heic", "heif"].includes(extension) && size > 0 && size > DIRECT_HEIC_MAX_BYTES) {
|
|
3818
|
+
return downloadOnly(extension, "HEIC \u56FE\u7247\u8D85\u8FC7 30MB \u6D4F\u89C8\u5668\u8F6C\u6362\u4E0A\u9650");
|
|
3819
|
+
}
|
|
3820
|
+
const platformTranscode = ["tif", "tiff"].includes(extension) && Boolean(item.objectName) && !isDirectStorageItem(item);
|
|
3821
|
+
return {
|
|
3822
|
+
extension,
|
|
3823
|
+
previewType: "image",
|
|
3824
|
+
renderMode: ["heic", "heif"].includes(extension) ? "image-heic" : platformTranscode ? "image-transcode" : ["tif", "tiff"].includes(extension) ? "download" : "inline",
|
|
3825
|
+
previewSurface: "media",
|
|
3826
|
+
previewProvider: platformTranscode ? "platform" : "browser",
|
|
3827
|
+
canPreview: platformTranscode || !["tif", "tiff"].includes(extension),
|
|
3828
|
+
canDownload: true,
|
|
3829
|
+
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
|
|
3830
|
+
};
|
|
3831
|
+
}
|
|
3832
|
+
if (VIDEO_EXTENSIONS.has(extension) || contentType.startsWith("video/")) {
|
|
3833
|
+
return {
|
|
3834
|
+
extension,
|
|
3835
|
+
previewType: "video",
|
|
3836
|
+
renderMode: "inline",
|
|
3837
|
+
previewSurface: "media",
|
|
3838
|
+
previewProvider: "browser",
|
|
3839
|
+
canPreview: true,
|
|
3840
|
+
canDownload: true
|
|
3841
|
+
};
|
|
3842
|
+
}
|
|
3843
|
+
if (AUDIO_EXTENSIONS.has(extension) || contentType.startsWith("audio/")) {
|
|
3844
|
+
return {
|
|
3845
|
+
extension,
|
|
3846
|
+
previewType: "audio",
|
|
3847
|
+
renderMode: "inline",
|
|
3848
|
+
previewSurface: "media",
|
|
3849
|
+
previewProvider: "browser",
|
|
3850
|
+
canPreview: true,
|
|
3851
|
+
canDownload: true
|
|
3852
|
+
};
|
|
3853
|
+
}
|
|
3854
|
+
if (extension === "pdf" || contentType.includes("pdf")) {
|
|
3855
|
+
return {
|
|
3856
|
+
extension: extension || "pdf",
|
|
3857
|
+
previewType: "pdf",
|
|
3858
|
+
renderMode: "pdfjs",
|
|
3859
|
+
previewSurface: "document",
|
|
3860
|
+
previewProvider: "browser",
|
|
3861
|
+
canPreview: true,
|
|
3862
|
+
canDownload: true
|
|
3863
|
+
};
|
|
3864
|
+
}
|
|
3865
|
+
if (extension === "docx") {
|
|
3866
|
+
if (size > 0 && size > DIRECT_DOCX_MAX_BYTES) {
|
|
3867
|
+
return downloadOnly(extension, "Word \u6587\u4EF6\u8D85\u8FC7 20MB \u6D4F\u89C8\u5668\u9884\u89C8\u4E0A\u9650");
|
|
3868
|
+
}
|
|
3869
|
+
return {
|
|
3870
|
+
extension,
|
|
3871
|
+
previewType: "office",
|
|
3872
|
+
renderMode: "docx-html",
|
|
3873
|
+
previewSurface: "document",
|
|
3874
|
+
previewProvider: "browser",
|
|
3875
|
+
canPreview: true,
|
|
3876
|
+
canDownload: true
|
|
3877
|
+
};
|
|
3878
|
+
}
|
|
3879
|
+
if (extension === "xlsx") {
|
|
3880
|
+
if (size > 0 && size > DIRECT_XLSX_MAX_BYTES) {
|
|
3881
|
+
return downloadOnly(extension, "Excel \u6587\u4EF6\u8D85\u8FC7 10MB \u6D4F\u89C8\u5668\u9884\u89C8\u4E0A\u9650");
|
|
3882
|
+
}
|
|
3883
|
+
return {
|
|
3884
|
+
extension,
|
|
3885
|
+
previewType: "spreadsheet",
|
|
3886
|
+
renderMode: "excel-client",
|
|
3887
|
+
previewSurface: "document",
|
|
3888
|
+
previewProvider: "browser",
|
|
3889
|
+
canPreview: true,
|
|
3890
|
+
canDownload: true
|
|
3891
|
+
};
|
|
3892
|
+
}
|
|
3893
|
+
if (TEXT_EXTENSIONS.has(extension) || contentType.startsWith("text/")) {
|
|
3894
|
+
return {
|
|
3895
|
+
extension,
|
|
3896
|
+
previewType: "text",
|
|
3897
|
+
renderMode: "text-client",
|
|
3898
|
+
previewSurface: "document",
|
|
3899
|
+
previewProvider: "browser",
|
|
3900
|
+
canPreview: true,
|
|
3901
|
+
canDownload: true
|
|
3902
|
+
};
|
|
3903
|
+
}
|
|
3904
|
+
return downloadOnly(extension, "\u5F53\u524D\u6587\u4EF6\u7C7B\u578B\u6CA1\u6709\u53EF\u7528\u7684\u5728\u7EBF\u9884\u89C8\u5668");
|
|
3905
|
+
};
|
|
3906
|
+
var getTicketObject = (ticket) => typeof ticket === "string" ? { previewUrl: ticket } : ticket || {};
|
|
3907
|
+
var prepareFilePreview = async (options) => {
|
|
3908
|
+
const { item, api, appType, bucketName } = options;
|
|
3909
|
+
const direct = isDirectStorageItem(item) || !item.objectName;
|
|
3910
|
+
if (direct) {
|
|
3911
|
+
const capability = resolveLocalPreviewCapability(item);
|
|
3912
|
+
return {
|
|
3913
|
+
item,
|
|
3914
|
+
direct: true,
|
|
3915
|
+
metadata: {
|
|
3916
|
+
...capability,
|
|
3917
|
+
fileName: item.name,
|
|
3918
|
+
size: item.size,
|
|
3919
|
+
contentType: item.contentType || item.mimeType,
|
|
3920
|
+
previewUrl: getPreviewSourceUrl(item),
|
|
3921
|
+
downloadUrl: item.downloadUrl || item.publicUrl || item.url
|
|
3922
|
+
}
|
|
3923
|
+
};
|
|
3924
|
+
}
|
|
3925
|
+
const ticketResult = getTicketObject(
|
|
3926
|
+
await api.createFileAccessTicket(
|
|
3927
|
+
item.bucketName || bucketName,
|
|
3928
|
+
item.objectName,
|
|
3929
|
+
item.name,
|
|
3930
|
+
"preview",
|
|
3931
|
+
{ appType: item.appType || appType }
|
|
3932
|
+
)
|
|
3933
|
+
);
|
|
3934
|
+
const localCapability = resolveLocalPreviewCapability(item);
|
|
3935
|
+
const ticket = String(ticketResult.ticket || "").trim();
|
|
3936
|
+
let metadata = {};
|
|
3937
|
+
if (ticketResult.metadataUrl || ticket) {
|
|
3938
|
+
const response = await api.request({
|
|
3939
|
+
url: ticketResult.metadataUrl || `/file/access-ticket/${encodeURIComponent(ticket)}`,
|
|
3940
|
+
method: "get"
|
|
3941
|
+
});
|
|
3942
|
+
metadata = unwrapFilePreviewPayload(response);
|
|
3943
|
+
}
|
|
3944
|
+
return {
|
|
3945
|
+
item,
|
|
3946
|
+
direct: false,
|
|
3947
|
+
metadata: {
|
|
3948
|
+
...localCapability,
|
|
3949
|
+
...ticketResult,
|
|
3950
|
+
...metadata,
|
|
3951
|
+
ticket: metadata.ticket || ticketResult.ticket,
|
|
3952
|
+
fileName: metadata.fileName || ticketResult.fileName || item.name,
|
|
3953
|
+
size: metadata.size ?? item.size,
|
|
3954
|
+
contentType: metadata.contentType || ticketResult.contentType || item.contentType || item.mimeType,
|
|
3955
|
+
previewUrl: ticketResult.previewUrl || metadata.previewUrl || getPreviewSourceUrl(item),
|
|
3956
|
+
downloadUrl: ticketResult.downloadUrl || metadata.downloadUrl || item.downloadUrl || item.publicUrl || item.url
|
|
3957
|
+
}
|
|
3958
|
+
};
|
|
3959
|
+
};
|
|
3960
|
+
var loadPreviewBlob = async (request, url) => {
|
|
3961
|
+
const response = await request({ url, method: "get", responseType: "blob" });
|
|
3962
|
+
return normalizePreviewBlobContent(response);
|
|
3963
|
+
};
|
|
3964
|
+
var convertHeicPreview = async (request, url) => {
|
|
3965
|
+
const source = await loadPreviewBlob(request, url);
|
|
3966
|
+
const module2 = await import("heic2any");
|
|
3967
|
+
const converted = await module2.default({
|
|
3968
|
+
blob: source,
|
|
3969
|
+
toType: "image/jpeg",
|
|
3970
|
+
quality: 0.92
|
|
3971
|
+
});
|
|
3972
|
+
const blob = Array.isArray(converted) ? converted[0] : converted;
|
|
3973
|
+
if (!(blob instanceof Blob)) {
|
|
3974
|
+
throw new Error("HEIC \u56FE\u7247\u8F6C\u6362\u5931\u8D25");
|
|
3975
|
+
}
|
|
3976
|
+
return URL.createObjectURL(blob);
|
|
3977
|
+
};
|
|
3978
|
+
|
|
3979
|
+
// packages/sdk/src/components/file-preview/FilePreviewContent.tsx
|
|
3980
|
+
var import_react7 = require("react");
|
|
3981
|
+
var import_antd2 = require("antd");
|
|
3982
|
+
var import_icons = require("@ant-design/icons");
|
|
3983
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
3984
|
+
var formatPreviewFileSize = (size) => {
|
|
3985
|
+
const value = Number(size || 0);
|
|
3986
|
+
if (!value) return "0 B";
|
|
3987
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
3988
|
+
const index = Math.min(
|
|
3989
|
+
units.length - 1,
|
|
3990
|
+
Math.floor(Math.log(value) / Math.log(1024))
|
|
3991
|
+
);
|
|
3992
|
+
return `${(value / Math.pow(1024, index)).toFixed(index === 0 ? 0 : 1)} ${units[index]}`;
|
|
3993
|
+
};
|
|
3994
|
+
var resolvePreviewServiceUrl = (url, servicePrefix = "/service") => {
|
|
3995
|
+
const value = String(url || "").trim();
|
|
3996
|
+
if (!value) return "";
|
|
3997
|
+
if (/^(https?:)?\/\//i.test(value) || /^(blob|data):/i.test(value)) return value;
|
|
3998
|
+
if (value === servicePrefix || value.startsWith(`${servicePrefix}/`)) return value;
|
|
3999
|
+
if (value.startsWith("/file/")) {
|
|
4000
|
+
return `${servicePrefix.replace(/\/+$/, "")}${value}`;
|
|
4001
|
+
}
|
|
4002
|
+
return value;
|
|
4003
|
+
};
|
|
4004
|
+
var toColumnName = (index) => {
|
|
4005
|
+
let value = index + 1;
|
|
4006
|
+
let name = "";
|
|
4007
|
+
while (value > 0) {
|
|
4008
|
+
const mod = (value - 1) % 26;
|
|
4009
|
+
name = String.fromCharCode(65 + mod) + name;
|
|
4010
|
+
value = Math.floor((value - mod) / 26);
|
|
4011
|
+
}
|
|
4012
|
+
return name;
|
|
4013
|
+
};
|
|
4014
|
+
var buildRowsTable = (rows = []) => {
|
|
4015
|
+
const maxColumns = rows.reduce(
|
|
4016
|
+
(count, row) => Math.max(count, Array.isArray(row) ? row.length : 0),
|
|
4017
|
+
0
|
|
4018
|
+
);
|
|
4019
|
+
const columns = [
|
|
4020
|
+
{
|
|
4021
|
+
title: "#",
|
|
4022
|
+
dataIndex: "__row",
|
|
4023
|
+
key: "__row",
|
|
4024
|
+
width: 58,
|
|
4025
|
+
fixed: "left",
|
|
4026
|
+
render: (value) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Typography.Text, { type: "secondary", children: value })
|
|
4027
|
+
},
|
|
4028
|
+
...Array.from({ length: maxColumns }).map((_, index) => ({
|
|
4029
|
+
title: toColumnName(index),
|
|
4030
|
+
dataIndex: `col_${index}`,
|
|
4031
|
+
key: `col_${index}`,
|
|
4032
|
+
width: 168,
|
|
4033
|
+
render: (value) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Typography.Text, { ellipsis: { tooltip: String(value ?? "") }, children: String(value ?? "") })
|
|
4034
|
+
}))
|
|
4035
|
+
];
|
|
4036
|
+
const dataSource = rows.map((row, rowIndex) => {
|
|
4037
|
+
const record = { key: rowIndex, __row: rowIndex + 1 };
|
|
4038
|
+
(Array.isArray(row) ? row : []).forEach((value, colIndex) => {
|
|
4039
|
+
record[`col_${colIndex}`] = value;
|
|
4040
|
+
});
|
|
4041
|
+
return record;
|
|
4042
|
+
});
|
|
4043
|
+
return { columns, dataSource };
|
|
4044
|
+
};
|
|
4045
|
+
var CenteredState = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4046
|
+
"div",
|
|
4047
|
+
{
|
|
4048
|
+
style: {
|
|
4049
|
+
minHeight: 280,
|
|
4050
|
+
height: "100%",
|
|
4051
|
+
display: "flex",
|
|
4052
|
+
alignItems: "center",
|
|
4053
|
+
justifyContent: "center",
|
|
4054
|
+
padding: 24
|
|
4055
|
+
},
|
|
4056
|
+
children
|
|
4057
|
+
}
|
|
4058
|
+
);
|
|
4059
|
+
var PayloadPreview = ({
|
|
4060
|
+
request,
|
|
4061
|
+
url,
|
|
4062
|
+
mode
|
|
4063
|
+
}) => {
|
|
4064
|
+
const [payload, setPayload] = (0, import_react7.useState)(null);
|
|
4065
|
+
const [loading, setLoading] = (0, import_react7.useState)(false);
|
|
4066
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4067
|
+
const [reloadKey, setReloadKey] = (0, import_react7.useState)(0);
|
|
4068
|
+
(0, import_react7.useEffect)(() => {
|
|
4069
|
+
let disposed = false;
|
|
4070
|
+
setPayload(null);
|
|
4071
|
+
setError("");
|
|
4072
|
+
if (!url) return () => {
|
|
4073
|
+
disposed = true;
|
|
4074
|
+
};
|
|
4075
|
+
setLoading(true);
|
|
4076
|
+
request({ url, method: "get" }).then((response) => {
|
|
4077
|
+
if (!disposed) setPayload(unwrapFilePreviewPayload(response));
|
|
4078
|
+
}).catch((currentError) => {
|
|
4079
|
+
if (!disposed) setError(currentError?.message || "\u6587\u4EF6\u9884\u89C8\u5185\u5BB9\u52A0\u8F7D\u5931\u8D25");
|
|
4080
|
+
}).finally(() => {
|
|
4081
|
+
if (!disposed) setLoading(false);
|
|
4082
|
+
});
|
|
4083
|
+
return () => {
|
|
4084
|
+
disposed = true;
|
|
4085
|
+
};
|
|
4086
|
+
}, [reloadKey, request, url]);
|
|
4087
|
+
if (loading) {
|
|
4088
|
+
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..." }) });
|
|
4089
|
+
}
|
|
4090
|
+
if (error) {
|
|
4091
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4092
|
+
import_antd2.Alert,
|
|
4093
|
+
{
|
|
4094
|
+
type: "error",
|
|
4095
|
+
showIcon: true,
|
|
4096
|
+
title: error,
|
|
4097
|
+
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" })
|
|
4098
|
+
}
|
|
4099
|
+
) });
|
|
4100
|
+
}
|
|
4101
|
+
if (mode === "excel") {
|
|
4102
|
+
const sheets = Array.isArray(payload?.sheets) ? payload.sheets : [];
|
|
4103
|
+
if (!sheets.length) {
|
|
4104
|
+
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" }) });
|
|
4105
|
+
}
|
|
4106
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4107
|
+
import_antd2.Tabs,
|
|
4108
|
+
{
|
|
4109
|
+
style: { height: "100%", padding: "0 16px" },
|
|
4110
|
+
items: sheets.map((sheet) => {
|
|
4111
|
+
const table = buildRowsTable(sheet.rows || []);
|
|
4112
|
+
return {
|
|
4113
|
+
key: String(sheet.id || sheet.name),
|
|
4114
|
+
label: sheet.name || "Sheet",
|
|
4115
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
|
|
4116
|
+
sheet.truncatedRows || sheet.truncatedColumns ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4117
|
+
import_antd2.Alert,
|
|
4118
|
+
{
|
|
4119
|
+
type: "info",
|
|
4120
|
+
showIcon: true,
|
|
4121
|
+
title: `\u5DE5\u4F5C\u8868\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D ${payload.maxRows || 200} \u884C\u3001${payload.maxColumns || 60} \u5217\u3002`
|
|
4122
|
+
}
|
|
4123
|
+
) : null,
|
|
4124
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4125
|
+
import_antd2.Table,
|
|
4126
|
+
{
|
|
4127
|
+
bordered: true,
|
|
4128
|
+
size: "small",
|
|
4129
|
+
pagination: false,
|
|
4130
|
+
scroll: { x: "max-content", y: "min(66vh, 680px)" },
|
|
4131
|
+
columns: table.columns,
|
|
4132
|
+
dataSource: table.dataSource
|
|
4133
|
+
}
|
|
4134
|
+
)
|
|
4135
|
+
] })
|
|
4136
|
+
};
|
|
4137
|
+
})
|
|
4138
|
+
}
|
|
4139
|
+
);
|
|
4140
|
+
}
|
|
4141
|
+
const text = String(payload?.text || "");
|
|
4142
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { height: "100%", overflow: "auto", background: "#fff" }, children: [
|
|
4143
|
+
payload?.truncated ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4144
|
+
import_antd2.Alert,
|
|
4145
|
+
{
|
|
4146
|
+
type: "info",
|
|
4147
|
+
showIcon: true,
|
|
4148
|
+
banner: true,
|
|
4149
|
+
title: "\u6587\u4EF6\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D\u90E8\u5185\u5BB9\uFF1B\u5B8C\u6574\u5185\u5BB9\u8BF7\u4E0B\u8F7D\u67E5\u770B\u3002"
|
|
4150
|
+
}
|
|
4151
|
+
) : null,
|
|
4152
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4153
|
+
"pre",
|
|
4154
|
+
{
|
|
4155
|
+
style: {
|
|
4156
|
+
minHeight: 280,
|
|
4157
|
+
margin: 0,
|
|
4158
|
+
padding: 20,
|
|
4159
|
+
color: "#1f2328",
|
|
4160
|
+
background: "#fff",
|
|
4161
|
+
fontSize: 13,
|
|
4162
|
+
lineHeight: 1.7,
|
|
4163
|
+
whiteSpace: "pre-wrap",
|
|
4164
|
+
wordBreak: "break-word",
|
|
4165
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace'
|
|
4166
|
+
},
|
|
4167
|
+
children: text || "\u6682\u65E0\u6587\u672C\u5185\u5BB9"
|
|
4168
|
+
}
|
|
4169
|
+
)
|
|
4170
|
+
] });
|
|
4171
|
+
};
|
|
4172
|
+
var ClientTextPreview = ({
|
|
4173
|
+
request,
|
|
4174
|
+
url
|
|
4175
|
+
}) => {
|
|
4176
|
+
const [payload, setPayload] = (0, import_react7.useState)(null);
|
|
4177
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4178
|
+
(0, import_react7.useEffect)(() => {
|
|
4179
|
+
let disposed = false;
|
|
4180
|
+
let textLimit = 1024 * 1024;
|
|
4181
|
+
loadPreviewBlob(request, url).then(async (blob) => {
|
|
4182
|
+
const slice = blob.size > textLimit ? blob.slice(0, textLimit) : blob;
|
|
4183
|
+
const text = await slice.text();
|
|
4184
|
+
if (!disposed) setPayload({ text, truncated: blob.size > textLimit });
|
|
4185
|
+
}).catch((currentError) => {
|
|
4186
|
+
if (!disposed) setError(currentError?.message || "\u6587\u672C\u8BFB\u53D6\u5931\u8D25");
|
|
4187
|
+
});
|
|
4188
|
+
return () => {
|
|
4189
|
+
disposed = true;
|
|
4190
|
+
textLimit = 0;
|
|
4191
|
+
};
|
|
4192
|
+
}, [request, url]);
|
|
4193
|
+
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 }) });
|
|
4194
|
+
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..." }) });
|
|
4195
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { height: "100%", overflow: "auto", background: "#fff" }, children: [
|
|
4196
|
+
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,
|
|
4197
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4198
|
+
"pre",
|
|
4199
|
+
{
|
|
4200
|
+
style: {
|
|
4201
|
+
margin: 0,
|
|
4202
|
+
padding: 20,
|
|
4203
|
+
whiteSpace: "pre-wrap",
|
|
4204
|
+
wordBreak: "break-word",
|
|
4205
|
+
fontSize: 13,
|
|
4206
|
+
lineHeight: 1.7
|
|
4207
|
+
},
|
|
4208
|
+
children: payload.text || "\u6682\u65E0\u6587\u672C\u5185\u5BB9"
|
|
4209
|
+
}
|
|
4210
|
+
)
|
|
4211
|
+
] });
|
|
4212
|
+
};
|
|
4213
|
+
var DocxPreview = ({ request, url }) => {
|
|
4214
|
+
const containerRef = (0, import_react7.useRef)(null);
|
|
4215
|
+
const [loading, setLoading] = (0, import_react7.useState)(true);
|
|
4216
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4217
|
+
(0, import_react7.useEffect)(() => {
|
|
4218
|
+
let disposed = false;
|
|
4219
|
+
const container = containerRef.current;
|
|
4220
|
+
if (!container || !url) return () => {
|
|
4221
|
+
disposed = true;
|
|
4222
|
+
};
|
|
4223
|
+
container.innerHTML = "";
|
|
4224
|
+
setLoading(true);
|
|
4225
|
+
setError("");
|
|
4226
|
+
(async () => {
|
|
4227
|
+
try {
|
|
4228
|
+
const blob = await loadPreviewBlob(request, url);
|
|
4229
|
+
const { renderAsync } = await import("docx-preview");
|
|
4230
|
+
if (disposed || !containerRef.current) return;
|
|
4231
|
+
await renderAsync(blob, containerRef.current, containerRef.current, {
|
|
4232
|
+
className: "sy-docx-preview",
|
|
4233
|
+
inWrapper: true,
|
|
4234
|
+
breakPages: true,
|
|
4235
|
+
ignoreLastRenderedPageBreak: false,
|
|
4236
|
+
renderHeaders: true,
|
|
4237
|
+
renderFooters: true,
|
|
4238
|
+
renderFootnotes: true,
|
|
4239
|
+
renderEndnotes: true,
|
|
4240
|
+
useBase64URL: false
|
|
4241
|
+
});
|
|
4242
|
+
} catch (currentError) {
|
|
4243
|
+
if (!disposed) setError(currentError?.message || "Word \u6587\u6863\u89E3\u6790\u5931\u8D25");
|
|
4244
|
+
} finally {
|
|
4245
|
+
if (!disposed) setLoading(false);
|
|
4246
|
+
}
|
|
4247
|
+
})();
|
|
4248
|
+
return () => {
|
|
4249
|
+
disposed = true;
|
|
4250
|
+
if (container) container.innerHTML = "";
|
|
4251
|
+
};
|
|
4252
|
+
}, [request, url]);
|
|
4253
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
4254
|
+
"div",
|
|
4255
|
+
{
|
|
4256
|
+
style: {
|
|
4257
|
+
minHeight: 360,
|
|
4258
|
+
height: "100%",
|
|
4259
|
+
overflow: "auto",
|
|
4260
|
+
position: "relative",
|
|
4261
|
+
background: "#e9edf2"
|
|
4262
|
+
},
|
|
4263
|
+
children: [
|
|
4264
|
+
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,
|
|
4265
|
+
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,
|
|
4266
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { ref: containerRef, style: { display: loading || error ? "none" : "block" } })
|
|
4267
|
+
]
|
|
4268
|
+
}
|
|
4269
|
+
);
|
|
4270
|
+
};
|
|
4271
|
+
var HeicImagePreview = ({
|
|
4272
|
+
request,
|
|
4273
|
+
url,
|
|
4274
|
+
fileName
|
|
4275
|
+
}) => {
|
|
4276
|
+
const [src, setSrc] = (0, import_react7.useState)("");
|
|
4277
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4278
|
+
(0, import_react7.useEffect)(() => {
|
|
4279
|
+
let disposed = false;
|
|
4280
|
+
let objectUrl = "";
|
|
4281
|
+
convertHeicPreview(request, url).then((result) => {
|
|
4282
|
+
objectUrl = result;
|
|
4283
|
+
if (!disposed) setSrc(result);
|
|
4284
|
+
}).catch((currentError) => {
|
|
4285
|
+
if (!disposed) setError(currentError?.message || "HEIC \u56FE\u7247\u8F6C\u6362\u5931\u8D25");
|
|
4286
|
+
});
|
|
4287
|
+
return () => {
|
|
4288
|
+
disposed = true;
|
|
4289
|
+
if (objectUrl) URL.revokeObjectURL?.(objectUrl);
|
|
4290
|
+
};
|
|
4291
|
+
}, [request, url]);
|
|
4292
|
+
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 }) });
|
|
4293
|
+
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..." }) });
|
|
4294
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { minHeight: 320, textAlign: "center", padding: 20, background: "#f3f5f7" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4295
|
+
import_antd2.Image,
|
|
4296
|
+
{
|
|
4297
|
+
src,
|
|
4298
|
+
alt: fileName || "HEIC \u56FE\u7247\u9884\u89C8",
|
|
4299
|
+
style: { maxWidth: "100%", maxHeight: "72vh", objectFit: "contain" }
|
|
4300
|
+
}
|
|
4301
|
+
) });
|
|
4302
|
+
};
|
|
4303
|
+
var ClientSpreadsheetPreview = ({
|
|
4304
|
+
request,
|
|
4305
|
+
url
|
|
4306
|
+
}) => {
|
|
4307
|
+
const [payload, setPayload] = (0, import_react7.useState)(null);
|
|
4308
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4309
|
+
(0, import_react7.useEffect)(() => {
|
|
4310
|
+
let disposed = false;
|
|
4311
|
+
(async () => {
|
|
4312
|
+
try {
|
|
4313
|
+
const blob = await loadPreviewBlob(request, url);
|
|
4314
|
+
const XLSX = await import("xlsx");
|
|
4315
|
+
const workbook = XLSX.read(await blob.arrayBuffer(), {
|
|
4316
|
+
cellDates: true,
|
|
4317
|
+
dense: true
|
|
4318
|
+
});
|
|
4319
|
+
const maxRows = 500;
|
|
4320
|
+
const maxColumns = 100;
|
|
4321
|
+
const sheets = workbook.SheetNames.map((name, index) => {
|
|
4322
|
+
const allRows = XLSX.utils.sheet_to_json(workbook.Sheets[name], {
|
|
4323
|
+
header: 1,
|
|
4324
|
+
defval: "",
|
|
4325
|
+
raw: false
|
|
4326
|
+
});
|
|
4327
|
+
const columnCount = allRows.reduce(
|
|
4328
|
+
(count, row) => Math.max(count, Array.isArray(row) ? row.length : 0),
|
|
4329
|
+
0
|
|
4330
|
+
);
|
|
4331
|
+
return {
|
|
4332
|
+
id: index,
|
|
4333
|
+
name,
|
|
4334
|
+
rows: allRows.slice(0, maxRows).map(
|
|
4335
|
+
(row) => (Array.isArray(row) ? row : []).slice(0, maxColumns)
|
|
4336
|
+
),
|
|
4337
|
+
truncatedRows: allRows.length > maxRows,
|
|
4338
|
+
truncatedColumns: columnCount > maxColumns
|
|
4339
|
+
};
|
|
4340
|
+
});
|
|
4341
|
+
if (!disposed) setPayload({ sheets, maxRows, maxColumns });
|
|
4342
|
+
} catch (currentError) {
|
|
4343
|
+
if (!disposed) setError(currentError?.message || "Excel \u6587\u4EF6\u89E3\u6790\u5931\u8D25");
|
|
4344
|
+
}
|
|
4345
|
+
})();
|
|
4346
|
+
return () => {
|
|
4347
|
+
disposed = true;
|
|
4348
|
+
};
|
|
4349
|
+
}, [request, url]);
|
|
4350
|
+
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 }) });
|
|
4351
|
+
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..." }) });
|
|
4352
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(PayloadPreviewFromValue, { payload });
|
|
4353
|
+
};
|
|
4354
|
+
var PayloadPreviewFromValue = ({ payload }) => {
|
|
4355
|
+
const sheets = Array.isArray(payload?.sheets) ? payload.sheets : [];
|
|
4356
|
+
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" }) });
|
|
4357
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4358
|
+
import_antd2.Tabs,
|
|
4359
|
+
{
|
|
4360
|
+
style: { height: "100%", padding: "0 16px" },
|
|
4361
|
+
items: sheets.map((sheet) => {
|
|
4362
|
+
const table = buildRowsTable(sheet.rows || []);
|
|
4363
|
+
return {
|
|
4364
|
+
key: String(sheet.id ?? sheet.name),
|
|
4365
|
+
label: sheet.name || "Sheet",
|
|
4366
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
|
|
4367
|
+
sheet.truncatedRows || sheet.truncatedColumns ? /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4368
|
+
import_antd2.Alert,
|
|
4369
|
+
{
|
|
4370
|
+
type: "info",
|
|
4371
|
+
showIcon: true,
|
|
4372
|
+
title: `\u5DE5\u4F5C\u8868\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D ${payload.maxRows} \u884C\u3001${payload.maxColumns} \u5217\u3002`
|
|
4373
|
+
}
|
|
4374
|
+
) : null,
|
|
4375
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4376
|
+
import_antd2.Table,
|
|
4377
|
+
{
|
|
4378
|
+
bordered: true,
|
|
4379
|
+
size: "small",
|
|
4380
|
+
pagination: false,
|
|
4381
|
+
scroll: { x: "max-content", y: "min(66vh, 680px)" },
|
|
4382
|
+
columns: table.columns,
|
|
4383
|
+
dataSource: table.dataSource
|
|
4384
|
+
}
|
|
4385
|
+
)
|
|
4386
|
+
] })
|
|
4387
|
+
};
|
|
4388
|
+
})
|
|
4389
|
+
}
|
|
4390
|
+
);
|
|
4391
|
+
};
|
|
4392
|
+
var scriptPromises = /* @__PURE__ */ new Map();
|
|
4393
|
+
var loadScriptOnce = (src) => {
|
|
4394
|
+
const existingPromise = scriptPromises.get(src);
|
|
4395
|
+
if (existingPromise) return existingPromise;
|
|
4396
|
+
const promise = new Promise((resolve, reject) => {
|
|
4397
|
+
if (!src || typeof document === "undefined") {
|
|
4398
|
+
reject(new Error("ONLYOFFICE \u811A\u672C\u5730\u5740\u4E0D\u53EF\u7528"));
|
|
4399
|
+
return;
|
|
4400
|
+
}
|
|
4401
|
+
const existed = document.querySelector(`script[src="${src}"]`);
|
|
4402
|
+
if (existed?.dataset.loaded === "true") {
|
|
4403
|
+
resolve();
|
|
4404
|
+
return;
|
|
4405
|
+
}
|
|
4406
|
+
const script = existed || document.createElement("script");
|
|
4407
|
+
script.src = src;
|
|
4408
|
+
script.async = true;
|
|
4409
|
+
script.onload = () => {
|
|
4410
|
+
script.dataset.loaded = "true";
|
|
4411
|
+
resolve();
|
|
4412
|
+
};
|
|
4413
|
+
script.onerror = () => reject(new Error("ONLYOFFICE \u811A\u672C\u52A0\u8F7D\u5931\u8D25"));
|
|
4414
|
+
if (!existed) document.body.appendChild(script);
|
|
4415
|
+
});
|
|
4416
|
+
scriptPromises.set(src, promise);
|
|
4417
|
+
promise.catch(() => scriptPromises.delete(src));
|
|
4418
|
+
return promise;
|
|
4419
|
+
};
|
|
4420
|
+
var OnlyOfficePreview = ({
|
|
4421
|
+
request,
|
|
4422
|
+
configUrl,
|
|
4423
|
+
ticket
|
|
4424
|
+
}) => {
|
|
4425
|
+
const editorId = (0, import_react7.useMemo)(
|
|
4426
|
+
() => `openxiangda-onlyoffice-${String(ticket || "editor").replace(/[^a-zA-Z0-9_-]/g, "")}`,
|
|
4427
|
+
[ticket]
|
|
4428
|
+
);
|
|
4429
|
+
const [loading, setLoading] = (0, import_react7.useState)(true);
|
|
4430
|
+
const [error, setError] = (0, import_react7.useState)("");
|
|
4431
|
+
(0, import_react7.useEffect)(() => {
|
|
4432
|
+
let disposed = false;
|
|
4433
|
+
let editor;
|
|
4434
|
+
setLoading(true);
|
|
4435
|
+
setError("");
|
|
4436
|
+
(async () => {
|
|
4437
|
+
try {
|
|
4438
|
+
const response = await request({ url: configUrl, method: "get" });
|
|
4439
|
+
const payload = unwrapFilePreviewPayload(response);
|
|
4440
|
+
const scriptUrl = `${String(payload?.documentServerUrl || "").replace(
|
|
4441
|
+
/\/+$/,
|
|
4442
|
+
""
|
|
4443
|
+
)}/web-apps/apps/api/documents/api.js`;
|
|
4444
|
+
await loadScriptOnce(scriptUrl);
|
|
4445
|
+
if (!disposed && window.DocsAPI?.DocEditor) {
|
|
4446
|
+
editor = new window.DocsAPI.DocEditor(editorId, payload.config);
|
|
4447
|
+
}
|
|
4448
|
+
} catch (currentError) {
|
|
4449
|
+
if (!disposed) setError(currentError?.message || "ONLYOFFICE \u9884\u89C8\u52A0\u8F7D\u5931\u8D25");
|
|
4450
|
+
} finally {
|
|
4451
|
+
if (!disposed) setLoading(false);
|
|
4452
|
+
}
|
|
4453
|
+
})();
|
|
4454
|
+
return () => {
|
|
4455
|
+
disposed = true;
|
|
4456
|
+
editor?.destroyEditor?.();
|
|
4457
|
+
};
|
|
4458
|
+
}, [configUrl, editorId, request]);
|
|
4459
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { style: { height: "100%", minHeight: 420, position: "relative", background: "#fff" }, children: [
|
|
4460
|
+
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,
|
|
4461
|
+
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,
|
|
4462
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { id: editorId, style: { height: "100%", minHeight: 420, display: error ? "none" : "block" } })
|
|
4463
|
+
] });
|
|
4464
|
+
};
|
|
4465
|
+
var FilePreviewContent = ({
|
|
4466
|
+
metadata,
|
|
4467
|
+
request,
|
|
4468
|
+
servicePrefix = "/service",
|
|
4469
|
+
onDownload
|
|
4470
|
+
}) => {
|
|
4471
|
+
const renderMode = metadata.renderMode || "download";
|
|
4472
|
+
const previewUrl = resolvePreviewServiceUrl(metadata.previewUrl, servicePrefix);
|
|
4473
|
+
const imageUrl = resolvePreviewServiceUrl(
|
|
4474
|
+
renderMode === "image-transcode" ? metadata.imagePreviewUrl : metadata.previewUrl,
|
|
4475
|
+
servicePrefix
|
|
4476
|
+
);
|
|
4477
|
+
if (renderMode === "inline" && metadata.previewType === "image") {
|
|
4478
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4479
|
+
"div",
|
|
4480
|
+
{
|
|
4481
|
+
style: {
|
|
4482
|
+
height: "100%",
|
|
4483
|
+
minHeight: 320,
|
|
4484
|
+
display: "flex",
|
|
4485
|
+
alignItems: "center",
|
|
4486
|
+
justifyContent: "center",
|
|
4487
|
+
overflow: "auto",
|
|
4488
|
+
padding: 20,
|
|
4489
|
+
background: "#f3f5f7"
|
|
4490
|
+
},
|
|
4491
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4492
|
+
import_antd2.Image,
|
|
4493
|
+
{
|
|
4494
|
+
src: imageUrl,
|
|
4495
|
+
alt: metadata.fileName || "\u56FE\u7247\u9884\u89C8",
|
|
4496
|
+
style: { maxWidth: "100%", maxHeight: "72vh", objectFit: "contain" }
|
|
4497
|
+
}
|
|
4498
|
+
)
|
|
4499
|
+
}
|
|
4500
|
+
);
|
|
4501
|
+
}
|
|
4502
|
+
if (renderMode === "image-transcode") {
|
|
4503
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { style: { minHeight: 320, textAlign: "center", padding: 20, background: "#f3f5f7" }, children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4504
|
+
import_antd2.Image,
|
|
4505
|
+
{
|
|
4506
|
+
src: imageUrl,
|
|
4507
|
+
alt: metadata.fileName || "\u56FE\u7247\u9884\u89C8",
|
|
4508
|
+
style: { maxWidth: "100%", maxHeight: "72vh", objectFit: "contain" }
|
|
4509
|
+
}
|
|
4510
|
+
) });
|
|
4511
|
+
}
|
|
4512
|
+
if (renderMode === "image-heic") {
|
|
4513
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4514
|
+
HeicImagePreview,
|
|
4515
|
+
{
|
|
4516
|
+
request,
|
|
4517
|
+
url: previewUrl,
|
|
4518
|
+
fileName: metadata.fileName
|
|
4519
|
+
}
|
|
4520
|
+
);
|
|
4521
|
+
}
|
|
4522
|
+
if (renderMode === "inline" && metadata.previewType === "video") {
|
|
4523
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4524
|
+
"div",
|
|
4525
|
+
{
|
|
4526
|
+
style: {
|
|
4527
|
+
height: "100%",
|
|
4528
|
+
minHeight: 320,
|
|
4529
|
+
display: "flex",
|
|
4530
|
+
alignItems: "center",
|
|
4531
|
+
background: "#080a0d"
|
|
4532
|
+
},
|
|
4533
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4534
|
+
"video",
|
|
4535
|
+
{
|
|
4536
|
+
controls: true,
|
|
4537
|
+
playsInline: true,
|
|
4538
|
+
preload: "metadata",
|
|
4539
|
+
src: previewUrl,
|
|
4540
|
+
style: { width: "100%", maxHeight: "76vh" },
|
|
4541
|
+
children: "\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u89C6\u9891\u64AD\u653E\u3002"
|
|
4542
|
+
}
|
|
4543
|
+
)
|
|
4544
|
+
}
|
|
4545
|
+
);
|
|
4546
|
+
}
|
|
4547
|
+
if (renderMode === "inline" && metadata.previewType === "audio") {
|
|
4548
|
+
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" }) });
|
|
4549
|
+
}
|
|
4550
|
+
if (renderMode === "pdfjs") {
|
|
4551
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4552
|
+
"iframe",
|
|
4553
|
+
{
|
|
4554
|
+
title: metadata.fileName || "PDF \u9884\u89C8",
|
|
4555
|
+
src: previewUrl,
|
|
4556
|
+
style: { width: "100%", height: "100%", minHeight: 520, border: 0, background: "#fff" }
|
|
4557
|
+
}
|
|
4558
|
+
);
|
|
4559
|
+
}
|
|
4560
|
+
if (renderMode === "docx-html") {
|
|
4561
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(DocxPreview, { request, url: previewUrl });
|
|
4562
|
+
}
|
|
4563
|
+
if (renderMode === "excel-client") {
|
|
4564
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ClientSpreadsheetPreview, { request, url: previewUrl });
|
|
4565
|
+
}
|
|
4566
|
+
if (renderMode === "excel-basic") {
|
|
4567
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4568
|
+
PayloadPreview,
|
|
4569
|
+
{
|
|
4570
|
+
request,
|
|
4571
|
+
url: metadata.excelPreviewUrl || "",
|
|
4572
|
+
mode: "excel"
|
|
4573
|
+
}
|
|
4574
|
+
);
|
|
4575
|
+
}
|
|
4576
|
+
if (renderMode === "text-client") {
|
|
4577
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ClientTextPreview, { request, url: previewUrl });
|
|
4578
|
+
}
|
|
4579
|
+
if (renderMode === "text" || renderMode === "office-text") {
|
|
4580
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4581
|
+
PayloadPreview,
|
|
4582
|
+
{
|
|
4583
|
+
request,
|
|
4584
|
+
url: renderMode === "office-text" ? metadata.officeTextPreviewUrl || "" : metadata.textPreviewUrl || "",
|
|
4585
|
+
mode: "text"
|
|
4586
|
+
}
|
|
4587
|
+
);
|
|
4588
|
+
}
|
|
4589
|
+
if (renderMode === "onlyoffice") {
|
|
4590
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4591
|
+
OnlyOfficePreview,
|
|
4592
|
+
{
|
|
4593
|
+
request,
|
|
4594
|
+
configUrl: metadata.onlyofficeConfigUrl || `/file/onlyoffice/config/${encodeURIComponent(metadata.ticket || "")}`,
|
|
4595
|
+
ticket: metadata.ticket
|
|
4596
|
+
}
|
|
4597
|
+
);
|
|
4598
|
+
}
|
|
4599
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(CenteredState, { children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
4600
|
+
import_antd2.Empty,
|
|
4601
|
+
{
|
|
4602
|
+
image: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_icons.FileOutlined, { style: { fontSize: 52, color: "#8c8c8c" } }),
|
|
4603
|
+
description: /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { children: [
|
|
4604
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_antd2.Typography.Text, { strong: true, children: "\u5F53\u524D\u6587\u4EF6\u65E0\u6CD5\u5728\u7EBF\u9884\u89C8" }),
|
|
4605
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("br", {}),
|
|
4606
|
+
/* @__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" })
|
|
4607
|
+
] }),
|
|
4608
|
+
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
|
|
4609
|
+
}
|
|
4610
|
+
) });
|
|
4611
|
+
};
|
|
4612
|
+
|
|
4613
|
+
// packages/sdk/src/components/file-preview/FilePreviewPage.tsx
|
|
4614
|
+
var import_react8 = require("react");
|
|
4615
|
+
var import_antd3 = require("antd");
|
|
4616
|
+
var import_icons2 = require("@ant-design/icons");
|
|
4617
|
+
var import_jsx_runtime4 = require("react/jsx-runtime");
|
|
4618
|
+
|
|
4619
|
+
// packages/sdk/src/components/file-preview/useFilePreview.tsx
|
|
4620
|
+
var import_react9 = require("react");
|
|
4621
|
+
var import_antd4 = require("antd");
|
|
4622
|
+
var import_icons3 = require("@ant-design/icons");
|
|
4623
|
+
var import_jsx_runtime5 = require("react/jsx-runtime");
|
|
4624
|
+
var canActOnItem = (item) => item.status !== "uploading" && item.status !== "error";
|
|
4625
|
+
var revokeImageItems = (items) => {
|
|
4626
|
+
items.forEach((item) => {
|
|
4627
|
+
if (item.revokeOnClose && item.src.startsWith("blob:")) {
|
|
4628
|
+
URL.revokeObjectURL?.(item.src);
|
|
4629
|
+
}
|
|
4630
|
+
});
|
|
4631
|
+
};
|
|
4632
|
+
var buildCapabilityMap = (items, requireServerCapability) => {
|
|
4633
|
+
const result = {};
|
|
4634
|
+
items.forEach((item, index) => {
|
|
4635
|
+
const key = getPreviewItemKey(item, index);
|
|
4636
|
+
const local = resolveLocalPreviewCapability(item);
|
|
4637
|
+
result[key] = requireServerCapability && item.objectName && !isDirectStorageItem(item) ? { ...local, canPreview: false } : local;
|
|
4638
|
+
});
|
|
4639
|
+
return result;
|
|
4640
|
+
};
|
|
4641
|
+
var useFilePreviewController = ({
|
|
4642
|
+
items,
|
|
4643
|
+
api,
|
|
4644
|
+
appType,
|
|
4645
|
+
bucketName,
|
|
4646
|
+
enabled = true,
|
|
4647
|
+
requireServerCapability = true
|
|
4648
|
+
}) => {
|
|
4649
|
+
const itemSignature = (0, import_react9.useMemo)(
|
|
4650
|
+
() => items.map(
|
|
4651
|
+
(item, index) => [
|
|
4652
|
+
getPreviewItemKey(item, index),
|
|
4653
|
+
item.name,
|
|
4654
|
+
item.objectName,
|
|
4655
|
+
item.contentType,
|
|
4656
|
+
item.size,
|
|
4657
|
+
item.status
|
|
4658
|
+
].join(":")
|
|
4659
|
+
).join("|"),
|
|
4660
|
+
[items]
|
|
4661
|
+
);
|
|
4662
|
+
const [capabilities, setCapabilities] = (0, import_react9.useState)(
|
|
4663
|
+
() => buildCapabilityMap(items, requireServerCapability)
|
|
4664
|
+
);
|
|
4665
|
+
const [openingKey, setOpeningKey] = (0, import_react9.useState)("");
|
|
4666
|
+
const [dialogPreview, setDialogPreview] = (0, import_react9.useState)(null);
|
|
4667
|
+
const [imagePreview, setImagePreview] = (0, import_react9.useState)({
|
|
4668
|
+
open: false,
|
|
4669
|
+
current: 0,
|
|
4670
|
+
items: []
|
|
4671
|
+
});
|
|
4672
|
+
(0, import_react9.useEffect)(() => {
|
|
4673
|
+
let disposed = false;
|
|
4674
|
+
const initial = buildCapabilityMap(items, requireServerCapability);
|
|
4675
|
+
setCapabilities(initial);
|
|
4676
|
+
if (!enabled || !requireServerCapability) return () => {
|
|
4677
|
+
disposed = true;
|
|
4678
|
+
};
|
|
4679
|
+
const protectedItems = items.map((item, index) => ({ item, key: getPreviewItemKey(item, index) })).filter(
|
|
4680
|
+
({ item }) => canActOnItem(item) && Boolean(item.objectName) && !isDirectStorageItem(item)
|
|
4681
|
+
);
|
|
4682
|
+
if (!protectedItems.length) return () => {
|
|
4683
|
+
disposed = true;
|
|
4684
|
+
};
|
|
4685
|
+
api.request({
|
|
4686
|
+
url: "/file/preview-capabilities",
|
|
4687
|
+
method: "post",
|
|
4688
|
+
data: {
|
|
4689
|
+
files: protectedItems.map(({ item, key }) => ({
|
|
4690
|
+
key,
|
|
4691
|
+
fileName: item.name,
|
|
4692
|
+
objectName: item.objectName,
|
|
4693
|
+
contentType: item.contentType || item.mimeType,
|
|
4694
|
+
size: item.size
|
|
4695
|
+
}))
|
|
4696
|
+
}
|
|
4697
|
+
}).then((response) => {
|
|
4698
|
+
if (disposed) return;
|
|
4699
|
+
const payload = unwrapFilePreviewPayload(response);
|
|
4700
|
+
const next = { ...initial };
|
|
4701
|
+
(payload?.items || []).forEach((capability) => {
|
|
4702
|
+
if (capability.key) next[capability.key] = capability;
|
|
4703
|
+
});
|
|
4704
|
+
setCapabilities(next);
|
|
4705
|
+
}).catch(() => {
|
|
4706
|
+
if (disposed) return;
|
|
4707
|
+
const fallback = { ...initial };
|
|
4708
|
+
protectedItems.forEach(({ item, key }) => {
|
|
4709
|
+
fallback[key] = resolveLocalPreviewCapability(item);
|
|
4710
|
+
});
|
|
4711
|
+
setCapabilities(fallback);
|
|
4712
|
+
});
|
|
4713
|
+
return () => {
|
|
4714
|
+
disposed = true;
|
|
4715
|
+
};
|
|
4716
|
+
}, [api, enabled, itemSignature, requireServerCapability]);
|
|
4717
|
+
const getCapability = (0, import_react9.useCallback)(
|
|
4718
|
+
(item) => {
|
|
4719
|
+
const index = items.indexOf(item);
|
|
4720
|
+
return capabilities[getPreviewItemKey(item, Math.max(index, 0))];
|
|
4721
|
+
},
|
|
4722
|
+
[capabilities, items]
|
|
4723
|
+
);
|
|
4724
|
+
const canPreview = (0, import_react9.useCallback)(
|
|
4725
|
+
(item) => enabled && canActOnItem(item) && getCapability(item)?.canPreview === true,
|
|
4726
|
+
[enabled, getCapability]
|
|
4727
|
+
);
|
|
4728
|
+
const closeImagePreview = (0, import_react9.useCallback)(() => {
|
|
4729
|
+
setImagePreview((current) => {
|
|
4730
|
+
revokeImageItems(current.items);
|
|
4731
|
+
return { open: false, current: 0, items: [] };
|
|
4732
|
+
});
|
|
4733
|
+
}, []);
|
|
4734
|
+
(0, import_react9.useEffect)(
|
|
4735
|
+
() => () => revokeImageItems(imagePreview.items),
|
|
4736
|
+
[imagePreview.items]
|
|
4737
|
+
);
|
|
4738
|
+
const resolvePreparedImageItem = (0, import_react9.useCallback)(
|
|
4739
|
+
async (prepared, index) => {
|
|
4740
|
+
const item = prepared.item;
|
|
4741
|
+
const metadata = prepared.metadata;
|
|
4742
|
+
let src = resolvePreviewServiceUrl(
|
|
4743
|
+
metadata.renderMode === "image-transcode" ? metadata.imagePreviewUrl : metadata.previewUrl
|
|
4744
|
+
);
|
|
4745
|
+
let revokeOnClose = false;
|
|
4746
|
+
if (metadata.renderMode === "image-heic") {
|
|
4747
|
+
src = await convertHeicPreview(api.request, src);
|
|
4748
|
+
revokeOnClose = true;
|
|
4749
|
+
}
|
|
4750
|
+
if (!src) throw new Error(`${item.name || "\u56FE\u7247"}\u6CA1\u6709\u53EF\u7528\u7684\u9884\u89C8\u5730\u5740`);
|
|
4751
|
+
return {
|
|
4752
|
+
key: getPreviewItemKey(item, index),
|
|
4753
|
+
src,
|
|
4754
|
+
name: metadata.fileName || item.name,
|
|
4755
|
+
revokeOnClose
|
|
4756
|
+
};
|
|
4757
|
+
},
|
|
4758
|
+
[api]
|
|
4759
|
+
);
|
|
4760
|
+
const prepareImageItem = (0, import_react9.useCallback)(
|
|
4761
|
+
async (item, index) => {
|
|
4762
|
+
const prepared = await prepareFilePreview({ item, api, appType, bucketName });
|
|
4763
|
+
return resolvePreparedImageItem(prepared, index);
|
|
4764
|
+
},
|
|
4765
|
+
[api, appType, bucketName, resolvePreparedImageItem]
|
|
4766
|
+
);
|
|
4767
|
+
const openPreview = (0, import_react9.useCallback)(
|
|
4768
|
+
async (item) => {
|
|
4769
|
+
const itemIndex = Math.max(items.indexOf(item), 0);
|
|
4770
|
+
const key = getPreviewItemKey(item, itemIndex);
|
|
4771
|
+
setOpeningKey(key);
|
|
4772
|
+
try {
|
|
4773
|
+
const prepared = await prepareFilePreview({ item, api, appType, bucketName });
|
|
4774
|
+
if (prepared.metadata.canPreview === false || prepared.metadata.renderMode === "download") {
|
|
4775
|
+
setDialogPreview(prepared);
|
|
4776
|
+
return;
|
|
4777
|
+
}
|
|
4778
|
+
if (prepared.metadata.previewType === "image") {
|
|
4779
|
+
const galleryCandidates = items.map((candidate, index) => ({ candidate, index })).filter(({ candidate }) => {
|
|
4780
|
+
const capability = getCapability(candidate) || resolveLocalPreviewCapability(candidate);
|
|
4781
|
+
return canActOnItem(candidate) && capability.canPreview && capability.previewType === "image";
|
|
4782
|
+
});
|
|
4783
|
+
const results = await Promise.allSettled(
|
|
4784
|
+
galleryCandidates.map(
|
|
4785
|
+
({ candidate, index }) => candidate === item ? resolvePreparedImageItem(prepared, index) : prepareImageItem(candidate, index)
|
|
4786
|
+
)
|
|
4787
|
+
);
|
|
4788
|
+
const gallery = results.flatMap(
|
|
4789
|
+
(result) => result.status === "fulfilled" ? [result.value] : []
|
|
4790
|
+
);
|
|
4791
|
+
if (!gallery.length || !gallery.some((image) => image.key === key)) {
|
|
4792
|
+
const fallback = await resolvePreparedImageItem(prepared, itemIndex);
|
|
4793
|
+
gallery.push(fallback);
|
|
4794
|
+
}
|
|
4795
|
+
const current = Math.max(0, gallery.findIndex((image) => image.key === key));
|
|
4796
|
+
closeImagePreview();
|
|
4797
|
+
setImagePreview({ open: true, current, items: gallery });
|
|
4798
|
+
return;
|
|
4799
|
+
}
|
|
4800
|
+
setDialogPreview(prepared);
|
|
4801
|
+
} catch (error) {
|
|
4802
|
+
setDialogPreview({
|
|
4803
|
+
item,
|
|
4804
|
+
direct: isDirectStorageItem(item),
|
|
4805
|
+
metadata: {
|
|
4806
|
+
...resolveLocalPreviewCapability(item),
|
|
4807
|
+
fileName: item.name,
|
|
4808
|
+
size: item.size,
|
|
4809
|
+
renderMode: "download",
|
|
4810
|
+
canPreview: false,
|
|
4811
|
+
unsupportedReason: error?.message || "\u6587\u4EF6\u9884\u89C8\u52A0\u8F7D\u5931\u8D25",
|
|
4812
|
+
downloadUrl: item.downloadUrl || item.publicUrl || item.url
|
|
4813
|
+
}
|
|
4814
|
+
});
|
|
4815
|
+
} finally {
|
|
4816
|
+
setOpeningKey("");
|
|
4817
|
+
}
|
|
4818
|
+
},
|
|
4819
|
+
[
|
|
4820
|
+
api,
|
|
4821
|
+
appType,
|
|
4822
|
+
bucketName,
|
|
4823
|
+
closeImagePreview,
|
|
4824
|
+
getCapability,
|
|
4825
|
+
items,
|
|
4826
|
+
prepareImageItem,
|
|
4827
|
+
resolvePreparedImageItem
|
|
4828
|
+
]
|
|
4829
|
+
);
|
|
4830
|
+
const downloadItem = (0, import_react9.useCallback)(
|
|
4831
|
+
async (item, prepared) => {
|
|
4832
|
+
let url = prepared?.metadata.downloadUrl || item.downloadUrl || item.publicUrl || item.url;
|
|
4833
|
+
if (!isDirectStorageItem(item) && item.objectName && !prepared?.metadata.downloadUrl) {
|
|
4834
|
+
const ticket = await api.createDownloadTicket(
|
|
4835
|
+
item.bucketName || bucketName,
|
|
4836
|
+
item.objectName,
|
|
4837
|
+
item.name
|
|
4838
|
+
);
|
|
4839
|
+
url = typeof ticket === "string" ? ticket : ticket?.downloadUrl || ticket?.relayUrl || ticket?.url || url;
|
|
4840
|
+
}
|
|
4841
|
+
if (url && typeof window !== "undefined") window.location.assign(url);
|
|
4842
|
+
},
|
|
4843
|
+
[api, bucketName]
|
|
4844
|
+
);
|
|
4845
|
+
const previewHost = imagePreview.open || dialogPreview ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_jsx_runtime5.Fragment, { children: [
|
|
4846
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4847
|
+
import_antd4.Image.PreviewGroup,
|
|
4848
|
+
{
|
|
4849
|
+
items: imagePreview.items.map((item) => ({ src: item.src, alt: item.name })),
|
|
4850
|
+
preview: {
|
|
4851
|
+
open: imagePreview.open,
|
|
4852
|
+
current: imagePreview.current,
|
|
4853
|
+
onChange: (current) => setImagePreview((value) => ({ ...value, current })),
|
|
4854
|
+
onOpenChange: (open) => {
|
|
4855
|
+
if (!open) closeImagePreview();
|
|
4856
|
+
},
|
|
4857
|
+
countRender: (current, total) => `${current}/${total}`
|
|
4858
|
+
},
|
|
4859
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)("span", { "aria-hidden": "true", style: { display: "none" } })
|
|
4860
|
+
}
|
|
4861
|
+
),
|
|
4862
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4863
|
+
FilePreviewDialog,
|
|
4864
|
+
{
|
|
4865
|
+
preview: dialogPreview,
|
|
4866
|
+
request: api.request,
|
|
4867
|
+
onClose: () => setDialogPreview(null),
|
|
4868
|
+
onDownload: () => {
|
|
4869
|
+
if (dialogPreview) void downloadItem(dialogPreview.item, dialogPreview);
|
|
4870
|
+
}
|
|
4871
|
+
}
|
|
4872
|
+
)
|
|
4873
|
+
] }) : null;
|
|
4874
|
+
return {
|
|
4875
|
+
canPreview,
|
|
4876
|
+
getCapability,
|
|
4877
|
+
openPreview,
|
|
4878
|
+
openingKey,
|
|
4879
|
+
isOpening: (item) => {
|
|
4880
|
+
const index = Math.max(items.indexOf(item), 0);
|
|
4881
|
+
return openingKey === getPreviewItemKey(item, index);
|
|
4882
|
+
},
|
|
4883
|
+
downloadItem,
|
|
4884
|
+
previewHost
|
|
4885
|
+
};
|
|
4886
|
+
};
|
|
4887
|
+
var FilePreviewDialog = ({
|
|
4888
|
+
preview,
|
|
4889
|
+
request,
|
|
4890
|
+
onClose,
|
|
4891
|
+
onDownload
|
|
4892
|
+
}) => {
|
|
4893
|
+
const metadata = preview?.metadata;
|
|
4894
|
+
const title = metadata?.fileName || preview?.item.name || "\u9644\u4EF6\u9884\u89C8";
|
|
4895
|
+
return /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4896
|
+
import_antd4.Modal,
|
|
4897
|
+
{
|
|
4898
|
+
open: Boolean(preview),
|
|
4899
|
+
title: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { minWidth: 0, paddingRight: 16 }, children: [
|
|
4900
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd4.Typography.Text, { strong: true, ellipsis: true, style: { display: "block" }, children: title }),
|
|
4901
|
+
metadata ? /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)(import_antd4.Typography.Text, { type: "secondary", style: { fontSize: 12 }, children: [
|
|
4902
|
+
(metadata.extension || "FILE").toUpperCase(),
|
|
4903
|
+
" \xB7 ",
|
|
4904
|
+
formatPreviewFileSize(metadata.size)
|
|
4905
|
+
] }) : null
|
|
4906
|
+
] }),
|
|
4907
|
+
width: "min(96vw, 1440px)",
|
|
4908
|
+
centered: true,
|
|
4909
|
+
destroyOnHidden: true,
|
|
4910
|
+
mask: { closable: false },
|
|
4911
|
+
closeIcon: /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_icons3.CloseOutlined, {}),
|
|
4912
|
+
onCancel: onClose,
|
|
4913
|
+
styles: {
|
|
4914
|
+
body: {
|
|
4915
|
+
height: "min(78vh, 900px)",
|
|
4916
|
+
minHeight: 360,
|
|
4917
|
+
padding: 0,
|
|
4918
|
+
overflow: "hidden",
|
|
4919
|
+
border: "1px solid #e5e7eb"
|
|
4920
|
+
}
|
|
4921
|
+
},
|
|
4922
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime5.jsxs)("div", { style: { display: "flex", justifyContent: "flex-end", gap: 8 }, children: [
|
|
4923
|
+
/* @__PURE__ */ (0, import_jsx_runtime5.jsx)(import_antd4.Button, { onClick: onClose, children: "\u5173\u95ED" }),
|
|
4924
|
+
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
|
|
4925
|
+
] }),
|
|
4926
|
+
children: preview && metadata ? /* @__PURE__ */ (0, import_jsx_runtime5.jsx)(
|
|
4927
|
+
FilePreviewContent,
|
|
4928
|
+
{
|
|
4929
|
+
metadata,
|
|
4930
|
+
request,
|
|
4931
|
+
onDownload
|
|
4932
|
+
}
|
|
4933
|
+
) : /* @__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..." }) })
|
|
4934
|
+
}
|
|
4935
|
+
);
|
|
4936
|
+
};
|
|
4937
|
+
|
|
4938
|
+
// packages/sdk/src/components/fields/shared/FileDisplay.tsx
|
|
4939
|
+
var import_icons4 = require("@ant-design/icons");
|
|
4940
|
+
var import_jsx_runtime6 = require("react/jsx-runtime");
|
|
4941
|
+
function FileTypeIcon({
|
|
4942
|
+
item,
|
|
4943
|
+
className
|
|
4944
|
+
}) {
|
|
4945
|
+
const category = getFileCategory(item.name, item.contentType);
|
|
4946
|
+
const extension = getFileExtension(item.name);
|
|
4947
|
+
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, {});
|
|
4948
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)("span", { className: `sy-file-icon sy-file-icon-${category} ${className || ""}`, "aria-hidden": "true", children: [
|
|
4949
|
+
icon,
|
|
4950
|
+
category !== "image" && extension ? /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { children: extension.toUpperCase() }) : null
|
|
4951
|
+
] });
|
|
4952
|
+
}
|
|
4953
|
+
function FileActionButton({
|
|
4954
|
+
type,
|
|
4955
|
+
disabled,
|
|
4956
|
+
onClick,
|
|
4957
|
+
testId
|
|
4958
|
+
}) {
|
|
4959
|
+
const label = type === "preview" ? "\u9884\u89C8" : type === "download" ? "\u4E0B\u8F7D" : "\u5220\u9664";
|
|
4960
|
+
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, {});
|
|
4961
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsxs)(
|
|
4962
|
+
"button",
|
|
4963
|
+
{
|
|
4964
|
+
type: "button",
|
|
4965
|
+
className: `sy-file-action sy-file-action-${type}`,
|
|
4966
|
+
disabled,
|
|
4967
|
+
onClick,
|
|
4968
|
+
"data-testid": testId,
|
|
4969
|
+
"aria-label": label,
|
|
4970
|
+
title: label,
|
|
4971
|
+
children: [
|
|
4972
|
+
icon,
|
|
4973
|
+
/* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "sy-sr-only", children: label })
|
|
4974
|
+
]
|
|
4975
|
+
}
|
|
4976
|
+
);
|
|
4977
|
+
}
|
|
4978
|
+
function FileStatusText({
|
|
4979
|
+
item,
|
|
4980
|
+
showFileSize = true,
|
|
4981
|
+
showFileTypeBadge = true
|
|
4982
|
+
}) {
|
|
4983
|
+
const extension = getFileExtension(item.name);
|
|
4984
|
+
const text = item.status === "uploading" ? `\u4E0A\u4F20\u4E2D ${Math.round(item.percent ?? 0)}%` : item.status === "error" ? item.error || "\u4E0A\u4F20\u5931\u8D25" : [
|
|
4985
|
+
showFileTypeBadge && extension ? extension.toUpperCase() : "",
|
|
4986
|
+
showFileSize ? formatFileSize(item.size) : ""
|
|
4987
|
+
].filter(Boolean).join(" \xB7 ") || "\u5DF2\u4E0A\u4F20";
|
|
4988
|
+
return /* @__PURE__ */ (0, import_jsx_runtime6.jsx)("span", { className: "sy-file-sub", children: text });
|
|
4989
|
+
}
|
|
4990
|
+
|
|
4991
|
+
// packages/sdk/src/runtime/react/filePreview.tsx
|
|
4992
|
+
var import_jsx_runtime7 = require("react/jsx-runtime");
|
|
4993
|
+
var EMPTY_ITEMS = [];
|
|
4994
|
+
var normalizeMethod2 = (method) => {
|
|
4995
|
+
const value = String(method || "get").toLowerCase();
|
|
4996
|
+
return ["get", "post", "put", "delete", "patch"].includes(value) ? value : "get";
|
|
4997
|
+
};
|
|
4998
|
+
var normalizeHeaders = (headers) => {
|
|
4999
|
+
if (!headers) return void 0;
|
|
5000
|
+
return Object.fromEntries(new Headers(headers).entries());
|
|
5001
|
+
};
|
|
5002
|
+
var toPageRequest = (config) => ({
|
|
5003
|
+
path: config.url,
|
|
5004
|
+
method: normalizeMethod2(config.method),
|
|
5005
|
+
query: config.params,
|
|
5006
|
+
body: config.data,
|
|
5007
|
+
headers: normalizeHeaders(config.headers)
|
|
5008
|
+
});
|
|
5009
|
+
var toRuntimeResponse = (response) => {
|
|
5010
|
+
if (response.raw && typeof response.raw === "object") {
|
|
5011
|
+
return response.raw;
|
|
5012
|
+
}
|
|
5013
|
+
return {
|
|
5014
|
+
code: Number(response.code) || 200,
|
|
5015
|
+
success: response.success,
|
|
5016
|
+
message: response.message,
|
|
5017
|
+
data: response.result,
|
|
5018
|
+
result: response.result
|
|
5019
|
+
};
|
|
5020
|
+
};
|
|
5021
|
+
var unwrapPageResult = (response) => response.result ?? response.data ?? null;
|
|
5022
|
+
var createPageFileRuntimeApi = (sdk) => {
|
|
5023
|
+
const request = async (config) => {
|
|
5024
|
+
const options = toPageRequest(config);
|
|
5025
|
+
if (config.responseType === "blob") {
|
|
5026
|
+
const response = await sdk.transport.download(options);
|
|
5027
|
+
return response.blob;
|
|
5028
|
+
}
|
|
5029
|
+
return toRuntimeResponse(await sdk.transport.request(options));
|
|
5030
|
+
};
|
|
5031
|
+
return createFormRuntimeApi({
|
|
5032
|
+
request,
|
|
5033
|
+
createFileAccessTicket: async (bucketName, objectName, fileName, purpose = "preview", options = {}) => unwrapPageResult(
|
|
5034
|
+
await sdk.createFileAccessTicket(
|
|
5035
|
+
bucketName,
|
|
5036
|
+
objectName,
|
|
5037
|
+
fileName,
|
|
5038
|
+
purpose,
|
|
5039
|
+
options
|
|
5040
|
+
)
|
|
5041
|
+
),
|
|
5042
|
+
createDownloadTicket: async (bucketName, objectName, fileName) => unwrapPageResult(
|
|
5043
|
+
await sdk.request({
|
|
5044
|
+
path: "/file/download-ticket",
|
|
5045
|
+
method: "post",
|
|
5046
|
+
body: { bucketName, objectName, fileName }
|
|
5047
|
+
})
|
|
5048
|
+
)
|
|
5049
|
+
});
|
|
5050
|
+
};
|
|
5051
|
+
var useFilePreview = ({
|
|
5052
|
+
items = EMPTY_ITEMS,
|
|
5053
|
+
appType,
|
|
5054
|
+
bucketName = "attachments",
|
|
5055
|
+
enabled = true,
|
|
5056
|
+
requireServerCapability = true
|
|
5057
|
+
}) => {
|
|
5058
|
+
const sdk = usePageSdk();
|
|
5059
|
+
const api = (0, import_react10.useMemo)(() => createPageFileRuntimeApi(sdk), [sdk]);
|
|
5060
|
+
const preview = useFilePreviewController({
|
|
5061
|
+
items,
|
|
5062
|
+
api,
|
|
5063
|
+
appType: appType || sdk.context.app.appType,
|
|
5064
|
+
bucketName,
|
|
5065
|
+
enabled,
|
|
5066
|
+
requireServerCapability
|
|
5067
|
+
});
|
|
5068
|
+
return {
|
|
5069
|
+
canPreview: preview.canPreview,
|
|
5070
|
+
getCapability: preview.getCapability,
|
|
5071
|
+
open: preview.openPreview,
|
|
5072
|
+
download: preview.downloadItem,
|
|
5073
|
+
isOpening: preview.isOpening,
|
|
5074
|
+
openingKey: preview.openingKey,
|
|
5075
|
+
host: preview.previewHost
|
|
5076
|
+
};
|
|
5077
|
+
};
|
|
5078
|
+
var AttachmentPreviewList = ({
|
|
5079
|
+
items = EMPTY_ITEMS,
|
|
5080
|
+
appType,
|
|
5081
|
+
bucketName = "attachments",
|
|
5082
|
+
showPreview = true,
|
|
5083
|
+
showDownload = true,
|
|
5084
|
+
showFileSize = true,
|
|
5085
|
+
showFileTypeBadge = false,
|
|
5086
|
+
emptyText = "\u6682\u65E0\u9644\u4EF6",
|
|
5087
|
+
className
|
|
5088
|
+
}) => {
|
|
5089
|
+
const preview = useFilePreview({
|
|
5090
|
+
items,
|
|
5091
|
+
appType,
|
|
5092
|
+
bucketName,
|
|
5093
|
+
enabled: showPreview,
|
|
5094
|
+
requireServerCapability: true
|
|
5095
|
+
});
|
|
5096
|
+
if (!items.length) {
|
|
5097
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_antd5.Empty, { description: emptyText, className });
|
|
5098
|
+
}
|
|
5099
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
5100
|
+
"div",
|
|
5101
|
+
{
|
|
5102
|
+
className: ["sy-readonly-files", "sy-readonly-attachments", className].filter(Boolean).join(" "),
|
|
5103
|
+
"data-testid": "openxiangda-attachment-preview-list",
|
|
5104
|
+
children: [
|
|
5105
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "sy-file-list", children: items.map((item, index) => {
|
|
5106
|
+
const key = getPreviewItemKey(item, index);
|
|
5107
|
+
const canAct = item.status !== "uploading" && item.status !== "error";
|
|
5108
|
+
const canDownload = preview.getCapability(item)?.canDownload !== false;
|
|
5109
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "sy-file-item", children: [
|
|
5110
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(FileTypeIcon, { item }),
|
|
5111
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "sy-file-meta", children: [
|
|
5112
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("span", { className: "sy-file-name", title: item.name, children: item.name || "\u672A\u547D\u540D\u9644\u4EF6" }),
|
|
5113
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5114
|
+
FileStatusText,
|
|
5115
|
+
{
|
|
5116
|
+
item,
|
|
5117
|
+
showFileSize,
|
|
5118
|
+
showFileTypeBadge
|
|
5119
|
+
}
|
|
5120
|
+
)
|
|
5121
|
+
] }),
|
|
5122
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "sy-file-actions", children: [
|
|
5123
|
+
showPreview && preview.canPreview(item) ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5124
|
+
FileActionButton,
|
|
5125
|
+
{
|
|
5126
|
+
type: "preview",
|
|
5127
|
+
disabled: !canAct || preview.isOpening(item),
|
|
5128
|
+
onClick: () => void preview.open(item),
|
|
5129
|
+
testId: `attachment-preview-${key}`
|
|
5130
|
+
}
|
|
5131
|
+
) : null,
|
|
5132
|
+
showDownload && canDownload ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5133
|
+
FileActionButton,
|
|
5134
|
+
{
|
|
5135
|
+
type: "download",
|
|
5136
|
+
disabled: !canAct,
|
|
5137
|
+
onClick: () => void preview.download(item),
|
|
5138
|
+
testId: `attachment-download-${key}`
|
|
5139
|
+
}
|
|
5140
|
+
) : null
|
|
5141
|
+
] })
|
|
5142
|
+
] }, `${key}-${index}`);
|
|
5143
|
+
}) }),
|
|
5144
|
+
preview.host
|
|
5145
|
+
]
|
|
5146
|
+
}
|
|
5147
|
+
);
|
|
5148
|
+
};
|
|
5149
|
+
var PreviewImageThumb = ({ item }) => {
|
|
5150
|
+
const src = item.thumbUrl || item.previewUrl || item.url;
|
|
5151
|
+
const [failed, setFailed] = (0, import_react10.useState)(false);
|
|
5152
|
+
import_react10.default.useEffect(() => setFailed(false), [src]);
|
|
5153
|
+
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" });
|
|
5154
|
+
};
|
|
5155
|
+
var ImagePreviewGrid = ({
|
|
5156
|
+
items = EMPTY_ITEMS,
|
|
5157
|
+
appType,
|
|
5158
|
+
bucketName = "images",
|
|
5159
|
+
showPreview = true,
|
|
5160
|
+
showDownload = true,
|
|
5161
|
+
showFileName = true,
|
|
5162
|
+
emptyText = "\u6682\u65E0\u56FE\u7247",
|
|
5163
|
+
className
|
|
5164
|
+
}) => {
|
|
5165
|
+
const preview = useFilePreview({
|
|
5166
|
+
items,
|
|
5167
|
+
appType,
|
|
5168
|
+
bucketName,
|
|
5169
|
+
enabled: showPreview,
|
|
5170
|
+
requireServerCapability: true
|
|
5171
|
+
});
|
|
5172
|
+
if (!items.length) {
|
|
5173
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(import_antd5.Empty, { description: emptyText, className });
|
|
5174
|
+
}
|
|
5175
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
5176
|
+
"div",
|
|
5177
|
+
{
|
|
5178
|
+
className: ["sy-readonly-files", "sy-readonly-images", className].filter(Boolean).join(" "),
|
|
5179
|
+
"data-testid": "openxiangda-image-preview-grid",
|
|
5180
|
+
children: [
|
|
5181
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5182
|
+
"div",
|
|
5183
|
+
{
|
|
5184
|
+
className: "sy-mobile-image-grid",
|
|
5185
|
+
style: { gridTemplateColumns: "repeat(auto-fill, minmax(112px, 160px))" },
|
|
5186
|
+
children: items.map((item, index) => {
|
|
5187
|
+
const key = getPreviewItemKey(item, index);
|
|
5188
|
+
const canAct = item.status !== "uploading" && item.status !== "error";
|
|
5189
|
+
const canOpen = showPreview && preview.canPreview(item);
|
|
5190
|
+
const canDownload = preview.getCapability(item)?.canDownload !== false;
|
|
5191
|
+
return /* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "sy-mobile-image-card", children: [
|
|
5192
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsx)("div", { className: "sy-mobile-image-thumb", children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5193
|
+
"button",
|
|
5194
|
+
{
|
|
5195
|
+
type: "button",
|
|
5196
|
+
className: "sy-image-preview",
|
|
5197
|
+
disabled: !canAct || !canOpen || preview.isOpening(item),
|
|
5198
|
+
onClick: () => void preview.open(item),
|
|
5199
|
+
"aria-label": `\u9884\u89C8 ${item.name || "\u56FE\u7247"}`,
|
|
5200
|
+
"data-testid": `image-preview-${key}`,
|
|
5201
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(PreviewImageThumb, { item })
|
|
5202
|
+
}
|
|
5203
|
+
) }),
|
|
5204
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)(
|
|
5205
|
+
"div",
|
|
5206
|
+
{
|
|
5207
|
+
style: {
|
|
5208
|
+
display: "flex",
|
|
5209
|
+
alignItems: "center",
|
|
5210
|
+
gap: 6,
|
|
5211
|
+
minWidth: 0
|
|
5212
|
+
},
|
|
5213
|
+
children: [
|
|
5214
|
+
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 } }),
|
|
5215
|
+
/* @__PURE__ */ (0, import_jsx_runtime7.jsxs)("div", { className: "sy-file-actions", children: [
|
|
5216
|
+
canOpen ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5217
|
+
FileActionButton,
|
|
5218
|
+
{
|
|
5219
|
+
type: "preview",
|
|
5220
|
+
disabled: !canAct || preview.isOpening(item),
|
|
5221
|
+
onClick: () => void preview.open(item)
|
|
5222
|
+
}
|
|
5223
|
+
) : null,
|
|
5224
|
+
showDownload && canDownload ? /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
|
|
5225
|
+
FileActionButton,
|
|
5226
|
+
{
|
|
5227
|
+
type: "download",
|
|
5228
|
+
disabled: !canAct,
|
|
5229
|
+
onClick: () => void preview.download(item)
|
|
5230
|
+
}
|
|
5231
|
+
) : null
|
|
5232
|
+
] })
|
|
5233
|
+
]
|
|
5234
|
+
}
|
|
5235
|
+
)
|
|
5236
|
+
] }, `${key}-${index}`);
|
|
5237
|
+
})
|
|
5238
|
+
}
|
|
5239
|
+
),
|
|
5240
|
+
preview.host
|
|
5241
|
+
]
|
|
5242
|
+
}
|
|
5243
|
+
);
|
|
5244
|
+
};
|
|
5245
|
+
|
|
2699
5246
|
// packages/sdk/src/runtime/react/workflow.tsx
|
|
2700
|
-
var
|
|
2701
|
-
var
|
|
2702
|
-
var
|
|
5247
|
+
var import_react16 = require("react");
|
|
5248
|
+
var import_antd10 = require("antd");
|
|
5249
|
+
var import_icons9 = require("@ant-design/icons");
|
|
2703
5250
|
|
|
2704
5251
|
// packages/sdk/src/components/modules/StickyActionBar.tsx
|
|
2705
|
-
var
|
|
2706
|
-
var
|
|
2707
|
-
var
|
|
5252
|
+
var import_react11 = require("react");
|
|
5253
|
+
var import_antd6 = require("antd");
|
|
5254
|
+
var import_icons5 = require("@ant-design/icons");
|
|
2708
5255
|
|
|
2709
5256
|
// packages/sdk/src/components/utils/confirmAction.ts
|
|
2710
5257
|
var confirmAction = (title, content) => {
|
|
@@ -2720,7 +5267,7 @@ var confirmAction = (title, content) => {
|
|
|
2720
5267
|
};
|
|
2721
5268
|
|
|
2722
5269
|
// packages/sdk/src/components/modules/StickyActionBar.tsx
|
|
2723
|
-
var
|
|
5270
|
+
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
2724
5271
|
var getActionPriority = (action) => {
|
|
2725
5272
|
const maybePriority = action.priority;
|
|
2726
5273
|
if (typeof maybePriority === "number") return maybePriority;
|
|
@@ -2738,14 +5285,14 @@ var StickyActionBar = ({
|
|
|
2738
5285
|
position = "sticky",
|
|
2739
5286
|
surface = "default"
|
|
2740
5287
|
}) => {
|
|
2741
|
-
const [isMobile, setIsMobile] = (0,
|
|
2742
|
-
(0,
|
|
5288
|
+
const [isMobile, setIsMobile] = (0, import_react11.useState)(false);
|
|
5289
|
+
(0, import_react11.useEffect)(() => {
|
|
2743
5290
|
const update = () => setIsMobile(typeof window !== "undefined" && window.innerWidth <= 768);
|
|
2744
5291
|
update();
|
|
2745
5292
|
window.addEventListener("resize", update);
|
|
2746
5293
|
return () => window.removeEventListener("resize", update);
|
|
2747
5294
|
}, []);
|
|
2748
|
-
const visibleActions = (0,
|
|
5295
|
+
const visibleActions = (0, import_react11.useMemo)(
|
|
2749
5296
|
() => actions.filter((action) => action.visible !== false).sort((left, right) => getActionPriority(left) - getActionPriority(right)),
|
|
2750
5297
|
[actions]
|
|
2751
5298
|
);
|
|
@@ -2766,8 +5313,8 @@ var StickyActionBar = ({
|
|
|
2766
5313
|
action.onClick();
|
|
2767
5314
|
};
|
|
2768
5315
|
const renderButton = (action, mobile = false) => {
|
|
2769
|
-
const button = /* @__PURE__ */ (0,
|
|
2770
|
-
|
|
5316
|
+
const button = /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
5317
|
+
import_antd6.Button,
|
|
2771
5318
|
{
|
|
2772
5319
|
type: action.type === "danger" ? "primary" : action.type === "text" ? "text" : action.type || "default",
|
|
2773
5320
|
danger: action.type === "danger",
|
|
@@ -2781,17 +5328,17 @@ var StickyActionBar = ({
|
|
|
2781
5328
|
action.key
|
|
2782
5329
|
);
|
|
2783
5330
|
if (!action.disabled || !action.disabledReason) return button;
|
|
2784
|
-
return /* @__PURE__ */ (0,
|
|
5331
|
+
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
5332
|
};
|
|
2786
|
-
return /* @__PURE__ */ (0,
|
|
5333
|
+
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: `${positionClass} z-20 ${spacingClass} ${surfaceClass} ${className}`, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
2787
5334
|
"div",
|
|
2788
5335
|
{
|
|
2789
5336
|
className: `mx-auto flex w-full items-center gap-3 ${!isMobile ? desktopJustifyClass : "justify-end"}`,
|
|
2790
5337
|
style: { maxWidth: maxWidthStyle },
|
|
2791
|
-
children: isMobile ? /* @__PURE__ */ (0,
|
|
2792
|
-
/* @__PURE__ */ (0,
|
|
2793
|
-
moreMobile.length > 0 && /* @__PURE__ */ (0,
|
|
2794
|
-
|
|
5338
|
+
children: isMobile ? /* @__PURE__ */ (0, import_jsx_runtime8.jsxs)(import_jsx_runtime8.Fragment, { children: [
|
|
5339
|
+
/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { className: "flex flex-1 gap-2", children: primaryMobile.map((action) => renderButton(action, true)) }),
|
|
5340
|
+
moreMobile.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(
|
|
5341
|
+
import_antd6.Dropdown,
|
|
2795
5342
|
{
|
|
2796
5343
|
trigger: ["click"],
|
|
2797
5344
|
placement: "topRight",
|
|
@@ -2805,17 +5352,17 @@ var StickyActionBar = ({
|
|
|
2805
5352
|
onClick: () => runAction(action)
|
|
2806
5353
|
}))
|
|
2807
5354
|
},
|
|
2808
|
-
children: /* @__PURE__ */ (0,
|
|
5355
|
+
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
5356
|
}
|
|
2810
5357
|
)
|
|
2811
|
-
] }) : layoutMode === "approval" ? /* @__PURE__ */ (0,
|
|
5358
|
+
] }) : 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
5359
|
}
|
|
2813
5360
|
) });
|
|
2814
5361
|
};
|
|
2815
5362
|
|
|
2816
5363
|
// packages/sdk/src/components/modules/ApprovalTimeline.tsx
|
|
2817
|
-
var
|
|
2818
|
-
var
|
|
5364
|
+
var import_react12 = require("react");
|
|
5365
|
+
var import_icons6 = require("@ant-design/icons");
|
|
2819
5366
|
|
|
2820
5367
|
// packages/sdk/src/components/core/constants.ts
|
|
2821
5368
|
var TASK_STATUS_META = {
|
|
@@ -2831,7 +5378,7 @@ var TASK_STATUS_META = {
|
|
|
2831
5378
|
};
|
|
2832
5379
|
|
|
2833
5380
|
// packages/sdk/src/components/modules/ApprovalTimeline.tsx
|
|
2834
|
-
var
|
|
5381
|
+
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
2835
5382
|
var systemNodeTypes = /* @__PURE__ */ new Set([
|
|
2836
5383
|
"condition",
|
|
2837
5384
|
"condition_branch",
|
|
@@ -2925,37 +5472,37 @@ function getStatusMeta(task, state, compact) {
|
|
|
2925
5472
|
}
|
|
2926
5473
|
function getIcon(task, state) {
|
|
2927
5474
|
if (state === "current")
|
|
2928
|
-
return task.nodeType === "callback_wait" ? /* @__PURE__ */ (0,
|
|
5475
|
+
return task.nodeType === "callback_wait" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.ClockCircleOutlined, {}) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.LoadingOutlined, {});
|
|
2929
5476
|
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,
|
|
5477
|
+
return task.nodeType === "approval" ? /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.UserOutlined, {}) : /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.ClockCircleOutlined, {});
|
|
5478
|
+
if (state === "rejected") return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.CloseCircleFilled, {});
|
|
5479
|
+
if (state === "returned") return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.RollbackOutlined, {});
|
|
2933
5480
|
switch (task.nodeType) {
|
|
2934
5481
|
case "start":
|
|
2935
|
-
return /* @__PURE__ */ (0,
|
|
5482
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.FileTextOutlined, {});
|
|
2936
5483
|
case "approval":
|
|
2937
|
-
return /* @__PURE__ */ (0,
|
|
5484
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.CheckCircleFilled, {});
|
|
2938
5485
|
case "originator_return":
|
|
2939
|
-
return /* @__PURE__ */ (0,
|
|
5486
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.EditOutlined, {});
|
|
2940
5487
|
case "copy":
|
|
2941
|
-
return /* @__PURE__ */ (0,
|
|
5488
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.CopyOutlined, {});
|
|
2942
5489
|
case "callback_wait":
|
|
2943
|
-
return /* @__PURE__ */ (0,
|
|
5490
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.ClockCircleOutlined, {});
|
|
2944
5491
|
case "js_code":
|
|
2945
|
-
return /* @__PURE__ */ (0,
|
|
5492
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.CodeOutlined, {});
|
|
2946
5493
|
case "connector_call":
|
|
2947
|
-
return /* @__PURE__ */ (0,
|
|
5494
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.ApiOutlined, {});
|
|
2948
5495
|
case "work_notification":
|
|
2949
5496
|
case "dingtalk_card":
|
|
2950
|
-
return /* @__PURE__ */ (0,
|
|
5497
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.NotificationOutlined, {});
|
|
2951
5498
|
case "data_retrieve_single":
|
|
2952
5499
|
case "data_retrieve_batch":
|
|
2953
5500
|
case "data_create":
|
|
2954
5501
|
case "data_update":
|
|
2955
5502
|
case "loop_container":
|
|
2956
|
-
return /* @__PURE__ */ (0,
|
|
5503
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.ReloadOutlined, {});
|
|
2957
5504
|
default:
|
|
2958
|
-
return /* @__PURE__ */ (0,
|
|
5505
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(import_icons6.CheckCircleFilled, {});
|
|
2959
5506
|
}
|
|
2960
5507
|
}
|
|
2961
5508
|
function getDotClass(state) {
|
|
@@ -2978,21 +5525,21 @@ var ApprovalTimeline = ({
|
|
|
2978
5525
|
compactMode = false,
|
|
2979
5526
|
showApproverInfo = true
|
|
2980
5527
|
}) => {
|
|
2981
|
-
const taskList = (0,
|
|
2982
|
-
const groups = (0,
|
|
5528
|
+
const taskList = (0, import_react12.useMemo)(() => Array.isArray(tasks) ? tasks : [], [tasks]);
|
|
5529
|
+
const groups = (0, import_react12.useMemo)(() => groupTasks(taskList), [taskList]);
|
|
2983
5530
|
if (taskList.length === 0) {
|
|
2984
|
-
return /* @__PURE__ */ (0,
|
|
5531
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
2985
5532
|
"div",
|
|
2986
5533
|
{
|
|
2987
5534
|
className: `rounded-lg border border-ant-border-secondary bg-ant-bg-container p-6 ${className}`,
|
|
2988
|
-
children: /* @__PURE__ */ (0,
|
|
5535
|
+
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
5536
|
}
|
|
2990
5537
|
);
|
|
2991
5538
|
}
|
|
2992
5539
|
if (renderNode) {
|
|
2993
|
-
return /* @__PURE__ */ (0,
|
|
5540
|
+
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
5541
|
}
|
|
2995
|
-
return /* @__PURE__ */ (0,
|
|
5542
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: `approval-timeline ${className}`, children: groups.map((group, index) => {
|
|
2996
5543
|
const node = group[0];
|
|
2997
5544
|
const isLast = index === groups.length - 1;
|
|
2998
5545
|
const isFutureGroup = group.some((task) => task.isSimulated || task.status === "simulated");
|
|
@@ -3001,62 +5548,62 @@ var ApprovalTimeline = ({
|
|
|
3001
5548
|
const statusMeta = getStatusMeta(node, state, compact);
|
|
3002
5549
|
const title = getNodeTitle(node);
|
|
3003
5550
|
const time = node.actionAt || node.createdAt;
|
|
3004
|
-
return /* @__PURE__ */ (0,
|
|
5551
|
+
return /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
3005
5552
|
"div",
|
|
3006
5553
|
{
|
|
3007
5554
|
className: `relative flex gap-4 pb-5 ${isLast ? "pb-0" : ""}`,
|
|
3008
5555
|
children: [
|
|
3009
|
-
!isLast && /* @__PURE__ */ (0,
|
|
5556
|
+
!isLast && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3010
5557
|
"div",
|
|
3011
5558
|
{
|
|
3012
5559
|
className: `absolute bottom-0 left-[21px] top-11 w-px ${state === "future" ? "border-l border-dashed border-gray-300" : "bg-ant-border-secondary"}`
|
|
3013
5560
|
}
|
|
3014
5561
|
),
|
|
3015
|
-
/* @__PURE__ */ (0,
|
|
5562
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3016
5563
|
"div",
|
|
3017
5564
|
{
|
|
3018
5565
|
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
5566
|
children: getIcon(node, state)
|
|
3020
5567
|
}
|
|
3021
5568
|
),
|
|
3022
|
-
/* @__PURE__ */ (0,
|
|
5569
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
3023
5570
|
"div",
|
|
3024
5571
|
{
|
|
3025
5572
|
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
5573
|
children: [
|
|
3027
|
-
/* @__PURE__ */ (0,
|
|
3028
|
-
/* @__PURE__ */ (0,
|
|
3029
|
-
/* @__PURE__ */ (0,
|
|
3030
|
-
/* @__PURE__ */ (0,
|
|
5574
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex flex-wrap items-start justify-between gap-2", children: [
|
|
5575
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [
|
|
5576
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "font-medium text-ant-text", children: title }),
|
|
5577
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3031
5578
|
"span",
|
|
3032
5579
|
{
|
|
3033
5580
|
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
5581
|
children: statusMeta.label
|
|
3035
5582
|
}
|
|
3036
5583
|
),
|
|
3037
|
-
node.nodeType === "originator_return" && /* @__PURE__ */ (0,
|
|
5584
|
+
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
5585
|
] }),
|
|
3039
|
-
!isFutureGroup && time && /* @__PURE__ */ (0,
|
|
5586
|
+
!isFutureGroup && time && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "text-xs text-ant-text-tertiary", children: time })
|
|
3040
5587
|
] }),
|
|
3041
|
-
showApproverInfo && !compact && group.length > 0 && /* @__PURE__ */ (0,
|
|
3042
|
-
/* @__PURE__ */ (0,
|
|
3043
|
-
group.map((assignee) => /* @__PURE__ */ (0,
|
|
5588
|
+
showApproverInfo && !compact && group.length > 0 && /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("div", { className: "mt-3 flex flex-wrap gap-3", children: [
|
|
5589
|
+
/* @__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" }),
|
|
5590
|
+
group.map((assignee) => /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
3044
5591
|
"span",
|
|
3045
5592
|
{
|
|
3046
5593
|
className: "inline-flex min-w-0 items-center gap-2",
|
|
3047
5594
|
children: [
|
|
3048
|
-
/* @__PURE__ */ (0,
|
|
3049
|
-
/* @__PURE__ */ (0,
|
|
3050
|
-
/* @__PURE__ */ (0,
|
|
3051
|
-
/* @__PURE__ */ (0,
|
|
5595
|
+
/* @__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) || "?" }),
|
|
5596
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsxs)("span", { className: "min-w-0", children: [
|
|
5597
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "block text-sm font-medium text-ant-text", children: assignee.assigneeName || "\u7CFB\u7EDF" }),
|
|
5598
|
+
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("span", { className: "block text-xs text-ant-text-tertiary", children: assignee.departmentName || assignee.actionAt || assignee.createdAt || "" })
|
|
3052
5599
|
] })
|
|
3053
5600
|
]
|
|
3054
5601
|
},
|
|
3055
5602
|
assignee.taskId || assignee.id
|
|
3056
5603
|
))
|
|
3057
5604
|
] }),
|
|
3058
|
-
showApproverInfo && compact && /* @__PURE__ */ (0,
|
|
3059
|
-
showRemarks && node.comments && /* @__PURE__ */ (0,
|
|
5605
|
+
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" : "") }),
|
|
5606
|
+
showRemarks && node.comments && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
|
|
3060
5607
|
"div",
|
|
3061
5608
|
{
|
|
3062
5609
|
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 +5621,9 @@ var ApprovalTimeline = ({
|
|
|
3074
5621
|
};
|
|
3075
5622
|
|
|
3076
5623
|
// packages/sdk/src/components/modules/ProcessPreview.tsx
|
|
3077
|
-
var
|
|
3078
|
-
var
|
|
3079
|
-
var
|
|
5624
|
+
var import_antd7 = require("antd");
|
|
5625
|
+
var import_icons7 = require("@ant-design/icons");
|
|
5626
|
+
var import_jsx_runtime10 = require("react/jsx-runtime");
|
|
3080
5627
|
var ProcessPreview = ({
|
|
3081
5628
|
open,
|
|
3082
5629
|
onClose,
|
|
@@ -3085,30 +5632,30 @@ var ProcessPreview = ({
|
|
|
3085
5632
|
loading = false
|
|
3086
5633
|
}) => {
|
|
3087
5634
|
const routeList = Array.isArray(routes) ? routes : [];
|
|
3088
|
-
return /* @__PURE__ */ (0,
|
|
3089
|
-
|
|
5635
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
5636
|
+
import_antd7.Modal,
|
|
3090
5637
|
{
|
|
3091
5638
|
getContainer: false,
|
|
3092
5639
|
title: "\u6D41\u7A0B\u9884\u89C8",
|
|
3093
5640
|
open,
|
|
3094
5641
|
onCancel: onClose,
|
|
3095
5642
|
width: 520,
|
|
3096
|
-
footer: /* @__PURE__ */ (0,
|
|
3097
|
-
/* @__PURE__ */ (0,
|
|
3098
|
-
/* @__PURE__ */ (0,
|
|
5643
|
+
footer: /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex justify-end gap-3", children: [
|
|
5644
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_antd7.Button, { onClick: onClose, children: "\u53D6\u6D88" }),
|
|
5645
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_antd7.Button, { type: "primary", onClick: onConfirm, loading, children: "\u786E\u8BA4\u63D0\u4EA4" })
|
|
3099
5646
|
] }),
|
|
3100
|
-
children: loading && routeList.length === 0 ? /* @__PURE__ */ (0,
|
|
5647
|
+
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
5648
|
const isLast = index === routeList.length - 1;
|
|
3102
|
-
return /* @__PURE__ */ (0,
|
|
3103
|
-
/* @__PURE__ */ (0,
|
|
3104
|
-
/* @__PURE__ */ (0,
|
|
3105
|
-
!isLast && /* @__PURE__ */ (0,
|
|
5649
|
+
return /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex gap-3", children: [
|
|
5650
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: "flex flex-col items-center", children: [
|
|
5651
|
+
/* @__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" }) }),
|
|
5652
|
+
!isLast && /* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "w-0.5 flex-1 bg-blue-200 mt-1" })
|
|
3106
5653
|
] }),
|
|
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,
|
|
5654
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsxs)("div", { className: `flex-1 ${isLast ? "pb-0" : "pb-5"}`, children: [
|
|
5655
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)("div", { className: "text-sm font-medium text-gray-900", children: route.nodeName }),
|
|
5656
|
+
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: [
|
|
5657
|
+
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_icons7.UserOutlined, { className: "text-gray-400 text-xs" }),
|
|
5658
|
+
route.assignees.map((assignee) => /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
|
|
3112
5659
|
"span",
|
|
3113
5660
|
{
|
|
3114
5661
|
className: "text-xs text-gray-500 bg-gray-100 px-1.5 py-0.5 rounded",
|
|
@@ -3125,20 +5672,20 @@ var ProcessPreview = ({
|
|
|
3125
5672
|
};
|
|
3126
5673
|
|
|
3127
5674
|
// packages/sdk/src/components/modules/InitiatorApproverSelector.tsx
|
|
3128
|
-
var
|
|
3129
|
-
var
|
|
5675
|
+
var import_react15 = require("react");
|
|
5676
|
+
var import_antd9 = require("antd");
|
|
3130
5677
|
|
|
3131
5678
|
// packages/sdk/src/components/core/processApi.ts
|
|
3132
5679
|
var hasOwn2 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
3133
5680
|
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
|
|
5681
|
+
var isSuccessCode3 = (code) => {
|
|
3135
5682
|
if (code === void 0 || code === null || code === "") return true;
|
|
3136
5683
|
const normalized = Number(code);
|
|
3137
5684
|
return Number.isFinite(normalized) ? normalized === 0 || normalized === 200 : false;
|
|
3138
5685
|
};
|
|
3139
5686
|
var unwrapRuntimeResponse = (response) => {
|
|
3140
5687
|
if (!isRuntimeEnvelope(response)) return response;
|
|
3141
|
-
if (response.success === false || !
|
|
5688
|
+
if (response.success === false || !isSuccessCode3(response.code)) {
|
|
3142
5689
|
throw new Error(response.message || response.error || "\u8BF7\u6C42\u5931\u8D25");
|
|
3143
5690
|
}
|
|
3144
5691
|
if (hasOwn2(response, "data")) return response.data;
|
|
@@ -3170,75 +5717,13 @@ async function getInitiatorSelectCandidates(request, params) {
|
|
|
3170
5717
|
}
|
|
3171
5718
|
|
|
3172
5719
|
// packages/sdk/src/components/fields/shared/UserPicker.tsx
|
|
3173
|
-
var
|
|
3174
|
-
var
|
|
3175
|
-
var
|
|
5720
|
+
var import_react14 = require("react");
|
|
5721
|
+
var import_antd8 = require("antd");
|
|
5722
|
+
var import_icons8 = require("@ant-design/icons");
|
|
3176
5723
|
var MobileAntd = __toESM(require("antd-mobile"));
|
|
3177
5724
|
|
|
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
5725
|
// packages/sdk/src/components/fields/shared/useLazyDepartmentTree.ts
|
|
3241
|
-
var
|
|
5726
|
+
var import_react13 = require("react");
|
|
3242
5727
|
var toLazyNode = (node) => {
|
|
3243
5728
|
const normalized = normalizeDepartmentNode(node);
|
|
3244
5729
|
const id = getDepartmentId(normalized);
|
|
@@ -3288,15 +5773,15 @@ function buildIndexes(nodes) {
|
|
|
3288
5773
|
return { nodeMap, parentMap, flatNodes };
|
|
3289
5774
|
}
|
|
3290
5775
|
function useLazyDepartmentTree(api, configuredTreeData) {
|
|
3291
|
-
const [treeData, setTreeDataState] = (0,
|
|
5776
|
+
const [treeData, setTreeDataState] = (0, import_react13.useState)(
|
|
3292
5777
|
() => (configuredTreeData || []).map(toLazyNode)
|
|
3293
5778
|
);
|
|
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,
|
|
5779
|
+
const [treeLoading, setTreeLoading] = (0, import_react13.useState)(false);
|
|
5780
|
+
const treeDataRef = (0, import_react13.useRef)(treeData);
|
|
5781
|
+
const rootsLoadedRef = (0, import_react13.useRef)(Boolean(configuredTreeData?.length));
|
|
5782
|
+
const rootPromiseRef = (0, import_react13.useRef)(null);
|
|
5783
|
+
const childPromiseRef = (0, import_react13.useRef)({});
|
|
5784
|
+
const setTreeData = (0, import_react13.useCallback)(
|
|
3300
5785
|
(next) => {
|
|
3301
5786
|
const resolved = typeof next === "function" ? next(treeDataRef.current) : next;
|
|
3302
5787
|
treeDataRef.current = resolved;
|
|
@@ -3305,13 +5790,13 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3305
5790
|
},
|
|
3306
5791
|
[]
|
|
3307
5792
|
);
|
|
3308
|
-
(0,
|
|
5793
|
+
(0, import_react13.useEffect)(() => {
|
|
3309
5794
|
if (!configuredTreeData) return;
|
|
3310
5795
|
const next = configuredTreeData.map(toLazyNode);
|
|
3311
5796
|
rootsLoadedRef.current = next.length > 0;
|
|
3312
5797
|
setTreeData(next);
|
|
3313
5798
|
}, [configuredTreeData, setTreeData]);
|
|
3314
|
-
const loadRootDepartments = (0,
|
|
5799
|
+
const loadRootDepartments = (0, import_react13.useCallback)(async () => {
|
|
3315
5800
|
if (rootsLoadedRef.current) return treeDataRef.current;
|
|
3316
5801
|
if (rootPromiseRef.current) return rootPromiseRef.current;
|
|
3317
5802
|
setTreeLoading(true);
|
|
@@ -3327,7 +5812,7 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3327
5812
|
rootPromiseRef.current = promise;
|
|
3328
5813
|
return promise;
|
|
3329
5814
|
}, [api, setTreeData]);
|
|
3330
|
-
const loadChildren = (0,
|
|
5815
|
+
const loadChildren = (0, import_react13.useCallback)(
|
|
3331
5816
|
async (parentId) => {
|
|
3332
5817
|
const id = String(parentId || "");
|
|
3333
5818
|
if (!id) return [];
|
|
@@ -3348,8 +5833,8 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3348
5833
|
},
|
|
3349
5834
|
[api, setTreeData]
|
|
3350
5835
|
);
|
|
3351
|
-
const indexes = (0,
|
|
3352
|
-
(0,
|
|
5836
|
+
const indexes = (0, import_react13.useMemo)(() => buildIndexes(treeData), [treeData]);
|
|
5837
|
+
(0, import_react13.useEffect)(() => {
|
|
3353
5838
|
void loadRootDepartments();
|
|
3354
5839
|
}, [loadRootDepartments]);
|
|
3355
5840
|
return {
|
|
@@ -3362,7 +5847,7 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3362
5847
|
}
|
|
3363
5848
|
|
|
3364
5849
|
// packages/sdk/src/components/fields/shared/UserPicker.tsx
|
|
3365
|
-
var
|
|
5850
|
+
var import_jsx_runtime11 = require("react/jsx-runtime");
|
|
3366
5851
|
var DEFAULT_MEMBER_PAGE_SIZE = 10;
|
|
3367
5852
|
var getMobileComponent = (name) => {
|
|
3368
5853
|
try {
|
|
@@ -3394,24 +5879,24 @@ function UserPickerPanel({
|
|
|
3394
5879
|
flatNodes,
|
|
3395
5880
|
loadChildren
|
|
3396
5881
|
} = 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,
|
|
5882
|
+
const [departmentKeyword, setDepartmentKeyword] = (0, import_react14.useState)("");
|
|
5883
|
+
const [memberKeyword, setMemberKeyword] = (0, import_react14.useState)("");
|
|
5884
|
+
const [mobileKeyword, setMobileKeyword] = (0, import_react14.useState)("");
|
|
5885
|
+
const [currentDeptId, setCurrentDeptId] = (0, import_react14.useState)("");
|
|
5886
|
+
const [expandedKeys, setExpandedKeys] = (0, import_react14.useState)([]);
|
|
5887
|
+
const [members, setMembers] = (0, import_react14.useState)(() => normalizeUsers(dataSource));
|
|
5888
|
+
const [memberPage, setMemberPage] = (0, import_react14.useState)(1);
|
|
5889
|
+
const [memberPageSize, setMemberPageSize] = (0, import_react14.useState)(DEFAULT_MEMBER_PAGE_SIZE);
|
|
5890
|
+
const [memberTotal, setMemberTotal] = (0, import_react14.useState)(() => normalizeUsers(dataSource).length);
|
|
5891
|
+
const [memberReloadKey, setMemberReloadKey] = (0, import_react14.useState)(0);
|
|
5892
|
+
const [loading, setLoading] = (0, import_react14.useState)(false);
|
|
5893
|
+
const [selected, setSelected] = (0, import_react14.useState)(() => normalizeUsers(value));
|
|
3409
5894
|
const selectedIds = selected.map(getUserId);
|
|
3410
5895
|
const MobileSearchBar = getMobileComponent("SearchBar");
|
|
3411
5896
|
const activeMemberKeyword = (mobile ? mobileKeyword : memberKeyword).trim();
|
|
3412
|
-
const staticUsers = (0,
|
|
5897
|
+
const staticUsers = (0, import_react14.useMemo)(() => normalizeUsers(dataSource), [dataSource]);
|
|
3413
5898
|
const hasStaticUserSource = staticUsers.length > 0;
|
|
3414
|
-
(0,
|
|
5899
|
+
(0, import_react14.useEffect)(() => {
|
|
3415
5900
|
if (mobile) return;
|
|
3416
5901
|
if (currentDeptId || deptTreeData.length === 0) return;
|
|
3417
5902
|
setExpandedKeys(deptTreeData.map((node) => getDepartmentId(node)));
|
|
@@ -3419,17 +5904,17 @@ function UserPickerPanel({
|
|
|
3419
5904
|
setCurrentDeptId(getDepartmentId(deptTreeData[0]));
|
|
3420
5905
|
}
|
|
3421
5906
|
}, [currentDeptId, deptTreeData, loadAllWhenNoDepartment, mobile]);
|
|
3422
|
-
(0,
|
|
5907
|
+
(0, import_react14.useEffect)(() => {
|
|
3423
5908
|
setMemberPage(1);
|
|
3424
5909
|
}, [activeMemberKeyword, currentDeptId, dataSource, mobile]);
|
|
3425
|
-
const handleDepartmentSelect = (0,
|
|
5910
|
+
const handleDepartmentSelect = (0, import_react14.useCallback)((deptId) => {
|
|
3426
5911
|
const nextDeptId = String(deptId || "");
|
|
3427
5912
|
setCurrentDeptId(nextDeptId);
|
|
3428
5913
|
setMemberKeyword("");
|
|
3429
5914
|
setMemberPage(1);
|
|
3430
5915
|
setMemberReloadKey((current) => current + 1);
|
|
3431
5916
|
}, []);
|
|
3432
|
-
(0,
|
|
5917
|
+
(0, import_react14.useEffect)(() => {
|
|
3433
5918
|
let active = true;
|
|
3434
5919
|
const keyword = activeMemberKeyword;
|
|
3435
5920
|
if (hasStaticUserSource) {
|
|
@@ -3502,7 +5987,7 @@ function UserPickerPanel({
|
|
|
3502
5987
|
memberReloadKey,
|
|
3503
5988
|
staticUsers
|
|
3504
5989
|
]);
|
|
3505
|
-
const currentPath = (0,
|
|
5990
|
+
const currentPath = (0, import_react14.useMemo)(() => {
|
|
3506
5991
|
if (!currentDeptId) return [];
|
|
3507
5992
|
const path = [];
|
|
3508
5993
|
let cursor = currentDeptId;
|
|
@@ -3514,7 +5999,7 @@ function UserPickerPanel({
|
|
|
3514
5999
|
}
|
|
3515
6000
|
return path;
|
|
3516
6001
|
}, [currentDeptId, nodeMap, parentMap]);
|
|
3517
|
-
const mobileDepartments = (0,
|
|
6002
|
+
const mobileDepartments = (0, import_react14.useMemo)(() => {
|
|
3518
6003
|
const keyword = mobileKeyword.trim().toLowerCase();
|
|
3519
6004
|
if (keyword) {
|
|
3520
6005
|
return flatNodes.filter((item) => item.name.toLowerCase().includes(keyword)).map((item) => item.node);
|
|
@@ -3536,48 +6021,48 @@ function UserPickerPanel({
|
|
|
3536
6021
|
}
|
|
3537
6022
|
setSelected(checked ? [normalized] : []);
|
|
3538
6023
|
};
|
|
3539
|
-
const renderSelected = () => /* @__PURE__ */ (0,
|
|
3540
|
-
/* @__PURE__ */ (0,
|
|
3541
|
-
/* @__PURE__ */ (0,
|
|
6024
|
+
const renderSelected = () => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker-selected", children: [
|
|
6025
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-org-picker-selected-head", children: [
|
|
6026
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { children: [
|
|
3542
6027
|
"\u5DF2\u9009 ",
|
|
3543
6028
|
selected.length,
|
|
3544
6029
|
" \u4EBA"
|
|
3545
6030
|
] }),
|
|
3546
|
-
/* @__PURE__ */ (0,
|
|
6031
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: () => setSelected([]), disabled: !selected.length, children: "\u6E05\u7A7A" })
|
|
3547
6032
|
] }),
|
|
3548
|
-
selected.length ? /* @__PURE__ */ (0,
|
|
6033
|
+
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
6034
|
] });
|
|
3550
|
-
const renderMemberList = () => /* @__PURE__ */ (0,
|
|
3551
|
-
/* @__PURE__ */ (0,
|
|
3552
|
-
|
|
6035
|
+
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: [
|
|
6036
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "sy-user-picker-list", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6037
|
+
import_antd8.List,
|
|
3553
6038
|
{
|
|
3554
6039
|
dataSource: members,
|
|
3555
6040
|
locale: { emptyText: "\u6682\u65E0\u6210\u5458" },
|
|
3556
6041
|
renderItem: (user) => {
|
|
3557
6042
|
const id = getUserId(user);
|
|
3558
6043
|
const checked = selectedIds.includes(id);
|
|
3559
|
-
return /* @__PURE__ */ (0,
|
|
3560
|
-
/* @__PURE__ */ (0,
|
|
3561
|
-
|
|
6044
|
+
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: [
|
|
6045
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6046
|
+
import_antd8.Checkbox,
|
|
3562
6047
|
{
|
|
3563
6048
|
checked,
|
|
3564
6049
|
onChange: (event) => toggleUser(user, event.target.checked)
|
|
3565
6050
|
}
|
|
3566
6051
|
),
|
|
3567
|
-
/* @__PURE__ */ (0,
|
|
3568
|
-
/* @__PURE__ */ (0,
|
|
6052
|
+
/* @__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, {}) }),
|
|
6053
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("span", { children: getUserName(user) })
|
|
3569
6054
|
] }) }, id);
|
|
3570
6055
|
}
|
|
3571
6056
|
}
|
|
3572
6057
|
) }),
|
|
3573
|
-
/* @__PURE__ */ (0,
|
|
3574
|
-
/* @__PURE__ */ (0,
|
|
6058
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker-pagination", children: [
|
|
6059
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("span", { children: [
|
|
3575
6060
|
"\u5171 ",
|
|
3576
6061
|
memberTotal,
|
|
3577
6062
|
" \u4EBA"
|
|
3578
6063
|
] }),
|
|
3579
|
-
/* @__PURE__ */ (0,
|
|
3580
|
-
|
|
6064
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6065
|
+
import_antd8.Pagination,
|
|
3581
6066
|
{
|
|
3582
6067
|
size: "small",
|
|
3583
6068
|
current: memberPage,
|
|
@@ -3594,43 +6079,43 @@ function UserPickerPanel({
|
|
|
3594
6079
|
] })
|
|
3595
6080
|
] }) });
|
|
3596
6081
|
if (mobile) {
|
|
3597
|
-
return /* @__PURE__ */ (0,
|
|
3598
|
-
/* @__PURE__ */ (0,
|
|
3599
|
-
/* @__PURE__ */ (0,
|
|
3600
|
-
/* @__PURE__ */ (0,
|
|
3601
|
-
/* @__PURE__ */ (0,
|
|
6082
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker sy-user-picker-mobile", children: [
|
|
6083
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-org-picker-mobile-head", children: [
|
|
6084
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: onCancel, children: "\u53D6\u6D88" }),
|
|
6085
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("strong", { children: "\u9009\u62E9\u6210\u5458" }),
|
|
6086
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: () => onConfirm(selected), children: "\u786E\u5B9A" })
|
|
3602
6087
|
] }),
|
|
3603
|
-
MobileSearchBar ? /* @__PURE__ */ (0,
|
|
6088
|
+
MobileSearchBar ? /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3604
6089
|
MobileSearchBar,
|
|
3605
6090
|
{
|
|
3606
6091
|
placeholder: "\u641C\u7D22\u90E8\u95E8\u6216\u6210\u5458",
|
|
3607
6092
|
value: mobileKeyword,
|
|
3608
6093
|
onChange: setMobileKeyword
|
|
3609
6094
|
}
|
|
3610
|
-
) : /* @__PURE__ */ (0,
|
|
3611
|
-
/* @__PURE__ */ (0,
|
|
3612
|
-
/* @__PURE__ */ (0,
|
|
3613
|
-
currentPath.map((item) => /* @__PURE__ */ (0,
|
|
6095
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime11.jsx)("input", { value: mobileKeyword, onChange: (event) => setMobileKeyword(event.target.value) }),
|
|
6096
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-org-picker-breadcrumb", children: [
|
|
6097
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("button", { type: "button", onClick: () => handleDepartmentSelect(""), children: "\u901A\u8BAF\u5F55" }),
|
|
6098
|
+
currentPath.map((item) => /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("button", { type: "button", onClick: () => handleDepartmentSelect(item.id), children: [
|
|
3614
6099
|
"/ ",
|
|
3615
6100
|
item.name
|
|
3616
6101
|
] }, item.id))
|
|
3617
6102
|
] }),
|
|
3618
|
-
/* @__PURE__ */ (0,
|
|
3619
|
-
|
|
6103
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Spin, { spinning: treeLoading, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6104
|
+
import_antd8.List,
|
|
3620
6105
|
{
|
|
3621
6106
|
dataSource: mobileDepartments,
|
|
3622
6107
|
locale: { emptyText: null },
|
|
3623
6108
|
renderItem: (node) => {
|
|
3624
6109
|
const id = getDepartmentId(node);
|
|
3625
|
-
return /* @__PURE__ */ (0,
|
|
3626
|
-
|
|
6110
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6111
|
+
import_antd8.List.Item,
|
|
3627
6112
|
{
|
|
3628
6113
|
onClick: async () => {
|
|
3629
6114
|
await loadChildren(id);
|
|
3630
6115
|
handleDepartmentSelect(id);
|
|
3631
6116
|
setMobileKeyword("");
|
|
3632
6117
|
},
|
|
3633
|
-
children: /* @__PURE__ */ (0,
|
|
6118
|
+
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
6119
|
},
|
|
3635
6120
|
id
|
|
3636
6121
|
);
|
|
@@ -3645,21 +6130,21 @@ function UserPickerPanel({
|
|
|
3645
6130
|
const filteredTreeData = lowerDepartmentKeyword ? deptTreeData.filter(
|
|
3646
6131
|
(node) => getDepartmentName(node).toLowerCase().includes(lowerDepartmentKeyword)
|
|
3647
6132
|
) : deptTreeData;
|
|
3648
|
-
return /* @__PURE__ */ (0,
|
|
3649
|
-
/* @__PURE__ */ (0,
|
|
3650
|
-
/* @__PURE__ */ (0,
|
|
3651
|
-
/* @__PURE__ */ (0,
|
|
3652
|
-
|
|
6133
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker", children: [
|
|
6134
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker-main", children: [
|
|
6135
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker-depts", children: [
|
|
6136
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6137
|
+
import_antd8.Input,
|
|
3653
6138
|
{
|
|
3654
6139
|
allowClear: true,
|
|
3655
|
-
prefix: /* @__PURE__ */ (0,
|
|
6140
|
+
prefix: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons8.SearchOutlined, {}),
|
|
3656
6141
|
placeholder: "\u641C\u7D22\u90E8\u95E8",
|
|
3657
6142
|
value: departmentKeyword,
|
|
3658
6143
|
onChange: (event) => setDepartmentKeyword(event.target.value)
|
|
3659
6144
|
}
|
|
3660
6145
|
),
|
|
3661
|
-
/* @__PURE__ */ (0,
|
|
3662
|
-
|
|
6146
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Spin, { spinning: treeLoading, children: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6147
|
+
import_antd8.Tree,
|
|
3663
6148
|
{
|
|
3664
6149
|
selectedKeys: currentDeptId ? [currentDeptId] : [],
|
|
3665
6150
|
expandedKeys,
|
|
@@ -3671,12 +6156,12 @@ function UserPickerPanel({
|
|
|
3671
6156
|
}
|
|
3672
6157
|
) })
|
|
3673
6158
|
] }),
|
|
3674
|
-
/* @__PURE__ */ (0,
|
|
3675
|
-
displaySearch && /* @__PURE__ */ (0,
|
|
3676
|
-
|
|
6159
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsxs)("div", { className: "sy-user-picker-members", children: [
|
|
6160
|
+
displaySearch && /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6161
|
+
import_antd8.Input,
|
|
3677
6162
|
{
|
|
3678
6163
|
allowClear: true,
|
|
3679
|
-
prefix: /* @__PURE__ */ (0,
|
|
6164
|
+
prefix: /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_icons8.SearchOutlined, {}),
|
|
3680
6165
|
placeholder: "\u641C\u7D22\u6210\u5458",
|
|
3681
6166
|
value: memberKeyword,
|
|
3682
6167
|
onChange: (event) => setMemberKeyword(event.target.value)
|
|
@@ -3686,9 +6171,9 @@ function UserPickerPanel({
|
|
|
3686
6171
|
] }),
|
|
3687
6172
|
renderSelected()
|
|
3688
6173
|
] }),
|
|
3689
|
-
/* @__PURE__ */ (0,
|
|
3690
|
-
/* @__PURE__ */ (0,
|
|
3691
|
-
/* @__PURE__ */ (0,
|
|
6174
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)("div", { className: "sy-org-picker-footer", children: /* @__PURE__ */ (0, import_jsx_runtime11.jsxs)(import_antd8.Space, { children: [
|
|
6175
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Button, { onClick: onCancel, children: "\u53D6\u6D88" }),
|
|
6176
|
+
/* @__PURE__ */ (0, import_jsx_runtime11.jsx)(import_antd8.Button, { type: "primary", onClick: () => onConfirm(selected), children: "\u786E\u5B9A" })
|
|
3692
6177
|
] }) })
|
|
3693
6178
|
] });
|
|
3694
6179
|
}
|
|
@@ -3703,7 +6188,7 @@ function UserPicker({
|
|
|
3703
6188
|
onOpenChange(false);
|
|
3704
6189
|
onCancel();
|
|
3705
6190
|
};
|
|
3706
|
-
const panel = /* @__PURE__ */ (0,
|
|
6191
|
+
const panel = /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3707
6192
|
UserPickerPanel,
|
|
3708
6193
|
{
|
|
3709
6194
|
...panelProps,
|
|
@@ -3718,7 +6203,7 @@ function UserPicker({
|
|
|
3718
6203
|
if (mobile) {
|
|
3719
6204
|
const MobilePopup = getMobileComponent("Popup");
|
|
3720
6205
|
if (!MobilePopup) return open ? panel : null;
|
|
3721
|
-
return /* @__PURE__ */ (0,
|
|
6206
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
3722
6207
|
MobilePopup,
|
|
3723
6208
|
{
|
|
3724
6209
|
visible: open,
|
|
@@ -3729,8 +6214,8 @@ function UserPicker({
|
|
|
3729
6214
|
}
|
|
3730
6215
|
);
|
|
3731
6216
|
}
|
|
3732
|
-
return /* @__PURE__ */ (0,
|
|
3733
|
-
|
|
6217
|
+
return /* @__PURE__ */ (0, import_jsx_runtime11.jsx)(
|
|
6218
|
+
import_antd8.Modal,
|
|
3734
6219
|
{
|
|
3735
6220
|
title: "\u9009\u62E9\u6210\u5458",
|
|
3736
6221
|
open,
|
|
@@ -3744,7 +6229,7 @@ function UserPicker({
|
|
|
3744
6229
|
}
|
|
3745
6230
|
|
|
3746
6231
|
// packages/sdk/src/components/modules/InitiatorApproverSelector.tsx
|
|
3747
|
-
var
|
|
6232
|
+
var import_jsx_runtime12 = require("react/jsx-runtime");
|
|
3748
6233
|
var scopeText = {
|
|
3749
6234
|
all: "\u5168\u90E8\u6210\u5458",
|
|
3750
6235
|
members: "\u6307\u5B9A\u6210\u5458",
|
|
@@ -3778,19 +6263,19 @@ var RequirementSelect = ({
|
|
|
3778
6263
|
selectedUsers,
|
|
3779
6264
|
onChange
|
|
3780
6265
|
}) => {
|
|
3781
|
-
const [pickerOpen, setPickerOpen] = (0,
|
|
3782
|
-
const initialCandidates = (0,
|
|
6266
|
+
const [pickerOpen, setPickerOpen] = (0, import_react15.useState)(false);
|
|
6267
|
+
const initialCandidates = (0, import_react15.useMemo)(
|
|
3783
6268
|
() => (requirement.candidateUsers || []).map(normalizeCandidate).filter(Boolean),
|
|
3784
6269
|
[requirement.candidateUsers]
|
|
3785
6270
|
);
|
|
3786
|
-
const [optionsSource, setOptionsSource] = (0,
|
|
3787
|
-
const [loading, setLoading] = (0,
|
|
3788
|
-
(0,
|
|
6271
|
+
const [optionsSource, setOptionsSource] = (0, import_react15.useState)(initialCandidates);
|
|
6272
|
+
const [loading, setLoading] = (0, import_react15.useState)(false);
|
|
6273
|
+
(0, import_react15.useEffect)(() => {
|
|
3789
6274
|
setOptionsSource(
|
|
3790
6275
|
(current) => mergeUsers(initialCandidates, mergeUsers(current, selectedUsers))
|
|
3791
6276
|
);
|
|
3792
6277
|
}, [initialCandidates, selectedUsers]);
|
|
3793
|
-
const loadCandidates = (0,
|
|
6278
|
+
const loadCandidates = (0, import_react15.useCallback)(
|
|
3794
6279
|
async (keyword) => {
|
|
3795
6280
|
setLoading(true);
|
|
3796
6281
|
try {
|
|
@@ -3820,7 +6305,7 @@ var RequirementSelect = ({
|
|
|
3820
6305
|
)
|
|
3821
6306
|
);
|
|
3822
6307
|
} else if (initialCandidates.length === 0) {
|
|
3823
|
-
|
|
6308
|
+
import_antd9.message.error("\u52A0\u8F7D\u5BA1\u6279\u5019\u9009\u4EBA\u5931\u8D25");
|
|
3824
6309
|
}
|
|
3825
6310
|
} finally {
|
|
3826
6311
|
setLoading(false);
|
|
@@ -3828,12 +6313,12 @@ var RequirementSelect = ({
|
|
|
3828
6313
|
},
|
|
3829
6314
|
[api, appType, formUuid, initialCandidates.length, requirement.nodeId, requirement.scope]
|
|
3830
6315
|
);
|
|
3831
|
-
(0,
|
|
6316
|
+
(0, import_react15.useEffect)(() => {
|
|
3832
6317
|
if (requirement.scope !== "all" && open && formUuid && appType && requirement.nodeId) {
|
|
3833
6318
|
void loadCandidates();
|
|
3834
6319
|
}
|
|
3835
6320
|
}, [appType, formUuid, loadCandidates, open, requirement.nodeId, requirement.scope]);
|
|
3836
|
-
const options = (0,
|
|
6321
|
+
const options = (0, import_react15.useMemo)(
|
|
3837
6322
|
() => optionsSource.map((user) => ({
|
|
3838
6323
|
value: user.id,
|
|
3839
6324
|
label: getUserLabel(user)
|
|
@@ -3841,19 +6326,19 @@ var RequirementSelect = ({
|
|
|
3841
6326
|
[optionsSource]
|
|
3842
6327
|
);
|
|
3843
6328
|
if (requirement.scope === "all") {
|
|
3844
|
-
return /* @__PURE__ */ (0,
|
|
3845
|
-
/* @__PURE__ */ (0,
|
|
3846
|
-
/* @__PURE__ */ (0,
|
|
3847
|
-
/* @__PURE__ */ (0,
|
|
3848
|
-
/* @__PURE__ */ (0,
|
|
6329
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "rounded-lg border border-ant-border-secondary bg-ant-bg-container p-3", children: [
|
|
6330
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "mb-2 flex items-start justify-between gap-3", children: [
|
|
6331
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { children: [
|
|
6332
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Typography.Text, { strong: true, children: requirement.nodeName }),
|
|
6333
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "mt-1 text-xs text-ant-color-text-tertiary", children: [
|
|
3849
6334
|
"\u9009\u62E9\u8303\u56F4\uFF1A",
|
|
3850
6335
|
scopeText[requirement.scope] || "\u5168\u90E8\u6210\u5458"
|
|
3851
6336
|
] })
|
|
3852
6337
|
] }),
|
|
3853
|
-
/* @__PURE__ */ (0,
|
|
6338
|
+
/* @__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
6339
|
] }),
|
|
3855
|
-
selectedUsers.length > 0 ? /* @__PURE__ */ (0,
|
|
3856
|
-
/* @__PURE__ */ (0,
|
|
6340
|
+
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" }),
|
|
6341
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
3857
6342
|
UserPicker,
|
|
3858
6343
|
{
|
|
3859
6344
|
api,
|
|
@@ -3873,16 +6358,16 @@ var RequirementSelect = ({
|
|
|
3873
6358
|
)
|
|
3874
6359
|
] });
|
|
3875
6360
|
}
|
|
3876
|
-
return /* @__PURE__ */ (0,
|
|
3877
|
-
/* @__PURE__ */ (0,
|
|
3878
|
-
/* @__PURE__ */ (0,
|
|
3879
|
-
/* @__PURE__ */ (0,
|
|
6361
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "rounded-lg border border-ant-border-secondary bg-ant-bg-container p-3", children: [
|
|
6362
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "mb-2", children: [
|
|
6363
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Typography.Text, { strong: true, children: requirement.nodeName }),
|
|
6364
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsxs)("div", { className: "mt-1 text-xs text-ant-color-text-tertiary", children: [
|
|
3880
6365
|
"\u9009\u62E9\u8303\u56F4\uFF1A",
|
|
3881
6366
|
scopeText[requirement.scope] || "\u5168\u90E8\u6210\u5458"
|
|
3882
6367
|
] })
|
|
3883
6368
|
] }),
|
|
3884
|
-
/* @__PURE__ */ (0,
|
|
3885
|
-
|
|
6369
|
+
/* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
6370
|
+
import_antd9.Select,
|
|
3886
6371
|
{
|
|
3887
6372
|
mode: "multiple",
|
|
3888
6373
|
className: "w-full",
|
|
@@ -3893,7 +6378,7 @@ var RequirementSelect = ({
|
|
|
3893
6378
|
loading,
|
|
3894
6379
|
value: selectedUsers.map((user) => user.id),
|
|
3895
6380
|
options,
|
|
3896
|
-
notFoundContent: loading ? "\u52A0\u8F7D\u4E2D..." : /* @__PURE__ */ (0,
|
|
6381
|
+
notFoundContent: loading ? "\u52A0\u8F7D\u4E2D..." : /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_antd9.Empty, { image: import_antd9.Empty.PRESENTED_IMAGE_SIMPLE }),
|
|
3897
6382
|
onSearch: (keyword) => {
|
|
3898
6383
|
void loadCandidates(keyword);
|
|
3899
6384
|
},
|
|
@@ -3905,7 +6390,7 @@ var RequirementSelect = ({
|
|
|
3905
6390
|
}
|
|
3906
6391
|
}
|
|
3907
6392
|
),
|
|
3908
|
-
selectedUsers.length > 0 ? /* @__PURE__ */ (0,
|
|
6393
|
+
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
6394
|
] });
|
|
3910
6395
|
};
|
|
3911
6396
|
var InitiatorApproverSelector = ({
|
|
@@ -3918,9 +6403,9 @@ var InitiatorApproverSelector = ({
|
|
|
3918
6403
|
onOk,
|
|
3919
6404
|
onCancel
|
|
3920
6405
|
}) => {
|
|
3921
|
-
const [selected, setSelected] = (0,
|
|
3922
|
-
const wasOpenRef = (0,
|
|
3923
|
-
(0,
|
|
6406
|
+
const [selected, setSelected] = (0, import_react15.useState)({});
|
|
6407
|
+
const wasOpenRef = (0, import_react15.useRef)(false);
|
|
6408
|
+
(0, import_react15.useEffect)(() => {
|
|
3924
6409
|
if (open && !wasOpenRef.current) {
|
|
3925
6410
|
setSelected(value || EMPTY_SELECTED_MAP);
|
|
3926
6411
|
}
|
|
@@ -3929,8 +6414,8 @@ var InitiatorApproverSelector = ({
|
|
|
3929
6414
|
const missingNodes = requirements.filter(
|
|
3930
6415
|
(requirement) => !(selected[requirement.nodeId] || []).length
|
|
3931
6416
|
);
|
|
3932
|
-
return /* @__PURE__ */ (0,
|
|
3933
|
-
|
|
6417
|
+
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(
|
|
6418
|
+
import_antd9.Modal,
|
|
3934
6419
|
{
|
|
3935
6420
|
getContainer: false,
|
|
3936
6421
|
title: "\u9009\u62E9\u5BA1\u6279\u4EBA",
|
|
@@ -3941,13 +6426,13 @@ var InitiatorApproverSelector = ({
|
|
|
3941
6426
|
onCancel,
|
|
3942
6427
|
onOk: () => {
|
|
3943
6428
|
if (missingNodes.length > 0) {
|
|
3944
|
-
|
|
6429
|
+
import_antd9.message.error("\u8BF7\u4E3A\u6240\u6709\u53D1\u8D77\u4EBA\u81EA\u9009\u8282\u70B9\u9009\u62E9\u5BA1\u6279\u4EBA");
|
|
3945
6430
|
return;
|
|
3946
6431
|
}
|
|
3947
6432
|
onOk(selected);
|
|
3948
6433
|
},
|
|
3949
6434
|
destroyOnHidden: true,
|
|
3950
|
-
children: /* @__PURE__ */ (0,
|
|
6435
|
+
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
6436
|
RequirementSelect,
|
|
3952
6437
|
{
|
|
3953
6438
|
open,
|
|
@@ -3965,7 +6450,7 @@ var InitiatorApproverSelector = ({
|
|
|
3965
6450
|
};
|
|
3966
6451
|
|
|
3967
6452
|
// packages/sdk/src/runtime/react/workflow.tsx
|
|
3968
|
-
var
|
|
6453
|
+
var import_jsx_runtime13 = require("react/jsx-runtime");
|
|
3969
6454
|
var getError = (error) => error instanceof Error ? error : new Error(String(error || "\u6D41\u7A0B\u80FD\u529B\u89E3\u6790\u5931\u8D25"));
|
|
3970
6455
|
var normalizeCapabilities = (value) => {
|
|
3971
6456
|
const raw = value || {};
|
|
@@ -3978,20 +6463,20 @@ var normalizeCapabilities = (value) => {
|
|
|
3978
6463
|
function useProcessCapabilities(options) {
|
|
3979
6464
|
const { enabled = true, refreshKey, onError, ...params } = options;
|
|
3980
6465
|
const sdk = usePageSdk();
|
|
3981
|
-
const [capabilities, setCapabilities] = (0,
|
|
6466
|
+
const [capabilities, setCapabilities] = (0, import_react16.useState)(
|
|
3982
6467
|
null
|
|
3983
6468
|
);
|
|
3984
|
-
const [loading, setLoading] = (0,
|
|
3985
|
-
const [error, setError] = (0,
|
|
3986
|
-
const mountedRef = (0,
|
|
6469
|
+
const [loading, setLoading] = (0, import_react16.useState)(false);
|
|
6470
|
+
const [error, setError] = (0, import_react16.useState)(null);
|
|
6471
|
+
const mountedRef = (0, import_react16.useRef)(true);
|
|
3987
6472
|
const paramsKey = JSON.stringify({ ...params, refreshKey });
|
|
3988
|
-
(0,
|
|
6473
|
+
(0, import_react16.useEffect)(() => {
|
|
3989
6474
|
mountedRef.current = true;
|
|
3990
6475
|
return () => {
|
|
3991
6476
|
mountedRef.current = false;
|
|
3992
6477
|
};
|
|
3993
6478
|
}, []);
|
|
3994
|
-
const refresh = (0,
|
|
6479
|
+
const refresh = (0, import_react16.useCallback)(async () => {
|
|
3995
6480
|
if (!enabled) return capabilities;
|
|
3996
6481
|
setLoading(true);
|
|
3997
6482
|
setError(null);
|
|
@@ -4017,7 +6502,7 @@ function useProcessCapabilities(options) {
|
|
|
4017
6502
|
}
|
|
4018
6503
|
}
|
|
4019
6504
|
}, [capabilities, enabled, onError, paramsKey, sdk]);
|
|
4020
|
-
(0,
|
|
6505
|
+
(0, import_react16.useEffect)(() => {
|
|
4021
6506
|
if (!enabled) return;
|
|
4022
6507
|
void refresh();
|
|
4023
6508
|
}, [enabled, paramsKey, refresh]);
|
|
@@ -4042,8 +6527,8 @@ var requireValue = (value, message3) => {
|
|
|
4042
6527
|
function useProcessActions(options) {
|
|
4043
6528
|
const { capabilities, formUuid, appType, getFormValues, onActionComplete } = options;
|
|
4044
6529
|
const sdk = usePageSdk();
|
|
4045
|
-
const [loadingAction, setLoadingAction] = (0,
|
|
4046
|
-
const buildUpdateFormDataJson = (0,
|
|
6530
|
+
const [loadingAction, setLoadingAction] = (0, import_react16.useState)(null);
|
|
6531
|
+
const buildUpdateFormDataJson = (0, import_react16.useCallback)(
|
|
4047
6532
|
(input) => {
|
|
4048
6533
|
if (input?.updateFormDataJson !== void 0) return input.updateFormDataJson;
|
|
4049
6534
|
const values = getFormValues?.();
|
|
@@ -4051,7 +6536,7 @@ function useProcessActions(options) {
|
|
|
4051
6536
|
},
|
|
4052
6537
|
[getFormValues]
|
|
4053
6538
|
);
|
|
4054
|
-
const executeOperation = (0,
|
|
6539
|
+
const executeOperation = (0, import_react16.useCallback)(
|
|
4055
6540
|
async (operation, input = {}) => {
|
|
4056
6541
|
if (!operation.enabled) return false;
|
|
4057
6542
|
setLoadingAction(operation.key);
|
|
@@ -4161,7 +6646,7 @@ function useProcessActions(options) {
|
|
|
4161
6646
|
sdk
|
|
4162
6647
|
]
|
|
4163
6648
|
);
|
|
4164
|
-
const execute = (0,
|
|
6649
|
+
const execute = (0, import_react16.useCallback)(
|
|
4165
6650
|
async (action, input) => {
|
|
4166
6651
|
const operation = (capabilities?.operations || []).find(
|
|
4167
6652
|
(item) => item.key === action
|
|
@@ -4204,12 +6689,12 @@ var actionTone = (key) => {
|
|
|
4204
6689
|
return "default";
|
|
4205
6690
|
};
|
|
4206
6691
|
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,
|
|
6692
|
+
if (key === "startProcess" || key === "approve") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.CheckOutlined, {});
|
|
6693
|
+
if (key === "reject") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.CloseOutlined, {});
|
|
6694
|
+
if (key === "transfer" || key === "adminTransfer") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.SwapOutlined, {});
|
|
6695
|
+
if (key === "return" || key === "withdraw") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.RollbackOutlined, {});
|
|
6696
|
+
if (key === "save") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.SaveOutlined, {});
|
|
6697
|
+
if (key === "retryException" || key === "callback") return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_icons9.ReloadOutlined, {});
|
|
4213
6698
|
return void 0;
|
|
4214
6699
|
};
|
|
4215
6700
|
var getModalTitle = (key) => {
|
|
@@ -4235,8 +6720,8 @@ var ProcessActionBar = ({
|
|
|
4235
6720
|
maxWidth,
|
|
4236
6721
|
position = "sticky"
|
|
4237
6722
|
}) => {
|
|
4238
|
-
const [form] =
|
|
4239
|
-
const [activeOperation, setActiveOperation] = (0,
|
|
6723
|
+
const [form] = import_antd10.Form.useForm();
|
|
6724
|
+
const [activeOperation, setActiveOperation] = (0, import_react16.useState)(null);
|
|
4240
6725
|
const autoCapabilities = useProcessCapabilities({
|
|
4241
6726
|
...capabilityParams || {},
|
|
4242
6727
|
enabled: Boolean(capabilityParams) && capabilityParams?.enabled !== false
|
|
@@ -4271,7 +6756,7 @@ var ProcessActionBar = ({
|
|
|
4271
6756
|
}
|
|
4272
6757
|
void actions.executeOperation(operation);
|
|
4273
6758
|
};
|
|
4274
|
-
const actionConfigs = (0,
|
|
6759
|
+
const actionConfigs = (0, import_react16.useMemo)(
|
|
4275
6760
|
() => operations.map((operation) => ({
|
|
4276
6761
|
key: operation.key,
|
|
4277
6762
|
label: operation.label || operation.key,
|
|
@@ -4303,8 +6788,8 @@ var ProcessActionBar = ({
|
|
|
4303
6788
|
label: String(node.nodeName || node.name || node.label || value)
|
|
4304
6789
|
};
|
|
4305
6790
|
});
|
|
4306
|
-
return /* @__PURE__ */ (0,
|
|
4307
|
-
/* @__PURE__ */ (0,
|
|
6791
|
+
return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
|
|
6792
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
4308
6793
|
StickyActionBar,
|
|
4309
6794
|
{
|
|
4310
6795
|
actions: actionConfigs,
|
|
@@ -4316,8 +6801,8 @@ var ProcessActionBar = ({
|
|
|
4316
6801
|
position
|
|
4317
6802
|
}
|
|
4318
6803
|
),
|
|
4319
|
-
/* @__PURE__ */ (0,
|
|
4320
|
-
|
|
6804
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
6805
|
+
import_antd10.Modal,
|
|
4321
6806
|
{
|
|
4322
6807
|
getContainer: false,
|
|
4323
6808
|
title: modalKey ? getModalTitle(modalKey) : "\u6D41\u7A0B\u64CD\u4F5C",
|
|
@@ -4333,27 +6818,27 @@ var ProcessActionBar = ({
|
|
|
4333
6818
|
form.resetFields();
|
|
4334
6819
|
},
|
|
4335
6820
|
destroyOnHidden: true,
|
|
4336
|
-
children: /* @__PURE__ */ (0,
|
|
4337
|
-
(modalKey === "transfer" || modalKey === "adminTransfer") && /* @__PURE__ */ (0,
|
|
4338
|
-
|
|
6821
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_antd10.Form, { form, layout: "vertical", children: [
|
|
6822
|
+
(modalKey === "transfer" || modalKey === "adminTransfer") && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
6823
|
+
import_antd10.Form.Item,
|
|
4339
6824
|
{
|
|
4340
6825
|
name: "newAssignee",
|
|
4341
6826
|
label: "\u63A5\u6536\u4EBA",
|
|
4342
6827
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u63A5\u6536\u4EBA\u7528\u6237ID" }],
|
|
4343
|
-
children: /* @__PURE__ */ (0,
|
|
6828
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_antd10.Input, { placeholder: "\u8BF7\u8F93\u5165\u7528\u6237ID" })
|
|
4344
6829
|
}
|
|
4345
6830
|
),
|
|
4346
|
-
modalKey === "return" && /* @__PURE__ */ (0,
|
|
4347
|
-
|
|
6831
|
+
modalKey === "return" && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
6832
|
+
import_antd10.Form.Item,
|
|
4348
6833
|
{
|
|
4349
6834
|
name: "targetNodeId",
|
|
4350
6835
|
label: "\u9000\u56DE\u8282\u70B9",
|
|
4351
6836
|
rules: [{ required: true, message: "\u8BF7\u9009\u62E9\u9000\u56DE\u8282\u70B9" }],
|
|
4352
|
-
children: /* @__PURE__ */ (0,
|
|
6837
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_antd10.Select, { placeholder: "\u8BF7\u9009\u62E9\u9000\u56DE\u8282\u70B9", options: returnOptions })
|
|
4353
6838
|
}
|
|
4354
6839
|
),
|
|
4355
|
-
/* @__PURE__ */ (0,
|
|
4356
|
-
|
|
6840
|
+
/* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
6841
|
+
import_antd10.Form.Item,
|
|
4357
6842
|
{
|
|
4358
6843
|
name: modalKey === "reject" || modalKey === "resubmit" ? "comments" : "reason",
|
|
4359
6844
|
label: modalKey === "reject" ? "\u62D2\u7EDD\u7406\u7531" : modalKey === "resubmit" ? "\u63D0\u4EA4\u610F\u89C1" : "\u8BF4\u660E",
|
|
@@ -4363,7 +6848,7 @@ var ProcessActionBar = ({
|
|
|
4363
6848
|
message: "\u8BF7\u586B\u5199\u8BF4\u660E"
|
|
4364
6849
|
}
|
|
4365
6850
|
],
|
|
4366
|
-
children: /* @__PURE__ */ (0,
|
|
6851
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_antd10.Input.TextArea, { rows: 4, maxLength: 500, showCount: true })
|
|
4367
6852
|
}
|
|
4368
6853
|
)
|
|
4369
6854
|
] })
|
|
@@ -4375,7 +6860,7 @@ var ProcessTimeline = ({
|
|
|
4375
6860
|
capabilities,
|
|
4376
6861
|
tasks,
|
|
4377
6862
|
...props
|
|
4378
|
-
}) => /* @__PURE__ */ (0,
|
|
6863
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
|
|
4379
6864
|
ApprovalTimeline,
|
|
4380
6865
|
{
|
|
4381
6866
|
...props,
|
|
@@ -4385,7 +6870,7 @@ var ProcessTimeline = ({
|
|
|
4385
6870
|
var ProcessPreviewPanel = ProcessPreview;
|
|
4386
6871
|
|
|
4387
6872
|
// packages/sdk/src/runtime/react/openxiangdaProvider.tsx
|
|
4388
|
-
var
|
|
6873
|
+
var import_react18 = require("react");
|
|
4389
6874
|
|
|
4390
6875
|
// packages/sdk/src/runtime/core/fetch.ts
|
|
4391
6876
|
var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
|
|
@@ -4421,24 +6906,24 @@ var createBoundFetch = (fetchImpl) => {
|
|
|
4421
6906
|
};
|
|
4422
6907
|
|
|
4423
6908
|
// packages/sdk/src/runtime/host/browserHost.ts
|
|
4424
|
-
var
|
|
4425
|
-
var getDefaultServicePrefix = () => typeof window !== "undefined" ?
|
|
6909
|
+
var trimTrailingSlash2 = (value) => value.replace(/\/+$/, "");
|
|
6910
|
+
var getDefaultServicePrefix = () => typeof window !== "undefined" ? trimTrailingSlash2(window.__OPENXIANGDA_SERVICE_PREFIX__ || "/service") : "/service";
|
|
4426
6911
|
var joinServicePath = (servicePrefix, path) => {
|
|
4427
6912
|
if (/^https?:\/\//i.test(path)) return path;
|
|
4428
|
-
const normalizedPrefix =
|
|
6913
|
+
const normalizedPrefix = trimTrailingSlash2(servicePrefix || "/service");
|
|
4429
6914
|
if (path.startsWith(normalizedPrefix)) return path;
|
|
4430
6915
|
return `${normalizedPrefix}${path.startsWith("/") ? path : `/${path}`}`;
|
|
4431
6916
|
};
|
|
4432
|
-
var
|
|
6917
|
+
var appendQuery2 = (url, query) => {
|
|
4433
6918
|
if (!query) return url;
|
|
4434
6919
|
return `${url}${url.includes("?") ? "&" : "?"}${query}`;
|
|
4435
6920
|
};
|
|
4436
|
-
var
|
|
6921
|
+
var normalizeMethod3 = (method) => {
|
|
4437
6922
|
const value = String(method || "get").toUpperCase();
|
|
4438
6923
|
return ["GET", "POST", "PUT", "DELETE", "PATCH"].includes(value) ? value : "GET";
|
|
4439
6924
|
};
|
|
4440
6925
|
var shouldRetryTransportRequest = (payload) => {
|
|
4441
|
-
const method =
|
|
6926
|
+
const method = normalizeMethod3(payload?.method);
|
|
4442
6927
|
if (method === "GET") return true;
|
|
4443
6928
|
const path = String(payload?.path || "").split("?")[0];
|
|
4444
6929
|
return method === "POST" && path === "/workflow/capabilities/resolve";
|
|
@@ -4448,7 +6933,7 @@ var normalizeEnvelopeCode2 = (value, fallback) => {
|
|
|
4448
6933
|
const normalized = Number(value);
|
|
4449
6934
|
return Number.isFinite(normalized) ? normalized : String(value);
|
|
4450
6935
|
};
|
|
4451
|
-
var
|
|
6936
|
+
var isSuccessCode4 = (value) => {
|
|
4452
6937
|
if (value === void 0 || value === null || value === "") return true;
|
|
4453
6938
|
const normalized = Number(value);
|
|
4454
6939
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -4463,7 +6948,7 @@ var parseJsonResponse = async (response) => {
|
|
|
4463
6948
|
const code = normalizeEnvelopeCode2(payload.code, response.status);
|
|
4464
6949
|
return {
|
|
4465
6950
|
code,
|
|
4466
|
-
success: payload.success !== false &&
|
|
6951
|
+
success: payload.success !== false && isSuccessCode4(code),
|
|
4467
6952
|
message: payload.message,
|
|
4468
6953
|
result: payload.result ?? payload.data ?? null,
|
|
4469
6954
|
data: payload.data,
|
|
@@ -4486,7 +6971,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4486
6971
|
if (!payload?.path) {
|
|
4487
6972
|
throw new Error("transport.request \u9700\u8981 path");
|
|
4488
6973
|
}
|
|
4489
|
-
const url =
|
|
6974
|
+
const url = appendQuery2(joinServicePath(servicePrefix, payload.path), payload.query);
|
|
4490
6975
|
const headers = new Headers(payload.headers);
|
|
4491
6976
|
let body;
|
|
4492
6977
|
if (payload.body !== void 0) {
|
|
@@ -4498,7 +6983,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4498
6983
|
}
|
|
4499
6984
|
}
|
|
4500
6985
|
const response = await fetchWithTransientRetry(fetchImpl, url, {
|
|
4501
|
-
method:
|
|
6986
|
+
method: normalizeMethod3(payload.method),
|
|
4502
6987
|
headers,
|
|
4503
6988
|
body,
|
|
4504
6989
|
credentials: "include"
|
|
@@ -4511,7 +6996,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4511
6996
|
if (!payload?.path) {
|
|
4512
6997
|
throw new Error("transport.download \u9700\u8981 path");
|
|
4513
6998
|
}
|
|
4514
|
-
const url =
|
|
6999
|
+
const url = appendQuery2(joinServicePath(servicePrefix, payload.path), payload.query);
|
|
4515
7000
|
const headers = new Headers(payload.headers);
|
|
4516
7001
|
let body;
|
|
4517
7002
|
if (payload.body !== void 0) {
|
|
@@ -4523,7 +7008,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4523
7008
|
}
|
|
4524
7009
|
}
|
|
4525
7010
|
const response = await fetchImpl(url, {
|
|
4526
|
-
method:
|
|
7011
|
+
method: normalizeMethod3(payload.method),
|
|
4527
7012
|
headers,
|
|
4528
7013
|
body,
|
|
4529
7014
|
credentials: "include"
|
|
@@ -4610,9 +7095,9 @@ var createBrowserPageContext = (bootstrap, options = {}) => {
|
|
|
4610
7095
|
};
|
|
4611
7096
|
|
|
4612
7097
|
// packages/sdk/src/runtime/react/auth.tsx
|
|
4613
|
-
var
|
|
4614
|
-
var
|
|
4615
|
-
var
|
|
7098
|
+
var import_react17 = require("react");
|
|
7099
|
+
var import_antd11 = require("antd");
|
|
7100
|
+
var import_icons10 = require("@ant-design/icons");
|
|
4616
7101
|
|
|
4617
7102
|
// packages/sdk/src/runtime/core/auth.ts
|
|
4618
7103
|
var AuthClientError = class extends Error {
|
|
@@ -4682,7 +7167,7 @@ var createAuthClient = ({
|
|
|
4682
7167
|
const payload = await readPayload(response);
|
|
4683
7168
|
const code = getRecordValue(payload, "code");
|
|
4684
7169
|
const success = getRecordValue(payload, "success");
|
|
4685
|
-
if (!response.ok || success === false || !
|
|
7170
|
+
if (!response.ok || success === false || !isSuccessCode5(code)) {
|
|
4686
7171
|
throw new AuthClientError(
|
|
4687
7172
|
String(getRecordValue(payload, "message") || `Auth request failed: ${response.status}`),
|
|
4688
7173
|
{
|
|
@@ -4761,7 +7246,7 @@ var readNumber = (value) => {
|
|
|
4761
7246
|
const numberValue = Number(value);
|
|
4762
7247
|
return Number.isFinite(numberValue) ? numberValue : void 0;
|
|
4763
7248
|
};
|
|
4764
|
-
var
|
|
7249
|
+
var isSuccessCode5 = (code) => {
|
|
4765
7250
|
if (code === void 0 || code === null || code === "") return true;
|
|
4766
7251
|
const normalized = Number(code);
|
|
4767
7252
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -4791,10 +7276,10 @@ var resolveLoginUrl = (appType, {
|
|
|
4791
7276
|
var getCurrentHref2 = () => typeof window === "undefined" ? "" : window.location.href;
|
|
4792
7277
|
|
|
4793
7278
|
// packages/sdk/src/runtime/react/auth.tsx
|
|
4794
|
-
var
|
|
7279
|
+
var import_jsx_runtime14 = require("react/jsx-runtime");
|
|
4795
7280
|
var useAuth = (options = {}) => {
|
|
4796
7281
|
const runtime = useOpenXiangda();
|
|
4797
|
-
const client = (0,
|
|
7282
|
+
const client = (0, import_react17.useMemo)(
|
|
4798
7283
|
() => createAuthClient({
|
|
4799
7284
|
appType: options.appType || runtime.appType,
|
|
4800
7285
|
servicePrefix: options.servicePrefix || runtime.servicePrefix,
|
|
@@ -4809,7 +7294,7 @@ var useAuth = (options = {}) => {
|
|
|
4809
7294
|
runtime.servicePrefix
|
|
4810
7295
|
]
|
|
4811
7296
|
);
|
|
4812
|
-
return (0,
|
|
7297
|
+
return (0, import_react17.useMemo)(
|
|
4813
7298
|
() => ({
|
|
4814
7299
|
client,
|
|
4815
7300
|
getMethods: client.getMethods,
|
|
@@ -4829,12 +7314,12 @@ var useAuth = (options = {}) => {
|
|
|
4829
7314
|
};
|
|
4830
7315
|
var useLoginMethods = (options = {}) => {
|
|
4831
7316
|
const auth = useAuth(options);
|
|
4832
|
-
const [state, setState] = (0,
|
|
7317
|
+
const [state, setState] = (0, import_react17.useState)({
|
|
4833
7318
|
data: null,
|
|
4834
7319
|
loading: true,
|
|
4835
7320
|
error: null
|
|
4836
7321
|
});
|
|
4837
|
-
const reload = (0,
|
|
7322
|
+
const reload = (0, import_react17.useCallback)(async () => {
|
|
4838
7323
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
4839
7324
|
try {
|
|
4840
7325
|
const data = await auth.getMethods();
|
|
@@ -4847,7 +7332,7 @@ var useLoginMethods = (options = {}) => {
|
|
|
4847
7332
|
});
|
|
4848
7333
|
}
|
|
4849
7334
|
}, [auth]);
|
|
4850
|
-
(0,
|
|
7335
|
+
(0, import_react17.useEffect)(() => {
|
|
4851
7336
|
let disposed = false;
|
|
4852
7337
|
const run = async () => {
|
|
4853
7338
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
@@ -4889,19 +7374,19 @@ var LoginPage = ({
|
|
|
4889
7374
|
const runtime = useOpenXiangda();
|
|
4890
7375
|
const auth = useAuth(authOptions);
|
|
4891
7376
|
const methodsState = useLoginMethods(authOptions);
|
|
4892
|
-
const [passwordForm] =
|
|
4893
|
-
const [phoneForm] =
|
|
4894
|
-
const [activeMethod, setActiveMethod] = (0,
|
|
7377
|
+
const [passwordForm] = import_antd11.Form.useForm();
|
|
7378
|
+
const [phoneForm] = import_antd11.Form.useForm();
|
|
7379
|
+
const [activeMethod, setActiveMethod] = (0, import_react17.useState)(
|
|
4895
7380
|
defaultMethod || "password"
|
|
4896
7381
|
);
|
|
4897
|
-
const [phonePurpose, setPhonePurpose] = (0,
|
|
7382
|
+
const [phonePurpose, setPhonePurpose] = (0, import_react17.useState)(
|
|
4898
7383
|
"login"
|
|
4899
7384
|
);
|
|
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,
|
|
7385
|
+
const [phoneChallengeId, setPhoneChallengeId] = (0, import_react17.useState)("");
|
|
7386
|
+
const [passwordChallenge, setPasswordChallenge] = (0, import_react17.useState)(null);
|
|
7387
|
+
const [submitting, setSubmitting] = (0, import_react17.useState)(false);
|
|
7388
|
+
const [sendingCode, setSendingCode] = (0, import_react17.useState)(false);
|
|
7389
|
+
const [error, setError] = (0, import_react17.useState)(null);
|
|
4905
7390
|
const methods = methodsState.methods.filter((method) => method.enabled !== false);
|
|
4906
7391
|
const passwordMethod = findMethod(methods, "password");
|
|
4907
7392
|
const phoneMethod = findMethod(methods, "phone_code");
|
|
@@ -4909,16 +7394,16 @@ var LoginPage = ({
|
|
|
4909
7394
|
const ssoMethod = findMethod(methods, "sso");
|
|
4910
7395
|
const guestMethod = findMethod(methods, "guest");
|
|
4911
7396
|
const allowRegister = methodsState.data?.registration?.mode !== "reject";
|
|
4912
|
-
const tabItems = (0,
|
|
7397
|
+
const tabItems = (0, import_react17.useMemo)(() => {
|
|
4913
7398
|
const items = [];
|
|
4914
7399
|
if (passwordMethod) {
|
|
4915
7400
|
items.push({
|
|
4916
7401
|
key: "password",
|
|
4917
|
-
label: /* @__PURE__ */ (0,
|
|
4918
|
-
/* @__PURE__ */ (0,
|
|
4919
|
-
/* @__PURE__ */ (0,
|
|
7402
|
+
label: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Space, { size: 6, children: [
|
|
7403
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.UserOutlined, {}),
|
|
7404
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: passwordMethod.label || "\u8D26\u53F7\u5BC6\u7801" })
|
|
4920
7405
|
] }),
|
|
4921
|
-
children: /* @__PURE__ */ (0,
|
|
7406
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
4922
7407
|
PasswordLoginForm,
|
|
4923
7408
|
{
|
|
4924
7409
|
challenge: passwordChallenge,
|
|
@@ -4960,11 +7445,11 @@ var LoginPage = ({
|
|
|
4960
7445
|
if (phoneMethod) {
|
|
4961
7446
|
items.push({
|
|
4962
7447
|
key: "phone_code",
|
|
4963
|
-
label: /* @__PURE__ */ (0,
|
|
4964
|
-
/* @__PURE__ */ (0,
|
|
4965
|
-
/* @__PURE__ */ (0,
|
|
7448
|
+
label: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Space, { size: 6, children: [
|
|
7449
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.MobileOutlined, {}),
|
|
7450
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)("span", { children: phoneMethod.label || "\u624B\u673A\u53F7" })
|
|
4966
7451
|
] }),
|
|
4967
|
-
children: /* @__PURE__ */ (0,
|
|
7452
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
4968
7453
|
PhoneCodeLoginForm,
|
|
4969
7454
|
{
|
|
4970
7455
|
allowRegister,
|
|
@@ -5028,7 +7513,7 @@ var LoginPage = ({
|
|
|
5028
7513
|
sendingCode,
|
|
5029
7514
|
submitting
|
|
5030
7515
|
]);
|
|
5031
|
-
(0,
|
|
7516
|
+
(0, import_react17.useEffect)(() => {
|
|
5032
7517
|
const firstKey = tabItems[0]?.key;
|
|
5033
7518
|
if (firstKey && !tabItems.some((item) => item.key === activeMethod)) {
|
|
5034
7519
|
setActiveMethod(firstKey);
|
|
@@ -5103,7 +7588,7 @@ var LoginPage = ({
|
|
|
5103
7588
|
);
|
|
5104
7589
|
}
|
|
5105
7590
|
}
|
|
5106
|
-
return /* @__PURE__ */ (0,
|
|
7591
|
+
return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
5107
7592
|
"div",
|
|
5108
7593
|
{
|
|
5109
7594
|
className,
|
|
@@ -5115,8 +7600,8 @@ var LoginPage = ({
|
|
|
5115
7600
|
background: "#f6f8fb",
|
|
5116
7601
|
...style
|
|
5117
7602
|
},
|
|
5118
|
-
children: /* @__PURE__ */ (0,
|
|
5119
|
-
|
|
7603
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7604
|
+
import_antd11.Card,
|
|
5120
7605
|
{
|
|
5121
7606
|
style: {
|
|
5122
7607
|
width: "min(100%, 420px)",
|
|
@@ -5124,54 +7609,54 @@ var LoginPage = ({
|
|
|
5124
7609
|
boxShadow: "0 16px 48px rgba(15, 23, 42, 0.10)"
|
|
5125
7610
|
},
|
|
5126
7611
|
styles: { body: { padding: 28 } },
|
|
5127
|
-
children: /* @__PURE__ */ (0,
|
|
5128
|
-
/* @__PURE__ */ (0,
|
|
5129
|
-
/* @__PURE__ */ (0,
|
|
5130
|
-
subtitle ? /* @__PURE__ */ (0,
|
|
7612
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Space, { direction: "vertical", size: 20, style: { width: "100%" }, children: [
|
|
7613
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)("div", { children: [
|
|
7614
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Typography.Title, { level: 3, style: { margin: 0 }, children: title || "\u5E94\u7528\u767B\u5F55" }),
|
|
7615
|
+
subtitle ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Typography.Text, { type: "secondary", children: subtitle }) : null
|
|
5131
7616
|
] }),
|
|
5132
|
-
methodsState.error ? /* @__PURE__ */ (0,
|
|
5133
|
-
|
|
7617
|
+
methodsState.error ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7618
|
+
import_antd11.Alert,
|
|
5134
7619
|
{
|
|
5135
7620
|
showIcon: true,
|
|
5136
7621
|
type: "error",
|
|
5137
7622
|
message: methodsState.error.message
|
|
5138
7623
|
}
|
|
5139
7624
|
) : null,
|
|
5140
|
-
error ? /* @__PURE__ */ (0,
|
|
5141
|
-
methodsState.loading ? /* @__PURE__ */ (0,
|
|
5142
|
-
|
|
7625
|
+
error ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Alert, { showIcon: true, type: "error", message: error }) : null,
|
|
7626
|
+
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)(
|
|
7627
|
+
import_antd11.Tabs,
|
|
5143
7628
|
{
|
|
5144
7629
|
activeKey: activeMethod,
|
|
5145
7630
|
items: tabItems,
|
|
5146
7631
|
onChange: setActiveMethod
|
|
5147
7632
|
}
|
|
5148
|
-
) : /* @__PURE__ */ (0,
|
|
5149
|
-
/* @__PURE__ */ (0,
|
|
5150
|
-
dingtalkMethod ? /* @__PURE__ */ (0,
|
|
5151
|
-
|
|
7633
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Empty, { description: "\u672A\u542F\u7528\u767B\u5F55\u65B9\u5F0F" }),
|
|
7634
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Space, { direction: "vertical", size: 10, style: { width: "100%" }, children: [
|
|
7635
|
+
dingtalkMethod ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7636
|
+
import_antd11.Button,
|
|
5152
7637
|
{
|
|
5153
7638
|
block: true,
|
|
5154
|
-
icon: /* @__PURE__ */ (0,
|
|
7639
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.QrcodeOutlined, {}),
|
|
5155
7640
|
loading: submitting,
|
|
5156
7641
|
onClick: handleDingTalkLogin,
|
|
5157
7642
|
children: dingtalkMethod.label || "\u9489\u9489\u514D\u767B"
|
|
5158
7643
|
}
|
|
5159
7644
|
) : null,
|
|
5160
|
-
ssoMethod ? /* @__PURE__ */ (0,
|
|
5161
|
-
|
|
7645
|
+
ssoMethod ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7646
|
+
import_antd11.Button,
|
|
5162
7647
|
{
|
|
5163
7648
|
block: true,
|
|
5164
|
-
icon: /* @__PURE__ */ (0,
|
|
7649
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.SafetyCertificateOutlined, {}),
|
|
5165
7650
|
loading: submitting,
|
|
5166
7651
|
onClick: handleSsoLogin,
|
|
5167
7652
|
children: ssoMethod.label || "SSO \u767B\u5F55"
|
|
5168
7653
|
}
|
|
5169
7654
|
) : null,
|
|
5170
|
-
guestMethod ? /* @__PURE__ */ (0,
|
|
5171
|
-
|
|
7655
|
+
guestMethod ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7656
|
+
import_antd11.Button,
|
|
5172
7657
|
{
|
|
5173
7658
|
block: true,
|
|
5174
|
-
icon: /* @__PURE__ */ (0,
|
|
7659
|
+
icon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_icons10.LoginOutlined, {}),
|
|
5175
7660
|
loading: submitting,
|
|
5176
7661
|
onClick: handleGuestLogin,
|
|
5177
7662
|
children: guestMethod.label || "\u8BBF\u5BA2\u8BBF\u95EE"
|
|
@@ -5184,28 +7669,28 @@ var LoginPage = ({
|
|
|
5184
7669
|
}
|
|
5185
7670
|
);
|
|
5186
7671
|
};
|
|
5187
|
-
var PasswordLoginForm = ({ challenge, form, loading, onFinish }) => /* @__PURE__ */ (0,
|
|
5188
|
-
/* @__PURE__ */ (0,
|
|
5189
|
-
|
|
7672
|
+
var PasswordLoginForm = ({ challenge, form, loading, onFinish }) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Form, { form, layout: "vertical", requiredMark: false, onFinish, children: [
|
|
7673
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7674
|
+
import_antd11.Form.Item,
|
|
5190
7675
|
{
|
|
5191
7676
|
label: "\u8D26\u53F7",
|
|
5192
7677
|
name: "username",
|
|
5193
7678
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u8D26\u53F7" }],
|
|
5194
|
-
children: /* @__PURE__ */ (0,
|
|
7679
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Input, { autoComplete: "username" })
|
|
5195
7680
|
}
|
|
5196
7681
|
),
|
|
5197
|
-
/* @__PURE__ */ (0,
|
|
5198
|
-
|
|
7682
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7683
|
+
import_antd11.Form.Item,
|
|
5199
7684
|
{
|
|
5200
7685
|
label: "\u5BC6\u7801",
|
|
5201
7686
|
name: "password",
|
|
5202
7687
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u5BC6\u7801" }],
|
|
5203
|
-
children: /* @__PURE__ */ (0,
|
|
7688
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Input.Password, { autoComplete: "current-password" })
|
|
5204
7689
|
}
|
|
5205
7690
|
),
|
|
5206
|
-
challenge ? /* @__PURE__ */ (0,
|
|
5207
|
-
/* @__PURE__ */ (0,
|
|
5208
|
-
|
|
7691
|
+
challenge ? /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_jsx_runtime14.Fragment, { children: [
|
|
7692
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7693
|
+
import_antd11.Alert,
|
|
5209
7694
|
{
|
|
5210
7695
|
showIcon: true,
|
|
5211
7696
|
type: "warning",
|
|
@@ -5213,17 +7698,17 @@ var PasswordLoginForm = ({ challenge, form, loading, onFinish }) => /* @__PURE__
|
|
|
5213
7698
|
description: readChallengeQuestion(challenge) || "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801\u540E\u7EE7\u7EED\u767B\u5F55\u3002"
|
|
5214
7699
|
}
|
|
5215
7700
|
),
|
|
5216
|
-
/* @__PURE__ */ (0,
|
|
5217
|
-
|
|
7701
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7702
|
+
import_antd11.Form.Item,
|
|
5218
7703
|
{
|
|
5219
7704
|
label: "\u9A8C\u8BC1\u7B54\u6848",
|
|
5220
7705
|
name: "challengeAnswer",
|
|
5221
7706
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7B54\u6848" }],
|
|
5222
|
-
children: /* @__PURE__ */ (0,
|
|
7707
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Input, { autoComplete: "one-time-code" })
|
|
5223
7708
|
}
|
|
5224
7709
|
)
|
|
5225
7710
|
] }) : null,
|
|
5226
|
-
/* @__PURE__ */ (0,
|
|
7711
|
+
/* @__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
7712
|
] });
|
|
5228
7713
|
var PhoneCodeLoginForm = ({
|
|
5229
7714
|
allowRegister,
|
|
@@ -5234,9 +7719,9 @@ var PhoneCodeLoginForm = ({
|
|
|
5234
7719
|
onPurposeChange,
|
|
5235
7720
|
onSendCode,
|
|
5236
7721
|
onFinish
|
|
5237
|
-
}) => /* @__PURE__ */ (0,
|
|
5238
|
-
allowRegister ? /* @__PURE__ */ (0,
|
|
5239
|
-
|
|
7722
|
+
}) => /* @__PURE__ */ (0, import_jsx_runtime14.jsxs)(import_antd11.Form, { form, layout: "vertical", requiredMark: false, onFinish, children: [
|
|
7723
|
+
allowRegister ? /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Form.Item, { style: { marginBottom: 12 }, children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7724
|
+
import_antd11.Tabs,
|
|
5240
7725
|
{
|
|
5241
7726
|
activeKey: phonePurpose,
|
|
5242
7727
|
items: [
|
|
@@ -5247,26 +7732,26 @@ var PhoneCodeLoginForm = ({
|
|
|
5247
7732
|
size: "small"
|
|
5248
7733
|
}
|
|
5249
7734
|
) }) : null,
|
|
5250
|
-
/* @__PURE__ */ (0,
|
|
5251
|
-
|
|
7735
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7736
|
+
import_antd11.Form.Item,
|
|
5252
7737
|
{
|
|
5253
7738
|
label: "\u624B\u673A\u53F7",
|
|
5254
7739
|
name: "phone",
|
|
5255
7740
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u624B\u673A\u53F7" }],
|
|
5256
|
-
children: /* @__PURE__ */ (0,
|
|
7741
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(import_antd11.Input, { autoComplete: "tel" })
|
|
5257
7742
|
}
|
|
5258
7743
|
),
|
|
5259
|
-
/* @__PURE__ */ (0,
|
|
5260
|
-
|
|
7744
|
+
/* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7745
|
+
import_antd11.Form.Item,
|
|
5261
7746
|
{
|
|
5262
7747
|
label: "\u9A8C\u8BC1\u7801",
|
|
5263
7748
|
name: "code",
|
|
5264
7749
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801" }],
|
|
5265
|
-
children: /* @__PURE__ */ (0,
|
|
5266
|
-
|
|
7750
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7751
|
+
import_antd11.Input,
|
|
5267
7752
|
{
|
|
5268
|
-
addonAfter: /* @__PURE__ */ (0,
|
|
5269
|
-
|
|
7753
|
+
addonAfter: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
|
|
7754
|
+
import_antd11.Button,
|
|
5270
7755
|
{
|
|
5271
7756
|
loading: sendingCode,
|
|
5272
7757
|
onClick: onSendCode,
|
|
@@ -5280,7 +7765,7 @@ var PhoneCodeLoginForm = ({
|
|
|
5280
7765
|
)
|
|
5281
7766
|
}
|
|
5282
7767
|
),
|
|
5283
|
-
/* @__PURE__ */ (0,
|
|
7768
|
+
/* @__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
7769
|
] });
|
|
5285
7770
|
var findMethod = (methods, type) => methods.find((method) => method.type === type);
|
|
5286
7771
|
var normalizeError = (error) => error instanceof Error ? error : new Error(String(error || "\u8BF7\u6C42\u5931\u8D25"));
|
|
@@ -5357,7 +7842,7 @@ var getCallbackUrl = () => {
|
|
|
5357
7842
|
};
|
|
5358
7843
|
|
|
5359
7844
|
// packages/sdk/src/runtime/react/openxiangdaProvider.tsx
|
|
5360
|
-
var
|
|
7845
|
+
var import_jsx_runtime15 = require("react/jsx-runtime");
|
|
5361
7846
|
var RuntimeHttpError = class extends Error {
|
|
5362
7847
|
constructor(snapshot) {
|
|
5363
7848
|
super(snapshot.message);
|
|
@@ -5368,26 +7853,26 @@ var RuntimeHttpError = class extends Error {
|
|
|
5368
7853
|
this.payload = snapshot.payload;
|
|
5369
7854
|
}
|
|
5370
7855
|
};
|
|
5371
|
-
var OpenXiangdaRuntimeContext = (0,
|
|
7856
|
+
var OpenXiangdaRuntimeContext = (0, import_react18.createContext)(null);
|
|
5372
7857
|
var OpenXiangdaProvider = ({
|
|
5373
7858
|
appType,
|
|
5374
7859
|
servicePrefix = "/service",
|
|
5375
7860
|
fetchImpl,
|
|
5376
7861
|
children
|
|
5377
7862
|
}) => {
|
|
5378
|
-
const resolvedFetch = (0,
|
|
5379
|
-
const resolvedAppType = (0,
|
|
7863
|
+
const resolvedFetch = (0, import_react18.useMemo)(() => createBoundFetch(fetchImpl), [fetchImpl]);
|
|
7864
|
+
const resolvedAppType = (0, import_react18.useMemo)(
|
|
5380
7865
|
() => appType || resolveAppTypeFromLocation(),
|
|
5381
7866
|
[appType]
|
|
5382
7867
|
);
|
|
5383
|
-
const [, setAccessTokenState] = (0,
|
|
5384
|
-
const [authState, setAuthState] = (0,
|
|
7868
|
+
const [, setAccessTokenState] = (0, import_react18.useState)(null);
|
|
7869
|
+
const [authState, setAuthState] = (0, import_react18.useState)({
|
|
5385
7870
|
status: "unknown",
|
|
5386
7871
|
error: null
|
|
5387
7872
|
});
|
|
5388
|
-
const accessTokenRef = (0,
|
|
5389
|
-
const refreshRequestRef = (0,
|
|
5390
|
-
const applyAccessToken = (0,
|
|
7873
|
+
const accessTokenRef = (0, import_react18.useRef)(null);
|
|
7874
|
+
const refreshRequestRef = (0, import_react18.useRef)(null);
|
|
7875
|
+
const applyAccessToken = (0, import_react18.useCallback)(
|
|
5391
7876
|
(nextAccessToken, options = {}) => {
|
|
5392
7877
|
if (!nextAccessToken && options.clearIfToken && accessTokenRef.current?.token !== options.clearIfToken) {
|
|
5393
7878
|
return accessTokenRef.current;
|
|
@@ -5405,7 +7890,7 @@ var OpenXiangdaProvider = ({
|
|
|
5405
7890
|
},
|
|
5406
7891
|
[]
|
|
5407
7892
|
);
|
|
5408
|
-
const setAccessToken = (0,
|
|
7893
|
+
const setAccessToken = (0, import_react18.useCallback)(
|
|
5409
7894
|
(nextAccessToken, options = {}) => {
|
|
5410
7895
|
const previousState = accessTokenRef.current;
|
|
5411
7896
|
const nextState = applyAccessToken(nextAccessToken, options);
|
|
@@ -5421,7 +7906,7 @@ var OpenXiangdaProvider = ({
|
|
|
5421
7906
|
},
|
|
5422
7907
|
[applyAccessToken]
|
|
5423
7908
|
);
|
|
5424
|
-
const markUnauthenticated = (0,
|
|
7909
|
+
const markUnauthenticated = (0, import_react18.useCallback)(
|
|
5425
7910
|
(error) => {
|
|
5426
7911
|
const runtimeError = normalizeRuntimeError(error);
|
|
5427
7912
|
applyAccessToken(null);
|
|
@@ -5429,7 +7914,7 @@ var OpenXiangdaProvider = ({
|
|
|
5429
7914
|
},
|
|
5430
7915
|
[applyAccessToken]
|
|
5431
7916
|
);
|
|
5432
|
-
const refreshAccessToken = (0,
|
|
7917
|
+
const refreshAccessToken = (0, import_react18.useCallback)(async () => {
|
|
5433
7918
|
if (!resolvedAppType) return null;
|
|
5434
7919
|
if (!refreshRequestRef.current) {
|
|
5435
7920
|
setAuthState((prev) => ({ ...prev, status: "refreshing", error: null }));
|
|
@@ -5490,7 +7975,7 @@ var OpenXiangdaProvider = ({
|
|
|
5490
7975
|
}
|
|
5491
7976
|
return refreshRequestRef.current;
|
|
5492
7977
|
}, [applyAccessToken, resolvedAppType, resolvedFetch, servicePrefix]);
|
|
5493
|
-
const authorizedFetch = (0,
|
|
7978
|
+
const authorizedFetch = (0, import_react18.useMemo)(
|
|
5494
7979
|
() => createAuthorizedFetch({
|
|
5495
7980
|
appType: resolvedAppType,
|
|
5496
7981
|
baseFetch: resolvedFetch,
|
|
@@ -5500,18 +7985,18 @@ var OpenXiangdaProvider = ({
|
|
|
5500
7985
|
}),
|
|
5501
7986
|
[markUnauthenticated, refreshAccessToken, resolvedAppType, resolvedFetch]
|
|
5502
7987
|
);
|
|
5503
|
-
const getAuthHeaders = (0,
|
|
7988
|
+
const getAuthHeaders = (0, import_react18.useCallback)(() => {
|
|
5504
7989
|
const state2 = accessTokenRef.current;
|
|
5505
7990
|
if (!state2) return {};
|
|
5506
7991
|
const token = resolveAccessTokenForCurrentRoute(state2);
|
|
5507
7992
|
return token ? { authorization: `Bearer ${token}` } : {};
|
|
5508
7993
|
}, []);
|
|
5509
|
-
const [state, setState] = (0,
|
|
7994
|
+
const [state, setState] = (0, import_react18.useState)({
|
|
5510
7995
|
data: null,
|
|
5511
7996
|
loading: true,
|
|
5512
7997
|
error: null
|
|
5513
7998
|
});
|
|
5514
|
-
const reload = (0,
|
|
7999
|
+
const reload = (0, import_react18.useCallback)(async (options = {}) => {
|
|
5515
8000
|
if (!resolvedAppType) {
|
|
5516
8001
|
setState({
|
|
5517
8002
|
data: null,
|
|
@@ -5575,10 +8060,10 @@ var OpenXiangdaProvider = ({
|
|
|
5575
8060
|
}
|
|
5576
8061
|
}
|
|
5577
8062
|
}, [authorizedFetch, resolvedAppType, resolvedFetch, servicePrefix]);
|
|
5578
|
-
(0,
|
|
8063
|
+
(0, import_react18.useEffect)(() => {
|
|
5579
8064
|
void reload();
|
|
5580
8065
|
}, [reload]);
|
|
5581
|
-
const value = (0,
|
|
8066
|
+
const value = (0, import_react18.useMemo)(
|
|
5582
8067
|
() => ({
|
|
5583
8068
|
...state,
|
|
5584
8069
|
appType: resolvedAppType,
|
|
@@ -5601,10 +8086,10 @@ var OpenXiangdaProvider = ({
|
|
|
5601
8086
|
authState
|
|
5602
8087
|
]
|
|
5603
8088
|
);
|
|
5604
|
-
return /* @__PURE__ */ (0,
|
|
8089
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(OpenXiangdaRuntimeContext.Provider, { value, children });
|
|
5605
8090
|
};
|
|
5606
8091
|
var useOpenXiangda = () => {
|
|
5607
|
-
const context = (0,
|
|
8092
|
+
const context = (0, import_react18.useContext)(OpenXiangdaRuntimeContext);
|
|
5608
8093
|
if (!context) {
|
|
5609
8094
|
throw new Error("useOpenXiangda must be used inside OpenXiangdaProvider");
|
|
5610
8095
|
}
|
|
@@ -5621,7 +8106,7 @@ var OpenXiangdaPageProvider = ({
|
|
|
5621
8106
|
navigation
|
|
5622
8107
|
}) => {
|
|
5623
8108
|
const runtime = useOpenXiangda();
|
|
5624
|
-
const context = (0,
|
|
8109
|
+
const context = (0, import_react18.useMemo)(() => {
|
|
5625
8110
|
const bootstrap = runtime.data;
|
|
5626
8111
|
const app = toRuntimeRecord(bootstrap?.app);
|
|
5627
8112
|
const user = toRuntimeRecord(bootstrap?.user);
|
|
@@ -5701,7 +8186,7 @@ var OpenXiangdaPageProvider = ({
|
|
|
5701
8186
|
runtime.fetchImpl,
|
|
5702
8187
|
runtime.servicePrefix
|
|
5703
8188
|
]);
|
|
5704
|
-
return /* @__PURE__ */ (0,
|
|
8189
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(PageProvider, { context, children });
|
|
5705
8190
|
};
|
|
5706
8191
|
var useAppMenus = () => {
|
|
5707
8192
|
const runtime = useOpenXiangda();
|
|
@@ -5719,12 +8204,12 @@ var usePermission = () => {
|
|
|
5719
8204
|
};
|
|
5720
8205
|
var useCanAccessRoute = (input) => {
|
|
5721
8206
|
const runtime = useOpenXiangda();
|
|
5722
|
-
const [state, setState] = (0,
|
|
8207
|
+
const [state, setState] = (0, import_react18.useState)({
|
|
5723
8208
|
data: null,
|
|
5724
8209
|
loading: true,
|
|
5725
8210
|
error: null
|
|
5726
8211
|
});
|
|
5727
|
-
(0,
|
|
8212
|
+
(0, import_react18.useEffect)(() => {
|
|
5728
8213
|
let disposed = false;
|
|
5729
8214
|
const check = async () => {
|
|
5730
8215
|
const permissions = runtime.data?.permissions;
|
|
@@ -5846,16 +8331,16 @@ var PermissionBoundary = ({
|
|
|
5846
8331
|
const access = useCanAccessRoute({ routeCode, menuCode, path });
|
|
5847
8332
|
const fallbackState = createPermissionFallbackState(access, runtime);
|
|
5848
8333
|
if (access.loading) {
|
|
5849
|
-
return /* @__PURE__ */ (0,
|
|
8334
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: renderBoundaryFallback(loadingFallback, fallbackState) });
|
|
5850
8335
|
}
|
|
5851
8336
|
if (!access.canAccess) {
|
|
5852
|
-
return /* @__PURE__ */ (0,
|
|
8337
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: renderBoundaryFallback(fallback, fallbackState) });
|
|
5853
8338
|
}
|
|
5854
|
-
return /* @__PURE__ */ (0,
|
|
8339
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children });
|
|
5855
8340
|
};
|
|
5856
8341
|
var useRuntimeAuth = () => {
|
|
5857
8342
|
const runtime = useOpenXiangda();
|
|
5858
|
-
const resolveLoginUrl2 = (0,
|
|
8343
|
+
const resolveLoginUrl2 = (0, import_react18.useCallback)(
|
|
5859
8344
|
async (options = {}) => {
|
|
5860
8345
|
const redirectUri = options.redirectUri || getCurrentHref4();
|
|
5861
8346
|
const domain = options.domain || getCurrentHostname2();
|
|
@@ -5902,7 +8387,7 @@ var useRuntimeAuth = () => {
|
|
|
5902
8387
|
},
|
|
5903
8388
|
[runtime.baseFetchImpl, runtime.data?.app, runtime.servicePrefix]
|
|
5904
8389
|
);
|
|
5905
|
-
const redirectToLogin = (0,
|
|
8390
|
+
const redirectToLogin = (0, import_react18.useCallback)(
|
|
5906
8391
|
async (options = {}) => {
|
|
5907
8392
|
const loginUrl = await resolveLoginUrl2(options);
|
|
5908
8393
|
if (typeof window !== "undefined") {
|
|
@@ -5916,7 +8401,7 @@ var useRuntimeAuth = () => {
|
|
|
5916
8401
|
},
|
|
5917
8402
|
[resolveLoginUrl2]
|
|
5918
8403
|
);
|
|
5919
|
-
const logout = (0,
|
|
8404
|
+
const logout = (0, import_react18.useCallback)(async () => {
|
|
5920
8405
|
const response = await runtime.baseFetchImpl(
|
|
5921
8406
|
buildServiceUrl2(runtime.servicePrefix, "/api/auth/logout"),
|
|
5922
8407
|
{
|
|
@@ -5936,7 +8421,7 @@ var useRuntimeAuth = () => {
|
|
|
5936
8421
|
runtime.setAccessToken(null);
|
|
5937
8422
|
return payload;
|
|
5938
8423
|
}, [runtime.baseFetchImpl, runtime.servicePrefix, runtime.setAccessToken]);
|
|
5939
|
-
const logoutAndRedirect = (0,
|
|
8424
|
+
const logoutAndRedirect = (0, import_react18.useCallback)(
|
|
5940
8425
|
async (options = {}) => {
|
|
5941
8426
|
try {
|
|
5942
8427
|
await logout();
|
|
@@ -5947,7 +8432,7 @@ var useRuntimeAuth = () => {
|
|
|
5947
8432
|
},
|
|
5948
8433
|
[logout, redirectToLogin]
|
|
5949
8434
|
);
|
|
5950
|
-
return (0,
|
|
8435
|
+
return (0, import_react18.useMemo)(
|
|
5951
8436
|
() => ({
|
|
5952
8437
|
logout,
|
|
5953
8438
|
logoutAndRedirect,
|
|
@@ -5966,7 +8451,7 @@ var RuntimeAuthGuard = ({
|
|
|
5966
8451
|
}) => {
|
|
5967
8452
|
const runtime = useOpenXiangda();
|
|
5968
8453
|
const auth = useRuntimeAuth();
|
|
5969
|
-
const redirectedRef = (0,
|
|
8454
|
+
const redirectedRef = (0, import_react18.useRef)(false);
|
|
5970
8455
|
const currentPath = getCurrentPathname();
|
|
5971
8456
|
const excluded = isRuntimeAuthGuardExcluded(
|
|
5972
8457
|
currentPath,
|
|
@@ -5974,7 +8459,7 @@ var RuntimeAuthGuard = ({
|
|
|
5974
8459
|
excludedPaths
|
|
5975
8460
|
);
|
|
5976
8461
|
const shouldRedirect = !disabled && !excluded && !runtime.loading && (runtime.authState.status === "unauthenticated" || runtime.error?.type === "unauthenticated");
|
|
5977
|
-
(0,
|
|
8462
|
+
(0, import_react18.useEffect)(() => {
|
|
5978
8463
|
if (!shouldRedirect || redirectedRef.current) return;
|
|
5979
8464
|
redirectedRef.current = true;
|
|
5980
8465
|
void auth.redirectToLogin({
|
|
@@ -5991,9 +8476,9 @@ var RuntimeAuthGuard = ({
|
|
|
5991
8476
|
redirectOptions.replace,
|
|
5992
8477
|
shouldRedirect
|
|
5993
8478
|
]);
|
|
5994
|
-
if (excluded) return /* @__PURE__ */ (0,
|
|
5995
|
-
if (shouldRedirect) return /* @__PURE__ */ (0,
|
|
5996
|
-
return /* @__PURE__ */ (0,
|
|
8479
|
+
if (excluded) return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children });
|
|
8480
|
+
if (shouldRedirect) return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children: fallback });
|
|
8481
|
+
return /* @__PURE__ */ (0, import_jsx_runtime15.jsx)(import_jsx_runtime15.Fragment, { children });
|
|
5997
8482
|
};
|
|
5998
8483
|
var buildServiceUrl2 = (servicePrefix, path) => {
|
|
5999
8484
|
const prefix = servicePrefix.endsWith("/") ? servicePrefix.slice(0, -1) : servicePrefix;
|
|
@@ -6264,7 +8749,7 @@ var buildBrowserRouteInfo = (route) => {
|
|
|
6264
8749
|
hash
|
|
6265
8750
|
};
|
|
6266
8751
|
};
|
|
6267
|
-
var
|
|
8752
|
+
var isSuccessCode6 = (code) => {
|
|
6268
8753
|
if (code === void 0 || code === null || code === "") return true;
|
|
6269
8754
|
const normalized = Number(code);
|
|
6270
8755
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -6272,7 +8757,7 @@ var isSuccessCode5 = (code) => {
|
|
|
6272
8757
|
var isRuntimeEnvelopeFailure = (response, payload) => {
|
|
6273
8758
|
const code = getRecordValue2(payload, "code");
|
|
6274
8759
|
const success = getRecordValue2(payload, "success");
|
|
6275
|
-
return !response.ok || success === false || !
|
|
8760
|
+
return !response.ok || success === false || !isSuccessCode6(code);
|
|
6276
8761
|
};
|
|
6277
8762
|
var isServerErrorCode = (code) => {
|
|
6278
8763
|
const normalized = Number(code);
|
|
@@ -6317,7 +8802,7 @@ var resolveAppTypeFromLocation = () => {
|
|
|
6317
8802
|
};
|
|
6318
8803
|
|
|
6319
8804
|
// packages/sdk/src/runtime/react/publicAccess.tsx
|
|
6320
|
-
var
|
|
8805
|
+
var import_react19 = require("react");
|
|
6321
8806
|
|
|
6322
8807
|
// packages/sdk/src/runtime/core/publicAccess.ts
|
|
6323
8808
|
var PublicAccessClientError = class extends Error {
|
|
@@ -6367,7 +8852,7 @@ var createPublicAccessClient = ({
|
|
|
6367
8852
|
const payload = await readPayload2(response);
|
|
6368
8853
|
const code = getRecordValue3(payload, "code");
|
|
6369
8854
|
const success = getRecordValue3(payload, "success");
|
|
6370
|
-
if (!response.ok || success === false || !
|
|
8855
|
+
if (!response.ok || success === false || !isSuccessCode7(code)) {
|
|
6371
8856
|
throw new PublicAccessClientError(
|
|
6372
8857
|
String(
|
|
6373
8858
|
getRecordValue3(payload, "message") || `Public access session failed: ${response.status}`
|
|
@@ -6405,7 +8890,7 @@ var getRecordValue3 = (value, key) => {
|
|
|
6405
8890
|
if (!value || typeof value !== "object") return void 0;
|
|
6406
8891
|
return value[key];
|
|
6407
8892
|
};
|
|
6408
|
-
var
|
|
8893
|
+
var isSuccessCode7 = (code) => {
|
|
6409
8894
|
if (code === void 0 || code === null || code === "") return true;
|
|
6410
8895
|
const normalized = Number(code);
|
|
6411
8896
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -6433,7 +8918,7 @@ var createRandomIdentifier = (appType) => {
|
|
|
6433
8918
|
};
|
|
6434
8919
|
|
|
6435
8920
|
// packages/sdk/src/runtime/react/publicAccess.tsx
|
|
6436
|
-
var
|
|
8921
|
+
var import_jsx_runtime16 = require("react/jsx-runtime");
|
|
6437
8922
|
var usePublicAccess = (options = {}) => {
|
|
6438
8923
|
const runtime = useOpenXiangda();
|
|
6439
8924
|
const {
|
|
@@ -6450,14 +8935,14 @@ var usePublicAccess = (options = {}) => {
|
|
|
6450
8935
|
autoStart = true,
|
|
6451
8936
|
...sessionInput
|
|
6452
8937
|
} = options;
|
|
6453
|
-
const [session, setSession] = (0,
|
|
6454
|
-
const [error, setError] = (0,
|
|
6455
|
-
const [loading, setLoading] = (0,
|
|
6456
|
-
const activeSessionRef = (0,
|
|
6457
|
-
const mountedRef = (0,
|
|
8938
|
+
const [session, setSession] = (0, import_react19.useState)(null);
|
|
8939
|
+
const [error, setError] = (0, import_react19.useState)(null);
|
|
8940
|
+
const [loading, setLoading] = (0, import_react19.useState)(Boolean(autoStart));
|
|
8941
|
+
const activeSessionRef = (0, import_react19.useRef)(null);
|
|
8942
|
+
const mountedRef = (0, import_react19.useRef)(true);
|
|
6458
8943
|
const sessionInputKey = JSON.stringify(sessionInput);
|
|
6459
|
-
const stableSessionInput = (0,
|
|
6460
|
-
const client = (0,
|
|
8944
|
+
const stableSessionInput = (0, import_react19.useMemo)(() => sessionInput, [sessionInputKey]);
|
|
8945
|
+
const client = (0, import_react19.useMemo)(
|
|
6461
8946
|
() => createPublicAccessClient({
|
|
6462
8947
|
appType,
|
|
6463
8948
|
servicePrefix,
|
|
@@ -6465,7 +8950,7 @@ var usePublicAccess = (options = {}) => {
|
|
|
6465
8950
|
}),
|
|
6466
8951
|
[appType, fetchImpl, servicePrefix]
|
|
6467
8952
|
);
|
|
6468
|
-
const startSession = (0,
|
|
8953
|
+
const startSession = (0, import_react19.useCallback)(
|
|
6469
8954
|
async (input = {}) => {
|
|
6470
8955
|
setLoading(true);
|
|
6471
8956
|
setError(null);
|
|
@@ -6511,11 +8996,11 @@ var usePublicAccess = (options = {}) => {
|
|
|
6511
8996
|
},
|
|
6512
8997
|
[client, reloadRuntime, setAccessToken, stableSessionInput]
|
|
6513
8998
|
);
|
|
6514
|
-
(0,
|
|
8999
|
+
(0, import_react19.useEffect)(() => {
|
|
6515
9000
|
if (!autoStart) return;
|
|
6516
9001
|
void startSession().catch(() => void 0);
|
|
6517
9002
|
}, [autoStart, startSession]);
|
|
6518
|
-
(0,
|
|
9003
|
+
(0, import_react19.useEffect)(
|
|
6519
9004
|
() => {
|
|
6520
9005
|
mountedRef.current = true;
|
|
6521
9006
|
return () => {
|
|
@@ -6544,11 +9029,11 @@ var PublicAccessGate = ({
|
|
|
6544
9029
|
...options
|
|
6545
9030
|
}) => {
|
|
6546
9031
|
const state = usePublicAccess(options);
|
|
6547
|
-
if (state.loading) return /* @__PURE__ */ (0,
|
|
9032
|
+
if (state.loading) return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children: fallback });
|
|
6548
9033
|
if (state.error) {
|
|
6549
|
-
return /* @__PURE__ */ (0,
|
|
9034
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children: typeof errorFallback === "function" ? errorFallback(state.error) : errorFallback });
|
|
6550
9035
|
}
|
|
6551
|
-
return /* @__PURE__ */ (0,
|
|
9036
|
+
return /* @__PURE__ */ (0, import_jsx_runtime16.jsx)(import_jsx_runtime16.Fragment, { children });
|
|
6552
9037
|
};
|
|
6553
9038
|
var readTicketFromLocation = () => {
|
|
6554
9039
|
if (typeof window === "undefined") return void 0;
|