登录页从路由中获取token登录
continuous-integration/drone/push Build is running
Details
continuous-integration/drone/push Build is running
Details
parent
42eeda29d2
commit
76252e50d1
|
@ -1,5 +1,5 @@
|
|||
import { getToken, setToken, removeToken, setName, removeName } from '@/utils/auth'
|
||||
import { login, getUserMenuTree, getUserPermissions, loginSelectUserRole } from '@/api/user'
|
||||
import { login, getUserMenuTree, getUserPermissions, loginSelectUserRole, TJUserLoginInfo } from '@/api/user'
|
||||
import { getUser } from '@/api/admin'
|
||||
import { resetRouter } from '@/router'
|
||||
import md5 from 'js-md5'
|
||||
|
@ -142,6 +142,23 @@ const actions = {
|
|||
})
|
||||
})
|
||||
},
|
||||
loginByToken({ commit }, Token) {
|
||||
return new Promise((resolve, reject) => {
|
||||
TJUserLoginInfo({ Token }).then(async response => {
|
||||
if (response.IsSuccess) {
|
||||
zzSessionStorage.removeItem('lastWorkbench')
|
||||
const data = response.Result
|
||||
setToken(response.OtherInfo)
|
||||
commit('SET_ROLES', data)
|
||||
resolve(data)
|
||||
} else {
|
||||
reject(response.ErrorMessage)
|
||||
}
|
||||
}).catch(() => {
|
||||
reject()
|
||||
})
|
||||
})
|
||||
},
|
||||
loginByRole({ commit }, userInfo) {
|
||||
const { UserId, UserTypeId } = userInfo
|
||||
let params = {
|
||||
|
@ -160,10 +177,12 @@ const actions = {
|
|||
zzSessionStorage.setItem('userId', UserId)
|
||||
const userString = decodeURIComponent(escape(window.atob(data.split('.')[1].replace(/-/g, '+').replace(/_/g, '/'))))
|
||||
const user = JSON.parse(userString)
|
||||
// return console.log(user, user.realName)
|
||||
zzSessionStorage.setItem('userTypeShortName', user.userTypeShortName)
|
||||
// commit('SET_USERTYPESHORTNAME', user.userTypeShortName)
|
||||
commit('SET_NAME', user.fullName)
|
||||
setName(user.fullName)
|
||||
commit('SET_NAME', user.realName)
|
||||
setName(user.realName)
|
||||
zzSessionStorage.setItem('realName', user.realName)
|
||||
zzSessionStorage.setItem('userTypeEnumInt', user.userTypeEnumInt)
|
||||
var permissions = await getUserPermissions()
|
||||
var menuTree = await getUserMenuTree()
|
||||
|
|
|
@ -112,6 +112,8 @@
|
|||
<el-button type="primary" @click="saveHospital">{{ $t("system:hospital:save") }}</el-button>
|
||||
</span>
|
||||
</el-dialog>
|
||||
<toggleRole v-if="toggleRoleVisible" :visible.sync="toggleRoleVisible" :loading="toggleRoleLoading"
|
||||
@save="loginByRole" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
@ -124,11 +126,12 @@ import Img1 from '@/assets/pic-1.png'
|
|||
import logoImg from '@/assets/zzlogo2.png'
|
||||
import { getHospital } from '@/api/hospital.js'
|
||||
import { getHIRHospitalList, updateDefaultHospital } from '@/api/admin'
|
||||
import { TJUserLoginInfo } from '@/api/user'
|
||||
import toggleRole from '@/components/toggleRole'
|
||||
import { resetRouter } from '@/router'
|
||||
|
||||
export default {
|
||||
name: 'Login',
|
||||
components: { TopLang, Vcode },
|
||||
components: { TopLang, Vcode, toggleRole },
|
||||
data() {
|
||||
return {
|
||||
config: WINDOW_CONFIG,
|
||||
|
@ -176,7 +179,10 @@ export default {
|
|||
hospitalList: [],
|
||||
form: {
|
||||
Id: null
|
||||
}
|
||||
},
|
||||
|
||||
toggleRoleVisible: false,
|
||||
toggleRoleLoading: false,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
|
@ -215,16 +221,74 @@ 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
|
||||
})
|
||||
},
|
||||
// 置换token
|
||||
async TJUserLoginInfo(Token) {
|
||||
try {
|
||||
let params = {
|
||||
Token
|
||||
}
|
||||
let res = await TJUserLoginInfo(params)
|
||||
} catch (err) {
|
||||
console.log(err)
|
||||
}
|
||||
this.$store
|
||||
.dispatch('user/loginByToken', { Token }).then(res => {
|
||||
if (res.length === 1) {
|
||||
return this.loginByRole(res[0])
|
||||
}
|
||||
this.toggleRoleVisible = true
|
||||
}).catch(err => {
|
||||
console.log(err)
|
||||
})
|
||||
},
|
||||
async saveHospital() {
|
||||
if (this.form.Id === this.hospital.Id) return this.visible = false
|
||||
|
|
|
@ -2,9 +2,8 @@
|
|||
<div class="trials-navbar" style="position: relative">
|
||||
<div class="leftMenu">
|
||||
<!-- <img v-if="language === 'zh' && hospital.HospitalLogoPath" -->
|
||||
<img v-if="hospital.HospitalLogoPath"
|
||||
:src="OSSclientConfig.basePath + hospital.HospitalLogoPath" crossOrigin="anonymous" alt=""
|
||||
style="min-width: 170px;" />
|
||||
<img v-if="hospital.HospitalLogoPath" :src="OSSclientConfig.basePath + hospital.HospitalLogoPath"
|
||||
crossOrigin="anonymous" alt="" style="min-width: 170px;" />
|
||||
<div v-else style="width: 170px;"></div>
|
||||
<!-- <img v-else src="@/assets/zzlogo3.png" alt="" /> -->
|
||||
<span style="white-space: nowrap">
|
||||
|
@ -74,7 +73,7 @@
|
|||
</el-submenu>
|
||||
</el-menu>
|
||||
<TopLang v-if="isDev" />
|
||||
<toggleRole v-if="toggleRoleVisible" :visible.sync="toggleRoleVisible" :loading="toggleRoleLoading" :roles="roles"
|
||||
<toggleRole v-if="toggleRoleVisible" :visible.sync="toggleRoleVisible" :loading="toggleRoleLoading"
|
||||
@save="loginByRole" />
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue