1 parent
42a173f742
commit
ae224649f3
25 files changed
+291
-313
No files matched your search
@@ -9,7 +9,6 @@ export function useMaintenance(pageKey) {
|
||||
page.rollbackPreview.value = null
|
||||
page.rollbackConfirmed.value = false
|
||||
}
|
||||
const auditPagination = usePagination(page.auditItems, 6)
|
||||
const backupPagination = usePagination(page.backups, 6)
|
||||
return { ...page, selectBackup, auditPagination, backupPagination }
|
||||
return { ...page, selectBackup, backupPagination }
|
||||
}
|
||||
+1
-33
@@ -149,36 +149,6 @@
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section v-else-if="pageKey === 'audit' && canAudit" class="maintenance-panel audit-panel">
|
||||
<div class="maintenance-body">
|
||||
<div class="panel-heading">
|
||||
<p class="heading-note">展示最近 50 条,导出最多 500 条记录。</p>
|
||||
<div class="audit-actions">
|
||||
<el-button size="small" :disabled="!!working" :loading="auditLoading" @click="loadAudit">查询</el-button>
|
||||
<el-button v-if="canExportAudit" size="small" type="primary" plain :disabled="!!working" :loading="working === 'export'" @click="exportAudit('json')">导出 JSON</el-button>
|
||||
<el-button v-if="canExportAudit" size="small" plain :disabled="!!working" :loading="working === 'export-csv'" @click="exportAudit('csv')">导出 CSV</el-button>
|
||||
</div>
|
||||
</div>
|
||||
<el-alert v-if="auditError" :title="auditError" type="warning" :closable="false" show-icon />
|
||||
<div v-else-if="auditItems.length" class="audit-list">
|
||||
<div v-for="{ entry: item } in auditRows" :key="item.id || `${item.createdAt}-${item.operation}`" class="audit-item">
|
||||
<div>
|
||||
<strong>{{ operationLabel(item.operation) }}</strong>
|
||||
<span>{{ sectionLabel(item.section) }} · {{ item.actorName || item.actorId || '系统' }}</span>
|
||||
<details v-if="item.changes?.length" class="audit-changes">
|
||||
<summary>{{ item.changes.length }} 个字段变更</summary>
|
||||
<p v-for="change in item.changes" :key="change.field">
|
||||
{{ change.field }}:{{ change.before }} → {{ change.after }}
|
||||
</p>
|
||||
</details>
|
||||
</div>
|
||||
<time>{{ formatTime(item.createdAt) }}</time>
|
||||
</div>
|
||||
</div>
|
||||
<el-empty v-else-if="!auditLoading" description="暂无配置审计记录" :image-size="72" />
|
||||
<ConfigPagination v-model:current-page="auditPage" :page-count="auditPageCount" :total="auditItems.length" label="审计记录" />
|
||||
</div>
|
||||
</section>
|
||||
<el-empty v-else description="当前账号无权访问此页面" />
|
||||
</template>
|
||||
</div>
|
||||
@@ -201,10 +171,8 @@ const {
|
||||
canRestart, serviceLabel, restartPreview, previewRestart, requestRestart,
|
||||
canRollback, backupsLoading, backupsError, backups, rollbackGeneration, rollbackConfirmed,
|
||||
rollbackPreview, loadBackups, selectBackup, previewRollback, executeRollback,
|
||||
canAudit, canExportAudit, auditLoading, auditError, auditItems, loadAudit, exportAudit,
|
||||
formatTime, sectionLabel, operationLabel, auditPagination, backupPagination
|
||||
formatTime, sectionLabel, backupPagination
|
||||
} = useMaintenance(props.pageKey)
|
||||
const { currentPage: auditPage, pageCount: auditPageCount, pageItems: auditRows } = auditPagination
|
||||
const { currentPage: backupPage, pageCount: backupPageCount, pageItems: backupRows } = backupPagination
|
||||
|
||||
defineExpose({ beforeLeave })
|
||||
|
||||
@@ -19,8 +19,7 @@ export function useNavigation() {
|
||||
const tools = [
|
||||
{ value: 'migration', label: '数据库迁移', capability: 'database.migrate' },
|
||||
{ value: 'restart', label: '服务重启', capability: 'service.restart' },
|
||||
{ value: 'backups', label: '备份与回滚', capability: 'config.rollback' },
|
||||
{ value: 'audit', label: '配置审计', capability: 'audit.read' }
|
||||
{ value: 'backups', label: '备份与回滚', capability: 'config.rollback' }
|
||||
]
|
||||
const sectionOptions = computed(() => store.hasCapability('config.read') ? pages : [])
|
||||
const maintenanceOptions = computed(() => store.hasCapability('config.read')
|
||||
|
||||
@@ -177,20 +177,15 @@
|
||||
.confirmation-check :deep(.el-checkbox__input) {
|
||||
margin-top: 3px;
|
||||
}
|
||||
.action-row,
|
||||
.audit-actions {
|
||||
.action-row {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 10px;
|
||||
margin-top: 12px;
|
||||
}
|
||||
.action-row > .el-button,
|
||||
.audit-actions > .el-button {
|
||||
.action-row > .el-button {
|
||||
margin-left: 0;
|
||||
}
|
||||
.audit-actions {
|
||||
margin-top: 0;
|
||||
}
|
||||
.maintenance-heading {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
@@ -315,37 +310,6 @@
|
||||
margin: 0;
|
||||
padding-left: 18px;
|
||||
}
|
||||
.audit-list {
|
||||
display: grid;
|
||||
gap: 10px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
.audit-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 16px;
|
||||
padding: 8px 12px;
|
||||
border-radius: var(--pm-radius-sm);
|
||||
background: var(--pm-bg-primary);
|
||||
}
|
||||
.audit-item div {
|
||||
display: grid;
|
||||
gap: 4px;
|
||||
min-width: 0;
|
||||
overflow-wrap: anywhere;
|
||||
}
|
||||
.audit-item strong {
|
||||
color: var(--pm-text-primary);
|
||||
}
|
||||
.audit-item span,
|
||||
.audit-item time {
|
||||
color: var(--pm-text-secondary);
|
||||
font-size: 13px;
|
||||
}
|
||||
.audit-item time {
|
||||
flex: none;
|
||||
}
|
||||
@container config-main (max-width: 620px) {
|
||||
.secret-editor {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
@@ -362,12 +326,7 @@
|
||||
.maintenance-summary {
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
.audit-item {
|
||||
align-items: stretch;
|
||||
flex-direction: column;
|
||||
}
|
||||
.action-row .el-button,
|
||||
.audit-actions .el-button {
|
||||
.action-row .el-button {
|
||||
flex: 1;
|
||||
min-width: 110px;
|
||||
}
|
||||
|
||||
@@ -26,14 +26,6 @@ const serviceLabels = {
|
||||
}
|
||||
|
||||
const sectionLabels = Object.fromEntries(sections.map(item => [item.value, item.label]))
|
||||
const operationLabels = {
|
||||
validate: '验证配置',
|
||||
update: '保存配置',
|
||||
apply: '应用配置',
|
||||
rollback_preview: '预览回滚',
|
||||
rollback_ticket: '签发回滚票据',
|
||||
rollback: '执行回滚'
|
||||
}
|
||||
|
||||
export function usePage(pageKey = 'base') {
|
||||
const isConfigPage = sections.some(item => item.value === pageKey)
|
||||
@@ -45,9 +37,7 @@ export function usePage(pageKey = 'base') {
|
||||
const saveFlow = ref('')
|
||||
const busy = computed(() => !!working.value || !!saveFlow.value)
|
||||
const backupsLoading = ref(false)
|
||||
const auditLoading = ref(false)
|
||||
const backupsError = ref('')
|
||||
const auditError = ref('')
|
||||
const status = reactive({
|
||||
setupState: '',
|
||||
tlsMode: '',
|
||||
@@ -116,7 +106,6 @@ export function usePage(pageKey = 'base') {
|
||||
const rollbackGeneration = ref(0)
|
||||
const rollbackConfirmed = ref(false)
|
||||
const rollbackPreview = ref(null)
|
||||
const auditItems = ref([])
|
||||
const databaseConfig = reactive({ type: '', name: '', localRef: '' })
|
||||
const migrationTargetName = ref('')
|
||||
const migrationTarget = reactive({ type: 'sqlite', host: '127.0.0.1', port: 3306, username: '', password: '' })
|
||||
@@ -161,8 +150,6 @@ export function usePage(pageKey = 'base') {
|
||||
|
||||
const canWrite = computed(() => globalStatus.hasCapability('config.write_global'))
|
||||
const canRollback = computed(() => globalStatus.hasCapability('config.rollback'))
|
||||
const canAudit = computed(() => globalStatus.hasCapability('audit.read'))
|
||||
const canExportAudit = computed(() => globalStatus.hasCapability('audit.export'))
|
||||
const canMigrate = computed(() => globalStatus.hasCapability('database.migrate'))
|
||||
const canRestart = computed(() => globalStatus.hasCapability('service.restart'))
|
||||
const stateLabel = computed(() => ({ new: '未初始化', bootstrap: '初始化中', ready: '就绪', degraded: '降级' }[status.setupState] || status.setupState || '未知'))
|
||||
@@ -208,7 +195,6 @@ export function usePage(pageKey = 'base') {
|
||||
const formatTime = value => value ? new Date(value).toLocaleString('zh-CN', { hour12: false }) : '-'
|
||||
const serviceLabel = value => serviceLabels[value] || value
|
||||
const sectionLabel = value => sectionLabels[value] || value || '-'
|
||||
const operationLabel = value => operationLabels[value] || value || '-'
|
||||
const migrationStatusLabels = {
|
||||
previewed: '已生成预览',
|
||||
created: '已创建',
|
||||
@@ -346,22 +332,6 @@ export function usePage(pageKey = 'base') {
|
||||
}
|
||||
}
|
||||
|
||||
const loadAudit = async () => {
|
||||
if (!canAudit.value) return
|
||||
auditLoading.value = true
|
||||
auditError.value = ''
|
||||
try {
|
||||
const response = await http.get('/api/v1/audits/config?limit=50')
|
||||
notifyResponseError(response, '配置审计读取失败')
|
||||
auditItems.value = Array.isArray(response.data) ? response.data : []
|
||||
} catch (error) {
|
||||
auditItems.value = []
|
||||
auditError.value = error.message || '配置审计读取失败'
|
||||
} finally {
|
||||
auditLoading.value = false
|
||||
}
|
||||
}
|
||||
|
||||
const previewDatabaseMigration = async () => {
|
||||
if (!canMigrate.value || working.value || sectionError.value || !migrationReady.value) return
|
||||
working.value = 'migration-preview'
|
||||
@@ -499,7 +469,6 @@ export function usePage(pageKey = 'base') {
|
||||
if (isConfigPage || (pageKey === 'migration' && canMigrate.value)) await loadSection()
|
||||
if (isConfigPage) await loadPending()
|
||||
if (pageKey === 'backups') await loadBackups()
|
||||
if (pageKey === 'audit') await loadAudit()
|
||||
} catch (error) {
|
||||
availabilityError.value = error.message || '配置管理数据读取失败'
|
||||
} finally {
|
||||
@@ -723,38 +692,6 @@ export function usePage(pageKey = 'base') {
|
||||
}
|
||||
}
|
||||
|
||||
const exportAudit = async format => {
|
||||
if (!canExportAudit.value || working.value) return
|
||||
working.value = format === 'csv' ? 'export-csv' : 'export'
|
||||
try {
|
||||
const response = await requestWithRecentAuthentication(() => http.post(
|
||||
'/api/v1/audits/config', { format, limit: 500 }, { responseType: 'blob' }
|
||||
))
|
||||
if (!(response instanceof Blob)) {
|
||||
throw new Error(response?.errorMsg || '审计导出响应格式不正确')
|
||||
}
|
||||
// Blob 请求也可能返回 JSON 业务错误,不能把错误响应当作审计文件下载。
|
||||
if (response.type.includes('json') || format === 'json') {
|
||||
const payload = JSON.parse(await response.text())
|
||||
if (payload && !Array.isArray(payload) && Object.hasOwn(payload, 'errorNo') && payload.errorNo !== 0) {
|
||||
throw new Error(payload.errorMsg || '审计导出失败')
|
||||
}
|
||||
}
|
||||
const blob = response
|
||||
const url = URL.createObjectURL(blob)
|
||||
const anchor = document.createElement('a')
|
||||
anchor.href = url
|
||||
anchor.download = `smail-config-audit.${format}`
|
||||
anchor.click()
|
||||
URL.revokeObjectURL(url)
|
||||
ElMessage.success('审计记录已导出')
|
||||
} catch (error) {
|
||||
if (!isRecentAuthenticationCancelled(error)) ElMessage.error(error.message || '审计导出失败')
|
||||
} finally {
|
||||
working.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
const beforeLeave = async () => {
|
||||
if (busy.value) {
|
||||
ElMessage.warning('当前操作尚未完成,请稍后再切换页面')
|
||||
@@ -795,11 +732,11 @@ export function usePage(pageKey = 'base') {
|
||||
loading, availabilityError, working, status, stateLabel, stateTagType, sectionOptions: sections,
|
||||
selectedSection, currentSection, sectionLoading, editorText, formConfig, formErrors, updateField, updateSecret,
|
||||
sectionError, saveError, sensitiveHint, secretField, secretValue,
|
||||
confirmed, savedGeneration, pendingCandidate, managePending, validationResult, canWrite, canRollback, canAudit, canExportAudit,
|
||||
confirmed, savedGeneration, pendingCandidate, managePending, validationResult, canWrite, canRollback,
|
||||
backupsLoading, backupsError, backups, rollbackGeneration, rollbackConfirmed, rollbackPreview,
|
||||
auditLoading, auditError, auditItems, loadAll, loadSection, validateConfig, saveConfig, applyConfig, saveAndApply, continuePending,
|
||||
loadBackups, previewRollback, executeRollback, loadAudit, exportAudit, formatTime,
|
||||
serviceLabel, sectionLabel, operationLabel, databaseConfig, databaseTypeLabel, canMigrate,
|
||||
loadAll, loadSection, validateConfig, saveConfig, applyConfig, saveAndApply, continuePending,
|
||||
loadBackups, previewRollback, executeRollback, formatTime,
|
||||
serviceLabel, sectionLabel, databaseConfig, databaseTypeLabel, canMigrate,
|
||||
migrationTargetName, migrationPreview, migrationToken, migrationRecord, migrationStatusLabel, migrationStatusType,
|
||||
migrationTarget, migrationReady, migrationError, invalidateMigration, changeMigrationType,
|
||||
previewDatabaseMigration, loadMigrationStatus, executeDatabaseMigration, canRestart, restartPreview,
|
||||
|
||||
@@ -3,7 +3,7 @@ import { http } from '@/utils/axios'
|
||||
import { parseRuntimeLine, summarizeRuntime, timeParts } from './RuntimeLog.js'
|
||||
|
||||
export function useLogs() {
|
||||
const category = ref('config')
|
||||
const category = ref('operation')
|
||||
const loading = ref(false)
|
||||
const error = ref('')
|
||||
const items = ref([])
|
||||
@@ -25,7 +25,6 @@ export function useLogs() {
|
||||
let appliedFilters = {}
|
||||
|
||||
const categories = [
|
||||
{ label: '配置审计', value: 'config' },
|
||||
{ label: '操作记录', value: 'operation' },
|
||||
{ label: '收发信记录', value: 'mail' },
|
||||
{ label: '运行日志', value: 'runtime' }
|
||||
@@ -36,7 +35,6 @@ export function useLogs() {
|
||||
const actionLabel = value => ({ update: '保存配置', rollback: '回滚配置', migration: '迁移配置' }[value] || value)
|
||||
const displayActor = item => item.payload?.actorName || (item.actorId && item.actorId !== '0' ? item.actorId : '系统')
|
||||
const details = computed(() => detail.value?.payload || {})
|
||||
const changes = computed(() => details.value.changes || [])
|
||||
const runtimeRows = computed(() => lines.value.map((line, index) => parseRuntimeLine(line, offset.value + index + 1)))
|
||||
const runtimeSummary = computed(() => summarizeRuntime(runtimeRows.value))
|
||||
const visibleCount = computed(() => isRuntime.value ? lines.value.length : items.value.length)
|
||||
@@ -125,7 +123,7 @@ export function useLogs() {
|
||||
|
||||
return {
|
||||
category, categories, loading, error, items, lines, offset,
|
||||
hasMore, actorId, dateRange, detail, details, changes, isRuntime,
|
||||
hasMore, actorId, dateRange, detail, details, isRuntime,
|
||||
runtimeDetail, runtimeRows, runtimeSummary, visibleCount, pageRange,
|
||||
currentCategory, resultType, runtimeRowClass, timeParts,
|
||||
formatTime, resultLabel, actionLabel, displayActor, search, recent, next, previous
|
||||
|
||||
@@ -129,15 +129,7 @@
|
||||
<el-dialog :model-value="Boolean(detail)" title="日志详情" width="min(760px, 92vw)" append-to-body @close="detail = null">
|
||||
<template v-if="detail">
|
||||
<p>{{ formatTime(detail.createdAt) }} · {{ displayActor(detail) }} · {{ actionLabel(detail.action) }}</p>
|
||||
<el-table v-if="changes.length" :data="changes" max-height="440">
|
||||
<el-table-column prop="field" label="变更字段" min-width="200" />
|
||||
<el-table-column prop="before" label="修改前" min-width="150" />
|
||||
<el-table-column prop="after" label="修改后" min-width="150" />
|
||||
</el-table>
|
||||
<p v-else-if="category === 'config'">
|
||||
{{ detail.id.startsWith('legacy-') || !details.actorName ? '此记录未保存字段前后值,不补造历史详情。' : '此次保存没有业务字段变更。' }}
|
||||
</p>
|
||||
<dl v-else-if="category === 'mail'" class="log-detail-grid">
|
||||
<dl v-if="category === 'mail'" class="log-detail-grid">
|
||||
<dt>发件人</dt><dd>{{ details.sender || '—' }}</dd>
|
||||
<dt>收件人数</dt><dd>{{ details.recipientCount }}</dd>
|
||||
<dt>邮件大小</dt><dd>{{ details.bytes }} 字节</dd>
|
||||
@@ -157,7 +149,7 @@ import { useLogs } from './LogSettings.js'
|
||||
|
||||
const {
|
||||
category, categories, loading, error, items, offset,
|
||||
hasMore, actorId, dateRange, detail, details, changes, isRuntime,
|
||||
hasMore, actorId, dateRange, detail, details, isRuntime,
|
||||
runtimeDetail, runtimeRows, runtimeSummary, pageRange,
|
||||
currentCategory, resultType, runtimeRowClass, timeParts,
|
||||
formatTime, resultLabel, actionLabel, displayActor, search, recent, next, previous
|
||||
|
||||
Reference in new issue
Block a user