update at 2026-02-14 11:20:38
This commit is contained in:
@@ -863,19 +863,16 @@ Page({
|
||||
|
||||
/**
|
||||
* 统一读取并解析文件。
|
||||
* - CSV 按 utf8 文本读取
|
||||
* - XLS/XLSX 按二进制读取
|
||||
* - 统一按二进制读取,交由解析器根据内容与后缀判断
|
||||
* - 避免上传文件名缺失/后缀错误时误按 CSV 读取(出现 PK... 头)
|
||||
*/
|
||||
readAndApplyFile(filePath, fileName, onReadFailPrefix) {
|
||||
const that = this;
|
||||
const extension = getFileExtension(fileName) || getFileExtension(getBaseNameFromPath(filePath));
|
||||
const isCsvFile = extension === 'csv';
|
||||
const readOptions = {
|
||||
filePath,
|
||||
success(readRes) {
|
||||
try {
|
||||
const filePayload = isCsvFile ? String(readRes.data || '') : readRes.data;
|
||||
const table = parseTableByFileName(fileName, filePayload);
|
||||
const table = parseTableByFileName(fileName, readRes.data);
|
||||
that.applyParsedTable(table, fileName);
|
||||
} catch (error) {
|
||||
that.setData({
|
||||
@@ -891,9 +888,6 @@ Page({
|
||||
that.refreshInfoLogs();
|
||||
}
|
||||
};
|
||||
if (isCsvFile) {
|
||||
readOptions.encoding = 'utf8';
|
||||
}
|
||||
wx.getFileSystemManager().readFile(readOptions);
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user