openxiangda 1.0.151 → 1.0.153
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -0
- package/openxiangda-skills/SKILL.md +1 -0
- package/openxiangda-skills/references/component-guide.md +13 -0
- package/openxiangda-skills/references/pages/page-sdk.md +37 -3
- package/package.json +6 -2
- package/packages/sdk/dist/{ProcessPreview-BOCARAvP.d.mts → ProcessPreview-DMkzccq4.d.mts} +58 -2
- package/packages/sdk/dist/{ProcessPreview-BOCARAvP.d.ts → ProcessPreview-DMkzccq4.d.ts} +58 -2
- package/packages/sdk/dist/components/index.cjs +3518 -2279
- package/packages/sdk/dist/components/index.cjs.map +1 -1
- package/packages/sdk/dist/components/index.d.mts +92 -38
- package/packages/sdk/dist/components/index.d.ts +92 -38
- package/packages/sdk/dist/components/index.mjs +3266 -2022
- package/packages/sdk/dist/components/index.mjs.map +1 -1
- package/packages/sdk/dist/{dataManagementApi-CLMqf79O.d.mts → dataManagementApi-C9O-Bb0j.d.ts} +2 -2
- package/packages/sdk/dist/{dataManagementApi-DhpRKmlp.d.ts → dataManagementApi-gpZkgRDM.d.mts} +2 -2
- package/packages/sdk/dist/runtime/index.cjs +8220 -7071
- package/packages/sdk/dist/runtime/index.cjs.map +1 -1
- package/packages/sdk/dist/runtime/index.d.mts +5 -4
- package/packages/sdk/dist/runtime/index.d.ts +5 -4
- package/packages/sdk/dist/runtime/index.mjs +8153 -6999
- package/packages/sdk/dist/runtime/index.mjs.map +1 -1
- package/packages/sdk/dist/runtime/react.cjs +2899 -453
- package/packages/sdk/dist/runtime/react.cjs.map +1 -1
- package/packages/sdk/dist/runtime/react.d.mts +63 -4
- package/packages/sdk/dist/runtime/react.d.ts +63 -4
- package/packages/sdk/dist/runtime/react.mjs +2908 -439
- package/packages/sdk/dist/runtime/react.mjs.map +1 -1
- package/templates/openxiangda-react-spa/.cursor/rules/openxiangda.mdc +1 -0
- package/templates/openxiangda-react-spa/.qoder/rules/openxiangda.md +1 -0
- package/templates/openxiangda-react-spa/AGENTS.md +5 -1
|
@@ -690,14 +690,14 @@ var createPageSdk = (context) => {
|
|
|
690
690
|
throw toSdkError(error, payload);
|
|
691
691
|
}
|
|
692
692
|
};
|
|
693
|
-
const createFileAccessTicket = (bucketName, objectName, fileName,
|
|
693
|
+
const createFileAccessTicket = (bucketName, objectName, fileName, purpose = "preview", options = {}) => request({
|
|
694
694
|
path: "/file/access-ticket",
|
|
695
695
|
method: "post",
|
|
696
696
|
body: {
|
|
697
697
|
bucketName,
|
|
698
698
|
objectName,
|
|
699
699
|
fileName,
|
|
700
|
-
|
|
700
|
+
purpose,
|
|
701
701
|
appType: resolveAppType(context, options.appType)
|
|
702
702
|
}
|
|
703
703
|
});
|
|
@@ -2619,21 +2619,2549 @@ var usePageRoute = () => {
|
|
|
2619
2619
|
return usePageContext().route;
|
|
2620
2620
|
};
|
|
2621
2621
|
|
|
2622
|
+
// packages/sdk/src/runtime/react/filePreview.tsx
|
|
2623
|
+
import React6, { useMemo as useMemo6, useState as useState6 } from "react";
|
|
2624
|
+
import { Empty as Empty3 } from "antd";
|
|
2625
|
+
|
|
2626
|
+
// packages/sdk/src/components/core/imageCompression.ts
|
|
2627
|
+
var DEFAULT_THUMB = {
|
|
2628
|
+
maxWidth: 320,
|
|
2629
|
+
maxHeight: 320,
|
|
2630
|
+
quality: 0.72,
|
|
2631
|
+
format: "source"
|
|
2632
|
+
};
|
|
2633
|
+
var DEFAULT_PREVIEW = {
|
|
2634
|
+
maxWidth: 1280,
|
|
2635
|
+
maxHeight: 1280,
|
|
2636
|
+
quality: 0.82,
|
|
2637
|
+
format: "source"
|
|
2638
|
+
};
|
|
2639
|
+
var COMPRESSIBLE_EXTENSIONS = /* @__PURE__ */ new Set(["jpg", "jpeg", "png", "webp", "bmp"]);
|
|
2640
|
+
function shouldCreateImageVariants(file, config) {
|
|
2641
|
+
if (!config || config.enabled === false) return false;
|
|
2642
|
+
if (!isCompressibleImageFile(file)) return false;
|
|
2643
|
+
if (config.skipBelowBytes && file.size <= config.skipBelowBytes) return false;
|
|
2644
|
+
return true;
|
|
2645
|
+
}
|
|
2646
|
+
async function createCompressedImageVariants(file, config) {
|
|
2647
|
+
if (!shouldCreateImageVariants(file, config)) return [];
|
|
2648
|
+
const variantConfigs = [];
|
|
2649
|
+
if (config?.thumb !== false) {
|
|
2650
|
+
variantConfigs.push(["thumb", { ...DEFAULT_THUMB, ...config?.thumb || {} }]);
|
|
2651
|
+
}
|
|
2652
|
+
if (config?.preview !== false) {
|
|
2653
|
+
variantConfigs.push(["preview", { ...DEFAULT_PREVIEW, ...config?.preview || {} }]);
|
|
2654
|
+
}
|
|
2655
|
+
if (variantConfigs.length === 0) return [];
|
|
2656
|
+
const source = await loadImageSource(file);
|
|
2657
|
+
if (!source) return [];
|
|
2658
|
+
try {
|
|
2659
|
+
const sourceWidth = Math.max(1, source.naturalWidth || source.width || 0);
|
|
2660
|
+
const sourceHeight = Math.max(1, source.naturalHeight || source.height || 0);
|
|
2661
|
+
if (!sourceWidth || !sourceHeight) return [];
|
|
2662
|
+
const results = [];
|
|
2663
|
+
for (const [kind, variantConfig] of variantConfigs) {
|
|
2664
|
+
const normalized = normalizeVariantConfig(kind, variantConfig);
|
|
2665
|
+
const target = getTargetSize(sourceWidth, sourceHeight, normalized);
|
|
2666
|
+
const mimeType = resolveOutputMimeType(file, normalized.format);
|
|
2667
|
+
const blob = await drawCompressedBlob(
|
|
2668
|
+
source,
|
|
2669
|
+
target.width,
|
|
2670
|
+
target.height,
|
|
2671
|
+
mimeType,
|
|
2672
|
+
normalized.quality
|
|
2673
|
+
);
|
|
2674
|
+
if (!blob || blob.size >= file.size) continue;
|
|
2675
|
+
const outputFile = new File([blob], buildVariantFileName(file.name, kind, mimeType), {
|
|
2676
|
+
type: blob.type || mimeType,
|
|
2677
|
+
lastModified: Date.now()
|
|
2678
|
+
});
|
|
2679
|
+
results.push({
|
|
2680
|
+
kind,
|
|
2681
|
+
file: outputFile,
|
|
2682
|
+
width: target.width,
|
|
2683
|
+
height: target.height,
|
|
2684
|
+
contentType: outputFile.type || mimeType,
|
|
2685
|
+
quality: normalized.quality
|
|
2686
|
+
});
|
|
2687
|
+
}
|
|
2688
|
+
return results;
|
|
2689
|
+
} finally {
|
|
2690
|
+
source.close?.();
|
|
2691
|
+
}
|
|
2692
|
+
}
|
|
2693
|
+
function isCompressibleImageFile(file) {
|
|
2694
|
+
const contentType = String(file.type || "").toLowerCase();
|
|
2695
|
+
if (contentType === "image/svg+xml" || contentType === "image/gif") return false;
|
|
2696
|
+
if (contentType.startsWith("image/")) {
|
|
2697
|
+
return ["image/jpeg", "image/png", "image/webp", "image/bmp"].includes(contentType);
|
|
2698
|
+
}
|
|
2699
|
+
const extension = getExtension(file.name);
|
|
2700
|
+
return COMPRESSIBLE_EXTENSIONS.has(extension);
|
|
2701
|
+
}
|
|
2702
|
+
async function loadImageSource(file) {
|
|
2703
|
+
if (typeof createImageBitmap === "function") {
|
|
2704
|
+
try {
|
|
2705
|
+
return await createImageBitmap(file);
|
|
2706
|
+
} catch {
|
|
2707
|
+
}
|
|
2708
|
+
}
|
|
2709
|
+
if (typeof Image === "undefined" || typeof URL === "undefined") return null;
|
|
2710
|
+
const objectUrl = URL.createObjectURL(file);
|
|
2711
|
+
try {
|
|
2712
|
+
const image = new Image();
|
|
2713
|
+
image.decoding = "async";
|
|
2714
|
+
image.src = objectUrl;
|
|
2715
|
+
if (typeof image.decode === "function") {
|
|
2716
|
+
await image.decode();
|
|
2717
|
+
} else {
|
|
2718
|
+
await new Promise((resolve, reject) => {
|
|
2719
|
+
image.onload = () => resolve();
|
|
2720
|
+
image.onerror = () => reject(new Error("\u56FE\u7247\u89E3\u7801\u5931\u8D25"));
|
|
2721
|
+
});
|
|
2722
|
+
}
|
|
2723
|
+
return image;
|
|
2724
|
+
} catch {
|
|
2725
|
+
return null;
|
|
2726
|
+
} finally {
|
|
2727
|
+
URL.revokeObjectURL(objectUrl);
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
function normalizeVariantConfig(kind, config) {
|
|
2731
|
+
const fallback = kind === "thumb" ? DEFAULT_THUMB : DEFAULT_PREVIEW;
|
|
2732
|
+
const maxWidth = Number(config.maxWidth || fallback.maxWidth);
|
|
2733
|
+
const maxHeight = Number(config.maxHeight || fallback.maxHeight);
|
|
2734
|
+
const quality = Number(config.quality ?? fallback.quality);
|
|
2735
|
+
return {
|
|
2736
|
+
maxWidth: Number.isFinite(maxWidth) && maxWidth > 0 ? maxWidth : fallback.maxWidth,
|
|
2737
|
+
maxHeight: Number.isFinite(maxHeight) && maxHeight > 0 ? maxHeight : fallback.maxHeight,
|
|
2738
|
+
quality: Number.isFinite(quality) && quality > 0 && quality <= 1 ? quality : fallback.quality,
|
|
2739
|
+
format: config.format || fallback.format
|
|
2740
|
+
};
|
|
2741
|
+
}
|
|
2742
|
+
function getTargetSize(sourceWidth, sourceHeight, config) {
|
|
2743
|
+
const scale = Math.min(1, config.maxWidth / sourceWidth, config.maxHeight / sourceHeight);
|
|
2744
|
+
return {
|
|
2745
|
+
width: Math.max(1, Math.round(sourceWidth * scale)),
|
|
2746
|
+
height: Math.max(1, Math.round(sourceHeight * scale))
|
|
2747
|
+
};
|
|
2748
|
+
}
|
|
2749
|
+
function drawCompressedBlob(source, width, height, mimeType, quality) {
|
|
2750
|
+
if (typeof document === "undefined") return Promise.resolve(null);
|
|
2751
|
+
const canvas = document.createElement("canvas");
|
|
2752
|
+
canvas.width = width;
|
|
2753
|
+
canvas.height = height;
|
|
2754
|
+
const context = canvas.getContext("2d");
|
|
2755
|
+
if (!context || typeof canvas.toBlob !== "function") return Promise.resolve(null);
|
|
2756
|
+
context.drawImage(source, 0, 0, width, height);
|
|
2757
|
+
return new Promise((resolve) => {
|
|
2758
|
+
canvas.toBlob(resolve, mimeType, mimeType === "image/png" ? void 0 : quality);
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
function resolveOutputMimeType(file, format) {
|
|
2762
|
+
if (format && format !== "source") {
|
|
2763
|
+
return format === "jpeg" ? "image/jpeg" : `image/${format}`;
|
|
2764
|
+
}
|
|
2765
|
+
const sourceType = String(file.type || "").toLowerCase();
|
|
2766
|
+
if (["image/jpeg", "image/png", "image/webp"].includes(sourceType)) return sourceType;
|
|
2767
|
+
const extension = getExtension(file.name);
|
|
2768
|
+
if (extension === "png") return "image/png";
|
|
2769
|
+
if (extension === "webp") return "image/webp";
|
|
2770
|
+
return "image/jpeg";
|
|
2771
|
+
}
|
|
2772
|
+
function buildVariantFileName(fileName, kind, mimeType) {
|
|
2773
|
+
const extension = extensionFromMimeType(mimeType);
|
|
2774
|
+
const baseName = String(fileName || "image").replace(/\.[^.]*$/, "").replace(/[^\w.-]+/g, "_").replace(/^_+|_+$/g, "");
|
|
2775
|
+
return `${baseName || "image"}.${kind}.${extension}`;
|
|
2776
|
+
}
|
|
2777
|
+
function extensionFromMimeType(mimeType) {
|
|
2778
|
+
if (mimeType === "image/png") return "png";
|
|
2779
|
+
if (mimeType === "image/webp") return "webp";
|
|
2780
|
+
return "jpg";
|
|
2781
|
+
}
|
|
2782
|
+
function getExtension(fileName) {
|
|
2783
|
+
return String(fileName || "").split(".").pop()?.toLowerCase() || "";
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
// packages/sdk/src/components/core/runtimeApi.ts
|
|
2787
|
+
var DEFAULT_CHUNK_SIZE = 5 * 1024 * 1024;
|
|
2788
|
+
var CHUNK_UPLOAD_THRESHOLD = 10 * 1024 * 1024;
|
|
2789
|
+
var DEFAULT_PUBLIC_FILE_BUCKET = "public-assets";
|
|
2790
|
+
var trimTrailingSlash = (value) => String(value || "").replace(/\/$/, "");
|
|
2791
|
+
var getDefaultBaseUrl = () => {
|
|
2792
|
+
const globalEnv = globalThis.process?.env;
|
|
2793
|
+
const envBaseUrl = globalEnv?.FORM_API_BASE_URL || globalEnv?.BASE_API_URL;
|
|
2794
|
+
if (envBaseUrl) return trimTrailingSlash(envBaseUrl);
|
|
2795
|
+
const browserGlobal = typeof window !== "undefined" ? window : void 0;
|
|
2796
|
+
const windowBaseUrl = browserGlobal?.FORM_API_BASE_URL || browserGlobal?.BASE_API_URL || browserGlobal?.__FORM_API_BASE_URL__ || browserGlobal?.__LOWCODE_API_BASE_URL__;
|
|
2797
|
+
if (windowBaseUrl) return trimTrailingSlash(windowBaseUrl);
|
|
2798
|
+
return typeof window !== "undefined" ? "/service" : "";
|
|
2799
|
+
};
|
|
2800
|
+
var appendQuery = (url, params) => {
|
|
2801
|
+
if (!params) return url;
|
|
2802
|
+
const search = new URLSearchParams();
|
|
2803
|
+
Object.entries(params).forEach(([key, value]) => {
|
|
2804
|
+
if (value === void 0 || value === null || value === "") return;
|
|
2805
|
+
if (Array.isArray(value)) {
|
|
2806
|
+
value.forEach((item) => search.append(key, String(item)));
|
|
2807
|
+
return;
|
|
2808
|
+
}
|
|
2809
|
+
search.append(key, String(value));
|
|
2810
|
+
});
|
|
2811
|
+
const query = search.toString();
|
|
2812
|
+
if (!query) return url;
|
|
2813
|
+
return `${url}${url.includes("?") ? "&" : "?"}${query}`;
|
|
2814
|
+
};
|
|
2815
|
+
var joinUrl = (baseUrl, url) => {
|
|
2816
|
+
if (/^https?:\/\//i.test(url)) return url;
|
|
2817
|
+
const normalizedBaseUrl = trimTrailingSlash(baseUrl);
|
|
2818
|
+
if (normalizedBaseUrl && (url === normalizedBaseUrl || url.startsWith(`${normalizedBaseUrl}/`))) {
|
|
2819
|
+
return url;
|
|
2820
|
+
}
|
|
2821
|
+
return `${normalizedBaseUrl}${url.startsWith("/") ? url : `/${url}`}`;
|
|
2822
|
+
};
|
|
2823
|
+
var isSuccessCode2 = (value) => {
|
|
2824
|
+
if (value === void 0 || value === null || value === "") return true;
|
|
2825
|
+
const code = Number(value);
|
|
2826
|
+
return Number.isFinite(code) ? code === 0 || code >= 200 && code < 300 : false;
|
|
2827
|
+
};
|
|
2828
|
+
var normalizeRuntimeFileUrl = (baseUrl, value) => {
|
|
2829
|
+
if (typeof value !== "string" || !value) return value;
|
|
2830
|
+
if (/^(https?:)?\/\//i.test(value) || /^(blob|data):/i.test(value)) return value;
|
|
2831
|
+
if (!value.startsWith("/file/")) return value;
|
|
2832
|
+
return joinUrl(baseUrl, value);
|
|
2833
|
+
};
|
|
2834
|
+
var normalizeFilePayloadUrls = (baseUrl, payload) => {
|
|
2835
|
+
if (!payload || typeof payload !== "object" || Array.isArray(payload)) return payload;
|
|
2836
|
+
return {
|
|
2837
|
+
...payload,
|
|
2838
|
+
url: normalizeRuntimeFileUrl(baseUrl, payload.url),
|
|
2839
|
+
downloadUrl: normalizeRuntimeFileUrl(baseUrl, payload.downloadUrl),
|
|
2840
|
+
publicUrl: normalizeRuntimeFileUrl(baseUrl, payload.publicUrl),
|
|
2841
|
+
relayUrl: normalizeRuntimeFileUrl(baseUrl, payload.relayUrl),
|
|
2842
|
+
previewUrl: normalizeRuntimeFileUrl(baseUrl, payload.previewUrl),
|
|
2843
|
+
metadataUrl: normalizeRuntimeFileUrl(baseUrl, payload.metadataUrl),
|
|
2844
|
+
previewPageUrl: payload.previewPageUrl
|
|
2845
|
+
};
|
|
2846
|
+
};
|
|
2847
|
+
var normalizeImageVariants = (baseUrl, variants) => {
|
|
2848
|
+
if (!variants || typeof variants !== "object" || Array.isArray(variants)) return void 0;
|
|
2849
|
+
const normalized = {};
|
|
2850
|
+
["thumb", "preview"].forEach((kind) => {
|
|
2851
|
+
const item = variants[kind];
|
|
2852
|
+
if (!item || typeof item !== "object") return;
|
|
2853
|
+
normalized[kind] = {
|
|
2854
|
+
...item,
|
|
2855
|
+
url: normalizeRuntimeFileUrl(baseUrl, item.url)
|
|
2856
|
+
};
|
|
2857
|
+
});
|
|
2858
|
+
return normalized.thumb || normalized.preview ? normalized : void 0;
|
|
2859
|
+
};
|
|
2860
|
+
var normalizeFileTicketResult = (baseUrl, payload) => typeof payload === "string" ? normalizeRuntimeFileUrl(baseUrl, payload) : normalizeFilePayloadUrls(baseUrl, payload);
|
|
2861
|
+
var parseResponse = async (response) => {
|
|
2862
|
+
const contentType = response.headers.get("content-type") || "";
|
|
2863
|
+
const payload = contentType.includes("application/json") ? await response.json() : await response.text();
|
|
2864
|
+
if (!response.ok) {
|
|
2865
|
+
const message3 = typeof payload === "object" && payload ? payload.message || payload.error || response.statusText : response.statusText;
|
|
2866
|
+
throw new Error(message3 || "\u8BF7\u6C42\u5931\u8D25");
|
|
2867
|
+
}
|
|
2868
|
+
if (typeof payload === "object" && payload) {
|
|
2869
|
+
const hasCode = Object.prototype.hasOwnProperty.call(payload, "code");
|
|
2870
|
+
if (payload.success === false || hasCode && !isSuccessCode2(payload.code)) {
|
|
2871
|
+
throw new Error(payload.message || payload.error || "\u8BF7\u6C42\u5931\u8D25");
|
|
2872
|
+
}
|
|
2873
|
+
}
|
|
2874
|
+
if (typeof payload === "object" && payload) {
|
|
2875
|
+
return payload;
|
|
2876
|
+
}
|
|
2877
|
+
return {
|
|
2878
|
+
code: response.status,
|
|
2879
|
+
success: response.ok,
|
|
2880
|
+
data: payload,
|
|
2881
|
+
result: payload,
|
|
2882
|
+
message: response.statusText
|
|
2883
|
+
};
|
|
2884
|
+
};
|
|
2885
|
+
var applyAuthHeaders = (headers, getAuthHeaders) => {
|
|
2886
|
+
const authHeaders = getAuthHeaders?.();
|
|
2887
|
+
if (authHeaders) {
|
|
2888
|
+
new Headers(authHeaders).forEach((value, key) => {
|
|
2889
|
+
if (!headers.has(key)) headers.set(key, value);
|
|
2890
|
+
});
|
|
2891
|
+
}
|
|
2892
|
+
const token = typeof window !== "undefined" ? window.localStorage?.getItem("token") : void 0;
|
|
2893
|
+
if (token && !headers.has("authorization")) {
|
|
2894
|
+
headers.set("authorization", token);
|
|
2895
|
+
}
|
|
2896
|
+
};
|
|
2897
|
+
var applyXhrAuthHeaders = (xhr, getAuthHeaders) => {
|
|
2898
|
+
let hasAuthorization = false;
|
|
2899
|
+
const authHeaders = getAuthHeaders?.();
|
|
2900
|
+
if (authHeaders) {
|
|
2901
|
+
new Headers(authHeaders).forEach((value, key) => {
|
|
2902
|
+
if (key.toLowerCase() === "authorization") hasAuthorization = true;
|
|
2903
|
+
xhr.setRequestHeader(key, value);
|
|
2904
|
+
});
|
|
2905
|
+
}
|
|
2906
|
+
const token = typeof window !== "undefined" ? window.localStorage?.getItem("token") : void 0;
|
|
2907
|
+
if (token && !hasAuthorization) xhr.setRequestHeader("authorization", token);
|
|
2908
|
+
};
|
|
2909
|
+
var createDefaultRequest = (baseUrl, fetchImpl = fetch, getAuthHeaders) => async (config) => {
|
|
2910
|
+
const method = config.method ?? "get";
|
|
2911
|
+
const url = appendQuery(joinUrl(baseUrl, config.url), config.params);
|
|
2912
|
+
const headers = new Headers(config.headers);
|
|
2913
|
+
let body;
|
|
2914
|
+
if (config.data !== void 0) {
|
|
2915
|
+
if (config.data instanceof FormData) {
|
|
2916
|
+
body = config.data;
|
|
2917
|
+
} else {
|
|
2918
|
+
headers.set("Content-Type", headers.get("Content-Type") || "application/json");
|
|
2919
|
+
body = JSON.stringify(config.data);
|
|
2920
|
+
}
|
|
2921
|
+
}
|
|
2922
|
+
applyAuthHeaders(headers, getAuthHeaders);
|
|
2923
|
+
const response = await fetchImpl(url, {
|
|
2924
|
+
method,
|
|
2925
|
+
headers,
|
|
2926
|
+
body,
|
|
2927
|
+
credentials: "include"
|
|
2928
|
+
});
|
|
2929
|
+
if (config.responseType === "blob") {
|
|
2930
|
+
if (!response.ok) throw new Error(response.statusText || "\u8BF7\u6C42\u5931\u8D25");
|
|
2931
|
+
return response.blob();
|
|
2932
|
+
}
|
|
2933
|
+
return parseResponse(response);
|
|
2934
|
+
};
|
|
2935
|
+
var generateUid = () => `${Date.now().toString(36)}${Math.random().toString(36).slice(2)}`;
|
|
2936
|
+
var normalizeFormInstancePayload = (payload) => {
|
|
2937
|
+
const { formInstanceId, ...rest } = payload || {};
|
|
2938
|
+
return {
|
|
2939
|
+
...rest,
|
|
2940
|
+
formInstId: payload?.formInstId || formInstanceId
|
|
2941
|
+
};
|
|
2942
|
+
};
|
|
2943
|
+
var unwrapBusinessResponse = (response) => {
|
|
2944
|
+
const isFailureCode = (value) => {
|
|
2945
|
+
if (value === void 0 || value === null || value === "") return false;
|
|
2946
|
+
const code = Number(value);
|
|
2947
|
+
return Number.isFinite(code) && code !== 0 && code !== 200;
|
|
2948
|
+
};
|
|
2949
|
+
if (response?.success === false || isFailureCode(response?.code)) {
|
|
2950
|
+
throw new Error(response.message || response.error || "\u8BF7\u6C42\u5931\u8D25");
|
|
2951
|
+
}
|
|
2952
|
+
const result = response?.data ?? response?.result ?? response;
|
|
2953
|
+
if (result?.success === false || isFailureCode(result?.code)) {
|
|
2954
|
+
throw new Error(result.message || response?.message || "\u8BF7\u6C42\u5931\u8D25");
|
|
2955
|
+
}
|
|
2956
|
+
return result;
|
|
2957
|
+
};
|
|
2958
|
+
var normalizeUploadData = (data, file, bucketName, baseUrl = "") => {
|
|
2959
|
+
const item = Array.isArray(data) ? data[0] : data;
|
|
2960
|
+
const objectName = item?.objectName || item?.objectKey || item?.key;
|
|
2961
|
+
const resolvedBucketName = item?.bucketName || bucketName;
|
|
2962
|
+
const variants = normalizeImageVariants(baseUrl, item?.variants);
|
|
2963
|
+
return {
|
|
2964
|
+
id: item?.id || item?.uid || objectName || generateUid(),
|
|
2965
|
+
uid: item?.uid || item?.id || objectName || generateUid(),
|
|
2966
|
+
name: item?.originalName || item?.name || file.name,
|
|
2967
|
+
originalName: item?.originalName || file.name,
|
|
2968
|
+
url: normalizeRuntimeFileUrl(baseUrl, item?.url) || "",
|
|
2969
|
+
downloadUrl: normalizeRuntimeFileUrl(baseUrl, item?.downloadUrl),
|
|
2970
|
+
previewUrl: normalizeRuntimeFileUrl(baseUrl, item?.previewUrl),
|
|
2971
|
+
publicUrl: normalizeRuntimeFileUrl(baseUrl, item?.publicUrl),
|
|
2972
|
+
thumbUrl: normalizeRuntimeFileUrl(baseUrl, item?.thumbUrl) || variants?.thumb?.url,
|
|
2973
|
+
visibility: item?.visibility,
|
|
2974
|
+
provider: item?.provider,
|
|
2975
|
+
uploadProvider: item?.uploadProvider,
|
|
2976
|
+
storageScope: item?.storageScope,
|
|
2977
|
+
storageCode: item?.storageCode,
|
|
2978
|
+
appType: item?.appType,
|
|
2979
|
+
status: "done",
|
|
2980
|
+
size: item?.size ?? file.size,
|
|
2981
|
+
objectName,
|
|
2982
|
+
bucketName: resolvedBucketName,
|
|
2983
|
+
contentType: item?.contentType || file.type,
|
|
2984
|
+
mimeType: item?.contentType || file.type,
|
|
2985
|
+
extension: item?.extension,
|
|
2986
|
+
width: item?.width,
|
|
2987
|
+
height: item?.height,
|
|
2988
|
+
variants
|
|
2989
|
+
};
|
|
2990
|
+
};
|
|
2991
|
+
var uploadWithXhr = (baseUrl, file, bucketName, onProgress, options = {}, getAuthHeaders) => new Promise((resolve, reject) => {
|
|
2992
|
+
if (globalThis.process?.env?.VITEST) {
|
|
2993
|
+
onProgress?.(100);
|
|
2994
|
+
resolve({
|
|
2995
|
+
id: generateUid(),
|
|
2996
|
+
uid: generateUid(),
|
|
2997
|
+
name: file.name,
|
|
2998
|
+
url: typeof URL !== "undefined" && URL.createObjectURL ? URL.createObjectURL(file) : "",
|
|
2999
|
+
status: "done",
|
|
3000
|
+
size: file.size,
|
|
3001
|
+
bucketName,
|
|
3002
|
+
contentType: file.type,
|
|
3003
|
+
visibility: options.visibility
|
|
3004
|
+
});
|
|
3005
|
+
return;
|
|
3006
|
+
}
|
|
3007
|
+
const xhr = new XMLHttpRequest();
|
|
3008
|
+
const formData = new FormData();
|
|
3009
|
+
formData.append("files", file);
|
|
3010
|
+
xhr.open(
|
|
3011
|
+
"POST",
|
|
3012
|
+
joinUrl(
|
|
3013
|
+
baseUrl,
|
|
3014
|
+
appendQuery("/file/upload", {
|
|
3015
|
+
bucketName,
|
|
3016
|
+
visibility: options.visibility
|
|
3017
|
+
})
|
|
3018
|
+
)
|
|
3019
|
+
);
|
|
3020
|
+
xhr.withCredentials = true;
|
|
3021
|
+
applyXhrAuthHeaders(xhr, getAuthHeaders);
|
|
3022
|
+
xhr.upload.onprogress = (event) => {
|
|
3023
|
+
if (event.lengthComputable) {
|
|
3024
|
+
onProgress?.(Math.round(event.loaded / event.total * 100));
|
|
3025
|
+
}
|
|
3026
|
+
};
|
|
3027
|
+
xhr.onload = () => {
|
|
3028
|
+
try {
|
|
3029
|
+
const payload = JSON.parse(xhr.responseText || "{}");
|
|
3030
|
+
if (xhr.status >= 200 && xhr.status < 300 && payload.success !== false) {
|
|
3031
|
+
resolve(normalizeUploadData(payload.data, file, bucketName, baseUrl));
|
|
3032
|
+
return;
|
|
3033
|
+
}
|
|
3034
|
+
reject(new Error(payload.message || payload.error || "\u4E0A\u4F20\u5931\u8D25"));
|
|
3035
|
+
} catch (error) {
|
|
3036
|
+
reject(error);
|
|
3037
|
+
}
|
|
3038
|
+
};
|
|
3039
|
+
xhr.onerror = () => reject(new Error("\u4E0A\u4F20\u5931\u8D25"));
|
|
3040
|
+
xhr.send(formData);
|
|
3041
|
+
});
|
|
3042
|
+
var uploadWithSignedUrl = (file, uploadInfo, bucketName, onProgress) => new Promise((resolve, reject) => {
|
|
3043
|
+
if (!uploadInfo?.uploadUrl) {
|
|
3044
|
+
reject(new Error("OSS \u4E0A\u4F20\u7B7E\u540D\u7F3A\u5C11 uploadUrl"));
|
|
3045
|
+
return;
|
|
3046
|
+
}
|
|
3047
|
+
const xhr = new XMLHttpRequest();
|
|
3048
|
+
xhr.open(String(uploadInfo.uploadMethod || "PUT").toUpperCase(), uploadInfo.uploadUrl);
|
|
3049
|
+
Object.entries(uploadInfo.headers || {}).forEach(([key, value]) => {
|
|
3050
|
+
if (value !== void 0 && value !== null) {
|
|
3051
|
+
xhr.setRequestHeader(key, String(value));
|
|
3052
|
+
}
|
|
3053
|
+
});
|
|
3054
|
+
xhr.upload.onprogress = (event) => {
|
|
3055
|
+
if (event.lengthComputable) {
|
|
3056
|
+
onProgress?.(Math.round(event.loaded / event.total * 100));
|
|
3057
|
+
}
|
|
3058
|
+
};
|
|
3059
|
+
xhr.onload = () => {
|
|
3060
|
+
if (xhr.status >= 200 && xhr.status < 300) {
|
|
3061
|
+
onProgress?.(100);
|
|
3062
|
+
resolve(
|
|
3063
|
+
normalizeUploadData(
|
|
3064
|
+
{
|
|
3065
|
+
...uploadInfo,
|
|
3066
|
+
provider: uploadInfo.provider || "oss",
|
|
3067
|
+
uploadProvider: uploadInfo.uploadProvider,
|
|
3068
|
+
storageScope: uploadInfo.storageScope,
|
|
3069
|
+
storageCode: uploadInfo.storageCode
|
|
3070
|
+
},
|
|
3071
|
+
file,
|
|
3072
|
+
uploadInfo.bucketName || bucketName
|
|
3073
|
+
)
|
|
3074
|
+
);
|
|
3075
|
+
return;
|
|
3076
|
+
}
|
|
3077
|
+
reject(new Error(xhr.statusText || "OSS \u4E0A\u4F20\u5931\u8D25"));
|
|
3078
|
+
};
|
|
3079
|
+
xhr.onerror = () => reject(new Error("OSS \u4E0A\u4F20\u5931\u8D25"));
|
|
3080
|
+
xhr.send(file);
|
|
3081
|
+
});
|
|
3082
|
+
async function uploadOssFile(request, file, bucketName, onProgress, options) {
|
|
3083
|
+
if (!options.appType) throw new Error("OSS \u4E0A\u4F20\u7F3A\u5C11 appType");
|
|
3084
|
+
if (!options.storageCode) throw new Error("OSS \u4E0A\u4F20\u7F3A\u5C11 storageCode");
|
|
3085
|
+
const response = await request({
|
|
3086
|
+
url: `/openxiangda-api/v1/apps/${encodeURIComponent(
|
|
3087
|
+
options.appType
|
|
3088
|
+
)}/storage-configs/${encodeURIComponent(options.storageCode)}/uploads/initiate`,
|
|
3089
|
+
method: "post",
|
|
3090
|
+
data: {
|
|
3091
|
+
fileName: file.name,
|
|
3092
|
+
fileSize: file.size,
|
|
3093
|
+
contentType: file.type || void 0,
|
|
3094
|
+
bucketName
|
|
3095
|
+
}
|
|
3096
|
+
});
|
|
3097
|
+
return uploadWithSignedUrl(file, response.data || response.result, bucketName, onProgress);
|
|
3098
|
+
}
|
|
3099
|
+
async function uploadBuiltinOssFile(request, file, bucketName, onProgress, options) {
|
|
3100
|
+
if (!options.appType) throw new Error("\u5E73\u53F0\u5185\u7F6E OSS \u4E0A\u4F20\u7F3A\u5C11 appType");
|
|
3101
|
+
const response = await request({
|
|
3102
|
+
url: `/openxiangda-api/v1/apps/${encodeURIComponent(
|
|
3103
|
+
options.appType
|
|
3104
|
+
)}/storage/builtin/uploads/initiate`,
|
|
3105
|
+
method: "post",
|
|
3106
|
+
data: {
|
|
3107
|
+
fileName: file.name,
|
|
3108
|
+
fileSize: file.size,
|
|
3109
|
+
contentType: file.type || void 0,
|
|
3110
|
+
bucketName,
|
|
3111
|
+
purpose: options.uploadPurpose
|
|
3112
|
+
}
|
|
3113
|
+
});
|
|
3114
|
+
return uploadWithSignedUrl(file, response.data || response.result, bucketName, onProgress);
|
|
3115
|
+
}
|
|
3116
|
+
async function uploadChunkedFile(request, file, bucketName, baseUrl, onProgress, options = {}) {
|
|
3117
|
+
const initiate = await request({
|
|
3118
|
+
url: "/file/multipart/initiate",
|
|
3119
|
+
method: "post",
|
|
3120
|
+
data: {
|
|
3121
|
+
fileName: file.name,
|
|
3122
|
+
fileSize: file.size,
|
|
3123
|
+
chunkSize: DEFAULT_CHUNK_SIZE,
|
|
3124
|
+
bucketName,
|
|
3125
|
+
visibility: options.visibility,
|
|
3126
|
+
contentType: file.type || void 0
|
|
3127
|
+
}
|
|
3128
|
+
});
|
|
3129
|
+
const uploadInfo = initiate.data || initiate.result;
|
|
3130
|
+
const totalParts = uploadInfo?.totalParts || Math.ceil(file.size / DEFAULT_CHUNK_SIZE);
|
|
3131
|
+
const parts = [];
|
|
3132
|
+
try {
|
|
3133
|
+
for (let index = 0; index < totalParts; index += 1) {
|
|
3134
|
+
const start = index * DEFAULT_CHUNK_SIZE;
|
|
3135
|
+
const end = Math.min(start + DEFAULT_CHUNK_SIZE, file.size);
|
|
3136
|
+
const formData = new FormData();
|
|
3137
|
+
formData.append("file", file.slice(start, end));
|
|
3138
|
+
formData.append("uploadId", uploadInfo.uploadId);
|
|
3139
|
+
formData.append("partNumber", String(index + 1));
|
|
3140
|
+
formData.append("bucketName", uploadInfo.bucketName);
|
|
3141
|
+
formData.append("objectName", uploadInfo.objectName);
|
|
3142
|
+
const part = await request({
|
|
3143
|
+
url: "/file/multipart/upload",
|
|
3144
|
+
method: "post",
|
|
3145
|
+
data: formData
|
|
3146
|
+
});
|
|
3147
|
+
parts.push(part.data || part.result);
|
|
3148
|
+
onProgress?.(Math.round((index + 1) / totalParts * 100));
|
|
3149
|
+
}
|
|
3150
|
+
const completed = await request({
|
|
3151
|
+
url: "/file/multipart/complete",
|
|
3152
|
+
method: "post",
|
|
3153
|
+
data: {
|
|
3154
|
+
uploadId: uploadInfo.uploadId,
|
|
3155
|
+
bucketName: uploadInfo.bucketName,
|
|
3156
|
+
objectName: uploadInfo.objectName,
|
|
3157
|
+
originalName: file.name,
|
|
3158
|
+
contentType: file.type || void 0,
|
|
3159
|
+
parts: parts.sort((a, b) => a.partNumber - b.partNumber)
|
|
3160
|
+
}
|
|
3161
|
+
});
|
|
3162
|
+
return normalizeUploadData(completed.data || completed.result, file, bucketName, baseUrl);
|
|
3163
|
+
} catch (error) {
|
|
3164
|
+
await request({
|
|
3165
|
+
url: "/file/multipart/abort",
|
|
3166
|
+
method: "post",
|
|
3167
|
+
data: {
|
|
3168
|
+
uploadId: uploadInfo?.uploadId,
|
|
3169
|
+
bucketName: uploadInfo?.bucketName,
|
|
3170
|
+
objectName: uploadInfo?.objectName
|
|
3171
|
+
}
|
|
3172
|
+
}).catch(() => void 0);
|
|
3173
|
+
throw error;
|
|
3174
|
+
}
|
|
3175
|
+
}
|
|
3176
|
+
var stripImageCompressionOptions = (options) => {
|
|
3177
|
+
const { imageCompression, ...rest } = options;
|
|
3178
|
+
return rest;
|
|
3179
|
+
};
|
|
3180
|
+
var createSegmentProgress = (onProgress, start, end) => (percent) => {
|
|
3181
|
+
const next = start + (end - start) * Math.max(0, Math.min(100, percent)) / 100;
|
|
3182
|
+
onProgress?.(Math.round(next));
|
|
3183
|
+
};
|
|
3184
|
+
var getAttachmentUrl = (item) => item.publicUrl || item.previewUrl || item.downloadUrl || item.url || "";
|
|
3185
|
+
async function uploadSingleRuntimeFile(request, baseUrl, file, bucketName, onProgress, options, getAuthHeaders) {
|
|
3186
|
+
const singleOptions = stripImageCompressionOptions(options);
|
|
3187
|
+
if (singleOptions.uploadProvider === "builtin-oss") {
|
|
3188
|
+
return uploadBuiltinOssFile(request, file, bucketName, onProgress, singleOptions);
|
|
3189
|
+
}
|
|
3190
|
+
if (singleOptions.uploadProvider === "oss" || singleOptions.storageCode) {
|
|
3191
|
+
return uploadOssFile(request, file, bucketName, onProgress, singleOptions);
|
|
3192
|
+
}
|
|
3193
|
+
if (file.size > CHUNK_UPLOAD_THRESHOLD) {
|
|
3194
|
+
return uploadChunkedFile(request, file, bucketName, baseUrl, onProgress);
|
|
3195
|
+
}
|
|
3196
|
+
return uploadWithXhr(baseUrl, file, bucketName, onProgress, {}, getAuthHeaders);
|
|
3197
|
+
}
|
|
3198
|
+
function toImageVariantMetadata(uploaded, variant) {
|
|
3199
|
+
return {
|
|
3200
|
+
url: getAttachmentUrl(uploaded),
|
|
3201
|
+
objectName: uploaded.objectName,
|
|
3202
|
+
bucketName: uploaded.bucketName,
|
|
3203
|
+
width: variant.width,
|
|
3204
|
+
height: variant.height,
|
|
3205
|
+
size: uploaded.size ?? variant.file.size,
|
|
3206
|
+
contentType: uploaded.contentType || variant.contentType,
|
|
3207
|
+
quality: variant.quality
|
|
3208
|
+
};
|
|
3209
|
+
}
|
|
3210
|
+
async function uploadFileWithImageVariants(request, baseUrl, file, bucketName, onProgress, options, getAuthHeaders) {
|
|
3211
|
+
let variants = [];
|
|
3212
|
+
try {
|
|
3213
|
+
variants = await createCompressedImageVariants(file, options.imageCompression);
|
|
3214
|
+
} catch {
|
|
3215
|
+
variants = [];
|
|
3216
|
+
}
|
|
3217
|
+
if (variants.length === 0) {
|
|
3218
|
+
return uploadSingleRuntimeFile(
|
|
3219
|
+
request,
|
|
3220
|
+
baseUrl,
|
|
3221
|
+
file,
|
|
3222
|
+
bucketName,
|
|
3223
|
+
onProgress,
|
|
3224
|
+
options,
|
|
3225
|
+
getAuthHeaders
|
|
3226
|
+
);
|
|
3227
|
+
}
|
|
3228
|
+
const originalProgressEnd = 70;
|
|
3229
|
+
const uploaded = await uploadSingleRuntimeFile(
|
|
3230
|
+
request,
|
|
3231
|
+
baseUrl,
|
|
3232
|
+
file,
|
|
3233
|
+
bucketName,
|
|
3234
|
+
createSegmentProgress(onProgress, 0, originalProgressEnd),
|
|
3235
|
+
options,
|
|
3236
|
+
getAuthHeaders
|
|
3237
|
+
);
|
|
3238
|
+
const imageVariants = { ...uploaded.variants || {} };
|
|
3239
|
+
const variantProgressStep = (100 - originalProgressEnd) / variants.length;
|
|
3240
|
+
for (let index = 0; index < variants.length; index += 1) {
|
|
3241
|
+
const variant = variants[index];
|
|
3242
|
+
const start = originalProgressEnd + variantProgressStep * index;
|
|
3243
|
+
const end = originalProgressEnd + variantProgressStep * (index + 1);
|
|
3244
|
+
try {
|
|
3245
|
+
const variantUpload = await uploadSingleRuntimeFile(
|
|
3246
|
+
request,
|
|
3247
|
+
baseUrl,
|
|
3248
|
+
variant.file,
|
|
3249
|
+
bucketName,
|
|
3250
|
+
createSegmentProgress(onProgress, start, end),
|
|
3251
|
+
options,
|
|
3252
|
+
getAuthHeaders
|
|
3253
|
+
);
|
|
3254
|
+
imageVariants[variant.kind] = toImageVariantMetadata(variantUpload, variant);
|
|
3255
|
+
} catch {
|
|
3256
|
+
onProgress?.(Math.round(end));
|
|
3257
|
+
}
|
|
3258
|
+
}
|
|
3259
|
+
onProgress?.(100);
|
|
3260
|
+
return {
|
|
3261
|
+
...uploaded,
|
|
3262
|
+
thumbUrl: imageVariants.thumb?.url || uploaded.thumbUrl,
|
|
3263
|
+
previewUrl: imageVariants.preview?.url || uploaded.previewUrl || uploaded.url,
|
|
3264
|
+
variants: imageVariants.thumb || imageVariants.preview ? imageVariants : uploaded.variants
|
|
3265
|
+
};
|
|
3266
|
+
}
|
|
3267
|
+
function createFormRuntimeApi(config) {
|
|
3268
|
+
const { baseUrl = getDefaultBaseUrl(), ...overrides } = config ?? {};
|
|
3269
|
+
const { fetchImpl, getAuthHeaders } = overrides;
|
|
3270
|
+
const request = overrides.request ?? createDefaultRequest(baseUrl, fetchImpl, getAuthHeaders);
|
|
3271
|
+
const defaults = {
|
|
3272
|
+
request,
|
|
3273
|
+
uploadFile: async (file, bucketName = "files", onProgress, options = {}) => {
|
|
3274
|
+
return uploadFileWithImageVariants(
|
|
3275
|
+
request,
|
|
3276
|
+
baseUrl,
|
|
3277
|
+
file,
|
|
3278
|
+
bucketName,
|
|
3279
|
+
onProgress,
|
|
3280
|
+
options,
|
|
3281
|
+
getAuthHeaders
|
|
3282
|
+
);
|
|
3283
|
+
},
|
|
3284
|
+
uploadPublicFile: async (file, bucketName = DEFAULT_PUBLIC_FILE_BUCKET, onProgress) => {
|
|
3285
|
+
if (file.size > CHUNK_UPLOAD_THRESHOLD) {
|
|
3286
|
+
return uploadChunkedFile(request, file, bucketName, baseUrl, onProgress, {
|
|
3287
|
+
visibility: "public"
|
|
3288
|
+
});
|
|
3289
|
+
}
|
|
3290
|
+
return uploadWithXhr(baseUrl, file, bucketName, onProgress, {
|
|
3291
|
+
visibility: "public"
|
|
3292
|
+
}, getAuthHeaders);
|
|
3293
|
+
},
|
|
3294
|
+
deleteFile: async (objectName, bucketName = "files", options = {}) => {
|
|
3295
|
+
if (options.uploadProvider === "builtin-oss" || options.storageScope === "platform") {
|
|
3296
|
+
if (!options.appType) throw new Error("\u5E73\u53F0\u5185\u7F6E OSS \u5220\u9664\u7F3A\u5C11 appType");
|
|
3297
|
+
await request({
|
|
3298
|
+
url: `/openxiangda-api/v1/apps/${encodeURIComponent(
|
|
3299
|
+
options.appType
|
|
3300
|
+
)}/storage/builtin/objects/delete`,
|
|
3301
|
+
method: "post",
|
|
3302
|
+
data: { bucketName, objectName }
|
|
3303
|
+
});
|
|
3304
|
+
return { success: true };
|
|
3305
|
+
}
|
|
3306
|
+
if (options.uploadProvider === "oss" || options.storageCode) {
|
|
3307
|
+
if (!options.appType) throw new Error("OSS \u5220\u9664\u7F3A\u5C11 appType");
|
|
3308
|
+
if (!options.storageCode) throw new Error("OSS \u5220\u9664\u7F3A\u5C11 storageCode");
|
|
3309
|
+
await request({
|
|
3310
|
+
url: `/openxiangda-api/v1/apps/${encodeURIComponent(
|
|
3311
|
+
options.appType
|
|
3312
|
+
)}/storage-configs/${encodeURIComponent(options.storageCode)}/objects/delete`,
|
|
3313
|
+
method: "post",
|
|
3314
|
+
data: { bucketName, objectName }
|
|
3315
|
+
});
|
|
3316
|
+
return { success: true };
|
|
3317
|
+
}
|
|
3318
|
+
await request({ url: "/file/delete", method: "post", data: { bucketName, objectName } });
|
|
3319
|
+
return { success: true };
|
|
3320
|
+
},
|
|
3321
|
+
createDownloadTicket: async (bucketName, objectName, fileName) => {
|
|
3322
|
+
const response = await request({
|
|
3323
|
+
url: "/file/download-ticket",
|
|
3324
|
+
method: "post",
|
|
3325
|
+
data: { bucketName, objectName, fileName }
|
|
3326
|
+
});
|
|
3327
|
+
return normalizeFileTicketResult(baseUrl, response.data || response.result);
|
|
3328
|
+
},
|
|
3329
|
+
createFileAccessTicket: async (bucketName, objectName, fileName, purpose = "preview", options = {}) => {
|
|
3330
|
+
const response = await request({
|
|
3331
|
+
url: "/file/access-ticket",
|
|
3332
|
+
method: "post",
|
|
3333
|
+
data: { bucketName, objectName, fileName, purpose, appType: options.appType }
|
|
3334
|
+
});
|
|
3335
|
+
return normalizeFileTicketResult(baseUrl, response.data || response.result);
|
|
3336
|
+
},
|
|
3337
|
+
getUserById: async (id) => {
|
|
3338
|
+
const response = await request({
|
|
3339
|
+
url: `/user/${id}`,
|
|
3340
|
+
method: "get"
|
|
3341
|
+
});
|
|
3342
|
+
return response.data || response.result;
|
|
3343
|
+
},
|
|
3344
|
+
getUserList: async (params) => {
|
|
3345
|
+
const response = await request({
|
|
3346
|
+
url: "/user/list",
|
|
3347
|
+
method: "get",
|
|
3348
|
+
params
|
|
3349
|
+
});
|
|
3350
|
+
const data = response.data || response.result;
|
|
3351
|
+
return Array.isArray(data) ? data : data?.items || data?.list || [];
|
|
3352
|
+
},
|
|
3353
|
+
getDepartmentRoots: async () => {
|
|
3354
|
+
const response = await request({
|
|
3355
|
+
url: "/department/root",
|
|
3356
|
+
method: "get"
|
|
3357
|
+
});
|
|
3358
|
+
return response.data || response.result || [];
|
|
3359
|
+
},
|
|
3360
|
+
getDepartmentChildren: async (parentId) => {
|
|
3361
|
+
const response = await request({
|
|
3362
|
+
url: `/department/${parentId}/children`,
|
|
3363
|
+
method: "get"
|
|
3364
|
+
});
|
|
3365
|
+
return response.data || response.result || [];
|
|
3366
|
+
},
|
|
3367
|
+
searchDepartments: async (params) => {
|
|
3368
|
+
const page = params?.page ?? 1;
|
|
3369
|
+
const pageSize = params?.pageSize ?? 50;
|
|
3370
|
+
const response = await request({
|
|
3371
|
+
url: "/department/search",
|
|
3372
|
+
method: "get",
|
|
3373
|
+
params: {
|
|
3374
|
+
keyword: params?.keyword,
|
|
3375
|
+
page,
|
|
3376
|
+
pageSize,
|
|
3377
|
+
includePath: params?.includePath ?? true
|
|
3378
|
+
}
|
|
3379
|
+
});
|
|
3380
|
+
const data = response.data || response.result;
|
|
3381
|
+
if (Array.isArray(data)) {
|
|
3382
|
+
return { items: data, total: data.length, page, pageSize };
|
|
3383
|
+
}
|
|
3384
|
+
return {
|
|
3385
|
+
items: data?.items || data?.list || [],
|
|
3386
|
+
total: Number(data?.total ?? data?.count ?? data?.items?.length ?? 0),
|
|
3387
|
+
page: Number(data?.page ?? page),
|
|
3388
|
+
pageSize: Number(data?.pageSize ?? pageSize)
|
|
3389
|
+
};
|
|
3390
|
+
},
|
|
3391
|
+
getDepartmentParentDepartments: async (id) => {
|
|
3392
|
+
const response = await request({
|
|
3393
|
+
url: `/department/${id}/parentDepartments`,
|
|
3394
|
+
method: "get"
|
|
3395
|
+
});
|
|
3396
|
+
return response.data || response.result || [];
|
|
3397
|
+
},
|
|
3398
|
+
getDepartmentMembers: async (id) => {
|
|
3399
|
+
const response = await request({
|
|
3400
|
+
url: `/department/${id}/members`,
|
|
3401
|
+
method: "get"
|
|
3402
|
+
});
|
|
3403
|
+
const data = response.data || response.result;
|
|
3404
|
+
return Array.isArray(data) ? data : data?.items || data?.list || [];
|
|
3405
|
+
},
|
|
3406
|
+
getDepartmentMembersPage: async (id, params) => {
|
|
3407
|
+
const page = params?.page ?? 1;
|
|
3408
|
+
const pageSize = params?.pageSize ?? 20;
|
|
3409
|
+
const response = await request({
|
|
3410
|
+
url: `/department/${id}/members`,
|
|
3411
|
+
method: "get",
|
|
3412
|
+
params: { page, pageSize }
|
|
3413
|
+
});
|
|
3414
|
+
const data = response.data || response.result;
|
|
3415
|
+
const items = Array.isArray(data) ? data : data?.items || data?.list || [];
|
|
3416
|
+
return {
|
|
3417
|
+
items,
|
|
3418
|
+
total: Number(data?.total ?? data?.count ?? items.length),
|
|
3419
|
+
page: Number(data?.page ?? page),
|
|
3420
|
+
pageSize: Number(data?.pageSize ?? pageSize)
|
|
3421
|
+
};
|
|
3422
|
+
},
|
|
3423
|
+
getChinaDivisions: async (parentAdcode) => {
|
|
3424
|
+
const response = await request({
|
|
3425
|
+
url: "/china-divisions",
|
|
3426
|
+
method: "get",
|
|
3427
|
+
params: parentAdcode ? { parentAdcode } : void 0
|
|
3428
|
+
});
|
|
3429
|
+
return response.data || response.result || [];
|
|
3430
|
+
},
|
|
3431
|
+
advancedSearch: async (params) => {
|
|
3432
|
+
const response = await request({
|
|
3433
|
+
url: `/${params.appType}/v1/form/advancedSearch.json`,
|
|
3434
|
+
method: "get",
|
|
3435
|
+
params
|
|
3436
|
+
});
|
|
3437
|
+
return response.result || response.data || {};
|
|
3438
|
+
},
|
|
3439
|
+
getDingTalkSignature: async (url) => {
|
|
3440
|
+
const response = await request({
|
|
3441
|
+
url: "/dingtalk/signature",
|
|
3442
|
+
method: "get",
|
|
3443
|
+
params: { url }
|
|
3444
|
+
});
|
|
3445
|
+
return response.data || response.result;
|
|
3446
|
+
},
|
|
3447
|
+
submitFormData: async (payload) => {
|
|
3448
|
+
const response = await request({
|
|
3449
|
+
url: "/form/submitFormData",
|
|
3450
|
+
method: "post",
|
|
3451
|
+
data: payload
|
|
3452
|
+
});
|
|
3453
|
+
return unwrapBusinessResponse(response);
|
|
3454
|
+
},
|
|
3455
|
+
updateFormData: async (payload) => {
|
|
3456
|
+
const data = normalizeFormInstancePayload(payload);
|
|
3457
|
+
const response = await request({
|
|
3458
|
+
url: `/${data.appType}/v1/form/updateFormData.json`,
|
|
3459
|
+
method: "post",
|
|
3460
|
+
data
|
|
3461
|
+
});
|
|
3462
|
+
return unwrapBusinessResponse(response);
|
|
3463
|
+
},
|
|
3464
|
+
startProcessFromExistingInstance: async (payload) => {
|
|
3465
|
+
const data = normalizeFormInstancePayload(payload);
|
|
3466
|
+
const response = await request({
|
|
3467
|
+
url: `/${data.appType}/v1/form/startProcessFromExistingInstance.json`,
|
|
3468
|
+
method: "post",
|
|
3469
|
+
data
|
|
3470
|
+
});
|
|
3471
|
+
return unwrapBusinessResponse(response);
|
|
3472
|
+
}
|
|
3473
|
+
};
|
|
3474
|
+
return { ...defaults, ...overrides, request };
|
|
3475
|
+
}
|
|
3476
|
+
|
|
3477
|
+
// packages/sdk/src/components/fields/shared/fieldFormat.ts
|
|
3478
|
+
function getUserId(user) {
|
|
3479
|
+
if (typeof user === "string" || typeof user === "number") return String(user).trim();
|
|
3480
|
+
return String(user?.id || user?.userId || user?.userid || user?.value || user?.key || "").trim();
|
|
3481
|
+
}
|
|
3482
|
+
function getUserName(user) {
|
|
3483
|
+
if (typeof user === "string" || typeof user === "number") return String(user).trim();
|
|
3484
|
+
return String(
|
|
3485
|
+
user?.name || user?.label || user?.title || user?.username || user?.nickname || getUserId(user)
|
|
3486
|
+
);
|
|
3487
|
+
}
|
|
3488
|
+
function normalizeUser(user) {
|
|
3489
|
+
const id = getUserId(user);
|
|
3490
|
+
const source = typeof user === "object" && user !== null ? user : {};
|
|
3491
|
+
return {
|
|
3492
|
+
...source,
|
|
3493
|
+
id,
|
|
3494
|
+
name: getUserName({ ...source, id })
|
|
3495
|
+
};
|
|
3496
|
+
}
|
|
3497
|
+
function getDepartmentId(node) {
|
|
3498
|
+
if (typeof node === "string" || typeof node === "number") return String(node).trim();
|
|
3499
|
+
return String(
|
|
3500
|
+
node?.id || node?.departmentId || node?.deptId || node?.value || node?.key || ""
|
|
3501
|
+
).trim();
|
|
3502
|
+
}
|
|
3503
|
+
function getDepartmentName(node) {
|
|
3504
|
+
if (typeof node === "string" || typeof node === "number") return String(node).trim();
|
|
3505
|
+
return String(
|
|
3506
|
+
node?.name || node?.label || node?.title || node?.deptName || node?.departmentName || getDepartmentId(node)
|
|
3507
|
+
);
|
|
3508
|
+
}
|
|
3509
|
+
function normalizeDepartmentNode(node) {
|
|
3510
|
+
const id = getDepartmentId(node);
|
|
3511
|
+
const source = typeof node === "object" && node !== null ? node : {};
|
|
3512
|
+
const name = getDepartmentName({ ...source, id });
|
|
3513
|
+
const hasChildren = typeof node?.hasChildren === "boolean" ? node.hasChildren : Array.isArray(node?.children) && node.children.length > 0;
|
|
3514
|
+
const children = Array.isArray(node?.children) ? node.children.map((child) => normalizeDepartmentNode(child)) : void 0;
|
|
3515
|
+
return {
|
|
3516
|
+
...source,
|
|
3517
|
+
id,
|
|
3518
|
+
name,
|
|
3519
|
+
key: String(node?.key || id),
|
|
3520
|
+
title: String(node?.title || name),
|
|
3521
|
+
hasChildren,
|
|
3522
|
+
isLeaf: typeof node?.isLeaf === "boolean" ? node.isLeaf : !hasChildren,
|
|
3523
|
+
children
|
|
3524
|
+
};
|
|
3525
|
+
}
|
|
3526
|
+
function flattenDepartments(nodes) {
|
|
3527
|
+
const result = [];
|
|
3528
|
+
const walk = (items) => {
|
|
3529
|
+
for (const node of items) {
|
|
3530
|
+
const id = getDepartmentId(node);
|
|
3531
|
+
if (id) result.push({ id, name: getDepartmentName(node), node });
|
|
3532
|
+
if (node.children?.length) walk(node.children);
|
|
3533
|
+
}
|
|
3534
|
+
};
|
|
3535
|
+
walk(nodes);
|
|
3536
|
+
return result;
|
|
3537
|
+
}
|
|
3538
|
+
function formatFileSize(bytes) {
|
|
3539
|
+
if (!bytes) return "";
|
|
3540
|
+
const units = ["B", "KB", "MB", "GB", "TB"];
|
|
3541
|
+
let value = bytes;
|
|
3542
|
+
let index = 0;
|
|
3543
|
+
while (value >= 1024 && index < units.length - 1) {
|
|
3544
|
+
value /= 1024;
|
|
3545
|
+
index += 1;
|
|
3546
|
+
}
|
|
3547
|
+
return `${Number(value.toFixed(value >= 10 || index === 0 ? 0 : 1))} ${units[index]}`;
|
|
3548
|
+
}
|
|
3549
|
+
function getFileExtension(fileName) {
|
|
3550
|
+
return String(fileName || "").split(".").pop()?.toLowerCase() || "";
|
|
3551
|
+
}
|
|
3552
|
+
function isImageFile(fileName, contentType) {
|
|
3553
|
+
return String(contentType || "").startsWith("image/") || [
|
|
3554
|
+
"jpg",
|
|
3555
|
+
"jpeg",
|
|
3556
|
+
"png",
|
|
3557
|
+
"gif",
|
|
3558
|
+
"bmp",
|
|
3559
|
+
"svg",
|
|
3560
|
+
"webp",
|
|
3561
|
+
"avif",
|
|
3562
|
+
"ico",
|
|
3563
|
+
"heic",
|
|
3564
|
+
"heif",
|
|
3565
|
+
"tif",
|
|
3566
|
+
"tiff"
|
|
3567
|
+
].includes(getFileExtension(fileName));
|
|
3568
|
+
}
|
|
3569
|
+
function getFileCategory(fileName, contentType) {
|
|
3570
|
+
const ext = getFileExtension(fileName);
|
|
3571
|
+
if (isImageFile(fileName, contentType)) return "image";
|
|
3572
|
+
if (["mp4", "webm", "ogg", "mov", "m4v"].includes(ext)) return "video";
|
|
3573
|
+
if (["mp3", "wav", "aac", "flac", "m4a", "ogg"].includes(ext)) return "audio";
|
|
3574
|
+
if (ext === "pdf") return "pdf";
|
|
3575
|
+
if (["xls", "xlsx", "csv"].includes(ext)) return "excel";
|
|
3576
|
+
if (["doc", "docx"].includes(ext)) return "word";
|
|
3577
|
+
if (["ppt", "pptx"].includes(ext)) return "ppt";
|
|
3578
|
+
if (["zip", "rar", "7z", "tar", "gz"].includes(ext)) return "archive";
|
|
3579
|
+
if (["txt", "json", "xml", "log", "md"].includes(ext)) return "text";
|
|
3580
|
+
if (["js", "jsx", "ts", "tsx", "html", "css", "scss", "less", "java", "py"].includes(ext)) {
|
|
3581
|
+
return "code";
|
|
3582
|
+
}
|
|
3583
|
+
return "file";
|
|
3584
|
+
}
|
|
3585
|
+
function getAttachmentItemIdentity(item) {
|
|
3586
|
+
return String(item?.uid || item?.id || item?.objectName || item?.url || item?.name || "");
|
|
3587
|
+
}
|
|
3588
|
+
|
|
3589
|
+
// packages/sdk/src/components/file-preview/capabilities.ts
|
|
3590
|
+
var IMAGE_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
3591
|
+
"jpg",
|
|
3592
|
+
"jpeg",
|
|
3593
|
+
"png",
|
|
3594
|
+
"gif",
|
|
3595
|
+
"bmp",
|
|
3596
|
+
"webp",
|
|
3597
|
+
"svg",
|
|
3598
|
+
"avif",
|
|
3599
|
+
"ico",
|
|
3600
|
+
"tif",
|
|
3601
|
+
"tiff",
|
|
3602
|
+
"heic",
|
|
3603
|
+
"heif"
|
|
3604
|
+
]);
|
|
3605
|
+
var VIDEO_EXTENSIONS = /* @__PURE__ */ new Set(["mp4", "webm", "ogg", "ogv", "mov", "m4v"]);
|
|
3606
|
+
var AUDIO_EXTENSIONS = /* @__PURE__ */ new Set(["mp3", "wav", "ogg", "oga", "m4a", "aac", "flac"]);
|
|
3607
|
+
var DIRECT_XLSX_MAX_BYTES = 10 * 1024 * 1024;
|
|
3608
|
+
var DIRECT_DOCX_MAX_BYTES = 20 * 1024 * 1024;
|
|
3609
|
+
var DIRECT_HEIC_MAX_BYTES = 30 * 1024 * 1024;
|
|
3610
|
+
var TEXT_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
3611
|
+
"txt",
|
|
3612
|
+
"csv",
|
|
3613
|
+
"tsv",
|
|
3614
|
+
"json",
|
|
3615
|
+
"xml",
|
|
3616
|
+
"log",
|
|
3617
|
+
"md",
|
|
3618
|
+
"markdown",
|
|
3619
|
+
"yaml",
|
|
3620
|
+
"yml",
|
|
3621
|
+
"ini",
|
|
3622
|
+
"conf",
|
|
3623
|
+
"properties",
|
|
3624
|
+
"sql",
|
|
3625
|
+
"js",
|
|
3626
|
+
"jsx",
|
|
3627
|
+
"ts",
|
|
3628
|
+
"tsx",
|
|
3629
|
+
"css",
|
|
3630
|
+
"scss",
|
|
3631
|
+
"less",
|
|
3632
|
+
"html",
|
|
3633
|
+
"htm",
|
|
3634
|
+
"java",
|
|
3635
|
+
"py",
|
|
3636
|
+
"go",
|
|
3637
|
+
"rs",
|
|
3638
|
+
"sh",
|
|
3639
|
+
"bash",
|
|
3640
|
+
"c",
|
|
3641
|
+
"cc",
|
|
3642
|
+
"cpp",
|
|
3643
|
+
"h",
|
|
3644
|
+
"hpp",
|
|
3645
|
+
"cs",
|
|
3646
|
+
"php",
|
|
3647
|
+
"rb",
|
|
3648
|
+
"vue"
|
|
3649
|
+
]);
|
|
3650
|
+
var unwrapFilePreviewPayload = (payload) => payload?.data ?? payload?.result ?? payload;
|
|
3651
|
+
var getBinaryResponseMessage = (response) => String(
|
|
3652
|
+
response?.message || response?.error || response?.errorMessage || response?.data?.message || response?.data?.error || response?.result?.message || ""
|
|
3653
|
+
).trim();
|
|
3654
|
+
var normalizePreviewBlobResponse = (response) => {
|
|
3655
|
+
const payload = response;
|
|
3656
|
+
const candidates = [
|
|
3657
|
+
response,
|
|
3658
|
+
payload?.blob,
|
|
3659
|
+
payload?.data,
|
|
3660
|
+
payload?.data?.blob,
|
|
3661
|
+
payload?.result,
|
|
3662
|
+
payload?.result?.blob
|
|
3663
|
+
];
|
|
3664
|
+
const blob = candidates.find(
|
|
3665
|
+
(candidate) => typeof Blob !== "undefined" && candidate instanceof Blob
|
|
3666
|
+
);
|
|
3667
|
+
if (blob) return blob;
|
|
3668
|
+
throw new Error(getBinaryResponseMessage(payload) || "\u6587\u4EF6\u5185\u5BB9\u54CD\u5E94\u4E0D\u662F\u4E8C\u8FDB\u5236\u6570\u636E");
|
|
3669
|
+
};
|
|
3670
|
+
var isDirectStorageItem = (item) => item.provider === "oss" || item.uploadProvider === "oss" || item.uploadProvider === "builtin-oss" || Boolean(item.storageCode);
|
|
3671
|
+
var getPreviewItemKey = (item, index = 0) => getAttachmentItemIdentity(item) || item.id || item.uid || `${item.name || "file"}-${index}`;
|
|
3672
|
+
var getPreviewSourceUrl = (item) => item.previewUrl || item.publicUrl || item.url || "";
|
|
3673
|
+
var inferExtensionFromContentType = (contentType) => {
|
|
3674
|
+
if (contentType.includes("wordprocessingml")) return "docx";
|
|
3675
|
+
if (contentType.includes("spreadsheetml")) return "xlsx";
|
|
3676
|
+
if (contentType.includes("pdf")) return "pdf";
|
|
3677
|
+
if (contentType.includes("heic")) return "heic";
|
|
3678
|
+
if (contentType.includes("heif")) return "heif";
|
|
3679
|
+
if (contentType.includes("tiff")) return "tiff";
|
|
3680
|
+
if (contentType.includes("csv")) return "csv";
|
|
3681
|
+
return "";
|
|
3682
|
+
};
|
|
3683
|
+
var downloadOnly = (extension, unsupportedReason) => ({
|
|
3684
|
+
extension,
|
|
3685
|
+
previewType: "download",
|
|
3686
|
+
renderMode: "download",
|
|
3687
|
+
previewSurface: "download",
|
|
3688
|
+
previewProvider: "none",
|
|
3689
|
+
canPreview: false,
|
|
3690
|
+
canDownload: true,
|
|
3691
|
+
unsupportedReason
|
|
3692
|
+
});
|
|
3693
|
+
var resolveLocalPreviewCapability = (item) => {
|
|
3694
|
+
const contentType = String(item.contentType || item.mimeType || "").toLowerCase();
|
|
3695
|
+
const extension = getFileExtension(item.name || item.originalName || item.objectName || "") || inferExtensionFromContentType(contentType);
|
|
3696
|
+
const size = Number(item.size || 0);
|
|
3697
|
+
if (IMAGE_EXTENSIONS.has(extension) || contentType.startsWith("image/")) {
|
|
3698
|
+
if (["heic", "heif"].includes(extension) && size > 0 && size > DIRECT_HEIC_MAX_BYTES) {
|
|
3699
|
+
return downloadOnly(extension, "HEIC \u56FE\u7247\u8D85\u8FC7 30MB \u6D4F\u89C8\u5668\u8F6C\u6362\u4E0A\u9650");
|
|
3700
|
+
}
|
|
3701
|
+
const platformTranscode = ["tif", "tiff"].includes(extension) && Boolean(item.objectName) && !isDirectStorageItem(item);
|
|
3702
|
+
return {
|
|
3703
|
+
extension,
|
|
3704
|
+
previewType: "image",
|
|
3705
|
+
renderMode: ["heic", "heif"].includes(extension) ? "image-heic" : platformTranscode ? "image-transcode" : ["tif", "tiff"].includes(extension) ? "download" : "inline",
|
|
3706
|
+
previewSurface: "media",
|
|
3707
|
+
previewProvider: platformTranscode ? "platform" : "browser",
|
|
3708
|
+
canPreview: platformTranscode || !["tif", "tiff"].includes(extension),
|
|
3709
|
+
canDownload: true,
|
|
3710
|
+
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
|
|
3711
|
+
};
|
|
3712
|
+
}
|
|
3713
|
+
if (VIDEO_EXTENSIONS.has(extension) || contentType.startsWith("video/")) {
|
|
3714
|
+
return {
|
|
3715
|
+
extension,
|
|
3716
|
+
previewType: "video",
|
|
3717
|
+
renderMode: "inline",
|
|
3718
|
+
previewSurface: "media",
|
|
3719
|
+
previewProvider: "browser",
|
|
3720
|
+
canPreview: true,
|
|
3721
|
+
canDownload: true
|
|
3722
|
+
};
|
|
3723
|
+
}
|
|
3724
|
+
if (AUDIO_EXTENSIONS.has(extension) || contentType.startsWith("audio/")) {
|
|
3725
|
+
return {
|
|
3726
|
+
extension,
|
|
3727
|
+
previewType: "audio",
|
|
3728
|
+
renderMode: "inline",
|
|
3729
|
+
previewSurface: "media",
|
|
3730
|
+
previewProvider: "browser",
|
|
3731
|
+
canPreview: true,
|
|
3732
|
+
canDownload: true
|
|
3733
|
+
};
|
|
3734
|
+
}
|
|
3735
|
+
if (extension === "pdf" || contentType.includes("pdf")) {
|
|
3736
|
+
return {
|
|
3737
|
+
extension: extension || "pdf",
|
|
3738
|
+
previewType: "pdf",
|
|
3739
|
+
renderMode: "pdfjs",
|
|
3740
|
+
previewSurface: "document",
|
|
3741
|
+
previewProvider: "browser",
|
|
3742
|
+
canPreview: true,
|
|
3743
|
+
canDownload: true
|
|
3744
|
+
};
|
|
3745
|
+
}
|
|
3746
|
+
if (extension === "docx") {
|
|
3747
|
+
if (size > 0 && size > DIRECT_DOCX_MAX_BYTES) {
|
|
3748
|
+
return downloadOnly(extension, "Word \u6587\u4EF6\u8D85\u8FC7 20MB \u6D4F\u89C8\u5668\u9884\u89C8\u4E0A\u9650");
|
|
3749
|
+
}
|
|
3750
|
+
return {
|
|
3751
|
+
extension,
|
|
3752
|
+
previewType: "office",
|
|
3753
|
+
renderMode: "docx-html",
|
|
3754
|
+
previewSurface: "document",
|
|
3755
|
+
previewProvider: "browser",
|
|
3756
|
+
canPreview: true,
|
|
3757
|
+
canDownload: true
|
|
3758
|
+
};
|
|
3759
|
+
}
|
|
3760
|
+
if (extension === "xlsx") {
|
|
3761
|
+
if (size > 0 && size > DIRECT_XLSX_MAX_BYTES) {
|
|
3762
|
+
return downloadOnly(extension, "Excel \u6587\u4EF6\u8D85\u8FC7 10MB \u6D4F\u89C8\u5668\u9884\u89C8\u4E0A\u9650");
|
|
3763
|
+
}
|
|
3764
|
+
return {
|
|
3765
|
+
extension,
|
|
3766
|
+
previewType: "spreadsheet",
|
|
3767
|
+
renderMode: "excel-client",
|
|
3768
|
+
previewSurface: "document",
|
|
3769
|
+
previewProvider: "browser",
|
|
3770
|
+
canPreview: true,
|
|
3771
|
+
canDownload: true
|
|
3772
|
+
};
|
|
3773
|
+
}
|
|
3774
|
+
if (TEXT_EXTENSIONS.has(extension) || contentType.startsWith("text/")) {
|
|
3775
|
+
return {
|
|
3776
|
+
extension,
|
|
3777
|
+
previewType: "text",
|
|
3778
|
+
renderMode: "text-client",
|
|
3779
|
+
previewSurface: "document",
|
|
3780
|
+
previewProvider: "browser",
|
|
3781
|
+
canPreview: true,
|
|
3782
|
+
canDownload: true
|
|
3783
|
+
};
|
|
3784
|
+
}
|
|
3785
|
+
return downloadOnly(extension, "\u5F53\u524D\u6587\u4EF6\u7C7B\u578B\u6CA1\u6709\u53EF\u7528\u7684\u5728\u7EBF\u9884\u89C8\u5668");
|
|
3786
|
+
};
|
|
3787
|
+
var getTicketObject = (ticket) => typeof ticket === "string" ? { previewUrl: ticket } : ticket || {};
|
|
3788
|
+
var prepareFilePreview = async (options) => {
|
|
3789
|
+
const { item, api, appType, bucketName } = options;
|
|
3790
|
+
const direct = isDirectStorageItem(item) || !item.objectName;
|
|
3791
|
+
if (direct) {
|
|
3792
|
+
const capability = resolveLocalPreviewCapability(item);
|
|
3793
|
+
return {
|
|
3794
|
+
item,
|
|
3795
|
+
direct: true,
|
|
3796
|
+
metadata: {
|
|
3797
|
+
...capability,
|
|
3798
|
+
fileName: item.name,
|
|
3799
|
+
size: item.size,
|
|
3800
|
+
contentType: item.contentType || item.mimeType,
|
|
3801
|
+
previewUrl: getPreviewSourceUrl(item),
|
|
3802
|
+
downloadUrl: item.downloadUrl || item.publicUrl || item.url
|
|
3803
|
+
}
|
|
3804
|
+
};
|
|
3805
|
+
}
|
|
3806
|
+
const ticketResult = getTicketObject(
|
|
3807
|
+
await api.createFileAccessTicket(
|
|
3808
|
+
item.bucketName || bucketName,
|
|
3809
|
+
item.objectName,
|
|
3810
|
+
item.name,
|
|
3811
|
+
"preview",
|
|
3812
|
+
{ appType: item.appType || appType }
|
|
3813
|
+
)
|
|
3814
|
+
);
|
|
3815
|
+
const localCapability = resolveLocalPreviewCapability(item);
|
|
3816
|
+
const ticket = String(ticketResult.ticket || "").trim();
|
|
3817
|
+
let metadata = {};
|
|
3818
|
+
if (ticketResult.metadataUrl || ticket) {
|
|
3819
|
+
const response = await api.request({
|
|
3820
|
+
url: ticketResult.metadataUrl || `/file/access-ticket/${encodeURIComponent(ticket)}`,
|
|
3821
|
+
method: "get"
|
|
3822
|
+
});
|
|
3823
|
+
metadata = unwrapFilePreviewPayload(response);
|
|
3824
|
+
}
|
|
3825
|
+
return {
|
|
3826
|
+
item,
|
|
3827
|
+
direct: false,
|
|
3828
|
+
metadata: {
|
|
3829
|
+
...localCapability,
|
|
3830
|
+
...ticketResult,
|
|
3831
|
+
...metadata,
|
|
3832
|
+
ticket: metadata.ticket || ticketResult.ticket,
|
|
3833
|
+
fileName: metadata.fileName || ticketResult.fileName || item.name,
|
|
3834
|
+
size: metadata.size ?? item.size,
|
|
3835
|
+
contentType: metadata.contentType || ticketResult.contentType || item.contentType || item.mimeType,
|
|
3836
|
+
previewUrl: ticketResult.previewUrl || metadata.previewUrl || getPreviewSourceUrl(item),
|
|
3837
|
+
downloadUrl: ticketResult.downloadUrl || metadata.downloadUrl || item.downloadUrl || item.publicUrl || item.url
|
|
3838
|
+
}
|
|
3839
|
+
};
|
|
3840
|
+
};
|
|
3841
|
+
var loadPreviewBlob = async (request, url) => {
|
|
3842
|
+
const response = await request({ url, method: "get", responseType: "blob" });
|
|
3843
|
+
return normalizePreviewBlobResponse(response);
|
|
3844
|
+
};
|
|
3845
|
+
var convertHeicPreview = async (request, url) => {
|
|
3846
|
+
const source = await loadPreviewBlob(request, url);
|
|
3847
|
+
const module = await import("heic2any");
|
|
3848
|
+
const converted = await module.default({
|
|
3849
|
+
blob: source,
|
|
3850
|
+
toType: "image/jpeg",
|
|
3851
|
+
quality: 0.92
|
|
3852
|
+
});
|
|
3853
|
+
const blob = Array.isArray(converted) ? converted[0] : converted;
|
|
3854
|
+
if (!(blob instanceof Blob)) {
|
|
3855
|
+
throw new Error("HEIC \u56FE\u7247\u8F6C\u6362\u5931\u8D25");
|
|
3856
|
+
}
|
|
3857
|
+
return URL.createObjectURL(blob);
|
|
3858
|
+
};
|
|
3859
|
+
|
|
3860
|
+
// packages/sdk/src/components/file-preview/FilePreviewContent.tsx
|
|
3861
|
+
import { useEffect as useEffect3, useMemo as useMemo4, useRef as useRef2, useState as useState3 } from "react";
|
|
3862
|
+
import { Alert, Button, Empty, Image as Image2, Spin, Table, Tabs, Typography } from "antd";
|
|
3863
|
+
import { DownloadOutlined, FileOutlined, ReloadOutlined } from "@ant-design/icons";
|
|
3864
|
+
import { jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
3865
|
+
var formatPreviewFileSize = (size) => {
|
|
3866
|
+
const value = Number(size || 0);
|
|
3867
|
+
if (!value) return "0 B";
|
|
3868
|
+
const units = ["B", "KB", "MB", "GB"];
|
|
3869
|
+
const index = Math.min(
|
|
3870
|
+
units.length - 1,
|
|
3871
|
+
Math.floor(Math.log(value) / Math.log(1024))
|
|
3872
|
+
);
|
|
3873
|
+
return `${(value / Math.pow(1024, index)).toFixed(index === 0 ? 0 : 1)} ${units[index]}`;
|
|
3874
|
+
};
|
|
3875
|
+
var resolvePreviewServiceUrl = (url, servicePrefix = "/service") => {
|
|
3876
|
+
const value = String(url || "").trim();
|
|
3877
|
+
if (!value) return "";
|
|
3878
|
+
if (/^(https?:)?\/\//i.test(value) || /^(blob|data):/i.test(value)) return value;
|
|
3879
|
+
if (value === servicePrefix || value.startsWith(`${servicePrefix}/`)) return value;
|
|
3880
|
+
if (value.startsWith("/file/")) {
|
|
3881
|
+
return `${servicePrefix.replace(/\/+$/, "")}${value}`;
|
|
3882
|
+
}
|
|
3883
|
+
return value;
|
|
3884
|
+
};
|
|
3885
|
+
var toColumnName = (index) => {
|
|
3886
|
+
let value = index + 1;
|
|
3887
|
+
let name = "";
|
|
3888
|
+
while (value > 0) {
|
|
3889
|
+
const mod = (value - 1) % 26;
|
|
3890
|
+
name = String.fromCharCode(65 + mod) + name;
|
|
3891
|
+
value = Math.floor((value - mod) / 26);
|
|
3892
|
+
}
|
|
3893
|
+
return name;
|
|
3894
|
+
};
|
|
3895
|
+
var buildRowsTable = (rows = []) => {
|
|
3896
|
+
const maxColumns = rows.reduce(
|
|
3897
|
+
(count, row) => Math.max(count, Array.isArray(row) ? row.length : 0),
|
|
3898
|
+
0
|
|
3899
|
+
);
|
|
3900
|
+
const columns = [
|
|
3901
|
+
{
|
|
3902
|
+
title: "#",
|
|
3903
|
+
dataIndex: "__row",
|
|
3904
|
+
key: "__row",
|
|
3905
|
+
width: 58,
|
|
3906
|
+
fixed: "left",
|
|
3907
|
+
render: (value) => /* @__PURE__ */ jsx3(Typography.Text, { type: "secondary", children: value })
|
|
3908
|
+
},
|
|
3909
|
+
...Array.from({ length: maxColumns }).map((_, index) => ({
|
|
3910
|
+
title: toColumnName(index),
|
|
3911
|
+
dataIndex: `col_${index}`,
|
|
3912
|
+
key: `col_${index}`,
|
|
3913
|
+
width: 168,
|
|
3914
|
+
render: (value) => /* @__PURE__ */ jsx3(Typography.Text, { ellipsis: { tooltip: String(value ?? "") }, children: String(value ?? "") })
|
|
3915
|
+
}))
|
|
3916
|
+
];
|
|
3917
|
+
const dataSource = rows.map((row, rowIndex) => {
|
|
3918
|
+
const record = { key: rowIndex, __row: rowIndex + 1 };
|
|
3919
|
+
(Array.isArray(row) ? row : []).forEach((value, colIndex) => {
|
|
3920
|
+
record[`col_${colIndex}`] = value;
|
|
3921
|
+
});
|
|
3922
|
+
return record;
|
|
3923
|
+
});
|
|
3924
|
+
return { columns, dataSource };
|
|
3925
|
+
};
|
|
3926
|
+
var CenteredState = ({ children }) => /* @__PURE__ */ jsx3(
|
|
3927
|
+
"div",
|
|
3928
|
+
{
|
|
3929
|
+
style: {
|
|
3930
|
+
minHeight: 280,
|
|
3931
|
+
height: "100%",
|
|
3932
|
+
display: "flex",
|
|
3933
|
+
alignItems: "center",
|
|
3934
|
+
justifyContent: "center",
|
|
3935
|
+
padding: 24
|
|
3936
|
+
},
|
|
3937
|
+
children
|
|
3938
|
+
}
|
|
3939
|
+
);
|
|
3940
|
+
var PayloadPreview = ({
|
|
3941
|
+
request,
|
|
3942
|
+
url,
|
|
3943
|
+
mode
|
|
3944
|
+
}) => {
|
|
3945
|
+
const [payload, setPayload] = useState3(null);
|
|
3946
|
+
const [loading, setLoading] = useState3(false);
|
|
3947
|
+
const [error, setError] = useState3("");
|
|
3948
|
+
const [reloadKey, setReloadKey] = useState3(0);
|
|
3949
|
+
useEffect3(() => {
|
|
3950
|
+
let disposed = false;
|
|
3951
|
+
setPayload(null);
|
|
3952
|
+
setError("");
|
|
3953
|
+
if (!url) return () => {
|
|
3954
|
+
disposed = true;
|
|
3955
|
+
};
|
|
3956
|
+
setLoading(true);
|
|
3957
|
+
request({ url, method: "get" }).then((response) => {
|
|
3958
|
+
if (!disposed) setPayload(unwrapFilePreviewPayload(response));
|
|
3959
|
+
}).catch((currentError) => {
|
|
3960
|
+
if (!disposed) setError(currentError?.message || "\u6587\u4EF6\u9884\u89C8\u5185\u5BB9\u52A0\u8F7D\u5931\u8D25");
|
|
3961
|
+
}).finally(() => {
|
|
3962
|
+
if (!disposed) setLoading(false);
|
|
3963
|
+
});
|
|
3964
|
+
return () => {
|
|
3965
|
+
disposed = true;
|
|
3966
|
+
};
|
|
3967
|
+
}, [reloadKey, request, url]);
|
|
3968
|
+
if (loading) {
|
|
3969
|
+
return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Spin, { description: mode === "excel" ? "\u6B63\u5728\u89E3\u6790\u5DE5\u4F5C\u7C3F..." : "\u6B63\u5728\u8BFB\u53D6\u6587\u672C..." }) });
|
|
3970
|
+
}
|
|
3971
|
+
if (error) {
|
|
3972
|
+
return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(
|
|
3973
|
+
Alert,
|
|
3974
|
+
{
|
|
3975
|
+
type: "error",
|
|
3976
|
+
showIcon: true,
|
|
3977
|
+
title: error,
|
|
3978
|
+
action: /* @__PURE__ */ jsx3(Button, { icon: /* @__PURE__ */ jsx3(ReloadOutlined, {}), onClick: () => setReloadKey((value) => value + 1), children: "\u91CD\u8BD5" })
|
|
3979
|
+
}
|
|
3980
|
+
) });
|
|
3981
|
+
}
|
|
3982
|
+
if (mode === "excel") {
|
|
3983
|
+
const sheets = Array.isArray(payload?.sheets) ? payload.sheets : [];
|
|
3984
|
+
if (!sheets.length) {
|
|
3985
|
+
return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Empty, { description: "\u6682\u65E0\u53EF\u9884\u89C8\u7684\u5DE5\u4F5C\u8868" }) });
|
|
3986
|
+
}
|
|
3987
|
+
return /* @__PURE__ */ jsx3(
|
|
3988
|
+
Tabs,
|
|
3989
|
+
{
|
|
3990
|
+
style: { height: "100%", padding: "0 16px" },
|
|
3991
|
+
items: sheets.map((sheet) => {
|
|
3992
|
+
const table = buildRowsTable(sheet.rows || []);
|
|
3993
|
+
return {
|
|
3994
|
+
key: String(sheet.id || sheet.name),
|
|
3995
|
+
label: sheet.name || "Sheet",
|
|
3996
|
+
children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
|
|
3997
|
+
sheet.truncatedRows || sheet.truncatedColumns ? /* @__PURE__ */ jsx3(
|
|
3998
|
+
Alert,
|
|
3999
|
+
{
|
|
4000
|
+
type: "info",
|
|
4001
|
+
showIcon: true,
|
|
4002
|
+
title: `\u5DE5\u4F5C\u8868\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D ${payload.maxRows || 200} \u884C\u3001${payload.maxColumns || 60} \u5217\u3002`
|
|
4003
|
+
}
|
|
4004
|
+
) : null,
|
|
4005
|
+
/* @__PURE__ */ jsx3(
|
|
4006
|
+
Table,
|
|
4007
|
+
{
|
|
4008
|
+
bordered: true,
|
|
4009
|
+
size: "small",
|
|
4010
|
+
pagination: false,
|
|
4011
|
+
scroll: { x: "max-content", y: "min(66vh, 680px)" },
|
|
4012
|
+
columns: table.columns,
|
|
4013
|
+
dataSource: table.dataSource
|
|
4014
|
+
}
|
|
4015
|
+
)
|
|
4016
|
+
] })
|
|
4017
|
+
};
|
|
4018
|
+
})
|
|
4019
|
+
}
|
|
4020
|
+
);
|
|
4021
|
+
}
|
|
4022
|
+
const text = String(payload?.text || "");
|
|
4023
|
+
return /* @__PURE__ */ jsxs("div", { style: { height: "100%", overflow: "auto", background: "#fff" }, children: [
|
|
4024
|
+
payload?.truncated ? /* @__PURE__ */ jsx3(
|
|
4025
|
+
Alert,
|
|
4026
|
+
{
|
|
4027
|
+
type: "info",
|
|
4028
|
+
showIcon: true,
|
|
4029
|
+
banner: true,
|
|
4030
|
+
title: "\u6587\u4EF6\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D\u90E8\u5185\u5BB9\uFF1B\u5B8C\u6574\u5185\u5BB9\u8BF7\u4E0B\u8F7D\u67E5\u770B\u3002"
|
|
4031
|
+
}
|
|
4032
|
+
) : null,
|
|
4033
|
+
/* @__PURE__ */ jsx3(
|
|
4034
|
+
"pre",
|
|
4035
|
+
{
|
|
4036
|
+
style: {
|
|
4037
|
+
minHeight: 280,
|
|
4038
|
+
margin: 0,
|
|
4039
|
+
padding: 20,
|
|
4040
|
+
color: "#1f2328",
|
|
4041
|
+
background: "#fff",
|
|
4042
|
+
fontSize: 13,
|
|
4043
|
+
lineHeight: 1.7,
|
|
4044
|
+
whiteSpace: "pre-wrap",
|
|
4045
|
+
wordBreak: "break-word",
|
|
4046
|
+
fontFamily: 'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", monospace'
|
|
4047
|
+
},
|
|
4048
|
+
children: text || "\u6682\u65E0\u6587\u672C\u5185\u5BB9"
|
|
4049
|
+
}
|
|
4050
|
+
)
|
|
4051
|
+
] });
|
|
4052
|
+
};
|
|
4053
|
+
var ClientTextPreview = ({
|
|
4054
|
+
request,
|
|
4055
|
+
url
|
|
4056
|
+
}) => {
|
|
4057
|
+
const [payload, setPayload] = useState3(null);
|
|
4058
|
+
const [error, setError] = useState3("");
|
|
4059
|
+
useEffect3(() => {
|
|
4060
|
+
let disposed = false;
|
|
4061
|
+
let textLimit = 1024 * 1024;
|
|
4062
|
+
loadPreviewBlob(request, url).then(async (blob) => {
|
|
4063
|
+
const slice = blob.size > textLimit ? blob.slice(0, textLimit) : blob;
|
|
4064
|
+
const text = await slice.text();
|
|
4065
|
+
if (!disposed) setPayload({ text, truncated: blob.size > textLimit });
|
|
4066
|
+
}).catch((currentError) => {
|
|
4067
|
+
if (!disposed) setError(currentError?.message || "\u6587\u672C\u8BFB\u53D6\u5931\u8D25");
|
|
4068
|
+
});
|
|
4069
|
+
return () => {
|
|
4070
|
+
disposed = true;
|
|
4071
|
+
textLimit = 0;
|
|
4072
|
+
};
|
|
4073
|
+
}, [request, url]);
|
|
4074
|
+
if (error) return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Alert, { type: "error", showIcon: true, title: error }) });
|
|
4075
|
+
if (!payload) return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Spin, { description: "\u6B63\u5728\u8BFB\u53D6\u6587\u672C..." }) });
|
|
4076
|
+
return /* @__PURE__ */ jsxs("div", { style: { height: "100%", overflow: "auto", background: "#fff" }, children: [
|
|
4077
|
+
payload.truncated ? /* @__PURE__ */ jsx3(Alert, { type: "info", showIcon: true, banner: true, title: "\u6587\u4EF6\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D\u90E8\u5185\u5BB9\u3002" }) : null,
|
|
4078
|
+
/* @__PURE__ */ jsx3(
|
|
4079
|
+
"pre",
|
|
4080
|
+
{
|
|
4081
|
+
style: {
|
|
4082
|
+
margin: 0,
|
|
4083
|
+
padding: 20,
|
|
4084
|
+
whiteSpace: "pre-wrap",
|
|
4085
|
+
wordBreak: "break-word",
|
|
4086
|
+
fontSize: 13,
|
|
4087
|
+
lineHeight: 1.7
|
|
4088
|
+
},
|
|
4089
|
+
children: payload.text || "\u6682\u65E0\u6587\u672C\u5185\u5BB9"
|
|
4090
|
+
}
|
|
4091
|
+
)
|
|
4092
|
+
] });
|
|
4093
|
+
};
|
|
4094
|
+
var DocxPreview = ({ request, url }) => {
|
|
4095
|
+
const containerRef = useRef2(null);
|
|
4096
|
+
const [loading, setLoading] = useState3(true);
|
|
4097
|
+
const [error, setError] = useState3("");
|
|
4098
|
+
useEffect3(() => {
|
|
4099
|
+
let disposed = false;
|
|
4100
|
+
const container = containerRef.current;
|
|
4101
|
+
if (!container || !url) return () => {
|
|
4102
|
+
disposed = true;
|
|
4103
|
+
};
|
|
4104
|
+
container.innerHTML = "";
|
|
4105
|
+
setLoading(true);
|
|
4106
|
+
setError("");
|
|
4107
|
+
(async () => {
|
|
4108
|
+
try {
|
|
4109
|
+
const blob = await loadPreviewBlob(request, url);
|
|
4110
|
+
const { renderAsync } = await import("docx-preview");
|
|
4111
|
+
if (disposed || !containerRef.current) return;
|
|
4112
|
+
await renderAsync(blob, containerRef.current, containerRef.current, {
|
|
4113
|
+
className: "sy-docx-preview",
|
|
4114
|
+
inWrapper: true,
|
|
4115
|
+
breakPages: true,
|
|
4116
|
+
ignoreLastRenderedPageBreak: false,
|
|
4117
|
+
renderHeaders: true,
|
|
4118
|
+
renderFooters: true,
|
|
4119
|
+
renderFootnotes: true,
|
|
4120
|
+
renderEndnotes: true,
|
|
4121
|
+
useBase64URL: false
|
|
4122
|
+
});
|
|
4123
|
+
} catch (currentError) {
|
|
4124
|
+
if (!disposed) setError(currentError?.message || "Word \u6587\u6863\u89E3\u6790\u5931\u8D25");
|
|
4125
|
+
} finally {
|
|
4126
|
+
if (!disposed) setLoading(false);
|
|
4127
|
+
}
|
|
4128
|
+
})();
|
|
4129
|
+
return () => {
|
|
4130
|
+
disposed = true;
|
|
4131
|
+
if (container) container.innerHTML = "";
|
|
4132
|
+
};
|
|
4133
|
+
}, [request, url]);
|
|
4134
|
+
return /* @__PURE__ */ jsxs(
|
|
4135
|
+
"div",
|
|
4136
|
+
{
|
|
4137
|
+
style: {
|
|
4138
|
+
minHeight: 360,
|
|
4139
|
+
height: "100%",
|
|
4140
|
+
overflow: "auto",
|
|
4141
|
+
position: "relative",
|
|
4142
|
+
background: "#e9edf2"
|
|
4143
|
+
},
|
|
4144
|
+
children: [
|
|
4145
|
+
loading ? /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Spin, { description: "\u6B63\u5728\u8FD8\u539F Word \u7248\u5F0F..." }) }) : null,
|
|
4146
|
+
error ? /* @__PURE__ */ jsx3("div", { style: { padding: 20 }, children: /* @__PURE__ */ jsx3(Alert, { type: "error", showIcon: true, title: error }) }) : null,
|
|
4147
|
+
/* @__PURE__ */ jsx3("div", { ref: containerRef, style: { display: loading || error ? "none" : "block" } })
|
|
4148
|
+
]
|
|
4149
|
+
}
|
|
4150
|
+
);
|
|
4151
|
+
};
|
|
4152
|
+
var HeicImagePreview = ({
|
|
4153
|
+
request,
|
|
4154
|
+
url,
|
|
4155
|
+
fileName
|
|
4156
|
+
}) => {
|
|
4157
|
+
const [src, setSrc] = useState3("");
|
|
4158
|
+
const [error, setError] = useState3("");
|
|
4159
|
+
useEffect3(() => {
|
|
4160
|
+
let disposed = false;
|
|
4161
|
+
let objectUrl = "";
|
|
4162
|
+
convertHeicPreview(request, url).then((result) => {
|
|
4163
|
+
objectUrl = result;
|
|
4164
|
+
if (!disposed) setSrc(result);
|
|
4165
|
+
}).catch((currentError) => {
|
|
4166
|
+
if (!disposed) setError(currentError?.message || "HEIC \u56FE\u7247\u8F6C\u6362\u5931\u8D25");
|
|
4167
|
+
});
|
|
4168
|
+
return () => {
|
|
4169
|
+
disposed = true;
|
|
4170
|
+
if (objectUrl) URL.revokeObjectURL?.(objectUrl);
|
|
4171
|
+
};
|
|
4172
|
+
}, [request, url]);
|
|
4173
|
+
if (error) return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Alert, { type: "error", showIcon: true, title: error }) });
|
|
4174
|
+
if (!src) return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Spin, { description: "\u6B63\u5728\u8F6C\u6362 HEIC \u56FE\u7247..." }) });
|
|
4175
|
+
return /* @__PURE__ */ jsx3("div", { style: { minHeight: 320, textAlign: "center", padding: 20, background: "#f3f5f7" }, children: /* @__PURE__ */ jsx3(
|
|
4176
|
+
Image2,
|
|
4177
|
+
{
|
|
4178
|
+
src,
|
|
4179
|
+
alt: fileName || "HEIC \u56FE\u7247\u9884\u89C8",
|
|
4180
|
+
style: { maxWidth: "100%", maxHeight: "72vh", objectFit: "contain" }
|
|
4181
|
+
}
|
|
4182
|
+
) });
|
|
4183
|
+
};
|
|
4184
|
+
var ClientSpreadsheetPreview = ({
|
|
4185
|
+
request,
|
|
4186
|
+
url
|
|
4187
|
+
}) => {
|
|
4188
|
+
const [payload, setPayload] = useState3(null);
|
|
4189
|
+
const [error, setError] = useState3("");
|
|
4190
|
+
useEffect3(() => {
|
|
4191
|
+
let disposed = false;
|
|
4192
|
+
(async () => {
|
|
4193
|
+
try {
|
|
4194
|
+
const blob = await loadPreviewBlob(request, url);
|
|
4195
|
+
const XLSX = await import("xlsx");
|
|
4196
|
+
const workbook = XLSX.read(await blob.arrayBuffer(), {
|
|
4197
|
+
cellDates: true,
|
|
4198
|
+
dense: true
|
|
4199
|
+
});
|
|
4200
|
+
const maxRows = 500;
|
|
4201
|
+
const maxColumns = 100;
|
|
4202
|
+
const sheets = workbook.SheetNames.map((name, index) => {
|
|
4203
|
+
const allRows = XLSX.utils.sheet_to_json(workbook.Sheets[name], {
|
|
4204
|
+
header: 1,
|
|
4205
|
+
defval: "",
|
|
4206
|
+
raw: false
|
|
4207
|
+
});
|
|
4208
|
+
const columnCount = allRows.reduce(
|
|
4209
|
+
(count, row) => Math.max(count, Array.isArray(row) ? row.length : 0),
|
|
4210
|
+
0
|
|
4211
|
+
);
|
|
4212
|
+
return {
|
|
4213
|
+
id: index,
|
|
4214
|
+
name,
|
|
4215
|
+
rows: allRows.slice(0, maxRows).map(
|
|
4216
|
+
(row) => (Array.isArray(row) ? row : []).slice(0, maxColumns)
|
|
4217
|
+
),
|
|
4218
|
+
truncatedRows: allRows.length > maxRows,
|
|
4219
|
+
truncatedColumns: columnCount > maxColumns
|
|
4220
|
+
};
|
|
4221
|
+
});
|
|
4222
|
+
if (!disposed) setPayload({ sheets, maxRows, maxColumns });
|
|
4223
|
+
} catch (currentError) {
|
|
4224
|
+
if (!disposed) setError(currentError?.message || "Excel \u6587\u4EF6\u89E3\u6790\u5931\u8D25");
|
|
4225
|
+
}
|
|
4226
|
+
})();
|
|
4227
|
+
return () => {
|
|
4228
|
+
disposed = true;
|
|
4229
|
+
};
|
|
4230
|
+
}, [request, url]);
|
|
4231
|
+
if (error) return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Alert, { type: "error", showIcon: true, title: error }) });
|
|
4232
|
+
if (!payload) return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Spin, { description: "\u6B63\u5728\u89E3\u6790\u5DE5\u4F5C\u7C3F..." }) });
|
|
4233
|
+
return /* @__PURE__ */ jsx3(PayloadPreviewFromValue, { payload });
|
|
4234
|
+
};
|
|
4235
|
+
var PayloadPreviewFromValue = ({ payload }) => {
|
|
4236
|
+
const sheets = Array.isArray(payload?.sheets) ? payload.sheets : [];
|
|
4237
|
+
if (!sheets.length) return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Empty, { description: "\u6682\u65E0\u53EF\u9884\u89C8\u7684\u5DE5\u4F5C\u8868" }) });
|
|
4238
|
+
return /* @__PURE__ */ jsx3(
|
|
4239
|
+
Tabs,
|
|
4240
|
+
{
|
|
4241
|
+
style: { height: "100%", padding: "0 16px" },
|
|
4242
|
+
items: sheets.map((sheet) => {
|
|
4243
|
+
const table = buildRowsTable(sheet.rows || []);
|
|
4244
|
+
return {
|
|
4245
|
+
key: String(sheet.id ?? sheet.name),
|
|
4246
|
+
label: sheet.name || "Sheet",
|
|
4247
|
+
children: /* @__PURE__ */ jsxs("div", { style: { display: "flex", flexDirection: "column", gap: 12 }, children: [
|
|
4248
|
+
sheet.truncatedRows || sheet.truncatedColumns ? /* @__PURE__ */ jsx3(
|
|
4249
|
+
Alert,
|
|
4250
|
+
{
|
|
4251
|
+
type: "info",
|
|
4252
|
+
showIcon: true,
|
|
4253
|
+
title: `\u5DE5\u4F5C\u8868\u8F83\u5927\uFF0C\u4EC5\u5C55\u793A\u524D ${payload.maxRows} \u884C\u3001${payload.maxColumns} \u5217\u3002`
|
|
4254
|
+
}
|
|
4255
|
+
) : null,
|
|
4256
|
+
/* @__PURE__ */ jsx3(
|
|
4257
|
+
Table,
|
|
4258
|
+
{
|
|
4259
|
+
bordered: true,
|
|
4260
|
+
size: "small",
|
|
4261
|
+
pagination: false,
|
|
4262
|
+
scroll: { x: "max-content", y: "min(66vh, 680px)" },
|
|
4263
|
+
columns: table.columns,
|
|
4264
|
+
dataSource: table.dataSource
|
|
4265
|
+
}
|
|
4266
|
+
)
|
|
4267
|
+
] })
|
|
4268
|
+
};
|
|
4269
|
+
})
|
|
4270
|
+
}
|
|
4271
|
+
);
|
|
4272
|
+
};
|
|
4273
|
+
var scriptPromises = /* @__PURE__ */ new Map();
|
|
4274
|
+
var loadScriptOnce = (src) => {
|
|
4275
|
+
const existingPromise = scriptPromises.get(src);
|
|
4276
|
+
if (existingPromise) return existingPromise;
|
|
4277
|
+
const promise = new Promise((resolve, reject) => {
|
|
4278
|
+
if (!src || typeof document === "undefined") {
|
|
4279
|
+
reject(new Error("ONLYOFFICE \u811A\u672C\u5730\u5740\u4E0D\u53EF\u7528"));
|
|
4280
|
+
return;
|
|
4281
|
+
}
|
|
4282
|
+
const existed = document.querySelector(`script[src="${src}"]`);
|
|
4283
|
+
if (existed?.dataset.loaded === "true") {
|
|
4284
|
+
resolve();
|
|
4285
|
+
return;
|
|
4286
|
+
}
|
|
4287
|
+
const script = existed || document.createElement("script");
|
|
4288
|
+
script.src = src;
|
|
4289
|
+
script.async = true;
|
|
4290
|
+
script.onload = () => {
|
|
4291
|
+
script.dataset.loaded = "true";
|
|
4292
|
+
resolve();
|
|
4293
|
+
};
|
|
4294
|
+
script.onerror = () => reject(new Error("ONLYOFFICE \u811A\u672C\u52A0\u8F7D\u5931\u8D25"));
|
|
4295
|
+
if (!existed) document.body.appendChild(script);
|
|
4296
|
+
});
|
|
4297
|
+
scriptPromises.set(src, promise);
|
|
4298
|
+
promise.catch(() => scriptPromises.delete(src));
|
|
4299
|
+
return promise;
|
|
4300
|
+
};
|
|
4301
|
+
var OnlyOfficePreview = ({
|
|
4302
|
+
request,
|
|
4303
|
+
configUrl,
|
|
4304
|
+
ticket
|
|
4305
|
+
}) => {
|
|
4306
|
+
const editorId = useMemo4(
|
|
4307
|
+
() => `openxiangda-onlyoffice-${String(ticket || "editor").replace(/[^a-zA-Z0-9_-]/g, "")}`,
|
|
4308
|
+
[ticket]
|
|
4309
|
+
);
|
|
4310
|
+
const [loading, setLoading] = useState3(true);
|
|
4311
|
+
const [error, setError] = useState3("");
|
|
4312
|
+
useEffect3(() => {
|
|
4313
|
+
let disposed = false;
|
|
4314
|
+
let editor;
|
|
4315
|
+
setLoading(true);
|
|
4316
|
+
setError("");
|
|
4317
|
+
(async () => {
|
|
4318
|
+
try {
|
|
4319
|
+
const response = await request({ url: configUrl, method: "get" });
|
|
4320
|
+
const payload = unwrapFilePreviewPayload(response);
|
|
4321
|
+
const scriptUrl = `${String(payload?.documentServerUrl || "").replace(
|
|
4322
|
+
/\/+$/,
|
|
4323
|
+
""
|
|
4324
|
+
)}/web-apps/apps/api/documents/api.js`;
|
|
4325
|
+
await loadScriptOnce(scriptUrl);
|
|
4326
|
+
if (!disposed && window.DocsAPI?.DocEditor) {
|
|
4327
|
+
editor = new window.DocsAPI.DocEditor(editorId, payload.config);
|
|
4328
|
+
}
|
|
4329
|
+
} catch (currentError) {
|
|
4330
|
+
if (!disposed) setError(currentError?.message || "ONLYOFFICE \u9884\u89C8\u52A0\u8F7D\u5931\u8D25");
|
|
4331
|
+
} finally {
|
|
4332
|
+
if (!disposed) setLoading(false);
|
|
4333
|
+
}
|
|
4334
|
+
})();
|
|
4335
|
+
return () => {
|
|
4336
|
+
disposed = true;
|
|
4337
|
+
editor?.destroyEditor?.();
|
|
4338
|
+
};
|
|
4339
|
+
}, [configUrl, editorId, request]);
|
|
4340
|
+
return /* @__PURE__ */ jsxs("div", { style: { height: "100%", minHeight: 420, position: "relative", background: "#fff" }, children: [
|
|
4341
|
+
loading ? /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(Spin, { description: "\u6B63\u5728\u52A0\u8F7D ONLYOFFICE..." }) }) : null,
|
|
4342
|
+
error ? /* @__PURE__ */ jsx3("div", { style: { padding: 20 }, children: /* @__PURE__ */ jsx3(Alert, { type: "error", showIcon: true, title: error }) }) : null,
|
|
4343
|
+
/* @__PURE__ */ jsx3("div", { id: editorId, style: { height: "100%", minHeight: 420, display: error ? "none" : "block" } })
|
|
4344
|
+
] });
|
|
4345
|
+
};
|
|
4346
|
+
var FilePreviewContent = ({
|
|
4347
|
+
metadata,
|
|
4348
|
+
request,
|
|
4349
|
+
servicePrefix = "/service",
|
|
4350
|
+
onDownload
|
|
4351
|
+
}) => {
|
|
4352
|
+
const renderMode = metadata.renderMode || "download";
|
|
4353
|
+
const previewUrl = resolvePreviewServiceUrl(metadata.previewUrl, servicePrefix);
|
|
4354
|
+
const imageUrl = resolvePreviewServiceUrl(
|
|
4355
|
+
renderMode === "image-transcode" ? metadata.imagePreviewUrl : metadata.previewUrl,
|
|
4356
|
+
servicePrefix
|
|
4357
|
+
);
|
|
4358
|
+
if (renderMode === "inline" && metadata.previewType === "image") {
|
|
4359
|
+
return /* @__PURE__ */ jsx3(
|
|
4360
|
+
"div",
|
|
4361
|
+
{
|
|
4362
|
+
style: {
|
|
4363
|
+
height: "100%",
|
|
4364
|
+
minHeight: 320,
|
|
4365
|
+
display: "flex",
|
|
4366
|
+
alignItems: "center",
|
|
4367
|
+
justifyContent: "center",
|
|
4368
|
+
overflow: "auto",
|
|
4369
|
+
padding: 20,
|
|
4370
|
+
background: "#f3f5f7"
|
|
4371
|
+
},
|
|
4372
|
+
children: /* @__PURE__ */ jsx3(
|
|
4373
|
+
Image2,
|
|
4374
|
+
{
|
|
4375
|
+
src: imageUrl,
|
|
4376
|
+
alt: metadata.fileName || "\u56FE\u7247\u9884\u89C8",
|
|
4377
|
+
style: { maxWidth: "100%", maxHeight: "72vh", objectFit: "contain" }
|
|
4378
|
+
}
|
|
4379
|
+
)
|
|
4380
|
+
}
|
|
4381
|
+
);
|
|
4382
|
+
}
|
|
4383
|
+
if (renderMode === "image-transcode") {
|
|
4384
|
+
return /* @__PURE__ */ jsx3("div", { style: { minHeight: 320, textAlign: "center", padding: 20, background: "#f3f5f7" }, children: /* @__PURE__ */ jsx3(
|
|
4385
|
+
Image2,
|
|
4386
|
+
{
|
|
4387
|
+
src: imageUrl,
|
|
4388
|
+
alt: metadata.fileName || "\u56FE\u7247\u9884\u89C8",
|
|
4389
|
+
style: { maxWidth: "100%", maxHeight: "72vh", objectFit: "contain" }
|
|
4390
|
+
}
|
|
4391
|
+
) });
|
|
4392
|
+
}
|
|
4393
|
+
if (renderMode === "image-heic") {
|
|
4394
|
+
return /* @__PURE__ */ jsx3(
|
|
4395
|
+
HeicImagePreview,
|
|
4396
|
+
{
|
|
4397
|
+
request,
|
|
4398
|
+
url: previewUrl,
|
|
4399
|
+
fileName: metadata.fileName
|
|
4400
|
+
}
|
|
4401
|
+
);
|
|
4402
|
+
}
|
|
4403
|
+
if (renderMode === "inline" && metadata.previewType === "video") {
|
|
4404
|
+
return /* @__PURE__ */ jsx3(
|
|
4405
|
+
"div",
|
|
4406
|
+
{
|
|
4407
|
+
style: {
|
|
4408
|
+
height: "100%",
|
|
4409
|
+
minHeight: 320,
|
|
4410
|
+
display: "flex",
|
|
4411
|
+
alignItems: "center",
|
|
4412
|
+
background: "#080a0d"
|
|
4413
|
+
},
|
|
4414
|
+
children: /* @__PURE__ */ jsx3(
|
|
4415
|
+
"video",
|
|
4416
|
+
{
|
|
4417
|
+
controls: true,
|
|
4418
|
+
playsInline: true,
|
|
4419
|
+
preload: "metadata",
|
|
4420
|
+
src: previewUrl,
|
|
4421
|
+
style: { width: "100%", maxHeight: "76vh" },
|
|
4422
|
+
children: "\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u89C6\u9891\u64AD\u653E\u3002"
|
|
4423
|
+
}
|
|
4424
|
+
)
|
|
4425
|
+
}
|
|
4426
|
+
);
|
|
4427
|
+
}
|
|
4428
|
+
if (renderMode === "inline" && metadata.previewType === "audio") {
|
|
4429
|
+
return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3("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" }) });
|
|
4430
|
+
}
|
|
4431
|
+
if (renderMode === "pdfjs") {
|
|
4432
|
+
return /* @__PURE__ */ jsx3(
|
|
4433
|
+
"iframe",
|
|
4434
|
+
{
|
|
4435
|
+
title: metadata.fileName || "PDF \u9884\u89C8",
|
|
4436
|
+
src: previewUrl,
|
|
4437
|
+
style: { width: "100%", height: "100%", minHeight: 520, border: 0, background: "#fff" }
|
|
4438
|
+
}
|
|
4439
|
+
);
|
|
4440
|
+
}
|
|
4441
|
+
if (renderMode === "docx-html") {
|
|
4442
|
+
return /* @__PURE__ */ jsx3(DocxPreview, { request, url: previewUrl });
|
|
4443
|
+
}
|
|
4444
|
+
if (renderMode === "excel-client") {
|
|
4445
|
+
return /* @__PURE__ */ jsx3(ClientSpreadsheetPreview, { request, url: previewUrl });
|
|
4446
|
+
}
|
|
4447
|
+
if (renderMode === "excel-basic") {
|
|
4448
|
+
return /* @__PURE__ */ jsx3(
|
|
4449
|
+
PayloadPreview,
|
|
4450
|
+
{
|
|
4451
|
+
request,
|
|
4452
|
+
url: metadata.excelPreviewUrl || "",
|
|
4453
|
+
mode: "excel"
|
|
4454
|
+
}
|
|
4455
|
+
);
|
|
4456
|
+
}
|
|
4457
|
+
if (renderMode === "text-client") {
|
|
4458
|
+
return /* @__PURE__ */ jsx3(ClientTextPreview, { request, url: previewUrl });
|
|
4459
|
+
}
|
|
4460
|
+
if (renderMode === "text" || renderMode === "office-text") {
|
|
4461
|
+
return /* @__PURE__ */ jsx3(
|
|
4462
|
+
PayloadPreview,
|
|
4463
|
+
{
|
|
4464
|
+
request,
|
|
4465
|
+
url: renderMode === "office-text" ? metadata.officeTextPreviewUrl || "" : metadata.textPreviewUrl || "",
|
|
4466
|
+
mode: "text"
|
|
4467
|
+
}
|
|
4468
|
+
);
|
|
4469
|
+
}
|
|
4470
|
+
if (renderMode === "onlyoffice") {
|
|
4471
|
+
return /* @__PURE__ */ jsx3(
|
|
4472
|
+
OnlyOfficePreview,
|
|
4473
|
+
{
|
|
4474
|
+
request,
|
|
4475
|
+
configUrl: metadata.onlyofficeConfigUrl || `/file/onlyoffice/config/${encodeURIComponent(metadata.ticket || "")}`,
|
|
4476
|
+
ticket: metadata.ticket
|
|
4477
|
+
}
|
|
4478
|
+
);
|
|
4479
|
+
}
|
|
4480
|
+
return /* @__PURE__ */ jsx3(CenteredState, { children: /* @__PURE__ */ jsx3(
|
|
4481
|
+
Empty,
|
|
4482
|
+
{
|
|
4483
|
+
image: /* @__PURE__ */ jsx3(FileOutlined, { style: { fontSize: 52, color: "#8c8c8c" } }),
|
|
4484
|
+
description: /* @__PURE__ */ jsxs("div", { children: [
|
|
4485
|
+
/* @__PURE__ */ jsx3(Typography.Text, { strong: true, children: "\u5F53\u524D\u6587\u4EF6\u65E0\u6CD5\u5728\u7EBF\u9884\u89C8" }),
|
|
4486
|
+
/* @__PURE__ */ jsx3("br", {}),
|
|
4487
|
+
/* @__PURE__ */ jsx3(Typography.Text, { type: "secondary", children: metadata.unsupportedReason || "\u8BF7\u4E0B\u8F7D\u540E\u4F7F\u7528\u672C\u5730\u5E94\u7528\u6253\u5F00\u3002" })
|
|
4488
|
+
] }),
|
|
4489
|
+
children: onDownload ? /* @__PURE__ */ jsx3(Button, { type: "primary", icon: /* @__PURE__ */ jsx3(DownloadOutlined, {}), onClick: onDownload, children: "\u4E0B\u8F7D\u6587\u4EF6" }) : null
|
|
4490
|
+
}
|
|
4491
|
+
) });
|
|
4492
|
+
};
|
|
4493
|
+
|
|
4494
|
+
// packages/sdk/src/components/file-preview/FilePreviewPage.tsx
|
|
4495
|
+
import { useCallback as useCallback3, useEffect as useEffect4, useState as useState4 } from "react";
|
|
4496
|
+
import { Alert as Alert2, Button as Button2, Empty as Empty2, Spin as Spin2, Tag, Tooltip, Typography as Typography2 } from "antd";
|
|
4497
|
+
import {
|
|
4498
|
+
ArrowLeftOutlined,
|
|
4499
|
+
DownloadOutlined as DownloadOutlined2,
|
|
4500
|
+
FileOutlined as FileOutlined2,
|
|
4501
|
+
ReloadOutlined as ReloadOutlined2
|
|
4502
|
+
} from "@ant-design/icons";
|
|
4503
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
4504
|
+
|
|
4505
|
+
// packages/sdk/src/components/file-preview/useFilePreview.tsx
|
|
4506
|
+
import { useCallback as useCallback4, useEffect as useEffect5, useMemo as useMemo5, useState as useState5 } from "react";
|
|
4507
|
+
import { Alert as Alert3, Button as Button3, Image as Image3, Modal, Spin as Spin3, Typography as Typography3 } from "antd";
|
|
4508
|
+
import { CloseOutlined, DownloadOutlined as DownloadOutlined3 } from "@ant-design/icons";
|
|
4509
|
+
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
4510
|
+
var canActOnItem = (item) => item.status !== "uploading" && item.status !== "error";
|
|
4511
|
+
var revokeImageItems = (items) => {
|
|
4512
|
+
items.forEach((item) => {
|
|
4513
|
+
if (item.revokeOnClose && item.src.startsWith("blob:")) {
|
|
4514
|
+
URL.revokeObjectURL?.(item.src);
|
|
4515
|
+
}
|
|
4516
|
+
});
|
|
4517
|
+
};
|
|
4518
|
+
var buildCapabilityMap = (items, requireServerCapability) => {
|
|
4519
|
+
const result = {};
|
|
4520
|
+
items.forEach((item, index) => {
|
|
4521
|
+
const key = getPreviewItemKey(item, index);
|
|
4522
|
+
const local = resolveLocalPreviewCapability(item);
|
|
4523
|
+
result[key] = requireServerCapability && item.objectName && !isDirectStorageItem(item) ? { ...local, canPreview: false } : local;
|
|
4524
|
+
});
|
|
4525
|
+
return result;
|
|
4526
|
+
};
|
|
4527
|
+
var useFilePreviewController = ({
|
|
4528
|
+
items,
|
|
4529
|
+
api,
|
|
4530
|
+
appType,
|
|
4531
|
+
bucketName,
|
|
4532
|
+
enabled = true,
|
|
4533
|
+
requireServerCapability = true
|
|
4534
|
+
}) => {
|
|
4535
|
+
const itemSignature = useMemo5(
|
|
4536
|
+
() => items.map(
|
|
4537
|
+
(item, index) => [
|
|
4538
|
+
getPreviewItemKey(item, index),
|
|
4539
|
+
item.name,
|
|
4540
|
+
item.objectName,
|
|
4541
|
+
item.contentType,
|
|
4542
|
+
item.size,
|
|
4543
|
+
item.status
|
|
4544
|
+
].join(":")
|
|
4545
|
+
).join("|"),
|
|
4546
|
+
[items]
|
|
4547
|
+
);
|
|
4548
|
+
const [capabilities, setCapabilities] = useState5(
|
|
4549
|
+
() => buildCapabilityMap(items, requireServerCapability)
|
|
4550
|
+
);
|
|
4551
|
+
const [openingKey, setOpeningKey] = useState5("");
|
|
4552
|
+
const [dialogPreview, setDialogPreview] = useState5(null);
|
|
4553
|
+
const [imagePreview, setImagePreview] = useState5({
|
|
4554
|
+
open: false,
|
|
4555
|
+
current: 0,
|
|
4556
|
+
items: []
|
|
4557
|
+
});
|
|
4558
|
+
useEffect5(() => {
|
|
4559
|
+
let disposed = false;
|
|
4560
|
+
const initial = buildCapabilityMap(items, requireServerCapability);
|
|
4561
|
+
setCapabilities(initial);
|
|
4562
|
+
if (!enabled || !requireServerCapability) return () => {
|
|
4563
|
+
disposed = true;
|
|
4564
|
+
};
|
|
4565
|
+
const protectedItems = items.map((item, index) => ({ item, key: getPreviewItemKey(item, index) })).filter(
|
|
4566
|
+
({ item }) => canActOnItem(item) && Boolean(item.objectName) && !isDirectStorageItem(item)
|
|
4567
|
+
);
|
|
4568
|
+
if (!protectedItems.length) return () => {
|
|
4569
|
+
disposed = true;
|
|
4570
|
+
};
|
|
4571
|
+
api.request({
|
|
4572
|
+
url: "/file/preview-capabilities",
|
|
4573
|
+
method: "post",
|
|
4574
|
+
data: {
|
|
4575
|
+
files: protectedItems.map(({ item, key }) => ({
|
|
4576
|
+
key,
|
|
4577
|
+
fileName: item.name,
|
|
4578
|
+
objectName: item.objectName,
|
|
4579
|
+
contentType: item.contentType || item.mimeType,
|
|
4580
|
+
size: item.size
|
|
4581
|
+
}))
|
|
4582
|
+
}
|
|
4583
|
+
}).then((response) => {
|
|
4584
|
+
if (disposed) return;
|
|
4585
|
+
const payload = unwrapFilePreviewPayload(response);
|
|
4586
|
+
const next = { ...initial };
|
|
4587
|
+
(payload?.items || []).forEach((capability) => {
|
|
4588
|
+
if (capability.key) next[capability.key] = capability;
|
|
4589
|
+
});
|
|
4590
|
+
setCapabilities(next);
|
|
4591
|
+
}).catch(() => {
|
|
4592
|
+
if (disposed) return;
|
|
4593
|
+
const fallback = { ...initial };
|
|
4594
|
+
protectedItems.forEach(({ item, key }) => {
|
|
4595
|
+
fallback[key] = resolveLocalPreviewCapability(item);
|
|
4596
|
+
});
|
|
4597
|
+
setCapabilities(fallback);
|
|
4598
|
+
});
|
|
4599
|
+
return () => {
|
|
4600
|
+
disposed = true;
|
|
4601
|
+
};
|
|
4602
|
+
}, [api, enabled, itemSignature, requireServerCapability]);
|
|
4603
|
+
const getCapability = useCallback4(
|
|
4604
|
+
(item) => {
|
|
4605
|
+
const index = items.indexOf(item);
|
|
4606
|
+
return capabilities[getPreviewItemKey(item, Math.max(index, 0))];
|
|
4607
|
+
},
|
|
4608
|
+
[capabilities, items]
|
|
4609
|
+
);
|
|
4610
|
+
const canPreview = useCallback4(
|
|
4611
|
+
(item) => enabled && canActOnItem(item) && getCapability(item)?.canPreview === true,
|
|
4612
|
+
[enabled, getCapability]
|
|
4613
|
+
);
|
|
4614
|
+
const closeImagePreview = useCallback4(() => {
|
|
4615
|
+
setImagePreview((current) => {
|
|
4616
|
+
revokeImageItems(current.items);
|
|
4617
|
+
return { open: false, current: 0, items: [] };
|
|
4618
|
+
});
|
|
4619
|
+
}, []);
|
|
4620
|
+
useEffect5(
|
|
4621
|
+
() => () => revokeImageItems(imagePreview.items),
|
|
4622
|
+
[imagePreview.items]
|
|
4623
|
+
);
|
|
4624
|
+
const resolvePreparedImageItem = useCallback4(
|
|
4625
|
+
async (prepared, index) => {
|
|
4626
|
+
const item = prepared.item;
|
|
4627
|
+
const metadata = prepared.metadata;
|
|
4628
|
+
let src = resolvePreviewServiceUrl(
|
|
4629
|
+
metadata.renderMode === "image-transcode" ? metadata.imagePreviewUrl : metadata.previewUrl
|
|
4630
|
+
);
|
|
4631
|
+
let revokeOnClose = false;
|
|
4632
|
+
if (metadata.renderMode === "image-heic") {
|
|
4633
|
+
src = await convertHeicPreview(api.request, src);
|
|
4634
|
+
revokeOnClose = true;
|
|
4635
|
+
}
|
|
4636
|
+
if (!src) throw new Error(`${item.name || "\u56FE\u7247"}\u6CA1\u6709\u53EF\u7528\u7684\u9884\u89C8\u5730\u5740`);
|
|
4637
|
+
return {
|
|
4638
|
+
key: getPreviewItemKey(item, index),
|
|
4639
|
+
src,
|
|
4640
|
+
name: metadata.fileName || item.name,
|
|
4641
|
+
revokeOnClose
|
|
4642
|
+
};
|
|
4643
|
+
},
|
|
4644
|
+
[api]
|
|
4645
|
+
);
|
|
4646
|
+
const prepareImageItem = useCallback4(
|
|
4647
|
+
async (item, index) => {
|
|
4648
|
+
const prepared = await prepareFilePreview({ item, api, appType, bucketName });
|
|
4649
|
+
return resolvePreparedImageItem(prepared, index);
|
|
4650
|
+
},
|
|
4651
|
+
[api, appType, bucketName, resolvePreparedImageItem]
|
|
4652
|
+
);
|
|
4653
|
+
const openPreview = useCallback4(
|
|
4654
|
+
async (item) => {
|
|
4655
|
+
const itemIndex = Math.max(items.indexOf(item), 0);
|
|
4656
|
+
const key = getPreviewItemKey(item, itemIndex);
|
|
4657
|
+
setOpeningKey(key);
|
|
4658
|
+
try {
|
|
4659
|
+
const prepared = await prepareFilePreview({ item, api, appType, bucketName });
|
|
4660
|
+
if (prepared.metadata.canPreview === false || prepared.metadata.renderMode === "download") {
|
|
4661
|
+
setDialogPreview(prepared);
|
|
4662
|
+
return;
|
|
4663
|
+
}
|
|
4664
|
+
if (prepared.metadata.previewType === "image") {
|
|
4665
|
+
const galleryCandidates = items.map((candidate, index) => ({ candidate, index })).filter(({ candidate }) => {
|
|
4666
|
+
const capability = getCapability(candidate) || resolveLocalPreviewCapability(candidate);
|
|
4667
|
+
return canActOnItem(candidate) && capability.canPreview && capability.previewType === "image";
|
|
4668
|
+
});
|
|
4669
|
+
const results = await Promise.allSettled(
|
|
4670
|
+
galleryCandidates.map(
|
|
4671
|
+
({ candidate, index }) => candidate === item ? resolvePreparedImageItem(prepared, index) : prepareImageItem(candidate, index)
|
|
4672
|
+
)
|
|
4673
|
+
);
|
|
4674
|
+
const gallery = results.flatMap(
|
|
4675
|
+
(result) => result.status === "fulfilled" ? [result.value] : []
|
|
4676
|
+
);
|
|
4677
|
+
if (!gallery.length || !gallery.some((image) => image.key === key)) {
|
|
4678
|
+
const fallback = await resolvePreparedImageItem(prepared, itemIndex);
|
|
4679
|
+
gallery.push(fallback);
|
|
4680
|
+
}
|
|
4681
|
+
const current = Math.max(0, gallery.findIndex((image) => image.key === key));
|
|
4682
|
+
closeImagePreview();
|
|
4683
|
+
setImagePreview({ open: true, current, items: gallery });
|
|
4684
|
+
return;
|
|
4685
|
+
}
|
|
4686
|
+
setDialogPreview(prepared);
|
|
4687
|
+
} catch (error) {
|
|
4688
|
+
setDialogPreview({
|
|
4689
|
+
item,
|
|
4690
|
+
direct: isDirectStorageItem(item),
|
|
4691
|
+
metadata: {
|
|
4692
|
+
...resolveLocalPreviewCapability(item),
|
|
4693
|
+
fileName: item.name,
|
|
4694
|
+
size: item.size,
|
|
4695
|
+
renderMode: "download",
|
|
4696
|
+
canPreview: false,
|
|
4697
|
+
unsupportedReason: error?.message || "\u6587\u4EF6\u9884\u89C8\u52A0\u8F7D\u5931\u8D25",
|
|
4698
|
+
downloadUrl: item.downloadUrl || item.publicUrl || item.url
|
|
4699
|
+
}
|
|
4700
|
+
});
|
|
4701
|
+
} finally {
|
|
4702
|
+
setOpeningKey("");
|
|
4703
|
+
}
|
|
4704
|
+
},
|
|
4705
|
+
[
|
|
4706
|
+
api,
|
|
4707
|
+
appType,
|
|
4708
|
+
bucketName,
|
|
4709
|
+
closeImagePreview,
|
|
4710
|
+
getCapability,
|
|
4711
|
+
items,
|
|
4712
|
+
prepareImageItem,
|
|
4713
|
+
resolvePreparedImageItem
|
|
4714
|
+
]
|
|
4715
|
+
);
|
|
4716
|
+
const downloadItem = useCallback4(
|
|
4717
|
+
async (item, prepared) => {
|
|
4718
|
+
let url = prepared?.metadata.downloadUrl || item.downloadUrl || item.publicUrl || item.url;
|
|
4719
|
+
if (!isDirectStorageItem(item) && item.objectName && !prepared?.metadata.downloadUrl) {
|
|
4720
|
+
const ticket = await api.createDownloadTicket(
|
|
4721
|
+
item.bucketName || bucketName,
|
|
4722
|
+
item.objectName,
|
|
4723
|
+
item.name
|
|
4724
|
+
);
|
|
4725
|
+
url = typeof ticket === "string" ? ticket : ticket?.downloadUrl || ticket?.relayUrl || ticket?.url || url;
|
|
4726
|
+
}
|
|
4727
|
+
if (url && typeof window !== "undefined") window.location.assign(url);
|
|
4728
|
+
},
|
|
4729
|
+
[api, bucketName]
|
|
4730
|
+
);
|
|
4731
|
+
const previewHost = imagePreview.open || dialogPreview ? /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
4732
|
+
/* @__PURE__ */ jsx5(
|
|
4733
|
+
Image3.PreviewGroup,
|
|
4734
|
+
{
|
|
4735
|
+
items: imagePreview.items.map((item) => ({ src: item.src, alt: item.name })),
|
|
4736
|
+
preview: {
|
|
4737
|
+
open: imagePreview.open,
|
|
4738
|
+
current: imagePreview.current,
|
|
4739
|
+
onChange: (current) => setImagePreview((value) => ({ ...value, current })),
|
|
4740
|
+
onOpenChange: (open) => {
|
|
4741
|
+
if (!open) closeImagePreview();
|
|
4742
|
+
},
|
|
4743
|
+
countRender: (current, total) => `${current}/${total}`
|
|
4744
|
+
},
|
|
4745
|
+
children: /* @__PURE__ */ jsx5("span", { "aria-hidden": "true", style: { display: "none" } })
|
|
4746
|
+
}
|
|
4747
|
+
),
|
|
4748
|
+
/* @__PURE__ */ jsx5(
|
|
4749
|
+
FilePreviewDialog,
|
|
4750
|
+
{
|
|
4751
|
+
preview: dialogPreview,
|
|
4752
|
+
request: api.request,
|
|
4753
|
+
onClose: () => setDialogPreview(null),
|
|
4754
|
+
onDownload: () => {
|
|
4755
|
+
if (dialogPreview) void downloadItem(dialogPreview.item, dialogPreview);
|
|
4756
|
+
}
|
|
4757
|
+
}
|
|
4758
|
+
)
|
|
4759
|
+
] }) : null;
|
|
4760
|
+
return {
|
|
4761
|
+
canPreview,
|
|
4762
|
+
getCapability,
|
|
4763
|
+
openPreview,
|
|
4764
|
+
openingKey,
|
|
4765
|
+
isOpening: (item) => {
|
|
4766
|
+
const index = Math.max(items.indexOf(item), 0);
|
|
4767
|
+
return openingKey === getPreviewItemKey(item, index);
|
|
4768
|
+
},
|
|
4769
|
+
downloadItem,
|
|
4770
|
+
previewHost
|
|
4771
|
+
};
|
|
4772
|
+
};
|
|
4773
|
+
var FilePreviewDialog = ({
|
|
4774
|
+
preview,
|
|
4775
|
+
request,
|
|
4776
|
+
onClose,
|
|
4777
|
+
onDownload
|
|
4778
|
+
}) => {
|
|
4779
|
+
const metadata = preview?.metadata;
|
|
4780
|
+
const title = metadata?.fileName || preview?.item.name || "\u9644\u4EF6\u9884\u89C8";
|
|
4781
|
+
return /* @__PURE__ */ jsx5(
|
|
4782
|
+
Modal,
|
|
4783
|
+
{
|
|
4784
|
+
open: Boolean(preview),
|
|
4785
|
+
title: /* @__PURE__ */ jsxs3("div", { style: { minWidth: 0, paddingRight: 16 }, children: [
|
|
4786
|
+
/* @__PURE__ */ jsx5(Typography3.Text, { strong: true, ellipsis: true, style: { display: "block" }, children: title }),
|
|
4787
|
+
metadata ? /* @__PURE__ */ jsxs3(Typography3.Text, { type: "secondary", style: { fontSize: 12 }, children: [
|
|
4788
|
+
(metadata.extension || "FILE").toUpperCase(),
|
|
4789
|
+
" \xB7 ",
|
|
4790
|
+
formatPreviewFileSize(metadata.size)
|
|
4791
|
+
] }) : null
|
|
4792
|
+
] }),
|
|
4793
|
+
width: "min(96vw, 1440px)",
|
|
4794
|
+
centered: true,
|
|
4795
|
+
destroyOnHidden: true,
|
|
4796
|
+
mask: { closable: false },
|
|
4797
|
+
closeIcon: /* @__PURE__ */ jsx5(CloseOutlined, {}),
|
|
4798
|
+
onCancel: onClose,
|
|
4799
|
+
styles: {
|
|
4800
|
+
body: {
|
|
4801
|
+
height: "min(78vh, 900px)",
|
|
4802
|
+
minHeight: 360,
|
|
4803
|
+
padding: 0,
|
|
4804
|
+
overflow: "hidden",
|
|
4805
|
+
border: "1px solid #e5e7eb"
|
|
4806
|
+
}
|
|
4807
|
+
},
|
|
4808
|
+
footer: /* @__PURE__ */ jsxs3("div", { style: { display: "flex", justifyContent: "flex-end", gap: 8 }, children: [
|
|
4809
|
+
/* @__PURE__ */ jsx5(Button3, { onClick: onClose, children: "\u5173\u95ED" }),
|
|
4810
|
+
metadata?.canDownload !== false ? /* @__PURE__ */ jsx5(Button3, { type: "primary", icon: /* @__PURE__ */ jsx5(DownloadOutlined3, {}), onClick: onDownload, children: "\u4E0B\u8F7D" }) : null
|
|
4811
|
+
] }),
|
|
4812
|
+
children: preview && metadata ? /* @__PURE__ */ jsx5(
|
|
4813
|
+
FilePreviewContent,
|
|
4814
|
+
{
|
|
4815
|
+
metadata,
|
|
4816
|
+
request,
|
|
4817
|
+
onDownload
|
|
4818
|
+
}
|
|
4819
|
+
) : /* @__PURE__ */ jsx5("div", { style: { height: "100%", display: "grid", placeItems: "center" }, children: /* @__PURE__ */ jsx5(Spin3, { description: "\u6B63\u5728\u51C6\u5907\u9884\u89C8..." }) })
|
|
4820
|
+
}
|
|
4821
|
+
);
|
|
4822
|
+
};
|
|
4823
|
+
|
|
4824
|
+
// packages/sdk/src/components/fields/shared/FileDisplay.tsx
|
|
4825
|
+
import {
|
|
4826
|
+
AudioOutlined,
|
|
4827
|
+
CloseOutlined as CloseOutlined2,
|
|
4828
|
+
DownloadOutlined as DownloadOutlined4,
|
|
4829
|
+
EyeOutlined,
|
|
4830
|
+
FileExcelOutlined,
|
|
4831
|
+
FileImageOutlined,
|
|
4832
|
+
FileOutlined as FileOutlined3,
|
|
4833
|
+
FilePdfOutlined,
|
|
4834
|
+
FilePptOutlined,
|
|
4835
|
+
FileTextOutlined,
|
|
4836
|
+
FileUnknownOutlined,
|
|
4837
|
+
FileWordOutlined,
|
|
4838
|
+
FileZipOutlined,
|
|
4839
|
+
PaperClipOutlined,
|
|
4840
|
+
PlusOutlined,
|
|
4841
|
+
UploadOutlined,
|
|
4842
|
+
VideoCameraOutlined
|
|
4843
|
+
} from "@ant-design/icons";
|
|
4844
|
+
import { jsx as jsx6, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
4845
|
+
function FileTypeIcon({
|
|
4846
|
+
item,
|
|
4847
|
+
className
|
|
4848
|
+
}) {
|
|
4849
|
+
const category = getFileCategory(item.name, item.contentType);
|
|
4850
|
+
const extension = getFileExtension(item.name);
|
|
4851
|
+
const icon = category === "image" ? /* @__PURE__ */ jsx6(FileImageOutlined, {}) : category === "video" ? /* @__PURE__ */ jsx6(VideoCameraOutlined, {}) : category === "audio" ? /* @__PURE__ */ jsx6(AudioOutlined, {}) : category === "pdf" ? /* @__PURE__ */ jsx6(FilePdfOutlined, {}) : category === "excel" ? /* @__PURE__ */ jsx6(FileExcelOutlined, {}) : category === "word" ? /* @__PURE__ */ jsx6(FileWordOutlined, {}) : category === "ppt" ? /* @__PURE__ */ jsx6(FilePptOutlined, {}) : category === "archive" ? /* @__PURE__ */ jsx6(FileZipOutlined, {}) : category === "text" || category === "code" ? /* @__PURE__ */ jsx6(FileTextOutlined, {}) : extension ? /* @__PURE__ */ jsx6(FileOutlined3, {}) : /* @__PURE__ */ jsx6(FileUnknownOutlined, {});
|
|
4852
|
+
return /* @__PURE__ */ jsxs4("span", { className: `sy-file-icon sy-file-icon-${category} ${className || ""}`, "aria-hidden": "true", children: [
|
|
4853
|
+
icon,
|
|
4854
|
+
category !== "image" && extension ? /* @__PURE__ */ jsx6("span", { children: extension.toUpperCase() }) : null
|
|
4855
|
+
] });
|
|
4856
|
+
}
|
|
4857
|
+
function FileActionButton({
|
|
4858
|
+
type,
|
|
4859
|
+
disabled,
|
|
4860
|
+
onClick,
|
|
4861
|
+
testId
|
|
4862
|
+
}) {
|
|
4863
|
+
const label = type === "preview" ? "\u9884\u89C8" : type === "download" ? "\u4E0B\u8F7D" : "\u5220\u9664";
|
|
4864
|
+
const icon = type === "preview" ? /* @__PURE__ */ jsx6(EyeOutlined, {}) : type === "download" ? /* @__PURE__ */ jsx6(DownloadOutlined4, {}) : /* @__PURE__ */ jsx6(CloseOutlined2, {});
|
|
4865
|
+
return /* @__PURE__ */ jsxs4(
|
|
4866
|
+
"button",
|
|
4867
|
+
{
|
|
4868
|
+
type: "button",
|
|
4869
|
+
className: `sy-file-action sy-file-action-${type}`,
|
|
4870
|
+
disabled,
|
|
4871
|
+
onClick,
|
|
4872
|
+
"data-testid": testId,
|
|
4873
|
+
"aria-label": label,
|
|
4874
|
+
title: label,
|
|
4875
|
+
children: [
|
|
4876
|
+
icon,
|
|
4877
|
+
/* @__PURE__ */ jsx6("span", { className: "sy-sr-only", children: label })
|
|
4878
|
+
]
|
|
4879
|
+
}
|
|
4880
|
+
);
|
|
4881
|
+
}
|
|
4882
|
+
function FileStatusText({
|
|
4883
|
+
item,
|
|
4884
|
+
showFileSize = true,
|
|
4885
|
+
showFileTypeBadge = true
|
|
4886
|
+
}) {
|
|
4887
|
+
const extension = getFileExtension(item.name);
|
|
4888
|
+
const text = item.status === "uploading" ? `\u4E0A\u4F20\u4E2D ${Math.round(item.percent ?? 0)}%` : item.status === "error" ? item.error || "\u4E0A\u4F20\u5931\u8D25" : [
|
|
4889
|
+
showFileTypeBadge && extension ? extension.toUpperCase() : "",
|
|
4890
|
+
showFileSize ? formatFileSize(item.size) : ""
|
|
4891
|
+
].filter(Boolean).join(" \xB7 ") || "\u5DF2\u4E0A\u4F20";
|
|
4892
|
+
return /* @__PURE__ */ jsx6("span", { className: "sy-file-sub", children: text });
|
|
4893
|
+
}
|
|
4894
|
+
|
|
4895
|
+
// packages/sdk/src/runtime/react/filePreview.tsx
|
|
4896
|
+
import { jsx as jsx7, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
4897
|
+
var EMPTY_ITEMS = [];
|
|
4898
|
+
var normalizeMethod2 = (method) => {
|
|
4899
|
+
const value = String(method || "get").toLowerCase();
|
|
4900
|
+
return ["get", "post", "put", "delete", "patch"].includes(value) ? value : "get";
|
|
4901
|
+
};
|
|
4902
|
+
var normalizeHeaders = (headers) => {
|
|
4903
|
+
if (!headers) return void 0;
|
|
4904
|
+
return Object.fromEntries(new Headers(headers).entries());
|
|
4905
|
+
};
|
|
4906
|
+
var toPageRequest = (config) => ({
|
|
4907
|
+
path: config.url,
|
|
4908
|
+
method: normalizeMethod2(config.method),
|
|
4909
|
+
query: config.params,
|
|
4910
|
+
body: config.data,
|
|
4911
|
+
headers: normalizeHeaders(config.headers)
|
|
4912
|
+
});
|
|
4913
|
+
var toRuntimeResponse = (response) => {
|
|
4914
|
+
if (response.raw && typeof response.raw === "object") {
|
|
4915
|
+
return response.raw;
|
|
4916
|
+
}
|
|
4917
|
+
return {
|
|
4918
|
+
code: Number(response.code) || 200,
|
|
4919
|
+
success: response.success,
|
|
4920
|
+
message: response.message,
|
|
4921
|
+
data: response.result,
|
|
4922
|
+
result: response.result
|
|
4923
|
+
};
|
|
4924
|
+
};
|
|
4925
|
+
var unwrapPageResult = (response) => response.result ?? response.data ?? null;
|
|
4926
|
+
var createPageFileRuntimeApi = (sdk) => {
|
|
4927
|
+
const request = async (config) => {
|
|
4928
|
+
const options = toPageRequest(config);
|
|
4929
|
+
if (config.responseType === "blob") {
|
|
4930
|
+
const response = await sdk.transport.download(options);
|
|
4931
|
+
return response.blob;
|
|
4932
|
+
}
|
|
4933
|
+
return toRuntimeResponse(await sdk.transport.request(options));
|
|
4934
|
+
};
|
|
4935
|
+
return createFormRuntimeApi({
|
|
4936
|
+
request,
|
|
4937
|
+
createFileAccessTicket: async (bucketName, objectName, fileName, purpose = "preview", options = {}) => unwrapPageResult(
|
|
4938
|
+
await sdk.createFileAccessTicket(
|
|
4939
|
+
bucketName,
|
|
4940
|
+
objectName,
|
|
4941
|
+
fileName,
|
|
4942
|
+
purpose,
|
|
4943
|
+
options
|
|
4944
|
+
)
|
|
4945
|
+
),
|
|
4946
|
+
createDownloadTicket: async (bucketName, objectName, fileName) => unwrapPageResult(
|
|
4947
|
+
await sdk.request({
|
|
4948
|
+
path: "/file/download-ticket",
|
|
4949
|
+
method: "post",
|
|
4950
|
+
body: { bucketName, objectName, fileName }
|
|
4951
|
+
})
|
|
4952
|
+
)
|
|
4953
|
+
});
|
|
4954
|
+
};
|
|
4955
|
+
var useFilePreview = ({
|
|
4956
|
+
items = EMPTY_ITEMS,
|
|
4957
|
+
appType,
|
|
4958
|
+
bucketName = "attachments",
|
|
4959
|
+
enabled = true,
|
|
4960
|
+
requireServerCapability = true
|
|
4961
|
+
}) => {
|
|
4962
|
+
const sdk = usePageSdk();
|
|
4963
|
+
const api = useMemo6(() => createPageFileRuntimeApi(sdk), [sdk]);
|
|
4964
|
+
const preview = useFilePreviewController({
|
|
4965
|
+
items,
|
|
4966
|
+
api,
|
|
4967
|
+
appType: appType || sdk.context.app.appType,
|
|
4968
|
+
bucketName,
|
|
4969
|
+
enabled,
|
|
4970
|
+
requireServerCapability
|
|
4971
|
+
});
|
|
4972
|
+
return {
|
|
4973
|
+
canPreview: preview.canPreview,
|
|
4974
|
+
getCapability: preview.getCapability,
|
|
4975
|
+
open: preview.openPreview,
|
|
4976
|
+
download: preview.downloadItem,
|
|
4977
|
+
isOpening: preview.isOpening,
|
|
4978
|
+
openingKey: preview.openingKey,
|
|
4979
|
+
host: preview.previewHost
|
|
4980
|
+
};
|
|
4981
|
+
};
|
|
4982
|
+
var AttachmentPreviewList = ({
|
|
4983
|
+
items = EMPTY_ITEMS,
|
|
4984
|
+
appType,
|
|
4985
|
+
bucketName = "attachments",
|
|
4986
|
+
showPreview = true,
|
|
4987
|
+
showDownload = true,
|
|
4988
|
+
showFileSize = true,
|
|
4989
|
+
showFileTypeBadge = false,
|
|
4990
|
+
emptyText = "\u6682\u65E0\u9644\u4EF6",
|
|
4991
|
+
className
|
|
4992
|
+
}) => {
|
|
4993
|
+
const preview = useFilePreview({
|
|
4994
|
+
items,
|
|
4995
|
+
appType,
|
|
4996
|
+
bucketName,
|
|
4997
|
+
enabled: showPreview,
|
|
4998
|
+
requireServerCapability: true
|
|
4999
|
+
});
|
|
5000
|
+
if (!items.length) {
|
|
5001
|
+
return /* @__PURE__ */ jsx7(Empty3, { description: emptyText, className });
|
|
5002
|
+
}
|
|
5003
|
+
return /* @__PURE__ */ jsxs5(
|
|
5004
|
+
"div",
|
|
5005
|
+
{
|
|
5006
|
+
className: ["sy-readonly-files", "sy-readonly-attachments", className].filter(Boolean).join(" "),
|
|
5007
|
+
"data-testid": "openxiangda-attachment-preview-list",
|
|
5008
|
+
children: [
|
|
5009
|
+
/* @__PURE__ */ jsx7("div", { className: "sy-file-list", children: items.map((item, index) => {
|
|
5010
|
+
const key = getPreviewItemKey(item, index);
|
|
5011
|
+
const canAct = item.status !== "uploading" && item.status !== "error";
|
|
5012
|
+
const canDownload = preview.getCapability(item)?.canDownload !== false;
|
|
5013
|
+
return /* @__PURE__ */ jsxs5("div", { className: "sy-file-item", children: [
|
|
5014
|
+
/* @__PURE__ */ jsx7(FileTypeIcon, { item }),
|
|
5015
|
+
/* @__PURE__ */ jsxs5("div", { className: "sy-file-meta", children: [
|
|
5016
|
+
/* @__PURE__ */ jsx7("span", { className: "sy-file-name", title: item.name, children: item.name || "\u672A\u547D\u540D\u9644\u4EF6" }),
|
|
5017
|
+
/* @__PURE__ */ jsx7(
|
|
5018
|
+
FileStatusText,
|
|
5019
|
+
{
|
|
5020
|
+
item,
|
|
5021
|
+
showFileSize,
|
|
5022
|
+
showFileTypeBadge
|
|
5023
|
+
}
|
|
5024
|
+
)
|
|
5025
|
+
] }),
|
|
5026
|
+
/* @__PURE__ */ jsxs5("div", { className: "sy-file-actions", children: [
|
|
5027
|
+
showPreview && preview.canPreview(item) ? /* @__PURE__ */ jsx7(
|
|
5028
|
+
FileActionButton,
|
|
5029
|
+
{
|
|
5030
|
+
type: "preview",
|
|
5031
|
+
disabled: !canAct || preview.isOpening(item),
|
|
5032
|
+
onClick: () => void preview.open(item),
|
|
5033
|
+
testId: `attachment-preview-${key}`
|
|
5034
|
+
}
|
|
5035
|
+
) : null,
|
|
5036
|
+
showDownload && canDownload ? /* @__PURE__ */ jsx7(
|
|
5037
|
+
FileActionButton,
|
|
5038
|
+
{
|
|
5039
|
+
type: "download",
|
|
5040
|
+
disabled: !canAct,
|
|
5041
|
+
onClick: () => void preview.download(item),
|
|
5042
|
+
testId: `attachment-download-${key}`
|
|
5043
|
+
}
|
|
5044
|
+
) : null
|
|
5045
|
+
] })
|
|
5046
|
+
] }, `${key}-${index}`);
|
|
5047
|
+
}) }),
|
|
5048
|
+
preview.host
|
|
5049
|
+
]
|
|
5050
|
+
}
|
|
5051
|
+
);
|
|
5052
|
+
};
|
|
5053
|
+
var PreviewImageThumb = ({ item }) => {
|
|
5054
|
+
const src = item.thumbUrl || item.previewUrl || item.url;
|
|
5055
|
+
const [failed, setFailed] = useState6(false);
|
|
5056
|
+
React6.useEffect(() => setFailed(false), [src]);
|
|
5057
|
+
return src && !failed ? /* @__PURE__ */ jsx7("img", { src, alt: item.name || "\u56FE\u7247", onError: () => setFailed(true) }) : /* @__PURE__ */ jsx7("span", { className: "sy-image-state", children: item.name || "\u56FE\u7247" });
|
|
5058
|
+
};
|
|
5059
|
+
var ImagePreviewGrid = ({
|
|
5060
|
+
items = EMPTY_ITEMS,
|
|
5061
|
+
appType,
|
|
5062
|
+
bucketName = "images",
|
|
5063
|
+
showPreview = true,
|
|
5064
|
+
showDownload = true,
|
|
5065
|
+
showFileName = true,
|
|
5066
|
+
emptyText = "\u6682\u65E0\u56FE\u7247",
|
|
5067
|
+
className
|
|
5068
|
+
}) => {
|
|
5069
|
+
const preview = useFilePreview({
|
|
5070
|
+
items,
|
|
5071
|
+
appType,
|
|
5072
|
+
bucketName,
|
|
5073
|
+
enabled: showPreview,
|
|
5074
|
+
requireServerCapability: true
|
|
5075
|
+
});
|
|
5076
|
+
if (!items.length) {
|
|
5077
|
+
return /* @__PURE__ */ jsx7(Empty3, { description: emptyText, className });
|
|
5078
|
+
}
|
|
5079
|
+
return /* @__PURE__ */ jsxs5(
|
|
5080
|
+
"div",
|
|
5081
|
+
{
|
|
5082
|
+
className: ["sy-readonly-files", "sy-readonly-images", className].filter(Boolean).join(" "),
|
|
5083
|
+
"data-testid": "openxiangda-image-preview-grid",
|
|
5084
|
+
children: [
|
|
5085
|
+
/* @__PURE__ */ jsx7(
|
|
5086
|
+
"div",
|
|
5087
|
+
{
|
|
5088
|
+
className: "sy-mobile-image-grid",
|
|
5089
|
+
style: { gridTemplateColumns: "repeat(auto-fill, minmax(112px, 160px))" },
|
|
5090
|
+
children: items.map((item, index) => {
|
|
5091
|
+
const key = getPreviewItemKey(item, index);
|
|
5092
|
+
const canAct = item.status !== "uploading" && item.status !== "error";
|
|
5093
|
+
const canOpen = showPreview && preview.canPreview(item);
|
|
5094
|
+
const canDownload = preview.getCapability(item)?.canDownload !== false;
|
|
5095
|
+
return /* @__PURE__ */ jsxs5("div", { className: "sy-mobile-image-card", children: [
|
|
5096
|
+
/* @__PURE__ */ jsx7("div", { className: "sy-mobile-image-thumb", children: /* @__PURE__ */ jsx7(
|
|
5097
|
+
"button",
|
|
5098
|
+
{
|
|
5099
|
+
type: "button",
|
|
5100
|
+
className: "sy-image-preview",
|
|
5101
|
+
disabled: !canAct || !canOpen || preview.isOpening(item),
|
|
5102
|
+
onClick: () => void preview.open(item),
|
|
5103
|
+
"aria-label": `\u9884\u89C8 ${item.name || "\u56FE\u7247"}`,
|
|
5104
|
+
"data-testid": `image-preview-${key}`,
|
|
5105
|
+
children: /* @__PURE__ */ jsx7(PreviewImageThumb, { item })
|
|
5106
|
+
}
|
|
5107
|
+
) }),
|
|
5108
|
+
/* @__PURE__ */ jsxs5(
|
|
5109
|
+
"div",
|
|
5110
|
+
{
|
|
5111
|
+
style: {
|
|
5112
|
+
display: "flex",
|
|
5113
|
+
alignItems: "center",
|
|
5114
|
+
gap: 6,
|
|
5115
|
+
minWidth: 0
|
|
5116
|
+
},
|
|
5117
|
+
children: [
|
|
5118
|
+
showFileName ? /* @__PURE__ */ jsx7("div", { className: "sy-mobile-image-name", title: item.name, style: { flex: 1 }, children: item.name || "\u56FE\u7247" }) : /* @__PURE__ */ jsx7("span", { style: { flex: 1 } }),
|
|
5119
|
+
/* @__PURE__ */ jsxs5("div", { className: "sy-file-actions", children: [
|
|
5120
|
+
canOpen ? /* @__PURE__ */ jsx7(
|
|
5121
|
+
FileActionButton,
|
|
5122
|
+
{
|
|
5123
|
+
type: "preview",
|
|
5124
|
+
disabled: !canAct || preview.isOpening(item),
|
|
5125
|
+
onClick: () => void preview.open(item)
|
|
5126
|
+
}
|
|
5127
|
+
) : null,
|
|
5128
|
+
showDownload && canDownload ? /* @__PURE__ */ jsx7(
|
|
5129
|
+
FileActionButton,
|
|
5130
|
+
{
|
|
5131
|
+
type: "download",
|
|
5132
|
+
disabled: !canAct,
|
|
5133
|
+
onClick: () => void preview.download(item)
|
|
5134
|
+
}
|
|
5135
|
+
) : null
|
|
5136
|
+
] })
|
|
5137
|
+
]
|
|
5138
|
+
}
|
|
5139
|
+
)
|
|
5140
|
+
] }, `${key}-${index}`);
|
|
5141
|
+
})
|
|
5142
|
+
}
|
|
5143
|
+
),
|
|
5144
|
+
preview.host
|
|
5145
|
+
]
|
|
5146
|
+
}
|
|
5147
|
+
);
|
|
5148
|
+
};
|
|
5149
|
+
|
|
2622
5150
|
// packages/sdk/src/runtime/react/workflow.tsx
|
|
2623
|
-
import { useCallback as
|
|
2624
|
-
import { Form, Input as Input2, Modal as
|
|
5151
|
+
import { useCallback as useCallback8, useEffect as useEffect10, useMemo as useMemo12, useRef as useRef5, useState as useState11 } from "react";
|
|
5152
|
+
import { Form, Input as Input2, Modal as Modal5, Select as Select2 } from "antd";
|
|
2625
5153
|
import {
|
|
2626
5154
|
CheckOutlined,
|
|
2627
|
-
CloseOutlined,
|
|
2628
|
-
ReloadOutlined as
|
|
5155
|
+
CloseOutlined as CloseOutlined3,
|
|
5156
|
+
ReloadOutlined as ReloadOutlined4,
|
|
2629
5157
|
RollbackOutlined as RollbackOutlined2,
|
|
2630
5158
|
SaveOutlined,
|
|
2631
5159
|
SwapOutlined
|
|
2632
5160
|
} from "@ant-design/icons";
|
|
2633
5161
|
|
|
2634
5162
|
// packages/sdk/src/components/modules/StickyActionBar.tsx
|
|
2635
|
-
import { useEffect as
|
|
2636
|
-
import { Button, Dropdown, Tooltip } from "antd";
|
|
5163
|
+
import { useEffect as useEffect6, useMemo as useMemo7, useState as useState7 } from "react";
|
|
5164
|
+
import { Button as Button4, Dropdown, Tooltip as Tooltip2 } from "antd";
|
|
2637
5165
|
import { MoreOutlined } from "@ant-design/icons";
|
|
2638
5166
|
|
|
2639
5167
|
// packages/sdk/src/components/utils/confirmAction.ts
|
|
@@ -2650,7 +5178,7 @@ var confirmAction = (title, content) => {
|
|
|
2650
5178
|
};
|
|
2651
5179
|
|
|
2652
5180
|
// packages/sdk/src/components/modules/StickyActionBar.tsx
|
|
2653
|
-
import { Fragment as
|
|
5181
|
+
import { Fragment as Fragment3, jsx as jsx8, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2654
5182
|
var getActionPriority = (action) => {
|
|
2655
5183
|
const maybePriority = action.priority;
|
|
2656
5184
|
if (typeof maybePriority === "number") return maybePriority;
|
|
@@ -2668,14 +5196,14 @@ var StickyActionBar = ({
|
|
|
2668
5196
|
position = "sticky",
|
|
2669
5197
|
surface = "default"
|
|
2670
5198
|
}) => {
|
|
2671
|
-
const [isMobile, setIsMobile] =
|
|
2672
|
-
|
|
5199
|
+
const [isMobile, setIsMobile] = useState7(false);
|
|
5200
|
+
useEffect6(() => {
|
|
2673
5201
|
const update = () => setIsMobile(typeof window !== "undefined" && window.innerWidth <= 768);
|
|
2674
5202
|
update();
|
|
2675
5203
|
window.addEventListener("resize", update);
|
|
2676
5204
|
return () => window.removeEventListener("resize", update);
|
|
2677
5205
|
}, []);
|
|
2678
|
-
const visibleActions =
|
|
5206
|
+
const visibleActions = useMemo7(
|
|
2679
5207
|
() => actions.filter((action) => action.visible !== false).sort((left, right) => getActionPriority(left) - getActionPriority(right)),
|
|
2680
5208
|
[actions]
|
|
2681
5209
|
);
|
|
@@ -2696,8 +5224,8 @@ var StickyActionBar = ({
|
|
|
2696
5224
|
action.onClick();
|
|
2697
5225
|
};
|
|
2698
5226
|
const renderButton = (action, mobile = false) => {
|
|
2699
|
-
const button = /* @__PURE__ */
|
|
2700
|
-
|
|
5227
|
+
const button = /* @__PURE__ */ jsx8(
|
|
5228
|
+
Button4,
|
|
2701
5229
|
{
|
|
2702
5230
|
type: action.type === "danger" ? "primary" : action.type === "text" ? "text" : action.type || "default",
|
|
2703
5231
|
danger: action.type === "danger",
|
|
@@ -2711,16 +5239,16 @@ var StickyActionBar = ({
|
|
|
2711
5239
|
action.key
|
|
2712
5240
|
);
|
|
2713
5241
|
if (!action.disabled || !action.disabledReason) return button;
|
|
2714
|
-
return /* @__PURE__ */
|
|
5242
|
+
return /* @__PURE__ */ jsx8(Tooltip2, { title: action.disabledReason, children: /* @__PURE__ */ jsx8("span", { className: mobile ? "flex min-w-0 flex-1" : "inline-flex", children: button }) }, action.key);
|
|
2715
5243
|
};
|
|
2716
|
-
return /* @__PURE__ */
|
|
5244
|
+
return /* @__PURE__ */ jsx8("div", { className: `${positionClass} z-20 ${spacingClass} ${surfaceClass} ${className}`, children: /* @__PURE__ */ jsx8(
|
|
2717
5245
|
"div",
|
|
2718
5246
|
{
|
|
2719
5247
|
className: `mx-auto flex w-full items-center gap-3 ${!isMobile ? desktopJustifyClass : "justify-end"}`,
|
|
2720
5248
|
style: { maxWidth: maxWidthStyle },
|
|
2721
|
-
children: isMobile ? /* @__PURE__ */
|
|
2722
|
-
/* @__PURE__ */
|
|
2723
|
-
moreMobile.length > 0 && /* @__PURE__ */
|
|
5249
|
+
children: isMobile ? /* @__PURE__ */ jsxs6(Fragment3, { children: [
|
|
5250
|
+
/* @__PURE__ */ jsx8("div", { className: "flex flex-1 gap-2", children: primaryMobile.map((action) => renderButton(action, true)) }),
|
|
5251
|
+
moreMobile.length > 0 && /* @__PURE__ */ jsx8(
|
|
2724
5252
|
Dropdown,
|
|
2725
5253
|
{
|
|
2726
5254
|
trigger: ["click"],
|
|
@@ -2735,16 +5263,16 @@ var StickyActionBar = ({
|
|
|
2735
5263
|
onClick: () => runAction(action)
|
|
2736
5264
|
}))
|
|
2737
5265
|
},
|
|
2738
|
-
children: /* @__PURE__ */
|
|
5266
|
+
children: /* @__PURE__ */ jsx8(Button4, { icon: /* @__PURE__ */ jsx8(MoreOutlined, {}), className: "rounded-md", children: "\u66F4\u591A" })
|
|
2739
5267
|
}
|
|
2740
5268
|
)
|
|
2741
|
-
] }) : layoutMode === "approval" ? /* @__PURE__ */
|
|
5269
|
+
] }) : layoutMode === "approval" ? /* @__PURE__ */ jsx8("div", { className: "flex flex-wrap items-center justify-center gap-3", children: visibleActions.map((action) => renderButton(action)) }) : /* @__PURE__ */ jsx8("div", { className: `flex flex-wrap items-center ${desktopJustifyClass} gap-3`, children: visibleActions.map((action) => renderButton(action)) })
|
|
2742
5270
|
}
|
|
2743
5271
|
) });
|
|
2744
5272
|
};
|
|
2745
5273
|
|
|
2746
5274
|
// packages/sdk/src/components/modules/ApprovalTimeline.tsx
|
|
2747
|
-
import { useMemo as
|
|
5275
|
+
import { useMemo as useMemo8 } from "react";
|
|
2748
5276
|
import {
|
|
2749
5277
|
ApiOutlined,
|
|
2750
5278
|
CheckCircleFilled,
|
|
@@ -2753,10 +5281,10 @@ import {
|
|
|
2753
5281
|
CodeOutlined,
|
|
2754
5282
|
CopyOutlined,
|
|
2755
5283
|
EditOutlined,
|
|
2756
|
-
FileTextOutlined,
|
|
5284
|
+
FileTextOutlined as FileTextOutlined2,
|
|
2757
5285
|
LoadingOutlined,
|
|
2758
5286
|
NotificationOutlined,
|
|
2759
|
-
ReloadOutlined,
|
|
5287
|
+
ReloadOutlined as ReloadOutlined3,
|
|
2760
5288
|
RollbackOutlined,
|
|
2761
5289
|
UserOutlined
|
|
2762
5290
|
} from "@ant-design/icons";
|
|
@@ -2775,7 +5303,7 @@ var TASK_STATUS_META = {
|
|
|
2775
5303
|
};
|
|
2776
5304
|
|
|
2777
5305
|
// packages/sdk/src/components/modules/ApprovalTimeline.tsx
|
|
2778
|
-
import { jsx as
|
|
5306
|
+
import { jsx as jsx9, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2779
5307
|
var systemNodeTypes = /* @__PURE__ */ new Set([
|
|
2780
5308
|
"condition",
|
|
2781
5309
|
"condition_branch",
|
|
@@ -2869,37 +5397,37 @@ function getStatusMeta(task, state, compact) {
|
|
|
2869
5397
|
}
|
|
2870
5398
|
function getIcon(task, state) {
|
|
2871
5399
|
if (state === "current")
|
|
2872
|
-
return task.nodeType === "callback_wait" ? /* @__PURE__ */
|
|
5400
|
+
return task.nodeType === "callback_wait" ? /* @__PURE__ */ jsx9(ClockCircleOutlined, {}) : /* @__PURE__ */ jsx9(LoadingOutlined, {});
|
|
2873
5401
|
if (state === "future" || state === "waiting")
|
|
2874
|
-
return task.nodeType === "approval" ? /* @__PURE__ */
|
|
2875
|
-
if (state === "rejected") return /* @__PURE__ */
|
|
2876
|
-
if (state === "returned") return /* @__PURE__ */
|
|
5402
|
+
return task.nodeType === "approval" ? /* @__PURE__ */ jsx9(UserOutlined, {}) : /* @__PURE__ */ jsx9(ClockCircleOutlined, {});
|
|
5403
|
+
if (state === "rejected") return /* @__PURE__ */ jsx9(CloseCircleFilled, {});
|
|
5404
|
+
if (state === "returned") return /* @__PURE__ */ jsx9(RollbackOutlined, {});
|
|
2877
5405
|
switch (task.nodeType) {
|
|
2878
5406
|
case "start":
|
|
2879
|
-
return /* @__PURE__ */
|
|
5407
|
+
return /* @__PURE__ */ jsx9(FileTextOutlined2, {});
|
|
2880
5408
|
case "approval":
|
|
2881
|
-
return /* @__PURE__ */
|
|
5409
|
+
return /* @__PURE__ */ jsx9(CheckCircleFilled, {});
|
|
2882
5410
|
case "originator_return":
|
|
2883
|
-
return /* @__PURE__ */
|
|
5411
|
+
return /* @__PURE__ */ jsx9(EditOutlined, {});
|
|
2884
5412
|
case "copy":
|
|
2885
|
-
return /* @__PURE__ */
|
|
5413
|
+
return /* @__PURE__ */ jsx9(CopyOutlined, {});
|
|
2886
5414
|
case "callback_wait":
|
|
2887
|
-
return /* @__PURE__ */
|
|
5415
|
+
return /* @__PURE__ */ jsx9(ClockCircleOutlined, {});
|
|
2888
5416
|
case "js_code":
|
|
2889
|
-
return /* @__PURE__ */
|
|
5417
|
+
return /* @__PURE__ */ jsx9(CodeOutlined, {});
|
|
2890
5418
|
case "connector_call":
|
|
2891
|
-
return /* @__PURE__ */
|
|
5419
|
+
return /* @__PURE__ */ jsx9(ApiOutlined, {});
|
|
2892
5420
|
case "work_notification":
|
|
2893
5421
|
case "dingtalk_card":
|
|
2894
|
-
return /* @__PURE__ */
|
|
5422
|
+
return /* @__PURE__ */ jsx9(NotificationOutlined, {});
|
|
2895
5423
|
case "data_retrieve_single":
|
|
2896
5424
|
case "data_retrieve_batch":
|
|
2897
5425
|
case "data_create":
|
|
2898
5426
|
case "data_update":
|
|
2899
5427
|
case "loop_container":
|
|
2900
|
-
return /* @__PURE__ */
|
|
5428
|
+
return /* @__PURE__ */ jsx9(ReloadOutlined3, {});
|
|
2901
5429
|
default:
|
|
2902
|
-
return /* @__PURE__ */
|
|
5430
|
+
return /* @__PURE__ */ jsx9(CheckCircleFilled, {});
|
|
2903
5431
|
}
|
|
2904
5432
|
}
|
|
2905
5433
|
function getDotClass(state) {
|
|
@@ -2922,21 +5450,21 @@ var ApprovalTimeline = ({
|
|
|
2922
5450
|
compactMode = false,
|
|
2923
5451
|
showApproverInfo = true
|
|
2924
5452
|
}) => {
|
|
2925
|
-
const taskList =
|
|
2926
|
-
const groups =
|
|
5453
|
+
const taskList = useMemo8(() => Array.isArray(tasks) ? tasks : [], [tasks]);
|
|
5454
|
+
const groups = useMemo8(() => groupTasks(taskList), [taskList]);
|
|
2927
5455
|
if (taskList.length === 0) {
|
|
2928
|
-
return /* @__PURE__ */
|
|
5456
|
+
return /* @__PURE__ */ jsx9(
|
|
2929
5457
|
"div",
|
|
2930
5458
|
{
|
|
2931
5459
|
className: `rounded-lg border border-ant-border-secondary bg-ant-bg-container p-6 ${className}`,
|
|
2932
|
-
children: /* @__PURE__ */
|
|
5460
|
+
children: /* @__PURE__ */ jsx9("p", { className: "m-0 text-center text-sm text-ant-text-tertiary", children: "\u6682\u65E0\u5BA1\u6279\u8BB0\u5F55" })
|
|
2933
5461
|
}
|
|
2934
5462
|
);
|
|
2935
5463
|
}
|
|
2936
5464
|
if (renderNode) {
|
|
2937
|
-
return /* @__PURE__ */
|
|
5465
|
+
return /* @__PURE__ */ jsx9("div", { className, children: taskList.map((task, index) => /* @__PURE__ */ jsx9("div", { children: renderNode(task, index) }, task.taskId || task.id || index)) });
|
|
2938
5466
|
}
|
|
2939
|
-
return /* @__PURE__ */
|
|
5467
|
+
return /* @__PURE__ */ jsx9("div", { className: `approval-timeline ${className}`, children: groups.map((group, index) => {
|
|
2940
5468
|
const node = group[0];
|
|
2941
5469
|
const isLast = index === groups.length - 1;
|
|
2942
5470
|
const isFutureGroup = group.some((task) => task.isSimulated || task.status === "simulated");
|
|
@@ -2945,62 +5473,62 @@ var ApprovalTimeline = ({
|
|
|
2945
5473
|
const statusMeta = getStatusMeta(node, state, compact);
|
|
2946
5474
|
const title = getNodeTitle(node);
|
|
2947
5475
|
const time = node.actionAt || node.createdAt;
|
|
2948
|
-
return /* @__PURE__ */
|
|
5476
|
+
return /* @__PURE__ */ jsxs7(
|
|
2949
5477
|
"div",
|
|
2950
5478
|
{
|
|
2951
5479
|
className: `relative flex gap-4 pb-5 ${isLast ? "pb-0" : ""}`,
|
|
2952
5480
|
children: [
|
|
2953
|
-
!isLast && /* @__PURE__ */
|
|
5481
|
+
!isLast && /* @__PURE__ */ jsx9(
|
|
2954
5482
|
"div",
|
|
2955
5483
|
{
|
|
2956
5484
|
className: `absolute bottom-0 left-[21px] top-11 w-px ${state === "future" ? "border-l border-dashed border-gray-300" : "bg-ant-border-secondary"}`
|
|
2957
5485
|
}
|
|
2958
5486
|
),
|
|
2959
|
-
/* @__PURE__ */
|
|
5487
|
+
/* @__PURE__ */ jsx9(
|
|
2960
5488
|
"div",
|
|
2961
5489
|
{
|
|
2962
5490
|
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)}`,
|
|
2963
5491
|
children: getIcon(node, state)
|
|
2964
5492
|
}
|
|
2965
5493
|
),
|
|
2966
|
-
/* @__PURE__ */
|
|
5494
|
+
/* @__PURE__ */ jsx9("div", { className: "min-w-0 flex-1", children: /* @__PURE__ */ jsxs7(
|
|
2967
5495
|
"div",
|
|
2968
5496
|
{
|
|
2969
5497
|
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"}`,
|
|
2970
5498
|
children: [
|
|
2971
|
-
/* @__PURE__ */
|
|
2972
|
-
/* @__PURE__ */
|
|
2973
|
-
/* @__PURE__ */
|
|
2974
|
-
/* @__PURE__ */
|
|
5499
|
+
/* @__PURE__ */ jsxs7("div", { className: "flex flex-wrap items-start justify-between gap-2", children: [
|
|
5500
|
+
/* @__PURE__ */ jsxs7("div", { className: "flex min-w-0 flex-wrap items-center gap-2", children: [
|
|
5501
|
+
/* @__PURE__ */ jsx9("span", { className: "font-medium text-ant-text", children: title }),
|
|
5502
|
+
/* @__PURE__ */ jsx9(
|
|
2975
5503
|
"span",
|
|
2976
5504
|
{
|
|
2977
5505
|
className: `inline-flex min-h-6 items-center rounded-md border px-2 text-xs font-medium ${state === "future" ? toneClasses.future : toneClasses[statusMeta.tone]}`,
|
|
2978
5506
|
children: statusMeta.label
|
|
2979
5507
|
}
|
|
2980
5508
|
),
|
|
2981
|
-
node.nodeType === "originator_return" && /* @__PURE__ */
|
|
5509
|
+
node.nodeType === "originator_return" && /* @__PURE__ */ jsx9("span", { className: "rounded-md bg-amber-50 px-2 py-1 text-xs text-amber-700", children: "\u53D1\u8D77\u4EBA\u64CD\u4F5C" })
|
|
2982
5510
|
] }),
|
|
2983
|
-
!isFutureGroup && time && /* @__PURE__ */
|
|
5511
|
+
!isFutureGroup && time && /* @__PURE__ */ jsx9("span", { className: "text-xs text-ant-text-tertiary", children: time })
|
|
2984
5512
|
] }),
|
|
2985
|
-
showApproverInfo && !compact && group.length > 0 && /* @__PURE__ */
|
|
2986
|
-
/* @__PURE__ */
|
|
2987
|
-
group.map((assignee) => /* @__PURE__ */
|
|
5513
|
+
showApproverInfo && !compact && group.length > 0 && /* @__PURE__ */ jsxs7("div", { className: "mt-3 flex flex-wrap gap-3", children: [
|
|
5514
|
+
/* @__PURE__ */ jsx9("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" }),
|
|
5515
|
+
group.map((assignee) => /* @__PURE__ */ jsxs7(
|
|
2988
5516
|
"span",
|
|
2989
5517
|
{
|
|
2990
5518
|
className: "inline-flex min-w-0 items-center gap-2",
|
|
2991
5519
|
children: [
|
|
2992
|
-
/* @__PURE__ */
|
|
2993
|
-
/* @__PURE__ */
|
|
2994
|
-
/* @__PURE__ */
|
|
2995
|
-
/* @__PURE__ */
|
|
5520
|
+
/* @__PURE__ */ jsx9("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) || "?" }),
|
|
5521
|
+
/* @__PURE__ */ jsxs7("span", { className: "min-w-0", children: [
|
|
5522
|
+
/* @__PURE__ */ jsx9("span", { className: "block text-sm font-medium text-ant-text", children: assignee.assigneeName || "\u7CFB\u7EDF" }),
|
|
5523
|
+
/* @__PURE__ */ jsx9("span", { className: "block text-xs text-ant-text-tertiary", children: assignee.departmentName || assignee.actionAt || assignee.createdAt || "" })
|
|
2996
5524
|
] })
|
|
2997
5525
|
]
|
|
2998
5526
|
},
|
|
2999
5527
|
assignee.taskId || assignee.id
|
|
3000
5528
|
))
|
|
3001
5529
|
] }),
|
|
3002
|
-
showApproverInfo && compact && /* @__PURE__ */
|
|
3003
|
-
showRemarks && node.comments && /* @__PURE__ */
|
|
5530
|
+
showApproverInfo && compact && /* @__PURE__ */ jsx9("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" : "") }),
|
|
5531
|
+
showRemarks && node.comments && /* @__PURE__ */ jsx9(
|
|
3004
5532
|
"div",
|
|
3005
5533
|
{
|
|
3006
5534
|
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"}`,
|
|
@@ -3018,9 +5546,9 @@ var ApprovalTimeline = ({
|
|
|
3018
5546
|
};
|
|
3019
5547
|
|
|
3020
5548
|
// packages/sdk/src/components/modules/ProcessPreview.tsx
|
|
3021
|
-
import { Modal, Skeleton, Button as
|
|
5549
|
+
import { Modal as Modal2, Skeleton, Button as Button5 } from "antd";
|
|
3022
5550
|
import { CheckCircleOutlined, UserOutlined as UserOutlined2 } from "@ant-design/icons";
|
|
3023
|
-
import { jsx as
|
|
5551
|
+
import { jsx as jsx10, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
3024
5552
|
var ProcessPreview = ({
|
|
3025
5553
|
open,
|
|
3026
5554
|
onClose,
|
|
@@ -3029,30 +5557,30 @@ var ProcessPreview = ({
|
|
|
3029
5557
|
loading = false
|
|
3030
5558
|
}) => {
|
|
3031
5559
|
const routeList = Array.isArray(routes) ? routes : [];
|
|
3032
|
-
return /* @__PURE__ */
|
|
3033
|
-
|
|
5560
|
+
return /* @__PURE__ */ jsx10(
|
|
5561
|
+
Modal2,
|
|
3034
5562
|
{
|
|
3035
5563
|
getContainer: false,
|
|
3036
5564
|
title: "\u6D41\u7A0B\u9884\u89C8",
|
|
3037
5565
|
open,
|
|
3038
5566
|
onCancel: onClose,
|
|
3039
5567
|
width: 520,
|
|
3040
|
-
footer: /* @__PURE__ */
|
|
3041
|
-
/* @__PURE__ */
|
|
3042
|
-
/* @__PURE__ */
|
|
5568
|
+
footer: /* @__PURE__ */ jsxs8("div", { className: "flex justify-end gap-3", children: [
|
|
5569
|
+
/* @__PURE__ */ jsx10(Button5, { onClick: onClose, children: "\u53D6\u6D88" }),
|
|
5570
|
+
/* @__PURE__ */ jsx10(Button5, { type: "primary", onClick: onConfirm, loading, children: "\u786E\u8BA4\u63D0\u4EA4" })
|
|
3043
5571
|
] }),
|
|
3044
|
-
children: loading && routeList.length === 0 ? /* @__PURE__ */
|
|
5572
|
+
children: loading && routeList.length === 0 ? /* @__PURE__ */ jsx10(Skeleton, { active: true, paragraph: { rows: 4 } }) : routeList.length === 0 ? /* @__PURE__ */ jsx10("p", { className: "text-sm text-gray-400 text-center py-8", children: "\u6682\u65E0\u6D41\u7A0B\u8282\u70B9" }) : /* @__PURE__ */ jsx10("div", { className: "py-2", children: routeList.map((route, index) => {
|
|
3045
5573
|
const isLast = index === routeList.length - 1;
|
|
3046
|
-
return /* @__PURE__ */
|
|
3047
|
-
/* @__PURE__ */
|
|
3048
|
-
/* @__PURE__ */
|
|
3049
|
-
!isLast && /* @__PURE__ */
|
|
5574
|
+
return /* @__PURE__ */ jsxs8("div", { className: "flex gap-3", children: [
|
|
5575
|
+
/* @__PURE__ */ jsxs8("div", { className: "flex flex-col items-center", children: [
|
|
5576
|
+
/* @__PURE__ */ jsx10("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__ */ jsx10(CheckCircleOutlined, { className: "text-blue-500 text-xs" }) }),
|
|
5577
|
+
!isLast && /* @__PURE__ */ jsx10("div", { className: "w-0.5 flex-1 bg-blue-200 mt-1" })
|
|
3050
5578
|
] }),
|
|
3051
|
-
/* @__PURE__ */
|
|
3052
|
-
/* @__PURE__ */
|
|
3053
|
-
route.assignees && route.assignees.length > 0 && /* @__PURE__ */
|
|
3054
|
-
/* @__PURE__ */
|
|
3055
|
-
route.assignees.map((assignee) => /* @__PURE__ */
|
|
5579
|
+
/* @__PURE__ */ jsxs8("div", { className: `flex-1 ${isLast ? "pb-0" : "pb-5"}`, children: [
|
|
5580
|
+
/* @__PURE__ */ jsx10("div", { className: "text-sm font-medium text-gray-900", children: route.nodeName }),
|
|
5581
|
+
route.assignees && route.assignees.length > 0 && /* @__PURE__ */ jsxs8("div", { className: "mt-1 flex items-center gap-1.5 flex-wrap", children: [
|
|
5582
|
+
/* @__PURE__ */ jsx10(UserOutlined2, { className: "text-gray-400 text-xs" }),
|
|
5583
|
+
route.assignees.map((assignee) => /* @__PURE__ */ jsx10(
|
|
3056
5584
|
"span",
|
|
3057
5585
|
{
|
|
3058
5586
|
className: "text-xs text-gray-500 bg-gray-100 px-1.5 py-0.5 rounded",
|
|
@@ -3069,20 +5597,20 @@ var ProcessPreview = ({
|
|
|
3069
5597
|
};
|
|
3070
5598
|
|
|
3071
5599
|
// packages/sdk/src/components/modules/InitiatorApproverSelector.tsx
|
|
3072
|
-
import { useCallback as
|
|
3073
|
-
import { Button as
|
|
5600
|
+
import { useCallback as useCallback7, useEffect as useEffect9, useMemo as useMemo11, useRef as useRef4, useState as useState10 } from "react";
|
|
5601
|
+
import { Button as Button7, Empty as Empty5, Modal as Modal4, Select, Space as Space2, Tag as Tag3, Typography as Typography4, message as message2 } from "antd";
|
|
3074
5602
|
|
|
3075
5603
|
// packages/sdk/src/components/core/processApi.ts
|
|
3076
5604
|
var hasOwn2 = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
|
|
3077
5605
|
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"));
|
|
3078
|
-
var
|
|
5606
|
+
var isSuccessCode3 = (code) => {
|
|
3079
5607
|
if (code === void 0 || code === null || code === "") return true;
|
|
3080
5608
|
const normalized = Number(code);
|
|
3081
5609
|
return Number.isFinite(normalized) ? normalized === 0 || normalized === 200 : false;
|
|
3082
5610
|
};
|
|
3083
5611
|
var unwrapRuntimeResponse = (response) => {
|
|
3084
5612
|
if (!isRuntimeEnvelope(response)) return response;
|
|
3085
|
-
if (response.success === false || !
|
|
5613
|
+
if (response.success === false || !isSuccessCode3(response.code)) {
|
|
3086
5614
|
throw new Error(response.message || response.error || "\u8BF7\u6C42\u5931\u8D25");
|
|
3087
5615
|
}
|
|
3088
5616
|
if (hasOwn2(response, "data")) return response.data;
|
|
@@ -3114,88 +5642,26 @@ async function getInitiatorSelectCandidates(request, params) {
|
|
|
3114
5642
|
}
|
|
3115
5643
|
|
|
3116
5644
|
// packages/sdk/src/components/fields/shared/UserPicker.tsx
|
|
3117
|
-
import { useCallback as
|
|
5645
|
+
import { useCallback as useCallback6, useEffect as useEffect8, useMemo as useMemo10, useState as useState9 } from "react";
|
|
3118
5646
|
import {
|
|
3119
5647
|
Avatar,
|
|
3120
|
-
Button as
|
|
5648
|
+
Button as Button6,
|
|
3121
5649
|
Checkbox,
|
|
3122
|
-
Empty,
|
|
5650
|
+
Empty as Empty4,
|
|
3123
5651
|
Input,
|
|
3124
5652
|
List,
|
|
3125
|
-
Modal as
|
|
5653
|
+
Modal as Modal3,
|
|
3126
5654
|
Pagination,
|
|
3127
5655
|
Space,
|
|
3128
|
-
Spin,
|
|
3129
|
-
Tag,
|
|
5656
|
+
Spin as Spin4,
|
|
5657
|
+
Tag as Tag2,
|
|
3130
5658
|
Tree
|
|
3131
5659
|
} from "antd";
|
|
3132
5660
|
import { SearchOutlined, TeamOutlined, UserOutlined as UserOutlined3 } from "@ant-design/icons";
|
|
3133
5661
|
import * as MobileAntd from "antd-mobile";
|
|
3134
5662
|
|
|
3135
|
-
// packages/sdk/src/components/fields/shared/fieldFormat.ts
|
|
3136
|
-
function getUserId(user) {
|
|
3137
|
-
if (typeof user === "string" || typeof user === "number") return String(user).trim();
|
|
3138
|
-
return String(user?.id || user?.userId || user?.userid || user?.value || user?.key || "").trim();
|
|
3139
|
-
}
|
|
3140
|
-
function getUserName(user) {
|
|
3141
|
-
if (typeof user === "string" || typeof user === "number") return String(user).trim();
|
|
3142
|
-
return String(
|
|
3143
|
-
user?.name || user?.label || user?.title || user?.username || user?.nickname || getUserId(user)
|
|
3144
|
-
);
|
|
3145
|
-
}
|
|
3146
|
-
function normalizeUser(user) {
|
|
3147
|
-
const id = getUserId(user);
|
|
3148
|
-
const source = typeof user === "object" && user !== null ? user : {};
|
|
3149
|
-
return {
|
|
3150
|
-
...source,
|
|
3151
|
-
id,
|
|
3152
|
-
name: getUserName({ ...source, id })
|
|
3153
|
-
};
|
|
3154
|
-
}
|
|
3155
|
-
function getDepartmentId(node) {
|
|
3156
|
-
if (typeof node === "string" || typeof node === "number") return String(node).trim();
|
|
3157
|
-
return String(
|
|
3158
|
-
node?.id || node?.departmentId || node?.deptId || node?.value || node?.key || ""
|
|
3159
|
-
).trim();
|
|
3160
|
-
}
|
|
3161
|
-
function getDepartmentName(node) {
|
|
3162
|
-
if (typeof node === "string" || typeof node === "number") return String(node).trim();
|
|
3163
|
-
return String(
|
|
3164
|
-
node?.name || node?.label || node?.title || node?.deptName || node?.departmentName || getDepartmentId(node)
|
|
3165
|
-
);
|
|
3166
|
-
}
|
|
3167
|
-
function normalizeDepartmentNode(node) {
|
|
3168
|
-
const id = getDepartmentId(node);
|
|
3169
|
-
const source = typeof node === "object" && node !== null ? node : {};
|
|
3170
|
-
const name = getDepartmentName({ ...source, id });
|
|
3171
|
-
const hasChildren = typeof node?.hasChildren === "boolean" ? node.hasChildren : Array.isArray(node?.children) && node.children.length > 0;
|
|
3172
|
-
const children = Array.isArray(node?.children) ? node.children.map((child) => normalizeDepartmentNode(child)) : void 0;
|
|
3173
|
-
return {
|
|
3174
|
-
...source,
|
|
3175
|
-
id,
|
|
3176
|
-
name,
|
|
3177
|
-
key: String(node?.key || id),
|
|
3178
|
-
title: String(node?.title || name),
|
|
3179
|
-
hasChildren,
|
|
3180
|
-
isLeaf: typeof node?.isLeaf === "boolean" ? node.isLeaf : !hasChildren,
|
|
3181
|
-
children
|
|
3182
|
-
};
|
|
3183
|
-
}
|
|
3184
|
-
function flattenDepartments(nodes) {
|
|
3185
|
-
const result = [];
|
|
3186
|
-
const walk = (items) => {
|
|
3187
|
-
for (const node of items) {
|
|
3188
|
-
const id = getDepartmentId(node);
|
|
3189
|
-
if (id) result.push({ id, name: getDepartmentName(node), node });
|
|
3190
|
-
if (node.children?.length) walk(node.children);
|
|
3191
|
-
}
|
|
3192
|
-
};
|
|
3193
|
-
walk(nodes);
|
|
3194
|
-
return result;
|
|
3195
|
-
}
|
|
3196
|
-
|
|
3197
5663
|
// packages/sdk/src/components/fields/shared/useLazyDepartmentTree.ts
|
|
3198
|
-
import { useCallback as
|
|
5664
|
+
import { useCallback as useCallback5, useEffect as useEffect7, useMemo as useMemo9, useRef as useRef3, useState as useState8 } from "react";
|
|
3199
5665
|
var toLazyNode = (node) => {
|
|
3200
5666
|
const normalized = normalizeDepartmentNode(node);
|
|
3201
5667
|
const id = getDepartmentId(normalized);
|
|
@@ -3245,15 +5711,15 @@ function buildIndexes(nodes) {
|
|
|
3245
5711
|
return { nodeMap, parentMap, flatNodes };
|
|
3246
5712
|
}
|
|
3247
5713
|
function useLazyDepartmentTree(api, configuredTreeData) {
|
|
3248
|
-
const [treeData, setTreeDataState] =
|
|
5714
|
+
const [treeData, setTreeDataState] = useState8(
|
|
3249
5715
|
() => (configuredTreeData || []).map(toLazyNode)
|
|
3250
5716
|
);
|
|
3251
|
-
const [treeLoading, setTreeLoading] =
|
|
3252
|
-
const treeDataRef =
|
|
3253
|
-
const rootsLoadedRef =
|
|
3254
|
-
const rootPromiseRef =
|
|
3255
|
-
const childPromiseRef =
|
|
3256
|
-
const setTreeData =
|
|
5717
|
+
const [treeLoading, setTreeLoading] = useState8(false);
|
|
5718
|
+
const treeDataRef = useRef3(treeData);
|
|
5719
|
+
const rootsLoadedRef = useRef3(Boolean(configuredTreeData?.length));
|
|
5720
|
+
const rootPromiseRef = useRef3(null);
|
|
5721
|
+
const childPromiseRef = useRef3({});
|
|
5722
|
+
const setTreeData = useCallback5(
|
|
3257
5723
|
(next) => {
|
|
3258
5724
|
const resolved = typeof next === "function" ? next(treeDataRef.current) : next;
|
|
3259
5725
|
treeDataRef.current = resolved;
|
|
@@ -3262,13 +5728,13 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3262
5728
|
},
|
|
3263
5729
|
[]
|
|
3264
5730
|
);
|
|
3265
|
-
|
|
5731
|
+
useEffect7(() => {
|
|
3266
5732
|
if (!configuredTreeData) return;
|
|
3267
5733
|
const next = configuredTreeData.map(toLazyNode);
|
|
3268
5734
|
rootsLoadedRef.current = next.length > 0;
|
|
3269
5735
|
setTreeData(next);
|
|
3270
5736
|
}, [configuredTreeData, setTreeData]);
|
|
3271
|
-
const loadRootDepartments =
|
|
5737
|
+
const loadRootDepartments = useCallback5(async () => {
|
|
3272
5738
|
if (rootsLoadedRef.current) return treeDataRef.current;
|
|
3273
5739
|
if (rootPromiseRef.current) return rootPromiseRef.current;
|
|
3274
5740
|
setTreeLoading(true);
|
|
@@ -3284,7 +5750,7 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3284
5750
|
rootPromiseRef.current = promise;
|
|
3285
5751
|
return promise;
|
|
3286
5752
|
}, [api, setTreeData]);
|
|
3287
|
-
const loadChildren =
|
|
5753
|
+
const loadChildren = useCallback5(
|
|
3288
5754
|
async (parentId) => {
|
|
3289
5755
|
const id = String(parentId || "");
|
|
3290
5756
|
if (!id) return [];
|
|
@@ -3305,8 +5771,8 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3305
5771
|
},
|
|
3306
5772
|
[api, setTreeData]
|
|
3307
5773
|
);
|
|
3308
|
-
const indexes =
|
|
3309
|
-
|
|
5774
|
+
const indexes = useMemo9(() => buildIndexes(treeData), [treeData]);
|
|
5775
|
+
useEffect7(() => {
|
|
3310
5776
|
void loadRootDepartments();
|
|
3311
5777
|
}, [loadRootDepartments]);
|
|
3312
5778
|
return {
|
|
@@ -3319,7 +5785,7 @@ function useLazyDepartmentTree(api, configuredTreeData) {
|
|
|
3319
5785
|
}
|
|
3320
5786
|
|
|
3321
5787
|
// packages/sdk/src/components/fields/shared/UserPicker.tsx
|
|
3322
|
-
import { jsx as
|
|
5788
|
+
import { jsx as jsx11, jsxs as jsxs9 } from "react/jsx-runtime";
|
|
3323
5789
|
var DEFAULT_MEMBER_PAGE_SIZE = 10;
|
|
3324
5790
|
var getMobileComponent = (name) => {
|
|
3325
5791
|
try {
|
|
@@ -3351,24 +5817,24 @@ function UserPickerPanel({
|
|
|
3351
5817
|
flatNodes,
|
|
3352
5818
|
loadChildren
|
|
3353
5819
|
} = useLazyDepartmentTree(api, treeData);
|
|
3354
|
-
const [departmentKeyword, setDepartmentKeyword] =
|
|
3355
|
-
const [memberKeyword, setMemberKeyword] =
|
|
3356
|
-
const [mobileKeyword, setMobileKeyword] =
|
|
3357
|
-
const [currentDeptId, setCurrentDeptId] =
|
|
3358
|
-
const [expandedKeys, setExpandedKeys] =
|
|
3359
|
-
const [members, setMembers] =
|
|
3360
|
-
const [memberPage, setMemberPage] =
|
|
3361
|
-
const [memberPageSize, setMemberPageSize] =
|
|
3362
|
-
const [memberTotal, setMemberTotal] =
|
|
3363
|
-
const [memberReloadKey, setMemberReloadKey] =
|
|
3364
|
-
const [loading, setLoading] =
|
|
3365
|
-
const [selected, setSelected] =
|
|
5820
|
+
const [departmentKeyword, setDepartmentKeyword] = useState9("");
|
|
5821
|
+
const [memberKeyword, setMemberKeyword] = useState9("");
|
|
5822
|
+
const [mobileKeyword, setMobileKeyword] = useState9("");
|
|
5823
|
+
const [currentDeptId, setCurrentDeptId] = useState9("");
|
|
5824
|
+
const [expandedKeys, setExpandedKeys] = useState9([]);
|
|
5825
|
+
const [members, setMembers] = useState9(() => normalizeUsers(dataSource));
|
|
5826
|
+
const [memberPage, setMemberPage] = useState9(1);
|
|
5827
|
+
const [memberPageSize, setMemberPageSize] = useState9(DEFAULT_MEMBER_PAGE_SIZE);
|
|
5828
|
+
const [memberTotal, setMemberTotal] = useState9(() => normalizeUsers(dataSource).length);
|
|
5829
|
+
const [memberReloadKey, setMemberReloadKey] = useState9(0);
|
|
5830
|
+
const [loading, setLoading] = useState9(false);
|
|
5831
|
+
const [selected, setSelected] = useState9(() => normalizeUsers(value));
|
|
3366
5832
|
const selectedIds = selected.map(getUserId);
|
|
3367
5833
|
const MobileSearchBar = getMobileComponent("SearchBar");
|
|
3368
5834
|
const activeMemberKeyword = (mobile ? mobileKeyword : memberKeyword).trim();
|
|
3369
|
-
const staticUsers =
|
|
5835
|
+
const staticUsers = useMemo10(() => normalizeUsers(dataSource), [dataSource]);
|
|
3370
5836
|
const hasStaticUserSource = staticUsers.length > 0;
|
|
3371
|
-
|
|
5837
|
+
useEffect8(() => {
|
|
3372
5838
|
if (mobile) return;
|
|
3373
5839
|
if (currentDeptId || deptTreeData.length === 0) return;
|
|
3374
5840
|
setExpandedKeys(deptTreeData.map((node) => getDepartmentId(node)));
|
|
@@ -3376,17 +5842,17 @@ function UserPickerPanel({
|
|
|
3376
5842
|
setCurrentDeptId(getDepartmentId(deptTreeData[0]));
|
|
3377
5843
|
}
|
|
3378
5844
|
}, [currentDeptId, deptTreeData, loadAllWhenNoDepartment, mobile]);
|
|
3379
|
-
|
|
5845
|
+
useEffect8(() => {
|
|
3380
5846
|
setMemberPage(1);
|
|
3381
5847
|
}, [activeMemberKeyword, currentDeptId, dataSource, mobile]);
|
|
3382
|
-
const handleDepartmentSelect =
|
|
5848
|
+
const handleDepartmentSelect = useCallback6((deptId) => {
|
|
3383
5849
|
const nextDeptId = String(deptId || "");
|
|
3384
5850
|
setCurrentDeptId(nextDeptId);
|
|
3385
5851
|
setMemberKeyword("");
|
|
3386
5852
|
setMemberPage(1);
|
|
3387
5853
|
setMemberReloadKey((current) => current + 1);
|
|
3388
5854
|
}, []);
|
|
3389
|
-
|
|
5855
|
+
useEffect8(() => {
|
|
3390
5856
|
let active = true;
|
|
3391
5857
|
const keyword = activeMemberKeyword;
|
|
3392
5858
|
if (hasStaticUserSource) {
|
|
@@ -3459,7 +5925,7 @@ function UserPickerPanel({
|
|
|
3459
5925
|
memberReloadKey,
|
|
3460
5926
|
staticUsers
|
|
3461
5927
|
]);
|
|
3462
|
-
const currentPath =
|
|
5928
|
+
const currentPath = useMemo10(() => {
|
|
3463
5929
|
if (!currentDeptId) return [];
|
|
3464
5930
|
const path = [];
|
|
3465
5931
|
let cursor = currentDeptId;
|
|
@@ -3471,7 +5937,7 @@ function UserPickerPanel({
|
|
|
3471
5937
|
}
|
|
3472
5938
|
return path;
|
|
3473
5939
|
}, [currentDeptId, nodeMap, parentMap]);
|
|
3474
|
-
const mobileDepartments =
|
|
5940
|
+
const mobileDepartments = useMemo10(() => {
|
|
3475
5941
|
const keyword = mobileKeyword.trim().toLowerCase();
|
|
3476
5942
|
if (keyword) {
|
|
3477
5943
|
return flatNodes.filter((item) => item.name.toLowerCase().includes(keyword)).map((item) => item.node);
|
|
@@ -3493,19 +5959,19 @@ function UserPickerPanel({
|
|
|
3493
5959
|
}
|
|
3494
5960
|
setSelected(checked ? [normalized] : []);
|
|
3495
5961
|
};
|
|
3496
|
-
const renderSelected = () => /* @__PURE__ */
|
|
3497
|
-
/* @__PURE__ */
|
|
3498
|
-
/* @__PURE__ */
|
|
5962
|
+
const renderSelected = () => /* @__PURE__ */ jsxs9("div", { className: "sy-user-picker-selected", children: [
|
|
5963
|
+
/* @__PURE__ */ jsxs9("div", { className: "sy-org-picker-selected-head", children: [
|
|
5964
|
+
/* @__PURE__ */ jsxs9("span", { children: [
|
|
3499
5965
|
"\u5DF2\u9009 ",
|
|
3500
5966
|
selected.length,
|
|
3501
5967
|
" \u4EBA"
|
|
3502
5968
|
] }),
|
|
3503
|
-
/* @__PURE__ */
|
|
5969
|
+
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => setSelected([]), disabled: !selected.length, children: "\u6E05\u7A7A" })
|
|
3504
5970
|
] }),
|
|
3505
|
-
selected.length ? /* @__PURE__ */
|
|
5971
|
+
selected.length ? /* @__PURE__ */ jsx11("div", { className: "sy-org-picker-tags", children: selected.map((item) => /* @__PURE__ */ jsx11(Tag2, { closable: true, onClose: () => toggleUser(item, false), children: getUserName(item) }, getUserId(item))) }) : /* @__PURE__ */ jsx11(Empty4, { image: Empty4.PRESENTED_IMAGE_SIMPLE, description: "\u6682\u65E0\u9009\u62E9" })
|
|
3506
5972
|
] });
|
|
3507
|
-
const renderMemberList = () => /* @__PURE__ */
|
|
3508
|
-
/* @__PURE__ */
|
|
5973
|
+
const renderMemberList = () => /* @__PURE__ */ jsx11("div", { className: "sy-user-picker-member-panel", children: /* @__PURE__ */ jsxs9(Spin4, { spinning: loading, wrapperClassName: "sy-user-picker-member-spin", children: [
|
|
5974
|
+
/* @__PURE__ */ jsx11("div", { className: "sy-user-picker-list", children: /* @__PURE__ */ jsx11(
|
|
3509
5975
|
List,
|
|
3510
5976
|
{
|
|
3511
5977
|
dataSource: members,
|
|
@@ -3513,27 +5979,27 @@ function UserPickerPanel({
|
|
|
3513
5979
|
renderItem: (user) => {
|
|
3514
5980
|
const id = getUserId(user);
|
|
3515
5981
|
const checked = selectedIds.includes(id);
|
|
3516
|
-
return /* @__PURE__ */
|
|
3517
|
-
/* @__PURE__ */
|
|
5982
|
+
return /* @__PURE__ */ jsx11(List.Item, { children: /* @__PURE__ */ jsxs9("label", { className: "sy-user-picker-row", children: [
|
|
5983
|
+
/* @__PURE__ */ jsx11(
|
|
3518
5984
|
Checkbox,
|
|
3519
5985
|
{
|
|
3520
5986
|
checked,
|
|
3521
5987
|
onChange: (event) => toggleUser(user, event.target.checked)
|
|
3522
5988
|
}
|
|
3523
5989
|
),
|
|
3524
|
-
/* @__PURE__ */
|
|
3525
|
-
/* @__PURE__ */
|
|
5990
|
+
/* @__PURE__ */ jsx11(Avatar, { size: 36, src: user.avatar, icon: !user.avatar && /* @__PURE__ */ jsx11(UserOutlined3, {}) }),
|
|
5991
|
+
/* @__PURE__ */ jsx11("span", { children: getUserName(user) })
|
|
3526
5992
|
] }) }, id);
|
|
3527
5993
|
}
|
|
3528
5994
|
}
|
|
3529
5995
|
) }),
|
|
3530
|
-
/* @__PURE__ */
|
|
3531
|
-
/* @__PURE__ */
|
|
5996
|
+
/* @__PURE__ */ jsxs9("div", { className: "sy-user-picker-pagination", children: [
|
|
5997
|
+
/* @__PURE__ */ jsxs9("span", { children: [
|
|
3532
5998
|
"\u5171 ",
|
|
3533
5999
|
memberTotal,
|
|
3534
6000
|
" \u4EBA"
|
|
3535
6001
|
] }),
|
|
3536
|
-
/* @__PURE__ */
|
|
6002
|
+
/* @__PURE__ */ jsx11(
|
|
3537
6003
|
Pagination,
|
|
3538
6004
|
{
|
|
3539
6005
|
size: "small",
|
|
@@ -3551,35 +6017,35 @@ function UserPickerPanel({
|
|
|
3551
6017
|
] })
|
|
3552
6018
|
] }) });
|
|
3553
6019
|
if (mobile) {
|
|
3554
|
-
return /* @__PURE__ */
|
|
3555
|
-
/* @__PURE__ */
|
|
3556
|
-
/* @__PURE__ */
|
|
3557
|
-
/* @__PURE__ */
|
|
3558
|
-
/* @__PURE__ */
|
|
6020
|
+
return /* @__PURE__ */ jsxs9("div", { className: "sy-user-picker sy-user-picker-mobile", children: [
|
|
6021
|
+
/* @__PURE__ */ jsxs9("div", { className: "sy-org-picker-mobile-head", children: [
|
|
6022
|
+
/* @__PURE__ */ jsx11("button", { type: "button", onClick: onCancel, children: "\u53D6\u6D88" }),
|
|
6023
|
+
/* @__PURE__ */ jsx11("strong", { children: "\u9009\u62E9\u6210\u5458" }),
|
|
6024
|
+
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => onConfirm(selected), children: "\u786E\u5B9A" })
|
|
3559
6025
|
] }),
|
|
3560
|
-
MobileSearchBar ? /* @__PURE__ */
|
|
6026
|
+
MobileSearchBar ? /* @__PURE__ */ jsx11(
|
|
3561
6027
|
MobileSearchBar,
|
|
3562
6028
|
{
|
|
3563
6029
|
placeholder: "\u641C\u7D22\u90E8\u95E8\u6216\u6210\u5458",
|
|
3564
6030
|
value: mobileKeyword,
|
|
3565
6031
|
onChange: setMobileKeyword
|
|
3566
6032
|
}
|
|
3567
|
-
) : /* @__PURE__ */
|
|
3568
|
-
/* @__PURE__ */
|
|
3569
|
-
/* @__PURE__ */
|
|
3570
|
-
currentPath.map((item) => /* @__PURE__ */
|
|
6033
|
+
) : /* @__PURE__ */ jsx11("input", { value: mobileKeyword, onChange: (event) => setMobileKeyword(event.target.value) }),
|
|
6034
|
+
/* @__PURE__ */ jsxs9("div", { className: "sy-org-picker-breadcrumb", children: [
|
|
6035
|
+
/* @__PURE__ */ jsx11("button", { type: "button", onClick: () => handleDepartmentSelect(""), children: "\u901A\u8BAF\u5F55" }),
|
|
6036
|
+
currentPath.map((item) => /* @__PURE__ */ jsxs9("button", { type: "button", onClick: () => handleDepartmentSelect(item.id), children: [
|
|
3571
6037
|
"/ ",
|
|
3572
6038
|
item.name
|
|
3573
6039
|
] }, item.id))
|
|
3574
6040
|
] }),
|
|
3575
|
-
/* @__PURE__ */
|
|
6041
|
+
/* @__PURE__ */ jsx11(Spin4, { spinning: treeLoading, children: /* @__PURE__ */ jsx11(
|
|
3576
6042
|
List,
|
|
3577
6043
|
{
|
|
3578
6044
|
dataSource: mobileDepartments,
|
|
3579
6045
|
locale: { emptyText: null },
|
|
3580
6046
|
renderItem: (node) => {
|
|
3581
6047
|
const id = getDepartmentId(node);
|
|
3582
|
-
return /* @__PURE__ */
|
|
6048
|
+
return /* @__PURE__ */ jsx11(
|
|
3583
6049
|
List.Item,
|
|
3584
6050
|
{
|
|
3585
6051
|
onClick: async () => {
|
|
@@ -3587,7 +6053,7 @@ function UserPickerPanel({
|
|
|
3587
6053
|
handleDepartmentSelect(id);
|
|
3588
6054
|
setMobileKeyword("");
|
|
3589
6055
|
},
|
|
3590
|
-
children: /* @__PURE__ */
|
|
6056
|
+
children: /* @__PURE__ */ jsx11(List.Item.Meta, { avatar: /* @__PURE__ */ jsx11(TeamOutlined, {}), title: getDepartmentName(node) })
|
|
3591
6057
|
},
|
|
3592
6058
|
id
|
|
3593
6059
|
);
|
|
@@ -3602,20 +6068,20 @@ function UserPickerPanel({
|
|
|
3602
6068
|
const filteredTreeData = lowerDepartmentKeyword ? deptTreeData.filter(
|
|
3603
6069
|
(node) => getDepartmentName(node).toLowerCase().includes(lowerDepartmentKeyword)
|
|
3604
6070
|
) : deptTreeData;
|
|
3605
|
-
return /* @__PURE__ */
|
|
3606
|
-
/* @__PURE__ */
|
|
3607
|
-
/* @__PURE__ */
|
|
3608
|
-
/* @__PURE__ */
|
|
6071
|
+
return /* @__PURE__ */ jsxs9("div", { className: "sy-user-picker", children: [
|
|
6072
|
+
/* @__PURE__ */ jsxs9("div", { className: "sy-user-picker-main", children: [
|
|
6073
|
+
/* @__PURE__ */ jsxs9("div", { className: "sy-user-picker-depts", children: [
|
|
6074
|
+
/* @__PURE__ */ jsx11(
|
|
3609
6075
|
Input,
|
|
3610
6076
|
{
|
|
3611
6077
|
allowClear: true,
|
|
3612
|
-
prefix: /* @__PURE__ */
|
|
6078
|
+
prefix: /* @__PURE__ */ jsx11(SearchOutlined, {}),
|
|
3613
6079
|
placeholder: "\u641C\u7D22\u90E8\u95E8",
|
|
3614
6080
|
value: departmentKeyword,
|
|
3615
6081
|
onChange: (event) => setDepartmentKeyword(event.target.value)
|
|
3616
6082
|
}
|
|
3617
6083
|
),
|
|
3618
|
-
/* @__PURE__ */
|
|
6084
|
+
/* @__PURE__ */ jsx11(Spin4, { spinning: treeLoading, children: /* @__PURE__ */ jsx11(
|
|
3619
6085
|
Tree,
|
|
3620
6086
|
{
|
|
3621
6087
|
selectedKeys: currentDeptId ? [currentDeptId] : [],
|
|
@@ -3628,12 +6094,12 @@ function UserPickerPanel({
|
|
|
3628
6094
|
}
|
|
3629
6095
|
) })
|
|
3630
6096
|
] }),
|
|
3631
|
-
/* @__PURE__ */
|
|
3632
|
-
displaySearch && /* @__PURE__ */
|
|
6097
|
+
/* @__PURE__ */ jsxs9("div", { className: "sy-user-picker-members", children: [
|
|
6098
|
+
displaySearch && /* @__PURE__ */ jsx11(
|
|
3633
6099
|
Input,
|
|
3634
6100
|
{
|
|
3635
6101
|
allowClear: true,
|
|
3636
|
-
prefix: /* @__PURE__ */
|
|
6102
|
+
prefix: /* @__PURE__ */ jsx11(SearchOutlined, {}),
|
|
3637
6103
|
placeholder: "\u641C\u7D22\u6210\u5458",
|
|
3638
6104
|
value: memberKeyword,
|
|
3639
6105
|
onChange: (event) => setMemberKeyword(event.target.value)
|
|
@@ -3643,9 +6109,9 @@ function UserPickerPanel({
|
|
|
3643
6109
|
] }),
|
|
3644
6110
|
renderSelected()
|
|
3645
6111
|
] }),
|
|
3646
|
-
/* @__PURE__ */
|
|
3647
|
-
/* @__PURE__ */
|
|
3648
|
-
/* @__PURE__ */
|
|
6112
|
+
/* @__PURE__ */ jsx11("div", { className: "sy-org-picker-footer", children: /* @__PURE__ */ jsxs9(Space, { children: [
|
|
6113
|
+
/* @__PURE__ */ jsx11(Button6, { onClick: onCancel, children: "\u53D6\u6D88" }),
|
|
6114
|
+
/* @__PURE__ */ jsx11(Button6, { type: "primary", onClick: () => onConfirm(selected), children: "\u786E\u5B9A" })
|
|
3649
6115
|
] }) })
|
|
3650
6116
|
] });
|
|
3651
6117
|
}
|
|
@@ -3660,7 +6126,7 @@ function UserPicker({
|
|
|
3660
6126
|
onOpenChange(false);
|
|
3661
6127
|
onCancel();
|
|
3662
6128
|
};
|
|
3663
|
-
const panel = /* @__PURE__ */
|
|
6129
|
+
const panel = /* @__PURE__ */ jsx11(
|
|
3664
6130
|
UserPickerPanel,
|
|
3665
6131
|
{
|
|
3666
6132
|
...panelProps,
|
|
@@ -3675,7 +6141,7 @@ function UserPicker({
|
|
|
3675
6141
|
if (mobile) {
|
|
3676
6142
|
const MobilePopup = getMobileComponent("Popup");
|
|
3677
6143
|
if (!MobilePopup) return open ? panel : null;
|
|
3678
|
-
return /* @__PURE__ */
|
|
6144
|
+
return /* @__PURE__ */ jsx11(
|
|
3679
6145
|
MobilePopup,
|
|
3680
6146
|
{
|
|
3681
6147
|
visible: open,
|
|
@@ -3686,8 +6152,8 @@ function UserPicker({
|
|
|
3686
6152
|
}
|
|
3687
6153
|
);
|
|
3688
6154
|
}
|
|
3689
|
-
return /* @__PURE__ */
|
|
3690
|
-
|
|
6155
|
+
return /* @__PURE__ */ jsx11(
|
|
6156
|
+
Modal3,
|
|
3691
6157
|
{
|
|
3692
6158
|
title: "\u9009\u62E9\u6210\u5458",
|
|
3693
6159
|
open,
|
|
@@ -3701,7 +6167,7 @@ function UserPicker({
|
|
|
3701
6167
|
}
|
|
3702
6168
|
|
|
3703
6169
|
// packages/sdk/src/components/modules/InitiatorApproverSelector.tsx
|
|
3704
|
-
import { jsx as
|
|
6170
|
+
import { jsx as jsx12, jsxs as jsxs10 } from "react/jsx-runtime";
|
|
3705
6171
|
var scopeText = {
|
|
3706
6172
|
all: "\u5168\u90E8\u6210\u5458",
|
|
3707
6173
|
members: "\u6307\u5B9A\u6210\u5458",
|
|
@@ -3735,19 +6201,19 @@ var RequirementSelect = ({
|
|
|
3735
6201
|
selectedUsers,
|
|
3736
6202
|
onChange
|
|
3737
6203
|
}) => {
|
|
3738
|
-
const [pickerOpen, setPickerOpen] =
|
|
3739
|
-
const initialCandidates =
|
|
6204
|
+
const [pickerOpen, setPickerOpen] = useState10(false);
|
|
6205
|
+
const initialCandidates = useMemo11(
|
|
3740
6206
|
() => (requirement.candidateUsers || []).map(normalizeCandidate).filter(Boolean),
|
|
3741
6207
|
[requirement.candidateUsers]
|
|
3742
6208
|
);
|
|
3743
|
-
const [optionsSource, setOptionsSource] =
|
|
3744
|
-
const [loading, setLoading] =
|
|
3745
|
-
|
|
6209
|
+
const [optionsSource, setOptionsSource] = useState10(initialCandidates);
|
|
6210
|
+
const [loading, setLoading] = useState10(false);
|
|
6211
|
+
useEffect9(() => {
|
|
3746
6212
|
setOptionsSource(
|
|
3747
6213
|
(current) => mergeUsers(initialCandidates, mergeUsers(current, selectedUsers))
|
|
3748
6214
|
);
|
|
3749
6215
|
}, [initialCandidates, selectedUsers]);
|
|
3750
|
-
const loadCandidates =
|
|
6216
|
+
const loadCandidates = useCallback7(
|
|
3751
6217
|
async (keyword) => {
|
|
3752
6218
|
setLoading(true);
|
|
3753
6219
|
try {
|
|
@@ -3785,12 +6251,12 @@ var RequirementSelect = ({
|
|
|
3785
6251
|
},
|
|
3786
6252
|
[api, appType, formUuid, initialCandidates.length, requirement.nodeId, requirement.scope]
|
|
3787
6253
|
);
|
|
3788
|
-
|
|
6254
|
+
useEffect9(() => {
|
|
3789
6255
|
if (requirement.scope !== "all" && open && formUuid && appType && requirement.nodeId) {
|
|
3790
6256
|
void loadCandidates();
|
|
3791
6257
|
}
|
|
3792
6258
|
}, [appType, formUuid, loadCandidates, open, requirement.nodeId, requirement.scope]);
|
|
3793
|
-
const options =
|
|
6259
|
+
const options = useMemo11(
|
|
3794
6260
|
() => optionsSource.map((user) => ({
|
|
3795
6261
|
value: user.id,
|
|
3796
6262
|
label: getUserLabel(user)
|
|
@@ -3798,19 +6264,19 @@ var RequirementSelect = ({
|
|
|
3798
6264
|
[optionsSource]
|
|
3799
6265
|
);
|
|
3800
6266
|
if (requirement.scope === "all") {
|
|
3801
|
-
return /* @__PURE__ */
|
|
3802
|
-
/* @__PURE__ */
|
|
3803
|
-
/* @__PURE__ */
|
|
3804
|
-
/* @__PURE__ */
|
|
3805
|
-
/* @__PURE__ */
|
|
6267
|
+
return /* @__PURE__ */ jsxs10("div", { className: "rounded-lg border border-ant-border-secondary bg-ant-bg-container p-3", children: [
|
|
6268
|
+
/* @__PURE__ */ jsxs10("div", { className: "mb-2 flex items-start justify-between gap-3", children: [
|
|
6269
|
+
/* @__PURE__ */ jsxs10("div", { children: [
|
|
6270
|
+
/* @__PURE__ */ jsx12(Typography4.Text, { strong: true, children: requirement.nodeName }),
|
|
6271
|
+
/* @__PURE__ */ jsxs10("div", { className: "mt-1 text-xs text-ant-color-text-tertiary", children: [
|
|
3806
6272
|
"\u9009\u62E9\u8303\u56F4\uFF1A",
|
|
3807
6273
|
scopeText[requirement.scope] || "\u5168\u90E8\u6210\u5458"
|
|
3808
6274
|
] })
|
|
3809
6275
|
] }),
|
|
3810
|
-
/* @__PURE__ */
|
|
6276
|
+
/* @__PURE__ */ jsx12(Button7, { onClick: () => setPickerOpen(true), children: selectedUsers.length > 0 ? "\u91CD\u65B0\u9009\u62E9\u6210\u5458" : "\u9009\u62E9\u6210\u5458" })
|
|
3811
6277
|
] }),
|
|
3812
|
-
selectedUsers.length > 0 ? /* @__PURE__ */
|
|
3813
|
-
/* @__PURE__ */
|
|
6278
|
+
selectedUsers.length > 0 ? /* @__PURE__ */ jsx12(Space2, { size: [4, 4], wrap: true, className: "mt-2", children: selectedUsers.map((user) => /* @__PURE__ */ jsx12(Tag3, { children: getUserLabel(user) }, user.id)) }) : /* @__PURE__ */ jsx12(Empty5, { image: Empty5.PRESENTED_IMAGE_SIMPLE, description: "\u8BF7\u4ECE\u7EC4\u7EC7\u67B6\u6784\u9009\u62E9\u6210\u5458" }),
|
|
6279
|
+
/* @__PURE__ */ jsx12(
|
|
3814
6280
|
UserPicker,
|
|
3815
6281
|
{
|
|
3816
6282
|
api,
|
|
@@ -3830,15 +6296,15 @@ var RequirementSelect = ({
|
|
|
3830
6296
|
)
|
|
3831
6297
|
] });
|
|
3832
6298
|
}
|
|
3833
|
-
return /* @__PURE__ */
|
|
3834
|
-
/* @__PURE__ */
|
|
3835
|
-
/* @__PURE__ */
|
|
3836
|
-
/* @__PURE__ */
|
|
6299
|
+
return /* @__PURE__ */ jsxs10("div", { className: "rounded-lg border border-ant-border-secondary bg-ant-bg-container p-3", children: [
|
|
6300
|
+
/* @__PURE__ */ jsxs10("div", { className: "mb-2", children: [
|
|
6301
|
+
/* @__PURE__ */ jsx12(Typography4.Text, { strong: true, children: requirement.nodeName }),
|
|
6302
|
+
/* @__PURE__ */ jsxs10("div", { className: "mt-1 text-xs text-ant-color-text-tertiary", children: [
|
|
3837
6303
|
"\u9009\u62E9\u8303\u56F4\uFF1A",
|
|
3838
6304
|
scopeText[requirement.scope] || "\u5168\u90E8\u6210\u5458"
|
|
3839
6305
|
] })
|
|
3840
6306
|
] }),
|
|
3841
|
-
/* @__PURE__ */
|
|
6307
|
+
/* @__PURE__ */ jsx12(
|
|
3842
6308
|
Select,
|
|
3843
6309
|
{
|
|
3844
6310
|
mode: "multiple",
|
|
@@ -3850,7 +6316,7 @@ var RequirementSelect = ({
|
|
|
3850
6316
|
loading,
|
|
3851
6317
|
value: selectedUsers.map((user) => user.id),
|
|
3852
6318
|
options,
|
|
3853
|
-
notFoundContent: loading ? "\u52A0\u8F7D\u4E2D..." : /* @__PURE__ */
|
|
6319
|
+
notFoundContent: loading ? "\u52A0\u8F7D\u4E2D..." : /* @__PURE__ */ jsx12(Empty5, { image: Empty5.PRESENTED_IMAGE_SIMPLE }),
|
|
3854
6320
|
onSearch: (keyword) => {
|
|
3855
6321
|
void loadCandidates(keyword);
|
|
3856
6322
|
},
|
|
@@ -3862,7 +6328,7 @@ var RequirementSelect = ({
|
|
|
3862
6328
|
}
|
|
3863
6329
|
}
|
|
3864
6330
|
),
|
|
3865
|
-
selectedUsers.length > 0 ? /* @__PURE__ */
|
|
6331
|
+
selectedUsers.length > 0 ? /* @__PURE__ */ jsx12(Space2, { size: [4, 4], wrap: true, className: "mt-2", children: selectedUsers.map((user) => /* @__PURE__ */ jsx12(Tag3, { children: getUserLabel(user) }, user.id)) }) : null
|
|
3866
6332
|
] });
|
|
3867
6333
|
};
|
|
3868
6334
|
var InitiatorApproverSelector = ({
|
|
@@ -3875,9 +6341,9 @@ var InitiatorApproverSelector = ({
|
|
|
3875
6341
|
onOk,
|
|
3876
6342
|
onCancel
|
|
3877
6343
|
}) => {
|
|
3878
|
-
const [selected, setSelected] =
|
|
3879
|
-
const wasOpenRef =
|
|
3880
|
-
|
|
6344
|
+
const [selected, setSelected] = useState10({});
|
|
6345
|
+
const wasOpenRef = useRef4(false);
|
|
6346
|
+
useEffect9(() => {
|
|
3881
6347
|
if (open && !wasOpenRef.current) {
|
|
3882
6348
|
setSelected(value || EMPTY_SELECTED_MAP);
|
|
3883
6349
|
}
|
|
@@ -3886,8 +6352,8 @@ var InitiatorApproverSelector = ({
|
|
|
3886
6352
|
const missingNodes = requirements.filter(
|
|
3887
6353
|
(requirement) => !(selected[requirement.nodeId] || []).length
|
|
3888
6354
|
);
|
|
3889
|
-
return /* @__PURE__ */
|
|
3890
|
-
|
|
6355
|
+
return /* @__PURE__ */ jsx12(
|
|
6356
|
+
Modal4,
|
|
3891
6357
|
{
|
|
3892
6358
|
getContainer: false,
|
|
3893
6359
|
title: "\u9009\u62E9\u5BA1\u6279\u4EBA",
|
|
@@ -3904,7 +6370,7 @@ var InitiatorApproverSelector = ({
|
|
|
3904
6370
|
onOk(selected);
|
|
3905
6371
|
},
|
|
3906
6372
|
destroyOnHidden: true,
|
|
3907
|
-
children: /* @__PURE__ */
|
|
6373
|
+
children: /* @__PURE__ */ jsx12(Space2, { direction: "vertical", size: 12, className: "w-full", children: requirements.map((requirement) => /* @__PURE__ */ jsx12(
|
|
3908
6374
|
RequirementSelect,
|
|
3909
6375
|
{
|
|
3910
6376
|
open,
|
|
@@ -3922,7 +6388,7 @@ var InitiatorApproverSelector = ({
|
|
|
3922
6388
|
};
|
|
3923
6389
|
|
|
3924
6390
|
// packages/sdk/src/runtime/react/workflow.tsx
|
|
3925
|
-
import { Fragment as
|
|
6391
|
+
import { Fragment as Fragment4, jsx as jsx13, jsxs as jsxs11 } from "react/jsx-runtime";
|
|
3926
6392
|
var getError = (error) => error instanceof Error ? error : new Error(String(error || "\u6D41\u7A0B\u80FD\u529B\u89E3\u6790\u5931\u8D25"));
|
|
3927
6393
|
var normalizeCapabilities = (value) => {
|
|
3928
6394
|
const raw = value || {};
|
|
@@ -3935,20 +6401,20 @@ var normalizeCapabilities = (value) => {
|
|
|
3935
6401
|
function useProcessCapabilities(options) {
|
|
3936
6402
|
const { enabled = true, refreshKey, onError, ...params } = options;
|
|
3937
6403
|
const sdk = usePageSdk();
|
|
3938
|
-
const [capabilities, setCapabilities] =
|
|
6404
|
+
const [capabilities, setCapabilities] = useState11(
|
|
3939
6405
|
null
|
|
3940
6406
|
);
|
|
3941
|
-
const [loading, setLoading] =
|
|
3942
|
-
const [error, setError] =
|
|
3943
|
-
const mountedRef =
|
|
6407
|
+
const [loading, setLoading] = useState11(false);
|
|
6408
|
+
const [error, setError] = useState11(null);
|
|
6409
|
+
const mountedRef = useRef5(true);
|
|
3944
6410
|
const paramsKey = JSON.stringify({ ...params, refreshKey });
|
|
3945
|
-
|
|
6411
|
+
useEffect10(() => {
|
|
3946
6412
|
mountedRef.current = true;
|
|
3947
6413
|
return () => {
|
|
3948
6414
|
mountedRef.current = false;
|
|
3949
6415
|
};
|
|
3950
6416
|
}, []);
|
|
3951
|
-
const refresh =
|
|
6417
|
+
const refresh = useCallback8(async () => {
|
|
3952
6418
|
if (!enabled) return capabilities;
|
|
3953
6419
|
setLoading(true);
|
|
3954
6420
|
setError(null);
|
|
@@ -3974,7 +6440,7 @@ function useProcessCapabilities(options) {
|
|
|
3974
6440
|
}
|
|
3975
6441
|
}
|
|
3976
6442
|
}, [capabilities, enabled, onError, paramsKey, sdk]);
|
|
3977
|
-
|
|
6443
|
+
useEffect10(() => {
|
|
3978
6444
|
if (!enabled) return;
|
|
3979
6445
|
void refresh();
|
|
3980
6446
|
}, [enabled, paramsKey, refresh]);
|
|
@@ -3999,8 +6465,8 @@ var requireValue = (value, message3) => {
|
|
|
3999
6465
|
function useProcessActions(options) {
|
|
4000
6466
|
const { capabilities, formUuid, appType, getFormValues, onActionComplete } = options;
|
|
4001
6467
|
const sdk = usePageSdk();
|
|
4002
|
-
const [loadingAction, setLoadingAction] =
|
|
4003
|
-
const buildUpdateFormDataJson =
|
|
6468
|
+
const [loadingAction, setLoadingAction] = useState11(null);
|
|
6469
|
+
const buildUpdateFormDataJson = useCallback8(
|
|
4004
6470
|
(input) => {
|
|
4005
6471
|
if (input?.updateFormDataJson !== void 0) return input.updateFormDataJson;
|
|
4006
6472
|
const values = getFormValues?.();
|
|
@@ -4008,7 +6474,7 @@ function useProcessActions(options) {
|
|
|
4008
6474
|
},
|
|
4009
6475
|
[getFormValues]
|
|
4010
6476
|
);
|
|
4011
|
-
const executeOperation =
|
|
6477
|
+
const executeOperation = useCallback8(
|
|
4012
6478
|
async (operation, input = {}) => {
|
|
4013
6479
|
if (!operation.enabled) return false;
|
|
4014
6480
|
setLoadingAction(operation.key);
|
|
@@ -4118,7 +6584,7 @@ function useProcessActions(options) {
|
|
|
4118
6584
|
sdk
|
|
4119
6585
|
]
|
|
4120
6586
|
);
|
|
4121
|
-
const execute =
|
|
6587
|
+
const execute = useCallback8(
|
|
4122
6588
|
async (action, input) => {
|
|
4123
6589
|
const operation = (capabilities?.operations || []).find(
|
|
4124
6590
|
(item) => item.key === action
|
|
@@ -4161,12 +6627,12 @@ var actionTone = (key) => {
|
|
|
4161
6627
|
return "default";
|
|
4162
6628
|
};
|
|
4163
6629
|
var actionIcon = (key) => {
|
|
4164
|
-
if (key === "startProcess" || key === "approve") return /* @__PURE__ */
|
|
4165
|
-
if (key === "reject") return /* @__PURE__ */
|
|
4166
|
-
if (key === "transfer" || key === "adminTransfer") return /* @__PURE__ */
|
|
4167
|
-
if (key === "return" || key === "withdraw") return /* @__PURE__ */
|
|
4168
|
-
if (key === "save") return /* @__PURE__ */
|
|
4169
|
-
if (key === "retryException" || key === "callback") return /* @__PURE__ */
|
|
6630
|
+
if (key === "startProcess" || key === "approve") return /* @__PURE__ */ jsx13(CheckOutlined, {});
|
|
6631
|
+
if (key === "reject") return /* @__PURE__ */ jsx13(CloseOutlined3, {});
|
|
6632
|
+
if (key === "transfer" || key === "adminTransfer") return /* @__PURE__ */ jsx13(SwapOutlined, {});
|
|
6633
|
+
if (key === "return" || key === "withdraw") return /* @__PURE__ */ jsx13(RollbackOutlined2, {});
|
|
6634
|
+
if (key === "save") return /* @__PURE__ */ jsx13(SaveOutlined, {});
|
|
6635
|
+
if (key === "retryException" || key === "callback") return /* @__PURE__ */ jsx13(ReloadOutlined4, {});
|
|
4170
6636
|
return void 0;
|
|
4171
6637
|
};
|
|
4172
6638
|
var getModalTitle = (key) => {
|
|
@@ -4193,7 +6659,7 @@ var ProcessActionBar = ({
|
|
|
4193
6659
|
position = "sticky"
|
|
4194
6660
|
}) => {
|
|
4195
6661
|
const [form] = Form.useForm();
|
|
4196
|
-
const [activeOperation, setActiveOperation] =
|
|
6662
|
+
const [activeOperation, setActiveOperation] = useState11(null);
|
|
4197
6663
|
const autoCapabilities = useProcessCapabilities({
|
|
4198
6664
|
...capabilityParams || {},
|
|
4199
6665
|
enabled: Boolean(capabilityParams) && capabilityParams?.enabled !== false
|
|
@@ -4228,7 +6694,7 @@ var ProcessActionBar = ({
|
|
|
4228
6694
|
}
|
|
4229
6695
|
void actions.executeOperation(operation);
|
|
4230
6696
|
};
|
|
4231
|
-
const actionConfigs =
|
|
6697
|
+
const actionConfigs = useMemo12(
|
|
4232
6698
|
() => operations.map((operation) => ({
|
|
4233
6699
|
key: operation.key,
|
|
4234
6700
|
label: operation.label || operation.key,
|
|
@@ -4260,8 +6726,8 @@ var ProcessActionBar = ({
|
|
|
4260
6726
|
label: String(node.nodeName || node.name || node.label || value)
|
|
4261
6727
|
};
|
|
4262
6728
|
});
|
|
4263
|
-
return /* @__PURE__ */
|
|
4264
|
-
/* @__PURE__ */
|
|
6729
|
+
return /* @__PURE__ */ jsxs11(Fragment4, { children: [
|
|
6730
|
+
/* @__PURE__ */ jsx13(
|
|
4265
6731
|
StickyActionBar,
|
|
4266
6732
|
{
|
|
4267
6733
|
actions: actionConfigs,
|
|
@@ -4273,8 +6739,8 @@ var ProcessActionBar = ({
|
|
|
4273
6739
|
position
|
|
4274
6740
|
}
|
|
4275
6741
|
),
|
|
4276
|
-
/* @__PURE__ */
|
|
4277
|
-
|
|
6742
|
+
/* @__PURE__ */ jsx13(
|
|
6743
|
+
Modal5,
|
|
4278
6744
|
{
|
|
4279
6745
|
getContainer: false,
|
|
4280
6746
|
title: modalKey ? getModalTitle(modalKey) : "\u6D41\u7A0B\u64CD\u4F5C",
|
|
@@ -4290,26 +6756,26 @@ var ProcessActionBar = ({
|
|
|
4290
6756
|
form.resetFields();
|
|
4291
6757
|
},
|
|
4292
6758
|
destroyOnHidden: true,
|
|
4293
|
-
children: /* @__PURE__ */
|
|
4294
|
-
(modalKey === "transfer" || modalKey === "adminTransfer") && /* @__PURE__ */
|
|
6759
|
+
children: /* @__PURE__ */ jsxs11(Form, { form, layout: "vertical", children: [
|
|
6760
|
+
(modalKey === "transfer" || modalKey === "adminTransfer") && /* @__PURE__ */ jsx13(
|
|
4295
6761
|
Form.Item,
|
|
4296
6762
|
{
|
|
4297
6763
|
name: "newAssignee",
|
|
4298
6764
|
label: "\u63A5\u6536\u4EBA",
|
|
4299
6765
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u63A5\u6536\u4EBA\u7528\u6237ID" }],
|
|
4300
|
-
children: /* @__PURE__ */
|
|
6766
|
+
children: /* @__PURE__ */ jsx13(Input2, { placeholder: "\u8BF7\u8F93\u5165\u7528\u6237ID" })
|
|
4301
6767
|
}
|
|
4302
6768
|
),
|
|
4303
|
-
modalKey === "return" && /* @__PURE__ */
|
|
6769
|
+
modalKey === "return" && /* @__PURE__ */ jsx13(
|
|
4304
6770
|
Form.Item,
|
|
4305
6771
|
{
|
|
4306
6772
|
name: "targetNodeId",
|
|
4307
6773
|
label: "\u9000\u56DE\u8282\u70B9",
|
|
4308
6774
|
rules: [{ required: true, message: "\u8BF7\u9009\u62E9\u9000\u56DE\u8282\u70B9" }],
|
|
4309
|
-
children: /* @__PURE__ */
|
|
6775
|
+
children: /* @__PURE__ */ jsx13(Select2, { placeholder: "\u8BF7\u9009\u62E9\u9000\u56DE\u8282\u70B9", options: returnOptions })
|
|
4310
6776
|
}
|
|
4311
6777
|
),
|
|
4312
|
-
/* @__PURE__ */
|
|
6778
|
+
/* @__PURE__ */ jsx13(
|
|
4313
6779
|
Form.Item,
|
|
4314
6780
|
{
|
|
4315
6781
|
name: modalKey === "reject" || modalKey === "resubmit" ? "comments" : "reason",
|
|
@@ -4320,7 +6786,7 @@ var ProcessActionBar = ({
|
|
|
4320
6786
|
message: "\u8BF7\u586B\u5199\u8BF4\u660E"
|
|
4321
6787
|
}
|
|
4322
6788
|
],
|
|
4323
|
-
children: /* @__PURE__ */
|
|
6789
|
+
children: /* @__PURE__ */ jsx13(Input2.TextArea, { rows: 4, maxLength: 500, showCount: true })
|
|
4324
6790
|
}
|
|
4325
6791
|
)
|
|
4326
6792
|
] })
|
|
@@ -4332,7 +6798,7 @@ var ProcessTimeline = ({
|
|
|
4332
6798
|
capabilities,
|
|
4333
6799
|
tasks,
|
|
4334
6800
|
...props
|
|
4335
|
-
}) => /* @__PURE__ */
|
|
6801
|
+
}) => /* @__PURE__ */ jsx13(
|
|
4336
6802
|
ApprovalTimeline,
|
|
4337
6803
|
{
|
|
4338
6804
|
...props,
|
|
@@ -4344,12 +6810,12 @@ var ProcessPreviewPanel = ProcessPreview;
|
|
|
4344
6810
|
// packages/sdk/src/runtime/react/openxiangdaProvider.tsx
|
|
4345
6811
|
import {
|
|
4346
6812
|
createContext as createContext2,
|
|
4347
|
-
useCallback as
|
|
6813
|
+
useCallback as useCallback10,
|
|
4348
6814
|
useContext as useContext2,
|
|
4349
|
-
useEffect as
|
|
4350
|
-
useMemo as
|
|
4351
|
-
useRef as
|
|
4352
|
-
useState as
|
|
6815
|
+
useEffect as useEffect12,
|
|
6816
|
+
useMemo as useMemo14,
|
|
6817
|
+
useRef as useRef6,
|
|
6818
|
+
useState as useState13
|
|
4353
6819
|
} from "react";
|
|
4354
6820
|
|
|
4355
6821
|
// packages/sdk/src/runtime/core/fetch.ts
|
|
@@ -4386,24 +6852,24 @@ var createBoundFetch = (fetchImpl) => {
|
|
|
4386
6852
|
};
|
|
4387
6853
|
|
|
4388
6854
|
// packages/sdk/src/runtime/host/browserHost.ts
|
|
4389
|
-
var
|
|
4390
|
-
var getDefaultServicePrefix = () => typeof window !== "undefined" ?
|
|
6855
|
+
var trimTrailingSlash2 = (value) => value.replace(/\/+$/, "");
|
|
6856
|
+
var getDefaultServicePrefix = () => typeof window !== "undefined" ? trimTrailingSlash2(window.__OPENXIANGDA_SERVICE_PREFIX__ || "/service") : "/service";
|
|
4391
6857
|
var joinServicePath = (servicePrefix, path) => {
|
|
4392
6858
|
if (/^https?:\/\//i.test(path)) return path;
|
|
4393
|
-
const normalizedPrefix =
|
|
6859
|
+
const normalizedPrefix = trimTrailingSlash2(servicePrefix || "/service");
|
|
4394
6860
|
if (path.startsWith(normalizedPrefix)) return path;
|
|
4395
6861
|
return `${normalizedPrefix}${path.startsWith("/") ? path : `/${path}`}`;
|
|
4396
6862
|
};
|
|
4397
|
-
var
|
|
6863
|
+
var appendQuery2 = (url, query) => {
|
|
4398
6864
|
if (!query) return url;
|
|
4399
6865
|
return `${url}${url.includes("?") ? "&" : "?"}${query}`;
|
|
4400
6866
|
};
|
|
4401
|
-
var
|
|
6867
|
+
var normalizeMethod3 = (method) => {
|
|
4402
6868
|
const value = String(method || "get").toUpperCase();
|
|
4403
6869
|
return ["GET", "POST", "PUT", "DELETE", "PATCH"].includes(value) ? value : "GET";
|
|
4404
6870
|
};
|
|
4405
6871
|
var shouldRetryTransportRequest = (payload) => {
|
|
4406
|
-
const method =
|
|
6872
|
+
const method = normalizeMethod3(payload?.method);
|
|
4407
6873
|
if (method === "GET") return true;
|
|
4408
6874
|
const path = String(payload?.path || "").split("?")[0];
|
|
4409
6875
|
return method === "POST" && path === "/workflow/capabilities/resolve";
|
|
@@ -4413,7 +6879,7 @@ var normalizeEnvelopeCode2 = (value, fallback) => {
|
|
|
4413
6879
|
const normalized = Number(value);
|
|
4414
6880
|
return Number.isFinite(normalized) ? normalized : String(value);
|
|
4415
6881
|
};
|
|
4416
|
-
var
|
|
6882
|
+
var isSuccessCode4 = (value) => {
|
|
4417
6883
|
if (value === void 0 || value === null || value === "") return true;
|
|
4418
6884
|
const normalized = Number(value);
|
|
4419
6885
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -4428,7 +6894,7 @@ var parseJsonResponse = async (response) => {
|
|
|
4428
6894
|
const code = normalizeEnvelopeCode2(payload.code, response.status);
|
|
4429
6895
|
return {
|
|
4430
6896
|
code,
|
|
4431
|
-
success: payload.success !== false &&
|
|
6897
|
+
success: payload.success !== false && isSuccessCode4(code),
|
|
4432
6898
|
message: payload.message,
|
|
4433
6899
|
result: payload.result ?? payload.data ?? null,
|
|
4434
6900
|
data: payload.data,
|
|
@@ -4451,7 +6917,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4451
6917
|
if (!payload?.path) {
|
|
4452
6918
|
throw new Error("transport.request \u9700\u8981 path");
|
|
4453
6919
|
}
|
|
4454
|
-
const url =
|
|
6920
|
+
const url = appendQuery2(joinServicePath(servicePrefix, payload.path), payload.query);
|
|
4455
6921
|
const headers = new Headers(payload.headers);
|
|
4456
6922
|
let body;
|
|
4457
6923
|
if (payload.body !== void 0) {
|
|
@@ -4463,7 +6929,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4463
6929
|
}
|
|
4464
6930
|
}
|
|
4465
6931
|
const response = await fetchWithTransientRetry(fetchImpl, url, {
|
|
4466
|
-
method:
|
|
6932
|
+
method: normalizeMethod3(payload.method),
|
|
4467
6933
|
headers,
|
|
4468
6934
|
body,
|
|
4469
6935
|
credentials: "include"
|
|
@@ -4476,7 +6942,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4476
6942
|
if (!payload?.path) {
|
|
4477
6943
|
throw new Error("transport.download \u9700\u8981 path");
|
|
4478
6944
|
}
|
|
4479
|
-
const url =
|
|
6945
|
+
const url = appendQuery2(joinServicePath(servicePrefix, payload.path), payload.query);
|
|
4480
6946
|
const headers = new Headers(payload.headers);
|
|
4481
6947
|
let body;
|
|
4482
6948
|
if (payload.body !== void 0) {
|
|
@@ -4488,7 +6954,7 @@ var createBrowserPageBridge = (options = {}) => {
|
|
|
4488
6954
|
}
|
|
4489
6955
|
}
|
|
4490
6956
|
const response = await fetchImpl(url, {
|
|
4491
|
-
method:
|
|
6957
|
+
method: normalizeMethod3(payload.method),
|
|
4492
6958
|
headers,
|
|
4493
6959
|
body,
|
|
4494
6960
|
credentials: "include"
|
|
@@ -4576,21 +7042,21 @@ var createBrowserPageContext = (bootstrap, options = {}) => {
|
|
|
4576
7042
|
|
|
4577
7043
|
// packages/sdk/src/runtime/react/auth.tsx
|
|
4578
7044
|
import {
|
|
4579
|
-
useCallback as
|
|
4580
|
-
useEffect as
|
|
4581
|
-
useMemo as
|
|
4582
|
-
useState as
|
|
7045
|
+
useCallback as useCallback9,
|
|
7046
|
+
useEffect as useEffect11,
|
|
7047
|
+
useMemo as useMemo13,
|
|
7048
|
+
useState as useState12
|
|
4583
7049
|
} from "react";
|
|
4584
7050
|
import {
|
|
4585
|
-
Alert,
|
|
4586
|
-
Button as
|
|
7051
|
+
Alert as Alert4,
|
|
7052
|
+
Button as Button8,
|
|
4587
7053
|
Card,
|
|
4588
|
-
Empty as
|
|
7054
|
+
Empty as Empty6,
|
|
4589
7055
|
Form as Form2,
|
|
4590
7056
|
Input as Input3,
|
|
4591
7057
|
Space as Space3,
|
|
4592
|
-
Tabs,
|
|
4593
|
-
Typography as
|
|
7058
|
+
Tabs as Tabs2,
|
|
7059
|
+
Typography as Typography5
|
|
4594
7060
|
} from "antd";
|
|
4595
7061
|
import {
|
|
4596
7062
|
LoginOutlined,
|
|
@@ -4668,7 +7134,7 @@ var createAuthClient = ({
|
|
|
4668
7134
|
const payload = await readPayload(response);
|
|
4669
7135
|
const code = getRecordValue(payload, "code");
|
|
4670
7136
|
const success = getRecordValue(payload, "success");
|
|
4671
|
-
if (!response.ok || success === false || !
|
|
7137
|
+
if (!response.ok || success === false || !isSuccessCode5(code)) {
|
|
4672
7138
|
throw new AuthClientError(
|
|
4673
7139
|
String(getRecordValue(payload, "message") || `Auth request failed: ${response.status}`),
|
|
4674
7140
|
{
|
|
@@ -4747,7 +7213,7 @@ var readNumber = (value) => {
|
|
|
4747
7213
|
const numberValue = Number(value);
|
|
4748
7214
|
return Number.isFinite(numberValue) ? numberValue : void 0;
|
|
4749
7215
|
};
|
|
4750
|
-
var
|
|
7216
|
+
var isSuccessCode5 = (code) => {
|
|
4751
7217
|
if (code === void 0 || code === null || code === "") return true;
|
|
4752
7218
|
const normalized = Number(code);
|
|
4753
7219
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -4777,10 +7243,10 @@ var resolveLoginUrl = (appType, {
|
|
|
4777
7243
|
var getCurrentHref2 = () => typeof window === "undefined" ? "" : window.location.href;
|
|
4778
7244
|
|
|
4779
7245
|
// packages/sdk/src/runtime/react/auth.tsx
|
|
4780
|
-
import { Fragment as
|
|
7246
|
+
import { Fragment as Fragment5, jsx as jsx14, jsxs as jsxs12 } from "react/jsx-runtime";
|
|
4781
7247
|
var useAuth = (options = {}) => {
|
|
4782
7248
|
const runtime = useOpenXiangda();
|
|
4783
|
-
const client =
|
|
7249
|
+
const client = useMemo13(
|
|
4784
7250
|
() => createAuthClient({
|
|
4785
7251
|
appType: options.appType || runtime.appType,
|
|
4786
7252
|
servicePrefix: options.servicePrefix || runtime.servicePrefix,
|
|
@@ -4795,7 +7261,7 @@ var useAuth = (options = {}) => {
|
|
|
4795
7261
|
runtime.servicePrefix
|
|
4796
7262
|
]
|
|
4797
7263
|
);
|
|
4798
|
-
return
|
|
7264
|
+
return useMemo13(
|
|
4799
7265
|
() => ({
|
|
4800
7266
|
client,
|
|
4801
7267
|
getMethods: client.getMethods,
|
|
@@ -4815,12 +7281,12 @@ var useAuth = (options = {}) => {
|
|
|
4815
7281
|
};
|
|
4816
7282
|
var useLoginMethods = (options = {}) => {
|
|
4817
7283
|
const auth = useAuth(options);
|
|
4818
|
-
const [state, setState] =
|
|
7284
|
+
const [state, setState] = useState12({
|
|
4819
7285
|
data: null,
|
|
4820
7286
|
loading: true,
|
|
4821
7287
|
error: null
|
|
4822
7288
|
});
|
|
4823
|
-
const reload =
|
|
7289
|
+
const reload = useCallback9(async () => {
|
|
4824
7290
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
4825
7291
|
try {
|
|
4826
7292
|
const data = await auth.getMethods();
|
|
@@ -4833,7 +7299,7 @@ var useLoginMethods = (options = {}) => {
|
|
|
4833
7299
|
});
|
|
4834
7300
|
}
|
|
4835
7301
|
}, [auth]);
|
|
4836
|
-
|
|
7302
|
+
useEffect11(() => {
|
|
4837
7303
|
let disposed = false;
|
|
4838
7304
|
const run = async () => {
|
|
4839
7305
|
setState((prev) => ({ ...prev, loading: true, error: null }));
|
|
@@ -4877,17 +7343,17 @@ var LoginPage = ({
|
|
|
4877
7343
|
const methodsState = useLoginMethods(authOptions);
|
|
4878
7344
|
const [passwordForm] = Form2.useForm();
|
|
4879
7345
|
const [phoneForm] = Form2.useForm();
|
|
4880
|
-
const [activeMethod, setActiveMethod] =
|
|
7346
|
+
const [activeMethod, setActiveMethod] = useState12(
|
|
4881
7347
|
defaultMethod || "password"
|
|
4882
7348
|
);
|
|
4883
|
-
const [phonePurpose, setPhonePurpose] =
|
|
7349
|
+
const [phonePurpose, setPhonePurpose] = useState12(
|
|
4884
7350
|
"login"
|
|
4885
7351
|
);
|
|
4886
|
-
const [phoneChallengeId, setPhoneChallengeId] =
|
|
4887
|
-
const [passwordChallenge, setPasswordChallenge] =
|
|
4888
|
-
const [submitting, setSubmitting] =
|
|
4889
|
-
const [sendingCode, setSendingCode] =
|
|
4890
|
-
const [error, setError] =
|
|
7352
|
+
const [phoneChallengeId, setPhoneChallengeId] = useState12("");
|
|
7353
|
+
const [passwordChallenge, setPasswordChallenge] = useState12(null);
|
|
7354
|
+
const [submitting, setSubmitting] = useState12(false);
|
|
7355
|
+
const [sendingCode, setSendingCode] = useState12(false);
|
|
7356
|
+
const [error, setError] = useState12(null);
|
|
4891
7357
|
const methods = methodsState.methods.filter((method) => method.enabled !== false);
|
|
4892
7358
|
const passwordMethod = findMethod(methods, "password");
|
|
4893
7359
|
const phoneMethod = findMethod(methods, "phone_code");
|
|
@@ -4895,16 +7361,16 @@ var LoginPage = ({
|
|
|
4895
7361
|
const ssoMethod = findMethod(methods, "sso");
|
|
4896
7362
|
const guestMethod = findMethod(methods, "guest");
|
|
4897
7363
|
const allowRegister = methodsState.data?.registration?.mode !== "reject";
|
|
4898
|
-
const tabItems =
|
|
7364
|
+
const tabItems = useMemo13(() => {
|
|
4899
7365
|
const items = [];
|
|
4900
7366
|
if (passwordMethod) {
|
|
4901
7367
|
items.push({
|
|
4902
7368
|
key: "password",
|
|
4903
|
-
label: /* @__PURE__ */
|
|
4904
|
-
/* @__PURE__ */
|
|
4905
|
-
/* @__PURE__ */
|
|
7369
|
+
label: /* @__PURE__ */ jsxs12(Space3, { size: 6, children: [
|
|
7370
|
+
/* @__PURE__ */ jsx14(UserOutlined4, {}),
|
|
7371
|
+
/* @__PURE__ */ jsx14("span", { children: passwordMethod.label || "\u8D26\u53F7\u5BC6\u7801" })
|
|
4906
7372
|
] }),
|
|
4907
|
-
children: /* @__PURE__ */
|
|
7373
|
+
children: /* @__PURE__ */ jsx14(
|
|
4908
7374
|
PasswordLoginForm,
|
|
4909
7375
|
{
|
|
4910
7376
|
challenge: passwordChallenge,
|
|
@@ -4946,11 +7412,11 @@ var LoginPage = ({
|
|
|
4946
7412
|
if (phoneMethod) {
|
|
4947
7413
|
items.push({
|
|
4948
7414
|
key: "phone_code",
|
|
4949
|
-
label: /* @__PURE__ */
|
|
4950
|
-
/* @__PURE__ */
|
|
4951
|
-
/* @__PURE__ */
|
|
7415
|
+
label: /* @__PURE__ */ jsxs12(Space3, { size: 6, children: [
|
|
7416
|
+
/* @__PURE__ */ jsx14(MobileOutlined, {}),
|
|
7417
|
+
/* @__PURE__ */ jsx14("span", { children: phoneMethod.label || "\u624B\u673A\u53F7" })
|
|
4952
7418
|
] }),
|
|
4953
|
-
children: /* @__PURE__ */
|
|
7419
|
+
children: /* @__PURE__ */ jsx14(
|
|
4954
7420
|
PhoneCodeLoginForm,
|
|
4955
7421
|
{
|
|
4956
7422
|
allowRegister,
|
|
@@ -5014,7 +7480,7 @@ var LoginPage = ({
|
|
|
5014
7480
|
sendingCode,
|
|
5015
7481
|
submitting
|
|
5016
7482
|
]);
|
|
5017
|
-
|
|
7483
|
+
useEffect11(() => {
|
|
5018
7484
|
const firstKey = tabItems[0]?.key;
|
|
5019
7485
|
if (firstKey && !tabItems.some((item) => item.key === activeMethod)) {
|
|
5020
7486
|
setActiveMethod(firstKey);
|
|
@@ -5089,7 +7555,7 @@ var LoginPage = ({
|
|
|
5089
7555
|
);
|
|
5090
7556
|
}
|
|
5091
7557
|
}
|
|
5092
|
-
return /* @__PURE__ */
|
|
7558
|
+
return /* @__PURE__ */ jsx14(
|
|
5093
7559
|
"div",
|
|
5094
7560
|
{
|
|
5095
7561
|
className,
|
|
@@ -5101,7 +7567,7 @@ var LoginPage = ({
|
|
|
5101
7567
|
background: "#f6f8fb",
|
|
5102
7568
|
...style
|
|
5103
7569
|
},
|
|
5104
|
-
children: /* @__PURE__ */
|
|
7570
|
+
children: /* @__PURE__ */ jsx14(
|
|
5105
7571
|
Card,
|
|
5106
7572
|
{
|
|
5107
7573
|
style: {
|
|
@@ -5110,54 +7576,54 @@ var LoginPage = ({
|
|
|
5110
7576
|
boxShadow: "0 16px 48px rgba(15, 23, 42, 0.10)"
|
|
5111
7577
|
},
|
|
5112
7578
|
styles: { body: { padding: 28 } },
|
|
5113
|
-
children: /* @__PURE__ */
|
|
5114
|
-
/* @__PURE__ */
|
|
5115
|
-
/* @__PURE__ */
|
|
5116
|
-
subtitle ? /* @__PURE__ */
|
|
7579
|
+
children: /* @__PURE__ */ jsxs12(Space3, { direction: "vertical", size: 20, style: { width: "100%" }, children: [
|
|
7580
|
+
/* @__PURE__ */ jsxs12("div", { children: [
|
|
7581
|
+
/* @__PURE__ */ jsx14(Typography5.Title, { level: 3, style: { margin: 0 }, children: title || "\u5E94\u7528\u767B\u5F55" }),
|
|
7582
|
+
subtitle ? /* @__PURE__ */ jsx14(Typography5.Text, { type: "secondary", children: subtitle }) : null
|
|
5117
7583
|
] }),
|
|
5118
|
-
methodsState.error ? /* @__PURE__ */
|
|
5119
|
-
|
|
7584
|
+
methodsState.error ? /* @__PURE__ */ jsx14(
|
|
7585
|
+
Alert4,
|
|
5120
7586
|
{
|
|
5121
7587
|
showIcon: true,
|
|
5122
7588
|
type: "error",
|
|
5123
7589
|
message: methodsState.error.message
|
|
5124
7590
|
}
|
|
5125
7591
|
) : null,
|
|
5126
|
-
error ? /* @__PURE__ */
|
|
5127
|
-
methodsState.loading ? /* @__PURE__ */
|
|
5128
|
-
|
|
7592
|
+
error ? /* @__PURE__ */ jsx14(Alert4, { showIcon: true, type: "error", message: error }) : null,
|
|
7593
|
+
methodsState.loading ? /* @__PURE__ */ jsx14(Button8, { block: true, loading: true, children: "\u52A0\u8F7D\u4E2D" }) : tabItems.length > 0 ? /* @__PURE__ */ jsx14(
|
|
7594
|
+
Tabs2,
|
|
5129
7595
|
{
|
|
5130
7596
|
activeKey: activeMethod,
|
|
5131
7597
|
items: tabItems,
|
|
5132
7598
|
onChange: setActiveMethod
|
|
5133
7599
|
}
|
|
5134
|
-
) : /* @__PURE__ */
|
|
5135
|
-
/* @__PURE__ */
|
|
5136
|
-
dingtalkMethod ? /* @__PURE__ */
|
|
5137
|
-
|
|
7600
|
+
) : /* @__PURE__ */ jsx14(Empty6, { description: "\u672A\u542F\u7528\u767B\u5F55\u65B9\u5F0F" }),
|
|
7601
|
+
/* @__PURE__ */ jsxs12(Space3, { direction: "vertical", size: 10, style: { width: "100%" }, children: [
|
|
7602
|
+
dingtalkMethod ? /* @__PURE__ */ jsx14(
|
|
7603
|
+
Button8,
|
|
5138
7604
|
{
|
|
5139
7605
|
block: true,
|
|
5140
|
-
icon: /* @__PURE__ */
|
|
7606
|
+
icon: /* @__PURE__ */ jsx14(QrcodeOutlined, {}),
|
|
5141
7607
|
loading: submitting,
|
|
5142
7608
|
onClick: handleDingTalkLogin,
|
|
5143
7609
|
children: dingtalkMethod.label || "\u9489\u9489\u514D\u767B"
|
|
5144
7610
|
}
|
|
5145
7611
|
) : null,
|
|
5146
|
-
ssoMethod ? /* @__PURE__ */
|
|
5147
|
-
|
|
7612
|
+
ssoMethod ? /* @__PURE__ */ jsx14(
|
|
7613
|
+
Button8,
|
|
5148
7614
|
{
|
|
5149
7615
|
block: true,
|
|
5150
|
-
icon: /* @__PURE__ */
|
|
7616
|
+
icon: /* @__PURE__ */ jsx14(SafetyCertificateOutlined, {}),
|
|
5151
7617
|
loading: submitting,
|
|
5152
7618
|
onClick: handleSsoLogin,
|
|
5153
7619
|
children: ssoMethod.label || "SSO \u767B\u5F55"
|
|
5154
7620
|
}
|
|
5155
7621
|
) : null,
|
|
5156
|
-
guestMethod ? /* @__PURE__ */
|
|
5157
|
-
|
|
7622
|
+
guestMethod ? /* @__PURE__ */ jsx14(
|
|
7623
|
+
Button8,
|
|
5158
7624
|
{
|
|
5159
7625
|
block: true,
|
|
5160
|
-
icon: /* @__PURE__ */
|
|
7626
|
+
icon: /* @__PURE__ */ jsx14(LoginOutlined, {}),
|
|
5161
7627
|
loading: submitting,
|
|
5162
7628
|
onClick: handleGuestLogin,
|
|
5163
7629
|
children: guestMethod.label || "\u8BBF\u5BA2\u8BBF\u95EE"
|
|
@@ -5170,28 +7636,28 @@ var LoginPage = ({
|
|
|
5170
7636
|
}
|
|
5171
7637
|
);
|
|
5172
7638
|
};
|
|
5173
|
-
var PasswordLoginForm = ({ challenge, form, loading, onFinish }) => /* @__PURE__ */
|
|
5174
|
-
/* @__PURE__ */
|
|
7639
|
+
var PasswordLoginForm = ({ challenge, form, loading, onFinish }) => /* @__PURE__ */ jsxs12(Form2, { form, layout: "vertical", requiredMark: false, onFinish, children: [
|
|
7640
|
+
/* @__PURE__ */ jsx14(
|
|
5175
7641
|
Form2.Item,
|
|
5176
7642
|
{
|
|
5177
7643
|
label: "\u8D26\u53F7",
|
|
5178
7644
|
name: "username",
|
|
5179
7645
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u8D26\u53F7" }],
|
|
5180
|
-
children: /* @__PURE__ */
|
|
7646
|
+
children: /* @__PURE__ */ jsx14(Input3, { autoComplete: "username" })
|
|
5181
7647
|
}
|
|
5182
7648
|
),
|
|
5183
|
-
/* @__PURE__ */
|
|
7649
|
+
/* @__PURE__ */ jsx14(
|
|
5184
7650
|
Form2.Item,
|
|
5185
7651
|
{
|
|
5186
7652
|
label: "\u5BC6\u7801",
|
|
5187
7653
|
name: "password",
|
|
5188
7654
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u5BC6\u7801" }],
|
|
5189
|
-
children: /* @__PURE__ */
|
|
7655
|
+
children: /* @__PURE__ */ jsx14(Input3.Password, { autoComplete: "current-password" })
|
|
5190
7656
|
}
|
|
5191
7657
|
),
|
|
5192
|
-
challenge ? /* @__PURE__ */
|
|
5193
|
-
/* @__PURE__ */
|
|
5194
|
-
|
|
7658
|
+
challenge ? /* @__PURE__ */ jsxs12(Fragment5, { children: [
|
|
7659
|
+
/* @__PURE__ */ jsx14(
|
|
7660
|
+
Alert4,
|
|
5195
7661
|
{
|
|
5196
7662
|
showIcon: true,
|
|
5197
7663
|
type: "warning",
|
|
@@ -5199,17 +7665,17 @@ var PasswordLoginForm = ({ challenge, form, loading, onFinish }) => /* @__PURE__
|
|
|
5199
7665
|
description: readChallengeQuestion(challenge) || "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801\u540E\u7EE7\u7EED\u767B\u5F55\u3002"
|
|
5200
7666
|
}
|
|
5201
7667
|
),
|
|
5202
|
-
/* @__PURE__ */
|
|
7668
|
+
/* @__PURE__ */ jsx14(
|
|
5203
7669
|
Form2.Item,
|
|
5204
7670
|
{
|
|
5205
7671
|
label: "\u9A8C\u8BC1\u7B54\u6848",
|
|
5206
7672
|
name: "challengeAnswer",
|
|
5207
7673
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7B54\u6848" }],
|
|
5208
|
-
children: /* @__PURE__ */
|
|
7674
|
+
children: /* @__PURE__ */ jsx14(Input3, { autoComplete: "one-time-code" })
|
|
5209
7675
|
}
|
|
5210
7676
|
)
|
|
5211
7677
|
] }) : null,
|
|
5212
|
-
/* @__PURE__ */
|
|
7678
|
+
/* @__PURE__ */ jsx14(Button8, { block: true, htmlType: "submit", icon: /* @__PURE__ */ jsx14(LoginOutlined, {}), loading, type: "primary", children: "\u767B\u5F55" })
|
|
5213
7679
|
] });
|
|
5214
7680
|
var PhoneCodeLoginForm = ({
|
|
5215
7681
|
allowRegister,
|
|
@@ -5220,9 +7686,9 @@ var PhoneCodeLoginForm = ({
|
|
|
5220
7686
|
onPurposeChange,
|
|
5221
7687
|
onSendCode,
|
|
5222
7688
|
onFinish
|
|
5223
|
-
}) => /* @__PURE__ */
|
|
5224
|
-
allowRegister ? /* @__PURE__ */
|
|
5225
|
-
|
|
7689
|
+
}) => /* @__PURE__ */ jsxs12(Form2, { form, layout: "vertical", requiredMark: false, onFinish, children: [
|
|
7690
|
+
allowRegister ? /* @__PURE__ */ jsx14(Form2.Item, { style: { marginBottom: 12 }, children: /* @__PURE__ */ jsx14(
|
|
7691
|
+
Tabs2,
|
|
5226
7692
|
{
|
|
5227
7693
|
activeKey: phonePurpose,
|
|
5228
7694
|
items: [
|
|
@@ -5233,26 +7699,26 @@ var PhoneCodeLoginForm = ({
|
|
|
5233
7699
|
size: "small"
|
|
5234
7700
|
}
|
|
5235
7701
|
) }) : null,
|
|
5236
|
-
/* @__PURE__ */
|
|
7702
|
+
/* @__PURE__ */ jsx14(
|
|
5237
7703
|
Form2.Item,
|
|
5238
7704
|
{
|
|
5239
7705
|
label: "\u624B\u673A\u53F7",
|
|
5240
7706
|
name: "phone",
|
|
5241
7707
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u624B\u673A\u53F7" }],
|
|
5242
|
-
children: /* @__PURE__ */
|
|
7708
|
+
children: /* @__PURE__ */ jsx14(Input3, { autoComplete: "tel" })
|
|
5243
7709
|
}
|
|
5244
7710
|
),
|
|
5245
|
-
/* @__PURE__ */
|
|
7711
|
+
/* @__PURE__ */ jsx14(
|
|
5246
7712
|
Form2.Item,
|
|
5247
7713
|
{
|
|
5248
7714
|
label: "\u9A8C\u8BC1\u7801",
|
|
5249
7715
|
name: "code",
|
|
5250
7716
|
rules: [{ required: true, message: "\u8BF7\u8F93\u5165\u9A8C\u8BC1\u7801" }],
|
|
5251
|
-
children: /* @__PURE__ */
|
|
7717
|
+
children: /* @__PURE__ */ jsx14(
|
|
5252
7718
|
Input3,
|
|
5253
7719
|
{
|
|
5254
|
-
addonAfter: /* @__PURE__ */
|
|
5255
|
-
|
|
7720
|
+
addonAfter: /* @__PURE__ */ jsx14(
|
|
7721
|
+
Button8,
|
|
5256
7722
|
{
|
|
5257
7723
|
loading: sendingCode,
|
|
5258
7724
|
onClick: onSendCode,
|
|
@@ -5266,7 +7732,7 @@ var PhoneCodeLoginForm = ({
|
|
|
5266
7732
|
)
|
|
5267
7733
|
}
|
|
5268
7734
|
),
|
|
5269
|
-
/* @__PURE__ */
|
|
7735
|
+
/* @__PURE__ */ jsx14(Button8, { block: true, htmlType: "submit", icon: /* @__PURE__ */ jsx14(MobileOutlined, {}), loading, type: "primary", children: phonePurpose === "register" ? "\u6CE8\u518C" : "\u767B\u5F55" })
|
|
5270
7736
|
] });
|
|
5271
7737
|
var findMethod = (methods, type) => methods.find((method) => method.type === type);
|
|
5272
7738
|
var normalizeError = (error) => error instanceof Error ? error : new Error(String(error || "\u8BF7\u6C42\u5931\u8D25"));
|
|
@@ -5343,7 +7809,7 @@ var getCallbackUrl = () => {
|
|
|
5343
7809
|
};
|
|
5344
7810
|
|
|
5345
7811
|
// packages/sdk/src/runtime/react/openxiangdaProvider.tsx
|
|
5346
|
-
import { Fragment as
|
|
7812
|
+
import { Fragment as Fragment6, jsx as jsx15 } from "react/jsx-runtime";
|
|
5347
7813
|
var RuntimeHttpError = class extends Error {
|
|
5348
7814
|
constructor(snapshot) {
|
|
5349
7815
|
super(snapshot.message);
|
|
@@ -5361,19 +7827,19 @@ var OpenXiangdaProvider = ({
|
|
|
5361
7827
|
fetchImpl,
|
|
5362
7828
|
children
|
|
5363
7829
|
}) => {
|
|
5364
|
-
const resolvedFetch =
|
|
5365
|
-
const resolvedAppType =
|
|
7830
|
+
const resolvedFetch = useMemo14(() => createBoundFetch(fetchImpl), [fetchImpl]);
|
|
7831
|
+
const resolvedAppType = useMemo14(
|
|
5366
7832
|
() => appType || resolveAppTypeFromLocation(),
|
|
5367
7833
|
[appType]
|
|
5368
7834
|
);
|
|
5369
|
-
const [, setAccessTokenState] =
|
|
5370
|
-
const [authState, setAuthState] =
|
|
7835
|
+
const [, setAccessTokenState] = useState13(null);
|
|
7836
|
+
const [authState, setAuthState] = useState13({
|
|
5371
7837
|
status: "unknown",
|
|
5372
7838
|
error: null
|
|
5373
7839
|
});
|
|
5374
|
-
const accessTokenRef =
|
|
5375
|
-
const refreshRequestRef =
|
|
5376
|
-
const applyAccessToken =
|
|
7840
|
+
const accessTokenRef = useRef6(null);
|
|
7841
|
+
const refreshRequestRef = useRef6(null);
|
|
7842
|
+
const applyAccessToken = useCallback10(
|
|
5377
7843
|
(nextAccessToken, options = {}) => {
|
|
5378
7844
|
if (!nextAccessToken && options.clearIfToken && accessTokenRef.current?.token !== options.clearIfToken) {
|
|
5379
7845
|
return accessTokenRef.current;
|
|
@@ -5391,7 +7857,7 @@ var OpenXiangdaProvider = ({
|
|
|
5391
7857
|
},
|
|
5392
7858
|
[]
|
|
5393
7859
|
);
|
|
5394
|
-
const setAccessToken =
|
|
7860
|
+
const setAccessToken = useCallback10(
|
|
5395
7861
|
(nextAccessToken, options = {}) => {
|
|
5396
7862
|
const previousState = accessTokenRef.current;
|
|
5397
7863
|
const nextState = applyAccessToken(nextAccessToken, options);
|
|
@@ -5407,7 +7873,7 @@ var OpenXiangdaProvider = ({
|
|
|
5407
7873
|
},
|
|
5408
7874
|
[applyAccessToken]
|
|
5409
7875
|
);
|
|
5410
|
-
const markUnauthenticated =
|
|
7876
|
+
const markUnauthenticated = useCallback10(
|
|
5411
7877
|
(error) => {
|
|
5412
7878
|
const runtimeError = normalizeRuntimeError(error);
|
|
5413
7879
|
applyAccessToken(null);
|
|
@@ -5415,7 +7881,7 @@ var OpenXiangdaProvider = ({
|
|
|
5415
7881
|
},
|
|
5416
7882
|
[applyAccessToken]
|
|
5417
7883
|
);
|
|
5418
|
-
const refreshAccessToken =
|
|
7884
|
+
const refreshAccessToken = useCallback10(async () => {
|
|
5419
7885
|
if (!resolvedAppType) return null;
|
|
5420
7886
|
if (!refreshRequestRef.current) {
|
|
5421
7887
|
setAuthState((prev) => ({ ...prev, status: "refreshing", error: null }));
|
|
@@ -5476,7 +7942,7 @@ var OpenXiangdaProvider = ({
|
|
|
5476
7942
|
}
|
|
5477
7943
|
return refreshRequestRef.current;
|
|
5478
7944
|
}, [applyAccessToken, resolvedAppType, resolvedFetch, servicePrefix]);
|
|
5479
|
-
const authorizedFetch =
|
|
7945
|
+
const authorizedFetch = useMemo14(
|
|
5480
7946
|
() => createAuthorizedFetch({
|
|
5481
7947
|
appType: resolvedAppType,
|
|
5482
7948
|
baseFetch: resolvedFetch,
|
|
@@ -5486,18 +7952,18 @@ var OpenXiangdaProvider = ({
|
|
|
5486
7952
|
}),
|
|
5487
7953
|
[markUnauthenticated, refreshAccessToken, resolvedAppType, resolvedFetch]
|
|
5488
7954
|
);
|
|
5489
|
-
const getAuthHeaders =
|
|
7955
|
+
const getAuthHeaders = useCallback10(() => {
|
|
5490
7956
|
const state2 = accessTokenRef.current;
|
|
5491
7957
|
if (!state2) return {};
|
|
5492
7958
|
const token = resolveAccessTokenForCurrentRoute(state2);
|
|
5493
7959
|
return token ? { authorization: `Bearer ${token}` } : {};
|
|
5494
7960
|
}, []);
|
|
5495
|
-
const [state, setState] =
|
|
7961
|
+
const [state, setState] = useState13({
|
|
5496
7962
|
data: null,
|
|
5497
7963
|
loading: true,
|
|
5498
7964
|
error: null
|
|
5499
7965
|
});
|
|
5500
|
-
const reload =
|
|
7966
|
+
const reload = useCallback10(async (options = {}) => {
|
|
5501
7967
|
if (!resolvedAppType) {
|
|
5502
7968
|
setState({
|
|
5503
7969
|
data: null,
|
|
@@ -5561,10 +8027,10 @@ var OpenXiangdaProvider = ({
|
|
|
5561
8027
|
}
|
|
5562
8028
|
}
|
|
5563
8029
|
}, [authorizedFetch, resolvedAppType, resolvedFetch, servicePrefix]);
|
|
5564
|
-
|
|
8030
|
+
useEffect12(() => {
|
|
5565
8031
|
void reload();
|
|
5566
8032
|
}, [reload]);
|
|
5567
|
-
const value =
|
|
8033
|
+
const value = useMemo14(
|
|
5568
8034
|
() => ({
|
|
5569
8035
|
...state,
|
|
5570
8036
|
appType: resolvedAppType,
|
|
@@ -5587,7 +8053,7 @@ var OpenXiangdaProvider = ({
|
|
|
5587
8053
|
authState
|
|
5588
8054
|
]
|
|
5589
8055
|
);
|
|
5590
|
-
return /* @__PURE__ */
|
|
8056
|
+
return /* @__PURE__ */ jsx15(OpenXiangdaRuntimeContext.Provider, { value, children });
|
|
5591
8057
|
};
|
|
5592
8058
|
var useOpenXiangda = () => {
|
|
5593
8059
|
const context = useContext2(OpenXiangdaRuntimeContext);
|
|
@@ -5607,7 +8073,7 @@ var OpenXiangdaPageProvider = ({
|
|
|
5607
8073
|
navigation
|
|
5608
8074
|
}) => {
|
|
5609
8075
|
const runtime = useOpenXiangda();
|
|
5610
|
-
const context =
|
|
8076
|
+
const context = useMemo14(() => {
|
|
5611
8077
|
const bootstrap = runtime.data;
|
|
5612
8078
|
const app = toRuntimeRecord(bootstrap?.app);
|
|
5613
8079
|
const user = toRuntimeRecord(bootstrap?.user);
|
|
@@ -5687,7 +8153,7 @@ var OpenXiangdaPageProvider = ({
|
|
|
5687
8153
|
runtime.fetchImpl,
|
|
5688
8154
|
runtime.servicePrefix
|
|
5689
8155
|
]);
|
|
5690
|
-
return /* @__PURE__ */
|
|
8156
|
+
return /* @__PURE__ */ jsx15(PageProvider, { context, children });
|
|
5691
8157
|
};
|
|
5692
8158
|
var useAppMenus = () => {
|
|
5693
8159
|
const runtime = useOpenXiangda();
|
|
@@ -5705,12 +8171,12 @@ var usePermission = () => {
|
|
|
5705
8171
|
};
|
|
5706
8172
|
var useCanAccessRoute = (input) => {
|
|
5707
8173
|
const runtime = useOpenXiangda();
|
|
5708
|
-
const [state, setState] =
|
|
8174
|
+
const [state, setState] = useState13({
|
|
5709
8175
|
data: null,
|
|
5710
8176
|
loading: true,
|
|
5711
8177
|
error: null
|
|
5712
8178
|
});
|
|
5713
|
-
|
|
8179
|
+
useEffect12(() => {
|
|
5714
8180
|
let disposed = false;
|
|
5715
8181
|
const check = async () => {
|
|
5716
8182
|
const permissions = runtime.data?.permissions;
|
|
@@ -5832,16 +8298,16 @@ var PermissionBoundary = ({
|
|
|
5832
8298
|
const access = useCanAccessRoute({ routeCode, menuCode, path });
|
|
5833
8299
|
const fallbackState = createPermissionFallbackState(access, runtime);
|
|
5834
8300
|
if (access.loading) {
|
|
5835
|
-
return /* @__PURE__ */
|
|
8301
|
+
return /* @__PURE__ */ jsx15(Fragment6, { children: renderBoundaryFallback(loadingFallback, fallbackState) });
|
|
5836
8302
|
}
|
|
5837
8303
|
if (!access.canAccess) {
|
|
5838
|
-
return /* @__PURE__ */
|
|
8304
|
+
return /* @__PURE__ */ jsx15(Fragment6, { children: renderBoundaryFallback(fallback, fallbackState) });
|
|
5839
8305
|
}
|
|
5840
|
-
return /* @__PURE__ */
|
|
8306
|
+
return /* @__PURE__ */ jsx15(Fragment6, { children });
|
|
5841
8307
|
};
|
|
5842
8308
|
var useRuntimeAuth = () => {
|
|
5843
8309
|
const runtime = useOpenXiangda();
|
|
5844
|
-
const resolveLoginUrl2 =
|
|
8310
|
+
const resolveLoginUrl2 = useCallback10(
|
|
5845
8311
|
async (options = {}) => {
|
|
5846
8312
|
const redirectUri = options.redirectUri || getCurrentHref4();
|
|
5847
8313
|
const domain = options.domain || getCurrentHostname2();
|
|
@@ -5888,7 +8354,7 @@ var useRuntimeAuth = () => {
|
|
|
5888
8354
|
},
|
|
5889
8355
|
[runtime.baseFetchImpl, runtime.data?.app, runtime.servicePrefix]
|
|
5890
8356
|
);
|
|
5891
|
-
const redirectToLogin =
|
|
8357
|
+
const redirectToLogin = useCallback10(
|
|
5892
8358
|
async (options = {}) => {
|
|
5893
8359
|
const loginUrl = await resolveLoginUrl2(options);
|
|
5894
8360
|
if (typeof window !== "undefined") {
|
|
@@ -5902,7 +8368,7 @@ var useRuntimeAuth = () => {
|
|
|
5902
8368
|
},
|
|
5903
8369
|
[resolveLoginUrl2]
|
|
5904
8370
|
);
|
|
5905
|
-
const logout =
|
|
8371
|
+
const logout = useCallback10(async () => {
|
|
5906
8372
|
const response = await runtime.baseFetchImpl(
|
|
5907
8373
|
buildServiceUrl2(runtime.servicePrefix, "/api/auth/logout"),
|
|
5908
8374
|
{
|
|
@@ -5922,7 +8388,7 @@ var useRuntimeAuth = () => {
|
|
|
5922
8388
|
runtime.setAccessToken(null);
|
|
5923
8389
|
return payload;
|
|
5924
8390
|
}, [runtime.baseFetchImpl, runtime.servicePrefix, runtime.setAccessToken]);
|
|
5925
|
-
const logoutAndRedirect =
|
|
8391
|
+
const logoutAndRedirect = useCallback10(
|
|
5926
8392
|
async (options = {}) => {
|
|
5927
8393
|
try {
|
|
5928
8394
|
await logout();
|
|
@@ -5933,7 +8399,7 @@ var useRuntimeAuth = () => {
|
|
|
5933
8399
|
},
|
|
5934
8400
|
[logout, redirectToLogin]
|
|
5935
8401
|
);
|
|
5936
|
-
return
|
|
8402
|
+
return useMemo14(
|
|
5937
8403
|
() => ({
|
|
5938
8404
|
logout,
|
|
5939
8405
|
logoutAndRedirect,
|
|
@@ -5952,7 +8418,7 @@ var RuntimeAuthGuard = ({
|
|
|
5952
8418
|
}) => {
|
|
5953
8419
|
const runtime = useOpenXiangda();
|
|
5954
8420
|
const auth = useRuntimeAuth();
|
|
5955
|
-
const redirectedRef =
|
|
8421
|
+
const redirectedRef = useRef6(false);
|
|
5956
8422
|
const currentPath = getCurrentPathname();
|
|
5957
8423
|
const excluded = isRuntimeAuthGuardExcluded(
|
|
5958
8424
|
currentPath,
|
|
@@ -5960,7 +8426,7 @@ var RuntimeAuthGuard = ({
|
|
|
5960
8426
|
excludedPaths
|
|
5961
8427
|
);
|
|
5962
8428
|
const shouldRedirect = !disabled && !excluded && !runtime.loading && (runtime.authState.status === "unauthenticated" || runtime.error?.type === "unauthenticated");
|
|
5963
|
-
|
|
8429
|
+
useEffect12(() => {
|
|
5964
8430
|
if (!shouldRedirect || redirectedRef.current) return;
|
|
5965
8431
|
redirectedRef.current = true;
|
|
5966
8432
|
void auth.redirectToLogin({
|
|
@@ -5977,9 +8443,9 @@ var RuntimeAuthGuard = ({
|
|
|
5977
8443
|
redirectOptions.replace,
|
|
5978
8444
|
shouldRedirect
|
|
5979
8445
|
]);
|
|
5980
|
-
if (excluded) return /* @__PURE__ */
|
|
5981
|
-
if (shouldRedirect) return /* @__PURE__ */
|
|
5982
|
-
return /* @__PURE__ */
|
|
8446
|
+
if (excluded) return /* @__PURE__ */ jsx15(Fragment6, { children });
|
|
8447
|
+
if (shouldRedirect) return /* @__PURE__ */ jsx15(Fragment6, { children: fallback });
|
|
8448
|
+
return /* @__PURE__ */ jsx15(Fragment6, { children });
|
|
5983
8449
|
};
|
|
5984
8450
|
var buildServiceUrl2 = (servicePrefix, path) => {
|
|
5985
8451
|
const prefix = servicePrefix.endsWith("/") ? servicePrefix.slice(0, -1) : servicePrefix;
|
|
@@ -6250,7 +8716,7 @@ var buildBrowserRouteInfo = (route) => {
|
|
|
6250
8716
|
hash
|
|
6251
8717
|
};
|
|
6252
8718
|
};
|
|
6253
|
-
var
|
|
8719
|
+
var isSuccessCode6 = (code) => {
|
|
6254
8720
|
if (code === void 0 || code === null || code === "") return true;
|
|
6255
8721
|
const normalized = Number(code);
|
|
6256
8722
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -6258,7 +8724,7 @@ var isSuccessCode5 = (code) => {
|
|
|
6258
8724
|
var isRuntimeEnvelopeFailure = (response, payload) => {
|
|
6259
8725
|
const code = getRecordValue2(payload, "code");
|
|
6260
8726
|
const success = getRecordValue2(payload, "success");
|
|
6261
|
-
return !response.ok || success === false || !
|
|
8727
|
+
return !response.ok || success === false || !isSuccessCode6(code);
|
|
6262
8728
|
};
|
|
6263
8729
|
var isServerErrorCode = (code) => {
|
|
6264
8730
|
const normalized = Number(code);
|
|
@@ -6303,7 +8769,7 @@ var resolveAppTypeFromLocation = () => {
|
|
|
6303
8769
|
};
|
|
6304
8770
|
|
|
6305
8771
|
// packages/sdk/src/runtime/react/publicAccess.tsx
|
|
6306
|
-
import { useCallback as
|
|
8772
|
+
import { useCallback as useCallback11, useEffect as useEffect13, useMemo as useMemo15, useRef as useRef7, useState as useState14 } from "react";
|
|
6307
8773
|
|
|
6308
8774
|
// packages/sdk/src/runtime/core/publicAccess.ts
|
|
6309
8775
|
var PublicAccessClientError = class extends Error {
|
|
@@ -6353,7 +8819,7 @@ var createPublicAccessClient = ({
|
|
|
6353
8819
|
const payload = await readPayload2(response);
|
|
6354
8820
|
const code = getRecordValue3(payload, "code");
|
|
6355
8821
|
const success = getRecordValue3(payload, "success");
|
|
6356
|
-
if (!response.ok || success === false || !
|
|
8822
|
+
if (!response.ok || success === false || !isSuccessCode7(code)) {
|
|
6357
8823
|
throw new PublicAccessClientError(
|
|
6358
8824
|
String(
|
|
6359
8825
|
getRecordValue3(payload, "message") || `Public access session failed: ${response.status}`
|
|
@@ -6391,7 +8857,7 @@ var getRecordValue3 = (value, key) => {
|
|
|
6391
8857
|
if (!value || typeof value !== "object") return void 0;
|
|
6392
8858
|
return value[key];
|
|
6393
8859
|
};
|
|
6394
|
-
var
|
|
8860
|
+
var isSuccessCode7 = (code) => {
|
|
6395
8861
|
if (code === void 0 || code === null || code === "") return true;
|
|
6396
8862
|
const normalized = Number(code);
|
|
6397
8863
|
return Number.isFinite(normalized) ? normalized === 0 || normalized >= 200 && normalized < 300 : false;
|
|
@@ -6419,7 +8885,7 @@ var createRandomIdentifier = (appType) => {
|
|
|
6419
8885
|
};
|
|
6420
8886
|
|
|
6421
8887
|
// packages/sdk/src/runtime/react/publicAccess.tsx
|
|
6422
|
-
import { Fragment as
|
|
8888
|
+
import { Fragment as Fragment7, jsx as jsx16 } from "react/jsx-runtime";
|
|
6423
8889
|
var usePublicAccess = (options = {}) => {
|
|
6424
8890
|
const runtime = useOpenXiangda();
|
|
6425
8891
|
const {
|
|
@@ -6436,14 +8902,14 @@ var usePublicAccess = (options = {}) => {
|
|
|
6436
8902
|
autoStart = true,
|
|
6437
8903
|
...sessionInput
|
|
6438
8904
|
} = options;
|
|
6439
|
-
const [session, setSession] =
|
|
6440
|
-
const [error, setError] =
|
|
6441
|
-
const [loading, setLoading] =
|
|
6442
|
-
const activeSessionRef =
|
|
6443
|
-
const mountedRef =
|
|
8905
|
+
const [session, setSession] = useState14(null);
|
|
8906
|
+
const [error, setError] = useState14(null);
|
|
8907
|
+
const [loading, setLoading] = useState14(Boolean(autoStart));
|
|
8908
|
+
const activeSessionRef = useRef7(null);
|
|
8909
|
+
const mountedRef = useRef7(true);
|
|
6444
8910
|
const sessionInputKey = JSON.stringify(sessionInput);
|
|
6445
|
-
const stableSessionInput =
|
|
6446
|
-
const client =
|
|
8911
|
+
const stableSessionInput = useMemo15(() => sessionInput, [sessionInputKey]);
|
|
8912
|
+
const client = useMemo15(
|
|
6447
8913
|
() => createPublicAccessClient({
|
|
6448
8914
|
appType,
|
|
6449
8915
|
servicePrefix,
|
|
@@ -6451,7 +8917,7 @@ var usePublicAccess = (options = {}) => {
|
|
|
6451
8917
|
}),
|
|
6452
8918
|
[appType, fetchImpl, servicePrefix]
|
|
6453
8919
|
);
|
|
6454
|
-
const startSession =
|
|
8920
|
+
const startSession = useCallback11(
|
|
6455
8921
|
async (input = {}) => {
|
|
6456
8922
|
setLoading(true);
|
|
6457
8923
|
setError(null);
|
|
@@ -6497,11 +8963,11 @@ var usePublicAccess = (options = {}) => {
|
|
|
6497
8963
|
},
|
|
6498
8964
|
[client, reloadRuntime, setAccessToken, stableSessionInput]
|
|
6499
8965
|
);
|
|
6500
|
-
|
|
8966
|
+
useEffect13(() => {
|
|
6501
8967
|
if (!autoStart) return;
|
|
6502
8968
|
void startSession().catch(() => void 0);
|
|
6503
8969
|
}, [autoStart, startSession]);
|
|
6504
|
-
|
|
8970
|
+
useEffect13(
|
|
6505
8971
|
() => {
|
|
6506
8972
|
mountedRef.current = true;
|
|
6507
8973
|
return () => {
|
|
@@ -6530,11 +8996,11 @@ var PublicAccessGate = ({
|
|
|
6530
8996
|
...options
|
|
6531
8997
|
}) => {
|
|
6532
8998
|
const state = usePublicAccess(options);
|
|
6533
|
-
if (state.loading) return /* @__PURE__ */
|
|
8999
|
+
if (state.loading) return /* @__PURE__ */ jsx16(Fragment7, { children: fallback });
|
|
6534
9000
|
if (state.error) {
|
|
6535
|
-
return /* @__PURE__ */
|
|
9001
|
+
return /* @__PURE__ */ jsx16(Fragment7, { children: typeof errorFallback === "function" ? errorFallback(state.error) : errorFallback });
|
|
6536
9002
|
}
|
|
6537
|
-
return /* @__PURE__ */
|
|
9003
|
+
return /* @__PURE__ */ jsx16(Fragment7, { children });
|
|
6538
9004
|
};
|
|
6539
9005
|
var readTicketFromLocation = () => {
|
|
6540
9006
|
if (typeof window === "undefined") return void 0;
|
|
@@ -6542,7 +9008,9 @@ var readTicketFromLocation = () => {
|
|
|
6542
9008
|
};
|
|
6543
9009
|
var readPathFromLocation = () => typeof window === "undefined" ? void 0 : window.location.pathname;
|
|
6544
9010
|
export {
|
|
9011
|
+
AttachmentPreviewList,
|
|
6545
9012
|
AuthClientError,
|
|
9013
|
+
ImagePreviewGrid,
|
|
6546
9014
|
InitiatorApproverSelector,
|
|
6547
9015
|
LoginPage,
|
|
6548
9016
|
OpenXiangdaPageProvider,
|
|
@@ -6568,6 +9036,7 @@ export {
|
|
|
6568
9036
|
useCanAccessRoute,
|
|
6569
9037
|
useCurrentUser,
|
|
6570
9038
|
useDataSource,
|
|
9039
|
+
useFilePreview,
|
|
6571
9040
|
useFormViewPermissions,
|
|
6572
9041
|
useLoginMethods,
|
|
6573
9042
|
useMessage,
|