| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- import { ChangeDetectionStrategy, Component, inject, OnInit } from '@angular/core';
- import { Router } from '@angular/router';
- import { DeviceService } from '../../core/device.service';
- import { SessionService } from '../../core/session.service';
- /**
- * 入口分流页(SPEC FR-01)
- *
- * 行为(2026-11-14 重构):
- * · 按 UA + 视口**一次性**判定访问端
- * · **先判登录态**:未登录直接跳 `/login`,不让用户白跑一趟业务页
- * · 已登录直接进对应端的业务页,**不经过空白中转**
- * · **`replaceUrl: true`** 跳转 → 浏览器返回不会弹回本页(AC-01.2)
- *
- * 🔴 端判定**只在此处发生一次**,之后不随窗口缩放/旋转改变(ADR-004 决策 3)。
- *
- * 🔴 为什么在这里判登录而不是靠守卫兜底:
- * 原实现无条件跳业务页,再由 `authGuard` 重定向到 `/login`。
- * 结果是「入口 → 业务页 → 登录」两次跳转,中间会闪一下空白/骨架,
- * 用户看到的就是「进去之后白屏加载」。现在一步到位。
- */
- @Component({
- selector: 'app-entry',
- changeDetection: ChangeDetectionStrategy.OnPush,
- template: `
- <div class="entry" role="status" aria-live="polite">
- <span class="entry-mark" aria-hidden="true"><i class="fa-solid fa-cube"></i></span>
- <p class="entry-text">正在进入…</p>
- </div>
- `,
- styles: [
- `
- :host {
- display: block;
- min-height: 100dvh;
- background: var(--canvas);
- }
- .entry {
- min-height: 100dvh;
- display: grid;
- place-content: center;
- justify-items: center;
- gap: var(--sp-3);
- }
- .entry-mark {
- display: grid;
- place-items: center;
- width: 56px;
- height: 56px;
- border-radius: var(--r-lg);
- background: var(--primary);
- color: var(--primary-content);
- font-size: var(--fs-20);
- }
- .entry-text {
- margin: 0;
- font-size: var(--fs-13);
- color: var(--muted);
- }
- `,
- ],
- })
- export class EntryComponent implements OnInit {
- private readonly device = inject(DeviceService);
- private readonly router = inject(Router);
- private readonly session = inject(SessionService);
- ngOnInit(): void {
- /*
- * 🔴 先判登录(2026-11-14 用户要求「登录检测成功自动进入对应页面,
- * 不空白加载」):未登录一步跳到登录页,不做「业务页 → 守卫 → 登录」两跳。
- */
- if (!this.session.isLoggedIn()) {
- void this.router.navigateByUrl('/login', { replaceUrl: true });
- return;
- }
- void this.router.navigateByUrl(this.device.entryPath(), { replaceUrl: true });
- }
- }
|