瀏覽代碼

导航栏的业务线设置

wangziqian 4 年之前
父節點
當前提交
494bcafc3a
共有 3 個文件被更改,包括 75 次插入78 次删除
  1. 68 77
      src/layout/components/Navbar.vue
  2. 3 0
      src/router/needIdList.js
  3. 4 1
      src/store/modules/data.js

+ 68 - 77
src/layout/components/Navbar.vue

@@ -4,7 +4,7 @@
       <!-- <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> -->
       <!-- <hamburger :is-active="sidebar.opened" class="hamburger-container" @toggleClick="toggleSideBar" /> -->
       <!-- <breadcrumb class="breadcrumb-container" /> -->
       <!-- <breadcrumb class="breadcrumb-container" /> -->
       <el-dropdown v-show="status" placement="bottom" trigger="click" @command="sumTypeCkeck">
       <el-dropdown v-show="status" placement="bottom" trigger="click" @command="sumTypeCkeck">
-        <el-button :disabled="bizId" type="primary">
+        <el-button :disabled="showBizId" type="primary">
           {{ sumType }}<i class="el-icon-arrow-down el-icon--right" />
           {{ sumType }}<i class="el-icon-arrow-down el-icon--right" />
         </el-button>
         </el-button>
         <el-dropdown-menu slot="dropdown">
         <el-dropdown-menu slot="dropdown">
@@ -43,9 +43,10 @@
 
 
 <script>
 <script>
 import { mapGetters } from 'vuex'
 import { mapGetters } from 'vuex'
+import { needIdList } from '@/router/needIdList'
+import { desDecryptId } from '@/utils/crypto-js.js'
 // import Breadcrumb from '@/components/Breadcrumb' // 面包屑
 // import Breadcrumb from '@/components/Breadcrumb' // 面包屑
 // import Hamburger from '@/components/Hamburger'  // 导航开关
 // import Hamburger from '@/components/Hamburger'  // 导航开关
-import Utils from '../../util.js'
 import { logoutUrl } from '@/apiConfig/requestIP.js'
 import { logoutUrl } from '@/apiConfig/requestIP.js'
 import { memberGetLoginInMemberInfoByLdap, settingGetBizList, settingUserSetBiz, settingUserGetBiz } from '@/api/projectIndex'
 import { memberGetLoginInMemberInfoByLdap, settingGetBizList, settingUserSetBiz, settingUserGetBiz } from '@/api/projectIndex'
 
 
@@ -63,7 +64,8 @@ export default {
       sumTypeArray: [],
       sumTypeArray: [],
       sumType: '',
       sumType: '',
       formulaArea: '', // 公式的文本框
       formulaArea: '', // 公式的文本框
-      typeObj: {}
+      typeObj: {},
+      showBizId: false
     }
     }
   },
   },
   computed: {
   computed: {
@@ -77,91 +79,80 @@ export default {
       return localStorage.getItem('realname')
       return localStorage.getItem('realname')
     }
     }
   },
   },
-  created() {
-    this.get_bizArr()
+  watch: {
+    $route: {
+      async handler(to, from) {
+        await this.settingGetBizList()
+        if (!to.query.bizId && !to.query.bizId_id) {
+          this.settingUserGetBiz()
+          return
+        }// 如果参数中bizId和bizId_id都不存在,去获取默认bizId
+        const existBizId_id = needIdList.find(item => item === to.name)
+        existBizId_id ? this.handerIdAndBizId() : this.handerBizId()
+      },
+      immediate: true
+    }
   },
   },
