|
@@ -123,7 +123,7 @@ const myNewComponentTypes = (editor) => {
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
|
const csrfToken = document.querySelector('meta[name="csrf-token"]').getAttribute('content');
|
|
// 创建 GrapesJS 编辑器实例
|
|
// 创建 GrapesJS 编辑器实例
|
|
const editor = grapesjs.init({
|
|
const editor = grapesjs.init({
|
|
- container: '#gjs', // 指定编辑器容器的 DOM 元素
|
|
|
|
|
|
+ container: '#mtb_visual_editor', // 指定编辑器容器的 DOM 元素
|
|
fromElement: true, // 从 DOM 元素中加载初始内容
|
|
fromElement: true, // 从 DOM 元素中加载初始内容
|
|
height: '100%', // 设置编辑器的高度
|
|
height: '100%', // 设置编辑器的高度
|
|
width: '100%', // 设置宽度自适应
|
|
width: '100%', // 设置宽度自适应
|
|
@@ -326,13 +326,16 @@ editor.on('load', () => {
|
|
customSelect = document.querySelector('.custom-select');
|
|
customSelect = document.querySelector('.custom-select');
|
|
// 创建 sendButton 按钮
|
|
// 创建 sendButton 按钮
|
|
const sendButton = document.createElement('button');
|
|
const sendButton = document.createElement('button');
|
|
- sendButton.textContent = 'publish'; // 按钮文本
|
|
|
|
|
|
+ sendButton.textContent = publishBtnName; // 按钮文本
|
|
sendButton.classList.add('send-button');
|
|
sendButton.classList.add('send-button');
|
|
sendButton.classList.add('layui-btn');
|
|
sendButton.classList.add('layui-btn');
|
|
sendButton.classList.add('layui-btn-radius');
|
|
sendButton.classList.add('layui-btn-radius');
|
|
sendButton.classList.add('layui-btn-radius');
|
|
sendButton.classList.add('layui-btn-radius');
|
|
sendButton.style = 'margin-left:10px;height:25px;line-height:25px;padding:0 10px;vertical-align:unset;'; // 添加样式(可选)
|
|
sendButton.style = 'margin-left:10px;height:25px;line-height:25px;padding:0 10px;vertical-align:unset;'; // 添加样式(可选)
|
|
customSelect.insertAdjacentElement('afterend', sendButton);
|
|
customSelect.insertAdjacentElement('afterend', sendButton);
|
|
|
|
+
|
|
|
|
+ //关闭loading
|
|
|
|
+ layer.close(loadIndex);
|
|
});
|
|
});
|
|
|
|
|
|
//更新时调用接口保存数据
|
|
//更新时调用接口保存数据
|
|
@@ -360,15 +363,18 @@ editor.on('update', () => {
|
|
});
|
|
});
|
|
});
|
|
});
|
|
|
|
|
|
-// 上传图片时触发
|
|
|
|
-var layer = layui.layer;
|
|
|
|
-var loadIndex = null;
|
|
|
|
|
|
+// 上传图片时触发loading效果
|
|
editor.on('asset:upload:start', () => {
|
|
editor.on('asset:upload:start', () => {
|
|
loadIndex = layer.load(0, {shade: [0.5, '#000']});
|
|
loadIndex = layer.load(0, {shade: [0.5, '#000']});
|
|
});
|
|
});
|
|
|
|
|
|
-// The upload is ended (completed or not)
|
|
|
|
editor.on('asset:upload:end', () => {
|
|
editor.on('asset:upload:end', () => {
|
|
layer.close(loadIndex);
|
|
layer.close(loadIndex);
|
|
});
|
|
});
|
|
|
|
|
|
|
|
+// 图片懒加载
|
|
|
|
+layui.use('flow', function(){
|
|
|
|
+ var flow = layui.flow;
|
|
|
|
+ //当你执行这样一个方法时,即对页面中的全部带有 lay-src 的 img 元素开启了懒加载(当然你也可以指定相关 img)
|
|
|
|
+ flow.lazyimg();
|
|
|
|
+});
|