NavMenu.vue 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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.go(0);
  135. //this.$forceUpdate();
  136. //刷新页面暂时能用。
  137. return false;
  138. }
  139. });
  140. }
  141. }
  142. },
  143. };
  144. </script>
  145. <style lang="css">
  146. .tabpanel_header {
  147. width: calc(100% - 80px);
  148. overflow: hidden;
  149. display: inline-block;
  150. }
  151. .btn-link {
  152. color: inherit;
  153. }
  154. .tabpanel_header_ref {
  155. width: 80px;
  156. float: right;
  157. margin-top:5px;
  158. }
  159. .tabpanel_tab_content {
  160. height: 29px;
  161. background-color: #f9f9f9;
  162. overflow: hidden;
  163. white-space: nowrap;
  164. position: relative;
  165. box-shadow: 0 2px 3px 0 rgba(0,0,0,.16), 0 2px 5px 0 rgba(0,0,0,.12);
  166. z-index: 100;
  167. }
  168. .tabpanel_mover {
  169. margin: 0px;
  170. padding: 0px;
  171. position: relative;
  172. }
  173. .tabpanel_mover li {
  174. width: 110px;
  175. line-height: 20px;
  176. padding: 5px 10px 5px 10px;
  177. background-color: #f4f6f8;
  178. display: inline-block;
  179. position: relative;
  180. list-style-type: none;
  181. cursor: pointer;
  182. border-right: 1px solid #ddd;
  183. overflow: hidden;
  184. }
  185. .tabpanel_mover li:hover {
  186. background-color: #e3e1e1;
  187. }
  188. .tabpanel_mover li .title {
  189. font-size: 13px;
  190. overflow: hidden;
  191. float: left;
  192. color: #4285f4;
  193. width:80px;
  194. text-overflow:ellipsis;
  195. }
  196. .J_mainContent {
  197. height: 100%;
  198. overflow: hidden;
  199. }
  200. .J_mainContent2 {
  201. height: calc(100% - 30px);
  202. overflow: hidden;
  203. }
  204. .tabpanel_content .html_content {
  205. width: 100%;
  206. height: 100%;
  207. }
  208. .tabpanel_mover li .closer {
  209. position: absolute;
  210. right: 0px;
  211. top: 10px;
  212. width: 15px;
  213. height: 15px;
  214. cursor: pointer;
  215. background:none;
  216. font-size: 10px;
  217. display:none;
  218. color:#4285f4;
  219. }
  220. .tabpanel_mover li.active:hover > .closer {
  221. display:block;
  222. color:#ffffff;
  223. }
  224. .tabpanel_mover li:hover > .closer {
  225. display:block;
  226. }
  227. .tabpanel_mover li.active {
  228. background-color:#4285f4;
  229. }
  230. .tabpanel_mover li.active .title {
  231. color:#fff;
  232. }
  233. </style>