Navbar.vue 7.7 KB

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