import { AppNotificationService } from '../../../core/app-notification.service'; import { NotificationSetupService } from '../../../core/notification-setup.service'; import { isNativeApp } from '../../../core/api/platform-proxy.service'; import { ChatService } from '../../../core/chat.service'; import { ChangeDetectionStrategy, Component, computed, inject, signal } from '@angular/core'; import { Router } from '@angular/router'; import { CHAT_FONT_SIZES, ChatFontService, UI_SCALES, UI_SCALE_LABEL } from '../../../core/chat-font.service'; import { DEFAULT_PALETTE, PALETTES, PaletteService } from '../../../core/palette.service'; import { PaletteId } from '../../../core/api/models'; import { SessionService } from '../../../core/session.service'; import { ChatSessionService } from '../../../core/chat-session.service'; import { ThemeService } from '../../../ui/theme/theme.service'; import { MAppBarComponent } from '../../components/m-app-bar/m-app-bar'; import { MAvatarComponent } from '../../components/m-avatar/m-avatar'; import { MDrawerComponent } from '../../components/m-drawer/m-drawer'; import { MConfirmComponent } from '../../components/m-confirm/m-confirm'; import { AppUpdateService } from '../../../core/app-update.service'; import { UpdateDialogComponent } from '../../components/m-update-dialog/m-update-dialog'; /** * 我的 / 设置(Demo 16) * * 顺序:个人资料 / 通知(原生端)/ 外观 / 账号与 Token / 退出。 * * 配色与深色直接复用既有服务(`PaletteService` / 底座 `ThemeService`), * 字号走 `ChatFontService`(写 `--ui-scale`),与桌面设置项**同一真源**, * 不另建一套偏好存储。 */ @Component({ selector: 'app-mb-mine-page', changeDetection: ChangeDetectionStrategy.OnPush, imports: [MAppBarComponent, MAvatarComponent, MDrawerComponent, MConfirmComponent, UpdateDialogComponent], template: `
{{ me()?.name || '未登录' }}
{{ me()?.mobile || '未设置手机号' }}@if (me()?.companyName) { · {{ me()?.companyName }} }
@if (isNative()) {

通知

}

外观

整体配色

@for (p of palettes; track p.id) { }
深色模式
正文大小 {{ font.size() }}px
界面大小 {{ uiScaleLabel() }}
@for (opt of uiScaleOptions; track opt.value) { }

正文大小影响对话内容;界面大小影响导航与图标。

账号

  • 访问 Token {{ tokenShown() ? tokenText() : maskToken() }}
`, styles: ` :host { display: block; min-height: 100dvh; background: var(--canvas); } /* 固定外壳 + 内部滚动(2026-11-04):外层不能滚,只有内容区滚 */ .m-page--scroll { display: flex; flex-direction: column; height: 100dvh; box-sizing: border-box; padding-bottom: calc(var(--mob-tabbar-h) + var(--mob-safe-bottom)); } .m-body { flex: 1; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: var(--sp-6); } .m-section { padding: 0 var(--mob-gutter); } .m-section + .m-section { margin-top: var(--sp-6); } .m-section:first-of-type { margin-top: var(--sp-3); } .m-section-title { margin: 0 0 var(--sp-3); color: var(--muted); font-size: var(--fs-13); font-weight: 400; } .m-card { padding: var(--sp-4); border: 1px solid var(--edge); border-radius: var(--r-lg); background: var(--surface); box-shadow: none; } .m-profile { display: flex; align-items: center; gap: var(--sp-3); } .m-profile-body { min-width: 0; } .m-profile-name { color: var(--ink); font-size: var(--fs-17); font-weight: 600; } .m-profile-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: var(--fs-13); } .m-list { margin: 0; padding: 0; list-style: none; border: 1px solid var(--edge); border-radius: var(--r-lg); background: var(--surface); overflow: hidden; } .m-list > li + li { border-top: 1px solid var(--edge); } .m-row { display: flex; align-items: center; gap: var(--sp-3); width: 100%; min-height: 56px; padding: var(--sp-3) var(--sp-4); box-sizing: border-box; border: 0; background: var(--surface); color: var(--ink); font: inherit; text-align: left; cursor: pointer; } .m-row--plain { min-height: 56px; padding: var(--sp-3) 0; margin-top: var(--sp-2); border-top: 1px solid var(--edge); cursor: default; } .m-row-body { flex: 1; min-width: 0; } .m-row-t1 { display: block; font-size: var(--fs-15); } .m-row-t2 { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--muted); font-size: var(--fs-13); } .m-row-sub { display: block; margin-top: var(--sp-1); color: var(--muted); font-size: var(--fs-12); line-height: 1.5; overflow-wrap: anywhere; } .m-token-row { display: flex; align-items: center; gap: var(--sp-2); min-height: 56px; padding: var(--sp-3) var(--sp-4); background: var(--surface); } .m-token-value { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } .m-token-btn { display: grid; place-items: center; flex: none; width: var(--touch-min); height: var(--touch-min); border: 0; border-radius: var(--r-sm); background: none; color: var(--muted); font-size: var(--fs-13); cursor: pointer; } .m-token-btn:active { background: var(--surface-hover); } .m-token-btn:disabled { opacity: 0.35; cursor: not-allowed; } .m-logout { width: 100%; min-height: 52px; border: 1px solid var(--edge); border-radius: var(--r-lg); background: var(--surface); color: var(--danger); font: inherit; font-size: var(--fs-15); font-weight: 600; cursor: pointer; } .m-logout:active { background: var(--surface-hover); } /* * 有新版本时的红点(2026-11-23) * 取代 chevron 的位置 —— 有红点时无需再提示「可进入」, * 点进去就是要更新,语义更聚焦。 */ .m-update-dot { flex: none; width: 8px; height: 8px; border-radius: 50%; background: #EF4444; box-shadow: 0 0 0 3px rgba(239, 68, 68, 0.16); } .m-chev { color: var(--muted); font-size: var(--fs-12); } .m-label { margin: 0 0 var(--sp-3); color: var(--ink-2); font-size: var(--fs-13); } .m-palette-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--sp-2); } .m-palette { min-width: 0; display: flex; flex-direction: column; align-items: center; gap: var(--sp-1); padding: var(--sp-2) var(--sp-1); border: 1.5px solid var(--edge); border-radius: var(--r-md); background: var(--surface); color: var(--ink-2); font: inherit; font-size: var(--fs-11); white-space: nowrap; cursor: pointer; } .m-palette.on { border-color: var(--primary); color: var(--primary); font-weight: 600; } .m-swatch { display: flex; width: 100%; height: 32px; border: 1px solid var(--edge); border-radius: var(--r-sm); overflow: hidden; } .m-swatch i { flex: 1; } .m-swatch i:nth-child(1) { background: var(--nav-surface); } .m-swatch i:nth-child(2) { background: var(--primary); } .m-swatch i:nth-child(3) { background: var(--surface-2); } /* * 配色缩略图:各自作用域内展示该套配色的导航 / 主色 / 表面色。 * * 🔴 这里不再重复写色值 —— _palette.scss 早已定义 * [data-preview-palette='xxx'] { --nav-surface / --primary / --surface-2 }, * 本组件的 [attr.data-preview-palette] 直接命中那套规则。 * 原先复制过来的 12 个色值是冗余副本,一旦调色就会与真源不一致。 */ .m-switch { position: relative; flex: none; width: 48px; height: var(--touch-min); border: 0; border-radius: var(--r-tag); background: transparent; cursor: pointer; transition: background var(--motion-fast) var(--ease-standard); } .m-switch::before { content: ''; position: absolute; inset: 8px 0; border-radius: var(--r-tag); background: var(--surface-active); } .m-switch::after { content: ''; position: absolute; top: 11px; left: 3px; width: 22px; height: 22px; border-radius: var(--r-tag); background: var(--surface); box-shadow: var(--shadow-soft); transition: transform var(--motion-fast) var(--ease-standard); } .m-switch[aria-checked='true']::before { background: var(--primary); } .m-switch[aria-checked='true']::after { transform: translateX(20px); background: var(--primary-content); } .m-font { margin-top: var(--sp-2); padding-top: var(--sp-3); border-top: 1px solid var(--edge); } .m-font-head { display: flex; align-items: baseline; justify-content: space-between; } .m-font-val { color: var(--muted); font-size: var(--fs-13); } .m-font-head--ui { margin-top: var(--sp-3); } /* 轻量预览:无背景框,直接用当前档位渲染一行样例 */ .m-font-preview { margin: var(--sp-1) 0 0; color: var(--muted); line-height: 1.5; } .m-font-hint { margin: var(--sp-3) 0 0; color: var(--faint); font-size: var(--fs-12); line-height: 1.5; } /* 界面大小:三档分段(与正文滑块区分开,避免两套控制混在一起) */ .m-ui-scale { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--sp-1); margin-top: var(--sp-2); padding: 3px; border-radius: var(--r-md); background: var(--surface-2); } .m-ui-scale button { min-height: var(--touch-min); border: 0; border-radius: var(--r-sm); background: transparent; color: var(--ink-2); font: inherit; font-size: var(--fs-14); cursor: pointer; } .m-ui-scale button.on { background: var(--surface); color: var(--primary); font-weight: 600; box-shadow: var(--shadow-soft); } .m-slider { width: 100%; margin-top: var(--sp-2); min-height: var(--touch-min); accent-color: var(--primary); } ` }) export class MbMinePage { private readonly chat = inject(ChatService); /** 当前打开的会话(抽屉高亮用) */ protected readonly activeSessionId = computed(() => this.chat.sessionId()); private readonly router = inject(Router); private readonly session = inject(SessionService); private readonly sessionsSvc = inject(ChatSessionService); protected readonly palette = inject(PaletteService); protected readonly theme = inject(ThemeService); protected readonly font = inject(ChatFontService); protected readonly drawerOpen = signal(false); protected readonly logoutOpen = signal(false); /** * 版本与更新(2026-11-23 新增) * * 服务是 root 级单例,和弹窗组件共享同一个实例 —— * 这里点了检查,弹窗那边立刻能感知到 hasUpdate 变化。 */ protected readonly update = inject(AppUpdateService); protected readonly updating = this.update.checking; /** 版本文案:本机版本 + 包名,方便反馈问题时一眼看出装的是哪个包 */ protected versionText(): string { const v = this.update.local(); if (!v) return '未获取到版本信息'; return `v${v.versionName} (${v.versionCode})`; } /** 手动检查更新:查完有新版就由弹窗接管显示 */ protected async checkUpdateNow(): Promise { await this.update.check(); if (!this.update.hasUpdate() && !this.update.error()) { /* * 已是最新 —— 给个轻提示。 * 不用弹窗(太重),直接在行内文案上体现就够了, * 用户点完看到「已是最新」自然明白。 */ this.updateTip.set('已是最新版本'); setTimeout(() => this.updateTip.set(null), 2000); } } /** 「已是最新」的临时提示 */ protected readonly updateTip = signal(null); protected readonly palettes = PALETTES; protected readonly fontMin = Math.min(...CHAT_FONT_SIZES); protected readonly fontMax = Math.max(...CHAT_FONT_SIZES); /** 界面大小三档(与正文大小分开设置) */ protected readonly uiScaleOptions = UI_SCALES.map((value) => ({ value, label: UI_SCALE_LABEL[value] })); protected readonly uiScaleLabel = computed(() => UI_SCALE_LABEL[this.font.ui()]); protected readonly me = this.session.me; constructor() { // 字号偏好按用户存储,进入设置页时载入(幂等) this.font.load(); this.loadNotificationState(); } /** Token 只展示尾部 4 位 —— 完整令牌不应出现在屏幕上 */ protected readonly tokenShown = signal(false); protected readonly copied = signal(false); /** 完整 Token(仅在用户主动点「显示」后渲染到 DOM) */ protected readonly tokenText = computed(() => this.session.token() ?? '—'); protected async copyToken(): Promise { try { await navigator.clipboard.writeText(this.session.token() ?? ''); this.copied.set(true); setTimeout(() => this.copied.set(false), 1500); } catch { /* 非安全上下文:静默失败,用户可手动选中复制 */ } } protected readonly maskToken = computed(() => { const t = this.session.token(); if (!t) return '—'; const visible = t.slice(-4); return `${t.startsWith('r:') ? 'r:' : ''}${'•'.repeat(12)}${visible}`; }); protected setPalette(id: PaletteId): void { this.palette.set(id || DEFAULT_PALETTE); } protected toggleDark(): void { this.theme.toggleMode(); } // ---------- 通知权限(2026-11-15) ---------- private readonly notify = inject(AppNotificationService); private readonly notificationSetup = inject(NotificationSetupService); /** 通知权限状态:null = 未知/查询中,true = 已开,false = 未开 */ /** * 通知权限状态:直接订阅 service 的 signal(2026-11-15)。 * 原来的本地 signal 只在构造函数查一次,从系统设置返回后不会更新。 */ protected readonly notifyGranted = computed(() => this.notify.grantedState()); /** 是否原生壳(浏览器里不显示「通知」入口 —— 浏览器没有这个系统权限) */ protected readonly isNative = signal(isNativeApp()); /** 进页面时查一次通知权限状态(构造函数里调用,不另开第二个 constructor) */ private loadNotificationState(): void { /* 进页面时强制刷新一次:用户可能刚从系统设置回来 */ void this.notify.refreshGranted(); } protected notifyStateText(): string { const g = this.notifyGranted(); if (g === null) return '检查中…'; if (!g) return '未开启 · 点此设置'; // 已开通知时进一步告知还有几项后台设置没配好,用户不用点进去才知道 const left = this.notificationSetup.remaining(); return left > 0 ? `系统通知已开启 · ${left} 项后台设置待处理` : '系统通知已开启 · 全部就绪'; } /** * 点「通知」行: * · 已开 → 去系统设置(可关闭) * · 未开 → 先申请;被系统拒绝(不再弹窗)则引导去设置页 */ protected async onNotificationRow(): Promise { this.notificationSetup.show(); } /** 字号滑块:吸附到最近的档位(与桌面设置同一组档位) */ protected onFont(e: Event): void { const v = Number((e.target as HTMLInputElement).value); const nearest = CHAT_FONT_SIZES.reduce((a, b) => (Math.abs(b - v) < Math.abs(a - v) ? b : a)); this.font.set(nearest); } protected logout(): void { this.logoutOpen.set(false); this.session.logout(); this.sessionsSvc.reset(); void this.router.navigateByUrl('/login', { replaceUrl: true }); } protected newChat(): void { this.drawerOpen.set(false); void this.router.navigateByUrl('/mobile/messages'); } /** * 在指定工作区中新建对话。 * * 这几页没有新建对话弹层,统一跳到会话列表页并带上工作区参数, * 由那里打开选择容器的弹层(避免每个页面各做一套)。 */ protected onNewChatIn(workspaceId: string): void { void this.router.navigateByUrl(`/mobile/messages?newIn=${encodeURIComponent(workspaceId)}`); } }