feat: 全面升级——后台优化 / 动态配置 / 个人中心 / OSS 存储

- OSS 文件存储(RustFS / S3 v4 兼容,零依赖手写 SigV4):
  上传/列表/删除走桶 arcticnewone,/uploads 代理服务 + 本地回退;
  server/utils/sigv4.ts 纯函数 + AWS 测试向量验证
- 业务动态配置:settings 表 + /api/settings(公开) + /api/admin/settings(PATCH),
  useSiteSettings 组合式,footer/contact/tools/app.vue/侧边栏/工具页全部接入,
  后台 /admin/settings 修改前台即时生效(站点/联系/社交/工具箱/页脚/SEO)
- 后台全面优化:Admin* 设计系统(按钮/输入/表单/卡片/徽标/弹窗/确认/空态/骨架/
  分页/页头/Toast)14 组件;Dashboard 增强;各列表页搜索/筛选/批量删除/分页;
  布局与侧边栏分组;统一 toast/确认反馈
- 个人中心全新重设计:顶部资料卡 + 统计、精致化改密/删号(二次确认)、
  收藏封面网格、评论卡片、移动端适配
- deploy.sh 支持 OSS 凭据注入(NUXT_OSS_*);.env.example 更新
- 测试 17 例全过(含 SigV4 AWS 向量、settings 默认结构)
This commit is contained in:
2026-08-06 18:40:17 +08:00
parent 685c7b51d1
commit 5a7ad8de11
55 changed files with 3857 additions and 1993 deletions
+180 -166
View File
@@ -1,124 +1,13 @@
<template>
<section class="p-4 md:p-8 lg:p-10">
<header class="mb-8 flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4">
<div class="flex items-center gap-3">
<div class="w-11 h-11 rounded-2xl bg-black text-white flex items-center justify-center flex-shrink-0">
<Icon name="ph:list-checks" class="w-6 h-6" />
</div>
<div>
<h1 class="text-2xl font-bold text-black leading-tight">操作日志</h1>
<p class="text-sm text-gray-500 mt-1">后台管理员的关键操作审计记录。</p>
</div>
</div>
<button
@click="clearLogs"
:disabled="!logs.length || clearing"
class="inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 disabled:opacity-40 disabled:cursor-not-allowed transition-colors flex-shrink-0"
title="清空全部操作日志"
>
<Icon v-if="clearing" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
<Icon v-else name="ph:trash" class="w-4 h-4" />
清空日志
</button>
</header>
<!-- 操作反馈 -->
<div
v-if="flash"
class="mb-6 px-4 py-3 rounded-xl text-sm font-medium flex items-center gap-2"
:class="flashKind === 'ok' ? 'bg-green-50 text-green-700 border border-green-200' : 'bg-red-50 text-red-700 border border-red-200'"
>
<Icon :name="flashKind === 'ok' ? 'ph:check-circle' : 'ph:warning-circle'" class="w-4 h-4" />
{{ flash }}
</div>
<div class="flex items-center gap-2 mb-4">
<span class="text-sm text-gray-500">共 {{ total }} 条日志</span>
</div>
<!-- 加载中 -->
<div v-if="loading" class="py-24 flex flex-col items-center gap-3 text-gray-400">
<Icon name="ph:circle-notch" class="w-8 h-8 animate-spin" />
<p class="text-sm">加载中…</p>
</div>
<!-- 加载失败 -->
<div v-else-if="loadError" class="py-24 text-center">
<div class="inline-flex flex-col items-center gap-3 text-gray-500">
<Icon name="ph:warning-circle" class="w-8 h-8 text-red-500" />
<p class="text-sm">{{ loadError }}</p>
<button @click="loadLogs" class="px-5 py-2 rounded-full bg-black text-white text-sm font-semibold hover:bg-gray-800 transition-colors">
重试
</button>
</div>
</div>
<!-- 空态 -->
<div v-else-if="!logs.length" class="py-24 flex flex-col items-center gap-3 text-gray-400">
<Icon name="ph:list-checks" class="w-10 h-10" />
<p class="text-sm">暂无操作日志</p>
</div>
<!-- 日志表格 -->
<div v-else class="bg-white rounded-2xl border border-gray-100 shadow-sm overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="text-left text-gray-500 border-b border-gray-100 bg-gray-50">
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap">时间</th>
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap">操作人</th>
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap">操作</th>
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider">对象</th>
<th class="px-6 py-4 font-semibold text-xs uppercase tracking-wider">详情</th>
</tr>
</thead>
<tbody>
<tr
v-for="log in logs"
:key="log.id"
class="border-b border-gray-100 last:border-b-0 hover:bg-gray-50/70 transition-colors"
>
<td class="px-6 py-4 text-gray-500 text-xs whitespace-nowrap">{{ formatDate(log.createdAt) }}</td>
<td class="px-6 py-4 text-gray-700 whitespace-nowrap">{{ log.actor_name || 'system' }}</td>
<td class="px-6 py-4 whitespace-nowrap">
<span
class="inline-flex items-center px-2.5 py-1 rounded-full text-xs font-semibold"
:class="actionMeta(log.action).cls"
>
{{ actionMeta(log.action).label }}
</span>
</td>
<td class="px-6 py-4">
<code class="text-xs text-gray-600 bg-gray-50 border border-gray-100 rounded px-2 py-1">{{ log.target }}</code>
</td>
<td class="px-6 py-4 text-gray-600 max-w-[320px] md:max-w-md truncate" :title="log.detail || undefined">
{{ log.detail || '—' }}
</td>
</tr>
</tbody>
</table>
</div>
<!-- 加载更多 -->
<div v-if="logs.length < total" class="p-4 border-t border-gray-100 flex justify-center">
<button
@click="loadMore"
:disabled="loadingMore"
class="inline-flex items-center gap-2 px-6 py-2.5 rounded-full border border-gray-200 bg-white text-sm font-semibold text-gray-700 hover:bg-gray-100 disabled:opacity-60 transition-colors"
>
<Icon v-if="loadingMore" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
{{ loadingMore ? '加载中…' : '加载更多' }}
</button>
</div>
</div>
</section>
</template>
<script setup lang="ts">
import { onMounted, ref } from 'vue'
/**
* 后台操作日志:后端分页 + 操作类型筛选 + 关键词检索(当前页过滤)+ 清空确认。
* - GET /api/admin/audit?page=&pageSize= → { logs, total, page, pageSize };DELETE /api/admin/audit
*/
import { computed, onMounted, ref, watch } from 'vue'
import { useToastStore } from '~/stores/toast'
definePageMeta({ middleware: 'admin', layout: 'admin' })
useSeoMeta({ title: '操作日志' })
useHead({ title: '操作日志' })
interface AuditLog {
id: number
@@ -129,41 +18,41 @@ interface AuditLog {
createdAt: string
}
const pageSize = 20
const page = ref(0)
const toast = useToastStore()
const ACTION_META: Record<string, { label: string; tone: 'green' | 'amber' | 'red' | 'blue' | 'gray' }> = {
create: { label: '新增', tone: 'green' },
update: { label: '更新', tone: 'amber' },
delete: { label: '删除', tone: 'red' },
upload: { label: '上传', tone: 'blue' },
clear: { label: '清空', tone: 'gray' },
}
const actionMeta = (action: string) =>
ACTION_META[action] ?? { label: action, tone: 'gray' as const }
const ACTION_OPTIONS = [
{ value: 'all', label: '全部操作' },
{ value: 'create', label: '新增' },
{ value: 'update', label: '更新' },
{ value: 'delete', label: '删除' },
{ value: 'upload', label: '上传' },
{ value: 'clear', label: '清空' },
]
/* ---------- 列表(后端分页) ---------- */
const pageSize = 15
const page = ref(1)
const total = ref(0)
const logs = ref<AuditLog[]>([])
const loading = ref(true)
const loadingMore = ref(false)
const loadError = ref('')
const ACTION_META: Record<string, { label: string; cls: string }> = {
create: { label: '新增', cls: 'bg-green-100 text-green-700' },
update: { label: '更新', cls: 'bg-amber-100 text-amber-700' },
delete: { label: '删除', cls: 'bg-red-100 text-red-700' },
upload: { label: '上传', cls: 'bg-blue-100 text-blue-700' },
clear: { label: '清空', cls: 'bg-gray-200 text-gray-600' },
}
const actionMeta = (action: string) => ACTION_META[action] ?? { label: action, cls: 'bg-gray-100 text-gray-700' }
const flash = ref('')
const flashKind = ref<'ok' | 'err'>('ok')
let flashTimer: ReturnType<typeof setTimeout> | null = null
const showFlash = (msg: string, kind: 'ok' | 'err' = 'ok') => {
flash.value = msg
flashKind.value = kind
if (flashTimer) clearTimeout(flashTimer)
flashTimer = setTimeout(() => {
flash.value = ''
}, 3000)
}
const loadLogs = async () => {
loading.value = true
loadError.value = ''
try {
const data = await $fetch<{ logs: AuditLog[]; total: number; page: number }>('/api/admin/audit', {
query: { page: 1, pageSize },
query: { page: page.value, pageSize },
})
logs.value = data.logs
total.value = data.total
@@ -176,35 +65,51 @@ const loadLogs = async () => {
}
}
const loadMore = async () => {
if (loadingMore.value || logs.value.length >= total.value) return
loadingMore.value = true
try {
const next = page.value + 1
const data = await $fetch<{ logs: AuditLog[]; total: number; page: number }>('/api/admin/audit', {
query: { page: next, pageSize },
})
logs.value.push(...data.logs)
page.value = data.page
} catch (err) {
console.error('load more audit error:', err)
showFlash('加载更多失败,请重试', 'err')
} finally {
loadingMore.value = false
}
onMounted(loadLogs)
const changePage = (p: number) => {
if (p === page.value) return
page.value = p
loadLogs()
}
/* ---------- 筛选 / 关键词(当前页过滤) ---------- */
const actionFilter = ref('all')
const keyword = ref('')
const filteredLogs = computed(() => {
const kw = keyword.value.trim().toLowerCase()
return logs.value.filter((log) => {
if (actionFilter.value !== 'all' && log.action !== actionFilter.value) return false
if (!kw) return true
return (
(log.actor_name || '').toLowerCase().includes(kw) ||
log.target.toLowerCase().includes(kw) ||
(log.detail || '').toLowerCase().includes(kw)
)
})
})
watch([actionFilter, keyword], () => {
if (page.value !== 1) {
page.value = 1
loadLogs()
}
})
/* ---------- 清空 ---------- */
const confirmClear = ref(false)
const clearing = ref(false)
const clearLogs = async () => {
if (!window.confirm('确定清空全部操作日志吗?此操作不可恢复。')) return
clearing.value = true
try {
await $fetch('/api/admin/audit', { method: 'DELETE' })
showFlash('日志已清空')
toast.success('日志已清空')
confirmClear.value = false
await loadLogs()
} catch (err) {
console.error('clear audit error:', err)
showFlash((err as any)?.data?.message || '清空失败,请重试', 'err')
} catch (err: any) {
toast.error(err?.data?.message || '清空失败,请重试')
} finally {
clearing.value = false
}
@@ -222,6 +127,115 @@ const formatDate = (raw?: string) => {
minute: '2-digit',
}).format(d)
}
onMounted(loadLogs)
</script>
<template>
<div>
<AdminPageHeader title="操作日志" subtitle="后台管理员的关键操作审计记录。">
<template #actions>
<AdminButton variant="danger" size="sm" :disabled="!total || clearing" :loading="clearing" @click="confirmClear = true">
<Icon name="ph:trash" class="w-4 h-4" /> 清空日志
</AdminButton>
</template>
</AdminPageHeader>
<!-- 统计 + 工具栏 -->
<div class="mb-4 flex flex-wrap items-center gap-x-4 gap-y-2">
<span class="text-sm text-gray-500">共 {{ total }} 条日志</span>
<span v-if="keyword" class="text-sm text-gray-400">· 当前页匹配 {{ filteredLogs.length }} 条</span>
</div>
<div class="mb-5 flex flex-col sm:flex-row gap-3">
<div class="relative flex-1 sm:max-w-xs">
<Icon name="ph:magnifying-glass" class="w-4 h-4 text-gray-400 absolute left-3.5 top-1/2 -translate-y-1/2 pointer-events-none" />
<input
v-model="keyword"
type="text"
placeholder="搜索操作人 / 对象 / 详情…"
class="w-full rounded-xl border border-gray-200 bg-white py-2.5 pl-10 pr-9 text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/10"
/>
<button
v-if="keyword"
@click="keyword = ''"
class="absolute right-2.5 top-1/2 -translate-y-1/2 w-5 h-5 rounded-full text-gray-400 hover:text-gray-600 hover:bg-gray-100 flex items-center justify-center"
aria-label="清空筛选"
>
<Icon name="ph:x" class="w-3.5 h-3.5" />
</button>
</div>
<AdminSelect v-model="actionFilter" :options="ACTION_OPTIONS" class="w-full sm:w-40" />
</div>
<!-- 加载态 -->
<AdminCard v-if="loading">
<AdminSkeleton :rows="6" />
</AdminCard>
<!-- 错误态 -->
<AdminCard v-else-if="loadError">
<div class="py-10 text-center">
<Icon name="ph:warning-circle" class="w-10 h-10 text-gray-300 mx-auto mb-4" />
<p class="text-gray-500 mb-4">{{ loadError }}</p>
<AdminButton size="sm" @click="loadLogs">重新加载</AdminButton>
</div>
</AdminCard>
<!-- 空态 -->
<AdminEmptyState v-else-if="!logs.length" icon="ph:list-checks" title="暂无操作日志" description="后台管理操作会自动记录在这里。" />
<AdminEmptyState
v-else-if="!filteredLogs.length"
icon="ph:magnifying-glass"
title="当前页没有匹配的日志"
description="换个关键词或筛选条件,或在其他页试试。"
/>
<!-- 日志表格 -->
<template v-else>
<div class="rounded-2xl border border-gray-100 bg-white shadow-sm overflow-hidden">
<div class="overflow-x-auto">
<table class="w-full text-sm">
<thead>
<tr class="text-left text-gray-400 border-b border-gray-100 bg-gray-50">
<th class="px-5 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap">时间</th>
<th class="px-5 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap">操作人</th>
<th class="px-5 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap">操作</th>
<th class="px-5 py-4 font-semibold text-xs uppercase tracking-wider">对象</th>
<th class="px-5 py-4 font-semibold text-xs uppercase tracking-wider">详情</th>
</tr>
</thead>
<tbody class="divide-y divide-gray-50">
<tr v-for="log in filteredLogs" :key="log.id" class="hover:bg-gray-50/60 transition-colors">
<td class="px-5 py-4 text-gray-500 text-xs whitespace-nowrap">{{ formatDate(log.createdAt) }}</td>
<td class="px-5 py-4 text-gray-700 whitespace-nowrap">{{ log.actor_name || 'system' }}</td>
<td class="px-5 py-4 whitespace-nowrap">
<AdminBadge :tone="actionMeta(log.action).tone">{{ actionMeta(log.action).label }}</AdminBadge>
</td>
<td class="px-5 py-4">
<code class="text-xs text-gray-600 bg-gray-50 border border-gray-100 rounded px-2 py-1">{{ log.target }}</code>
</td>
<td class="px-5 py-4 text-gray-600 max-w-[320px] md:max-w-md truncate" :title="log.detail || undefined">
{{ log.detail || '—' }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="mt-4">
<AdminPagination :total="total" :page="page" :page-size="pageSize" @page="changePage" />
</div>
</template>
<!-- 清空确认 -->
<AdminConfirm
:open="confirmClear"
:loading="clearing"
danger
message="确定清空全部操作日志吗?此操作不可恢复。"
@update:open="confirmClear = false"
@confirm="clearLogs"
/>
</div>
</template>