Files
foton-laws-system-front/src/pages/loginVerify/index.vue
T
2022-01-19 06:50:45 +08:00

161 lines
6.6 KiB
Vue

<!-- 长城项目 登录页 -->
<template>
</template>
<script>
import { mapMutations, mapActions } from 'vuex'
import axios from 'axios'
import util from 'util'
import { get_verify_by_instance,loginIdm,getMenu } from 'api/process'
import { ssoLoginUrlDev,ssoLogoutUrlDev,ssoLoginUrl,webLoginType,devWebUrl } from '@/sysConfig'
export default {
name: 'LoginVerify',
data () {
return {
username: this.$store.state.laws_urm || '', // 用户名
password: this.$store.state.laws_prm || '', // 密码
loading: false,
isRemember: false, // 记住密码
showIETips: false
}
},
methods: {
/**
* @description: 获取菜单logout
* @author: chenxiaoxi
* @date: 2018/11/11 13:42:14
*/
getMenu () {
return new Promise((resolve, reject) => {
this.$http.get('sarUser/user/menu', {
userId: this.$store.getters.userInfo.userId,
}, {
_this: this,
}, res => {
if (res.ok) {
resolve(res.data)
}
}, e => {
reject(e)
})
})
},
loginNew (res) {
if (res.data.orgId === null || res.data.orgId === '') {
this.$message.warning('未分配组织机构,请联系管理员分配后重新登录')
return
}
let Base64 = require('js-base64').Base64
let userInfoStr = Base64.decode(res.data)
let userInfo2 = decodeURIComponent(userInfoStr)
let userInfoObj = JSON.parse(userInfo2)
userInfoObj.userId = userInfoObj.usid
window.sessionStorage.setItem('userInfoObj', userInfoObj); // del
this.setToken(userInfoObj.token) // vuex存储token
let userInfo = {}
for (let key in userInfoObj) {
if (key !== 'uname') {
userInfo[key] = userInfoObj[key]
} else {
userInfo.uName = userInfoObj[key]
}
}
this.setUserInfo(JSON.stringify((userInfo)))
// this.resetTime()
// 获取用户菜单
window.sessionStorage.setItem('userInfo', userInfo); // del
this.getMenu().then((menuList) => {
let hasHomeMenu = false
menuList.map((menuItem) => {
if (menuItem.id === 'asdfadf') {
hasHomeMenu = true
}
})
window.sessionStorage.setItem('hasHomeMenu', hasHomeMenu); // del
window.sessionStorage.setItem('menuList', menuList); // del
if (hasHomeMenu) {
this.setMenu(JSON.stringify(menuList)).then(res => {
// this.$router.push('/home1')
let routerUrl = localStorage.getItem("routerUrl");
let routerParam = localStorage.getItem("routerParam");
// 路由跳转
if(routerParam && routerParam != ''){
const UA = navigator.userAgent.toLocaleLowerCase()
if (UA.match(/msie/) != null || UA.match(/trident/) != null) {
alert('为了最佳显示效果 请使用google chrome')
}
const param = routerParam.split("&");
this.$router.push({
name: routerUrl,
query: {
taskIds: param[0].split("=")[1],
prcId: param[1].split("=")[1],
prcNum: param[2].split("=")[1],
prcName: param[3].split("=")[1],
prcType: param[4].split("=")[1]
}
})
}else {
this.$router.push('/'+routerUrl)
}
}, e => {
this.$message.warning('未获取到菜单')
})
} else {
alert('无系统权限')
// window.location.href = 'http://testsso1.foton.com.cn/oauth2.0/authorize?client_id=app_slrs&redirect_uri=http://127.0.0.1:9090&response_type=code';
}
})
},
...mapMutations(['setToken', 'setUserInfo', 'resetTime', 'rememberPwd', 'setJESSCookie']),
...mapActions(['setMenu'])
},
computed: {
},
mounted () {
let url = window.location.search
let code = "";
if(url){
url = url.substr(1);
url = url.split('&');
let info = [];
let obj = {};
for (let i = 0,len = url.length; i < len; i++) {
info = url[i].split('=')
obj[info[0]] = decodeURI(info[1]);
url[i] = obj;
}
code = url[0].code
}
let _formData = new FormData()
_formData.append('code', code === undefined ? "" : code)
loginIdm(_formData).then(res => {
if (res.ok) {
this.loginNew(res)
} else {
if(res.respCode && res.respCode === 'r0011'){
this.$message.warning('系统无权限访问')
this.$store.dispatch('logout')
// window.location.href = 'http://sso.foton.com.cn/logout?service='
window.location.href = ssoLogoutUrlDev
}
}
})
if (this.$store.state.laws_urm !== '') {
this.isRemember = true
}
const UA = navigator.userAgent.toLocaleLowerCase()
if (UA.match(/msie/) != null || UA.match(/trident/) != null) {
this.showIETips = true
}
}
}
</script>
<style lang="less" scoped>
</style>