Navbar.vue 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309
  1. <template>
  2. <div class="navbar">
  3. <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar(0)" />
  4. <!-- <breadcrumb id="breadcrumb-container" class="breadcrumb-container" /> -->
  5. <!-- <SignNumArr class="SignNumArr"/> -->
  6. <div class="sign_box">
  7. <div class="sign_item" :class="{active: activeMenu.includes((item.path||item.redirect))}" v-for="(item,index) in this.sidebarRouters.filter(res => {
  8. return res.hidden == false || res.redirect == 'index'
  9. })" :key="index"
  10. @click="tabBtn(item)">
  11. <item v-if="item.meta" :icon="item.meta && item.meta.icon" :title="item.meta.title" />
  12. <item v-if="!item.meta" :icon="item.meta && item.meta.icon" :title="'首页'" />
  13. </div>
  14. </div>
  15. <div class="right-menu">
  16. <!-- <template v-if="device!=='mobile'">
  17. <search id="header-search" class="right-menu-item" />
  18. <el-tooltip content="源码地址" effect="dark" placement="bottom">
  19. <ruo-yi-git id="ruoyi-git" class="right-menu-item hover-effect" />
  20. </el-tooltip>
  21. <el-tooltip content="文档地址" effect="dark" placement="bottom">
  22. <ruo-yi-doc id="ruoyi-doc" class="right-menu-item hover-effect" />
  23. </el-tooltip>
  24. <screenfull id="screenfull" class="right-menu-item hover-effect" />
  25. <el-tooltip content="布局大小" effect="dark" placement="bottom">
  26. <size-select id="size-select" class="right-menu-item hover-effect" />
  27. </el-tooltip>
  28. </template> -->
  29. <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
  30. <div class="avatar-wrapper">
  31. <img :src="avatar" class="user-avatar">
  32. <span></span>
  33. <i class="el-icon-caret-bottom" />
  34. </div>
  35. <el-dropdown-menu slot="dropdown">
  36. <router-link to="/user/profile">
  37. <el-dropdown-item>个人中心</el-dropdown-item>
  38. </router-link>
  39. <el-dropdown-item @click.native="setting = true">
  40. <span>布局设置</span>
  41. </el-dropdown-item>
  42. <el-dropdown-item divided @click.native="logout">
  43. <span>退出登录</span>
  44. </el-dropdown-item>
  45. </el-dropdown-menu>
  46. </el-dropdown>
  47. </div>
  48. </div>
  49. </template>
  50. <script>
  51. import { mapGetters, mapState } from 'vuex'
  52. import Breadcrumb from '@/components/Breadcrumb'
  53. import SignNumArr from '@/components/SignNumArr'
  54. import Hamburger from '@/components/Hamburger'
  55. import Screenfull from '@/components/Screenfull'
  56. import SizeSelect from '@/components/SizeSelect'
  57. import Search from '@/components/HeaderSearch'
  58. import RuoYiGit from '@/components/RuoYi/Git'
  59. import RuoYiDoc from '@/components/RuoYi/Doc'
  60. import Item from '@/layout/components/Sidebar/Item'
  61. export default {
  62. data() {
  63. return {
  64. indexs: 1,
  65. newArr: [],
  66. showde:true
  67. }
  68. },
  69. components: {
  70. SignNumArr,
  71. Hamburger,
  72. Screenfull,
  73. SizeSelect,
  74. Search,
  75. RuoYiGit,
  76. RuoYiDoc,
  77. Item
  78. },
  79. mounted() {
  80. this.init()
  81. },
  82. computed: {
  83. ...mapGetters([
  84. 'sidebar',
  85. 'avatar',
  86. 'device',
  87. "sidebarRouters", "sidebar", "tabIndex"
  88. ]),
  89. activeMenu() {
  90. return this.tabIndex;
  91. },
  92. setting: {
  93. get() {
  94. return this.$store.state.settings.showSettings
  95. },
  96. set(val) {
  97. this.$store.dispatch('settings/changeSetting', {
  98. key: 'showSettings',
  99. value: val
  100. })
  101. },
  102. }
  103. },
  104. methods: {
  105. toggleSideBar(index) {
  106. this.$store.dispatch('app/toggleSideBar')
  107. // console.log( this.$store.dispatch('app/toggleSideBar'))
  108. },
  109. async logout() {
  110. this.$confirm('确定注销并退出系统吗?', '提示', {
  111. confirmButtonText: '确定',
  112. cancelButtonText: '取消',
  113. type: 'warning'
  114. }).then(() => {
  115. this.$store.dispatch('LogOut').then(() => {
  116. location.href = '/index';
  117. })
  118. })
  119. },
  120. tabBtn(item) {
  121. console.log(item)
  122. if(this.activeMenu.includes((item.path||item.redirect))){
  123. return
  124. }
  125. this.$store.dispatch('app/toggleSideBartwo')
  126. if (item.redirect == 'index') {
  127. if(this.$route.path!=='/index'){
  128. this.$router.push({
  129. path: '/index'
  130. })
  131. }
  132. this.$store.dispatch('TabFn', item.redirect)
  133. return
  134. }
  135. this.$store.dispatch('TabFn', item.path)
  136. this.showde = true
  137. },
  138. init() {
  139. const route = this.$route;
  140. const {
  141. meta,
  142. path
  143. } = route;
  144. // if set path, the sidebar will highlight the path you set
  145. console.log(route)
  146. if (meta.activeMenu) {
  147. this.$store.dispatch('TabFn', meta.activeMenu)
  148. }
  149. this.$store.dispatch('TabFn', path)
  150. }
  151. }
  152. }
  153. </script>
  154. <style lang="scss" scoped>
  155. .navbar {
  156. height: 50px;
  157. overflow: hidden;
  158. position: relative;
  159. background-color: #3C8DBC;
  160. box-shadow: 0 1px 4px rgba(0,21,41,.08);
  161. .SignNumArr{
  162. float: left;
  163. }
  164. .hamburger-container {
  165. line-height: 46px;
  166. height: 100%;
  167. float: left;
  168. cursor: pointer;
  169. transition: background .3s;
  170. color: #fff;
  171. -webkit-tap-highlight-color:transparent;
  172. svg{
  173. color: #fff!important;
  174. }
  175. &:hover {
  176. background: rgba(0, 0, 0, .025)
  177. }
  178. }
  179. .breadcrumb-container {
  180. float: left;
  181. }
  182. .errLog-container {
  183. display: inline-block;
  184. vertical-align: top;
  185. }
  186. .right-menu {
  187. float: right;
  188. height: 100%;
  189. line-height: 50px;
  190. &:focus {
  191. outline: none;
  192. }
  193. .right-menu-item {
  194. display: inline-block;
  195. padding: 0 8px;
  196. height: 100%;
  197. font-size: 18px;
  198. color: #5a5e66;
  199. vertical-align: text-bottom;
  200. &.hover-effect {
  201. cursor: pointer;
  202. transition: background .3s;
  203. &:hover {
  204. background: rgba(0, 0, 0, .025)
  205. }
  206. }
  207. }
  208. .avatar-container {
  209. margin-right: 30px;
  210. .avatar-wrapper {
  211. margin-top: 5px;
  212. position: relative;
  213. .user-avatar {
  214. cursor: pointer;
  215. width: 40px;
  216. height: 40px;
  217. border-radius: 50%;
  218. }
  219. .el-icon-caret-bottom {
  220. cursor: pointer;
  221. position: absolute;
  222. right: -20px;
  223. top: 25px;
  224. color: #fff;
  225. font-size: 12px;
  226. }
  227. }
  228. }
  229. }
  230. }
  231. .sign_box {
  232. // padding-left: 12px;
  233. width: calc(100% - 160px);
  234. overflow-x: scroll;
  235. white-space: nowrap;
  236. .sign_item {
  237. cursor: pointer;
  238. float: left;
  239. display: inline-table;
  240. height: 50px;
  241. text-align: center;
  242. line-height: 50px;
  243. position: relative;
  244. width: 143px;
  245. box-sizing: border-box;
  246. color: #fff;
  247. .img {
  248. width: 153px;
  249. height: 48px;
  250. position: absolute;
  251. left: 0;
  252. bottom: 0;
  253. }
  254. .icon {
  255. position: relative;
  256. z-index: 1;
  257. width: 16px;
  258. height: 16px;
  259. margin-right: 8px;
  260. }
  261. span {
  262. position: relative;
  263. z-index: 1;
  264. color: #fff !important;
  265. font-size: 16px !important;
  266. }
  267. svg {
  268. color: #fff !important;
  269. z-index: 2;
  270. line-height: 1;
  271. margin-right: 5px;
  272. }
  273. }
  274. }
  275. .active{
  276. background-color: #367FA8!important;
  277. }
  278. </style>