Browse Source

feat: add sessionToken display + copy button for OpenClaw integration

gangvy 5 months ago
parent
commit
e4b260d313
3 changed files with 31 additions and 0 deletions
  1. 3 0
      src/app/app.html
  2. 15 0
      src/app/app.scss
  3. 13 0
      src/app/app.ts

+ 3 - 0
src/app/app.html

@@ -7,6 +7,9 @@
   <div class="subtitle">API 服务充值</div>
   <div class="user-bar" *ngIf="loggedInUser">
     <span class="user-badge">👤 已登录</span>
+    <button class="token-copy-btn" (click)="copyToken()" *ngIf="sessionToken">
+      {{tokenCopied ? '✅ 已复制' : '📋 复制Token'}}
+    </button>
   </div>
 </div>
 

+ 15 - 0
src/app/app.scss

@@ -114,6 +114,21 @@
   border: 1px solid rgba(0,255,136,0.2);
   border-radius: 20px;
 }
+.page-header .token-copy-btn {
+  padding: 4px 12px;
+  font-size: 12px;
+  font-weight: 600;
+  color: var(--neon);
+  background: rgba(0,212,255,0.08);
+  border: 1px solid rgba(0,212,255,0.2);
+  border-radius: 20px;
+  cursor: pointer;
+  transition: all 0.2s;
+}
+.page-header .token-copy-btn:hover {
+  background: rgba(0,212,255,0.15);
+  border-color: var(--neon);
+}
 
 /* ─── Main Container ─── */
 .main-container {

+ 13 - 0
src/app/app.ts

@@ -59,8 +59,10 @@ export class App implements OnInit {
   // Login state
   needLogin = false;
   loggedInUser: string = '';
+  sessionToken: string = '';
   apigList: ApigData[] = [];
   apigListLoading = false;
+  tokenCopied = false;
 
   // State
   apig: ApigData | null = null;
@@ -116,6 +118,7 @@ export class App implements OnInit {
       console.log('[AUTH] 从 localStorage 恢复用户:', cachedUserId);
       this.userId = cachedUserId;
       this.loggedInUser = cachedUserId;
+      this.sessionToken = cachedToken;
       // 后台验证 token 是否还有效
       this.validateCachedToken(cachedToken, cachedUserId);
       if (this.apigId) {
@@ -155,6 +158,7 @@ export class App implements OnInit {
     console.log('[AUTH] 登录成功, userId:', event.userId);
     this.userId = event.userId;
     this.loggedInUser = event.userId;
+    this.sessionToken = event.sessionToken;
     this.needLogin = false;
     this.errorMsg = '';
 
@@ -200,6 +204,15 @@ export class App implements OnInit {
     window.location.href = url.toString();
   }
 
+  copyToken(): void {
+    if (!this.sessionToken) return;
+    navigator.clipboard.writeText(this.sessionToken).then(() => {
+      this.tokenCopied = true;
+      this.cdr.detectChanges();
+      setTimeout(() => { this.tokenCopied = false; this.cdr.detectChanges(); }, 2000);
+    });
+  }
+
   // ─── Load APIG Info ───
   async loadApig(): Promise<void> {
     try {