update at 2025-10-10 17:00:09
This commit is contained in:
@@ -19,6 +19,17 @@ export interface PlatformChooserOptions {
|
||||
onPlatformChange?: (platform: PlatformType) => Promise<void>;
|
||||
}
|
||||
|
||||
export interface PlatformActionLabels {
|
||||
refresh: string;
|
||||
publish: string;
|
||||
}
|
||||
|
||||
export interface PlatformChooserActions {
|
||||
onRefresh?: () => void | Promise<void>;
|
||||
onPublish?: () => void | Promise<void>;
|
||||
getLabels?: (platform: PlatformType) => PlatformActionLabels;
|
||||
}
|
||||
|
||||
/**
|
||||
* 平台信息接口
|
||||
*/
|
||||
@@ -48,8 +59,11 @@ const SUPPORTED_PLATFORMS: PlatformInfo[] = [
|
||||
export class PlatformChooser {
|
||||
private container: HTMLElement;
|
||||
private selectElement: HTMLSelectElement | null = null;
|
||||
private refreshButton: HTMLButtonElement | null = null;
|
||||
private publishButton: HTMLButtonElement | null = null;
|
||||
private currentPlatform: PlatformType;
|
||||
private onChange?: (platform: PlatformType) => void;
|
||||
private actions: PlatformChooserActions | null = null;
|
||||
|
||||
constructor(container: HTMLElement, options: PlatformChooserOptions = {}) {
|
||||
this.container = container;
|
||||
@@ -101,6 +115,16 @@ export class PlatformChooser {
|
||||
const newPlatform = platformSelect.value as PlatformType;
|
||||
this.switchPlatformInternal(newPlatform);
|
||||
};
|
||||
|
||||
// 刷新按钮
|
||||
this.refreshButton = this.container.createEl('button', { cls: 'toolbar-button purple-gradient' });
|
||||
this.refreshButton.onclick = () => this.handleRefreshClick();
|
||||
|
||||
// 发布按钮
|
||||
this.publishButton = this.container.createEl('button', { cls: 'toolbar-button' });
|
||||
this.publishButton.onclick = () => this.handlePublishClick();
|
||||
|
||||
this.updateActionLabels();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,6 +147,8 @@ export class PlatformChooser {
|
||||
console.error('[PlatformChooser] 平台切换失败:', error);
|
||||
}
|
||||
}
|
||||
|
||||
this.updateActionLabels();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -133,6 +159,7 @@ export class PlatformChooser {
|
||||
if (this.selectElement) {
|
||||
this.selectElement.value = platform;
|
||||
}
|
||||
this.updateActionLabels();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -160,5 +187,45 @@ export class PlatformChooser {
|
||||
this.selectElement.onchange = null;
|
||||
this.selectElement = null;
|
||||
}
|
||||
if (this.refreshButton) {
|
||||
this.refreshButton.onclick = null;
|
||||
this.refreshButton = null;
|
||||
}
|
||||
if (this.publishButton) {
|
||||
this.publishButton.onclick = null;
|
||||
this.publishButton = null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置通用操作按钮
|
||||
*/
|
||||
setActions(actions: PlatformChooserActions): void {
|
||||
this.actions = actions;
|
||||
this.updateActionLabels();
|
||||
}
|
||||
|
||||
private handleRefreshClick(): void {
|
||||
if (!this.actions?.onRefresh) return;
|
||||
Promise.resolve(this.actions.onRefresh()).catch((error) => {
|
||||
console.error('[PlatformChooser] 刷新操作失败:', error);
|
||||
});
|
||||
}
|
||||
|
||||
private handlePublishClick(): void {
|
||||
if (!this.actions?.onPublish) return;
|
||||
Promise.resolve(this.actions.onPublish()).catch((error) => {
|
||||
console.error('[PlatformChooser] 发布操作失败:', error);
|
||||
});
|
||||
}
|
||||
|
||||
private updateActionLabels(): void {
|
||||
if (!this.refreshButton || !this.publishButton) return;
|
||||
const labels = this.actions?.getLabels?.(this.currentPlatform) ?? {
|
||||
refresh: '🔄 刷新',
|
||||
publish: '📤 发布',
|
||||
};
|
||||
this.refreshButton.innerText = labels.refresh;
|
||||
this.publishButton.innerText = labels.publish;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user