337eb4f05a
- 移除内置密码注册/登录/改密/删号/头像,统一走 Casdoor OIDC 授权码 - 服务端 casdoor-nodejs-sdk:code 换 token + 证书公钥验签 + get-account 补齐资料 - 用户表重建为 provider+provider_id(Casdoor sub 为准),邮箱不再唯一 - 管理员由 Casdoor token 的 isAdmin/IsAdmin 字段或 admin 角色判定,删除角色切换接口 - 前端登录弹窗改为申统认证跳转,注册去 Casdoor;后台用户列表只读角色 - 会话沿用 an_session httpOnly Cookie,requireUser/requireAdmin 守卫保留 - 配置注入 deploy.sh/.env.example;新增 casdoor 单测,删除 password 单测
450 lines
20 KiB
Vue
450 lines
20 KiB
Vue
<script setup lang="ts">
|
||
/**
|
||
* 后台站点设置:分组表单,管理站点全局信息。
|
||
* - 加载 GET /api/admin/settings(返回合并默认值后的完整 SiteSettings)
|
||
* - 保存 PATCH /api/admin/settings,body { settings: <整体表单> }(按叶节点写库,未提供项不变)
|
||
* - 保存后前台 /api/settings 即时生效
|
||
*/
|
||
import { onMounted, reactive, ref } from 'vue'
|
||
import { defaultSettings, type SiteSettings } from '~/config/site'
|
||
import { useToastStore } from '~/stores/toast'
|
||
|
||
definePageMeta({ middleware: 'admin', layout: 'admin' })
|
||
|
||
useHead({ title: '站点设置' })
|
||
|
||
const toast = useToastStore()
|
||
|
||
const clone = <T>(v: T): T => JSON.parse(JSON.stringify(v))
|
||
|
||
/* ---------- 表单数据 ---------- */
|
||
// 先以默认值初始化,加载成功后整体覆盖为后端配置
|
||
const form = reactive<SiteSettings>(clone(defaultSettings))
|
||
|
||
const loading = ref(true)
|
||
const error = ref('')
|
||
const saving = ref(false)
|
||
|
||
const loadSettings = async () => {
|
||
loading.value = true
|
||
error.value = ''
|
||
try {
|
||
const data = await $fetch<SiteSettings>('/api/admin/settings')
|
||
Object.assign(form, clone(data))
|
||
} catch (err: any) {
|
||
error.value = err?.data?.message || '配置加载失败'
|
||
} finally {
|
||
loading.value = false
|
||
}
|
||
}
|
||
|
||
onMounted(loadSettings)
|
||
|
||
/* ---------- 保存 ---------- */
|
||
const saveAll = async () => {
|
||
saving.value = true
|
||
try {
|
||
await $fetch('/api/admin/settings', {
|
||
method: 'PATCH',
|
||
body: { settings: clone(form) },
|
||
})
|
||
toast.success('已保存,前台即时生效')
|
||
} catch (err: any) {
|
||
toast.error(err?.data?.message || '保存失败,请重试')
|
||
} finally {
|
||
saving.value = false
|
||
}
|
||
}
|
||
|
||
/* ---------- 社交链接 ---------- */
|
||
// 分组图标:国内平台用 Remix Icon(ri),国际平台用 Phosphor(ph)
|
||
const SOCIAL_ICONS = [
|
||
{
|
||
group: '国内平台',
|
||
options: [
|
||
{ label: '微博', value: 'ri:weibo-fill' },
|
||
{ label: '微信', value: 'ri:wechat-fill' },
|
||
{ label: '知乎', value: 'ri:zhihu-fill' },
|
||
{ label: '哔哩哔哩', value: 'ri:bilibili-fill' },
|
||
{ label: 'QQ', value: 'ri:qq-fill' },
|
||
{ label: '豆瓣', value: 'ri:douban-fill' },
|
||
{ label: '淘宝', value: 'ri:taobao-fill' },
|
||
{ label: '支付宝', value: 'ri:alipay-fill' },
|
||
{ label: '网易云音乐', value: 'ri:netease-cloud-music-fill' },
|
||
],
|
||
},
|
||
{
|
||
group: '国际平台',
|
||
options: [
|
||
{ label: 'X (Twitter)', value: 'ph:x-logo' },
|
||
{ label: 'Instagram', value: 'ph:instagram-logo' },
|
||
{ label: 'LinkedIn', value: 'ph:linkedin-logo' },
|
||
{ label: 'GitHub', value: 'ri:github-fill' },
|
||
{ label: 'YouTube', value: 'ph:youtube-logo' },
|
||
{ label: 'Facebook', value: 'ph:facebook-logo' },
|
||
],
|
||
},
|
||
{
|
||
group: '其他',
|
||
options: [
|
||
{ label: '邮箱', value: 'ph:envelope-simple' },
|
||
{ label: '链接', value: 'ph:link-simple' },
|
||
{ label: '地球', value: 'ph:globe-simple' },
|
||
],
|
||
},
|
||
]
|
||
|
||
// 生成列表项稳定 id(仅用于前台 v-for key,非业务标识)
|
||
const uid = () => 'id-' + Math.random().toString(36).slice(2, 9)
|
||
|
||
const addSocial = () => form.socials.push({ name: '', icon: 'ri:weibo-fill', url: '' })
|
||
const removeSocial = (i: number) => form.socials.splice(i, 1)
|
||
|
||
/* ---------- 首页成就数据 ---------- */
|
||
const addAchievement = () =>
|
||
form.achievements.push({
|
||
id: uid(),
|
||
number: 100,
|
||
suffix: '+',
|
||
titleZh: '',
|
||
titleEn: '',
|
||
descriptionZh: '',
|
||
descriptionEn: '',
|
||
})
|
||
const removeAchievement = (i: number) => form.achievements.splice(i, 1)
|
||
|
||
/* ---------- 客户评价 ---------- */
|
||
const addTestimonial = () =>
|
||
form.testimonials.push({
|
||
id: uid(),
|
||
name: '',
|
||
roleZh: '',
|
||
roleEn: '',
|
||
contentZh: '',
|
||
contentEn: '',
|
||
})
|
||
const removeTestimonial = (i: number) => form.testimonials.splice(i, 1)
|
||
|
||
/* ---------- 合作伙伴 ---------- */
|
||
const addPartner = () => form.partners.push({ id: uid(), name: '', logo: null, url: null })
|
||
const removePartner = (i: number) => form.partners.splice(i, 1)
|
||
|
||
/* ---------- 首页 Hero 画廊 ---------- */
|
||
const addHeroImage = () => form.hero.gallery.push('')
|
||
const removeHeroImage = (i: number) => form.hero.gallery.splice(i, 1)
|
||
|
||
/* ---------- 工具箱 ---------- */
|
||
const TOOL_COLORS = [
|
||
{ label: '橙 · 琥珀', value: 'from-orange-50/50 to-amber-100/50' },
|
||
{ label: '紫 · 靛蓝', value: 'from-purple-50/50 to-indigo-100/50' },
|
||
{ label: '蓝 · 青', value: 'from-blue-50/50 to-cyan-100/50' },
|
||
{ label: '绿 · 翠', value: 'from-emerald-50/50 to-teal-100/50' },
|
||
{ label: '粉 · 玫', value: 'from-pink-50/50 to-rose-100/50' },
|
||
{ label: '灰 · 石板', value: 'from-gray-50/50 to-slate-100/50' },
|
||
]
|
||
|
||
const addTool = () =>
|
||
form.tools.push({
|
||
id: '',
|
||
name: '',
|
||
url: '',
|
||
icon: 'ph:wrench-duotone',
|
||
color: TOOL_COLORS[0].value,
|
||
descZh: '',
|
||
descEn: '',
|
||
})
|
||
const removeTool = (i: number) => form.tools.splice(i, 1)
|
||
</script>
|
||
|
||
<template>
|
||
<div>
|
||
<!-- 页头 -->
|
||
<AdminPageHeader title="站点设置" subtitle="管理站点全局信息,保存后前台即时生效">
|
||
<template #actions>
|
||
<AdminButton :loading="saving" :disabled="loading || !!error" @click="saveAll">
|
||
<Icon v-if="!saving" name="ph:floppy-disk" class="w-4 h-4" />
|
||
{{ saving ? '保存中…' : '保存全部' }}
|
||
</AdminButton>
|
||
</template>
|
||
</AdminPageHeader>
|
||
|
||
<!-- 加载骨架 -->
|
||
<div v-if="loading" class="space-y-6 max-w-5xl">
|
||
<AdminCard v-for="i in 4" :key="i" title="">
|
||
<AdminSkeleton :rows="5" />
|
||
</AdminCard>
|
||
</div>
|
||
|
||
<!-- 加载失败 -->
|
||
<div
|
||
v-else-if="error"
|
||
class="max-w-5xl rounded-2xl bg-white border border-gray-100 shadow-sm p-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">{{ error }}</p>
|
||
<AdminButton variant="secondary" @click="loadSettings">
|
||
<Icon name="ph:arrow-clockwise" class="w-4 h-4" /> 重新加载
|
||
</AdminButton>
|
||
</div>
|
||
|
||
<!-- 表单 -->
|
||
<div v-else class="space-y-6 max-w-5xl">
|
||
<!-- 1. 站点信息 -->
|
||
<AdminCard title="站点信息" subtitle="品牌标识与浏览器标题等基础信息">
|
||
<template #actions><Icon name="ph:info" class="w-5 h-5 text-gray-300" /></template>
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
|
||
<AdminInput v-model="form.site.name" label="站点名称" placeholder="ArcticNewOne" />
|
||
<AdminInput v-model="form.site.brand" label="品牌名" placeholder="北极新一" />
|
||
<AdminTextarea v-model="form.site.description.zh" label="站点简介(中文)" :rows="3" />
|
||
<AdminTextarea v-model="form.site.description.en" label="Description (EN)" :rows="3" />
|
||
</div>
|
||
</AdminCard>
|
||
|
||
<!-- 2. 联系方式 -->
|
||
<AdminCard title="联系方式" subtitle="前台「联系我们」展示的联系信息">
|
||
<template #actions><Icon name="ph:envelope-simple" class="w-5 h-5 text-gray-300" /></template>
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-5">
|
||
<AdminInput v-model="form.contact.email" label="联系邮箱" type="email" placeholder="hello@..." />
|
||
<AdminInput v-model="form.contact.infoEmail" label="信息邮箱" type="email" placeholder="info@..." />
|
||
<AdminInput v-model="form.contact.wechat" label="微信号" placeholder="LucskyNew" />
|
||
<AdminTextarea v-model="form.contact.address.zh" label="地址(中文)" :rows="2" />
|
||
<AdminTextarea v-model="form.contact.address.en" label="Address (EN)" :rows="2" />
|
||
</div>
|
||
</AdminCard>
|
||
|
||
<!-- 3. 社交链接 -->
|
||
<AdminCard title="社交链接" subtitle="前台页脚与联系页展示的社交入口">
|
||
<template #actions><Icon name="ph:share-network" class="w-5 h-5 text-gray-300" /></template>
|
||
<div class="space-y-4">
|
||
<div
|
||
v-for="(s, i) in form.socials"
|
||
:key="i"
|
||
class="rounded-xl border border-gray-100 bg-gray-50/50 p-4"
|
||
>
|
||
<div class="grid grid-cols-1 md:grid-cols-[120px_200px_1fr_auto] gap-3 items-end">
|
||
<AdminInput v-model="s.name" label="名称" placeholder="X" />
|
||
<AdminSelect v-model="s.icon" :options="SOCIAL_ICONS" label="图标" />
|
||
<AdminInput v-model="s.url" label="链接" type="url" placeholder="https://..." />
|
||
<button
|
||
type="button"
|
||
class="mb-1 w-9 h-9 rounded-lg text-gray-400 hover:text-red-600 hover:bg-red-50 flex items-center justify-center transition-colors"
|
||
:aria-label="`删除社交链接 ${s.name}`"
|
||
@click="removeSocial(i)"
|
||
>
|
||
<Icon name="ph:trash" class="w-4 h-4" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<AdminButton variant="secondary" size="sm" @click="addSocial">
|
||
<Icon name="ph:plus" class="w-4 h-4" /> 添加社交链接
|
||
</AdminButton>
|
||
</div>
|
||
</AdminCard>
|
||
|
||
<!-- 4. 工具箱 -->
|
||
<AdminCard title="工具箱" subtitle="前台「工具箱」页展示的在线工具">
|
||
<template #actions><Icon name="ph:wrench" class="w-5 h-5 text-gray-300" /></template>
|
||
<div class="space-y-4">
|
||
<div
|
||
v-for="(tool, i) in form.tools"
|
||
:key="i"
|
||
class="rounded-xl border border-gray-100 bg-gray-50/50 p-4 space-y-3"
|
||
>
|
||
<div class="flex items-center justify-between">
|
||
<span class="text-xs font-semibold text-gray-400">工具 #{{ i + 1 }}</span>
|
||
<button
|
||
type="button"
|
||
class="inline-flex items-center gap-1 px-2.5 py-1.5 rounded-lg text-xs font-semibold text-gray-400 hover:text-red-600 hover:bg-red-50 transition-colors"
|
||
@click="removeTool(i)"
|
||
>
|
||
<Icon name="ph:trash" class="w-3.5 h-3.5" /> 删除
|
||
</button>
|
||
</div>
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||
<AdminInput v-model="tool.id" label="ID" placeholder="drawio" />
|
||
<AdminInput v-model="tool.name" label="名称" placeholder="Drawio" />
|
||
<AdminInput v-model="tool.url" label="链接" type="url" placeholder="https://..." />
|
||
<AdminInput v-model="tool.icon" label="图标名" placeholder="ph:flow-arrow-duotone" />
|
||
<AdminSelect v-model="tool.color" :options="TOOL_COLORS" label="主题色" />
|
||
</div>
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||
<AdminTextarea v-model="tool.descZh" label="中文简介" :rows="2" />
|
||
<AdminTextarea v-model="tool.descEn" label="Description (EN)" :rows="2" />
|
||
</div>
|
||
</div>
|
||
<AdminButton variant="secondary" size="sm" @click="addTool">
|
||
<Icon name="ph:plus" class="w-4 h-4" /> 添加工具
|
||
</AdminButton>
|
||
</div>
|
||
</AdminCard>
|
||
|
||
<!-- 5. 首页成就数据 -->
|
||
<AdminCard title="首页成就数据" subtitle="首页「成就」板块的数字统计;留空则不展示该板块">
|
||
<template #actions><Icon name="ph:trend-up" class="w-5 h-5 text-gray-300" /></template>
|
||
<div class="space-y-4">
|
||
<div
|
||
v-for="(a, i) in form.achievements"
|
||
:key="i"
|
||
class="rounded-xl border border-gray-100 bg-gray-50/50 p-4 space-y-3"
|
||
>
|
||
<div class="flex items-center justify-between">
|
||
<span class="text-xs font-semibold text-gray-400">成就 #{{ i + 1 }}</span>
|
||
<button
|
||
type="button"
|
||
class="inline-flex items-center gap-1 px-2.5 py-1.5 rounded-lg text-xs font-semibold text-gray-400 hover:text-red-600 hover:bg-red-50 transition-colors"
|
||
@click="removeAchievement(i)"
|
||
>
|
||
<Icon name="ph:trash" class="w-3.5 h-3.5" /> 删除
|
||
</button>
|
||
</div>
|
||
<div class="grid grid-cols-2 md:grid-cols-4 gap-3">
|
||
<AdminInput v-model="a.titleZh" label="标题(中文)" />
|
||
<AdminInput v-model="a.titleEn" label="Title (EN)" />
|
||
<AdminInput v-model="a.number" label="数字" type="number" />
|
||
<AdminInput v-model="a.suffix" label="后缀" placeholder="+ 或 %" />
|
||
</div>
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||
<AdminTextarea v-model="a.descriptionZh" label="描述(中文)" :rows="2" />
|
||
<AdminTextarea v-model="a.descriptionEn" label="Description (EN)" :rows="2" />
|
||
</div>
|
||
</div>
|
||
<AdminButton variant="secondary" size="sm" @click="addAchievement">
|
||
<Icon name="ph:plus" class="w-4 h-4" /> 添加成就
|
||
</AdminButton>
|
||
</div>
|
||
</AdminCard>
|
||
|
||
<!-- 6. 客户评价 -->
|
||
<AdminCard title="客户评价" subtitle="首页「客户评价」轮播内容;留空则不展示该板块">
|
||
<template #actions><Icon name="ph:quotes-duotone" class="w-5 h-5 text-gray-300" /></template>
|
||
<div class="space-y-4">
|
||
<div
|
||
v-for="(tm, i) in form.testimonials"
|
||
:key="i"
|
||
class="rounded-xl border border-gray-100 bg-gray-50/50 p-4 space-y-3"
|
||
>
|
||
<div class="flex items-center justify-between">
|
||
<span class="text-xs font-semibold text-gray-400">评价 #{{ i + 1 }}</span>
|
||
<button
|
||
type="button"
|
||
class="inline-flex items-center gap-1 px-2.5 py-1.5 rounded-lg text-xs font-semibold text-gray-400 hover:text-red-600 hover:bg-red-50 transition-colors"
|
||
@click="removeTestimonial(i)"
|
||
>
|
||
<Icon name="ph:trash" class="w-3.5 h-3.5" /> 删除
|
||
</button>
|
||
</div>
|
||
<div class="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||
<AdminInput v-model="tm.name" label="姓名" />
|
||
<AdminInput v-model="tm.roleZh" label="角色(中文)" />
|
||
<AdminInput v-model="tm.roleEn" label="Role (EN)" />
|
||
</div>
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||
<AdminTextarea v-model="tm.contentZh" label="评价内容(中文)" :rows="3" />
|
||
<AdminTextarea v-model="tm.contentEn" label="Content (EN)" :rows="3" />
|
||
</div>
|
||
</div>
|
||
<AdminButton variant="secondary" size="sm" @click="addTestimonial">
|
||
<Icon name="ph:plus" class="w-4 h-4" /> 添加评价
|
||
</AdminButton>
|
||
</div>
|
||
</AdminCard>
|
||
|
||
<!-- 7. 合作伙伴 -->
|
||
<AdminCard title="合作伙伴" subtitle="首页「合作伙伴」排展示;留空则不展示该排">
|
||
<template #actions><Icon name="ph:handshake" class="w-5 h-5 text-gray-300" /></template>
|
||
<div class="space-y-4">
|
||
<div
|
||
v-for="(p, i) in form.partners"
|
||
:key="i"
|
||
class="rounded-xl border border-gray-100 bg-gray-50/50 p-4 space-y-3"
|
||
>
|
||
<div class="flex items-center justify-between">
|
||
<span class="text-xs font-semibold text-gray-400">合作方 #{{ i + 1 }}</span>
|
||
<button
|
||
type="button"
|
||
class="inline-flex items-center gap-1 px-2.5 py-1.5 rounded-lg text-xs font-semibold text-gray-400 hover:text-red-600 hover:bg-red-50 transition-colors"
|
||
@click="removePartner(i)"
|
||
>
|
||
<Icon name="ph:trash" class="w-3.5 h-3.5" /> 删除
|
||
</button>
|
||
</div>
|
||
<div class="grid grid-cols-1 md:grid-cols-3 gap-3">
|
||
<AdminInput v-model="p.name" label="名称" />
|
||
<AdminInput v-model="p.logo" label="Logo 图片 URL" placeholder="本地 /uploads/... 或 https://..." />
|
||
<AdminInput v-model="p.url" label="官网链接(可选)" type="url" placeholder="https://..." />
|
||
</div>
|
||
</div>
|
||
<AdminButton variant="secondary" size="sm" @click="addPartner">
|
||
<Icon name="ph:plus" class="w-4 h-4" /> 添加合作方
|
||
</AdminButton>
|
||
</div>
|
||
</AdminCard>
|
||
|
||
<!-- 8. 首页 Hero 画廊 -->
|
||
<AdminCard title="首页 Hero 画廊" subtitle="首页背景滚动的图片,会均分到左右两列;留空时显示品牌纯色背景">
|
||
<template #actions><Icon name="ph:images" class="w-5 h-5 text-gray-300" /></template>
|
||
<div class="space-y-4">
|
||
<div
|
||
v-for="(img, i) in form.hero.gallery"
|
||
:key="i"
|
||
class="rounded-xl border border-gray-100 bg-gray-50/50 p-4"
|
||
>
|
||
<div class="grid grid-cols-1 md:grid-cols-[1fr_auto] gap-3 items-end">
|
||
<AdminInput v-model="form.hero.gallery[i]" label="图片 URL" placeholder="本地 /uploads/... 或 https://..." />
|
||
<button
|
||
type="button"
|
||
class="mb-1 w-9 h-9 rounded-lg text-gray-400 hover:text-red-600 hover:bg-red-50 flex items-center justify-center transition-colors"
|
||
:aria-label="`删除图片 ${i + 1}`"
|
||
@click="removeHeroImage(i)"
|
||
>
|
||
<Icon name="ph:trash" class="w-4 h-4" />
|
||
</button>
|
||
</div>
|
||
</div>
|
||
<AdminButton variant="secondary" size="sm" @click="addHeroImage">
|
||
<Icon name="ph:plus" class="w-4 h-4" /> 添加图片
|
||
</AdminButton>
|
||
</div>
|
||
</AdminCard>
|
||
|
||
<!-- 9. 页脚文案 -->
|
||
<AdminCard title="页脚文案" subtitle="前台页脚与订阅区的文案">
|
||
<template #actions><Icon name="ph:paragraph" class="w-5 h-5 text-gray-300" /></template>
|
||
<div class="space-y-5">
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||
<AdminTextarea v-model="form.footer.title.zh" label="主标题(中文)" :rows="3" />
|
||
<AdminTextarea v-model="form.footer.title.en" label="Headline (EN)" :rows="3" />
|
||
</div>
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||
<AdminInput v-model="form.footer.newsletterTitle.zh" label="订阅标题(中文)" />
|
||
<AdminInput v-model="form.footer.newsletterTitle.en" label="Newsletter Title (EN)" />
|
||
</div>
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||
<AdminInput v-model="form.footer.newsletterNote.zh" label="订阅说明(中文)" />
|
||
<AdminInput v-model="form.footer.newsletterNote.en" label="Newsletter Note (EN)" />
|
||
</div>
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||
<AdminInput v-model="form.footer.copyright.zh" label="版权(中文)" />
|
||
<AdminInput v-model="form.footer.copyright.en" label="Copyright (EN)" />
|
||
</div>
|
||
</div>
|
||
</AdminCard>
|
||
|
||
<!-- 10. SEO -->
|
||
<AdminCard title="SEO" subtitle="搜索引擎描述与关键词">
|
||
<template #actions><Icon name="ph:magnifying-glass" class="w-5 h-5 text-gray-300" /></template>
|
||
<div class="space-y-5">
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||
<AdminTextarea v-model="form.seo.description.zh" label="描述(中文)" :rows="3" />
|
||
<AdminTextarea v-model="form.seo.description.en" label="Description (EN)" :rows="3" />
|
||
</div>
|
||
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
|
||
<AdminTextarea v-model="form.seo.keywords.zh" label="关键词(中文,逗号分隔)" :rows="2" />
|
||
<AdminTextarea v-model="form.seo.keywords.en" label="Keywords (EN, comma-separated)" :rows="2" />
|
||
</div>
|
||
</div>
|
||
</AdminCard>
|
||
</div>
|
||
</div>
|
||
</template>
|