Navbar.vue 7.8 KB

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