diff --git a/lib/zin/wg/mainnavbar/js/v1.js b/lib/zin/wg/mainnavbar/js/v1.js index b8bb553a67..023c1e3b2f 100644 --- a/lib/zin/wg/mainnavbar/js/v1.js +++ b/lib/zin/wg/mainnavbar/js/v1.js @@ -39,12 +39,13 @@ function getCurrentMainNavbarItems() { const $elm = $(element); $a = $elm.find('a'); - items.push( - { - name: $a.attr('data-id'), - order: index * 5 - } - ); + + const menuItem = {}; + menuItem.name = $a.attr('data-id'), + menuItem.order = index * 5; + if(typeof $elm.data('hidden') != 'undefined') menuItem.hidden = true; + + items.push(menuItem); } ); return items; @@ -157,7 +158,7 @@ $(document).on( onClick: hideDisabled ? null : () => { - $li.remove(); + $li.hide().attr('data-hidden', '1'); saveMainNavbarToServer($item); } }, diff --git a/lib/zin/wg/navbar/js/v1.js b/lib/zin/wg/navbar/js/v1.js index ac3e269c96..d59b4f69bf 100644 --- a/lib/zin/wg/navbar/js/v1.js +++ b/lib/zin/wg/navbar/js/v1.js @@ -42,16 +42,17 @@ function getCurrentNavbarItems() $nav.children().each( function(index, element) { - const $elm = $(element) - const $a = $elm.find('a'); - items.push( - { - name: $elm.is('.nav-divider') ? 'divider' : ($a.attr('data-id') || $a.attr('id')), - order: index * 5 - } - ); + const $elm = $(element) + const $a = $elm.find('a'); + const menuItem = {}; + menuItem.name = $elm.is('.nav-divider') ? 'divider' : ($a.attr('data-id') || $a.attr('id')); + menuItem.order = index * 5; + if(typeof $elm.data('hidden') != 'undefined') menuItem.hidden = true; + + items.push(menuItem); } ); + console.log(items); return items; } @@ -198,7 +199,7 @@ $(document).on( onClick: hideDisabled ? null : () => { - $li.remove(); + $li.hasClass('nav-divider') ? $li.remove() : $li.hide().attr('data-hidden', '1'); saveNavbarToServer(); } }, diff --git a/module/common/model.php b/module/common/model.php index d7a6801502..31100fda0a 100644 --- a/module/common/model.php +++ b/module/common/model.php @@ -621,18 +621,37 @@ class commonModel extends model /* Ensure user has latest rights set. */ $app->user->rights = $app->control->loadModel('user')->authorize($app->user->account); - $menuOrder = array(); + $menuOrder = $lang->mainNav->menuOrder; $hasCustomMenu = false; if(isset($config->customMenu->nav) && !$useDefault && !commonModel::isTutorialMode()) { - $items = json_decode($config->customMenu->nav); - foreach($items as $item) $menuOrder[$item->order] = $item->name; + $customMenuOrder = array(); + $items = json_decode($config->customMenu->nav); + $hiddenItems = array(); + foreach($items as $item) + { + if(!empty($item->hidden)) + { + $hiddenItems[] = $item->name; + continue; + } + + $customMenuOrder[$item->order] = $item->name; + } + + $customMenuItems = array_values($customMenuOrder); + foreach($menuOrder as $order => $name) + { + if(in_array($name, $customMenuItems) || in_array($name, $hiddenItems)) continue; + + while(isset($customMenuOrder[$order])) $order ++; + $customMenuOrder[$order] = $name; + } + + $menuOrder = $customMenuOrder; $hasCustomMenu = true; } - else - { - $menuOrder = $lang->mainNav->menuOrder; - } + ksort($menuOrder); $items = array(); diff --git a/module/custom/control.php b/module/custom/control.php index 5209e941a9..8d469f0d37 100644 --- a/module/custom/control.php +++ b/module/custom/control.php @@ -566,6 +566,24 @@ class custom extends control $menu = $this->post->menu; // 导航类型,nav(左侧主导航)|$app(顶部一级导航)|$app-home(项目集、项目的首页导航)|$app-$subMenu(顶部二级导航)|admin-$menuKey(后台导航) $items = $this->post->items; // 导航项 $account = $this->app->user->account; + $oldMenu = isset($this->config->customMenu->{$menu}) ? $this->config->customMenu->{$menu} : ''; + + /* 之前隐藏的导航若没开启继续保持隐藏。 */ + if($oldMenu) + { + $oldMenus = json_decode($oldMenu); + $menus = json_decode($items); + + $menuNames = array(); + foreach($menus as $key => $item) $menuNames[] = $item->name; + + foreach($oldMenus as $key => $item) + { + if(!empty($item->hidden) && !in_array($item->name, $menuNames)) $menus[] = $item; + } + + $items = json_encode($menus); + } if($menu && $items) $this->loadModel('setting')->setItem("$account.common.customMenu.$menu@{$this->config->vision}", $items); } diff --git a/module/custom/model.php b/module/custom/model.php index 04b282f250..2b1b4441e4 100644 --- a/module/custom/model.php +++ b/module/custom/model.php @@ -180,7 +180,7 @@ class customModel extends model */ public static function setMenuByConfig(object|array $allMenu, string|array $customMenu, string $module = ''): array { - global $app, $lang, $config; + global $app, $lang; $tab = $app->tab; list($customMenuMap, $order) = static::buildCustomMenuMap($allMenu, $customMenu, $module); @@ -193,6 +193,7 @@ class customModel extends model } $menu = static::buildMenuItems($allMenu, $customMenuMap, $module, $order); + ksort($menu, SORT_NUMERIC); if(!isset($lang->{$tab})) return array(); @@ -364,7 +365,7 @@ class customModel extends model /* Process menu item's order and hidden attirbute. */ $menuItem = static::buildMenuItem($item, $customMenuMap, $name, $label, $itemLink, $isTutorialMode, $subMenu); $menuItem->order = (isset($customMenuMap[$name]) && isset($customMenuMap[$name]->order) ? $customMenuMap[$name]->order : $order ++); - if(!empty($customMenuMap) && !isset($customMenuMap[$name])) $menuItem->hidden = true; // 自定义过滤掉的菜单不显示。 + if(!empty($customMenuMap) && !empty($customMenuMap[$name]->hidden)) $menuItem->hidden = true; // 自定义过滤掉的菜单不显示。 if(isset($customMenuMap[$name]) && isset($customMenuMap[$name]->divider)) $menuItem->divider = true; if($app->viewType == 'mhtml' && isset($config->custom->moblieHidden[$menuModuleName]) && in_array($name, $config->custom->moblieHidden[$menuModuleName])) $menuItem->hidden = 1; // Hidden menu by config in mobile. while(isset($menu[$menuItem->order])) $menuItem->order ++; diff --git a/module/index/js/index.ui.js b/module/index/js/index.ui.js index 552ee9b9c8..2957c181d3 100644 --- a/module/index/js/index.ui.js +++ b/module/index/js/index.ui.js @@ -836,14 +836,15 @@ function getMenuNavData() const data = []; const $nav = $('#menuMainNav'); $nav.children().each(function(index, element) { - const $elm = $(element); - data.push( - { - name: $elm.is('.divider') ? 'divider' : $elm.data('app'), - order: index * 5 - } - ); + const $elm = $(element); + const menuItem = {}; + menuItem.name = $elm.is('.divider') ? 'divider' : $elm.data('app'); + menuItem.order = index * 5; + if(typeof $elm.data('hidden') != 'undefined') menuItem.hidden = true; + + data.push(menuItem); }); + return data; } @@ -864,6 +865,7 @@ function restoreMenuNavToServer() { const url = $.createLink('custom', 'ajaxRestoreMenu'); $.ajaxSubmit({url, data: {menu: 'nav'}}); + top.location.reload(); } /** @@ -979,8 +981,6 @@ $(document).on('contextmenu', '#menuMainNav .divider', function(event) { text: langData.restore, onClick: () => { - initAppsMenu(allAppsItems); - refreshMenu(); restoreMenuNavToServer(); } } @@ -1070,7 +1070,7 @@ $(document).on('click', '.open-in-app,.show-in-app', function(e) : () => { closeApp(code); const $li = $btn.closest('li'); - $li.remove(); + $li.hide().attr('data-hidden', '1'); refreshMenu(); saveMenuNavToServer(); }, @@ -1096,8 +1096,6 @@ $(document).on('click', '.open-in-app,.show-in-app', function(e) { text: langData.restore, onClick: () => { - initAppsMenu(allAppsItems); - refreshMenu(); restoreMenuNavToServer(); } }