feat(shipping-notice): 增强订单抽取功能,添加进度事件和诊断运行管理,优化数据模型和访问控制
This commit is contained in:
1 parent
ce26d6d0c4
commit
c4095b08da
175 files changed
+13064
-1814
No files matched your search
+100
-14
@@ -8,7 +8,7 @@
|
||||
import { computed, onMounted, reactive, ref, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { useRouter } from 'vue-router';
|
||||
import { ArrowUpRight, Check, CircleDotDashed, FileCheck2, Layers3, Plus, Send, Tags, Workflow } from 'lucide-vue-next';
|
||||
import { ArrowUpRight, Check, CircleDotDashed, CircleHelp, FileCheck2, Layers3, Plus, Send, Tags, Workflow } from 'lucide-vue-next';
|
||||
import { BusinessError } from '@/shared/api/client';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
import {
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
saveShippingIdentityDefinition,
|
||||
saveShippingIdentityRuleSet,
|
||||
} from '@/features/admin/api/shipping-identity-rules.api';
|
||||
import type { ShippingIdentityRuleCatalog, ShippingIdentityRuleSet } from '@/features/admin/types/shipping-identity-rules.types';
|
||||
import type { ShippingIdentityDefinition, ShippingIdentityRuleCatalog, ShippingIdentityRuleSet } from '@/features/admin/types/shipping-identity-rules.types';
|
||||
|
||||
const { t } = useI18n();
|
||||
const router = useRouter();
|
||||
@@ -32,15 +32,14 @@ const loading = ref(false);
|
||||
const saving = ref(false);
|
||||
const form = reactive({
|
||||
display_name: '', description: '', evidence_label: '', target_type: 'customer', context_field_id: '',
|
||||
default_weight: 100,
|
||||
default_weight: 100, max_automation: 'none' as 'none' | 'conditional',
|
||||
});
|
||||
|
||||
const selectedDefinitionCount = computed(() => selectedDefinitionIds.value.length);
|
||||
const activeDefinitions = computed(() => catalog.value?.definitions.filter((item) => item.status === 'active') || []);
|
||||
const publishedRuleSet = computed(() => ruleSets.value.find((item) => item.status === 'published') || null);
|
||||
const selectedAutomation = computed(() => {
|
||||
const field = catalog.value?.context_fields.find((item) => item.field_id === form.context_field_id);
|
||||
return field?.field_category === 'general_context' && form.target_type === 'customer' ? 'conditional' : 'none';
|
||||
return form.max_automation;
|
||||
});
|
||||
|
||||
/** 说明当前来源实际从何处取值和自动化边界,帮助管理员在提交前理解选择结果。 */
|
||||
@@ -75,12 +74,66 @@ const load = async (): Promise<void> => {
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* 将定义写接口返回的最新数据合并到本地目录,避免保存后整页重新加载并打断管理员当前操作。
|
||||
* @param definition - 后端已校验并保存的识别定义。
|
||||
*/
|
||||
const upsertDefinition = (definition: ShippingIdentityDefinition): void => {
|
||||
if (!catalog.value) return;
|
||||
const index = catalog.value.definitions.findIndex((item) => item.id === definition.id);
|
||||
if (index === -1) {
|
||||
catalog.value.definitions = [...catalog.value.definitions, definition];
|
||||
return;
|
||||
}
|
||||
catalog.value.definitions.splice(index, 1, definition);
|
||||
};
|
||||
|
||||
/**
|
||||
* 用规则集写接口返回的快照更新本地版本列表,保留当前页面的编辑位置和加载状态。
|
||||
* @param ruleSet - 后端返回的最新规则集版本。
|
||||
*/
|
||||
const upsertRuleSet = (ruleSet: ShippingIdentityRuleSet): void => {
|
||||
const index = ruleSets.value.findIndex((item) => item.id === ruleSet.id);
|
||||
if (index === -1) {
|
||||
ruleSets.value = [ruleSet, ...ruleSets.value];
|
||||
return;
|
||||
}
|
||||
ruleSets.value.splice(index, 1, ruleSet);
|
||||
};
|
||||
|
||||
const saveDefinition = async (): Promise<void> => {
|
||||
saving.value = true;
|
||||
try {
|
||||
await saveShippingIdentityDefinition({ ...form });
|
||||
Object.assign(form, { display_name: '', description: '', evidence_label: '' });
|
||||
await load();
|
||||
const saved = await saveShippingIdentityDefinition({ ...form });
|
||||
upsertDefinition(saved);
|
||||
Object.assign(form, { display_name: '', description: '', evidence_label: '', max_automation: 'none' });
|
||||
message.success(t('admin.shippingIdentityRules.definitionSaved'));
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
} finally {
|
||||
saving.value = false;
|
||||
}
|
||||
};
|
||||
|
||||
/** 更新已有定义的自动化授权;已发布快照不变,下一次发布规则集时才会生效。 */
|
||||
const updateDefinitionAutomation = async (
|
||||
definition: ShippingIdentityDefinition,
|
||||
maxAutomation: 'none' | 'conditional',
|
||||
): Promise<void> => {
|
||||
if (definition.max_automation === maxAutomation) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
const saved = await saveShippingIdentityDefinition({
|
||||
definition_code: definition.definition_code,
|
||||
display_name: definition.display_name,
|
||||
description: definition.description,
|
||||
evidence_label: definition.evidence_label,
|
||||
target_type: definition.target_type,
|
||||
context_field_id: definition.context_field_id,
|
||||
default_weight: definition.default_weight,
|
||||
max_automation: maxAutomation,
|
||||
}, definition.id);
|
||||
upsertDefinition(saved);
|
||||
message.success(t('admin.shippingIdentityRules.definitionSaved'));
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
@@ -95,8 +148,8 @@ const createDraft = async (): Promise<void> => {
|
||||
const draft = await createShippingIdentityRuleSet({
|
||||
copy_from_rule_set_id: ruleSets.value.find((item) => item.status === 'published')?.id,
|
||||
});
|
||||
upsertRuleSet(draft);
|
||||
selectedRuleSet.value = draft;
|
||||
await load();
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
} finally {
|
||||
@@ -112,8 +165,8 @@ const saveDraft = async (): Promise<void> => {
|
||||
expected_lock_version: selectedRuleSet.value.lock_version,
|
||||
definition_ids: selectedDefinitionIds.value,
|
||||
});
|
||||
upsertRuleSet(saved);
|
||||
selectedRuleSet.value = saved;
|
||||
await load();
|
||||
message.success(t('admin.shippingIdentityRules.ruleSetSaved'));
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
@@ -123,11 +176,21 @@ const saveDraft = async (): Promise<void> => {
|
||||
};
|
||||
|
||||
const publishDraft = async (): Promise<void> => {
|
||||
if (!selectedRuleSet.value || selectedRuleSet.value.status !== 'draft') return;
|
||||
if (!selectedRuleSet.value || selectedRuleSet.value.status !== 'draft' || !selectedDefinitionCount.value) return;
|
||||
saving.value = true;
|
||||
try {
|
||||
await publishShippingIdentityRuleSet(selectedRuleSet.value.id, selectedRuleSet.value.lock_version);
|
||||
await load();
|
||||
// 发布必须先持久化当前勾选,避免投产上一次保存的旧规则快照。
|
||||
const saved = await saveShippingIdentityRuleSet(selectedRuleSet.value.id, {
|
||||
expected_lock_version: selectedRuleSet.value.lock_version,
|
||||
definition_ids: selectedDefinitionIds.value,
|
||||
});
|
||||
const published = await publishShippingIdentityRuleSet(saved.id, saved.lock_version);
|
||||
// 新发布版本会替代旧发布版本;本地同步状态而不重新装载整页。
|
||||
ruleSets.value = ruleSets.value.map((item) => (
|
||||
item.status === 'published' && item.id !== published.id ? { ...item, status: 'retired' } : item
|
||||
));
|
||||
upsertRuleSet(published);
|
||||
selectedRuleSet.value = published;
|
||||
message.success(t('admin.shippingIdentityRules.ruleSetPublished'));
|
||||
} catch (error) {
|
||||
showError(error);
|
||||
@@ -185,7 +248,7 @@ onMounted(() => { void load(); });
|
||||
<div class="identity-definition-row__icon"><Tags class="h-4 w-4" /></div>
|
||||
<div class="min-w-0"><strong>{{ definition.display_name }}</strong><p>{{ definition.description || sourceDisplay(definition) }}</p></div>
|
||||
<span class="identity-target">{{ t(`admin.shippingIdentityRules.targets.${definition.target_type}`) }}</span>
|
||||
<span class="identity-automation" :class="{ 'identity-automation--enabled': definition.max_automation === 'conditional' }">{{ t(`admin.shippingIdentityRules.automations.${definition.max_automation}`) }}</span>
|
||||
<select class="identity-automation identity-automation-select" :class="{ 'identity-automation--enabled': definition.max_automation === 'conditional' }" :value="definition.max_automation" :disabled="saving" @change="updateDefinitionAutomation(definition, ($event.target as HTMLSelectElement).value as 'none' | 'conditional')"><option value="none">{{ t('admin.shippingIdentityRules.automations.none') }}</option><option value="conditional">{{ t('admin.shippingIdentityRules.automations.conditional') }}</option></select>
|
||||
</article>
|
||||
</div>
|
||||
<div v-else class="identity-empty"><Tags class="h-5 w-5" /><span>{{ t('admin.shippingIdentityRules.definitionHint') }}</span></div>
|
||||
@@ -198,6 +261,7 @@ onMounted(() => { void load(); });
|
||||
<label><span>{{ t('admin.shippingIdentityRules.target') }}</span><select v-model="form.target_type" class="input-field"><option value="customer">{{ t('admin.shippingIdentityRules.targets.customer') }}</option><option value="site">{{ t('admin.shippingIdentityRules.targets.site') }}</option></select></label>
|
||||
<label><span>{{ t('admin.shippingIdentityRules.evidenceLabel') }}</span><input v-model="form.evidence_label" required class="input-field" :placeholder="t('admin.shippingIdentityRules.evidenceLabelPlaceholder')"></label>
|
||||
<label><span>{{ t('admin.shippingIdentityRules.description') }}</span><input v-model="form.description" class="input-field" :placeholder="t('admin.shippingIdentityRules.descriptionPlaceholder')"></label>
|
||||
<label><span class="identity-label-with-tip">{{ t('admin.shippingIdentityRules.automationPolicy') }}<CircleHelp class="identity-label-tip" :title="t('admin.shippingIdentityRules.automationPolicyHint')" :aria-label="t('admin.shippingIdentityRules.automationPolicyHint')" /></span><select v-model="form.max_automation" class="input-field"><option value="none">{{ t('admin.shippingIdentityRules.automations.none') }}</option><option value="conditional">{{ t('admin.shippingIdentityRules.automations.conditional') }}</option></select></label>
|
||||
<div class="identity-source-help"><strong>{{ t('admin.shippingIdentityRules.selectionResult') }}</strong><span>{{ selectedSourceHint }}</span><small>{{ t(`admin.shippingIdentityRules.automations.${selectedAutomation}`) }}</small></div>
|
||||
<button type="submit" class="btn-primary identity-definition-form__submit" :disabled="saving || !form.context_field_id"><Plus class="h-4 w-4" />{{ t('admin.shippingIdentityRules.addDefinition') }}</button>
|
||||
</form>
|
||||
@@ -222,6 +286,17 @@ onMounted(() => { void load(); });
|
||||
<input v-model="selectedDefinitionIds" type="checkbox" :value="definition.id"><span>{{ definition.display_name }}</span><small>{{ t(`admin.shippingIdentityRules.targets.${definition.target_type}`) }}</small>
|
||||
</label>
|
||||
</div>
|
||||
<div v-else-if="selectedRuleSet" class="identity-published-definitions">
|
||||
<div class="identity-selection__heading"><span>{{ t('admin.shippingIdentityRules.publishedDefinitions') }}</span><strong>{{ selectedRuleSet.definition?.definitions.length || 0 }}</strong></div>
|
||||
<div v-if="selectedRuleSet.definition?.definitions.length" class="identity-published-definition-list">
|
||||
<div v-for="definition in selectedRuleSet.definition.definitions" :key="definition.id" class="identity-published-definition">
|
||||
<div><strong>{{ definition.display_name }}</strong><small>{{ definition.context_field?.display_name || definition.context_field?.field_code || '-' }}</small></div>
|
||||
<span class="identity-target">{{ t(`admin.shippingIdentityRules.targets.${definition.target_type}`) }}</span>
|
||||
<span class="identity-automation" :class="{ 'identity-automation--enabled': definition.max_automation === 'conditional' }">{{ t(`admin.shippingIdentityRules.automations.${definition.max_automation}`) }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<p v-else class="identity-published-empty">{{ t('admin.shippingIdentityRules.publishedDefinitionsEmpty') }}</p>
|
||||
</div>
|
||||
|
||||
<div v-if="selectedRuleSet" class="identity-publication__actions">
|
||||
<template v-if="selectedRuleSet.status === 'draft'">
|
||||
@@ -266,12 +341,16 @@ onMounted(() => { void load(); });
|
||||
.identity-definition-row strong { color: #1a3856; font-size: .86rem; font-weight: 750; }
|
||||
.identity-definition-row p { overflow: hidden; margin-top: .18rem; color: #8194a8; font-size: .72rem; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.identity-target, .identity-automation { padding: .32rem .52rem; border-radius: 999px; background: #f1f5f8; color: #677f98; font-size: .7rem; white-space: nowrap; }
|
||||
.identity-automation-select { border: 1px solid #dce8ef; cursor: pointer; }
|
||||
.identity-automation--enabled { background: #e4f8ef; color: #12865c; }
|
||||
.identity-empty { display: flex; align-items: center; gap: .55rem; min-height: 5.5rem; padding: 1.2rem 1.35rem; color: #7c91a7; font-size: .82rem; }
|
||||
.identity-definition-form { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: .85rem; padding: 1.1rem 1.35rem 1.35rem; background: linear-gradient(135deg, #f7fbfd 0%, #f3f9fc 100%); }
|
||||
.identity-form-title { grid-column: 1 / -1; display: flex; align-items: center; gap: .42rem; color: #173857; font-size: .85rem; }
|
||||
.identity-form-guide { grid-column: 1 / -1; margin: -.45rem 0 .1rem; color: #73889e; font-size: .75rem; line-height: 1.55; }
|
||||
.identity-definition-form label { display: grid; gap: .35rem; color: #667f99; font-size: .72rem; font-weight: 700; }
|
||||
.identity-label-with-tip { display: inline-flex; align-items: center; gap: .28rem; }
|
||||
.identity-label-tip { width: .9rem; height: .9rem; color: #7d93a8; cursor: help; }
|
||||
.identity-label-tip:focus-visible { border-radius: 50%; outline: 2px solid #7cc7eb; outline-offset: 2px; }
|
||||
.identity-definition-form label small { color: #8295a8; font-size: .67rem; font-weight: 500; line-height: 1.35; }
|
||||
.identity-definition-form .input-field, .identity-static-field { box-sizing: border-box; min-width: 0; height: 2.75rem; padding: 0 .8rem; border-color: #d9e7ef; background: #fff; font-size: .83rem; line-height: 1.25; }
|
||||
.identity-definition-form select.input-field { padding-top: 0; padding-bottom: 0; line-height: 2.75rem; }
|
||||
@@ -288,6 +367,13 @@ onMounted(() => { void load(); });
|
||||
.identity-version:hover, .identity-version--selected { border-color: #0b91cd; background: #eefaff; color: #087cae; }
|
||||
.identity-version span { font-weight: 800; }.identity-version small { font-size: .68rem; }
|
||||
.identity-selection { margin: 1rem 0; }
|
||||
.identity-published-definitions { margin: 1rem 0; }
|
||||
.identity-published-definition-list { display: grid; gap: .45rem; }
|
||||
.identity-published-definition { display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: .5rem; align-items: center; padding: .58rem .65rem; border: 1px solid #e5eef3; border-radius: .6rem; background: #fbfdfe; }
|
||||
.identity-published-definition strong, .identity-published-definition small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.identity-published-definition strong { color: #294660; font-size: .76rem; }
|
||||
.identity-published-definition small { margin-top: .15rem; color: #8194a8; font-size: .68rem; }
|
||||
.identity-published-empty { margin: 0; color: #8194a8; font-size: .76rem; }
|
||||
.identity-selection__heading { display: flex; justify-content: space-between; margin-bottom: .6rem; color: #274563; font-size: .78rem; font-weight: 750; }
|
||||
.identity-selection__heading strong { color: #0a8bc4; }
|
||||
.identity-check-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: .5rem; padding: .54rem 0; border-bottom: 1px dashed #e2ebf1; color: #37516c; font-size: .78rem; }
|
||||
|
||||
Reference in new issue
Block a user