feat(player): 接入创蓝短信手机注册与登录页优化
新增 SMS 验证码注册、8 国手机号选择与 Redis 频控;优化登录/注册 UI 及图形验证码样式。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
251
apps/player/src/components/PhoneCountrySelect.vue
Normal file
251
apps/player/src/components/PhoneCountrySelect.vue
Normal file
@@ -0,0 +1,251 @@
|
||||
<script setup lang="ts">
|
||||
import { ref, computed, onMounted, onUnmounted, watch } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import {
|
||||
PHONE_COUNTRIES,
|
||||
getPhoneCountryLabel,
|
||||
searchPhoneCountries,
|
||||
findPhoneCountryByIso,
|
||||
defaultPhoneIsoForLocale,
|
||||
} from '@thebet365/shared';
|
||||
|
||||
const model = defineModel<string>({ required: true });
|
||||
const { t, locale } = useI18n();
|
||||
|
||||
const open = ref(false);
|
||||
const query = ref('');
|
||||
const root = ref<HTMLElement | null>(null);
|
||||
|
||||
const options = computed(() =>
|
||||
searchPhoneCountries(query.value, locale.value).map((country) => ({
|
||||
iso: country.iso,
|
||||
dial: country.dial,
|
||||
code: `+${country.dial}`,
|
||||
name: getPhoneCountryLabel(country, locale.value),
|
||||
flag: country.flag,
|
||||
})),
|
||||
);
|
||||
|
||||
const current = computed(() => {
|
||||
const matched = findPhoneCountryByIso(model.value)
|
||||
?? PHONE_COUNTRIES.find((c) => c.dial === model.value);
|
||||
if (matched) {
|
||||
return {
|
||||
iso: matched.iso,
|
||||
code: `+${matched.dial}`,
|
||||
name: getPhoneCountryLabel(matched, locale.value),
|
||||
};
|
||||
}
|
||||
return { iso: '--', code: '+--', name: '' };
|
||||
});
|
||||
|
||||
function pick(iso: string) {
|
||||
model.value = iso;
|
||||
open.value = false;
|
||||
query.value = '';
|
||||
}
|
||||
|
||||
function toggle() {
|
||||
open.value = !open.value;
|
||||
if (open.value) query.value = '';
|
||||
}
|
||||
|
||||
function onOutsideClick(e: Event) {
|
||||
if (!root.value?.contains(e.target as Node)) {
|
||||
open.value = false;
|
||||
query.value = '';
|
||||
}
|
||||
}
|
||||
|
||||
watch(open, (isOpen) => {
|
||||
if (!isOpen) query.value = '';
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
if (!findPhoneCountryByIso(model.value)) {
|
||||
model.value = defaultPhoneIsoForLocale(locale.value);
|
||||
}
|
||||
document.addEventListener('click', onOutsideClick);
|
||||
document.addEventListener('touchend', onOutsideClick);
|
||||
});
|
||||
onUnmounted(() => {
|
||||
document.removeEventListener('click', onOutsideClick);
|
||||
document.removeEventListener('touchend', onOutsideClick);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="root" class="country-switch" :class="{ open }">
|
||||
<button
|
||||
type="button"
|
||||
class="country-trigger"
|
||||
:aria-expanded="open"
|
||||
aria-haspopup="listbox"
|
||||
:title="current.name"
|
||||
@click.stop="toggle"
|
||||
>
|
||||
<span class="country-iso">{{ current.iso }}</span>
|
||||
<span class="country-sep">·</span>
|
||||
<span class="country-dial">{{ current.code }}</span>
|
||||
</button>
|
||||
<div v-show="open" class="country-panel">
|
||||
<input
|
||||
v-model="query"
|
||||
class="country-search"
|
||||
type="search"
|
||||
:placeholder="t('auth.country_search')"
|
||||
autocomplete="off"
|
||||
@click.stop
|
||||
/>
|
||||
<ul class="country-menu" role="listbox">
|
||||
<li
|
||||
v-for="opt in options"
|
||||
:key="opt.iso"
|
||||
role="option"
|
||||
:aria-selected="model === opt.iso"
|
||||
class="country-option"
|
||||
:class="{ active: model === opt.iso }"
|
||||
@click="pick(opt.iso)"
|
||||
>
|
||||
<span class="country-iso">{{ opt.iso }}</span>
|
||||
<span class="country-dial">{{ opt.code }}</span>
|
||||
<span class="country-name">{{ opt.name }}</span>
|
||||
</li>
|
||||
<li v-if="options.length === 0" class="country-empty">{{ t('auth.country_not_found') }}</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.country-switch {
|
||||
position: relative;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
.country-trigger {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 3px;
|
||||
height: 36px;
|
||||
padding: 0 8px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: #0d0d0d;
|
||||
color: var(--text);
|
||||
font-family: inherit;
|
||||
font-size: 12px;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.country-trigger:active {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.country-iso {
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.03em;
|
||||
}
|
||||
|
||||
.country-sep {
|
||||
color: var(--text-muted);
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.country-dial {
|
||||
color: var(--text-muted);
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.country-panel {
|
||||
position: absolute;
|
||||
top: calc(100% + 4px);
|
||||
left: 0;
|
||||
z-index: 60;
|
||||
width: min(260px, calc(100vw - 48px));
|
||||
padding: 4px;
|
||||
background: #141414;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
box-shadow: var(--shadow);
|
||||
}
|
||||
|
||||
.country-search {
|
||||
width: 100%;
|
||||
margin-bottom: 4px;
|
||||
padding: 6px 8px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 4px;
|
||||
background: #0d0d0d;
|
||||
color: var(--text);
|
||||
font-size: 12px;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.country-search::placeholder {
|
||||
color: rgba(255, 255, 255, 0.35);
|
||||
}
|
||||
|
||||
.country-search:focus {
|
||||
outline: none;
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.country-menu {
|
||||
max-height: 180px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
list-style: none;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.country-option {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
padding: 6px 8px;
|
||||
border-radius: 4px;
|
||||
font-size: 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.country-option:hover,
|
||||
.country-option.active {
|
||||
background: var(--bg-hover);
|
||||
}
|
||||
|
||||
.country-option .country-iso {
|
||||
flex-shrink: 0;
|
||||
width: 26px;
|
||||
font-weight: 700;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.country-option .country-dial {
|
||||
flex-shrink: 0;
|
||||
width: 38px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.country-name {
|
||||
min-width: 0;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.country-option:hover .country-name,
|
||||
.country-option.active .country-name {
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.country-empty {
|
||||
padding: 10px 8px;
|
||||
color: var(--text-muted);
|
||||
font-size: 11px;
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@@ -12,6 +12,8 @@ const validated = ref(false);
|
||||
const errorMsg = ref('');
|
||||
|
||||
const CHARS = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789';
|
||||
const CANVAS_W = 96;
|
||||
const CANVAS_H = 36;
|
||||
|
||||
function generateCode() {
|
||||
let result = '';
|
||||
@@ -24,40 +26,39 @@ function generateCode() {
|
||||
function drawCaptcha() {
|
||||
const canvas = canvasRef.value;
|
||||
if (!canvas) return;
|
||||
const w = 108, h = 44;
|
||||
canvas.width = w;
|
||||
canvas.height = h;
|
||||
canvas.width = CANVAS_W;
|
||||
canvas.height = CANVAS_H;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return;
|
||||
|
||||
ctx.fillStyle = '#2a2210';
|
||||
ctx.fillRect(0, 0, w, h);
|
||||
ctx.fillStyle = '#0d0d0d';
|
||||
ctx.fillRect(0, 0, CANVAS_W, CANVAS_H);
|
||||
|
||||
for (let i = 0; i < 28; i++) {
|
||||
ctx.fillStyle = `rgba(212, 175, 55, ${0.1 + Math.random() * 0.2})`;
|
||||
for (let i = 0; i < 20; i++) {
|
||||
ctx.fillStyle = `rgba(255, 255, 255, ${0.03 + Math.random() * 0.06})`;
|
||||
ctx.beginPath();
|
||||
ctx.arc(Math.random() * w, Math.random() * h, Math.random() * 2.2, 0, Math.PI * 2);
|
||||
ctx.arc(Math.random() * CANVAS_W, Math.random() * CANVAS_H, Math.random() * 1.8, 0, Math.PI * 2);
|
||||
ctx.fill();
|
||||
}
|
||||
|
||||
for (let i = 0; i < 5; i++) {
|
||||
ctx.strokeStyle = `rgba(212, 175, 55, ${0.15 + Math.random() * 0.25})`;
|
||||
for (let i = 0; i < 3; i++) {
|
||||
ctx.strokeStyle = `rgba(255, 255, 255, ${0.06 + Math.random() * 0.08})`;
|
||||
ctx.lineWidth = 1;
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(Math.random() * w, Math.random() * h);
|
||||
ctx.lineTo(Math.random() * w, Math.random() * h);
|
||||
ctx.moveTo(Math.random() * CANVAS_W, Math.random() * CANVAS_H);
|
||||
ctx.lineTo(Math.random() * CANVAS_W, Math.random() * CANVAS_H);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
const charWidth = w / (code.value.length + 1);
|
||||
const charWidth = CANVAS_W / (code.value.length + 1);
|
||||
for (let i = 0; i < code.value.length; i++) {
|
||||
ctx.save();
|
||||
const x = charWidth * (i + 0.5) + (Math.random() - 0.5) * 4;
|
||||
const y = h / 2 + (Math.random() - 0.5) * 6;
|
||||
const x = charWidth * (i + 0.5) + (Math.random() - 0.5) * 3;
|
||||
const y = CANVAS_H / 2 + (Math.random() - 0.5) * 4;
|
||||
ctx.translate(x, y);
|
||||
ctx.rotate((Math.random() - 0.5) * 0.4);
|
||||
ctx.font = `bold ${18 + Math.random() * 6}px 'Courier New', monospace`;
|
||||
ctx.fillStyle = `hsl(${40 + Math.random() * 20}, ${80 + Math.random() * 20}%, ${65 + Math.random() * 20}%)`;
|
||||
ctx.rotate((Math.random() - 0.5) * 0.35);
|
||||
ctx.font = `bold ${15 + Math.random() * 4}px 'Courier New', monospace`;
|
||||
ctx.fillStyle = `rgba(240, 216, 117, ${0.85 + Math.random() * 0.15})`;
|
||||
ctx.textAlign = 'center';
|
||||
ctx.textBaseline = 'middle';
|
||||
ctx.fillText(code.value[i], 0, 0);
|
||||
@@ -94,24 +95,58 @@ defineExpose({ validate, refresh });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="captcha-row">
|
||||
<input v-model="honeypot" type="text" name="website" tabindex="-1"
|
||||
autocomplete="off" class="hp-field" aria-hidden="true" />
|
||||
<input v-model="input" type="text" maxlength="4"
|
||||
class="captcha-input" :placeholder="t('auth.captcha_placeholder')" autocomplete="off" />
|
||||
<canvas ref="canvasRef" class="captcha-canvas"
|
||||
:title="t('auth.captcha_refresh')" role="button" tabindex="0"
|
||||
@click="refresh" @keydown.enter="refresh" />
|
||||
<div class="captcha-wrap">
|
||||
<div class="captcha-row">
|
||||
<input
|
||||
v-model="honeypot"
|
||||
type="text"
|
||||
name="website"
|
||||
tabindex="-1"
|
||||
autocomplete="off"
|
||||
class="hp-field"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
<input
|
||||
v-model="input"
|
||||
type="text"
|
||||
maxlength="4"
|
||||
class="captcha-input"
|
||||
:placeholder="t('auth.captcha_placeholder')"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<canvas
|
||||
ref="canvasRef"
|
||||
class="captcha-canvas"
|
||||
:width="CANVAS_W"
|
||||
:height="CANVAS_H"
|
||||
:title="t('auth.captcha_refresh')"
|
||||
role="button"
|
||||
tabindex="0"
|
||||
@click="refresh"
|
||||
@keydown.enter="refresh"
|
||||
/>
|
||||
</div>
|
||||
<p v-if="errorMsg" class="captcha-error">{{ errorMsg }}</p>
|
||||
</div>
|
||||
<p v-if="errorMsg" class="captcha-error">{{ errorMsg }}</p>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.captcha-wrap {
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.captcha-row {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
align-items: stretch;
|
||||
height: 44px;
|
||||
height: 36px;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 6px;
|
||||
background: #0d0d0d;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
.captcha-row:focus-within {
|
||||
border-color: #555;
|
||||
}
|
||||
|
||||
.hp-field {
|
||||
@@ -126,40 +161,33 @@ defineExpose({ validate, refresh });
|
||||
.captcha-input {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
padding: 0 14px;
|
||||
border: 1px solid var(--border);
|
||||
border-right: none;
|
||||
border-radius: 8px 0 0 8px;
|
||||
background: #1a1a1a;
|
||||
color: #fff;
|
||||
font-size: 15px;
|
||||
padding: 0 10px;
|
||||
border: none;
|
||||
background: transparent;
|
||||
color: var(--text);
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.15em;
|
||||
letter-spacing: 0.12em;
|
||||
text-transform: uppercase;
|
||||
outline: none;
|
||||
text-align: center;
|
||||
font-family: inherit;
|
||||
}
|
||||
|
||||
.captcha-input::placeholder {
|
||||
color: var(--text-muted);
|
||||
color: rgba(255, 255, 255, 0.32);
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.02em;
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
.captcha-input:focus {
|
||||
border-color: var(--primary-light);
|
||||
}
|
||||
|
||||
.captcha-canvas {
|
||||
flex-shrink: 0;
|
||||
width: 108px;
|
||||
height: 44px;
|
||||
width: 96px;
|
||||
height: 36px;
|
||||
cursor: pointer;
|
||||
display: block;
|
||||
border-radius: 0 8px 8px 0;
|
||||
border: 1px solid var(--border);
|
||||
border-left: none;
|
||||
border: none;
|
||||
border-left: 1px solid var(--border);
|
||||
}
|
||||
|
||||
.captcha-error {
|
||||
|
||||
Reference in New Issue
Block a user