plans.ts 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889
  1. import { UserNoticePipe } from '../../../components/feedback/user-notice.pipe';
  2. import { ChangeDetectionStrategy, Component, computed, inject, OnInit, signal } from '@angular/core';
  3. import { Router } from '@angular/router';
  4. import { PaidPlanCode } from '../../../core/api/models';
  5. import { LoadingOverlayComponent } from '../../../components/domain/loading-overlay/loading-overlay';
  6. import { ProvisionInstructionComponent } from '../../../components/domain/provision-instruction/provision-instruction';
  7. import { PlanService } from '../../../core/plan.service';
  8. import { ProvisionService } from '../../../core/provision.service';
  9. import { RenewalGuideComponent } from '../../../components/domain/renewal-guide/renewal-guide';
  10. import { LiveService } from '../../../core/live.service';
  11. import { ProvisionConfirmComponent } from '../../../components/domain/provision-confirm/provision-confirm';
  12. import { suggestContainerName } from '../../../components/domain/provision-confirm/container-name';
  13. /**
  14. * 桌面端套餐与开通(2026-11-25 第一期)
  15. *
  16. * ## 与移动端的差异(两端独立设计)
  17. *
  18. * 桌面横向空间充足,用**三列详情卡**:图标 / 名称 / 副标题 / 价格 /
  19. * 开通按钮 / 权益清单全部展示,一屏看完三档对比。
  20. * 移动端受窄屏所限用紧凑选择卡,见 `mobile/pages/plans`。
  21. *
  22. * ## 本期边界
  23. *
  24. * 只做展示 + 申请意向。**不显示金额、不显示「已开通」、不显示开通进度**。
  25. */
  26. @Component({
  27. selector: 'app-dk-plans-page',
  28. changeDetection: ChangeDetectionStrategy.OnPush,
  29. imports: [UserNoticePipe, ProvisionInstructionComponent, LoadingOverlayComponent, RenewalGuideComponent, ProvisionConfirmComponent],
  30. template: `
  31. <div class="plans-page">
  32. <!-- 名额已满提示(2026-12-03):页面顶部,用户点了开通马上能看到 -->
  33. @if (quotaFull(); as qf) {
  34. <div class="quota-full" role="alert">
  35. <p>「{{ qf.plan }}」的名额已满({{ existingNames().length }}/{{ qf.quota }})。</p>
  36. <p>可以删除不用的容器,或升级到名额更多的套餐。</p>
  37. <button type="button" (click)="quotaFull.set(null)">知道了</button>
  38. </div>
  39. }
  40. <header class="plans-head">
  41. <div>
  42. <p class="plans-eyebrow"><i class="fa-solid fa-crown" aria-hidden="true"></i> 套餐与开通</p>
  43. <h1>选择适合你的协作方式。</h1>
  44. <p class="plans-lead">按需选择,随时升级。</p>
  45. </div>
  46. </header>
  47. <!--
  48. 当前资产概览(2026-12-02 PC 优化)。
  49. 桌面端宽屏下先回答「我现在有什么」,再让用户选「要不要再开一个」——
  50. 原来一进页面只能看到三张价格卡,对自己已有的容器与名额没有概念。
  51. -->
  52. <section class="plans-status" aria-label="当前容器与名额">
  53. <div class="plans-status-item">
  54. <span class="plans-status-label">我的容器</span>
  55. @if (live.hasData()) {
  56. <strong class="plans-status-value">{{ live.agents().length }} 个</strong>
  57. <span class="plans-status-hint">{{ runningCount() }} 个运行中</span>
  58. } @else {
  59. <strong class="plans-status-value">—</strong>
  60. <span class="plans-status-hint">正在读取…</span>
  61. }
  62. </div>
  63. <div class="plans-status-item">
  64. <span class="plans-status-label">当前套餐</span>
  65. <strong class="plans-status-value">{{ currentPlanName() }}</strong>
  66. <span class="plans-status-hint">{{ provision.hasJob() ? provision.statusText() : '按需升级,随时生效' }}</span>
  67. </div>
  68. <div class="plans-status-actions">
  69. <button type="button" class="plans-status-btn" (click)="go('/desktop/my-containers')">
  70. <i class="fa-solid fa-server" aria-hidden="true"></i> 管理容器
  71. </button>
  72. <button type="button" class="plans-status-btn plans-status-btn--primary" [disabled]="provision.startBlocked()" (click)="apply('advanced')">
  73. <i class="fa-solid fa-plus" aria-hidden="true"></i> 新增容器
  74. </button>
  75. </div>
  76. </section>
  77. <!-- 开通进行中 / 提示词 / 试用引导 -->
  78. @if (provision.hasJob()) {
  79. <section class="plans-banner plans-banner--pending">
  80. <i class="fa-solid"
  81. [class]="provision.isReady() ? 'fa-circle-check' : provision.isFailed() ? 'fa-triangle-exclamation' : 'fa-spinner fa-spin'"
  82. aria-hidden="true"></i>
  83. <div style="flex:1;min-width:0">
  84. <h2>{{ provision.statusText() }}</h2>
  85. <p>{{ (provision.isFailed() ? provision.failureMessage() : '容器创建由平台自动完成,请稍候。') | userNotice:'暂时无法确认开通结果,请先查看已有申请。':'verify-result' }}</p>
  86. @if (provision.isRunning() && provision.completedStages() > 0) {
  87. <div class="plans-progress" role="progressbar"
  88. [attr.aria-valuenow]="provision.completedStages()"
  89. [attr.aria-valuemin]="0" [attr.aria-valuemax]="5">
  90. <span class="plans-progress-bar"
  91. [style.width.%]="(provision.completedStages() / 5) * 100"></span>
  92. </div>
  93. }
  94. </div>
  95. @if (provision.isFailed() && provision.canRetry()) {
  96. <button type="button" class="plans-banner-btn" (click)="provision.retry()">重试</button>
  97. } @else if (provision.isFailed()) {
  98. <button type="button" class="plans-banner-btn" (click)="go('/plans')">查看套餐升级</button>
  99. } @else if (!provision.isReady()) {
  100. <button type="button" class="plans-banner-btn" (click)="go('/provision?jobId=' + provision.current()?.jobId)">查看开通进度</button>
  101. } @else {
  102. <button type="button" class="plans-banner-btn" (click)="go('/desktop/my-containers')">查看我的容器</button>
  103. }
  104. </section>
  105. } @else if (provision.instruction(); as ins) {
  106. <!-- 试用/入门:接入提示词(组件内含复制 + 失败兜底) -->
  107. <app-provision-instruction [text]="ins" />
  108. } @else {
  109. <section class="plans-banner">
  110. <div class="plans-banner-icon">
  111. <i class="fa-solid fa-wand-magic-sparkles" aria-hidden="true"></i>
  112. </div>
  113. <div class="plans-banner-body">
  114. <h2>先体验,再决定。<span>两天试用</span></h2>
  115. <p>使用你自己的容器接入 Fmode</p>
  116. </div>
  117. <button type="button" class="plans-banner-btn" [disabled]="provision.startBlocked()" (click)="apply('trial')">
  118. @if (provision.isStarting('trial')) {
  119. <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
  120. 生成中…
  121. } @else {
  122. 开始两天试用
  123. }
  124. </button>
  125. </section>
  126. }
  127. @if (provision.error(); as err) {
  128. <p class="plans-error"><i class="fa-solid fa-circle-exclamation" aria-hidden="true"></i> {{ (err) | userNotice:'暂时无法确认开通结果,请先查看已有申请。':'verify-result' }}</p>
  129. @if (provision.recoveryFailed()) {
  130. <button type="button" class="plans-banner-btn" (click)="provision.restorePending()">重新检查开通任务</button>
  131. @if (provision.pendingStartRetryAvailable()) {
  132. <button type="button" class="plans-banner-btn" [disabled]="provision.starting()" (click)="provision.retryPendingStart()">安全重试原申请</button>
  133. }
  134. }
  135. }
  136. <div class="plans-section-head">
  137. <h2>为下一步,准备合适的空间</h2>
  138. <p>个人专属 · 企业共享 · 按需增配</p>
  139. </div>
  140. <div class="plans-grid">
  141. @for (item of plans(); track item.code) {
  142. <article class="plan-card" [class.plan-card--featured]="item.recommended">
  143. @if (item.recommended) {
  144. <span class="plan-ribbon">推荐</span>
  145. }
  146. <div class="plan-icon">
  147. <i [class]="iconOf(item.code)" aria-hidden="true"></i>
  148. </div>
  149. <h3>{{ item.name }}</h3>
  150. <p class="plan-tagline">{{ item.tagline }}</p>
  151. <!-- 名额显示已用/上限(2026-12-03 用户反馈「看不到我的限额」);列表未载出时只显示上限 -->
  152. <p class="plan-quota">
  153. @if (live.hasData()) {
  154. <strong>{{ live.agents().length }}/{{ item.quota }}</strong>
  155. } @else {
  156. <strong>{{ item.quota }}</strong>
  157. }
  158. <span>{{ item.quotaLabel }}</span>
  159. </p>
  160. <div class="plan-price">
  161. <strong>价格待定</strong>
  162. @if (item.billingUnit) {
  163. <span>{{ item.billingUnit }}</span>
  164. }
  165. </div>
  166. <p class="plan-billing">{{ item.billingNote }}</p>
  167. <button
  168. type="button"
  169. class="plan-cta"
  170. [class.plan-cta--primary]="item.recommended"
  171. [disabled]="provision.startBlocked()"
  172. (click)="apply(item.code)"
  173. >
  174. <!-- 🔴 只在本档提交时转,不是所有卡片一起转 -->
  175. @if (provision.isStarting(item.code)) {
  176. <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
  177. 提交中…
  178. } @else {
  179. 立即开通
  180. }
  181. </button>
  182. <ul class="plan-features">
  183. @for (f of item.features; track f) {
  184. <li><i class="fa-solid fa-check" aria-hidden="true"></i><span>{{ f }}</span></li>
  185. }
  186. </ul>
  187. </article>
  188. }
  189. </div>
  190. <p class="plans-note">
  191. <i class="fa-solid fa-circle-info" aria-hidden="true"></i>
  192. <span>具体价格请咨询客服。提交申请后由工作人员联系确认,确认前不会产生费用。</span>
  193. </p>
  194. <app-renewal-guide />
  195. <!--
  196. 底部不再放「我的容器」入口卡(2026-12-03 用户反馈):
  197. 顶部状态条已有「管理容器」按钮,两个入口同页重复。
  198. -->
  199. <div class="plans-links">
  200. <section class="plans-link-card">
  201. <i class="fa-solid fa-shield-halved" aria-hidden="true"></i>
  202. <div>
  203. <h3>数据为你保留</h3>
  204. <p>试用结束后,开通套餐即可继续使用原有容器</p>
  205. </div>
  206. </section>
  207. </div>
  208. </div>
  209. <!--
  210. 🔴 全屏加载遮罩(2026-11-27)
  211. 用户反馈「点开通感觉像卡死」—— 请求要 1-3 秒,只有按钮变字在大屏上看不出来。
  212. 遮罩同时起两个作用:① 明确告知正在进行 ② 阻断误点
  213. -->
  214. <!--
  215. 开通命名确认弹窗(2026-12-03)。
  216. 🔴 不能复用 app-prompt-modal:/plans 是顶层路由、不在 shell 内。
  217. -->
  218. @if (confirmOpen()) {
  219. <app-provision-confirm
  220. [planName]="pendingPlanName()"
  221. [isOnboarding]="pendingIsOnboarding()"
  222. [quota]="pendingQuota()"
  223. [quotaUsed]="existingNames().length"
  224. [existingNames]="existingNames()"
  225. [busy]="submitting()"
  226. (confirm)="onNameConfirmed($event)"
  227. (cancel)="cancelConfirm()"
  228. />
  229. }
  230. @if (loadingHint(); as hint) {
  231. <app-loading-overlay [message]="hint.message" [hint]="hint.detail" />
  232. }
  233. `,
  234. styles: [`
  235. /* 名额已满提示(2026-12-03):内联在页面顶部,不遮挡操作 */
  236. .quota-full {
  237. display: flex;
  238. flex-direction: column;
  239. gap: var(--sp-1);
  240. margin: 0 0 var(--sp-4);
  241. padding: var(--sp-4);
  242. border: 1px solid var(--warning);
  243. border-radius: var(--r-md, 10px);
  244. background: var(--surface-2);
  245. color: var(--ink-2);
  246. font-size: var(--fs-13);
  247. }
  248. .quota-full p {
  249. margin: 0;
  250. line-height: 1.55;
  251. }
  252. .quota-full button {
  253. align-self: flex-start;
  254. min-height: 36px;
  255. margin-top: var(--sp-2);
  256. padding: 0 var(--sp-4);
  257. border: 1px solid var(--edge);
  258. border-radius: var(--r-sm, 6px);
  259. background: var(--surface);
  260. color: var(--ink);
  261. font: inherit;
  262. font-size: var(--fs-13);
  263. cursor: pointer;
  264. }
  265. :host {
  266. display: block;
  267. height: 100%;
  268. overflow-y: auto;
  269. }
  270. .plans-page {
  271. max-width: 1120px;
  272. margin: 0 auto;
  273. padding: var(--sp-8);
  274. }
  275. .plans-eyebrow {
  276. display: flex;
  277. align-items: center;
  278. gap: var(--sp-2);
  279. margin: 0 0 var(--sp-2);
  280. color: var(--muted);
  281. font-size: var(--fs-12);
  282. }
  283. .plans-head h1 {
  284. margin: 0;
  285. font-size: var(--fs-26);
  286. font-weight: 600;
  287. letter-spacing: -0.04em;
  288. }
  289. .plans-lead {
  290. margin: var(--sp-2) 0 0;
  291. color: var(--muted);
  292. font-size: var(--fs-14);
  293. }
  294. /* ---------- 横幅 ---------- */
  295. .plans-banner {
  296. display: flex;
  297. align-items: center;
  298. gap: var(--sp-5);
  299. margin: var(--sp-6) 0;
  300. padding: var(--sp-6);
  301. border: 1px solid var(--edge-strong);
  302. border-radius: var(--r-lg);
  303. background: var(--surface);
  304. }
  305. .plans-banner--pending {
  306. align-items: flex-start;
  307. border-color: var(--edge);
  308. background: var(--warning-subtle);
  309. }
  310. .plans-banner--pending > i {
  311. margin-top: 3px;
  312. color: var(--warning);
  313. }
  314. /* 真实阶段进度条:源自 Agent 写库的 step 记录,不是估算 */
  315. .plans-progress {
  316. width: 100%;
  317. max-width: 320px;
  318. height: 4px;
  319. margin-top: var(--sp-3);
  320. border-radius: 999px;
  321. background: var(--surface-2);
  322. overflow: hidden;
  323. }
  324. .plans-progress-bar {
  325. display: block;
  326. height: 100%;
  327. border-radius: inherit;
  328. background: var(--primary);
  329. transition: width 200ms cubic-bezier(0.2, 0, 0, 1);
  330. }
  331. @media (prefers-reduced-motion: reduce) {
  332. .plans-progress-bar {
  333. transition: none;
  334. }
  335. }
  336. .plans-banner-icon {
  337. display: grid;
  338. width: 48px;
  339. height: 48px;
  340. flex: none;
  341. place-items: center;
  342. border: 1px solid var(--edge);
  343. border-radius: var(--r-lg);
  344. background: var(--surface-2);
  345. color: var(--primary);
  346. font-size: var(--fs-20);
  347. }
  348. .plans-banner-body {
  349. flex: 1;
  350. min-width: 0;
  351. }
  352. .plans-banner h2 {
  353. display: flex;
  354. align-items: center;
  355. gap: var(--sp-3);
  356. margin: 0;
  357. font-size: var(--fs-20);
  358. font-weight: 600;
  359. letter-spacing: -0.02em;
  360. }
  361. .plans-banner h2 > span {
  362. padding: 1px 7px;
  363. border-radius: var(--r-sm);
  364. background: var(--success-subtle);
  365. color: var(--success);
  366. font-size: var(--fs-11);
  367. font-weight: 500;
  368. }
  369. .plans-banner p {
  370. margin: var(--sp-2) 0 0;
  371. color: var(--muted);
  372. font-size: var(--fs-13);
  373. }
  374. .plans-banner-btn {
  375. flex: none;
  376. min-height: 44px;
  377. padding: 0 var(--sp-5);
  378. border: 0;
  379. border-radius: var(--r-md);
  380. background: var(--primary);
  381. color: var(--primary-content);
  382. font: inherit;
  383. font-size: var(--fs-14);
  384. font-weight: 500;
  385. cursor: pointer;
  386. }
  387. /* ---------- 三列卡 ---------- */
  388. .plans-section-head {
  389. display: flex;
  390. align-items: baseline;
  391. justify-content: space-between;
  392. gap: var(--sp-4);
  393. margin-bottom: var(--sp-4);
  394. }
  395. .plans-section-head h2 {
  396. margin: 0;
  397. font-size: var(--fs-17);
  398. font-weight: 600;
  399. }
  400. .plans-section-head p {
  401. margin: 0;
  402. color: var(--muted);
  403. font-size: var(--fs-12);
  404. }
  405. .plans-grid {
  406. display: grid;
  407. grid-template-columns: repeat(3, minmax(0, 1fr));
  408. gap: var(--sp-4);
  409. }
  410. .plan-card {
  411. position: relative;
  412. display: flex;
  413. flex-direction: column;
  414. padding: var(--sp-6);
  415. border: 1px solid var(--edge);
  416. border-radius: var(--r-lg);
  417. background: var(--surface);
  418. }
  419. .plan-card--featured {
  420. border-color: var(--primary);
  421. box-shadow: inset 0 0 0 1px var(--primary);
  422. }
  423. .plan-ribbon {
  424. position: absolute;
  425. top: -11px;
  426. left: var(--sp-5);
  427. padding: 2px 9px;
  428. border-radius: var(--r-sm);
  429. background: var(--primary);
  430. color: var(--primary-content);
  431. font-size: var(--fs-11);
  432. white-space: nowrap;
  433. }
  434. .plan-icon {
  435. display: grid;
  436. width: 36px;
  437. height: 36px;
  438. margin-bottom: var(--sp-4);
  439. place-items: center;
  440. border: 1px solid var(--edge);
  441. border-radius: var(--r-md);
  442. background: var(--surface-2);
  443. color: var(--ink-2);
  444. }
  445. .plan-card h3 {
  446. margin: 0;
  447. font-size: var(--fs-20);
  448. font-weight: 600;
  449. }
  450. .plan-tagline {
  451. margin: 5px 0 0;
  452. color: var(--muted);
  453. font-size: var(--fs-13);
  454. }
  455. .plan-quota {
  456. display: flex;
  457. align-items: baseline;
  458. gap: 3px;
  459. margin: var(--sp-2, 8px) 0 0;
  460. line-height: 1.2;
  461. }
  462. .plan-quota strong {
  463. font-size: var(--fs-18);
  464. font-weight: 600;
  465. letter-spacing: -0.02em;
  466. }
  467. .plan-quota span {
  468. color: var(--muted);
  469. font-size: var(--fs-12);
  470. }
  471. .plan-price {
  472. display: flex;
  473. align-items: baseline;
  474. gap: 7px;
  475. margin: var(--sp-6) 0 var(--sp-1);
  476. }
  477. .plan-price strong {
  478. font-size: var(--fs-26);
  479. font-weight: 600;
  480. letter-spacing: -0.04em;
  481. }
  482. .plan-price span {
  483. color: var(--muted);
  484. font-size: var(--fs-12);
  485. }
  486. .plan-billing {
  487. min-height: 24px;
  488. margin: 0;
  489. color: var(--muted);
  490. font-size: var(--fs-12);
  491. }
  492. .plan-cta {
  493. width: 100%;
  494. min-height: 44px;
  495. margin-top: var(--sp-4);
  496. border: 1px solid var(--edge);
  497. border-radius: var(--r-md);
  498. background: var(--surface);
  499. color: var(--ink);
  500. font: inherit;
  501. font-size: var(--fs-14);
  502. font-weight: 500;
  503. cursor: pointer;
  504. }
  505. .plan-cta--primary {
  506. border-color: transparent;
  507. background: var(--primary);
  508. color: var(--primary-content);
  509. }
  510. .plan-cta:disabled {
  511. opacity: 0.5;
  512. cursor: not-allowed;
  513. }
  514. .plan-features {
  515. display: flex;
  516. flex-direction: column;
  517. gap: var(--sp-3);
  518. margin: var(--sp-6) 0 0;
  519. padding: var(--sp-5) 0 0;
  520. border-top: 1px solid var(--edge);
  521. list-style: none;
  522. }
  523. .plan-features li {
  524. display: flex;
  525. align-items: flex-start;
  526. gap: var(--sp-2);
  527. color: var(--ink-2);
  528. font-size: var(--fs-13);
  529. line-height: 1.6;
  530. }
  531. .plan-features i {
  532. margin-top: 4px;
  533. color: var(--muted);
  534. font-size: var(--fs-11);
  535. }
  536. .plans-code {
  537. max-height: 200px;
  538. overflow: auto;
  539. margin: var(--sp-3) 0 0;
  540. padding: var(--sp-3);
  541. border: 1px solid var(--edge);
  542. border-radius: var(--r-sm);
  543. background: var(--surface-2);
  544. color: var(--ink-2);
  545. font-family: ui-monospace, Consolas, monospace;
  546. font-size: var(--fs-12);
  547. line-height: 1.6;
  548. white-space: pre-wrap;
  549. overflow-wrap: anywhere;
  550. }
  551. .plans-error {
  552. display: flex;
  553. align-items: flex-start;
  554. gap: var(--sp-2);
  555. margin: 0 0 var(--sp-4);
  556. color: var(--danger);
  557. font-size: var(--fs-13);
  558. }
  559. .plans-note {
  560. display: flex;
  561. align-items: flex-start;
  562. gap: var(--sp-2);
  563. margin: var(--sp-5) 0 var(--sp-8);
  564. color: var(--muted);
  565. font-size: var(--fs-12);
  566. }
  567. .plans-note > i {
  568. margin-top: 3px;
  569. }
  570. /* ---------- 当前资产概览(2026-12-02) ---------- */
  571. .plans-status {
  572. display: grid;
  573. grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  574. gap: var(--sp-5);
  575. align-items: center;
  576. margin: 0 0 var(--sp-5);
  577. padding: var(--sp-4) var(--sp-5);
  578. border: 1px solid var(--edge);
  579. border-radius: var(--r-md);
  580. background: var(--surface);
  581. }
  582. .plans-status-item {
  583. display: flex;
  584. flex-direction: column;
  585. gap: 2px;
  586. min-width: 0;
  587. }
  588. .plans-status-label {
  589. font-size: var(--fs-12);
  590. color: var(--muted);
  591. }
  592. .plans-status-value {
  593. font-size: var(--fs-20);
  594. font-weight: 600;
  595. color: var(--ink);
  596. font-variant-numeric: tabular-nums;
  597. }
  598. .plans-status-hint {
  599. overflow: hidden;
  600. text-overflow: ellipsis;
  601. white-space: nowrap;
  602. font-size: var(--fs-12);
  603. color: var(--faint);
  604. }
  605. .plans-status-actions {
  606. display: flex;
  607. gap: var(--sp-2);
  608. }
  609. .plans-status-btn {
  610. display: inline-flex;
  611. align-items: center;
  612. gap: var(--sp-1);
  613. min-height: 40px;
  614. padding: 0 var(--sp-4);
  615. border: 1px solid var(--edge);
  616. border-radius: var(--r-md);
  617. background: var(--surface);
  618. color: var(--ink);
  619. font: inherit;
  620. font-size: var(--fs-13);
  621. cursor: pointer;
  622. }
  623. .plans-status-btn:hover {
  624. background: var(--surface-hover);
  625. }
  626. .plans-status-btn--primary {
  627. border-color: var(--primary);
  628. background: var(--primary);
  629. color: var(--inverse);
  630. }
  631. .plans-status-btn--primary:hover {
  632. background: var(--primary);
  633. opacity: 0.92;
  634. }
  635. .plans-status-btn:disabled {
  636. opacity: 0.5;
  637. cursor: not-allowed;
  638. }
  639. @media (max-width: 1100px) {
  640. .plans-status {
  641. grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  642. }
  643. .plans-status-actions {
  644. grid-column: 1 / -1;
  645. }
  646. }
  647. /* ---------- 底部链接 ---------- */
  648. .plans-links {
  649. display: grid;
  650. grid-template-columns: 1fr 1fr;
  651. gap: var(--sp-4);
  652. }
  653. .plans-link-card {
  654. display: flex;
  655. align-items: center;
  656. gap: var(--sp-3);
  657. padding: var(--sp-4) var(--sp-5);
  658. border: 1px solid var(--edge);
  659. border-radius: var(--r-md);
  660. background: var(--surface);
  661. }
  662. .plans-link-card > i {
  663. color: var(--muted);
  664. font-size: var(--fs-17);
  665. }
  666. .plans-link-card > div {
  667. flex: 1;
  668. min-width: 0;
  669. }
  670. .plans-link-card h3 {
  671. margin: 0;
  672. font-size: var(--fs-14);
  673. font-weight: 500;
  674. }
  675. .plans-link-card p {
  676. margin: 3px 0 0;
  677. color: var(--muted);
  678. font-size: var(--fs-12);
  679. }
  680. .plans-link-btn {
  681. flex: none;
  682. min-height: 44px;
  683. padding: 0 var(--sp-4);
  684. border: 1px solid var(--edge);
  685. border-radius: var(--r-md);
  686. background: var(--surface);
  687. color: var(--ink);
  688. font: inherit;
  689. font-size: var(--fs-13);
  690. cursor: pointer;
  691. }
  692. `,
  693. ],
  694. })
  695. export class DkPlansPage implements OnInit {
  696. protected readonly plan = inject(PlanService);
  697. protected readonly live = inject(LiveService);
  698. /* 命名确认弹窗状态(2026-12-03) */
  699. protected readonly confirmOpen = signal(false);
  700. protected readonly pendingCode = signal<PaidPlanCode | 'trial' | null>(null);
  701. protected readonly submitting = signal(false);
  702. /** 名额已满提示(2026-12-03)。null = 不显示 */
  703. protected readonly quotaFull = signal<{ plan: string; quota: number } | null>(null);
  704. protected readonly provision = inject(ProvisionService);
  705. private readonly router = inject(Router);
  706. ngOnInit(): void {
  707. void this.provision.restorePending();
  708. /*
  709. * 配额预检与重名校验都依赖容器列表(2026-12-03):
  710. * /plans 是顶层路由不在 shell 内,没人替本页拉 live,
  711. * 不主动加载 existingNames() 永远是空 —— 配额预检形同虚设。
  712. */
  713. void this.live.ensureLoaded();
  714. }
  715. protected readonly plans = computed(() => this.plan.catalog);
  716. /** 运行中的容器数(资产概览用;状态口径与通讯录一致) */
  717. protected readonly runningCount = computed(
  718. () => this.live.agents().filter((a) => a.status === 'running' || a.status === 'idle').length,
  719. );
  720. /**
  721. * 当前套餐名。
  722. *
  723. * 🔴 不从容器数量反推档位(2026-12-02 自查):2 个容器可能是「入门版 + 加购」,
  724. * 也可能是进阶版送的名额,数量推不出套餐 —— 猜错比不说更糟。
  725. * PlanService 暂无「当前订阅」字段,这里如实显示「已开通」;
  726. * 接入订阅接口后替换为真实套餐名。
  727. */
  728. protected readonly currentPlanName = computed(() =>
  729. this.live.agents().length > 0 ? '已开通' : '尚未开通',
  730. );
  731. /**
  732. * 全屏加载遮罩的文案(null = 不显示)。
  733. *
  734. * 🔴 区分两种慢操作,因为用户等待时的心理预期完全不同:
  735. * · 试用档生成提示词 → 要建 Matrix 身份,首次可能需要十秒左右
  736. * · 进阶/企业开通 → 只受理,很快,之后跳等待页
  737. */
  738. protected readonly loadingHint = computed<{ message: string; detail: string } | null>(() => {
  739. /*
  740. * 🔴 restoring 不再上全屏遮罩(2026-12-03 用户实测反馈):
  741. * 开通中离开再回 /plans,每次进页都重放一遍「正在检查开通任务…」过场动画。
  742. * restore 本来就是静默找回——完了有任务就显示 plans-banner,没有就无事发生。
  743. */
  744. const p = this.provision.startingPlan();
  745. if (!p) return null;
  746. if (p === 'trial' || p === 'starter') {
  747. return { message: '正在准备接入信息…', detail: '首次生成可能需要 10 秒左右,请稍候' };
  748. }
  749. return { message: '正在提交开通申请…', detail: '马上就好' };
  750. });
  751. protected iconOf(code: PaidPlanCode): string {
  752. switch (code) {
  753. case 'starter':
  754. return 'fa-solid fa-server';
  755. case 'advanced':
  756. return 'fa-solid fa-wand-magic-sparkles';
  757. case 'enterprise':
  758. return 'fa-solid fa-building';
  759. default:
  760. return 'fa-solid fa-cube';
  761. }
  762. }
  763. /**
  764. * 发起开通。
  765. *
  766. * 🔴 只发起请求,不承诺结果:
  767. * · 试用/入门 → 后端返回接入提示词(用户自己的容器)
  768. * · 进阶/企业 → 后端真实创建,进入轮询态
  769. */
  770. /**
  771. * 发起开通(2026-11-27 改造)
  772. *
  773. * 与移动端同源逻辑:试用/入门留在本页给提示词,进阶/企业跳全屏等待页。
  774. */
  775. protected async apply(code: PaidPlanCode | 'trial'): Promise<void> {
  776. if (this.provision.isRunning()) return;
  777. /*
  778. * 配额判断依赖容器列表;首载还没落地时 existingNames() 是空数组,
  779. * 直接判会永远放行(2026-12-03 用户实测:已有 2 个容器仍没看到名额提示)。
  780. * 先等首载完成再校验;加载失败则由服务端配额校验兜底。
  781. */
  782. await this.live.ensureLoaded();
  783. /*
  784. * 名额已满就别让用户填名字了(2026-12-03)。
  785. * 在弹窗之前拦,而不是等提交后云函数返回 409 ——
  786. * 「认真填完名字才被告知名额已满」是很差的体验。
  787. */
  788. const quota = code === 'trial' ? 1 : (this.plan.planOf(code as never)?.quota ?? 0);
  789. if (quota > 0 && this.existingNames().length >= quota) {
  790. this.quotaFull.set({ plan: this.plan.planOf(code as never)?.name || '该套餐', quota });
  791. return;
  792. }
  793. /* 先弹命名确认(用户裁决 2026-12-03),不再直接提交 */
  794. this.pendingCode.set(code);
  795. this.confirmOpen.set(true);
  796. }
  797. /** 命名确认后真正提交;`name` 已由弹窗校验并 NFKC 归一化 */
  798. protected async onNameConfirmed(name: string): Promise<void> {
  799. const code = this.pendingCode();
  800. if (!code) return;
  801. this.submitting.set(true);
  802. try {
  803. const result = await this.provision.start(code, name);
  804. this.confirmOpen.set(false);
  805. this.pendingCode.set(null);
  806. if (result?.mode === 'provision' && result.jobId) {
  807. await this.router.navigateByUrl(`/provision?jobId=${encodeURIComponent(result.jobId)}`, {
  808. replaceUrl: true,
  809. });
  810. }
  811. } catch {
  812. /*
  813. * 提交抛错也要关弹窗(2026-12-03):否则弹窗永远盖在页面上,
  814. * 页面级的错误提示(plans-error)用户根本看不到。
  815. * 错误本身由 ProvisionService.error() 呈现在页面上。
  816. */
  817. this.confirmOpen.set(false);
  818. this.pendingCode.set(null);
  819. } finally {
  820. this.submitting.set(false);
  821. }
  822. }
  823. protected cancelConfirm(): void {
  824. this.confirmOpen.set(false);
  825. this.pendingCode.set(null);
  826. }
  827. protected readonly pendingPlanName = computed(() => {
  828. const c = this.pendingCode();
  829. if (!c) return '';
  830. if (c === 'trial') return '试用';
  831. return this.plan.planOf(c as PaidPlanCode)?.name ?? '套餐';
  832. });
  833. protected readonly pendingIsOnboarding = computed(() => {
  834. const c = this.pendingCode();
  835. return c === 'trial' || c === 'starter';
  836. });
  837. protected readonly pendingQuota = computed(() => {
  838. const c = this.pendingCode();
  839. if (!c || c === 'trial') return 1;
  840. return this.plan.planOf(c as PaidPlanCode)?.quota ?? 0;
  841. });
  842. protected readonly existingNames = computed(() =>
  843. this.live.agents().map((a) => a.name).filter((n): n is string => !!n),
  844. );
  845. protected readonly suggestedName = computed(() => suggestContainerName(this.existingNames()));
  846. protected go(path: string): void {
  847. void this.router.navigateByUrl(path);
  848. }
  849. }