Navbar.vue 7.4 KB

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