瀏覽代碼

切换部门偶发性报错

shenqilong 4 月之前
父節點
當前提交
4bc5a2f317
共有 1 個文件被更改,包括 45 次插入33 次删除
  1. 45 33
      src/layout/header-aside/components/header-user/index.vue

+ 45 - 33
src/layout/header-aside/components/header-user/index.vue

@@ -166,7 +166,7 @@ import ChangePassword from '@/views/platform/org/employee/change-password'
 import UserInfo from '@/views/platform/org/employee/edit'
 import request from '@/utils/request'
 import { getUserInfo } from '@/api/oauth2/user'
-
+import storage from '@/utils/storage'
 export default {
   components: {
     ChangePassword,
@@ -305,38 +305,50 @@ export default {
       this.$router.replace('/tenantSelect')
     },
     handleMainChange(item) {
-      getUserInfo(this.users.account).then(async (response) => {
-        if (!response) {
-          reject(response)
-        }
-        const info = response.data
-        info.positions.sort((a, b) => a.id - b.id)
-        this.positions.sort((a, b) => a.id - b.id)
-        if (info.positions.length !== this.positions.length) {
-          this.$message.warning('部门信息更新,请在刷新后重新选择!')
-          location.reload()
-          return
-        } else {
-          info.positions.forEach((element, i) => {
-            if (
-              element.id !== this.positions[i].id ||
-              element.isMainPost !== this.positions[i].isMainPost
-            ) {
-              this.$message.warning('部门信息更新,请在刷新后重新选择!')
-              location.reload()
-              return
-            }
-          })
-        }
-        if (this.$utils.isEmpty(this.mainPosition)) {
-          this.setMainPosition(item.id)
-          return
-        }
-        if (this.mainPosition && this.mainPosition.id === item.id) {
-          return
-        }
-        this.updateMainPosition(this.mainPosition.id, item.id)
-      })
+      if (!this.users.account) {
+        this.$message.warning(
+          `没有获取到用户名, 请开发人员排查!store:${
+            this.$store.getters?.userInfo?.user?.account
+          },storage:${storage.getItem('username')}`
+        )
+        return
+      }
+      getUserInfo(this.users.account)
+        .then(async (response) => {
+          if (!response) {
+            reject(response)
+          }
+          const info = response.data
+          info.positions.sort((a, b) => a.id - b.id)
+          this.positions.sort((a, b) => a.id - b.id)
+          if (info.positions.length !== this.positions.length) {
+            this.$message.warning('部门信息更新,请在刷新后重新选择!')
+            location.reload()
+            return
+          } else {
+            info.positions.forEach((element, i) => {
+              if (
+                element.id !== this.positions[i].id ||
+                element.isMainPost !== this.positions[i].isMainPost
+              ) {
+                this.$message.warning('部门信息更新,请在刷新后重新选择!')
+                location.reload()
+                return
+              }
+            })
+          }
+          if (this.$utils.isEmpty(this.mainPosition)) {
+            this.setMainPosition(item.id)
+            return
+          }
+          if (this.mainPosition && this.mainPosition.id === item.id) {
+            return
+          }
+          this.updateMainPosition(this.mainPosition.id, item.id)
+        })
+        .catch((error) => {
+          this.logout({ vm: this, confirm: false })
+        })
     },
     handleMainDutyChange(item) {
       getUserInfo(this.users.account).then(async (response) => {