feat(phone-image): Wave2 CSS样式+自动保存+历史加载

- T4: 新增编辑器区/操作栏/弹框CSS样式(390行),覆盖两栏布局、
  wangeditor编辑区排版、divider分页标记、设置弹框、右侧预览区
- T5: onChange自动保存(2.6s防抖),保存状态指示器(waiting/saving/saved/error)
- T6: loadFromHistory改用editor.setHtml()+updateConfig()替换旧init
- 修复: doAutoSave删除无效递归调用
This commit is contained in:
augushong
2026-05-11 22:55:24 +08:00
parent 1f8128385f
commit f6fc53940c
2 changed files with 442 additions and 6 deletions

View File

@@ -198,8 +198,17 @@
}
};
var autoSaveTimer = null;
var autoSaveLock = false;
editorConfig.onChange = function (editor) {
// T5会实现自动保存
// 自动保存2.6s 防抖
clearTimeout(autoSaveTimer);
autoSaveLock = true;
updateSaveState('waiting');
autoSaveTimer = setTimeout(function () {
doAutoSave();
}, 2600);
};
// 粘贴处理:处理外部图片下载
@@ -369,10 +378,45 @@
align: 'right'
});
// ========== 自动保存相关函数 ==========
function updateSaveState(state) {
var $state = $('#save-state');
if (!$state.length) return;
switch(state) {
case 'waiting': $state.text('等待保存...').css('color', '#e6a23c'); break;
case 'saving': $state.text('保存中...').css('color', '#409eff'); break;
case 'saved': $state.text('已保存').css('color', '#67c23a'); break;
case 'error': $state.text('保存失败').css('color', '#f56c6c'); break;
}
}
function doAutoSave() {
if (autoSaveLock) {
autoSaveLock = false;
updateSaveState('saving');
PhoneImageEngine.saveConfig(postData.postId, {
size: currentConfig.size,
watermark: currentConfig.watermark,
content_html: PhoneImageEngine.getContentHtml()
}, saveConfigUrl).then(function (data) {
if (data.output_id) lastOutputId = data.output_id;
updateSaveState('saved');
}).catch(function (err) {
updateSaveState('error');
});
}
}
// ========== 保存状态指示器 ==========
$('<span id="save-state" style="font-size:12px;color:#999;">已保存</span>').insertAfter('#btn-generate');
// ========== 保存配置(不生成图片) ==========
$('#btn-save').click(function () {
var btn = $(this);
btn.prop('disabled', true);
// 清除自动保存定时器,避免冲突
clearTimeout(autoSaveTimer);
autoSaveLock = false;
layer.msg('保存中...');
PhoneImageEngine.saveConfig(postData.postId, {
@@ -383,8 +427,10 @@
if (data.output_id) lastOutputId = data.output_id;
$('#post-content-html').html(PhoneImageEngine.getContentHtml());
layer.msg('保存成功');
updateSaveState('saved');
}).catch(function (err) {
layer.msg('保存失败: ' + err);
updateSaveState('error');
}).always(function () {
setTimeout(function () { btn.prop('disabled', false); }, 2000);
});
@@ -504,9 +550,9 @@
var cfg = res.data.config || {};
// 更新 postData 中的 contentHtml
if (res.data.content_html) {
postData.contentHtml = res.data.content_html;
// 用 setHtml 将历史内容加载到 wangeditor
if (res.data.content_html && window.phoneImageEditor) {
window.phoneImageEditor.setHtml(res.data.content_html);
}
// 构建历史配置
@@ -522,8 +568,8 @@
lastOutputId = outputId;
layer.closeAll();
// 全量初始化引擎(加载历史是新内容,需要完整初始化)
PhoneImageEngine.init(postData, historyConfig);
// 更新引擎配置并重新渲染
PhoneImageEngine.updateConfig(historyConfig);
var loadIdx3 = layer.load();
PhoneImageEngine.render().then(function (pages) {
layer.close(loadIdx3);