登录接口变更
continuous-integration/drone/push Build is passing Details

main
wangxiaoshuang 2025-08-15 15:33:24 +08:00
parent 687985e66b
commit e7e373ca37
5 changed files with 175 additions and 132 deletions

View File

@ -159,14 +159,6 @@ export function GetObjectStoreToken(params) {
method: 'get'
})
}
export function loginSelectUserRole(params) {
return request({
url: `/user/loginSelectUserType`,
method: 'get',
params
})
}
// 置换token
export function TJUserLoginInfo(params) {
return request({
@ -175,4 +167,20 @@ export function TJUserLoginInfo(params) {
params
})
}
// 登陆获取角色
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,
})
}

View File

@ -70,10 +70,7 @@ export default {
if (!this.form.userRoleId)
return this.$message.warning(this.$t('toggleRole:ruleMessage:select'))
zzSessionStorage.removeItem('lastWorkbench')
this.$emit('save', {
UserId: this.form.userRoleId,
UserTypeId: this.roles.find(item => item.Id === this.form.userRoleId).UserTypeId
})
this.$emit('save', this.form.userRoleId)
} catch (err) {
console.log(err)
}

View File

@ -1,5 +1,5 @@
import { getToken, setToken, removeToken, setName, removeName } from '@/utils/auth'
import { login, getUserMenuTree, getUserPermissions, loginSelectUserRole, TJUserLoginInfo } from '@/api/user'
import { login, loginOut, getUserMenuTree, getUserPermissions, loginSelectUserRole, getUserLoginRoleList, TJUserLoginInfo } from '@/api/user'
import { getUser } from '@/api/admin'
import { resetRouter } from '@/router'
import md5 from 'js-md5'
@ -87,20 +87,29 @@ const actions = {
},
// user login
login({ commit }, userInfo) {
const { username, password } = userInfo
const { username, password, UserId } = userInfo
return new Promise((resolve, reject) => {
login({ UserName: username.trim(), Password: md5(password) }).then(async response => {
let data = {
UserName: username.trim(), Password: md5(password)
}
if (UserId) {
data.UserId = UserId;
}
getUserLoginRoleList(data).then(async response => {
if (response.IsSuccess) {
zzSessionStorage.removeItem('lastWorkbench')
zzSessionStorage.setItem('my_username', username.trim())
zzSessionStorage.setItem('my_password', md5(password))
zzSessionStorage.setItem('my_EMail', response.Result.BasicInfo.EMail)
localStorage.setItem('CompanyInfo', JSON.stringify(response.Result.CompanyInfo))
const data = response.Result
if (data.BasicInfo.IsFirstAdd) {
commit('SET_ROLES', data.BasicInfo.AccountList)
if (data.BasicInfo.IsFirstAdd || data.BasicInfo.LoginState === 1) {
try {
zzSessionStorage.setItem('userId', data.BasicInfo.Id)
commit('SET_TOKEN', data.JWTStr)
setToken(data.JWTStr)
resolve(false)
resolve(response.Result)
} catch (e) {
console.log(e)
}
@ -110,25 +119,24 @@ const actions = {
zzSessionStorage.setItem('IsReviewer', data.BasicInfo.IsReviewer)
zzSessionStorage.setItem('userName', data.BasicInfo.UserName)
commit('SET_TOKEN', data.JWTStr)
commit('SET_NAME', data.BasicInfo.RealName)
zzSessionStorage.setItem('realName', data.BasicInfo.RealName)
// commit('SET_NAME', data.BasicInfo.UserName)
zzSessionStorage.setItem('isTestUser', data.BasicInfo.IsTestUser)
commit('SET_ISTESTUSER', data.BasicInfo.IsTestUser)
commit('SET_USERNAME', data.BasicInfo.UserName)
commit('SET_USERID', data.BasicInfo.Id)
setToken(data.JWTStr)
setName(data.BasicInfo.RealName)
const userString = decodeURIComponent(escape(window.atob(data.JWTStr.split('.')[1].replace(/-/g, '+').replace(/_/g, '/'))))
const user = JSON.parse(userString)
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))
// setName(data.BasicInfo.RealName)
// const userString = decodeURIComponent(escape(window.atob(data.JWTStr.split('.')[1].replace(/-/g, '+').replace(/_/g, '/'))))
// const user = JSON.parse(userString)
// zzSessionStorage.setItem('userId', user.identityUserId)
// commit('SET_IDENTITYUSERID', user.identityUserId)
// zzSessionStorage.setItem('identityUserId', user.identityUserId)
// 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))
} catch (e) {
console.log(e)
}
@ -161,16 +169,15 @@ const actions = {
})
},
loginByRole({ commit }, userInfo) {
const { UserId, UserTypeId } = userInfo
const { userRoleId } = userInfo
let params = {
UserId, UserTypeId
userRoleId
}
return new Promise((resolve, reject) => {
loginSelectUserRole(params).then(async response => {
if (response.IsSuccess) {
const data = response.Result.JWTStr
try {
commit('SET_TOKEN', data)
setToken(data)
@ -247,12 +254,22 @@ const actions = {
commit('SET_NAME', zzSessionStorage.getItem('realName'))
},
// user logout
logout({ commit, state }) {
removeToken() // must remove token first
resetRouter()
removeName()
zzSessionStorage.clear()
commit('RESET_STATE')
async logout({ commit, state }) {
try {
removeToken() // must remove token first
await loginOut({
UserRoleId: zzSessionStorage.getItem('userId'),
IdentityUserId: zzSessionStorage.getItem('identityUserId'),
})
resetRouter()
removeName()
let lang = zzSessionStorage.getItem('lang')
zzSessionStorage.clear()
zzSessionStorage.setItem('lang', lang)
commit('RESET_STATE')
} catch (e) {
console.log(e)
}
},
setToken({ commit }, token) {
commit('SET_TOKEN', token)

View File

@ -87,9 +87,9 @@ service.interceptors.response.use(
console.log(err)
}
router.push(`/login`)
this.$i18n.locale = 'zh'
this.setLanguage('zh')
this.$updateDictionary()
// this.$i18n.locale = 'zh'
// this.setLanguage('zh')
// this.$updateDictionary()
})
}
switch (status) {
@ -119,9 +119,9 @@ service.interceptors.response.use(
}
store.dispatch('user/logout').then(() => {
router.push(`/login`)
this.$i18n.locale = 'zh'
this.setLanguage('zh')
this.$updateDictionary()
// this.$i18n.locale = 'zh'
// this.setLanguage('zh')
// this.$updateDictionary()
})
} else {
Message({

View File

@ -125,7 +125,7 @@
</span>
</el-dialog>
<toggleRole v-if="toggleRoleVisible" :visible.sync="toggleRoleVisible" :loading="toggleRoleLoading"
@save="loginByRole" />
@save="loginByRole" @cancel="cancel" />
</div>
</template>
@ -237,62 +237,11 @@ export default {
},
methods: {
...mapMutations({ setLanguage: 'lang/setLanguage' }),
loginByRole(row) {
let { UserId, UserTypeId } = row
if (this.$store.state.user.userId === UserId) {
this.toggleRoleVisible = false
this.toggleRoleLoading = false
return false
}
this.toggleRoleLoading = true
this.$store
.dispatch('user/loginByRole', { UserId, UserTypeId })
.then((res) => {
if (res) {
this.$store
.dispatch('permission/generateRoutes')
.then(async (res) => {
if (res && res.length > 0) {
resetRouter()
await this.$store.dispatch('global/getNoticeList')
this.$router.addRoutes(res)
this.toggleRoleLoading = false
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:pm', 'role:oa', 'role:admin', 'role:dev'])
) {
history.replaceState(null, null, '/trials/trials-inspection')
history.go(0)
} else {
history.replaceState(null, null, '/trials/trials-list')
history.go(0)
}
this.toggleRoleVisible = false
this.toggleRoleLoading = false
this.$EventBus.$emit('reload')
} else {
//
this.toggleRoleLoading = false
this.$message.warning(this.$t('login:message:login2'))
}
})
.catch((err) => {
this.toggleRoleLoading = false
})
} else {
this.toggleRoleLoading = false
}
})
.catch(() => {
this.toggleRoleLoading = false
})
cancel() {
this.showCode = true
this.loading = false
this.toggleRoleLoading = false
// this.toggleRoleVisible = false
},
// token
async TJUserLoginInfo(Token) {
@ -385,7 +334,10 @@ export default {
this.$store
.dispatch('user/login', this.loginForm)
.then((res) => {
if (!res) {
if (res.BasicInfo.LoginState === 2) {
this.$message.warning(this.$t('login:message:login4'))
}
if (res.BasicInfo.IsFirstAdd) {
// ,
this.$message.success(this.$t('login:message:login1'))
setTimeout(() => {
@ -394,39 +346,108 @@ export default {
})
}, 500)
return
} else if (res.BasicInfo.NeedChangePassWord) {
//
this.$alert(
this.$t('login:message:login3'),
this.$t('common:title:warning'),
{
callback: (action) => {
this.$router.push({
path: `/recompose?userName=${this.loginForm.username}`,
})
return
},
}
)
return
}
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:pm', 'role:oa', 'role:admin', 'role:dev'])
) {
this.$router.replace({ path: '/trials/trials-inspection' })
} else if (this.hasPermi(['role:oa'])) {
this.$router.replace({ path: '/system' })
} else {
this.$router.replace({ path: '/trials' })
}
} else {
//
this.$message.warning(this.$t('login:message:login2'))
}
})
zzSessionStorage.removeItem('userId')
zzSessionStorage.removeItem('identityUserId')
this.changeRoleLogin()
})
.catch(() => {
this.loading = false
})
},
changeRoleLogin() {
if (
Array.isArray(this.$store.state.user.roles) &&
this.$store.state.user.roles.length === 1
) {
this.loginByRole(this.$store.state.user.roles[0].Id)
return
}
if (
Array.isArray(this.$store.state.user.roles) &&
this.$store.state.user.roles.filter((item) => item.IsUserRoleDisabled)
.length ===
this.$store.state.user.roles.length - 1
) {
let role = this.$store.state.user.roles.find(
(item) => !item.IsUserRoleDisabled
)
this.loginByRole(role.Id)
return
}
return (this.toggleRoleVisible = true)
},
loginByRole(userRoleId) {
this.toggleRoleLoading = true
this.$store
.dispatch('user/loginByRole', { userRoleId })
.then((res) => {
this.toggleRoleLoading = false
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.LoginState === 2) {
// this.$message.warning(this.$t('login:message:login4'))
// }
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.toggleRoleLoading = false
//
this.$message.warning(this.$t('login:message:login2'))
}
})
.catch((err) => {
this.toggleRoleLoading = false
})
} else {
this.toggleRoleLoading = false
}
})
.catch((err) => {
this.showCode = true
this.loading = false
this.toggleRoleLoading = false
})
},
onSuccess() {
this.isShow = false
this.loginIn()