Navbar.vue 8.0 KB

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