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:
+261
-124
@@ -1,110 +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:envelope" 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">订阅了站内更新的邮箱列表,可导出 CSV。</p>
|
||||
</div>
|
||||
</div>
|
||||
<a
|
||||
:href="'/api/admin/subscribers/export'"
|
||||
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 transition-colors flex-shrink-0"
|
||||
title="导出全部订阅邮箱"
|
||||
>
|
||||
<Icon name="ph:download-simple" class="w-4 h-4" />
|
||||
导出 CSV
|
||||
</a>
|
||||
</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">共 {{ subscribers.length }} 个订阅</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="loadSubscribers" 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="!subscribers.length" class="py-24 flex flex-col items-center gap-3 text-gray-400">
|
||||
<Icon name="ph:envelope" 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">邮箱</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 text-right">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr
|
||||
v-for="s in subscribers"
|
||||
:key="s.id"
|
||||
class="border-b border-gray-100 last:border-b-0 hover:bg-gray-50/70 transition-colors"
|
||||
>
|
||||
<td class="px-6 py-4">
|
||||
<a :href="`mailto:${s.email}`" class="inline-flex items-center gap-2 font-semibold text-black hover:text-gray-600 transition-colors">
|
||||
<Icon name="ph:envelope-simple" class="w-4 h-4 text-gray-400" />
|
||||
{{ s.email }}
|
||||
</a>
|
||||
</td>
|
||||
<td class="px-6 py-4 text-gray-500 text-xs whitespace-nowrap">{{ formatDate(s.createdAt) }}</td>
|
||||
<td class="px-6 py-4">
|
||||
<div class="flex items-center justify-end">
|
||||
<button
|
||||
@click="removeSubscriber(s)"
|
||||
class="w-8 h-8 rounded-full flex items-center justify-center text-gray-400 hover:bg-red-50 hover:text-red-600 transition-colors"
|
||||
title="删除订阅"
|
||||
>
|
||||
<Icon name="ph:trash" class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from 'vue'
|
||||
/**
|
||||
* 后台订阅管理:列表 + 搜索 + 多选批量删除 + 导出 CSV + 前端分页。
|
||||
* - GET/DELETE /api/admin/subscribers[/id];导出 GET /api/admin/subscribers/export
|
||||
*/
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useToastStore } from '~/stores/toast'
|
||||
|
||||
definePageMeta({ middleware: 'admin', layout: 'admin' })
|
||||
useSeoMeta({ title: '邮件订阅' })
|
||||
useHead({ title: '订阅管理' })
|
||||
|
||||
interface AdminSubscriber {
|
||||
id: number
|
||||
@@ -112,22 +15,13 @@ interface AdminSubscriber {
|
||||
createdAt: string
|
||||
}
|
||||
|
||||
const toast = useToastStore()
|
||||
|
||||
/* ---------- 列表 ---------- */
|
||||
const subscribers = ref<AdminSubscriber[]>([])
|
||||
const loading = ref(true)
|
||||
const loadError = ref('')
|
||||
|
||||
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 loadSubscribers = async () => {
|
||||
loading.value = true
|
||||
loadError.value = ''
|
||||
@@ -142,15 +36,108 @@ const loadSubscribers = async () => {
|
||||
}
|
||||
}
|
||||
|
||||
const removeSubscriber = async (s: AdminSubscriber) => {
|
||||
if (!window.confirm(`确定取消订阅「${s.email}」吗?此操作不可恢复。`)) return
|
||||
onMounted(loadSubscribers)
|
||||
|
||||
/* ---------- 搜索 / 分页 ---------- */
|
||||
const keyword = ref('')
|
||||
const filteredSubscribers = computed(() => {
|
||||
const kw = keyword.value.trim().toLowerCase()
|
||||
if (!kw) return subscribers.value
|
||||
return subscribers.value.filter((s) => s.email.toLowerCase().includes(kw))
|
||||
})
|
||||
|
||||
const pageSize = 15
|
||||
const page = ref(1)
|
||||
const totalPages = computed(() => Math.max(1, Math.ceil(filteredSubscribers.value.length / pageSize)))
|
||||
|
||||
const pagedSubscribers = computed(() => {
|
||||
const p = Math.min(page.value, totalPages.value)
|
||||
const start = (p - 1) * pageSize
|
||||
return filteredSubscribers.value.slice(start, start + pageSize)
|
||||
})
|
||||
|
||||
watch(keyword, () => {
|
||||
page.value = 1
|
||||
})
|
||||
|
||||
const changePage = (p: number) => {
|
||||
page.value = Math.min(Math.max(1, p), totalPages.value)
|
||||
}
|
||||
|
||||
/* ---------- 多选 / 批量删除 ---------- */
|
||||
const selected = ref<Set<number>>(new Set())
|
||||
|
||||
const allChecked = computed(
|
||||
() => pagedSubscribers.value.length > 0 && pagedSubscribers.value.every((s) => selected.value.has(s.id)),
|
||||
)
|
||||
|
||||
const toggleAll = () => {
|
||||
if (allChecked.value) {
|
||||
for (const s of pagedSubscribers.value) selected.value.delete(s.id)
|
||||
selected.value = new Set(selected.value)
|
||||
} else {
|
||||
const next = new Set(selected.value)
|
||||
for (const s of pagedSubscribers.value) next.add(s.id)
|
||||
selected.value = next
|
||||
}
|
||||
}
|
||||
|
||||
const toggleOne = (id: number) => {
|
||||
const next = new Set(selected.value)
|
||||
if (next.has(id)) next.delete(id)
|
||||
else next.add(id)
|
||||
selected.value = next
|
||||
}
|
||||
|
||||
const batchConfirmOpen = ref(false)
|
||||
const batchDeleting = ref(false)
|
||||
|
||||
const doBatchDelete = async () => {
|
||||
const ids = [...selected.value]
|
||||
if (!ids.length) return
|
||||
batchDeleting.value = true
|
||||
let failed = 0
|
||||
for (const id of ids) {
|
||||
try {
|
||||
await $fetch(`/api/admin/subscribers/${id}`, { method: 'DELETE' })
|
||||
} catch (err: any) {
|
||||
console.error('batch delete subscriber error:', err)
|
||||
failed++
|
||||
}
|
||||
}
|
||||
batchDeleting.value = false
|
||||
batchConfirmOpen.value = false
|
||||
selected.value = new Set()
|
||||
if (failed === 0) {
|
||||
toast.success(`已取消订阅 ${ids.length} 个邮箱`)
|
||||
} else {
|
||||
toast.error(`删除 ${ids.length - failed} 个成功,${failed} 个失败`)
|
||||
}
|
||||
await loadSubscribers()
|
||||
}
|
||||
|
||||
/* ---------- 单条删除 ---------- */
|
||||
const confirmDelete = ref<AdminSubscriber | null>(null)
|
||||
const deleting = ref(false)
|
||||
|
||||
const askDelete = (s: AdminSubscriber) => {
|
||||
confirmDelete.value = s
|
||||
}
|
||||
|
||||
const doDelete = async () => {
|
||||
const s = confirmDelete.value
|
||||
if (!s) return
|
||||
deleting.value = true
|
||||
try {
|
||||
await $fetch(`/api/admin/subscribers/${s.id}`, { method: 'DELETE' })
|
||||
subscribers.value = subscribers.value.filter((x) => x.id !== s.id)
|
||||
showFlash(`已取消订阅「${s.email}」`)
|
||||
} catch (err) {
|
||||
console.error('delete subscriber error:', err)
|
||||
showFlash((err as any)?.data?.message || '删除失败,请重试', 'err')
|
||||
selected.value.delete(s.id)
|
||||
toast.success(`已取消订阅「${s.email}」`)
|
||||
confirmDelete.value = null
|
||||
} catch (err: any) {
|
||||
toast.error(err?.data?.message || '删除失败,请重试')
|
||||
} finally {
|
||||
deleting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,6 +153,156 @@ const formatDate = (raw?: string) => {
|
||||
minute: '2-digit',
|
||||
}).format(d)
|
||||
}
|
||||
|
||||
onMounted(loadSubscribers)
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<AdminPageHeader title="订阅管理" subtitle="订阅了站内更新的邮箱列表,可导出 CSV。">
|
||||
<template #actions>
|
||||
<a
|
||||
:href="'/api/admin/subscribers/export'"
|
||||
class="inline-flex items-center justify-center gap-2 rounded-xl bg-black px-4 py-2 text-sm font-semibold text-white shadow-sm transition-all duration-200 hover:bg-gray-800"
|
||||
title="导出全部订阅邮箱"
|
||||
>
|
||||
<Icon name="ph:download-simple" class="w-4 h-4" /> 导出 CSV
|
||||
</a>
|
||||
</template>
|
||||
</AdminPageHeader>
|
||||
|
||||
<!-- 统计 + 工具栏 -->
|
||||
<div class="mb-4 flex flex-wrap items-center gap-x-4 gap-y-2">
|
||||
<span class="text-sm text-gray-500">共 {{ subscribers.length }} 个订阅</span>
|
||||
<span v-if="selected.size" class="text-sm text-gray-400">· 已选 {{ selected.size }} 项</span>
|
||||
</div>
|
||||
|
||||
<div class="mb-5 flex flex-wrap items-center 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>
|
||||
<AdminButton variant="danger" size="sm" :disabled="!selected.size" @click="batchConfirmOpen = true">
|
||||
<Icon name="ph:trash" class="w-4 h-4" /> 批量删除
|
||||
</AdminButton>
|
||||
</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="loadSubscribers">重新加载</AdminButton>
|
||||
</div>
|
||||
</AdminCard>
|
||||
|
||||
<!-- 空态 -->
|
||||
<AdminEmptyState v-else-if="!subscribers.length" icon="ph:envelope" title="暂无订阅" description="还没有人订阅站内更新。" />
|
||||
|
||||
<AdminEmptyState
|
||||
v-else-if="!filteredSubscribers.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 w-10">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="allChecked"
|
||||
class="w-4 h-4 rounded border-gray-300 accent-black cursor-pointer"
|
||||
@change="toggleAll"
|
||||
/>
|
||||
</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 whitespace-nowrap">订阅时间</th>
|
||||
<th class="px-5 py-4 font-semibold text-xs uppercase tracking-wider text-right">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="divide-y divide-gray-50">
|
||||
<tr
|
||||
v-for="s in pagedSubscribers"
|
||||
:key="s.id"
|
||||
class="hover:bg-gray-50/60 transition-colors"
|
||||
:class="selected.has(s.id) ? 'bg-gray-50/70' : ''"
|
||||
>
|
||||
<td class="px-5 py-4">
|
||||
<input
|
||||
type="checkbox"
|
||||
:checked="selected.has(s.id)"
|
||||
class="w-4 h-4 rounded border-gray-300 accent-black cursor-pointer"
|
||||
@change="toggleOne(s.id)"
|
||||
/>
|
||||
</td>
|
||||
<td class="px-5 py-4">
|
||||
<a
|
||||
:href="`mailto:${s.email}`"
|
||||
class="inline-flex items-center gap-2 font-semibold text-black hover:text-gray-600 transition-colors"
|
||||
>
|
||||
<Icon name="ph:envelope-simple" class="w-4 h-4 text-gray-400" />
|
||||
{{ s.email }}
|
||||
</a>
|
||||
</td>
|
||||
<td class="px-5 py-4 text-gray-500 text-xs whitespace-nowrap">{{ formatDate(s.createdAt) }}</td>
|
||||
<td class="px-5 py-4">
|
||||
<div class="flex items-center justify-end">
|
||||
<AdminButton size="sm" variant="ghost" @click="askDelete(s)">
|
||||
<Icon name="ph:trash" class="w-4 h-4" />
|
||||
</AdminButton>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-4">
|
||||
<AdminPagination :total="filteredSubscribers.length" :page="page" :page-size="pageSize" @page="changePage" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 批量删除确认 -->
|
||||
<AdminConfirm
|
||||
:open="batchConfirmOpen"
|
||||
:loading="batchDeleting"
|
||||
danger
|
||||
:message="`确定删除已选的 ${selected.size} 个订阅邮箱吗?此操作不可恢复。`"
|
||||
@update:open="batchConfirmOpen = false"
|
||||
@confirm="doBatchDelete"
|
||||
/>
|
||||
|
||||
<!-- 单条删除确认 -->
|
||||
<AdminConfirm
|
||||
:open="!!confirmDelete"
|
||||
:loading="deleting"
|
||||
danger
|
||||
:message="`确定取消订阅「${confirmDelete?.email}」吗?此操作不可恢复。`"
|
||||
@update:open="confirmDelete = null"
|
||||
@confirm="doDelete"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
Reference in New Issue
Block a user