yuang-framework-ui-common 1.0.53 → 1.0.54
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/config/applicationConfig.ts +37 -0
- package/lib/config/gatewayConfig.ts +4 -3
- package/lib/config/httpConfig.ts +17 -6
- package/lib/utils/ssoUtils.ts +20 -8
- package/lib/utils/urlUtils.ts +24 -8
- package/package.json +1 -1
- package/src/main.ts +5 -5
- package/src/views/sso/auth/auth-success.vue +4 -3
- package/src/views/sso/auth/index.vue +4 -1
- package/lib/config/initConfig.ts +0 -31
@@ -0,0 +1,37 @@
|
|
1
|
+
import { isPc } from '../utils/deviceUtils';
|
2
|
+
|
3
|
+
|
4
|
+
import ElementPlus from 'element-plus'
|
5
|
+
import 'element-plus/dist/index.css'
|
6
|
+
import { ElMessage } from 'element-plus'
|
7
|
+
|
8
|
+
import vant from 'vant';
|
9
|
+
import 'vant/lib/index.css';
|
10
|
+
|
11
|
+
|
12
|
+
import { http } from './httpConfig';
|
13
|
+
// import moment from 'moment';
|
14
|
+
|
15
|
+
const initApplicationConfig = (app: any, applicationConfig: any) => {
|
16
|
+
// app.config.globalProperties.$http = http;
|
17
|
+
// app.config.globalProperties.$moment = moment;
|
18
|
+
|
19
|
+
if (isPc()) {
|
20
|
+
app.config.globalProperties.$message = ElMessage;
|
21
|
+
app.use(ElementPlus);
|
22
|
+
} else {
|
23
|
+
app.use(vant);
|
24
|
+
}
|
25
|
+
if (applicationConfig?.apiFullBaseUrl) {
|
26
|
+
http.defaults.baseURL = applicationConfig?.apiFullBaseUrl;
|
27
|
+
} else {
|
28
|
+
http.defaults.baseURL = applicationConfig?.gatewayServerFullBaseUrl;
|
29
|
+
}
|
30
|
+
(window as any).applicationConfig = Object.freeze(applicationConfig);
|
31
|
+
}
|
32
|
+
|
33
|
+
const getApplicationConfig = () => {
|
34
|
+
return (window as any).applicationConfig || {};
|
35
|
+
}
|
36
|
+
|
37
|
+
export { initApplicationConfig, getApplicationConfig } ;
|
@@ -1,10 +1,12 @@
|
|
1
1
|
import { http } from '../config/httpConfig';
|
2
2
|
import { getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem } from '../utils/storageUtils';
|
3
|
+
import { getApplicationConfig } from "./applicationConfig";
|
3
4
|
|
4
|
-
const getGatewayConfigUrl = '/server/gateway-config/getGatewayConfig';
|
5
5
|
const initGatewayConfig = () => {
|
6
|
+
const applicationConfig = getApplicationConfig();
|
7
|
+
|
6
8
|
return new Promise<void>(async resolve => {
|
7
|
-
let res = await http.get(
|
9
|
+
let res = await http.get(`${applicationConfig.gatewayServerFullBaseUrl}/server/gateway-config/getGatewayConfig`);
|
8
10
|
setLocalStorageItem("gatewayAccessToken", res.data.data.gatewayAccessToken, res.data.data.gatewayTimeout);
|
9
11
|
setLocalStorageItem("gatewayPublicKey", res.data.data.gatewayPublicKey, res.data.data.gatewayTimeout);
|
10
12
|
resolve();
|
@@ -16,7 +18,6 @@ const clearGatewayConfig = () => {
|
|
16
18
|
removeLocalStorageItem("gatewayPublicKey");
|
17
19
|
}
|
18
20
|
export {
|
19
|
-
getGatewayConfigUrl,
|
20
21
|
initGatewayConfig,
|
21
22
|
clearGatewayConfig
|
22
23
|
}
|
package/lib/config/httpConfig.ts
CHANGED
@@ -6,11 +6,13 @@ import type { AxiosResponse } from 'axios';
|
|
6
6
|
import { showErrorMessage } from '../utils/messageUtils';
|
7
7
|
import { alertMessageBox } from '../utils/messageBoxUtils';
|
8
8
|
|
9
|
+
import { getApplicationConfig } from '../config/applicationConfig';
|
9
10
|
import { getSsoLoginUrl, clearSsoAccessToken, setSsoAccessToken } from '../utils/ssoUtils';
|
10
11
|
|
11
|
-
import { clearGatewayConfig, initGatewayConfig
|
12
|
+
import { clearGatewayConfig, initGatewayConfig } from '../config/gatewayConfig';
|
12
13
|
|
13
14
|
import { getLocalStorageItem, setLocalStorageItem } from '../utils/storageUtils'
|
15
|
+
import { removeParameter } from "../utils/urlUtils";
|
14
16
|
|
15
17
|
const router = useRouter();
|
16
18
|
|
@@ -19,10 +21,8 @@ const messageMap = {
|
|
19
21
|
responseSturctError: '响应结构错误',
|
20
22
|
}
|
21
23
|
|
22
|
-
const apiBaseUrl = '/gateway-server';
|
23
|
-
|
24
24
|
const http = axios.create({
|
25
|
-
baseURL: apiBaseUrl,
|
25
|
+
// baseURL: apiBaseUrl,
|
26
26
|
timeout: 10000,
|
27
27
|
headers: {}
|
28
28
|
})
|
@@ -30,8 +30,10 @@ const http = axios.create({
|
|
30
30
|
|
31
31
|
/* 请求拦截 */
|
32
32
|
http.interceptors.request.use(async config => {
|
33
|
+
const applicationConfig = getApplicationConfig();
|
34
|
+
|
33
35
|
let gatewayAccessToken = getLocalStorageItem("gatewayAccessToken") ?? '';
|
34
|
-
if (!gatewayAccessToken && config.url !=
|
36
|
+
if (!gatewayAccessToken && config.url != `${applicationConfig.gatewayServerFullBaseUrl}/server/gateway-config/getGatewayConfig`) {
|
35
37
|
await initGatewayConfig();
|
36
38
|
}
|
37
39
|
beforeRequestConfig(config);
|
@@ -91,12 +93,19 @@ http.interceptors.response.use(async (res: any) => {
|
|
91
93
|
}
|
92
94
|
return axios.request(res.config);
|
93
95
|
} else if (res?.data?.statusCode === 500815006) {
|
96
|
+
// 这里存疑: 返回500815004 的时候获取router为null
|
94
97
|
const fullPath = router.currentRoute.value.fullPath;
|
95
98
|
router.push(`/sso/auth/index?ssoRedirectRoutePath=${encodeURIComponent(fullPath)}`);
|
96
99
|
return;
|
97
100
|
} else if (res?.data?.statusCode === 500815003) {
|
98
101
|
showErrorMessage(res?.data?.message || messageMap.requestError);
|
99
102
|
return Promise.reject(new Error(res?.data?.message));
|
103
|
+
} else if (res?.data?.statusCode === 500815004) {
|
104
|
+
let fullUrl = window.location.href;
|
105
|
+
// 移除参数 ssoAuthCode
|
106
|
+
fullUrl = removeParameter('ssoAuthCode', fullUrl) || '';
|
107
|
+
window.location.href = fullUrl;
|
108
|
+
return;
|
100
109
|
}
|
101
110
|
showErrorMessage(res?.data?.message || messageMap.requestError);
|
102
111
|
return Promise.reject(new Error(res?.data?.message));
|
@@ -154,12 +163,14 @@ const refreshSsoAccessToken = (res: any) => {
|
|
154
163
|
if(!ssoRefreshToken) {
|
155
164
|
return showErrorMessage('参数[ssoRefreshToken]为空');
|
156
165
|
}
|
166
|
+
const applicationConfig = getApplicationConfig();
|
167
|
+
|
157
168
|
return new Promise((resolve, reject) => {
|
158
169
|
const config = res.config
|
159
170
|
config.params = {
|
160
171
|
ssoRefreshToken: ssoRefreshToken,
|
161
172
|
}
|
162
|
-
axios.get(
|
173
|
+
axios.get(`${applicationConfig.gatewayServerFullBaseUrl}/sso-api/client/sso-auth/getSsoRefreshToken`, config).then(res => {
|
163
174
|
if (res?.data?.statusCode !== 200) {
|
164
175
|
return reject();
|
165
176
|
}
|
package/lib/utils/ssoUtils.ts
CHANGED
@@ -1,15 +1,22 @@
|
|
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';
|
4
5
|
import { getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem } from './storageUtils';
|
6
|
+
import { getApplicationConfig } from "../config/applicationConfig";
|
5
7
|
|
6
8
|
|
7
9
|
const getSsoLoginUrl = (ssoRedirectUrl = '') => {
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
const applicationConfig = getApplicationConfig();
|
11
|
+
|
12
|
+
let gatewayServerFullBaseUrl = applicationConfig.gatewayServerFullBaseUrl;
|
13
|
+
if (!gatewayServerFullBaseUrl) {
|
14
|
+
throw new Error('参数[gatewayServerFullBaseUrl]为空');
|
15
|
+
}
|
16
|
+
if (!isFullUrl(gatewayServerFullBaseUrl)) {
|
17
|
+
throw new Error('参数[gatewayServerFullBaseUrl]必须是完整路径');
|
11
18
|
}
|
12
|
-
let ssoLoginUrl = `${
|
19
|
+
let ssoLoginUrl = `${gatewayServerFullBaseUrl}/sso-api/server/sso/login`;
|
13
20
|
if (!ssoRedirectUrl) {
|
14
21
|
ssoLoginUrl += `?ssoRedirectUrl=${encodeURIComponent(window.location.href)}`;
|
15
22
|
} else {
|
@@ -19,11 +26,16 @@ const getSsoLoginUrl = (ssoRedirectUrl = '') => {
|
|
19
26
|
}
|
20
27
|
|
21
28
|
const getSsoLogoutUrl = (ssoRedirectUrl = '') => {
|
22
|
-
|
23
|
-
|
24
|
-
|
29
|
+
const applicationConfig = getApplicationConfig();
|
30
|
+
|
31
|
+
let gatewayServerFullBaseUrl = applicationConfig.gatewayServerFullBaseUrl;
|
32
|
+
if (!gatewayServerFullBaseUrl) {
|
33
|
+
throw new Error('参数[gatewayServerFullBaseUrl]为空');
|
34
|
+
}
|
35
|
+
if (!isFullUrl(gatewayServerFullBaseUrl)) {
|
36
|
+
throw new Error('参数[gatewayServerFullBaseUrl]必须是完整路径');
|
25
37
|
}
|
26
|
-
let ssoLogoutUrl = `${
|
38
|
+
let ssoLogoutUrl = `${gatewayServerFullBaseUrl}/sso-api/server/sso/logout`;
|
27
39
|
if (!ssoRedirectUrl) {
|
28
40
|
ssoLogoutUrl += `?ssoRedirectUrl=${encodeURIComponent(window.location.href)}`;
|
29
41
|
} else if (ssoRedirectUrl) {
|
package/lib/utils/urlUtils.ts
CHANGED
@@ -5,20 +5,20 @@
|
|
5
5
|
* @param url,如果不传递,就使用当前url
|
6
6
|
* @returns {string|null}
|
7
7
|
*/
|
8
|
-
const getParameter = (name: string, url?: string) => {
|
8
|
+
const getParameter = (name: string, url?: string) : string => {
|
9
9
|
url = url || window.location.search;
|
10
10
|
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
|
11
11
|
var r = url.substr(1).match(reg);
|
12
12
|
if (r != null) return decodeURIComponent(r[2]);
|
13
|
-
return
|
13
|
+
return '';
|
14
14
|
}
|
15
15
|
|
16
16
|
/**
|
17
|
-
* 获取url
|
17
|
+
* 获取url的参数map集合
|
18
18
|
* @param url,如果不传递,就使用当前url
|
19
19
|
* @returns {map|null}
|
20
20
|
*/
|
21
|
-
const getParameterMap = (url?: string) => {
|
21
|
+
const getParameterMap = (url?: string): Map<string, string> => {
|
22
22
|
url = url || window.location.search;
|
23
23
|
|
24
24
|
let arrObj = url.split("?") as any;
|
@@ -39,9 +39,10 @@ const getParameterMap = (url?: string) => {
|
|
39
39
|
* @param parameter
|
40
40
|
* @return {string}
|
41
41
|
*/
|
42
|
-
const removeParameter = (name: string, url?: string) => {
|
42
|
+
const removeParameter = (name: string, url?: string): string => {
|
43
43
|
if (!name) {
|
44
|
-
|
44
|
+
console.error('参数[name]为空');
|
45
|
+
return '';
|
45
46
|
}
|
46
47
|
url = url || location.href;
|
47
48
|
let urlObj;
|
@@ -68,7 +69,7 @@ const removeParameter = (name: string, url?: string) => {
|
|
68
69
|
* @param url,如果不传递,就使用当前url
|
69
70
|
* @returns {string}
|
70
71
|
*/
|
71
|
-
const getBaseUrl = (url?: string) => {
|
72
|
+
const getBaseUrl = (url?: string): string => {
|
72
73
|
url = url || location.href;
|
73
74
|
let arr = url.split('/');
|
74
75
|
if (arr.length > 3) {
|
@@ -84,6 +85,21 @@ const getBaseUrl = (url?: string) => {
|
|
84
85
|
} else {
|
85
86
|
console.error('地址存在问题');
|
86
87
|
}
|
88
|
+
return '';
|
87
89
|
};
|
88
90
|
|
89
|
-
|
91
|
+
/**
|
92
|
+
* 是否完整url
|
93
|
+
* @param url
|
94
|
+
*/
|
95
|
+
const isFullUrl = (url?: string): boolean => {
|
96
|
+
if(!url){
|
97
|
+
return false;
|
98
|
+
}
|
99
|
+
if(url.startsWith('http://') || url.startsWith('https://')){
|
100
|
+
return true;
|
101
|
+
}
|
102
|
+
return false;
|
103
|
+
};
|
104
|
+
|
105
|
+
export { getParameter, getParameterMap, removeParameter, getBaseUrl, isFullUrl };
|
package/package.json
CHANGED
package/src/main.ts
CHANGED
@@ -4,18 +4,18 @@ import { createPinia } from 'pinia'
|
|
4
4
|
|
5
5
|
import App from './App.vue'
|
6
6
|
import router from './router'
|
7
|
-
import {
|
7
|
+
import {initApplicationConfig} from '../lib/config/applicationConfig';
|
8
8
|
|
9
9
|
const app = createApp(App)
|
10
|
-
|
10
|
+
debugger
|
11
11
|
app.use(createPinia())
|
12
12
|
app.use(router)
|
13
13
|
|
14
|
-
const
|
15
|
-
|
14
|
+
const applicationConfig = {
|
15
|
+
gatewayServerFullBaseUrl: import.meta.env.VITE_GATEWAY_SERVER_FULL_BASE_URL,
|
16
16
|
apiFullBaseUrl: import.meta.env.VITE_API_FULL_BASE_URL
|
17
17
|
};
|
18
|
-
|
18
|
+
initApplicationConfig(app, applicationConfig);
|
19
19
|
|
20
20
|
app.mount('#app')
|
21
21
|
|
@@ -13,26 +13,27 @@
|
|
13
13
|
|
14
14
|
import { getSsoAccessToken, logoutSso } from '../../../../lib/utils/ssoUtils';
|
15
15
|
import { http } from '../../../../lib/config/httpConfig';
|
16
|
+
import { getApplicationConfig } from "../../../../lib/config/applicationConfig";
|
17
|
+
const applicationConfig = getApplicationConfig();
|
16
18
|
|
17
19
|
let ssoData = reactive({
|
18
20
|
ssoTokenUser: {},
|
19
21
|
ssoIdentity: {}
|
20
22
|
});
|
21
|
-
|
22
23
|
onMounted(() => {
|
23
24
|
let ssoAccessToken = getSsoAccessToken();
|
24
25
|
console.log('ssoAccessToken', ssoAccessToken);
|
25
26
|
getSsoTokenUser();
|
26
27
|
});
|
27
28
|
const getSsoTokenUser = () => {
|
28
|
-
http.get(
|
29
|
+
http.get(`${applicationConfig.gatewayServerFullBaseUrl}/sso-api/client/sso-user/getSsoTokenUser`).then((res: any) => {
|
29
30
|
ssoData.ssoTokenUser = res.data.data;
|
30
31
|
console.log('ssoTokenUser', ssoData.ssoTokenUser);
|
31
32
|
ElMessage.success('获取成功');
|
32
33
|
});
|
33
34
|
};
|
34
35
|
const getSsoIdentity = () => {
|
35
|
-
http.get(
|
36
|
+
http.get(`${applicationConfig.gatewayServerFullBaseUrl}/sso-api/client/sso-user/getSsoIdentity`, { params: { ssoClientAccount: 'yuang-sso' } }).then((res: any) => {
|
36
37
|
ssoData.ssoIdentity = res.data.data;
|
37
38
|
console.log('ssoIdentity', ssoData.ssoIdentity);
|
38
39
|
ElMessage.success('获取成功');
|
@@ -6,13 +6,16 @@
|
|
6
6
|
import { getCurrentInstance, onMounted } from 'vue';
|
7
7
|
import { useRouter } from 'vue-router';
|
8
8
|
|
9
|
+
import { getApplicationConfig } from '../../../../lib/config/applicationConfig';
|
9
10
|
import { getSsoLoginUrl, setSsoAccessToken } from '../../../../lib/utils/ssoUtils';
|
10
11
|
import { removeParameter } from '../../../../lib/utils/urlUtils';
|
12
|
+
import { http } from '../../../../lib/config/httpConfig';
|
11
13
|
|
12
14
|
const router = useRouter();
|
13
15
|
|
14
16
|
const { proxy } = getCurrentInstance() as any;
|
15
17
|
|
18
|
+
const applicationConfig = getApplicationConfig();
|
16
19
|
onMounted(() => {
|
17
20
|
const ssoAuthCode = router.currentRoute.value.query.ssoAuthCode;
|
18
21
|
if (!ssoAuthCode) {
|
@@ -21,7 +24,7 @@
|
|
21
24
|
return;
|
22
25
|
}
|
23
26
|
|
24
|
-
|
27
|
+
http.get(`${applicationConfig.gatewayServerFullBaseUrl}/sso-api/client/sso-auth/getSsoAccessToken`, { params: { ssoAuthCode: ssoAuthCode } }).then((res: any) => {
|
25
28
|
setSsoAccessToken(res.data.data);
|
26
29
|
let ssoRedirectRoutePath = router.currentRoute.value.query.ssoRedirectRoutePath as string;
|
27
30
|
ssoRedirectRoutePath = (ssoRedirectRoutePath && decodeURIComponent(ssoRedirectRoutePath)) || ('/sso/auth/auth-success' as any);
|
package/lib/config/initConfig.ts
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
import {isPc} from '../utils/deviceUtils';
|
2
|
-
|
3
|
-
|
4
|
-
import ElementPlus from 'element-plus'
|
5
|
-
import 'element-plus/dist/index.css'
|
6
|
-
import {ElMessage} from 'element-plus'
|
7
|
-
|
8
|
-
import vant from 'vant';
|
9
|
-
import 'vant/lib/index.css';
|
10
|
-
|
11
|
-
|
12
|
-
import {http} from './httpConfig';
|
13
|
-
// import moment from 'moment';
|
14
|
-
|
15
|
-
const initConfig = (app: any, config: any) => {
|
16
|
-
// app.config.globalProperties.$http = http;
|
17
|
-
// app.config.globalProperties.$moment = moment;
|
18
|
-
|
19
|
-
if (isPc()) {
|
20
|
-
app.config.globalProperties.$message = ElMessage;
|
21
|
-
app.use(ElementPlus);
|
22
|
-
} else {
|
23
|
-
app.use(vant);
|
24
|
-
}
|
25
|
-
if(config?.apiBaseUrl) {
|
26
|
-
http.defaults.baseURL = config?.apiBaseUrl;
|
27
|
-
}
|
28
|
-
(window as any).$config = Object.freeze(config);
|
29
|
-
}
|
30
|
-
|
31
|
-
export {initConfig} ;
|