Navbar.vue 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. <template>
  2. <div class="navbar">
  3. <div class="bizIdSet">
  4. <!-- <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> -->
  5. <!-- <breadcrumb class="breadcrumb-container" /> -->
  6. <el-button v-show="status" :disabled="showBizId" type="primary" @click="changeBizId">
  7. {{ sumType }}
  8. </el-button>
  9. </div>
  10. <div>
  11. <div class="right-menu" style="display: fiex; align-items: center; justify-content: space-between;">
  12. <el-avatar style="vertical-align: middle; background: #FFF;" size="small"><img :src="options.phoneUrl"></el-avatar>
  13. <el-dropdown placement="bottom" trigger="click" @visible-change="visibleChange">
  14. <span class="el-dropdown-link avatar-container" style="color: #FFFFFF; cursor: pointer;" @click="show2 = !show2">
  15. {{ username }}
  16. <i class="el-icon-arrow-right" :class="{rotateNone:show2,rotate:!show2}" />
  17. </span>
  18. <el-dropdown-menu slot="dropdown">
  19. <el-dropdown-item @click.native="Logout">退出</el-dropdown-item>
  20. </el-dropdown-menu>
  21. </el-dropdown>
  22. </div>
  23. </div>
  24. </div>
  25. </template>
  26. <script>
  27. import { mapGetters } from 'vuex'
  28. import { needIdList } from '@/router/needIdList'
  29. import { redirect } from '@/router/redirect'
  30. import { EncryptId, desDecryptId, analysisBizId_id } from '@/utils/crypto-js.js'
  31. // import Breadcrumb from '@/components/Breadcrumb' // 面包屑
  32. // import Hamburger from '@/components/Hamburger' // 导航开关
  33. import { logoutUrl } from '@/apiConfig/requestIP.js'
  34. import { memberGetLoginInMemberInfoByLdap, settingGetBizList, settingUserGetBiz } from '@/api/projectIndex'
  35. export default {
  36. // components: {
  37. // Breadcrumb
  38. // Hamburger
  39. // },
  40. data() {
  41. return {
  42. show2: false,
  43. options: {},
  44. value: '',
  45. arr_data: [],
  46. sumTypeArray: [],
  47. formulaArea: '', // 公式的文本框
  48. typeObj: {},
  49. showBizId: false
  50. }
  51. },
  52. computed: {
  53. ...mapGetters([
  54. 'sidebar',
  55. 'avatar',
  56. 'status',
  57. 'bizId'
  58. ]),
  59. username() {
  60. return localStorage.getItem('realname')
  61. },
  62. sumType() {
  63. const nowBiz = this.sumTypeArray.find(item => item.code === this.bizId)
  64. if (nowBiz) return nowBiz.name
  65. return ''
  66. }
  67. },
  68. watch: {
  69. $route: {
  70. async handler(to, from) {
  71. const redirectUrl = `http://zhihui.xiaojukeji.com/#${to.fullPath}`
  72. if (redirect[redirectUrl]) {
  73. window.location.href = redirect[redirectUrl]
  74. window.location.reload()
  75. }
  76. // 如果业务线列表不存在,请求获取路由业务线列表
  77. if (this.sumTypeArray.length < 1) await this.settingGetBizList()
  78. // 如果没有业务线,但是页面又是工作台
  79. if (this.bizId === -1 && (to.name === '个人工作台' || to.name === '团队工作台')) this.settingUserGetBiz(true)
  80. // 如果是业务线选择页面,不作处理
  81. if (to.name === '业务线选择' || to.name === '个人工作台' || to.name === '团队工作台') return
  82. // 如果与原路由相同,不作处理
  83. if (from && to.path === from.path) return
  84. // 如果已存在业务线ID
  85. if (this.bizId !== -1) {
  86. const existBizId_id = needIdList.find(item => item === this.$route.name)
  87. existBizId_id
  88. ? ''
  89. : this.$router.replace({
  90. path: this.$route.path,
  91. query: { ...this.$route.query, bizId: EncryptId(this.bizId) }
  92. })
  93. return
  94. }
  95. // 如果前往路由中参数中bizId和bizId_id都不存在,去获取默认bizId
  96. if (!to.query.bizId && !to.query.bizId_id) {
  97. this.settingUserGetBiz()
  98. return
  99. }
  100. // 如果是需要bizId和id的详情页
  101. const existBizId_id = needIdList.find(item => item === to.name)
  102. existBizId_id ? this.handlerIdAndBizId() : this.handlerBizId()
  103. },
  104. immediate: true
  105. }
  106. },
  107. created() {
  108. this.getLoginMember()
  109. },
  110. methods: {
  111. handlerBizId() { // 只处理bizId
  112. const bizId = Number(desDecryptId(this.$route.query.bizId))
  113. const isExistBizId = this.sumTypeArray.find(item => bizId === item.code)// 业务线id是否存在
  114. if (isExistBizId) {
  115. this.$store.dispatch('global/setBizId', bizId)
  116. } else {
  117. this.settingUserGetBiz()
  118. }
  119. console.log('mainbizId', this.bizId)
  120. },
  121. handlerIdAndBizId() { // 处理bizId和id
  122. const arr = analysisBizId_id(this.$route.query.bizId_id)
  123. const isExistBizId = this.sumTypeArray.find(item => Number(arr[0]) === item.code)// 业务线id是否存在
  124. if (isExistBizId) {
  125. this.$store.dispatch('global/setBizId', Number(arr[0]))
  126. } else {
  127. this.settingUserGetBiz()
  128. }
  129. console.log('mainbizId', this.bizId)
  130. },
  131. async settingGetBizList() { // 获取业务线列表
  132. const res = await settingGetBizList({})
  133. this.sumTypeArray = res.data || []
  134. },
  135. async settingUserGetBiz(noQuery = false) { // 获取人员默认业务线
  136. const res = await settingUserGetBiz()
  137. const nowBiz = this.sumTypeArray.find(item => res.data.bizId === item.code)
  138. if (nowBiz) {
  139. this.$store.dispatch('global/setBizId', nowBiz.code)
  140. localStorage.setItem('bizId', nowBiz.code)
  141. if (noQuery) return // 如果是不需要url参数的,直接返回
  142. const existBizId_id = needIdList.find(item => item === this.$route.name)
  143. // 如果不是在需要bizId_id的详情页,就去给路由添加bizId
  144. existBizId_id
  145. ? ''
  146. : this.$router.replace({
  147. path: this.$route.path,
  148. query: { ...this.$route.query, bizId: EncryptId(nowBiz.code) }
  149. })
  150. } else {
  151. this.$router.push({ name: '业务线选择' })
  152. }
  153. },
  154. async remoteMethod(query) {
  155. if (query !== '') {
  156. const res = await settingGetBizList({ bizName: query })
  157. this.sumTypeArray = res.data
  158. } else {
  159. this.get_bizArr()
  160. }
  161. },
  162. changeBizId(type) { // 更改业务线
  163. this.$router.push({ name: '业务线选择' })
  164. },
  165. async getLoginMember() { // 获取登录人员信息
  166. const res = await memberGetLoginInMemberInfoByLdap()
  167. this.options = res.data
  168. localStorage.setItem('UserAvatar', this.options.phoneUrl)
  169. },
  170. visibleChange(e) {
  171. if (!e) {
  172. this.show2 = false
  173. }
  174. },
  175. Logout() {
  176. location.href = logoutUrl
  177. }
  178. }
  179. }
  180. </script>
  181. <style lang="stylus">
  182. .bizIdSet .el-button--primary.is-disabled, .el-button--primary.is-disabled:active, .el-button--primary.is-disabled:focus, .el-button--primary.is-disabled:hover {
  183. color: #FFF;
  184. background-color: #409EFF;
  185. border-color: #409EFF;
  186. }
  187. </style>
  188. <style lang="scss" scoped>
  189. .navbar .rotateNone {
  190. transform: rotate(270deg);
  191. }
  192. .navbar img {
  193. margin: 0 auto;
  194. }
  195. .navbar .rotate {
  196. transform: rotate(90deg);
  197. }
  198. .navbar {
  199. display: flex;
  200. align-items: center;
  201. justify-content: space-between;
  202. height: 55px;
  203. overflow: hidden;
  204. position: relative;
  205. background: #409EFF;
  206. box-shadow: 0 1px 4px rgba(0,21,41,.08);
  207. .right-menu {
  208. &:focus {
  209. outline: none;
  210. }
  211. .right-menu-item {
  212. // display: inline-block;
  213. padding: 0 8px;
  214. height: 100%;
  215. font-size: 18px;
  216. color: #c0c8d8;
  217. vertical-align: text-bottom;
  218. &.hover-effect {
  219. cursor: pointer;
  220. transition: background .3s;
  221. &:hover {
  222. background: rgba(0, 0, 0, .025)
  223. }
  224. }
  225. }
  226. .avatar-container {
  227. margin-right: 30px;
  228. .avatar-wrapper {
  229. position: relative;
  230. .user-avatar {
  231. cursor: pointer;
  232. width: 40px;
  233. height: 40px;
  234. border-radius: 10px;
  235. }
  236. .el-icon-caret-bottom {
  237. cursor: pointer;
  238. position: absolute;
  239. right: -20px;
  240. top: 25px;
  241. font-size: 12px;
  242. }
  243. }
  244. }
  245. }
  246. }
  247. </style>