@ticatec/batch-data-uploader 0.0.3 → 0.0.9
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/README.md +74 -121
- package/dist/BaseEncodingTemplate.d.ts +30 -0
- package/dist/BaseEncodingTemplate.js +34 -0
- package/dist/BaseTemplate.d.ts +5 -0
- package/dist/BaseTemplate.js +20 -3
- package/dist/BaseUploadTemplate.d.ts +3 -3
- package/dist/BaseUploadTemplate.js +15 -10
- package/dist/DataColumn.d.ts +4 -4
- package/dist/EncodingWizard.svelte +89 -0
- package/dist/EncodingWizard.svelte.d.ts +26 -0
- package/dist/FileUploadWizard.svelte +18 -16
- package/dist/FileUploadWizard.svelte.d.ts +1 -0
- package/dist/i18n_resources/batch_cn_resource.d.ts +1 -0
- package/dist/i18n_resources/batch_cn_resource.js +2 -1
- package/dist/i18n_resources/batch_en_resource.d.ts +5 -0
- package/dist/i18n_resources/batch_en_resource.js +16 -11
- package/dist/i18n_resources/i18nKeys.d.ts +20 -0
- package/dist/i18n_resources/i18nKeys.js +20 -0
- package/documents/BaseEncodingTemplate.md +156 -0
- package/documents/BaseEncodingTemplate_cn.md +156 -0
- package/documents/BaseTemplate.md +222 -0
- package/documents/BaseTemplate_cn.md +225 -0
- package/documents/BaseUploadTemplate.md +170 -0
- package/documents/BaseUploadTemplate_cn.md +172 -0
- package/documents/EncodingWizard.md +89 -0
- package/documents/EncodingWizard_cn.md +90 -0
- package/documents/FileUploadWizard.md +91 -0
- package/documents/FileUploadWizard_cn.md +94 -0
- package/package.json +18 -5
- package/dist/BaseLoadTemplate.d.ts +0 -18
- package/dist/BaseLoadTemplate.js +0 -25
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
|
|
2
|
+
# Excel Encoding Wizard 组件
|
|
3
|
+
|
|
4
|
+
一个基于 Svelte 的对话框组件,用于解析 Excel 文件、通过服务器端接口验证/补全数据,并显示验证结果,结合 `BaseEncodingTemplate` 实现数据处理功能。
|
|
5
|
+
|
|
6
|
+
## 概述
|
|
7
|
+
|
|
8
|
+
该组件提供了一个交互式的对话框界面,允许用户选择 Excel 文件、解析文件内容、通过服务器端接口验证和补全数据、显示数据表格,并在数据有效时提供确认操作。组件支持国际化、动态按钮操作,适用于需要验证和补全 Excel 数据的场景。
|
|
9
|
+
|
|
10
|
+
## 使用方法
|
|
11
|
+
|
|
12
|
+
将组件嵌入 Svelte 应用,并传递必要的属性。以下是一个示例:
|
|
13
|
+
|
|
14
|
+
1. 实现数据模版,定义和excel文件匹配的字段。[BaseEncodingTemplate](./BaseEncodingTemplate_cn.md)
|
|
15
|
+
2. 打开对话框,加载本地的excel文件,将触发解析和调用服务api验证数据,验证通过后,显示确认按钮。点击确认按钮会通过回传函数返回数据集。
|
|
16
|
+
|
|
17
|
+
```typescript
|
|
18
|
+
<script lang="ts">
|
|
19
|
+
import EncodingDialog from '@ticatec/batch-data-uploader/EncodingDialog.svelte';
|
|
20
|
+
import type { DataColumn } from '@ticatec/batch-data-uploader/DataColumn';
|
|
21
|
+
import MyEncodingTemplate from './MyEncodingTemplate'; // 继承自 BaseEncodingTemplate
|
|
22
|
+
|
|
23
|
+
const template = new MyEncodingTemplate();
|
|
24
|
+
|
|
25
|
+
function handleClose() {
|
|
26
|
+
console.log('Dialog closed');
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function handleConfirm(data: any[]) {
|
|
30
|
+
console.log('Confirmed data:', data);
|
|
31
|
+
}
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<ExcelEncodingDialog
|
|
35
|
+
title="验证 Excel 数据"
|
|
36
|
+
width="800px"
|
|
37
|
+
height="600px"
|
|
38
|
+
{template}
|
|
39
|
+
closeHandler={handleClose}
|
|
40
|
+
confirmCallback={handleConfirm}
|
|
41
|
+
/>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## 组件详情
|
|
45
|
+
|
|
46
|
+
### 属性
|
|
47
|
+
|
|
48
|
+
- **title**: `string`
|
|
49
|
+
- 对话框标题。
|
|
50
|
+
- **width**: `string` (默认: `"800px"`)
|
|
51
|
+
- 对话框宽度。
|
|
52
|
+
- **height**: `string` (默认: `"600px"`)
|
|
53
|
+
- 对话框高度。
|
|
54
|
+
- **template**: `BaseEncodingTemplate`
|
|
55
|
+
- `BaseEncodingTemplate` 实例,用于解析 Excel 文件、验证和补全数据。
|
|
56
|
+
- **confirmCallback**: `any`
|
|
57
|
+
- 确认按钮点击时调用的回调函数,接收解析后的数据列表(`template.list`)。
|
|
58
|
+
|
|
59
|
+
### 按钮操作
|
|
60
|
+
|
|
61
|
+
- **btnChoose**: 选择文件按钮,触发文件输入框以选择 Excel 文件。
|
|
62
|
+
- **btnConfirm**: 确认按钮,仅在数据有效(`template.valid` 为 `true`)时显示,调用 `confirmCallback` 并关闭对话框。
|
|
63
|
+
|
|
64
|
+
### 事件处理
|
|
65
|
+
|
|
66
|
+
- **文件选择**:通过隐藏的 `<input type="file">` 元素触发 `parseExcelFile`,解析选中的 Excel 文件并调用 `template.parseExcelFile` 进行验证/补全。
|
|
67
|
+
- **数据验证**:解析完成后检查 `template.valid`,如果数据有效,则添加“确认”按钮。
|
|
68
|
+
- **错误提示**:解析失败时通过 `window.Toast` 显示错误信息,并隐藏加载指示器。
|
|
69
|
+
|
|
70
|
+
## 类型
|
|
71
|
+
|
|
72
|
+
- **DataColumn**: 自定义接口,定义列元数据(继承自 `@ticatec/uniface-element/DataTable` 的 `TableColumn`)。
|
|
73
|
+
- **ButtonAction** / **ButtonActions**: 来自 `@ticatec/uniface-element/ActionBar`,定义按钮操作。
|
|
74
|
+
- **IndicatorColumn**: 来自 `@ticatec/uniface-element/DataTable`,定义行号列。
|
|
75
|
+
|
|
76
|
+
## 依赖组件
|
|
77
|
+
|
|
78
|
+
- **Dialog**: 来自 `@ticatec/uniface-element/Dialog`,提供对话框容器。
|
|
79
|
+
- **DataTable**: 来自 `@ticatec/uniface-element/DataTable`,显示数据表格。
|
|
80
|
+
- **Box**: 来自 `@ticatec/uniface-element/Box`,提供带边框的容器样式。
|
|
81
|
+
- **getI18nText**: 来自 `@ticatec/i18n`,用于国际化文本。
|
|
82
|
+
|
|
83
|
+
## 注意事项
|
|
84
|
+
|
|
85
|
+
- 确保 `BaseEncodingTemplate` 已正确实现 `isDataValid`、`encodeData` 方法和 `valid` 属性,以支持数据验证和补全。
|
|
86
|
+
- 文件输入框仅接受 `.xls` 和 `.xlsx` 格式的文件。
|
|
87
|
+
- 解析过程中会显示加载指示器(`window.Indicator`),失败时通过 `window.Toast` 显示错误提示。
|
|
88
|
+
- 确认按钮仅在 `template.valid` 为 `true` 时显示,确保只有有效数据可以提交。
|
|
89
|
+
- 依赖 `window.Indicator` 和 `window.Toast` 进行 UI 提示,需确保这些全局对象已定义。
|
|
90
|
+
- `confirmCallback` 接收解析后的完整数据列表,适合用于后续处理或提交。
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
# FileUploadWizard Component
|
|
2
|
+
|
|
3
|
+
A Svelte-based dialog component for handling Excel file uploads, parsing, and data display, integrated with `BaseUploadTemplate` to enable file parsing and batch upload functionality.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
This component provides an interactive dialog interface that allows users to select an Excel file, parse its contents, display a data table, perform upload operations, and export data containing errors. The component supports internationalization, dynamic button operations, and upload progress management, making it suitable for scenarios requiring batch processing of Excel data.
|
|
8
|
+
|
|
9
|
+
## Usage
|
|
10
|
+
|
|
11
|
+
1. Implement a data template to define fields that match the Excel file. [BaseUploadTemplate](./BaseUploadTemplate.md)
|
|
12
|
+
2. Open the dialog to load a local Excel file, which triggers parsing and displays the upload button. Clicking the upload button starts the upload process.
|
|
13
|
+
3. Upon upload completion, if there are errors, a button to save error data will be displayed. Clicking this button allows downloading the error data locally.
|
|
14
|
+
```typescript
|
|
15
|
+
<script lang="ts">
|
|
16
|
+
import ExcelUploadDialog from './ExcelUploadDialog.svelte';
|
|
17
|
+
import type { DataColumn } from './DataColumn';
|
|
18
|
+
import MyUploadTemplate from './MyUploadTemplate'; // Extends BaseUploadTemplate
|
|
19
|
+
const template = new MyUploadTemplate();
|
|
20
|
+
|
|
21
|
+
async function handleAfterUploaded() {
|
|
22
|
+
console.log('Upload completed');
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function handleClose() {
|
|
26
|
+
console.log('Dialog closed');
|
|
27
|
+
}
|
|
28
|
+
</script>
|
|
29
|
+
|
|
30
|
+
<ExcelUploadDialog
|
|
31
|
+
title="Upload Excel File"
|
|
32
|
+
width="800px"
|
|
33
|
+
height="600px"
|
|
34
|
+
{template}
|
|
35
|
+
afterUploaded={handleAfterUploaded}
|
|
36
|
+
/>
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## Component Details
|
|
40
|
+
|
|
41
|
+
### Properties
|
|
42
|
+
|
|
43
|
+
- **title**: `string`
|
|
44
|
+
- The dialog title.
|
|
45
|
+
- **width**: `string` (default: `"800px"`)
|
|
46
|
+
- The dialog width.
|
|
47
|
+
- **height**: `string` (default: `"600px"`)
|
|
48
|
+
- The dialog height.
|
|
49
|
+
- **template**: `BaseUploadTemplate`
|
|
50
|
+
- An instance of `BaseUploadTemplate` used for parsing and uploading Excel data.
|
|
51
|
+
- **afterUploaded**: `() => Promise<void>`
|
|
52
|
+
- A callback function invoked after the upload is completed.
|
|
53
|
+
|
|
54
|
+
### Button Actions
|
|
55
|
+
|
|
56
|
+
- **btnChoose**: File selection button that triggers the file input dialog.
|
|
57
|
+
- **btnUpload**: Upload button that calls `template.upload()` to perform batch uploads.
|
|
58
|
+
- **btnSave**: Save errors button that calls `template.exportErrorRowsToExcel()` to export data with errors.
|
|
59
|
+
|
|
60
|
+
### Event Handling
|
|
61
|
+
|
|
62
|
+
- **File Selection**: Triggered via a hidden `<input type="file">` element, which calls `parseExcelFile` to parse the selected Excel file.
|
|
63
|
+
- **Upload Progress**: Listens to upload progress via `template.setProgressStatusListener` to dynamically update `list`.
|
|
64
|
+
- **Close Confirmation**: Uses `confirmCloseDialog` to prevent closing the dialog during the `Uploading` state.
|
|
65
|
+
|
|
66
|
+
### Component Logic
|
|
67
|
+
|
|
68
|
+
- **Initialization**: In `onMount`, retrieves `template.columns` and sets the progress status listener.
|
|
69
|
+
- **Status Management**: Dynamically updates button states and availability based on `status`:
|
|
70
|
+
- `Init`: Displays only the "Choose File" button.
|
|
71
|
+
- `Pending`: Displays "Upload" and "Choose File" buttons.
|
|
72
|
+
- `Uploading`: Disables all buttons and changes the mouse cursor to a loading state.
|
|
73
|
+
- `Done`: If error data exists, displays "Save Errors" and "Choose File" buttons; otherwise, displays only the "Choose File" button.
|
|
74
|
+
- **File Parsing**: Calls `template.parseExcelFile` to parse the Excel file, displays a loading indicator, and handles success or failure prompts.
|
|
75
|
+
- **Data Table**: Uses the `DataTable` component to display parsed data, including an indicator column (showing row numbers).
|
|
76
|
+
|
|
77
|
+
## Types
|
|
78
|
+
|
|
79
|
+
- **ProcessStatus**: `'Init' | 'Pending' | 'Uploading' | 'Done'`
|
|
80
|
+
- Represents the data processing status.
|
|
81
|
+
- **DataColumn**: A custom interface defining column metadata (extends `TableColumn` from `@ticatec/uniface-element/DataTable`).
|
|
82
|
+
- **ButtonAction** / **ButtonActions**: From `@ticatec/uniface-element/ActionBar`, defining button operations.
|
|
83
|
+
- **IndicatorColumn**: From `@ticatec/uniface-element/DataTable`, defining the row number column.
|
|
84
|
+
|
|
85
|
+
## Notes
|
|
86
|
+
|
|
87
|
+
- Ensure `BaseUploadTemplate` correctly implements the `uploadData` method to handle the actual upload logic.
|
|
88
|
+
- The file input only accepts `.xls` and `.xlsx` file formats.
|
|
89
|
+
- A loading indicator is displayed during the upload process, and errors are shown via `window.Toast`.
|
|
90
|
+
- The dialog checks for the `Uploading` state when closing to prevent interrupting the upload.
|
|
91
|
+
- The exported error data filename is formatted as `error-${filename}`, based on the original filename.
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
|
|
2
|
+
# FileUploadWizard 组件
|
|
3
|
+
|
|
4
|
+
一个基于 Svelte 的对话框组件,用于处理 Excel 文件的上传、解析和数据显示,结合 `BaseUploadTemplate` 实现文件解析和批量上传功能。
|
|
5
|
+
|
|
6
|
+
## 概述
|
|
7
|
+
|
|
8
|
+
该组件提供了一个交互式的对话框界面,允许用户选择 Excel 文件、解析文件内容、显示数据表格、执行上传操作,并支持导出包含错误的数据。组件支持国际化、动态按钮操作和上传进度管理,适用于需要批量处理 Excel 数据的场景。
|
|
9
|
+
|
|
10
|
+
## 使用方法
|
|
11
|
+
|
|
12
|
+
1. 实现数据模版,定义和excel文件匹配的字段。[BaseUploadTemplate](./BaseUploadTemplate_cn.md)
|
|
13
|
+
2. 打开对话框,加载本地的excel文件,将触发解析,显示上传按钮。点击上传按钮会开始上传过程。
|
|
14
|
+
3. 上传完毕,如果有错误将显示保存错误数据的按钮,点击按钮可以将错误数据下载到本地
|
|
15
|
+
|
|
16
|
+
```typescript
|
|
17
|
+
<script lang="ts">
|
|
18
|
+
import ExcelUploadDialog from './ExcelUploadDialog.svelte';
|
|
19
|
+
import type { DataColumn } from './DataColumn';
|
|
20
|
+
import MyUploadTemplate from './MyUploadTemplate'; // 继承自 BaseUploadTemplate
|
|
21
|
+
const template = new MyUploadTemplate();
|
|
22
|
+
|
|
23
|
+
async function handleAfterUploaded() {
|
|
24
|
+
console.log('Upload completed');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function handleClose() {
|
|
28
|
+
console.log('Dialog closed');
|
|
29
|
+
}
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
<ExcelUploadDialog
|
|
33
|
+
title="上传 Excel 文件"
|
|
34
|
+
width="800px"
|
|
35
|
+
height="600px"
|
|
36
|
+
{template}
|
|
37
|
+
afterUploaded={handleAfterUploaded}
|
|
38
|
+
/>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 组件详情
|
|
42
|
+
|
|
43
|
+
### 属性
|
|
44
|
+
|
|
45
|
+
- **title**: `string`
|
|
46
|
+
- 对话框标题。
|
|
47
|
+
- **width**: `string` (默认: `"800px"`)
|
|
48
|
+
- 对话框宽度。
|
|
49
|
+
- **height**: `string` (默认: `"600px"`)
|
|
50
|
+
- 对话框高度。
|
|
51
|
+
- **template**: `BaseUploadTemplate`
|
|
52
|
+
- `BaseUploadTemplate` 实例,用于解析和上传 Excel 数据。
|
|
53
|
+
- **afterUploaded**: `() => Promise<void>`
|
|
54
|
+
- 上传完成后的回调函数。
|
|
55
|
+
|
|
56
|
+
### 按钮操作
|
|
57
|
+
|
|
58
|
+
- **btnChoose**: 选择文件按钮,触发文件输入框。
|
|
59
|
+
- **btnUpload**: 上传按钮,调用 `template.upload()` 执行批量上传。
|
|
60
|
+
- **btnSave**: 保存错误按钮,调用 `template.exportErrorRowsToExcel()` 导出包含错误的数据。
|
|
61
|
+
|
|
62
|
+
### 事件处理
|
|
63
|
+
|
|
64
|
+
- **文件选择**:通过隐藏的 `<input type="file">` 元素触发 `parseExcelFile`,解析选中的 Excel 文件。
|
|
65
|
+
- **上传进度**:通过 `template.setProgressStatusListener` 监听上传进度,动态更新 `list`。
|
|
66
|
+
- **关闭确认**:通过 `confirmCloseDialog` 阻止在上传中 (`Uploading`) 关闭对话框。
|
|
67
|
+
|
|
68
|
+
### 组件逻辑
|
|
69
|
+
|
|
70
|
+
- **初始化**:在 `onMount` 中获取 `template.columns` 并设置进度状态监听器。
|
|
71
|
+
- **状态管理**:根据 `status` 动态更新按钮状态和可用性:
|
|
72
|
+
- `Init`: 仅显示“选择文件”按钮。
|
|
73
|
+
- `Pending`: 显示“上传”和“选择文件”按钮。
|
|
74
|
+
- `Uploading`: 禁用所有按钮,鼠标指针变为加载状态。
|
|
75
|
+
- `Done`: 如果存在错误数据,显示“保存错误”和“选择文件”按钮;否则仅显示“选择文件”按钮。
|
|
76
|
+
- **文件解析**:调用 `template.parseExcelFile` 解析 Excel 文件,显示加载指示器,处理成功或失败的提示。
|
|
77
|
+
- **数据表格**:使用 `DataTable` 组件显示解析后的数据,包含一个指示列(显示行号)。
|
|
78
|
+
|
|
79
|
+
## 类型
|
|
80
|
+
|
|
81
|
+
- **ProcessStatus**: `'Init' | 'Pending' | 'Uploading' | 'Done'`
|
|
82
|
+
- 表示数据处理的状态。
|
|
83
|
+
- **DataColumn**: 自定义接口,定义列元数据(继承自 `@ticatec/uniface-element/DataTable` 的 `TableColumn`)。
|
|
84
|
+
- **ButtonAction** / **ButtonActions**: 来自 `@ticatec/uniface-element/ActionBar`,定义按钮操作。
|
|
85
|
+
- **IndicatorColumn**: 来自 `@ticatec/uniface-element/DataTable`,定义行号列。
|
|
86
|
+
|
|
87
|
+
## 注意事项
|
|
88
|
+
|
|
89
|
+
- 确保 `BaseUploadTemplate` 已正确实现 `uploadData` 方法,以处理实际的上传逻辑。
|
|
90
|
+
- 文件输入框仅接受 `.xls` 和 `.xlsx` 格式的文件。
|
|
91
|
+
- 上传过程中会显示加载指示器,失败时通过 `window.Toast` 显示错误提示。
|
|
92
|
+
- 关闭对话框时会检查是否处于 `Uploading` 状态,防止中断上传。
|
|
93
|
+
- 错误数据导出文件名格式为 `error-${filename}`,基于原始文件名。
|
|
94
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ticatec/batch-data-uploader",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.9",
|
|
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",
|
|
@@ -22,6 +22,7 @@
|
|
|
22
22
|
],
|
|
23
23
|
"files": [
|
|
24
24
|
"dist",
|
|
25
|
+
"documents",
|
|
25
26
|
"!dist/**/*.scss",
|
|
26
27
|
"!dist/**/*.test.*",
|
|
27
28
|
"!dist/**/*.spec.*"
|
|
@@ -46,9 +47,9 @@
|
|
|
46
47
|
"types": "./dist/BaseUploadTemplate.d.ts",
|
|
47
48
|
"import": "./dist/BaseUploadTemplate.js"
|
|
48
49
|
},
|
|
49
|
-
"./
|
|
50
|
-
"types": "./dist/
|
|
51
|
-
"import": "./dist/
|
|
50
|
+
"./BaseEncodingTemplate": {
|
|
51
|
+
"types": "./dist/BaseEncodingTemplate.ts.d.ts",
|
|
52
|
+
"import": "./dist/BaseEncodingTemplate.ts.js"
|
|
52
53
|
},
|
|
53
54
|
"./DataColumn": {
|
|
54
55
|
"types": "./dist/DataColumn.d.ts",
|
|
@@ -57,6 +58,10 @@
|
|
|
57
58
|
"./FileUploadWizard.svelte": {
|
|
58
59
|
"types": "./dist/FileUploadWizard.svelte.d.ts",
|
|
59
60
|
"import": "./dist/FileUploadWizard.svelte"
|
|
61
|
+
},
|
|
62
|
+
"./EncodingWizard.svelte.svelte": {
|
|
63
|
+
"types": "./dist/EncodingWizard.svelte.d.ts",
|
|
64
|
+
"import": "./dist/EncodingWizard.svelte"
|
|
60
65
|
}
|
|
61
66
|
},
|
|
62
67
|
"peerDependencies": {
|
|
@@ -87,5 +92,13 @@
|
|
|
87
92
|
"private": false,
|
|
88
93
|
"dependencies": {
|
|
89
94
|
"xlsx": "^0.18.5"
|
|
90
|
-
}
|
|
95
|
+
},
|
|
96
|
+
"repository": {
|
|
97
|
+
"type": "https",
|
|
98
|
+
"url": "https://github.com/ticatec/batch-upload.git"
|
|
99
|
+
},
|
|
100
|
+
"bugs": {
|
|
101
|
+
"url": "https://github.com/ticatec/batch-upload/issues"
|
|
102
|
+
},
|
|
103
|
+
"homepage": "https://github.com/ticatec/batch-upload"
|
|
91
104
|
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import BaseTemplate from "./BaseTemplate";
|
|
2
|
-
import type DataColumn from "./DataColumn";
|
|
3
|
-
export type DataFetcher = (rows: Array<any>) => Promise<Array<any>>;
|
|
4
|
-
export type CheckMatch = (o1: any, o2: any) => boolean;
|
|
5
|
-
/**
|
|
6
|
-
* 用于前台数据和服务器端的数据整合
|
|
7
|
-
*/
|
|
8
|
-
export default abstract class BaseLoadTemplate extends BaseTemplate {
|
|
9
|
-
protected fetcher: DataFetcher;
|
|
10
|
-
protected isMatch: CheckMatch;
|
|
11
|
-
protected constructor(columns: Array<DataColumn>, fetcher: DataFetcher, checkMatch: CheckMatch, rowOffset?: number);
|
|
12
|
-
/**
|
|
13
|
-
* 从服务器抓取数据,然后根据主键进行数据合并
|
|
14
|
-
* @param rows
|
|
15
|
-
* @protected
|
|
16
|
-
*/
|
|
17
|
-
protected consolidateData(rows: Array<any>): Promise<Array<any>>;
|
|
18
|
-
}
|
package/dist/BaseLoadTemplate.js
DELETED
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import BaseTemplate from "./BaseTemplate";
|
|
2
|
-
/**
|
|
3
|
-
* 用于前台数据和服务器端的数据整合
|
|
4
|
-
*/
|
|
5
|
-
export default class BaseLoadTemplate extends BaseTemplate {
|
|
6
|
-
fetcher;
|
|
7
|
-
isMatch;
|
|
8
|
-
constructor(columns, fetcher, checkMatch, rowOffset = 1) {
|
|
9
|
-
super(columns, rowOffset);
|
|
10
|
-
this.fetcher = fetcher;
|
|
11
|
-
this.isMatch = checkMatch;
|
|
12
|
-
}
|
|
13
|
-
/**
|
|
14
|
-
* 从服务器抓取数据,然后根据主键进行数据合并
|
|
15
|
-
* @param rows
|
|
16
|
-
* @protected
|
|
17
|
-
*/
|
|
18
|
-
async consolidateData(rows) {
|
|
19
|
-
let data = await this.fetcher?.(rows);
|
|
20
|
-
return rows.map(row => {
|
|
21
|
-
let item = data.find(el => this.isMatch(row, el));
|
|
22
|
-
return [...row, ...item];
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
}
|