|
@@ -99,46 +99,49 @@ const actions = {
|
|
|
const { username, password } = userInfo
|
|
|
return new Promise((resolve, reject) => {
|
|
|
login({ username: username.trim(), password: password }).then(response => {
|
|
|
+ if(Cookies.get('sso') == 1){
|
|
|
// 单点登录=============================
|
|
|
- // const fullURL = window.location.href;
|
|
|
- // // 使用正则表达式提取code参数的值
|
|
|
- // const codeMatch = fullURL.match(/[\?&]access=([^&]+)/);
|
|
|
- // console.log('codeMatch===>',codeMatch)
|
|
|
- // if (codeMatch) {
|
|
|
- // // 如果匹配成功,将code的值存储在组件的data中
|
|
|
- // var code = codeMatch[1];
|
|
|
- // //TODO 保存token
|
|
|
- // // 去除后面的#/login
|
|
|
- // if ( code && code.includes("#/login")) {
|
|
|
- // code = code.replace("#/login", "");
|
|
|
- // }
|
|
|
- // //base64解密this.cose
|
|
|
- // console.log('解密token',atob(code))
|
|
|
- // let token = atob(code)
|
|
|
- // commit('SET_TOKEN', token)
|
|
|
- // setToken(token)
|
|
|
- // resolve()
|
|
|
- // let url = window.location.href;
|
|
|
- // // 使用split方法将URL拆分为数组
|
|
|
- // let jmpurl = url.split('?')[0]+'#/dashboard'
|
|
|
- // window.open(jmpurl, "_self");
|
|
|
- // }
|
|
|
+ const fullURL = window.location.href;
|
|
|
+ // 使用正则表达式提取code参数的值
|
|
|
+ const codeMatch = fullURL.match(/[\?&]access=([^&]+)/);
|
|
|
+ console.log('codeMatch===>',codeMatch)
|
|
|
+ if (codeMatch) {
|
|
|
+ // 如果匹配成功,将code的值存储在组件的data中
|
|
|
+ var code = codeMatch[1];
|
|
|
+ //TODO 保存token
|
|
|
+ // 去除后面的#/login
|
|
|
+ if ( code && code.includes("#/login")) {
|
|
|
+ code = code.replace("#/login", "");
|
|
|
+ }
|
|
|
+ //base64解密this.cose
|
|
|
+ console.log('解密token',atob(code))
|
|
|
+ let token = atob(code)
|
|
|
+ commit('SET_TOKEN', token)
|
|
|
+ setToken(token)
|
|
|
+ resolve()
|
|
|
+ let url = window.location.href;
|
|
|
+ // 使用split方法将URL拆分为数组
|
|
|
+ let jmpurl = url.split('?')[0]+'#/dashboard'
|
|
|
+ window.open(jmpurl, "_self");
|
|
|
+ }
|
|
|
// =============================
|
|
|
- const { data, msg } = response
|
|
|
- if (msg !== 'ok') {
|
|
|
- Message({
|
|
|
- message: data,
|
|
|
- type: 'error',
|
|
|
- duration: 5 * 1000
|
|
|
- })
|
|
|
- reject(data)
|
|
|
- }
|
|
|
- commit('SET_TOKEN', data.token)
|
|
|
- if (Cookies == null) {
|
|
|
- console.log(1)
|
|
|
+ }else{
|
|
|
+ const { data, msg } = response
|
|
|
+ if (msg !== 'ok') {
|
|
|
+ Message({
|
|
|
+ message: data,
|
|
|
+ type: 'error',
|
|
|
+ duration: 5 * 1000
|
|
|
+ })
|
|
|
+ reject(data)
|
|
|
+ }
|
|
|
+ commit('SET_TOKEN', data.token)
|
|
|
+ if (Cookies == null) {
|
|
|
+ console.log(1)
|
|
|
+ }
|
|
|
+ setToken(data.token)
|
|
|
+ resolve()
|
|
|
}
|
|
|
- setToken(data.token)
|
|
|
- resolve()
|
|
|
}).catch(error => {
|
|
|
reject(error)
|
|
|
})
|
|
@@ -161,29 +164,31 @@ const actions = {
|
|
|
if (!role || role.length <= 0) {
|
|
|
reject('该用户未分配角色!')
|
|
|
console.log('no=============')
|
|
|
- setTimeout(()=>{
|
|
|
- commit('SET_BUTTONS', [])
|
|
|
- // console.log('-------------', state)
|
|
|
- commit('SET_TOKEN', '')
|
|
|
- commit('SET_ROLES', [])
|
|
|
- Cookies.remove('employename')
|
|
|
- Cookies.remove('employeid')
|
|
|
- Cookies.remove('pastureid')
|
|
|
- removeToken()
|
|
|
- resetRouter()
|
|
|
- resolve()
|
|
|
- // 单点登录
|
|
|
- // var url = process.env.VUE_APP_BASE_API
|
|
|
- // //获取当前url
|
|
|
+ if(Cookies.get('sso') == 1){
|
|
|
+ setTimeout(()=>{
|
|
|
+ commit('SET_BUTTONS', [])
|
|
|
+ // console.log('-------------', state)
|
|
|
+ commit('SET_TOKEN', '')
|
|
|
+ commit('SET_ROLES', [])
|
|
|
+ Cookies.remove('employename')
|
|
|
+ Cookies.remove('employeid')
|
|
|
+ Cookies.remove('pastureid')
|
|
|
+ removeToken()
|
|
|
+ resetRouter()
|
|
|
+ resolve()
|
|
|
+ // 单点登录
|
|
|
+ var url = process.env.VUE_APP_BASE_API
|
|
|
+ //获取当前url
|
|
|
|
|
|
- // if(url.indexOf('/')==0 && url.length==1){
|
|
|
- // url= window.location.protocol + "//"+window.location.host+url
|
|
|
- // }
|
|
|
- // const externalURL = "https://id.xiandaimuye.com/api/v1/logout?redirect_url="+url+ '&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I';
|
|
|
- // // 使用 $router.push 进行页面跳转
|
|
|
- // // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
|
|
|
- // window.open(externalURL, "_self");
|
|
|
- },2000)
|
|
|
+ if(url.indexOf('/')==0 && url.length==1){
|
|
|
+ url= window.location.protocol + "//"+window.location.host+url
|
|
|
+ }
|
|
|
+ const externalURL = "https://id.xiandaimuye.com/api/v1/logout?redirect_url="+url+ '&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I';
|
|
|
+ // 使用 $router.push 进行页面跳转
|
|
|
+ // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
|
|
|
+ window.open(externalURL, "_self");
|
|
|
+ },2000)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
GetDataByName({ 'name': 'getUserPCButtons', 'parammaps': { 'jwt_username': username }}).then(response => {
|
|
@@ -271,19 +276,33 @@ const actions = {
|
|
|
removeToken()
|
|
|
resetRouter()
|
|
|
resolve()
|
|
|
+ if(Cookies.get('sso') == 1){
|
|
|
// 单点登录
|
|
|
- // var url = process.env.VUE_APP_BASE_API
|
|
|
- // console.log(url,'url')
|
|
|
- // //获取当前url
|
|
|
+ var url = process.env.VUE_APP_BASE_API
|
|
|
+ console.log(url,'url')
|
|
|
+ //获取当前url
|
|
|
|
|
|
- // if(url.indexOf('/')==0 && url.length==1){
|
|
|
- // url= window.location.protocol + "//"+window.location.host+url
|
|
|
- // }
|
|
|
- // const externalURL = "https://id.xiandaimuye.com/api/v1/logout?redirect_url=" + url + '&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I';
|
|
|
- // // 使用 $router.push 进行页面跳转
|
|
|
- // // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
|
|
|
- // window.open(externalURL, "_self");
|
|
|
- // location.reload()
|
|
|
+ if(url.indexOf('/')==0 && url.length==1){
|
|
|
+ url= window.location.protocol + "//"+window.location.host+url
|
|
|
+ }
|
|
|
+ const externalURL = "https://id.xiandaimuye.com/api/v1/logout?redirect_url=" + url + '&client_id=fTBm64I4k3kqHYtoFTUpvirCDxxCfx7I';
|
|
|
+ // 使用 $router.push 进行页面跳转
|
|
|
+ // 注意: 这里的跳转是在当前窗口进行的,如果需要在新标签页打开,可以使用 window.open(externalURL)
|
|
|
+ window.open(externalURL, "_self");
|
|
|
+ // location.reload()
|
|
|
+ }else{
|
|
|
+ commit('SET_BUTTONS', [])
|
|
|
+ // console.log('-------------', state)
|
|
|
+ commit('SET_TOKEN', '')
|
|
|
+ commit('SET_ROLES', [])
|
|
|
+ Cookies.remove('employename')
|
|
|
+ Cookies.remove('employeid')
|
|
|
+ Cookies.remove('pastureid')
|
|
|
+ removeToken()
|
|
|
+ resetRouter()
|
|
|
+ resolve()
|
|
|
+ location.reload()
|
|
|
+ }
|
|
|
}).catch(error => {
|
|
|
reject(error)
|
|
|
})
|