yuang-framework-ui-common 1.0.41 → 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.
- package/lib/utils/ssoUtils.ts +27 -0
- package/lib/utils/urlUtils.ts +33 -0
- package/package.json +1 -1
- package/src/shims-vue.d.ts +3 -0
- package/src/views/sso/login/index.vue +31 -10
package/lib/utils/ssoUtils.ts
CHANGED
@@ -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
package/src/shims-vue.d.ts
CHANGED
@@ -24,20 +24,41 @@
|
|
24
24
|
setSsoAccessToken(res.data.data);
|
25
25
|
let ssoRedirectRoutePath = router.currentRoute.value.query.ssoRedirectRoutePath as string;
|
26
26
|
ssoRedirectRoutePath = (ssoRedirectRoutePath && decodeURIComponent(ssoRedirectRoutePath)) || ('/sso/login/login-success' as any);
|
27
|
+
ssoRedirectRoutePath = removeUrlParameter(ssoRedirectRoutePath, 'ssoAuthCode');
|
27
28
|
router.push(ssoRedirectRoutePath);
|
28
29
|
});
|
29
30
|
});
|
30
31
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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>
|