Navbar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. <template>
  2. <div class="navbar">
  3. <div class="sys-name">
  4. <img id="nav-logo" :src="logo" alt="logo">
  5. <hamburger v-if="!hideMenuBt" id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
  6. <!-- <span v-if="userData.ocName" class="tag">/{{ userData.ocName }}</span> -->
  7. </div>
  8. <!-- 隐藏标签 -->
  9. <breadcrumb v-if="0" id="breadcrumb-container" class="breadcrumb-container" />
  10. <div class="right-menu">
  11. <template v-if="device!=='mobile'">
  12. <search v-if="false" id="header-search" class="right-menu-item" />
  13. <error-log class="errLog-container right-menu-item hover-effect" />
  14. <screenfull v-if="false" id="screenfull" class="right-menu-item hover-effect" />
  15. <el-tooltip v-if="false" content="Global Size" effect="dark" placement="bottom">
  16. <size-select id="size-select" class="right-menu-item hover-effect" />
  17. </el-tooltip>
  18. </template>
  19. <div class="sideMenuTab">
  20. <div
  21. v-for="(tab,index) in sideMenuTabList"
  22. :key="'sideMenuTab'+index"
  23. class="item"
  24. :class="sideMenuTabIndex===tab.id?'active-'+sideMenuTabIndex:''"
  25. @click="sideTabChange(tab.id,tab)"
  26. >
  27. <i class="iconfont" :class="tab.icon" />
  28. <p>{{ tab.name }}</p>
  29. </div>
  30. </div>
  31. <div class="right-menu-item" @click="navToPage('/message')">
  32. <el-badge :is-dot="false" class="nav-icon">
  33. <i class="el-icon-message-solid" />
  34. </el-badge>
  35. </div>
  36. <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
  37. <div class="avatar-wrapper">
  38. <el-avatar v-if="userData" :src="userData.userAvatar" />
  39. <i class="el-icon-caret-bottom" />
  40. </div>
  41. <el-dropdown-menu slot="dropdown">
  42. <router-link to="/profile/index">
  43. <el-dropdown-item>
  44. 个人中心
  45. </el-dropdown-item>
  46. </router-link>
  47. <el-dropdown-item divided @click.native="logout">
  48. <span style="display:block;">退出登录</span>
  49. </el-dropdown-item>
  50. </el-dropdown-menu>
  51. </el-dropdown>
  52. </div>
  53. </div>
  54. </template>
  55. <script>
  56. import { mapGetters } from 'vuex'
  57. import { Breadcrumb, Hamburger, ErrorLog, Screenfull, SizeSelect, Search } from '@/components'
  58. import { getUnReadCounter } from '@/api/system/msgApi'
  59. export default {
  60. name: 'NaveBarComponent',
  61. components: {
  62. Breadcrumb,
  63. Hamburger,
  64. ErrorLog,
  65. Screenfull,
  66. SizeSelect,
  67. Search
  68. },
  69. data() {
  70. return {
  71. logo: require('@/assets/images/logo/logo.png'),
  72. sideMenuTabIndex: 0,
  73. sideMenuTabList: [
  74. // { name: '数字全景', icon: 'el-icon-s-platform', path: '/', permit: 'aqpt_panorama', id: 0 },
  75. // { name: '预警中心', icon: 'icon-common_saving', path: '/alert', permit: 'aqpt_alert_center', id: 1 },
  76. // { name: '工作台', icon: 'icon-common_task', path: '/task', permit: 'aqpt_task_center', id: 2 },
  77. // { name: '双重预防', icon: 'icon-common_quality', path: '/aqpt/scene', permit: 'aqpt_workflow', id: 3 },
  78. // { name: '设备管理', icon: 'icon-common_equipment', path: '/aqpt/equipment', permit: 'aqpt_equipment', id: 4 },
  79. // { name: '作业票', icon: 'icon-common_satisfaction', path: '/aqpt/ticket', permit: 'aqpt_ticket', id: 5 },
  80. // { name: '奖惩考核', icon: 'icon-common_quality', path: '/aqpt/kpi/regulation', permit: 'aqpt_kpi', id: 6 },
  81. // { name: '安全智库', icon: 'icon-common_knowledge', path: '/aqpt/art', permit: 'aqpt_art_center', id: 7 },
  82. // { name: '文件中心', icon: 'icon-common_file', path: '/aqpt/doc', permit: 'aqpt_doc_center', id: 8 },
  83. // { name: '系统管理', icon: 'icon iconfont icon-common_configuration', path: '/aqpt/account', permit: 'aqpt_system', id: 9 },
  84. /** ckq */
  85. { name: '数字全景', icon: 'el-icon-s-platform', href: 'http://localhost:8080/', permit: 'aqpt_panorama', id: 0 },
  86. { name: '双重预防【采空区信息&人员巡检】', icon: 'icon-common_quality', path: '/aqpt/scene', permit: 'aqpt_workflow', id: 3 },
  87. { name: '设备管理【传感器】', icon: 'icon-common_equipment', path: '/aqpt/equipment', permit: 'aqpt_equipment', id: 4 },
  88. { name: '预警中心', icon: 'icon-common_saving', path: '/alert', permit: 'aqpt_alert_center', id: 1 },
  89. { name: '工作台', icon: 'icon-common_task', path: '/task', permit: 'aqpt_task_center', id: 2 },
  90. // { name: '作业票', icon: 'icon-common_satisfaction', path: '/aqpt/ticket', permit: 'aqpt_ticket', id: 5 },
  91. // { name: '奖惩考核', icon: 'icon-common_quality', path: '/aqpt/kpi/regulation', permit: 'aqpt_kpi', id: 6 },
  92. { name: '安全智库', icon: 'icon-common_knowledge', path: '/aqpt/art', permit: 'aqpt_art_center', id: 7 },
  93. { name: '文件中心', icon: 'icon-common_file', path: '/aqpt/doc', permit: 'aqpt_doc_center', id: 8 },
  94. { name: '系统管理', icon: 'icon iconfont icon-common_configuration', path: '/aqpt/account', permit: 'aqpt_system', id: 9 }
  95. ]
  96. }
  97. },
  98. computed: {
  99. ...mapGetters([
  100. 'device',
  101. 'sidebar',
  102. 'avatar',
  103. 'userData',
  104. 'permission_routes',
  105. 'menuSiderTab',
  106. 'permits'
  107. ]),
  108. hideMenuBt() {
  109. return this.permission_routes.filter(item => !item.hidden).length < 1
  110. }
  111. },
  112. watch: {
  113. menuSideTab(val) {
  114. const item = this.sideMenuTabList[val]
  115. this.sideTabChange(val, item)
  116. }
  117. },
  118. mounted() {
  119. this.getUnReadMsg()
  120. this.initSideMenu()
  121. this.initsideTab()
  122. },
  123. methods: {
  124. getUnReadMsg() {
  125. getUnReadCounter().then((resp) => {
  126. this.unReadCount = resp.data
  127. })
  128. },
  129. initSideMenu() {
  130. const permits = JSON.parse(JSON.stringify(this.permits))
  131. let sideMenuTabList = JSON.parse(JSON.stringify(this.sideMenuTabList))
  132. sideMenuTabList = sideMenuTabList.filter(item => permits.includes(item.permit))
  133. this.sideMenuTabList = sideMenuTabList
  134. },
  135. initsideTab() {
  136. let index = 0
  137. if (this.isNotNull(localStorage.getItem('tabIndex'))) {
  138. index = parseFloat(localStorage.getItem('tabIndex'))
  139. }
  140. this.sideTabChange(index, {
  141. path: this.$route.fullPath
  142. })
  143. },
  144. toggleSideBar() {
  145. this.$store.dispatch('app/toggleSideBar')
  146. },
  147. navToPage(path) {
  148. this.$emit('initMessage')
  149. },
  150. async logout() {
  151. localStorage.clear() // 垃圾数据清除
  152. await this.$store.dispatch('user/logout')
  153. this.$router.push(`/login?redirect=${this.$route.fullPath}`)
  154. },
  155. sideTabChange(index, item) {
  156. if (item.href) {
  157. window.open(item.href)
  158. return
  159. }
  160. this.sideMenuTabIndex = index
  161. this.$router.replace({
  162. path: item.path
  163. })
  164. localStorage.setItem('tabIndex', index)
  165. var permission_routes = localStorage.getItem('permission_routes')
  166. if (permission_routes) { permission_routes = JSON.parse(permission_routes) } else {
  167. permission_routes = this.permission_routes
  168. localStorage.setItem('permission_routes', JSON.stringify(permission_routes))
  169. }
  170. // 获取权限路由,根据groupId进行过滤
  171. const filterRoutes = permission_routes.filter((item) => {
  172. if (item.groupId) {
  173. return item.groupId.includes(index)
  174. }
  175. return item
  176. })
  177. this.$store.state.permission.routes = filterRoutes
  178. },
  179. isNotNull(value) {
  180. if (value !== undefined && value !== 'undefined' && value !== null && value !== '') return true
  181. return false
  182. }
  183. }
  184. }
  185. </script>
  186. <style lang="scss" scoped>
  187. .navbar {
  188. height: var(--navHeight);
  189. overflow: hidden;
  190. background: unset;
  191. box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
  192. border-bottom: 1px solid #457486;
  193. position: fixed;
  194. width: 100%;
  195. z-index: 999;
  196. left: 0;
  197. box-sizing: border-box;
  198. background-color: var(--menuBg, #113144);
  199. top: 0;
  200. .sys-name{
  201. height: 100%;
  202. display: flex;
  203. align-items: center;
  204. float: left;
  205. padding-left: 10px;
  206. color: #fff;
  207. flex: 1;
  208. #nav-logo{
  209. display: block;
  210. width: 200px;
  211. height: 32px;
  212. }
  213. .tag{
  214. font-size: 18px;
  215. line-height: 18px;
  216. font-weight: 300;
  217. padding-left: 10px;
  218. margin-top: 10px;
  219. }
  220. }
  221. .hamburger-container {
  222. padding: 3px 6px;
  223. margin-left: 10px;
  224. line-height: var(--navHeight);
  225. height: 100%;
  226. font-size: 16px;
  227. float: left;
  228. color: rgb(219, 204, 204) !important;
  229. cursor: pointer;
  230. transition: background .3s;
  231. -webkit-tap-highlight-color:transparent;
  232. &:hover {
  233. background: rgba(0, 0, 0, .025)
  234. }
  235. }
  236. .breadcrumb-container {
  237. float: left;
  238. }
  239. .errLog-container {
  240. display: inline-block;
  241. vertical-align: top;
  242. }
  243. .right-menu {
  244. float: right;
  245. height: 100%;
  246. line-height: var(--navHeight);
  247. display: flex;
  248. justify-content: flex-start;
  249. align-items: center;
  250. &:focus {
  251. outline: none;
  252. }
  253. .right-menu-item {
  254. display: inline-block;
  255. padding: 0 8px;
  256. height: 100%;
  257. font-size: 18px;
  258. color: #fff;
  259. vertical-align: text-bottom;
  260. &.hover-effect {
  261. cursor: pointer;
  262. transition: background .3s;
  263. &:hover {
  264. background: rgba(0, 0, 0, .025)
  265. }
  266. }
  267. }
  268. .avatar-container {
  269. margin-right: 30px;
  270. .avatar-wrapper {
  271. margin-top: 12px;
  272. position: relative;
  273. .user-avatar {
  274. cursor: pointer;
  275. width: 40px;
  276. height: 40px;
  277. border-radius: 10px;
  278. }
  279. .el-icon-caret-bottom {
  280. cursor: pointer;
  281. position: absolute;
  282. right: -20px;
  283. top: 25px;
  284. font-size: 14px;
  285. }
  286. }
  287. }
  288. .sideMenuTab{
  289. height: 100%;
  290. display: flex;
  291. justify-content: flex-start;
  292. padding-right: 20px;
  293. .item{
  294. height: 100%;
  295. display: flex;
  296. justify-content: center;
  297. align-items: center;
  298. flex-direction: column;
  299. color: #fff;
  300. line-height: 1;
  301. padding: 0 15px;
  302. cursor: pointer;
  303. transition: 0.2s;
  304. &.active-0{color: #1890ff;font-weight: 600;}
  305. &.active-1{color: #b97741;font-weight: 600;}
  306. &.active-2{color: #97cd38;font-weight: 600;}
  307. &.active-3 {color: #dc5a2c;font-weight: 600;}
  308. &.active-4{color: #414ab9;font-weight: 600;}
  309. &.active-5{color: #c13ac9;font-weight: 600;}
  310. &.active-6{color: #29c761;font-weight: 600;}
  311. &.active-7 {color: #c7795c;font-weight: 600;}
  312. &.active-8{color: #bd966f;font-weight: 600;}
  313. &.active-9{color: #832188;font-weight: 600;}
  314. &.active-10{color: #66db8f;font-weight: 600;}
  315. .iconfont{
  316. color: inherit;
  317. }
  318. .iconfont{
  319. font-size: 36px;
  320. &.el-icon-s-platform{
  321. font-family: "element-icons" !important;
  322. }
  323. &.icon-common_health{
  324. font-size: 28px;
  325. }
  326. }
  327. p{
  328. padding-top: 3px;
  329. margin: 2px 0px;
  330. font-size: 14px;
  331. color: #fff;
  332. }
  333. }
  334. }
  335. }
  336. }
  337. </style>