fast-cocos 1.0.0 → 1.0.3
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/dist/xlsx/src/XlsxParser.js +76 -3
- package/package.json +1 -1
|
@@ -100,7 +100,8 @@ class XlsxParser {
|
|
|
100
100
|
intros,
|
|
101
101
|
types,
|
|
102
102
|
fields,
|
|
103
|
-
data
|
|
103
|
+
data,
|
|
104
|
+
firstColumnMergedArray: SheetType.Array == sheetType && this.isFirstColumnMergedArray(data)
|
|
104
105
|
};
|
|
105
106
|
console.info("\x1b[36m%s\x1b[0m", "解析表: " + name);
|
|
106
107
|
switch (sheetType) {
|
|
@@ -108,7 +109,12 @@ class XlsxParser {
|
|
|
108
109
|
this.parseMap(sheetInfo);
|
|
109
110
|
break;
|
|
110
111
|
case SheetType.Array:
|
|
111
|
-
|
|
112
|
+
if (sheetInfo.firstColumnMergedArray) {
|
|
113
|
+
this.parseFirstColumnMergedArray(sheetInfo);
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
this.parseArray(sheetInfo);
|
|
117
|
+
}
|
|
112
118
|
break;
|
|
113
119
|
case SheetType.KVMap:
|
|
114
120
|
this.parseKVMap(sheetInfo);
|
|
@@ -176,6 +182,62 @@ class XlsxParser {
|
|
|
176
182
|
// 写json文件
|
|
177
183
|
this.writeSheetSync(sheetInfo.outPath, content);
|
|
178
184
|
}
|
|
185
|
+
/**
|
|
186
|
+
* 解析首列合并行数组
|
|
187
|
+
* @param sheetInfo 工作表信息
|
|
188
|
+
*/
|
|
189
|
+
parseFirstColumnMergedArray(sheetInfo) {
|
|
190
|
+
const { types, fields, data } = sheetInfo;
|
|
191
|
+
// 类型声明
|
|
192
|
+
this.parseTypeDeclare(sheetInfo);
|
|
193
|
+
// 解析内容
|
|
194
|
+
const content = [];
|
|
195
|
+
let group;
|
|
196
|
+
for (let i = 0; i < data.length; ++i) {
|
|
197
|
+
const col = data[i];
|
|
198
|
+
if (col[0]) {
|
|
199
|
+
const columns = data.map((v) => v[0]);
|
|
200
|
+
group = {
|
|
201
|
+
[fields[0]]: this.parseValue(types[0], col[0], columns),
|
|
202
|
+
arr: []
|
|
203
|
+
};
|
|
204
|
+
content.push(group);
|
|
205
|
+
}
|
|
206
|
+
const info = this.parseRowInfo(sheetInfo, col);
|
|
207
|
+
if (group && Object.keys(info).length) {
|
|
208
|
+
group.arr.push(info);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
// 写json文件
|
|
212
|
+
this.writeSheetSync(sheetInfo.outPath, content);
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 解析行数据
|
|
216
|
+
* @param sheetInfo 工作表信息
|
|
217
|
+
* @param row 行数据
|
|
218
|
+
*/
|
|
219
|
+
parseRowInfo(sheetInfo, row) {
|
|
220
|
+
const { types, fields, data } = sheetInfo;
|
|
221
|
+
const info = {};
|
|
222
|
+
for (let i = 0; i < row.length; ++i) {
|
|
223
|
+
const field = fields[i];
|
|
224
|
+
if (field) {
|
|
225
|
+
const columns = data.map((v) => v[i]);
|
|
226
|
+
info[field] = this.parseValue(types[i], row[i], columns);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return info;
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* 是否首列合并行数组
|
|
233
|
+
* @param data 数据行
|
|
234
|
+
*/
|
|
235
|
+
isFirstColumnMergedArray(data) {
|
|
236
|
+
if (data.length <= 0 || !data[0][0]) {
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
return data.some((row, index) => index > 0 && !row[0] && row.some((value) => value));
|
|
240
|
+
}
|
|
179
241
|
/**
|
|
180
242
|
* 解析键值表
|
|
181
243
|
* @param sheetInfo 工作表信息
|
|
@@ -446,7 +508,18 @@ class XlsxParser {
|
|
|
446
508
|
}
|
|
447
509
|
this.pushUnique(lines, `}\n`, 0);
|
|
448
510
|
this.pushUnique(lines, `/** ${xlsxName} */`, 0);
|
|
449
|
-
|
|
511
|
+
if (sheetInfo.firstColumnMergedArray) {
|
|
512
|
+
const type = this.removeExtraType(types[0]);
|
|
513
|
+
lines.push(`interface ${basename}Group {`);
|
|
514
|
+
lines.push(` /** ${intros[0]} */`);
|
|
515
|
+
lines.push(` readonly ${fields[0]}: ${type};`);
|
|
516
|
+
lines.push(` readonly arr: ${basename}[];`);
|
|
517
|
+
lines.push(`}\n`);
|
|
518
|
+
lines.push(`type ${typeName} = ${basename}Group[];`);
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
this.pushUnique(lines, `type ${typeName} = ${basename}[];`, 0);
|
|
522
|
+
}
|
|
450
523
|
this.declareMap.set(typeName, lines);
|
|
451
524
|
break;
|
|
452
525
|
}
|