Navbar.vue 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381
  1. <template>
  2. <div class="navbar">
  3. <div class="hos-name">
  4. <!--Logo-->
  5. <img :src="logo" class="logo" alt="logo">
  6. <!--开关左边导航-->
  7. <hamburger id="hamburger-container" :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" />
  8. <!--单位名称-->
  9. <span v-if="userData.ocName" class="tag">{{ userData.ocName }}</span>
  10. <!--消息-->
  11. <countdown v-if="userData.licExpiredTime" :end-time="userData.licExpiredTime">
  12. <div
  13. slot="process"
  14. slot-scope="{ timeObj }"
  15. class="tag authorization"
  16. >(授权时长:{{ `${timeObj.d}天${timeObj.h}:${timeObj.m}:${timeObj.s}` }})</div>
  17. <div slot="finish" class="tag authorization error">(请续费使用)</div>
  18. </countdown>
  19. </div>
  20. <!-- 隐藏标签 -->
  21. <breadcrumb v-if="0" id="breadcrumb-container" class="breadcrumb-container" />
  22. <div class="right-menu">
  23. <template v-if="device!=='mobile'">
  24. <search v-if="false" id="header-search" class="right-menu-item" />
  25. <error-log v-if="false" class="errLog-container right-menu-item hover-effect" />
  26. <screenfull v-if="false" id="screenfull" class="right-menu-item hover-effect" />
  27. <el-tooltip v-if="false" content="Global Size" effect="dark" placement="bottom">
  28. <size-select id="size-select" class="right-menu-item hover-effect" />
  29. </el-tooltip>
  30. </template>
  31. <!--上面导航-->
  32. <div class="sideMenuTab">
  33. <div
  34. v-for="(tab,index) in sideMenus"
  35. :key="'sideMenuTab'+index"
  36. class="item"
  37. :class="sideMenuTabId===tab.id?'active-'+sideMenuTabId:''"
  38. @click="sideTabChange(tab.id,tab)"
  39. >
  40. <i class="iconfont" :class="tab.icon" />
  41. <p>{{ tab.name }}</p>
  42. </div>
  43. </div>
  44. <!--消息-->
  45. <div class="right-menu-item" @click="navToPage('/message')">
  46. <el-badge :is-dot="false" class="nav-icon">
  47. <i class="el-icon-message-solid" />
  48. </el-badge>
  49. </div>
  50. <!--用户-->
  51. <el-dropdown class="avatar-container right-menu-item hover-effect" trigger="click">
  52. <div class="avatar-wrapper">
  53. <el-avatar v-if="userData" :src="userData.userAvatar" />
  54. <i class="el-icon-caret-bottom" />
  55. </div>
  56. <el-dropdown-menu slot="dropdown">
  57. <router-link to="/profile/index">
  58. <el-dropdown-item>
  59. 个人中心
  60. </el-dropdown-item>
  61. </router-link>
  62. <el-dropdown-item divided @click.native="logout">
  63. <span style="display:block;">退出登录</span>
  64. </el-dropdown-item>
  65. </el-dropdown-menu>
  66. </el-dropdown>
  67. </div>
  68. </div>
  69. </template>
  70. <script>
  71. import { mapGetters } from 'vuex'
  72. import Breadcrumb from '@/components/Breadcrumb'
  73. import Hamburger from '@/components/Hamburger'
  74. import ErrorLog from '@/components/ErrorLog'
  75. import Screenfull from '@/components/Screenfull'
  76. import SizeSelect from '@/components/SizeSelect'
  77. import Search from '@/components/HeaderSearch'
  78. import { getUnReadCounter } from '@/api/system/msgApi'
  79. import { isNotNull } from '@/utils'
  80. export default {
  81. name: 'NavBar',
  82. components: {
  83. Breadcrumb,
  84. Hamburger,
  85. ErrorLog,
  86. Screenfull,
  87. SizeSelect,
  88. Search
  89. },
  90. data() {
  91. return {
  92. logo: require('@/assets/images/logo/logo.png'),
  93. sideMenuTabId: 0,
  94. sideMenus: [],
  95. sideMenuTabList: [
  96. { name: '数字全景', icon: 'icon-common_panorama1', path: '/hos/satisfy/panorama', permit: 'hos_satisfy_panorama', id: 0 },
  97. { name: '工作总览', icon: 'el-icon-s-platform', path: '/hos/satisfy/overview', permit: 'hos_satisfy_overview', id: 1 },
  98. { name: '建设计划', icon: 'icon-common_saving', path: '/hos/satisfy/instruction', permit: 'hos_satisfy_instruction', id: 2 },
  99. { name: '工作动态', icon: 'icon-common_task', path: '/hos/satisfy/task', permit: 'hos_satisfy_task', id: 3 },
  100. { name: '成果评价', icon: 'icon-common_evaluate', path: '/hos/satisfy/assess', permit: 'hos_satisfy_assess', id: 4 },
  101. { name: '文件中心', icon: 'icon-common_file', path: '/hos/satisfy/doc', permit: 'hos_satisfy_doc', id: 5 },
  102. { name: '业务配置', icon: 'el-icon-setting', path: '/hos/checklist', permit: 'hos_checklist', id: 6 },
  103. { name: '系统管理', icon: 'icon-common_workbench', path: '/hos/profile', permit: 'hos_setting', id: 7 }
  104. ]
  105. }
  106. },
  107. computed: {
  108. ...mapGetters([
  109. 'device',
  110. 'sidebar',
  111. 'avatar',
  112. 'userData',
  113. 'permission_routes',
  114. 'menuSiderTab',
  115. 'permits'
  116. ])
  117. },
  118. watch: {
  119. menuSiderTab(val) {
  120. const item = this.sideMenuTabList[val]
  121. this.sideTabChange(val, item)
  122. }
  123. },
  124. mounted() {
  125. this.getUnReadMsg()
  126. this.initSideMenu()
  127. this.initSideTab()
  128. },
  129. methods: {
  130. // 未读消息
  131. getUnReadMsg() {
  132. getUnReadCounter().then((resp) => {
  133. this.unReadCount = resp.data
  134. })
  135. },
  136. // 渲染导航
  137. initSideMenu() {
  138. const permits = JSON.parse(JSON.stringify(this.permits))
  139. let sideMenuTabList = JSON.parse(JSON.stringify(this.sideMenuTabList))
  140. sideMenuTabList = sideMenuTabList.filter(item => permits.includes(item.permit))
  141. this.sideMenus = sideMenuTabList
  142. },
  143. // 渲染导航
  144. initSideTab() {
  145. let id = this.sideMenuTabId
  146. if (isNotNull(localStorage.getItem('csat_tabId'))) {
  147. id = parseFloat(localStorage.getItem('csat_tabId'))
  148. }
  149. const path = this.sideMenuTabList.filter(item => item.id === id)[0].path
  150. this.sideTabChange(id, {
  151. path
  152. })
  153. },
  154. // 开关导航
  155. toggleSideBar() {
  156. this.$store.dispatch('app/toggleSideBar')
  157. },
  158. // 导航到路径
  159. navToPage(path) {
  160. this.$emit('initMessage')
  161. },
  162. // 退出
  163. async logout() {
  164. localStorage.clear()
  165. await this.$store.dispatch('user/logout')
  166. this.$router.push(`/login?redirect=${this.$route.fullPath}`)
  167. },
  168. // 导航变化
  169. sideTabChange(id, item) {
  170. this.sideMenuTabId = id
  171. this.$router.replace({
  172. path: item.path
  173. })
  174. localStorage.setItem('csat_tabId', id)
  175. let permission_routes = localStorage.getItem('csat_permission_routes')
  176. if (permission_routes) { permission_routes = JSON.parse(permission_routes) } else {
  177. permission_routes = this.permission_routes
  178. localStorage.setItem('csat_permission_routes', JSON.stringify(permission_routes))
  179. }
  180. // 获取权限路由,根据groupId进行过滤
  181. const filterRoutes = permission_routes.filter((item) => {
  182. if (item.groupId) {
  183. return item.groupId.includes(id)
  184. }
  185. return item
  186. })
  187. this.$store.state.permission.routes = filterRoutes
  188. }
  189. }
  190. }
  191. </script>
  192. <style lang="scss" scoped>
  193. .navbar {
  194. height: var(--navHeight);
  195. overflow: hidden;
  196. background: unset;
  197. box-shadow: 0 1px 4px rgba(0, 21, 41, .08);
  198. border-bottom: 1px solid #457486;
  199. position: fixed;
  200. width: 100%;
  201. z-index: 999;
  202. left: 0;
  203. box-sizing: border-box;
  204. background-color: inherit;
  205. top: 0;
  206. .hos-name{
  207. height: 100%;
  208. display: flex;
  209. align-items: center;
  210. float: left;
  211. padding-left: 10px;
  212. color: #fff;
  213. flex: 1;
  214. .logo {
  215. display: block;
  216. width: auto;
  217. height: 38px;
  218. }
  219. .tag{
  220. font-size: 16px;
  221. line-height: 1;
  222. font-weight: 300;
  223. padding-left: 5px;
  224. margin-top: 3px;
  225. &.authorization{
  226. font-size: 12px;
  227. margin-top: 13px;
  228. color: #a33e3e;
  229. // color: rgba(255, 255, 255, 0.7);
  230. }
  231. }
  232. }
  233. .hamburger-container {
  234. padding: 3px;
  235. line-height: var(--navHeight);
  236. height: 100%;
  237. font-size: 16px;
  238. float: left;
  239. color: rgb(219, 204, 204) !important;
  240. cursor: pointer;
  241. transition: background .3s;
  242. -webkit-tap-highlight-color:transparent;
  243. text-align: center;
  244. &:hover {
  245. background: rgba(0, 0, 0, .025)
  246. }
  247. }
  248. .breadcrumb-container {
  249. float: left;
  250. }
  251. .errLog-container {
  252. display: inline-block;
  253. vertical-align: top;
  254. }
  255. .right-menu {
  256. float: right;
  257. height: 100%;
  258. line-height: var(--navHeight);
  259. display: flex;
  260. justify-content: flex-start;
  261. align-items: center;
  262. &:focus {
  263. outline: none;
  264. }
  265. .right-menu-item {
  266. display: inline-block;
  267. padding: 0 8px;
  268. height: 100%;
  269. font-size: 18px;
  270. color: #fff;
  271. vertical-align: text-bottom;
  272. &.hover-effect {
  273. cursor: pointer;
  274. transition: background .3s;
  275. &:hover {
  276. background: rgba(0, 0, 0, .025)
  277. }
  278. }
  279. }
  280. .avatar-container {
  281. margin-right: 30px;
  282. .avatar-wrapper {
  283. margin-top: 12px;
  284. position: relative;
  285. .user-avatar {
  286. cursor: pointer;
  287. width: 40px;
  288. height: 40px;
  289. border-radius: 10px;
  290. }
  291. .el-icon-caret-bottom {
  292. cursor: pointer;
  293. position: absolute;
  294. right: -20px;
  295. top: 25px;
  296. font-size: 12px;
  297. }
  298. }
  299. }
  300. .sideMenuTab{
  301. height: 100%;
  302. display: flex;
  303. justify-content: flex-start;
  304. padding-right: 50px;
  305. .item{
  306. height: 100%;
  307. display: flex;
  308. justify-content: center;
  309. align-items: center;
  310. flex-direction: column;
  311. color: #ccc;
  312. line-height: 1;
  313. font-weight: 600;
  314. padding: 0 15px;
  315. cursor: pointer;
  316. transition: 0.2s;
  317. &.active-0{color: #1890ff;font-weight: 600;}
  318. &.active-1{color: #b97741;font-weight: 600;}
  319. &.active-2{color: #97cd38;font-weight: 600;}
  320. &.active-3{color: #dc5a2c;font-weight: 600;}
  321. &.active-4{color: #414ab9;font-weight: 600;}
  322. &.active-5{color: #c13ac9;font-weight: 600;}
  323. &.active-6{color: #29c761;font-weight: 600;}
  324. &.active-7{color: #f9e871;font-weight: 600;}
  325. .iconfont{
  326. font-size: 36px;
  327. color: inherit;
  328. &[class^=el-icon-], &[class*=" el-icon-"]{
  329. font-family: "element-icons" !important;
  330. }
  331. &.icon-common_health{
  332. font-size: 28px;
  333. }
  334. }
  335. p{
  336. padding: 0;
  337. margin: 5px 0 0 0;
  338. font-size: 14px;
  339. color: #ccc;
  340. }
  341. }
  342. }
  343. }
  344. }
  345. </style>