@ticatec/batch-data-uploader 0.1.3 → 0.1.5

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,7 +1,7 @@
1
1
  import BaseTemplate from "./BaseTemplate";
2
2
  import i18nRes from "./i18n_res";
3
3
  const ValidData = `<span style="color: #76FF03">${i18nRes.textValid}</span>`;
4
- const InvalidData = `<span style="color: #ff3e00">${i18nRes.textInvalid.key}</span>`;
4
+ const InvalidData = `<span style="color: #ff3e00">${i18nRes.textInvalid}</span>`;
5
5
  export default class BaseEncodingTemplate extends BaseTemplate {
6
6
  hintColumn = {
7
7
  text: i18nRes.labelHint,
@@ -14,7 +14,7 @@ export default class BaseEncodingTemplate extends BaseTemplate {
14
14
  field: "valid",
15
15
  width: 90,
16
16
  align: 'center',
17
- escapeHTML: false, // 修复:需要渲染HTML
17
+ escapeHTML: true,
18
18
  formatter: valid => valid ? ValidData : InvalidData
19
19
  };
20
20
  /**
@@ -28,7 +28,23 @@ export default abstract class BaseTemplate {
28
28
  * @param c 列索引 (0 表示第A列)
29
29
  */
30
30
  protected getCellValue(r: number, c: number): any;
31
+ /**
32
+ * 解析表单级别的变量
33
+ * @protected
34
+ */
31
35
  protected extractFormAttributes(): void;
36
+ /**
37
+ * 添加更多的字段
38
+ * @param rowData
39
+ * @param data
40
+ * @protected
41
+ */
42
+ protected appendMoreFields(rowData: any, data: any): void;
43
+ /**
44
+ * 解析数据
45
+ * @param arr
46
+ * @protected
47
+ */
32
48
  protected extractData(arr: Array<any>): any[];
33
49
  protected wrapData(data: any): any;
34
50
  get columns(): Array<TableColumn>;
@@ -25,7 +25,7 @@ export default class BaseTemplate {
25
25
  this._list = [];
26
26
  try {
27
27
  const buffer = await file.arrayBuffer();
28
- this._workbook = XLSX.read(buffer, { type: 'array' });
28
+ this._workbook = XLSX.read(buffer, { type: 'array', cellNF: true });
29
29
  if (!this._workbook.SheetNames || this._workbook.SheetNames.length === 0) {
30
30
  throw new Error('Excel file contains no worksheets');
31
31
  }
@@ -128,10 +128,32 @@ export default class BaseTemplate {
128
128
  const cellAddress = { r, c };
129
129
  const cellRef = XLSX.utils.encode_cell(cellAddress);
130
130
  const cell = sheet[cellRef];
131
- return cell ? cell.v : null;
131
+ if (!cell || cell.v === undefined)
132
+ return null;
133
+ if (cell.t === 'n' && cell.z && /y|m|d|h|s/i.test(cell.z)) {
134
+ return new Date(Math.round((cell.v - 25569) * 86400 * 1000));
135
+ }
136
+ return cell.v;
132
137
  }
138
+ /**
139
+ * 解析表单级别的变量
140
+ * @protected
141
+ */
133
142
  extractFormAttributes() {
134
143
  }
144
+ /**
145
+ * 添加更多的字段
146
+ * @param rowData
147
+ * @param data
148
+ * @protected
149
+ */
150
+ appendMoreFields(rowData, data) {
151
+ }
152
+ /**
153
+ * 解析数据
154
+ * @param arr
155
+ * @protected
156
+ */
135
157
  extractData(arr) {
136
158
  return arr.map(item => {
137
159
  let result = {};
@@ -141,6 +163,7 @@ export default class BaseTemplate {
141
163
  utils.setNestedValue(result, col.field, utils.getNestedValue(data, col.field));
142
164
  }
143
165
  }
166
+ this.appendMoreFields(item.data, result);
144
167
  return result;
145
168
  });
146
169
  }
@@ -74,7 +74,6 @@
74
74
  const parseExcelFile = async (excelFile: File) => {
75
75
  if (excelFile) {
76
76
  const sheetNames = await openExcelFile(excelFile);
77
- console.log('sheets', sheetNames)
78
77
  let sheetName = sheetNames[0];
79
78
  if (sheetNames.length > 1) {
80
79
  sheetName = await showSheetChooseDialog(sheetNames)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ticatec/batch-data-uploader",
3
- "version": "0.1.3",
3
+ "version": "0.1.5",
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",