(\s|[\r\n]| )*<\/div>/.test(oldHtml)) {
html = oldHtml.replace(/
(\s|[\r\n]| )*<\/div>/g, newHtml);
} else {
html = oldHtml + '
' + newHtml;
}
let str = html.substring(html.length - 10);
if (!str.includes('
';
}
return html;
};
//插入商品卡片
let insertHtml = function (html, insert = false) {
let editor;
if (typeof KindEditor !== 'undefined') {
if (insert) {
KindEditor.sync("#c-content");
KindEditor.html('#c-content', formatHtml(KindEditor('#c-content').val(), html));
} else {
KindEditor.insertHtml("#c-content", html);
}
} else if (typeof UM !== 'undefined' && typeof UM.list["c-content"] !== 'undefined') {
editor = UM.list["c-content"];
if (insert) {
editor.setContent(formatHtml(editor.getContent(), html));
} else {
editor.execCommand("insertHtml", html);
}
} else if (typeof UE !== 'undefined' && typeof UE.list["c-content"] !== 'undefined') {
editor = UE.list["c-content"];
if (insert) {
editor.setContent(formatHtml(editor.getContent(), html));
} else {
editor.execCommand("insertHtml", html);
}
} else if ($("#c-content").data("summernote")) {
editor = $('#c-content');
if (insert) {
editor.summernote('code', formatHtml(editor.summernote('code'), html))
} else {
editor.summernote('pasteHTML', html);
}
} else if (typeof Simditor !== 'undefined' && typeof Simditor.list['c-content'] !== 'undefined') {
editor = Simditor.list['c-content'];
if (insert) {
editor.setValue(formatHtml(editor.getValue(), html));
} else {
editor.setValue(editor.getValue() + html);
}
} else if (typeof tinymce !== 'undefined' && typeof tinymce.get('c-content') !== 'undefined') {
editor = tinymce.get('c-content');
if (insert) {
editor.setContent(formatHtml(editor.getContent(), html));
} else {
editor.insertContent(html);
}
} else if (html && insert) {
Layer.open({
content: "你的编辑器暂不支持插入HTML代码,请手动复制以下代码到你的编辑器" + "
", title: "温馨提示"
});
}
};
//点击插入卡片按钮
$(document).on('click', '.btn-card', function () {
insertHtml('
');
let cancelCallback = function () {
insertHtml('', 1);
};
Layer.open({
id: 'goods-tpl-select',
type: 1,
title: '请选择卡片模板',
area: ['600px', '210px'],
content: Template('tplselect', {}),
zIndex: 99,
shade: 0,
btn: ["确定", "取消"],
success: function (layero, index) {
Form.events.selectpage($(".c-select-goods", layero));
require(['selectpage'], function () {
$('.selectpage', $('.select-template', layero)).selectPage({
eAjaxSuccess: function (data) {
data.totalRow = data.total;
return data;
},
eSelect: function (row) {
switch (row.type) {
case 0://商品
$('.c-select-goods', layero).html(Template('goodstemplte', {}));
break;
case 1://优惠券
$('.c-select-goods', layero).html(Template('coupontemplte', {}));
break;
}
setTimeout(function () {
Form.events.selectpage($(".c-select-goods", layero));
}, 100);
}
});
});
},
yes: function (index, layero) {
let tpl = $('#c-template', layero).val();
let source_id = $('#c-source_id', layero).val();
if (!tpl) {
Toastr.error('请选择卡片模板');
return;
}
if (!source_id) {
Toastr.error('请选择资源数据');
return;
}
Fast.api.ajax({
url: 'shop/ajax/get_tpl',
data: {
tpl_id: tpl,
source_id
}
}, function (html) {
insertHtml(html, 1);
Layer.close(index);
return false;
})
},
cancel: cancelCallback,
btn2: cancelCallback
});
});
},
preview: function () {
let content = $('#c-content').val();
content = content.replace(/\{\$.*?title\s{0,}\}/g, '标题')
.replace(/\{\$.*?name\s{0,}\}/g, '名称')
.replace(/\{\$.*?price\s{0,}\}|\{\$.*?marketprice\s{0,}\}|\{\$.*?number\s{0,}\}/g, '0.0')
.replace(/\{\$.*?result_tips\s{0,}\}/g, '满?减?')
.replace(/\{\$.*?expire_time\s{0,}\}/g, '过期时间')
.replace(/\{if.*?\/if\}/g, '?')
.replace(/\{.*?\}/g, '--');
let dom = $(content)
dom.find('img').attr('src', '/assets/addons/shop/img/swiper2.jpg')
dom.find('a').attr('href', 'javascript:;').attr('target', '');
$('#preview').html(dom.html());
}
}
};
return Controller;
});