style(frontend): 列表页统一版式(分页固定底部)+ 操作记录面板

列表统一版式(对齐订单页):
- 所有列表页卡片撑满可视高度(flex:1 + min-height:0),el-card__body 改为 flex 列并 overflow:hidden
- 筛选区固定(flex:0 0 auto),表格区 flex:1 且 overflow:hidden,表格传 height="100%" 只在表体滚动
- 分页组件固定在底部,不再跟着表格滚走
- 涉及页面:商品、组合商品、主体管理、账号管理、外部打单平台
  (导出任务、库存单据、库存流水、店铺、店铺商品、出入库单此前已统一)

操作记录面板:
- 新增 components/OperationLogPanel.vue(分页表格:时间/操作/说明/操作人/来源)与 api/operationLog.ts
- 店铺商品页:点击商品行在表格下方展开操作记录,再次点击或「收起」关闭
- 商品、组合商品页:行内新增「日志」按钮,弹窗展示操作记录

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
liufumingren 2026-11-03 03:43:35 +08:00
parent a9cca6aa6f
commit ce636c15f4
9 changed files with 544 additions and 40 deletions

View File

@ -0,0 +1,53 @@
import { get } from '@/utils/request'
/** 日志对象类型:店铺商品 / 系统商品 / 组合商品 */
export type OperationLogTargetType = 'shop_product' | 'product' | 'combo_product'
/** 一条操作记录 */
export interface OperationLogItem {
id: number
principal_id: number
target_type: OperationLogTargetType
target_id: number
/** 动作码:create / update / bind / unbind / remove / offline / delete */
action: string
/** 操作说明(已包含对象名称,可直接展示) */
title: string
detail?: Record<string, unknown> | null
/** ui 界面操作 / sync 自动同步 / system 系统任务 */
source: string
operator_id: number | null
operator_name: string | null
created_at: string
}
/** 动作码 → 中文标签 */
export const ACTION_LABELS: Record<string, string> = {
create: '新增',
update: '修改',
bind: '绑定',
unbind: '解绑',
remove: '移出',
offline: '下架',
delete: '删除',
}
/** 来源 → 中文标签 */
export const SOURCE_LABELS: Record<string, string> = {
ui: '界面操作',
sync: '自动同步',
system: '系统任务',
}
/** 分页查询某个对象的操作记录 */
export function getOperationLogs(params: {
target_type: OperationLogTargetType
target_id: number
page?: number
pageSize?: number
}) {
return get<{ list: OperationLogItem[]; total: number; page: number; pageSize: number }>(
'/operation-logs',
params,
)
}

View File

