Merge branch 'dev' into order-delivery-reply
# Conflicts: # .env.shared # backend/app/api/chat.py # backend/app/core/config/settings.py # backend/app/models/user.py # backend/app/services/admin/permission_service.py # docs/demand.md # frontend/src/app/router/routes/workspace.routes.ts # frontend/src/features/admin/modules/users/components/UserFormModal.vue # frontend/src/features/admin/modules/users/composables/useUsersAdmin.ts # frontend/src/features/admin/types/user.types.ts # frontend/src/features/auth/stores/auth.store.ts # frontend/src/features/user/views/UserProfilePage.vue # frontend/src/locales/en/admin.json # frontend/src/locales/en/errors.json # frontend/src/locales/th/admin.json # frontend/src/locales/th/errors.json # frontend/src/locales/zh-CN/admin.json # frontend/src/locales/zh-CN/errors.json # frontend/src/locales/zh-TW/admin.json # frontend/src/locales/zh-TW/errors.json # frontend/src/shared/utils/auth.ts
This commit is contained in:
commit
616034a4cd
541 files changed
+43805
-14767
No files matched your search
+135
-120
@@ -129,88 +129,44 @@
|
||||
<label><span>{{ t('admin.shippingInventory.warehouseResolution') }}</span><select v-model="source.warehouse_resolution_mode" class="select-field"><option value="fixed">{{ t('admin.shippingInventory.fixedWarehouse') }}</option><option value="inventory_match">{{ t('admin.shippingInventory.inventoryMatch') }}</option></select></label>
|
||||
<label v-if="source.warehouse_resolution_mode === 'fixed'"><span>{{ t('admin.shippingInventory.warehouse') }}</span><input v-model="source.fixed_warehouse_id" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.snapshotTtl') }}</span><input v-model.number="source.snapshot_ttl_seconds" class="input-field" min="1" type="number" required></label>
|
||||
<section v-if="selectedId" class="readiness-card full" :class="{ ready: source.enabled }">
|
||||
<header class="readiness-heading">
|
||||
<div>
|
||||
<span class="readiness-kicker">{{ t('admin.shippingInventory.activationStatus') }}</span>
|
||||
<strong>{{ readinessHeadline }}</strong>
|
||||
<p>{{ readinessGuidance }}</p>
|
||||
</div>
|
||||
<span class="readiness-count">{{ readinessSummary }}</span>
|
||||
</header>
|
||||
<section class="readiness-section">
|
||||
<div class="readiness-section-heading">
|
||||
<b>{{ t('admin.shippingInventory.activationRequiredTitle') }}</b>
|
||||
<small>{{ t('admin.shippingInventory.activationRequiredHint') }}</small>
|
||||
</div>
|
||||
<ol v-if="firstBlockingCheck && !source.enabled" class="readiness-steps">
|
||||
<li :class="`is-${firstBlockingCheck.status}`">
|
||||
<span class="readiness-marker" aria-hidden="true">{{ readinessMarker(firstBlockingCheck.status) }}</span>
|
||||
<div class="readiness-copy"><b>{{ t(`admin.shippingInventory.activationRequirement.${firstBlockingCheck.code}`) }}</b><small>{{ readinessDetail(firstBlockingCheck) }}</small></div>
|
||||
<button v-if="readinessActionLabel(firstBlockingCheck)" type="button" class="readiness-action" :disabled="isReadinessActionBlocked(firstBlockingCheck)" :title="isReadinessActionBlocked(firstBlockingCheck) ? t('admin.shippingInventory.saveBeforeReadinessAction') : undefined" @click="runReadinessAction(firstBlockingCheck)">{{ readinessActionLabel(firstBlockingCheck) }}</button>
|
||||
</li>
|
||||
</ol>
|
||||
</section>
|
||||
<details v-if="optionalReadinessChecks.length" class="readiness-optional">
|
||||
<summary><span>{{ t('admin.shippingInventory.activationOptionalTitle') }}</span><small>{{ t('admin.shippingInventory.activationOptionalHint') }}</small></summary>
|
||||
<ol class="readiness-steps">
|
||||
<li v-for="check in optionalReadinessChecks" :key="check.code" :class="`is-${check.status}`">
|
||||
<span class="readiness-marker" aria-hidden="true">{{ readinessMarker(check.status) }}</span>
|
||||
<div class="readiness-copy"><b>{{ t(`admin.shippingInventory.activationRequirement.${check.code}`) }}</b><small>{{ readinessDetail(check) }}</small></div>
|
||||
</li>
|
||||
</ol>
|
||||
</details>
|
||||
<template v-if="configurationTest">
|
||||
<p class="readiness-run" :class="{ failed: configurationTest.status === 'failed' }">{{ t(`admin.shippingInventory.configurationTestStage.${configurationTest.stage}`) }}</p>
|
||||
<details class="readiness-audit"><summary>{{ t('admin.shippingInventory.configurationTestRunNo') }} {{ configurationTest.run_no }}</summary><dl><div><dt>{{ t('admin.shippingInventory.configurationTestConfigVersion') }}</dt><dd>{{ configurationTest.source_config_version }}</dd></div><div><dt>{{ t('admin.shippingInventory.configurationTestConnectionVersion') }}</dt><dd>{{ configurationTest.rpa_profile_config_version }}</dd></div><div><dt>{{ t('admin.shippingInventory.configurationTestUpdatedAt') }}</dt><dd>{{ formatDate(configurationTest.completed_at || configurationTest.created_at) }}</dd></div></dl></details>
|
||||
<p v-if="configurationTest.error_message" class="form-tip">{{ configurationTest.error_message }}</p>
|
||||
<p v-if="configurationTest.status === 'completed_empty'" class="form-tip">{{ t('admin.shippingInventory.configurationTestEmptyResult') }}</p>
|
||||
<section v-if="configurationTest.status === 'completed'" class="recommendation-list">
|
||||
<p v-if="configurationTest.result?.current_profile_verified" class="configuration-test-verified">{{ t(`admin.shippingInventory.currentProfileVerified.${configurationTest.result.profile_match_level || 'compatible'}`) }}</p>
|
||||
<article v-for="candidate in configurationTest.result?.analysis?.match_result?.candidates || []" :key="candidate.profile_id"><b>{{ candidate.display_name }} V{{ candidate.version }}</b><small>{{ t(`admin.shippingInventory.recommendationLevel.${candidate.level}`) }} · {{ t('admin.shippingInventory.configurationTestCandidateHint') }}</small></article>
|
||||
<p v-if="!configurationTest.result?.current_profile_verified && !(configurationTest.result?.analysis?.match_result?.candidates || []).length">{{ t('admin.shippingInventory.configurationTestNoRecommendation') }}</p>
|
||||
</section>
|
||||
</template>
|
||||
<footer v-if="source.enabled || source.activation?.ready" class="readiness-footer">
|
||||
<button v-if="source.enabled" type="button" class="btn-danger btn-sm" @click="requestSourceDeactivation">{{ t('admin.shippingInventory.deactivateSource') }}</button>
|
||||
<button
|
||||
v-else
|
||||
type="button"
|
||||
class="btn-primary btn-sm"
|
||||
:disabled="sourceDirty"
|
||||
:title="sourceDirty ? t('admin.shippingInventory.saveBeforeReadinessAction') : undefined"
|
||||
@click="requestSourceActivation"
|
||||
>{{ t('admin.shippingInventory.activateSource') }}</button>
|
||||
</footer>
|
||||
</section>
|
||||
<div v-if="!selectedId" class="form-tip full">{{ t('admin.shippingInventory.sourceSavedDisabledHint') }}</div>
|
||||
<template v-if="source.connector_type === 'dbs'">
|
||||
<div class="subsection full">{{ t('admin.shippingInventory.reportPath') }}</div>
|
||||
<label><span>{{ t('admin.shippingInventory.programGroup') }}</span><input v-model="source.report_path_json.program_group" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.programLabel') }}</span><input v-model="source.report_path_json.program_label" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.reportGroup') }}</span><input v-model="source.report_path_json.report_group" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.reportName') }}</span><input v-model="source.report_path_json.report_name" class="input-field" required></label>
|
||||
<div class="subsection full">{{ t('admin.shippingInventory.queryParameters') }}</div>
|
||||
<div v-for="(parameter, index) in source.query_parameters_json" :key="`${index}-${parameter.name}`" class="parameter-row full">
|
||||
<input v-model="parameter.name" class="input-field" :placeholder="t('admin.shippingInventory.parameterName')">
|
||||
<select v-model="parameter.mode" class="select-field"><option value="single">{{ t('admin.shippingInventory.single') }}</option><option value="multi_text">{{ t('admin.shippingInventory.multiText') }}</option><option value="multi_select">{{ t('admin.shippingInventory.multiSelect') }}</option></select>
|
||||
<input class="input-field" :value="parameter.values.join(', ')" :placeholder="t('admin.shippingInventory.parameterValues')" @input="parameter.values = splitValues(($event.target as HTMLInputElement).value)">
|
||||
<label class="inline-check"><input v-model="parameter.required" type="checkbox">{{ t('admin.shippingInventory.required') }}</label>
|
||||
<label class="inline-check"><input v-model="parameter.select_all" type="checkbox">{{ t('admin.shippingInventory.selectAll') }}</label>
|
||||
<button type="button" class="btn-danger btn-sm" @click="source.query_parameters_json.splice(index, 1)">{{ t('admin.delete') }}</button>
|
||||
<section class="path-card full">
|
||||
<button type="button" class="path-card-header" :aria-expanded="inventoryPathOpen" @click="inventoryPathOpen = !inventoryPathOpen">
|
||||
<span class="path-card-title"><b>{{ t('admin.shippingInventory.reportPath') }}</b></span>
|
||||
<span class="path-card-toggle" aria-hidden="true">{{ inventoryPathOpen ? '▾' : '▸' }}</span>
|
||||
</button>
|
||||
<div v-show="inventoryPathOpen" class="path-card-body">
|
||||
<label><span>{{ t('admin.shippingInventory.programGroup') }}</span><input v-model="source.report_path_json.program_group" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.programLabel') }}</span><input v-model="source.report_path_json.program_label" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.reportGroup') }}</span><input v-model="source.report_path_json.report_group" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.reportName') }}</span><input v-model="source.report_path_json.report_name" class="input-field" required></label>
|
||||
<div class="subsection full">{{ t('admin.shippingInventory.queryParameters') }}</div>
|
||||
<div v-for="(parameter, index) in source.query_parameters_json" :key="`${index}-${parameter.name}`" class="parameter-row full">
|
||||
<input v-model="parameter.name" class="input-field" :placeholder="t('admin.shippingInventory.parameterName')">
|
||||
<select v-model="parameter.mode" class="select-field"><option value="single">{{ t('admin.shippingInventory.single') }}</option><option value="multi_text">{{ t('admin.shippingInventory.multiText') }}</option><option value="multi_select">{{ t('admin.shippingInventory.multiSelect') }}</option></select>
|
||||
<input class="input-field" :value="parameter.values.join(', ')" :placeholder="t('admin.shippingInventory.parameterValues')" @input="parameter.values = splitValues(($event.target as HTMLInputElement).value)">
|
||||
<label class="inline-check"><input v-model="parameter.required" type="checkbox">{{ t('admin.shippingInventory.required') }}</label>
|
||||
<label class="inline-check"><input v-model="parameter.select_all" type="checkbox">{{ t('admin.shippingInventory.selectAll') }}</label>
|
||||
<button type="button" class="btn-danger btn-sm" @click="source.query_parameters_json.splice(index, 1)">{{ t('admin.delete') }}</button>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary btn-sm full" @click="addParameter">{{ t('admin.shippingInventory.addParameter') }}</button>
|
||||
</div>
|
||||
<button type="button" class="btn-secondary btn-sm full" @click="addParameter">{{ t('admin.shippingInventory.addParameter') }}</button>
|
||||
</template>
|
||||
<section v-if="selectedId" class="receipt-report-config full">
|
||||
<div class="subsection">{{ t('admin.shippingInventory.receiptReportConfig') }}<small>{{ t('admin.shippingInventory.receiptReportConfigHint') }}</small></div>
|
||||
<div class="switch-field"><span>{{ t('admin.shippingInventory.receiptReportEnabled') }}</span><button type="button" class="status-switch" :class="{ on: receiptConfig.enabled }" role="switch" :aria-checked="receiptConfig.enabled" @click="receiptConfig.enabled = !receiptConfig.enabled"><i></i><b>{{ receiptConfig.enabled ? t('admin.shippingInventory.enabledState') : t('admin.shippingInventory.disabledState') }}</b></button></div>
|
||||
</section>
|
||||
</template>
|
||||
<section v-if="selectedId" class="path-card receipt full" :class="{ configured: receiptConfigExists }">
|
||||
<button type="button" class="path-card-header" :aria-expanded="receiptSectionOpen" @click="toggleReceiptSection">
|
||||
<span class="path-card-title"><b>{{ t('admin.shippingInventory.receiptReportConfig') }}</b><small>{{ t('admin.shippingInventory.receiptReportConfigHint') }}</small></span>
|
||||
<span class="path-badge" :class="receiptConfigExists ? 'on' : 'off'">{{ receiptConfigExists ? t('admin.shippingInventory.pathSectionConfigured') : t('admin.shippingInventory.pathSectionNotConfigured') }}</span>
|
||||
<span class="path-card-toggle" aria-hidden="true">{{ receiptSectionOpen ? '▾' : '▸' }}</span>
|
||||
</button>
|
||||
<div v-show="receiptSectionOpen" class="path-card-body">
|
||||
<template v-if="source.connector_type === 'dbs'">
|
||||
<label><span>{{ t('admin.shippingInventory.programGroup') }}</span><input v-model="receiptConfig.report_path_json.program_group" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.programLabel') }}</span><input v-model="receiptConfig.report_path_json.program_label" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.reportGroup') }}</span><input v-model="receiptConfig.report_path_json.report_group" class="input-field" required></label>
|
||||
<label><span>{{ t('admin.shippingInventory.reportName') }}</span><input v-model="receiptConfig.report_path_json.report_name" class="input-field" required></label>
|
||||
<label class="full"><span>{{ t('admin.shippingInventory.receiptWarehouses') }}</span><input class="input-field" :value="receiptConfig.warehouse_ids_json.join(', ')" :placeholder="t('admin.shippingInventory.receiptWarehousesHint')" @input="receiptConfig.warehouse_ids_json = splitValues(($event.target as HTMLInputElement).value)"></label>
|
||||
<div class="subsection full">{{ t('admin.shippingInventory.receiptOptionalParameters') }}</div>
|
||||
<div class="subsection full">{{ t('admin.shippingInventory.queryParameters') }}<small>{{ t('admin.shippingInventory.receiptQueryParametersHint') }}</small></div>
|
||||
<div v-for="(parameter, index) in receiptConfig.query_parameters_json" :key="`receipt-${index}-${parameter.name}`" class="parameter-row full">
|
||||
<input v-model="parameter.name" class="input-field" :placeholder="t('admin.shippingInventory.parameterName')">
|
||||
<select v-model="parameter.mode" class="select-field"><option value="single">{{ t('admin.shippingInventory.single') }}</option><option value="multi_text">{{ t('admin.shippingInventory.multiText') }}</option><option value="multi_select">{{ t('admin.shippingInventory.multiSelect') }}</option></select>
|
||||
@@ -222,8 +178,8 @@
|
||||
<button type="button" class="btn-secondary btn-sm full" @click="addReceiptParameter">{{ t('admin.shippingInventory.addParameter') }}</button>
|
||||
</template>
|
||||
<p v-else class="form-tip full">{{ t('admin.shippingInventory.receiptCraneFixedPath') }}</p>
|
||||
<div class="receipt-config-actions full"><button type="button" class="btn-secondary btn-sm" :disabled="receiptConfigLoading || receiptConfigSaving" @click="saveReceiptConfig">{{ receiptConfigSaving ? t('admin.shippingInventory.saving') : t('admin.shippingInventory.saveReceiptReportConfig') }}</button></div>
|
||||
</section>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<template v-else-if="activeTab === 'parsing'">
|
||||
@@ -377,6 +333,48 @@
|
||||
<div class="switch-field"><span>{{ t('admin.shippingInventory.enabled') }}</span><button type="button" class="status-switch" :class="{ on: mapping.enabled }" role="switch" :aria-checked="mapping.enabled" @click="mapping.enabled = !mapping.enabled"><i></i><b>{{ mapping.enabled ? t('admin.shippingInventory.enabledState') : t('admin.shippingInventory.disabledState') }}</b></button></div>
|
||||
</template>
|
||||
|
||||
<section v-if="selectedId" class="readiness-card full" :class="{ ready: source.enabled }">
|
||||
<div class="readiness-inline">
|
||||
<template v-if="source.enabled">
|
||||
<span class="readiness-marker is-passed" aria-hidden="true">✓</span>
|
||||
<div class="readiness-copy"><b>{{ t('admin.shippingInventory.activationReady') }}</b><small v-if="configurationTest?.completed_at">{{ t('admin.shippingInventory.readinessLastVerified', { time: formatDate(configurationTest.completed_at) }) }}</small></div>
|
||||
<button type="button" class="btn-danger btn-sm" @click="requestSourceDeactivation">{{ t('admin.shippingInventory.deactivateSource') }}</button>
|
||||
</template>
|
||||
<template v-else-if="firstBlockingCheck">
|
||||
<span class="readiness-marker" :class="`is-${firstBlockingCheck.status}`" aria-hidden="true">{{ readinessMarker(firstBlockingCheck.status) }}</span>
|
||||
<div class="readiness-copy"><b>{{ t('admin.shippingInventory.readinessBlockedBy', { requirement: t(`admin.shippingInventory.activationRequirement.${firstBlockingCheck.code}`) }) }}</b><small>{{ t('admin.shippingInventory.readinessAutoEnableHint') }}</small></div>
|
||||
<button v-if="readinessActionLabel(firstBlockingCheck)" type="button" class="readiness-action" :disabled="isReadinessActionBlocked(firstBlockingCheck)" :title="isReadinessActionBlocked(firstBlockingCheck) ? t('admin.shippingInventory.saveBeforeReadinessAction') : undefined" @click="runReadinessAction(firstBlockingCheck)">{{ readinessActionLabel(firstBlockingCheck) }}</button>
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="readiness-marker is-passed" aria-hidden="true">✓</span>
|
||||
<div class="readiness-copy"><b>{{ t('admin.shippingInventory.activationCanEnable') }}</b></div>
|
||||
<button type="button" class="btn-primary btn-sm" :disabled="sourceDirty" :title="sourceDirty ? t('admin.shippingInventory.saveBeforeReadinessAction') : undefined" @click="requestSourceActivation">{{ t('admin.shippingInventory.activateSource') }}</button>
|
||||
</template>
|
||||
</div>
|
||||
<details v-if="optionalReadinessChecks.length" class="readiness-optional">
|
||||
<summary><span>{{ t('admin.shippingInventory.activationOptionalTitle') }}</span><small>{{ t('admin.shippingInventory.readinessOptionalPending', { count: optionalReadinessPending }) }}</small></summary>
|
||||
<ol class="readiness-steps">
|
||||
<li v-for="check in optionalReadinessChecks" :key="check.code" :class="`is-${check.status}`">
|
||||
<span class="readiness-marker" aria-hidden="true">{{ readinessMarker(check.status) }}</span>
|
||||
<div class="readiness-copy"><b>{{ t(`admin.shippingInventory.activationRequirement.${check.code}`) }}</b><small>{{ readinessDetail(check) }}</small></div>
|
||||
</li>
|
||||
</ol>
|
||||
</details>
|
||||
<template v-if="configurationTest">
|
||||
<p v-if="configurationTest.status === 'failed'" class="readiness-run failed">{{ t(`admin.shippingInventory.configurationTestStage.${configurationTest.stage}`) }}</p>
|
||||
<p v-if="configurationTest.error_message" class="form-tip">{{ configurationTest.error_message }}</p>
|
||||
<p v-if="configurationTest.status === 'completed_empty'" class="form-tip">{{ t('admin.shippingInventory.configurationTestEmptyResult') }}</p>
|
||||
<details v-if="configurationTest.status !== 'failed'" class="readiness-audit">
|
||||
<summary>{{ t('admin.shippingInventory.configurationTestRunNo') }} {{ configurationTest.run_no }} · {{ t(`admin.shippingInventory.configurationTestStage.${configurationTest.stage}`) }}</summary>
|
||||
<dl><div><dt>{{ t('admin.shippingInventory.configurationTestConfigVersion') }}</dt><dd>{{ configurationTest.source_config_version }}</dd></div><div><dt>{{ t('admin.shippingInventory.configurationTestConnectionVersion') }}</dt><dd>{{ configurationTest.rpa_profile_config_version }}</dd></div><div><dt>{{ t('admin.shippingInventory.configurationTestUpdatedAt') }}</dt><dd>{{ formatDate(configurationTest.completed_at || configurationTest.created_at) }}</dd></div></dl>
|
||||
<section v-if="configurationTest.status === 'completed'" class="recommendation-list">
|
||||
<p v-if="configurationTest.result?.current_profile_verified" class="configuration-test-verified">{{ t(`admin.shippingInventory.currentProfileVerified.${configurationTest.result.profile_match_level || 'compatible'}`) }}</p>
|
||||
<article v-for="candidate in configurationTest.result?.analysis?.match_result?.candidates || []" :key="candidate.profile_id"><b>{{ candidate.display_name }} V{{ candidate.version }}</b><small>{{ t(`admin.shippingInventory.recommendationLevel.${candidate.level}`) }} · {{ t('admin.shippingInventory.configurationTestCandidateHint') }}</small></article>
|
||||
<p v-if="!configurationTest.result?.current_profile_verified && !(configurationTest.result?.analysis?.match_result?.candidates || []).length">{{ t('admin.shippingInventory.configurationTestNoRecommendation') }}</p>
|
||||
</section>
|
||||
</details>
|
||||
</template>
|
||||
</section>
|
||||
<div v-if="isEditableTab" class="form-actions full">
|
||||
<button v-if="!parsingReadOnly" type="submit" class="btn-primary" :disabled="saving || ruleReadOnly || templateReadOnly || inventoryFieldReadOnly">{{ saving ? t('admin.shippingInventory.saving') : t('admin.save') }}</button>
|
||||
<button v-if="activeTab === 'rules' && selectedId && selectedRuleStatus === 'draft'" type="button" class="btn-secondary btn-sm" @click="publishCurrentRule">{{ t('admin.shippingInventory.publish') }}</button>
|
||||
@@ -627,9 +625,12 @@ const bulkBinding = reactive({ visible: false, sourceIds: [] as number[], profil
|
||||
const batchValidation = reactive({ visible: false, sourceIds: [] as number[], query: '', statusFilter: 'all' as 'all' | 'processing' | 'completed' | 'completed_empty' | 'failed', saving: false, result: null as ShippingInventoryValidationBatch | null });
|
||||
let batchValidationTimer: number | null = null;
|
||||
const source = reactive({ source_code: '', display_name: '', connector_type: 'dbs', rpa_profile_id: 0, parsing_profile_id: 0, excel_template_id: 0, warehouse_resolution_mode: 'fixed', fixed_warehouse_id: '', snapshot_ttl_seconds: 86400, report_path_json: { program_group: '', program_label: '', report_group: 'Inventory', report_name: '' }, query_parameters_json: [] as Parameter[], enabled: false, activation: { ready: false, checks: [] as ShippingInventoryReadinessCheck[], missing_requirements: [] as string[] } as SourceActivation });
|
||||
const receiptConfig = reactive({ enabled: false, report_path_json: { program_group: '', program_label: '', report_group: 'Inbound', report_name: '' } as Record<string, string>, query_parameters_json: [] as Parameter[], warehouse_ids_json: [] as string[] });
|
||||
const receiptConfigLoading = ref(false);
|
||||
const receiptConfigSaving = ref(false);
|
||||
const receiptConfig = reactive({ report_path_json: { program_group: '', program_label: '', report_group: 'Inbound', report_name: '' } as Record<string, string>, query_parameters_json: [] as Parameter[] });
|
||||
const receiptConfigExists = ref(false);
|
||||
const receiptSectionTouched = ref(false);
|
||||
const receiptSectionOpen = ref(false);
|
||||
const inventoryPathOpen = ref(true);
|
||||
const receiptBaseline = ref('');
|
||||
const sourceBaseline = ref('');
|
||||
const rule = reactive({ rule_code: '', rule_name: '', scope: 'line', priority: 100, conditions: [{ source_kind: 'order_field', order_field_id: '', operator: 'prefix', expected: '' }] as RuleCondition[], source_codes: [] as string[] });
|
||||
const mapping = reactive({ inventory_source_id: 0, freight_warehouse_id: '', external_system_code: 'TOPGP', external_organization_code: '', external_site_code: '', external_warehouse_code: '', external_warehouse_name: '', enabled: true });
|
||||
@@ -646,26 +647,15 @@ const matchingOrderFields = computed(() => routingFields.value.filter((field) =>
|
||||
const canAddParsingMatchKey = computed(() => Boolean(
|
||||
structureAnalysis.value && unusedMatchingInventoryFields.value.length && unusedOrderMatchFields.value.length,
|
||||
));
|
||||
const sourceDirty = computed(() => Boolean(selectedId.value && sourceBaseline.value && sourceBaseline.value !== serialiseSourceInput()));
|
||||
const sourceDirty = computed(() => Boolean(selectedId.value && (
|
||||
(sourceBaseline.value && sourceBaseline.value !== serialiseSourceInput())
|
||||
|| (receiptConfigExists.value && receiptBaseline.value && receiptBaseline.value !== serialiseReceiptInput())
|
||||
)));
|
||||
const readinessChecks = computed<ShippingInventoryReadinessCheck[]>(() => source.activation?.checks || []);
|
||||
const requiredReadinessChecks = computed(() => readinessChecks.value.filter((item) => item.blocking));
|
||||
const firstBlockingCheck = computed(() => requiredReadinessChecks.value.find((item) => item.status !== 'passed'));
|
||||
const optionalReadinessChecks = computed(() => readinessChecks.value.filter((item) => !item.blocking));
|
||||
const readinessSummary = computed(() => {
|
||||
const required = requiredReadinessChecks.value;
|
||||
const total = required.length;
|
||||
const passed = required.filter((item) => item.status === 'passed').length;
|
||||
return t('admin.shippingInventory.readinessProgress', { passed, total });
|
||||
});
|
||||
const readinessHeadline = computed(() => {
|
||||
if (source.enabled) return t('admin.shippingInventory.activationReady');
|
||||
return source.activation?.ready ? t('admin.shippingInventory.activationCanEnable') : t('admin.shippingInventory.activationDraft');
|
||||
});
|
||||
const readinessGuidance = computed(() => source.enabled
|
||||
? t('admin.shippingInventory.activationEnabledHint')
|
||||
: source.activation?.ready
|
||||
? t('admin.shippingInventory.activationCanEnableHint')
|
||||
: t('admin.shippingInventory.activationMissingHint'));
|
||||
const optionalReadinessPending = computed(() => optionalReadinessChecks.value.filter((item) => item.status !== 'passed').length);
|
||||
const sampleReplacementNotice = computed(() => {
|
||||
const difference = pendingSampleReplacement.value?.difference || {};
|
||||
const missing = Array.isArray(difference.missing_mapped_headers) ? difference.missing_mapped_headers : [];
|
||||
@@ -848,36 +838,37 @@ async function load(): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
/** 重置当前站点的独立收料表单,不借用库存报表路径或查询条件。 */
|
||||
/** 重置当前站点的独立收料表单与卡片状态,与库存同构(路径+查询条件)。 */
|
||||
function resetReceiptConfig(connectorType: unknown): void {
|
||||
Object.assign(receiptConfig, {
|
||||
enabled: false,
|
||||
report_path_json: String(connectorType || '').toLowerCase() === 'crane'
|
||||
? { report_name: 'Inbound Details' }
|
||||
: { program_group: '', program_label: '', report_group: 'Inbound', report_name: '' },
|
||||
query_parameters_json: [],
|
||||
warehouse_ids_json: [],
|
||||
});
|
||||
}
|
||||
|
||||
/** 读取收料独立配置;读取失败不影响库存站点配置和既有库存运行。 */
|
||||
async function loadReceiptConfig(sourceId: number, connectorType: unknown): Promise<void> {
|
||||
receiptConfigLoading.value = true;
|
||||
resetReceiptConfig(connectorType);
|
||||
receiptConfigExists.value = false;
|
||||
receiptSectionTouched.value = false;
|
||||
receiptSectionOpen.value = false;
|
||||
receiptBaseline.value = '';
|
||||
try {
|
||||
const config = await getShippingReceiptReportConfig(sourceId);
|
||||
if (!config) return;
|
||||
const isCrane = String(connectorType || '').toLowerCase() === 'crane';
|
||||
Object.assign(receiptConfig, {
|
||||
enabled: Boolean(config.enabled),
|
||||
report_path_json: isCrane
|
||||
? { report_name: 'Inbound Details' }
|
||||
: { program_group: '', program_label: '', report_group: 'Inbound', report_name: '', ...((config.report_path_json || {}) as Record<string, string>) },
|
||||
query_parameters_json: Array.isArray(config.query_parameters_json) ? config.query_parameters_json.map((parameter) => ({ ...parameter })) : [],
|
||||
warehouse_ids_json: Array.isArray(config.warehouse_ids_json) ? [...config.warehouse_ids_json].map(String) : [],
|
||||
});
|
||||
receiptConfigExists.value = true;
|
||||
receiptSectionOpen.value = true;
|
||||
} catch (cause) { showError(cause, 'loadFailed'); }
|
||||
finally { receiptConfigLoading.value = false; }
|
||||
finally { receiptBaseline.value = serialiseReceiptInput(); }
|
||||
}
|
||||
|
||||
/** 新增 DBS 可选收料条件;Crane 固定默认查询,不维护查询条件。 */
|
||||
@@ -885,16 +876,10 @@ function addReceiptParameter(): void {
|
||||
receiptConfig.query_parameters_json.push({ name: '', mode: 'single', values: [], required: false, select_all: false });
|
||||
}
|
||||
|
||||
/** 仅提交白名单收料字段到独立 API,绝不调用库存 Source 保存接口。 */
|
||||
async function saveReceiptConfig(): Promise<void> {
|
||||
if (!selectedId.value) return;
|
||||
receiptConfigSaving.value = true;
|
||||
try {
|
||||
await saveShippingReceiptReportConfig(selectedId.value, buildReceiptReportConfigPayload(receiptConfig));
|
||||
await loadReceiptConfig(selectedId.value, source.connector_type);
|
||||
message.success(t('admin.shippingInventory.receiptReportSaved'));
|
||||
} catch (cause) { showError(cause, 'saveFailed'); }
|
||||
finally { receiptConfigSaving.value = false; }
|
||||
/** 展开收料卡即视为有配置意图:统一保存时会提交收料配置,避免未展开时误建空配置。 */
|
||||
function toggleReceiptSection(): void {
|
||||
receiptSectionOpen.value = !receiptSectionOpen.value;
|
||||
if (receiptSectionOpen.value) receiptSectionTouched.value = true;
|
||||
}
|
||||
|
||||
/** 切换管理对象时同步深链并清空选择,避免不同对象的数据残留在编辑器中。 */
|
||||
@@ -949,6 +934,11 @@ function createNew(): void {
|
||||
if (activeTab.value === 'sources') {
|
||||
Object.assign(source, { source_code: '', display_name: '', connector_type: 'dbs', rpa_profile_id: 0, parsing_profile_id: 0, excel_template_id: 0, warehouse_resolution_mode: 'fixed', fixed_warehouse_id: '', snapshot_ttl_seconds: 86400, report_path_json: { program_group: '', program_label: '', report_group: 'Inventory', report_name: '' }, query_parameters_json: [], enabled: false, activation: { ready: false, checks: [], missing_requirements: ['configuration_test'] } });
|
||||
resetReceiptConfig('dbs');
|
||||
receiptConfigExists.value = false;
|
||||
receiptSectionTouched.value = false;
|
||||
receiptSectionOpen.value = false;
|
||||
inventoryPathOpen.value = true;
|
||||
receiptBaseline.value = '';
|
||||
sourceBaseline.value = '';
|
||||
}
|
||||
if (activeTab.value === 'rules') Object.assign(rule, { rule_code: '', rule_name: '', scope: 'line', priority: 100, conditions: [{ source_kind: 'order_field', order_field_id: '', operator: 'prefix', expected: '' }], source_codes: [] });
|
||||
@@ -1174,7 +1164,21 @@ async function saveCurrent(): Promise<void> {
|
||||
await createShippingExcelTemplate(form);
|
||||
}
|
||||
}
|
||||
if (activeTab.value === 'sources') await saveShippingInventorySource({ ...source, enabled: false, fixed_warehouse_id: source.warehouse_resolution_mode === 'fixed' ? source.fixed_warehouse_id : null, report_path_json: normaliseInventoryReportPath(source.connector_type, source.report_path_json) }, selectedId.value || undefined);
|
||||
if (activeTab.value === 'sources') {
|
||||
await saveShippingInventorySource({ ...source, enabled: false, fixed_warehouse_id: source.warehouse_resolution_mode === 'fixed' ? source.fixed_warehouse_id : null, report_path_json: normaliseInventoryReportPath(source.connector_type, source.report_path_json) }, selectedId.value || undefined);
|
||||
// 收料与站点同批保存:仅当已有配置或管理员展开过收料卡时才提交,避免未配置站点被误建空收料配置。
|
||||
if (selectedId.value && (receiptSectionTouched.value || (receiptConfigExists.value && receiptBaseline.value !== serialiseReceiptInput()))) {
|
||||
try {
|
||||
await saveShippingReceiptReportConfig(selectedId.value, buildReceiptReportConfigPayload(receiptConfig));
|
||||
receiptConfigExists.value = true;
|
||||
receiptBaseline.value = serialiseReceiptInput();
|
||||
} catch (cause) {
|
||||
showError(cause, 'saveFailed');
|
||||
await load();
|
||||
return; // 站点已保存但收料保存失败:保持抽屉打开,修正后可直接重试统一保存。
|
||||
}
|
||||
}
|
||||
}
|
||||
if (activeTab.value === 'rules') await saveShippingInventoryRule({ rule_code: rule.rule_code, rule_name: rule.rule_name || rule.rule_code, scope: rule.scope, priority: rule.priority, match_mode: 'all', action_type: 'add_source_candidates', action_payload_json: { source_codes: splitValues(rule.source_codes) }, conditions: rule.conditions.map((condition) => ({ source_kind: 'order_field', order_field_id: condition.order_field_id, operator: condition.operator, expected_value_json: normalizeExpectedValue(condition) })) }, selectedId.value || undefined);
|
||||
if (activeTab.value === 'mappings') await saveShippingInventoryExternalMapping({ ...mapping, freight_warehouse_id: mapping.freight_warehouse_id || null, external_organization_code: mapping.external_organization_code || null, external_site_code: mapping.external_site_code || null }, selectedId.value || undefined);
|
||||
await load();
|
||||
@@ -1553,6 +1557,14 @@ function serialiseSourceInput(): string {
|
||||
});
|
||||
}
|
||||
|
||||
/** 将收料配置表单稳定序列化,作为统一保存与启用守卫的收料脏检查基线。 */
|
||||
function serialiseReceiptInput(): string {
|
||||
return JSON.stringify({
|
||||
report_path_json: receiptConfig.report_path_json,
|
||||
query_parameters_json: receiptConfig.query_parameters_json,
|
||||
});
|
||||
}
|
||||
|
||||
/** 返回状态轨道的简洁可视标记,文本状态仍由相邻内容提供,避免颜色成为唯一信息来源。 */
|
||||
function readinessMarker(status: ShippingInventoryReadinessCheck['status']): string {
|
||||
const marker = readinessMarkerKind(status);
|
||||
@@ -1673,10 +1685,10 @@ onMounted(load);
|
||||
.filename-variable-menu button { display: grid; width: 100%; grid-template-columns: 154px minmax(0, 1fr); gap: 8px; border: 0; border-radius: 4px; background: transparent; padding: 7px 8px; color: #64748b; font: inherit; font-size: 12px; text-align: left; cursor: pointer; }
|
||||
.filename-variable-menu button:hover, .filename-variable-menu button.active { background: #eef8f7; color: #145f5a; }.filename-variable-menu code { color: #047f76; font-size: 12px; }.filename-variable-menu p { margin: 0; padding: 8px; color: #94a3b8; font-size: 12px; }
|
||||
.readiness-card { display: grid; gap: 12px; border: 1px solid #cfe2ea; border-radius: 12px; background: #fbfdfe; padding: 16px; }.readiness-card.ready { border-color: #b9dfc4; background: #fcfffd; }
|
||||
.readiness-heading { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; }.readiness-heading > div { display: grid; gap: 5px; }.readiness-kicker { color: #5f798c; font-size: 11px; font-weight: 700; letter-spacing: .04em; }.readiness-heading strong { color: #263b4e; font-size: 14px; line-height: 1.4; }.readiness-heading p { margin: 0; color: #6d8292; font-size: 12px; line-height: 1.45; }.readiness-count { flex: 0 0 auto; border: 1px solid #cce7f1; border-radius: 999px; background: #edf8fc; padding: 5px 9px; color: #176f9f; font-size: 12px; font-weight: 700; white-space: nowrap; }.readiness-card.ready .readiness-count { border-color: #cce8d4; background: #eef9f1; color: #19703a; }
|
||||
.readiness-section { border: 1px solid #e1edf2; border-radius: 9px; background: #fff; padding: 0 12px; }.readiness-section-heading { display: grid; gap: 2px; padding: 11px 0 8px; }.readiness-section-heading b { color: #385166; font-size: 12px; }.readiness-section-heading small { color: #8192a0; font-size: 11px; }.readiness-steps { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }.readiness-steps li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-height: 46px; border-top: 1px solid #edf2f5; padding: 7px 0; }.readiness-marker { display: inline-grid; width: 20px; height: 20px; place-items: center; border-radius: 50%; background: #e9eef3; color: #6c7d8d; font-size: 12px; font-weight: 800; }.readiness-copy { display: grid; min-width: 0; gap: 2px; }.readiness-copy b { overflow: hidden; color: #425466; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }.readiness-copy small { color: #8190a0; font-size: 11px; line-height: 1.35; }.readiness-steps .is-passed .readiness-marker { background: #dff6e6; color: #16803a; }.readiness-steps .is-passed .readiness-copy b { color: #2d6b40; }.readiness-steps .is-failed .readiness-marker, .readiness-steps .is-stale .readiness-marker { background: #fff0ed; color: #bf4a38; }.readiness-steps .is-failed .readiness-copy b, .readiness-steps .is-stale .readiness-copy b { color: #9d382b; }
|
||||
.readiness-inline { display: flex; align-items: center; gap: 10px; }.readiness-inline .readiness-copy { flex: 1 1 auto; }.readiness-inline .readiness-copy b { white-space: normal; }.readiness-inline .readiness-copy small { white-space: normal; }.readiness-inline .btn-sm, .readiness-inline .readiness-action { flex: 0 0 auto; }
|
||||
.readiness-steps { display: grid; gap: 0; margin: 0; padding: 0; list-style: none; }.readiness-steps li { display: grid; grid-template-columns: 24px minmax(0, 1fr) auto; align-items: center; gap: 9px; min-height: 46px; border-top: 1px solid #edf2f5; padding: 7px 0; }.readiness-marker { display: inline-grid; width: 20px; height: 20px; place-items: center; border-radius: 50%; background: #e9eef3; color: #6c7d8d; font-size: 12px; font-weight: 800; }.readiness-copy { display: grid; min-width: 0; gap: 2px; }.readiness-copy b { overflow: hidden; color: #425466; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }.readiness-copy small { color: #8190a0; font-size: 11px; line-height: 1.35; }.readiness-steps .is-passed .readiness-marker { background: #dff6e6; color: #16803a; }.readiness-steps .is-passed .readiness-copy b { color: #2d6b40; }.readiness-steps .is-failed .readiness-marker, .readiness-steps .is-stale .readiness-marker { background: #fff0ed; color: #bf4a38; }.readiness-steps .is-failed .readiness-copy b, .readiness-steps .is-stale .readiness-copy b { color: #9d382b; }.readiness-inline > .readiness-marker.is-passed { background: #dff6e6; color: #16803a; }.readiness-inline > .readiness-marker.is-failed, .readiness-inline > .readiness-marker.is-stale { background: #fff0ed; color: #bf4a38; }
|
||||
.readiness-optional { border-top: 1px solid #e4edf2; padding-top: 10px; }.readiness-optional summary, .readiness-audit summary { display: flex; align-items: baseline; gap: 8px; color: #61798a; cursor: pointer; list-style: none; }.readiness-optional summary::-webkit-details-marker, .readiness-audit summary::-webkit-details-marker { display: none; }.readiness-optional summary::before, .readiness-audit summary::before { color: #4d849f; content: '›'; font-size: 16px; line-height: .8; transition: transform .15s; }.readiness-optional[open] summary::before, .readiness-audit[open] summary::before { transform: rotate(90deg); }.readiness-optional summary span { color: #516b7d; font-size: 12px; font-weight: 700; }.readiness-optional summary small { color: #8797a5; font-size: 11px; }.readiness-optional .readiness-steps { margin-top: 8px; }
|
||||
.readiness-action { border: 0; border-radius: 5px; background: #e8f3f9; padding: 6px 8px; color: #16759f; font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; }.readiness-action:hover { background: #d8edf7; }.readiness-run { margin: 0; border-left: 3px solid #74b8d8; background: #f0f8fc; padding: 8px 10px; color: #547185; font-size: 11px; line-height: 1.5; }.readiness-run.failed { border-left-color: #e06a58; background: #fff5f3; color: #9d382b; }.readiness-audit { margin: 0; border-top: 1px solid #e4edf2; padding-top: 10px; }.readiness-audit summary { color: #61798a; font-size: 11px; font-weight: 700; }.readiness-audit dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; margin: 9px 0 0; overflow: hidden; border: 1px solid #dce8ef; border-radius: 7px; background: #dce8ef; }.readiness-audit dl > div { min-width: 0; background: #fff; padding: 8px 9px; }.readiness-audit dt { color: #7b8998; font-size: 11px; font-weight: 700; }.readiness-audit dd { overflow: hidden; margin: 4px 0 0; color: #3d5366; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }.readiness-footer { display: flex; justify-content: flex-end; border-top: 1px solid #e6eef4; padding-top: 11px; }
|
||||
.readiness-action { border: 0; border-radius: 5px; background: #e8f3f9; padding: 6px 8px; color: #16759f; font: inherit; font-size: 11px; font-weight: 700; cursor: pointer; }.readiness-action:hover { background: #d8edf7; }.readiness-run { margin: 0; border-left: 3px solid #74b8d8; background: #f0f8fc; padding: 8px 10px; color: #547185; font-size: 11px; line-height: 1.5; }.readiness-run.failed { border-left-color: #e06a58; background: #fff5f3; color: #9d382b; }.readiness-audit { margin: 0; border-top: 1px solid #e4edf2; padding-top: 10px; }.readiness-audit summary { color: #61798a; font-size: 11px; font-weight: 700; }.readiness-audit dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 1px; margin: 9px 0 0; overflow: hidden; border: 1px solid #dce8ef; border-radius: 7px; background: #dce8ef; }.readiness-audit dl > div { min-width: 0; background: #fff; padding: 8px 9px; }.readiness-audit dt { color: #7b8998; font-size: 11px; font-weight: 700; }.readiness-audit dd { overflow: hidden; margin: 4px 0 0; color: #3d5366; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 11px; font-variant-numeric: tabular-nums; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.form-tip { border-radius: 8px; background: #f1f6fa; padding: 11px; color: #5d7084; font-size: 12px; line-height: 1.55; }
|
||||
.upload-config-section { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; border: 1px solid #e1edf2; border-radius: 9px; background: #fff; padding: 0 12px 12px; }.upload-config-heading { display: grid; gap: 2px; grid-column: 1 / -1; padding: 11px 0 8px; }.upload-config-heading b { color: #385166; font-size: 12px; }.upload-config-heading small { color: #8192a0; font-size: 11px; }.upload-config-section .full { grid-column: 1 / -1; }.upload-config-section textarea.input-field { resize: vertical; }
|
||||
.configuration-test-verified { margin: 0; border-left: 3px solid #34a56b; background: #effaf3; padding: 9px 10px; color: #256b43; font-size: 12px; font-weight: 600; line-height: 1.45; }
|
||||
@@ -1685,9 +1697,12 @@ onMounted(load);
|
||||
.sample-evidence-card dl { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px 16px; margin: 0; }.sample-evidence-card dl div { min-width: 0; }.sample-evidence-card dt { color: #8190a0; font-size: 11px; }.sample-evidence-card dd { margin: 3px 0 0; overflow-wrap: anywhere; color: #475569; font-size: 12px; font-weight: 600; }
|
||||
.sample-replacement-input { display: grid; gap: 6px; border-top: 1px solid #e5edf3; padding-top: 11px; color: #52677a; font-size: 12px; font-weight: 600; }.sample-replacement-input input { max-width: 100%; }.sample-replacement-warning { border-left: 3px solid #e5a21a; background: #fff9eb; padding: 8px 10px; color: #855e00 !important; }.sample-replacement-warning p { margin: 0; }.sample-replacement-warning ul { display: grid; gap: 3px; margin: 7px 0 0; padding-left: 17px; }
|
||||
.parameter-row { display: grid; align-items: center; grid-template-columns: 1.1fr .9fr 1.25fr auto auto auto; gap: 8px; border-radius: 8px; background: #f8fafc; padding: 9px; }
|
||||
.receipt-report-config { display: grid; grid-column: 1 / -1; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; border-top: 1px solid #dbe8ee; margin-top: 8px; padding-top: 14px; }
|
||||
.receipt-report-config .subsection, .receipt-report-config .full { grid-column: 1 / -1; }
|
||||
.receipt-config-actions { display: flex; justify-content: flex-end; }
|
||||
.path-card { display: grid; grid-column: 1 / -1; border: 1px solid #dbe8ee; border-radius: 10px; background: #fff; overflow: hidden; }
|
||||
.path-card-header { display: flex; align-items: center; gap: 10px; border: 0; background: #f7fbfd; padding: 10px 12px; cursor: pointer; font: inherit; text-align: left; }.path-card-header:hover { background: #eff7fa; }
|
||||
.path-card-title { display: grid; flex: 1 1 auto; min-width: 0; gap: 2px; }.path-card-title b { color: #145f5a; font-size: 12px; font-weight: 800; }.path-card-title small { color: #94a3b8; font-size: 11px; font-weight: 400; }
|
||||
.path-badge { flex: 0 0 auto; border-radius: 999px; background: #eef2f5; padding: 3px 8px; color: #7b8998; font-size: 11px; font-weight: 700; }.path-card.configured .path-badge.on { background: #e6f6ec; color: #19703a; }
|
||||
.path-card-toggle { flex: 0 0 auto; color: #4d849f; font-size: 14px; line-height: 1; }
|
||||
.path-card-body { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; border-top: 1px solid #e6eef4; padding: 14px 12px; }.path-card-body .full { grid-column: 1 / -1; }
|
||||
.condition-row, .mapping-row, .template-mapping { display: grid; align-items: center; gap: 8px; border-radius: 8px; background: #f8fafc; padding: 9px; }
|
||||
.condition-row { grid-template-columns: 1.15fr .9fr 1fr auto; }
|
||||
.mapping-row { grid-template-columns: 1fr 1fr auto; }
|
||||
@@ -1728,5 +1743,5 @@ onMounted(load);
|
||||
.object-list .empty-state { grid-column: 1 / -1; display: grid; min-height: 260px; place-items: center; }
|
||||
.empty-state { border: 1px dashed #c9d7e5; border-radius: 10px; background: #f9fbfd; padding: 38px 18px; color: #7b899a; font-size: 13px; text-align: center; }
|
||||
@media (max-width: 980px) { .parameter-row, .condition-row, .mapping-row, .template-mapping, .record-card { grid-template-columns: 1fr 1fr; } .mapping-value-row { grid-template-columns: minmax(0, 1.6fr) minmax(180px, 1fr); }.readiness-audit { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
|
||||
@media (max-width: 640px) { .inventory-console { padding: 18px; } .editor-form, .parameter-row, .condition-row, .mapping-row, .template-mapping, .record-card, .mapping-value-row, .parsing-mapping-card, .readonly-mapping-section .parsing-mapping-card, .parsing-summary, .receipt-report-config { grid-template-columns: 1fr; } .mapping-arrow { transform: rotate(90deg); }.workbench-heading { display: block; } .workbench-heading .btn-primary { margin-top: 12px; }.batch-source-list { grid-template-columns: 1fr; }.batch-stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }.batch-run { grid-template-columns: 9px minmax(0, 1fr); }.batch-run-error { grid-column: 2; }.readiness-heading { display: grid; }.readiness-count { justify-self: start; }.readiness-steps li { grid-template-columns: 24px minmax(0, 1fr); }.readiness-action { grid-column: 2; justify-self: start; }.readiness-footer { justify-content: stretch; }.readiness-footer .btn-primary { width: 100%; } }
|
||||
@media (max-width: 640px) { .inventory-console { padding: 18px; } .editor-form, .parameter-row, .condition-row, .mapping-row, .template-mapping, .record-card, .mapping-value-row, .parsing-mapping-card, .readonly-mapping-section .parsing-mapping-card, .parsing-summary, .path-card-body { grid-template-columns: 1fr; } .mapping-arrow { transform: rotate(90deg); }.workbench-heading { display: block; } .workbench-heading .btn-primary { margin-top: 12px; }.batch-source-list { grid-template-columns: 1fr; }.batch-stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }.batch-run { grid-template-columns: 9px minmax(0, 1fr); }.batch-run-error { grid-column: 2; }.readiness-inline { flex-wrap: wrap; }.readiness-steps li { grid-template-columns: 24px minmax(0, 1fr); }.readiness-action { grid-column: 2; justify-self: start; } }
|
||||
</style>
|
||||
+16
-9
@@ -2,7 +2,8 @@
|
||||
* features/admin/modules/shipping-inventory/receiptReportConfigForm.spec.ts
|
||||
* 用途:覆盖收料报表表单的独立载荷边界。
|
||||
* 依赖:receiptReportConfigForm、vitest。
|
||||
* 逻辑:防止收料配置保存时把库存站点路径、库存查询条件或启停状态误发到库存接口。
|
||||
* 逻辑:防止收料配置保存时把库存站点路径、库存查询条件或启停状态误发到库存接口;
|
||||
* 收料无独立启停字段,载荷不得包含 enabled。
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
@@ -10,24 +11,30 @@ import { buildReceiptReportConfigPayload } from './receiptReportConfigForm';
|
||||
|
||||
describe('receiptReportConfigForm', () => {
|
||||
it('builds a receipt-only payload without inventory source fields', () => {
|
||||
// 关键断言:收料路径、条件与仓库必须走独立 API,不能夹带库存 RPA 配置。
|
||||
// 关键断言:收料路径与条件必须走独立 API,不能夹带库存 RPA 配置或启停字段。
|
||||
const payload = buildReceiptReportConfigPayload({
|
||||
enabled: true,
|
||||
report_path_json: { program_group: 'Bison', program_label: 'AWSBI', report_group: 'Inbound', report_name: 'Receipt Detail' },
|
||||
query_parameters_json: [{ name: 'Owner', mode: 'single', values: ['AWS'], required: false, select_all: false }],
|
||||
warehouse_ids_json: ['A', 'B'],
|
||||
query_parameters_json: [
|
||||
{ name: 'Warehouse', mode: 'multi_text', values: ['AWSDU', 'AWSDU-02'], required: false, select_all: false },
|
||||
{ name: 'Owner', mode: 'single', values: ['AWS'], required: false, select_all: false },
|
||||
],
|
||||
source_code: 'INVENTORY-SHOULD-NOT-LEAK',
|
||||
snapshot_ttl_seconds: 86400,
|
||||
enabled: true,
|
||||
warehouse_ids_json: ['SHOULD-NOT-LEAK'],
|
||||
inventory_report_path_json: { report_name: 'On Hand' },
|
||||
});
|
||||
} as Parameters<typeof buildReceiptReportConfigPayload>[0] & Record<string, unknown>);
|
||||
|
||||
expect(payload).toEqual({
|
||||
enabled: true,
|
||||
report_path_json: { program_group: 'Bison', program_label: 'AWSBI', report_group: 'Inbound', report_name: 'Receipt Detail' },
|
||||
query_parameters_json: [{ name: 'Owner', mode: 'single', values: ['AWS'], required: false, select_all: false }],
|
||||
warehouse_ids_json: ['A', 'B'],
|
||||
query_parameters_json: [
|
||||
{ name: 'Warehouse', mode: 'multi_text', values: ['AWSDU', 'AWSDU-02'], required: false, select_all: false },
|
||||
{ name: 'Owner', mode: 'single', values: ['AWS'], required: false, select_all: false },
|
||||
],
|
||||
});
|
||||
expect(payload).not.toHaveProperty('source_code');
|
||||
expect(payload).not.toHaveProperty('snapshot_ttl_seconds');
|
||||
expect(payload).not.toHaveProperty('enabled');
|
||||
expect(payload).not.toHaveProperty('warehouse_ids_json');
|
||||
});
|
||||
});
|
||||
@@ -2,14 +2,13 @@
|
||||
* features/admin/modules/shipping-inventory/receiptReportConfigForm.ts
|
||||
* 用途:构建独立收料报表配置的受限保存载荷。
|
||||
* 依赖:无外部依赖。
|
||||
* 逻辑:页面仅将收料路径、可选条件和 Warehouse 列表提交到收料配置 API,隔离库存站点字段。
|
||||
* 逻辑:页面仅将收料路径与查询条件提交到收料配置 API,与库存同构(Warehouse 为条件之一),
|
||||
* 隔离库存站点字段;收料无独立启停字段,是否运行统一由库存站点 enabled 决定。
|
||||
*/
|
||||
|
||||
export type ReceiptReportConfigInput = {
|
||||
enabled: boolean;
|
||||
report_path_json: Record<string, unknown>;
|
||||
query_parameters_json: Array<Record<string, unknown>>;
|
||||
warehouse_ids_json: string[];
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -20,9 +19,7 @@ export type ReceiptReportConfigInput = {
|
||||
*/
|
||||
export function buildReceiptReportConfigPayload(input: ReceiptReportConfigInput): ReceiptReportConfigInput {
|
||||
return {
|
||||
enabled: Boolean(input.enabled),
|
||||
report_path_json: { ...(input.report_path_json || {}) },
|
||||
query_parameters_json: (input.query_parameters_json || []).map((item) => ({ ...item })),
|
||||
warehouse_ids_json: [...(input.warehouse_ids_json || [])],
|
||||
};
|
||||
}
|
||||
+15
-4
@@ -613,6 +613,14 @@ const coordinateCanvasActions = computed<OrderProfileCanvasActions>(() => ({
|
||||
page: (nextPageNo) => { void selectPage(nextPageNo); },
|
||||
draw: (kind) => startDrawing(kind),
|
||||
}));
|
||||
/** 页图 token 失效时自动重签;客户端渲染失败(如 worker MIME)不得超过预算。 */
|
||||
let previewReauthInFlight = false;
|
||||
let previewAutoReauthCount = 0;
|
||||
const PREVIEW_AUTO_REAUTH_LIMIT = 2;
|
||||
const resetPreviewAutoReauthBudget = () => {
|
||||
previewAutoReauthCount = 0;
|
||||
};
|
||||
|
||||
/**
|
||||
* 共享视觉画布模型:模板差异在此处一次性被 adapter 吸收,之后所有画布事件和 props
|
||||
* 均只消费 visualCanvas。datasets path、集合与拆分规则不属于视觉模型,继续留在 XFA
|
||||
@@ -659,7 +667,10 @@ const visualCanvas = computed<OrderProfileVisualCanvasAdapter>(() => {
|
||||
warningVisible: adapterWarningVisible || canvasUnavailable.value,
|
||||
warningText: adapterWarningText
|
||||
|| (canvasUnavailable.value ? t('admin.shippingOrderProfiles.workbench.canvasUnavailable') : null),
|
||||
retryCanvas: () => { void loadPages(); },
|
||||
retryCanvas: () => {
|
||||
resetPreviewAutoReauthBudget();
|
||||
void loadPages();
|
||||
},
|
||||
reportCanvasLoadFailed: () => { canvasUnavailable.value = true; },
|
||||
applyAutomarkCandidates: () => false,
|
||||
canRender: true,
|
||||
@@ -814,13 +825,13 @@ const deskCanvasReadonly = computed(() => visualCanvas.value.canvasReadonly);
|
||||
const deskCanvasWarningVisible = computed(() => visualCanvas.value.warningVisible);
|
||||
const deskCanvasWarningText = computed(() => visualCanvas.value.warningText || '');
|
||||
const onDeskCanvasRetry = () => visualCanvas.value.retryCanvas();
|
||||
/** 页图 token 失效时自动重签一批预览令牌,避免翻页后只能手动点「重试画布」。 */
|
||||
let previewReauthInFlight = false;
|
||||
/** 页图/原 PDF 令牌 HTTP 失效时自动重签;客户端渲染失败不得走此路径(见 DocumentCanvas)。 */
|
||||
const onDeskCanvasLoadFailed = async () => {
|
||||
if (previewReauthInFlight) {
|
||||
if (previewReauthInFlight || previewAutoReauthCount >= PREVIEW_AUTO_REAUTH_LIMIT) {
|
||||
visualCanvas.value.reportCanvasLoadFailed();
|
||||
return;
|
||||
}
|
||||
previewAutoReauthCount += 1;
|
||||
previewReauthInFlight = true;
|
||||
try {
|
||||
await loadPages();
|
||||
|
||||
+90
-4
@@ -14,11 +14,12 @@ const { getDocumentMock, getPageMock, renderMock } = vi.hoisted(() => ({
|
||||
renderMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('pdfjs-dist', () => ({
|
||||
GlobalWorkerOptions: {},
|
||||
getDocument: (...args: unknown[]) => getDocumentMock(...args),
|
||||
vi.mock('@/shared/utils/pdfjs', () => ({
|
||||
loadPdfJs: async () => ({
|
||||
GlobalWorkerOptions: {},
|
||||
getDocument: (...args: unknown[]) => getDocumentMock(...args),
|
||||
}),
|
||||
}));
|
||||
vi.mock('pdfjs-dist/build/pdf.worker.min.mjs?url', () => ({ default: '/pdf.worker.min.mjs' }));
|
||||
vi.mock('@/shared/utils/auth', () => ({ getAuthHeaders: () => ({ Authorization: 'Bearer test' }) }));
|
||||
|
||||
describe('OrderProfileDocumentCanvas PDF preview', () => {
|
||||
@@ -274,4 +275,89 @@ describe('OrderProfileDocumentCanvas PDF preview', () => {
|
||||
// 使用 PDF.js 原始像素而不是 CSS 缩放后的大小,保证回读与用户框选区域一致。
|
||||
expect(drawImage).toHaveBeenCalledWith(source, 60, 160, 181, 240, 0, 0, 181, 240);
|
||||
});
|
||||
|
||||
it('keeps pdfCanvas mounted under pdfPreview error overlay and does not reauth on render failure', async () => {
|
||||
getDocumentMock.mockReturnValue({
|
||||
promise: Promise.resolve({
|
||||
numPages: 1,
|
||||
getPage: vi.fn(async () => {
|
||||
throw new Error('PDF canvas is unavailable');
|
||||
}),
|
||||
}),
|
||||
});
|
||||
const wrapper = mount(OrderProfileDocumentCanvas, {
|
||||
props: {
|
||||
profileId: 71,
|
||||
pdfPreview: { preview_token: 'single-use-token' },
|
||||
regions: [], pageNo: 1, pageCount: 1,
|
||||
},
|
||||
global: {
|
||||
plugins: [createI18n({
|
||||
legacy: false,
|
||||
locale: 'zh-CN',
|
||||
messages: {
|
||||
'zh-CN': {
|
||||
admin: { shippingOrderProfiles: { workbench: { canvasUnavailable: '受控 PDF 画布暂不可用', retryCanvas: '重试' } } },
|
||||
},
|
||||
},
|
||||
})],
|
||||
},
|
||||
});
|
||||
await flushPromises();
|
||||
await flushPromises();
|
||||
|
||||
// 关键断言:原 PDF 路径失败不得卸掉 canvas,否则重试/reauth 后 render 仍读到 null。
|
||||
expect(wrapper.find('canvas.pdf-page').exists()).toBe(true);
|
||||
expect(wrapper.find('.canvas-error-overlay').exists()).toBe(true);
|
||||
expect(wrapper.emitted('loadFailed')).toBeUndefined();
|
||||
});
|
||||
|
||||
it('reuses in-memory PDF bytes for the same single-use preview token', async () => {
|
||||
const wrapper = mount(OrderProfileDocumentCanvas, {
|
||||
props: {
|
||||
profileId: 71,
|
||||
pdfPreview: { preview_token: 'single-use-token' },
|
||||
regions: [], pageNo: 1, pageCount: 1,
|
||||
},
|
||||
global: { plugins: [createI18n({ legacy: false, locale: 'zh', messages: { zh: {} } })] },
|
||||
});
|
||||
await flushPromises();
|
||||
await flushPromises();
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
|
||||
// 改 grant 依赖重入 watch,但 pdfPreview token 不变;必须走内存缓存,否则 getdel 二次 GET=404。
|
||||
await wrapper.setProps({
|
||||
grant: { page_no: 1, preview_token: 'png-ignored' },
|
||||
pdfPreview: { preview_token: 'single-use-token' },
|
||||
});
|
||||
await flushPromises();
|
||||
await flushPromises();
|
||||
expect(fetch).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('emits loadFailed only for preview-token HTTP failures', async () => {
|
||||
vi.stubGlobal('fetch', vi.fn(async () => new Response('', { status: 404 })));
|
||||
const wrapper = mount(OrderProfileDocumentCanvas, {
|
||||
props: {
|
||||
profileId: 71,
|
||||
pdfPreview: { preview_token: 'dead-token' },
|
||||
regions: [], pageNo: 1, pageCount: 1,
|
||||
},
|
||||
global: {
|
||||
plugins: [createI18n({
|
||||
legacy: false,
|
||||
locale: 'zh-CN',
|
||||
messages: {
|
||||
'zh-CN': {
|
||||
admin: { shippingOrderProfiles: { workbench: { canvasUnavailable: '受控 PDF 画布暂不可用', retryCanvas: '重试' } } },
|
||||
},
|
||||
},
|
||||
})],
|
||||
},
|
||||
});
|
||||
await flushPromises();
|
||||
await flushPromises();
|
||||
expect(wrapper.emitted('loadFailed')).toHaveLength(1);
|
||||
expect(wrapper.find('canvas.pdf-page').exists()).toBe(true);
|
||||
});
|
||||
});
|
||||
+93
-35
@@ -4,6 +4,9 @@
|
||||
依赖:浏览器 fetch、认证请求头、OrderProfileCanvasRegion、isUnboundOrderFieldCanvasRegion。
|
||||
逻辑:父级签发单页令牌并提供分页动作;mode=readonly 时只允许查看/缩放/切页,不允许写入任何标注改动;
|
||||
PNG 预览 token 为一次性消费,组件内按页缓存 blob,翻页回访不再重新拉 token;
|
||||
原 PDF(pdf-preview)令牌亦为 Redis getdel 单次消费:同 token 字节必须缓存,且仅 HTTP 401/403/404
|
||||
才 emit loadFailed 触发父级 reauth;画布/渲染失败不得重签,否则会空转授权风暴;
|
||||
pdfPreview 错误态用 overlay,禁止 v-if 卸掉 pdfCanvas(否则 renderPdfPage 必失败);
|
||||
未绑定订单字段框强制高亮(region--unbound),并暴露 scrollRegionIntoView 供横幅定位删除;
|
||||
选中框用 top/right/bottom/left 定位(避免 height% 在内容撑高容器上失效);
|
||||
拖拽/缩放进行中忽略滚轮缩放,避免触控板纵向手势把高度调整抢走;
|
||||
@@ -16,28 +19,11 @@ import { computed, nextTick, onBeforeUnmount, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { Anchor, ArrowLeft, ArrowRight, Columns3, Copy, Eraser, MessageSquareText, Minus, Plus, Redo2, RotateCcw, Rows3, Save, TableProperties, Tag, TextCursorInput, Trash2, WandSparkles } from 'lucide-vue-next';
|
||||
import { getAuthHeaders } from '@/shared/utils/auth';
|
||||
import { loadPdfJs } from '@/shared/utils/pdfjs';
|
||||
import type { OrderProfileCanvasRegion, OrderProfilePreviewPageGrant } from '@/features/admin/types/shipping-order-document-profile.types';
|
||||
import { isUnboundOrderFieldCanvasRegion } from '../orderProfileForm.utils';
|
||||
import type { PDFDocumentProxy } from 'pdfjs-dist';
|
||||
|
||||
type PdfJsModule = typeof import('pdfjs-dist');
|
||||
let pdfjsLoader: Promise<PdfJsModule> | null = null;
|
||||
|
||||
/** 动态加载 PDF.js 与 worker;坐标 PDF 与 XFA 在受控管理员画布按需共用。 */
|
||||
async function loadPdfJs(): Promise<PdfJsModule> {
|
||||
if (!pdfjsLoader) {
|
||||
pdfjsLoader = (async () => {
|
||||
const [pdfjs, workerMod] = await Promise.all([
|
||||
import('pdfjs-dist'),
|
||||
import('pdfjs-dist/build/pdf.worker.min.mjs?url'),
|
||||
]);
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = workerMod.default;
|
||||
return pdfjs;
|
||||
})();
|
||||
}
|
||||
return pdfjsLoader;
|
||||
}
|
||||
|
||||
const props = defineProps<{
|
||||
profileId: number | null;
|
||||
grant?: OrderProfilePreviewPageGrant | null;
|
||||
@@ -107,6 +93,12 @@ const viewport = ref<HTMLElement | null>(null);
|
||||
const zoom = ref(1);
|
||||
/** 按页缓存已消费 token 拉取的 PNG,翻页回访不再触发一次性 token 失效。 */
|
||||
const pageImageCache = new Map<string, string>();
|
||||
/**
|
||||
* 原 PDF 字节缓存:pdf-preview 令牌是 Redis getdel 单次消费。
|
||||
* 同 token 的并发/重入 loadPage 若再次 GET 会 404,并误触发父级 reauth 风暴。
|
||||
*/
|
||||
let cachedPdfBytes: Uint8Array | null = null;
|
||||
let cachedPdfToken: string | null = null;
|
||||
let loadGeneration = 0;
|
||||
let cachedProfileId: number | null = null;
|
||||
const zoomPercent = computed(() => Math.round(zoom.value * 100));
|
||||
@@ -123,17 +115,34 @@ const emptyStateText = computed(() => (
|
||||
props.emptyHint || t('admin.shippingOrderProfiles.workbench.selectBoundPdf')
|
||||
));
|
||||
|
||||
/**
|
||||
* 等待 pdfCanvas 进入 DOM。
|
||||
* 错误态曾用 v-if 卸掉 canvas;清错后仅一次 nextTick 仍可能读到 null,
|
||||
* 进而抛 "PDF canvas is unavailable",被空 catch 吃掉且 0 console error。
|
||||
*/
|
||||
const ensurePdfCanvas = async (): Promise<{ canvas: HTMLCanvasElement; context: CanvasRenderingContext2D }> => {
|
||||
for (let attempt = 0; attempt < 10; attempt += 1) {
|
||||
await nextTick();
|
||||
const el = pdfCanvas.value;
|
||||
const context = el?.getContext('2d');
|
||||
if (el && context) return { canvas: el, context };
|
||||
await new Promise<void>((resolve) => {
|
||||
if (typeof requestAnimationFrame === 'function') requestAnimationFrame(() => resolve());
|
||||
else window.setTimeout(() => resolve(), 16);
|
||||
});
|
||||
}
|
||||
throw new Error('PDF canvas is unavailable');
|
||||
};
|
||||
|
||||
/**
|
||||
* 将内存中的原 PDF 按真实页面外观流绘制到 Canvas。
|
||||
* 核心逻辑:坐标 PDF 与 hybrid XFA 都用 page.render(),不生成可下载 URL。
|
||||
*/
|
||||
const renderPdfPage = async (pdf: PDFDocumentProxy) => {
|
||||
await nextTick();
|
||||
const targetPage = Math.min(Math.max(props.pageNo, 1), pdf.numPages);
|
||||
const targetPage = Math.min(Math.max(props.pageNo, 1), pdf.numPages || 1);
|
||||
if (pdf.numPages < 1) throw new Error('PDF has no pages');
|
||||
const page = await pdf.getPage(targetPage);
|
||||
const canvas = pdfCanvas.value;
|
||||
const context = canvas?.getContext('2d');
|
||||
if (!canvas || !context) throw new Error('PDF canvas is unavailable');
|
||||
const { canvas, context } = await ensurePdfCanvas();
|
||||
const viewport = page.getViewport({ scale: zoom.value });
|
||||
pdfPageSize.value = { width: viewport.width, height: viewport.height };
|
||||
canvas.width = Math.ceil(viewport.width);
|
||||
@@ -142,6 +151,12 @@ const renderPdfPage = async (pdf: PDFDocumentProxy) => {
|
||||
pdfRendered.value = true;
|
||||
};
|
||||
|
||||
/** 令牌失效类 HTTP 才值得父级 reauth;画布未挂载/渲染失败重签只会空转。 */
|
||||
const isPreviewTokenHttpError = (error: unknown): boolean => {
|
||||
if (!(error instanceof Error)) return false;
|
||||
return /^HTTP (401|403|404)\b/.test(error.message);
|
||||
};
|
||||
|
||||
/**
|
||||
* 回收某次会话内全部页图 blob;切换样本 Profile 或卸载时调用。
|
||||
*/
|
||||
@@ -149,6 +164,8 @@ const clearPageImageCache = () => {
|
||||
for (const url of pageImageCache.values()) URL.revokeObjectURL(url);
|
||||
pageImageCache.clear();
|
||||
inflightPageLoads.clear();
|
||||
cachedPdfBytes = null;
|
||||
cachedPdfToken = null;
|
||||
};
|
||||
|
||||
/** 同一页的并发拉取共用一个 Promise,成功后必入缓存(即使请求已过期)。 */
|
||||
@@ -206,13 +223,21 @@ const loadPage = async () => {
|
||||
|| `/api/admin/shipping-notice/order-document-profiles/${props.profileId}/preview-pages`;
|
||||
if (props.pdfPreview) {
|
||||
imageUrl.value = '';
|
||||
const response = await fetch(
|
||||
`${previewPath}?preview_token=${encodeURIComponent(props.pdfPreview.preview_token)}`,
|
||||
{ headers: getAuthHeaders(), cache: 'no-store' },
|
||||
);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
const token = props.pdfPreview.preview_token;
|
||||
let bytes: Uint8Array;
|
||||
if (cachedPdfToken === token && cachedPdfBytes) {
|
||||
bytes = cachedPdfBytes;
|
||||
} else {
|
||||
const response = await fetch(
|
||||
`${previewPath}?preview_token=${encodeURIComponent(token)}`,
|
||||
{ headers: getAuthHeaders(), cache: 'no-store' },
|
||||
);
|
||||
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
||||
bytes = new Uint8Array(await response.arrayBuffer());
|
||||
cachedPdfBytes = bytes;
|
||||
cachedPdfToken = token;
|
||||
}
|
||||
const pdfjs = await loadPdfJs();
|
||||
const bytes = new Uint8Array(await response.arrayBuffer());
|
||||
pdfDocument = await pdfjs.getDocument({ data: bytes, enableXfa: true }).promise;
|
||||
if (generation !== loadGeneration) return;
|
||||
emit('pageCount', pdfDocument.numPages);
|
||||
@@ -224,7 +249,7 @@ const loadPage = async () => {
|
||||
const blobUrl = await fetchPageImage(previewPath, grant);
|
||||
if (generation !== loadGeneration) return;
|
||||
imageUrl.value = blobUrl;
|
||||
} catch {
|
||||
} catch (error) {
|
||||
if (generation !== loadGeneration) return;
|
||||
const fallback = props.grant ? pageImageCache.get(String(props.grant.page_no)) : null;
|
||||
if (fallback) {
|
||||
@@ -234,7 +259,10 @@ const loadPage = async () => {
|
||||
}
|
||||
imageUrl.value = '';
|
||||
internalLoadError.value = t('admin.shippingOrderProfiles.workbench.canvasUnavailable');
|
||||
emit('loadFailed');
|
||||
// 仅令牌 HTTP 失效才通知父级重签;画布未挂载/PDF.js 渲染失败重签只会烧掉单次 token。
|
||||
if (isPreviewTokenHttpError(error) || (props.grant && error instanceof Error && /^HTTP \d+/.test(error.message))) {
|
||||
emit('loadFailed');
|
||||
}
|
||||
} finally {
|
||||
if (generation === loadGeneration) loading.value = false;
|
||||
}
|
||||
@@ -442,10 +470,20 @@ defineExpose({
|
||||
watch(() => [props.grant?.page_no, props.grant?.preview_token, props.pdfPreview?.preview_token], () => { void loadPage(); }, { immediate: true });
|
||||
watch(() => props.pageNo, async (value) => {
|
||||
pageInput.value = value;
|
||||
if (props.pdfPreview && pdfDocument) await renderPdfPage(pdfDocument);
|
||||
if (!(props.pdfPreview && pdfDocument)) return;
|
||||
try {
|
||||
await renderPdfPage(pdfDocument);
|
||||
} catch {
|
||||
/* 翻页时画布可能短暂卸载;下一次 load/retry 会恢复 */
|
||||
}
|
||||
});
|
||||
watch(zoom, async () => {
|
||||
if (props.pdfPreview && pdfDocument) await renderPdfPage(pdfDocument);
|
||||
if (!(props.pdfPreview && pdfDocument)) return;
|
||||
try {
|
||||
await renderPdfPage(pdfDocument);
|
||||
} catch {
|
||||
/* 缩放同翻页:避免未捕获 Promise 干扰控制台 */
|
||||
}
|
||||
});
|
||||
onBeforeUnmount(() => {
|
||||
endMove();
|
||||
@@ -494,7 +532,8 @@ onBeforeUnmount(() => {
|
||||
</div>
|
||||
</header>
|
||||
<div v-if="loading && !pdfPreview" class="canvas-state">{{ t('admin.shippingOrderProfiles.workbench.loadingPage') }}</div>
|
||||
<div v-else-if="displayLoadError" class="canvas-state canvas-state--error" role="alert">
|
||||
<!-- PNG 路径仍可用整页错误态;原 PDF 路径必须保留 canvas 挂载,否则 renderPdfPage 必抛 canvas unavailable。 -->
|
||||
<div v-else-if="displayLoadError && !pdfPreview" class="canvas-state canvas-state--error" role="alert">
|
||||
<p>{{ displayLoadError }}</p>
|
||||
<button type="button" class="canvas-retry" @click="onRetryClick">
|
||||
{{ t('admin.shippingOrderProfiles.workbench.retryCanvas') }}
|
||||
@@ -592,6 +631,12 @@ onBeforeUnmount(() => {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="displayLoadError && pdfPreview" class="canvas-error-overlay" role="alert">
|
||||
<p>{{ displayLoadError }}</p>
|
||||
<button type="button" class="canvas-retry" @click="onRetryClick">
|
||||
{{ t('admin.shippingOrderProfiles.workbench.retryCanvas') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
@@ -635,7 +680,20 @@ onBeforeUnmount(() => {
|
||||
cursor: pointer;
|
||||
}
|
||||
.canvas-retry:hover { border-color: #60a5fa; background: #26364f; }
|
||||
.canvas-work-area { display: flex; min-height: 0; flex: 1; gap: .6rem; }
|
||||
.canvas-work-area { position: relative; display: flex; min-height: 0; flex: 1; gap: .6rem; }
|
||||
.canvas-error-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
z-index: 8;
|
||||
display: grid;
|
||||
place-content: center;
|
||||
gap: .75rem;
|
||||
background: rgb(15 23 42 / .82);
|
||||
color: #fecaca;
|
||||
font-size: .875rem;
|
||||
text-align: center;
|
||||
padding: 1rem;
|
||||
}
|
||||
.canvas-work-area.readonly { gap: 0; }
|
||||
.canvas-viewport { position: relative; min-width: 0; flex: 1; overflow: auto; }
|
||||
.canvas-viewport.panning { cursor: grab; }
|
||||
|
||||
@@ -10,7 +10,9 @@ import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
BookOpen,
|
||||
CheckCircle2,
|
||||
ChevronDown,
|
||||
ChevronRight,
|
||||
ChevronUp,
|
||||
ClipboardCheck,
|
||||
Edit,
|
||||
FileQuestion,
|
||||
@@ -105,6 +107,19 @@ const directVideoResources = computed(() => contentResources.value.filter((resou
|
||||
resource.resource_type === 'agent_guide'
|
||||
&& videoGuideCandidates.value.some((guide) => guide.id === resource.agent_guide_id)
|
||||
)));
|
||||
// 培训视频上传列表默认收起:超过阈值仅展示前 N 条,底部按钮可展开查看全部,避免视频过多时页面过长
|
||||
const DIRECT_VIDEO_PREVIEW_COUNT = 3;
|
||||
const isDirectVideoExpanded = ref(false);
|
||||
const hasMoreDirectVideos = computed(() => directVideoResources.value.length > DIRECT_VIDEO_PREVIEW_COUNT);
|
||||
const directVideoVisibleResources = computed(() => (
|
||||
hasMoreDirectVideos.value && !isDirectVideoExpanded.value
|
||||
? directVideoResources.value.slice(0, DIRECT_VIDEO_PREVIEW_COUNT)
|
||||
: directVideoResources.value
|
||||
));
|
||||
/** 切换培训视频上传列表展开/收起:收起仅保留前 N 条,其余视频仍在表单资源中参与保存。 */
|
||||
const toggleDirectVideoExpanded = () => {
|
||||
isDirectVideoExpanded.value = !isDirectVideoExpanded.value;
|
||||
};
|
||||
const contentResources = computed(() => form.value.resources.filter((resource) => resource.resource_type !== 'inline_questions'));
|
||||
const trainingLevels: TrainingLevel[] = ['company', 'department', 'team'];
|
||||
const guideGroups = computed(() => {
|
||||
@@ -263,6 +278,18 @@ const pushLeanTaskNow = async () => {
|
||||
if (!leanTask.value || isPushingLeanTask.value) return;
|
||||
isPushingLeanTask.value = true;
|
||||
try {
|
||||
// [STEP] 表单与已保存任务不一致(如刚勾选新视频未发布)时自动先保存再补推:
|
||||
// 补推只作用于服务端冻结清单,不先保存会按旧清单推送而误报“全部视频已推送完毕”
|
||||
if (isLeanTaskFormDirty()) {
|
||||
try {
|
||||
await persistLeanTask();
|
||||
msg.success(t('admin.trainingConfig.lean.autoSavedBeforePush'));
|
||||
} catch (error) {
|
||||
// 自动保存失败(含周次校验拦截)时终止补推,具体原因已提示
|
||||
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.saveFailed'));
|
||||
return;
|
||||
}
|
||||
}
|
||||
const log = await pushAdminLeanTrainingWeeklyTask(leanTask.value.id);
|
||||
if (log.status === 'completed') {
|
||||
msg.warning(t('admin.trainingConfig.lean.pushCompleted'));
|
||||
@@ -318,27 +345,53 @@ const toggleLeanVideo = (resourceId: number) => {
|
||||
: [...leanVideoResourceIds.value, resourceId];
|
||||
};
|
||||
|
||||
const saveLeanTask = async () => {
|
||||
/**
|
||||
* 判断精益周任务表单是否与已保存任务不一致(勾选/周次/截止/对象/每周数量任一变更即视为脏)。
|
||||
* AI 触发时机:点击【立即新增任务补推】时必须先感知未保存变更并自动保存——补推只作用于服务端冻结清单,
|
||||
* 不自动保存会按旧清单推送而误报“全部视频已推送完毕”。
|
||||
*/
|
||||
const isLeanTaskFormDirty = (): boolean => {
|
||||
const task = leanTask.value;
|
||||
if (!task) return false;
|
||||
if (JSON.stringify(leanVideoResourceIds.value) !== JSON.stringify(task.video_resource_ids || [])) return true;
|
||||
if (leanWeekKey.value !== (task.week_key || '')) return true;
|
||||
if (Number(leanWeeklyCount.value) !== Number(task.weekly_count || 1)) return true;
|
||||
const savedDueAtMs = Date.parse(task.due_at || '');
|
||||
if (!Number.isNaN(savedDueAtMs) && Math.abs(Date.parse(leanDueAt.value) - savedDueAtMs) > 1000) return true;
|
||||
const normalizeTargets = (values: Array<string | number> | undefined) => JSON.stringify([...(values || [])].map(String).sort());
|
||||
if (normalizeTargets(leanTargetRoles.value) !== normalizeTargets(task.target_roles)) return true;
|
||||
if (normalizeTargets(leanTargetUserIds.value) !== normalizeTargets(task.target_user_ids)) return true;
|
||||
return false;
|
||||
};
|
||||
|
||||
/**
|
||||
* 保存精益周任务表单到服务端(【发布周任务】与【补推前自动保存】共用同一持久化入口)。
|
||||
* 校验失败或接口失败时抛出异常,由调用方决定提示方式与是否继续后续动作。
|
||||
*/
|
||||
const persistLeanTask = async () => {
|
||||
// 任务周必须为周一:date input 允许选任意日期,前端先行拦截,后端同规则兜底校验
|
||||
if (!leanWeekKey.value || new Date(`${leanWeekKey.value}T00:00:00`).getDay() !== 1) {
|
||||
msg.warning(t('admin.trainingConfig.lean.weekMustBeMonday'));
|
||||
return;
|
||||
throw new Error(t('admin.trainingConfig.lean.weekMustBeMonday'));
|
||||
}
|
||||
leanTask.value = await createOrUpdateAdminLeanTrainingWeeklyTask({
|
||||
// 任务周/截止时间支持修改:按表单所选周创建或更新,发布/补推均作用于所选周任务(周任务规则 7)
|
||||
week_key: leanWeekKey.value,
|
||||
due_at: new Date(leanDueAt.value).toISOString(),
|
||||
// 未勾选任何视频时传空数组,服务端自动按上传时间倒序冻结全部视频(周任务规则 6)
|
||||
video_resource_ids: leanVideoResourceIds.value,
|
||||
target_roles: leanTargetRoles.value,
|
||||
target_user_ids: leanTargetUserIds.value,
|
||||
weekly_count: leanWeeklyCount.value,
|
||||
});
|
||||
// 保存后回填勾选状态(空选择时服务端可能已自动填充全部视频)
|
||||
leanVideoResourceIds.value = leanTask.value?.video_resource_ids ? [...leanTask.value.video_resource_ids] : [];
|
||||
await loadLeanPushLogs();
|
||||
};
|
||||
|
||||
const saveLeanTask = async () => {
|
||||
isSavingLeanTask.value = true;
|
||||
try {
|
||||
leanTask.value = await createOrUpdateAdminLeanTrainingWeeklyTask({
|
||||
// 任务周/截止时间支持修改:按表单所选周创建或更新,发布/补推均作用于所选周任务(周任务规则 7)
|
||||
week_key: leanWeekKey.value,
|
||||
due_at: new Date(leanDueAt.value).toISOString(),
|
||||
// 未勾选任何视频时传空数组,服务端自动按上传时间倒序冻结全部视频(周任务规则 6)
|
||||
video_resource_ids: leanVideoResourceIds.value,
|
||||
target_roles: leanTargetRoles.value,
|
||||
target_user_ids: leanTargetUserIds.value,
|
||||
weekly_count: leanWeeklyCount.value,
|
||||
});
|
||||
// 保存后回填勾选状态(空选择时服务端可能已自动填充全部视频)
|
||||
leanVideoResourceIds.value = leanTask.value?.video_resource_ids ? [...leanTask.value.video_resource_ids] : [];
|
||||
await loadLeanPushLogs();
|
||||
await persistLeanTask();
|
||||
msg.success(t('admin.trainingConfig.messages.leanTaskSaved'));
|
||||
} catch (error) {
|
||||
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.saveFailed'));
|
||||
@@ -414,6 +467,8 @@ const selectConfig = (config: TrainingConfig) => {
|
||||
questionJsonText.value = JSON.stringify(questions, null, 2);
|
||||
questionSourceVersionId.value = null;
|
||||
questionParseMeta.value = null;
|
||||
// 切换培训类型时培训视频上传列表恢复默认收起,避免上一配置的展开状态带入
|
||||
isDirectVideoExpanded.value = false;
|
||||
void loadLeanTask();
|
||||
};
|
||||
|
||||
@@ -702,6 +757,8 @@ const uploadTrainingVideo = async (event: Event) => {
|
||||
required_duration: 0,
|
||||
sort_order: form.value.resources.length,
|
||||
});
|
||||
// 新上传的视频排在列表末尾,自动展开避免用户以为上传失败找不到新视频
|
||||
isDirectVideoExpanded.value = true;
|
||||
msg.success(t('admin.trainingConfig.messages.videoUploaded'));
|
||||
} catch (error) {
|
||||
msg.error(error instanceof Error ? error.message : t('admin.trainingConfig.messages.videoUploadFailed'));
|
||||
@@ -907,11 +964,19 @@ onMounted(() => void load());
|
||||
</div>
|
||||
<div class="space-y-3 p-4 md:p-5">
|
||||
<div v-if="!directVideoResources.length" class="rounded-xl border border-dashed border-default bg-surface-soft/50 px-3 py-8 text-center text-xs text-muted">{{ t('admin.trainingConfig.directVideo.empty') }}</div>
|
||||
<div v-for="(resource, index) in directVideoResources" v-else :key="resource.id || `direct-video-${index}`" class="grid gap-3 rounded-xl border border-default bg-white p-4 md:grid-cols-[minmax(0,1fr)_180px_auto] md:items-end">
|
||||
<div class="flex min-w-0 items-center gap-2 text-sm font-medium text-primary"><Video class="h-4 w-4 shrink-0 text-violet-500" /><span class="truncate">{{ resource.title || videoGuideCandidates.find((guide) => guide.id === resource.agent_guide_id)?.file_name || t('admin.trainingConfig.directVideo.unnamed') }}</span></div>
|
||||
<label class="label-field">{{ t('admin.trainingConfig.fields.requiredDuration') }}<input v-model.number="resource.required_duration" type="number" min="0" class="input-field mt-2" /></label>
|
||||
<button class="btn-danger btn-sm" type="button" @click="removeResource(resource)"><Trash2 class="h-4 w-4" />{{ t('admin.delete') }}</button>
|
||||
</div>
|
||||
<!-- 培训视频上传列表默认收起:超过阈值仅展示前 N 条,底部可展开查看全部 -->
|
||||
<template v-else>
|
||||
<div v-for="(resource, index) in directVideoVisibleResources" :key="resource.id || `direct-video-${index}`" class="grid gap-3 rounded-xl border border-default bg-white p-4 md:grid-cols-[minmax(0,1fr)_180px_auto] md:items-end">
|
||||
<div class="flex min-w-0 items-center gap-2 text-sm font-medium text-primary"><Video class="h-4 w-4 shrink-0 text-violet-500" /><span class="truncate">{{ resource.title || videoGuideCandidates.find((guide) => guide.id === resource.agent_guide_id)?.file_name || t('admin.trainingConfig.directVideo.unnamed') }}</span></div>
|
||||
<label class="label-field">{{ t('admin.trainingConfig.fields.requiredDuration') }}<input v-model.number="resource.required_duration" type="number" min="0" class="input-field mt-2" /></label>
|
||||
<button class="btn-danger btn-sm" type="button" @click="removeResource(resource)"><Trash2 class="h-4 w-4" />{{ t('admin.delete') }}</button>
|
||||
</div>
|
||||
<button v-if="hasMoreDirectVideos" class="flex w-full items-center justify-center gap-1.5 rounded-xl border border-dashed border-default bg-surface-soft/50 px-3 py-2.5 text-xs font-medium text-secondary transition hover:bg-surface-soft" type="button" @click="toggleDirectVideoExpanded">
|
||||
<ChevronDown v-if="!isDirectVideoExpanded" class="h-4 w-4" />
|
||||
<ChevronUp v-else class="h-4 w-4" />
|
||||
{{ isDirectVideoExpanded ? t('admin.trainingConfig.directVideo.collapseList') : t('admin.trainingConfig.directVideo.expandAll', { count: directVideoResources.length }) }}
|
||||
</button>
|
||||
</template>
|
||||
</div>
|
||||
</article>
|
||||
<article
|
||||
|
||||
@@ -218,19 +218,13 @@ onMounted(() => {
|
||||
>
|
||||
{{ t('admin.role.' + user.role) }}
|
||||
</span>
|
||||
<div v-if="user.feature_permissions?.training_hr_manage || user.feature_permissions?.['contract_payment.access']" class="mt-2 flex flex-wrap gap-1.5">
|
||||
<div v-if="user.feature_permissions?.training_hr_manage" class="mt-2 flex flex-wrap gap-1.5">
|
||||
<span
|
||||
v-if="user.feature_permissions?.training_hr_manage"
|
||||
class="inline-flex rounded-full border border-brand-100 bg-brand-50 px-2.5 py-0.5 text-xs font-medium text-brand-700"
|
||||
>
|
||||
{{ t('admin.user.fields.trainingHrManage') }}
|
||||
</span>
|
||||
<span
|
||||
v-if="user.feature_permissions?.['contract_payment.access']"
|
||||
class="inline-flex rounded-full border border-brand-100 bg-brand-50 px-2.5 py-0.5 text-xs font-medium text-brand-700"
|
||||
>
|
||||
{{ t('admin.user.fields.contractPaymentAccess') }}
|
||||
</span>
|
||||
</div>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-right">
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
/**
|
||||
* features/admin/modules/users/components/UserFormModal.vue
|
||||
* 创建/编辑用户弹窗,含角色与功能权限勾选(培训 HR、合同付款预警访问)。
|
||||
* 创建/编辑用户弹窗,含角色与培训 HR 功能权限勾选。
|
||||
*/
|
||||
<script setup lang="ts">
|
||||
import { useI18n } from 'vue-i18n';
|
||||
|
||||
Reference in new issue
Block a user