-  mounted() {
-    Utils.$on('demo', msg => {
-      this.$alert('提示:任务所属业务线和当前设置业务线不一致,将修改用户所在业务线为任务所属业务线,请知晓!', '提示', {
-        confirmButtonText: '确定',
-        callback: action => {
-          settingGetBizList({}).then(res => {
-            res.data.map(item => {
-              item.code === msg ? this.typeObj = item : ''
-            })
-            this.sumTypeCkeck(this.typeObj)
-          })
-        }
-      })
-    })
+  created() {
+    this.getLoginMember()
   },
   },
   methods: {
   methods: {
-    remoteMethod(query) {
+    handerBizId() { // 只处理bizId
+      const bizId = Number(desDecryptId(this.$route.query.bizId))
+      const isExistBizId = this.sumTypeArray.find(item => bizId === item.code)
+      isExistBizId ? this.$store.dispatch('data/setBizId', bizId) : this.settingUserGetBiz()
+    },
+    handerIdAndBizId() { // 处理bizId和id
+      const bizId_id = this.$route.query.bizId_id
+      const arr = Number(desDecryptId(bizId_id)).split('_')
+      const isExistBizId = this.sumTypeArray.find(item => arr[0] === item.code)
+      isExistBizId ? this.$store.dispatch('data/setBizId', arr[0]) : this.settingUserGetBiz()
+    },
+    async remoteMethod(query) {
       if (query !== '') {
       if (query !== '') {
-        setTimeout(() => {
-          settingGetBizList({ bizName: query }).then(res => {
-            this.sumTypeArray = res.data
-          })
-        }, 200)
+        const res = await settingGetBizList({ bizName: query })
+        this.sumTypeArray = res.data
       } else {
       } else {
         this.get_bizArr()
         this.get_bizArr()
       }
       }
     },
     },
-    // toggleSideBar() {
-    //   this.$store.dispatch('app/toggleSideBar')
-    // },
-    // logout() {
-    //   // await this.$store.dispatch('user/logout')
-    //   // this.$router.push(`/login?redirect=${this.$route.fullPath}`)
-    //   location.href = logoutUrl
-    // },
-    sumTypeCkeck(type) { // 下拉列表的点击事件x
+    async sumTypeCkeck(type) { // 下拉列表的点击事件x
       this.sumType = type.name
       this.sumType = type.name
-      settingUserSetBiz({ bizId: type.code }).then(res => {
-        localStorage.setItem('bizId', type.code)
-        localStorage.setItem('bizName', type.name)
-        const url = window.location.href
-        const urlArr = url.split('?')
-        const k = urlArr[0]
-        const appU = k.split('/')
-        const name = appU[appU.length - 1]
-        name === 'projectViewDetails' ? this.$router.push({ name: '项目', query: {}}) : ''
-        name === 'taskViewDetails' ? this.$router.push({ name: '任务', query: {}}) : ''
-        name === 'requirementDetails' ? this.$router.push({ name: '需求', query: {}}) : ''
-        name === 'iterationDetails' ? this.$router.push({ name: '迭代', query: {}}) : ''
-        if (name !== 'projectViewDetails' && name !== 'taskViewDetails' && name !== 'requirementDetails' && name !== 'iterationDetails') {
-          window.location.reload()
+      await settingUserSetBiz({ bizId: type.code })
+      this.$store.dispatch('data/setBizId', type.code)
+      const url = window.location.href
+      const urlArr = url.split('?')
+      const k = urlArr[0]
+      const appU = k.split('/')
+      const name = appU[appU.length - 1]
+      name === 'projectViewDetails' ? this.$router.push({ name: '项目', query: {}}) : ''
+      name === 'taskViewDetails' ? this.$router.push({ name: '任务', query: {}}) : ''
+      name === 'requirementDetails' ? this.$router.push({ name: '需求', query: {}}) : ''
+      name === 'iterationDetails' ? this.$router.push({ name: '迭代', query: {}}) : ''
+      if (name !== 'projectViewDetails' && name !== 'taskViewDetails' && name !== 'requirementDetails' && name !== 'iterationDetails') {
+        window.location.reload()
+      }
+    },
+    async settingGetBizList() { // 获取业务线列表
+      const res = await settingGetBizList({})
+      this.sumTypeArray = res.data || []
+    },
+    async settingUserGetBiz() { // 获取人员默认业务线
+      const res = await settingUserGetBiz()
+      if (res.data) {
+        const nowBiz = this.sumTypeArray.find(item => res.data.bizId === item.code)
+        if (nowBiz) {
+          this.sumType = nowBiz.name
+          this.$store.dispatch('data/setBizId', nowBiz.code)
+        } else {
+          console.log('重定向到业务线选择页面')
         }
         }
-      })
+      }
     },
     },
-    get_bizArr() {
-      memberGetLoginInMemberInfoByLdap().then(res => {
-        this.options = res.data
-        localStorage.setItem('UserAvatar', this.options.phoneUrl)
-      })
-      settingGetBizList({}).then(res => {
-        this.sumTypeArray = res.data
-        settingUserGetBiz().then(res => {
-          if (res.data) {
-            this.sumTypeArray.map(item => {
-              if (res.data.bizId === item.code) {
-                this.sumType = item.name
-                localStorage.setItem('bizId', item.code)
-                localStorage.setItem('bizName', item.name)
-              }
-            })
-          } else {
-            this.sumType = this.sumTypeArray[0].name
-            localStorage.setItem('bizId', this.sumTypeArray[0].code)
-            localStorage.setItem('bizName', this.sumTypeArray[0].name)
-          }
-          if (this.sumType === '') {
-            this.sumType = this.sumTypeArray[0].name
-            localStorage.setItem('bizId', this.sumTypeArray[0].code)
-            localStorage.setItem('bizName', this.sumTypeArray[0].name)
-          }
-        })
-      })
+    async getLoginMember() { // 获取登录人员信息
+      const res = await memberGetLoginInMemberInfoByLdap()
+      this.options = res.data
+      localStorage.setItem('UserAvatar', this.options.phoneUrl)
     },
     },
     visibleChange(e) {
     visibleChange(e) {
       if (!e) {
       if (!e) {

+ 3 - 0
src/router/needIdList.js

@@ -0,0 +1,3 @@
+export const needIdList = [
+  '项目'
+]

+ 4 - 1
src/store/modules/data.js

@@ -4,7 +4,7 @@ const state = {
   subMenu: '',
   subMenu: '',
   RichText: '',
   RichText: '',
   status: false,
   status: false,
-  bizId: false,
+  bizId: -1,
   notice: false
   notice: false
 }
 }
 
 
@@ -45,6 +45,9 @@ const actions = {
   setRoutes({ commit }, value) {
   setRoutes({ commit }, value) {
     commit('SETROUTES', value)
     commit('SETROUTES', value)
   },
   },
+  setBizId({ commit }, value) {
+    commit('SETBIZID', value)
+  },
   setNotice({ commit }, value) {
   setNotice({ commit }, value) {
     commit('SETNOTICE', value)
     commit('SETNOTICE', value)
   }
   }