Skip to content

Commit

Permalink
feat: layui主题支持url中#号后面的地址作为一个标签页打开
Browse files Browse the repository at this point in the history
  • Loading branch information
xxred committed Nov 20, 2023
1 parent 19b1e14 commit d6cc4ce
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions NewLife.CubeNC/wwwroot/Content/layui/layui_main_cube.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ layui.use(['element_cube', 'layer', 'util'], function () {
var title = othis.data('title');

cubeAddTab(url, title);

// 将链接记录到url的hash,下次打开该链接将自动打开该标签页
location.hash = url;
}
});

Expand Down Expand Up @@ -113,4 +116,20 @@ layui.use(['element_cube', 'layer', 'util'], function () {

return false;
};

// 判断url是否存在hash,自动打开该标签页
if (location.hash && location.hash.startsWith('#/')) {
const url = location.hash.replace('#', '');
const eleA = $(`.layui-nav .layui-nav-item dd a[data-url="${url}"]`)
if (eleA) {
// 点击对应菜单
eleA.click()
// 菜单对应父级
const eleLi = eleA.parents('.layui-nav-item')
// 关闭其他打开菜单
eleLi.siblings('.layui-nav-itemed').find('>a').click()
// 展开父级菜单
if (!eleLi.hasClass('layui-nav-itemed')) eleLi.find('>a').click()
}
}
});

0 comments on commit d6cc4ce

Please sign in to comment.