增加 WangEditor 支持

This commit is contained in:
邹景立 2024-07-26 00:05:28 +08:00
parent e2d44537ab
commit 2e65d799ab
6 changed files with 24234 additions and 3 deletions

View File

@ -96,7 +96,7 @@ class Login extends Controller
$this->app->session->set('user', $user->toArray());
$this->app->session->delete('LoginInputSessionError');
// 更新登录次数
SystemUser::mk()->where(['id' => $user->getAttr('id')])->inc('login_num')->update([
$user->where(['id' => $user->getAttr('id')])->inc('login_num')->update([
'login_at' => date('Y-m-d H:i:s'), 'login_ip' => $this->app->request->ip(),
]);
// 刷新用户权限

View File

@ -43,8 +43,8 @@
</div>
<div class="layui-card-body layui-clear">
<div class="layui-btn-group shadow-mini">
{if !in_array(sysconf('base.editor'),['ckeditor4','ckeditor5','auto'])}{php}sysconf('base.editor','ckeditor4');{/php}{/if}
{foreach ['ckeditor4'=>'CKEditor4','ckeditor5'=>'CKEditor5','auto'=>lang('自适应模式')] as $k => $v}{if sysconf('base.editor') eq $k}
{if !in_array(sysconf('base.editor'),['ckeditor4','ckeditor5','wangEditor','auto'])}{php}sysconf('base.editor','ckeditor4');{/php}{/if}
{foreach ['ckeditor4'=>'CKEditor4','ckeditor5'=>'CKEditor5','wangEditor'=>'wangEditor','auto'=>lang('自适应模式')] as $k => $v}{if sysconf('base.editor') eq $k}
{if auth('storage')}<a data-title="配置{$v}" class="layui-btn layui-btn-sm layui-btn-active">{$v}</a>{else}<a class="layui-btn layui-btn-sm layui-btn-active">{$v}</a>{/if}
{else}
{if auth('storage')}<a data-title="配置{$v}" data-action="{:url('admin/api.system/editor')}" data-value="editor#{$k}" class="layui-btn layui-btn-sm layui-btn-primary">{$v}</a>{else}<a class="layui-btn layui-btn-sm layui-btn-primary">{$v}</a>{/if}
@ -53,6 +53,7 @@
<div class="margin-top-20 full-width pull-left">
<p><b>CKEditor4</b>{:lang('旧版本编辑器,对浏览器兼容较好,但内容编辑体验稍有不足。')}</p>
<p><b>CKEditor5</b>{:lang('新版本编辑器,只支持新特性浏览器,对内容编辑体验较好,推荐使用。')}</p>
<p><b>wangEditor</b>{:lang('国产优质富文本编辑器对于小程序及App内容支持会更友好推荐使用。')}</p>
<p><b>{:lang('自适应模式')}</b>{:lang('优先使用新版本编辑器,若浏览器不支持新版本时自动降级为旧版本编辑器。')}</p>
</div>
</div>

View File

@ -48,6 +48,7 @@ require.config({
'angular': ['plugs/angular/angular.min'],
'cropper': ['plugs/cropper/cropper.min'],
'echarts': ['plugs/echarts/echarts.min'],
'weditor': ['plugs/editor/create'],
'ckeditor4': ['plugs/ckeditor4/ckeditor'],
'ckeditor5': ['plugs/ckeditor5/ckeditor'],
'artplayer': ['plugs/jquery/artplayer.min'],
@ -55,6 +56,7 @@ require.config({
'websocket': ['plugs/socket/websocket'],
'compressor': ['plugs/jquery/compressor.min'],
'sortablejs': ['plugs/sortable/sortable.min'],
'_weditor': ['plugs/editor/index'],
'vue.sortable': ['plugs/sortable/vue.draggable.min'],
'jquery.ztree': ['plugs/ztree/ztree.all.min'],
'jquery.masonry': ['plugs/jquery/masonry.min'],
@ -65,6 +67,7 @@ require.config({
'excel': {deps: [baseRoot + 'plugs/layui_exts/excel.js']},
'notify': {deps: ['css!' + baseRoot + 'plugs/notify/theme.css']},
'cropper': {deps: ['css!' + baseRoot + 'plugs/cropper/cropper.min.css']},
'_weditor': {deps: ['css!' + baseRoot + 'plugs/editor/css/style.css']},
'websocket': {deps: [baseRoot + 'plugs/socket/swfobject.js']},
'ckeditor5': {deps: ['jquery', 'upload', 'css!' + baseRoot + 'plugs/ckeditor5/ckeditor.css']},
'vue.sortable': {deps: ['vue', 'sortablejs']},
@ -80,12 +83,17 @@ define('jquery', [], function () {
/*! 注册 ckeditor 组件 */
define('ckeditor', (function (type) {
if (type === 'wangEditor') return ['weditor'];
if (/^ckeditor[45]$/.test(type)) return [type];
return [Object.fromEntries ? 'ckeditor5' : 'ckeditor4'];
})(window.taEditor || 'ckeditor4'), function (ckeditor) {
return ckeditor;
});
require(['ckeditor'], function () {
})
$(function () {
window.$body = $('body');

View File

@ -0,0 +1,66 @@
define(['_weditor', 'upload'], function (editor) {
window.wangEditor = editor;
window.createEditor = function (ele, option) {
if ($(ele).data('editorLayout')) return;
const $layout = $('<div style="border:1px solid #ccc;z-index:1001;"><div style="border-bottom:1px solid #ccc;"></div><div style="height:400px;"></div></div>');
$(ele).hide().data('editorLayout', $layout).after($layout).parent();
// 创建编辑器
const _editor = editor.createEditor({
html: '<p><br></p>',
selector: $layout.find("div:last").get(0),
config: {
height: (option || {}).height || 500,
MENU_CONF: {
uploadImage: {
async customUpload(file, insertFn) {
if (window.AdminUploadAdapter) {
new window.AdminUploadAdapter().upload([file], url => insertFn(url, file.name))
} else {
let reader = new window.FileReader();
reader.addEventListener('load', () => insertFn(reader.result, file.name));
reader.readAsDataURL(file);
}
}
},
uploadVideo: {
async customUpload(file, insertFn) {
if (window.AdminUploadAdapter) {
new window.AdminUploadAdapter().upload([file], url => insertFn(url, file.name))
} else {
let reader = new window.FileReader();
reader.addEventListener('load', () => insertFn(reader.result, file.name));
reader.readAsDataURL(file);
}
}
}
},
placeholder: 'Type here...',
onCreated(editor) {
editor.setHtml($(ele).val());
},
onChange(editor) {
$(ele).val(editor.getHtml())
}
},
mode: 'default', // or 'simple'
})
// 设置工具栏
editor.createToolbar({
editor: _editor,
selector: $layout.find('div:first').get(0),
config: {
excludeKeys: ['fullScreen']
},
mode: 'default',
})
// 兼容其他版本
_editor.getData = function () {
return _editor.getHtml()
}
_editor.setData = function (html) {
return _editor.setHtml(html)
}
return _editor;
}
})

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long