feat: 登录改为 Casdoor 统一身份认证(SSO),重建用户体系
- 移除内置密码注册/登录/改密/删号/头像,统一走 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 单测
This commit is contained in:
+8
-193
@@ -3,7 +3,7 @@
|
||||
* 个人中心(重新设计)—— 对齐站点黑白编辑风:极简、大排版、充足留白。
|
||||
* - 资料区:头像 + 大号姓名 + 邮箱 + 角色/加入时间 + 三项统计(细分隔线)
|
||||
* - 导航:下划线页签
|
||||
* - profile:资料编辑 / 修改密码 / 删除账号(克制危险区)
|
||||
* - profile:资料编辑(仅用户名;账号信息由 Casdoor 管理)
|
||||
* - favorites:作品封面网格;comments:评论列表
|
||||
*/
|
||||
import { computed, nextTick, onBeforeUnmount, onMounted, reactive, ref } from 'vue'
|
||||
@@ -46,107 +46,22 @@ const switchTab = (key: string) => {
|
||||
}
|
||||
|
||||
/* ---------- 资料编辑 ---------- */
|
||||
const profileForm = reactive({ username: '', phone: '' })
|
||||
const profileForm = reactive({ username: '' })
|
||||
const profileSaving = ref(false)
|
||||
const profileMsg = ref<{ ok: boolean; text: string } | null>(null)
|
||||
const initProfileForm = () => {
|
||||
profileForm.username = userStore.user?.username ?? ''
|
||||
profileForm.phone = userStore.user?.phone ?? ''
|
||||
}
|
||||
const saveProfile = async () => {
|
||||
profileSaving.value = true
|
||||
profileMsg.value = null
|
||||
const result = await userStore.updateProfile({ username: profileForm.username, phone: profileForm.phone })
|
||||
const result = await userStore.updateProfile({ username: profileForm.username })
|
||||
profileSaving.value = false
|
||||
profileMsg.value = result.success
|
||||
? { ok: true, text: t('account.saved') }
|
||||
: { ok: false, text: apiError({ data: { code: result.code } }) }
|
||||
}
|
||||
|
||||
/* ---------- 头像 ---------- */
|
||||
const avatarUpdating = ref(false)
|
||||
const avatarMsg = ref<{ ok: boolean; text: string } | null>(null)
|
||||
const onAvatarChange = async (e: Event) => {
|
||||
const input = e.target as HTMLInputElement
|
||||
const file = input.files?.[0]
|
||||
if (!file) return
|
||||
if (!/^image\//.test(file.type) || file.size > 8 * 1024 * 1024) {
|
||||
avatarMsg.value = { ok: false, text: t('account.avatar.error') }
|
||||
input.value = ''
|
||||
return
|
||||
}
|
||||
avatarUpdating.value = true
|
||||
avatarMsg.value = null
|
||||
const result = await userStore.updateAvatar(file)
|
||||
avatarUpdating.value = false
|
||||
input.value = ''
|
||||
avatarMsg.value = result.success
|
||||
? { ok: true, text: t('account.avatar.success') }
|
||||
: { ok: false, text: t('account.avatar.error') }
|
||||
}
|
||||
const removeAvatar = async () => {
|
||||
avatarUpdating.value = true
|
||||
avatarMsg.value = null
|
||||
const result = await userStore.updateAvatar(null)
|
||||
avatarUpdating.value = false
|
||||
avatarMsg.value = result.success
|
||||
? { ok: true, text: t('account.avatar.success') }
|
||||
: { ok: false, text: t('account.avatar.error') }
|
||||
}
|
||||
|
||||
/* ---------- 修改密码 ---------- */
|
||||
const pwForm = reactive({ currentPassword: '', newPassword: '', confirmPassword: '' })
|
||||
const pwSaving = ref(false)
|
||||
const pwError = ref('')
|
||||
const pwOk = ref(false)
|
||||
const changePassword = async () => {
|
||||
pwError.value = ''
|
||||
pwOk.value = false
|
||||
if (pwForm.newPassword.length < 8) { pwError.value = t('account.changePassword.tooShort'); return }
|
||||
if (pwForm.newPassword !== pwForm.confirmPassword) { pwError.value = t('account.changePassword.mismatch'); return }
|
||||
pwSaving.value = true
|
||||
try {
|
||||
await $fetch('/api/auth/password', { method: 'PATCH', body: { currentPassword: pwForm.currentPassword, newPassword: pwForm.newPassword } })
|
||||
pwForm.currentPassword = ''
|
||||
pwForm.newPassword = ''
|
||||
pwForm.confirmPassword = ''
|
||||
pwOk.value = true
|
||||
} catch (err) {
|
||||
pwError.value = (err as any)?.data?.code === 'WRONG_PASSWORD'
|
||||
? t('account.changePassword.wrongPassword')
|
||||
: apiError(err, 'account.changePassword.failed')
|
||||
} finally {
|
||||
pwSaving.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 删除账号 ---------- */
|
||||
const deletePassword = ref('')
|
||||
const deleting = ref(false)
|
||||
const deleteError = ref('')
|
||||
const deleteConfirmOpen = ref(false)
|
||||
const askDeleteAccount = () => {
|
||||
deleteError.value = ''
|
||||
if (!deletePassword.value.trim()) { deleteError.value = t('account.deleteAccount.passwordPlaceholder'); return }
|
||||
deleteConfirmOpen.value = true
|
||||
}
|
||||
const doDeleteAccount = async () => {
|
||||
deleting.value = true
|
||||
try {
|
||||
await $fetch('/api/auth/me', { method: 'DELETE', body: { password: deletePassword.value } })
|
||||
deleteConfirmOpen.value = false
|
||||
await userStore.logout()
|
||||
await navigateTo('/')
|
||||
} catch (err) {
|
||||
deleteConfirmOpen.value = false
|
||||
deleteError.value = (err as any)?.data?.code === 'WRONG_PASSWORD'
|
||||
? t('account.deleteAccount.wrongPassword')
|
||||
: apiError(err)
|
||||
} finally {
|
||||
deleting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 收藏 ---------- */
|
||||
interface FavedWork { slug: string; titleZh: string; titleEn: string; image: string | null; year: string; category: string }
|
||||
const favorites = ref<FavedWork[]>([])
|
||||
@@ -314,28 +229,8 @@ onBeforeUnmount(() => ctx?.revert())
|
||||
<div class="mt-6 flex items-center gap-6">
|
||||
<img :src="userStore.avatar" :alt="userStore.user?.username"
|
||||
class="w-20 h-20 rounded-2xl object-cover ring-1 ring-black/10 flex-shrink-0" />
|
||||
<div class="space-y-2.5">
|
||||
<label class="inline-flex cursor-pointer">
|
||||
<input type="file" accept="image/*" class="hidden" @change="onAvatarChange" />
|
||||
<span
|
||||
class="inline-flex items-center gap-1.5 px-4 py-2 rounded-full border border-gray-200 text-sm font-semibold text-gray-700 hover:border-black hover:text-black transition-colors"
|
||||
>
|
||||
<Icon v-if="avatarUpdating" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
|
||||
<Icon v-else name="ph:camera" class="w-4 h-4" />
|
||||
{{ t('account.avatar.change') }}
|
||||
</span>
|
||||
</label>
|
||||
<button
|
||||
v-if="userStore.user?.avatar"
|
||||
@click="removeAvatar"
|
||||
:disabled="avatarUpdating"
|
||||
class="block text-sm text-gray-400 hover:text-red-600 transition-colors disabled:opacity-50"
|
||||
>
|
||||
{{ t('account.avatar.remove') }}
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-sm text-gray-400">头像由 Casdoor 统一账号管理</p>
|
||||
</div>
|
||||
<p v-if="avatarMsg" class="mt-3 text-sm" :class="avatarMsg.ok ? 'text-green-600' : 'text-red-600'">{{ avatarMsg.text }}</p>
|
||||
|
||||
<div class="mt-7 space-y-5">
|
||||
<div>
|
||||
@@ -343,11 +238,6 @@ onBeforeUnmount(() => ctx?.revert())
|
||||
<input v-model="profileForm.username" type="text"
|
||||
class="w-full rounded-xl border border-gray-200 bg-white px-3.5 py-2.5 text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/10" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.phone') }}</label>
|
||||
<input v-model="profileForm.phone" type="tel"
|
||||
class="w-full rounded-xl border border-gray-200 bg-white px-3.5 py-2.5 text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/10" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.email') }}</label>
|
||||
<input :value="userStore.user?.email ?? ''" type="email" disabled
|
||||
@@ -364,62 +254,10 @@ onBeforeUnmount(() => ctx?.revert())
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- 安全设置 -->
|
||||
<div class="px-6 md:px-8 py-7">
|
||||
<h3 class="text-lg font-bold text-black">{{ t('account.changePassword.title') }}</h3>
|
||||
<p class="text-sm text-gray-400 mt-0.5">定期更换密码更安全</p>
|
||||
<form class="mt-6 space-y-5" @submit.prevent="changePassword">
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.changePassword.currentPassword') }}</label>
|
||||
<input v-model="pwForm.currentPassword" type="password" autocomplete="current-password" required
|
||||
class="w-full rounded-xl border border-gray-200 bg-white px-3.5 py-2.5 text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/10" />
|
||||
</div>
|
||||
<div class="grid grid-cols-1 sm:grid-cols-2 gap-5">
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.changePassword.newPassword') }}</label>
|
||||
<input v-model="pwForm.newPassword" type="password" autocomplete="new-password" required
|
||||
class="w-full rounded-xl border border-gray-200 bg-white px-3.5 py-2.5 text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/10" />
|
||||
</div>
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('account.changePassword.confirmPassword') }}</label>
|
||||
<input v-model="pwForm.confirmPassword" type="password" autocomplete="new-password" required
|
||||
class="w-full rounded-xl border border-gray-200 bg-white px-3.5 py-2.5 text-sm outline-none transition-all focus:border-black focus:ring-2 focus:ring-black/10" />
|
||||
</div>
|
||||
</div>
|
||||
<p v-if="pwError" class="text-sm text-red-600">{{ pwError }}</p>
|
||||
<p v-if="pwOk" class="text-sm text-green-600">{{ t('account.changePassword.success') }}</p>
|
||||
<div class="flex justify-end">
|
||||
<button type="submit" :disabled="pwSaving"
|
||||
class="inline-flex items-center gap-2 px-6 py-2.5 rounded-full border border-gray-200 text-gray-700 text-sm font-semibold hover:border-black hover:text-black transition-colors disabled:opacity-50">
|
||||
<Icon v-if="pwSaving" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
|
||||
{{ pwSaving ? t('account.changePassword.saving') : t('account.changePassword.submit') }}
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<!-- 危险操作 -->
|
||||
<div class="px-6 md:px-8 py-7 bg-red-50/40">
|
||||
<h3 class="text-lg font-bold text-red-600">{{ t('account.deleteAccount.title') }}</h3>
|
||||
<p class="text-sm text-red-400 mt-0.5">危险操作</p>
|
||||
<div class="mt-6 space-y-5">
|
||||
<p class="text-sm text-gray-600 leading-relaxed">{{ t('account.deleteAccount.hint') }}</p>
|
||||
<div>
|
||||
<label class="block text-sm font-semibold text-gray-800 mb-1.5">{{ t('auth.password') }}</label>
|
||||
<input v-model="deletePassword" type="password" autocomplete="current-password"
|
||||
:placeholder="t('account.deleteAccount.passwordPlaceholder')"
|
||||
@keydown.enter.prevent="askDeleteAccount"
|
||||
class="w-full rounded-xl border border-gray-200 bg-white px-3.5 py-2.5 text-sm outline-none transition-all focus:border-red-400 focus:ring-2 focus:ring-red-500/10" />
|
||||
</div>
|
||||
<p v-if="deleteError" class="text-sm text-red-600">{{ deleteError }}</p>
|
||||
<div class="flex justify-end">
|
||||
<button @click="askDeleteAccount" :disabled="deleting"
|
||||
class="inline-flex items-center gap-2 px-6 py-2.5 rounded-full bg-red-600 text-white text-sm font-semibold hover:bg-red-700 transition-colors disabled:opacity-50">
|
||||
<Icon v-if="deleting" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
|
||||
{{ t('account.deleteAccount.confirmButton') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- 账号说明 -->
|
||||
<div class="px-6 md:px-8 py-7 bg-gray-50/60">
|
||||
<h3 class="text-lg font-bold text-black">{{ t('account.ssoAccount') }}</h3>
|
||||
<p class="text-sm text-gray-500 mt-1 leading-relaxed">{{ t('account.ssoAccountHint') }}</p>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
@@ -500,29 +338,6 @@ onBeforeUnmount(() => ctx?.revert())
|
||||
</Transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<!-- 删除账号确认 -->
|
||||
<div v-if="deleteConfirmOpen" class="fixed inset-0 z-[150] flex items-center justify-center bg-black/40 p-4" @click.self="deleteConfirmOpen = false">
|
||||
<div class="w-full max-w-sm rounded-2xl bg-white shadow-2xl overflow-hidden">
|
||||
<div class="px-6 py-5 border-b border-gray-100 flex items-start gap-3">
|
||||
<div class="flex h-10 w-10 shrink-0 items-center justify-center rounded-full bg-red-50 text-red-600">
|
||||
<Icon name="ph:warning-fill" class="w-5 h-5" />
|
||||
</div>
|
||||
<p class="text-sm text-gray-700 leading-relaxed pt-1">{{ t('account.deleteAccount.confirmText') }}</p>
|
||||
</div>
|
||||
<div class="flex justify-end gap-2 px-6 py-4">
|
||||
<button @click="deleteConfirmOpen = false" :disabled="deleting"
|
||||
class="px-4 py-2 rounded-full border border-gray-200 text-sm font-semibold text-gray-600 hover:border-gray-300 transition-colors disabled:opacity-50">
|
||||
{{ t('account.deleteAccount.cancelButton') }}
|
||||
</button>
|
||||
<button @click="doDeleteAccount" :disabled="deleting"
|
||||
class="inline-flex items-center gap-2 px-5 py-2 rounded-full bg-red-600 text-white text-sm font-semibold hover:bg-red-700 transition-colors disabled:opacity-50">
|
||||
<Icon v-if="deleting" name="ph:circle-notch" class="w-4 h-4 animate-spin" />
|
||||
{{ t('account.deleteAccount.confirmButton') }}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
|
||||
+202
-13
@@ -57,22 +57,82 @@ const saveAll = async () => {
|
||||
}
|
||||
|
||||
/* ---------- 社交链接 ---------- */
|
||||
// 分组图标:国内平台用 Remix Icon(ri),国际平台用 Phosphor(ph)
|
||||
const SOCIAL_ICONS = [
|
||||
{ label: 'X (Twitter)', value: 'ph:x-logo' },
|
||||
{ label: 'Instagram', value: 'ph:instagram-logo' },
|
||||
{ label: 'LinkedIn', value: 'ph:linkedin-logo' },
|
||||
{ label: 'GitHub', value: 'ph:github-logo' },
|
||||
{ label: 'YouTube', value: 'ph:youtube-logo' },
|
||||
{ label: 'Facebook', value: 'ph:facebook-logo' },
|
||||
{ label: '微信', value: 'ph:wechat-logo' },
|
||||
{ label: '邮箱', value: 'ph:envelope-simple' },
|
||||
{ label: '链接', value: 'ph:link-simple' },
|
||||
{ label: '地球', value: 'ph:globe-simple' },
|
||||
{
|
||||
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' },
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const addSocial = () => form.socials.push({ name: '', icon: 'ph:link-simple', url: '' })
|
||||
// 生成列表项稳定 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' },
|
||||
@@ -218,7 +278,136 @@ const removeTool = (i: number) => form.tools.splice(i, 1)
|
||||
</div>
|
||||
</AdminCard>
|
||||
|
||||
<!-- 5. 页脚文案 -->
|
||||
<!-- 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">
|
||||
@@ -241,7 +430,7 @@ const removeTool = (i: number) => form.tools.splice(i, 1)
|
||||
</div>
|
||||
</AdminCard>
|
||||
|
||||
<!-- 6. SEO -->
|
||||
<!-- 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">
|
||||
|
||||
+10
-53
@@ -1,7 +1,8 @@
|
||||
<script setup lang="ts">
|
||||
/**
|
||||
* 后台用户管理:列表 + 搜索/角色筛选 + 角色切换 + 删除确认 + 前端分页。
|
||||
* - GET /api/admin/users;PATCH /api/admin/users/[id](角色切换,不能操作自己);DELETE /api/admin/users/[id]
|
||||
* 后台用户管理:列表 + 搜索 + 删除确认 + 前端分页。
|
||||
* - GET /api/admin/users;DELETE /api/admin/users/[id]
|
||||
* - 角色由 Casdoor 统一身份认证决定(token 的 IsAdmin claim),本地仅缓存展示,不提供切换。
|
||||
*/
|
||||
import { computed, onMounted, ref, watch } from 'vue'
|
||||
import { useUserStore } from '~/stores/user'
|
||||
@@ -14,7 +15,6 @@ interface AdminUser {
|
||||
id: number
|
||||
username: string
|
||||
email: string | null
|
||||
phone: string | null
|
||||
role: 'user' | 'admin'
|
||||
createdAt: string
|
||||
}
|
||||
@@ -53,11 +53,7 @@ const filteredUsers = computed(() => {
|
||||
return users.value.filter((u) => {
|
||||
if (roleFilter.value !== 'all' && u.role !== roleFilter.value) return false
|
||||
if (!kw) return true
|
||||
return (
|
||||
u.username.toLowerCase().includes(kw) ||
|
||||
(u.email || '').toLowerCase().includes(kw) ||
|
||||
(u.phone || '').toLowerCase().includes(kw)
|
||||
)
|
||||
return u.username.toLowerCase().includes(kw) || (u.email || '').toLowerCase().includes(kw)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -82,22 +78,6 @@ const changePage = (p: number) => {
|
||||
page.value = Math.min(Math.max(1, p), totalPages.value)
|
||||
}
|
||||
|
||||
/* ---------- 角色切换 ---------- */
|
||||
const togglingId = ref<number | null>(null)
|
||||
const toggleRole = async (u: AdminUser) => {
|
||||
const next: AdminUser['role'] = u.role === 'admin' ? 'user' : 'admin'
|
||||
togglingId.value = u.id
|
||||
try {
|
||||
await $fetch(`/api/admin/users/${u.id}`, { method: 'PATCH', body: { role: next } })
|
||||
u.role = next
|
||||
toast.success(`已将「${u.username}」设为${next === 'admin' ? '管理员' : '普通用户'}`)
|
||||
} catch (err: any) {
|
||||
toast.error(err?.data?.message || '操作失败,请重试')
|
||||
} finally {
|
||||
togglingId.value = null
|
||||
}
|
||||
}
|
||||
|
||||
/* ---------- 删除 ---------- */
|
||||
const confirmDelete = ref<AdminUser | null>(null)
|
||||
const deleting = ref(false)
|
||||
@@ -138,7 +118,7 @@ const formatDate = (raw?: string) => {
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<AdminPageHeader title="用户管理" subtitle="管理站点注册用户,调整角色或删除账号。">
|
||||
<AdminPageHeader title="用户管理" subtitle="查看站点 SSO 用户,角色由 Casdoor 统一身份判定。">
|
||||
<template #actions>
|
||||
<AdminButton variant="secondary" size="sm" @click="loadUsers">
|
||||
<Icon name="ph:arrows-clockwise" class="w-4 h-4" /> 刷新
|
||||
@@ -158,7 +138,7 @@ const formatDate = (raw?: string) => {
|
||||
<input
|
||||
v-model="keyword"
|
||||
type="text"
|
||||
placeholder="搜索用户名 / 邮箱 / 手机号"
|
||||
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
|
||||
@@ -196,7 +176,7 @@ const formatDate = (raw?: string) => {
|
||||
</AdminCard>
|
||||
|
||||
<!-- 空态 -->
|
||||
<AdminEmptyState v-else-if="!users.length" icon="ph:users-three" title="暂无用户" description="还没有注册用户。" />
|
||||
<AdminEmptyState v-else-if="!users.length" icon="ph:users-three" title="暂无用户" description="还没有登录用户。" />
|
||||
|
||||
<AdminEmptyState
|
||||
v-else-if="!filteredUsers.length"
|
||||
@@ -216,9 +196,8 @@ const formatDate = (raw?: string) => {
|
||||
<th class="px-5 py-4 font-semibold text-xs uppercase tracking-wider whitespace-nowrap sticky left-0 bg-gray-50 z-10 border-r border-gray-100">ID</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>
|
||||
<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>
|
||||
<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 text-right">操作</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@@ -227,7 +206,6 @@ const formatDate = (raw?: string) => {
|
||||
<td class="px-5 py-4 text-gray-400 font-mono text-xs whitespace-nowrap sticky left-0 bg-white z-10 border-r border-gray-100">#{{ u.id }}</td>
|
||||
<td class="px-5 py-4 font-semibold text-black whitespace-nowrap">{{ u.username }}</td>
|
||||
<td class="px-5 py-4 text-gray-600">{{ u.email || '—' }}</td>
|
||||
<td class="px-5 py-4 text-gray-600 whitespace-nowrap">{{ u.phone || '—' }}</td>
|
||||
<td class="px-5 py-4 whitespace-nowrap">
|
||||
<AdminBadge :tone="u.role === 'admin' ? 'black' : 'gray'">
|
||||
<Icon v-if="u.role === 'admin'" name="ph:crown-simple" class="w-3 h-3" />
|
||||
@@ -238,14 +216,6 @@ const formatDate = (raw?: string) => {
|
||||
<td class="px-5 py-4">
|
||||
<div class="flex items-center justify-end gap-2">
|
||||
<template v-if="u.id !== meId">
|
||||
<AdminButton
|
||||
size="sm"
|
||||
:variant="u.role === 'admin' ? 'secondary' : 'primary'"
|
||||
:loading="togglingId === u.id"
|
||||
@click="toggleRole(u)"
|
||||
>
|
||||
{{ u.role === 'admin' ? '设为用户' : '设为管理员' }}
|
||||
</AdminButton>
|
||||
<AdminButton size="sm" variant="danger" @click="askDelete(u)">
|
||||
<Icon name="ph:trash" class="w-3.5 h-3.5" /> 删除
|
||||
</AdminButton>
|
||||
@@ -289,25 +259,12 @@ const formatDate = (raw?: string) => {
|
||||
<dd class="text-gray-700 text-right break-all">{{ u.email || '—' }}</dd>
|
||||
</div>
|
||||
<div class="flex justify-between gap-3">
|
||||
<dt class="text-gray-400 flex-shrink-0">手机号</dt>
|
||||
<dd class="text-gray-700 text-right">{{ u.phone || '—' }}</dd>
|
||||
</div>
|
||||
<div class="flex justify-between gap-3">
|
||||
<dt class="text-gray-400 flex-shrink-0">注册时间</dt>
|
||||
<dt class="text-gray-400 flex-shrink-0">加入时间</dt>
|
||||
<dd class="text-gray-700 text-right">{{ formatDate(u.createdAt) }}</dd>
|
||||
</div>
|
||||
</dl>
|
||||
<div class="mt-4 flex flex-wrap items-center gap-2">
|
||||
<template v-if="u.id !== meId">
|
||||
<AdminButton
|
||||
size="sm"
|
||||
class="flex-1 min-h-10"
|
||||
:variant="u.role === 'admin' ? 'secondary' : 'primary'"
|
||||
:loading="togglingId === u.id"
|
||||
@click="toggleRole(u)"
|
||||
>
|
||||
{{ u.role === 'admin' ? '设为用户' : '设为管理员' }}
|
||||
</AdminButton>
|
||||
<AdminButton size="sm" variant="danger" class="min-h-10" @click="askDelete(u)">
|
||||
<Icon name="ph:trash" class="w-3.5 h-3.5" /> 删除
|
||||
</AdminButton>
|
||||
@@ -332,4 +289,4 @@ const formatDate = (raw?: string) => {
|
||||
@confirm="doDelete"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
</template>
|
||||
@@ -172,7 +172,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="contact-info-card p-6 md:p-8 rounded-2xl bg-gradient-to-br from-black to-gray-800 text-white border border-gray-800">
|
||||
<div v-if="socials.length" class="contact-info-card p-6 md:p-8 rounded-2xl bg-gradient-to-br from-black to-gray-800 text-white border border-gray-800">
|
||||
<h3 class="text-base md:text-lg font-bold mb-4">{{ t('contact.info.social') }}</h3>
|
||||
<div class="flex gap-3">
|
||||
<a
|
||||
@@ -351,8 +351,8 @@ onBeforeUnmount(() => {
|
||||
contactCtx?.revert()
|
||||
})
|
||||
|
||||
// 社交链接统一取自站点动态配置(后台可改)
|
||||
const socials = computed(() => settings?.socials ?? [])
|
||||
// 社交链接统一取自站点动态配置(后台可改);仅展示已填写 URL 的条目
|
||||
const socials = computed(() => (settings?.socials ?? []).filter((s) => s.url))
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
|
||||
<!-- 文章 Hero -->
|
||||
<section class="relative h-[50vh] md:h-[60vh] overflow-hidden">
|
||||
<img
|
||||
:src="article.image || ''"
|
||||
<CoverImage
|
||||
:src="article.image"
|
||||
:alt="title"
|
||||
:title="title"
|
||||
class="w-full h-full object-cover"
|
||||
/>
|
||||
<div class="absolute inset-0 bg-gradient-to-t from-black/80 via-black/40 to-transparent"></div>
|
||||
@@ -132,7 +133,7 @@
|
||||
class="group block rounded-2xl overflow-hidden bg-white shadow-lg hover:shadow-xl transition-all duration-300 hover:-translate-y-1"
|
||||
>
|
||||
<div class="relative aspect-[16/10] overflow-hidden">
|
||||
<img :src="related.image || ''" :alt="locText(related.titleZh, related.titleEn)" class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105" />
|
||||
<CoverImage :src="related.image" :alt="locText(related.titleZh, related.titleEn)" :title="locText(related.titleZh, related.titleEn)" class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105" />
|
||||
</div>
|
||||
<div class="p-5">
|
||||
<span class="text-xs text-gray-500">{{ formatNewsDate(related.date, locale) }}</span>
|
||||
|
||||
@@ -57,10 +57,10 @@
|
||||
class="news-card group relative flex flex-col rounded-2xl md:rounded-3xl overflow-hidden bg-white border border-gray-100 hover:shadow-xl transition-all duration-500 cursor-pointer hover:-translate-y-2"
|
||||
>
|
||||
<div class="relative aspect-[16/10] overflow-hidden bg-gray-100">
|
||||
<img
|
||||
:src="article.image || ''"
|
||||
<CoverImage
|
||||
:src="article.image"
|
||||
:alt="locText(article.titleZh, article.titleEn)"
|
||||
:loading="'lazy'"
|
||||
:title="locText(article.titleZh, article.titleEn)"
|
||||
class="w-full h-full object-cover transition-transform duration-700 group-hover:scale-110"
|
||||
/>
|
||||
<div class="absolute top-4 left-4">
|
||||
|
||||
@@ -13,9 +13,10 @@
|
||||
|
||||
<!-- Hero 大图 -->
|
||||
<section class="relative h-[60vh] md:h-[70vh] overflow-hidden">
|
||||
<img
|
||||
:src="project.image || ''"
|
||||
<CoverImage
|
||||
:src="project.image"
|
||||
:alt="title"
|
||||
:title="title"
|
||||
class="w-full h-full object-cover"
|
||||
/>
|
||||
<div class="absolute inset-0 bg-gradient-to-t from-black/80 via-black/40 to-transparent"></div>
|
||||
@@ -178,7 +179,7 @@
|
||||
class="group block rounded-2xl overflow-hidden bg-white shadow-lg hover:shadow-xl transition-all duration-300 hover:-translate-y-1"
|
||||
>
|
||||
<div class="relative aspect-[4/3] overflow-hidden">
|
||||
<img :src="related.image || ''" :alt="locText(related.titleZh, related.titleEn)" class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105" />
|
||||
<CoverImage :src="related.image" :alt="locText(related.titleZh, related.titleEn)" :title="locText(related.titleZh, related.titleEn)" class="w-full h-full object-cover transition-transform duration-500 group-hover:scale-105" />
|
||||
</div>
|
||||
<div class="p-5">
|
||||
<h3 class="text-lg font-bold text-black group-hover:text-gray-600 transition-colors">{{ locText(related.titleZh, related.titleEn) }}</h3>
|
||||
|
||||
@@ -57,10 +57,10 @@
|
||||
class="work-card group relative block rounded-2xl md:rounded-3xl overflow-hidden cursor-pointer hover:shadow-2xl transition-all duration-500"
|
||||
>
|
||||
<div class="relative aspect-[4/3] overflow-hidden bg-gray-100">
|
||||
<img
|
||||
:src="project.image || ''"
|
||||
<CoverImage
|
||||
:src="project.image"
|
||||
:alt="locText(project.titleZh, project.titleEn)"
|
||||
:loading="'lazy'"
|
||||
:title="locText(project.titleZh, project.titleEn)"
|
||||
class="w-full h-full object-cover transition-transform duration-700 group-hover:scale-110"
|
||||
/>
|
||||
<div class="absolute inset-0 bg-gradient-to-t from-black/60 via-black/20 to-transparent opacity-0 group-hover:opacity-100 transition-opacity duration-500"></div>
|
||||
|
||||
Reference in New Issue
Block a user