From 578fa91d36a3b2ff568744d891a186884095cf2c Mon Sep 17 00:00:00 2001 From: augushong Date: Fri, 15 Aug 2025 23:16:13 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=BC=80=E5=A7=8B=E5=85=A8=E9=A1=B5?= =?UTF-8?q?=E9=9D=A2=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- extend/base/admin/view/index/index.js | 1 + extend/base/admin/view/system/admin/add.html | 5 +- .../plugs/lay-module/layuimini/miniTab.js | 69 ++++++--- .../static/plugs/ulthon-admin/ulthon-admin.js | 140 ++++++++++++------ 4 files changed, 151 insertions(+), 64 deletions(-) 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..fb81980 100644 --- a/extend/base/admin/view/system/admin/add.html +++ b/extend/base/admin/view/system/admin/add.html @@ -53,7 +53,10 @@
- + {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..d4bc158 100644 --- a/public/static/plugs/lay-module/layuimini/miniTab.js +++ b/public/static/plugs/lay-module/layuimini/miniTab.js @@ -69,14 +69,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 +112,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; }, @@ -245,14 +252,29 @@ 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) { miniTab.create({ tabId: tabId, @@ -264,6 +286,11 @@ } parent.layui.element.tabChange('layuiminiTab', tabId); parent.layer.close(loading); + if(back == 1){ + console.log(back); + + miniTab.delete(ua.getCurrentPageId()); + } }); /** @@ -404,19 +431,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..c122eca 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,7 @@ toolbarHtml += ' \n'; } else if (v === 'add') { if (admin.checkAuth('add', elem)) { - toolbarHtml += '\n'; + toolbarHtml += '\n'; } } else if (v === 'delete') { if (admin.checkAuth('delete', elem)) { @@ -1112,7 +1112,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 + '" ' : ''; } @@ -2261,39 +2262,7 @@ 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.refreshTable = option.refreshTable || false; @@ -2406,6 +2375,7 @@ // 判断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; } @@ -2422,7 +2392,48 @@ complete = complete || function () { $(form).removeClass('loading'); }; - admin.api.form(url, dataField, ok, no, ex, refresh, close, complete); + // 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) { + if (backHref) { + var backWindow = admin.findPageId(backHref); + console.log(backWindow); + console.log(option.refreshTable); + + backWindow.layui.table.reloadData(option.refreshTable); + + admin.findIndexPage(function (window) { + window.layui.element.tabDelete('layuiminiTab', backHref); + }); + + } else { + admin.api.closeCurrentOpen({ + refreshTable: refreshTable, + onClose: function () { + complete(); + } + }); + } + } + }); + return false; + }; + } + + admin.request.post({ + url: url, + data: data, + }, ok, no, ex, complete); return false; }); @@ -3097,6 +3108,51 @@ } return oldValue; + }, + isCurrentIndex() { + console.log(window.pageType); + + 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){ + window.layui.$('.layui-tab-title li').each(function () { + var checkTabId = $(this).attr('lay-id'); + + if (checkTabId != null && checkTabId === tabId) { + iframeWindow = $(this).find('iframe').contentWindow + } + }); + }) + return iframeWindow } };