Navbar.vue 8.0 KB

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