Blame view

ant-design-vue-jeecg/src/cas/sso.js 1.81 KB
肖超群 authored
1
import Vue from 'vue'
肖超群 authored
2
import {ACCESS_TOKEN} from "@/store/mutation-types"
肖超群 authored
3
import store from '@/store'
肖超群 authored
4
肖超群 authored
5
6
7
8
9
10
11
12
/**
 * 单点登录
 */
const init = (callback) => {
  if (process.env.VUE_APP_SSO == 'true') {
    console.log("-------单点登录开始-------");
    let token = Vue.ls.get(ACCESS_TOKEN);
    let st = getUrlParam("ticket");
13
    let sevice = "http://" + window.location.host + "/wms/";
肖超群 authored
14
15
16
17
18
19
20
21
22
23
24
    if (token) {
      loginSuccess(callback);
    } else {
      if (st) {
        validateSt(st, sevice, callback);
      } else {
        let serviceUrl = encodeURIComponent(sevice);
        window.location.href = window._CONFIG['casPrefixUrl'] + "/login?service=" + serviceUrl;
      }
    }
    console.log("-------单点登录结束-------");
肖超群 authored
25
  } else {
肖超群 authored
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
    callback && callback()
  }
};
const SSO = {
  init: init
};

function getUrlParam(paraName) {
  let url = document.location.toString();
  let arrObj = url.split("?");

  if (arrObj.length > 1) {
    let arrPara = arrObj[1].split("&");
    let arr;

    for (let i = 0; i < arrPara.length; i++) {
      arr = arrPara[i].split("=");

      if (arr != null && arr[0] == paraName) {
        return arr[1];
      }
    }
    return "";
肖超群 authored
49
  } else {
肖超群 authored
50
51
52
53
    return "";
  }
}
肖超群 authored
54
function validateSt(ticket, service, callback) {
肖超群 authored
55
56
  let params = {
    ticket: ticket,
肖超群 authored
57
    service: service
肖超群 authored
58
  };
肖超群 authored
59
  store.dispatch('ValidateLogin', params).then(res => {
肖超群 authored
60
    //this.departConfirm(res)
肖超群 authored
61
    if (res.success) {
肖超群 authored
62
      loginSuccess(callback);
肖超群 authored
63
    } else {
64
      let sevice = "http://" + window.location.host + "/wms/";
肖超群 authored
65
      let serviceUrl = encodeURIComponent(sevice);
肖超群 authored
66
      window.location.href = window._CONFIG['casPrefixUrl'] + "/login?service=" + serviceUrl;
肖超群 authored
67
68
69
70
71
72
73
    }
  }).catch((err) => {
    console.log(err);
    //that.requestFailed(err);
  });
}
肖超群 authored
74
function loginSuccess(callback) {
肖超群 authored
75
76
  callback();
}
肖超群 authored
77
肖超群 authored
78
export default SSO;