新增HTML编辑器,优化编辑器调用

This commit is contained in:
wolfcode
2024-04-15 18:25:13 +08:00
parent 796c3155c0
commit 1d0b94009f
11 changed files with 24282 additions and 60 deletions

View File

@@ -36,7 +36,8 @@ return [
// 默认编辑器
'editor_types' => [
'ueditor' => '百度编辑器',
'ckeditor' => 'CK编辑器',
'ueditor' => '百度编辑器',
'ckeditor' => 'CK编辑器',
'wangEditor' => 'wangEditor',
],
];

View File

@@ -21,15 +21,19 @@
IS_SUPER_ADMIN: "{$isSuperAdmin|default='false'}",
VERSION: "{$version|default='1.0.0'}",
CSRF_TOKEN: "{:token()}",
EDITOR_TYPE: "{:sysconfig('site','editor_type')?:'ueditor'}",
ADMIN_UPLOAD_URL: "{$adminUploadUrl|DEFAULT=''}",
EDITOR_TYPE: "{$adminEditor|default='ueditor'}",
};
</script>
<script src="__STATIC__/plugs/layui-v2.8.x/layui.js?v={$version}" charset="utf-8"></script>
<script src="__STATIC__/plugs/require-2.3.6/require.js?v={$version}" charset="utf-8"></script>
<script src="__STATIC__/config-admin.js?v={$version}" charset="utf-8"></script>
<script src="__STATIC__/common/js/admin.js?v={$version}" charset="utf-8"></script>
{include file="layout/editor" /}
</head>
<body>
{__CONTENT__}
</body>
</html>

View File

@@ -0,0 +1,20 @@
{switch $adminEditor}
{case ckeditor}
<script src="__STATIC__/plugs/ckeditor4/ckeditor.js?v={$version}" charset="utf-8"></script>
{/case}
{case wangEditor}
<link rel="stylesheet" href="__STATIC__/plugs/wangEditor/dist/style.css?v={$version}">
<script src="__STATIC__/plugs/wangEditor/dist/index.js?v={$version}"></script>
{/case}
{default /}
<script src="__STATIC__/plugs/ueditor/ueditor.config.js?v={$version}" charset="utf-8"></script>
<script src="__STATIC__/plugs/ueditor/ueditor.all.js?v={$version}" charset="utf-8"></script>
<script src="__STATIC__/plugs/ueditor/lang/zh-cn/zh-cn.js?v={$version}" charset="utf-8"></script>
<script src="__STATIC__/plugs/ueditor/third-party/codemirror/codemirror.js?v={$version}" charset="utf-8"></script>
<script src="__STATIC__/plugs/ueditor/third-party/zeroclipboard/zeroclipboard.js?v={$version}" charset="utf-8"></script>
{/switch}

View File

@@ -132,6 +132,7 @@ if (!function_exists('auth')) {
$editor_type = sysconfig('site', 'editor_type');
return match ($editor_type) {
'ckeditor' => "<textarea name='{$name}' rows='20' class='layui-textarea editor' placeholder='{$placeholder}'>{$detail}</textarea>",
'wangEditor' => "<div class='wangEditor_div'><textarea name='{$name}' rows='20' class='layui-textarea editor layui-hide'>{$detail}</textarea><div id='editor_toolbar_{$name}'></div><div id='editor_{$name}' style='height: 300px'></div></div>",
default => "<script type='text/plain' id='{$name}' name='{$name}' class='editor' data-content='{$detail}'></script>",
};
}

View File

@@ -128,7 +128,7 @@ class AdminController extends BaseController
{
try {
parent::validate($data, $validate, $message, $batch);
} catch (\Exception $e) {
}catch (\Exception $e) {
$this->error($e->getMessage());
}
return true;
@@ -213,10 +213,10 @@ class AdminController extends BaseController
foreach ($thisControllerArr as $vo) {
empty($jsPath) ? $jsPath = parse_name($vo) : $jsPath .= '/' . parse_name($vo);
}
$autoloadJs = file_exists(root_path('public') . "static/{$thisModule}/js/{$jsPath}.js") ? true : false;
$autoloadJs = file_exists(root_path('public') . "static/{$thisModule}/js/{$jsPath}.js");
$thisControllerJsPath = "{$thisModule}/js/{$jsPath}.js";
$adminModuleName = config('app.admin_alias_name');
$isSuperAdmin = session('admin.id') == AdminConstant::SUPER_ADMIN_ID ? true : false;
$isSuperAdmin = session('admin.id') == AdminConstant::SUPER_ADMIN_ID;
$data = [
'adminModuleName' => $adminModuleName,
'thisController' => parse_name($thisController),
@@ -226,6 +226,8 @@ class AdminController extends BaseController
'autoloadJs' => $autoloadJs,
'isSuperAdmin' => $isSuperAdmin,
'version' => env('APP_DEBUG') ? time() : ConfigService::getVersion(),
'adminUploadUrl' => url('ajax/upload', [], false),
'adminEditor' => sysconfig('site', 'editor_type') ?: 'ueditor',
];
View::assign($data);

View File

@@ -523,3 +523,7 @@ table样式
background: goldenrod;
white-space: nowrap;
}
.wangEditor_div {
z-index: 99999;
}

