refactor(express/waybill): 下线更新轨迹接口与按钮,保留轨迹查询标签页
- 移除 waybill.warehouse.updateTrace / updateTraceTaskProgress 接口封装、参数类型与模块导出 - 移除工具栏「更新轨迹」按钮、按钮动作、任务进度轮询及进度弹窗 - 清理配置中的接口注册与导入 - 轨迹面板空态文案不再提示「更新轨迹」 - 保留 waybill.warehouse.getTrace 与「轨迹」标签页 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
parent
b2d53e3b72
commit
3fa899d02d
@ -247,72 +247,6 @@ export function waybillWarehouseUpdateReceiveTaskProgress(
|
||||
} as any)
|
||||
}
|
||||
|
||||
// ============ waybill.warehouse.updateTrace ============
|
||||
|
||||
/** waybill.warehouse.updateTrace 请求参数(waybillCodes 与 where 二选一,同时传入时 waybillCodes 优先) */
|
||||
export type WaybillWarehouseUpdateTraceParams = {
|
||||
/** 运单号列表(字符串数组),优先于 where */
|
||||
waybillCodes?: string[]
|
||||
/** waybillCodes 的下划线别名,二者取其一 */
|
||||
waybill_codes?: string[]
|
||||
/**
|
||||
* 与 waybill.warehouse.list 一致的筛选条件(不含分页/排序)。
|
||||
* 服务端先解析命中的运单号再执行;超过 5000 条时直接失败,不做截断。
|
||||
*/
|
||||
where?: WaybillWarehouseListWhere
|
||||
}
|
||||
|
||||
/**
|
||||
* waybill.warehouse.updateTrace:批量更新运单物流轨迹-仓库侧
|
||||
*
|
||||
* 调用外部接口 waybill.getTrace 查询轨迹(单批最多 10 单,超出自动切批),
|
||||
* 结果按 (express_id, op_time, scan_type) 幂等写入 wms_order_express_trace。
|
||||
* 异步任务模式:返回任务受理信息(任务 ID 前缀 waybill_trace_),进度用 updateTraceTaskProgress 查询。
|
||||
* 仓库未配置承接该回调方法的 API 应用时直接失败,不创建任务。
|
||||
*/
|
||||
export function waybillWarehouseUpdateTrace(
|
||||
data: WaybillWarehouseUpdateTraceParams
|
||||
): Promise<any> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'waybill.warehouse.updateTrace',
|
||||
v,
|
||||
timestamp: Date.now()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
// ============ waybill.warehouse.updateTraceTaskProgress ============
|
||||
|
||||
/** waybill.warehouse.updateTraceTaskProgress 请求参数 */
|
||||
export type WaybillWarehouseUpdateTraceTaskProgressParams = {
|
||||
/** 异步任务ID(前缀 waybill_trace_)。与 taskId 二选一 */
|
||||
task_id?: string
|
||||
/** 异步任务ID(别名,优先使用)。至少传入 taskId 或 task_id 之一 */
|
||||
taskId?: string
|
||||
}
|
||||
|
||||
/** waybill.warehouse.updateTraceTaskProgress:运单物流轨迹更新进度查询-仓库侧 */
|
||||
export function waybillWarehouseUpdateTraceTaskProgress(
|
||||
data: WaybillWarehouseUpdateTraceTaskProgressParams
|
||||
): Promise<any> {
|
||||
return request({
|
||||
url: '/system',
|
||||
method: 'post',
|
||||
params: {
|
||||
method: 'waybill.warehouse.updateTraceTaskProgress',
|
||||
v,
|
||||
timestamp: Date.now()
|
||||
},
|
||||
data,
|
||||
isSystemApi: true
|
||||
} as any)
|
||||
}
|
||||
|
||||
// ============ waybill.warehouse.getTrace ============
|
||||
|
||||
/** waybill.warehouse.getTrace 请求参数 */
|
||||
@ -346,7 +280,7 @@ export type WaybillWarehouseTraceItem = {
|
||||
/**
|
||||
* waybill.warehouse.getTrace:查询单个运单的全部物流轨迹-仓库侧
|
||||
*
|
||||
* 只读接口:仅查 wms_order_express_trace 中 updateTrace 已落库的数据,不调外部接口。
|
||||
* 只读接口:仅查 wms_order_express_trace 中已落库的轨迹数据,不调外部接口。
|
||||
* 不分页,按 op_time DESC, id DESC 返回;无数据时返回空列表(不报错)。
|
||||
*/
|
||||
export function waybillWarehouseGetTrace(
|
||||
@ -374,7 +308,5 @@ export const waybillWarehouseModule = {
|
||||
exportTaskProgress: waybillWarehouseExportTaskProgress,
|
||||
updateReceive: waybillWarehouseUpdateReceive,
|
||||
updateReceiveTaskProgress: waybillWarehouseUpdateReceiveTaskProgress,
|
||||
updateTrace: waybillWarehouseUpdateTrace,
|
||||
updateTraceTaskProgress: waybillWarehouseUpdateTraceTaskProgress,
|
||||
getTrace: waybillWarehouseGetTrace
|
||||
}
|
||||
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
<div v-if="loading" class="empty-tip">加载中…</div>
|
||||
<div v-else-if="error" class="empty-tip">{{ error }}</div>
|
||||
<div v-else-if="!traceList.length" class="empty-tip">暂无轨迹数据,可先点击「更新轨迹」拉取</div>
|
||||
<div v-else-if="!traceList.length" class="empty-tip">暂无轨迹数据</div>
|
||||
<div v-else class="trace-timeline">
|
||||
<div
|
||||
v-for="(item, index) in traceList"
|
||||
|
||||
@ -8,8 +8,6 @@
|
||||
* - waybillWarehouseExport → waybill.warehouse.export 运单导出
|
||||
* - waybillWarehouseUpdateReceive → waybill.warehouse.updateReceive 批量更新揽收
|
||||
* - waybillWarehouseUpdateReceiveTaskProgress → waybill.warehouse.updateReceiveTaskProgress 揽收更新进度
|
||||
* - waybillWarehouseUpdateTrace → waybill.warehouse.updateTrace 批量更新物流轨迹
|
||||
* - waybillWarehouseUpdateTraceTaskProgress → waybill.warehouse.updateTraceTaskProgress 轨迹更新进度
|
||||
* - waybillWarehouseGetTrace → waybill.warehouse.getTrace 单运单物流轨迹
|
||||
*/
|
||||
|
||||
@ -23,8 +21,6 @@ import {
|
||||
waybillWarehouseExportTaskProgress,
|
||||
waybillWarehouseUpdateReceive,
|
||||
waybillWarehouseUpdateReceiveTaskProgress,
|
||||
waybillWarehouseUpdateTrace,
|
||||
waybillWarehouseUpdateTraceTaskProgress,
|
||||
waybillWarehouseGetTrace,
|
||||
} from '@/api/waybill.warehouse'
|
||||
|
||||
@ -583,10 +579,6 @@ export interface TabPageApiConfig {
|
||||
updateReceive?: ApiMethod
|
||||
/** 揽收状态更新任务进度查询 */
|
||||
updateReceiveProgress?: ApiMethod
|
||||
/** 批量更新运单物流轨迹(异步任务) */
|
||||
updateTrace?: ApiMethod
|
||||
/** 物流轨迹更新任务进度查询 */
|
||||
updateTraceProgress?: ApiMethod
|
||||
/** 单个运单的物流轨迹查询(明细面板「轨迹」标签页) */
|
||||
trace?: ApiMethod
|
||||
scanBoxOptions?: Record<string, ApiMethod>
|
||||
@ -915,23 +907,7 @@ export const TOOLBAR_BUTTONS: Record<string, ToolbarButtonConfig> = {
|
||||
{ label: '更新选中', action: 'handleUpdateReceiveSelected' },
|
||||
{ label: '更新全部(当前筛选)', action: 'handleUpdateReceiveAll', divided: true }
|
||||
]
|
||||
},
|
||||
updateTrace: {
|
||||
key: 'updateTrace',
|
||||
label: '更新轨迹',
|
||||
category: 'function',
|
||||
size: 'small',
|
||||
type: 'warning',
|
||||
plain: true,
|
||||
loadingKey: 'traceLoading',
|
||||
// 两种范围:选中 / 当前筛选全部;未勾选时的提示由 handleUpdateTraceSelected 内部处理。
|
||||
action: 'handleUpdateTraceSelected',
|
||||
buttonType: 'dropdown',
|
||||
dropdownOptions: [
|
||||
{ label: '更新选中', action: 'handleUpdateTraceSelected' },
|
||||
{ label: '更新全部(当前筛选)', action: 'handleUpdateTraceAll', divided: true }
|
||||
]
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function getTabToolbarButtons(tabName: string): ToolbarButtonConfig[] {
|
||||
@ -1063,8 +1039,6 @@ export const tabPages: TabPageRawConfig[] = [
|
||||
exportProgress: waybillWarehouseExportTaskProgress as ApiMethod,
|
||||
updateReceive: waybillWarehouseUpdateReceive as ApiMethod,
|
||||
updateReceiveProgress: waybillWarehouseUpdateReceiveTaskProgress as ApiMethod,
|
||||
updateTrace: waybillWarehouseUpdateTrace as ApiMethod,
|
||||
updateTraceProgress: waybillWarehouseUpdateTraceTaskProgress as ApiMethod,
|
||||
trace: waybillWarehouseGetTrace as ApiMethod,
|
||||
parseListResponse(res: any) {
|
||||
const data = res?.data ?? res
|
||||
|
||||
@ -263,20 +263,6 @@
|
||||
:error-text="receiveProgressState.error"
|
||||
@close="closeReceiveProgress"
|
||||
/>
|
||||
|
||||
<!-- 批量更新物流轨迹(waybill.warehouse.updateTrace 异步任务) -->
|
||||
<TaskProgressDialog
|
||||
v-if="traceProgressVisible"
|
||||
:visible="traceProgressVisible"
|
||||
title="更新物流轨迹"
|
||||
:polling="traceProgressPolling"
|
||||
:task-id="traceProgressState.taskId"
|
||||
:progress-percent="traceProgressState.progress"
|
||||
:status-label="traceProgressStatusLabel"
|
||||
:error-text="traceProgressState.error"
|
||||
:result-text="traceProgressPolling ? '' : traceProgressState.message"
|
||||
@close="closeTraceProgress"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@ -490,8 +476,7 @@ const buttonDisabledMap = computed<Record<string, boolean>>(() => ({
|
||||
const buttonLoadingMap = computed<Record<string, boolean>>(() => ({
|
||||
loading: loading.value,
|
||||
exportLoading: exportLoading.value,
|
||||
receiveLoading: receiveLoading.value,
|
||||
traceLoading: traceLoading.value
|
||||
receiveLoading: receiveLoading.value
|
||||
}))
|
||||
|
||||
const buttonLabelMap = computed<Record<string, string>>(() => ({
|
||||
@ -597,9 +582,7 @@ const toolbarActionMap: Record<string, () => void> = {
|
||||
handleExportAll: () => { void handleExportAll() },
|
||||
openTransferByWaybillsDialog: () => { openTransferByWaybillsDialog() },
|
||||
handleUpdateReceiveSelected: () => { void handleUpdateReceiveSelected() },
|
||||
handleUpdateReceiveAll: () => { void handleUpdateReceiveAll() },
|
||||
handleUpdateTraceSelected: () => { void handleUpdateTraceSelected() },
|
||||
handleUpdateTraceAll: () => { void handleUpdateTraceAll() }
|
||||
handleUpdateReceiveAll: () => { void handleUpdateReceiveAll() }
|
||||
}
|
||||
|
||||
function handleToolbarButtonClick(action: string) {
|
||||
@ -1051,151 +1034,6 @@ async function handleUpdateReceiveAll() {
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 批量更新物流轨迹(waybill.warehouse.updateTrace)
|
||||
// ============================================================
|
||||
|
||||
/** 提交中(按钮 loading / 防重复提交) */
|
||||
const traceLoading = ref(false)
|
||||
|
||||
/** 服务端按筛选条件解析运单号时的单次上限(超过即失败,不做截断) */
|
||||
const TRACE_MAX_CODES = 5000
|
||||
|
||||
const {
|
||||
visible: traceProgressVisible,
|
||||
polling: traceProgressPolling,
|
||||
state: traceProgressState,
|
||||
startPolling: startTracePolling,
|
||||
close: closeTraceProgress
|
||||
} = useTaskProgress({
|
||||
interval: 1500,
|
||||
// 200 次 × 1.5s ≈ 5 分钟上限,超时后提示刷新查看结果
|
||||
maxAttempts: 200,
|
||||
pollFn: async (taskId: string) => {
|
||||
const cfg = currentTabConfig.value
|
||||
if (!cfg?.api?.updateTraceProgress) throw new Error('轨迹进度接口未配置')
|
||||
const res = await cfg.api.updateTraceProgress({ task_id: taskId })
|
||||
return normalizeTaskProgress(res)
|
||||
},
|
||||
onSuccess: async () => {
|
||||
ElMessage.success('物流轨迹更新完成')
|
||||
upperTableRef.value?.clearSelection?.()
|
||||
selectedRows.value = []
|
||||
await loadData()
|
||||
},
|
||||
onError: (error: string) => {
|
||||
ElMessage.error(error || '物流轨迹更新失败')
|
||||
}
|
||||
})
|
||||
|
||||
const traceProgressStatusLabel = computed(() => {
|
||||
const map: Record<string, string> = {
|
||||
submitted: '已提交',
|
||||
running: '处理中',
|
||||
success: '已完成',
|
||||
completed: '已完成',
|
||||
failed: '失败',
|
||||
error: '错误'
|
||||
}
|
||||
return map[traceProgressState.status] || traceProgressState.status || '—'
|
||||
})
|
||||
|
||||
/** 提交物流轨迹更新任务(运单号 / 筛选条件 二选一) */
|
||||
async function submitTraceTask(payload: { waybillCodes?: string[]; where?: Record<string, any> }) {
|
||||
const cfg = currentTabConfig.value
|
||||
if (!cfg?.api?.updateTrace) {
|
||||
throw new Error('物流轨迹更新接口未配置')
|
||||
}
|
||||
|
||||
const res = await cfg.api.updateTrace(payload)
|
||||
const taskPayload = parseTaskPayload(res)
|
||||
const taskId = String(taskPayload.task_id || taskPayload.taskId || '').trim()
|
||||
if (!taskId) {
|
||||
throw new Error(taskPayload.message || res?.message || '物流轨迹更新任务提交失败')
|
||||
}
|
||||
const countText = payload.waybillCodes?.length
|
||||
? `${payload.waybillCodes.length} 个运单`
|
||||
: '当前筛选条件下的运单'
|
||||
ElMessage.success(`已提交${countText}的物流轨迹更新任务`)
|
||||
// 异步任务:不 await,轮询由进度弹窗接管
|
||||
void startTracePolling(taskId)
|
||||
}
|
||||
|
||||
/** 勾选运单 → 提交物流轨迹更新任务 → 轮询进度 */
|
||||
async function handleUpdateTraceSelected() {
|
||||
if (traceLoading.value) return
|
||||
if (!selectedRows.value.length) {
|
||||
ElMessage.warning('请先勾选需要更新物流轨迹的运单')
|
||||
return
|
||||
}
|
||||
|
||||
const waybillCodes = selectedRows.value
|
||||
.map((row: any) => String(row?.waybill_code ?? row?.waybillCode ?? '').trim())
|
||||
.filter(Boolean)
|
||||
|
||||
if (!waybillCodes.length) {
|
||||
ElMessage.warning('勾选的运单缺少运单号,无法更新物流轨迹')
|
||||
return
|
||||
}
|
||||
|
||||
traceLoading.value = true
|
||||
try {
|
||||
await submitTraceTask({ waybillCodes })
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '物流轨迹更新失败')
|
||||
} finally {
|
||||
traceLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/** 按当前筛选条件全部更新(接口直接接收 where,由服务端解析运单号) */
|
||||
async function handleUpdateTraceAll() {
|
||||
if (traceLoading.value) return
|
||||
|
||||
const conditions = scanBoxRef.value?.getConditions?.() || {}
|
||||
const where = buildWhereConditions(conditions)
|
||||
// 没有任何筛选条件时,避免误把整表全部更新
|
||||
if (!Object.keys(where).length) {
|
||||
ElMessage.warning('请先在筛选区设置条件(如创建时间)后,再使用「更新全部」')
|
||||
return
|
||||
}
|
||||
|
||||
if (pagination.total > TRACE_MAX_CODES) {
|
||||
ElMessage.warning(
|
||||
`当前筛选命中 ${pagination.total} 条,超过单次更新上限 ${TRACE_MAX_CODES} 条,请缩小筛选范围(如缩小创建时间)`
|
||||
)
|
||||
return
|
||||
}
|
||||
|
||||
const totalText = pagination.total > 0
|
||||
? `当前筛选共 ${pagination.total} 条运单`
|
||||
: '当前筛选命中的全部运单'
|
||||
|
||||
try {
|
||||
await ElMessageBox.confirm(
|
||||
`将按当前筛选条件批量更新物流轨迹:${totalText}。任务在后台执行,完成后可重新查询确认。`,
|
||||
'更新全部物流轨迹',
|
||||
{
|
||||
confirmButtonText: '开始更新',
|
||||
cancelButtonText: '取消',
|
||||
type: 'warning',
|
||||
buttonSize: 'small'
|
||||
}
|
||||
)
|
||||
} catch {
|
||||
return
|
||||
}
|
||||
|
||||
traceLoading.value = true
|
||||
try {
|
||||
await submitTraceTask({ where })
|
||||
} catch (e: any) {
|
||||
ElMessage.error(e?.message || '更新全部物流轨迹失败')
|
||||
} finally {
|
||||
traceLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// 明细面板
|
||||
// ============================================================
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user