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:
2026-08-09 00:18:47 +08:00
parent bdafac2857
commit 337eb4f05a
51 changed files with 1395 additions and 1504 deletions
+15 -5
View File
@@ -7,7 +7,12 @@
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 disabled:opacity-50"
@change="emit('update:modelValue', ($event.target as HTMLSelectElement).value)"
>
<option v-for="o in options" :key="o.value" :value="o.value">{{ o.label }}</option>
<template v-for="o in options" :key="isGroup(o) ? o.group : o.value">
<optgroup v-if="isGroup(o)" :label="o.group">
<option v-for="opt in o.options" :key="opt.value" :value="opt.value">{{ opt.label }}</option>
</optgroup>
<option v-else :value="o.value">{{ o.label }}</option>
</template>
</select>
</div>
</template>
@@ -17,9 +22,14 @@ interface Option {
label: string
value: string
}
withDefaults(defineProps<{ modelValue: string; options: Option[]; label?: string; disabled?: boolean }>(), {
label: '',
disabled: false,
})
interface OptionGroup {
group: string
options: Option[]
}
withDefaults(
defineProps<{ modelValue: string; options: Array<Option | OptionGroup>; label?: string; disabled?: boolean }>(),
{ label: '', disabled: false },
)
const isGroup = (o: Option | OptionGroup): o is OptionGroup => 'group' in o && !!o.group
const emit = defineEmits<{ 'update:modelValue': [v: string] }>()
</script>
+30
View File
@@ -0,0 +1,30 @@
<template>
<!-- 有图显示图片;无图显示品牌渐变兜底 + 标题文字,避免裂图 -->
<img
v-if="src"
:src="src"
:alt="alt"
v-bind="$attrs"
loading="lazy"
decoding="async"
/>
<div
v-else
v-bind="$attrs"
class="flex items-center justify-center bg-gradient-to-br from-gray-200 via-gray-100 to-gray-200"
>
<span class="px-4 text-center text-sm md:text-base font-bold tracking-tight text-gray-400">
{{ title }}
</span>
</div>
</template>
<script setup lang="ts">
defineOptions({ inheritAttrs: false })
defineProps<{
src?: string | null
alt?: string
title?: string
}>()
</script>
+32 -87
View File
@@ -7,7 +7,6 @@
@click.self="closeModal"
>
<div
ref="modalRef"
class="relative w-full max-w-md bg-white rounded-2xl shadow-2xl overflow-hidden"
@click.stop
>
@@ -20,69 +19,30 @@
<Icon name="ph:x" class="w-5 h-5 text-gray-600" />
</button>
<!-- 登录表单 -->
<!-- 统一身份认证 -->
<div class="p-8">
<h2 class="text-2xl md:text-3xl font-bold text-black mb-2">{{ t('auth.login') }}</h2>
<p class="text-gray-600 mb-8">{{ t('auth.loginDescription') }}</p>
<p class="text-gray-600 mb-8">{{ t('auth.casdoorDescription') }}</p>
<form @submit.prevent="handleLogin" class="space-y-5">
<div>
<label for="account" class="block text-sm font-semibold text-gray-800 mb-2">
{{ t('auth.account') }}
</label>
<input
id="account"
v-model="account"
type="text"
required
autocomplete="username"
:disabled="isSubmitting"
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed"
:placeholder="t('auth.accountPlaceholder')"
/>
</div>
<p class="text-sm text-gray-500 mb-4">{{ t('auth.casdoorHint') }}</p>
<div>
<label for="password" class="block text-sm font-semibold text-gray-800 mb-2">
{{ t('auth.password') }}
</label>
<input
id="password"
v-model="password"
type="password"
required
autocomplete="current-password"
:disabled="isSubmitting"
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed"
:placeholder="t('auth.passwordPlaceholder')"
/>
</div>
<!-- 登录按钮:跳转 Casdoor,回跳当前页面 -->
<button
type="button"
:disabled="isRedirecting"
class="w-full py-3 rounded-xl font-semibold text-white transition-all duration-300 flex items-center justify-center gap-2 bg-black hover:bg-gray-800 shadow-lg hover:shadow-xl disabled:opacity-60 disabled:cursor-not-allowed"
@click="handleLogin"
>
<Icon name="ph:shield-check" class="w-5 h-5" />
<span>{{ isRedirecting ? t('auth.redirecting') : t('auth.loginWithCasdoor') }}</span>
</button>
<!-- 错误消息 -->
<div v-if="errorMessage" class="p-3 rounded-lg bg-red-50 border border-red-200 text-red-800 text-sm">
{{ errorMessage }}
</div>
<!-- 登录按钮 -->
<button
type="submit"
:disabled="isSubmitting || !account || !password"
class="w-full py-3 rounded-xl font-semibold text-white transition-all duration-300 flex items-center justify-center gap-2"
:class="isSubmitting || !account || !password
? 'bg-gray-400 cursor-not-allowed'
: 'bg-black hover:bg-gray-800 shadow-lg hover:shadow-xl'"
>
<Icon v-if="isSubmitting" name="ph:circle-notch" class="w-5 h-5 animate-spin" />
<span>{{ isSubmitting ? t('auth.loggingIn') : t('auth.loginButton') }}</span>
</button>
</form>
<!-- 注册账号链接 -->
<!-- 注册:前往 Casdoor 注册页 -->
<p class="mt-6 text-center text-sm text-gray-600">
{{ t('auth.noAccount') }}
<button @click="authModal.switchToRegister()" class="text-black font-semibold hover:underline">
<a :href="signupUrl" target="_blank" rel="noopener" class="text-black font-semibold hover:underline">
{{ t('auth.createAccount') }}
</button>
</a>
</p>
</div>
</div>
@@ -93,54 +53,39 @@
<script setup lang="ts">
import { ref, watch } from 'vue'
import { useRoute } from '#app'
import { useI18n } from 'vue-i18n'
import { useUserStore } from '~/stores/user'
import { useAuthModalStore } from '~/stores/authModal'
import { useApiError } from '~/composables/useApiError'
import { getCasdoorSignupUrl } from '~/utils/casdoorClient'
const { t } = useI18n()
const userStore = useUserStore()
const route = useRoute()
const authModal = useAuthModalStore()
const apiError = useApiError()
const account = ref('')
const password = ref('')
const isSubmitting = ref(false)
const errorMessage = ref('')
const isRedirecting = ref(false)
const signupUrl = getCasdoorSignupUrl()
const closeModal = () => {
if (!isSubmitting.value) {
if (!isRedirecting.value) {
authModal.closeAll()
}
}
// 打开时重置表单
// 打开时重置状态
watch(
() => authModal.isLoginOpen,
(open) => {
if (open) {
account.value = ''
password.value = ''
errorMessage.value = ''
}
if (open) isRedirecting.value = false
},
)
const handleLogin = async () => {
if (isSubmitting.value) return
isSubmitting.value = true
errorMessage.value = ''
const result = await userStore.login(account.value, password.value)
if (result.success) {
account.value = ''
password.value = ''
authModal.closeAll()
} else {
errorMessage.value = apiError({ data: { code: result.code } })
}
isSubmitting.value = false
const handleLogin = () => {
if (isRedirecting.value) return
isRedirecting.value = true
const next = route.fullPath
const target = next.startsWith('/') && !next.startsWith('//') ? next : '/'
const url = `/api/auth/casdoor-login?next=${encodeURIComponent(target)}`
window.location.assign(url)
}
// ESC 关闭
@@ -179,4 +124,4 @@ if (typeof window !== 'undefined') {
transform: scale(0.95) translateY(20px);
opacity: 0;
}
</style>
</style>
-263
View File
@@ -1,263 +0,0 @@
<template>
<Teleport to="body">
<Transition name="modal">
<div
v-if="authModal.isRegisterOpen"
class="fixed inset-0 z-[100] flex items-center justify-center bg-black/50 backdrop-blur-sm px-4"
@click.self="closeModal"
>
<div
ref="modalRef"
class="relative w-full max-w-md bg-white rounded-2xl shadow-2xl overflow-hidden"
@click.stop
>
<!-- 关闭按钮 -->
<button
@click="closeModal"
class="absolute top-4 right-4 w-8 h-8 flex items-center justify-center rounded-full hover:bg-gray-100 transition-colors z-10"
aria-label="Close"
>
<Icon name="ph:x" class="w-5 h-5 text-gray-600" />
</button>
<!-- 注册表单 -->
<div class="p-8">
<h2 class="text-2xl md:text-3xl font-bold text-black mb-2">{{ t('auth.register') }}</h2>
<p class="text-gray-600 mb-8">{{ t('auth.registerDescription') }}</p>
<form @submit.prevent="handleRegister" class="space-y-5">
<div>
<label for="reg-username" class="block text-sm font-semibold text-gray-800 mb-2">
{{ t('auth.username') }}
</label>
<input
id="reg-username"
v-model="username"
type="text"
required
autocomplete="username"
:disabled="isSubmitting"
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed"
:placeholder="t('auth.usernamePlaceholder')"
/>
</div>
<div>
<label for="reg-email" class="block text-sm font-semibold text-gray-800 mb-2">
{{ t('auth.email') }}
</label>
<input
id="reg-email"
v-model="email"
type="email"
required
autocomplete="email"
:disabled="isSubmitting"
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed"
:placeholder="t('auth.emailPlaceholder')"
/>
</div>
<div>
<label for="reg-phone" class="block text-sm font-semibold text-gray-800 mb-2">
{{ t('auth.phone') }}
</label>
<input
id="reg-phone"
v-model="phone"
type="tel"
autocomplete="tel"
:disabled="isSubmitting"
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed"
:placeholder="t('auth.phonePlaceholder')"
/>
</div>
<div>
<label for="reg-password" class="block text-sm font-semibold text-gray-800 mb-2">
{{ t('auth.password') }}
</label>
<input
id="reg-password"
v-model="password"
type="password"
required
autocomplete="new-password"
:disabled="isSubmitting"
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed"
:placeholder="t('auth.passwordPlaceholder')"
/>
</div>
<div>
<label for="reg-confirm-password" class="block text-sm font-semibold text-gray-800 mb-2">
{{ t('auth.confirmPassword') }}
</label>
<input
id="reg-confirm-password"
v-model="confirmPassword"
type="password"
required
autocomplete="new-password"
:disabled="isSubmitting"
class="w-full px-4 py-3 rounded-xl border border-gray-200 focus:border-black focus:ring-2 focus:ring-black/5 outline-none transition-all duration-300 disabled:opacity-50 disabled:cursor-not-allowed"
:placeholder="t('auth.confirmPasswordPlaceholder')"
/>
</div>
<!-- 错误消息 -->
<div v-if="errorMessage" class="p-3 rounded-lg bg-red-50 border border-red-200 text-red-800 text-sm">
{{ errorMessage }}
</div>
<!-- 成功消息 -->
<div v-if="successMessage" class="p-3 rounded-lg bg-green-50 border border-green-200 text-green-800 text-sm">
{{ successMessage }}
</div>
<!-- 注册按钮 -->
<button
type="submit"
:disabled="isSubmitting || !username || !email || !password || !confirmPassword"
class="w-full py-3 rounded-xl font-semibold text-white transition-all duration-300 flex items-center justify-center gap-2"
:class="isSubmitting || !username || !email || !password || !confirmPassword
? 'bg-gray-400 cursor-not-allowed'
: 'bg-black hover:bg-gray-800 shadow-lg hover:shadow-xl'"
>
<Icon v-if="isSubmitting" name="ph:circle-notch" class="w-5 h-5 animate-spin" />
<span>{{ isSubmitting ? t('auth.registering') : t('auth.registerButton') }}</span>
</button>
</form>
<!-- 返回登录链接 -->
<p class="mt-6 text-center text-sm text-gray-600">
{{ t('auth.alreadyHaveAccount') }}
<button @click="authModal.switchToLogin()" class="text-black font-semibold hover:underline">
{{ t('auth.backToLogin') }}
</button>
</p>
</div>
</div>
</div>
</Transition>
</Teleport>
</template>
<script setup lang="ts">
import { ref, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import { useUserStore } from '~/stores/user'
import { useAuthModalStore } from '~/stores/authModal'
import { useApiError } from '~/composables/useApiError'
const { t } = useI18n()
const userStore = useUserStore()
const authModal = useAuthModalStore()
const apiError = useApiError()
const username = ref('')
const email = ref('')
const phone = ref('')
const password = ref('')
const confirmPassword = ref('')
const isSubmitting = ref(false)
const errorMessage = ref('')
const successMessage = ref('')
const closeModal = () => {
if (!isSubmitting.value) {
authModal.closeAll()
}
}
// 打开时重置表单
watch(
() => authModal.isRegisterOpen,
(open) => {
if (open) {
username.value = ''
email.value = ''
phone.value = ''
password.value = ''
confirmPassword.value = ''
errorMessage.value = ''
successMessage.value = ''
}
},
)
const handleRegister = async () => {
if (isSubmitting.value) return
errorMessage.value = ''
successMessage.value = ''
if (password.value !== confirmPassword.value) {
errorMessage.value = t('auth.passwordMismatch')
return
}
if (phone.value && !/^1[3-9]\d{9}$/.test(phone.value)) {
errorMessage.value = t('auth.invalidPhone')
return
}
isSubmitting.value = true
const result = await userStore.register({
username: username.value,
email: email.value,
phone: phone.value,
password: password.value,
})
if (result.success) {
successMessage.value = t('auth.registerSuccess')
username.value = ''
email.value = ''
phone.value = ''
password.value = ''
confirmPassword.value = ''
setTimeout(() => {
authModal.closeAll()
}, 1500)
} else {
errorMessage.value = apiError({ data: { code: result.code } })
}
isSubmitting.value = false
}
// ESC 关闭
const handleKeydown = (e: KeyboardEvent) => {
if (e.key === 'Escape' && authModal.isRegisterOpen) {
closeModal()
}
}
if (typeof window !== 'undefined') {
window.addEventListener('keydown', handleKeydown)
}
</script>
<style scoped>
.modal-enter-active,
.modal-leave-active {
transition: opacity 0.3s ease;
}
.modal-enter-from,
.modal-leave-to {
opacity: 0;
}
.modal-enter-active .relative,
.modal-leave-active .relative {
transition: transform 0.3s ease, opacity 0.3s ease;
}
.modal-enter-from .relative {
transform: scale(0.95) translateY(20px);
opacity: 0;
}
.modal-leave-to .relative {
transform: scale(0.95) translateY(20px);
opacity: 0;
}
</style>
+27 -34
View File
@@ -1,5 +1,5 @@
<template>
<section ref="rootRef" class="relative bg-black text-white min-h-screen flex items-center justify-center overflow-hidden">
<section v-if="achievements.length" ref="rootRef" class="relative bg-black text-white min-h-screen flex items-center justify-center overflow-hidden">
<!-- 背景粒子 -->
<canvas ref="canvasRef" class="absolute inset-0 w-full h-full opacity-30"></canvas>
@@ -32,10 +32,10 @@
<!-- 描述 -->
<div class="flex-1">
<h3 class="text-2xl md:text-3xl font-bold mb-3">
{{ t(`home.achievements.items.${achievement.id}.title`) }}
{{ achievement.title }}
</h3>
<p class="text-gray-400 text-base md:text-lg leading-relaxed">
{{ t(`home.achievements.items.${achievement.id}.description`) }}
{{ achievement.description }}
</p>
</div>
</div>
@@ -45,14 +45,16 @@
</template>
<script setup lang="ts">
import { ref, onMounted, onUnmounted, nextTick } from 'vue'
import { ref, onMounted, onUnmounted, nextTick, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import gsap from 'gsap'
import { ScrollTrigger } from 'gsap/ScrollTrigger'
import { useSiteSettings } from '~/composables/useSiteSettings'
gsap.registerPlugin(ScrollTrigger)
const { t } = useI18n()
const { locale } = useI18n()
const { settings } = useSiteSettings()
const rootRef = ref<HTMLElement | null>(null)
const canvasRef = ref<HTMLCanvasElement | null>(null)
@@ -69,37 +71,28 @@ const setNumberRef = (el: any, index: number) => {
if (el) numberElements.value[index] = el
}
const achievements = [
{
id: 'projects',
number: 150,
suffix: '+',
color: 'text-blue-400',
bgColor: 'bg-blue-500'
},
{
id: 'clients',
number: 85,
suffix: '+',
color: 'text-purple-400',
bgColor: 'bg-purple-500'
},
{
id: 'experience',
number: 12,
suffix: '+',
color: 'text-green-400',
bgColor: 'bg-green-500'
},
{
id: 'satisfaction',
number: 98,
suffix: '%',
color: 'text-orange-400',
bgColor: 'bg-orange-500'
}
// 颜色预设按序号循环,后台无需逐条选色
const ACHIEVEMENT_STYLES = [
{ color: 'text-blue-400', bgColor: 'bg-blue-500' },
{ color: 'text-purple-400', bgColor: 'bg-purple-500' },
{ color: 'text-green-400', bgColor: 'bg-green-500' },
{ color: 'text-orange-400', bgColor: 'bg-orange-500' },
]
const locStr = (zh: string, en: string) => (locale.value === 'zh' ? zh : en)
// 成就数据来自后台配置(/admin/settings 首页成就数据),空则不渲染该板块
const achievements = computed(() =>
(settings.value?.achievements ?? []).map((a, i) => ({
id: a.id,
number: Number(a.number) || 0,
suffix: a.suffix,
title: locStr(a.titleZh, a.titleEn),
description: locStr(a.descriptionZh, a.descriptionEn),
...ACHIEVEMENT_STYLES[i % ACHIEVEMENT_STYLES.length],
})),
)
// 粒子动画
const initParticles = () => {
const canvas = canvasRef.value
+27 -12
View File
@@ -1,18 +1,26 @@
<script setup lang="ts">
import { onMounted, onBeforeUnmount, ref } from 'vue'
import { onMounted, onBeforeUnmount, ref, computed } from 'vue'
import { useNuxtApp } from '#app'
import { useI18n } from 'vue-i18n'
import gsap from 'gsap'
import AnimatedButton from '~/components/common/AnimatedButton.vue'
import { useSiteSettings } from '~/composables/useSiteSettings'
const { t } = useI18n()
const { settings } = useSiteSettings()
// 定义背景画廊与主视图绑定的总滚动距离(像素),数值越大,用户向下滚动时 Hero 面板缩放的过程就越长
const heroPinDistance = 1200
const heroGalleryColumns = [
{ side: 'left', images: ['1018', '1015', '1024', '1039'].map(id => `https://picsum.photos/id/${id}/900/1200`) },
{ side: 'right', images: ['1043', '1050', '1067', '1074'].map(id => `https://picsum.photos/id/${id}/900/1200`) },
] as const
// 背景画廊:由后台「首页 Hero 画廊」配置,图片均分到左右两列;为空时显示品牌纯色兜底
const heroGalleryColumns = computed(() => {
const gallery = settings.value?.hero?.gallery ?? []
const left = gallery.filter((_, i) => i % 2 === 0)
const right = gallery.filter((_, i) => i % 2 === 1)
const columns: { side: 'left' | 'right'; images: string[] }[] = []
if (left.length) columns.push({ side: 'left', images: left })
if (right.length) columns.push({ side: 'right', images: right })
return columns
})
const heroStageRef = ref<HTMLElement | null>(null)
const heroRef = ref<HTMLElement | null>(null)
@@ -202,14 +210,16 @@ defineExpose({ play })
class="relative bg-black"
:style="{ height: `calc(100svh + ${heroPinDistance}px)` }"
>
<section ref="heroRef" class="sticky top-0 h-[100svh] overflow-hidden bg-[#111]" v-once>
<section ref="heroRef" class="sticky top-0 h-[100svh] overflow-hidden bg-[#111]">
<div class="absolute inset-0 overflow-hidden bg-black" aria-hidden="true">
<div
v-for="column in heroGalleryColumns"
:key="column.side"
class="absolute -bottom-10 -top-10 w-[49vw] overflow-hidden"
:class="column.side === 'left' ? 'left-0' : 'right-0'"
>
<!-- 有后台画廊配置时渲染图片列;否则显示品牌纯色兜底 -->
<template v-if="heroGalleryColumns.length">
<div
v-for="column in heroGalleryColumns"
:key="column.side"
class="absolute -bottom-10 -top-10 w-[49vw] overflow-hidden"
:class="column.side === 'left' ? 'left-0' : 'right-0'"
>
<!-- 复制两份图片组,配合 translateY(-50%) 做无缝循环。 -->
<div
class="hero-gallery-track will-change-transform"
@@ -228,6 +238,11 @@ defineExpose({ play })
</div>
</div>
</div>
</template>
<template v-else>
<!-- 兜底:无后台画廊配置时的品牌背景 -->
<div class="absolute inset-0 bg-gradient-to-br from-neutral-800 via-neutral-900 to-black"></div>
</template>
</div>
<div ref="heroPanelRef" class="absolute inset-0 flex flex-col justify-between items-center bg-white text-black will-change-transform pt-24 pb-8 md:pt-36 md:pb-12 overflow-hidden">
<div class="flex flex-col justify-between w-page-container max-w-[calc(100%-2rem)] mx-auto px-4 h-full">
+39 -54
View File
@@ -3,10 +3,12 @@ import { onMounted, onUnmounted, ref, computed, watch } from 'vue'
import { useI18n } from 'vue-i18n'
import gsap from 'gsap'
import { ScrollTrigger } from 'gsap/ScrollTrigger'
import { useSiteSettings } from '~/composables/useSiteSettings'
gsap.registerPlugin(ScrollTrigger)
const { t, locale } = useI18n()
const { settings } = useSiteSettings()
interface WorkItem {
slug: string
@@ -26,40 +28,8 @@ const rootRef = ref<HTMLElement | null>(null)
const workSectionRef = ref<HTMLElement | null>(null)
const workPinRef = ref<HTMLElement | null>(null)
const partners = [
{
id: 'p1',
svg: '<svg viewBox="0 0 64 64" width="34" height="34" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M20 44V20h12c7 0 12 4 12 10s-5 10-12 10h-6v4H20Z" stroke="currentColor" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/><path d="M34 40l10 12" stroke="currentColor" stroke-width="3" stroke-linecap="round"/></svg>',
},
{
id: 'p2',
svg: '<svg viewBox="0 0 64 64" width="34" height="34" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14 32c0-9.94 8.06-18 18-18s18 8.06 18 18-8.06 18-18 18-18-8.06-18-18Z" stroke="currentColor" stroke-width="3"/><path d="M24 32c0-4.42 3.58-8 8-8s8 3.58 8 8-3.58 8-8 8-8-3.58-8-8Z" stroke="currentColor" stroke-width="3"/></svg>',
},
{
id: 'p3',
svg: '<svg viewBox="0 0 64 64" width="34" height="34" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M32 14v10M32 40v10M14 32h10M40 32h10" stroke="currentColor" stroke-width="3" stroke-linecap="round"/><path d="M32 22c5.52 0 10 4.48 10 10s-4.48 10-10 10-10-4.48-10-10 4.48-10 10-10Z" stroke="currentColor" stroke-width="3"/></svg>',
},
{
id: 'p4',
svg: '<svg viewBox="0 0 64 64" width="34" height="34" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M14 44c10-2 12-14 18-18s10-1 18-6" stroke="currentColor" stroke-width="3" stroke-linecap="round"/><path d="M16 34c8-2 10 8 18 6s10-18 18-18" stroke="currentColor" stroke-width="3" stroke-linecap="round"/></svg>',
},
{
id: 'p5',
svg: '<svg viewBox="0 0 64 64" width="34" height="34" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 38c0-9 6-18 14-18s14 9 14 18" stroke="currentColor" stroke-width="3" stroke-linecap="round"/><path d="M22 42h20" stroke="currentColor" stroke-width="3" stroke-linecap="round"/></svg>',
},
{
id: 'p6',
svg: '<svg viewBox="0 0 64 64" width="34" height="34" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 20v24M30 20v24M42 20v24" stroke="currentColor" stroke-width="3" stroke-linecap="round"/><path d="M14 20h36M14 44h36" stroke="currentColor" stroke-width="3" stroke-linecap="round"/></svg>',
},
{
id: 'p7',
svg: '<svg viewBox="0 0 64 64" width="34" height="34" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M18 44V20h10c9 0 18 7 18 12s-9 12-18 12H18Z" stroke="currentColor" stroke-width="3" stroke-linejoin="round"/></svg>',
},
{
id: 'p8',
svg: '<svg viewBox="0 0 64 64" width="34" height="34" fill="none" xmlns="http://www.w3.org/2000/svg"><path d="M16 34c8-14 18-14 32-4" stroke="currentColor" stroke-width="3" stroke-linecap="round"/><path d="M18 44c10-10 20-10 30-2" stroke="currentColor" stroke-width="3" stroke-linecap="round"/></svg>',
},
]
// 合作伙伴来自后台配置(/admin/settings 合作伙伴),空则隐藏该排展示
const partners = computed(() => settings.value?.partners ?? [])
let st: ScrollTrigger | null = null
let madeTweens: gsap.core.Animation[] = []
@@ -191,23 +161,39 @@ onUnmounted(() => {
<template>
<section ref="rootRef" class="bg-[#F5F5F5]">
<div class="w-page-container max-w-[calc(100%-2rem)] mx-auto px-6 md:px-10 lg:px-14 pt-24 pb-20">
<div class="grid grid-cols-[1fr_auto_1fr] items-center">
<p class="justify-self-start text-xs font-semibold tracking-tight text-black">( {{ t('home.partners.label') }} )</p>
<div class="flex items-center justify-self-center gap-8 text-xs font-semibold tracking-tight text-black">
<span class="h-1 w-1 rounded-full bg-black" />
<span>{{ t('home.partners.years') }}</span>
<!-- 合作伙伴(后台配置;空则不展示该排) -->
<template v-if="partners.length">
<div class="grid grid-cols-[1fr_auto_1fr] items-center">
<p class="justify-self-start text-xs font-semibold tracking-tight text-black">( {{ t('home.partners.label') }} )</p>
<div class="flex items-center justify-self-center gap-8 text-xs font-semibold tracking-tight text-black">
<span class="h-1 w-1 rounded-full bg-black" />
<span>{{ t('home.partners.years') }}</span>
</div>
<span class="justify-self-end h-1 w-1 rounded-full bg-black" />
</div>
<span class="justify-self-end h-1 w-1 rounded-full bg-black" />
</div>
<div class="mt-12 grid grid-cols-2 sm:grid-cols-4 gap-5">
<div
v-for="item in partners"
:key="item.id"
class="h-[152px] rounded-[20px] bg-white flex items-center justify-center text-black border-0 shadow-none outline-none ring-0"
v-html="item.svg"
/>
</div>
<div class="mt-12 grid grid-cols-2 sm:grid-cols-4 gap-5">
<template v-for="item in partners" :key="item.id">
<a
v-if="item.url"
:href="item.url"
target="_blank"
rel="noopener noreferrer"
class="h-[152px] rounded-[20px] bg-white flex items-center justify-center border-0 shadow-none outline-none ring-0 group"
>
<img v-if="item.logo" :src="item.logo" :alt="item.name" class="max-h-[72px] max-w-[80%] object-contain" />
<span v-else class="text-lg font-bold text-gray-400 group-hover:text-black transition-colors">{{ item.name }}</span>
</a>
<div
v-else
class="h-[152px] rounded-[20px] bg-white flex items-center justify-center border-0 shadow-none outline-none ring-0"
>
<img v-if="item.logo" :src="item.logo" :alt="item.name" class="max-h-[72px] max-w-[80%] object-contain" />
<span v-else class="text-lg font-bold text-gray-400">{{ item.name }}</span>
</div>
</template>
</div>
</template>
</div>
<section id="work" ref="workSectionRef" class="bg-white">
@@ -244,12 +230,11 @@ onUnmounted(() => {
:to="`/work/${item.slug}`"
class="will-change-transform relative block"
>
<img
class="h-full w-full object-cover"
:src="item.image || ''"
<CoverImage
:src="item.image"
:alt="locText(item.titleZh, item.titleEn)"
loading="eager"
decoding="async"
:title="locText(item.titleZh, item.titleEn)"
class="h-full w-full object-cover"
@load="refresh"
/>
<div class="absolute left-6 top-6 flex items-baseline gap-3">
+30 -13
View File
@@ -1,5 +1,5 @@
<template>
<section ref="rootRef" class="relative bg-gradient-to-b from-gray-50 to-white min-h-screen flex flex-col items-center justify-center overflow-hidden py-20">
<section v-if="testimonials.length" ref="rootRef" class="relative bg-gradient-to-b from-gray-50 to-white min-h-screen flex flex-col items-center justify-center overflow-hidden py-20">
<div class="w-full max-w-[1400px] mx-auto px-6 md:px-10">
<!-- 标题 -->
<div ref="headerRef" class="text-center mb-16 md:mb-20">
@@ -33,7 +33,7 @@
<!-- 评价内容 -->
<p class="text-gray-700 text-base md:text-lg leading-relaxed mb-8 italic">
"{{ t(`home.testimonials.items.${item.id}.content`) }}"
"{{ item.content }}"
</p>
<!-- 客户信息 -->
@@ -45,10 +45,10 @@
</div>
<div>
<h4 class="text-lg md:text-xl font-bold text-black">
{{ t(`home.testimonials.items.${item.id}.name`) }}
{{ item.name }}
</h4>
<p class="text-sm md:text-base text-gray-500">
{{ t(`home.testimonials.items.${item.id}.role`) }}
{{ item.role }}
</p>
</div>
</div>
@@ -69,10 +69,12 @@ import { ref, onMounted, onUnmounted, nextTick, computed } from 'vue'
import { useI18n } from 'vue-i18n'
import gsap from 'gsap'
import { ScrollTrigger } from 'gsap/ScrollTrigger'
import { useSiteSettings } from '~/composables/useSiteSettings'
gsap.registerPlugin(ScrollTrigger)
const { t } = useI18n()
const { t, locale } = useI18n()
const { settings } = useSiteSettings()
const rootRef = ref<HTMLElement | null>(null)
const headerRef = ref<HTMLElement | null>(null)
@@ -80,16 +82,31 @@ const trackRef = ref<HTMLElement | null>(null)
let ctx: gsap.Context | null = null
let animFrameId: number | null = null
const testimonials = [
{ id: 'client1', initial: 'A', avatarGradient: 'from-blue-500 to-cyan-500' },
{ id: 'client2', initial: 'B', avatarGradient: 'from-purple-500 to-pink-500' },
{ id: 'client3', initial: 'C', avatarGradient: 'from-orange-500 to-red-500' },
{ id: 'client4', initial: 'D', avatarGradient: 'from-green-500 to-emerald-500' },
{ id: 'client5', initial: 'E', avatarGradient: 'from-indigo-500 to-purple-500' },
// 头像渐变预设按序号循环,后台无需逐条选色
const AVATAR_STYLES = [
'from-blue-500 to-cyan-500',
'from-purple-500 to-pink-500',
'from-orange-500 to-red-500',
'from-green-500 to-emerald-500',
'from-indigo-500 to-purple-500',
]
const locStr = (zh: string, en: string) => (locale.value === 'zh' ? zh : en)
// 客户评价来自后台配置(/admin/settings 客户评价),空则不渲染该板块
const testimonials = computed(() =>
(settings.value?.testimonials ?? []).map((t, i) => ({
id: t.id,
name: t.name,
role: locStr(t.roleZh, t.roleEn),
content: locStr(t.contentZh, t.contentEn),
initial: (t.name || '?').trim().charAt(0).toUpperCase(),
avatarGradient: AVATAR_STYLES[i % AVATAR_STYLES.length],
})),
)
// 复制一份用于无缝循环
const allTestimonials = computed(() => [...testimonials, ...testimonials])
const allTestimonials = computed(() => [...testimonials.value, ...testimonials.value])
// 自动滚动状态
const offset = ref(0)
@@ -98,7 +115,7 @@ let isPaused = false
const cardWidth = 400 + 32 // 卡片宽度 + gap
const startAutoplay = () => {
const totalWidth = testimonials.length * cardWidth
const totalWidth = testimonials.value.length * cardWidth
const animate = () => {
if (!isPaused) {
@@ -1,6 +1,6 @@
<script setup lang="ts">
import { useI18n } from 'vue-i18n'
import { onMounted, ref, onUnmounted } from 'vue'
import { onMounted, ref, onUnmounted, computed } from 'vue'
import { gsap } from 'gsap'
import { ScrollTrigger } from 'gsap/ScrollTrigger'
import FooterLogo from '~/components/common/FooterLogo.vue'
@@ -10,6 +10,9 @@ import { useSiteSettings } from '~/composables/useSiteSettings'
const { t } = useI18n()
const { settings, loc } = useSiteSettings()
// 仅展示已填写 URL 的社交入口
const socials = computed(() => (settings.value?.socials ?? []).filter((s) => s.url))
gsap.registerPlugin(ScrollTrigger)
const footerRef = ref<HTMLElement | null>(null)
@@ -266,9 +269,9 @@ onUnmounted(() => {
</div>
</div>
<div class="flex gap-3 animated-item">
<div v-if="socials.length" class="flex gap-3 animated-item">
<a
v-for="social in settings?.socials ?? []"
v-for="social in socials"
:key="social.name"
:href="social.url"
target="_blank"
@@ -9,7 +9,6 @@ import { useUserStore } from '~/stores/user'
import { useAuthModalStore } from '~/stores/authModal'
import AppLogo from '~/components/common/AppLogo.vue'
import LoginModal from '~/components/common/LoginModal.vue'
import RegisterModal from '~/components/common/RegisterModal.vue'
gsap.registerPlugin(ScrollTrigger)
@@ -491,9 +490,6 @@ if (typeof window !== 'undefined') {
<!-- 登录弹窗(由 authModal store 控制开关) -->
<LoginModal />
<!-- 注册弹窗(由 authModal store 控制开关) -->
<RegisterModal />
<header ref="bottomHeaderRef" class="site-header-bottom z-50 bg-white/80 backdrop-blur-md">
<!-- 左侧菜单 (前两个菜单项) -->
<nav class="flex items-center justify-evenly md:justify-end gap-3 md:gap-4 w-full">
+51 -4
View File
@@ -26,6 +26,43 @@ export interface ToolItem {
descEn: string
}
/** 首页 Hero 背景画廊 */
export interface HeroSettings {
/** 图片 URL 列表,均分到左右两列;为空时显示品牌纯色兜底 */
gallery: string[]
}
/** 首页「成就数据」:数字统计(可在后台配置) */
export interface AchievementItem {
id: string
number: number
suffix: string
titleZh: string
titleEn: string
descriptionZh: string
descriptionEn: string
}
/** 首页「客户评价」(可在后台配置) */
export interface TestimonialItem {
id: string
name: string
roleZh: string
roleEn: string
contentZh: string
contentEn: string
}
/** 首页「合作伙伴」(可在后台配置;无 logo 时显示名称文字) */
export interface PartnerItem {
id: string
name: string
/** logo 图片 URL,可留空 */
logo?: string | null
/** 合作伙伴官网链接,可留空 */
url?: string | null
}
export interface SiteSettings {
site: {
name: string
@@ -40,6 +77,10 @@ export interface SiteSettings {
}
socials: SocialLink[]
tools: ToolItem[]
hero: HeroSettings
achievements: AchievementItem[]
testimonials: TestimonialItem[]
partners: PartnerItem[]
footer: {
title: LocalizedText
newsletterTitle: LocalizedText
@@ -71,10 +112,10 @@ export const defaultSettings: SiteSettings = {
},
},
socials: [
{ name: 'X', icon: 'ph:x-logo', url: 'https://x.com/arcticnewone' },
{ name: 'Instagram', icon: 'ph:instagram-logo', url: 'https://instagram.com/arcticnewone' },
{ name: 'LinkedIn', icon: 'ph:linkedin-logo', url: 'https://www.linkedin.com/company/arcticnewone' },
{ name: 'GitHub', icon: 'ph:github-logo', url: 'https://github.com/arcticnewone' },
{ name: '微博', icon: 'ri:weibo-fill', url: '' },
{ name: '知乎', icon: 'ri:zhihu-fill', url: '' },
{ name: '哔哩哔哩', icon: 'ri:bilibili-fill', url: '' },
{ name: 'GitHub', icon: 'ri:github-fill', url: '' },
],
tools: [
{
@@ -105,6 +146,12 @@ export const defaultSettings: SiteSettings = {
descEn: 'An all-in-one practical tool collection for developers and IT professionals.',
},
],
hero: {
gallery: [],
},
achievements: [],
testimonials: [],
partners: [],
footer: {
title: {
zh: '雕琢视觉,塑造故事。\n让我们共创卓越作品!',
+8 -193
View File
@@ -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
View File
@@ -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
View File
@@ -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>
+3 -3
View File
@@ -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>
+4 -3
View File
@@ -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>
+3 -3
View File
@@ -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">
+4 -3
View File
@@ -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>
+3 -3
View File
@@ -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>
+8 -30
View File
@@ -2,55 +2,33 @@ import { defineStore } from 'pinia'
import { ref, watch } from 'vue'
/**
* 登录/注册弹窗全局状态。
* Header、个人中心、收藏/评论组件等都可直接 openLogin() 唤起登录弹窗,
* 避免层层 prop/事件传递。
* 登录弹窗全局状态(统一认证跳转由 LoginModal 触发)。
* Header、个人中心、收藏/评论组件等都可直接 openLogin() 唤起,
* 避免层层 prop/事件传递。注册账号统一跳转 Casdoor 完成,此处不再提供注册弹窗。
*/
export const useAuthModalStore = defineStore('authModal', () => {
const isLoginOpen = ref(false)
const isRegisterOpen = ref(false)
// 任一弹窗打开时锁定背景滚动
// 弹窗打开时锁定背景滚动
watch(
() => [isLoginOpen.value, isRegisterOpen.value],
([login, register]) => {
() => isLoginOpen.value,
(open) => {
if (typeof document === 'undefined') return
document.body.style.overflow = login || register ? 'hidden' : ''
document.body.style.overflow = open ? 'hidden' : ''
},
)
const openLogin = () => {
isRegisterOpen.value = false
isLoginOpen.value = true
}
const openRegister = () => {
isLoginOpen.value = false
isRegisterOpen.value = true
}
const closeAll = () => {
isLoginOpen.value = false
isRegisterOpen.value = false
}
const switchToRegister = () => {
isLoginOpen.value = false
isRegisterOpen.value = true
}
const switchToLogin = () => {
isRegisterOpen.value = false
isLoginOpen.value = true
}
return {
isLoginOpen,
isRegisterOpen,
openLogin,
openRegister,
closeAll,
switchToRegister,
switchToLogin,
}
})
})
+14 -59
View File
@@ -3,9 +3,9 @@ import { ref, computed } from 'vue'
export interface User {
id: number
providerId: string
username: string
email: string
phone: string | null
avatar: string | null
role: 'user' | 'admin'
createdAt: string
@@ -21,46 +21,21 @@ const AVATAR_URL = (name: string) =>
`https://ui-avatars.com/api/?name=${encodeURIComponent(name)}&background=000&color=fff&size=128`
/**
* 用户会话状态(真实后端:httpOnly Cookie 会话)。
* 用户会话状态(Casdoor 统一认证 + 服务端会话,仅恢复/登出两个动作)。
* 登录不在此 store 发起表单请求:点击登录统一跳转 /api/auth/casdoor-login。
*/
export const useUserStore = defineStore('user', () => {
const user = ref<User | null>(null)
const isAuthenticated = computed(() => user.value !== null)
// 登录
const login = async (account: string, password: string): Promise<ApiResult> => {
try {
const data = await $fetch<{ user: User }>('/api/auth/login', {
method: 'POST',
body: { account, password },
})
user.value = data.user
return { success: true }
} catch (err) {
return { success: false, code: (err as any)?.data?.code || 'SERVER_ERROR' }
}
// 跳转 Casdoor 统一登录(next 为回跳路径,仅站内相对路径)
const loginRedirect = (next = '/'): void => {
const target = next.startsWith('/') && !next.startsWith('//') ? next : '/'
const url = `/api/auth/casdoor-login?next=${encodeURIComponent(target)}`
if (typeof window !== 'undefined') window.location.assign(url)
}
// 注册(成功即自动登录)
const register = async (data: {
username: string
email: string
phone?: string
password: string
}): Promise<ApiResult> => {
try {
const res = await $fetch<{ user: User }>('/api/auth/register', {
method: 'POST',
body: data,
})
user.value = res.user
return { success: true }
} catch (err) {
return { success: false, code: (err as any)?.data?.code || 'SERVER_ERROR' }
}
}
// 登出
// 登出:销毁本地会话并清 Cookie;如需 Casdoor 单点登出再跳转其 logout 地址
const logout = async (): Promise<void> => {
try {
await $fetch('/api/auth/logout', { method: 'POST' })
@@ -80,8 +55,8 @@ export const useUserStore = defineStore('user', () => {
}
}
// 更新资料
const updateProfile = async (patch: { username?: string; phone?: string }): Promise<ApiResult> => {
// 仅支持修改用户名(头像/邮箱等账号信息统一由 Casdoor 管理)
const updateProfile = async (patch: { username?: string }): Promise<ApiResult> => {
try {
const data = await $fetch<{ user: User }>('/api/auth/me', { method: 'PATCH', body: patch })
user.value = data.user
@@ -91,25 +66,7 @@ export const useUserStore = defineStore('user', () => {
}
}
// 更新头像(上传后由接口返回新 user,直接替换)
const updateAvatar = async (file: File | null): Promise<ApiResult> => {
try {
if (file) {
const fd = new FormData()
fd.append('file', file)
const data = await $fetch<{ user: User }>('/api/auth/avatar', { method: 'POST', body: fd })
user.value = data.user
} else {
const data = await $fetch<{ user: User }>('/api/auth/avatar', { method: 'POST', body: { clear: true } })
user.value = data.user
}
return { success: true }
} catch (err) {
return { success: false, code: (err as any)?.data?.code || 'SERVER_ERROR' }
}
}
// 头像:用户自定义优先,否则按用户名生成
// 头像:Casdoor 头像优先,否则按用户名生成
const avatar = computed(() => {
if (!user.value) return ''
return user.value.avatar || AVATAR_URL(user.value.username)
@@ -119,11 +76,9 @@ export const useUserStore = defineStore('user', () => {
user,
isAuthenticated,
avatar,
login,
register,
loginRedirect,
logout,
restoreUser,
updateProfile,
updateAvatar,
}
})
})
+48
View File
@@ -0,0 +1,48 @@
import { useRuntimeConfig } from '#app'
/**
* Casdoor 客户端配置读取(public runtimeConfig 注入,不含任何 secret)。
* 登录跳转走后端端点 /api/auth/casdoor-login,这里仅提供注册页与单点登出地址。
*/
export interface CasdoorPublic {
serverUrl: string
clientId: string
orgName: string
appName: string
redirectPath: string
}
export function getCasdoorPublic(): CasdoorPublic {
const c = useRuntimeConfig()
const pub = (c.public ?? {}) as Record<string, string | undefined>
return {
serverUrl: (pub.casdoorServerUrl as string) || '',
clientId: (pub.casdoorClientId as string) || '',
orgName: (pub.casdoorOrgName as string) || '',
appName: (pub.casdoorAppName as string) || '',
redirectPath: (pub.casdoorRedirectPath as string) || '/api/auth/callback',
}
}
/** 注册账号统一在 Casdoor 完成 */
export function getCasdoorSignupUrl(): string {
const { serverUrl, appName } = getCasdoorPublic()
if (!serverUrl || !appName) return ''
return `${serverUrl}/signup/${appName}`
}
/** 本站回调完整地址(用于登出回跳) */
export function getCasdoorRedirectUri(): string {
const { redirectPath } = getCasdoorPublic()
const { public: p } = useRuntimeConfig()
const siteUrl = String((p as any).siteUrl || '').replace(/\/$/, '')
return `${siteUrl}${redirectPath}`
}
/** 单点登出地址(可选使用:登出后跳回本站回调) */
export function getCasdoorLogoutUrl(): string {
const { serverUrl, clientId } = getCasdoorPublic()
if (!serverUrl || !clientId) return ''
return `${serverUrl}/logout?client_id=${clientId}&redirect_uri=${encodeURIComponent(getCasdoorRedirectUri())}`
}