@ticatec/batch-data-uploader 0.1.0 → 0.1.1

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.
@@ -1,5 +1,5 @@
1
1
  import BaseTemplate from "./BaseTemplate";
2
- import i18nRes from "./i18n_resources/i18nRes";
2
+ import i18nRes from "./i18n_res";
3
3
  const ValidData = `<span style="color: #76FF03">${i18nRes.textValid}</span>`;
4
4
  const InvalidData = `<span style="color: #ff3e00">${i18nRes.textInvalid.key}</span>`;
5
5
  export default class BaseEncodingTemplate extends BaseTemplate {
@@ -1,16 +1,14 @@
1
1
  import type DataColumn from "./DataColumn";
2
2
  import type { DataColumn as TableColumn } from "@ticatec/uniface-element/DataTable";
3
3
  export default abstract class BaseTemplate {
4
- protected readonly _columns: Array<DataColumn>;
5
- protected readonly rowOffset: number;
6
4
  protected _list: Array<any>;
7
5
  /**
8
6
  *
9
- * @param columns
10
- * @param rowOffset
11
7
  * @protected
12
8
  */
13
- protected constructor(columns: Array<DataColumn>, rowOffset?: number);
9
+ protected constructor();
10
+ protected abstract getMetaColumns(): Array<DataColumn>;
11
+ protected getRowOffset(): number;
14
12
  /**
15
13
  * 整理数据,在子类可以通过重载完成数据的二次处理
16
14
  * @param rows
@@ -1,18 +1,15 @@
1
1
  import * as XLSX from 'xlsx';
2
2
  import utils from "./utils";
3
3
  export default class BaseTemplate {
4
- _columns;
5
- rowOffset;
6
4
  _list = [];
7
5
  /**
8
6
  *
9
- * @param columns
10
- * @param rowOffset
11
7
  * @protected
12
8
  */
13
- constructor(columns, rowOffset = 1) {
14
- this._columns = columns;
15
- this.rowOffset = rowOffset;
9
+ constructor() {
10
+ }
11
+ getRowOffset() {
12
+ return 1;
16
13
  }
17
14
  /**
18
15
  * 整理数据,在子类可以通过重载完成数据的二次处理
@@ -27,6 +24,8 @@ export default class BaseTemplate {
27
24
  * @param file
28
25
  */
29
26
  async parseExcelFile(file) {
27
+ const columns = this.getMetaColumns();
28
+ const rowOffset = this.getRowOffset();
30
29
  try {
31
30
  const buffer = await file.arrayBuffer();
32
31
  const workbook = XLSX.read(buffer, { type: 'array' });
@@ -41,16 +40,16 @@ export default class BaseTemplate {
41
40
  }
42
41
  const range = XLSX.utils.decode_range(sheet['!ref']); // 获取范围
43
42
  // 验证是否有足够的行数
44
- if (range.e.r < this.rowOffset) {
45
- throw new Error(`Not enough rows in file. Expected at least ${this.rowOffset + 1} rows`);
43
+ if (range.e.r < rowOffset) {
44
+ throw new Error(`Not enough rows in file. Expected at least ${rowOffset + 1} rows`);
46
45
  }
47
46
  const rows = [];
48
- for (let rowIndex = range.s.r + this.rowOffset; rowIndex <= range.e.r; rowIndex++) {
47
+ for (let rowIndex = range.s.r + rowOffset; rowIndex <= range.e.r; rowIndex++) {
49
48
  const rowObject = {};
50
49
  let dummyCount = 0;
51
50
  let hasData = false;
52
- for (let i = 0; i < this._columns.length; i++) {
53
- const colDef = this._columns[i];
51
+ for (let i = 0; i < columns.length; i++) {
52
+ const colDef = columns[i];
54
53
  if (colDef.dummy) {
55
54
  dummyCount++;
56
55
  }
@@ -101,7 +100,7 @@ export default class BaseTemplate {
101
100
  extractData(arr) {
102
101
  let list = arr.map(item => {
103
102
  let result = {};
104
- for (let col of this._columns) {
103
+ for (let col of this.getMetaColumns()) {
105
104
  // 修复逻辑错误:ignore应该为true时才忽略,visible为false时才隐藏
106
105
  if (col.visible != false && col.ignore != true && !col.dummy) {
107
106
  let data = item.data;
@@ -124,7 +123,7 @@ export default class BaseTemplate {
124
123
  * 获取表格的列定义
125
124
  */
126
125
  get columns() {
127
- return this._columns
126
+ return this.getMetaColumns()
128
127
  .filter(col => col.visible !== false)
129
128
  .map(col => ({ ...col, field: `data.${col.field}` }));
130
129
  }
@@ -1,6 +1,5 @@
1
1
  import BaseTemplate from "./BaseTemplate";
2
2
  import type { DataColumn as TableColumn } from "@ticatec/uniface-element/DataTable";
3
- import type DataColumn from "./DataColumn";
4
3
  export type UploadFun = (arr: Array<any>) => Promise<Array<any>>;
5
4
  export type UpdateProgressStatus = () => void;
6
5
  export interface UploadResult {
@@ -17,7 +16,7 @@ export default abstract class BaseUploadTemplate extends BaseTemplate {
17
16
  protected batchSize: number;
18
17
  protected updateProgressStatus: UpdateProgressStatus | null;
19
18
  private _uploadAborted;
20
- protected constructor(columns: Array<DataColumn>, batchSize?: number, rowOffset?: number);
19
+ protected constructor(batchSize?: number);
21
20
  /**
22
21
  * 状态更新的监听器
23
22
  * @param value
@@ -1,9 +1,8 @@
1
1
  // 改进的BaseUploadTemplate.ts - 完全清理元数据相关代码
2
2
  import BaseTemplate from "./BaseTemplate";
3
- import i18nKeys from "./i18n_resources/i18nKeys";
4
3
  import utils from "./utils";
5
4
  import * as XLSX from 'xlsx';
6
- import i18nRes from "./i18n_resources/i18nRes";
5
+ import i18nRes from "./i18n_res/i18nRes";
7
6
  const statusColumn = {
8
7
  text: i18nRes.labelStatus,
9
8
  width: 240,
@@ -29,8 +28,8 @@ export default class BaseUploadTemplate extends BaseTemplate {
29
28
  batchSize;
30
29
  updateProgressStatus = null;
31
30
  _uploadAborted = false;
32
- constructor(columns, batchSize = 50, rowOffset = 1) {
33
- super(columns, rowOffset);
31
+ constructor(batchSize = 50) {
32
+ super();
34
33
  this.batchSize = Math.max(1, batchSize);
35
34
  }
36
35
  /**
@@ -213,7 +212,7 @@ export default class BaseUploadTemplate extends BaseTemplate {
213
212
  return;
214
213
  }
215
214
  // 获取可见且非虚拟的列
216
- const exportColumns = this._columns.filter(col => col.visible !== false && !col.dummy && !col.ignore);
215
+ const exportColumns = this.getMetaColumns().filter(col => col.visible !== false && !col.dummy && !col.ignore);
217
216
  // 创建标题行(与原始导入格式一致)
218
217
  const headers = exportColumns.map(col => col.text || col.field);
219
218
  // 创建数据行
@@ -242,7 +241,7 @@ export default class BaseUploadTemplate extends BaseTemplate {
242
241
  : this._list.filter(row => row.status === 'D' && row.error);
243
242
  if (errorRows.length === 0)
244
243
  return;
245
- const visibleColumns = this._columns.filter(col => col.visible !== false && !col.dummy);
244
+ const visibleColumns = this.getMetaColumns().filter(col => col.visible !== false && !col.dummy);
246
245
  const headers = [
247
246
  '行号',
248
247
  ...visibleColumns.map(col => col.text || col.field),
@@ -6,7 +6,7 @@
6
6
  import {onMount} from "svelte";
7
7
  import type DataColumn from "./DataColumn";
8
8
  import type BaseEncodingTemplate from "./BaseEncodingTemplate";
9
- import i18nRes from "./i18n_resources/i18nRes";
9
+ import i18nRes from "./i18n_res/i18nRes";
10
10
  import {i18nUtils} from "@ticatec/i18n";
11
11
 
12
12
  export let title: string;
@@ -7,7 +7,7 @@
7
7
  import {onMount} from "svelte";
8
8
  import type DataColumn from "./DataColumn";
9
9
  import type BaseUploadTemplate from "./BaseUploadTemplate.js";
10
- import i18nRes from "./i18n_resources/i18nRes";
10
+ import i18nRes from "./i18n_res/i18nRes";
11
11
  import {i18nUtils} from "@ticatec/i18n";
12
12
 
13
13
  export let title: string;
@@ -0,0 +1,27 @@
1
+ import { i18nUtils } from "@ticatec/i18n";
2
+ const langRes = {
3
+ status: {
4
+ pending: "To upload",
5
+ uploading: "Uploading...",
6
+ successful: "Success",
7
+ fail: "Failure"
8
+ },
9
+ parsing: "Parsing file...",
10
+ parseFailure: "Cannot parse file: {{name}}",
11
+ waitUploading: "Cannot exit during uploading!",
12
+ button: {
13
+ upload: "Upload",
14
+ save: "Save error data",
15
+ open: "Open",
16
+ confirm: "Confirm"
17
+ },
18
+ errorTitle: "Error",
19
+ sheetName: "Abnormal data",
20
+ labelStatus: "Status",
21
+ labelValid: "Validity",
22
+ textValid: "Yes",
23
+ textInvalid: "No",
24
+ labelHint: "Hint"
25
+ };
26
+ const i18nRes = i18nUtils.createResourceProxy(langRes, 'batchUploading');
27
+ export default i18nRes;
@@ -0,0 +1,2 @@
1
+ import i18nRes from "./i18nRes";
2
+ export default i18nRes;
@@ -0,0 +1,2 @@
1
+ import i18nRes from "./i18nRes";
2
+ export default i18nRes;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ticatec/batch-data-uploader",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "A reusable Svelte component for batch uploading Excel data with support for error handling, multi-language, and preprocessing.",
5
5
  "scripts": {
6
6
  "dev": "vite dev",
@@ -74,7 +74,7 @@
74
74
  "@sveltejs/package": "^2.0.0",
75
75
  "@sveltejs/vite-plugin-svelte": "^4.0.0",
76
76
  "@ticatec/i18n": "^0.2.0",
77
- "@ticatec/uniface-element": "^0.1.71",
77
+ "@ticatec/uniface-element": "^0.2.0",
78
78
  "@ticatec/uniface-google-material-icons": "^0.1.2",
79
79
  "dayjs": "^1.11.10",
80
80
  "publint": "^0.3.2",
@@ -1,22 +0,0 @@
1
- declare const langRes: {
2
- batchUploading: {
3
- status: {
4
- pending: string;
5
- uploading: string;
6
- successful: string;
7
- fail: string;
8
- };
9
- parsing: string;
10
- parseFailure: string;
11
- waitUploading: string;
12
- button: {
13
- upload: string;
14
- save: string;
15
- open: string;
16
- };
17
- errorTitle: string;
18
- sheetName: string;
19
- labelStatus: string;
20
- };
21
- };
22
- export default langRes;
@@ -1,22 +0,0 @@
1
- const langRes = {
2
- batchUploading: {
3
- status: {
4
- pending: '待上传',
5
- uploading: "上传中...",
6
- successful: '处理成功',
7
- fail: '处理失败'
8
- },
9
- parsing: '解析文件...',
10
- parseFailure: '无法解析文件{{name}}',
11
- waitUploading: '上传过程中无法退出!',
12
- button: {
13
- upload: '上传',
14
- save: '导出异常',
15
- open: '文件'
16
- },
17
- errorTitle: '异常原因',
18
- sheetName: '错误数据',
19
- labelStatus: "状态"
20
- }
21
- };
22
- export default langRes;
@@ -1,27 +0,0 @@
1
- declare const langRes: {
2
- batchUploading: {
3
- status: {
4
- pending: string;
5
- uploading: string;
6
- successful: string;
7
- fail: string;
8
- };
9
- parsing: string;
10
- parseFailure: string;
11
- waitUploading: string;
12
- button: {
13
- upload: string;
14
- save: string;
15
- open: string;
16
- confirm: string;
17
- };
18
- errorTitle: string;
19
- sheetName: string;
20
- labelStatus: string;
21
- labelValid: string;
22
- textValid: string;
23
- textInvalid: string;
24
- labelHint: string;
25
- };
26
- };
27
- export default langRes;
@@ -1,27 +0,0 @@
1
- const langRes = {
2
- batchUploading: {
3
- status: {
4
- pending: "To upload",
5
- uploading: "Uploading...",
6
- successful: "Success",
7
- fail: "Failure"
8
- },
9
- parsing: "Parsing file...",
10
- parseFailure: "Cannot parse file: {{name}}",
11
- waitUploading: "Cannot exit during uploading!",
12
- button: {
13
- upload: "Upload",
14
- save: "Save error data",
15
- open: "Open",
16
- confirm: "Confirm"
17
- },
18
- errorTitle: "Error",
19
- sheetName: "Abnormal data",
20
- labelStatus: "Status",
21
- labelValid: "Validity",
22
- textValid: "Yes",
23
- textInvalid: "No",
24
- labelHint: "Hint"
25
- }
26
- };
27
- export default langRes;
@@ -1,79 +0,0 @@
1
- declare const i18nKeys: {
2
- status: {
3
- pending: {
4
- key: string;
5
- text: string;
6
- };
7
- uploading: {
8
- key: string;
9
- text: string;
10
- };
11
- successful: {
12
- key: string;
13
- text: string;
14
- };
15
- fail: {
16
- key: string;
17
- text: string;
18
- };
19
- };
20
- labelValid: {
21
- key: string;
22
- text: string;
23
- };
24
- labelHint: {
25
- key: string;
26
- text: string;
27
- };
28
- labelStatus: {
29
- key: string;
30
- text: string;
31
- };
32
- parsing: {
33
- key: string;
34
- text: string;
35
- };
36
- parseFailure: {
37
- key: string;
38
- text: string;
39
- };
40
- waitUploading: {
41
- key: string;
42
- text: string;
43
- };
44
- button: {
45
- upload: {
46
- key: string;
47
- text: string;
48
- };
49
- save: {
50
- key: string;
51
- text: string;
52
- };
53
- open: {
54
- key: string;
55
- text: string;
56
- };
57
- confirm: {
58
- key: string;
59
- text: string;
60
- };
61
- };
62
- errorTitle: {
63
- key: string;
64
- text: string;
65
- };
66
- sheetName: {
67
- key: string;
68
- text: string;
69
- };
70
- textValid: {
71
- key: string;
72
- text: string;
73
- };
74
- textInvalid: {
75
- key: string;
76
- text: string;
77
- };
78
- };
79
- export default i18nKeys;
@@ -1,80 +0,0 @@
1
- import langRes from "./batch_en_resource";
2
- const i18nKeys = {
3
- status: {
4
- pending: {
5
- key: "batchUploading.status.pending",
6
- text: langRes.batchUploading.status.pending
7
- },
8
- uploading: {
9
- key: "batchUploading.status.uploading",
10
- text: langRes.batchUploading.status.uploading
11
- },
12
- successful: {
13
- key: "batchUploading.status.successful",
14
- text: langRes.batchUploading.status.successful
15
- },
16
- fail: {
17
- key: "batchUploading.status.fail",
18
- text: langRes.batchUploading.status.fail
19
- }
20
- },
21
- labelValid: {
22
- key: 'batchUploading.labelValid',
23
- text: langRes.batchUploading.labelValid
24
- },
25
- labelHint: {
26
- key: 'batchUploading.labelValid',
27
- text: langRes.batchUploading.labelHint
28
- },
29
- labelStatus: {
30
- key: 'batchUploading.labelStatus',
31
- text: langRes.batchUploading.labelStatus
32
- },
33
- parsing: {
34
- key: 'batchUploading.parsing',
35
- text: langRes.batchUploading.parsing
36
- },
37
- parseFailure: {
38
- key: 'batchUploading.parseFailure',
39
- text: langRes.batchUploading.parseFailure
40
- },
41
- waitUploading: {
42
- key: 'batchUploading.waitUploading',
43
- text: langRes.batchUploading.waitUploading
44
- },
45
- button: {
46
- upload: {
47
- key: 'batchUploading.button.upload',
48
- text: langRes.batchUploading.button.upload
49
- },
50
- save: {
51
- key: 'batchUploading.button.save',
52
- text: langRes.batchUploading.button.save
53
- },
54
- open: {
55
- key: 'batchUploading.button.open',
56
- text: langRes.batchUploading.button.open
57
- },
58
- confirm: {
59
- key: 'batchUploading.button.confirm',
60
- text: langRes.batchUploading.button.confirm
61
- }
62
- },
63
- errorTitle: {
64
- key: 'batchUploading.errorTitle',
65
- text: langRes.batchUploading.errorTitle
66
- },
67
- sheetName: {
68
- key: 'batchUploading.sheetName',
69
- text: langRes.batchUploading.sheetName
70
- },
71
- textValid: {
72
- key: 'batchUploading.textValid',
73
- text: langRes.batchUploading.textValid
74
- },
75
- textInvalid: {
76
- key: 'batchUploading.textInvalid',
77
- text: langRes.batchUploading.textInvalid
78
- }
79
- };
80
- export default i18nKeys;
@@ -1,29 +0,0 @@
1
- import { i18nUtils } from "@ticatec/i18n";
2
- const langRes = {
3
- batchUploading: {
4
- status: {
5
- pending: "To upload",
6
- uploading: "Uploading...",
7
- successful: "Success",
8
- fail: "Failure"
9
- },
10
- parsing: "Parsing file...",
11
- parseFailure: "Cannot parse file: {{name}}",
12
- waitUploading: "Cannot exit during uploading!",
13
- button: {
14
- upload: "Upload",
15
- save: "Save error data",
16
- open: "Open",
17
- confirm: "Confirm"
18
- },
19
- errorTitle: "Error",
20
- sheetName: "Abnormal data",
21
- labelStatus: "Status",
22
- labelValid: "Validity",
23
- textValid: "Yes",
24
- textInvalid: "No",
25
- labelHint: "Hint"
26
- }
27
- };
28
- const i18nRes = i18nUtils.createResourceProxy(langRes, 'omni');
29
- export default i18nRes;
@@ -1,3 +0,0 @@
1
- import cn_resource from "./batch_cn_resource";
2
- import en_resource from "./batch_en_resource";
3
- export { cn_resource, en_resource };
@@ -1,3 +0,0 @@
1
- import cn_resource from "./batch_cn_resource";
2
- import en_resource from "./batch_en_resource";
3
- export { cn_resource, en_resource };
File without changes