import { afterRenderEffect, ChangeDetectionStrategy, Component, computed, ElementRef, inject } from '@angular/core'; import { Router } from '@angular/router'; import { NgTemplateOutlet } from '@angular/common'; import { UiAlert, UiButton, UiInput } from '../../ui'; import { LoginFlowService } from '../../core/login-flow.service'; import { LoginAssistance } from '../../components/domain/login-assistance/login-assistance'; import { LoginFieldDirective } from '../../components/domain/login-assistance/login-field.directive'; import { DeviceService } from '../../core/device.service'; import { PaletteService } from '../../core/palette.service'; type LoginMethod = 'password' | 'mobile' | 'token'; /** * 登录页(SPEC FR-02)—— 两端共用同一组件,形态随端自适应 * * 结构参照**第一版项目**(用户 2026-10-15 反馈:当前样式不符合之前版本): * · 桌面:左侧品牌落地页(品牌 + 标语 + 价值卡 + 统计) + 右侧登录卡 * · 移动:顶部品牌区 + 登录卡 * · 校验:Token 形如 `r:` 开头 * * 实现纪律:底座组件(`ui-input`/`ui-button`/`ui-alert`)+ 令牌控制样式。 * * AC:02.1 两种登录方式 / 02.2 `#token=` 自动登录后清地址栏 / 02.3 回跳 redirect * / 02.6 明确错误文案 / 02.7 防抖不并发 */ @Component({ selector: 'app-login', changeDetection: ChangeDetectionStrategy.OnPush, imports: [NgTemplateOutlet, UiAlert, UiButton, UiInput, LoginAssistance, LoginFieldDirective], providers: [LoginFlowService], template: ` @if (isMobile()) {
飞马SI 数字生命消息中枢
安全登录

人机共生 · IM 中枢

继续处理你的
会话与交付

登录后查看数字生命状态、任务进度和最新成果。

工作状态实时同步,成果可追溯

} @else {
飞马SI
数字生命消息中枢
人机共生 · IM 中枢

让每个数字生命
随时在线,随时交付

飞马SI 把人、数字生命与成果收敛到同一条消息流里 —— 你发一句话,它在后台自主执行,状态、过程与交付物实时回流。

@for (v of values; track v.title) {
{{ v.title }}
{{ v.desc }}
}
@for (s of stats; track s.label) {
{{ s.value }} {{ s.label }}
}
人机共生 · 成果可追溯
安全登录 飞马SI · Fmode
}

进入工作空间

{{ method() === 'mobile' ? '欢迎回来' : method() === 'password' ? '账号密码登录' : 'Token 登录' }}

{{ method() === 'mobile' ? '用手机号验证码继续你的工作' : method() === 'password' ? '使用已有账号和密码继续' : '粘贴以 r: 开头的登录 Token' }}

@if (method() === 'password') { } @if (method() === 'mobile') { } @else if (method() === 'token') { } @if (error(); as message) {
} @if (flow.notice()) {

{{ flow.notice() }}

} {{ busy() ? '登录中…' : flow.authenticated() ? '进入工作空间' : '登录' }} @if (method() === 'token') {

登录凭证可在已登录设备的账号设置中复制,请勿分享给他人

}
@if (isMobile() && wideViewport()) {

当前窗口适合桌面端

已检测到窗口宽度达到 768px,可以切换到桌面布局继续使用。

} `, styles: [ ` @use '../../core/styles/breakpoints' as bp; /* 账号密码行(2026-12-04):输入框与眼睛按钮同高、同圆角,避免高低不齐 */ .credential-row { display: grid; grid-template-columns: minmax(0, 1fr) var(--touch-min); gap: var(--sp-2); align-items: stretch; } .credential-row ui-input { min-width: 0; } .credential-toggle { display: inline-flex; align-items: center; justify-content: center; border: 1px solid var(--edge); border-radius: var(--r-md); background: var(--surface); color: var(--muted); min-height: var(--touch-min); cursor: pointer; } .credential-toggle:hover { border-color: var(--edge-strong); color: var(--ink-2); } .login-help { display: block; margin: var(--sp-2) auto 0; padding: 0 var(--sp-3); min-height: var(--touch-min); border: 0; background: none; color: var(--muted); font: inherit; font-size: var(--fs-13); cursor: pointer; } .credential-toggle:focus-visible, .login-help:focus-visible, .mode-tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; } :host { display: block; min-height: 100dvh; background: var(--canvas); } /* 品牌位(2026-11-23):由 fa-cube 换成官方 logo 图形,本身带渐变故不加底色 */ .brand-mark { display: block; width: 40px; height: 40px; flex-shrink: 0; object-fit: contain; } /* ============ 桌面:左落地 + 右登录卡 ============ */ .split { display: grid; /* * 🔴 右侧登录栏收窄(2026-11-12 用户反馈「压缩一下整体宽度」): * 原 420px 下限让卡片显得过宽、留白过多。收到 380px, * 并在下方给卡片本身加 max-width,避免超宽屏被拉满。 */ grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.85fr); min-height: 100dvh; } .landing { display: flex; flex-direction: column; padding: clamp(var(--sp-6), 4vh, var(--sp-8)) clamp(var(--sp-6), 5vw, 72px); border-right: 1px solid var(--edge); min-width: 0; /* * 2026-12-04 PC 优化:原来纯 --surface 一色到底,左侧显得空而平。 * 用主色微光 + 细网格纹理撑起层次(只动背景,不改内容结构)。 */ background: radial-gradient(1100px 520px at 12% -10%, var(--primary-subtle) 0%, transparent 62%), radial-gradient(760px 420px at 92% 108%, var(--primary-subtle) 0%, transparent 58%), linear-gradient(180deg, var(--surface) 0%, var(--surface) 100%); } .lp-head { display: flex; align-items: center; gap: var(--sp-3); flex-shrink: 0; } .lp-brand { font-size: var(--fs-17); font-weight: 650; color: var(--ink); } .lp-sub { font-size: var(--fs-11); color: var(--muted); } .lp-body { flex: 1; display: grid; align-content: center; gap: var(--sp-5); padding: var(--sp-6) 0; max-width: 640px; min-width: 0; } .lp-tag { justify-self: start; padding: 0 var(--sp-3); border-radius: var(--r-tag); background: var(--primary-subtle); color: var(--primary); font-size: var(--fs-11); line-height: 26px; } .lp-title { margin: 0; /* 🔴 只用存在的令牌:--fs-36 不存在会让整个 clamp 失效(2026-12-04 踩坑) */ font-size: clamp(var(--fs-26), 3.2vw, var(--fs-42)); line-height: 1.22; letter-spacing: -0.02em; color: var(--ink); } .grad { color: var(--primary); font-weight: 650; } .lp-lead { margin: 0; font-size: var(--fs-15); line-height: 1.8; color: var(--ink-2); max-width: 54ch; } .lp-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-3); margin-top: var(--sp-2); } .lp-card { display: flex; gap: var(--sp-3); padding: var(--sp-4); border: 1px solid var(--edge); border-radius: var(--r-md); background: var(--surface); box-shadow: var(--shadow-soft); transition: border-color 0.18s ease, transform 0.18s ease; } .lp-card:hover { border-color: var(--primary); transform: translateY(-1px); } @media (prefers-reduced-motion: reduce) { .lp-card { transition: none; } .lp-card:hover { transform: none; } } .lp-ico { display: grid; place-items: center; width: 36px; height: 36px; flex-shrink: 0; border-radius: var(--r-sm); background: var(--primary-subtle); color: var(--primary); font-size: var(--fs-15); } .lp-card-title { font-size: var(--fs-13); font-weight: 600; color: var(--ink); } .lp-card-desc { margin-top: 2px; font-size: var(--fs-11); color: var(--muted); line-height: 1.6; } .lp-stats { display: flex; gap: clamp(var(--sp-5), 3vw, var(--sp-8)); flex-wrap: wrap; margin-top: var(--sp-4); padding-top: var(--sp-5); border-top: 1px solid var(--edge); } .lp-stat { display: grid; } .lp-stat b { font-size: var(--fs-24); color: var(--primary); line-height: 1.1; letter-spacing: -0.02em; } .lp-stat span { font-size: var(--fs-11); color: var(--muted); } .lp-foot { display: flex; align-items: center; gap: var(--sp-2); font-size: var(--fs-11); color: var(--muted); flex-shrink: 0; } .dot { width: 6px; height: 6px; border-radius: var(--r-tag); background: var(--success); } .panel { display: grid; place-items: center; padding: var(--sp-6); background: var(--canvas); } .panel-inner { width: 100%; max-width: 440px; } .panel-meta { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); margin: 0 0 var(--sp-3); color: var(--muted); font-size: var(--fs-11); } .panel-meta span { display: inline-flex; align-items: center; gap: var(--sp-2); color: var(--ink-2); font-weight: 600; } .panel-meta i { color: var(--success); } .card { width: 100%; /* * 2026-12-04 PC 优化:400px 在宽屏上显得局促(用户反馈「难看」)。 * 放宽到 420px 并保留 --sp-6 内边距,字段之间统一用 --sp-5 的节奏。 */ max-width: 420px; display: grid; gap: var(--sp-5); padding: var(--sp-6) var(--sp-6) var(--sp-5); border: 1px solid var(--edge); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-card); } /* ============ 移动:品牌说明 + 单一登录面板 ============ */ .m-login { min-height: 100dvh; display: grid; align-content: start; gap: var(--sp-4); padding: calc(var(--sp-5) + var(--mob-safe-top)) var(--mob-gutter) calc(var(--sp-6) + var(--mob-safe-bottom)); background: var(--canvas); } .m-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); } .m-brand { display: flex; align-items: center; gap: var(--sp-3); } .m-top .brand-mark { width: 40px; height: 40px; } .m-brand-copy { display: grid; gap: 2px; } .m-brand-copy strong { font-size: var(--fs-17); line-height: 1.2; color: var(--ink); } .m-brand-copy span { font-size: var(--fs-11); color: var(--muted); } .m-secure { display: inline-flex; align-items: center; gap: var(--sp-1); color: var(--success); font-size: var(--fs-11); white-space: nowrap; } .m-intro { display: grid; gap: var(--sp-2); padding: var(--sp-4) 0 var(--sp-2); } .m-eyebrow, .form-kicker { margin: 0; color: var(--primary); font-size: var(--fs-11); font-weight: 600; letter-spacing: 0; } .m-intro h1 { margin: 0; color: var(--ink); font-size: var(--fs-26); font-weight: 500; line-height: 1.25; } .m-intro h1 span { color: var(--primary); font-weight: 650; } .m-intro > p:last-child { margin: 0; color: var(--muted); font-size: var(--fs-13); } .m-card { display: grid; gap: var(--sp-5); padding: var(--sp-5) var(--sp-4) var(--sp-4); border: 1px solid var(--edge); border-radius: var(--r-lg); background: var(--surface); box-shadow: var(--shadow-card); } .m-foot { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); margin: 0; color: var(--muted); font-size: var(--fs-11); } .m-foot i { color: var(--success); } /* ============ 表单(共用)============ */ .form-head { display: grid; gap: var(--sp-1); } .form-kicker { color: var(--muted); font-weight: 500; } .form-head h2 { margin: 0; font-size: var(--fs-22); color: var(--ink); } .form-head p { margin: var(--sp-1) 0 0; font-size: var(--fs-13); color: var(--muted); } .mode-tabs { display: grid; /* * 🔴 三种登录方式必须**横排一行**(2026-11-12 用户截图反馈): * 两列时第三个 tab 会被挤到第二行,看起来像「上下布局」。 * 这里固定三等分,窄屏时靠字号与内边距压缩,不换行。 */ grid-template-columns: repeat(3, minmax(0, 1fr)); gap: var(--sp-1); padding: var(--sp-1); border: 1px solid var(--edge); border-radius: var(--r-md); background: var(--surface-2); } .mode-tab { min-height: 36px; border: 1px solid transparent; border-radius: calc(var(--r-md) - 2px); background: transparent; color: var(--ink-2); font-size: var(--fs-13); cursor: pointer; transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease; } .mode-tab:hover:not(.active) { color: var(--ink); } .mode-tab.active { background: var(--surface); border-color: var(--edge); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-soft); } @media (prefers-reduced-motion: reduce) { .mode-tab { transition: none; } } .mode-tab { min-height: var(--touch-min); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-2); font-size: var(--fs-13); /* * 🔴 三等分后文字更窄,允许折行而不是溢出(2026-11-12); * 同时收紧内边距,保证「验证码登录」这类 5 字标签不挤出按钮。 */ padding: 0 var(--sp-1); line-height: 1.2; white-space: normal; cursor: pointer; } .mode-tab.active { background: var(--surface); color: var(--ink); font-weight: 600; box-shadow: var(--shadow-soft); } .mode-tab:focus-visible { outline: 2px solid var(--primary-ring); outline-offset: -2px; } /* * 输入框统一外壳(2026-12-04 参照用户提供的设计稿): * 填充灰底、无边框、大圆角、高 56px —— 比「白底细边框」更有体量感。 * 通过外层容器实现,不改底座 ui-input(底座禁改)。 */ .input-shell { border-radius: 12px; background: var(--surface-2); transition: box-shadow 0.16s ease, background 0.16s ease; } .input-shell:focus-within { background: var(--surface); box-shadow: 0 0 0 1.5px var(--primary); } /* 清掉底座输入框自身的边框,只保留外壳的灰底圆角 */ .input-shell ::ng-deep input { height: 56px !important; padding-inline: 16px !important; border: 0 !important; border-radius: 12px !important; background: transparent !important; box-shadow: none !important; font-size: var(--fs-15) !important; } .input-shell ::ng-deep input:focus, .input-shell ::ng-deep input:focus-visible { /* 浏览器默认 focus 黑框太硬(2026-12-04):统一交给外壳的主色环表达焦点 */ outline: none !important; box-shadow: none !important; border: 0 !important; } .input-shell ::ng-deep input::placeholder { color: var(--faint, var(--muted)); } @media (prefers-reduced-motion: reduce) { .input-shell { transition: none; } } /* * 获取验证码(2026-12-04 用户裁决:不要边框)。 * 做成**纯文字按钮**压在验证码输入框右侧,点击区 44px 保证触控; * 这样它与输入框是一个整体,不会像描边按钮那样「两个框并排」显得碎。 */ .code-row { position: relative; align-items: center; grid-template-columns: minmax(0, 1fr); } .code-send { position: absolute; top: 50%; right: 6px; transform: translateY(-50%); min-height: 44px; padding: 0 12px; border: 0; border-radius: 8px; background: transparent; color: var(--primary); font-size: var(--fs-13); font-weight: 500; white-space: nowrap; cursor: pointer; transition: color 0.16s ease, opacity 0.16s ease; } .code-send:hover:not(:disabled) { text-decoration: underline; } .code-send:disabled { color: var(--muted); opacity: 0.7; cursor: default; } /* 给右侧文字按钮留出位置,避免输入内容被它盖住 */ .code-row .input-shell ::ng-deep input { padding-right: 132px !important; } .field { display: grid; gap: var(--sp-2); min-width: 0; } .field-label { font-size: var(--fs-13); font-weight: 500; color: var(--ink-2); } .code-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: var(--sp-2); } .code-row ui-button { min-width: 120px; } .field-hint { color: var(--muted); font-size: var(--fs-11); } .form-error { margin-top: calc(var(--sp-2) * -1); } .hint { display: flex; align-items: flex-start; gap: var(--sp-2); margin: 0; font-size: var(--fs-11); color: var(--muted); } .hint i { flex-shrink: 0; margin-top: 3px; color: var(--primary); } /* 窄于桌面两栏时收为单列(用断点 mixin,不写裸媒体查询) */ @include bp.dk-below-full { .split { grid-template-columns: minmax(0, 1fr); } .landing { display: none; } } /* 端切换提示层(与 mobile-shell 的 .wide-mobile 同口径) */ .wide-login { position: fixed; inset: 0; z-index: var(--z-mask); display: grid; place-items: center; padding: var(--sp-6); background: var(--canvas); } .wide-card { display: grid; justify-items: center; gap: var(--sp-2); max-width: 360px; text-align: center; } .wide-icon { display: grid; place-items: center; width: 56px; height: 56px; border-radius: var(--r-lg); background: var(--primary-subtle); color: var(--primary); font-size: var(--fs-20); } .wide-card h2 { margin: 0; color: var(--ink); font-size: var(--fs-20); } .wide-card p { margin: 0; color: var(--muted); font-size: var(--fs-13); line-height: 1.7; } .wide-btn { min-height: var(--touch-min); margin-top: var(--sp-2); padding: 0 var(--sp-4); border: 0; border-radius: var(--r-sm); background: var(--primary); color: var(--primary-content); font-size: var(--fs-13); cursor: pointer; } `, ], }) export class LoginComponent { readonly flow = inject(LoginFlowService); private readonly device = inject(DeviceService); private readonly router = inject(Router); private readonly host = inject>(ElementRef); readonly method = computed(() => this.flow.stage() === 'password' ? 'password' : this.flow.stage() === 'token' ? 'token' : 'mobile'); readonly mobile = this.flow.phone; readonly username = this.flow.username; readonly password = this.flow.password; readonly showPassword = this.flow.showPassword; readonly code = this.flow.code; readonly token = this.flow.token; readonly error = this.flow.error; readonly busy = this.flow.busy; readonly sendingCode = this.flow.sending; readonly countdown = this.flow.countdown; readonly isMobile = computed(() => this.device.mode() === 'mobile'); readonly wideViewport = computed(() => typeof window !== 'undefined' && !/FmodeApp\//i.test(navigator.userAgent) && window.innerWidth >= 768); readonly mobileValid = this.flow.phoneValid; readonly codeValid = this.flow.codeValid; readonly tokenValid = computed(() => !!this.flow.token().trim()); readonly usernameValid = computed(() => !!this.flow.username().trim()); readonly passwordValid = computed(() => !!this.flow.password()); readonly canSendCode = this.flow.canSendCode; readonly canSubmit = this.flow.canSubmit; readonly values = [ { icon: 'fa-comment', title: '一句话下发', desc: '用 IM 与数字生命对话,指令即任务' }, { icon: 'fa-bolt', title: '状态实时回流', desc: '运行、阻塞与失败第一时间可见' }, { icon: 'fa-box', title: '成果可追溯', desc: '每次交付都留档,随时查看与下载' }, ]; readonly stats = [ { value: '7', label: '功能模块' }, { value: '双端', label: '桌面 / 手机' }, { value: 'IM', label: '消息中枢' }, ]; private lastFocusedStage: string | null = null; constructor() { inject(PaletteService).init(); this.flow.initialize(); afterRenderEffect(() => { const stage = this.flow.stage(); if (this.flow.panel() || stage === this.lastFocusedStage) return; const name = stage === 'password' ? 'username' : stage === 'token' ? 'token' : stage === 'code' ? 'code' : 'phone'; const field = this.host.nativeElement.querySelector('input[name="' + name + '"]'); if (!field) return; const initial = this.lastFocusedStage === null; this.lastFocusedStage = stage; if (!(initial && stage === 'phone')) field.focus(); }); } switchMethod(method: LoginMethod): void { this.flow.switchStage(method === 'mobile' ? 'phone' : method); } onMobile(value: unknown): void { this.flow.setPhone(String(value)); } onUsername(value: unknown): void { this.flow.setUsername(String(value)); } onPassword(value: unknown): void { this.flow.setPassword(String(value)); } onCode(value: unknown): void { this.flow.setCode(String(value)); } onToken(value: unknown): void { this.flow.setToken(String(value)); } sendCode(): Promise { return this.flow.sendCode(); } submit(): Promise { return this.flow.submit(); } onKeyboardSubmit(event: Event): void { event.preventDefault(); if (this.method() === 'mobile' && !this.code() && !this.flow.authenticated()) void this.sendCode(); else void this.submit(); } goDesktop(): void { const { path } = this.device.switchMode(); // 端切换由原设备服务负责,入口继续保留既有业务分流。 void this.router.navigateByUrl(path, { replaceUrl: true }); } }