yuang-framework-ui-common 1.0.96 → 1.0.98

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.
@@ -1,7 +1,6 @@
1
1
  import Cookies from 'js-cookie'
2
2
  import { getAesRandomKey, aesEncrypt } from './aesUtils';
3
3
  import { rsaEncrypt } from './rsaUtils';
4
- import { isFullUrl } from './urlUtils';
5
4
  import { getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem } from './storageUtils';
6
5
  import { application } from '../config/applicationConfig';
7
6
  import { getIsDebug } from '../utils/htmlUtils';
@@ -20,9 +19,6 @@ const getSsoLoginUrl = (ssoRedirectUrl = '') => {
20
19
  if (!gatewayServerBaseUrl) {
21
20
  throw new Error('参数[gatewayServerBaseUrl]为空');
22
21
  }
23
- if (!isFullUrl(gatewayServerBaseUrl)) {
24
- throw new Error('参数[gatewayServerBaseUrl]必须是完整路径');
25
- }
26
22
  let ssoLoginUrl = `${gatewayServerBaseUrl}/sso-api/server/sso/login`;
27
23
  if (!ssoRedirectUrl) {
28
24
  ssoLoginUrl += `?ssoRedirectUrl=${encodeURIComponent(window.location.href)}`;
@@ -44,9 +40,6 @@ const getSsoAuthUrl = (ssoRedirectUrl = '') => {
44
40
  if (!gatewayServerBaseUrl) {
45
41
  throw new Error('参数[gatewayServerBaseUrl]为空');
46
42
  }
47
- if (!isFullUrl(gatewayServerBaseUrl)) {
48
- throw new Error('参数[gatewayServerBaseUrl]必须是完整路径');
49
- }
50
43
  let ssoAuthUrl = `${gatewayServerBaseUrl}/sso-api/server/sso/auth`;
51
44
  if (!ssoRedirectUrl) {
52
45
  ssoAuthUrl += `?ssoRedirectUrl=${encodeURIComponent(window.location.href)}`;
@@ -68,9 +61,6 @@ const getSsoLogoutUrl = (ssoRedirectUrl = '') => {
68
61
  if (!gatewayServerBaseUrl) {
69
62
  throw new Error('参数[gatewayServerBaseUrl]为空');
70
63
  }
71
- if (!isFullUrl(gatewayServerBaseUrl)) {
72
- throw new Error('参数[gatewayServerBaseUrl]必须是完整路径');
73
- }
74
64
  let ssoLogoutUrl = `${gatewayServerBaseUrl}/sso-api/server/sso/logout`;
75
65
  if (!ssoRedirectUrl) {
76
66
  ssoLogoutUrl += `?ssoRedirectUrl=${encodeURIComponent(window.location.href)}`;
@@ -79,33 +69,13 @@ const getSsoLogoutUrl = (ssoRedirectUrl = '') => {
79
69
  }
80
70
  return ssoLogoutUrl;
81
71
  }
82
- //
83
- // /**
84
- // * 获取sso认证路由路径
85
- // * @param ssoRedirectRoutePath
86
- // */
87
- // const getSsoAuthRoutePath = (ssoRedirectRoutePath = '') => {
88
- // if(getIsDebug()) {
89
- // debugger;
90
- // }
91
- // let ssoAuthRoutePath = '/sso/client/sso-auth/index';
92
- // if (!ssoRedirectRoutePath) {
93
- // ssoAuthRoutePath += `?ssoRedirectRoutePath=${encodeURIComponent('/sso/client/sso-auth/auth-success')}`;
94
- // } else {
95
- // ssoAuthRoutePath += `?ssoRedirectRoutePath=${encodeURIComponent(ssoRedirectRoutePath)}`;
96
- // }
97
- // if(getIsDebug()) {
98
- // console.log('ssoAuthRoutePath', ssoAuthRoutePath);
99
- // }
100
- // return ssoAuthRoutePath;
101
- // }
102
72
 
103
73
  /**
104
- * 处理路由守卫sso认证
74
+ * 处理sso认证
105
75
  * @param to
106
76
  * @param from
107
77
  */
108
- const handleRouterGuardSsoAuth = (to : any, from : any) => {
78
+ const handleSsoAuth = (to : any, from : any) => {
109
79
  from;
110
80
  return new Promise((resolve, reject) => {
111
81
  // 已登录,直接放行
@@ -124,19 +94,13 @@ const handleRouterGuardSsoAuth = (to : any, from : any) => {
124
94
  return resolve({result: false});
125
95
  }
126
96
  try {
127
- // 有认证码,请求获取 AccessToken(try/catch 捕获所有异常)
128
97
  http.get(`/sso-api/client/sso-auth/getSsoAccessToken`, { params: { ssoAuthCode } }).then(res =>{
129
98
  setSsoAccessToken(res.data.data);
130
99
  // 处理重定向路径
131
- let ssoRedirectRoutePath = to.query.ssoRedirectRoutePath as string;
132
- ssoRedirectRoutePath = (ssoRedirectRoutePath && decodeURIComponent(ssoRedirectRoutePath)) || '/sso/client/sso-login/sso-login-success';
133
- ssoRedirectRoutePath = removeParameter('ssoAuthCode', ssoRedirectRoutePath);
134
- // 无权限页重定向为登录成功页,避免切换账号误解
135
- if (ssoRedirectRoutePath === '/sso/client/sso-login/sso-login-no-privilege') {
136
- ssoRedirectRoutePath = '/sso/client/sso-login/sso-login-success';
137
- }
100
+ let fullPath = to.fullPath;
101
+ fullPath = removeParameter('ssoAuthCode', fullPath);
138
102
  // 返回重定向路径
139
- return resolve({result: false, path: ssoRedirectRoutePath});
103
+ return resolve({result: true, path: fullPath });
140
104
  });
141
105
  } catch (error) {
142
106
  console.error('SSO 获取 AccessToken 失败:', error);
@@ -263,8 +227,7 @@ export {
263
227
  getSsoLoginUrl,
264
228
  getSsoAuthUrl,
265
229
  getSsoLogoutUrl,
266
- // getSsoAuthRoutePath,
267
- handleRouterGuardSsoAuth,
230
+ handleSsoAuth,
268
231
 
269
232
  getSsoEncrypt,
270
233
  getSsoEncryptList,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.96",
3
+ "version": "1.0.98",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -1,19 +1,12 @@
1
1
  import {createRouter, createWebHistory} from 'vue-router'
2
2
  import {getExceptionRoutes} from '../../lib/utils/routerUtils'
3
3
 
4
- import { getSsoAccessToken, getSsoAuthRoutePath, handleSsoRouterGuardAuth } from '../../lib/utils/ssoUtils';
4
+ import { handleSsoAuth } from '../../lib/utils/ssoUtils';
5
5
 
6
6
 
7
7
  const router = createRouter({
8
8
  history: createWebHistory(import.meta.env.BASE_URL),
9
9
  routes: [
10
- {
11
- path: '/sso/client/sso-auth/auth-success',
12
- component: () => import('@/views/sso/client/sso-auth/auth-success.vue'),
13
- meta: {
14
- title: '认证成功',
15
- }
16
- },
17
10
  {
18
11
  path: '/gateway/gateway-config',
19
12
  component: () => import('@/views/gateway/gateway-config.vue')
@@ -69,7 +62,7 @@ const router = createRouter({
69
62
 
70
63
  /* 路由守卫 */
71
64
  router.beforeEach(async (to, from) => {
72
- let ssoAuthResult = await handleRouterGuardSsoAuth(to, from);
65
+ let ssoAuthResult = await handleSsoAuth(to, from);
73
66
  return ssoAuthResult.result;
74
67
  });
75
68
 
@@ -1,46 +0,0 @@
1
- <template>
2
- <h1>认证成功! {{ ssoData?.ssoTokenUser?.account }}</h1>
3
-
4
- <h3 @click="getSsoTokenUser">获取ssoTokenUser</h3>
5
- <h3 @click="getSsoIdentity">获取SsoIdentity</h3>
6
-
7
- <a @click="logout">注销登录</a>
8
- </template>
9
-
10
- <script setup lang="ts">
11
- import { onMounted, reactive } from 'vue';
12
- import { ElMessage } from 'element-plus/es';
13
-
14
- import { getSsoAccessToken, logoutSso } from '../../../../lib/utils/ssoUtils';
15
- import { http } from '../../../../lib/config/httpConfig';
16
-
17
- let ssoData = reactive({
18
- ssoTokenUser: {},
19
- ssoIdentity: {}
20
- });
21
- onMounted(() => {
22
- let ssoAccessToken = getSsoAccessToken();
23
- console.log('ssoAccessToken', ssoAccessToken);
24
- getSsoTokenUser();
25
- });
26
- const getSsoTokenUser = () => {
27
- http.get(`/sso-api/client/sso-user/getSsoTokenUser`).then((res: any) => {
28
- ssoData.ssoTokenUser = res.data.data;
29
- console.log('ssoTokenUser', ssoData.ssoTokenUser);
30
- ElMessage.success('获取成功');
31
- });
32
- };
33
- const getSsoIdentity = () => {
34
- http.get(`/sso-api/client/sso-user/getSsoIdentity`).then((res: any) => {
35
- ssoData.ssoIdentity = res.data.data;
36
- console.log('ssoIdentity', ssoData.ssoIdentity);
37
- ElMessage.success('获取成功');
38
- });
39
- };
40
-
41
- const logout = () => {
42
- logoutSso();
43
- };
44
- </script>
45
-
46
- <style scoped></style>