fix(layout): IPv6按钮顶栏内正常排版不遮挡 + 窄屏收缩;relay/my-ip/用户菜单等本次改动入库
This commit is contained in:
1 parent
ea4e3deb50
commit
7b22e53d1a
8 files changed
+1050
-106
No files matched your search
+49
-67
@@ -7,76 +7,34 @@ import { useCloudSync } from '@/composable/cloud-sync';
|
||||
const { isLoggedIn, username, isAdmin, login, register, logout } = useUserAuth();
|
||||
const { syncNow } = useCloudSync();
|
||||
|
||||
// ---- Cloudflare Turnstile ----
|
||||
const CF_SITEKEY = '0x4AAAAAAFUO0U-CvL78Vr6y';
|
||||
const cfToken = ref('');
|
||||
const cfReady = ref(false);
|
||||
let cfWidgetId = '';
|
||||
// ---- 本地图片验证码(服务端出图,不依赖外网) ----
|
||||
const captchaId = ref('');
|
||||
const captchaImg = ref('');
|
||||
const captchaCode = ref('');
|
||||
|
||||
declare global {
|
||||
interface Window {
|
||||
turnstile?: any;
|
||||
__cfOnload?: () => void;
|
||||
}
|
||||
}
|
||||
|
||||
function loadTurnstileScript(): Promise<void> {
|
||||
if (window.turnstile) {
|
||||
return Promise.resolve();
|
||||
}
|
||||
return new Promise((resolve) => {
|
||||
window.__cfOnload = () => resolve();
|
||||
const s = document.createElement('script');
|
||||
s.src = 'https://challenges.cloudflare.com/turnstile/v0/api.js?onload=__cfOnload&render=explicit';
|
||||
s.async = true;
|
||||
document.head.appendChild(s);
|
||||
});
|
||||
}
|
||||
|
||||
function resetCf() {
|
||||
cfToken.value = '';
|
||||
if (window.turnstile && cfWidgetId) {
|
||||
try {
|
||||
window.turnstile.reset(cfWidgetId);
|
||||
async function loadCaptcha() {
|
||||
captchaCode.value = '';
|
||||
try {
|
||||
const res = await fetch('/relay/user/captcha');
|
||||
const body = await res.json().catch(() => ({} as any));
|
||||
if (body?.code === 200 && body.data?.id) {
|
||||
captchaId.value = body.data.id;
|
||||
captchaImg.value = `data:image/png;base64,${body.data.img}`;
|
||||
}
|
||||
catch { /* ignore */ }
|
||||
}
|
||||
}
|
||||
|
||||
async function mountCf() {
|
||||
await loadTurnstileScript();
|
||||
// wait until container is in DOM (modal just opened)
|
||||
await new Promise(r => setTimeout(r, 80));
|
||||
const el = document.querySelector('.cf-container');
|
||||
if (!el || cfWidgetId) {
|
||||
return;
|
||||
}
|
||||
cfWidgetId = window.turnstile.render(el as HTMLElement, {
|
||||
sitekey: CF_SITEKEY,
|
||||
theme: 'light',
|
||||
size: 'flexible',
|
||||
callback: (token: string) => {
|
||||
cfToken.value = token;
|
||||
},
|
||||
'expired-callback': () => {
|
||||
cfToken.value = '';
|
||||
},
|
||||
'error-callback': () => {
|
||||
cfToken.value = '';
|
||||
},
|
||||
});
|
||||
cfReady.value = true;
|
||||
catch { /* 静默:提交时服务端会再校验 */ }
|
||||
}
|
||||
|
||||
const showLogin = ref(false);
|
||||
|
||||
watch(showLogin, (v) => {
|
||||
if (v) {
|
||||
mountCf().catch(() => {});
|
||||
loadCaptcha().catch(() => {});
|
||||
}
|
||||
else {
|
||||
cfWidgetId = '';
|
||||
cfToken.value = '';
|
||||
captchaId.value = '';
|
||||
captchaImg.value = '';
|
||||
captchaCode.value = '';
|
||||
}
|
||||
});
|
||||
const mode = ref<'login' | 'register'>('login');
|
||||
@@ -105,10 +63,10 @@ async function submit() {
|
||||
busy.value = true;
|
||||
try {
|
||||
if (mode.value === 'login') {
|
||||
await login(formUser.value.trim(), formPass.value, cfToken.value);
|
||||
await login(formUser.value.trim(), formPass.value, captchaId.value, captchaCode.value.trim());
|
||||
}
|
||||
else {
|
||||
await register(formUser.value.trim(), formPass.value, cfToken.value);
|
||||
await register(formUser.value.trim(), formPass.value, captchaId.value, captchaCode.value.trim());
|
||||
}
|
||||
showLogin.value = false;
|
||||
formPass.value = '';
|
||||
@@ -119,7 +77,8 @@ async function submit() {
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = String(e?.message || e);
|
||||
resetCf();
|
||||
// 验证码单次有效,失败后必须换一张
|
||||
loadCaptcha().catch(() => {});
|
||||
}
|
||||
finally {
|
||||
busy.value = false;
|
||||
@@ -182,8 +141,10 @@ function switchMode() {
|
||||
<input v-model="formPass" class="user-input" type="password" placeholder="密码(至少 6 位)" :autocomplete="mode === 'login' ? 'current-password' : 'new-password'" @keyup.enter="submit">
|
||||
<input v-if="mode === 'register'" v-model="formPass2" class="user-input" type="password" placeholder="确认密码" autocomplete="new-password" @keyup.enter="submit">
|
||||
|
||||
<div class="cf-wrap" :style="{ opacity: cfToken ? 0.4 : 1 }">
|
||||
<div class="cf-container" />
|
||||
<div class="captcha-row">
|
||||
<input v-model="captchaCode" class="user-input captcha-input" placeholder="验证码(4位)" autocomplete="off" @keyup.enter="submit">
|
||||
<img v-if="captchaImg" class="captcha-img" :src="captchaImg" alt="验证码" title="点击换一张" @click="loadCaptcha">
|
||||
<a v-else href="javascript:;" class="captcha-reload" @click="loadCaptcha">获取验证码</a>
|
||||
</div>
|
||||
|
||||
<div v-if="error" class="user-error">
|
||||
@@ -198,7 +159,7 @@ function switchMode() {
|
||||
<c-button size="small" @click="showLogin = false">
|
||||
取消
|
||||
</c-button>
|
||||
<c-button size="small" type="primary" ml-8px :disabled="busy || !formUser || !formPass || !cfToken" @click="submit">
|
||||
<c-button size="small" type="primary" ml-8px :disabled="busy || !formUser || !formPass || !captchaCode.trim() || !captchaId" @click="submit">
|
||||
{{ busy ? '请稍候…' : (mode === 'login' ? '登录' : '注册并登录') }}
|
||||
</c-button>
|
||||
</div>
|
||||
@@ -263,9 +224,30 @@ function switchMode() {
|
||||
}
|
||||
}
|
||||
|
||||
.cf-wrap {
|
||||
.captcha-row {
|
||||
display: flex;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
margin: 2px 0 8px;
|
||||
transition: opacity 0.2s;
|
||||
|
||||
.captcha-input {
|
||||
flex: 1;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.captcha-img {
|
||||
height: 40px;
|
||||
border-radius: 4px;
|
||||
cursor: pointer;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.captcha-reload {
|
||||
flex-shrink: 0;
|
||||
font-size: 13px;
|
||||
color: #18a058;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.user-mask {
|
||||
|
||||
Reference in new issue
Block a user