import menulist from "./components/index/Menulist.js"; import breadcrumb from "./components/index/Breadcrumb.js"; import tabs from "./components/index/Tabs.js"; import themesetting from "./components/index/ThemeSetting.js"; import message from "./components/index/Message.js"; import fullscreen from "./components/index/Fullscreen.js"; import trash from "./components/index/Trash.js"; import platform from "./components/index/Platform.js"; import userinfo from "./components/index/Userinfo.js"; import {getUniqid} from "./util.js"; const findBreadcrumbById=function(tree, targetId, result = []) { for (let i = 0; i < tree.length; i++) { const node = tree[i]; if (node.id === targetId) { result.push(node); if (node.pid !== 0) { findBreadcrumbById(tree, node.pid, result); } break; } else if (node.childlist.length > 0) { findBreadcrumbById(node.childlist, targetId, result); if (result.length > 0) { result.push(node); break; } } } return result.reverse(); } const findTabsMenu=function(menu) { if(menu.childlist.length===0){ return menu; } let r; if(menu.childlist.length>0){ for(let i in menu.childlist){ r=findTabsMenu(menu.childlist[i]); if(r.childlist.length===0){ break; } } } return r; } const inJson=function(json, id) { for (var i = 0; i < json.length; i++) { if (json[i].id === id) { return true; } else if (json[i].childlist && json[i].childlist.length > 0) { if (inJson(json[i].childlist, id)) { return true; } } } return false; } const findChildMenu=function (menu){ for(let i_0=0;i_00){ let menulist1=Yunqi.data.menulist[i_0].childlist; for(let i_1=0;i_10){ if(inJson(menulist1[i_1].childlist,menu.id)){ return menulist1; } } } } } } export default{ components:{ 'Menulist':menulist, 'Breadcrumb':breadcrumb, 'Tabs':tabs, 'ThemeSetting':themesetting, 'Message':message, 'Fullscreen':fullscreen, 'Trash':trash, 'Platform':platform, 'Userinfo':userinfo }, data(){ return { documentWidth:'', contentWidth:'', contentHeight:'', menuHeight: '', layerExpandHeight:0, elementUi:'', menuList:[], childMenuList:[], breadcrumb:[], activeTab:'', activeLayer:'', openMenu:'', layerList:[], tabList:[], imageList:[], mainFrameExpand:false, logo_img:'' } }, onLoad:function (){ this.elementUi=Yunqi.getElementUi(); this.changeLogo(); this.menuList=Yunqi.data.menulist; this.initMainContentFrame(); }, onShow:function (){ this.clickMenu(Yunqi.data.selected); if(Yunqi.data.referer.url){ this.clickMenu(Yunqi.data.referer); } }, methods:{ changeLogo:function (){ if(this.elementUi.dark){ this.logo_img=Yunqi.data.site.logo_white; return; } if(this.elementUi.layout=='vertical'){ this.logo_img=Yunqi.data.site.logo; return; } this.logo_img=Yunqi.data.site.logo_white; }, initMainContentFrame:function (){ this.setMainContentFrame(); //监听屏幕宽度变化 window.addEventListener('resize',()=>{ let contentWidth=document.documentElement.clientWidth; if(contentWidth<800){ this.elementUi.is_menu_collapse=true; }else{ this.elementUi.is_menu_collapse=false; } this.setMainContentFrame(); }); }, setMainContentFrame:function (){ let documentWidth=document.documentElement.clientWidth; let contentWidth=document.documentElement.clientWidth; if(documentWidth>600){ contentWidth=contentWidth-25; if(this.elementUi.layout=='vertical' || this.elementUi.layout=='classic'){ if(this.elementUi.is_menu_collapse){ contentWidth=contentWidth-65; }else{ contentWidth=contentWidth-210; } } if(this.elementUi.layout=='columns'){ contentWidth=contentWidth-70; if(this.childMenuList.length>0 && this.elementUi.is_menu_collapse){ contentWidth=contentWidth-65; } if(this.childMenuList.length>0 && !this.elementUi.is_menu_collapse){ contentWidth=contentWidth-210; } } } let contentHeight=document.documentElement.clientHeight-75; if(this.elementUi.tabs){ contentHeight=contentHeight-40; } if(this.elementUi.footer){ contentHeight=contentHeight-32; } let menuHeight=document.documentElement.clientHeight-55; let layerExpandHeight=document.documentElement.clientHeight-92; this.parseZoom(documentWidth,contentWidth,contentHeight,menuHeight,layerExpandHeight); }, parseZoom:function (documentWidth,contentWidth,contentHeight,menuHeight,layerExpandHeight){ let zoom=1; this.documentWidth=documentWidth/zoom; this.contentWidth=contentWidth/zoom; this.contentHeight=contentHeight/zoom; this.menuHeight=menuHeight/zoom; this.layerExpandHeight=layerExpandHeight/zoom; }, isChildMenu:function (id){ let breadcrumb=findBreadcrumbById(Yunqi.data.menulist,this.activeTab.id,[]); for(let i in breadcrumb){ if(id==breadcrumb[i].id){ return true; } } return false; }, layerExpand:function (layer){ layer.expand=!layer.expand; let tab=document.getElementById('layer-'+layer.id).contentWindow; tab.Yunqi.app.setContentHeight_(); }, maximize:function (){ let id=this.activeTab.id; let tab=document.getElementById('addtabs-'+id).contentWindow; let expand=tab.document.getElementById('mainFrameExpand'); if(expand){ expand.click(); }else{ this.mainFrameExpand=true; } tab.Yunqi.app.setContentHeight_(); }, minimize:function (){ let id=this.activeTab.id; let tab=document.getElementById('addtabs-'+id).contentWindow; let expand=tab.document.getElementById('mainFrameExpand'); if(expand){ expand.click(); }else{ this.mainFrameExpand=false; } tab.Yunqi.app.setContentHeight_(); }, expand:function(){ this.mainFrameExpand=true; let id=this.activeTab.id; let tab=document.getElementById('addtabs-'+id).contentWindow; tab.Yunqi.app.setContentHeight_(); }, compress:function () { this.mainFrameExpand=false; let id=this.activeTab.id; let tab=document.getElementById('addtabs-'+id).contentWindow; tab.Yunqi.app.setContentHeight_(); }, setBreadcrumb:function (){ if(this.activeTab.id==Yunqi.data.selected.id){ this.breadcrumb=[Yunqi.data.selected]; }else{ let breadcrumb=findBreadcrumbById(Yunqi.data.menulist,this.activeTab.id,[]); breadcrumb.unshift(Yunqi.data.selected); this.breadcrumb=breadcrumb; } }, onBreadcrumbClick:function (){ }, changeSubMenu:function (menu){ this.clickMenu(findTabsMenu(menu)); }, clickMenu:function (menu){ menu.id=menu.id || getUniqid(); this.openMenu=menu; if(menu.menutype=='tab'){ this.addTabs(menu); } if(menu.menutype=='layer'){ this.openLayer(menu); } if(menu.menutype=='blank'){ window.open(menu.url,"_blank"); } if(this.documentWidth<=600){ this.elementUi.is_menu_collapse=true; } }, openLayer:function(menu){ if(this.documentWidth<=600){ menu.expand=true; } let list=this.layerList; //如果已经显示了就返回,并找到要隐藏的layer let index=-1; for(let i in list){ if(list[i].id==menu.id && list[i].show){ return; } if(list[i].id==menu.id){ index=i; } } if(index!=-1){ list[index].show=true; let app=Yunqi.getApp(list[index].id); app && app.onShow(); } if(index==-1){ menu.show=true; list.push(menu); } this.activeLayer=menu; this.$refs.tabs.tabAdd(menu); }, hideLayer:function (layer){ layer.show=false; let app=Yunqi.getApp(layer.id); app && app.onHide(); let list=this.layerList; for(let i=list.length;i>0;i--){ let j=i-1; if(list[j].show){ this.$refs.tabs.tabAdd(list[j]); return; } } this.$refs.tabs.tabAdd(this.activeTab); }, calculateLayerIndex:function(index){ let list=this.layerList; let r=-1; for(let i=0;i0;i--){ let j=i-1; if(list[j].show){ this.$refs.tabs.tabAdd(list[j]); return; } } this.$refs.tabs.tabAdd(this.activeTab); } }, closeTabs:function (options,callback){ //弹窗模式下禁止增加tab for(let i=0;i