Commit 5be2c0ac authored by jingnan's avatar jingnan 👀

合并产品【测评】添加用户角色信息,区分账号类型

parent 428a77a3
......@@ -65,3 +65,6 @@ export function getUserTheme() {
export function getSecretMatrix() {
return get('/SecretCodeMatrix/getSecretMatrix')
}
export function getUserRole(userId) {
return get('/perm/Role/getUserRoleVO?userId=' + userId)
}
......@@ -59,6 +59,7 @@ const getters = {
tripleManage: state => state.tripleManage.switch,
getUserSecretMetrix: state => state.secret.userSecretMetrix,
breadcrumb: state => state.breadcrumb.visitePath,
viewSearchList: state => state.viewSearchList.list
viewSearchList: state => state.viewSearchList.list,
ternaryUserInfo: state => state.user.ternaryUserInfo || {}
}
export default getters
import { login, logout } from '../../api/user'
import { login, logout, getUserRole } from '../../api/user'
import { getAuditThresholeWarning, getUserLevel } from '../../api/permission'
import { getToken, setToken, removeToken } from '../../utils/auth'
import router from '../../router'
import _get from 'lodash.get'
import { showMessage, showNotification } from '../../utils/util'
import { showMessage, showNotification, setUserRoleInfo, getUserRoleInfo } from '../../utils/util'
import { getUserInfo, downloadFileById } from '@/api/usercenter'
// import store from '@/store'
function base64ToUint8Array(base64String) {
......@@ -23,7 +23,9 @@ function base64ToUint8Array(base64String) {
const state = {
token: getToken(),
userId: '',
userInfo: null
userInfo: null,
// 三元用户标识
ternaryUserInfo: getUserRoleInfo()
}
const mutations = {
SET_TOKEN: (state, token) => {
......@@ -34,6 +36,10 @@ const mutations = {
},
SET_USER_ID: (state, userId) => {
state.userId = userId
},
SET_TERNARY_USER_INFO: (state, info) => {
setUserRoleInfo(info)
state.ternaryUserInfo = info
}
}
const actions = {
......@@ -96,11 +102,43 @@ const actions = {
localStorage.setItem('token', token)
showMessage('登录成功!', 'success')
localStorage.setItem('org', response.items.userVO.dxOrganizationId)
// localStorage.setItem('org', JSON.stringify(orgInfo))
// 查询当前用户级别
getUserLevel().then(res => {
localStorage.setItem('userLevel', JSON.stringify(res.items))
})
getUserRole(userVO.id)
.then(res => {
const roles = res.items.content || []
const syNames = ['sysadmin', 'audadmin', 'secadmin']
// 是管理员
let isAdmin = false
// 是系统管理员
let isSysAdmin = false
// 是审计管理员
let isAudAdmin = false
// 是安全管理员
let isSecAdmin = false
roles.forEach(m => {
if (!isAdmin) {
isAdmin = syNames.includes(m.name)
}
if (!isSysAdmin) {
isSysAdmin = m.name === 'sysadmin'
}
if (!isAudAdmin) {
isAudAdmin = m.name === 'audadmin'
}
if (!isSecAdmin) {
isSecAdmin = m.name === 'secadmin'
}
})
commit('SET_TERNARY_USER_INFO', { isAdmin, isSysAdmin, isAudAdmin, isSecAdmin })
})
.catch(() => {
commit('SET_TERNARY_USER_INFO', {})
})
// 获取审计日志阈值警告(仅内置用户可见)
if (userVO && userVO.isInnerUser) {
getAuditThresholeWarning().then(res => {
......@@ -139,6 +177,7 @@ const actions = {
localStorage.setItem('org', '')
commit('SET_USER_INFO', null)
commit('SET_USER_ID', '')
commit('SET_TERNARY_USER_INFO', {})
resolve(response)
}).catch(error => {
if (error.items === 401) {
......
......@@ -1545,6 +1545,27 @@ export function deepClone(obj) {
return objClone
}
// 存储用户角色信息
export function setUserRoleInfo(data) {
localStorage.setItem('userRoleInfo', JSON.stringify(data))
}
// 获取用户角色类型信息
export function getUserRoleInfo(key) {
let data = null
try {
data = JSON.parse(localStorage.getItem('userRoleInfo'))
if (!(data && typeof data === 'object')) {
data = {}
}
} catch (e) {
data = {}
}
if (key) {
return data[key] || false
}
return data
}
export function fileByIdDownload(objName, objId, linkId) {
downFileByFileId(objName, objId, linkId).then(res => {
this.downLoadFile(res)
......@@ -1690,6 +1711,8 @@ export default {
groupBy,
filterParams,
deepClone,
setUserRoleInfo,
getUserRoleInfo,
fileByIdDownload,
findForm,
sumArray,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment