index.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. historyArr:[{url:'../html/home.html',text:'全文病历检索'}], //历史记录
  8. activeIndex:'0' , //当前历史记录选中的下标
  9. leftTabActive:'2-0',//左边菜单中当前高亮下标
  10. isCollapse: false, //导航栏是否隐藏
  11. screenWidth: document.body.clientWidth,//屏幕宽度
  12. }
  13. },
  14. computed: {
  15. navWidth:function() { //左边菜单的的宽度
  16. return this.isCollapse ? '51px' : '200px'
  17. },
  18. titleTip:function() {
  19. return this.isCollapse ? '显示导航栏' : '隐藏导航栏'
  20. },
  21. },
  22. mounted:function() {
  23. if(sessionStorage.lastRouter){
  24. this.setHistory(JSON.parse(sessionStorage.lastRouter))
  25. }
  26. this.resize()
  27. this.bidnEvent()
  28. },
  29. methods: {
  30. bidnEvent:function(){ //供子页面调用的事件 (子页面是iframe)
  31. var vm =this;
  32. GlobalEventBus.$on("setLoading", function(arg) { //控制整个界面加载
  33. if(arg && arg.loading){
  34. vm.loading = true
  35. }
  36. else{
  37. vm.loading = false
  38. }
  39. });
  40. GlobalEventBus.$on("setIframeUrl", function(arg) { //新打开窗口并且记录历史记录
  41. vm.setHistory(arg.history)
  42. });
  43. GlobalEventBus.$on("setleftTabUrl", function(arg) { //打开左边菜单中的页面 可直接传对应
  44. vm.handleSelect(arg.key)
  45. });
  46. },
  47. resize:function() { //监听页面改变大小
  48. const that = this
  49. this.isCollapse = this.screenWidth >= 786 ? false : true;
  50. window.onresize = function() {
  51. return (function(){
  52. window.screenWidth = document.body.clientWidth;
  53. that.screenWidth = window.screenWidth;
  54. })()
  55. }
  56. },
  57. handleSelect: function (key) {
  58. console.log(key)
  59. var vm = this;
  60. var activeObj =null;
  61. switch (key) {
  62. case '1':
  63. this.isCollapse = !this.isCollapse;
  64. break;
  65. case '2-0':
  66. activeObj = {url:'../html/home.html',text:'全文病历检索'};
  67. break;
  68. case '2-1':
  69. window.open('../../bigData/html/medical.html')
  70. break;
  71. case '2-2':
  72. window.open('../../bigData/html/insurance.html')
  73. break;
  74. case '2-3':
  75. window.open('../../bigData/html/home.html')
  76. break;
  77. case '2-4':
  78. activeObj = {url:'../html/tableChange.html',text:'医保控费分析'};
  79. break;
  80. }
  81. if(!activeObj)return
  82. this.leftTabActive=key
  83. activeObj.fromLeft=true
  84. // key=key.toString()
  85. // this.isActive = key.substring(0, 1)
  86. // var childrenIndex= key.split('-')[1]-1;
  87. // var activeObj = this.tabList[(this.isActive-1)].children[childrenIndex];
  88. vm.setHistory(activeObj)
  89. },
  90. deleteHistory:function(index){
  91. this.historyArr.splice(index,1);
  92. if(!this.historyArr[this.activeIndex] && this.activeIndex-1>=0){
  93. this.activeIndex-=1
  94. }
  95. },
  96. setHistory:function(obj){
  97. var vm = this;
  98. var exist = false;
  99. var index = null;
  100. // if(typeof(obj)=='string'){ //如果左边菜单换成数组的话 现在暂时没空
  101. // vm.tabList.forEach(function(v){
  102. // v.children.forEach(function(value){
  103. // if(typeof(obj)=='string' && obj.indexOf(value.url) != -1){
  104. // var obj1 =newObj(value);
  105. // obj1.url=obj;
  106. // obj=obj1;
  107. // }
  108. // })
  109. // })
  110. // }
  111. vm.historyArr= vm.historyArr.map(function(v,i){ //检测要跳转的url是否在历史记录中
  112. if(obj.url.indexOf(v.url.split('?')[0]) != -1 ){
  113. switch (obj.url){ //已经存在并且在左边的菜单的话则需要高亮左边菜单
  114. case "../html/home.html":obj.index='2-0';break;
  115. case "../html/search.html":obj.index='2-0';break;
  116. case "../html/tableChange.html":obj.index='2-4';break;
  117. }
  118. exist=true;
  119. index = i;
  120. if(v.url!=obj.url && !obj.fromLeft) v.url=obj.url //如果参数不同则重新赋值 按左边的则不需要比较
  121. }
  122. return v
  123. })
  124. sessionStorage.lastRouter = JSON.stringify(obj)
  125. if(!exist){ //不存在则添加进历史记录
  126. vm.historyArr.push(obj);
  127. this.activeIndex =vm.historyArr.length-1
  128. }
  129. else{ //存在则直接跳转
  130. this.activeIndex =index
  131. }
  132. if(obj.index)
  133. this.leftTabActive=obj.index //控制左边菜单选中
  134. },
  135. controlRouter:function(key) {
  136. switch (key) {
  137. case '1':
  138. this.closeAllHistory();
  139. break;
  140. case '2':
  141. this.closeAllHistory(true);
  142. break;
  143. }
  144. },
  145. closeAllHistory:function(is) { //不传参则全部关闭 传参则关闭除了自己之外的
  146. var that =this;
  147. if (is && this.activeIndex !=0) {
  148. this.historyArr = this.historyArr.filter(function(v,i) {
  149. return i == that.activeIndex || i==0
  150. })
  151. this.activeIndex=1
  152. }
  153. else{
  154. this.historyArr = this.historyArr.filter(function(v,i) {
  155. return i ==0
  156. })
  157. this.activeIndex=0
  158. }
  159. },
  160. },
  161. watch: {
  162. screenWidth:function(value) {
  163. this.isCollapse = value >= 786 ? false : true;
  164. },
  165. }
  166. })