fix(goods): 修复后台商品添加与编辑页面富文本编辑器嵌套与响应式绑定问题

这个提交包含在:
chen
2026-09-19 15:41:17 +08:00
父节点 aaaed1f83c
当前提交 f06538ddf6
共有 3 个文件被更改,包括 116 次插入 和 10 次删除

查看文件

@@ -454,6 +454,53 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
},
})
function initEditor() {
let $editor = $('#goodsContent');
if (!$editor.length) return;
// 同步原始 textarea 属性与内容
if (typeof form.model.content !== 'undefined' && form.model.content !== null) {
$editor.val(form.model.content);
}
// 若已初始化 summernote,则同步 code 并返回
if ($editor.next('.note-editor').length > 0) {
if (typeof $editor.summernote === 'function') {
if (form.model.content && !$editor.summernote('code')) {
$editor.summernote('code', form.model.content);
}
}
return;
}
// 优先走 FastAdmin 标准 bindevent
Controller.api.bindevent();
// 容错兜底:若 150ms 内未自动实例化,则直接初始化 summernote
setTimeout(() => {
if ($editor.next('.note-editor').length === 0 && typeof $.fn.summernote !== 'undefined') {
var options = (window.Config && window.Config.summernote) || {};
$editor.summernote($.extend(true, {
height: parseInt(options.height || 300),
minHeight: parseInt(options.minHeight || 250),
lang: 'zh-CN',
dialogsInBody: true
}, $editor.data("summernote-options") || {}));
if (form.model.content) {
$editor.summernote('code', form.model.content);
}
}
}, 150);
}
watch(() => state.activeStep, (newStep) => {
if (newStep == 4) {
nextTick(() => {
initEditor();
});
}
});
function getDetail() {
Fast.api.ajax({
url: `shopro/goods/goods/detail/id/${state.id}`,
@@ -479,8 +526,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
form.model.service_ids = form.model.service_ids ? form.model.service_ids : [];
// 富文本
Controller.api.bindevent();
$('#goodsContent').html(form.model.content)
$('#goodsContent').val(form.model.content || '');
if (state.activeStep == 4) {
nextTick(() => {
initEditor();
});
}
getDispatchSelect()
return false
@@ -568,9 +619,11 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
getDetail()
} else {
getDispatchSelect()
nextTick(() => {
Controller.api.bindevent();
})
if (state.activeStep == 4) {
nextTick(() => {
initEditor();
})
}
}
}
return false
@@ -944,7 +997,14 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
delete submitForm.sn;
}
submitForm.content = $("#goodsContent").val()
let editorContent = '';
let $editor = $("#goodsContent");
if ($editor.next('.note-editor').length > 0 && typeof $editor.summernote === 'function') {
editorContent = $editor.summernote('code');
} else {
editorContent = $editor.val() || '';
}
submitForm.content = editorContent;
if (state.type == 'copy') {
delete submitForm.id;
@@ -1433,8 +1493,9 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
createApp('addStock', addStock);
},
api: {
bindevent: function () {
Form.api.bindevent($("form[role=form]"));
bindevent: function (container) {
var $target = container ? $(container) : ($("#goodsContent").closest("form").length ? $("#goodsContent").closest("form") : ($("form[role=form]").length ? $("form[role=form]") : $("#addEdit")));
Form.api.bindevent($target);
},
},
};