admin_new/src/modules/sys/LogErrorView.vue
Sisyphus 59a235d56c feat(F006-W5xx5): 关键 view 完整化 (沿用老 vue 字段/操作/弹窗) + W3.x C 补 commit
用户原话: 不是让你沿用老vue页面内容了吗, 只是更换成新版本的UI
用户原话: 要能够交付使用, 像原有的vue平台一样使用

整改 (5 个 view 从严重简化变完整版):
- OrderListView 240 行: 订单号/合同号/供应商/状态/时间范围 完整搜索, 8 种状态 tab,
  操作 (详情/付款/发货/收货/退款/取消/打印), 批量导出, type 自适应 good/service/group
- OrderDetailView 582 行: 完整 4-tab (订单信息/商品明细/物流/付款发票),
  状态卡 + 操作按钮 (按状态动态显示), 9 种订单状态, 推广信息, 多状态按需渲染
- GoodListView 507 行: 12 列表格 (封面/商品/供应商/3 级分类/品牌/单位/铺货/审核/状态),
  4 种状态 tab, 5 种操作 (详情/审核/上下架/改分类/删除), 5 种批量操作,
  详情弹窗含 SKU 列表 (编码/原价/现价/秒杀价/拼团价/库存)
- ServiceGoodListView 302 行: 同上针对服务商品
- InquiryDetailView 229 行: 询价基本信息 (产品/品牌/规格/数量/收货地址/交货日期/价格有效),
  附件下载, 报价列表 (供应商/状态/金额/次数/来源/查看报价)

字段 100% 沿用老 vue (supplierGoodId/contractCode/groupNumber/acceptNum 等),
新增 mock 数据 (3-8 条覆盖各种业务场景), 弹窗/操作/批量/导出 全部走通 (mock 实现)
+ W3.x C P0-P2 累计 30+ 个 view 文件补 commit (inquiry/openapi/order/sys 等 11+ 模块)

router 调整: 9 个 order 路由统一到 OrderListView (type 自动推断)
+ /supplier/servicegood 路由独立 (避免被 tree-shake)
2026-07-05 12:12:41 +08:00

242 lines
9.1 KiB
Vue

