login.ts 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838
  1. import { afterRenderEffect, ChangeDetectionStrategy, Component, computed, ElementRef, inject } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { NgTemplateOutlet } from '@angular/common';
  4. import { UiAlert, UiButton, UiInput } from '../../ui';
  5. import { LoginFlowService } from '../../core/login-flow.service';
  6. import { LoginAssistance } from '../../components/domain/login-assistance/login-assistance';
  7. import { LoginFieldDirective } from '../../components/domain/login-assistance/login-field.directive';
  8. import { DeviceService } from '../../core/device.service';
  9. import { PaletteService } from '../../core/palette.service';
  10. type LoginMethod = 'password' | 'mobile' | 'token';
  11. /**
  12. * 登录页(SPEC FR-02)—— 两端共用同一组件,形态随端自适应
  13. *
  14. * 结构参照**第一版项目**(用户 2026-10-15 反馈:当前样式不符合之前版本):
  15. * · 桌面:左侧品牌落地页(品牌 + 标语 + 价值卡 + 统计) + 右侧登录卡
  16. * · 移动:顶部品牌区 + 登录卡
  17. * · 校验:Token 形如 `r:` 开头
  18. *
  19. * 实现纪律:底座组件(`ui-input`/`ui-button`/`ui-alert`)+ 令牌控制样式。
  20. *
  21. * AC:02.1 两种登录方式 / 02.2 `#token=` 自动登录后清地址栏 / 02.3 回跳 redirect
  22. * / 02.6 明确错误文案 / 02.7 防抖不并发
  23. */
  24. @Component({
  25. selector: 'app-login',
  26. changeDetection: ChangeDetectionStrategy.OnPush,
  27. imports: [NgTemplateOutlet, UiAlert, UiButton, UiInput, LoginAssistance, LoginFieldDirective],
  28. providers: [LoginFlowService],
  29. template: `
  30. @if (isMobile()) {
  31. <!-- ============ 移动端:顶部品牌 + 登录卡 ============ -->
  32. <div class="m-login">
  33. <header class="m-top">
  34. <div class="m-brand">
  35. <img class="brand-mark" src="icons/logo-mark.png" alt="" aria-hidden="true" />
  36. <div class="m-brand-copy">
  37. <strong>飞马SI</strong>
  38. <span>数字生命消息中枢</span>
  39. </div>
  40. </div>
  41. <span class="m-secure"><i class="fa-solid fa-shield-halved" aria-hidden="true"></i>安全登录</span>
  42. </header>
  43. <section class="m-intro" aria-labelledby="mobile-login-title">
  44. <p class="m-eyebrow">人机共生 · IM 中枢</p>
  45. <h1 id="mobile-login-title">继续处理你的<br /><span>会话与交付</span></h1>
  46. <p>登录后查看数字生命状态、任务进度和最新成果。</p>
  47. </section>
  48. <div class="m-card">
  49. <ng-container *ngTemplateOutlet="form" />
  50. </div>
  51. <p class="m-foot"><i class="fa-solid fa-circle-check" aria-hidden="true"></i>工作状态实时同步,成果可追溯</p>
  52. </div>
  53. } @else {
  54. <!-- ============ 桌面端:左落地页 + 右登录卡 ============ -->
  55. <div class="split">
  56. <section class="landing">
  57. <header class="lp-head">
  58. <img class="brand-mark" src="icons/logo-mark.png" alt="" aria-hidden="true" />
  59. <div>
  60. <div class="lp-brand">飞马SI</div>
  61. <div class="lp-sub">数字生命消息中枢</div>
  62. </div>
  63. </header>
  64. <div class="lp-body">
  65. <span class="lp-tag">人机共生 · IM 中枢</span>
  66. <h1 class="lp-title">
  67. 让每个数字生命<br />
  68. <span class="grad">随时在线,随时交付</span>
  69. </h1>
  70. <p class="lp-lead">
  71. 飞马SI 把人、数字生命与成果收敛到同一条消息流里 ——
  72. 你发一句话,它在后台自主执行,状态、过程与交付物实时回流。
  73. </p>
  74. <div class="lp-cards">
  75. @for (v of values; track v.title) {
  76. <div class="lp-card">
  77. <span class="lp-ico" aria-hidden="true"><i class="fa-solid" [class]="v.icon"></i></span>
  78. <div>
  79. <div class="lp-card-title">{{ v.title }}</div>
  80. <div class="lp-card-desc">{{ v.desc }}</div>
  81. </div>
  82. </div>
  83. }
  84. </div>
  85. <div class="lp-stats">
  86. @for (s of stats; track s.label) {
  87. <div class="lp-stat">
  88. <b>{{ s.value }}</b>
  89. <span>{{ s.label }}</span>
  90. </div>
  91. }
  92. </div>
  93. </div>
  94. <footer class="lp-foot">
  95. <span class="dot" aria-hidden="true"></span>人机共生 · 成果可追溯
  96. </footer>
  97. </section>
  98. <section class="panel">
  99. <div class="panel-inner">
  100. <div class="panel-meta">
  101. <span><i class="fa-solid fa-shield-halved" aria-hidden="true"></i>安全登录</span>
  102. <small>飞马SI · Fmode</small>
  103. </div>
  104. <div class="card">
  105. <ng-container *ngTemplateOutlet="form" />
  106. </div>
  107. </div>
  108. </section>
  109. </div>
  110. }
  111. <!-- ============ 登录表单(两端共用)============ -->
  112. <ng-template #form>
  113. <header class="form-head">
  114. <p class="form-kicker">进入工作空间</p>
  115. <h2>{{ method() === 'mobile' ? '欢迎回来' : method() === 'password' ? '账号密码登录' : '从已登录设备登录' }}</h2>
  116. <p>{{ method() === 'mobile' ? '用手机号验证码继续你的工作' : method() === 'password' ? '使用已有账号和密码继续' : '粘贴从已登录设备复制的登录凭证' }}</p>
  117. </header>
  118. <div class="mode-tabs">
  119. <button
  120. type="button"
  121. class="mode-tab" [disabled]="flow.working()"
  122. [class.active]="method() === 'password'"
  123. [attr.aria-pressed]="method() === 'password'"
  124. (click)="switchMethod('password')"
  125. >
  126. 账号登录
  127. </button>
  128. <button
  129. type="button"
  130. class="mode-tab" [disabled]="flow.working()"
  131. [class.active]="method() === 'mobile'"
  132. [attr.aria-pressed]="method() === 'mobile'"
  133. (click)="switchMethod('mobile')"
  134. >
  135. 验证码登录
  136. </button>
  137. <button
  138. type="button"
  139. class="mode-tab" [disabled]="flow.working()"
  140. [class.active]="method() === 'token'"
  141. [attr.aria-pressed]="method() === 'token'"
  142. (click)="switchMethod('token')"
  143. >
  144. 快捷登录
  145. </button>
  146. </div>
  147. @if (method() === 'password') {
  148. <!--
  149. 账号密码登录(2026-11-12):康师傅账套 27 个账号
  150. (用户名=姓名拼音,密码统一发放)主要走这里。
  151. -->
  152. <label class="field">
  153. <span class="field-label">账号</span>
  154. <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="username"
  155. placeholder="请输入账号"
  156. [value]="username()"
  157. [invalid]="!!error() && !usernameValid()"
  158. (valueChange)="onUsername($event)"
  159. />
  160. </label>
  161. <label class="field">
  162. <span class="field-label">密码</span>
  163. <div class="credential-row">
  164. <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="password" [type]="showPassword() ? 'text' : 'password'" placeholder="请输入密码"
  165. [value]="password()" (valueChange)="onPassword($event)" />
  166. <button type="button" class="credential-toggle" [disabled]="flow.working()" [attr.aria-label]="showPassword() ? '隐藏密码' : '显示密码'" [attr.aria-pressed]="showPassword()" (click)="showPassword.set(!showPassword())">
  167. <i [class]="showPassword() ? 'fa-solid fa-eye-slash' : 'fa-solid fa-eye'" aria-hidden="true"></i>
  168. </button>
  169. </div>
  170. </label>
  171. }
  172. @if (method() === 'mobile') {
  173. <label class="field">
  174. <span class="field-label">手机号</span>
  175. <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="phone"
  176. placeholder="请输入手机号"
  177. [value]="mobile()"
  178. [invalid]="!!error() && !mobileValid()"
  179. (valueChange)="onMobile($event)"
  180. />
  181. </label>
  182. <label class="field">
  183. <span class="field-label">验证码</span>
  184. <div class="code-row">
  185. <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="code"
  186. placeholder="6 位验证码"
  187. [value]="code()"
  188. [invalid]="!!error() && !codeValid()"
  189. (valueChange)="onCode($event)"
  190. />
  191. <ui-button variant="outline" [disabled]="!canSendCode()" (click)="sendCode()">
  192. {{ countdown() > 0 ? countdown() + 's 后重试' : sendingCode() ? '发送中…' : '获取验证码' }}
  193. </ui-button>
  194. </div>
  195. <small class="field-hint">手机号仅用于登录验证</small>
  196. </label>
  197. } @else if (method() === 'token') {
  198. <!--
  199. 🔴 必须是显式 else if(2026-11-12 修复):
  200. 原来写的是裸 else,它只与上一个「method === 'mobile'」配对 ——
  201. 于是选中「账号登录」时也会落进这个分支,把 SessionToken 输入框露出来。
  202. ⚠️ 模板注释里**不要写反引号**:它会被当成模板字符串起始,吞掉后续内容,
  203. 报错却指向好几行之后(本次踩坑:报 "Unexpected ;" 在 534 行)。
  204. -->
  205. <label class="field">
  206. <span class="field-label">登录凭证</span>
  207. <div class="credential-row">
  208. <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="token" [type]="flow.showToken() ? 'text' : 'password'" placeholder="粘贴登录凭证"
  209. [value]="token()" (valueChange)="onToken($event)" />
  210. <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())">
  211. <i [class]="flow.showToken() ? 'fa-solid fa-eye-slash' : 'fa-solid fa-eye'" aria-hidden="true"></i>
  212. </button>
  213. </div>
  214. </label>
  215. }
  216. <!-- AC-02.6:明确错误文案,不静默失败 -->
  217. @if (error(); as message) {
  218. <div class="form-error">
  219. <ui-alert type="danger" [description]="message" />
  220. </div>
  221. }
  222. @if (flow.notice()) { <p class="hint" role="status">{{ flow.notice() }}</p> }
  223. <app-login-assistance [flow]="flow" />
  224. <ui-button variant="primary" block [disabled]="!canSubmit()" [loading]="busy()" (click)="submit()">
  225. {{ busy() ? '登录中…' : flow.authenticated() ? '进入工作空间' : '登录' }}
  226. </ui-button>
  227. <button type="button" class="login-help" [disabled]="flow.working()" (click)="flow.openPanel('help')">登录遇到问题?</button>
  228. @if (method() === 'token') {
  229. <p class="hint"><i class="fa-solid fa-circle-info" aria-hidden="true"></i>登录凭证可在已登录设备的账号设置中复制,请勿分享给他人</p>
  230. }
  231. </ng-template>
  232. <!--
  233. 🔴 端切换提示(与 mobile-shell 同口径)。
  234. 场景:端判定为 mobile,但当前窗口已达桌面宽度 → 提示可切到桌面端。
  235. 此前 /login 不在任何 shell 内,**缺这个提示**,用户在电脑上遇到
  236. mobile 版式时无从切换。
  237. -->
  238. @if (isMobile() && wideViewport()) {
  239. <div class="wide-login" role="alertdialog" aria-label="窗口适合桌面端">
  240. <div class="wide-card">
  241. <span class="wide-icon" aria-hidden="true"><i class="fa-solid fa-display"></i></span>
  242. <h2>当前窗口适合桌面端</h2>
  243. <p>已检测到窗口宽度达到 768px,可以切换到桌面布局继续使用。</p>
  244. <button type="button" class="wide-btn" (click)="goDesktop()">切换到桌面端</button>
  245. </div>
  246. </div>
  247. }
  248. `,
  249. styles: [
  250. `
  251. @use '../../core/styles/breakpoints' as bp;
  252. /* 账号密码行(2026-12-04):输入框与眼睛按钮同高、同圆角,避免高低不齐 */
  253. .credential-row {
  254. display: grid;
  255. grid-template-columns: minmax(0, 1fr) var(--touch-min);
  256. gap: var(--sp-2);
  257. align-items: stretch;
  258. }
  259. .credential-row ui-input { min-width: 0; }
  260. .credential-toggle {
  261. display: inline-flex; align-items: center; justify-content: center;
  262. border: 1px solid var(--edge); border-radius: var(--r-md);
  263. background: var(--surface); color: var(--muted);
  264. min-height: var(--touch-min); cursor: pointer;
  265. }
  266. .credential-toggle:hover { border-color: var(--edge-strong); color: var(--ink-2); }
  267. .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; }
  268. .credential-toggle:focus-visible, .login-help:focus-visible, .mode-tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
  269. :host {
  270. display: block;
  271. min-height: 100dvh;
  272. background: var(--canvas);
  273. }
  274. /* 品牌位(2026-11-23):由 fa-cube 换成官方 logo 图形,本身带渐变故不加底色 */
  275. .brand-mark {
  276. display: block;
  277. width: 40px;
  278. height: 40px;
  279. flex-shrink: 0;
  280. object-fit: contain;
  281. }
  282. /* ============ 桌面:左落地 + 右登录卡 ============ */
  283. .split {
  284. display: grid;
  285. /*
  286. * 🔴 右侧登录栏收窄(2026-11-12 用户反馈「压缩一下整体宽度」):
  287. * 原 420px 下限让卡片显得过宽、留白过多。收到 380px,
  288. * 并在下方给卡片本身加 max-width,避免超宽屏被拉满。
  289. */
  290. grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.85fr);
  291. min-height: 100dvh;
  292. }
  293. .landing {
  294. display: flex;
  295. flex-direction: column;
  296. padding: clamp(var(--sp-6), 4vh, var(--sp-8)) clamp(var(--sp-6), 5vw, 72px);
  297. border-right: 1px solid var(--edge);
  298. min-width: 0;
  299. /*
  300. * 2026-12-04 PC 优化:原来纯 --surface 一色到底,左侧显得空而平。
  301. * 用主色微光 + 细网格纹理撑起层次(只动背景,不改内容结构)。
  302. */
  303. background:
  304. radial-gradient(1100px 520px at 12% -10%, var(--primary-subtle) 0%, transparent 62%),
  305. radial-gradient(760px 420px at 92% 108%, var(--primary-subtle) 0%, transparent 58%),
  306. linear-gradient(180deg, var(--surface) 0%, var(--surface) 100%);
  307. }
  308. .lp-head {
  309. display: flex;
  310. align-items: center;
  311. gap: var(--sp-3);
  312. flex-shrink: 0;
  313. }
  314. .lp-brand {
  315. font-size: var(--fs-17);
  316. font-weight: 650;
  317. color: var(--ink);
  318. }
  319. .lp-sub {
  320. font-size: var(--fs-11);
  321. color: var(--muted);
  322. }
  323. .lp-body {
  324. flex: 1;
  325. display: grid;
  326. align-content: center;
  327. gap: var(--sp-5);
  328. padding: var(--sp-6) 0;
  329. max-width: 640px;
  330. min-width: 0;
  331. }
  332. .lp-tag {
  333. justify-self: start;
  334. padding: 0 var(--sp-3);
  335. border-radius: var(--r-tag);
  336. background: var(--primary-subtle);
  337. color: var(--primary);
  338. font-size: var(--fs-11);
  339. line-height: 26px;
  340. }
  341. .lp-title {
  342. margin: 0;
  343. /* 🔴 只用存在的令牌:--fs-36 不存在会让整个 clamp 失效(2026-12-04 踩坑) */
  344. font-size: clamp(var(--fs-26), 3.2vw, var(--fs-42));
  345. line-height: 1.22;
  346. letter-spacing: -0.02em;
  347. color: var(--ink);
  348. }
  349. .grad {
  350. color: var(--primary);
  351. font-weight: 650;
  352. }
  353. .lp-lead {
  354. margin: 0;
  355. font-size: var(--fs-15);
  356. line-height: 1.8;
  357. color: var(--ink-2);
  358. max-width: 54ch;
  359. }
  360. .lp-cards {
  361. display: grid;
  362. grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  363. gap: var(--sp-3);
  364. margin-top: var(--sp-2);
  365. }
  366. .lp-card {
  367. display: flex;
  368. gap: var(--sp-3);
  369. padding: var(--sp-4);
  370. border: 1px solid var(--edge);
  371. border-radius: var(--r-md);
  372. background: var(--surface);
  373. box-shadow: var(--shadow-soft);
  374. transition: border-color 0.18s ease, transform 0.18s ease;
  375. }
  376. .lp-card:hover {
  377. border-color: var(--primary);
  378. transform: translateY(-1px);
  379. }
  380. @media (prefers-reduced-motion: reduce) {
  381. .lp-card { transition: none; }
  382. .lp-card:hover { transform: none; }
  383. }
  384. .lp-ico {
  385. display: grid;
  386. place-items: center;
  387. width: 36px;
  388. height: 36px;
  389. flex-shrink: 0;
  390. border-radius: var(--r-sm);
  391. background: var(--primary-subtle);
  392. color: var(--primary);
  393. font-size: var(--fs-15);
  394. }
  395. .lp-card-title {
  396. font-size: var(--fs-13);
  397. font-weight: 600;
  398. color: var(--ink);
  399. }
  400. .lp-card-desc {
  401. margin-top: 2px;
  402. font-size: var(--fs-11);
  403. color: var(--muted);
  404. line-height: 1.6;
  405. }
  406. .lp-stats {
  407. display: flex;
  408. gap: clamp(var(--sp-5), 3vw, var(--sp-8));
  409. flex-wrap: wrap;
  410. margin-top: var(--sp-4);
  411. padding-top: var(--sp-5);
  412. border-top: 1px solid var(--edge);
  413. }
  414. .lp-stat {
  415. display: grid;
  416. }
  417. .lp-stat b {
  418. font-size: var(--fs-24);
  419. color: var(--primary);
  420. line-height: 1.1;
  421. letter-spacing: -0.02em;
  422. }
  423. .lp-stat span {
  424. font-size: var(--fs-11);
  425. color: var(--muted);
  426. }
  427. .lp-foot {
  428. display: flex;
  429. align-items: center;
  430. gap: var(--sp-2);
  431. font-size: var(--fs-11);
  432. color: var(--muted);
  433. flex-shrink: 0;
  434. }
  435. .dot {
  436. width: 6px;
  437. height: 6px;
  438. border-radius: var(--r-tag);
  439. background: var(--success);
  440. }
  441. .panel {
  442. display: grid;
  443. place-items: center;
  444. padding: var(--sp-6);
  445. background: var(--canvas);
  446. }
  447. .panel-inner {
  448. width: 100%;
  449. max-width: 440px;
  450. }
  451. .panel-meta {
  452. display: flex;
  453. align-items: center;
  454. justify-content: space-between;
  455. gap: var(--sp-3);
  456. margin: 0 0 var(--sp-3);
  457. color: var(--muted);
  458. font-size: var(--fs-11);
  459. }
  460. .panel-meta span {
  461. display: inline-flex;
  462. align-items: center;
  463. gap: var(--sp-2);
  464. color: var(--ink-2);
  465. font-weight: 600;
  466. }
  467. .panel-meta i {
  468. color: var(--success);
  469. }
  470. .card {
  471. width: 100%;
  472. /* 卡片本体最宽 400px(2026-11-12):再宽输入框会显得空旷 */
  473. max-width: 400px;
  474. display: grid;
  475. gap: var(--sp-5);
  476. padding: var(--sp-6);
  477. border: 1px solid var(--edge);
  478. border-radius: var(--r-lg);
  479. background: var(--surface);
  480. box-shadow: var(--shadow-card);
  481. }
  482. /* ============ 移动:品牌说明 + 单一登录面板 ============ */
  483. .m-login {
  484. min-height: 100dvh;
  485. display: grid;
  486. align-content: start;
  487. gap: var(--sp-4);
  488. padding: calc(var(--sp-5) + var(--mob-safe-top)) var(--mob-gutter)
  489. calc(var(--sp-6) + var(--mob-safe-bottom));
  490. background: var(--canvas);
  491. }
  492. .m-top {
  493. display: flex;
  494. align-items: center;
  495. justify-content: space-between;
  496. gap: var(--sp-3);
  497. }
  498. .m-brand {
  499. display: flex;
  500. align-items: center;
  501. gap: var(--sp-3);
  502. }
  503. .m-top .brand-mark {
  504. width: 40px;
  505. height: 40px;
  506. }
  507. .m-brand-copy {
  508. display: grid;
  509. gap: 2px;
  510. }
  511. .m-brand-copy strong {
  512. font-size: var(--fs-17);
  513. line-height: 1.2;
  514. color: var(--ink);
  515. }
  516. .m-brand-copy span {
  517. font-size: var(--fs-11);
  518. color: var(--muted);
  519. }
  520. .m-secure {
  521. display: inline-flex;
  522. align-items: center;
  523. gap: var(--sp-1);
  524. color: var(--success);
  525. font-size: var(--fs-11);
  526. white-space: nowrap;
  527. }
  528. .m-intro {
  529. display: grid;
  530. gap: var(--sp-2);
  531. padding: var(--sp-4) 0 var(--sp-2);
  532. }
  533. .m-eyebrow,
  534. .form-kicker {
  535. margin: 0;
  536. color: var(--primary);
  537. font-size: var(--fs-11);
  538. font-weight: 600;
  539. letter-spacing: 0;
  540. }
  541. .m-intro h1 {
  542. margin: 0;
  543. color: var(--ink);
  544. font-size: var(--fs-26);
  545. font-weight: 500;
  546. line-height: 1.25;
  547. }
  548. .m-intro h1 span {
  549. color: var(--primary);
  550. font-weight: 650;
  551. }
  552. .m-intro > p:last-child {
  553. margin: 0;
  554. color: var(--muted);
  555. font-size: var(--fs-13);
  556. }
  557. .m-card {
  558. display: grid;
  559. gap: var(--sp-5);
  560. padding: var(--sp-5) var(--sp-4) var(--sp-4);
  561. border: 1px solid var(--edge);
  562. border-radius: var(--r-lg);
  563. background: var(--surface);
  564. box-shadow: var(--shadow-card);
  565. }
  566. .m-foot {
  567. display: flex;
  568. align-items: center;
  569. justify-content: center;
  570. gap: var(--sp-2);
  571. margin: 0;
  572. color: var(--muted);
  573. font-size: var(--fs-11);
  574. }
  575. .m-foot i {
  576. color: var(--success);
  577. }
  578. /* ============ 表单(共用)============ */
  579. .form-head {
  580. display: grid;
  581. gap: var(--sp-1);
  582. }
  583. .form-kicker {
  584. color: var(--muted);
  585. font-weight: 500;
  586. }
  587. .form-head h2 {
  588. margin: 0;
  589. font-size: var(--fs-22);
  590. color: var(--ink);
  591. }
  592. .form-head p {
  593. margin: var(--sp-1) 0 0;
  594. font-size: var(--fs-13);
  595. color: var(--muted);
  596. }
  597. .mode-tabs {
  598. display: grid;
  599. /*
  600. * 🔴 三种登录方式必须**横排一行**(2026-11-12 用户截图反馈):
  601. * 两列时第三个 tab 会被挤到第二行,看起来像「上下布局」。
  602. * 这里固定三等分,窄屏时靠字号与内边距压缩,不换行。
  603. */
  604. grid-template-columns: repeat(3, minmax(0, 1fr));
  605. gap: var(--sp-1);
  606. padding: var(--sp-1);
  607. border: 1px solid var(--edge);
  608. border-radius: var(--r-md);
  609. background: var(--surface-2);
  610. }
  611. .mode-tab {
  612. min-height: var(--touch-min);
  613. border: 0;
  614. border-radius: var(--r-sm);
  615. background: transparent;
  616. color: var(--ink-2);
  617. font-size: var(--fs-13);
  618. /*
  619. * 🔴 三等分后文字更窄,允许折行而不是溢出(2026-11-12);
  620. * 同时收紧内边距,保证「验证码登录」这类 5 字标签不挤出按钮。
  621. */
  622. padding: 0 var(--sp-1);
  623. line-height: 1.2;
  624. white-space: normal;
  625. cursor: pointer;
  626. }
  627. .mode-tab.active {
  628. background: var(--surface);
  629. color: var(--ink);
  630. font-weight: 600;
  631. box-shadow: var(--shadow-soft);
  632. }
  633. .mode-tab:focus-visible {
  634. outline: 2px solid var(--primary-ring);
  635. outline-offset: -2px;
  636. }
  637. .field {
  638. display: grid;
  639. gap: var(--sp-2);
  640. }
  641. .field-label {
  642. font-size: var(--fs-13);
  643. color: var(--ink-2);
  644. }
  645. .code-row {
  646. display: grid;
  647. grid-template-columns: minmax(0, 1fr) auto;
  648. gap: var(--sp-2);
  649. }
  650. .code-row ui-button {
  651. min-width: 120px;
  652. }
  653. .field-hint {
  654. color: var(--muted);
  655. font-size: var(--fs-11);
  656. }
  657. .form-error {
  658. margin-top: calc(var(--sp-2) * -1);
  659. }
  660. .hint {
  661. display: flex;
  662. align-items: flex-start;
  663. gap: var(--sp-2);
  664. margin: 0;
  665. font-size: var(--fs-11);
  666. color: var(--muted);
  667. }
  668. .hint i {
  669. flex-shrink: 0;
  670. margin-top: 3px;
  671. color: var(--primary);
  672. }
  673. /* 窄于桌面两栏时收为单列(用断点 mixin,不写裸媒体查询) */
  674. @include bp.dk-below-full {
  675. .split {
  676. grid-template-columns: minmax(0, 1fr);
  677. }
  678. .landing {
  679. display: none;
  680. }
  681. }
  682. /* 端切换提示层(与 mobile-shell 的 .wide-mobile 同口径) */
  683. .wide-login {
  684. position: fixed;
  685. inset: 0;
  686. z-index: var(--z-mask);
  687. display: grid;
  688. place-items: center;
  689. padding: var(--sp-6);
  690. background: var(--canvas);
  691. }
  692. .wide-card {
  693. display: grid;
  694. justify-items: center;
  695. gap: var(--sp-2);
  696. max-width: 360px;
  697. text-align: center;
  698. }
  699. .wide-icon {
  700. display: grid;
  701. place-items: center;
  702. width: 56px;
  703. height: 56px;
  704. border-radius: var(--r-lg);
  705. background: var(--primary-subtle);
  706. color: var(--primary);
  707. font-size: var(--fs-20);
  708. }
  709. .wide-card h2 {
  710. margin: 0;
  711. color: var(--ink);
  712. font-size: var(--fs-20);
  713. }
  714. .wide-card p {
  715. margin: 0;
  716. color: var(--muted);
  717. font-size: var(--fs-13);
  718. line-height: 1.7;
  719. }
  720. .wide-btn {
  721. min-height: var(--touch-min);
  722. margin-top: var(--sp-2);
  723. padding: 0 var(--sp-4);
  724. border: 0;
  725. border-radius: var(--r-sm);
  726. background: var(--primary);
  727. color: var(--primary-content);
  728. font-size: var(--fs-13);
  729. cursor: pointer;
  730. }
  731. `,
  732. ],
  733. })
  734. export class LoginComponent {
  735. readonly flow = inject(LoginFlowService);
  736. private readonly device = inject(DeviceService);
  737. private readonly router = inject(Router);
  738. private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
  739. readonly method = computed<LoginMethod>(() => this.flow.stage() === 'password' ? 'password' : this.flow.stage() === 'token' ? 'token' : 'mobile');
  740. readonly mobile = this.flow.phone;
  741. readonly username = this.flow.username;
  742. readonly password = this.flow.password;
  743. readonly showPassword = this.flow.showPassword;
  744. readonly code = this.flow.code;
  745. readonly token = this.flow.token;
  746. readonly error = this.flow.error;
  747. readonly busy = this.flow.busy;
  748. readonly sendingCode = this.flow.sending;
  749. readonly countdown = this.flow.countdown;
  750. readonly isMobile = computed(() => this.device.mode() === 'mobile');
  751. readonly wideViewport = computed(() => typeof window !== 'undefined' && !/FmodeApp\//i.test(navigator.userAgent) && window.innerWidth >= 768);
  752. readonly mobileValid = this.flow.phoneValid;
  753. readonly codeValid = this.flow.codeValid;
  754. readonly tokenValid = computed(() => !!this.flow.token().trim());
  755. readonly usernameValid = computed(() => !!this.flow.username().trim());
  756. readonly passwordValid = computed(() => !!this.flow.password());
  757. readonly canSendCode = this.flow.canSendCode;
  758. readonly canSubmit = this.flow.canSubmit;
  759. readonly values = [
  760. { icon: 'fa-comment', title: '一句话下发', desc: '用 IM 与数字生命对话,指令即任务' },
  761. { icon: 'fa-bolt', title: '状态实时回流', desc: '运行、阻塞与失败第一时间可见' },
  762. { icon: 'fa-box', title: '成果可追溯', desc: '每次交付都留档,随时查看与下载' },
  763. ];
  764. readonly stats = [
  765. { value: '7', label: '功能模块' },
  766. { value: '双端', label: '桌面 / 手机' },
  767. { value: 'IM', label: '消息中枢' },
  768. ];
  769. private lastFocusedStage: string | null = null;
  770. constructor() {
  771. inject(PaletteService).init();
  772. this.flow.initialize();
  773. afterRenderEffect(() => {
  774. const stage = this.flow.stage();
  775. if (this.flow.panel() || stage === this.lastFocusedStage) return;
  776. const name = stage === 'password' ? 'username' : stage === 'token' ? 'token' : stage === 'code' ? 'code' : 'phone';
  777. const field = this.host.nativeElement.querySelector<HTMLInputElement>('input[name="' + name + '"]');
  778. if (!field) return;
  779. const initial = this.lastFocusedStage === null;
  780. this.lastFocusedStage = stage;
  781. if (!(initial && stage === 'phone')) field.focus();
  782. });
  783. }
  784. switchMethod(method: LoginMethod): void { this.flow.switchStage(method === 'mobile' ? 'phone' : method); }
  785. onMobile(value: unknown): void { this.flow.setPhone(String(value)); }
  786. onUsername(value: unknown): void { this.flow.setUsername(String(value)); }
  787. onPassword(value: unknown): void { this.flow.setPassword(String(value)); }
  788. onCode(value: unknown): void { this.flow.setCode(String(value)); }
  789. onToken(value: unknown): void { this.flow.setToken(String(value)); }
  790. sendCode(): Promise<void> { return this.flow.sendCode(); }
  791. submit(): Promise<void> { return this.flow.submit(); }
  792. onKeyboardSubmit(event: Event): void {
  793. event.preventDefault();
  794. if (this.method() === 'mobile' && !this.code() && !this.flow.authenticated()) void this.sendCode();
  795. else void this.submit();
  796. }
  797. goDesktop(): void {
  798. const { path } = this.device.switchMode();
  799. // 端切换由原设备服务负责,入口继续保留既有业务分流。
  800. void this.router.navigateByUrl(path, { replaceUrl: true });
  801. }
  802. }