|
|
@@ -0,0 +1,351 @@
|
|
|
+import {
|
|
|
+ ChangeDetectionStrategy,
|
|
|
+ Component,
|
|
|
+ ElementRef,
|
|
|
+ computed,
|
|
|
+ effect,
|
|
|
+ input,
|
|
|
+ output,
|
|
|
+ signal,
|
|
|
+ viewChild,
|
|
|
+} from '@angular/core';
|
|
|
+import {
|
|
|
+ CONTAINER_NAME_MAX,
|
|
|
+ normalizeContainerName,
|
|
|
+ suggestContainerName,
|
|
|
+ validateContainerName,
|
|
|
+} from './container-name';
|
|
|
+
|
|
|
+/**
|
|
|
+ * 开通容器前的**命名确认弹窗**(2026-12-03)。
|
|
|
+ *
|
|
|
+ * ## 为什么是独立组件,不复用 PromptModalService
|
|
|
+ *
|
|
|
+ * `/plans` 是顶层路由(`app.routes.ts`),**不在 shell 内**;
|
|
|
+ * 而 `app-prompt-modal` 只挂在 shell 模板上,所以在套餐页根本渲染不出来。
|
|
|
+ * 移动端 agent 页也因此自己写了一套本地弹层,原因相同。
|
|
|
+ *
|
|
|
+ * 本组件自带遮罩与对话框,挂在套餐页模板里即可,不依赖任何外壳。
|
|
|
+ *
|
|
|
+ * ## 为什么必须有这一步
|
|
|
+ *
|
|
|
+ * 原来容器名是代码写死的(`我的${plan.name}`),开几个就重几个,
|
|
|
+ * 用户既不能命名、也无从确认自己要开的是什么。服务端也只按 40 字截断、
|
|
|
+ * 不做任何校验,空名、换行、重名都能写进 SOUL.md 和 Matrix localpart。
|
|
|
+ *
|
|
|
+ * ## 结构
|
|
|
+ *
|
|
|
+ * ```
|
|
|
+ * ┌──────────────────────────────────┐
|
|
|
+ * │ 为容器起个名字 │
|
|
|
+ * │ [输入框 ] 12/24│
|
|
|
+ * │ 错误提示(实时) │
|
|
|
+ * │ ───────────────────────────── │
|
|
|
+ * │ 进阶版 · 将创建 1 个容器 · 名额 2/3│
|
|
|
+ * │ 预计 3-8 分钟,可离开本页 │
|
|
|
+ * │ ───────────────────────────── │
|
|
|
+ * │ [取消] [确认开通] │
|
|
|
+ * └──────────────────────────────────┘
|
|
|
+ * ```
|
|
|
+ */
|
|
|
+@Component({
|
|
|
+ selector: 'app-provision-confirm',
|
|
|
+ changeDetection: ChangeDetectionStrategy.OnPush,
|
|
|
+ template: `
|
|
|
+ <div class="mask" (click)="onMaskClick()"></div>
|
|
|
+ <div class="dialog" role="dialog" aria-modal="true" aria-labelledby="pc-title">
|
|
|
+ <h2 id="pc-title" class="title">为容器起个名字</h2>
|
|
|
+ <p class="subtitle">开通后也能在容器设置里改名。</p>
|
|
|
+
|
|
|
+ <label class="field">
|
|
|
+ <input
|
|
|
+ #nameInput
|
|
|
+ type="text"
|
|
|
+ class="input"
|
|
|
+ [class.input--error]="errorText() !== null"
|
|
|
+ [attr.maxlength]="max"
|
|
|
+ [attr.aria-invalid]="errorText() !== null"
|
|
|
+ [attr.aria-describedby]="errorText() ? 'pc-error' : 'pc-hint'"
|
|
|
+ [placeholder]="placeholder()"
|
|
|
+ [value]="name()"
|
|
|
+ (input)="onInput($event)"
|
|
|
+ (keydown.enter)="submit()"
|
|
|
+ (keydown.escape)="cancel.emit()"
|
|
|
+ autocomplete="off"
|
|
|
+ spellcheck="false"
|
|
|
+ />
|
|
|
+ <span class="counter" [class.counter--warn]="length() > max - 4">{{ length() }}/{{ max }}</span>
|
|
|
+ </label>
|
|
|
+
|
|
|
+ @if (errorText(); as err) {
|
|
|
+ <p id="pc-error" class="error" role="alert">{{ err }}</p>
|
|
|
+ } @else {
|
|
|
+ <p id="pc-hint" class="hint">2-24 个字,可用中文、英文、数字、下划线和短横线</p>
|
|
|
+ }
|
|
|
+
|
|
|
+ <div class="preview">
|
|
|
+ <i class="fa-solid" [class]="isOnboarding() ? 'fa-key' : 'fa-server'" aria-hidden="true"></i>
|
|
|
+ <span>{{ previewText() }}</span>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <div class="actions">
|
|
|
+ <button type="button" class="btn" [disabled]="busy()" (click)="cancel.emit()">取消</button>
|
|
|
+ <button
|
|
|
+ type="button"
|
|
|
+ class="btn btn--primary"
|
|
|
+ [disabled]="busy() || !canSubmit()"
|
|
|
+ (click)="submit()"
|
|
|
+ >
|
|
|
+ @if (busy()) {
|
|
|
+ <i class="fa-solid fa-circle-notch fa-spin" aria-hidden="true"></i>
|
|
|
+ 提交中…
|
|
|
+ } @else {
|
|
|
+ 确认开通
|
|
|
+ }
|
|
|
+ </button>
|
|
|
+ </div>
|
|
|
+ </div>
|
|
|
+ `,
|
|
|
+ styles: [
|
|
|
+ `
|
|
|
+ :host {
|
|
|
+ position: fixed;
|
|
|
+ inset: 0;
|
|
|
+ z-index: var(--z-modal, 1100);
|
|
|
+ display: grid;
|
|
|
+ place-items: center;
|
|
|
+ padding: var(--sp-4);
|
|
|
+ }
|
|
|
+ .mask {
|
|
|
+ position: absolute;
|
|
|
+ inset: 0;
|
|
|
+ background: var(--overlay, rgb(0 0 0 / 45%));
|
|
|
+ animation: pc-fade var(--motion-fast, 150ms) var(--ease-standard, ease-out);
|
|
|
+ }
|
|
|
+ .dialog {
|
|
|
+ position: relative;
|
|
|
+ width: min(420px, 100%);
|
|
|
+ max-height: calc(100dvh - var(--sp-8));
|
|
|
+ overflow-y: auto;
|
|
|
+ padding: var(--sp-5);
|
|
|
+ border: 1px solid var(--edge);
|
|
|
+ border-radius: var(--r-lg, 14px);
|
|
|
+ background: var(--surface);
|
|
|
+ box-shadow: var(--shadow-overlay, 0 16px 48px rgb(0 0 0 / 22%));
|
|
|
+ animation: pc-in var(--motion-normal, 220ms) var(--ease-standard, ease-out);
|
|
|
+ }
|
|
|
+ .title {
|
|
|
+ margin: 0 0 var(--sp-1);
|
|
|
+ font-size: var(--fs-17);
|
|
|
+ font-weight: 600;
|
|
|
+ color: var(--ink);
|
|
|
+ }
|
|
|
+ .subtitle {
|
|
|
+ margin: 0 0 var(--sp-4);
|
|
|
+ font-size: var(--fs-13);
|
|
|
+ color: var(--muted);
|
|
|
+ }
|
|
|
+ .field {
|
|
|
+ position: relative;
|
|
|
+ display: block;
|
|
|
+ }
|
|
|
+ .input {
|
|
|
+ width: 100%;
|
|
|
+ min-height: 44px;
|
|
|
+ padding: 0 var(--sp-11) 0 var(--sp-3);
|
|
|
+ border: 1px solid var(--edge-strong);
|
|
|
+ border-radius: var(--r-md, 10px);
|
|
|
+ background: var(--canvas);
|
|
|
+ color: var(--ink);
|
|
|
+ font: inherit;
|
|
|
+ font-size: 16px; /* iOS 输入框低于 16px 会触发缩放 */
|
|
|
+ outline: none;
|
|
|
+ transition: border-color var(--motion-fast, 150ms) var(--ease-standard, ease-out);
|
|
|
+ }
|
|
|
+ .input:focus {
|
|
|
+ border-color: var(--primary);
|
|
|
+ box-shadow: 0 0 0 3px var(--primary-subtle, rgb(0 0 0 / 8%));
|
|
|
+ }
|
|
|
+ .input--error {
|
|
|
+ border-color: var(--danger);
|
|
|
+ }
|
|
|
+ .counter {
|
|
|
+ position: absolute;
|
|
|
+ right: var(--sp-3);
|
|
|
+ top: 50%;
|
|
|
+ transform: translateY(-50%);
|
|
|
+ color: var(--faint);
|
|
|
+ font-size: var(--fs-12);
|
|
|
+ font-variant-numeric: tabular-nums;
|
|
|
+ pointer-events: none;
|
|
|
+ }
|
|
|
+ .counter--warn {
|
|
|
+ color: var(--warning);
|
|
|
+ }
|
|
|
+ .error,
|
|
|
+ .hint {
|
|
|
+ margin: var(--sp-2) 0 0;
|
|
|
+ font-size: var(--fs-12);
|
|
|
+ line-height: 1.5;
|
|
|
+ }
|
|
|
+ .error {
|
|
|
+ color: var(--danger);
|
|
|
+ }
|
|
|
+ .hint {
|
|
|
+ color: var(--faint);
|
|
|
+ }
|
|
|
+ .preview {
|
|
|
+ display: flex;
|
|
|
+ align-items: flex-start;
|
|
|
+ gap: var(--sp-2);
|
|
|
+ margin: var(--sp-4) 0 0;
|
|
|
+ padding: var(--sp-3);
|
|
|
+ border-radius: var(--r-md, 10px);
|
|
|
+ background: var(--surface-2);
|
|
|
+ color: var(--ink-2);
|
|
|
+ font-size: var(--fs-13);
|
|
|
+ line-height: 1.55;
|
|
|
+ }
|
|
|
+ .preview i {
|
|
|
+ margin-top: 2px;
|
|
|
+ flex: none;
|
|
|
+ color: var(--primary);
|
|
|
+ }
|
|
|
+ .actions {
|
|
|
+ display: flex;
|
|
|
+ justify-content: flex-end;
|
|
|
+ gap: var(--sp-2);
|
|
|
+ margin-top: var(--sp-5);
|
|
|
+ }
|
|
|
+ .btn {
|
|
|
+ display: inline-flex;
|
|
|
+ align-items: center;
|
|
|
+ justify-content: center;
|
|
|
+ gap: var(--sp-1);
|
|
|
+ min-height: 44px;
|
|
|
+ padding: 0 var(--sp-5);
|
|
|
+ border: 1px solid var(--edge);
|
|
|
+ border-radius: var(--r-md, 10px);
|
|
|
+ background: var(--surface);
|
|
|
+ color: var(--ink);
|
|
|
+ font: inherit;
|
|
|
+ font-size: var(--fs-14);
|
|
|
+ cursor: pointer;
|
|
|
+ transition: background-color var(--motion-fast, 150ms) var(--ease-standard, ease-out);
|
|
|
+ }
|
|
|
+ .btn:hover:not(:disabled) {
|
|
|
+ background: var(--surface-hover);
|
|
|
+ }
|
|
|
+ .btn--primary {
|
|
|
+ border-color: var(--primary);
|
|
|
+ background: var(--primary);
|
|
|
+ color: var(--inverse);
|
|
|
+ }
|
|
|
+ .btn--primary:hover:not(:disabled) {
|
|
|
+ background: var(--primary);
|
|
|
+ opacity: 0.92;
|
|
|
+ }
|
|
|
+ .btn:disabled {
|
|
|
+ opacity: 0.5;
|
|
|
+ cursor: not-allowed;
|
|
|
+ }
|
|
|
+ @keyframes pc-fade {
|
|
|
+ from {
|
|
|
+ opacity: 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @keyframes pc-in {
|
|
|
+ from {
|
|
|
+ opacity: 0;
|
|
|
+ transform: translateY(8px) scale(0.98);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @media (prefers-reduced-motion: reduce) {
|
|
|
+ .mask,
|
|
|
+ .dialog {
|
|
|
+ animation: none;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ `,
|
|
|
+ ],
|
|
|
+})
|
|
|
+export class ProvisionConfirmComponent {
|
|
|
+ /** 套餐名,用于预览文案 */
|
|
|
+ readonly planName = input.required<string>();
|
|
|
+ /** 是否试用/入门(不建平台容器,只生成接入提示词) */
|
|
|
+ readonly isOnboarding = input(false);
|
|
|
+ /** 配额上限(进阶 3 / 企业 5;试用/入门为 1) */
|
|
|
+ readonly quota = input(0);
|
|
|
+ /** 当前已用数量 */
|
|
|
+ readonly quotaUsed = input(0);
|
|
|
+ /** 已有容器名,用于默认值与重名校验 */
|
|
|
+ readonly existingNames = input<readonly string[]>([]);
|
|
|
+ /** 提交中 */
|
|
|
+ readonly busy = input(false);
|
|
|
+
|
|
|
+ /** 确认:输出**规范化后**的名称 */
|
|
|
+ readonly confirm = output<string>();
|
|
|
+ readonly cancel = output<void>();
|
|
|
+
|
|
|
+ private readonly inputEl = viewChild<ElementRef<HTMLInputElement>>('nameInput');
|
|
|
+
|
|
|
+ protected readonly max = CONTAINER_NAME_MAX;
|
|
|
+ protected readonly name = signal('');
|
|
|
+ /** 用户是否已输入过(未输入前不显示「至少 2 个字」的报错,避免一打开就红) */
|
|
|
+ private readonly touched = signal(false);
|
|
|
+
|
|
|
+ protected readonly length = computed(() => [...this.name()].length);
|
|
|
+
|
|
|
+ protected readonly validationError = computed(() =>
|
|
|
+ validateContainerName(this.name(), { existing: this.existingNames() }),
|
|
|
+ );
|
|
|
+
|
|
|
+ /** 显示的错误:只有用户动过之后才显示 */
|
|
|
+ protected readonly errorText = computed(() => (this.touched() ? this.validationError() : null));
|
|
|
+
|
|
|
+ protected readonly canSubmit = computed(() => this.validationError() === null && this.name().trim().length > 0);
|
|
|
+
|
|
|
+ protected readonly placeholder = computed(() => suggestContainerName(this.existingNames()));
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 预览文案(用户裁决「加一行说明」)。
|
|
|
+ *
|
|
|
+ * 两条路径说清楚区别:试用/入门**不建平台容器**,只是生成提示词;
|
|
|
+ * 进阶/企业才是真创建。写错会让用户以为试用也要等三分钟。
|
|
|
+ */
|
|
|
+ protected readonly previewText = computed(() => {
|
|
|
+ const quotaText = this.quota() > 0 ? ` · 名额 ${this.quotaUsed()}/${this.quota()}` : '';
|
|
|
+ if (this.isOnboarding()) {
|
|
|
+ return `${this.planName()} · 生成接入提示词 · 将创建 1 条容器记录${quotaText}`;
|
|
|
+ }
|
|
|
+ return `${this.planName()} · 将创建 1 个容器${quotaText} · 预计 3-8 分钟,可离开本页`;
|
|
|
+ });
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+ /* 打开即聚焦并全选默认名,用户可直接输入覆盖 */
|
|
|
+ effect(() => {
|
|
|
+ const el = this.inputEl()?.nativeElement;
|
|
|
+ if (!el) return;
|
|
|
+ el.value = this.placeholder();
|
|
|
+ this.name.set(this.placeholder());
|
|
|
+ queueMicrotask(() => {
|
|
|
+ el.focus();
|
|
|
+ el.select();
|
|
|
+ });
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ protected onInput(e: Event): void {
|
|
|
+ this.touched.set(true);
|
|
|
+ this.name.set(normalizeContainerName((e.target as HTMLInputElement).value));
|
|
|
+ }
|
|
|
+
|
|
|
+ protected submit(): void {
|
|
|
+ if (this.busy() || !this.canSubmit()) return;
|
|
|
+ this.confirm.emit(this.name());
|
|
|
+ }
|
|
|
+
|
|
|
+ protected onMaskClick(): void {
|
|
|
+ if (!this.busy()) this.cancel.emit();
|
|
|
+ }
|
|
|
+}
|