|
|
<script setup lang="ts">
|
|
|
import { ref, computed, watch, onMounted, onUnmounted } from 'vue'
|
|
|
import { useRouter, useRoute } from 'vue-router'
|
|
|
import 'bootstrap/dist/css/bootstrap.min.css'
|
|
|
import '../styles/prototype-styles.css'
|
|
|
import { getApiBase, TOKEN_KEY } from '../config/api'
|
|
|
import {
|
|
|
brandingFormFromApi,
|
|
|
emptyBrandingForm,
|
|
|
hasVisibleText,
|
|
|
participantApplyPageTitle,
|
|
|
type BrandingForm,
|
|
|
} from '../utils/competitionBranding'
|
|
|
|
|
|
const router = useRouter()
|
|
|
const route = useRoute()
|
|
|
|
|
|
const participantSlug = computed(() => String(route.params.slug ?? '').trim())
|
|
|
|
|
|
const brand = ref<BrandingForm>(emptyBrandingForm())
|
|
|
const competitionName = ref('')
|
|
|
|
|
|
const layoutHeaderTitle = computed(() => participantApplyPageTitle(brand.value, competitionName.value))
|
|
|
|
|
|
/** 与登录页一致:运营配置优先,否则按赛事名生成默认版权文案 */
|
|
|
const layoutFooterCopyright = computed(() => {
|
|
|
if (hasVisibleText(brand.value.login.footerCopyright)) {
|
|
|
return brand.value.login.footerCopyright
|
|
|
}
|
|
|
const n = competitionName.value.trim()
|
|
|
return n ? `版权所有:${n}` : '版权所有'
|
|
|
})
|
|
|
|
|
|
async function loadParticipantBranding() {
|
|
|
const s = participantSlug.value
|
|
|
if (!s) {
|
|
|
brand.value = emptyBrandingForm()
|
|
|
competitionName.value = ''
|
|
|
return
|
|
|
}
|
|
|
try {
|
|
|
const r = await fetch(
|
|
|
`${getApiBase()}/api/v1/public/competitions/by-slug/${encodeURIComponent(s)}`,
|
|
|
{ headers: { Accept: 'application/json' } },
|
|
|
)
|
|
|
if (!r.ok) {
|
|
|
brand.value = emptyBrandingForm()
|
|
|
competitionName.value = ''
|
|
|
return
|
|
|
}
|
|
|
const raw = (await r.json()) as Record<string, unknown>
|
|
|
const data =
|
|
|
raw.data != null && typeof raw.data === 'object' && !Array.isArray(raw.data)
|
|
|
? (raw.data as Record<string, unknown>)
|
|
|
: raw
|
|
|
competitionName.value = String(data.name ?? '')
|
|
|
brand.value = brandingFormFromApi(data.branding_json ?? null)
|
|
|
} catch {
|
|
|
brand.value = emptyBrandingForm()
|
|
|
competitionName.value = ''
|
|
|
}
|
|
|
}
|
|
|
|
|
|
watch(participantSlug, () => {
|
|
|
void loadParticipantBranding()
|
|
|
}, { immediate: true })
|
|
|
|
|
|
/** branding 未配置时与首页/登录同款深蓝,避免子元素 var(--primary) 回退到原型 :root 洋红 */
|
|
|
const PARTICIPANT_DEFAULT_PRIMARY = '#052d62'
|
|
|
|
|
|
function primaryHexToRgbTriplet(hex: string): string | null {
|
|
|
const s = hex.trim().replace('#', '')
|
|
|
if (!/^[0-9a-f]{6}$/i.test(s)) return null
|
|
|
const r = parseInt(s.slice(0, 2), 16)
|
|
|
const g = parseInt(s.slice(2, 4), 16)
|
|
|
const b = parseInt(s.slice(4, 6), 16)
|
|
|
return `${r}, ${g}, ${b}`
|
|
|
}
|
|
|
|
|
|
/** 与登录页一致:把运营配置的主题色写回 body;无配置时用默认深蓝并同步 --bs-primary,避免首屏 Bootstrap 主按钮仍是默认色 */
|
|
|
function applyParticipantBodyTheme() {
|
|
|
if (typeof document === 'undefined') return
|
|
|
const custom = brand.value.login.themePrimary?.trim() ?? ''
|
|
|
const theme = hasVisibleText(custom)
|
|
|
? /^(?:#|rgb|hsl)/i.test(custom)
|
|
|
? custom
|
|
|
: `#${custom.replace(/^#/, '')}`
|
|
|
: PARTICIPANT_DEFAULT_PRIMARY
|
|
|
document.body.style.setProperty('--primary', theme)
|
|
|
document.body.style.setProperty('--bs-primary', theme)
|
|
|
if (theme.startsWith('#')) {
|
|
|
document.body.style.setProperty('--primary-soft', `${theme}14`)
|
|
|
const rgb = primaryHexToRgbTriplet(theme)
|
|
|
if (rgb) document.body.style.setProperty('--bs-primary-rgb', rgb)
|
|
|
} else {
|
|
|
document.body.style.removeProperty('--primary-soft')
|
|
|
document.body.style.removeProperty('--bs-primary-rgb')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
watch(brand, () => applyParticipantBodyTheme(), { deep: true, immediate: true })
|
|
|
|
|
|
const profileLabel = ref('')
|
|
|
|
|
|
const roleBadge = computed(() => profileLabel.value || '用户')
|
|
|
|
|
|
async function loadProfile() {
|
|
|
const t = localStorage.getItem(TOKEN_KEY)
|
|
|
const base = getApiBase()
|
|
|
if (!t) return
|
|
|
try {
|
|
|
const r = await fetch(`${base}/api/me`, {
|
|
|
headers: { Authorization: `Bearer ${t}`, Accept: 'application/json' },
|
|
|
})
|
|
|
if (!r.ok) return
|
|
|
const u = (await r.json()) as { name?: string | null; mobile?: string | null }
|
|
|
profileLabel.value = u.name || u.mobile || ''
|
|
|
} catch {
|
|
|
/* 忽略 */
|
|
|
}
|
|
|
}
|
|
|
|
|
|
function logout() {
|
|
|
localStorage.removeItem(TOKEN_KEY)
|
|
|
localStorage.removeItem('cxxfds_user')
|
|
|
const s = participantSlug.value
|
|
|
if (s) {
|
|
|
void router.push({ name: 'participant-login', params: { slug: s } })
|
|
|
} else {
|
|
|
void router.push('/c')
|
|
|
}
|
|
|
}
|
|
|
|
|
|
onMounted(() => {
|
|
|
document.body.classList.add('prototype-page', 'user-mobile-no-menu')
|
|
|
loadProfile()
|
|
|
})
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
document.body.classList.remove('prototype-page', 'user-mobile-no-menu')
|
|
|
document.body.style.removeProperty('--primary')
|
|
|
document.body.style.removeProperty('--primary-soft')
|
|
|
document.body.style.removeProperty('--bs-primary')
|
|
|
document.body.style.removeProperty('--bs-primary-rgb')
|
|
|
})
|
|
|
</script>
|
|
|
|
|
|
<template>
|
|
|
<div class="participant-layout">
|
|
|
<header class="navbar navbar-expand-lg layout-header">
|
|
|
<div class="container-fluid px-3 px-lg-4">
|
|
|
<span class="navbar-brand mb-0 prototype-title">{{ layoutHeaderTitle }}</span>
|
|
|
<div class="dropdown">
|
|
|
<button
|
|
|
class="header-user dropdown-toggle"
|
|
|
type="button"
|
|
|
data-bs-toggle="dropdown"
|
|
|
aria-expanded="false"
|
|
|
>
|
|
|
<svg width="22" height="22" viewBox="0 0 24 24" fill="none" aria-hidden="true">
|
|
|
<circle cx="12" cy="12" r="9.5" stroke="currentColor" stroke-width="2" />
|
|
|
<circle cx="12" cy="9" r="3.2" fill="currentColor" />
|
|
|
<path
|
|
|
d="M6.8 18.2c1.1-2.4 3-3.6 5.2-3.6s4.1 1.2 5.2 3.6"
|
|
|
fill="currentColor"
|
|
|
/>
|
|
|
</svg>
|
|
|
<span class="header-user-name">{{ roleBadge }}</span>
|
|
|
</button>
|
|
|
<ul class="dropdown-menu dropdown-menu-end header-user-menu">
|
|
|
<li>
|
|
|
<a class="dropdown-item text-danger" href="javascript:void(0)" @click.prevent="logout">
|
|
|
<span class="menu-icon">↪</span>退出登录
|
|
|
</a>
|
|
|
</li>
|
|
|
</ul>
|
|
|
</div>
|
|
|
</div>
|
|
|
</header>
|
|
|
|
|
|
<div class="container-fluid px-3 px-lg-4 py-3 layout-main">
|
|
|
<div class="row layout-main-row g-3">
|
|
|
<aside class="col-12 col-md-2 col-lg-2 layout-sider">
|
|
|
<div class="card h-100">
|
|
|
<div class="card-body">
|
|
|
<nav class="nav flex-column gap-2">
|
|
|
<router-link
|
|
|
class="nav-link text-start"
|
|
|
active-class="active"
|
|
|
:to="{ name: 'participant-apply', params: { slug: participantSlug } }"
|
|
|
>
|
|
|
赛事报名
|
|
|
</router-link>
|
|
|
</nav>
|
|
|
</div>
|
|
|
</div>
|
|
|
</aside>
|
|
|
<main class="col-12 col-md-10 col-lg-10 participant-main-col">
|
|
|
<router-view />
|
|
|
</main>
|
|
|
</div>
|
|
|
</div>
|
|
|
|
|
|
<footer
|
|
|
id="layoutFooter"
|
|
|
class="border-top bg-white text-center py-2 small text-secondary prototype-subtitle"
|
|
|
>
|
|
|
{{ layoutFooterCopyright }}
|
|
|
</footer>
|
|
|
</div>
|
|
|
</template>
|
|
|
|
|
|
<style scoped>
|
|
|
:deep(a.router-link-active.nav-link) {
|
|
|
background: #eef7fc;
|
|
|
color: #052d62;
|
|
|
font-weight: 600;
|
|
|
}
|
|
|
|
|
|
:deep(.layout-sider .nav-link:not(.router-link-active)) {
|
|
|
color: #3a4a5c;
|
|
|
}
|
|
|
</style>
|
|
|
|
|
|
<style>
|
|
|
/**
|
|
|
* 选手端整页 flex:页脚贴视口底;避免 .layout-main 固定 height 导致中间空白、footer 视觉位置异常。
|
|
|
* ≥md:锁定 html/body/#app 高度,仅中间表单槽滚动,避免整页滚动把页脚顶下去。
|
|
|
* 下拉菜单依赖侧栏/卡片 overflow: visible;中间列与 .apply-form-scroll 负责裁剪纵向滚动。
|
|
|
*/
|
|
|
#app .participant-layout {
|
|
|
flex: 1 1 auto;
|
|
|
display: flex;
|
|
|
flex-direction: column;
|
|
|
width: 100%;
|
|
|
min-height: 100svh;
|
|
|
}
|
|
|
|
|
|
/* 顶栏与主区容器全宽,避免 max-width + 居中导致内容缩在中间一条 */
|
|
|
body.prototype-page.user-mobile-no-menu .participant-layout .layout-header > .container-fluid,
|
|
|
body.prototype-page.user-mobile-no-menu .participant-layout .layout-main.container-fluid {
|
|
|
max-width: none !important;
|
|
|
width: 100%;
|
|
|
margin-left: 0;
|
|
|
margin-right: 0;
|
|
|
}
|
|
|
|
|
|
.participant-layout .layout-main {
|
|
|
flex: 1 1 auto;
|
|
|
min-height: 0;
|
|
|
overflow: visible;
|
|
|
}
|
|
|
|
|
|
.participant-layout .layout-main > .layout-main-row {
|
|
|
overflow: visible;
|
|
|
min-height: 0;
|
|
|
}
|
|
|
|
|
|
.participant-layout .layout-main > .layout-main-row > main {
|
|
|
min-width: 0;
|
|
|
}
|
|
|
|
|
|
.participant-layout #layoutFooter {
|
|
|
flex-shrink: 0;
|
|
|
margin-top: auto;
|
|
|
}
|
|
|
|
|
|
@media (min-width: 768px) {
|
|
|
html:has(body.prototype-page.user-mobile-no-menu) {
|
|
|
height: 100%;
|
|
|
max-height: 100dvh;
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
|
|
|
body.prototype-page.user-mobile-no-menu {
|
|
|
height: 100%;
|
|
|
max-height: 100dvh;
|
|
|
margin: 0;
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
|
|
|
body.prototype-page.user-mobile-no-menu #app {
|
|
|
height: 100%;
|
|
|
max-height: 100dvh;
|
|
|
min-height: 0 !important;
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
|
|
|
#app .participant-layout {
|
|
|
min-height: 0 !important;
|
|
|
height: 100%;
|
|
|
max-height: 100%;
|
|
|
overflow: hidden;
|
|
|
}
|
|
|
|
|
|
.participant-layout .layout-main {
|
|
|
flex: 1 1 0%;
|
|
|
min-height: 0;
|
|
|
overflow: hidden;
|
|
|
display: flex;
|
|
|
flex-direction: column;
|
|
|
}
|
|
|
|
|
|
.participant-layout .layout-main > .layout-main-row {
|
|
|
flex: 1 1 0%;
|
|
|
min-height: 0;
|
|
|
max-height: 100%;
|
|
|
flex-wrap: nowrap;
|
|
|
align-items: stretch;
|
|
|
overflow: visible;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/* 主题赛道自定义下拉:菜单不被 main/card 裁剪 */
|
|
|
.participant-layout .track-custom-select .dropdown-menu {
|
|
|
z-index: 1085;
|
|
|
}
|
|
|
|
|
|
.participant-layout main .card {
|
|
|
overflow: visible;
|
|
|
}
|
|
|
</style>
|