yuang-framework-ui-common 1.0.2 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -29,12 +29,16 @@ $http.interceptors.request.use(config => {
29
29
  /* 响应拦截器 */
30
30
  $http.interceptors.response.use((res) => {
31
31
  // 登录过期处理
32
- if (res.data.statusCode === 401) {
33
- clearSsoAccessToken();
34
- // router.push('/sso/login');
35
- location.href = 'http://localhost:8110/sso-ui-pc/sso/login';
32
+ if (res.data.statusCode !== 200) {
33
+ if (res.data.statusCode === 401) {
34
+ clearSsoAccessToken();
35
+ // router.push('/sso/login');
36
+ location.href = 'http://localhost:8110/sso-ui-pc/sso/login';
37
+ return Promise.reject(new Error(res.data.message));
38
+ }
36
39
  return Promise.reject(new Error(res.data.message));
37
40
  }
41
+
38
42
  return res;
39
43
  }, (error) => {
40
44
  return Promise.reject(error);
@@ -1,14 +1,13 @@
1
- import {ElMessage} from 'element-plus/es';
2
1
 
3
2
  import http from '../config/http';
4
3
 
5
4
  const initGateway = () => {
6
- return new Promise(async resolve => {
5
+ return new Promise<void>(async resolve => {
7
6
  let gatewayAccessToken = localStorage.getItem("gatewayAccessToken");
8
7
  if (!gatewayAccessToken) {
9
8
  let res = await http.get('/server/gateway/getGatewayAccessToken');
10
9
  if (res.data.statusCode != 200) {
11
- return EleMessage.error(res.data.message);
10
+ return console.error(res.data.message);
12
11
  }
13
12
  localStorage.setItem("gatewayAccessToken", res.data.data.gatewayAccessToken);
14
13
  }
@@ -4,20 +4,20 @@
4
4
  import Cookies from 'js-cookie'
5
5
 
6
6
  const getSsoLoginUrl = function () {
7
- return 'http://localhost:8110/sso-ui-pc/sso/login';
7
+ return 'http://localhost:8110/gateway-api/sso-api/server/sso/login';
8
8
  }
9
9
 
10
10
  const getSsoLogoutUrl = function () {
11
- return 'http://localhost:8110/sso-ui-pc/sso/logout';
11
+ return 'http://localhost:8110/gateway-api/sso-api/server/sso/logout';
12
12
  }
13
13
 
14
14
 
15
- const ssoAccessTokenCookieKey:string = 'Sso-Access-Token';
16
- const ssoAccessTokenLocalKey:string = 'ssoAccessToken';
17
- const ssoRefreshTokenLocalKey:string = 'ssoRefreshToken';
15
+ const ssoAccessTokenCookieKey: string = 'Sso-Access-Token';
16
+ const ssoAccessTokenLocalKey: string = 'ssoAccessToken';
17
+ const ssoRefreshTokenLocalKey: string = 'ssoRefreshToken';
18
18
 
19
19
 
20
- const getSsoAccessToken = function () {
20
+ const getSsoAccessToken = () => {
21
21
  let ssoAccessToken = Cookies.get(ssoAccessTokenCookieKey);
22
22
 
23
23
  if (!ssoAccessToken) {
@@ -29,14 +29,16 @@ const getSsoAccessToken = function () {
29
29
  }
30
30
 
31
31
 
32
- const setSsoAccessToken = function (param: any) {
32
+ const setSsoAccessToken = (param: any) => {
33
+ Cookies.set(ssoAccessTokenCookieKey, param.ssoAccessToken);
34
+
33
35
  localStorage.setItem(ssoAccessTokenLocalKey, param.ssoAccessToken);
34
36
  localStorage.setItem(ssoRefreshTokenLocalKey, param.ssoRefreshToken);
35
37
 
36
38
  }
37
39
 
38
40
 
39
- const clearSsoAccessToken = function () {
41
+ const clearSsoAccessToken = () => {
40
42
  Cookies.remove(ssoAccessTokenCookieKey);
41
43
 
42
44
  localStorage.removeItem(ssoAccessTokenLocalKey);
@@ -44,6 +46,11 @@ const clearSsoAccessToken = function () {
44
46
 
45
47
  }
46
48
 
49
+ const logoutSso = () => {
50
+ clearSsoAccessToken();
51
+ window.location.href = `${getSsoLogoutUrl()}?redirectUrl=${encodeURIComponent(window.location.href)}`;
52
+ }
53
+
47
54
 
48
55
  export {
49
56
  getSsoLoginUrl,
@@ -54,4 +61,5 @@ export {
54
61
 
55
62
  clearSsoAccessToken,
56
63
 
64
+ logoutSso,
57
65
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {