login.ts 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  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' ? '账号密码登录' : 'Token 登录' }}</h2>
  116. <p>{{ method() === 'mobile' ? '用手机号验证码继续你的工作' : method() === 'password' ? '使用已有账号和密码继续' : '粘贴以 r: 开头的登录 Token' }}</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. Token 登录
  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. <div class="input-shell">
  155. <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="username"
  156. placeholder="请输入账号"
  157. [value]="username()"
  158. [invalid]="!!error() && !usernameValid()"
  159. (valueChange)="onUsername($event)"
  160. />
  161. </div>
  162. </label>
  163. <label class="field">
  164. <span class="field-label">密码</span>
  165. <!-- 2026-12-04 用户裁决:密码框后面不要眼睛按钮,直接输入 -->
  166. <div class="input-shell">
  167. <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="password" [type]="showPassword() ? 'text' : 'password'" placeholder="请输入密码"
  168. [value]="password()" (valueChange)="onPassword($event)" />
  169. </div>
  170. </label>
  171. }
  172. @if (method() === 'mobile') {
  173. <label class="field">
  174. <span class="field-label">手机号</span>
  175. <div class="input-shell">
  176. <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="phone"
  177. placeholder="请输入手机号"
  178. [value]="mobile()"
  179. [invalid]="!!error() && !mobileValid()"
  180. (valueChange)="onMobile($event)"
  181. />
  182. </div>
  183. </label>
  184. <label class="field">
  185. <span class="field-label">验证码</span>
  186. <div class="code-row">
  187. <div class="input-shell">
  188. <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="code"
  189. placeholder="6 位验证码"
  190. [value]="code()"
  191. [invalid]="!!error() && !codeValid()"
  192. (valueChange)="onCode($event)"
  193. />
  194. </div>
  195. <!-- 获取验证码(2026-12-04):与输入框同高 56px、同圆角,描边主色 -->
  196. <button type="button" class="code-send" [disabled]="!canSendCode()" (click)="sendCode()">
  197. {{ countdown() > 0 ? countdown() + 's 后重试' : sendingCode() ? '发送中…' : '获取验证码' }}
  198. </button>
  199. </div>
  200. <small class="field-hint">手机号仅用于登录验证</small>
  201. </label>
  202. } @else if (method() === 'token') {
  203. <!--
  204. 🔴 必须是显式 else if(2026-11-12 修复):
  205. 原来写的是裸 else,它只与上一个「method === 'mobile'」配对 ——
  206. 于是选中「账号登录」时也会落进这个分支,把 SessionToken 输入框露出来。
  207. ⚠️ 模板注释里**不要写反引号**:它会被当成模板字符串起始,吞掉后续内容,
  208. 报错却指向好几行之后(本次踩坑:报 "Unexpected ;" 在 534 行)。
  209. -->
  210. <label class="field">
  211. <span class="field-label">Token</span>
  212. <!-- 2026-12-04 用户裁决:Token 输入框也去掉眼睛按钮,直接粘贴 -->
  213. <div class="input-shell">
  214. <ui-input [disabled]="flow.working()" (keydown.enter)="onKeyboardSubmit($event)" appLoginField="token" [type]="flow.showToken() ? 'text' : 'password'" placeholder="粘贴 Token,以 r: 开头"
  215. [value]="token()" (valueChange)="onToken($event)" />
  216. </div>
  217. </label>
  218. }
  219. <!-- AC-02.6:明确错误文案,不静默失败 -->
  220. @if (error(); as message) {
  221. <div class="form-error">
  222. <ui-alert type="danger" [description]="message" />
  223. </div>
  224. }
  225. @if (flow.notice()) { <p class="hint" role="status">{{ flow.notice() }}</p> }
  226. <app-login-assistance [flow]="flow" />
  227. <ui-button variant="primary" block [disabled]="!canSubmit()" [loading]="busy()" (click)="submit()">
  228. {{ busy() ? '登录中…' : flow.authenticated() ? '进入工作空间' : '登录' }}
  229. </ui-button>
  230. <!-- 2026-12-04 用户裁决:去掉「登录遇到问题?」,保持界面干净 -->
  231. @if (method() === 'token') {
  232. <p class="hint"><i class="fa-solid fa-circle-info" aria-hidden="true"></i>登录凭证可在已登录设备的账号设置中复制,请勿分享给他人</p>
  233. }
  234. </ng-template>
  235. <!--
  236. 🔴 端切换提示(与 mobile-shell 同口径)。
  237. 场景:端判定为 mobile,但当前窗口已达桌面宽度 → 提示可切到桌面端。
  238. 此前 /login 不在任何 shell 内,**缺这个提示**,用户在电脑上遇到
  239. mobile 版式时无从切换。
  240. -->
  241. @if (isMobile() && wideViewport()) {
  242. <div class="wide-login" role="alertdialog" aria-label="窗口适合桌面端">
  243. <div class="wide-card">
  244. <span class="wide-icon" aria-hidden="true"><i class="fa-solid fa-display"></i></span>
  245. <h2>当前窗口适合桌面端</h2>
  246. <p>已检测到窗口宽度达到 768px,可以切换到桌面布局继续使用。</p>
  247. <button type="button" class="wide-btn" (click)="goDesktop()">切换到桌面端</button>
  248. </div>
  249. </div>
  250. }
  251. `,
  252. styles: [
  253. `
  254. @use '../../core/styles/breakpoints' as bp;
  255. /* 账号密码行(2026-12-04):输入框与眼睛按钮同高、同圆角,避免高低不齐 */
  256. .credential-row {
  257. display: grid;
  258. grid-template-columns: minmax(0, 1fr) var(--touch-min);
  259. gap: var(--sp-2);
  260. align-items: stretch;
  261. }
  262. .credential-row ui-input { min-width: 0; }
  263. .credential-toggle {
  264. display: inline-flex; align-items: center; justify-content: center;
  265. border: 1px solid var(--edge); border-radius: var(--r-md);
  266. background: var(--surface); color: var(--muted);
  267. min-height: var(--touch-min); cursor: pointer;
  268. }
  269. .credential-toggle:hover { border-color: var(--edge-strong); color: var(--ink-2); }
  270. .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; }
  271. .credential-toggle:focus-visible, .login-help:focus-visible, .mode-tab:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }
  272. :host {
  273. display: block;
  274. min-height: 100dvh;
  275. background: var(--canvas);
  276. }
  277. /* 品牌位(2026-11-23):由 fa-cube 换成官方 logo 图形,本身带渐变故不加底色 */
  278. .brand-mark {
  279. display: block;
  280. width: 40px;
  281. height: 40px;
  282. flex-shrink: 0;
  283. object-fit: contain;
  284. }
  285. /* ============ 桌面:左落地 + 右登录卡 ============ */
  286. .split {
  287. display: grid;
  288. /*
  289. * 🔴 右侧登录栏收窄(2026-11-12 用户反馈「压缩一下整体宽度」):
  290. * 原 420px 下限让卡片显得过宽、留白过多。收到 380px,
  291. * 并在下方给卡片本身加 max-width,避免超宽屏被拉满。
  292. */
  293. grid-template-columns: minmax(0, 1.15fr) minmax(380px, 0.85fr);
  294. min-height: 100dvh;
  295. }
  296. .landing {
  297. display: flex;
  298. flex-direction: column;
  299. padding: clamp(var(--sp-6), 4vh, var(--sp-8)) clamp(var(--sp-6), 5vw, 72px);
  300. border-right: 1px solid var(--edge);
  301. min-width: 0;
  302. /*
  303. * 2026-12-04 PC 优化:原来纯 --surface 一色到底,左侧显得空而平。
  304. * 用主色微光 + 细网格纹理撑起层次(只动背景,不改内容结构)。
  305. */
  306. background:
  307. radial-gradient(1100px 520px at 12% -10%, var(--primary-subtle) 0%, transparent 62%),
  308. radial-gradient(760px 420px at 92% 108%, var(--primary-subtle) 0%, transparent 58%),
  309. linear-gradient(180deg, var(--surface) 0%, var(--surface) 100%);
  310. }
  311. .lp-head {
  312. display: flex;
  313. align-items: center;
  314. gap: var(--sp-3);
  315. flex-shrink: 0;
  316. }
  317. .lp-brand {
  318. font-size: var(--fs-17);
  319. font-weight: 650;
  320. color: var(--ink);
  321. }
  322. .lp-sub {
  323. font-size: var(--fs-11);
  324. color: var(--muted);
  325. }
  326. .lp-body {
  327. flex: 1;
  328. display: grid;
  329. align-content: center;
  330. gap: var(--sp-5);
  331. padding: var(--sp-6) 0;
  332. max-width: 640px;
  333. min-width: 0;
  334. }
  335. .lp-tag {
  336. justify-self: start;
  337. padding: 0 var(--sp-3);
  338. border-radius: var(--r-tag);
  339. background: var(--primary-subtle);
  340. color: var(--primary);
  341. font-size: var(--fs-11);
  342. line-height: 26px;
  343. }
  344. .lp-title {
  345. margin: 0;
  346. /* 🔴 只用存在的令牌:--fs-36 不存在会让整个 clamp 失效(2026-12-04 踩坑) */
  347. font-size: clamp(var(--fs-26), 3.2vw, var(--fs-42));
  348. line-height: 1.22;
  349. letter-spacing: -0.02em;
  350. color: var(--ink);
  351. }
  352. .grad {
  353. color: var(--primary);
  354. font-weight: 650;
  355. }
  356. .lp-lead {
  357. margin: 0;
  358. font-size: var(--fs-15);
  359. line-height: 1.8;
  360. color: var(--ink-2);
  361. max-width: 54ch;
  362. }
  363. .lp-cards {
  364. display: grid;
  365. grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  366. gap: var(--sp-3);
  367. margin-top: var(--sp-2);
  368. }
  369. .lp-card {
  370. display: flex;
  371. gap: var(--sp-3);
  372. padding: var(--sp-4);
  373. border: 1px solid var(--edge);
  374. border-radius: var(--r-md);
  375. background: var(--surface);
  376. box-shadow: var(--shadow-soft);
  377. transition: border-color 0.18s ease, transform 0.18s ease;
  378. }
  379. .lp-card:hover {
  380. border-color: var(--primary);
  381. transform: translateY(-1px);
  382. }
  383. @media (prefers-reduced-motion: reduce) {
  384. .lp-card { transition: none; }
  385. .lp-card:hover { transform: none; }
  386. }
  387. .lp-ico {
  388. display: grid;
  389. place-items: center;
  390. width: 36px;
  391. height: 36px;
  392. flex-shrink: 0;
  393. border-radius: var(--r-sm);
  394. background: var(--primary-subtle);
  395. color: var(--primary);
  396. font-size: var(--fs-15);
  397. }
  398. .lp-card-title {
  399. font-size: var(--fs-13);
  400. font-weight: 600;
  401. color: var(--ink);
  402. }
  403. .lp-card-desc {
  404. margin-top: 2px;
  405. font-size: var(--fs-11);
  406. color: var(--muted);
  407. line-height: 1.6;
  408. }
  409. .lp-stats {
  410. display: flex;
  411. gap: clamp(var(--sp-5), 3vw, var(--sp-8));
  412. flex-wrap: wrap;
  413. margin-top: var(--sp-4);
  414. padding-top: var(--sp-5);
  415. border-top: 1px solid var(--edge);
  416. }
  417. .lp-stat {
  418. display: grid;
  419. }
  420. .lp-stat b {
  421. font-size: var(--fs-24);
  422. color: var(--primary);
  423. line-height: 1.1;
  424. letter-spacing: -0.02em;
  425. }
  426. .lp-stat span {
  427. font-size: var(--fs-11);
  428. color: var(--muted);
  429. }
  430. .lp-foot {
  431. display: flex;
  432. align-items: center;
  433. gap: var(--sp-2);
  434. font-size: var(--fs-11);
  435. color: var(--muted);
  436. flex-shrink: 0;
  437. }
  438. .dot {
  439. width: 6px;
  440. height: 6px;
  441. border-radius: var(--r-tag);
  442. background: var(--success);
  443. }
  444. .panel {
  445. display: grid;
  446. place-items: center;
  447. padding: var(--sp-6);
  448. background: var(--canvas);
  449. }
  450. .panel-inner {
  451. width: 100%;
  452. max-width: 440px;
  453. }
  454. .panel-meta {
  455. display: flex;
  456. align-items: center;
  457. justify-content: space-between;
  458. gap: var(--sp-3);
  459. margin: 0 0 var(--sp-3);
  460. color: var(--muted);
  461. font-size: var(--fs-11);
  462. }
  463. .panel-meta span {
  464. display: inline-flex;
  465. align-items: center;
  466. gap: var(--sp-2);
  467. color: var(--ink-2);
  468. font-weight: 600;
  469. }
  470. .panel-meta i {
  471. color: var(--success);
  472. }
  473. .card {
  474. width: 100%;
  475. /*
  476. * 2026-12-04 PC 优化:400px 在宽屏上显得局促(用户反馈「难看」)。
  477. * 放宽到 420px 并保留 --sp-6 内边距,字段之间统一用 --sp-5 的节奏。
  478. */
  479. max-width: 420px;
  480. display: grid;
  481. gap: var(--sp-5);
  482. padding: var(--sp-6) var(--sp-6) var(--sp-5);
  483. border: 1px solid var(--edge);
  484. border-radius: var(--r-lg);
  485. background: var(--surface);
  486. box-shadow: var(--shadow-card);
  487. }
  488. /* ============ 移动:品牌说明 + 单一登录面板 ============ */
  489. .m-login {
  490. min-height: 100dvh;
  491. display: grid;
  492. align-content: start;
  493. gap: var(--sp-4);
  494. padding: calc(var(--sp-5) + var(--mob-safe-top)) var(--mob-gutter)
  495. calc(var(--sp-6) + var(--mob-safe-bottom));
  496. background: var(--canvas);
  497. }
  498. .m-top {
  499. display: flex;
  500. align-items: center;
  501. justify-content: space-between;
  502. gap: var(--sp-3);
  503. }
  504. .m-brand {
  505. display: flex;
  506. align-items: center;
  507. gap: var(--sp-3);
  508. }
  509. .m-top .brand-mark {
  510. width: 40px;
  511. height: 40px;
  512. }
  513. .m-brand-copy {
  514. display: grid;
  515. gap: 2px;
  516. }
  517. .m-brand-copy strong {
  518. font-size: var(--fs-17);
  519. line-height: 1.2;
  520. color: var(--ink);
  521. }
  522. .m-brand-copy span {
  523. font-size: var(--fs-11);
  524. color: var(--muted);
  525. }
  526. .m-secure {
  527. display: inline-flex;
  528. align-items: center;
  529. gap: var(--sp-1);
  530. color: var(--success);
  531. font-size: var(--fs-11);
  532. white-space: nowrap;
  533. }
  534. .m-intro {
  535. display: grid;
  536. gap: var(--sp-2);
  537. padding: var(--sp-4) 0 var(--sp-2);
  538. }
  539. .m-eyebrow,
  540. .form-kicker {
  541. margin: 0;
  542. color: var(--primary);
  543. font-size: var(--fs-11);
  544. font-weight: 600;
  545. letter-spacing: 0;
  546. }
  547. .m-intro h1 {
  548. margin: 0;
  549. color: var(--ink);
  550. font-size: var(--fs-26);
  551. font-weight: 500;
  552. line-height: 1.25;
  553. }
  554. .m-intro h1 span {
  555. color: var(--primary);
  556. font-weight: 650;
  557. }
  558. .m-intro > p:last-child {
  559. margin: 0;
  560. color: var(--muted);
  561. font-size: var(--fs-13);
  562. }
  563. .m-card {
  564. display: grid;
  565. gap: var(--sp-5);
  566. padding: var(--sp-5) var(--sp-4) var(--sp-4);
  567. border: 1px solid var(--edge);
  568. border-radius: var(--r-lg);
  569. background: var(--surface);
  570. box-shadow: var(--shadow-card);
  571. }
  572. .m-foot {
  573. display: flex;
  574. align-items: center;
  575. justify-content: center;
  576. gap: var(--sp-2);
  577. margin: 0;
  578. color: var(--muted);
  579. font-size: var(--fs-11);
  580. }
  581. .m-foot i {
  582. color: var(--success);
  583. }
  584. /* ============ 表单(共用)============ */
  585. .form-head {
  586. display: grid;
  587. gap: var(--sp-1);
  588. }
  589. .form-kicker {
  590. color: var(--muted);
  591. font-weight: 500;
  592. }
  593. .form-head h2 {
  594. margin: 0;
  595. font-size: var(--fs-22);
  596. color: var(--ink);
  597. }
  598. .form-head p {
  599. margin: var(--sp-1) 0 0;
  600. font-size: var(--fs-13);
  601. color: var(--muted);
  602. }
  603. .mode-tabs {
  604. display: grid;
  605. /*
  606. * 🔴 三种登录方式必须**横排一行**(2026-11-12 用户截图反馈):
  607. * 两列时第三个 tab 会被挤到第二行,看起来像「上下布局」。
  608. * 这里固定三等分,窄屏时靠字号与内边距压缩,不换行。
  609. */
  610. grid-template-columns: repeat(3, minmax(0, 1fr));
  611. gap: var(--sp-1);
  612. padding: var(--sp-1);
  613. border: 1px solid var(--edge);
  614. border-radius: var(--r-md);
  615. background: var(--surface-2);
  616. }
  617. .mode-tab {
  618. min-height: 36px;
  619. border: 1px solid transparent;
  620. border-radius: calc(var(--r-md) - 2px);
  621. background: transparent;
  622. color: var(--ink-2);
  623. font-size: var(--fs-13);
  624. cursor: pointer;
  625. transition: background 0.16s ease, color 0.16s ease, box-shadow 0.16s ease;
  626. }
  627. .mode-tab:hover:not(.active) { color: var(--ink); }
  628. .mode-tab.active {
  629. background: var(--surface);
  630. border-color: var(--edge);
  631. color: var(--ink);
  632. font-weight: 600;
  633. box-shadow: var(--shadow-soft);
  634. }
  635. @media (prefers-reduced-motion: reduce) {
  636. .mode-tab { transition: none; }
  637. }
  638. .mode-tab {
  639. min-height: var(--touch-min);
  640. border: 0;
  641. border-radius: var(--r-sm);
  642. background: transparent;
  643. color: var(--ink-2);
  644. font-size: var(--fs-13);
  645. /*
  646. * 🔴 三等分后文字更窄,允许折行而不是溢出(2026-11-12);
  647. * 同时收紧内边距,保证「验证码登录」这类 5 字标签不挤出按钮。
  648. */
  649. padding: 0 var(--sp-1);
  650. line-height: 1.2;
  651. white-space: normal;
  652. cursor: pointer;
  653. }
  654. .mode-tab.active {
  655. background: var(--surface);
  656. color: var(--ink);
  657. font-weight: 600;
  658. box-shadow: var(--shadow-soft);
  659. }
  660. .mode-tab:focus-visible {
  661. outline: 2px solid var(--primary-ring);
  662. outline-offset: -2px;
  663. }
  664. /*
  665. * 输入框统一外壳(2026-12-04 参照用户提供的设计稿):
  666. * 填充灰底、无边框、大圆角、高 56px —— 比「白底细边框」更有体量感。
  667. * 通过外层容器实现,不改底座 ui-input(底座禁改)。
  668. */
  669. .input-shell {
  670. border-radius: 12px;
  671. background: var(--surface-2);
  672. transition: box-shadow 0.16s ease, background 0.16s ease;
  673. }
  674. .input-shell:focus-within {
  675. background: var(--surface);
  676. box-shadow: 0 0 0 1.5px var(--primary);
  677. }
  678. /* 清掉底座输入框自身的边框,只保留外壳的灰底圆角 */
  679. .input-shell ::ng-deep input {
  680. height: 56px !important;
  681. padding-inline: 16px !important;
  682. border: 0 !important;
  683. border-radius: 12px !important;
  684. background: transparent !important;
  685. box-shadow: none !important;
  686. font-size: var(--fs-15) !important;
  687. }
  688. .input-shell ::ng-deep input:focus,
  689. .input-shell ::ng-deep input:focus-visible {
  690. /* 浏览器默认 focus 黑框太硬(2026-12-04):统一交给外壳的主色环表达焦点 */
  691. outline: none !important;
  692. box-shadow: none !important;
  693. border: 0 !important;
  694. }
  695. .input-shell ::ng-deep input::placeholder { color: var(--faint, var(--muted)); }
  696. @media (prefers-reduced-motion: reduce) {
  697. .input-shell { transition: none; }
  698. }
  699. /*
  700. * 获取验证码(2026-12-04 用户裁决:不要边框)。
  701. * 做成**纯文字按钮**压在验证码输入框右侧,点击区 44px 保证触控;
  702. * 这样它与输入框是一个整体,不会像描边按钮那样「两个框并排」显得碎。
  703. */
  704. .code-row {
  705. position: relative;
  706. align-items: center;
  707. grid-template-columns: minmax(0, 1fr);
  708. }
  709. .code-send {
  710. position: absolute;
  711. top: 50%;
  712. right: 6px;
  713. transform: translateY(-50%);
  714. min-height: 44px;
  715. padding: 0 12px;
  716. border: 0;
  717. border-radius: 8px;
  718. background: transparent;
  719. color: var(--primary);
  720. font-size: var(--fs-13);
  721. font-weight: 500;
  722. white-space: nowrap;
  723. cursor: pointer;
  724. transition: color 0.16s ease, opacity 0.16s ease;
  725. }
  726. .code-send:hover:not(:disabled) { text-decoration: underline; }
  727. .code-send:disabled { color: var(--muted); opacity: 0.7; cursor: default; }
  728. /* 给右侧文字按钮留出位置,避免输入内容被它盖住 */
  729. .code-row .input-shell ::ng-deep input { padding-right: 132px !important; }
  730. .field {
  731. display: grid;
  732. gap: var(--sp-2);
  733. min-width: 0;
  734. }
  735. .field-label {
  736. font-size: var(--fs-13);
  737. font-weight: 500;
  738. color: var(--ink-2);
  739. }
  740. .code-row {
  741. display: grid;
  742. grid-template-columns: minmax(0, 1fr) auto;
  743. gap: var(--sp-2);
  744. }
  745. .code-row ui-button {
  746. min-width: 120px;
  747. }
  748. .field-hint {
  749. color: var(--muted);
  750. font-size: var(--fs-11);
  751. }
  752. .form-error {
  753. margin-top: calc(var(--sp-2) * -1);
  754. }
  755. .hint {
  756. display: flex;
  757. align-items: flex-start;
  758. gap: var(--sp-2);
  759. margin: 0;
  760. font-size: var(--fs-11);
  761. color: var(--muted);
  762. }
  763. .hint i {
  764. flex-shrink: 0;
  765. margin-top: 3px;
  766. color: var(--primary);
  767. }
  768. /* 窄于桌面两栏时收为单列(用断点 mixin,不写裸媒体查询) */
  769. @include bp.dk-below-full {
  770. .split {
  771. grid-template-columns: minmax(0, 1fr);
  772. }
  773. .landing {
  774. display: none;
  775. }
  776. }
  777. /* 端切换提示层(与 mobile-shell 的 .wide-mobile 同口径) */
  778. .wide-login {
  779. position: fixed;
  780. inset: 0;
  781. z-index: var(--z-mask);
  782. display: grid;
  783. place-items: center;
  784. padding: var(--sp-6);
  785. background: var(--canvas);
  786. }
  787. .wide-card {
  788. display: grid;
  789. justify-items: center;
  790. gap: var(--sp-2);
  791. max-width: 360px;
  792. text-align: center;
  793. }
  794. .wide-icon {
  795. display: grid;
  796. place-items: center;
  797. width: 56px;
  798. height: 56px;
  799. border-radius: var(--r-lg);
  800. background: var(--primary-subtle);
  801. color: var(--primary);
  802. font-size: var(--fs-20);
  803. }
  804. .wide-card h2 {
  805. margin: 0;
  806. color: var(--ink);
  807. font-size: var(--fs-20);
  808. }
  809. .wide-card p {
  810. margin: 0;
  811. color: var(--muted);
  812. font-size: var(--fs-13);
  813. line-height: 1.7;
  814. }
  815. .wide-btn {
  816. min-height: var(--touch-min);
  817. margin-top: var(--sp-2);
  818. padding: 0 var(--sp-4);
  819. border: 0;
  820. border-radius: var(--r-sm);
  821. background: var(--primary);
  822. color: var(--primary-content);
  823. font-size: var(--fs-13);
  824. cursor: pointer;
  825. }
  826. `,
  827. ],
  828. })
  829. export class LoginComponent {
  830. readonly flow = inject(LoginFlowService);
  831. private readonly device = inject(DeviceService);
  832. private readonly router = inject(Router);
  833. private readonly host = inject<ElementRef<HTMLElement>>(ElementRef);
  834. readonly method = computed<LoginMethod>(() => this.flow.stage() === 'password' ? 'password' : this.flow.stage() === 'token' ? 'token' : 'mobile');
  835. readonly mobile = this.flow.phone;
  836. readonly username = this.flow.username;
  837. readonly password = this.flow.password;
  838. readonly showPassword = this.flow.showPassword;
  839. readonly code = this.flow.code;
  840. readonly token = this.flow.token;
  841. readonly error = this.flow.error;
  842. readonly busy = this.flow.busy;
  843. readonly sendingCode = this.flow.sending;
  844. readonly countdown = this.flow.countdown;
  845. readonly isMobile = computed(() => this.device.mode() === 'mobile');
  846. readonly wideViewport = computed(() => typeof window !== 'undefined' && !/FmodeApp\//i.test(navigator.userAgent) && window.innerWidth >= 768);
  847. readonly mobileValid = this.flow.phoneValid;
  848. readonly codeValid = this.flow.codeValid;
  849. readonly tokenValid = computed(() => !!this.flow.token().trim());
  850. readonly usernameValid = computed(() => !!this.flow.username().trim());
  851. readonly passwordValid = computed(() => !!this.flow.password());
  852. readonly canSendCode = this.flow.canSendCode;
  853. readonly canSubmit = this.flow.canSubmit;
  854. readonly values = [
  855. { icon: 'fa-comment', title: '一句话下发', desc: '用 IM 与数字生命对话,指令即任务' },
  856. { icon: 'fa-bolt', title: '状态实时回流', desc: '运行、阻塞与失败第一时间可见' },
  857. { icon: 'fa-box', title: '成果可追溯', desc: '每次交付都留档,随时查看与下载' },
  858. ];
  859. readonly stats = [
  860. { value: '7', label: '功能模块' },
  861. { value: '双端', label: '桌面 / 手机' },
  862. { value: 'IM', label: '消息中枢' },
  863. ];
  864. private lastFocusedStage: string | null = null;
  865. constructor() {
  866. inject(PaletteService).init();
  867. this.flow.initialize();
  868. afterRenderEffect(() => {
  869. const stage = this.flow.stage();
  870. if (this.flow.panel() || stage === this.lastFocusedStage) return;
  871. const name = stage === 'password' ? 'username' : stage === 'token' ? 'token' : stage === 'code' ? 'code' : 'phone';
  872. const field = this.host.nativeElement.querySelector<HTMLInputElement>('input[name="' + name + '"]');
  873. if (!field) return;
  874. const initial = this.lastFocusedStage === null;
  875. this.lastFocusedStage = stage;
  876. if (!(initial && stage === 'phone')) field.focus();
  877. });
  878. }
  879. switchMethod(method: LoginMethod): void { this.flow.switchStage(method === 'mobile' ? 'phone' : method); }
  880. onMobile(value: unknown): void { this.flow.setPhone(String(value)); }
  881. onUsername(value: unknown): void { this.flow.setUsername(String(value)); }
  882. onPassword(value: unknown): void { this.flow.setPassword(String(value)); }
  883. onCode(value: unknown): void { this.flow.setCode(String(value)); }
  884. onToken(value: unknown): void { this.flow.setToken(String(value)); }
  885. sendCode(): Promise<void> { return this.flow.sendCode(); }
  886. submit(): Promise<void> { return this.flow.submit(); }
  887. onKeyboardSubmit(event: Event): void {
  888. event.preventDefault();
  889. if (this.method() === 'mobile' && !this.code() && !this.flow.authenticated()) void this.sendCode();
  890. else void this.submit();
  891. }
  892. goDesktop(): void {
  893. const { path } = this.device.switchMode();
  894. // 端切换由原设备服务负责,入口继续保留既有业务分流。
  895. void this.router.navigateByUrl(path, { replaceUrl: true });
  896. }
  897. }