From 8afaccb9619d058cc90f974d966e8f884a9113d6 Mon Sep 17 00:00:00 2001
From: xiaoyi <908147524@qq.com>
Date: 星期三, 28 十月 2026 17:44:05 +0800
Subject: [PATCH] feat(chdl): 长辉品牌登录页 + 数采监控页面 + 接口地址切到长辉环境
---
src/views/_core/authentication/login.vue | 342 +++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 250 insertions(+), 92 deletions(-)
diff --git a/src/views/_core/authentication/login.vue b/src/views/_core/authentication/login.vue
index 0a7547b..acd4e37 100644
--- a/src/views/_core/authentication/login.vue
+++ b/src/views/_core/authentication/login.vue
@@ -1,104 +1,41 @@
<script lang="ts" setup>
import type { VbenFormSchema } from '@vben/common-ui';
-import type { AuthApi } from '#/api/core/auth';
+import { computed, onMounted, reactive, ref } from 'vue';
-import { computed, onMounted, ref } from 'vue';
-
-import { AuthenticationLogin, Verification, z } from '@vben/common-ui';
-import { isCaptchaEnable, isTenantEnable } from '@vben/hooks';
+import { useVbenForm, Verification, VbenCheckbox, z } from '@vben/common-ui';
+import { isCaptchaEnable } from '@vben/hooks';
+import { IconifyIcon } from '@vben/icons';
import { $t } from '@vben/locales';
-import { useAccessStore } from '@vben/stores';
-import {
- checkCaptcha,
- getCaptcha,
- getTenantByWebsite,
- getTenantSimpleList,
-} from '#/api/core/auth';
+import { checkCaptcha, getCaptcha } from '#/api/core/auth';
import { useAuthStore } from '#/store';
defineOptions({ name: 'Login' });
const authStore = useAuthStore();
-const accessStore = useAccessStore();
-const tenantEnable = isTenantEnable();
const captchaEnable = isCaptchaEnable();
-const loginRef = ref();
const verifyRef = ref();
-
const captchaType = 'blockPuzzle'; // 楠岃瘉鐮佺被鍨嬶細'blockPuzzle' | 'clickWord'
-/** 鑾峰彇绉熸埛鍒楄〃 */
-const tenantList = ref<AuthApi.TenantResult[]>([]); // 绉熸埛鍒楄〃
-async function fetchTenantList() {
- if (!tenantEnable) {
- return;
- }
- try {
- // 鑾峰彇绉熸埛鍒楄〃
- tenantList.value = await getTenantSimpleList();
- } catch (error) {
- console.error('鑾峰彇绉熸埛鍒楄〃澶辫触:', error);
- }
-}
+/** 璁颁綇璐﹀彿锛氭部鐢ㄥ師鏈� key锛屼繚璇佽�佺敤鎴峰凡璁颁綇鐨勮处鍙蜂笉涓㈠け */
+const REMEMBER_ME_KEY = `REMEMBER_ME_USERNAME_${location.hostname}`;
+const rememberedUsername = localStorage.getItem(REMEMBER_ME_KEY) || '';
+const rememberMe = ref(Boolean(rememberedUsername));
-/** 澶勭悊鐧诲綍 */
-async function handleLogin(values: any) {
- // 濡傛灉寮�鍚獙璇佺爜锛屽垯鍏堥獙璇侀獙璇佺爜
- if (captchaEnable) {
- verifyRef.value.show();
- return;
- }
- // 鏃犻獙璇佺爜锛岀洿鎺ョ櫥褰�
- await authStore.authLogin('username', values);
-}
-
-/** 楠岃瘉鐮侀�氳繃锛屾墽琛岀櫥褰� */
-async function handleVerifySuccess({ captchaVerification }: any) {
- try {
- await authStore.authLogin('username', {
- ...(await loginRef.value.getFormApi().getValues()),
- captchaVerification,
- });
- } catch (error) {
- console.error('Error in handleLogin:', error);
- }
-}
-
-/** 缁勪欢鎸傝浇鏃惰幏鍙栫鎴蜂俊鎭� */
-onMounted(() => {
- fetchTenantList();
-});
+/** 绛夊緟楠岃瘉鐮侀�氳繃鍚庡啀鎻愪氦鐨勮〃鍗曞�� */
+const pendingValues = ref<Record<string, any>>({});
const formSchema = computed((): VbenFormSchema[] => {
return [
- // {
- // component: 'VbenSelect',
- // componentProps: {
- // options: tenantList.value.map((item) => ({
- // label: item.name,
- // value: item.id.toString(),
- // })),
- // placeholder: $t('authentication.tenantTip'),
- // },
- // fieldName: 'tenantId',
- // label: $t('authentication.tenant'),
- // dependencies: {
- // triggerFields: ['tenantId'],
- // if: tenantEnable,
- // trigger(values) {
- // accessStore.setTenantId(values.tenantId ? Number(values.tenantId) : null);
- // },
- // },
- // },
{
component: 'VbenInput',
componentProps: {
- placeholder: $t('authentication.usernameTip'),
- autocomplete: 'username',
'aria-label': $t('authentication.username'),
+ autocomplete: 'username',
+ class: 'login-field',
+ placeholder: $t('authentication.usernameTip'),
},
fieldName: 'username',
label: $t('authentication.username'),
@@ -110,9 +47,10 @@
{
component: 'VbenInputPassword',
componentProps: {
- placeholder: $t('authentication.passwordTip'),
- autocomplete: 'current-password',
'aria-label': $t('authentication.password'),
+ autocomplete: 'current-password',
+ class: 'login-field',
+ placeholder: $t('authentication.passwordTip'),
},
fieldName: 'password',
label: $t('authentication.password'),
@@ -123,22 +61,100 @@
},
];
});
+
+const [Form, formApi] = useVbenForm(
+ reactive({
+ commonConfig: {
+ hideLabel: false,
+ hideRequiredMark: true,
+ },
+ layout: 'vertical' as const,
+ schema: formSchema,
+ showDefaultActions: false,
+ }),
+);
+
+/** 璋冪敤鐧诲綍鎺ュ彛 */
+async function submitLogin(values: Record<string, any>) {
+ try {
+ await authStore.authLogin('username', values);
+ } catch (error) {
+ // 閿欒鎻愮ず鐢辫姹傛嫤鎴櫒缁熶竴寮瑰嚭锛岃繖閲屼粎閬垮厤鏈崟鑾风殑 Promise 鎷掔粷
+ console.error('鐧诲綍澶辫触:', error);
+ }
+}
+
+/** 鎻愪氦锛氭牎楠� -> 璁颁綇璐﹀彿 -> 楠岃瘉鐮� -> 鐧诲綍 */
+async function handleSubmit() {
+ if (authStore.loginLoading) {
+ return;
+ }
+ const { valid } = await formApi.validate();
+ if (!valid) {
+ return;
+ }
+ const values = await formApi.getValues();
+ localStorage.setItem(
+ REMEMBER_ME_KEY,
+ rememberMe.value ? String(values.username ?? '') : '',
+ );
+
+ if (captchaEnable) {
+ pendingValues.value = values;
+ verifyRef.value.show();
+ return;
+ }
+ await submitLogin(values);
+}
+
+/** 楠岃瘉鐮侀�氳繃锛屾墽琛岀櫥褰� */
+async function handleVerifySuccess({ captchaVerification }: any) {
+ await submitLogin({ ...pendingValues.value, captchaVerification });
+}
+
+onMounted(() => {
+ if (rememberedUsername) {
+ formApi.setFieldValue('username', rememberedUsername);
+ }
+});
</script>
<template>
- <div>
- <AuthenticationLogin
- ref="loginRef"
- :form-schema="formSchema"
- :loading="authStore.loginLoading"
- :show-code-login="false"
- :show-qrcode-login="false"
- :show-third-party-login="false"
- :show-register="false"
- :show-forget-password="false"
- :show-doc-link="false"
- @submit="handleLogin"
- />
+ <div class="login">
+ <header class="login__head">
+ <h2 class="login__title">{{ $t('authentication.welcomeBack') }}</h2>
+ <p class="login__desc">{{ $t('authentication.loginSubtitle') }}</p>
+ </header>
+
+ <Form @keydown.enter.prevent="handleSubmit" />
+
+ <div class="login__row">
+ <VbenCheckbox v-model="rememberMe" name="rememberMe">
+ {{ $t('authentication.rememberMe') }}
+ </VbenCheckbox>
+ </div>
+
+ <button
+ :disabled="authStore.loginLoading"
+ class="login__submit"
+ type="button"
+ @click="handleSubmit"
+ >
+ <span class="login__submit-text">
+ {{
+ authStore.loginLoading
+ ? $t('authentication.loginSubmitting')
+ : $t('authentication.loginSubmit')
+ }}
+ </span>
+ <span class="login__submit-icon" aria-hidden="true">
+ <IconifyIcon
+ :class="{ 'animate-pulse': authStore.loginLoading }"
+ icon="lucide:arrow-right"
+ />
+ </span>
+ </button>
+
<Verification
ref="verifyRef"
v-if="captchaEnable"
@@ -151,3 +167,145 @@
/>
</div>
</template>
+
+<style scoped>
+.login {
+ --login-control-height: 2.75rem;
+}
+
+/* ---------- 鏍囬 ---------- */
+.login__head {
+ margin-bottom: 1.5rem;
+}
+
+.login__title {
+ margin: 0;
+ font-size: 1.5rem;
+ font-weight: 700;
+ line-height: 1.3;
+ letter-spacing: -0.01em;
+ color: hsl(var(--foreground));
+}
+
+.login__desc {
+ margin: 0.5rem 0 0;
+ font-size: 0.875rem;
+ line-height: 1.6;
+ color: hsl(var(--muted-foreground));
+}
+
+/* ---------- 瀛楁 ---------- */
+.login :deep(label) {
+ margin-bottom: 0.375rem;
+ font-size: 0.75rem;
+ font-weight: 600;
+ letter-spacing: 0.08em;
+ color: hsl(var(--muted-foreground));
+}
+
+.login :deep(.login-field) {
+ height: var(--login-control-height);
+ border-radius: 0.625rem;
+ border-color: hsl(var(--border));
+ background: hsl(var(--muted) / 0.55);
+ font-size: 0.9375rem;
+ transition:
+ background 0.24s cubic-bezier(0.32, 0.72, 0, 1),
+ box-shadow 0.24s cubic-bezier(0.32, 0.72, 0, 1);
+}
+
+.login :deep(.login-field:focus-visible) {
+ background: hsl(var(--background));
+ box-shadow: inset 0 0 0 1px hsl(var(--primary));
+}
+
+/* placeholder 鍔犳繁锛屼繚璇佸湪娴呯伆搴曚笂浠嶅彲杈ㄨ瘑锛圓A锛� */
+.login :deep(.login-field::placeholder) {
+ color: hsl(var(--muted-foreground));
+ opacity: 1;
+}
+
+/* 瀵嗙爜鍙鎬ф寜閽笌杈撳叆妗嗗榻� */
+.login :deep(.login-field ~ button) {
+ padding-right: 0.75rem;
+}
+
+/* ---------- 璁颁綇璐﹀彿 ---------- */
+.login__row {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ margin: 0.25rem 0 1.25rem;
+ font-size: 0.875rem;
+}
+
+/* ---------- 鎻愪氦鎸夐挳 ---------- */
+.login__submit {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ gap: 0.625rem;
+ width: 100%;
+ height: var(--login-control-height);
+ border: none;
+ border-radius: 0.625rem;
+ background: hsl(var(--primary));
+ color: hsl(var(--primary-foreground));
+ font-size: 0.9375rem;
+ font-weight: 600;
+ letter-spacing: 0.04em;
+ cursor: pointer;
+ box-shadow:
+ inset 0 1px 0 rgb(255 255 255 / 0.18),
+ 0 10px 24px -16px hsl(var(--primary) / 0.95);
+ transition:
+ transform 0.18s cubic-bezier(0.32, 0.72, 0, 1),
+ background 0.18s ease;
+}
+
+.login__submit:hover:not(:disabled) {
+ background: hsl(var(--primary) / 0.92);
+}
+
+.login__submit:focus-visible {
+ outline: 2px solid hsl(var(--ring));
+ outline-offset: 2px;
+}
+
+.login__submit:active:not(:disabled) {
+ transform: scale(0.985);
+}
+
+.login__submit:disabled {
+ cursor: not-allowed;
+ opacity: 0.72;
+}
+
+.login__submit-text {
+ line-height: 1;
+}
+
+.login__submit-icon {
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ width: 1.5rem;
+ height: 1.5rem;
+ border-radius: 9999px;
+ background: rgb(255 255 255 / 0.16);
+ font-size: 0.875rem;
+ transition: transform 0.18s cubic-bezier(0.32, 0.72, 0, 1);
+}
+
+.login__submit:hover:not(:disabled) .login__submit-icon {
+ transform: translateX(2px);
+}
+
+@media (prefers-reduced-motion: reduce) {
+ .login :deep(.login-field),
+ .login__submit,
+ .login__submit-icon {
+ transition: none;
+ }
+}
+</style>
--
Gitblit v1.9.3