index.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. new Vue({
  2. el: '#app',
  3. data: function () {
  4. return {
  5. // iframeSrc: "../../new-quailty-manager/html/new-quailty-manager.html",
  6. loading: false,
  7. tabList: [],
  8. historyArr:[{url:'../../bigData/html/home.html',text:'测试'},], //历史记录
  9. activeIndex:'0' , //当前历史记录选中的下标
  10. leftTabActive:'2-0',//左边菜单中当前高亮下标
  11. isCollapse: false, //导航栏是否隐藏
  12. screenWidth: document.body.clientWidth,//屏幕宽度
  13. }
  14. },
  15. computed: {
  16. navWidth:function() { //左边菜单的的宽度
  17. return this.isCollapse ? '51px' : '200px'
  18. },
  19. titleTip:function() {
  20. return this.isCollapse ? '显示导航栏' : '隐藏导航栏'
  21. },
  22. },
  23. mounted:function() {
  24. this.resize()
  25. GlobalEventBus.$on("setLoading", function(arg) {
  26. if(arg.loading){
  27. vm.loading = true
  28. }
  29. else{
  30. vm.loading = false
  31. }
  32. });
  33. GlobalEventBus.$on("setIframeUrl", function(arg) {
  34. vm.setHistory(arg.history)
  35. });
  36. },
  37. methods: {
  38. resize:function() { //监听页面改变大小
  39. const that = this
  40. this.isCollapse = this.screenWidth >= 786 ? false : true;
  41. window.onresize = function() {
  42. return (function(){
  43. window.screenWidth = document.body.clientWidth;
  44. that.screenWidth = window.screenWidth;
  45. })()
  46. }
  47. },
  48. handleSelect: function (key) {
  49. console.log(key)
  50. var vm = this;
  51. var activeObj =null;
  52. switch (key) {
  53. case '1':
  54. this.isCollapse = !this.isCollapse;
  55. break;
  56. case '2-0':
  57. break;
  58. case '2-1':
  59. activeObj = {url:'../../bigData/html/medical.html',text:'各个'};
  60. break;
  61. case '2-2':
  62. break;
  63. case '2-3':
  64. }
  65. this.leftTabActive=key
  66. // key=key.toString()
  67. // this.isActive = key.substring(0, 1)
  68. // var childrenIndex= key.split('-')[1]-1;
  69. // var activeObj = this.tabList[(this.isActive-1)].children[childrenIndex];
  70. if(activeObj)
  71. vm.setHistory(activeObj)
  72. },
  73. deleteHistory:function(index){
  74. this.historyArr.splice(index,1);
  75. if(!this.historyArr[this.activeIndex] && this.activeIndex-1>=0){
  76. this.activeIndex-=1
  77. }
  78. },
  79. setHistory:function(obj){
  80. var vm = this;
  81. var exist = false;
  82. var index = null;
  83. if(typeof(obj)=='string'){ //有些页面直接传url过来 先检测是是左边菜单中的哪个
  84. vm.tabList.forEach(function(v){
  85. v.children.forEach(function(value){
  86. if(typeof(obj)=='string' && obj.indexOf(value.url) != -1){
  87. var obj1 =newObj(value);
  88. obj1.url=obj;
  89. obj=obj1;
  90. }
  91. })
  92. })
  93. }
  94. vm.historyArr= vm.historyArr.map(function(v,i){ //检测要跳转的url是否在历史记录中
  95. if(obj.url.indexOf(v.url.split('?')[0]) != -1 ){
  96. exist=true;
  97. index = i;
  98. if(v.url!=obj.url) v.url=obj.url //如果参数不同则重新赋值
  99. }
  100. return v
  101. })
  102. if(!exist){ //不存在则添加进历史记录
  103. vm.historyArr.push(obj);
  104. this.activeIndex =vm.historyArr.length-1
  105. }
  106. else{ //存在则直接跳转
  107. this.activeIndex =index
  108. }
  109. if(obj.index) this.leftTabActive=obj.index //控制左边菜单选中
  110. },
  111. controlRouter:function(key) {
  112. debugger
  113. switch (key) {
  114. case '1':
  115. this.closeAllHistory();
  116. break;
  117. case '2':
  118. this.closeAllHistory(true);
  119. break;
  120. }
  121. },
  122. closeAllHistory:function(is) { //不传参则全部关闭 传参则关闭除了自己之外的
  123. var that =this;
  124. if (is && this.activeIndex !=0) {
  125. this.historyArr = this.historyArr.filter(function(v,i) {
  126. return i == that.activeIndex || i==0
  127. })
  128. this.activeIndex=1
  129. }
  130. else{
  131. this.historyArr = this.historyArr.filter(function(v,i) {
  132. return i ==0
  133. })
  134. this.activeIndex=0
  135. }
  136. },
  137. },
  138. watch: {
  139. screenWidth:function(value) {
  140. this.isCollapse = value >= 786 ? false : true;
  141. },
  142. }
  143. })