- 新增 TaskProgressFloatWidget;TaskProgressDialog 增加 minimizable 与 minimize 事件,运行中可「收起后台」,浮窗继续轮询并支持点击还原窗口, 运单页「更新揽收状态」已接入 - UpperTable 新增 #pagination-info 插槽(支持「已选 N 项」等精简文案), 运单号列对齐方式透传给 WaybillCodeActions - 盘点、入库、出库、收货、波次、订单明细、库存详情、仓库与店铺等 20+ 处 日志/明细列表由 el-table 迁移至 UpperTable,统一分页、行选择、 虚拟滚动、状态文本样式与列插槽 - 拆包录像列表、出库单详情表单、运单称重弹窗等按 task-panel 结构统一; 运单轨迹浮层支持拖动并复用 task-panel 标题与关闭样式 - 补充相关样式,修正内嵌表格高度与分页区布局,避免卡片阴影与高度塌陷
288 lines
7.9 KiB
Vue
288 lines
7.9 KiB
Vue
<!--
|
||
LogPanel — 操作日志面板(通用)
|
||
|
||
支持两种数据来源:
|
||
- apiMethod 传入 → 调用真实接口获取日志
|
||
- 无 apiMethod → 基于 row 生成模拟日志(开发调试用)
|
||
-->
|
||
<template>
|
||
<div class="log-panel">
|
||
<!-- 按钮行(间距 6px 对齐 toolbar),对齐 stock/external_stock 面板新样式 -->
|
||
<div class="header-actions">
|
||
<div class="left-actions">
|
||
<el-button
|
||
size="small"
|
||
type="primary"
|
||
:loading="apiLoading"
|
||
:disabled="!row || !apiMethod"
|
||
@click="loadLogs"
|
||
>
|
||
刷新
|
||
</el-button>
|
||
</div>
|
||
</div>
|
||
|
||
<div class="table-host">
|
||
<upper-table
|
||
:table-id="`${tableIdPrefix}-logs`"
|
||
:data="pagedLogs"
|
||
:columns="logColumns"
|
||
default-align="center"
|
||
table-size="small"
|
||
:show-selection="true"
|
||
:pagination="pagination"
|
||
:page-sizes="[10, 20, 50, 100]"
|
||
:loading="apiLoading"
|
||
:row-key="(row: LogItem) => row.__key"
|
||
empty-text="暂无操作日志"
|
||
@page-change="handlePageChange"
|
||
@page-size-change="handlePageSizeChange"
|
||
>
|
||
<!-- 已选数量放左下角(UpperTable 分页区左侧) -->
|
||
<template #pagination-info="{ count }">已选 {{ count }} 项</template>
|
||
|
||
<template #column-result="{ row }">
|
||
<span :class="getStatusTextClass(resultTagType(row))">{{ row.result }}</span>
|
||
</template>
|
||
<template #column-detail="{ row }">{{ row.detail || '—' }}</template>
|
||
</upper-table>
|
||
</div>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, ref, watch } from 'vue'
|
||
import { getStatusTextClass } from '@/utils/statusText'
|
||
import UpperTable from '@/components/UpperTable/index.vue'
|
||
|
||
defineOptions({ name: 'LogPanel' })
|
||
|
||
interface LogItem {
|
||
operator: string
|
||
action: string
|
||
result: string
|
||
detail?: string
|
||
time: string
|
||
level: 'success' | 'info' | 'warning' | 'error'
|
||
/** 本地行 key(日志无 id) */
|
||
__key?: string
|
||
}
|
||
|
||
const props = withDefaults(defineProps<{
|
||
/** 当前选中行数据(用于生成关联日志) */
|
||
row: Record<string, any> | null
|
||
/** 可选的日志 API 方法,传入后自动调用获取真实日志 */
|
||
apiMethod?: (...args: any[]) => Promise<any>
|
||
/** 列配置持久化前缀(区分不同页面) */
|
||
tableIdPrefix?: string
|
||
}>(), {
|
||
tableIdPrefix: 'data-ordersummary'
|
||
})
|
||
|
||
/** 通过 API 获取的真实日志列表 */
|
||
const apiLogs = ref<LogItem[] | null>(null)
|
||
const apiLoading = ref(false)
|
||
|
||
/** 日志列配置(UpperTable) */
|
||
const logColumns = [
|
||
{ prop: 'time', label: '时间', width: '175' },
|
||
{ prop: 'operator', label: '操作人', width: '120' },
|
||
{ prop: 'action', label: '操作类型', minWidth: '180', showOverflowTooltip: true },
|
||
{ prop: 'result', label: '结果', width: '90' },
|
||
{ prop: 'detail', label: '说明', minWidth: '220', showOverflowTooltip: true }
|
||
]
|
||
|
||
/** 表格本地分页(对齐 storage/receiving 操作日志体验) */
|
||
const currentPage = ref(1)
|
||
const pageSize = ref(10)
|
||
const pagination = computed(() => ({
|
||
currentPage: currentPage.value,
|
||
pageSize: pageSize.value,
|
||
total: logs.value.length
|
||
}))
|
||
const pagedLogs = computed<LogItem[]>(() => {
|
||
const start = (currentPage.value - 1) * pageSize.value
|
||
return logs.value.slice(start, start + pageSize.value)
|
||
})
|
||
|
||
function handlePageChange(page: number) {
|
||
currentPage.value = page
|
||
}
|
||
|
||
function handlePageSizeChange(size: number) {
|
||
pageSize.value = size
|
||
currentPage.value = 1
|
||
}
|
||
|
||
function resultTagType(row: LogItem): string {
|
||
if (row.result === '成功') return 'success'
|
||
if (row.result === '失败') return 'danger'
|
||
return 'info'
|
||
}
|
||
|
||
watch(() => props.row, () => {
|
||
void loadLogs()
|
||
}, { immediate: true })
|
||
|
||
/** 拉取日志(按钮「刷新」也走这个函数) */
|
||
async function loadLogs() {
|
||
const newRow = props.row
|
||
currentPage.value = 1
|
||
if (newRow && props.apiMethod) {
|
||
apiLoading.value = true
|
||
try {
|
||
const res = await props.apiMethod({
|
||
id: newRow.id,
|
||
code: newRow.code,
|
||
page: 1,
|
||
pageSize: 100
|
||
})
|
||
if (res && (res.code === 1 || res.code === 200)) {
|
||
const list = res.data?.list ?? res.data?.logs ?? res.list ?? res.logs ?? []
|
||
apiLogs.value = Array.isArray(list) ? list.map((item: any) => ({
|
||
operator: item.operator ?? item.creator ?? '—',
|
||
action: item.action ?? item.operation ?? '—',
|
||
result: item.result ?? item.status ?? '—',
|
||
detail: item.detail ?? item.description ?? '',
|
||
time: item.time ?? item.create_time ?? '—',
|
||
level: (item.result === '成功' || item.status === 'success') ? 'success'
|
||
: (item.result === '失败' || item.status === 'error') ? 'error'
|
||
: 'info'
|
||
})) : []
|
||
} else {
|
||
apiLogs.value = []
|
||
}
|
||
} catch {
|
||
apiLogs.value = []
|
||
} finally {
|
||
apiLoading.value = false
|
||
}
|
||
} else {
|
||
apiLogs.value = null
|
||
}
|
||
}
|
||
|
||
/** 基于 row 生成模拟日志(无 apiMethod 时使用) */
|
||
const mockLogs = computed<LogItem[]>(() => {
|
||
if (!props.row) return []
|
||
|
||
const rowName = props.row.name ?? props.row.code ?? '—'
|
||
const now = new Date()
|
||
const pad = (n: number) => String(n).padStart(2, '0')
|
||
const fmt = (d: Date) =>
|
||
`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
|
||
|
||
return [
|
||
{
|
||
operator: '系统',
|
||
action: `创建了「${rowName}」`,
|
||
result: '成功',
|
||
time: fmt(new Date(now.getTime() - 3600000 * 3)),
|
||
level: 'success'
|
||
},
|
||
{
|
||
operator: props.row.creator ?? '管理员',
|
||
action: `更新了「${rowName}」`,
|
||
result: '成功',
|
||
detail: `修改了状态和相关配置`,
|
||
time: fmt(new Date(now.getTime() - 3600000)),
|
||
level: 'success'
|
||
}
|
||
]
|
||
})
|
||
|
||
/** 最终展示的日志:优先使用 API 日志,否则使用 mock 日志(附本地行 key) */
|
||
const logs = computed<LogItem[]>(() => {
|
||
const list = apiLogs.value !== null ? apiLogs.value : mockLogs.value
|
||
return list.map((item, index) => ({ ...item, __key: `log-${index}` }))
|
||
})
|
||
|
||
/** 数据变化后页码超出范围时回退到最后一页(必须放在 logs 声明之后,否则 setup 阶段 TDZ 报错) */
|
||
watch(logs, (list) => {
|
||
const maxPage = Math.max(1, Math.ceil(list.length / pageSize.value))
|
||
if (currentPage.value > maxPage) currentPage.value = maxPage
|
||
})
|
||
</script>
|
||
|
||
<style lang="scss" scoped>
|
||
/* ut-status-text 系列状态文字颜色类定义在 @/styles/status-text.scss 里(scoped 样式需要本组件自行引入) */
|
||
@use "@/styles/status-text.scss";
|
||
|
||
/* 日志面板:按钮行 + 自适应高度表格 + 右对齐分页(对齐 stock/external_stock 面板列表新样式) */
|
||
.log-panel {
|
||
flex: 1;
|
||
min-height: 0;
|
||
width: 100%;
|
||
height: 100%;
|
||
padding: 8px 0;
|
||
box-sizing: border-box;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
}
|
||
|
||
.header-actions {
|
||
display: flex;
|
||
justify-content: space-between;
|
||
align-items: center;
|
||
margin-bottom: 6px;
|
||
flex-shrink: 0;
|
||
gap: 4px;
|
||
flex-wrap: wrap;
|
||
}
|
||
|
||
.left-actions {
|
||
display: flex;
|
||
align-items: center;
|
||
gap: 6px;
|
||
|
||
/* 清除 Element Plus 默认按钮左边距,统一由 gap 控制间距 */
|
||
:deep(.el-button) {
|
||
margin-left: 0;
|
||
margin-right: 0;
|
||
}
|
||
}
|
||
|
||
.table-host {
|
||
flex: 1;
|
||
min-height: 120px;
|
||
min-width: 0;
|
||
overflow: hidden;
|
||
display: flex;
|
||
flex-direction: column;
|
||
|
||
:deep(.upper-table-container) {
|
||
height: 100%;
|
||
display: flex;
|
||
flex-direction: column;
|
||
overflow: hidden;
|
||
box-shadow: none;
|
||
border-radius: 0;
|
||
}
|
||
|
||
:deep(.table-container) {
|
||
flex: 1;
|
||
min-height: 0;
|
||
height: auto !important;
|
||
}
|
||
|
||
:deep(.pagination-container) {
|
||
flex-shrink: 0;
|
||
padding: 0;
|
||
border-top: none;
|
||
margin-top: 6px;
|
||
justify-content: space-between;
|
||
}
|
||
|
||
:deep(.pagination-info) {
|
||
font-size: 12px;
|
||
color: #606266;
|
||
}
|
||
}
|
||
|
||
.empty-tip {
|
||
color: #909399;
|
||
font-size: 13px;
|
||
}
|
||
</style>
|