front/src/views/login/index.vue
zzh 1d168d0943
All checks were successful
Build and Deploy Front / deploy (push) Successful in 3m45s
feat: 官网比例对齐、登录同壳切换与关怀条体验
统一飞机/标题矮屏缩放;登录互切免虹膜重挂;角色占位淡入;关怀条日出日落风格并加客户欢迎文案。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-12-03 16:09:52 +08:00

827 lines
21 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<template>
<div
:class="[
'login-container',
{
'login-container--customer': isCustomerLogin,
'login-container--light': isLightMode,
'login-container--exit': isExiting,
},
]"
ref="containerRef"
>
<div class="login-stage">
<div ref="leftSplitRef" class="login-split login-split--left" aria-hidden="true" />
<div ref="rightSplitRef" class="login-split login-split--right" aria-hidden="true" />
<LoginCareBanner
v-if="shellReady && careBannerReady && (isAdminLogin || isCustomerLogin)"
:audience="isCustomerLogin ? 'customer' : 'admin'"
/>
<div v-if="shellReady" ref="leftPaneRef" class="login-pane login-pane--left">
<aside v-if="isCustomerLogin" class="login-hero-panel">
<LoginHero
:light="isLightMode"
portal="customer"
/>
</aside>
<div v-if="isCustomerLogin" class="login-characters-panel">
<!-- 壳一出来就占位;勿限制面板高度,真角色布局盒仍是 550×400 -->
<div
class="login-characters-placeholder"
:class="{ 'is-gone': charactersReady }"
aria-hidden="true"
>
<span class="login-characters-placeholder__bar login-characters-placeholder__bar--purple" />
<span class="login-characters-placeholder__bar login-characters-placeholder__bar--black" />
<span class="login-characters-placeholder__bar login-characters-placeholder__bar--orange" />
<span class="login-characters-placeholder__bar login-characters-placeholder__bar--yellow" />
</div>
<LoginCharacters
v-if="showCharacters"
:appear="charactersReady"
@register="registerLoginCharacters"
/>
</div>
</div>
<aside
v-if="shellReady && !isCustomerLogin"
class="login-hero-panel login-hero-panel--admin"
>
<LoginHero
:light="isLightMode"
:portal="isAgentLogin ? 'agent' : 'admin'"
/>
</aside>
<div v-if="shellReady" ref="rightPaneRef" class="login-pane login-pane--right">
<div
ref="loginFormRef"
:class="[
'login-form',
{
'login-form--ready': shellReady,
'login-form--portal-row': isAdminLogin,
},
]"
>
<div class="login-form-toolbar">
<LoginLangToggle />
<a-tooltip :content="isLightMode ? t('login.theme.toNight') : t('login.theme.toDay')">
<a-button
shape="circle"
type="text"
class="theme-toggle-btn"
:aria-label="isLightMode ? t('login.theme.toNight') : t('login.theme.toDay')"
@click="toggleAppearance"
>
<template #icon>
<icon-sun-fill v-if="!isLightMode" />
<icon-moon-fill v-else />
</template>
</a-button>
</a-tooltip>
</div>
<div class="login-content">
<LoginForm
v-if="activeKey === 'pwd'"
:login-type="loginType"
@switch-wechat="setLoginMode('wechat')"
@prefetch-wechat="prefetchWechatQr"
/>
<WechatLogin
v-if="isCustomerLogin && (activeKey === 'wechat' || wechatMounted)"
v-show="activeKey === 'wechat'"
ref="wechatLoginRef"
@switch-pwd="setLoginMode('pwd')"
/>
</div>
<LoginPortalSwitch
v-if="loginType !== OmsLoginType.Agent"
:target="isCustomerLogin ? 'admin' : 'customer'"
:placement="isAdminLogin ? 'row' : 'corner'"
/>
</div>
</div>
</div>
</div>
</template>
<script lang="ts" setup>
import {
ref,
computed,
watch,
onMounted,
onBeforeUnmount,
provide,
shallowRef,
defineAsyncComponent,
} from 'vue';
import { useRoute } from 'vue-router';
import { useI18n } from 'vue-i18n';
import { OmsLoginType } from '@/api/rbac';
import { getLoginTypeFromRouteName } from '@/utils/login-portal';
import { IconSunFill, IconMoonFill } from '@arco-design/web-vue/es/icon';
import LoginForm from './components/pwd-login/index.vue';
import LoginHero from './components/LoginHero.vue';
import LoginLangToggle from './components/LoginLangToggle.vue';
import LoginPortalSwitch from './components/LoginPortalSwitch.vue';
import {
LOGIN_CHARACTERS_KEY,
type LoginCharactersApi,
} from './composables/useLoginCharacters';
import { LOGIN_EXIT_KEY, type LoginExitApi } from './composables/useLoginExit';
import { isPortalIrisActive } from '@/utils/page-transition-flag';
/** Admin login never mounts WeChat; keep it out of the critical path */
const WechatLogin = defineAsyncComponent(
() => import('./components/wechat-login.vue'),
);
/** Characters + gsap 异步;客户登录尽早预取,避免切换回来才开始拉包 */
const loadLoginCharacters = () => import('./components/LoginCharacters.vue');
const LoginCharacters = defineAsyncComponent(loadLoginCharacters);
const LoginCareBanner = defineAsyncComponent(
() => import('./components/LoginCareBanner.vue'),
);
const LOGIN_APPEARANCE_KEY = 'login-appearance';
const LOGIN_PAGE_SCROLL_LOCK_CLASS = 'login-page-no-scroll';
defineOptions({ name: 'Login' });
const { t } = useI18n();
const route = useRoute();
const loginType = computed(() => getLoginTypeFromRouteName(route.name as string));
const isCustomerLogin = computed(() => loginType.value === OmsLoginType.Customer);
const isAgentLogin = computed(() => loginType.value === OmsLoginType.Agent);
const isAdminLogin = computed(() => loginType.value === OmsLoginType.User);
/** 角色动画偏重:先占位,chunk 就绪后再挂真组件 */
const showCharacters = ref(false);
/** 真角色已 register,用于淡出剪影 */
const charactersReady = ref(false);
/** 管理端关怀条在翻页结束后再挂,避免展开过程中插入一块新图层 */
const careBannerReady = ref(!isPortalIrisActive());
/** 客户登录尽早预取角色包(setup 阶段,不等 onMounted) */
if (isCustomerLogin.value) {
void loadLoginCharacters();
}
const activeKey = ref<'pwd' | 'wechat'>('pwd');
const wechatMounted = ref(false);
const wechatLoginRef = ref<{ prefetch?: () => void } | null>(null);
/** 翻页进入时立刻出壳,避免过渡中空屏 */
const shellReady = ref(
route.query.from === 'official-site' ||
route.name === 'login' ||
route.name === 'adminLogin' ||
route.name === 'agentLogin',
);
const isExiting = ref(false);
const loginCharactersApi = shallowRef<LoginCharactersApi | null>(null);
const containerRef = ref<HTMLElement | null>(null);
const leftSplitRef = ref<HTMLElement | null>(null);
const rightSplitRef = ref<HTMLElement | null>(null);
const leftPaneRef = ref<HTMLElement | null>(null);
const rightPaneRef = ref<HTMLElement | null>(null);
const loginFormRef = ref<HTMLElement | null>(null);
function collectExitTargets(side: 'left' | 'right'): HTMLElement[] {
if (side === 'left') {
return [leftSplitRef.value, leftPaneRef.value].filter((el): el is HTMLElement => !!el);
}
return [rightSplitRef.value, rightPaneRef.value].filter((el): el is HTMLElement => !!el);
}
provide(LOGIN_EXIT_KEY, {
playExitAnimation(): Promise<void> {
if (isExiting.value) {
return Promise.resolve();
}
// Flips login-container--exit: hides admin overlays outside pane clip-paths
isExiting.value = true;
const leftTargets = collectExitTargets('left');
const rightTargets = collectExitTargets('right');
const formEl = loginFormRef.value;
return new Promise((resolve) => {
if (!leftTargets.length && !rightTargets.length) {
resolve();
return;
}
void import('gsap').then(({ default: gsap }) => {
gsap.set([...leftTargets, ...rightTargets], {
x: 0,
opacity: 1,
force3D: true,
});
const tl = gsap.timeline({
defaults: { ease: 'power2.inOut' },
onComplete: resolve,
});
if (formEl) {
tl.to(
formEl,
{
opacity: 0,
duration: 0.22,
ease: 'power1.out',
},
0,
);
}
tl.to(
leftTargets,
{
x: '-100%',
opacity: 0.96,
duration: 0.32,
ease: 'power3.inOut',
},
0.02,
);
tl.to(
rightTargets,
{
x: '100%',
opacity: 0.96,
duration: 0.32,
ease: 'power3.inOut',
},
0.04,
);
if (containerRef.value) {
const pageBg =
getComputedStyle(document.documentElement).getPropertyValue('--app-page-bg').trim() ||
'#f0f3f4';
tl.to(
containerRef.value,
{
backgroundColor: pageBg,
duration: 0.28,
ease: 'power1.inOut',
},
0.02,
);
}
});
});
},
} satisfies LoginExitApi);
provide(LOGIN_CHARACTERS_KEY, loginCharactersApi);
function registerLoginCharacters(api: LoginCharactersApi) {
loginCharactersApi.value = api;
// 下一帧再标 ready,保证首屏 paint 后再淡入
requestAnimationFrame(() => {
charactersReady.value = true;
});
}
function mountLoginCharactersSoon() {
if (!isCustomerLogin.value || showCharacters.value) return;
void loadLoginCharacters()
.catch(() => undefined)
.finally(() => {
afterPortalIris(() => {
// 包已在内存时立刻挂;略延一帧让占位先 paint
requestAnimationFrame(() => {
showCharacters.value = true;
});
});
});
}
function readStoredAppearance(): boolean {
try {
return localStorage.getItem(LOGIN_APPEARANCE_KEY) === 'light';
} catch {
return false;
}
}
const isLightMode = ref(readStoredAppearance());
function toggleAppearance() {
isLightMode.value = !isLightMode.value;
try {
localStorage.setItem(LOGIN_APPEARANCE_KEY, isLightMode.value ? 'light' : 'dark');
} catch {
/* ignore */
}
}
function setLoginMode(mode: 'pwd' | 'wechat') {
if (mode === 'wechat' && !isCustomerLogin.value) return;
if (mode === 'wechat') {
wechatMounted.value = true;
}
activeKey.value = mode;
}
function prefetchWechatQr() {
if (!isCustomerLogin.value) return;
wechatMounted.value = true;
// 下一帧组件已挂载后再触发预取(若已在加载则内部会跳过)
requestAnimationFrame(() => {
wechatLoginRef.value?.prefetch?.();
});
}
/** 翻页进行中主线程要让给裁剪动画,装饰内容等动画结束后再挂 */
function afterPortalIris(run: () => void) {
if (!isPortalIrisActive()) {
run();
return;
}
const started = performance.now();
const wait = () => {
if (!isPortalIrisActive() || performance.now() - started > 1800) {
run();
return;
}
window.setTimeout(wait, 80);
};
window.setTimeout(wait, 80);
}
/** 同壳互切时按门户类型装卸装饰,避免整页 remount */
watch(isCustomerLogin, (customer) => {
if (customer) {
charactersReady.value = false;
showCharacters.value = false;
loginCharactersApi.value = null;
mountLoginCharactersSoon();
return;
}
showCharacters.value = false;
charactersReady.value = false;
loginCharactersApi.value = null;
});
watch([isAdminLogin, isCustomerLogin], ([admin, customer]) => {
if (admin || customer) {
careBannerReady.value = true;
}
});
onMounted(() => {
document.documentElement.classList.add(LOGIN_PAGE_SCROLL_LOCK_CLASS);
shellReady.value = true;
mountLoginCharactersSoon();
const idle = window.requestIdleCallback
? (cb: () => void, timeout = 1200) => window.requestIdleCallback(cb, { timeout })
: (cb: () => void, timeout = 1200) => window.setTimeout(cb, Math.min(timeout, 400));
afterPortalIris(() => {
if (isAdminLogin.value || isCustomerLogin.value) {
careBannerReady.value = true;
}
idle(() => {
void import('@/locale').then(({ ensureFullLocaleMessages }) => {
void ensureFullLocaleMessages();
});
}, 2500);
});
});
onBeforeUnmount(() => {
document.documentElement.classList.remove(LOGIN_PAGE_SCROLL_LOCK_CLASS);
});
</script>
<style lang="less" scoped>
.login-container {
/* 斜线:顶 62% → 底 38%,右侧为上窄下宽的倒梯形 */
--login-split-top: 62%;
--login-split-bottom: 38%;
--login-left-bg: #142637;
--login-right-bg: var(--app-page-bg, #f0f3f4);
box-sizing: border-box;
/* 官网 body 行高 1.55 会留到翻页结束。钉成页面默认 1.15,避免卸样式时登录卡缩短下移 */
font-size: 14px;
line-height: 1.15;
height: 100dvh;
max-height: 100dvh;
min-height: 100dvh;
position: relative;
display: flex;
align-items: center;
justify-content: center;
padding: max(24px, 4vh) max(24px, 3vw);
overflow: hidden;
overscroll-behavior: none;
background: #e6ebf0;
}
.login-container--light {
--login-left-bg: #e8eef5;
--login-right-bg: var(--app-page-bg, #f0f3f4);
background: #eef1f4;
}
/* 登录主舞台:约 80% 视口,不铺满全屏 */
.login-stage {
position: relative;
width: min(80vw, 1360px);
height: min(80dvh, 920px);
max-width: 100%;
max-height: 100%;
overflow: hidden;
border-radius: 20px;
background: var(--login-right-bg);
box-shadow:
0 1px 2px rgba(15, 23, 42, 0.04),
0 24px 64px rgba(15, 23, 42, 0.12);
}
.login-container--exit {
pointer-events: none;
/* Safety net: admin overlays are outside pane clip-paths */
.login-hero-panel--admin,
:deep(.login-care-banner) {
opacity: 0 !important;
visibility: hidden !important;
pointer-events: none;
}
}
.login-split {
position: absolute;
inset: 0;
z-index: 0;
will-change: transform;
}
/* 左:正梯形(上宽下窄) */
.login-split--left {
background: var(--login-left-bg);
clip-path: polygon(0 0, var(--login-split-top) 0, var(--login-split-bottom) 100%, 0 100%);
}
/* 右:倒梯形(上窄下宽) */
.login-split--right {
background: var(--login-right-bg);
clip-path: polygon(
var(--login-split-top) 0,
100% 0,
100% 100%,
var(--login-split-bottom) 100%
);
}
.login-pane {
position: absolute;
inset: 0;
z-index: 2;
will-change: transform;
}
.login-pane--left {
clip-path: polygon(0 0, var(--login-split-top) 0, var(--login-split-bottom) 100%, 0 100%);
pointer-events: none;
}
.login-brand-corner {
position: absolute;
top: 28px;
left: 32px;
z-index: 8;
display: flex;
align-items: baseline;
gap: 0.35em;
line-height: 1;
color: #fff;
pointer-events: none;
}
.login-brand-corner__name {
font-size: clamp(1.6rem, 2.4vw, 2.25rem);
font-weight: 800;
letter-spacing: 0.12em;
}
.login-brand-corner__suffix {
font-size: clamp(0.95rem, 1.55vw, 1.375rem);
font-weight: 600;
letter-spacing: 0.04em;
opacity: 0.88;
}
.login-brand-corner--light {
color: #1a2d4a;
}
.login-pane--right {
clip-path: polygon(
var(--login-split-top) 0,
100% 0,
100% 100%,
var(--login-split-bottom) 100%
);
pointer-events: none;
}
.login-pane--right .login-form {
position: absolute;
top: 50%;
left: calc((var(--login-split-top) + var(--login-split-bottom) + 100% + 100%) / 4);
transform: translate(-50%, calc(-50% + 16px));
pointer-events: auto;
}
.login-pane--right .login-form--ready {
transform: translate(-50%, -50%);
}
.login-hero-panel {
position: absolute;
top: 50%;
left: calc((var(--login-split-top) + var(--login-split-bottom)) / 4);
transform: translate(-50%, -50%);
width: min(920px, calc((var(--login-split-top) + var(--login-split-bottom)) / 2 - 24px));
max-width: calc(100% - 32px);
pointer-events: auto;
}
/* 客户左区铺满斜切内,给角色留底;氛围层填空、文案居中偏上 */
.login-container--customer .login-hero-panel {
top: 0;
left: 0;
bottom: 0;
transform: none;
width: calc((var(--login-split-top) + var(--login-split-bottom)) / 2);
max-width: none;
padding: 48px 24px 120px 40px;
display: flex;
align-items: center;
}
.login-characters-panel {
position: absolute;
left: 0;
bottom: 0;
right: auto;
z-index: 6;
pointer-events: auto;
padding: 0 0 16px 8px;
overflow: visible;
}
/* 视觉尺寸约 198×144,叠在真角色同位置;面板本身不能锁死高度 */
.login-characters-placeholder {
position: absolute;
left: 8px;
bottom: 16px;
z-index: 1;
width: 198px;
height: 144px;
pointer-events: none;
opacity: 1;
transition: opacity 0.35s ease;
filter: saturate(0.92);
&.is-gone {
opacity: 0;
visibility: hidden;
}
}
.login-characters-placeholder__bar {
position: absolute;
bottom: 0;
border-radius: 4px 4px 0 0;
transform-origin: bottom center;
animation: login-chars-ph-breathe 1.6s ease-in-out infinite;
&--purple {
left: 25px;
width: 65px;
height: 144px;
background: #2fa084;
animation-delay: 0s;
}
&--black {
left: 86px;
width: 43px;
height: 112px;
background: #6fcf97;
animation-delay: 0.12s;
}
&--orange {
left: 0;
width: 61px;
height: 79px;
background: #1f6f5f;
z-index: 2;
animation-delay: 0.24s;
}
&--yellow {
left: 112px;
width: 72px;
height: 72px;
border-radius: 50%;
background: #eeeeee;
bottom: 0;
z-index: 3;
animation-delay: 0.36s;
}
}
@keyframes login-chars-ph-breathe {
0%,
100% {
opacity: 0.55;
transform: scaleY(0.98);
}
50% {
opacity: 0.85;
transform: scaleY(1);
}
}
.login-hero-panel--admin {
inset: 0;
top: 0;
left: 0;
bottom: 0;
right: 0;
transform: none;
z-index: 3;
display: block;
width: auto;
max-width: none;
pointer-events: none;
}
.login-hero-panel--admin .login-hero {
width: 100%;
height: 100%;
}
.login-form-toolbar {
position: absolute;
top: 14px;
right: 14px;
z-index: 2;
display: flex;
align-items: center;
gap: 4px;
}
.login-form-toolbar :deep(.theme-toggle-btn.arco-btn),
.login-form-toolbar :deep(.login-lang-toggle) {
width: 32px;
height: 32px;
flex-shrink: 0;
border: none !important;
box-shadow: none !important;
background: transparent !important;
color: #86868b !important;
}
.login-form-toolbar :deep(.theme-toggle-btn.arco-btn:hover),
.login-form-toolbar :deep(.login-lang-toggle:hover) {
border: none !important;
box-shadow: none !important;
background: rgba(0, 0, 0, 0.04) !important;
color: #1d1d1f !important;
}
.login-form {
/* Apple 登录卡:白底 + 细边 + 轻外阴影 */
--login-card-bg: #ffffff;
--login-card-shadow: 0 2px 8px rgba(0, 0, 0, 0.04), 0 16px 32px rgba(0, 0, 0, 0.06);
position: relative;
z-index: 10;
width: 100%;
max-width: 380px;
min-height: auto;
padding: 36px 30px 28px;
&.login-form--portal-row {
padding-bottom: 12px;
}
background: var(--login-card-bg);
border: 1px solid #e8e8ed;
outline: none;
border-radius: 16px;
box-shadow: var(--login-card-shadow);
display: flex;
flex-direction: column;
transition: box-shadow 0.2s ease, background 0.2s ease;
}
.login-content {
flex: 1;
min-height: 0;
display: flex;
flex-direction: column;
}
.login-form :deep(.account-entry-btn) {
background: #fff;
border: 1px solid #d2d2d7;
backdrop-filter: none;
-webkit-backdrop-filter: none;
box-shadow: none;
}
.login-form :deep(.account-entry-btn:hover) {
background: #f5f5f7;
border-color: #c7c7cc;
}
@media screen and (max-width: 1024px) {
.login-characters-panel {
display: none;
}
}
@media screen and (max-width: 1250px) {
.login-container {
--login-split-top: 0%;
--login-split-bottom: 0%;
padding: 16px;
}
.login-stage {
width: min(92vw, 520px);
height: auto;
min-height: min(78dvh, 720px);
border-radius: 16px;
}
.login-split--left,
.login-pane--left {
display: none;
}
.login-pane--right .login-form {
position: relative;
top: auto;
left: auto;
transform: none;
margin: auto;
}
.login-pane--right .login-form--ready {
transform: none;
}
.login-split--right,
.login-pane--right {
clip-path: none;
display: flex;
align-items: center;
justify-content: center;
padding: 16px;
}
}
@media screen and (max-width: 600px) {
.login-container {
padding: 12px;
}
.login-stage {
width: 100%;
min-height: min(86dvh, 680px);
border-radius: 14px;
}
.login-form {
max-width: 97% !important;
padding: 30px 20px 40px;
border-radius: 14px;
}
}
</style>
<style lang="less">
html.login-page-no-scroll,
html.login-page-no-scroll body {
overflow: hidden !important;
height: 100% !important;
margin: 0;
}
html.login-page-no-scroll #app {
height: 100%;
overflow: hidden;
}
</style>