entry.ts 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/core';
  2. import { Router } from '@angular/router';
  3. import { DeviceService } from '../../core/device.service';
  4. import { SessionService } from '../../core/session.service';
  5. /**
  6. * 入口分流页(SPEC FR-01)
  7. *
  8. * 行为(2026-11-14 重构):
  9. * · 按 UA + 视口**一次性**判定访问端
  10. * · **先判登录态**:未登录直接跳 `/login`,不让用户白跑一趟业务页
  11. * · 已登录直接进对应端的业务页,**不经过空白中转**
  12. * · **`replaceUrl: true`** 跳转 → 浏览器返回不会弹回本页(AC-01.2)
  13. *
  14. * 🔴 端判定**只在此处发生一次**,之后不随窗口缩放/旋转改变(ADR-004 决策 3)。
  15. *
  16. * 🔴 为什么在这里判登录而不是靠守卫兜底:
  17. * 原实现无条件跳业务页,再由 `authGuard` 重定向到 `/login`。
  18. * 结果是「入口 → 业务页 → 登录」两次跳转,中间会闪一下空白/骨架,
  19. * 用户看到的就是「进去之后白屏加载」。现在一步到位。
  20. */
  21. @Component({
  22. selector: 'app-entry',
  23. changeDetection: ChangeDetectionStrategy.OnPush,
  24. template: `
  25. <div class="entry" role="status" aria-live="polite">
  26. <span class="entry-mark" aria-hidden="true"><i class="fa-solid fa-cube"></i></span>
  27. <p class="entry-text">正在进入…</p>
  28. </div>
  29. `,
  30. styles: [
  31. `
  32. :host {
  33. display: block;
  34. min-height: 100dvh;
  35. background: var(--canvas);
  36. }
  37. .entry {
  38. min-height: 100dvh;
  39. display: grid;
  40. place-content: center;
  41. justify-items: center;
  42. gap: var(--sp-3);
  43. }
  44. .entry-mark {
  45. display: grid;
  46. place-items: center;
  47. width: 56px;
  48. height: 56px;
  49. border-radius: var(--r-lg);
  50. background: var(--primary);
  51. color: var(--primary-content);
  52. font-size: var(--fs-20);
  53. }
  54. .entry-text {
  55. margin: 0;
  56. font-size: var(--fs-13);
  57. color: var(--muted);
  58. }
  59. `,
  60. ],
  61. })
  62. export class EntryComponent implements OnInit {
  63. private readonly device = inject(DeviceService);
  64. private readonly router = inject(Router);
  65. private readonly session = inject(SessionService);
  66. ngOnInit(): void {
  67. /*
  68. * 🔴 先判登录(2026-11-14 用户要求「登录检测成功自动进入对应页面,
  69. * 不空白加载」):未登录一步跳到登录页,不做「业务页 → 守卫 → 登录」两跳。
  70. */
  71. if (!this.session.isLoggedIn()) {
  72. void this.router.navigateByUrl('/login', { replaceUrl: true });
  73. return;
  74. }
  75. void this.router.navigateByUrl(this.device.entryPath(), { replaceUrl: true });
  76. }
  77. }