NavMenu.vue 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237
  1. <template>
  2. <div class="tabpanel_tab_content">
  3. <div class="tabpanel_header">
  4. <ul class="tabpanel_mover">
  5. <template v-for="(item) in menus">
  6. <li :id="item.id" :key="item.id" :class="item.active" @click="selectmenu(item.url)">
  7. <div class="title"><i :class="item.icon"></i> {{item.text}}</div>
  8. <div @click.stop="closemenu(item.url)" v-if="item.closeBtn === true" class="closer fa fa-close"></div>
  9. </li>
  10. </template>
  11. </ul>
  12. </div>
  13. <div class="tabpanel_header_ref">
  14. <a class="btn btn-link btn-xs" @click="gotab('right')" title="右移选项卡">
  15. <i class="glyphicon glyphicon-chevron-left"></i>
  16. </a>
  17. <el-dropdown @command="handleCommand" menu-align='start'>
  18. <span class="avator">
  19. <i class="fa fa-exchange"></i>
  20. </span>
  21. <el-dropdown-menu slot="dropdown">
  22. <el-dropdown-item command="flash">刷新当前页面</el-dropdown-item>
  23. <el-dropdown-item command="fullScreem">全屏当前页面</el-dropdown-item>
  24. <el-dropdown-item command="closeother">关闭其他页面</el-dropdown-item>
  25. <el-dropdown-item command="closeall">关闭全部页面</el-dropdown-item>
  26. </el-dropdown-menu>
  27. </el-dropdown>
  28. <a class="btn btn-link btn-xs" @click="gotab('left')" title="左移选项卡">
  29. <i class="glyphicon glyphicon-chevron-right"></i>
  30. </a>
  31. </div>
  32. </div>
  33. </template>
  34. <script>
  35. import { ajax } from "@/common/biConfig";
  36. import $ from "jquery";
  37. export default {
  38. name: "navMenu",
  39. data() {
  40. return {
  41. menus:[{
  42. id:"b_home",
  43. text:"首页",
  44. icon:"fa fa-home",
  45. url:"/Welcome",
  46. active:"active",
  47. closeBtn:false
  48. }]
  49. };
  50. },
  51. mounted:function(){
  52. },
  53. methods: {
  54. gotab(pos){
  55. var o = $(".tabpanel_mover");
  56. var left = Number(o.css("marginLeft").replace("px", ""));
  57. if(pos =='left'){
  58. left = left - 110;
  59. }else{
  60. left = left + 110;
  61. }
  62. if(left > 0){
  63. left = 0;
  64. }
  65. var size = $(".tabpanel_mover li").length;
  66. if(Math.abs(left/110) < size){
  67. o.css("marginLeft", left+"px");
  68. }
  69. },
  70. menuAdd(menu){
  71. for(let m of this.menus){
  72. m.active = "";
  73. }
  74. //如果菜单存在,让菜单选中
  75. let ls = this.menus.filter(function(m){
  76. return m.url === menu.menuUrl
  77. });
  78. if(ls.length >= 1){ //存在
  79. ls[0].active = "active";
  80. }else{ //不存在,添加
  81. this.menus.push({
  82. id:"b_"+menu.menuId,
  83. text:menu.menuName,
  84. icon:menu.avatar,
  85. url:menu.menuUrl,
  86. active:"active",
  87. closeBtn:true
  88. });
  89. }
  90. },
  91. closemenu(url){
  92. let ts = this;
  93. $(this.menus).each((a, b)=>{
  94. if(b.url === url){
  95. if(b.active === 'active'){ //删除的刚好是active
  96. let provNode = ts.menus[a - 1]; //前一个节点
  97. provNode.active = 'active';
  98. ts.$router.push(provNode.url);
  99. }
  100. ts.menus.splice(a, 1);
  101. return false;
  102. }
  103. });
  104. },
  105. selectmenu(url){
  106. let ts = this;
  107. for(let m of this.menus){
  108. m.active = "";
  109. }
  110. $(this.menus).each((a, b)=>{
  111. if(b.url === url){
  112. b.active = "active";
  113. ts.$router.push(url);
  114. return false;
  115. }
  116. });
  117. },
  118. handleCommand(cmd){
  119. if(cmd === "closeother"){
  120. this.menus = this.menus.filter(m=>m.id==='b_home' || m.active === 'active');
  121. $(this.menus).each((a, b)=>{
  122. if(b.active === 'active'){
  123. this.$router.push(b.url);
  124. return false;
  125. }
  126. });
  127. }else if(cmd === "closeall"){
  128. this.menus.splice(1, this.menus.length);
  129. this.menus[0].active = "active";
  130. this.$router.push(this.menus[0].url);
  131. }else if(cmd === 'flash'){
  132. $(this.menus).each((a, b)=>{
  133. if(b.active === 'active'){
  134. //this.$router.push(b.url);
  135. //刷新页面暂时能用。
  136. return false;
  137. }
  138. });
  139. }
  140. }
  141. },
  142. };
  143. </script>
  144. <style lang="css">
  145. .tabpanel_header {
  146. width: calc(100% - 80px);
  147. overflow: hidden;
  148. display: inline-block;
  149. }
  150. .btn-link {
  151. color: inherit;
  152. }
  153. .tabpanel_header_ref {
  154. width: 80px;
  155. float: right;
  156. margin-top:5px;
  157. }
  158. .tabpanel_tab_content {
  159. height: 29px;
  160. background-color: #f9f9f9;
  161. overflow: hidden;
  162. white-space: nowrap;
  163. position: relative;
  164. box-shadow: 0 2px 3px 0 rgba(0,0,0,.16), 0 2px 5px 0 rgba(0,0,0,.12);
  165. z-index: 100;
  166. }
  167. .tabpanel_mover {
  168. margin: 0px;
  169. padding: 0px;
  170. position: relative;
  171. }
  172. .tabpanel_mover li {
  173. width: 110px;
  174. line-height: 20px;
  175. padding: 5px 10px 5px 10px;
  176. background-color: #f4f6f8;
  177. display: inline-block;
  178. position: relative;
  179. list-style-type: none;
  180. cursor: pointer;
  181. border-right: 1px solid #ddd;
  182. overflow: hidden;
  183. }
  184. .tabpanel_mover li:hover {
  185. background-color: #e3e1e1;
  186. }
  187. .tabpanel_mover li .title {
  188. font-size: 13px;
  189. overflow: hidden;
  190. float: left;
  191. color: #4285f4;
  192. width:80px;
  193. text-overflow:ellipsis;
  194. }
  195. .J_mainContent {
  196. height: 100%;
  197. overflow: hidden;
  198. }
  199. .J_mainContent2 {
  200. height: calc(100% - 30px);
  201. overflow: hidden;
  202. }
  203. .tabpanel_content .html_content {
  204. width: 100%;
  205. height: 100%;
  206. }
  207. .tabpanel_mover li .closer {
  208. position: absolute;
  209. right: 0px;
  210. top: 10px;
  211. width: 15px;
  212. height: 15px;
  213. cursor: pointer;
  214. background:none;
  215. font-size: 10px;
  216. display:none;
  217. color:#4285f4;
  218. }
  219. .tabpanel_mover li.active:hover > .closer {
  220. display:block;
  221. color:#ffffff;
  222. }
  223. .tabpanel_mover li:hover > .closer {
  224. display:block;
  225. }
  226. .tabpanel_mover li.active {
  227. background-color:#4285f4;
  228. }
  229. .tabpanel_mover li.active .title {
  230. color:#fff;
  231. }
  232. </style>