const _token = ''; let insTb; let Tools = { getInsTb: function () { return insTb; }, setInsTb: function (ins) { insTb = ins; } } layui.use(['jquery', 'form', 'layer', 'miniTab', 'laytpl', 'table', 'skuTable'], function () { let $ = layui.jquery, form = layui.form, layer = layui.layer, miniTab = layui.miniTab, skuTable = layui.skuTable, table = layui.table; let modifyUrl = $('#row-modify').data('url'); miniTab.listen(); //页面加载时,根据需要加载富文本编辑器 if ($('.editor').length) { editor(); } //监听配置页面提交 form.on('submit(saveConfig)', function (data) { let url = $(data.elem).data('url'); $.post(url, data.field, function (res) { layer.msg(res.msg); if (res.code === 0) { setTimeout(function () { //关闭当前弹出层 miniTab.deleteCurrentByIframe(); }, 1000) } }); return false; }); //监听提交 form.on('submit(saveBtn)', function (data) { let url = $(data.elem).data('url'); let isTab = $(data.elem).data('tab'); let index = layer.load(2); $.post(url, data.field, function (res) { layer.close(index); layer.msg(res.msg); if (res.code === 0) { if (isTab) { //关闭tab setTimeout(function () { miniTab.deleteCurrentByIframe(); }, 1000) } else { //刷新父级列表 parent.layui.$('[data-table-refresh]').trigger("click"); setTimeout(function () { //关闭当前弹出层 let iframeIndex = parent.layer.getFrameIndex(window.name); parent.layer.close(iframeIndex); }, 1000) } } }); return false; }); //监听关闭 form.on('submit(close)', function () { let iframeIndex = parent.layer.getFrameIndex(window.name); parent.layer.close(iframeIndex); return false; }); //监听单元格编辑 table.on('edit(table-container-filter)', function (obj) { let insTb = Tools.getInsTb(); $.post(modifyUrl, {id: obj.data.id, field: obj.field, value: obj.value}, function (res) { layer.msg(res.msg) if (res.code !== 0 || obj.field === 'sort') { refreshTab(insTb); } }) }); //监听状态改变 form.on('switch(changeStatus)', function (obj) { let val = obj.elem.checked ? 1 : 0; let insTb = Tools.getInsTb(); $.post(modifyUrl, {id: this.value, field: this.name, value: val}, function (res) { layer.msg(res.msg) if (res.code !== 0) { setTimeout(function () { refreshTab(insTb); }, 1000) } }) }); // 监听搜索操作 form.on('submit(data-search-btn)', function (data) { //执行搜索重载 table.reload('table-container', { page: {curr: 1} , where: {searchParams: data.field} }, 'data'); return false; }); //监听工具条 注意区别toolbar和tool toolbar是表头上的工具条 tool是行中的工具条 table.on('toolbar(table-container)', function (obj) { let layEvent = obj.event; let insTb = Tools.getInsTb(); let url = $($(this).context).data('href') let title = $($(this).context).data('title') let width = $($(this).context).data('width') ? $($(this).context).data('width') : '100%'; let height = $($(this).context).data('height') ? $($(this).context).data('height') : '100%'; // debugger; switch (layEvent) { // toolbar 删除 case 'del': let checkStatus = table.checkStatus('table-container'); if (checkStatus.data.length <= 0) { layer.msg('请先选择数据'); return false; } let selected = checkStatus.data; let ids = []; $.each(selected, function (index, val) { ids.push(val.id); }) delRow(url, ids, insTb); return false; // toolbar 刷新 case 'refresh': refreshTab(insTb); return false; // toolbar 搜索 case 'search': let search = $('.table-search-fieldset'); if (search.hasClass('div-show')) { search.css('display', 'none').removeClass('div-show'); } else { search.css('display', 'block').addClass('div-show'); } return false; // 其他 默认为打开弹出层 default: if (layEvent !== 'LAYTABLE_COLS' && layEvent !== 'LAYTABLE_EXPORT') { openLayer(url, title, width, height); return false; } } }); //监听行工具条 table.on('tool(table-container)', function (obj) { let data = obj.data; let layEvent = obj.event; let url = $($(this).context).data('href'); let title = $($(this).context).data('title'); let width = $($(this).context).data('width') ? $($(this).context).data('width') : '100%'; let height = $($(this).context).data('height') ? $($(this).context).data('height') : '100%'; let insTb = Tools.getInsTb(); switch (layEvent) { // 行 删除 case 'del': let ids = [data.id]; delRow(url, ids, insTb); return false; //其他 默认为打开弹出层 default: openLayer(url, title, width, height); return false; } }); /** 图片预览 **/ $('body').on('click', '.layui-layer-photos', function () { layer.photos({ photos: '.layui-layer-photos' // 指向图片的父容器 ,anim: 5 //0-6的选择,指定弹出图片动画类型,默认随机(3.0之前的版本用shift参数) }); }) }); //富文本编辑器,单页面可以添加多个,需要使用不同的ID TODO 使用的原CMS操作 function editor() { layui.use(['jquery', 'wangEditor'], function () { let $ = layui.jquery, E = layui.wangEditor; if ($('.editor').length) { $.each($('.editor'), function (i) { var wang = new E(this); var $text1 = $(this).parent().find('textarea'); wang.customConfig.onchange = function (html) { // 监控变化,同步更新到 textarea $text1.val(html) } wang.customConfig.pasteTextHandle = function (content) { if (content == '' && !content) return '';//其中content就是你zhantie过来的原始的文本 return removeFormatWrd(content); }; function removeFormatWrd(html) { // console.log(html) // html = html.replace(/[\s\S]*?<\/xml>/ig, ''); // html = html.replace(/