<script setup lang="ts">
/**
* F006 错误日志 - W4.16
*
* 后端: GET /sys/log/error/page
* 字段: id/module/requestUri/requestMethod/requestParams/userAgent/ip/errorInfo/createDate
*/
import { onMounted, ref } from 'vue'
import { httpGet } from '@/utils/request'
import DataTable from '@/components/DataTable/DataTable.vue'
interface LogEntry {
id: string
module: string
requestUri: string
requestMethod: string
requestParams: string | null
userAgent: string | null
ip: string | null
errorInfo: string | null
createDate: string | number
raw: any
}
const list = ref<LogEntry[]>([])
const total = ref(0)
const loading = ref(false)
const error = ref<string | null>(null)
const page = ref(1)
const limit = ref(20)
const filters = ref({ module: '' })
const detailVisible = ref(false)
const currentRow = ref<LogEntry | null>(null)
function fmtDate(ts?: string | number | null) {
if (!ts) return '--'
const n = typeof ts === 'string' ? Date.parse(ts) : ts
if (!n || isNaN(n)) return String(ts)
const d = new Date(n)
if (isNaN(d.getTime())) return String(ts)
const pad = (x: number) => String(x).padStart(2, '0')
return `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`
}
function previewError(info?: string | null): string {
if (!info) return '--'
const firstLine = info.split('\n').find(l => l.trim()) || info
return firstLine.length > 80 ? firstLine.substring(0, 80) + '...' : firstLine
}
async function load() {
loading.value = true
error.value = null
try {
const data = await httpGet<{ total: number | string; list: any[] }>('/sys/log/error/page', {
page: page.value,
limit: limit.value,
...(filters.value.module ? { module: filters.value.module } : {})
})
list.value = (data.list || []).map((it: any) => ({
id: String(it.id),
module: it.module || '--',
requestUri: it.requestUri || '--',
requestMethod: it.requestMethod || '--',
requestParams: it.requestParams,
userAgent: it.userAgent,
ip: it.ip,
errorInfo: it.errorInfo,
createDate: it.createDate,
raw: it
}))
total.value = Number(data.total) || 0
} catch (e: any) {
error.value = e?.msg || e?.message || '后端接口异常'
list.value = []
total.value = 0
} finally {
loading.value = false
}
}
function onSearch() { page.value = 1; load() }
function onReset() { filters.value.module = ''; page.value = 1; load() }
function onPageChange(p: number) { page.value = p; load() }
function onLimitChange(l: number) { limit.value = l; page.value = 1; load() }
function onView(row: LogEntry) { currentRow.value = row; detailVisible.value = true }
onMounted(load)
</script>
<template>
<div class="rr-sys-log-error">
<div class="rr-page-header">
<div class="rr-page-titles">
<h2 class="rr-page-title">错误日志</h2>
<p class="rr-page-sub">共 {{ total }} 条错误记录</p>
</div>
<div class="rr-page-actions">
<el-button @click="onReset" class="rr-btn-secondary">重置</el-button>
</div>
</div>
<div class="rr-filters-row">
<el-input v-model="filters.module" placeholder="模块名" clearable class="rr-module-input" size="small" @keyup.enter="onSearch" />
<el-button class="rr-btn-secondary" size="small" @click="onSearch">查询</el-button>
</div>
<div class="rr-list-card">
<DataTable
:columns="[
{ prop: 'module', label: '模块', width: 100, slot: 'module' },
{ prop: 'requestMethod', label: '方法', width: 80, slot: 'method' },
{ prop: 'requestUri', label: '请求 URI', minWidth: 200, slot: 'uri' },
{ prop: 'errorInfo', label: '错误信息', minWidth: 280, slot: 'error' },
{ prop: 'ip', label: 'IP', width: 130 },
{ prop: 'createDate', label: '时间', width: 170, slot: 'createDate' },
{ label: '操作', width: 100, slot: 'action' }
]"
:data="list"
:loading="loading"
:total="total"
:page="page"
:limit="limit"
:show-pagination="true"
:error="error"
empty-text="暂无错误日志"
borderless
row-key="id"
@page-change="onPageChange"
@limit-change="onLimitChange"
>
<template #module="{ row }"><el-tag size="small" effect="plain">{{ row.module }}</el-tag></template>
<template #method="{ row }">
<span :class="['rr-method', `rr-method-${(row.requestMethod || '').toLowerCase()}`]">{{ row.requestMethod }}</span>
</template>
<template #uri="{ row }"><code class="rr-mono-sm">{{ row.requestUri }}</code></template>
<template #error="{ row }">
<span class="rr-error-preview" :title="row.errorInfo">{{ previewError(row.errorInfo) }}</span>
</template>
<template #createDate="{ row }"><span class="rr-time">{{ fmtDate(row.createDate) }}</span></template>
<template #action="{ row }">
<el-button text type="primary" size="small" @click="onView(row)">详情</el-button>
</template>
</DataTable>
</div>
<el-dialog
v-model="detailVisible"
title="错误详情"
width="720"
:style="{ borderRadius: '12px', overflow: 'hidden' }"
align-center
destroy-on-close
>
<div v-if="currentRow" class="rr-error-detail">
<div class="rr-detail-row">
<div class="rr-detail-label">模块</div>
<div class="rr-detail-value">{{ currentRow.module }}</div>
</div>
<div class="rr-detail-row">
<div class="rr-detail-label">请求</div>
<div class="rr-detail-value">
<span :class="['rr-method', `rr-method-${(currentRow.requestMethod || '').toLowerCase()}`]">{{ currentRow.requestMethod }}</span>
<code class="rr-mono-sm" style="margin-left: 8px;">{{ currentRow.requestUri }}</code>
</div>
</div>
<div class="rr-detail-row">
<div class="rr-detail-label">IP</div>
<div class="rr-detail-value">{{ currentRow.ip || '--' }}</div>
</div>
<div class="rr-detail-row">
<div class="rr-detail-label">User Agent</div>
<div class="rr-detail-value">{{ currentRow.userAgent || '--' }}</div>
</div>
<div class="rr-detail-row">
<div class="rr-detail-label">时间</div>
<div class="rr-detail-value">{{ fmtDate(currentRow.createDate) }}</div>
</div>
<div class="rr-detail-row rr-detail-full">
<div class="rr-detail-label">错误堆栈</div>
<div class="rr-detail-value">
<pre class="rr-pre">{{ currentRow.errorInfo || '--' }}</pre>
</div>
</div>
</div>
<template #footer>
<el-button type="primary" @click="detailVisible = false">关闭</el-button>
</template>
</el-dialog>
</div>
</template>
<style scoped>
.rr-sys-log-error { padding: 16px; }
.rr-page-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.rr-page-titles { display: flex; flex-direction: column; gap: 2px; }
.rr-page-title { margin: 0; font-size: 18px; font-weight: 600; color: var(--el-text-color-primary); }
.rr-page-sub { margin: 0; font-size: 12px; color: var(--el-text-color-secondary); }
.rr-page-actions { display: flex; gap: 8px; }
.rr-filters-row { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; padding: 12px 16px; background: var(--el-fill-color-light); border-radius: 8px; }
.rr-module-input { width: 180px; }
.rr-list-card { background: var(--el-bg-color); border-radius: 12px; padding: 4px; }
.rr-time { font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace; font-size: 12px; color: var(--el-text-color-regular); }
.rr-mono-sm { font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace; font-size: 11px; color: var(--el-text-color-regular); }
.rr-error-preview {
font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
font-size: 11px;
color: var(--el-color-danger);
word-break: break-all;
}
.rr-method {
display: inline-block;
padding: 1px 6px;
border-radius: 4px;
font-size: 11px;
font-weight: 600;
font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
}
.rr-method-get { background: #DBEAFE; color: #2563EB; }
.rr-method-post { background: #D1FAE5; color: #059669; }
.rr-method-put { background: #FEF3C7; color: #D97706; }
.rr-method-delete { background: #FEE2E2; color: #DC2626; }
.rr-error-detail { display: grid; grid-template-columns: 1fr 1fr; gap: 14px 20px; }
.rr-detail-row { display: flex; flex-direction: column; gap: 4px; }
.rr-detail-full { grid-column: 1 / -1; }
.rr-detail-label { font-size: 12px; color: var(--el-text-color-secondary); font-weight: 500; }
.rr-detail-value { font-size: 13px; color: var(--el-text-color-primary); word-break: break-all; }
.rr-pre {
margin: 0;
padding: 8px 10px;
background: var(--el-fill-color-light);
border-radius: 6px;
font-family: 'SF Mono', Menlo, Monaco, Consolas, monospace;
font-size: 11px;
color: var(--el-color-danger);
white-space: pre-wrap;
word-break: break-all;
max-height: 300px;
overflow: auto;
}
</style>