yuang-framework-ui-common 1.0.40 → 1.0.42

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.
@@ -78,7 +78,7 @@ http.interceptors.response.use(async (res: any) => {
78
78
  return axios.request(res.config);
79
79
  } else if (res?.data?.statusCode === 500815006) {
80
80
  const fullPath = router.currentRoute.value.fullPath;
81
- router.push(`/sso/login/index?redirectRoutePath=${encodeURIComponent(fullPath)}`);
81
+ router.push(`/sso/login/index?ssoRedirectRoutePath=${encodeURIComponent(fullPath)}`);
82
82
  return;
83
83
  } else if (res?.data?.statusCode === 500815003) {
84
84
  showErrorMessage(res?.data?.message || messageMap.requestError);
@@ -1,3 +1,4 @@
1
+ import safeStringify from 'safe-stringify';
1
2
 
2
3
  /**
3
4
  * 浅度克隆对象
@@ -15,7 +16,9 @@ const shallowClone = (obj) => {
15
16
  * @returns {{}|*}
16
17
  */
17
18
  const deepClone = (obj) => {
18
- let result;
19
+ /*
20
+ 约到允许依赖就没法了,报错:Maximum call stack size exceeded
21
+ let result;
19
22
  const type = typeOf(obj);
20
23
  if (type === 'Object') result = {};
21
24
  else if (type === 'Array') result = [];
@@ -26,6 +29,11 @@ const deepClone = (obj) => {
26
29
  else result[key] = obj[key];
27
30
  });
28
31
  return result;
32
+ */
33
+ if(!obj){
34
+ return null;
35
+ }
36
+ return JSON.parse(safeStringify(obj));
29
37
  }
30
38
  /**
31
39
  * 获取变量类型
@@ -1,47 +1,47 @@
1
1
  import Cookies from 'js-cookie'
2
- import {getAesRandomKey, aesEncrypt} from './aesUtils';
3
- import {rsaEncrypt} from './rsaUtils';
4
- import {getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem} from './storageUtils';
2
+ import { getAesRandomKey, aesEncrypt } from './aesUtils';
3
+ import { rsaEncrypt } from './rsaUtils';
4
+ import { getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem } from './storageUtils';
5
5
 
6
6
 
7
- const getSsoLoginUrl = (redirectUrl = '') => {
7
+ const getSsoLoginUrl = (ssoRedirectUrl = '') => {
8
8
  let apiFullBaseUrl = (window as any).$config?.apiFullBaseUrl;
9
- if(!apiFullBaseUrl) {
9
+ if (!apiFullBaseUrl) {
10
10
  throw new Error('参数[apiFullBaseUrl]为空');
11
11
  }
12
12
  let ssoLoginUrl = `${apiFullBaseUrl}/sso-api/server/sso/login`;
13
- if (!redirectUrl) {
14
- ssoLoginUrl += `?redirectUrl=${encodeURIComponent(window.location.href)}`;
13
+ if (!ssoRedirectUrl) {
14
+ ssoLoginUrl += `?ssoRedirectUrl=${encodeURIComponent(window.location.href)}`;
15
15
  } else {
16
- ssoLoginUrl += `?redirectUrl=${encodeURIComponent(redirectUrl)}`;
16
+ ssoLoginUrl += `?ssoRedirectUrl=${encodeURIComponent(ssoRedirectUrl)}`;
17
17
  }
18
18
  return ssoLoginUrl;
19
19
  }
20
20
 
21
- const getSsoLogoutUrl = (redirectUrl = '') => {
21
+ const getSsoLogoutUrl = (ssoRedirectUrl = '') => {
22
22
  let apiFullBaseUrl = (window as any).$config?.apiFullBaseUrl;
23
- if(!apiFullBaseUrl) {
23
+ if (!apiFullBaseUrl) {
24
24
  throw new Error('参数[apiFullBaseUrl]为空');
25
25
  }
26
26
  let ssoLogoutUrl = `${apiFullBaseUrl}/sso-api/server/sso/logout`;
27
- if (!redirectUrl) {
28
- ssoLogoutUrl += `?redirectUrl=${encodeURIComponent(window.location.href)}`;
29
- } else if (redirectUrl) {
30
- ssoLogoutUrl += `?redirectUrl=${encodeURIComponent(redirectUrl)}`;
27
+ if (!ssoRedirectUrl) {
28
+ ssoLogoutUrl += `?ssoRedirectUrl=${encodeURIComponent(window.location.href)}`;
29
+ } else if (ssoRedirectUrl) {
30
+ ssoLogoutUrl += `?ssoRedirectUrl=${encodeURIComponent(ssoRedirectUrl)}`;
31
31
  }
32
32
  return ssoLogoutUrl;
33
33
  }
34
34
 
35
35
  /**
36
36
  * 获取sso登录路由路径
37
- * @param redirectRoutePath
37
+ * @param ssoRedirectRoutePath
38
38
  */
39
- const getSsoLoginRoutePath = (redirectRoutePath = '') => {
39
+ const getSsoLoginRoutePath = (ssoRedirectRoutePath = '') => {
40
40
  let ssoLoginRoutePath = '/sso/login/index';
41
- if (!redirectRoutePath) {
42
- ssoLoginRoutePath += `?redirectRoutePath=${encodeURIComponent('/sso/login/login-success')}`;
41
+ if (!ssoRedirectRoutePath) {
42
+ ssoLoginRoutePath += `?ssoRedirectRoutePath=${encodeURIComponent('/sso/login/login-success')}`;
43
43
  } else {
44
- ssoLoginRoutePath += `?redirectRoutePath=${encodeURIComponent(redirectRoutePath)}`;
44
+ ssoLoginRoutePath += `?ssoRedirectRoutePath=${encodeURIComponent(ssoRedirectRoutePath)}`;
45
45
  }
46
46
  return ssoLoginRoutePath;
47
47
  }
@@ -59,7 +59,7 @@ const getSsoEncrypt = (password = '') => {
59
59
  // 使用AES16位的密钥将请求报文加密(使用的是加密前的aes密钥)
60
60
  const encryptPassword = aesEncrypt(aesKey, password);
61
61
 
62
- return {encryptPassword, rsaAesKey};
62
+ return { encryptPassword, rsaAesKey };
63
63
  }
64
64
 
65
65
  /**
@@ -78,7 +78,7 @@ const getSsoEncryptList = (passwordList = []) => {
78
78
  encryptPasswordList[i] = aesEncrypt(aesKey, passwordList[i]);
79
79
  }
80
80
 
81
- return {encryptPasswordList, rsaAesKey};
81
+ return { encryptPasswordList, rsaAesKey };
82
82
  }
83
83
 
84
84
 
@@ -99,16 +99,16 @@ const getSsoAccessToken = () => {
99
99
 
100
100
 
101
101
  const setSsoAccessToken = (param: any) => {
102
- if(!param.ssoAccessToken) {
102
+ if (!param.ssoAccessToken) {
103
103
  throw new Error('参数[ssoAccessToken]为空');
104
104
  }
105
- if(!param.ssoExpiresIn) {
105
+ if (!param.ssoExpiresIn) {
106
106
  throw new Error('参数[ssoExpiresIn]为空');
107
107
  }
108
- if(!param.ssoRefreshToken) {
108
+ if (!param.ssoRefreshToken) {
109
109
  throw new Error('参数[ssoRefreshToken]为空');
110
110
  }
111
- if(!param.ssoRefreshExpiresIn) {
111
+ if (!param.ssoRefreshExpiresIn) {
112
112
  throw new Error('参数[ssoRefreshExpiresIn]为空');
113
113
  }
114
114
  Cookies.set(ssoAccessTokenCookieKey, param.ssoAccessToken);
@@ -119,6 +119,30 @@ const setSsoAccessToken = (param: any) => {
119
119
  }
120
120
 
121
121
 
122
+
123
+ const getSsoCookieAccessToken = () => {
124
+ let ssoAccessToken = Cookies.get(ssoAccessTokenCookieKey);
125
+ return ssoAccessToken;
126
+ }
127
+
128
+
129
+ const setSsoCookieAccessToken = (param: any) => {
130
+ if (!param.ssoAccessToken) {
131
+ throw new Error('参数[ssoAccessToken]为空');
132
+ }
133
+ if (!param.ssoExpiresIn) {
134
+ throw new Error('参数[ssoExpiresIn]为空');
135
+ }
136
+ if (!param.ssoRefreshToken) {
137
+ throw new Error('参数[ssoRefreshToken]为空');
138
+ }
139
+ if (!param.ssoRefreshExpiresIn) {
140
+ throw new Error('参数[ssoRefreshExpiresIn]为空');
141
+ }
142
+ Cookies.set(ssoAccessTokenCookieKey, param.ssoAccessToken);
143
+ }
144
+
145
+
122
146
  const clearSsoAccessToken = () => {
123
147
  Cookies.remove(ssoAccessTokenCookieKey);
124
148
 
@@ -144,6 +168,9 @@ export {
144
168
  getSsoAccessToken,
145
169
  setSsoAccessToken,
146
170
 
171
+ getSsoCookieAccessToken,
172
+ setSsoCookieAccessToken,
173
+
147
174
  clearSsoAccessToken,
148
175
 
149
176
  logoutSso,
@@ -0,0 +1,33 @@
1
+
2
+ /**
3
+ * 删除url中的指定参数
4
+ * @param url
5
+ * @param parameter
6
+ * @return {string}
7
+ */
8
+ const removeUrlParameter = (url, parameter) => {
9
+ if (!url) {
10
+ return console.error('参数[url]为空');
11
+ }
12
+ if (!parameter) {
13
+ return console.error('参数[parameter]为空');
14
+ }
15
+ let urlObj;
16
+ let isFullUrl = url.startsWith('http');
17
+ if (isFullUrl) {
18
+ urlObj = new URL(url);
19
+ } else {
20
+ urlObj = new URL(url, window.location.origin);
21
+ }
22
+ urlObj.searchParams.delete(parameter);
23
+ let result = urlObj.pathname + urlObj.search;
24
+ if (url.includes('#')) {
25
+ result += '#' + url.split('#')[1];
26
+ }
27
+ if (isFullUrl) {
28
+ result = urlObj.origin + result;
29
+ }
30
+ return result;
31
+ };
32
+
33
+ export { removeUrlParameter };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yuang-framework-ui-common",
3
- "version": "1.0.40",
3
+ "version": "1.0.42",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "scripts": {
@@ -35,6 +35,7 @@
35
35
  "lodash": "^4.17.21",
36
36
  "moment": "^2.30.1",
37
37
  "pinia": "^2.1.7",
38
+ "safe-stringify": "^1.1.1",
38
39
  "vant": "^4.9.8",
39
40
  "vue": "^3.4.29",
40
41
  "vue-router": "^4.3.3"
@@ -8,3 +8,6 @@ declare module '*.vue' {
8
8
  const component: DefineComponent<{}, {}, any>;
9
9
  export default component;
10
10
  }
11
+
12
+
13
+ declare module 'js-cookie';
@@ -13,31 +13,52 @@
13
13
  const { proxy } = getCurrentInstance() as any;
14
14
 
15
15
  onMounted(() => {
16
- const code = router.currentRoute.value.query.code;
17
- if (!code) {
16
+ const ssoAuthCode = router.currentRoute.value.query.ssoAuthCode;
17
+ if (!ssoAuthCode) {
18
18
  window.location.href = getSsoLoginUrl(window.location.href) || '';
19
19
  // 这里一定要return,不return还是会继续执行下面的代码
20
20
  return;
21
21
  }
22
22
 
23
- proxy.$http.get('/sso-api/client/sso-auth/getSsoAccessToken', { params: { code: code } }).then((res: any) => {
23
+ proxy.$http.get('/sso-api/client/sso-auth/getSsoAccessToken', { params: { ssoAuthCode: ssoAuthCode } }).then((res: any) => {
24
24
  setSsoAccessToken(res.data.data);
25
- let redirectRoutePath = router.currentRoute.value.query.redirectRoutePath as string;
26
- redirectRoutePath = (redirectRoutePath && decodeURIComponent(redirectRoutePath)) || ('/sso/login/login-success' as any);
27
- router.push(redirectRoutePath);
25
+ let ssoRedirectRoutePath = router.currentRoute.value.query.ssoRedirectRoutePath as string;
26
+ ssoRedirectRoutePath = (ssoRedirectRoutePath && decodeURIComponent(ssoRedirectRoutePath)) || ('/sso/login/login-success' as any);
27
+ ssoRedirectRoutePath = removeUrlParameter(ssoRedirectRoutePath, 'ssoAuthCode');
28
+ router.push(ssoRedirectRoutePath);
28
29
  });
29
30
  });
30
31
 
31
- const removeParameter = (url: string, parameter: string) => {
32
- // 使用正则表达式匹配参数
33
- const regex = new RegExp('[?&]' + parameter + '=[^&]*&?');
34
- const newUrl = url.replace(regex, (match, offset, string) => {
35
- offset;
36
- string;
37
- return match.includes('&') ? '&' : '';
38
- });
39
- return newUrl;
40
- }
32
+ /**
33
+ * 删除url中的指定参数
34
+ * @param url
35
+ * @param parameter
36
+ * @return {string}
37
+ */
38
+ const removeUrlParameter = (url, parameter) => {
39
+ if (!url) {
40
+ return console.error('参数[url]为空');
41
+ }
42
+ if (!parameter) {
43
+ return console.error('参数[parameter]为空');
44
+ }
45
+ let urlObj;
46
+ let isFullUrl = url.startsWith('http');
47
+ if (isFullUrl) {
48
+ urlObj = new URL(url);
49
+ } else {
50
+ urlObj = new URL(url, window.location.origin);
51
+ }
52
+ urlObj.searchParams.delete(parameter);
53
+ let result = urlObj.pathname + urlObj.search;
54
+ if (url.includes('#')) {
55
+ result += '#' + url.split('#')[1];
56
+ }
57
+ if (isFullUrl) {
58
+ result = urlObj.origin + result;
59
+ }
60
+ return result;
61
+ };
41
62
  </script>
42
63
 
43
64
  <style scoped></style>
package/lib/.DS_Store DELETED
Binary file
package/src/.DS_Store DELETED
Binary file
Binary file