Files
arcticnewone/app/components/home/HomePartnersWork.vue
T
virtheart 337eb4f05a 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 单测
2026-08-09 00:18:47 +08:00

257 lines
9.1 KiB
Vue
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
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
titleZh: string
titleEn: string
year: string
image: string | null
}
// 内容 API(仅已发布)
const { data } = await useFetch<{ works: WorkItem[] }>('/api/work')
const works = computed(() => data.value?.works ?? [])
const locText = (zh: string, en: string) => (locale.value === 'zh' ? zh : en)
const rootRef = ref<HTMLElement | null>(null)
const workSectionRef = ref<HTMLElement | null>(null)
const workPinRef = ref<HTMLElement | null>(null)
// 合作伙伴来自后台配置(/admin/settings 合作伙伴),空则隐藏该排展示
const partners = computed(() => settings.value?.partners ?? [])
let st: ScrollTrigger | null = null
let madeTweens: gsap.core.Animation[] = []
let positionedCards: HTMLElement[] = []
let initedOnce = false
let retryTimer: ReturnType<typeof setTimeout> | null = null
let stopRetry = false
const refresh = () => {
ScrollTrigger.refresh()
}
// 全部用 DOM 选择器(仅客户端;SSR 无 document,返回空)
const getWorkSection = () => (typeof document !== 'undefined' ? document.getElementById('work') : null)
const getPinEl = () => (typeof document !== 'undefined' ? document.querySelector<HTMLElement>('#work [data-work-pin]') : null)
const getCards = (): HTMLElement[] =>
typeof document !== 'undefined'
? Array.from(document.querySelectorAll<HTMLElement>('#work a[href^="/work/"]'))
: []
const initScrollAnimation = (): boolean => {
if (initedOnce) return true // 只初始化一次,绝不重初始化
const section = getWorkSection()
const pinEl = getPinEl()
if (!section || !pinEl) return false
const cards = getCards()
const count = cards.length
if (count < 2) return false
initedOnce = true
const enterOffset = 160
const scaleTo = 0.92
const depthOffsetY = -18
// 定位卡片为 absolute 堆叠(用原生样式,避免 gsap.set 被 pin 机制 revert)
positionedCards = cards
cards.forEach((card, i) => {
card.style.position = 'absolute'
card.style.top = '0'
card.style.right = '0'
card.style.bottom = '0'
card.style.left = '0'
card.style.zIndex = String(i + 1)
card.style.borderRadius = '22px'
card.style.overflow = 'hidden'
card.style.boxShadow = '0 18px 40px rgba(0,0,0,0.12)'
card.style.transform = i === 0 ? 'none' : `translateY(${window.innerHeight + enterOffset}px)`
})
const tl = gsap.timeline()
for (let i = 1; i < count; i += 1) {
const prev = cards[i - 1]
const next = cards[i]
const start = i - 1
tl.to(next, { y: 0, duration: 1, ease: 'power2.out' }, start)
tl.to(prev, { scale: scaleTo, y: depthOffsetY, duration: 0.6, ease: 'power2.out' }, start + 0.35)
tl.set(prev, { scale: scaleTo, y: depthOffsetY }, start + 1)
}
madeTweens.push(tl)
st = ScrollTrigger.create({
trigger: section,
start: 'top top',
end: () => `+=${(count - 1) * window.innerHeight}`,
pin: pinEl,
pinType: 'transform',
scrub: true,
anticipatePin: 1,
invalidateOnRefresh: true,
animation: tl,
})
requestAnimationFrame(() => ScrollTrigger.refresh())
return true
}
// 自愈初始化:卡片尚未就绪时每 200ms 重试,直到成功(成功即停)
const ensureInit = () => {
if (stopRetry) return
if (typeof window === 'undefined') return // SSR 不执行
if (initScrollAnimation()) {
if (retryTimer) {
clearTimeout(retryTimer)
retryTimer = null
}
return
}
retryTimer = setTimeout(ensureInit, 200)
}
// 数据变化时触发(不在 setup 立即执行——hydration 前初始化会被 hydration 重置样式)
watch(works, ensureInit)
onMounted(() => {
ensureInit() // hydration 完成后初始化
if (typeof window !== 'undefined') {
window.addEventListener('hero-intro-done', ensureInit, { once: true })
setTimeout(ensureInit, 3000)
}
})
onUnmounted(() => {
stopRetry = true
if (retryTimer) clearTimeout(retryTimer)
if (st) {
st.kill()
st = null
}
madeTweens.forEach((t) => t.revert())
madeTweens = []
// 复位卡片定位样式
positionedCards.forEach((c) => {
if (!c) return
c.style.position = ''
c.style.top = ''
c.style.right = ''
c.style.bottom = ''
c.style.left = ''
c.style.zIndex = ''
c.style.borderRadius = ''
c.style.overflow = ''
c.style.boxShadow = ''
c.style.transform = ''
})
positionedCards = []
})
</script>
<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">
<!-- 合作伙伴(后台配置;空则不展示该排) -->
<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>
<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">
<div class="w-page-container max-w-[calc(100%-2rem)] mx-auto px-4 pb-28">
<div
data-work-pin
class="flex flex-col lg:flex-row gap-10 lg:gap-16 h-[100svh] items-stretch"
>
<div class="lg:w-[340px] flex flex-col gap-8 pt-8 md:pt-10">
<p class="text-xs font-semibold tracking-tight text-black/70">( {{ t('home.work.label') }} )</p>
<div>
<h2 class="text-5xl md:text-6xl font-bold tracking-tighter leading-[0.92]">
{{ t('home.work.title') }}
<span class="text-black/40 text-base md:text-lg align-middle ml-2 font-semibold tracking-tight">
({{ works.length }})
</span>
</h2>
</div>
<NuxtLink
to="/work"
class="inline-flex w-fit items-center gap-2 rounded-full bg-black px-6 py-3 text-white text-sm font-semibold shadow-[0_15px_30px_-5px_rgba(0,0,0,0.25)]"
>
{{ t('home.work.viewAll') }}
</NuxtLink>
</div>
<div class="relative flex-1 h-full flex items-center">
<div class="relative w-full h-[78svh] md:h-[82svh] lg:h-[88svh] p-[clamp(14px,2.4vw,28px)]">
<div class="relative h-full w-full">
<NuxtLink
v-for="item in works"
:key="item.slug"
:to="`/work/${item.slug}`"
class="will-change-transform relative block"
>
<CoverImage
:src="item.image"
:alt="locText(item.titleZh, item.titleEn)"
: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">
<p class="text-white text-sm md:text-base font-semibold tracking-tight drop-shadow-[0_10px_18px_rgba(0,0,0,0.4)]">
{{ locText(item.titleZh, item.titleEn) }}
</p>
<p class="text-white/80 text-xs md:text-sm font-semibold tracking-tight drop-shadow-[0_10px_18px_rgba(0,0,0,0.4)]">
{{ item.year }} ©
</p>
</div>
</NuxtLink>
</div>
</div>
</div>
</div>
</div>
</section>
</section>
</template>