From 044aaaa01c29c34b18c2370e81a8e5b6252782dd Mon Sep 17 00:00:00 2001 From: “shentao” Date: Thu, 13 Oct 2016 21:29:22 +0800 Subject: GSO-16 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: Ib677365c7e0550e56aa8a8dd859af2cb156563cf Signed-off-by: “shentao” --- .../main/webapp/common/js/core/load_menuList.js | 69 ++++++ .../main/webapp/common/js/core/openoFrameWork.js | 235 +++------------------ 2 files changed, 103 insertions(+), 201 deletions(-) create mode 100644 openo-portal/portal-common/src/main/webapp/common/js/core/load_menuList.js (limited to 'openo-portal/portal-common/src/main/webapp/common/js/core') diff --git a/openo-portal/portal-common/src/main/webapp/common/js/core/load_menuList.js b/openo-portal/portal-common/src/main/webapp/common/js/core/load_menuList.js new file mode 100644 index 00000000..c56952e5 --- /dev/null +++ b/openo-portal/portal-common/src/main/webapp/common/js/core/load_menuList.js @@ -0,0 +1,69 @@ +/* + * Copyright 2016, CMCC Technologies Co., Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +var initLeftMenu = function() { + var i18nName = "openo_frame_left_menu_i18n"; + var parentMenus; + var childMenus; + + $.ajax({ + async : false, + "type" : "GET", + url : "json/menu_list.json", + dataType : "json", + "success" : function (res, textStatus, jqXHR) { + parentMenus = res.parentMenus; + childMenus = res.childMenus; + }, + error : function () { + } + }); + + var templateParent = "" + + "" + + "" + + "" + + "" + + ""; + + var templateChild = "
  • " + + "" + + "" + + "" + + "" + + "
  • "; + + var menuContent = ""; + for (var i = 0; i < parentMenus.length; i++) { + var parentMenuContent = templateParent.replace("{id}", parentMenus[i].id) + .replace("{iconClass}", parentMenus[i].iconClass) + .replace("{i18nName}", i18nName); + + var childMenuContent = ""; + for (var j = 0; j < childMenus.length; j++) { + if (childMenus[j].parentId == parentMenus[i].id) { + childMenuContent = childMenuContent + templateChild.replace("{id}", childMenus[j].id) + .replace("{url}", childMenus[j].url) + .replace("{iconClass}", childMenus[j].iconClass) + .replace("{i18nName}", i18nName); + } + } + childMenuContent = ""; + + menuContent = menuContent + "
  • " + parentMenuContent + childMenuContent + "
  • "; + } + + return menuContent; +} \ No newline at end of file diff --git a/openo-portal/portal-common/src/main/webapp/common/js/core/openoFrameWork.js b/openo-portal/portal-common/src/main/webapp/common/js/core/openoFrameWork.js index beebcb87..267b7219 100644 --- a/openo-portal/portal-common/src/main/webapp/common/js/core/openoFrameWork.js +++ b/openo-portal/portal-common/src/main/webapp/common/js/core/openoFrameWork.js @@ -3172,39 +3172,37 @@ var openoFrameWork = function () { }(); -var currentRunningScriptSrcPath = {}; //抽取html片段中任意位置的script标签(包括代码是内嵌的情况)逐个运行(不会在单个script加载不到的时候停下来) function runHtmlScripts(s) { var div = document.createElement('div'); div.innerHTML = s; - var scripts = div.getElementsByTagName('script'); - $(scripts).each(function(){ + var scripts = div.getElementsByTagName('script'); + + var currentRunningScriptSrcPath = {}; + $(scripts).each(function() { var src = this.src; - src=openoFrameWork.handlBaseURL(src); - if(src){ - //存储当前Script标签的绝对路径以适应该js被其他系统跨域引用的情况 - currentRunningScriptSrcPath[src.substring(src.lastIndexOf("/") + 1)] = src.substring(0, src.lastIndexOf("/")+1); - $.getScript(src); - }else{ + src = openoFrameWork.handlBaseURL(src); + if (src) { + currentRunningScriptSrcPath[src.substring(src.lastIndexOf("/") + 1)] = src.substring(0, src.lastIndexOf("/") + 1); + $.getScript(src); + } else { $.globalEval(this.text || this.textContent || this.innerHTML || ''); } }); -} -function stripHtmlScripts(s) { - var div = document.createElement('div'); - div.innerHTML = s; - var scripts = div.getElementsByTagName('script'); - $(scripts).each(function(){ - /* if(this.src){ - $.getScript(this.src); - }else{ - $.globalEval(this.text || this.textContent || this.innerHTML || ''); - } */ - this.src=openoFrameWork.handlBaseURL(this.src); +}; + +function stripHtmlScripts(htmlContent) { + var divContent = document.createElement('div'); + divContent.innerHTML = htmlContent; + var scripts = divContent.getElementsByTagName('script'); + + $(scripts).each(function() { + this.src = openoFrameWork.handlBaseURL(this.src); this.parentNode.removeChild(this); }); - return div.innerHTML; -} + return divContent.innerHTML; +}; + function getsiderBarMenu(url){ if (url.length<2){ return; @@ -3284,103 +3282,21 @@ var setLayoutValueByCookie = function () { function iniFMenu() { - var fsidemenu = $('#page-f-sidebar-menu'); - if (!fsidemenu) { - return; - } - var urlsider = fsidemenu.attr("menuSrc"); - if (urlsider && urlsider.length > 0) { - getFMenu(urlsider); - } -}; + var fsidemenu = $('#' + fMenuSiderDivId); -function getFMenu(urlSider) { - urlSider = openoFrameWork.handlBaseURL(urlSider); - openoFrameWork.startPageLoading(); + if (fsidemenu) { + openoFrameWork.startPageLoading(); - var fpagesidebar=$('#' + fMenuSiderDivId); - fpagesidebar.empty(); - fpagesidebar.append(""); - $.ajax({ - type: "GET", - cache: false, - url: urlSider, - dataType: "html", - success: function (res) { - var resScriptsSriped = stripHtmlScripts(res); - fpagesidebar.append(resScriptsSriped); - //先全部隐藏,后面根据与hash的匹配情况来显示 - //fpagesidebar.children().css('display','none'); - runHtmlScripts(res); - dealMysqlBackupMenu(); - FMenuAuthentication( fMenuMegaDivId ,fMenuSiderDivId ); - ajustFMenu( fMenuMegaDivId ,fMenuSiderDivId ); - openoFrameWork.stopPageLoading(); - //loadi18n_WebFramework_sideMenu(); - }, - error: function (xhr, ajaxOptions, thrownError) { - $('.page-f-sidebar-menu').append('');//加载系统菜单失败!;//加载系统菜单失败! - } - }); -}; -function iniSidebarMenu(){ - var sidermenu=$('#page-sidebar-menu'); - if(!sidermenu) return; - var url=sidermenu.attr("menuSrc"); - if(url&&url.length>0){ - getsiderBarMenu(url); - } -}; -function getChangePWDDlg(url){ - if (url.length<2){ - return; - } - openoFrameWork.startPageLoading();//加载中.... - var pageChangepasswd=$('.modal-dialog .Changepasswd'); - pageChangepasswd.empty(); - $.ajax({ - type: "GET", - cache: false, - url: url, - dataType: "html", - success: function (res) { - $('.modal-dialog .Changepasswd').append(res); - ChangePWD.init(); - openoFrameWork.stopPageLoading(); - }, - error: function (xhr, ajaxOptions, thrownError) { - $('.modal-dialog .Changepasswd').append('

    '+$.i18n.prop('com_zte_ums_ict_framework_ui_loadchgpwdpageError')+'

    ');//加载修改密码页面失败! - } - }); -}; -function iniChangePWDDlg(){ - var url=$('.modal-dialog .Changepasswd').attr("dlgsrc"); - if(url&&url.length>0){ - getChangePWDDlg(url); - } -}; -function getHeaderMenu(url){ - if (url.length<2){ - return; - } - openoFrameWork.startPageLoading();//加载中请稍候.... - var headerMenu=$('#headerMenu'); - headerMenu.empty(); - $.ajax({ - type: "GET", - cache: false, - async: false, - url: url, - dataType: "html", - success: function (res) { - $('#headerMenu').append(res); - openoFrameWork.stopPageLoading(); - }, - error: function (xhr, ajaxOptions, thrownError) { - //$('#headerMenu').append('

    '+$.i18n.prop('com_zte_ums_ict_framework_ui_loadmenuerror')+'

    ');//加载系统菜单失败! - } - }); + var menuContent = initLeftMenu(); + fsidemenu.empty(); + fsidemenu.append(""); + fsidemenu.append(menuContent); + loadi18n_WebFramework('web-framework-menu-i18n', 'i18n/', 'openo_frame_left_menu_i18n'); + + openoFrameWork.stopPageLoading(); + } }; + function goToHomePage(){ locationhash = openoFrameWork.getLocationHash(); if(!!locationhash&&locationhash.length>0){//有锚点,直接触发 @@ -3608,90 +3524,7 @@ function horMenuAuthentication( horMenuId ) { }); rebuildHorMenu(); }; -//根据F菜单的竖菜单来调整横菜单。获取hparentid相同的竖菜单中的第一个,来更新横菜单上对应父亲菜单的href、catchnum等信息 -function ajustFMenu(megaBarDivId , siderbarDivId){ - var hparentIds = {}; - $('a[hparentid]', $('#'+ siderbarDivId)).each(function () { - var hparentId = $(this).attr("hparentId"); - var parentMenu = $('a[id = ' + hparentId + ']', $('#' + megaBarDivId)); - var oldAHref = parentMenu.attr("href"); - if (oldAHref == null || oldAHref.trim() == "#" || oldAHref == "javascript") { - var hrefMenu = $(this); - //竖菜单的第一级有可能是虚菜单,则找这个虚节点下面的第一个有href的菜单 - if( $(this).attr('href') == null || $(this).attr('href') == "#" || $(this).attr('href') == "javascript:;"){ - $('a[href]', $(this).parent().children('ul')).each(function () { - hrefMenu = $(this); - if (hrefMenu != null && hrefMenu != "#" && hrefMenu != "javascript") { - return false; //跳出循环 - } - }) - } - parentMenu.attr("href", hrefMenu.attr("href")); - parentMenu.attr("shiftjs", hrefMenu.attr("shiftjs")); - parentMenu.attr("cachenum", hrefMenu.attr("cachenum")); - parentMenu.attr("iframeName", hrefMenu.attr("iframeName")); - parentMenu.attr("xdomain", hrefMenu.attr("xdomain")); - parentMenu.attr("cssSrc", hrefMenu.attr("cssSrc")); - parentMenu.attr("category", hrefMenu.attr("category")); - parentMenu.attr("breadcrumgroupbuttonsrc", hrefMenu.attr("breadcrumgroupbuttonsrc")); - parentMenu.attr("operation", hrefMenu.attr("operation")); - parentMenu.attr("iframeautoscroll", hrefMenu.attr("iframeautoscroll")); - } - }); -} -function FMenuAuthentication(megaBarDivId , siderbarDivId){ - var beforeHparentId = {}; - $('a[hparentid]', $('#'+ siderbarDivId)).each(function(){ - var parentid = $(this).attr("hparentid"); - beforeHparentId[parentid] = 1; - }); - checkFmenuRightByAttr('licenseid' , megaBarDivId , siderbarDivId , getLcsRight); - checkFmenuRightByAttr('operation' , megaBarDivId , siderbarDivId, getAllOperCodeRights); - rebuildSiderBarMenu(); - var afterHparentId={}; - $('a[hparentid]', $('#'+ siderbarDivId)).each(function(){ - var parentid = $(this).attr("hparentid"); - afterHparentId[parentid] = 1; - }); - //比较鉴权前后的父菜单差异,如果这个父菜单自己没有href属性,且鉴权后,所有的子菜单都没有权限,那么这个父菜单需要从界面上去掉 - for( var parentid in beforeHparentId ){ - if( afterHparentId[parentid] == null ){ - var parent = $('#'+ parentid , $('#'+ megaBarDivId)); - if(parent.attr('href') == null || parent.attr('href') == "javascript:;" || parent.attr('href') == "#"){ - parent.parent().remove(); - } - } - } -} -function checkFmenuRightByAttr( attrName, megaBarDivId , siderbarDivId ,callback ){ - // license 鉴权 - var menuids = new Array(); - var parentMenuId = new Array(); - var operations = new Array(); - //从页面DOM取得菜单license项。 - $('a['+ attrName+']', $('#'+ siderbarDivId)).each(function () { - var attrValue = $(this).attr(attrName); - if (attrValue) { - operations.push(attrValue); - var id = $(this).attr("id"); - menuids.push({'id':id }); - } - }); - var rights = callback(operations);// 取得license数据。 - if (rights && (rights.length == menuids.length)) { - // 根据后台license值判断所在菜单项是否显示 - for (var i = 0; i < menuids.length; i++) { - var id = menuids[i].id; - var hparentId =menuids[i].hParentId; - var key = operations[i]; - var item = rights[i]; - // 菜单项如果配了licenseid, 并且不是true字符串, 则移除菜单项 - if (item.value != "True") { - $('#'+id, $('#'+ siderbarDivId)).parent().remove(); - } - } - } -} + // “更多操作”分组按钮鉴权 function groupButtonAuthentication() { // license 鉴权 -- cgit 1.2.3-korg