Navbar.vue 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. <template>
  2. <div class="navbar">
  3. <div class="sys-name">
  4. <!-- <img id="nav-logo" :src="logo" alt="logo"> -->
  5. <h2>工业物联网平台</h2>
  6. <hamburger v-if="!hideMenuBt" id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
  7. <!-- <span v-if="userData.ocName" class="tag">/{{ userData.ocName }}</span> -->
  8. </div>
  9. <!-- 隐藏标签 -->
  10. <breadcrumb v-if="0" id="breadcrumb-container" class="breadcrumb-container" />
  11. <div class="right-menu">
  12. <template v-if="device!=='mobile'">
  13. <search v-if="false" id="header-search" class="right-menu-item" />
  14. <error-log class="errLog-container right-menu-item hover-effect" />
  15. <screenfull v-if="false" id="screenfull" class="right-menu-item hover-effect" />
  16. <el-tooltip v-if="false" content="Global Size" effect="dark" placement="bottom">
  17. <size-select id="size-select" class="right-menu-item hover-effect" />
  18. </el-tooltip>
  19. </template>
  20. <div class="sideMenuTab">
  21. <div
  22. v-for="(tab,index) in sideMenuTabList"
  23. :key="'sideMenuTab'+index"
  24. class="item"
  25. :class="sideMenuTabIndex===tab.id?'active-'+sideMenuTabIndex:''"
  26. @click="sideTabChange(tab.id,tab)"
  27. >
  28. <template v-if="sideMenuTabIndex===tab.id">
  29. <img :src="tab.iconSelectEd" :alt="tab.name">
  30. </template>
  31. <template v-else>
  32. <img :src="tab.icon" :alt="tab.name">
  33. </template>
  34. <p>{{ tab.name }}</p>
  35. </div>
  36. </div>
  37. <div class="right-menu-item" @click="navToPage('/message')">
  38. <el-badge :is-dot="false" class="nav-icon">
  39. <img class="icon" src="@/assets/images/Navbar/notice.png" alt="">
  40. <span class="name">预警信息</span>
  41. </el-badge>
  42. </div>
  43. <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
  44. <div class="avatar-wrapper">
  45. <!-- <el-avatar v-if="userData" :src="userData.userAvatar" /> -->
  46. <img class="icon" src="@/assets/images/Navbar/user.png" alt="">
  47. <span class="name">{{ userData&&userData.userName||'--' }}</span>
  48. <i class="el-icon-caret-bottom" />
  49. </div>
  50. <el-dropdown-menu slot="dropdown">
  51. <router-link to="/profile/index">
  52. <el-dropdown-item>
  53. 个人中心
  54. </el-dropdown-item>
  55. </router-link>
  56. <el-dropdown-item divided @click.native="logout">
  57. <span style="display:block;">退出登录</span>
  58. </el-dropdown-item>
  59. </el-dropdown-menu>
  60. </el-dropdown>
  61. </div>
  62. </div>
  63. </template>
  64. <script>
  65. import { mapGetters } from 'vuex'
  66. import { Breadcrumb, Hamburger, ErrorLog, Screenfull, SizeSelect, Search } from '@/components'
  67. import { getUnReadCounter } from '@/api/system/msgApi'
  68. export default {
  69. name: 'NaveBarComponent',
  70. components: {
  71. Breadcrumb,
  72. Hamburger,
  73. ErrorLog,
  74. Screenfull,
  75. SizeSelect,
  76. Search
  77. },
  78. data() {
  79. return {
  80. logo: require('@/assets/images/logo/logo.png'),
  81. sideMenuTabIndex: 'iiot-eq',
  82. sideMenuTabList: [
  83. { name: '设备', icon: require('@/assets/images/Navbar/sensor.png'), iconSelectEd: require('@/assets/images/Navbar/sensor_selected.png'), path: '/iiot-eq-overview/index', id: 'iiot-eq', permit: 'aqpt_system' },
  84. { name: '传感器', icon: require('@/assets/images/Navbar/warn.png'), iconSelectEd: require('@/assets/images/Navbar/warn_selected.png'), path: '/iiot-sensor/index', id: 'iiot-sensor', permit: 'aqpt_system' },
  85. { name: '系统管理', icon: require('@/assets/images/Navbar/sys.png'), iconSelectEd: require('@/assets/images/Navbar/sys_selected.png'), path: '/aqpt/account', permit: 'aqpt_system', id: 9 },
  86. { name: '数字全景', icon: require('@/assets/images/Navbar/bigscreen.png'), iconSelectEd: require('@/assets/images/Navbar/bigscreen_selected.png'), path: '/bigScreen', permit: 'aqpt_panorama', id: 10 }
  87. ]
  88. }
  89. },
  90. computed: {
  91. ...mapGetters([
  92. 'device',
  93. 'sidebar',
  94. 'avatar',
  95. 'userData',
  96. 'permission_routes',
  97. 'menuSiderTab',
  98. 'permits'
  99. ]),
  100. hideMenuBt() {
  101. return this.permission_routes.filter(item => !item.hidden).length < 1
  102. }
  103. },
  104. watch: {
  105. menuSideTab(val) {
  106. const item = this.sideMenuTabList[val]
  107. this.sideTabChange(val, item)
  108. }
  109. },
  110. mounted() {
  111. this.getUnReadMsg()
  112. this.initSideMenu()
  113. if (this.sideMenuTabList.length > 0) {
  114. this.initsideTab()
  115. }
  116. },
  117. methods: {
  118. getUnReadMsg() {
  119. getUnReadCounter().then((resp) => {
  120. this.unReadCount = resp.data
  121. })
  122. },
  123. initSideMenu() {
  124. const permits = JSON.parse(JSON.stringify(this.permits))
  125. let sideMenuTabList = JSON.parse(JSON.stringify(this.sideMenuTabList))
  126. sideMenuTabList = sideMenuTabList.filter(item => permits.includes(item.permit))
  127. this.sideMenuTabList = sideMenuTabList
  128. },
  129. initsideTab() {
  130. let index = 'iiot-eq'
  131. if (this.isNotNull(localStorage.getItem('tabIndex'))) {
  132. if (isNaN(localStorage.getItem('tabIndex'))) {
  133. index = localStorage.getItem('tabIndex')
  134. } else {
  135. index = parseFloat(localStorage.getItem('tabIndex'))
  136. }
  137. }
  138. const paths = this.sideMenuTabList.filter(item => item.id === index)[0]
  139. const path = paths.length > 0 ? paths[0].path : this.sideMenuTabList[0].path
  140. const fullPath = this.$route.fullPath
  141. this.sideTabChange(index, { path: fullPath.includes('404') ? path : fullPath })
  142. },
  143. toggleSideBar() {
  144. this.$store.dispatch('app/toggleSideBar')
  145. },
  146. navToPage(path) {
  147. this.$emit('initMessage')
  148. },
  149. async logout() {
  150. localStorage.clear() // 垃圾数据清除
  151. await this.$store.dispatch('user/logout')
  152. this.$router.push(`/login?redirect=${this.$route.fullPath}`)
  153. },
  154. sideTabChange(index, item) {
  155. this.sideMenuTabIndex = index
  156. if (index === 10) {
  157. this.$router.push({
  158. path: item.path
  159. })
  160. return
  161. } else {
  162. this.$router.replace({
  163. path: item.path
  164. })
  165. }
  166. localStorage.setItem('tabIndex', index)
  167. var permission_routes = localStorage.getItem('permission_routes')
  168. if (permission_routes) { permission_routes = JSON.parse(permission_routes) } else {
  169. permission_routes = this.permission_routes
  170. localStorage.setItem('permission_routes', JSON.stringify(permission_routes))
  171. }
  172. // 获取权限路由,根据groupId进行过滤
  173. const filterRoutes = permission_routes.filter((item) => {
  174. if (item.groupId) {
  175. return item.groupId.includes(index)
  176. }
  177. return item
  178. })
  179. this.$store.state.permission.routes = filterRoutes
  180. },
  181. isNotNull(value) {
  182. if (value !== undefined && value !== 'undefined' && value !== null && value !== '') return true
  183. return false
  184. }
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. .navbar {
  190. height: var(--navHeight);
  191. overflow: hidden;
  192. background: unset;
  193. box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
  194. border-bottom: 1px solid #457486;
  195. position: fixed;
  196. width: 100%;
  197. z-index: 999;
  198. left: 0;
  199. box-sizing: border-box;
  200. background-color: var(--menuBg, #113144);
  201. top: 0;
  202. .sys-name{
  203. height: 100%;
  204. display: flex;
  205. align-items: center;
  206. float: left;
  207. padding-left: 10px;
  208. color: #fff;
  209. flex: 1;
  210. #nav-logo{
  211. display: block;
  212. width: 200px;
  213. height: 32px;
  214. }
  215. .tag{
  216. font-size: 18px;
  217. line-height: 18px;
  218. font-weight: 300;
  219. padding-left: 10px;
  220. margin-top: 10px;
  221. }
  222. }
  223. .hamburger-container {
  224. padding: 3px 6px;
  225. margin-left: 10px;
  226. line-height: var(--navHeight);
  227. height: 100%;
  228. font-size: 16px;
  229. float: left;
  230. color: rgb(219, 204, 204) !important;
  231. cursor: pointer;
  232. transition: background .3s;
  233. -webkit-tap-highlight-color:transparent;
  234. &:hover {
  235. background: rgba(0, 0, 0, .025)
  236. }
  237. }
  238. .breadcrumb-container {
  239. float: left;
  240. }
  241. .errLog-container {
  242. display: inline-block;
  243. vertical-align: top;
  244. }
  245. .right-menu {
  246. float: right;
  247. height: 100%;
  248. line-height: var(--navHeight);
  249. display: flex;
  250. justify-content: flex-start;
  251. align-items: center;
  252. &:focus {
  253. outline: none;
  254. }
  255. .right-menu-item {
  256. display: inline-block;
  257. height: 100%;
  258. font-size: 18px;
  259. color: #fff;
  260. vertical-align: text-bottom;
  261. &.hover-effect {
  262. cursor: pointer;
  263. transition: background .3s;
  264. &:hover {
  265. background: rgba(0, 0, 0, .025)
  266. }
  267. }
  268. }
  269. .avatar-container {
  270. margin-right: 30px;
  271. .avatar-wrapper {
  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. img{
  316. display: block;
  317. width: 28px;
  318. }
  319. .iconfont{
  320. color: inherit;
  321. }
  322. .iconfont{
  323. font-size: 36px;
  324. &.el-icon-s-platform{
  325. font-family: "element-icons" !important;
  326. }
  327. &.icon-common_health{
  328. font-size: 28px;
  329. }
  330. }
  331. p{
  332. padding-top: 3px;
  333. margin: 2px 0px;
  334. font-size: 14px;
  335. color: #fff;
  336. }
  337. &[class*="active-"]{
  338. p{
  339. color: #1890FF;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. .nav-icon,.avatar-wrapper{
  346. display: flex;
  347. align-items: center;
  348. .iocn{
  349. display: block;
  350. width: 24px;
  351. }
  352. .name{
  353. color:rgba(255, 255, 255, 0.76);
  354. font-size:14px;
  355. margin-left:5px;
  356. }
  357. }
  358. }
  359. </style>