@peng_kai/kit 0.2.48 → 0.2.50

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.
@@ -7,7 +7,7 @@ export function createAwsS3Request(awsS3: AwsS3, rootPath?: string) {
7
7
  return async (options: UploadRequestOption) => {
8
8
  if (!(options.file instanceof File))
9
9
  throw new Error('options.file 不是 File 对象');
10
-
10
+
11
11
  const { uploader, fileURL } = await awsS3.upload(options.file, rootPath);
12
12
 
13
13
  uploader.on('httpUploadProgress', (progress) => {
@@ -31,6 +31,7 @@ export function urlToUploadFile(urls?: string[] | string) {
31
31
  name: getFileNameByUrl(url),
32
32
  status: 'done',
33
33
  url,
34
+ thumbUrl: url,
34
35
  }));
35
36
 
36
37
  return files;
@@ -74,9 +74,10 @@ function groupingForm(groupName: string, items: Record<string, FormItemProps>) {
74
74
  * 格式化表单项组
75
75
  * @param name - 组名
76
76
  * @param items - 包含表单数据
77
+ * @param removeTempKey - 是否移除临时字段(建议删除前克隆 items)
77
78
  * @returns 返回一个数组,其元素为分组后的表单项对象,如果没有找到匹配的组名,则返回 undefined
78
79
  */
79
- function formatGroup(name: string, items: Record<string, any>) {
80
+ function formatGroup(name: string, items: Record<string, any>, removeTempKey = false) {
80
81
  const group: any[] = [];
81
82
 
82
83
  for (const k in items) {
@@ -89,6 +90,14 @@ function formatGroup(name: string, items: Record<string, any>) {
89
90
  group[params.index][params.fieldName] = items[k];
90
91
  }
91
92
 
93
+ if (removeTempKey) {
94
+ const keyRE = new RegExp(`^${name}${GROUP_SEP}\\d+${GROUP_SEP}`);
95
+ Object.keys(items).forEach((key) => {
96
+ if (keyRE.test(key))
97
+ delete items[key];
98
+ });
99
+ }
100
+
92
101
  return group?.length ? group.filter(g => !!g) : undefined;
93
102
  }
94
103
 
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@peng_kai/kit",
3
3
  "type": "module",
4
- "version": "0.2.48",
4
+ "version": "0.2.50",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",
@@ -1,6 +1,7 @@
1
1
  import type { AxiosInterceptorManager } from 'axios';
2
2
  import FingerprintJS from '@fingerprintjs/fingerprintjs';
3
3
  import type { GetResult } from '@fingerprintjs/fingerprintjs';
4
+ import { toBase64 } from '../../utils/string';
4
5
 
5
6
  /**
6
7
  * 【请求拦截器】检索设备信息并在请求中设置“Device”头。
@@ -24,8 +25,16 @@ export function getDeviceInfo(callback: (base: Record<string, any>, all: GetResu
24
25
  };
25
26
 
26
27
  req.headers.set('Device', callback(base, result));
28
+ req.headers.set('Accept-Date', getCurrentTimeZone());
27
29
 
28
30
  return req;
29
31
  },
30
32
  ];
31
33
  }
34
+
35
+ function getCurrentTimeZone() {
36
+ const now = new Date();
37
+ const [_, time, tz, describe] = now.toString().match(/(\w{3} \w{3} \d{2} \d{4} \d{2}:\d{2}:\d{2})? (GMT[+-]\d{4}) \((.*?)\)/) ?? [];
38
+ const tzOffset = now.getTimezoneOffset() / 60;
39
+ return toBase64([time, tz, tzOffset, describe].join('|'));
40
+ }
package/utils/string.ts CHANGED
@@ -1,3 +1,6 @@
1
+ import { Base64 } from 'crypto-es/lib/enc-base64';
2
+ import { Utf8 } from 'crypto-es/lib/core';
3
+
1
4
  /**
2
5
  * 字符串脱敏,省略中间字符串
3
6
  * @param str 字符串
@@ -26,3 +29,14 @@ export function randomString(length: number) {
26
29
  const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
27
30
  return Array.from({ length }, () => characters[Math.floor(Math.random() * characters.length)]).join('');
28
31
  }
32
+
33
+ /**
34
+ * 转为base64字符串
35
+ * @param str 值
36
+ */
37
+ export function toBase64(str: string | number) {
38
+ if (!['string', 'number'].includes(typeof str) || !str)
39
+ return '';
40
+
41
+ return Base64.stringify(Utf8.parse(String(str)));
42
+ }
@@ -23,7 +23,7 @@ export class AwsS3 {
23
23
  public async upload(file: File, root?: string) {
24
24
  const s3Client = await this.refreshClient();
25
25
  const filePath = await this.genFilePath(root || 'unclassified');
26
- const fileName = await (this.fileHandler?.genFileName(file) ?? this.genFileName(file));
26
+ const fileName = await (this.fileHandler?.genFileName?.(file) ?? this.genFileName(file));
27
27
  const fullPath = `${filePath}/${fileName}`;
28
28
 
29
29
  const uploader = new Upload({