yuang-framework-ui-common 1.0.99 → 1.0.101
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/hooks/framework/frameworkEnum.ts +50 -0
- package/lib/hooks/sso/ssoUser.ts +50 -0
- package/lib/hooks/uims/uimsUser.ts +50 -1
- package/lib/utils/aesUtils.ts +6 -6
- package/lib/utils/rsaAesUtils.ts +37 -0
- package/lib/utils/ssoUtils.ts +1 -0
- package/package.json +1 -1
- package/src/views/utils/rsa-aes-utils.vue +29 -0
- package/src/views/utils/sso-utils.vue +2 -5
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// 首先建议创建类型定义文件(如 types/api.d.ts),或直接在当前文件定义类型
|
|
2
|
+
// 定义接口:枚举列表项的类型
|
|
3
|
+
export interface StatusEnumItem {
|
|
4
|
+
// 根据实际返回的字段补充类型,比如:
|
|
5
|
+
value: string;
|
|
6
|
+
name: string;
|
|
7
|
+
// 兼容对象中未显式定义的任意字段,避免 TS 报错
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
import { ref } from 'vue';
|
|
12
|
+
import { http } from '../../../lib/config/httpConfig';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 提供“获取状态枚举列表”的能力
|
|
16
|
+
*
|
|
17
|
+
* Vue3 官方明确规定,组合式函数必须以 use 开头(参考:Vue3 组合式函数文档),目的是让开发者一眼识别:“这是一个可复用的组合式逻辑,返回响应式能力”
|
|
18
|
+
*/
|
|
19
|
+
export const useStatusEnumList = () => {
|
|
20
|
+
// 定义响应式数据,指定类型
|
|
21
|
+
const statusEnumList = ref<StatusEnumItem[]>([]);
|
|
22
|
+
// 定义加载状态(可选,增强体验)
|
|
23
|
+
const isLoadingEnum = ref<boolean>(false);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 获取状态枚举列表的核心方法
|
|
27
|
+
*/
|
|
28
|
+
const getStatusEnumList = async (): Promise<void> => {
|
|
29
|
+
try {
|
|
30
|
+
isLoadingEnum.value = true;
|
|
31
|
+
// 指定响应数据类型,TS会自动校验
|
|
32
|
+
const res = await http.get('/framework-api/union/framework-data/getStatusEnumList', {});
|
|
33
|
+
statusEnumList.value = res.data.data;
|
|
34
|
+
} catch (ex) {
|
|
35
|
+
console.error('获取状态枚举列表失败:', ex);
|
|
36
|
+
statusEnumList.value = [];
|
|
37
|
+
} finally {
|
|
38
|
+
isLoadingEnum.value = false;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// 初始化调用(可选,也可由外部调用)
|
|
43
|
+
getStatusEnumList();
|
|
44
|
+
|
|
45
|
+
// 返回响应式数据和方法,供组件使用
|
|
46
|
+
return {
|
|
47
|
+
statusEnumList,
|
|
48
|
+
isLoadingEnum
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
// 首先建议创建类型定义文件(如 types/api.d.ts),或直接在当前文件定义类型
|
|
2
|
+
// 定义接口:枚举列表项的类型
|
|
3
|
+
export interface StatusEnumItem {
|
|
4
|
+
// 根据实际返回的字段补充类型,比如:
|
|
5
|
+
value: string;
|
|
6
|
+
name: string;
|
|
7
|
+
// 兼容对象中未显式定义的任意字段,避免 TS 报错
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
import { ref } from 'vue';
|
|
12
|
+
import { http } from '../../../lib/config/httpConfig';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 提供“获取状态枚举列表”的能力
|
|
16
|
+
*
|
|
17
|
+
* Vue3 官方明确规定,组合式函数必须以 use 开头(参考:Vue3 组合式函数文档),目的是让开发者一眼识别:“这是一个可复用的组合式逻辑,返回响应式能力”
|
|
18
|
+
*/
|
|
19
|
+
export const useStatusEnumList = () => {
|
|
20
|
+
// 定义响应式数据,指定类型
|
|
21
|
+
const statusEnumList = ref<StatusEnumItem[]>([]);
|
|
22
|
+
// 定义加载状态(可选,增强体验)
|
|
23
|
+
const isLoadingEnum = ref<boolean>(false);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 获取状态枚举列表的核心方法
|
|
27
|
+
*/
|
|
28
|
+
const getStatusEnumList = async (): Promise<void> => {
|
|
29
|
+
try {
|
|
30
|
+
isLoadingEnum.value = true;
|
|
31
|
+
// 指定响应数据类型,TS会自动校验
|
|
32
|
+
const res = await http.get('/framework-api/union/sso-user/getStatusEnumList', {});
|
|
33
|
+
statusEnumList.value = res.data.data;
|
|
34
|
+
} catch (ex) {
|
|
35
|
+
console.error('获取状态枚举列表失败:', ex);
|
|
36
|
+
statusEnumList.value = [];
|
|
37
|
+
} finally {
|
|
38
|
+
isLoadingEnum.value = false;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// 初始化调用(可选,也可由外部调用)
|
|
43
|
+
getStatusEnumList();
|
|
44
|
+
|
|
45
|
+
// 返回响应式数据和方法,供组件使用
|
|
46
|
+
return {
|
|
47
|
+
statusEnumList,
|
|
48
|
+
isLoadingEnum
|
|
49
|
+
};
|
|
50
|
+
};
|
|
@@ -1 +1,50 @@
|
|
|
1
|
-
|
|
1
|
+
// 首先建议创建类型定义文件(如 types/api.d.ts),或直接在当前文件定义类型
|
|
2
|
+
// 定义接口:枚举列表项的类型
|
|
3
|
+
export interface StatusEnumItem {
|
|
4
|
+
// 根据实际返回的字段补充类型,比如:
|
|
5
|
+
value: string;
|
|
6
|
+
name: string;
|
|
7
|
+
// 兼容对象中未显式定义的任意字段,避免 TS 报错
|
|
8
|
+
[key: string]: any;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
import { ref } from 'vue';
|
|
12
|
+
import { http } from '../../../lib/config/httpConfig';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 提供“获取状态枚举列表”的能力
|
|
16
|
+
*
|
|
17
|
+
* Vue3 官方明确规定,组合式函数必须以 use 开头(参考:Vue3 组合式函数文档),目的是让开发者一眼识别:“这是一个可复用的组合式逻辑,返回响应式能力”
|
|
18
|
+
*/
|
|
19
|
+
export const useStatusEnumList = () => {
|
|
20
|
+
// 定义响应式数据,指定类型
|
|
21
|
+
const statusEnumList = ref<StatusEnumItem[]>([]);
|
|
22
|
+
// 定义加载状态(可选,增强体验)
|
|
23
|
+
const isLoadingEnum = ref<boolean>(false);
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 获取状态枚举列表的核心方法
|
|
27
|
+
*/
|
|
28
|
+
const getStatusEnumList = async (): Promise<void> => {
|
|
29
|
+
try {
|
|
30
|
+
isLoadingEnum.value = true;
|
|
31
|
+
// 指定响应数据类型,TS会自动校验
|
|
32
|
+
const res = await http.get('/framework-api/union/uims-user/getStatusEnumList', {});
|
|
33
|
+
statusEnumList.value = res.data.data;
|
|
34
|
+
} catch (ex) {
|
|
35
|
+
console.error('获取状态枚举列表失败:', ex);
|
|
36
|
+
statusEnumList.value = [];
|
|
37
|
+
} finally {
|
|
38
|
+
isLoadingEnum.value = false;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
// 初始化调用(可选,也可由外部调用)
|
|
43
|
+
getStatusEnumList();
|
|
44
|
+
|
|
45
|
+
// 返回响应式数据和方法,供组件使用
|
|
46
|
+
return {
|
|
47
|
+
statusEnumList,
|
|
48
|
+
isLoadingEnum
|
|
49
|
+
};
|
|
50
|
+
};
|
package/lib/utils/aesUtils.ts
CHANGED
|
@@ -27,8 +27,8 @@ const getAesStaticKey = () => {
|
|
|
27
27
|
|
|
28
28
|
/**
|
|
29
29
|
* aes加密
|
|
30
|
-
* @param aesKey
|
|
31
|
-
* @param originalData
|
|
30
|
+
* @param aesKey aes秘钥
|
|
31
|
+
* @param originalData 原始数据
|
|
32
32
|
*/
|
|
33
33
|
const aesEncrypt = (aesKey:string, originalData: string) => {
|
|
34
34
|
// 设置一个默认值,如果第二个参数为空采用默认值,不为空则采用新设置的密钥
|
|
@@ -45,12 +45,12 @@ const aesEncrypt = (aesKey:string, originalData: string) => {
|
|
|
45
45
|
|
|
46
46
|
/**
|
|
47
47
|
* aes解密
|
|
48
|
-
* @param aesKey
|
|
49
|
-
* @param
|
|
48
|
+
* @param aesKey aes秘钥
|
|
49
|
+
* @param encryptData 加密的数据
|
|
50
50
|
*/
|
|
51
|
-
const aesDecrypt = (aesKey:string,
|
|
51
|
+
const aesDecrypt = (aesKey:string, encryptData:string) => {
|
|
52
52
|
var key = CryptoJS.enc.Utf8.parse(aesKey)
|
|
53
|
-
var decrypt = CryptoJS.AES.decrypt(
|
|
53
|
+
var decrypt = CryptoJS.AES.decrypt(encryptData, key, {
|
|
54
54
|
// 切记 需要和后端算法模式一致
|
|
55
55
|
mode: CryptoJS.mode.ECB,
|
|
56
56
|
padding: CryptoJS.pad.Pkcs7
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { getLocalStorageItem } from "./storageUtils";
|
|
2
|
+
import { aesEncrypt, aesDecrypt, getAesRandomKey } from "./aesUtils";
|
|
3
|
+
import { rsaEncrypt, rsaDecrypt } from "./rsaUtils";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* rsaAes加密
|
|
7
|
+
* @param rsaPublicKey rsa公钥
|
|
8
|
+
* @param aesKey aes秘钥
|
|
9
|
+
* @param oiginData 原始数据
|
|
10
|
+
*/
|
|
11
|
+
const rsaAesEncrypt = (rsaPublicKey, aesKey, oiginData) => {
|
|
12
|
+
// 用登陆后后端生成并返回给前端的的RSA密钥对的公钥将AES16位密钥进行加密
|
|
13
|
+
const rsaAesKey = rsaEncrypt(gatewayPublicKey, aesKey);
|
|
14
|
+
// 使用AES16位的密钥将请求报文加密(使用的是加密前的aes密钥)
|
|
15
|
+
const aesEncryptData = aesEncrypt(aesKey, oiginData);
|
|
16
|
+
|
|
17
|
+
return { rsaAesKey, aesEncryptData };
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* rsaAes解密
|
|
22
|
+
* @param rsaPrivateKey rsa私钥
|
|
23
|
+
* @param rsaAesKey rsa私钥
|
|
24
|
+
* @param encryptData 加密的数据
|
|
25
|
+
*/
|
|
26
|
+
const rsaAesDecrypt = (rsaPrivateKey, rsaAesKey, encryptData) => {
|
|
27
|
+
let aesKey = rsaDecrypt(rsaPrivateKey, rsaAesKey);
|
|
28
|
+
|
|
29
|
+
let decryptData = aesDecrypt(aesKey, encryptData);
|
|
30
|
+
|
|
31
|
+
return decryptData;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export {
|
|
35
|
+
rsaAesEncrypt,
|
|
36
|
+
rsaAesDecrypt,
|
|
37
|
+
}
|
package/lib/utils/ssoUtils.ts
CHANGED
package/package.json
CHANGED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div>encryptData:{{ encryptData }}</div>
|
|
3
|
+
<div>decryptData:{{ decryptData }}</div>
|
|
4
|
+
</template>
|
|
5
|
+
|
|
6
|
+
<script setup lang="ts">
|
|
7
|
+
import {onMounted, ref} from 'vue';
|
|
8
|
+
import { rsaAesDecrypt, rsaAesEncrypt } from '../../../lib/utils/rsaAesUtils';
|
|
9
|
+
import { getLocalStorageItem } from "../../../lib/utils/storageUtils";
|
|
10
|
+
import { getAesRandomKey } from "../../../lib/utils/aesUtils";
|
|
11
|
+
|
|
12
|
+
let encryptData = ref({});
|
|
13
|
+
let decryptData = ref('');
|
|
14
|
+
|
|
15
|
+
onMounted(async () => {
|
|
16
|
+
let gatewayPublicKey = getLocalStorageItem('gatewayPublicKey');
|
|
17
|
+
let aesKey = getAesRandomKey();
|
|
18
|
+
encryptData.value = rsaAesEncrypt(gatewayPublicKey, aesKey, '测试');
|
|
19
|
+
|
|
20
|
+
let rsaPrivateKey = '';
|
|
21
|
+
decryptData = rsaAesDecrypt(rsaPrivateKey, encryptData.value.rsaAesKey, encryptData.value.encryptData);
|
|
22
|
+
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
</script>
|
|
26
|
+
|
|
27
|
+
<style scoped>
|
|
28
|
+
|
|
29
|
+
</style>
|
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div>
|
|
2
|
+
<div> </div>
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
5
|
<script setup lang="ts">
|
|
6
6
|
import {onMounted, ref} from 'vue';
|
|
7
|
-
import {getSsoEncrypt} from '../../../lib/utils/ssoUtils';
|
|
8
7
|
|
|
9
8
|
|
|
10
|
-
let ssoEncrypt = ref('');
|
|
11
9
|
|
|
12
10
|
onMounted(async () => {
|
|
13
|
-
|
|
14
|
-
})
|
|
11
|
+
})
|
|
15
12
|
|
|
16
13
|
</script>
|
|
17
14
|
|