分角色登录
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
parent
a17359a56e
commit
eeac5b76c4
|
@ -193,3 +193,19 @@ export function getPublicKey() {
|
|||
method: 'get',
|
||||
})
|
||||
}
|
||||
// 登陆获取角色
|
||||
export function getUserLoginRoleList(data) {
|
||||
return request({
|
||||
url: `/User/getUserLoginRoleList`,
|
||||
method: 'post',
|
||||
data,
|
||||
})
|
||||
}
|
||||
// 登陆角色id获取token
|
||||
export function loginSelectUserRole(params) {
|
||||
return request({
|
||||
url: `/User/loginSelectUserRole`,
|
||||
method: 'get',
|
||||
params,
|
||||
})
|
||||
}
|
||||
|
|
|
@ -0,0 +1,83 @@
|
|||
<template>
|
||||
<el-dialog
|
||||
v-if="visible"
|
||||
:visible.sync="visible"
|
||||
v-dialogDrag
|
||||
width="540px"
|
||||
:close-on-click-modal="false"
|
||||
append-to-body
|
||||
:title="$t('toggleRole:tip:title')"
|
||||
center
|
||||
:show-close="false"
|
||||
@close="cancel"
|
||||
>
|
||||
<el-radio-group v-model="form.UserTypeId" class="roles" v-if="hasRole">
|
||||
<el-radio
|
||||
v-for="item in roles"
|
||||
:key="item.UserTypeId"
|
||||
:label="item.UserTypeId"
|
||||
:disabled="item.isUserRoleDisabled"
|
||||
style="margin-bottom: 10px"
|
||||
>
|
||||
{{ item.UserTypeShortName }}
|
||||
</el-radio>
|
||||
</el-radio-group>
|
||||
<div v-else>{{ $t('toggleRole:tip:noRole') }}</div>
|
||||
<div slot="footer">
|
||||
<!-- 保存 -->
|
||||
<el-button type="primary" size="small" @click="save" :loading="loading">
|
||||
{{ $t('common:button:confirm') }}
|
||||
</el-button>
|
||||
</div>
|
||||
</el-dialog>
|
||||
</template>
|
||||
<script>
|
||||
export default {
|
||||
name: 'toggleRole',
|
||||
props: {
|
||||
visible: {
|
||||
type: Boolean,
|
||||
default: true,
|
||||
},
|
||||
},
|
||||
data() {
|
||||
return {
|
||||
form: {
|
||||
UserTypeId: null,
|
||||
},
|
||||
loading: false,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
roles() {
|
||||
return this.$store.state.user.roles
|
||||
},
|
||||
hasRole() {
|
||||
return this.roles && this.roles.length > 0
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
cancel() {
|
||||
this.$emit('update:visible', false)
|
||||
},
|
||||
async save() {
|
||||
try {
|
||||
if (!this.form.UserTypeId)
|
||||
return this.$message.warning(this.$t('toggleRole:ruleMessage:select'))
|
||||
this.$emit('save', this.form.UserTypeId)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
<style lang="scss" scoped>
|
||||
.roles {
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-content: center;
|
||||
justify-content: center;
|
||||
flex-wrap: wrap;
|
||||
}
|
||||
</style>
|
|
@ -1,5 +1,5 @@
|
|||
import { getToken, setToken, removeToken, setName, removeName } from '@/utils/auth'
|
||||
import { login, loginOut, getUserMenuTree, getUserPermissions } from '@/api/user'
|
||||
import { login, loginOut, getUserMenuTree, getUserPermissions, getUserLoginRoleList, loginSelectUserRole } from '@/api/user'
|
||||
|
||||
import { resetRouter } from '@/router'
|
||||
import md5 from 'js-md5'
|
||||
|
@ -16,13 +16,17 @@ const getDefaultState = () => {
|
|||
TotalNeedSignSystemDocCount: eval(process.env.VUE_APP_WORD_FOR_PERMISSION) ? null : 0,
|
||||
TotalNeedSignTrialDocCount: eval(process.env.VUE_APP_WORD_FOR_PERMISSION) ? null : 0,
|
||||
TrialStatusStr: null,
|
||||
isTestUser: false
|
||||
isTestUser: false,
|
||||
roles: []
|
||||
}
|
||||
}
|
||||
|
||||
const state = getDefaultState()
|
||||
|
||||
const mutations = {
|
||||
SET_ROLES: (state, roles) => {
|
||||
state.roles = roles
|
||||
},
|
||||
RESET_STATE: (state) => {
|
||||
Object.assign(state, getDefaultState())
|
||||
},
|
||||
|
@ -78,6 +82,9 @@ const mutations = {
|
|||
}
|
||||
|
||||
const actions = {
|
||||
setRoles({ commit }, roles) {
|
||||
commit('SET_ROLES', roles)
|
||||
},
|
||||
changeUserName({ commit }, userName) {
|
||||
commit('SET_USERNAME', userName)
|
||||
},
|
||||
|
@ -91,7 +98,7 @@ const actions = {
|
|||
if (UserId) {
|
||||
data.UserId = UserId;
|
||||
}
|
||||
login(data).then(async response => {
|
||||
getUserLoginRoleList(data).then(async response => {
|
||||
if (response.IsSuccess) {
|
||||
zzSessionStorage.removeItem('lastWorkbench')
|
||||
zzSessionStorage.setItem('my_username', username.trim())
|
||||
|
@ -99,6 +106,7 @@ const actions = {
|
|||
zzSessionStorage.setItem('my_EMail', response.Result.BasicInfo.EMail)
|
||||
localStorage.setItem('CompanyInfo', JSON.stringify(response.Result.CompanyInfo))
|
||||
const data = response.Result
|
||||
commit('SET_ROLES', data.BasicInfo.AccountList)
|
||||
if (data.BasicInfo.IsFirstAdd || data.BasicInfo.LoginState === 1) {
|
||||
try {
|
||||
zzSessionStorage.setItem('userId', data.BasicInfo.Id)
|
||||
|
@ -127,12 +135,12 @@ const actions = {
|
|||
zzSessionStorage.setItem('userTypeShortName', user.userTypeShortName)
|
||||
zzSessionStorage.setItem('userId', user.id)
|
||||
zzSessionStorage.setItem('userTypeEnumInt', user.userTypeEnumInt)
|
||||
var permissions = await getUserPermissions()
|
||||
var menuTree = await getUserMenuTree()
|
||||
commit('SET_TREE', menuTree.Result)
|
||||
commit('SET_PERMISSIONS', permissions.Result)
|
||||
zzSessionStorage.setItem('newTree', JSON.stringify(menuTree.Result))
|
||||
zzSessionStorage.setItem('permissions', JSON.stringify(permissions.Result))
|
||||
// var permissions = await getUserPermissions()
|
||||
// var menuTree = await getUserMenuTree()
|
||||
// commit('SET_TREE', menuTree.Result)
|
||||
// commit('SET_PERMISSIONS', permissions.Result)
|
||||
// zzSessionStorage.setItem('newTree', JSON.stringify(menuTree.Result))
|
||||
// zzSessionStorage.setItem('permissions', JSON.stringify(permissions.Result))
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
|
@ -146,6 +154,39 @@ const actions = {
|
|||
})
|
||||
})
|
||||
},
|
||||
loginByRole({ commit }, userInfo) {
|
||||
const { UserTypeId } = userInfo
|
||||
let params = {
|
||||
UserTypeId
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
loginSelectUserRole(params).then(async response => {
|
||||
if (response.IsSuccess) {
|
||||
const data = response.Result
|
||||
|
||||
try {
|
||||
commit('SET_TOKEN', data)
|
||||
setToken(data)
|
||||
var permissions = await getUserPermissions()
|
||||
var menuTree = await getUserMenuTree()
|
||||
commit('SET_TREE', menuTree.Result)
|
||||
commit('SET_PERMISSIONS', permissions.Result)
|
||||
zzSessionStorage.setItem('newTree', JSON.stringify(menuTree.Result))
|
||||
zzSessionStorage.setItem('permissions', JSON.stringify(permissions.Result))
|
||||
} catch (e) {
|
||||
console.log(e)
|
||||
}
|
||||
resolve(response.Result)
|
||||
|
||||
} else {
|
||||
reject(response.ErrorMessage)
|
||||
}
|
||||
}).catch(() => {
|
||||
reject()
|
||||
})
|
||||
})
|
||||
},
|
||||
setTree({ commit }, tree) {
|
||||
commit('SET_TREE', tree)
|
||||
},
|
||||
|
|
|
@ -243,6 +243,7 @@
|
|||
</div>
|
||||
</el-dialog>
|
||||
<browserTip ref="browserTip" />
|
||||
<toggleRole :visible="toggleRoleVisible" @save="loginByRole" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -253,9 +254,10 @@ import TopLang from './topLang'
|
|||
import Vcode from 'vue-puzzle-vcode'
|
||||
import browserTip from '@/views/dictionary/template/browser/tip.vue'
|
||||
import Img1 from '@/assets/pic-2.png'
|
||||
import toggleRole from '@/components/toggleRole'
|
||||
export default {
|
||||
name: 'Login',
|
||||
components: { TopLang, Vcode, browserTip },
|
||||
components: { TopLang, Vcode, browserTip, toggleRole },
|
||||
data() {
|
||||
return {
|
||||
NODE_ENV: process.env.NODE_ENV, // process.env.NODE_ENV
|
||||
|
@ -298,6 +300,7 @@ export default {
|
|||
isShow: false,
|
||||
showCode: false,
|
||||
Img1,
|
||||
toggleRoleVisible: false,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -416,31 +419,49 @@ export default {
|
|||
// this.$alert(this.$t('login:message:login4'), this.$t('common:title:warning'))
|
||||
this.$message.warning(this.$t('login:message:login4'))
|
||||
}
|
||||
this.$store.dispatch('permission/generateRoutes').then((res) => {
|
||||
this.loading = false
|
||||
if (res && res.length > 0) {
|
||||
this.$store.dispatch('global/getNoticeList')
|
||||
this.$router.addRoutes(res)
|
||||
if (this.loginType === 'DevOps') {
|
||||
this.$router.replace({ path: res[0].path })
|
||||
return
|
||||
}
|
||||
if (this.hasPermi(['role:radmin'])) {
|
||||
this.$router.replace({ path: res[0].path })
|
||||
return
|
||||
}
|
||||
if (
|
||||
this.hasPermi(['role:air', 'role:rpm', 'role:rcrc', 'role:rir'])
|
||||
) {
|
||||
this.$router.replace({ path: '/trials/trials-list' })
|
||||
return (this.toggleRoleVisible = true)
|
||||
})
|
||||
.catch(() => {
|
||||
this.showCode = true
|
||||
this.loading = false
|
||||
})
|
||||
},
|
||||
loginByRole(UserTypeId) {
|
||||
this.$store
|
||||
.dispatch('user/loginByRole', { UserTypeId })
|
||||
.then((res) => {
|
||||
if (res) {
|
||||
this.$store.dispatch('permission/generateRoutes').then((res) => {
|
||||
this.loading = false
|
||||
if (res && res.length > 0) {
|
||||
this.$store.dispatch('global/getNoticeList')
|
||||
this.$router.addRoutes(res)
|
||||
if (this.loginType === 'DevOps') {
|
||||
this.$router.replace({ path: res[0].path })
|
||||
return
|
||||
}
|
||||
if (this.hasPermi(['role:radmin'])) {
|
||||
this.$router.replace({ path: res[0].path })
|
||||
return
|
||||
}
|
||||
if (
|
||||
this.hasPermi([
|
||||
'role:air',
|
||||
'role:rpm',
|
||||
'role:rcrc',
|
||||
'role:rir',
|
||||
])
|
||||
) {
|
||||
this.$router.replace({ path: '/trials/trials-list' })
|
||||
} else {
|
||||
this.$router.replace({ path: '/trials' })
|
||||
}
|
||||
} else {
|
||||
this.$router.replace({ path: '/trials' })
|
||||
// 此账户暂未配置菜单权限,请联系管理员处理后再登录。
|
||||
this.$message.warning(this.$t('login:message:login2'))
|
||||
}
|
||||
} else {
|
||||
// 此账户暂未配置菜单权限,请联系管理员处理后再登录。
|
||||
this.$message.warning(this.$t('login:message:login2'))
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
})
|
||||
.catch(() => {
|
||||
this.showCode = true
|
||||
|
|
|
@ -225,7 +225,7 @@ export default {
|
|||
// 保存权限配置
|
||||
async savePermission(){
|
||||
try{
|
||||
let validate = this.$refs.permissionForm.validate();
|
||||
let validate =await this.$refs.permissionForm.validate();
|
||||
if(!validate) return false;
|
||||
this.assignLoadStatus = true;
|
||||
let data = Object.assign({ Id: this.trialId },this.permission)
|
||||
|
|
Loading…
Reference in New Issue