yuang-framework-ui-common 1.0.55 → 1.0.56
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 +14 -9
- package/lib/config/gatewayConfig.ts +6 -8
- package/lib/config/httpConfig.ts +11 -13
- package/lib/utils/aesUtils.ts +2 -2
- package/lib/utils/ssoUtils.ts +3 -7
- package/package.json +1 -1
- package/src/main.ts +3 -3
- package/src/views/sso/auth/auth-success.vue +3 -4
- package/src/views/sso/auth/index.vue +2 -3
- package/src/views/utils/gateway-utils.vue +1 -1
@@ -12,7 +12,12 @@ import 'vant/lib/index.css';
|
|
12
12
|
import { http } from './httpConfig';
|
13
13
|
// import moment from 'moment';
|
14
14
|
|
15
|
-
const
|
15
|
+
const application = {
|
16
|
+
gatewayServerBaseUrl: '',
|
17
|
+
apiBaseUrl: ''
|
18
|
+
};
|
19
|
+
|
20
|
+
const initApplication = (app: any, config: any) => {
|
16
21
|
// app.config.globalProperties.$http = http;
|
17
22
|
// app.config.globalProperties.$moment = moment;
|
18
23
|
|
@@ -22,16 +27,16 @@ const initApplicationConfig = (app: any, applicationConfig: any) => {
|
|
22
27
|
} else {
|
23
28
|
app.use(vant);
|
24
29
|
}
|
25
|
-
if (
|
26
|
-
http.defaults.baseURL =
|
30
|
+
if (config?.apiBaseUrl) {
|
31
|
+
http.defaults.baseURL = config?.apiBaseUrl;
|
27
32
|
} else {
|
28
|
-
http.defaults.baseURL =
|
33
|
+
http.defaults.baseURL = config?.gatewayServerBaseUrl;
|
29
34
|
}
|
30
|
-
|
31
|
-
|
35
|
+
application.gatewayServerBaseUrl = Object.freeze(config.gatewayServerBaseUrl);
|
36
|
+
application.apiBaseUrl = Object.freeze(config.apiBaseUrl);
|
32
37
|
|
33
|
-
|
34
|
-
|
38
|
+
// 小程序没有window,暂时这样
|
39
|
+
(window as any).application = Object.freeze(application);
|
35
40
|
}
|
36
41
|
|
37
|
-
export {
|
42
|
+
export { application, initApplication } ;
|
@@ -1,23 +1,21 @@
|
|
1
1
|
import { http } from '../config/httpConfig';
|
2
2
|
import { getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem } from '../utils/storageUtils';
|
3
|
-
import {
|
4
|
-
|
5
|
-
const initGatewayConfig = () => {
|
6
|
-
const applicationConfig = getApplicationConfig();
|
3
|
+
import { application } from "./applicationConfig";
|
7
4
|
|
5
|
+
const initGateway = () => {
|
8
6
|
return new Promise<void>(async resolve => {
|
9
|
-
let res = await http.get(`${
|
7
|
+
let res = await http.get(`${application.gatewayServerBaseUrl}/server/gateway-config/getGatewayConfig`);
|
10
8
|
setLocalStorageItem("gatewayAccessToken", res.data.data.gatewayAccessToken, res.data.data.gatewayTimeout);
|
11
9
|
setLocalStorageItem("gatewayPublicKey", res.data.data.gatewayPublicKey, res.data.data.gatewayTimeout);
|
12
10
|
resolve();
|
13
11
|
})
|
14
12
|
}
|
15
13
|
|
16
|
-
const
|
14
|
+
const clearGateway = () => {
|
17
15
|
removeLocalStorageItem("gatewayAccessToken");
|
18
16
|
removeLocalStorageItem("gatewayPublicKey");
|
19
17
|
}
|
20
18
|
export {
|
21
|
-
|
22
|
-
|
19
|
+
initGateway,
|
20
|
+
clearGateway
|
23
21
|
}
|
package/lib/config/httpConfig.ts
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
+
/**
|
2
|
+
* http配置
|
3
|
+
*/
|
4
|
+
|
1
5
|
import axios from "axios"
|
2
6
|
import { useRouter } from 'vue-router';
|
3
7
|
|
4
|
-
import type { AxiosResponse } from 'axios';
|
5
|
-
|
6
8
|
import { showErrorMessage } from '../utils/messageUtils';
|
7
9
|
import { alertMessageBox } from '../utils/messageBoxUtils';
|
8
10
|
|
9
|
-
import {
|
11
|
+
import { application } from '../config/applicationConfig';
|
10
12
|
import { getSsoLoginUrl, clearSsoAccessToken, setSsoAccessToken } from '../utils/ssoUtils';
|
11
13
|
|
12
|
-
import {
|
14
|
+
import { clearGateway, initGateway } from '../config/gatewayConfig';
|
13
15
|
|
14
16
|
import { getLocalStorageItem, setLocalStorageItem } from '../utils/storageUtils'
|
15
17
|
import { removeParameter } from "../utils/urlUtils";
|
@@ -30,11 +32,9 @@ const http = axios.create({
|
|
30
32
|
|
31
33
|
/* 请求拦截 */
|
32
34
|
http.interceptors.request.use(async config => {
|
33
|
-
const applicationConfig = getApplicationConfig();
|
34
|
-
|
35
35
|
let gatewayAccessToken = getLocalStorageItem("gatewayAccessToken") ?? '';
|
36
|
-
if (!gatewayAccessToken && config.url != `${
|
37
|
-
await
|
36
|
+
if (!gatewayAccessToken && config.url != `${application.gatewayServerBaseUrl}/server/gateway-config/getGatewayConfig`) {
|
37
|
+
await initGateway();
|
38
38
|
}
|
39
39
|
beforeRequestConfig(config);
|
40
40
|
return config;
|
@@ -67,8 +67,8 @@ http.interceptors.response.use(async (res: any) => {
|
|
67
67
|
});
|
68
68
|
return Promise.reject(new Error(res?.data?.message));
|
69
69
|
} else if (res?.data?.statusCode === 500822001) {
|
70
|
-
|
71
|
-
await
|
70
|
+
clearGateway();
|
71
|
+
await initGateway();
|
72
72
|
// 重发请求
|
73
73
|
let gatewayAccessToken = getLocalStorageItem("gatewayAccessToken") ?? '';
|
74
74
|
let gatewayPublicKey = getLocalStorageItem("gatewayPublicKey") ?? '';
|
@@ -163,14 +163,12 @@ const refreshSsoAccessToken = (res: any) => {
|
|
163
163
|
if(!ssoRefreshToken) {
|
164
164
|
return showErrorMessage('参数[ssoRefreshToken]为空');
|
165
165
|
}
|
166
|
-
const applicationConfig = getApplicationConfig();
|
167
|
-
|
168
166
|
return new Promise((resolve, reject) => {
|
169
167
|
const config = res.config
|
170
168
|
config.params = {
|
171
169
|
ssoRefreshToken: ssoRefreshToken,
|
172
170
|
}
|
173
|
-
axios.get(`${
|
171
|
+
axios.get(`${application.gatewayServerBaseUrl}/sso-api/client/sso-auth/getSsoRefreshToken`, config).then(res => {
|
174
172
|
if (res?.data?.statusCode !== 200) {
|
175
173
|
return reject();
|
176
174
|
}
|
package/lib/utils/aesUtils.ts
CHANGED
@@ -22,7 +22,7 @@ const getAesRandomKey = () => {
|
|
22
22
|
* @param aesKey
|
23
23
|
* @param originalData
|
24
24
|
*/
|
25
|
-
const aesEncrypt = (aesKey, originalData) => {
|
25
|
+
const aesEncrypt = (aesKey:string, originalData: string) => {
|
26
26
|
// 设置一个默认值,如果第二个参数为空采用默认值,不为空则采用新设置的密钥
|
27
27
|
var key = CryptoJS.enc.Utf8.parse(aesKey)
|
28
28
|
var srcs = CryptoJS.enc.Utf8.parse(originalData)
|
@@ -40,7 +40,7 @@ const aesEncrypt = (aesKey, originalData) => {
|
|
40
40
|
* @param aesKey
|
41
41
|
* @param originalData
|
42
42
|
*/
|
43
|
-
const aesDecrypt = (aesKey, originalData) => {
|
43
|
+
const aesDecrypt = (aesKey:string, originalData:string) => {
|
44
44
|
var key = CryptoJS.enc.Utf8.parse(aesKey)
|
45
45
|
var decrypt = CryptoJS.AES.decrypt(originalData, key, {
|
46
46
|
// 切记 需要和后端算法模式一致
|
package/lib/utils/ssoUtils.ts
CHANGED
@@ -3,13 +3,11 @@ import { getAesRandomKey, aesEncrypt } from './aesUtils';
|
|
3
3
|
import { rsaEncrypt } from './rsaUtils';
|
4
4
|
import { isFullUrl } from './urlUtils';
|
5
5
|
import { getLocalStorageItem, setLocalStorageItem, removeLocalStorageItem } from './storageUtils';
|
6
|
-
import {
|
6
|
+
import { application } from '../config/applicationConfig';
|
7
7
|
|
8
8
|
|
9
9
|
const getSsoLoginUrl = (ssoRedirectUrl = '') => {
|
10
|
-
|
11
|
-
|
12
|
-
let gatewayServerBaseUrl = applicationConfig.gatewayServerBaseUrl;
|
10
|
+
let gatewayServerBaseUrl = application.gatewayServerBaseUrl;
|
13
11
|
if (!gatewayServerBaseUrl) {
|
14
12
|
throw new Error('参数[gatewayServerBaseUrl]为空');
|
15
13
|
}
|
@@ -26,9 +24,7 @@ const getSsoLoginUrl = (ssoRedirectUrl = '') => {
|
|
26
24
|
}
|
27
25
|
|
28
26
|
const getSsoLogoutUrl = (ssoRedirectUrl = '') => {
|
29
|
-
|
30
|
-
|
31
|
-
let gatewayServerBaseUrl = applicationConfig.gatewayServerBaseUrl;
|
27
|
+
let gatewayServerBaseUrl = application.gatewayServerBaseUrl;
|
32
28
|
if (!gatewayServerBaseUrl) {
|
33
29
|
throw new Error('参数[gatewayServerBaseUrl]为空');
|
34
30
|
}
|
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 {initApplication} 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
|
14
|
+
const config = {
|
15
15
|
gatewayServerBaseUrl: import.meta.env.VITE_GATEWAY_SERVER_BASE_URL,
|
16
16
|
apiBaseUrl: import.meta.env.VITE_API_BASE_URL
|
17
17
|
};
|
18
|
-
|
18
|
+
initApplication(app, config);
|
19
19
|
|
20
20
|
app.mount('#app')
|
21
21
|
|
@@ -13,8 +13,7 @@
|
|
13
13
|
|
14
14
|
import { getSsoAccessToken, logoutSso } from '../../../../lib/utils/ssoUtils';
|
15
15
|
import { http } from '../../../../lib/config/httpConfig';
|
16
|
-
import {
|
17
|
-
const applicationConfig = getApplicationConfig();
|
16
|
+
import { application } from "../../../../lib/config/applicationConfig";
|
18
17
|
|
19
18
|
let ssoData = reactive({
|
20
19
|
ssoTokenUser: {},
|
@@ -26,14 +25,14 @@
|
|
26
25
|
getSsoTokenUser();
|
27
26
|
});
|
28
27
|
const getSsoTokenUser = () => {
|
29
|
-
http.get(`${
|
28
|
+
http.get(`${application.gatewayServerBaseUrl}/sso-api/client/sso-user/getSsoTokenUser`).then((res: any) => {
|
30
29
|
ssoData.ssoTokenUser = res.data.data;
|
31
30
|
console.log('ssoTokenUser', ssoData.ssoTokenUser);
|
32
31
|
ElMessage.success('获取成功');
|
33
32
|
});
|
34
33
|
};
|
35
34
|
const getSsoIdentity = () => {
|
36
|
-
http.get(`${
|
35
|
+
http.get(`${application.gatewayServerBaseUrl}/sso-api/client/sso-user/getSsoIdentity`, { params: { ssoClientAccount: 'yuang-sso' } }).then((res: any) => {
|
37
36
|
ssoData.ssoIdentity = res.data.data;
|
38
37
|
console.log('ssoIdentity', ssoData.ssoIdentity);
|
39
38
|
ElMessage.success('获取成功');
|
@@ -6,7 +6,7 @@
|
|
6
6
|
import { getCurrentInstance, onMounted } from 'vue';
|
7
7
|
import { useRouter } from 'vue-router';
|
8
8
|
|
9
|
-
import {
|
9
|
+
import { application } from '../../../../lib/config/applicationConfig';
|
10
10
|
import { getSsoLoginUrl, setSsoAccessToken } from '../../../../lib/utils/ssoUtils';
|
11
11
|
import { removeParameter } from '../../../../lib/utils/urlUtils';
|
12
12
|
import { http } from '../../../../lib/config/httpConfig';
|
@@ -15,7 +15,6 @@
|
|
15
15
|
|
16
16
|
const { proxy } = getCurrentInstance() as any;
|
17
17
|
|
18
|
-
const applicationConfig = getApplicationConfig();
|
19
18
|
onMounted(() => {
|
20
19
|
const ssoAuthCode = router.currentRoute.value.query.ssoAuthCode;
|
21
20
|
if (!ssoAuthCode) {
|
@@ -24,7 +23,7 @@
|
|
24
23
|
return;
|
25
24
|
}
|
26
25
|
|
27
|
-
http.get(`${
|
26
|
+
http.get(`${application.gatewayServerBaseUrl}/sso-api/client/sso-auth/getSsoAccessToken`, { params: { ssoAuthCode: ssoAuthCode } }).then((res: any) => {
|
28
27
|
setSsoAccessToken(res.data.data);
|
29
28
|
let ssoRedirectRoutePath = router.currentRoute.value.query.ssoRedirectRoutePath as string;
|
30
29
|
ssoRedirectRoutePath = (ssoRedirectRoutePath && decodeURIComponent(ssoRedirectRoutePath)) || ('/sso/auth/auth-success' as any);
|
@@ -10,7 +10,7 @@ import { ElMessage } from 'element-plus/es';
|
|
10
10
|
|
11
11
|
const sendRequest = () => {
|
12
12
|
// 测试
|
13
|
-
http.get("/
|
13
|
+
http.get("/framework-api/standard/framework-captcha/getSliderCaptcha", { params: {} }).then((res) => {
|
14
14
|
ElMessage.success('发送成功');
|
15
15
|
});
|
16
16
|
}
|