update at 2025-10-09 12:39:24
This commit is contained in:
@@ -93,25 +93,23 @@ export class WechatPreview {
|
||||
* 构建工具栏
|
||||
*/
|
||||
private buildToolbar(parent: HTMLDivElement): void {
|
||||
let lineDiv;
|
||||
// 单层 Grid:所有控件直接挂到 parent(.preview-toolbar)
|
||||
|
||||
// 公众号选择
|
||||
if (this.settings.wxInfo.length > 1 || Platform.isDesktop) {
|
||||
lineDiv = parent.createDiv({ cls: 'toolbar-line' });
|
||||
|
||||
const wxLabel = lineDiv.createDiv({ cls: 'style-label' });
|
||||
const wxLabel = parent.createDiv({ cls: 'style-label' });
|
||||
wxLabel.innerText = '公众号';
|
||||
|
||||
const wxSelect = lineDiv.createEl('select', { cls: 'wechat-select' });
|
||||
|
||||
const wxSelect = parent.createEl('select', { cls: 'wechat-select' });
|
||||
wxSelect.onchange = async () => {
|
||||
this.currentAppId = wxSelect.value;
|
||||
this.onAppIdChanged();
|
||||
};
|
||||
|
||||
|
||||
const defaultOp = wxSelect.createEl('option');
|
||||
defaultOp.value = '';
|
||||
defaultOp.text = '请在设置里配置公众号';
|
||||
|
||||
|
||||
for (let i = 0; i < this.settings.wxInfo.length; i++) {
|
||||
const op = wxSelect.createEl('option');
|
||||
const wx = this.settings.wxInfo[i];
|
||||
@@ -125,8 +123,8 @@ export class WechatPreview {
|
||||
this.wechatSelect = wxSelect;
|
||||
|
||||
if (Platform.isDesktop) {
|
||||
const separator = lineDiv.createDiv({ cls: 'toolbar-separator' });
|
||||
const openBtn = lineDiv.createEl('button', { text: '🌐 去公众号后台', cls: 'toolbar-button purple-gradient' });
|
||||
//parent.createDiv({ cls: 'toolbar-separator' });
|
||||
const openBtn = parent.createEl('button', { text: '🌐 去公众号后台', cls: 'toolbar-button purple-gradient' });
|
||||
openBtn.onclick = async () => {
|
||||
const { shell } = require('electron');
|
||||
shell.openExternal('https://mp.weixin.qq.com');
|
||||
@@ -135,21 +133,15 @@ export class WechatPreview {
|
||||
}
|
||||
}
|
||||
|
||||
// 操作按钮行
|
||||
lineDiv = parent.createDiv({ cls: 'toolbar-line flex-wrap' });
|
||||
|
||||
const refreshBtn = lineDiv.createEl('button', { text: '🔄 刷新', cls: 'toolbar-button purple-gradient' });
|
||||
refreshBtn.onclick = async () => {
|
||||
if (this.onRefreshCallback) {
|
||||
await this.onRefreshCallback();
|
||||
}
|
||||
};
|
||||
// 操作按钮(直接平铺在 Grid 中)
|
||||
const refreshBtn = parent.createEl('button', { text: '🔄 刷新', cls: 'toolbar-button purple-gradient' });
|
||||
refreshBtn.onclick = async () => { if (this.onRefreshCallback) await this.onRefreshCallback(); };
|
||||
|
||||
const postBtn = lineDiv.createEl('button', { text: '📝 发布', cls: 'toolbar-button' });
|
||||
const postBtn = parent.createEl('button', { text: '📝 发布', cls: 'toolbar-button' });
|
||||
postBtn.onclick = async () => await this.postArticle();
|
||||
|
||||
if (Platform.isDesktop && this.settings.isAuthKeyVaild()) {
|
||||
const htmlBtn = lineDiv.createEl('button', { text: '💾 导出HTML', cls: 'toolbar-button' });
|
||||
const htmlBtn = parent.createEl('button', { text: '💾 导出HTML', cls: 'toolbar-button' });
|
||||
htmlBtn.onclick = async () => await this.exportHTML();
|
||||
}
|
||||
|
||||
@@ -166,11 +158,10 @@ export class WechatPreview {
|
||||
* 构建封面选择器
|
||||
*/
|
||||
private buildCoverSelector(parent: HTMLDivElement): void {
|
||||
const lineDiv = parent.createDiv({ cls: 'toolbar-line' });
|
||||
const coverTitle = lineDiv.createDiv({ cls: 'style-label' });
|
||||
const coverTitle = parent.createDiv({ cls: 'style-label' });
|
||||
coverTitle.innerText = '封面';
|
||||
|
||||
this.useDefaultCover = lineDiv.createEl('input', { cls: 'input-style' });
|
||||
this.useDefaultCover = parent.createEl('input', { cls: 'input-style' });
|
||||
this.useDefaultCover.setAttr('type', 'radio');
|
||||
this.useDefaultCover.setAttr('name', 'cover');
|
||||
this.useDefaultCover.setAttr('value', 'default');
|
||||
@@ -182,11 +173,11 @@ export class WechatPreview {
|
||||
}
|
||||
};
|
||||
|
||||
const defaultLabel = lineDiv.createEl('label');
|
||||
const defaultLabel = parent.createEl('label');
|
||||
defaultLabel.innerText = '默认';
|
||||
defaultLabel.setAttr('for', 'default-cover');
|
||||
|
||||
this.useLocalCover = lineDiv.createEl('input', { cls: 'input-style' });
|
||||
this.useLocalCover = parent.createEl('input', { cls: 'input-style' });
|
||||
this.useLocalCover.setAttr('type', 'radio');
|
||||
this.useLocalCover.setAttr('name', 'cover');
|
||||
this.useLocalCover.setAttr('value', 'local');
|
||||
@@ -198,11 +189,11 @@ export class WechatPreview {
|
||||
}
|
||||
};
|
||||
|
||||
const localLabel = lineDiv.createEl('label');
|
||||
const localLabel = parent.createEl('label');
|
||||
localLabel.setAttr('for', 'local-cover');
|
||||
localLabel.innerText = '上传';
|
||||
|
||||
this.coverEl = lineDiv.createEl('input', { cls: 'upload-input' });
|
||||
this.coverEl = parent.createEl('input', { cls: 'upload-input' });
|
||||
this.coverEl.setAttr('type', 'file');
|
||||
this.coverEl.setAttr('placeholder', '封面图片');
|
||||
this.coverEl.setAttr('accept', '.png, .jpg, .jpeg');
|
||||
@@ -214,12 +205,10 @@ export class WechatPreview {
|
||||
* 构建样式选择器
|
||||
*/
|
||||
private buildStyleSelector(parent: HTMLDivElement): void {
|
||||
const lineDiv = parent.createDiv({ cls: 'toolbar-line flex-wrap' });
|
||||
|
||||
const cssStyle = lineDiv.createDiv({ cls: 'style-label' });
|
||||
const cssStyle = parent.createDiv({ cls: 'style-label' });
|
||||
cssStyle.innerText = '样式';
|
||||
|
||||
const selectBtn = lineDiv.createEl('select', { cls: 'style-select' });
|
||||
const selectBtn = parent.createEl('select', { cls: 'style-select' });
|
||||
selectBtn.onchange = async () => {
|
||||
this.currentTheme = selectBtn.value;
|
||||
this.render.updateStyle(selectBtn.value);
|
||||
@@ -233,12 +222,12 @@ export class WechatPreview {
|
||||
}
|
||||
this.themeSelect = selectBtn;
|
||||
|
||||
const separator = lineDiv.createDiv({ cls: 'toolbar-separator' });
|
||||
parent.createDiv({ cls: 'toolbar-separator' });
|
||||
|
||||
const highlightStyle = lineDiv.createDiv({ cls: 'style-label' });
|
||||
const highlightStyle = parent.createDiv({ cls: 'style-label' });
|
||||
highlightStyle.innerText = '代码高亮';
|
||||
|
||||
const highlightStyleBtn = lineDiv.createEl('select', { cls: 'style-select' });
|
||||
const highlightStyleBtn = parent.createEl('select', { cls: 'style-select' });
|
||||
highlightStyleBtn.onchange = async () => {
|
||||
this.currentHighlight = highlightStyleBtn.value;
|
||||
this.render.updateHighLight(highlightStyleBtn.value);
|
||||
|
||||
Reference in New Issue
Block a user