fix(admin): 兼容 HTTP 内网下 crypto.randomUUID 不可用

订单模板编辑页在非 secure context 白屏;统一经 createRandomUuid 降级生成会话与 operation_id。
This commit is contained in:
hugo committed 2026-09-08 15:24:57 +08:00
1 parent 5ce9221476
commit c7770c12d2
8 files changed
+88 -18

No files matched your search

@@ -11,6 +11,7 @@ import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { BusinessError } from '@/shared/api/client';
import { useMessage } from '@/shared/composables/useMessage';
import { createRandomUuid } from '@/shared/utils/id';
import {
approveOrderProfileTestSuite,
confirmOrderProfileBlindTestReviews,
@@ -36,7 +37,7 @@ const router = useRouter();
const message = useMessage();
const { t } = useI18n();
const profileId = Number(route.params.profileId);
const sessionId = String(route.query.editorSessionId || '').trim() || crypto.randomUUID();
const sessionId = String(route.query.editorSessionId || '').trim() || createRandomUuid();
const suite = ref<OrderProfileTestSuite | null>(null);
const availableSamples = ref<OrderProfileBlindTestAvailableSample[]>([]);
const selectedSampleKey = ref('');
@@ -11,6 +11,7 @@ import { useI18n } from 'vue-i18n';
import { ArrowLeft, ArrowRight, Check, FileText, Layers3, Sparkles } from 'lucide-vue-next';
import { BusinessError } from '@/shared/api/client';
import { useMessage } from '@/shared/composables/useMessage';
import { createRandomUuid } from '@/shared/utils/id';
import { getShippingOrderSchemaState } from '@/features/admin/api/shipping-order-schema.api';
import { completeOrderDocumentProfileWizard, getOrderProfileSampleTables, listOrderProfileSamples } from '@/features/admin/api/shipping-order-document-profile.api';
import type { OrderProfileSampleDocument } from '@/features/admin/types/shipping-order-document-profile.types';
@@ -33,7 +34,7 @@ const tables = ref<Array<{ table_id: string; page_no: number; row_count: number;
const identity = reactive<Identity>({ displayName: '', schemaId: 0 });
const documentId = ref(0);
const tableId = ref('');
const browserSessionId = crypto.randomUUID();
const browserSessionId = createRandomUuid();
let sampleRefreshTimer: ReturnType<typeof setTimeout> | null = null;
const publishedSchemas = computed(() => schemas.value.filter((item) => item.status === 'published'));
@@ -140,7 +141,7 @@ async function finish(enterEditor: boolean): Promise<void> {
document_id: documentId.value,
main_table_id: tableId.value,
browser_session_id: browserSessionId,
operation_id: crypto.randomUUID(),
operation_id: createRandomUuid(),
};
const profile = await completeOrderDocumentProfileWizard(payload);
message.success(t('admin.shippingOrderProfiles.created'));
@@ -21,6 +21,7 @@ import { onBeforeRouteLeave, useRoute, useRouter } from "vue-router";
import { useI18n } from "vue-i18n";
import { BusinessError } from "@/shared/api/client";
import { useMessage } from "@/shared/composables/useMessage";
import { createRandomUuid } from "@/shared/utils/id";
import { getShippingOrderSchemaState } from "@/features/admin/api/shipping-order-schema.api";
import {
authorizeOrderProfilePreviewPages,
@@ -218,7 +219,7 @@ const documentAnchorNotice = ref('');
const history = ref<OrderProfileCanvasRegion[][]>([]);
const future = ref<OrderProfileCanvasRegion[][]>([]);
const editLeaseToken = ref<string | null>(null);
const editorSessionId = String(route.query.editorSessionId || '').trim() || crypto.randomUUID();
const editorSessionId = String(route.query.editorSessionId || '').trim() || createRandomUuid();
const compactEditor = ref(false);
const saveState = ref<'saved' | 'saving' | 'failed' | 'readonly'>('saved');
@@ -1820,7 +1821,7 @@ const save = async (automatic = false) => {
expected_lock_version: existingProfile.lock_version,
browser_session_id: editorSessionId,
lease_token: editLeaseToken.value || '',
operation_id: crypto.randomUUID(),
operation_id: createRandomUuid(),
...(adapterPayload.splitRuleConfirmationTokens
? { split_rule_confirmation_tokens: adapterPayload.splitRuleConfirmationTokens }
: {}),
@@ -2139,7 +2140,7 @@ const decidePendingSuggestion = async (decision: 'accepted' | 'accepted_adjusted
await decideOrderDocumentProfileSuggestion(active.value.id, {
suggestion_id: item.id, suggestion_checksum: item.checksum, suggestion_summary: item.summary, decision,
adjustment_summary: adjustmentSummary,
browser_session_id: editorSessionId, lease_token: editLeaseToken.value, operation_id: crypto.randomUUID(),
browser_session_id: editorSessionId, lease_token: editLeaseToken.value, operation_id: createRandomUuid(),
});
if (decision !== 'rejected') {
checkpoint();
@@ -2758,7 +2759,7 @@ const restoreRegions = (profile: ShippingOrderDocumentProfile) => {
const acquireEditLease = async (profileId: number): Promise<void> => {
const lease = await acquireOrderDocumentProfileEditLease(profileId, {
browser_session_id: editorSessionId,
operation_id: crypto.randomUUID(),
operation_id: createRandomUuid(),
});
editLeaseToken.value = lease.lease_token;
startLeaseRenewal();
@@ -2774,7 +2775,7 @@ const renewEditLease = async (): Promise<void> => {
const lease = await renewOrderDocumentProfileEditLease(active.value.id, {
browser_session_id: editorSessionId,
lease_token: editLeaseToken.value,
operation_id: crypto.randomUUID(),
operation_id: createRandomUuid(),
});
editLeaseToken.value = lease.lease_token;
} catch (error) {
@@ -2961,7 +2962,7 @@ const recoverEditLease = async (confirmTakeover = false) => {
try {
const lease = await acquireOrderDocumentProfileEditLease(active.value.id, {
browser_session_id: editorSessionId,
operation_id: crypto.randomUUID(),
operation_id: createRandomUuid(),
confirm_takeover: confirmTakeover,
});
editLeaseToken.value = lease.lease_token;
@@ -3124,7 +3125,7 @@ onBeforeUnmount(() => {
void releaseOrderDocumentProfileEditLease(active.value.id, {
browser_session_id: editorSessionId,
lease_token: editLeaseToken.value,
operation_id: crypto.randomUUID(),
operation_id: createRandomUuid(),
});
}
});
@@ -10,6 +10,7 @@ import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { BusinessError } from '@/shared/api/client';
import { useMessage } from '@/shared/composables/useMessage';
import { createRandomUuid } from '@/shared/utils/id';
import {
acquireOrderDocumentProfileEditLease,
confirmOrderProfilePublishCheck,
@@ -31,7 +32,7 @@ const runs = ref<OrderProfileValidationRun[]>([]);
const report = ref<OrderProfilePublishCheckReport | null>(null);
const confirmed = ref<string[]>([]);
const busy = ref(false);
const sessionId = String(route.query.editorSessionId || '').trim() || crypto.randomUUID();
const sessionId = String(route.query.editorSessionId || '').trim() || createRandomUuid();
const leaseToken = ref('');
const validationRun = computed(() => runs.value.find((item) => item.run_type === 'current_sample' && item.status === 'passed') || null);
@@ -92,7 +93,7 @@ async function ensureLease(): Promise<boolean> {
try {
leaseToken.value = (await acquireOrderDocumentProfileEditLease(profileId, {
browser_session_id: sessionId,
operation_id: crypto.randomUUID(),
operation_id: createRandomUuid(),
})).lease_token;
return true;
} catch (error) {
@@ -121,7 +122,7 @@ async function createReport(): Promise<void> {
overlap_validation_run_id: overlapRun.value?.id,
browser_session_id: sessionId,
lease_token: leaseToken.value,
operation_id: crypto.randomUUID(),
operation_id: createRandomUuid(),
});
confirmed.value = [];
await loadRuns();
@@ -141,7 +142,7 @@ async function publish(): Promise<void> {
confirmed_warning_keys: confirmed.value,
browser_session_id: sessionId,
lease_token: leaseToken.value,
operation_id: crypto.randomUUID(),
operation_id: createRandomUuid(),
});
await router.replace({
name: 'AdminShippingOrderDocumentProfileVersionDetail',
@@ -11,6 +11,7 @@ import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { BusinessError } from '@/shared/api/client';
import { useMessage } from '@/shared/composables/useMessage';
import { createRandomUuid } from '@/shared/utils/id';
import { getShippingOrderSchemaVersion } from '@/features/admin/api/shipping-order-schema.api';
import {
acquireOrderDocumentProfileEditLease,
@@ -42,7 +43,7 @@ const leaseToken = ref('');
const profile = ref<ShippingOrderDocumentProfile | null>(null);
const sample = ref<OrderProfileBoundSample | null>(null);
const fieldNames = ref(new Map<string, string>());
const sessionId = String(route.query.editorSessionId || '').trim() || crypto.randomUUID();
const sessionId = String(route.query.editorSessionId || '').trim() || createRandomUuid();
const blindTestSuite = ref<OrderProfileTestSuite | null>(null);
const validationEvidence = computed<OrderProfileValidationEvidence | null>(() => {
const raw = sampleRun.value?.summary?.validation_evidence;
@@ -206,7 +207,7 @@ async function ensureLease(): Promise<boolean> {
if (leaseToken.value) return true;
try {
leaseToken.value = (await acquireOrderDocumentProfileEditLease(profileId, {
browser_session_id: sessionId, operation_id: crypto.randomUUID(),
browser_session_id: sessionId, operation_id: createRandomUuid(),
})).lease_token;
return true;
} catch (error) { report(error); return false; }
@@ -221,7 +222,7 @@ async function validateCurrentDraft(): Promise<void> {
}
executing.value = true;
try {
const payload = () => ({ browser_session_id: sessionId, lease_token: leaseToken.value, operation_id: crypto.randomUUID() });
const payload = () => ({ browser_session_id: sessionId, lease_token: leaseToken.value, operation_id: createRandomUuid() });
await runOrderProfileInstantCheck(profileId, payload());
await runOrderProfileCurrentSample(profileId, { ...payload(), sample_binding_id: sample.value.id });
await loadRuns();
@@ -10,6 +10,7 @@ import { computed, onMounted, ref, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { BusinessError } from '@/shared/api/client';
import { useMessage } from '@/shared/composables/useMessage';
import { createRandomUuid } from '@/shared/utils/id';
import {
previewOrderProfileSampleXfaSplitRules,
} from '@/features/admin/api/shipping-order-document-profile.api';
@@ -97,9 +98,10 @@ const showUnsavedConfirmBanner = computed(() => (
/**
* 生成 seg-/rule-/stage- 前缀的客户端 UUID(无连字符)。
* HTTP 非安全上下文亦可用(经 createRandomUuid 降级)。
*/
function newClientId(prefix: 'seg' | 'rule' | 'stage'): string {
return `${prefix}-${crypto.randomUUID().replace(/-/g, '')}`;
return `${prefix}-${createRandomUuid().replace(/-/g, '')}`;
}
/**