feat(shipping-notice): 新增订单行与字段冲突管理功能,支持字段冲突查询与解决
This commit is contained in:
1 parent
4fbaed2b4c
commit
9da0481fc3
74 files changed
+4861
-375
No files matched your search
@@ -0,0 +1,111 @@
|
||||
<!--
|
||||
features/chat/components/ShippingTaskFieldConflictPanel.vue
|
||||
用途:展示并解决任务级订单字段冲突(keep / take incoming)。
|
||||
依赖:shipping.api.resolveWorkspaceShippingFieldConflict、vue-i18n、useMessage。
|
||||
逻辑:由 ShippingTaskParsedResultCard 挂载;解决成功后 emit refreshed 让父级重拉 Task Detail。
|
||||
-->
|
||||
<script setup lang="ts">
|
||||
import { computed, ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import { resolveWorkspaceShippingFieldConflict } from '@/features/chat/api/shipping.api';
|
||||
import type { ShippingFieldConflict } from '@/features/chat/types/shipping.api.types';
|
||||
import { useMessage } from '@/shared/composables/useMessage';
|
||||
|
||||
const props = defineProps<{
|
||||
taskNo: string;
|
||||
conflicts?: ShippingFieldConflict[] | null;
|
||||
orderDataVersion?: number | null;
|
||||
}>();
|
||||
|
||||
const emit = defineEmits<{
|
||||
refreshed: [];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const msg = useMessage();
|
||||
const resolvingId = ref<number | null>(null);
|
||||
|
||||
const openConflicts = computed(() =>
|
||||
(props.conflicts || []).filter((item) => String(item.status || '') === 'open'),
|
||||
);
|
||||
|
||||
/**
|
||||
* 解决单条冲突。
|
||||
* 核心逻辑:携带 conflict_version 与 order_data_version;409 时提示刷新。
|
||||
*/
|
||||
async function resolveConflict(
|
||||
conflict: ShippingFieldConflict,
|
||||
resolution: 'keep_existing' | 'take_incoming',
|
||||
) {
|
||||
if (!props.taskNo || resolvingId.value != null) return;
|
||||
resolvingId.value = conflict.id;
|
||||
try {
|
||||
await resolveWorkspaceShippingFieldConflict(props.taskNo, conflict.id, {
|
||||
resolution,
|
||||
expectedConflictVersion: conflict.conflict_version,
|
||||
expectedOrderDataVersion: props.orderDataVersion ?? undefined,
|
||||
idempotencyKey: `conflict-${conflict.id}-${resolution}-${conflict.conflict_version}`,
|
||||
});
|
||||
msg.success(t('chat.shippingFieldConflict.resolveSuccess'));
|
||||
emit('refreshed');
|
||||
} catch (err) {
|
||||
msg.error(err instanceof Error ? err.message : t('chat.shippingFieldConflict.resolveFailed'));
|
||||
} finally {
|
||||
resolvingId.value = null;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
v-if="openConflicts.length"
|
||||
class="space-y-2 rounded-lg border border-rose-200 bg-rose-50/80 px-2.5 py-2"
|
||||
>
|
||||
<div class="text-[11px] font-semibold text-rose-900">
|
||||
{{ t('chat.shippingFieldConflict.title', { count: openConflicts.length }) }}
|
||||
</div>
|
||||
<div class="text-[11px] leading-5 text-rose-800">
|
||||
{{ t('chat.shippingFieldConflict.hint') }}
|
||||
</div>
|
||||
<ul class="space-y-2">
|
||||
<li
|
||||
v-for="conflict in openConflicts"
|
||||
:key="conflict.id"
|
||||
class="rounded-md border border-rose-200 bg-white/90 px-2.5 py-2 text-[11px]"
|
||||
>
|
||||
<div class="font-medium text-rose-900">
|
||||
<span v-if="conflict.position != null">#{{ Number(conflict.position) + 1 }} · </span>
|
||||
<span class="font-mono">{{ conflict.field_name }}</span>
|
||||
</div>
|
||||
<div class="mt-1 grid gap-1 text-slate-700 sm:grid-cols-2">
|
||||
<div>
|
||||
<span class="text-muted">{{ t('chat.shippingFieldConflict.existing') }}:</span>
|
||||
<span class="ml-1 font-mono">{{ conflict.existing_value || '—' }}</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="text-muted">{{ t('chat.shippingFieldConflict.incoming') }}:</span>
|
||||
<span class="ml-1 font-mono">{{ conflict.incoming_value || '—' }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="mt-2 flex flex-wrap gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded border border-slate-300 bg-white px-2 py-1 text-[11px] font-medium hover:bg-slate-50 disabled:opacity-50"
|
||||
:disabled="resolvingId != null"
|
||||
@click="resolveConflict(conflict, 'keep_existing')"
|
||||
>
|
||||
{{ t('chat.shippingFieldConflict.keepExisting') }}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
class="rounded border border-rose-300 bg-rose-100 px-2 py-1 text-[11px] font-medium text-rose-900 hover:bg-rose-200 disabled:opacity-50"
|
||||
:disabled="resolvingId != null"
|
||||
@click="resolveConflict(conflict, 'take_incoming')"
|
||||
>
|
||||
{{ t('chat.shippingFieldConflict.takeIncoming') }}
|
||||
</button>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user