Files
thebet365/apps/player/src/views/RegisterView.vue
Mars f9d68d94ce feat(player): theme-2 认证页 zt2 背景与表单样式优化
- 登录/注册/找回密码使用 zt2.webp,移除暗色渐变遮罩

- 表单标题、标签、链接改为深蓝/灰色,适配 Pinnacle 浅色主题

- 更新 zt2.webp 资源文件
2026-06-23 15:56:13 +08:00

446 lines
11 KiB
Vue

<script setup lang="ts">
import { ref } from 'vue';
import { useRoute, useRouter } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { defaultPhoneIsoForLocale, getPhoneDialFromIso, isValidPlayerUsername } from '@thebet365/shared';
import { useAuthStore } from '../stores/auth';
import { useAppLocale } from '../composables/useAppLocale';
import { useSmsCode } from '../composables/useSmsCode';
import LocaleSwitcher from '../components/LocaleSwitcher.vue';
import PhoneCountrySelect from '../components/PhoneCountrySelect.vue';
import GoldSpinner from '../components/GoldSpinner.vue';
import loginBg from '../assets/images/zt2.webp';
const { t, locale } = useI18n();
const { initFromUser } = useAppLocale();
const auth = useAuthStore();
const router = useRouter();
const route = useRoute();
const account = ref('');
const phone = ref('');
const countryIso = ref(defaultPhoneIsoForLocale(locale.value));
const password = ref('');
const confirmPassword = ref('');
const smsCode = ref('');
const inviteCode = ref(typeof route.query.code === 'string' ? route.query.code : '');
const error = ref('');
const loading = ref(false);
const { sessionId, countdown, sending, error: smsError, send } = useSmsCode();
async function sendCode() {
await send(phone.value, getPhoneDialFromIso(countryIso.value));
}
async function submit() {
if (!account.value.trim()) {
error.value = t('auth.username_required');
return;
}
if (!isValidPlayerUsername(account.value)) {
error.value = t('auth.username_format_invalid');
return;
}
if (!sessionId.value) {
error.value = t('auth.sms_required');
return;
}
if (!smsCode.value.trim()) {
error.value = t('auth.sms_code_required');
return;
}
if (password.value !== confirmPassword.value) {
error.value = t('auth.password_mismatch');
return;
}
loading.value = true;
error.value = '';
try {
await auth.register(
account.value,
phone.value,
getPhoneDialFromIso(countryIso.value),
password.value,
smsCode.value,
sessionId.value,
inviteCode.value,
);
initFromUser(auth.user?.locale);
const redirectTo = (route.query.redirect as string) || '/';
router.push(redirectTo);
} catch (e: unknown) {
error.value = (e as { response?: { data?: { error?: string } } })?.response?.data?.error || t('auth.register_failed');
} finally {
loading.value = false;
}
}
function goLogin() {
router.push({ path: '/login', query: route.query.redirect ? { redirect: route.query.redirect as string } : {} });
}
function isGuestBrowsablePath(path: string): boolean {
if (!path || path === '/' || path === '/bet') return true;
if (path.startsWith('/match/')) return true;
return false;
}
function continueBrowsing() {
const redirect = typeof route.query.redirect === 'string' ? route.query.redirect : '';
const target = isGuestBrowsablePath(redirect) ? redirect || '/' : '/';
router.replace(target);
}
const fieldError = () => {
if (error.value) return error.value;
if (smsError.value === 'phone_required') return t('auth.phone_required');
if (smsError.value) return smsError.value;
return '';
};
</script>
<template>
<div class="login-page" :style="{ backgroundImage: `url(${loginBg})` }">
<div class="login-lang">
<LocaleSwitcher compact />
</div>
<div class="login-stack">
<form @submit.prevent="submit" class="login-form ps-gold-frame" :class="{ 'is-busy': loading }">
<div v-if="loading" class="form-busy-overlay" aria-hidden="true">
<GoldSpinner :size="40" :active="true" />
<p class="form-busy-text">{{ t('auth.registering') }}</p>
</div>
<h2 class="form-title">{{ t('auth.register') }}</h2>
<div class="field">
<label>{{ t('auth.username') }}</label>
<input
v-model="account"
class="field-input ps-gold-input"
required
autocomplete="username"
maxlength="32"
minlength="7"
:disabled="loading"
:placeholder="t('auth.username_register_placeholder')"
/>
</div>
<div class="field">
<label>{{ t('auth.phone') }}</label>
<div class="inline-row">
<PhoneCountrySelect v-model="countryIso" />
<input
v-model="phone"
class="field-input ps-gold-input"
type="tel"
required
autocomplete="tel-national"
:disabled="loading"
:placeholder="t('auth.phone_local_placeholder')"
/>
</div>
</div>
<div class="field">
<label>{{ t('auth.sms_code') }}</label>
<div class="inline-row">
<input
v-model="smsCode"
class="field-input ps-gold-input"
inputmode="numeric"
maxlength="6"
autocomplete="one-time-code"
:disabled="loading"
:placeholder="t('auth.sms_code_placeholder')"
/>
<button
type="button"
class="btn-secondary"
:disabled="sending || countdown > 0 || !phone.trim() || loading"
@click="sendCode"
>
<span v-if="sending" class="btn-inline-loading">
<GoldSpinner :size="14" :active="true" />
{{ t('auth.sending_sms') }}
</span>
<span v-else>{{ countdown > 0 ? `${countdown}s` : t('auth.send_sms') }}</span>
</button>
</div>
</div>
<div class="field">
<label>{{ t('auth.password') }}</label>
<input v-model="password" class="field-input ps-gold-input" type="password" required autocomplete="new-password" minlength="8" :disabled="loading" />
</div>
<div class="field">
<label>{{ t('auth.confirm_password') }}</label>
<input v-model="confirmPassword" class="field-input ps-gold-input" type="password" required autocomplete="new-password" minlength="8" :disabled="loading" />
</div>
<div class="field field-optional">
<label>{{ t('auth.invite_code') }} <span class="optional-tag">{{ t('auth.optional') }}</span></label>
<input v-model="inviteCode" class="field-input ps-gold-input" autocomplete="off" :disabled="loading" />
</div>
<p v-if="fieldError()" class="error">{{ fieldError() }}</p>
<button
type="submit"
class="btn-login btn-gold-outline"
:class="{ 'is-loading': loading }"
:disabled="loading"
:aria-busy="loading"
>
<span v-if="loading" class="btn-inline-loading">
<GoldSpinner :size="18" :active="true" />
{{ t('auth.registering') }}
</span>
<span v-else>{{ t('auth.register_btn') }}</span>
</button>
</form>
<div class="login-actions">
<button type="button" class="btn-skip" :disabled="loading" @click="goLogin">
{{ t('auth.have_account') }}
</button>
<button type="button" class="btn-skip-light" :disabled="loading" @click="continueBrowsing">
{{ t('auth.continue_browsing') }}
</button>
</div>
</div>
</div>
</template>
<style scoped>
.login-lang {
position: absolute;
top: max(12px, env(safe-area-inset-top));
right: 16px;
z-index: 10;
}
.login-page {
position: relative;
height: 100%;
min-height: 100dvh;
overflow-y: auto;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-end;
padding: 30vh 16px max(20px, env(safe-area-inset-bottom));
background-color: var(--bg-body);
background-size: cover;
background-position: center top;
background-repeat: no-repeat;
}
.login-stack {
position: relative;
z-index: 1;
width: 100%;
max-width: 320px;
display: flex;
flex-direction: column;
gap: 8px;
}
.login-form {
position: relative;
width: 100%;
display: flex;
flex-direction: column;
gap: 8px;
padding: 14px;
}
.login-actions {
display: flex;
flex-direction: column;
align-items: center;
gap: 2px;
padding: 0 14px 4px;
}
.login-form.is-busy {
pointer-events: none;
}
.form-busy-overlay {
position: absolute;
inset: 0;
z-index: 3;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 10px;
border-radius: inherit;
background: rgba(255, 255, 255, 0.88);
backdrop-filter: blur(4px);
pointer-events: all;
}
.form-busy-text {
margin: 0;
font-size: 13px;
font-weight: 700;
color: var(--primary);
letter-spacing: 0.04em;
}
.btn-inline-loading {
display: inline-flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.form-title {
margin: 0 0 2px;
font-size: 16px;
font-weight: 800;
color: var(--text);
text-align: center;
}
.field {
display: flex;
flex-direction: column;
gap: 4px;
}
.field-optional {
opacity: 0.85;
}
label {
font-size: 10px;
color: var(--text-muted);
font-weight: 600;
letter-spacing: 0.03em;
}
.optional-tag {
font-size: 10px;
font-weight: 500;
color: var(--text-muted);
}
.field-input {
width: 100%;
height: 36px;
padding: 0 10px;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--bg-input);
color: var(--text);
font-size: 14px;
font-family: inherit;
}
.field-input::placeholder {
color: rgba(0, 0, 0, 0.35);
}
.field-input:focus {
outline: none;
border-color: var(--border-gold-soft);
}
.inline-row {
display: flex;
gap: 6px;
align-items: center;
}
.inline-row .field-input {
flex: 1;
min-width: 0;
}
.btn-secondary {
flex-shrink: 0;
height: 36px;
padding: 0 10px;
border: 1px solid var(--border);
border-radius: 6px;
background: var(--bg-card);
color: var(--text);
font-size: 11px;
font-weight: 600;
white-space: nowrap;
cursor: pointer;
}
.btn-secondary:not(:disabled).active,
.btn-secondary:active:not(:disabled) {
border-color: var(--primary);
background: var(--surface-accent);
color: var(--text);
}
.btn-secondary:disabled {
opacity: 0.45;
cursor: not-allowed;
}
.btn-login {
margin-top: 2px;
padding: 9px 12px;
border-radius: 6px;
font-size: 14px;
font-weight: 800;
}
.btn-login:disabled {
opacity: 0.45;
cursor: not-allowed;
}
.btn-login.is-loading:disabled {
opacity: 1;
}
.btn-skip {
padding: 6px 14px;
border: none;
background: transparent;
color: var(--primary);
font-size: 13px;
font-weight: 600;
cursor: pointer;
text-align: center;
}
.btn-skip:active {
color: var(--primary-dark);
}
.btn-skip-light {
padding: 6px 16px;
border: none;
background: transparent;
color: var(--text-muted);
font-size: 13px;
font-weight: 400;
cursor: pointer;
white-space: nowrap;
text-align: center;
}
.btn-skip-light:active {
color: var(--text);
}
.error {
margin: 0;
color: var(--danger);
font-size: 12px;
font-weight: 600;
line-height: 1.3;
}
</style>