@ -0,0 +1,178 @@
<script setup lang="ts">
/**
* 操作记录面板
*
* 按对象(店铺商品 / 系统商品 / 组合商品)分页展示历史操作:
* 何时采集进系统、何时绑定/解绑、谁操作的、来源是界面还是自动同步。
* 供店铺商品页底部内嵌使用,也供商品/组合商品弹窗使用。
*/
import { ref, watch } from 'vue'
import { ACTION_LABELS, SOURCE_LABELS, getOperationLogs, type OperationLogItem, type OperationLogTargetType } from '@/api/operationLog'
import { formatDateTime } from '@/utils/datetime'
import DataTable from '@/components/DataTable.vue'
import ListPager from '@/components/ListPager.vue'
import { DEFAULT_PAGE_SIZE } from '@/composables/useListPage'
const props = withDefaults(
defineProps<{
targetType: OperationLogTargetType
targetId: number | null
/** 标题右侧展示的对象名称 */
targetName?: string
/** 表格高度:内嵌面板用百分比,弹窗里用固定像素 */
tableHeight?: string | number
/** 是否隐藏标题栏(弹窗标题已说明对象时) */
hideHeader?: boolean
}>(),
{
targetName: '',
tableHeight: '100%',
hideHeader: false,
},
)
const loading = ref(false)
const list = ref<OperationLogItem[]>([])
const total = ref(0)
const page = ref(1)
const pageSize = ref(DEFAULT_PAGE_SIZE)
const elapsed = ref<number | null>(null)
const ACTION_TAGS: Record<string, string> = {
create: 'success',
update: 'primary',
bind: 'warning',
unbind: 'info',
remove: 'danger',
offline: 'info',
delete: 'danger',
}
async function fetchList() {
if (!props.targetId) {
list.value = []
total.value = 0
return
}
loading.value = true
const startedAt = performance.now()
try {
const res = await getOperationLogs({
target_type: props.targetType,
target_id: props.targetId,
page: page.value,
pageSize: pageSize.value,
})
list.value = res.list
total.value = res.total
} catch {
list.value = []
total.value = 0
} finally {
elapsed.value = Math.round(performance.now() - startedAt)
loading.value = false
}
}
function search() {
page.value = 1
void fetchList()
}
function handlePageChange(next: number) {
page.value = next
void fetchList()
}
function handleSizeChange(size: number) {
pageSize.value = size
page.value = 1
void fetchList()
}
watch(
() => [ props.targetType, props.targetId ] as const,
() => search(),
{ immediate: true },
)
defineExpose({ refresh: fetchList })
</script>
<template>
<div class="log-panel">
<div v-if="!props.hideHeader" class="log-header">
<span class="log-title">操作记录</span>
<span v-if="props.targetName" class="log-target">{{ props.targetName }}</span>
<el-button link type="primary" size="small" class="log-refresh" @click="search">刷新</el-button>
</div>
<div class="log-table">
<DataTable :loading="loading" :data="list" :height="tableHeight">
<el-table-column label="时间" width="165">
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
</el-table-column>
<el-table-column label="操作" width="90">
<template #default="{ row }">
<el-tag :type="ACTION_TAGS[row.action] || 'info'" size="small" effect="plain">
{{ ACTION_LABELS[row.action] || row.action }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="title" label="说明" min-width="280" show-overflow-tooltip />
<el-table-column label="操作人" width="120">
<template #default="{ row }">{{ row.operator_name || '-' }}</template>
</el-table-column>
<el-table-column label="来源" width="100">
<template #default="{ row }">
<span class="log-source">{{ SOURCE_LABELS[row.source] || row.source }}</span>
</template>
</el-table-column>
</DataTable>
</div>
<ListPager
:total="total"
:elapsed="elapsed"
:page="page"
:page-size="pageSize"
@page-change="handlePageChange"
@size-change="handleSizeChange"
/>
</div>
</template>
<style scoped>
.log-panel {
display: flex;
flex-direction: column;
height: 100%;
min-height: 0;
}
.log-header {
flex: 0 0 auto;
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 6px;
}
.log-title {
font-weight: 600;
font-size: 13px;
}
.log-target {
font-size: 12px;
color: var(--el-text-color-secondary);
}
.log-refresh {
margin-left: auto;
}
.log-table {
flex: 1 1 auto;
min-height: 0;
}
.log-source {
font-size: 12px;
color: var(--el-text-color-secondary);
}
</style>

View File

@ -12,6 +12,7 @@ import { searchProducts, type ProductSearchItem } from '@/api/product'
import DataTable from '@/components/DataTable.vue'
import ExportButton from '@/components/ExportButton.vue'
import ListPager from '@/components/ListPager.vue'
import OperationLogPanel from '@/components/OperationLogPanel.vue'
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
const query = reactive({
@ -220,11 +221,26 @@ async function handleDelete(row: ComboProductItem) {
}
}
/* -------------------- 操作记录 -------------------- */
const logVisible = ref(false)
const logRow = ref<ComboProductItem | null>(null)
function openLog(row: ComboProductItem) {
logRow.value = row
logVisible.value = true
}
const logTitle = computed(() => {
const row = logRow.value
if (!row) return '操作记录'
return `操作记录:${row.name || ''}(${row.code || ''})`
})
onMounted(fetchList)
</script>
<template>
<el-card>
<el-card class="list-card">
<template #header>
<div class="page-header">
<span>组合商品</span>
@ -256,8 +272,9 @@ onMounted(fetchList)
</el-form-item>
</el-form>
<DataTable :loading="loading" :data="list">
<el-table-column prop="code" label="组合编码" width="130" />
<div class="list-table-wrap">
<DataTable :loading="loading" :data="list" height="100%">
<el-table-column prop="code" label="组合编码" width="130" />
<el-table-column prop="name" label="组合名称" min-width="150" />
<el-table-column label="组合售价" width="100" align="right">
<template #default="{ row }">{{ row.price }}</template>
@ -272,13 +289,15 @@ onMounted(fetchList)
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="140" fixed="right">
<el-table-column label="操作" width="180" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
<el-button link type="info" @click="openLog(row)">日志</el-button>
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
</template>
</el-table-column>
</DataTable>
</DataTable>
</div>
<ListPager
:total="total"
@ -289,6 +308,22 @@ onMounted(fetchList)
@size-change="handleSizeChange"
/>
<!-- 操作记录:新增 / 修改(含子商品构成)/ 删除留痕 -->
<el-dialog v-model="logVisible" :title="logTitle" width="min(900px, 94vw)" top="6vh" destroy-on-close>
<div class="log-dialog-body">
<OperationLogPanel
v-if="logRow"
:target-type="'combo_product'"
:target-id="logRow.id"
:table-height="360"
hide-header
/>
</div>
<template #footer>
<el-button @click="logVisible = false">关闭</el-button>
</template>
</el-dialog>
<el-drawer
v-model="drawerVisible"
:title="editId == null ? '新增组合商品' : '编辑组合商品'"
@ -396,12 +431,37 @@ onMounted(fetchList)
</template>
<style scoped>
/* 列表页统一版式:卡片撑满可视高度,筛选与分页固定,只有表格主体滚动 */
.list-card {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.list-card :deep(.el-card__body) {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 10px 12px;
}
.list-table-wrap {
flex: 1;
min-height: 0;
overflow: hidden;
}
.page-header {
display: flex;
align-items: center;
justify-content: space-between;
font-weight: 600;
}
.log-dialog-body {
height: 420px;
display: flex;
flex-direction: column;
}
.search-bar {
margin-bottom: 16px;
}

View File

@ -351,8 +351,9 @@ onBeforeUnmount(() => {
</el-form-item>
</el-form>
<DataTable :loading="loading" :data="list">
<el-table-column label="平台" min-width="140">
<div class="list-table-wrap">
<DataTable :loading="loading" :data="list" height="100%">
<el-table-column label="平台" min-width="140">
<template #default="{ row }">{{ row.platform?.name || platformName(row.platform_id) }}</template>
</el-table-column>
<el-table-column prop="account" label="账号" min-width="160" show-overflow-tooltip />
@ -394,7 +395,8 @@ onBeforeUnmount(() => {
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
</template>
</el-table-column>
</DataTable>
</DataTable>
</div>
<ListPager
:total="total"
@ -492,6 +494,28 @@ onBeforeUnmount(() => {
</template>
<style scoped>
/* 列表页统一版式:卡片撑满可视高度,筛选与分页固定,只有表格主体滚动 */
.external-print-card {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.external-print-card :deep(.el-card__body) {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 10px 12px;
}
.list-table-wrap {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
}
.page-header {
display: flex;
align-items: center;
@ -502,6 +526,7 @@ onBeforeUnmount(() => {
margin-bottom: 12px;
}
.search-bar {
flex: 0 0 auto;
margin-bottom: 12px;
}
.merchant-search {

View File

@ -79,7 +79,7 @@ onMounted(fetchList)
</script>
<template>
<el-card>
<el-card class="list-card">
<template #header>
<div class="page-header">
<span>主体管理</span>
@ -100,24 +100,26 @@ onMounted(fetchList)
</el-form-item>
</el-form>
<DataTable :loading="loading" :data="list">
<el-table-column prop="name" label="名称" min-width="160" />
<el-table-column label="类型" width="100">
<template #default="{ row }">{{ TYPE_LABELS[row.type] || row.type }}</template>
</el-table-column>
<el-table-column prop="contact_name" label="联系人" width="120" />
<el-table-column prop="contact_phone" label="联系电话" width="140" />
<el-table-column label="状态" width="90">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'info'">
{{ row.status === 1 ? '启用' : '禁用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="created_at" label="创建时间" width="180">
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
</el-table-column>
</DataTable>
<div class="list-table-wrap">
<DataTable :loading="loading" :data="list" height="100%">
<el-table-column prop="name" label="名称" min-width="160" />
<el-table-column label="类型" width="100">
<template #default="{ row }">{{ TYPE_LABELS[row.type] || row.type }}</template>
</el-table-column>
<el-table-column prop="contact_name" label="联系人" width="120" />
<el-table-column prop="contact_phone" label="联系电话" width="140" />
<el-table-column label="状态" width="90">
<template #default="{ row }">
<el-tag :type="row.status === 1 ? 'success' : 'info'">
{{ row.status === 1 ? '启用' : '禁用' }}
</el-tag>
</template>
</el-table-column>
<el-table-column prop="created_at" label="创建时间" width="180">
<template #default="{ row }">{{ formatDateTime(row.created_at) }}</template>
</el-table-column>
</DataTable>
</div>
<ListPager
:total="total"
@ -159,6 +161,26 @@ onMounted(fetchList)
</template>
<style scoped>
/* 列表页统一版式:卡片撑满可视高度,筛选与分页固定,只有表格主体滚动 */
.list-card {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.list-card :deep(.el-card__body) {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 10px 12px;
}
.list-table-wrap {
flex: 1;
min-height: 0;
overflow: hidden;
}
.page-header {
display: flex;
align-items: center;
@ -166,6 +188,7 @@ onMounted(fetchList)
font-weight: 600;
}
.search-bar {
margin-bottom: 16px;
flex: 0 0 auto;
margin-bottom: 12px;
}
</style>

View File

@ -211,7 +211,7 @@ onMounted(fetchList)
</script>
<template>
<el-card>
<el-card class="list-card">
<template #header>
<div class="page-header">
<span>账号</span>
@ -242,8 +242,9 @@ onMounted(fetchList)
</el-form-item>
</el-form>
<DataTable :loading="loading" :data="list">
<el-table-column label="用户" min-width="180">
<div class="list-table-wrap">
<DataTable :loading="loading" :data="list" height="100%">
<el-table-column label="用户" min-width="180">
<template #default="{ row }">
<div class="user-cell">
<el-avatar :size="28" :src="mediaUrl(row.avatar) || undefined">{{ avatarText(row) }}</el-avatar>
@ -274,7 +275,8 @@ onMounted(fetchList)
<el-button link type="danger" @click="handleUnbind(row)">解绑</el-button>
</template>
</el-table-column>
</DataTable>
</DataTable>
</div>
<ListPager
:total="total"
@ -365,6 +367,26 @@ onMounted(fetchList)
</template>
<style scoped>
/* 列表页统一版式:卡片撑满可视高度,筛选与分页固定,只有表格主体滚动 */
.list-card {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.list-card :deep(.el-card__body) {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 10px 12px;
}
.list-table-wrap {
flex: 1;
min-height: 0;
overflow: hidden;
}
.page-header {
display: flex;
align-items: center;
@ -372,7 +394,8 @@ onMounted(fetchList)
font-weight: 600;
}
.search-bar {
margin-bottom: 16px;
flex: 0 0 auto;
margin-bottom: 12px;
}
/* 列表用户列:头像 + 名称 */
.user-cell {

View File

@ -28,6 +28,7 @@ import ImageUploader from '@/components/ImageUploader.vue'
import ExportButton from '@/components/ExportButton.vue'
import DataTable from '@/components/DataTable.vue'
import ListPager from '@/components/ListPager.vue'
import OperationLogPanel from '@/components/OperationLogPanel.vue'
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
import { mediaUrl } from '@/utils/media'
@ -355,6 +356,21 @@ async function handleDelete(row: ProductItem) {
}
}
/* -------------------- 操作记录 -------------------- */
const logVisible = ref(false)
const logRow = ref<ProductItem | null>(null)
function openLog(row: ProductItem) {
logRow.value = row
logVisible.value = true
}
const logTitle = computed(() => {
const row = logRow.value
if (!row) return '操作记录'
return `操作记录:${row.item_name || ''}(${row.item_code || ''})`
})
onMounted(async () => {
await loadAttributeOptions()
applyRouteQuery()
@ -363,7 +379,7 @@ onMounted(async () => {
</script>
<template>
<el-card>
<el-card class="list-card">
<template #header>
<div class="page-header">
<span>商品</span>
@ -428,8 +444,9 @@ onMounted(async () => {
</el-form-item>
</el-form>
<DataTable :loading="loading" :data="list">
<el-table-column prop="item_code" label="商品编码" width="130" />
<div class="list-table-wrap">
<DataTable :loading="loading" :data="list" height="100%">
<el-table-column prop="item_code" label="商品编码" width="130" />
<el-table-column prop="goods_code" label="货物编码" width="120" />
<el-table-column prop="barcode" label="条码" width="120" />
<el-table-column prop="item_name" label="商品名称" min-width="160" />
@ -475,13 +492,15 @@ onMounted(async () => {
</el-tag>
</template>
</el-table-column>
<el-table-column label="操作" width="140" fixed="right">
<el-table-column label="操作" width="180" fixed="right">
<template #default="{ row }">
<el-button link type="primary" @click="openEdit(row)">编辑</el-button>
<el-button link type="info" @click="openLog(row)">日志</el-button>
<el-button link type="danger" @click="handleDelete(row)">删除</el-button>
</template>
</el-table-column>
</DataTable>
</DataTable>
</div>
<ListPager
:total="total"
@ -492,6 +511,22 @@ onMounted(async () => {
@size-change="handleSizeChange"
/>
<!-- 操作记录:新增 / 修改 / 删除留痕 -->
<el-dialog v-model="logVisible" :title="logTitle" width="min(900px, 94vw)" top="6vh" destroy-on-close>
<div class="log-dialog-body">
<OperationLogPanel
v-if="logRow"
:target-type="'product'"
:target-id="logRow.id"
:table-height="360"
hide-header
/>
</div>
<template #footer>
<el-button @click="logVisible = false">关闭</el-button>
</template>
</el-dialog>
<el-drawer
v-model="drawerVisible"
:title="editId == null ? '新增商品' : '编辑商品'"
@ -669,12 +704,37 @@ onMounted(async () => {
</template>
<style scoped>
/* 列表页统一版式:卡片撑满可视高度,筛选与分页固定,只有表格主体滚动 */
.list-card {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.list-card :deep(.el-card__body) {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
overflow: hidden;
padding: 10px 12px;
}
.list-table-wrap {
flex: 1;
min-height: 0;
overflow: hidden;
}
.page-header {
display: flex;
align-items: center;
justify-content: space-between;
font-weight: 600;
}
.log-dialog-body {
height: 420px;
display: flex;
flex-direction: column;
}
.search-bar {
margin-bottom: 16px;
}

View File

@ -335,6 +335,7 @@ onMounted(fetchList)
flex-direction: column;
}
.search-bar {
flex: 0 0 auto;
margin-bottom: 12px;
}
.add-btn {
@ -343,6 +344,7 @@ onMounted(fetchList)
.table-wrap {
flex: 1;
min-height: 0;
overflow: hidden;
}
:deep(.el-input-number) {
width: 100%;

View File

@ -15,6 +15,7 @@ import { getComboProducts, type ComboProductItem } from '@/api/comboProduct'
import DataTable from '@/components/DataTable.vue'
import ExportButton from '@/components/ExportButton.vue'
import ListPager from '@/components/ListPager.vue'
import OperationLogPanel from '@/components/OperationLogPanel.vue'
import { DEFAULT_PAGE_SIZE, useListPage } from '@/composables/useListPage'
import VirtualSelect from '@/components/VirtualSelect.vue'
@ -290,6 +291,32 @@ function boundName(row: ShopProductItem) {
return '-'
}
/* -------------------- 操作记录(点击行后底部展示) -------------------- */
const logRow = ref<ShopProductItem | null>(null)
const logPanelHeight = ref(240)
function onRowClick(row: ShopProductItem) {
// 再次点击同一行则收起
if (logRow.value && logRow.value.id === row.id) {
closeLog()
return
}
logRow.value = row
}
function closeLog() {
logRow.value = null
}
/** 日志里展示的商品名(标题 + 平台商品ID) */
const logTargetName = computed(() => {
const row = logRow.value
if (!row) return ''
const name = row.title || row.outer_item_id
const spec = row.outer_sku_id ? `,规格 ${row.outer_sku_id}` : ''
return `${name}(平台商品ID ${row.outer_item_id}${spec})`
})
/* -------------------- 按平台商品ID补拉 -------------------- */
const pullVisible = ref(false)
const pullSubmitting = ref(false)
@ -429,8 +456,14 @@ onBeforeUnmount(() => {
</el-form-item>
</el-form>
<div class="list-table-wrap">
<DataTable :loading="loading" :data="list" height="100%">
<div class="list-table-wrap" :class="{ 'list-table-wrap--with-log': !!logRow }">
<DataTable
:loading="loading"
:data="list"
height="100%"
highlight-current-row
@row-click="onRowClick"
>
<el-table-column label="店铺" width="140">
<template #default="{ row }">{{ row.shop?.name || '-' }}</template>
</el-table-column>
@ -489,6 +522,22 @@ onBeforeUnmount(() => {
@size-change="handleSizeChange"
/>
<!-- 操作记录:点击商品行后在下方展开(采集时间 / 绑定解绑 / 操作人) -->
<div v-if="logRow" class="log-wrap" :style="{ height: `${logPanelHeight}px` }">
<div class="log-head">
<span class="log-name">{{ logTargetName }}</span>
<el-button link size="small" class="log-close" @click="closeLog">收起</el-button>
</div>
<div class="log-body">
<OperationLogPanel
:target-type="'shop_product'"
:target-id="logRow.id"
:table-height="'100%'"
hide-header
/>
</div>
</div>
<el-dialog v-model="pullVisible" title="按平台商品ID拉取" width="520px">
<el-alert
type="info"
@ -701,6 +750,37 @@ onBeforeUnmount(() => {
flex: 1 1 auto;
min-height: 0;
}
/* 底部展开操作记录后,表格让出一部分高度(表格内部仍可滚动) */
.log-wrap {
flex: 0 0 auto;
display: flex;
flex-direction: column;
min-height: 0;
margin-top: 8px;
padding-top: 8px;
border-top: 1px solid var(--el-border-color-lighter);
}
.log-head {
flex: 0 0 auto;
display: flex;
align-items: center;
gap: 8px;
margin-bottom: 4px;
}
.log-name {
font-size: 12px;
font-weight: 600;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.log-close {
margin-left: auto;
}
.log-body {
flex: 1 1 auto;
min-height: 0;
}
.bound-name {
margin-left: 8px;
}