方法1:
文件地址:\public\assets\js\addons.js
//第100行代码
onImageUpload: function (files) {
var that = this;
//依次上传图片
//自定义图片上传格式 图片宽度 编辑器上传图片
for (var i = 0; i < files.length; i++) {
Upload.api.send(files[i], function (data) {
var url = Fast.api.cdnurl(data.url, true);
//上传图片后,这一段会插入到编辑器中,可自定义URL与其他
$(that).summernote("insertImage", url, 'filename123');
});
}
}
}
}, $(this).data("summernote-options") || {}));
方法2:
修改控制器代码。
edit方法:
//自定义添加规则,找到img,清除width或设置为100%
// 使用正则表达式匹配 <img> 标签并去除 style 中的 width 属性
$content = $params['content'];
$updatedContent = preg_replace_callback(
'/<img([^>]*?)style\s*=\s*"(.*?)"(.*?)>/i',
function ($matches) {
// 找到并移除 width 属性
$newStyle = preg_replace('/\bwidth\s*:\s*\d+(\.\d+)?px\s*;?\s*/i', '', $matches[2]);
// 如果 style 为空则移除 style 属性
if (trim($newStyle) === '') {
return '<img' . $matches[1] . $matches[3] . '>';
}
return '<img' . $matches[1] . 'style="' . $newStyle . '"' . $matches[3] . '>';
},
$content
);
// 更新后的内容
$params['content'] = $updatedContent;
Db::startTrans();
try {
.....
....