update at 2025-10-21 21:47:02

This commit is contained in:
douboer
2025-10-21 21:47:02 +08:00
parent 8d40fbb01f
commit b823d90b55
29 changed files with 2159 additions and 1626 deletions

View File

@@ -14,7 +14,7 @@
*/
import { TFile, Notice, App } from 'obsidian';
import { PlatformChooser, PlatformType } from './platform-chooser';
import { PlatformType } from './platform-chooser';
import { WechatPreview } from './wechat/wechat-preview';
import { XiaohongshuPreview } from './xiaohongshu/xhs-preview';
import { ArticleRender } from './article-render';
@@ -27,7 +27,6 @@ export class PreviewManager {
private settings: NMPSettings;
// 子组件
private platformChooser: PlatformChooser | null = null;
private wechatPreview: WechatPreview | null = null;
private xhsPreview: XiaohongshuPreview | null = null;
@@ -36,8 +35,8 @@ export class PreviewManager {
private wechatContainer: HTMLDivElement | null = null;
private xhsContainer: HTMLDivElement | null = null;
// 状态
private currentPlatform: PlatformType = 'xiaohongshu';
// 默认平台
private currentPlatform: PlatformType = 'wechat';
private currentFile: TFile | null = null;
constructor(container: HTMLElement, app: App, render: ArticleRender) {
@@ -59,53 +58,19 @@ export class PreviewManager {
// 创建主容器
this.mainDiv = this.container.createDiv({ cls: 'note-preview' });
// 1. 创建并构建平台选择器
this.createPlatformChooser();
// 2. 创建并构建微信预览
// 1. 创建并构建微信预览
this.createWechatPreview();
// 3. 创建并构建小红书预览
// 2. 创建并构建小红书预览
this.createXiaohongshuPreview();
// 4. 初始显示小红书平台
await this.switchPlatform('xiaohongshu');
// 3. 初始显示公众号平台
await this.switchPlatform('wechat');
console.log('[PreviewManager] 界面构建完成');
}
/**
* 创建平台选择器
*/
private createPlatformChooser(): void {
if (!this.mainDiv) return;
// 创建平台选择器容器
const chooserContainer = this.mainDiv.createDiv({ cls: 'platform-chooser-container' });
// 创建平台选择器实例
this.platformChooser = new PlatformChooser(chooserContainer);
// 设置平台切换回调
this.platformChooser.setOnChange((platform) => {
this.switchPlatform(platform as PlatformType);
});
// 构建 UI
this.platformChooser.render();
// 共享操作按钮
this.platformChooser.setActions({
onRefresh: () => this.refresh(),
onPublish: () => this.publishCurrentPlatform(),
getLabels: (platform) => {
if (platform === 'wechat') {
return { refresh: '🔄 刷新', publish: '📝 发布' };
}
return { refresh: '🔄 刷新', publish: '📤 发布' };
},
});
}
/**
* 创建微信预览组件
@@ -133,6 +98,10 @@ export class PreviewManager {
// 可以在这里处理公众号切换的额外逻辑
};
this.wechatPreview.onPlatformChangeCallback = (platform: string) => {
this.switchPlatform(platform as PlatformType);
};
// 构建 UI
this.wechatPreview.build();
}
@@ -194,11 +163,6 @@ export class PreviewManager {
const previousPlatform = this.currentPlatform;
this.currentPlatform = platform;
// 更新平台选择器显示
if (this.platformChooser) {
this.platformChooser.switchPlatform(platform);
}
if (platform === 'wechat') {
// 显示微信,隐藏小红书
this.showWechat();
@@ -410,7 +374,6 @@ export class PreviewManager {
this.xhsPreview = null;
}
this.platformChooser = null;
this.mainDiv = null;
this.wechatContainer = null;
this.xhsContainer = null;