@peng_kai/kit 0.2.48 → 0.2.49

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.49",
5
5
  "description": "",
6
6
  "author": "",
7
7
  "license": "ISC",
@@ -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({