yuang-framework-ui-common 1.0.101 → 1.0.103
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/dateUtils.ts +131 -63
- package/lib/utils/rsaAesUtils.ts +31 -7
- package/lib/utils/rsaUtils.ts +24 -6
- package/lib/utils/ssoUtils.ts +1 -38
- package/package.json +2 -2
- package/src/router/index.ts +4 -0
- package/src/views/utils/rsa-aes-utils.vue +8 -5
package/lib/utils/dateUtils.ts
CHANGED
|
@@ -1,29 +1,67 @@
|
|
|
1
1
|
import { setNumAddZero } from './dataUtils';
|
|
2
|
+
import dayjs, { type Dayjs, type ConfigType } from 'dayjs';
|
|
3
|
+
// 引入必要插件(按需加载,减小体积)
|
|
4
|
+
import 'dayjs/locale/zh-cn'; // 中文语言包
|
|
5
|
+
import relativeTime from 'dayjs/plugin/relativeTime'; // 相对时间插件(formatFromNow 用)
|
|
6
|
+
import isSameOrAfter from 'dayjs/plugin/isSameOrAfter'; // 辅助比较插件
|
|
7
|
+
import isSameOrBefore from 'dayjs/plugin/isSameOrBefore';
|
|
2
8
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
9
|
+
// 注册插件
|
|
10
|
+
dayjs.extend(relativeTime);
|
|
11
|
+
dayjs.extend(isSameOrAfter);
|
|
12
|
+
dayjs.extend(isSameOrBefore);
|
|
13
|
+
|
|
14
|
+
// 设置全局语言为中文
|
|
15
|
+
dayjs.locale('zh-cn');
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
// ===================== 常用日期格式常量(统一维护)=====================
|
|
21
|
+
/** 完整时间格式(默认):年-月-日 时:分:秒 */
|
|
22
|
+
export const FORMAT_YYYY_MM_DD_HH_MM_SS = 'YYYY-MM-DD HH:mm:ss';
|
|
23
|
+
/** 简化时间格式:年-月-日 时:分 */
|
|
24
|
+
export const FORMAT_YYYY_MM_DD_HH_MM = 'YYYY-MM-DD HH:mm';
|
|
25
|
+
/** 仅日期格式:年-月-日 */
|
|
26
|
+
export const FORMAT_YYYY_MM_DD = 'YYYY-MM-DD';
|
|
27
|
+
/** 年月格式:年-月 */
|
|
28
|
+
export const FORMAT_YYYY_MM = 'YYYY-MM';
|
|
29
|
+
/** 月日格式:月-日 */
|
|
30
|
+
export const FORMAT_MM_DD = 'MM-DD';
|
|
31
|
+
/** 仅时间格式:时:分:秒 */
|
|
32
|
+
export const FORMAT_HH_MM_SS = 'HH:mm:ss';
|
|
33
|
+
/** 仅时间简化格式:时:分 */
|
|
34
|
+
export const FORMAT_HH_MM = 'HH:mm';
|
|
35
|
+
/** 中文格式:年-月-日 时:分:秒 */
|
|
36
|
+
export const FORMAT_YYYY_MM_DD_HH_MM_SS_CN = 'YYYY年MM月DD日 HH时mm分ss秒';
|
|
37
|
+
/** 中文仅日期:年-月-日 */
|
|
38
|
+
export const FORMAT_YYYY_MM_DD_CN = 'YYYY年MM月DD日';
|
|
39
|
+
/** 紧凑格式(无分隔符):年月日时分秒 */
|
|
40
|
+
export const FORMAT_YYYYMMDDHHMMSS = 'YYYYMMDDHHmmss';
|
|
41
|
+
/** 紧凑格式(无分隔符):年月日 */
|
|
42
|
+
export const FORMAT_YYYYMMDD = 'YYYYMMDD';
|
|
43
|
+
/** 紧凑格式(无分隔符):年月日时分秒 */
|
|
44
|
+
export const FORMAT_YYYYMMDDHHMMSSSSS = 'YYYYMMDDHHmmssSSS';
|
|
6
45
|
|
|
7
|
-
moment.locale('zh-cn');
|
|
8
46
|
|
|
9
47
|
/**
|
|
10
48
|
* 初始化日期对象(内部工具函数,不对外导出)
|
|
11
|
-
* @param {string|number|Date|
|
|
12
|
-
* @returns {
|
|
49
|
+
* @param {string|number|Date|Dayjs} date - 日期入参(不传则为当前时间)
|
|
50
|
+
* @returns {Dayjs} 格式化后的dayjs对象(无效则返回当前时间)
|
|
13
51
|
*/
|
|
14
|
-
const initDate = (date?:
|
|
15
|
-
if (!date) return
|
|
16
|
-
const
|
|
17
|
-
return
|
|
52
|
+
const initDate = (date?: ConfigType): Dayjs => {
|
|
53
|
+
if (!date) return dayjs();
|
|
54
|
+
const dayjsDate = dayjs(date);
|
|
55
|
+
return dayjsDate.isValid() ? dayjsDate : dayjs();
|
|
18
56
|
};
|
|
19
57
|
|
|
20
58
|
/**
|
|
21
59
|
* 日期格式化(默认格式:YYYY-MM-DD HH:mm:ss)
|
|
22
|
-
* @param {string|number|Date|
|
|
60
|
+
* @param {string|number|Date|Dayjs} date - 要格式化的日期
|
|
23
61
|
* @param {string} format - 自定义格式
|
|
24
62
|
* @returns {string} 格式化后的日期字符串
|
|
25
63
|
*/
|
|
26
|
-
const formatDate = (date, format = 'YYYY-MM-DD HH:mm:ss') => {
|
|
64
|
+
const formatDate = (date: ConfigType, format = 'YYYY-MM-DD HH:mm:ss'): string => {
|
|
27
65
|
return initDate(date).format(format);
|
|
28
66
|
};
|
|
29
67
|
|
|
@@ -32,30 +70,35 @@ const formatDate = (date, format = 'YYYY-MM-DD HH:mm:ss') => {
|
|
|
32
70
|
* @param {string} format - 自定义格式
|
|
33
71
|
* @returns {string} 当前时间字符串
|
|
34
72
|
*/
|
|
35
|
-
const getNow = (format =
|
|
36
|
-
return
|
|
73
|
+
const getNow = (format = FORMAT_YYYY_MM_DD_HH_MM_SS): string => {
|
|
74
|
+
return dayjs().format(format);
|
|
37
75
|
};
|
|
38
76
|
|
|
39
77
|
/**
|
|
40
78
|
* 日期加减计算
|
|
41
|
-
* @param {string|number|Date|
|
|
79
|
+
* @param {string|number|Date|Dayjs} date - 基准日期
|
|
42
80
|
* @param {number} num - 加减的数值(正数加,负数减)
|
|
43
81
|
* @param {string} unit - 单位(year/month/day/hour/minute/second/week)
|
|
44
82
|
* @param {string} format - 输出格式
|
|
45
83
|
* @returns {string} 计算后的日期字符串
|
|
46
84
|
*/
|
|
47
|
-
const addSubtractDate = (
|
|
48
|
-
|
|
49
|
-
|
|
85
|
+
const addSubtractDate = (
|
|
86
|
+
date: ConfigType,
|
|
87
|
+
num: number,
|
|
88
|
+
unit: dayjs.ManipulateType,
|
|
89
|
+
format = 'YYYY-MM-DD HH:mm:ss'
|
|
90
|
+
): string => {
|
|
91
|
+
const dayjsDate = initDate(date);
|
|
92
|
+
return dayjsDate.add(num, unit).format(format);
|
|
50
93
|
};
|
|
51
94
|
|
|
52
95
|
/**
|
|
53
96
|
* 比较两个日期的大小
|
|
54
|
-
* @param {string|number|Date|
|
|
55
|
-
* @param {string|number|Date|
|
|
97
|
+
* @param {string|number|Date|Dayjs} date1 - 日期1
|
|
98
|
+
* @param {string|number|Date|Dayjs} date2 - 日期2
|
|
56
99
|
* @returns {number} 1: date1 > date2;-1: date1 < date2;0: 相等
|
|
57
100
|
*/
|
|
58
|
-
const compareDate = (date1, date2) => {
|
|
101
|
+
const compareDate = (date1: ConfigType, date2: ConfigType): number => {
|
|
59
102
|
const m1 = initDate(date1);
|
|
60
103
|
const m2 = initDate(date2);
|
|
61
104
|
if (m1.isAfter(m2)) return 1;
|
|
@@ -65,73 +108,94 @@ const compareDate = (date1, date2) => {
|
|
|
65
108
|
|
|
66
109
|
/**
|
|
67
110
|
* 计算两个日期的差值
|
|
68
|
-
* @param {string|number|Date|
|
|
69
|
-
* @param {string|number|Date|
|
|
111
|
+
* @param {string|number|Date|Dayjs} date1 - 日期1
|
|
112
|
+
* @param {string|number|Date|Dayjs} date2 - 日期2
|
|
70
113
|
* @param {string} unit - 差值单位(days/hours/minutes/seconds/months/years)
|
|
71
114
|
* @returns {number} 差值(正数,date1 - date2 的绝对值)
|
|
72
115
|
*/
|
|
73
|
-
const diffDate = (
|
|
116
|
+
const diffDate = (
|
|
117
|
+
date1: ConfigType,
|
|
118
|
+
date2: ConfigType,
|
|
119
|
+
unit: dayjs.OpUnitType = 'days'
|
|
120
|
+
): number => {
|
|
74
121
|
const m1 = initDate(date1);
|
|
75
122
|
const m2 = initDate(date2);
|
|
76
|
-
// @ts-ignore
|
|
77
123
|
return Math.abs(m1.diff(m2, unit));
|
|
78
124
|
};
|
|
79
125
|
|
|
80
126
|
/**
|
|
81
127
|
* 验证日期是否有效
|
|
82
|
-
* @param {string|number|Date|
|
|
128
|
+
* @param {string|number|Date|Dayjs} date - 要验证的日期
|
|
83
129
|
* @returns {boolean} true: 有效;false: 无效
|
|
84
130
|
*/
|
|
85
|
-
const isValidDate = (date) => {
|
|
86
|
-
return
|
|
131
|
+
const isValidDate = (date: ConfigType): boolean => {
|
|
132
|
+
return dayjs(date).isValid();
|
|
87
133
|
};
|
|
88
134
|
|
|
89
135
|
/**
|
|
90
136
|
* 获取日期的指定部分(年/月/日/时/分/秒)
|
|
91
|
-
* @param {string|number|Date|
|
|
137
|
+
* @param {string|number|Date|Dayjs} date - 基准日期
|
|
92
138
|
* @param {string} unit - 要获取的单位(year/month/day/hour/minute/second/weekday)
|
|
93
139
|
* @returns {number} 对应的值(month 从 1 开始,weekday 周日为 0)
|
|
94
140
|
*/
|
|
95
|
-
const getDatePart = (date, unit) => {
|
|
96
|
-
const
|
|
97
|
-
|
|
98
|
-
|
|
141
|
+
const getDatePart = (date: ConfigType, unit: string): number => {
|
|
142
|
+
const dayjsDate = initDate(date);
|
|
143
|
+
switch (unit) {
|
|
144
|
+
case 'year':
|
|
145
|
+
return dayjsDate.year();
|
|
146
|
+
case 'month':
|
|
147
|
+
return dayjsDate.month() + 1; // dayjs的month是0开始,转为1开始(和原逻辑一致)
|
|
148
|
+
case 'day':
|
|
149
|
+
return dayjsDate.date();
|
|
150
|
+
case 'hour':
|
|
151
|
+
return dayjsDate.hour();
|
|
152
|
+
case 'minute':
|
|
153
|
+
return dayjsDate.minute();
|
|
154
|
+
case 'second':
|
|
155
|
+
return dayjsDate.second();
|
|
156
|
+
case 'weekday':
|
|
157
|
+
return dayjsDate.day(); // 周日为0,和moment一致
|
|
158
|
+
default:
|
|
159
|
+
return 0;
|
|
99
160
|
}
|
|
100
|
-
return momentDate[unit]();
|
|
101
161
|
};
|
|
102
162
|
|
|
103
163
|
/**
|
|
104
164
|
* 转换为时间戳
|
|
105
|
-
* @param {string|number|Date|
|
|
165
|
+
* @param {string|number|Date|Dayjs} date - 基准日期
|
|
106
166
|
* @param {boolean} isMillisecond - 是否返回毫秒级(默认false:秒级)
|
|
107
167
|
* @returns {number} 时间戳
|
|
108
168
|
*/
|
|
109
|
-
const toDateTimestamp = (date, isMillisecond = false) => {
|
|
110
|
-
const
|
|
111
|
-
return isMillisecond ?
|
|
169
|
+
const toDateTimestamp = (date: ConfigType, isMillisecond = false): number => {
|
|
170
|
+
const dayjsDate = initDate(date);
|
|
171
|
+
return isMillisecond ? dayjsDate.valueOf() : dayjsDate.unix();
|
|
112
172
|
};
|
|
113
173
|
|
|
114
174
|
/**
|
|
115
175
|
* 格式化相对时间(如:几秒前、几小时前)
|
|
116
|
-
* @param {string|number|Date|
|
|
176
|
+
* @param {string|number|Date|Dayjs} date - 基准日期
|
|
117
177
|
* @returns {string} 相对时间字符串(中文)
|
|
118
178
|
*/
|
|
119
|
-
const formatFromNow = (date) => {
|
|
179
|
+
const formatFromNow = (date: ConfigType): string => {
|
|
120
180
|
return initDate(date).fromNow();
|
|
121
181
|
};
|
|
122
182
|
|
|
123
183
|
/**
|
|
124
184
|
* 获取当月的第一天/最后一天
|
|
125
|
-
* @param {string|number|Date|
|
|
185
|
+
* @param {string|number|Date|Dayjs} date - 基准日期
|
|
126
186
|
* @param {boolean} isFirst - true: 第一天;false: 最后一天
|
|
127
187
|
* @param {string} format - 输出格式
|
|
128
188
|
* @returns {string} 对应日期
|
|
129
189
|
*/
|
|
130
|
-
const getMonthEdgeDate = (
|
|
131
|
-
|
|
190
|
+
const getMonthEdgeDate = (
|
|
191
|
+
date: ConfigType,
|
|
192
|
+
isFirst = true,
|
|
193
|
+
format = 'YYYY-MM-DD'
|
|
194
|
+
): string => {
|
|
195
|
+
const dayjsDate = initDate(date);
|
|
132
196
|
return isFirst
|
|
133
|
-
?
|
|
134
|
-
:
|
|
197
|
+
? dayjsDate.startOf('month').format(format)
|
|
198
|
+
: dayjsDate.endOf('month').format(format);
|
|
135
199
|
};
|
|
136
200
|
|
|
137
201
|
/**
|
|
@@ -140,38 +204,45 @@ const getMonthEdgeDate = (date, isFirst = true, format = 'YYYY-MM-DD') => {
|
|
|
140
204
|
* @param onlyDate 超过30天是否仅返回日期
|
|
141
205
|
* @returns {string} 语义化后的时间
|
|
142
206
|
*/
|
|
143
|
-
const getTimeAgoString = (time, onlyDate) => {
|
|
207
|
+
const getTimeAgoString = (time: ConfigType, onlyDate: boolean): string => {
|
|
144
208
|
if (!time) return '';
|
|
209
|
+
// Day.js 原生支持 '-' 分隔的日期,无需替换为 '/'(兼容原逻辑,保留也可)
|
|
145
210
|
if (typeof time === 'string') time = time.replace(/-/g, '/');
|
|
146
|
-
|
|
147
|
-
let
|
|
211
|
+
|
|
212
|
+
let arr: string[][] = [ [], [] ];
|
|
213
|
+
const currentTime = dayjs().valueOf();
|
|
214
|
+
const targetTime = dayjs(time).valueOf();
|
|
215
|
+
let timestamp = currentTime - targetTime;
|
|
216
|
+
|
|
148
217
|
// 30天以上返回具体日期
|
|
149
218
|
if (timestamp > 1000 * 60 * 60 * 24 * 31) {
|
|
150
|
-
|
|
151
|
-
arr[0][0] = setNumAddZero(date.
|
|
152
|
-
arr[0][1] = setNumAddZero(date.
|
|
153
|
-
arr[0][2] = setNumAddZero(date.
|
|
219
|
+
const date = dayjs(time);
|
|
220
|
+
arr[0][0] = setNumAddZero(date.year(), 4);
|
|
221
|
+
arr[0][1] = setNumAddZero(date.month() + 1);
|
|
222
|
+
arr[0][2] = setNumAddZero(date.date());
|
|
223
|
+
|
|
154
224
|
// 是否输出时间
|
|
155
225
|
if (!onlyDate) {
|
|
156
|
-
arr[1][0] = setNumAddZero(date.
|
|
157
|
-
arr[1][1] = setNumAddZero(date.
|
|
158
|
-
arr[1][2] = setNumAddZero(date.
|
|
226
|
+
arr[1][0] = setNumAddZero(date.hour());
|
|
227
|
+
arr[1][1] = setNumAddZero(date.minute());
|
|
228
|
+
arr[1][2] = setNumAddZero(date.second());
|
|
159
229
|
}
|
|
160
230
|
return arr[0].join('-') + ' ' + arr[1].join(':');
|
|
161
231
|
}
|
|
232
|
+
|
|
162
233
|
// 30天以内,返回“多久前”
|
|
163
234
|
if (timestamp >= 1000 * 60 * 60 * 24) {
|
|
164
|
-
return (
|
|
235
|
+
return Math.floor(timestamp / 1000 / 60 / 60 / 24) + '天前';
|
|
165
236
|
} else if (timestamp >= 1000 * 60 * 60) {
|
|
166
|
-
return (
|
|
237
|
+
return Math.floor(timestamp / 1000 / 60 / 60) + '小时前';
|
|
167
238
|
} else if (timestamp >= 1000 * 60 * 3) { // 3分钟以内为:刚刚
|
|
168
|
-
return (
|
|
239
|
+
return Math.floor(timestamp / 1000 / 60) + '分钟前';
|
|
169
240
|
} else if (timestamp < 0) {
|
|
170
241
|
return '未来';
|
|
171
242
|
} else {
|
|
172
243
|
return '刚刚';
|
|
173
244
|
}
|
|
174
|
-
}
|
|
245
|
+
};
|
|
175
246
|
|
|
176
247
|
export {
|
|
177
248
|
formatDate,
|
|
@@ -184,8 +255,5 @@ export {
|
|
|
184
255
|
toDateTimestamp,
|
|
185
256
|
formatFromNow,
|
|
186
257
|
getMonthEdgeDate,
|
|
187
|
-
|
|
188
|
-
|
|
189
258
|
getTimeAgoString,
|
|
190
|
-
|
|
191
|
-
}
|
|
259
|
+
};
|
package/lib/utils/rsaAesUtils.ts
CHANGED
|
@@ -6,25 +6,49 @@ import { rsaEncrypt, rsaDecrypt } from "./rsaUtils";
|
|
|
6
6
|
* rsaAes加密
|
|
7
7
|
* @param rsaPublicKey rsa公钥
|
|
8
8
|
* @param aesKey aes秘钥
|
|
9
|
-
* @param
|
|
9
|
+
* @param originalData 原始数据
|
|
10
10
|
*/
|
|
11
|
-
const rsaAesEncrypt = (rsaPublicKey, aesKey,
|
|
11
|
+
const rsaAesEncrypt = (rsaPublicKey:string, aesKey:string, originalData:string) => {
|
|
12
|
+
if(!rsaPublicKey){
|
|
13
|
+
throw new Error('参数[rsaPublicKey]为空');
|
|
14
|
+
}
|
|
15
|
+
if(!aesKey){
|
|
16
|
+
throw new Error('参数[aesKey]为空');
|
|
17
|
+
}
|
|
18
|
+
if(!originalData){
|
|
19
|
+
throw new Error('参数[originalData]为空');
|
|
20
|
+
}
|
|
21
|
+
console.log(rsaPublicKey, aesKey, originalData);
|
|
12
22
|
// 用登陆后后端生成并返回给前端的的RSA密钥对的公钥将AES16位密钥进行加密
|
|
13
|
-
const rsaAesKey = rsaEncrypt(
|
|
23
|
+
const rsaAesKey = rsaEncrypt(rsaPublicKey, aesKey);
|
|
24
|
+
|
|
25
|
+
console.log('rsaAesKey', rsaAesKey);
|
|
26
|
+
|
|
14
27
|
// 使用AES16位的密钥将请求报文加密(使用的是加密前的aes密钥)
|
|
15
|
-
const aesEncryptData = aesEncrypt(aesKey,
|
|
28
|
+
const aesEncryptData = aesEncrypt(aesKey, originalData);
|
|
16
29
|
|
|
17
30
|
return { rsaAesKey, aesEncryptData };
|
|
18
31
|
}
|
|
19
32
|
|
|
20
33
|
/**
|
|
21
|
-
* rsaAes解密
|
|
34
|
+
* rsaAes解密 未验证成功,后面处理
|
|
22
35
|
* @param rsaPrivateKey rsa私钥
|
|
23
36
|
* @param rsaAesKey rsa私钥
|
|
24
37
|
* @param encryptData 加密的数据
|
|
25
38
|
*/
|
|
26
|
-
const rsaAesDecrypt = (rsaPrivateKey, rsaAesKey, encryptData) => {
|
|
27
|
-
|
|
39
|
+
const rsaAesDecrypt = (rsaPrivateKey:string, rsaAesKey:string, encryptData:string) => {
|
|
40
|
+
if(!rsaPrivateKey){
|
|
41
|
+
throw new Error('参数[rsaPrivateKey]为空');
|
|
42
|
+
}
|
|
43
|
+
if(!rsaAesKey){
|
|
44
|
+
throw new Error('参数[rsaAesKey]为空');
|
|
45
|
+
}
|
|
46
|
+
if(!encryptData){
|
|
47
|
+
throw new Error('参数[encryptData]为空');
|
|
48
|
+
}
|
|
49
|
+
const aesKey: any = rsaDecrypt(rsaPrivateKey, rsaAesKey);
|
|
50
|
+
|
|
51
|
+
console.log('aesKey', aesKey);
|
|
28
52
|
|
|
29
53
|
let decryptData = aesDecrypt(aesKey, encryptData);
|
|
30
54
|
|
package/lib/utils/rsaUtils.ts
CHANGED
|
@@ -42,12 +42,20 @@ const getRsaKeys = () => {
|
|
|
42
42
|
/**
|
|
43
43
|
* rsa加密
|
|
44
44
|
* @param publicKey
|
|
45
|
-
* @param
|
|
45
|
+
* @param originalData
|
|
46
46
|
*/
|
|
47
|
-
const rsaEncrypt = (publicKey,
|
|
47
|
+
const rsaEncrypt = (publicKey: string, originalData: string) => {
|
|
48
|
+
if(!publicKey){
|
|
49
|
+
throw new Error('参数[publicKey]为空');
|
|
50
|
+
}
|
|
51
|
+
if(!originalData){
|
|
52
|
+
throw new Error('参数[originalData]为空');
|
|
53
|
+
}
|
|
48
54
|
const encryptor = new JSEncrypt();
|
|
49
55
|
encryptor.setPublicKey(publicKey);
|
|
50
|
-
|
|
56
|
+
|
|
57
|
+
const encryptData = encryptor.encrypt(originalData);
|
|
58
|
+
return encryptData;
|
|
51
59
|
}
|
|
52
60
|
|
|
53
61
|
/**
|
|
@@ -55,13 +63,23 @@ const rsaEncrypt = (publicKey, oiginData) => {
|
|
|
55
63
|
* @param privateKey
|
|
56
64
|
* @param encryptData
|
|
57
65
|
*/
|
|
58
|
-
const rsaDecrypt = (privateKey, encryptData) => {
|
|
66
|
+
const rsaDecrypt = (privateKey:string, encryptData:string) => {
|
|
67
|
+
if(!privateKey){
|
|
68
|
+
throw new Error('参数[privateKey]为空');
|
|
69
|
+
}
|
|
70
|
+
if(!encryptData){
|
|
71
|
+
throw new Error('参数[encryptData]为空');
|
|
72
|
+
}
|
|
59
73
|
const encryptor = new JSEncrypt();
|
|
60
74
|
encryptor.setPrivateKey(privateKey);
|
|
61
|
-
|
|
75
|
+
const decryptData = encryptor.decrypt(encryptData);
|
|
76
|
+
|
|
77
|
+
console.log('decryptData', decryptData);
|
|
78
|
+
|
|
79
|
+
return decryptData;
|
|
62
80
|
}
|
|
63
81
|
|
|
64
|
-
const convertText = (buffer, isPrivate = 0) => {
|
|
82
|
+
const convertText = (buffer: any, isPrivate = 0) => {
|
|
65
83
|
var binary = ''
|
|
66
84
|
var bytes = new Uint8Array(buffer)
|
|
67
85
|
var len = bytes.byteLength
|
package/lib/utils/ssoUtils.ts
CHANGED
|
@@ -120,41 +120,7 @@ const handleSsoAuth = (to : any, from : any) => {
|
|
|
120
120
|
});
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
/**
|
|
124
|
-
* 获取sso加密参数
|
|
125
|
-
* 后续改成 rsaAesUtils 里面去实现
|
|
126
|
-
* @param password
|
|
127
|
-
*/
|
|
128
|
-
const getSsoEncrypt = (password = '') => {
|
|
129
|
-
let gatewayPublicKey = getLocalStorageItem('gatewayPublicKey');
|
|
130
|
-
// 每次请求生成aeskey
|
|
131
|
-
let aesKey = getAesRandomKey();
|
|
132
|
-
// 用登陆后后端生成并返回给前端的的RSA密钥对的公钥将AES16位密钥进行加密
|
|
133
|
-
const rsaAesKey = rsaEncrypt(gatewayPublicKey, aesKey);
|
|
134
|
-
// 使用AES16位的密钥将请求报文加密(使用的是加密前的aes密钥)
|
|
135
|
-
const encryptPassword = aesEncrypt(aesKey, password);
|
|
136
|
-
|
|
137
|
-
return { encryptPassword, rsaAesKey };
|
|
138
|
-
}
|
|
139
123
|
|
|
140
|
-
/**
|
|
141
|
-
* 获取sso加密参数列表
|
|
142
|
-
* @param password
|
|
143
|
-
*/
|
|
144
|
-
const getSsoEncryptList = (passwordList = []) => {
|
|
145
|
-
let gatewayPublicKey = getLocalStorageItem('gatewayPublicKey');
|
|
146
|
-
// 每次请求生成aeskey
|
|
147
|
-
let aesKey = getAesRandomKey();
|
|
148
|
-
// 用登陆后后端生成并返回给前端的的RSA密钥对的公钥将AES16位密钥进行加密
|
|
149
|
-
const rsaAesKey = rsaEncrypt(gatewayPublicKey, aesKey);
|
|
150
|
-
// 使用AES16位的密钥将请求报文加密(使用的是加密前的aes密钥)
|
|
151
|
-
const encryptPasswordList = [];
|
|
152
|
-
for (let i = 0; i < passwordList.length; i++) {
|
|
153
|
-
encryptPasswordList[i] = aesEncrypt(aesKey, passwordList[i]);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
return { encryptPasswordList, rsaAesKey };
|
|
157
|
-
}
|
|
158
124
|
|
|
159
125
|
|
|
160
126
|
const ssoAccessTokenCookieKey: string = 'Sso-Access-Token';
|
|
@@ -228,7 +194,7 @@ const clearSsoAccessToken = () => {
|
|
|
228
194
|
|
|
229
195
|
}
|
|
230
196
|
|
|
231
|
-
const setSsoIdentity = (ssoIdentity) => {
|
|
197
|
+
const setSsoIdentity = (ssoIdentity:object) => {
|
|
232
198
|
if(!ssoIdentity) {
|
|
233
199
|
console.error('参数[ssoIdentity]为null');
|
|
234
200
|
return;
|
|
@@ -258,9 +224,6 @@ export {
|
|
|
258
224
|
getSsoLogoutUrl,
|
|
259
225
|
handleSsoAuth,
|
|
260
226
|
|
|
261
|
-
getSsoEncrypt,
|
|
262
|
-
getSsoEncryptList,
|
|
263
|
-
|
|
264
227
|
getSsoAccessToken,
|
|
265
228
|
setSsoAccessToken,
|
|
266
229
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "yuang-framework-ui-common",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.103",
|
|
4
4
|
"private": false,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -29,11 +29,11 @@
|
|
|
29
29
|
"@wangeditor/editor-for-vue": "^5.1.12",
|
|
30
30
|
"axios": "^1.7.3",
|
|
31
31
|
"crypto-js": "^4.2.0",
|
|
32
|
+
"dayjs": "^1.11.13",
|
|
32
33
|
"element-plus": "^2.8.4",
|
|
33
34
|
"js-cookie": "^3.0.5",
|
|
34
35
|
"jsencrypt": "^3.3.2",
|
|
35
36
|
"lodash": "^4.17.21",
|
|
36
|
-
"moment": "^2.30.1",
|
|
37
37
|
"pinia": "^2.1.7",
|
|
38
38
|
"safe-stringify": "^1.1.1",
|
|
39
39
|
"vant": "^4.9.8",
|
package/src/router/index.ts
CHANGED
|
@@ -19,6 +19,10 @@ const router = createRouter({
|
|
|
19
19
|
path: '/utils/rsa-utils',
|
|
20
20
|
component: () => import('@/views/utils/rsa-utils.vue')
|
|
21
21
|
},
|
|
22
|
+
{
|
|
23
|
+
path: '/utils/rsa-aes-utils',
|
|
24
|
+
component: () => import('@/views/utils/rsa-aes-utils.vue')
|
|
25
|
+
},
|
|
22
26
|
{
|
|
23
27
|
path: '/utils/sso-utils',
|
|
24
28
|
component: () => import('@/views/utils/sso-utils.vue')
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
http://localhost:8020/framework-ui-common/utils/rsa-aes-utils
|
|
3
|
+
-->
|
|
1
4
|
<template>
|
|
2
5
|
<div>encryptData:{{ encryptData }}</div>
|
|
3
6
|
<div>decryptData:{{ decryptData }}</div>
|
|
@@ -6,20 +9,20 @@
|
|
|
6
9
|
<script setup lang="ts">
|
|
7
10
|
import {onMounted, ref} from 'vue';
|
|
8
11
|
import { rsaAesDecrypt, rsaAesEncrypt } from '../../../lib/utils/rsaAesUtils';
|
|
9
|
-
import { getLocalStorageItem } from "../../../lib/utils/storageUtils";
|
|
10
12
|
import { getAesRandomKey } from "../../../lib/utils/aesUtils";
|
|
11
13
|
|
|
12
14
|
let encryptData = ref({});
|
|
13
15
|
let decryptData = ref('');
|
|
14
16
|
|
|
15
17
|
onMounted(async () => {
|
|
16
|
-
let
|
|
18
|
+
let rsaPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAlroQv10uuYLiupAw50WeqkHZ44Qw35IBz28xH4ZcMjUSn9mZhZpP9jMZqxxjS3W6vFsT+Wqp7XSl2q+rj91R7YxW5Mz3JazMCG+vj3dlgbTgqTgGf+QnQ4qIgSz3VKM56QLBXegcNv9IbGPmX+1gU14aB8cMQQYLEl0efNBFpzLnkfz+8HqHlbwc0tDDQTycf7HJXd0YziwQWmWsAZ9aNzhQBXOnI28MTqASHYRpVf1Cziu9aYBDM/Tqmb3wZKRR1s8RTUlzZfZ1XfRHsRu2xgVdb7+S0o5g4wVxFpGXK2PEAhidaTpnvasaWEU9/8KNdCC5hP8i+kMDv5MZ4RgDXQIDAQA";
|
|
19
|
+
let rsaPrivateKey = "MIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCWuhC/XS65guK6kDDnRZ6qQdnjhDDfkgHPbzEfhlwyNRKf2ZmFmk/2MxmrHGNLdbq8WxP5aqntdKXar6uP3VHtjFbkzPclrMwIb6+Pd2WBtOCpOAZ/5CdDioiBLPdUoznpAsFd6Bw2/0hsY+Zf7WBTXhoHxwxBBgsSXR580EWnMueR/P7weoeVvBzS0MNBPJx/scld3RjOLBBaZawBn1o3OFAFc6cjbwxOoBIdhGlV/ULOK71pgEMz9OqZvfBkpFHWzxFNSXNl9nVd9EexG7bGBV1vv5LSjmDjBXEWkZcrY8QCGJ1pOme9qxpYRT3/wo10ILmE/yL6QwO/kxnhGANdAgMBAAECggEAE3CO/WdiwdlgLaiwLfvcMWBJ3l6rwQH/SsYwAz1cgbs3mjdB5inXW00O5/NC2TYnbeifRGFd5jrPs0tJ6MWmLemWQW8wBwNo00O4VFwVUuvFt/16VR9TcxIYdfSbN6bPrr5EuzxW+z7kk9o0mbWvYUE3QT6KVY6WeflZl8Zy3VPwKiqxcuI5+SbWrlSslCta1rg2pikQ6ALkWzQOeSpMafAW5GdQmCvyKQ2K1QCfXnGnqpPYiWcsGxXFRAFoa61IxedE6EKmIg49lF5G/5X2WHa/Ljb0s9z0EGf9sonmpYEfG8m5RceBjDWsUyUZG+WDgM+9umpkvGYnU+MScNQmoQKBgQDQAtayKVoZHL09XhjQoTlMjh00fZ9rihRZbY2yIfgsIGl3oZFOEnBSXye3mAQpjKuw81fw1UAqmzwMCleEs+WCs5CGqN1uLChH+WJPIi1qdWbUG6tSexW8qmZM0w5PBenV9HeaRzJJwfMYJglM90xH7M0XWLnttgDmf+ivc8tKcQKBgQC5gAKt1HKWzac2Z4xSfOHUclQTDhLZYGL/JDITAUsmoaC9FjUH/SAnKkf5SLdvj90ZH8pM/O5Ct8UcHCNWYYn1w08swILnx96x2WvfweuHaCof1yBafBk5jhMPxhOfognGKwrolhzqEKPtZQcRbNBc7jgSOs3rJU7y86nr1KqFrQKBgQCZGT3EK8NwsEJopJVHGSL/QaolNEDd+ec4WvXroizy7Xgy4Ov9tnyNZBPrgSuvGSZVOwYC8DImKdNsWUBJH89Q/7DkK+2uZTnQn7DH5bPfo0Fn5GWYc5dwIUriSIVDjGqrWx+cocJVnza5E2XNDEdMuPHKuTc/yrGm9YXhfSynQQKBgQCAQy4XCdWtxkc/S/vvsV/pKKBPiKSp34a0ClABahyPeqSM+gTzICgSTJ71lD0aC6yCScP01dLdGPpWxHH+sXTWFRTyya36G+40pTR8xDZaK0EtQO+jATnj3QP7HSfGciE1/98MEXeutJDUfc2UU9wC1ci5eiWV2Pcs8CRm52Z9BQKBgQDDqI2a5aCi5QxRMuapSC6DYvSNssyFOb1dZzGkVOaZg1sdDH6YEqOGaboMqAHnFooyPUYGp8s4nagYRt9X2Hc/RFHrH6jSlwXwKtiXNhMDjzKoDft2VfeDRui3TYRCLOZNpt6U1sq5Q/4sHQCUL5bXX5a58VMRqrvmidTzimJd9A=";
|
|
17
20
|
let aesKey = getAesRandomKey();
|
|
18
|
-
encryptData.value = rsaAesEncrypt(
|
|
21
|
+
encryptData.value = rsaAesEncrypt(rsaPublicKey, aesKey, '测试');
|
|
22
|
+
console.log('encryptData.value',encryptData.value);
|
|
19
23
|
|
|
20
|
-
let rsaPrivateKey = '';
|
|
21
|
-
decryptData = rsaAesDecrypt(rsaPrivateKey, encryptData.value.rsaAesKey, encryptData.value.encryptData);
|
|
22
24
|
|
|
25
|
+
decryptData.value = rsaAesDecrypt(rsaPrivateKey, encryptData.value.rsaAesKey, encryptData.value.aesEncryptData);
|
|
23
26
|
})
|
|
24
27
|
|
|
25
28
|
</script>
|