more interactive refresh and ux improvements
This commit is contained in:
1 parent
3f834ebd3d
commit
6afd4647ae
5 files changed
+234
-61
No files matched your search
Generated
+8
-8
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "getdeepin-quota",
|
"name": "getdeepin-quota",
|
||||||
"version": "0.0.1",
|
"version": "0.1.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "getdeepin-quota",
|
"name": "getdeepin-quota",
|
||||||
"version": "0.0.1",
|
"version": "0.1.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/node": "^20.10.0",
|
"@types/node": "^20.10.0",
|
||||||
"@types/vscode": "^1.85.0",
|
"@types/vscode": "^1.85.0",
|
||||||
@@ -17,9 +17,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/node": {
|
"node_modules/@types/node": {
|
||||||
"version": "20.19.39",
|
"version": "20.19.40",
|
||||||
"resolved": "https://registry.npmmirror.com/@types/node/-/node-20.19.39.tgz",
|
"resolved": "https://registry.npmmirror.com/@types/node/-/node-20.19.40.tgz",
|
||||||
"integrity": "sha512-orrrD74MBUyK8jOAD/r0+lfa1I2MO6I+vAkmAWzMYbCcgrN4lCrmK52gRFQq/JRxfYPfonkr4b0jcY7Olqdqbw==",
|
"integrity": "sha512-xxx6M2IpSTnnKcR0cMvIiohkiCx20/oRPtWGbenFygKCGl3zqUzdNjQ/1V4solq1LU+dgv0nQzeGOuqkqZGg0Q==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
@@ -27,9 +27,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@types/vscode": {
|
"node_modules/@types/vscode": {
|
||||||
"version": "1.116.0",
|
"version": "1.118.0",
|
||||||
"resolved": "https://registry.npmmirror.com/@types/vscode/-/vscode-1.116.0.tgz",
|
"resolved": "https://registry.npmmirror.com/@types/vscode/-/vscode-1.118.0.tgz",
|
||||||
"integrity": "sha512-sYHp4MO6BqJ2PD7Hjt0hlIS3tMaYsVPJrd0RUjDJ8HtOYnyJIEej0bLSccM8rE77WrC+Xox/kdBwEFDO8MsxNA==",
|
"integrity": "sha512-Ah6eTlqDcwIMELEVwQMO++rJAFBRz/oLluLD/vWdYrH1KuI9kfpaM+7pg0OvvascgcJy+ghLCERAYouM4QbzGw==",
|
||||||
"dev": true,
|
"dev": true,
|
||||||
"license": "MIT"
|
"license": "MIT"
|
||||||
},
|
},
|
||||||
|
|||||||
+1
-1
@@ -2,7 +2,7 @@
|
|||||||
"name": "getdeepin-quota",
|
"name": "getdeepin-quota",
|
||||||
"displayName": "GetDeepin AI Quota",
|
"displayName": "GetDeepin AI Quota",
|
||||||
"description": "显示大模型资源用量情况",
|
"description": "显示大模型资源用量情况",
|
||||||
"version": "0.0.3",
|
"version": "0.1.0",
|
||||||
"publisher": "getdeepin",
|
"publisher": "getdeepin",
|
||||||
"repository": "https://gitlabwh.uniontech.com/wangzichong/vscode-getdeepin-quota",
|
"repository": "https://gitlabwh.uniontech.com/wangzichong/vscode-getdeepin-quota",
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
+11
-6
@@ -48,6 +48,10 @@ export class AuthService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type FetchQuotaResult =
|
||||||
|
| { ok: true; response: Response }
|
||||||
|
| { ok: false; error: string };
|
||||||
|
|
||||||
export class QuotaService {
|
export class QuotaService {
|
||||||
private authService: AuthService;
|
private authService: AuthService;
|
||||||
|
|
||||||
@@ -55,9 +59,9 @@ export class QuotaService {
|
|||||||
this.authService = authService;
|
this.authService = authService;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchQuota(): Promise<Response | null> {
|
async fetchQuota(): Promise<FetchQuotaResult> {
|
||||||
if (!this.authService.isLoggedIn()) {
|
if (!this.authService.isLoggedIn()) {
|
||||||
return null;
|
return { ok: false, error: '未设置 Token' };
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -69,17 +73,18 @@ export class QuotaService {
|
|||||||
|
|
||||||
if (response.status === 401 || response.status === 403) {
|
if (response.status === 401 || response.status === 403) {
|
||||||
await this.authService.logout();
|
await this.authService.logout();
|
||||||
return null;
|
return { ok: false, error: 'Token 无效或已过期' };
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
return null;
|
return { ok: false, error: `请求失败(HTTP ${response.status})` };
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return { ok: true, response };
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fetch quota failed:', error);
|
console.error('Fetch quota failed:', error);
|
||||||
return null;
|
const message = error instanceof Error ? error.message : String(error);
|
||||||
|
return { ok: false, error: `网络请求失败:${message}` };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+51
-14
@@ -9,6 +9,20 @@ let authService: AuthService;
|
|||||||
let quotaService: QuotaService;
|
let quotaService: QuotaService;
|
||||||
let statusBar: StatusBarManager;
|
let statusBar: StatusBarManager;
|
||||||
let currentQuota: QuotaDisplay | null = null;
|
let currentQuota: QuotaDisplay | null = null;
|
||||||
|
let lastRefreshAt: Date | null = null;
|
||||||
|
let lastRefreshError: string | null = null;
|
||||||
|
|
||||||
|
function getConfiguredBaseUrl(): string {
|
||||||
|
const config = vscode.workspace.getConfiguration('getdeepin-quota');
|
||||||
|
const url = config.get<string>('baseUrl', 'https://ai.getdeepin.org/');
|
||||||
|
return url.endsWith('/') ? url : `${url}/`;
|
||||||
|
}
|
||||||
|
|
||||||
|
type RefreshResult = {
|
||||||
|
data: QuotaDisplay | null;
|
||||||
|
lastRefreshAt: Date | null;
|
||||||
|
error: string | null;
|
||||||
|
};
|
||||||
|
|
||||||
export async function activate(context: vscode.ExtensionContext) {
|
export async function activate(context: vscode.ExtensionContext) {
|
||||||
storageService = new StorageService(context);
|
storageService = new StorageService(context);
|
||||||
@@ -24,8 +38,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||||||
|
|
||||||
statusBar = new StatusBarManager(
|
statusBar = new StatusBarManager(
|
||||||
async () => {
|
async () => {
|
||||||
await refreshQuota();
|
return await refreshQuota();
|
||||||
return currentQuota;
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
context.subscriptions.push(statusBar);
|
context.subscriptions.push(statusBar);
|
||||||
@@ -39,9 +52,10 @@ export async function activate(context: vscode.ExtensionContext) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function loginCommand(): Promise<void> {
|
async function loginCommand(): Promise<void> {
|
||||||
|
const baseUrl = getConfiguredBaseUrl();
|
||||||
const token = await vscode.window.showInputBox({
|
const token = await vscode.window.showInputBox({
|
||||||
prompt: '请输入 Bearer Token',
|
prompt: '请输入 Bearer Token',
|
||||||
placeHolder: '在 https://ai.getdeepin.org/me 生成 Token',
|
placeHolder: `在 ${baseUrl}me 生成 Token`,
|
||||||
password: true
|
password: true
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -50,21 +64,26 @@ async function loginCommand(): Promise<void> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await authService.setToken(token);
|
await authService.setToken(token);
|
||||||
const response = await quotaService.fetchQuota();
|
const result = await quotaService.fetchQuota();
|
||||||
|
|
||||||
if (!response) {
|
if (!result.ok) {
|
||||||
vscode.window.showErrorMessage('Token 无效或已过期,请检查后重试');
|
vscode.window.showErrorMessage(result.error);
|
||||||
await authService.logout();
|
await authService.logout();
|
||||||
statusBar.updateNotLoggedIn();
|
statusBar.updateNotLoggedIn();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await response.json() as QuotaResponse;
|
const data = await result.response.json() as QuotaResponse;
|
||||||
currentQuota = parseQuotaResponse(data);
|
currentQuota = parseQuotaResponse(data);
|
||||||
|
lastRefreshAt = new Date();
|
||||||
|
lastRefreshError = null;
|
||||||
statusBar.updateWithQuota(currentQuota);
|
statusBar.updateWithQuota(currentQuota);
|
||||||
vscode.window.showInformationMessage('Token 验证成功');
|
vscode.window.showInformationMessage('Token 验证成功');
|
||||||
} catch {
|
} catch (error) {
|
||||||
|
console.error('Parse quota response failed:', error);
|
||||||
|
currentQuota = null;
|
||||||
|
lastRefreshError = '解析用量数据失败';
|
||||||
vscode.window.showErrorMessage('解析用量数据失败');
|
vscode.window.showErrorMessage('解析用量数据失败');
|
||||||
statusBar.updateWithError();
|
statusBar.updateWithError();
|
||||||
}
|
}
|
||||||
@@ -73,30 +92,48 @@ async function loginCommand(): Promise<void> {
|
|||||||
async function logoutCommand(): Promise<void> {
|
async function logoutCommand(): Promise<void> {
|
||||||
await authService.logout();
|
await authService.logout();
|
||||||
currentQuota = null;
|
currentQuota = null;
|
||||||
|
lastRefreshAt = null;
|
||||||
|
lastRefreshError = null;
|
||||||
statusBar.updateNotLoggedIn();
|
statusBar.updateNotLoggedIn();
|
||||||
vscode.window.showInformationMessage('已移除 Token');
|
vscode.window.showInformationMessage('已移除 Token');
|
||||||
}
|
}
|
||||||
|
|
||||||
async function refreshQuota(): Promise<void> {
|
async function refreshQuota(): Promise<RefreshResult> {
|
||||||
const response = await quotaService.fetchQuota();
|
const result = await quotaService.fetchQuota();
|
||||||
|
|
||||||
if (!response) {
|
if (!result.ok) {
|
||||||
|
currentQuota = null;
|
||||||
|
lastRefreshError = result.error;
|
||||||
statusBar.updateWithError();
|
statusBar.updateWithError();
|
||||||
return;
|
return {
|
||||||
|
data: null,
|
||||||
|
lastRefreshAt,
|
||||||
|
error: lastRefreshError
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const data = await response.json() as QuotaResponse;
|
const data = await result.response.json() as QuotaResponse;
|
||||||
currentQuota = parseQuotaResponse(data);
|
currentQuota = parseQuotaResponse(data);
|
||||||
|
lastRefreshAt = new Date();
|
||||||
|
lastRefreshError = null;
|
||||||
statusBar.updateWithQuota(currentQuota);
|
statusBar.updateWithQuota(currentQuota);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Parse quota response failed:', error);
|
console.error('Parse quota response failed:', error);
|
||||||
|
currentQuota = null;
|
||||||
|
lastRefreshError = '解析用量数据失败';
|
||||||
statusBar.updateWithError();
|
statusBar.updateWithError();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: currentQuota,
|
||||||
|
lastRefreshAt,
|
||||||
|
error: lastRefreshError
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function showPopup(): void {
|
function showPopup(): void {
|
||||||
statusBar.showPopup(currentQuota, authService.isLoggedIn());
|
statusBar.showPopup(currentQuota, authService.isLoggedIn(), lastRefreshAt, lastRefreshError);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function deactivate() {}
|
export function deactivate() {}
|
||||||
+163
-32
@@ -4,9 +4,17 @@ import { QuotaResponse, QuotaDisplay } from './types';
|
|||||||
export class StatusBarManager {
|
export class StatusBarManager {
|
||||||
private statusBarItem: vscode.StatusBarItem;
|
private statusBarItem: vscode.StatusBarItem;
|
||||||
private currentPanel: vscode.WebviewPanel | undefined;
|
private currentPanel: vscode.WebviewPanel | undefined;
|
||||||
private onRefresh: () => Promise<QuotaDisplay | null>;
|
private onRefresh: () => Promise<{
|
||||||
|
data: QuotaDisplay | null;
|
||||||
|
lastRefreshAt: Date | null;
|
||||||
|
error: string | null;
|
||||||
|
}>;
|
||||||
|
|
||||||
constructor(onRefresh: () => Promise<QuotaDisplay | null>) {
|
constructor(onRefresh: () => Promise<{
|
||||||
|
data: QuotaDisplay | null;
|
||||||
|
lastRefreshAt: Date | null;
|
||||||
|
error: string | null;
|
||||||
|
}>) {
|
||||||
this.onRefresh = onRefresh;
|
this.onRefresh = onRefresh;
|
||||||
this.statusBarItem = vscode.window.createStatusBarItem(
|
this.statusBarItem = vscode.window.createStatusBarItem(
|
||||||
vscode.StatusBarAlignment.Right,
|
vscode.StatusBarAlignment.Right,
|
||||||
@@ -78,18 +86,23 @@ export class StatusBarManager {
|
|||||||
return md;
|
return md;
|
||||||
}
|
}
|
||||||
|
|
||||||
showPopup(data: QuotaDisplay | null, isLoggedIn: boolean): void {
|
showPopup(
|
||||||
|
data: QuotaDisplay | null,
|
||||||
|
isLoggedIn: boolean,
|
||||||
|
lastRefreshAt: Date | null,
|
||||||
|
lastRefreshError: string | null
|
||||||
|
): void {
|
||||||
if (!isLoggedIn) {
|
if (!isLoggedIn) {
|
||||||
this.showLoginPrompt();
|
this.showLoginPrompt();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!data) {
|
if (!data) {
|
||||||
this.showErrorPrompt();
|
this.showErrorPrompt(lastRefreshAt, lastRefreshError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.showQuotaPanel(data);
|
this.showQuotaPanel(data, lastRefreshAt, lastRefreshError);
|
||||||
}
|
}
|
||||||
|
|
||||||
private showLoginPrompt(): void {
|
private showLoginPrompt(): void {
|
||||||
@@ -103,27 +116,38 @@ export class StatusBarManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private showErrorPrompt(): void {
|
private showErrorPrompt(lastRefreshAt: Date | null, lastRefreshError: string | null): void {
|
||||||
vscode.window.showQuickPick(
|
vscode.window.showQuickPick(
|
||||||
[
|
[
|
||||||
{ label: '$(refresh) 重试', id: 'refresh' },
|
{ label: '$(refresh) 重试', id: 'refresh' },
|
||||||
|
{ label: '$(preview) 查看详情', id: 'details' },
|
||||||
{ label: '$(key) 重新设置 Token', id: 'login' }
|
{ label: '$(key) 重新设置 Token', id: 'login' }
|
||||||
],
|
],
|
||||||
{ placeHolder: '获取用量数据失败' }
|
{
|
||||||
|
placeHolder: lastRefreshError
|
||||||
|
? `获取用量数据失败: ${lastRefreshError}`
|
||||||
|
: '获取用量数据失败'
|
||||||
|
}
|
||||||
).then(selection => {
|
).then(selection => {
|
||||||
const item = selection as any;
|
const item = selection as any;
|
||||||
if (item?.id === 'refresh') {
|
if (item?.id === 'refresh') {
|
||||||
vscode.commands.executeCommand('getdeepin-quota.refresh');
|
vscode.commands.executeCommand('getdeepin-quota.refresh');
|
||||||
|
} else if (item?.id === 'details') {
|
||||||
|
this.showQuotaPanel(null, lastRefreshAt, lastRefreshError);
|
||||||
} else if (item?.id === 'login') {
|
} else if (item?.id === 'login') {
|
||||||
vscode.commands.executeCommand('getdeepin-quota.login');
|
vscode.commands.executeCommand('getdeepin-quota.login');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private showQuotaPanel(data: QuotaDisplay): void {
|
private showQuotaPanel(
|
||||||
|
data: QuotaDisplay | null,
|
||||||
|
lastRefreshAt: Date | null,
|
||||||
|
lastRefreshError: string | null
|
||||||
|
): void {
|
||||||
if (this.currentPanel) {
|
if (this.currentPanel) {
|
||||||
this.currentPanel.reveal(vscode.ViewColumn.Active);
|
this.currentPanel.reveal(vscode.ViewColumn.Active);
|
||||||
this.currentPanel.webview.html = this.generatePanelHtml(data);
|
this.currentPanel.webview.html = this.generatePanelHtml(data, lastRefreshAt, lastRefreshError);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,13 +159,24 @@ export class StatusBarManager {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.currentPanel = panel;
|
this.currentPanel = panel;
|
||||||
panel.webview.html = this.generatePanelHtml(data);
|
panel.webview.html = this.generatePanelHtml(data, lastRefreshAt, lastRefreshError);
|
||||||
|
|
||||||
panel.webview.onDidReceiveMessage(async (message) => {
|
panel.webview.onDidReceiveMessage(async (message) => {
|
||||||
if (message.command === 'refresh') {
|
if (message.command === 'refresh') {
|
||||||
const newData = await this.onRefresh();
|
try {
|
||||||
if (newData && this.currentPanel) {
|
const result = await this.onRefresh();
|
||||||
this.currentPanel.webview.html = this.generatePanelHtml(newData);
|
if (this.currentPanel === panel) {
|
||||||
|
this.currentPanel.webview.html = this.generatePanelHtml(
|
||||||
|
result.data,
|
||||||
|
result.lastRefreshAt,
|
||||||
|
result.error
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
if (this.currentPanel === panel) {
|
||||||
|
void this.currentPanel.webview.postMessage({ command: 'refreshFinished' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -151,9 +186,16 @@ export class StatusBarManager {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private generatePanelHtml(data: QuotaDisplay): string {
|
private generatePanelHtml(
|
||||||
|
data: QuotaDisplay | null,
|
||||||
|
lastRefreshAt: Date | null,
|
||||||
|
lastRefreshError: string | null
|
||||||
|
): string {
|
||||||
const formatTokens = (n: number) => n.toLocaleString('zh-CN');
|
const formatTokens = (n: number) => n.toLocaleString('zh-CN');
|
||||||
const formatPercent = (n: number) => n.toFixed(1);
|
const formatPercent = (n: number) => n.toFixed(1);
|
||||||
|
const formatTime = (time: Date | null) => time
|
||||||
|
? time.toLocaleString('zh-CN', { hour12: false })
|
||||||
|
: '暂无';
|
||||||
|
|
||||||
const renderQuotaSection = (
|
const renderQuotaSection = (
|
||||||
label: string,
|
label: string,
|
||||||
@@ -203,6 +245,39 @@ export class StatusBarManager {
|
|||||||
return html;
|
return html;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const refreshMetaHtml = `
|
||||||
|
<div class="meta-row">
|
||||||
|
<span class="meta-label">最后刷新</span>
|
||||||
|
<span class="meta-value">${formatTime(lastRefreshAt)}</span>
|
||||||
|
</div>
|
||||||
|
${lastRefreshError ? `
|
||||||
|
<div class="error-banner">
|
||||||
|
<strong>刷新失败</strong>
|
||||||
|
<div>${lastRefreshError}</div>
|
||||||
|
</div>` : ''}`;
|
||||||
|
|
||||||
|
const quotaContentHtml = data ? `
|
||||||
|
${renderQuotaSection(
|
||||||
|
data.domestic.label,
|
||||||
|
data.domestic.remainingDailyPercent,
|
||||||
|
data.domestic.remainingMonthlyPercent,
|
||||||
|
data.domestic.hasDailyLimit,
|
||||||
|
data.domestic.totalTokens,
|
||||||
|
data.domestic.models
|
||||||
|
)}
|
||||||
|
|
||||||
|
${renderQuotaSection(
|
||||||
|
data.global.label,
|
||||||
|
data.global.remainingDailyPercent,
|
||||||
|
data.global.remainingMonthlyPercent,
|
||||||
|
data.global.hasDailyLimit,
|
||||||
|
data.global.totalTokens,
|
||||||
|
data.global.models
|
||||||
|
)}` : `
|
||||||
|
<div class="empty-state">
|
||||||
|
当前没有可展示的额度数据,请检查 Token 或稍后重试。
|
||||||
|
</div>`;
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
@@ -227,6 +302,37 @@ export class StatusBarManager {
|
|||||||
.user-info {
|
.user-info {
|
||||||
color: var(--vscode-descriptionForeground);
|
color: var(--vscode-descriptionForeground);
|
||||||
}
|
}
|
||||||
|
.meta-row {
|
||||||
|
display: flex;
|
||||||
|
gap: 8px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
color: var(--vscode-descriptionForeground);
|
||||||
|
}
|
||||||
|
.meta-label {
|
||||||
|
min-width: 60px;
|
||||||
|
}
|
||||||
|
.meta-value {
|
||||||
|
color: var(--vscode-foreground);
|
||||||
|
}
|
||||||
|
.error-banner {
|
||||||
|
margin-bottom: 20px;
|
||||||
|
padding: 12px 14px;
|
||||||
|
border-radius: 6px;
|
||||||
|
border: 1px solid var(--vscode-inputValidation-errorBorder);
|
||||||
|
background-color: var(--vscode-inputValidation-errorBackground);
|
||||||
|
color: var(--vscode-inputValidation-errorForeground);
|
||||||
|
}
|
||||||
|
.error-banner strong {
|
||||||
|
display: block;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
}
|
||||||
|
.empty-state {
|
||||||
|
margin: 20px 0 24px;
|
||||||
|
padding: 16px;
|
||||||
|
border: 1px dashed var(--vscode-panel-border);
|
||||||
|
border-radius: 6px;
|
||||||
|
color: var(--vscode-descriptionForeground);
|
||||||
|
}
|
||||||
.quota-section {
|
.quota-section {
|
||||||
margin-bottom: 24px;
|
margin-bottom: 24px;
|
||||||
}
|
}
|
||||||
@@ -294,45 +400,70 @@ export class StatusBarManager {
|
|||||||
border-radius: 4px;
|
border-radius: 4px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
|
display: inline-flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 6px;
|
||||||
}
|
}
|
||||||
.refresh-btn:hover {
|
.refresh-btn:hover {
|
||||||
background-color: var(--vscode-button-hoverBackground);
|
background-color: var(--vscode-button-hoverBackground);
|
||||||
}
|
}
|
||||||
|
.refresh-btn:disabled {
|
||||||
|
opacity: 0.6;
|
||||||
|
cursor: not-allowed;
|
||||||
|
}
|
||||||
|
@keyframes spin {
|
||||||
|
from { transform: rotate(0deg); }
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
.spinner {
|
||||||
|
display: inline-block;
|
||||||
|
width: 14px;
|
||||||
|
height: 14px;
|
||||||
|
border: 2px solid var(--vscode-button-foreground);
|
||||||
|
border-top-color: transparent;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 0.6s linear infinite;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<h1>AI 模型用量统计</h1>
|
<h1>AI 模型用量统计</h1>
|
||||||
|
${data ? `
|
||||||
<div class="user-info">
|
<div class="user-info">
|
||||||
<strong>${data.user.display_name}</strong> (${data.user.job_id}) · ${data.user.email}
|
<strong>${data.user.display_name}</strong> (${data.user.job_id}) · ${data.user.email}
|
||||||
</div>
|
</div>` : ''}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
${renderQuotaSection(
|
${refreshMetaHtml}
|
||||||
data.domestic.label,
|
|
||||||
data.domestic.remainingDailyPercent,
|
|
||||||
data.domestic.remainingMonthlyPercent,
|
|
||||||
data.domestic.hasDailyLimit,
|
|
||||||
data.domestic.totalTokens,
|
|
||||||
data.domestic.models
|
|
||||||
)}
|
|
||||||
|
|
||||||
${renderQuotaSection(
|
${quotaContentHtml}
|
||||||
data.global.label,
|
|
||||||
data.global.remainingDailyPercent,
|
|
||||||
data.global.remainingMonthlyPercent,
|
|
||||||
data.global.hasDailyLimit,
|
|
||||||
data.global.totalTokens,
|
|
||||||
data.global.models
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div class="actions">
|
<div class="actions">
|
||||||
<button class="refresh-btn" onclick="refresh()">刷新数据</button>
|
<button id="refresh-btn" class="refresh-btn" onclick="refresh()">刷新数据</button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
const vscode = acquireVsCodeApi();
|
const vscode = acquireVsCodeApi();
|
||||||
|
function setRefreshing(refreshing) {
|
||||||
|
const btn = document.getElementById('refresh-btn');
|
||||||
|
if (!btn) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
btn.disabled = refreshing;
|
||||||
|
btn.innerHTML = refreshing
|
||||||
|
? '<span class="spinner"></span>刷新中...'
|
||||||
|
: '刷新数据';
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener('message', (event) => {
|
||||||
|
if (event.data?.command === 'refreshFinished') {
|
||||||
|
setRefreshing(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
function refresh() {
|
function refresh() {
|
||||||
|
setRefreshing(true);
|
||||||
vscode.postMessage({ command: 'refresh' });
|
vscode.postMessage({ command: 'refresh' });
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in new issue
Block a user