287 lines
7.3 KiB
Vue
287 lines
7.3 KiB
Vue
<template>
|
||
<div class="log-container">
|
||
<el-button-group class="toolbar-btn-group">
|
||
<el-button
|
||
type="primary"
|
||
size="small"
|
||
:icon="Refresh"
|
||
title="刷新"
|
||
:loading="loading"
|
||
class="toolbar-btn"
|
||
:disabled="!orderId"
|
||
@click="handleRefresh"
|
||
>
|
||
刷新
|
||
</el-button>
|
||
</el-button-group>
|
||
|
||
<el-table
|
||
:data="tableData"
|
||
border
|
||
stripe
|
||
style="width: 100%; height: 100%"
|
||
height="100%"
|
||
v-loading="loading"
|
||
>
|
||
<el-table-column prop="created_at" label="时间" width="175" />
|
||
<el-table-column label="操作人" width="110">
|
||
<template #default="{ row }">
|
||
{{ row.operator_name ?? '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="操作类型" min-width="160" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ formatOperationLabel(row) }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="平台" width="100" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ row.platform_name || row.platform_code || '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="外部日志" width="108" align="center">
|
||
<template #default="{ row }">
|
||
<el-tag v-if="row.external_log_type && row.external_log_type !== 'NONE'" size="small" type="info">
|
||
{{ row.external_log_type }}
|
||
</el-tag>
|
||
<span v-else class="cell-muted">—</span>
|
||
</template>
|
||
</el-table-column>
|
||
<el-table-column label="说明" min-width="220" show-overflow-tooltip>
|
||
<template #default="{ row }">
|
||
{{ row.message ?? '—' }}
|
||
</template>
|
||
</el-table-column>
|
||
|
||
<el-table-column label="操作" width="108" align="center" fixed="right">
|
||
<template #default="scope">
|
||
<el-button
|
||
v-if="hasExternalPayload(scope.row)"
|
||
type="primary"
|
||
link
|
||
size="small"
|
||
@click="viewData(scope.row)"
|
||
>
|
||
查看报文
|
||
</el-button>
|
||
<span v-else class="cell-muted">—</span>
|
||
</template>
|
||
</el-table-column>
|
||
</el-table>
|
||
|
||
<div class="pagination-container">
|
||
<el-pagination
|
||
v-model:current-page="pagination.page"
|
||
v-model:page-size="pagination.pageSize"
|
||
:page-sizes="[10, 20, 50, 100]"
|
||
:total="pagination.total"
|
||
layout="total, sizes, prev, pager, next, jumper"
|
||
background
|
||
size="small"
|
||
@size-change="handlePageSizeChange"
|
||
@current-change="handlePageChange"
|
||
/>
|
||
</div>
|
||
|
||
<el-drawer
|
||
v-model="showRequestData"
|
||
direction="rtl"
|
||
:with-header="false"
|
||
size="800px"
|
||
class="el-drawers"
|
||
>
|
||
<RequestData v-if="showRequestData" :id="requestId" :type="requestType" />
|
||
</el-drawer>
|
||
</div>
|
||
</template>
|
||
|
||
<script setup lang="ts">
|
||
import { computed, reactive, ref, watch } from 'vue'
|
||
import { ElMessage } from 'element-plus'
|
||
import { Refresh } from '@element-plus/icons-vue'
|
||
import RequestData from '@/components/RequestData/index.vue'
|
||
import { orderQueryOrderLogs } from '@/api/order.index/orderindex'
|
||
|
||
const props = defineProps<{
|
||
/** 当前选中订单行(与其它订单页一致,使用 id 作为 order_id) */
|
||
data?: Record<string, any> | null
|
||
}>()
|
||
|
||
const loading = ref(false)
|
||
const tableData = ref<any[]>([])
|
||
|
||
const showRequestData = ref(false)
|
||
const requestId = ref(0)
|
||
const requestType = ref('')
|
||
|
||
const pagination = reactive({
|
||
page: 1,
|
||
pageSize: 20,
|
||
total: 0
|
||
})
|
||
|
||
const orderId = computed(() => {
|
||
const id = props.data?.id
|
||
if (id === undefined || id === null || id === '') return ''
|
||
return String(id)
|
||
})
|
||
|
||
function extractLogListPayload(res: any): { list: any[]; total: number } {
|
||
if (!res) return { list: [], total: 0 }
|
||
const inner = res.data && typeof res.data === 'object' && !Array.isArray(res.data) ? res.data : res
|
||
const list = Array.isArray(inner.list)
|
||
? inner.list
|
||
: Array.isArray(res.list)
|
||
? res.list
|
||
: []
|
||
const totalRaw = inner.pagination?.total ?? inner.total ?? res.total
|
||
const total =
|
||
typeof totalRaw === 'number' && !Number.isNaN(totalRaw)
|
||
? totalRaw
|
||
: list.length
|
||
return { list, total }
|
||
}
|
||
|
||
function formatOperationLabel(row: any): string {
|
||
const name = row?.operation_name
|
||
const code = row?.operation_code
|
||
if (name && String(name).trim() && name !== code) return String(name)
|
||
if (name && String(name).trim()) return String(name)
|
||
if (code) return String(code)
|
||
return '—'
|
||
}
|
||
|
||
function hasExternalPayload(row: any): boolean {
|
||
const id = row?.external_log_id
|
||
if (id === undefined || id === null || id === '') return false
|
||
const n = typeof id === 'number' ? id : Number(id)
|
||
return Number.isFinite(n) && n > 0
|
||
}
|
||
|
||
watch(
|
||
() => orderId.value,
|
||
(newOrderId) => {
|
||
if (newOrderId) {
|
||
pagination.page = 1
|
||
loadOrderLogs()
|
||
} else {
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
}
|
||
},
|
||
{ immediate: true }
|
||
)
|
||
|
||
async function handlePageChange(page: number) {
|
||
pagination.page = page
|
||
await loadOrderLogs()
|
||
}
|
||
|
||
async function handlePageSizeChange(pageSize: number) {
|
||
pagination.pageSize = pageSize
|
||
pagination.page = 1
|
||
await loadOrderLogs()
|
||
}
|
||
|
||
async function handleRefresh() {
|
||
pagination.page = 1
|
||
await loadOrderLogs()
|
||
}
|
||
|
||
async function loadOrderLogs() {
|
||
if (!orderId.value) return
|
||
|
||
loading.value = true
|
||
try {
|
||
const response: any = await orderQueryOrderLogs({
|
||
id: orderId.value,
|
||
page: pagination.page,
|
||
pageSize: pagination.pageSize
|
||
})
|
||
if (response && ![1, 200].includes(response.code)) {
|
||
throw new Error(response?.message || '请求失败')
|
||
}
|
||
const { list, total } = extractLogListPayload(response)
|
||
tableData.value = list
|
||
pagination.total = total
|
||
} catch (error: any) {
|
||
console.error('order.queryOrderLogs failed:', error)
|
||
ElMessage.error(error?.message || '获取订单日志失败')
|
||
tableData.value = []
|
||
pagination.total = 0
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
function viewData(row: any) {
|
||
const raw = row.external_log_id
|
||
const n = typeof raw === 'number' ? raw : Number(raw)
|
||
requestId.value = Number.isFinite(n) ? n : 0
|
||
requestType.value = row.external_log_type || ''
|
||
showRequestData.value = true
|
||
}
|
||
</script>
|
||
|
||
<style scoped lang="scss">
|
||
.log-container {
|
||
height: 100%;
|
||
padding: 8px 10px;
|
||
overflow: hidden;
|
||
display: flex;
|
||
flex-direction: column;
|
||
box-sizing: border-box;
|
||
}
|
||
|
||
.toolbar-btn-group {
|
||
margin-bottom: 5px;
|
||
}
|
||
|
||
.cell-muted {
|
||
color: var(--el-text-color-placeholder);
|
||
font-size: 12px;
|
||
}
|
||
|
||
.el-table {
|
||
flex: 1;
|
||
}
|
||
|
||
.pagination-container {
|
||
display: flex;
|
||
justify-content: flex-end;
|
||
align-items: center;
|
||
padding: 5px 10px;
|
||
border-top: 1px solid #e8e8e8;
|
||
background: #fff;
|
||
flex-shrink: 0;
|
||
}
|
||
|
||
.pagination-container :deep(.el-pagination) {
|
||
--el-pagination-button-width: 28px;
|
||
--el-pagination-button-height: 28px;
|
||
font-size: 12px;
|
||
}
|
||
|
||
.pagination-container :deep(.el-pagination .el-select .el-input__wrapper) {
|
||
min-height: 24px;
|
||
}
|
||
|
||
.pagination-container :deep(.btn-prev),
|
||
.pagination-container :deep(.btn-next),
|
||
.pagination-container :deep(.el-pager li) {
|
||
border-radius: 4px;
|
||
color: #606266;
|
||
}
|
||
|
||
.pagination-container :deep(.el-pager li.is-active) {
|
||
color: #409eff;
|
||
font-weight: 600;
|
||
background: #ffffff;
|
||
}
|
||
|
||
:deep(.el-drawer__body) {
|
||
height: 100%;
|
||
padding: 0;
|
||
}
|
||
</style>
|