add vConsole trigger for login index

This commit is contained in:
Timi
2026-11-05 16:51:01 +08:00
parent 59af9763a9
commit a204dd3211
3 changed files with 39 additions and 26 deletions
+2 -24
View File
@@ -48,7 +48,7 @@ import { SettingAPI } from "timi-web-api";
import Logo from "@/pages/user/component/Logo.vue";
import { getErrorMessage } from "@/utils/error";
import { Message } from "@/utils/message";
import { toggleVConsole } from "@/utils/vConsole";
import { createVConsoleClickHandler, toggleVConsole } from "@/utils/vConsole";
type AgreementItem = {
icon: string;
@@ -67,29 +67,7 @@ const router = useRouter();
const agreementItemList = ref<AgreementItem[]>([]);
const isLoading = ref(false);
let debugClickCount = 0;
let debugClickTimer: number | undefined;
async function handleLogoClick(): Promise<void> {
debugClickCount++;
if (debugClickTimer !== undefined) {
window.clearTimeout(debugClickTimer);
}
debugClickTimer = window.setTimeout(() => {
debugClickCount = 0;
debugClickTimer = undefined;
}, 1_500);
if (debugClickCount < 5) {
return;
}
debugClickCount = 0;
window.clearTimeout(debugClickTimer);
debugClickTimer = undefined;
await toggleVConsole();
}
const handleLogoClick = createVConsoleClickHandler(toggleVConsole);
async function openAgreement(item: AgreementItem): Promise<void> {
await router.push({
+6 -1
View File
@@ -2,7 +2,7 @@
<div class="login-page diselect">
<section class="login-panel">
<div class="brand">
<logo v-entrance-transition />
<logo v-entrance-transition @click="handleLogoClick" />
<h1 v-entrance-transition>糕店客户管理</h1>
</div>
<t-segmented
@@ -23,6 +23,7 @@ import PasswordLogin from "@/pages/user/component/PasswordLogin.vue";
import SmsLogin from "@/pages/user/component/SmsLogin.vue";
import Logo from "@/pages/user/component/Logo.vue";
import UserAgreement from "@/pages/user/component/UserAgreement.vue";
import { createVConsoleClickHandler, enableVConsole } from "@/utils/vConsole";
defineOptions({
name: "LoginIndex"
@@ -36,6 +37,10 @@ const loginTypeOptions = [
{ value: "password" as LoginType, label: "密码登录" },
{ value: "sms" as LoginType, label: "短信登录" }
];
// ---------- 调试控制台 ----------
const handleLogoClick = createVConsoleClickHandler(enableVConsole);
</script>
<style scoped lang="less">
+31 -1
View File
@@ -13,7 +13,14 @@ export async function toggleVConsole(): Promise<void> {
console.warn("[调试] vConsole 已关闭");
return;
}
if (isVConsoleLoading) {
await enableVConsole();
}
/**
* 启用移动端调试控制台。
*/
export async function enableVConsole(): Promise<void> {
if (vConsoleInstance || isVConsoleLoading) {
return;
}
@@ -28,3 +35,26 @@ export async function toggleVConsole(): Promise<void> {
isVConsoleLoading = false;
}
}
/**
* 创建连续点击五次后执行的处理函数。
*/
export function createVConsoleClickHandler(action: () => Promise<void>): () => Promise<void> {
let clickCount = 0;
let lastClickTime = 0;
return async () => {
const now = Date.now();
if (1_500 < now - lastClickTime) {
clickCount = 0;
}
lastClickTime = now;
clickCount++;
if (clickCount < 5) {
return;
}
clickCount = 0;
await action();
};
}