View File

@@ -21,12 +21,6 @@ require.config({
"iconPickerFa": ["plugs/lay-module/iconPicker/iconPickerFa"],
"autocomplete": ["plugs/lay-module/autocomplete/autocomplete"],
"vue": ["plugs/vue-2.6.10/vue.min"],
"ckeditor": ["plugs/ckeditor4/ckeditor"],
"ueditor.config": ["plugs/ueditor/ueditor.config"],
"ueditor": ["plugs/ueditor/ueditor.all"],
"ueditor.zh-cn": ["plugs/ueditor/lang/zh-cn/zh-cn"],
"codemirror": ["plugs/ueditor/third-party/codemirror"],
"ZeroClipboard": ["plugs/ueditor/third-party/zeroclipboard/zeroclipboard"],
}
});
@@ -45,6 +39,3 @@ if ("undefined" != typeof CONFIG.AUTOLOAD_JS && CONFIG.AUTOLOAD_JS) {
});
}
require(['ZeroClipboard', 'ueditor.config', 'ueditor'], function (ZeroClipboard) {
window['ZeroClipboard'] = ZeroClipboard;
})

View File

@@ -1,4 +1,4 @@
define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefined) {
define(["jquery", "tableSelect"], function ($, tableSelect) {
var form = layui.form,
layer = layui.layer,
@@ -1326,12 +1326,18 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
// 富文本数据处理
if (editorList.length > 0) {
$.each(editorList, function (i, v) {
if (window.CONFIG.EDITOR_TYPE == 'ueditor') {
var name = $(this).attr("id");
dataField[name] = UE.getEditor(name).getContent();
} else {
var name = $(this).attr("name");
dataField[name] = CKEDITOR.instances[name].getData();
switch (window.CONFIG.EDITOR_TYPE) {
case 'ckeditor':
var name = $(this).attr("name");
dataField[name] = CKEDITOR.instances[name].getData();
break;
case 'wangEditor':
var name = $(this).attr("name");
dataField[name] = window.editor.getHtml()
break;
default:
var name = $(this).attr("id");
dataField[name] = UE.getEditor(name).getContent();
}
});
}
@@ -1484,38 +1490,76 @@ define(["jquery", "tableSelect", "ckeditor"], function ($, tableSelect, undefine
}
},
editor: function () {
CKEDITOR.tools.setCookie('ckCsrfToken', init.csrf_token);
let editorList = document.querySelectorAll(".editor");
if (editorList.length > 0) {
$.each(editorList, function (i, v) {
if (window.CONFIG.EDITOR_TYPE == 'ueditor') {
let name = $(this).attr("name");
let content = $(this).data('content')
let editorOption = {
initialFrameWidth: '100%',
initialFrameHeight: 420,
initialContent: content,
toolbars: [["fullscreen", "source", "|", "undo", "redo", "|", "bold", "italic", "underline", "fontborder", "strikethrough",
"superscript", "subscript", "removeformat", "formatmatch", "autotypeset", "blockquote", "pasteplain", "|",
"forecolor", "backcolor", "insertorderedlist", "insertunorderedlist", "selectall", "cleardoc", "|",
"rowspacingtop", "rowspacingbottom", "lineheight", "|", "customstyle", "paragraph", "fontfamily", "fontsize", "|",
"directionalityltr", "directionalityrtl", "indent", "|", "justifyleft", "justifycenter", "justifyright", "justifyjustify", "|",
"touppercase", "tolowercase", "|", "link", "unlink", "anchor", "|", "imagenone", "imageleft", "imageright", "imagecenter", "|",
"insertimage", "emotion", "insertframe", "insertcode", "pagebreak", "template", "background", "formula", "|",
"horizontal", "date", "time", "spechars", "wordimage", "|",
"inserttable", "deletetable", "insertparagraphbeforetable", "insertrow", "deleterow", "insertcol", "deletecol", "mergecells", "mergeright", "mergedown", "splittocells", "splittorows", "splittocols", "|",
"print", "preview", "searchreplace", "help",
]],
}
setTimeout(function () {
let _UEditor = new baidu.editor.ui.Editor(editorOption);
_UEditor.render(name);
}, 100)
} else {
CKEDITOR.replace($(this).attr("name"), {
height: $(this).height(),
filebrowserImageUploadUrl: admin.url('ajax/upload?type=editor'),
});
switch (window.CONFIG.EDITOR_TYPE) {
case 'ckeditor':
CKEDITOR.tools.setCookie('ckCsrfToken', init.csrf_token);
CKEDITOR.replace($(this).attr("name"), {
height: $(this).height(),
filebrowserImageUploadUrl: admin.url('ajax/upload?type=editor'),
});
break;
case 'wangEditor':
var wangEditor = window.wangEditor;
window.editor = wangEditor.createEditor({
selector: '#editor_' + $(this).attr("name"),
html: $(this).text(),
config: {
MENU_CONF: {
uploadImage: {
server: window.CONFIG.ADMIN_UPLOAD_URL,
fieldName: 'file',
meta: {
editor: 'editor',
},
async customInsert(res, insertFn) {
let code = res.code || 0
if (code != '1') {
layer.msg(res.msg || '上传失败', {icon: 2});
return
}
let url = res.data?.url || ''
let alt = ''
let href = ''
insertFn(url, alt, href)
}
}
},
}
})
window.toolbar = wangEditor.createToolbar({
editor,
selector: '#editor_toolbar_' + $(this).attr("name"),
config: {}
})
break;
default:
let name = $(this).attr("name");
let content = $(this).data('content')
let editorOption = {
initialFrameWidth: '100%',
initialFrameHeight: 420,
initialContent: content,
toolbars: [["fullscreen", "source", "|", "undo", "redo", "|", "bold", "italic", "underline", "fontborder", "strikethrough",
"superscript", "subscript", "removeformat", "formatmatch", "autotypeset", "blockquote", "pasteplain", "|",
"forecolor", "backcolor", "insertorderedlist", "insertunorderedlist", "selectall", "cleardoc", "|",
"rowspacingtop", "rowspacingbottom", "lineheight", "|", "customstyle", "paragraph", "fontfamily", "fontsize", "|",
"directionalityltr", "directionalityrtl", "indent", "|", "justifyleft", "justifycenter", "justifyright", "justifyjustify", "|",
"touppercase", "tolowercase", "|", "link", "unlink", "anchor", "|", "imagenone", "imageleft", "imageright", "imagecenter", "|",
"insertimage", "emotion", "insertframe", "insertcode", "pagebreak", "template", "background", "formula", "|",
"horizontal", "date", "time", "spechars", "wordimage", "|",
"inserttable", "deletetable", "insertparagraphbeforetable", "insertrow", "deleterow", "insertcol", "deletecol", "mergecells", "mergeright", "mergedown", "splittocells", "splittorows", "splittocols", "|",
"print", "preview", "searchreplace", "help",
]],
}
setTimeout(function () {
let _UEditor = new baidu.editor.ui.Editor(editorOption);
_UEditor.render(name);
}, 100)
break;
}
});
}

View File

@@ -1242,15 +1242,16 @@
};
_globalConfig.hoverClass = "zeroclipboard-is-hover";
_globalConfig.activeClass = "zeroclipboard-is-active";
if (typeof define === "function" && define.amd) {
define(function() {
return ZeroClipboard;
});
} else if (typeof module === "object" && module && typeof module.exports === "object" && module.exports) {
module.exports = ZeroClipboard;
} else {
window.ZeroClipboard = ZeroClipboard;
}
// if (typeof define === "function" && define.amd) {
// define(function() {
// return ZeroClipboard;
// });
// } else if (typeof module === "object" && module && typeof module.exports === "object" && module.exports) {
// module.exports = ZeroClipboard;
// } else {
// window.ZeroClipboard = ZeroClipboard;
// }
window.ZeroClipboard = ZeroClipboard;
})(function() {
return this;
}());

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long