| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838 |
- 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()) {
- <!-- ============ 移动端:顶部品牌 + 登录卡 ============ -->
- <div class="m-login">
- <header class="m-top">
- <div class="m-brand">
- <img class="brand-mark" src="icons/logo-mark.png" alt="" aria-hidden="true" />
- <div class="m-brand-copy">
- <strong>飞马SI</strong>
- <span>数字生命消息中枢</span>
- </div>
- </div>
- <span class="m-secure"><i class="fa-solid fa-shield-halved" aria-hidden="true"></i>安全登录</span>
- </header>
- <section class="m-intro" aria-labelledby="mobile-login-title">
- <p class="m-eyebrow">人机共生 · IM 中枢</p>
- <h1 id="mobile-login-title">继续处理你的<br /><span>会话与交付</span></h1>
- <p>登录后查看数字生命状态、任务进度和最新成果。</p>
- </section>
- <div class="m-card">
- <ng-container *ngTemplateOutlet="form" />
- </div>
- <p class="m-foot"><i class="fa-solid fa-circle-check" aria-hidden="true"></i>工作状态实时同步,成果可追溯</p>
- </div>
- } @else {
- <!-- ============ 桌面端:左落地页 + 右登录卡 ============ -->
- <div class="split">
- <section class="landing">
- <header class="lp-head">
- <img class="brand-mark" src="icons/logo-mark.png" alt="" aria-hidden="true" />
- <div>
- <div class="lp-brand">飞马SI</div>
- <div class="lp-sub">数字生命消息中枢</div>
- </div>
- </header>
- <div class="lp-body">
- <span class="lp-tag">人机共生 · IM 中枢</span>
- <h1 class="lp-title">
- 让每个数字生命<br />
- <span class="grad">随时在线,随时交付</span>
- </h1>
- <p class="lp-lead">
- 飞马SI 把人、数字生命与成果收敛到同一条消息流里 ——
- 你发一句话,它在后台自主执行,状态、过程与交付物实时回流。
- </p>
- <div class="lp-cards">
- @for (v of values; track v.title) {
- <div class="lp-card">
- <span class="lp-ico" aria-hidden="true"><i class="fa-solid" [class]="v.icon"></i></span>
- <div>
- <div class="lp-card-title">{{ v.title }}</div>
- <div class="lp-card-desc">{{ v.desc }}</div>
- </div>
- </div>
- }
- </div>
- <div class="lp-stats">
- @for (s of stats; track s.label) {
- <div class="lp-stat">
- <b>{{ s.value }}</b>
- <span>{{ s.label }}</span>
- </div>
- }
- </div>
- </div>
- <footer class="lp-foot">
- <span class="dot" aria-hidden="true"></span>人机共生 · 成果可追溯
- </footer>
- </section>
- <section class="panel">
- <div class="panel-inner">
- <div class="panel-meta">
- <span><i class="fa-solid fa-shield-halved" aria-hidden="true"></i>安全登录</span>
- <small>飞马SI · Fmode</small>
- </div>
- <div class="card">
- <ng-container *ngTemplateOutlet="form" />
- </div>
- </div>
- </section>
- </div>
- }
- <!-- ============ 登录表单(两端共用)============ -->
- <ng-template #form>
- <header class="form-head">
- <p class="form-kicker">进入工作空间</p>
- <h2>{{ method() === 'mobile' ? '欢迎回来' : method() === 'password' ? '账号密码登录' : '从已登录设备登录' }}</h2>
- <p>{{ method() === 'mobile' ? '用手机号验证码继续你的工作' : method() === 'password' ? '使用已有账号和密码继续' : '粘贴从已登录设备复制的登录凭证' }}</p>
- </header>
- <div class="mode-tabs">
- <button
- type="button"
- class="mode-tab" [disabled]="flow.working()"
- [class.active]="method() === 'password'"
- [attr.aria-pressed]="method() === 'password'"
- (click)="switchMethod('password')"
- >
- 账号登录
- </button>
- <button
- type="button"
- class="mode-tab" [disabled]="flow.working()"
- [class.active]="method() === 'mobile'"
- [attr.aria-pressed]="method() === 'mobile'"
- (click)="switchMethod('mobile')"
- >
- 验证码登录
- </button>
- <button
- type="button"
- class="mode-tab" [disabled]="flow.working()"
- [class.active]="method() === 'token'"
- [attr.aria-pressed]="method() === 'token'"
- (click)="switchMethod('token')"
- >
- 快捷登录
- </button>
- </div>
- @if (method() === 'password') {
- <!--
- 账号密码登录(2026-11-12):康师傅账套 27 个账号
- (用户名=姓名拼音,密码统一发放)主要走这里。
- -->
- <label class="field">
- <span class="field-label">账号</span>
- <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="username"
- placeholder="请输入账号"
- [value]="username()"
- [invalid]="!!error() && !usernameValid()"
- (valueChange)="onUsername($event)"
- />
- </label>
- <label class="field">
- <span class="field-label">密码</span>
- <div class="credential-row">
- <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="password" [type]="showPassword() ? 'text' : 'password'" placeholder="请输入密码"
- [value]="password()" (valueChange)="onPassword($event)" />
- <button type="button" class="credential-toggle" [disabled]="flow.working()" [attr.aria-label]="showPassword() ? '隐藏密码' : '显示密码'" [attr.aria-pressed]="showPassword()" (click)="showPassword.set(!showPassword())">
- <i [class]="showPassword() ? 'fa-solid fa-eye-slash' : 'fa-solid fa-eye'" aria-hidden="true"></i>
- </button>
- </div>
- </label>
- }
- @if (method() === 'mobile') {
- <label class="field">
- <span class="field-label">手机号</span>
- <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="phone"
- placeholder="请输入手机号"
- [value]="mobile()"
- [invalid]="!!error() && !mobileValid()"
- (valueChange)="onMobile($event)"
- />
- </label>
- <label class="field">
- <span class="field-label">验证码</span>
- <div class="code-row">
- <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="code"
- placeholder="6 位验证码"
- [value]="code()"
- [invalid]="!!error() && !codeValid()"
- (valueChange)="onCode($event)"
- />
- <ui-button variant="outline" [disabled]="!canSendCode()" (click)="sendCode()">
- {{ countdown() > 0 ? countdown() + 's 后重试' : sendingCode() ? '发送中…' : '获取验证码' }}
- </ui-button>
- </div>
- <small class="field-hint">手机号仅用于登录验证</small>
- </label>
- } @else if (method() === 'token') {
- <!--
- 🔴 必须是显式 else if(2026-11-12 修复):
- 原来写的是裸 else,它只与上一个「method === 'mobile'」配对 ——
- 于是选中「账号登录」时也会落进这个分支,把 SessionToken 输入框露出来。
- ⚠️ 模板注释里**不要写反引号**:它会被当成模板字符串起始,吞掉后续内容,
- 报错却指向好几行之后(本次踩坑:报 "Unexpected ;" 在 534 行)。
- -->
- <label class="field">
- <span class="field-label">登录凭证</span>
- <div class="credential-row">
- <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="token" [type]="flow.showToken() ? 'text' : 'password'" placeholder="粘贴登录凭证"
- [value]="token()" (valueChange)="onToken($event)" />
- <button type="button" class="credential-toggle" [disabled]="flow.working()" [attr.aria-label]="flow.showToken() ? '隐藏登录凭证' : '显示登录凭证'" [attr.aria-pressed]="flow.showToken()" (click)="flow.showToken.set(!flow.showToken())">
- <i [class]="flow.showToken() ? 'fa-solid fa-eye-slash' : 'fa-solid fa-eye'" aria-hidden="true"></i>
- </button>
- </div>
- </label>
- }
- <!-- AC-02.6:明确错误文案,不静默失败 -->
- @if (error(); as message) {
- <div class="form-error">
- <ui-alert type="danger" [description]="message" />
- </div>
- }
- @if (flow.notice()) { <p class="hint" role="status">{{ flow.notice() }}</p> }
- <app-login-assistance [flow]="flow" />
- <ui-button variant="primary" block [disabled]="!canSubmit()" [loading]="busy()" (click)="submit()">
- {{ busy() ? '登录中…' : flow.authenticated() ? '进入工作空间' : '登录' }}
- </ui-button>
- <button type="button" class="login-help" [disabled]="flow.working()" (click)="flow.openPanel('help')">登录遇到问题?</button>
- @if (method() === 'token') {
- <p class="hint"><i class="fa-solid fa-circle-info" aria-hidden="true"></i>登录凭证可在已登录设备的账号设置中复制,请勿分享给他人</p>
- }
- </ng-template>
- <!--
- 🔴 端切换提示(与 mobile-shell 同口径)。
- 场景:端判定为 mobile,但当前窗口已达桌面宽度 → 提示可切到桌面端。
- 此前 /login 不在任何 shell 内,**缺这个提示**,用户在电脑上遇到
- mobile 版式时无从切换。
- -->
- @if (isMobile() && wideViewport()) {
- <div class="wide-login" role="alertdialog" aria-label="窗口适合桌面端">
- <div class="wide-card">
- <span class="wide-icon" aria-hidden="true"><i class="fa-solid fa-display"></i></span>
- <h2>当前窗口适合桌面端</h2>
- <p>已检测到窗口宽度达到 768px,可以切换到桌面布局继续使用。</p>
- <button type="button" class="wide-btn" (click)="goDesktop()">切换到桌面端</button>
- </div>
- </div>
- }
- `,
- 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%;
- /* 卡片本体最宽 400px(2026-11-12):再宽输入框会显得空旷 */
- max-width: 400px;
- display: grid;
- gap: var(--sp-5);
- padding: var(--sp-6);
- 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: 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;
- }
- .field {
- display: grid;
- gap: var(--sp-2);
- }
- .field-label {
- font-size: var(--fs-13);
- 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<HTMLElement>>(ElementRef);
- readonly method = computed<LoginMethod>(() => 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<HTMLInputElement>('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<void> { return this.flow.sendCode(); }
- submit(): Promise<void> { 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 });
- }
- }
|