- task-progress 新增 tags 表单字段类型与 SelectedTags 组件,任务弹窗可展示 已选订单/运单/出库单标签并支持逐个移除,样式对齐「编辑投递计划」输入行 - 更新备注、更新订单备注/地址、同步订单号、分配储位、批量异步任务等表单, 以及待处理/异常/复核/波次面板接入该能力,提交前可核对并调整已选项 - 新增 orderTagItems 工具:按行或按 ids 顺序生成标签,兼容 id / order_id 与 delivery_order_code / order_code 等字段差异 - waybill.warehouse 新增 updateReceive、updateReceiveTaskProgress 异步接口, 运单页新增「更新揽收状态」工具栏按钮,接入任务进度轮询、结果汇总与列表刷新 - 库存批量编辑、出库单批量作废、收货列表等页面同步接入已选项标签展示 - UnifiedTaskProgressDialog 补充 remove-field-item 事件透传,保持各任务弹窗行为一致
642 lines
15 KiB
Vue
642 lines
15 KiB
Vue
<template>
|
||
<div class="task-panel" :class="`is-${mode}`">
|
||
<header class="task-panel__head">
|
||
<div class="task-panel__titles">
|
||
<h2>{{ title }}</h2>
|
||
<p v-if="subtitle">{{ subtitle }}</p>
|
||
</div>
|
||
|
||
<span v-if="taskId" class="task-panel__task">任务ID:{{ taskId }}</span>
|
||
|
||
<button v-if="closable" class="task-panel__close" type="button" aria-label="关闭" @click="emit('close')">
|
||
<svg viewBox="0 0 12 12" fill="none">
|
||
<path d="M1 1L11 11M11 1L1 11" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" />
|
||
</svg>
|
||
</button>
|
||
</header>
|
||
|
||
<div class="task-panel__body">
|
||
<template v-if="mode === 'form'">
|
||
<div v-if="fields.length" class="task-panel__form">
|
||
<div
|
||
v-for="field in fields"
|
||
:key="field.label"
|
||
class="task-panel__field"
|
||
:class="{ 'is-tags': field.type === 'tags' }"
|
||
>
|
||
<span class="task-panel__field-label">{{ field.label }}</span>
|
||
<!-- 标签列表:逐个展示已选数据,标签可移除(移除后由调用方同步数据) -->
|
||
<div v-if="field.type === 'tags'" class="task-panel__field-tags">
|
||
<el-tag
|
||
v-for="item in field.items || []"
|
||
:key="item.value"
|
||
size="small"
|
||
:closable="field.closable !== false"
|
||
@close="emit('remove-field-item', field, item)"
|
||
>{{ item.label }}</el-tag>
|
||
<span v-if="!(field.items && field.items.length)" class="task-panel__field-empty">
|
||
{{ field.emptyText || '—' }}
|
||
</span>
|
||
</div>
|
||
<button
|
||
v-else-if="field.type === 'switch'"
|
||
type="button"
|
||
class="task-panel__switch"
|
||
:class="{ 'is-on': field.active, 'is-clickable': field.interactive }"
|
||
:disabled="!field.interactive"
|
||
@click="emit('toggle-field', field)"
|
||
>
|
||
<i></i>
|
||
</button>
|
||
<strong v-else class="task-panel__field-value">{{ field.value ?? '—' }}</strong>
|
||
</div>
|
||
</div>
|
||
<!-- 表单态自定义扩展区(如:展示已选订单 ID 列表) -->
|
||
<slot name="form-extra" />
|
||
<p v-if="formTip" class="task-panel__form-tip">{{ formTip }}</p>
|
||
</template>
|
||
|
||
<template v-else>
|
||
<div v-if="summary && summary.length" class="task-panel__summary">
|
||
<div v-for="item in summary" :key="item.label" class="task-panel__summary-item">
|
||
<span>{{ item.label }}</span>
|
||
<strong>{{ item.value }}</strong>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="task-panel__progress">
|
||
<div class="task-panel__progress-head">
|
||
<div class="task-panel__percent">{{ displayPercent }}<em>%</em></div>
|
||
<div class="task-panel__state">
|
||
<strong>{{ statusLabel }}</strong>
|
||
<span v-if="detail">{{ animateDetail ? smoothDetail : detail }}</span>
|
||
</div>
|
||
<span v-if="etaLabel" class="task-panel__eta">{{ etaLabel }}</span>
|
||
</div>
|
||
|
||
<CheetahProgressBar :progress="smoothPercent" :state="state" />
|
||
|
||
<div v-if="metrics && metrics.length" class="task-panel__metrics">
|
||
<div v-for="item in metrics" :key="item.label" class="task-panel__metric">
|
||
<span>{{ item.label }}</span>
|
||
<strong><AnimatedNumber :value="item.value" /><em v-if="item.unit">{{ item.unit }}</em></strong>
|
||
</div>
|
||
</div>
|
||
|
||
<p v-if="message" class="task-panel__message">{{ message }}</p>
|
||
<p v-if="error" class="task-panel__error">{{ error }}</p>
|
||
</div>
|
||
|
||
<div v-if="resultIds.length" class="task-panel__ids">
|
||
<span>{{ resultIdsLabel }}</span>
|
||
<p>{{ resultIds.join('、') }}</p>
|
||
</div>
|
||
|
||
<p v-if="tip" class="task-panel__tip" :class="{ 'is-primary': tipType === 'primary' }">{{ tip }}</p>
|
||
</template>
|
||
</div>
|
||
|
||
<footer v-if="showFooter && $slots.footer" class="task-panel__foot">
|
||
<slot name="footer" />
|
||
</footer>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, watch } from 'vue'
|
||
import AnimatedNumber from './AnimatedNumber.vue'
|
||
import CheetahProgressBar from './CheetahProgressBar.vue'
|
||
import { estimateRemainingText } from './estimate'
|
||
import { useSmoothNumber, useSmoothNumericText } from './smoothing'
|
||
import type {
|
||
ProgressFormField,
|
||
ProgressFormFieldItem,
|
||
ProgressMetricItem,
|
||
ProgressState,
|
||
ProgressSummaryItem
|
||
} from './types'
|
||
|
||
const props = withDefaults(
|
||
defineProps<{
|
||
title: string
|
||
subtitle?: string
|
||
taskId?: string
|
||
/** form:提交前参数;progress:任务进度 */
|
||
mode?: 'form' | 'progress'
|
||
state?: ProgressState
|
||
/** 0-100 */
|
||
progress?: number
|
||
/** 优先于 state 的默认文案 */
|
||
statusText?: string
|
||
/** 进度下方的明细,如「已处理 1,286 / 2,040」 */
|
||
detail?: string
|
||
/** 已用时长(毫秒):传入后自动按「已用 × (100-进度)/进度」估算剩余时间 */
|
||
elapsedMs?: number
|
||
/** 右侧胶囊,如「预计剩余 6秒」;传入则优先于 elapsedMs 估算结果 */
|
||
etaText?: string
|
||
/** 参数摘要(仓库 / 策略 / 范围…) */
|
||
summary?: ProgressSummaryItem[]
|
||
/** 统计指标(匹配 / 未匹配 / 耗时…) */
|
||
metrics?: ProgressMetricItem[]
|
||
/** 表单态字段 */
|
||
fields?: ProgressFormField[]
|
||
/** 表单态提示 */
|
||
formTip?: string
|
||
/** 进度态结果 ID 列表 */
|
||
resultIds?: Array<string | number>
|
||
resultIdsLabel?: string
|
||
/** 进度态底部提示 */
|
||
tip?: string
|
||
/** 提示文案样式:default 灰色 / primary 蓝色 */
|
||
tipType?: 'default' | 'primary'
|
||
message?: string
|
||
error?: string
|
||
closable?: boolean
|
||
/** 是否显示底部操作区;由任务状态自动控制的弹窗可关闭 */
|
||
showFooter?: boolean
|
||
/** 明细里的数字是否补间(明细含时间/日期时建议关闭) */
|
||
animateDetail?: boolean
|
||
}>(),
|
||
{
|
||
state: 'running',
|
||
mode: 'progress',
|
||
progress: 0,
|
||
closable: true,
|
||
showFooter: true,
|
||
subtitle: '',
|
||
taskId: '',
|
||
statusText: '',
|
||
detail: '',
|
||
etaText: '',
|
||
elapsedMs: 0,
|
||
summary: () => [],
|
||
metrics: () => [],
|
||
fields: () => [],
|
||
formTip: '',
|
||
resultIds: () => [],
|
||
resultIdsLabel: '订单ID',
|
||
tip: '',
|
||
tipType: 'default',
|
||
message: '',
|
||
error: '',
|
||
/** 进度明细里的数字是否补间(含时间/日期的明细建议关闭) */
|
||
animateDetail: true
|
||
}
|
||
)
|
||
|
||
const emit = defineEmits<{
|
||
(e: 'close'): void
|
||
(e: 'toggle-field', field: ProgressFormField): void
|
||
(e: 'remove-field-item', field: ProgressFormField, item: ProgressFormFieldItem): void
|
||
}>()
|
||
|
||
const roundedPercent = computed(() => {
|
||
const value = Number(props.progress || 0)
|
||
if (!Number.isFinite(value)) return 0
|
||
return Math.min(100, Math.max(0, Math.round(value)))
|
||
})
|
||
|
||
/** 接口返回的目标进度(未取整),用于平滑动画 */
|
||
const targetPercent = computed(() => {
|
||
const value = Number(props.progress || 0)
|
||
if (!Number.isFinite(value)) return 0
|
||
return Math.min(100, Math.max(0, value))
|
||
})
|
||
|
||
const { value: smoothPercent, snapTo: snapPercent } = useSmoothNumber(() => targetPercent.value)
|
||
const displayPercent = computed(() => Math.round(smoothPercent.value))
|
||
|
||
const { value: smoothDetail, snapTo: snapDetail } = useSmoothNumericText(() =>
|
||
props.animateDetail ? props.detail : ''
|
||
)
|
||
|
||
/** 结束态直接对齐,避免进度条绿色后还缓慢爬行、数字继续追赶 */
|
||
watch(
|
||
() => props.state,
|
||
(state) => {
|
||
if (state === 'running') return
|
||
snapPercent()
|
||
snapDetail()
|
||
}
|
||
)
|
||
|
||
const statusLabel = computed(() => {
|
||
if (props.statusText) return props.statusText
|
||
if (props.state === 'success') return '处理完成'
|
||
if (props.state === 'failed') return '处理失败'
|
||
return '处理中'
|
||
})
|
||
|
||
/** 优先用调用方给的文案,否则根据已用时长本地预估 */
|
||
const etaLabel = computed(
|
||
() => props.etaText || estimateRemainingText(roundedPercent.value, props.elapsedMs, props.state)
|
||
)
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.task-panel {
|
||
background: #fff;
|
||
color: #303133;
|
||
|
||
&__head {
|
||
display: flex;
|
||
align-items: flex-start;
|
||
gap: 12px;
|
||
/* 对齐 el-dialog 默认:容器 padding 16 + header 下内边距 16 */
|
||
padding: 16px 16px 16px;
|
||
}
|
||
|
||
&__titles {
|
||
flex: 1;
|
||
min-width: 0;
|
||
|
||
h2 {
|
||
margin: 0;
|
||
font-size: 18px;
|
||
line-height: 24px;
|
||
font-weight: 400;
|
||
color: #303133;
|
||
}
|
||
|
||
p {
|
||
margin: 4px 0 0;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
}
|
||
}
|
||
|
||
&__task {
|
||
flex: none;
|
||
font-size: 12px;
|
||
line-height: 24px;
|
||
color: #909399;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
&__close {
|
||
width: 24px;
|
||
height: 24px;
|
||
flex: none;
|
||
display: inline-flex;
|
||
align-items: center;
|
||
justify-content: center;
|
||
border: none;
|
||
border-radius: 4px;
|
||
background: transparent;
|
||
color: #909399;
|
||
cursor: pointer;
|
||
transition: color 0.2s;
|
||
|
||
svg {
|
||
width: 12px;
|
||
height: 12px;
|
||
}
|
||
|
||
&:hover {
|
||
color: #409eff;
|
||
}
|
||
}
|
||
|
||
&__body {
|
||
/* 对齐「新增投递计划」.form-body:标题下再留 12px */
|
||
padding: 12px 16px 0;
|
||
}
|
||
|
||
/* ---------- 参数摘要 ---------- */
|
||
&__summary {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
|
||
gap: 8px;
|
||
margin-bottom: 12px;
|
||
}
|
||
|
||
&__summary-item {
|
||
padding: 8px 12px;
|
||
border: 1px solid #ebeef5;
|
||
border-radius: 4px;
|
||
background: #fafafa;
|
||
|
||
span {
|
||
display: block;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
margin-bottom: 2px;
|
||
}
|
||
|
||
strong {
|
||
display: block;
|
||
font-size: 13px;
|
||
line-height: 20px;
|
||
font-weight: 500;
|
||
color: #303133;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
}
|
||
|
||
/* ---------- 进度面板 ---------- */
|
||
&__progress {
|
||
padding: 12px 14px 10px;
|
||
border: 1px solid #e4e7ed;
|
||
border-radius: 4px;
|
||
background: #fafcff;
|
||
}
|
||
|
||
&__progress-head {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 12px;
|
||
}
|
||
|
||
&__percent {
|
||
flex: none;
|
||
white-space: nowrap;
|
||
font-size: 28px;
|
||
line-height: 1;
|
||
font-weight: 500;
|
||
color: #409eff;
|
||
font-variant-numeric: tabular-nums;
|
||
|
||
em {
|
||
font-style: normal;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
color: #909399;
|
||
margin-left: 2px;
|
||
}
|
||
}
|
||
|
||
&__state {
|
||
flex: 1;
|
||
min-width: 0;
|
||
|
||
strong {
|
||
display: block;
|
||
font-size: 13px;
|
||
line-height: 20px;
|
||
font-weight: 500;
|
||
color: #303133;
|
||
}
|
||
|
||
span {
|
||
display: block;
|
||
margin-top: 2px;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #606266;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
}
|
||
|
||
&__eta {
|
||
flex: none;
|
||
padding: 2px 8px;
|
||
border: 1px solid #d9ecff;
|
||
border-radius: 4px;
|
||
background: #ecf5ff;
|
||
font-size: 12px;
|
||
line-height: 20px;
|
||
color: #409eff;
|
||
font-variant-numeric: tabular-nums;
|
||
}
|
||
|
||
&__metrics {
|
||
display: grid;
|
||
grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
|
||
margin-top: 12px;
|
||
padding-top: 10px;
|
||
border-top: 1px solid #ebeef5;
|
||
}
|
||
|
||
&__metric {
|
||
span {
|
||
display: block;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
margin-bottom: 2px;
|
||
}
|
||
|
||
strong {
|
||
font-size: 15px;
|
||
line-height: 22px;
|
||
font-weight: 500;
|
||
color: #303133;
|
||
font-variant-numeric: tabular-nums;
|
||
|
||
em {
|
||
font-style: normal;
|
||
font-size: 12px;
|
||
font-weight: 400;
|
||
color: #909399;
|
||
margin-left: 1px;
|
||
}
|
||
}
|
||
}
|
||
|
||
&__message {
|
||
margin: 8px 0 0;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #409eff;
|
||
}
|
||
|
||
&__error {
|
||
margin: 8px 0 0;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #f56c6c;
|
||
}
|
||
|
||
&__ids {
|
||
margin-top: 10px;
|
||
padding-top: 8px;
|
||
border-top: 1px solid #ebeef5;
|
||
|
||
span {
|
||
font-size: 12px;
|
||
color: #909399;
|
||
}
|
||
|
||
p {
|
||
margin: 4px 0 0;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #606266;
|
||
word-break: break-all;
|
||
}
|
||
}
|
||
|
||
&__tip {
|
||
margin: 8px 0 0;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
|
||
&.is-primary {
|
||
color: #409eff;
|
||
}
|
||
}
|
||
|
||
/* ---------- 表单态 ---------- */
|
||
&__form {
|
||
display: flex;
|
||
flex-direction: column;
|
||
gap: 8px;
|
||
}
|
||
|
||
&__field {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 16px;
|
||
min-height: 40px;
|
||
padding: 8px 12px;
|
||
border: 1px solid #ebeef5;
|
||
border-radius: 4px;
|
||
background: #fafafa;
|
||
}
|
||
|
||
/* 标签列固定宽度(含必填星号占位):对齐「手工录入运单号」表单,保证各行标签/值对齐 */
|
||
&__field-label {
|
||
flex: none;
|
||
width: 88px;
|
||
padding-left: 10px;
|
||
box-sizing: border-box;
|
||
font-size: 12px;
|
||
line-height: 20px;
|
||
color: #606266;
|
||
text-align: left;
|
||
white-space: nowrap;
|
||
}
|
||
|
||
&__field-value {
|
||
font-size: 13px;
|
||
font-weight: 500;
|
||
color: #303133;
|
||
text-align: right;
|
||
}
|
||
|
||
/* 标签型字段:对齐「编辑投递计划 - 投递时间」的输入行(无灰底、无边框,标签直接铺开) */
|
||
&__field.is-tags {
|
||
align-items: flex-start;
|
||
min-height: 0;
|
||
padding: 4px 0 0 12px;
|
||
border: none;
|
||
border-radius: 0;
|
||
background: transparent;
|
||
|
||
.task-panel__field-label {
|
||
padding-top: 2px;
|
||
}
|
||
}
|
||
|
||
&__field-tags {
|
||
flex: 1;
|
||
min-width: 0;
|
||
display: flex;
|
||
flex-wrap: wrap;
|
||
align-content: flex-start;
|
||
gap: 6px;
|
||
max-height: 148px;
|
||
overflow-y: auto;
|
||
scrollbar-width: thin;
|
||
scrollbar-color: #dcdfe6 transparent;
|
||
|
||
&::-webkit-scrollbar {
|
||
width: 6px;
|
||
}
|
||
|
||
&::-webkit-scrollbar-thumb {
|
||
border-radius: 3px;
|
||
background: #dcdfe6;
|
||
}
|
||
|
||
&::-webkit-scrollbar-track {
|
||
background: transparent;
|
||
}
|
||
|
||
:deep(.el-tag) {
|
||
max-width: 100%;
|
||
margin: 0;
|
||
}
|
||
|
||
/* 单号较长时省略,避免撑破弹窗 */
|
||
:deep(.el-tag .el-tag__content) {
|
||
min-width: 0;
|
||
overflow: hidden;
|
||
text-overflow: ellipsis;
|
||
white-space: nowrap;
|
||
}
|
||
}
|
||
|
||
&__field-empty {
|
||
font-size: 12px;
|
||
line-height: 20px;
|
||
color: #909399;
|
||
}
|
||
|
||
&__switch {
|
||
position: relative;
|
||
width: 40px;
|
||
height: 20px;
|
||
flex: none;
|
||
padding: 0;
|
||
border: none;
|
||
border-radius: 10px;
|
||
background: #dcdfe6;
|
||
cursor: default;
|
||
transition: background 0.2s;
|
||
|
||
&.is-clickable {
|
||
cursor: pointer;
|
||
}
|
||
|
||
&:disabled {
|
||
opacity: 1;
|
||
}
|
||
|
||
i {
|
||
position: absolute;
|
||
top: 2px;
|
||
left: 2px;
|
||
width: 16px;
|
||
height: 16px;
|
||
border-radius: 50%;
|
||
background: #fff;
|
||
transition: left 0.2s;
|
||
}
|
||
|
||
&.is-on {
|
||
background: #409eff;
|
||
|
||
i {
|
||
left: 22px;
|
||
}
|
||
}
|
||
}
|
||
|
||
&__form-tip {
|
||
margin: 8px 0 0;
|
||
padding: 8px 12px;
|
||
border-radius: 4px;
|
||
background: #f4f4f5;
|
||
font-size: 12px;
|
||
line-height: 18px;
|
||
color: #909399;
|
||
}
|
||
|
||
&__foot {
|
||
display: flex;
|
||
align-items: center;
|
||
justify-content: space-between;
|
||
gap: 12px;
|
||
/* 对齐 el-dialog 默认 footer:上间距 16、距底 16 */
|
||
padding: 16px 16px 16px;
|
||
}
|
||
}
|
||
</style>
|