diff --git a/.gitignore b/.gitignore index 6ea4d5f..7e95115 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,4 @@ ul.db /.VSCodeCounter result.txt test.php +/.env.prod \ No newline at end of file diff --git a/extend/base/admin/service/curd/templates/view/form.code b/extend/base/admin/service/curd/templates/view/form.code index 9e92c33..6107bbb 100644 --- a/extend/base/admin/service/curd/templates/view/form.code +++ b/extend/base/admin/service/curd/templates/view/form.code @@ -3,6 +3,9 @@ {{formList}}
+ {notempty name='$Request.param.backTagId'} +
返回
+ {/notempty}
diff --git a/extend/base/admin/view/index/index.js b/extend/base/admin/view/index/index.js index a9a02c0..e7f0dca 100644 --- a/extend/base/admin/view/index/index.js +++ b/extend/base/admin/view/index/index.js @@ -1,3 +1,4 @@ +window.pageType = 'index'; $(function () { var options = { iniUrl: ua.url('ajax/initAdmin'), // 初始化接口 diff --git a/extend/base/admin/view/system/admin/add.html b/extend/base/admin/view/system/admin/add.html index e33f123..efe3ef0 100644 --- a/extend/base/admin/view/system/admin/add.html +++ b/extend/base/admin/view/system/admin/add.html @@ -53,6 +53,9 @@
+ {notempty name='$Request.param.backTagId'} +
返回
+ {/notempty}
diff --git a/extend/base/admin/view/system/admin/edit.html b/extend/base/admin/view/system/admin/edit.html index bb4f4cc..f634b0d 100644 --- a/extend/base/admin/view/system/admin/edit.html +++ b/extend/base/admin/view/system/admin/edit.html @@ -53,6 +53,9 @@
+ {notempty name='$Request.param.backTagId'} +
返回
+ {/notempty}
diff --git a/public/static/plugs/lay-module/layuimini/miniTab.js b/public/static/plugs/lay-module/layuimini/miniTab.js index f86f6c5..72f47cf 100644 --- a/public/static/plugs/lay-module/layuimini/miniTab.js +++ b/public/static/plugs/lay-module/layuimini/miniTab.js @@ -2,12 +2,16 @@ var element = layui.element; $ = layui.$; + var miniTab = { + renderOptions: {}, /** * 初始化tab * @param options */ render: function (options) { + this.renderOptions = options; + options.filter = options.filter || null; options.urlHashLocation = options.urlHashLocation || false; options.maxTabNum = options.maxTabNum || 20; @@ -69,14 +73,9 @@ * @param isParent */ delete: function (tabId, isParent) { - // todo 未知BUG,不知道是不是layui问题,必须先删除元素 - $('.layuimini-tab .layui-tab-title .layui-unselect.layui-tab-bar').remove(); - - if (isParent === true) { - parent.layui.element.tabDelete('layuiminiTab', tabId); - } else { - element.tabDelete('layuiminiTab', tabId); - } + ua.findIndexPage(function (window) { + window.layui.element.tabDelete('layuiminiTab', tabId); + }); }, /** @@ -117,21 +116,33 @@ check: function (tabId, isIframe) { // 判断选项卡上是否有 var checkTab = false; - if (isIframe === undefined || isIframe === false) { - $('.layui-tab-title li').each(function () { + // if (isIframe === undefined || isIframe === false) { + // $('.layui-tab-title li').each(function () { + // var checkTabId = $(this).attr('lay-id'); + // if (checkTabId != null && checkTabId === tabId) { + // checkTab = true; + // } + // }); + // } else { + // parent.layui.$('.layui-tab-title li').each(function () { + // var checkTabId = $(this).attr('lay-id'); + // if (checkTabId != null && checkTabId === tabId) { + // checkTab = true; + // } + // }); + // } + + + ua.findIndexPage(function (window) { + + window.layui.$('.layui-tab-title li').each(function () { var checkTabId = $(this).attr('lay-id'); + if (checkTabId != null && checkTabId === tabId) { checkTab = true; } }); - } else { - parent.layui.$('.layui-tab-title li').each(function () { - var checkTabId = $(this).attr('lay-id'); - if (checkTabId != null && checkTabId === tabId) { - checkTab = true; - } - }); - } + }); return checkTab; }, @@ -173,6 +184,10 @@ * @param menuList */ searchMenu: function (href, menuList) { + if (!menuList) { + menuList = this.renderOptions.menuList; + } + var menu; for (key in menuList) { var item = menuList[key]; @@ -245,15 +260,41 @@ var tabId = $(this).attr('layuimini-content-href'), href = $(this).attr('layuimini-content-href'), title = $(this).attr('data-title'), + back = $(this).attr('data-back') || 0, + external = $(this).attr('data-external') || false, target = $(this).attr('target'); + + + if (back == 0) { + if (href.indexOf("?") === -1) { + href += '?backTagId=' + ua.getCurrentPageId(); + } else { + href += '&backTagId=' + ua.getCurrentPageId(); + } + } + href = external ? href : ua.url(href); + tabId = href; + if (target === '_blank') { parent.layer.close(loading); window.open(href, '_blank'); return false; } + if (tabId === null || tabId === undefined) tabId = new Date().getTime(); var checkTab = miniTab.check(tabId, true); + if (!checkTab) { + if (!title) { + title = tabId; + ua.findIndexPage(function (window) { + var menu = window.miniTab.searchMenu(tabId); + + if (menu) { + title = menu.title; + } + }); + } miniTab.create({ tabId: tabId, href: href, @@ -264,6 +305,11 @@ } parent.layui.element.tabChange('layuiminiTab', tabId); parent.layer.close(loading); + if (back == 1) { + console.log(back); + + miniTab.delete(ua.getCurrentPageId()); + } }); /** @@ -366,6 +412,7 @@ listenSwitch: function (options) { options.filter = options.filter || null; options.urlHashLocation = options.urlHashLocation || false; + options.listenSwichCallback = options.listenSwichCallback || function () { }; element.on('tab(' + options.filter + ')', function (data) { var tabId = $(this).attr('lay-id'); @@ -404,19 +451,19 @@ if (!options.urlHashLocation) return false; var tabId = location.hash.replace(/^#/, ''); if (tabId === null || tabId === undefined || tabId === '') return false; - + // 判断是否为首页 if (tabId === options.homeInfo.href || tabId === options.homeInfo.mb_href) return false; // 判断tab是否已存在 - if($('.layuimini-tab .layui-tab-content [lay-id="'+tabId+'"]').length > 0) { + if ($('.layuimini-tab .layui-tab-content [lay-id="' + tabId + '"]').length > 0) { element.tabChange('layuiminiTab', tabId); return false; } // 判断是否为右侧菜单 var menu = miniTab.searchMenu(tabId, options.menuList); - + if (menu !== undefined) { miniTab.create({ tabId: tabId, diff --git a/public/static/plugs/ulthon-admin/ulthon-admin.js b/public/static/plugs/ulthon-admin/ulthon-admin.js index 931cadd..c6e1a7e 100644 --- a/public/static/plugs/ulthon-admin/ulthon-admin.js +++ b/public/static/plugs/ulthon-admin/ulthon-admin.js @@ -144,28 +144,28 @@ }; complete = complete || function () { }; - if(no){ + if (no) { var originalNo = no; no = function (res) { originalNo(res); complete(); - } - }else{ + }; + } else { no = function (res) { var msg = res.msg == undefined ? '返回数据格式有误' : res.msg; admin.msg.error(msg); complete(); return false; - } + }; } - if(ex){ + if (ex) { var originalEx = ex; ex = function (res) { originalEx(res); complete(); - } - }else{ + }; + } else { ex = function (res) { complete(); }; @@ -524,7 +524,8 @@ toolbarHtml += ' \n'; } else if (v === 'add') { if (admin.checkAuth('add', elem)) { - toolbarHtml += '\n'; + toolbarHtml += '\n'; + // toolbarHtml += '\n'; } } else if (v === 'delete') { if (admin.checkAuth('delete', elem)) { @@ -1112,7 +1113,8 @@ formatToolbar.method = ''; } else if (toolbar.method === 'blank') { formatToolbar.method = ' href="' + formatToolbar.url + '" target="_blank" '; - + } else if (operat.method === 'tab') { + formatToolbar.method = ' layuimini-content-href="' + formatToolbar.url + '" data-title="' + formatToolbar.title + '"'; } else { formatToolbar.method = formatToolbar.method !== '' ? 'data-request="' + formatToolbar.url + '" data-title="' + formatToolbar.title + '" ' : ''; } @@ -1139,7 +1141,6 @@ var titleEndfix = ''; if (typeof operat.titleField == 'function') { - console.log(operat.titleField(data, operat)); titleEndfix = operat.titleField(data, operat); } else if (data[operat.titleField]) { @@ -1325,7 +1326,7 @@ case 'edit': var operat = { class: 'layui-btn layui-btn-success layui-btn-xs', - method: 'open', + method: 'tab', field: 'id', icon: '', text: '编辑', @@ -2261,54 +2262,50 @@ window.open(admin.url($(this).attr('href'))); }); }, - form: function (url, data, ok, no, ex, refreshTable, close, complete) { - if (refreshTable === undefined) { - refreshTable = true; - } - if(ok){ - var originalOk = ok; - ok = function (res) { - originalOk(res); - complete() - } - }else{ - ok = function (res) { - res.msg = res.msg || ''; - admin.msg.success(res.msg, function () { - if (close) { - admin.api.closeCurrentOpen({ - refreshTable: refreshTable, - onClose: function () { - complete(); - } - }); - } - }); - return false; - }; - } - admin.request.post({ - url: url, - data: data, - }, ok, no, ex, complete); - return false; - }, closeCurrentOpen: function (option) { option = option || {}; + option.backHref = option.backHref || ''; option.refreshTable = option.refreshTable || false; option.refreshFrame = option.refreshFrame || false; option.onClose = option.onClose || function () { }; if (option.refreshTable === true) { option.refreshTable = init.tableRenderId; } + var backWindow = window.parent; + if (option.backHref) { + // 标签打开页面,需要返回上一个标签刷新的情况 + backWindow = admin.findPageId(option.backHref); + if (backWindow) { + backWindow.layui.table.reloadData(option.refreshTable); + } else { + admin.findIndexPage(function (window) { + var menu = window.miniTab.searchMenu(option.backHref); + var title = option.backHref + + if(menu){ + title = menu.title; + } + window.miniTab.create({ + tabId: option.backHref, + href: option.backHref, + title: title, + }); + }); + } + admin.findIndexPage(function (window) { + window.layui.element.tabDelete('layuiminiTab', admin.getCurrentPageId()); + }); + return; + } + // 弹框保存后刷新的情况 var index = parent.layer.getFrameIndex(window.name); - parent.layer.close(index, option.onClose); + backWindow.layer.close(index, option.onClose); if (option.refreshTable !== false) { - parent.layui.table.reloadData(option.refreshTable); + backWindow.layui.table.reloadData(option.refreshTable); } if (option.refreshFrame) { - parent.location.reload(); + backWindow.location.reload(); } return false; }, @@ -2406,14 +2403,16 @@ // 判断btn是否具备name和value属性,如果有,则加到表单数据里 var btnName = $(btnElem).attr('name'); var btnValue = $(btnElem).attr('value'); + var backHref = $(btnElem).attr('data-back-href'); if (btnName !== undefined && btnValue !== undefined) { data.field[btnName] = btnValue; } + if (!backHref) { + backHref = admin.getQueryVariable('backTagId'); + } var dataField = data.field; - dataField = admin.api.formSubmitEditor(dataField, v); - dataField = admin.api.formSubmitCity(dataField, v); if (typeof preposeCallback === 'function') { @@ -2422,7 +2421,37 @@ complete = complete || function () { $(form).removeClass('loading'); }; - admin.api.form(url, dataField, ok, no, ex, refresh, close, complete); + + if (ok) { + var originalOk = ok; + ok = function (res) { + originalOk(res); + complete(); + }; + } else { + ok = function (res) { + res.msg = res.msg || ''; + admin.msg.success(res.msg, function () { + if (close) { + + admin.api.closeCurrentOpen({ + refreshTable: refresh, + backHref: backHref, + onClose: function () { + complete(); + } + }); + + } + }); + return false; + }; + } + + admin.request.post({ + url: url, + data: dataField, + }, ok, no, ex, complete); return false; }); @@ -3097,7 +3126,51 @@ } return oldValue; - } + }, + isCurrentIndex() { + if (window.pageType && window.pageType == 'index') { + return true; + } + return false; + }, + findIndexPage(findCallback, missCallback) { + if (!findCallback) { + findCallback = function (w) { return w; }; + } + if (!missCallback) { + missCallback = function (w) { return w; }; + } + if (this.isCurrentIndex()) { + return findCallback(window); + } + + var parent = window.parent; + if (parent && parent != window) { + return parent.ua.findIndexPage(findCallback, missCallback); + } + + return missCallback(null); + }, + getCurrentPageId() { + // pageId就是路径加参数 + var path = location.pathname; + var params = location.search; + return path + params; + }, + findPageId(tabId) { + var iframeWindow; + this.findIndexPage(function (window) { + // 查找对应的tab内容区域 + var tabContent = window.layui.$('.layui-tab-content .layui-tab-item[lay-id="' + tabId + '"]'); + if (tabContent.length > 0) { + var iframe = tabContent.find('iframe')[0]; + if (iframe) { + iframeWindow = iframe.contentWindow; + } + } + }); + return iframeWindow; + }, };