Browse Source

获取用户信息

zhengnaiwen_citu 6 months ago
parent
commit
87516bd18c
3 changed files with 23 additions and 2 deletions
  1. 5 0
      src/api/user.js
  2. 17 2
      src/store/modules/user.js
  3. 1 0
      src/views/login/index.vue

+ 5 - 0
src/api/user.js

@@ -61,3 +61,8 @@ export function userExcelExport (params) {
 export function getRoleDataPermissionList () {
   return http.upload('/authentication/role/data/config/list')
 }
+
+// 获取当前员工花名册信息
+export function getEmployeeInfo () {
+  return http.upload('/digitizationData/employee/current/login/get')
+}

+ 17 - 2
src/store/modules/user.js

@@ -1,4 +1,4 @@
-import { login } from '@/api/user'
+import { login, getEmployeeInfo } from '@/api/user'
 import router, { resetRouter } from '@/router'
 import { setToken, deleteToken } from '@/utils/auth'
 import Base from '@/utils/base64ToPassword'
@@ -7,10 +7,12 @@ import Base from '@/utils/base64ToPassword'
 
 const SET_SINGLE_SIGN_ON = localStorage.getItem('SET_SINGLE_SIGN_ON')
 const USERINFO = localStorage.getItem('userInfo')
+const EMPLOYEE_INFO = localStorage.getItem('EMPLOYEE_INFO')
 
 const state = {
   singleSignOn: SET_SINGLE_SIGN_ON !== '0', // 单点登录
-  userInfo: !USERINFO ? {} : JSON.parse(USERINFO)
+  userInfo: USERINFO ? JSON.parse(USERINFO) : {},
+  employeeInfo: EMPLOYEE_INFO ? JSON.parse(EMPLOYEE_INFO) : {}
 }
 
 const mutations = {
@@ -21,10 +23,23 @@ const mutations = {
   SET_USERINFO: (state, userInfo) => {
     state.userInfo = userInfo
     localStorage.setItem('userInfo', JSON.stringify(userInfo))
+  },
+  SET_EMPLOYEE_INFO: (state, employeeInfo) => {
+    state.employeeInfo = employeeInfo
+    localStorage.setItem('EMPLOYEE_INFO', JSON.stringify(employeeInfo))
   }
 }
 
 const actions = {
+  getEmployee ({ commit, dispatch }) {
+    return new Promise((resolve, reject) => {
+      getEmployeeInfo().then(res => {
+        const { data } = res
+        commit('SET_EMPLOYEE_INFO', data)
+        resolve(data)
+      })
+    })
+  },
   login ({ commit, dispatch }, params) {
     const { username, password, ...query } = params
     const newBase = new Base()

+ 1 - 0
src/views/login/index.vue

@@ -88,6 +88,7 @@ export default {
             query: this.query
           })
           await this.$store.dispatch('user/login', query)
+          await this.$store.dispatch('user/getEmployee')
           this.$router.push('/')
         } catch (error) {
           if (typeof error === 'object' && error?.code) {