Navbar.vue 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. <template>
  2. <div class="navbar">
  3. <div style="display: flex; justify-content: center;">
  4. <div class="cursor index menu-hover" @click="handlerIndex">首页</div>
  5. <div class="cursor menu menu-hover" @click="handlerShowMenu">数据接口</div>
  6. <!-- 伸缩按钮 -->
  7. <hamburger id="hamburger-container" :is-active="sidebar.opened" v-show="isShowHamBurger" class="hamburger-container"
  8. @toggleClick="toggleSideBar" />
  9. <top-nav @showHamBurger="isShowHamBurger=true" @closeMenuHandler="handlerShowMenu" :isShowMenu="isShowMenu"></top-nav>
  10. </div>
  11. <breadcrumb id="breadcrumb-container" class="breadcrumb-container" v-if="!topNav" />
  12. <!-- <top-nav id="topmenu-container" class="topmenu-container" v-if="topNav" /> -->
  13. <div class="right-menu">
  14. <template v-if="device !== 'mobile'">
  15. <search id="header-search" class="right-menu-item" />
  16. <screenfull id="screenfull" class="right-menu-item hover-effect" />
  17. <el-tooltip content="布局大小" effect="dark" placement="bottom">
  18. <size-select id="size-select" class="right-menu-item hover-effect" />
  19. </el-tooltip>
  20. </template>
  21. <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
  22. <div class="avatar-wrapper">
  23. <img :src="avatar" class="user-avatar">
  24. <i class="el-icon-caret-bottom" />
  25. </div>
  26. <el-dropdown-menu slot="dropdown">
  27. <router-link to="/user/profile">
  28. <el-dropdown-item>个人中心</el-dropdown-item>
  29. </router-link>
  30. <el-dropdown-item @click.native="setting = true">
  31. <span>布局设置</span>
  32. </el-dropdown-item>
  33. <el-dropdown-item divided @click.native="logout">
  34. <span>退出登录</span>
  35. </el-dropdown-item>
  36. </el-dropdown-menu>
  37. </el-dropdown>
  38. </div>
  39. </div>
  40. </template>
  41. <script>
  42. import { mapGetters } from 'vuex'
  43. import Breadcrumb from '@/components/Breadcrumb'
  44. import TopNav from '@/components/TopNav'
  45. import Hamburger from '@/components/Hamburger'
  46. import Screenfull from '@/components/Screenfull'
  47. import SizeSelect from '@/components/SizeSelect'
  48. import Search from '@/components/HeaderSearch'
  49. import RuoYiGit from '@/components/RuoYi/Git'
  50. import RuoYiDoc from '@/components/RuoYi/Doc'
  51. export default {
  52. data() {
  53. return {
  54. // 菜单列表显示、隐藏
  55. isShowMenu: false,
  56. // 伸缩按钮显示、隐藏
  57. isShowHamBurger:false,
  58. routeImgs: [require('@/assets/route_images/u211.svg'), require('@/assets/route_images/u217.svg'), require('@/assets/route_images/u226.svg'), require('@/assets/route_images/u214.svg'), require('@/assets/route_images/u223.svg'), require('@/assets/route_images/u229.svg'), require('@/assets/route_images/u220.svg'), require('@/assets/route_images/u232.svg')],
  59. }
  60. },
  61. components: {
  62. Breadcrumb,
  63. TopNav,
  64. Hamburger,
  65. Screenfull,
  66. SizeSelect,
  67. Search,
  68. RuoYiGit,
  69. RuoYiDoc
  70. },
  71. computed: {
  72. ...mapGetters([
  73. 'sidebar',
  74. 'avatar',
  75. 'device',
  76. 'sidebarRouters'
  77. ]),
  78. setting: {
  79. get() {
  80. return this.$store.state.settings.showSettings
  81. },
  82. set(val) {
  83. this.$store.dispatch('settings/changeSetting', {
  84. key: 'showSettings',
  85. value: val
  86. })
  87. }
  88. },
  89. topNav: {
  90. get() {
  91. return this.$store.state.settings.topNav
  92. }
  93. }
  94. },
  95. methods: {
  96. toggleSideBar() {
  97. this.$store.dispatch('app/toggleSideBar')
  98. },
  99. async logout() {
  100. this.$confirm('确定注销并退出系统吗?', '提示', {
  101. confirmButtonText: '确定',
  102. cancelButtonText: '取消',
  103. type: 'warning'
  104. }).then(() => {
  105. this.$store.dispatch('LogOut').then(() => {
  106. location.href = '/ruoyi-vue-web/index';
  107. })
  108. }).catch(() => { });
  109. },
  110. handlerShowMenu() {
  111. this.isShowMenu = !this.isShowMenu;
  112. },
  113. handlerIndex() {
  114. this.isShowHamBurger = false;
  115. this.$router.push("/")
  116. }
  117. },
  118. watch:{
  119. '$route.fullPath':{
  120. handler:function(newV,oldV){
  121. if(newV == '/index'){
  122. this.isShowHamBurger = false;
  123. }else{
  124. this.isShowHamBurger = true;
  125. }
  126. },
  127. // deep:true,
  128. }
  129. }
  130. }
  131. </script>
  132. <style lang="scss" scoped>
  133. .navbar {
  134. height: 50px;
  135. // overflow: hidden;
  136. position: relative;
  137. background: #fff;
  138. box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
  139. display: flex;
  140. align-items: center;
  141. justify-content: space-between;
  142. .index {
  143. width: 80px;
  144. text-align: center;
  145. }
  146. .cursor {
  147. cursor: pointer;
  148. }
  149. .menu-hover {
  150. padding: 10px;
  151. &:hover {
  152. background-color: rgb(221, 235, 248);
  153. }
  154. }
  155. .hamburger-container {
  156. line-height: 46px;
  157. height: 100%;
  158. float: left;
  159. cursor: pointer;
  160. transition: background .3s;
  161. -webkit-tap-highlight-color: transparent;
  162. &:hover {
  163. background: rgba(0, 0, 0, .025)
  164. }
  165. }
  166. .breadcrumb-container {
  167. float: left;
  168. }
  169. .topmenu-container {
  170. position: absolute;
  171. left: 50px;
  172. }
  173. .errLog-container {
  174. display: inline-block;
  175. vertical-align: top;
  176. }
  177. .right-menu {
  178. float: right;
  179. height: 100%;
  180. line-height: 50px;
  181. &:focus {
  182. outline: none;
  183. }
  184. .right-menu-item {
  185. display: inline-block;
  186. padding: 0 8px;
  187. height: 100%;
  188. font-size: 18px;
  189. color: #5a5e66;
  190. vertical-align: text-bottom;
  191. &.hover-effect {
  192. cursor: pointer;
  193. transition: background .3s;
  194. &:hover {
  195. background: rgba(0, 0, 0, .025)
  196. }
  197. }
  198. }
  199. .avatar-container {
  200. margin-right: 30px;
  201. .avatar-wrapper {
  202. margin-top: 5px;
  203. position: relative;
  204. .user-avatar {
  205. cursor: pointer;
  206. width: 40px;
  207. height: 40px;
  208. border-radius: 10px;
  209. }
  210. .el-icon-caret-bottom {
  211. cursor: pointer;
  212. position: absolute;
  213. right: -20px;
  214. top: 25px;
  215. font-size: 12px;
  216. }
  217. }
  218. }
  219. }
  220. }
  221. </style>