update at 2026-02-14 11:16:40
This commit is contained in:
@@ -66,6 +66,15 @@ function getFileExtension(fileName) {
|
||||
return lowerName.slice(lastDotIndex + 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 从路径提取文件名,兼容 Unix/Windows 路径分隔符。
|
||||
*/
|
||||
function getBaseNameFromPath(filePath) {
|
||||
const normalized = String(filePath || '').replace(/\\/g, '/');
|
||||
const segments = normalized.split('/');
|
||||
return segments[segments.length - 1] || '';
|
||||
}
|
||||
|
||||
const FALLBACK_THEME_COLORS = ['#9b6bc2', '#7e95f7', '#4cc9f0', '#f4a261'];
|
||||
|
||||
/**
|
||||
@@ -859,7 +868,7 @@ Page({
|
||||
*/
|
||||
readAndApplyFile(filePath, fileName, onReadFailPrefix) {
|
||||
const that = this;
|
||||
const extension = getFileExtension(fileName);
|
||||
const extension = getFileExtension(fileName) || getFileExtension(getBaseNameFromPath(filePath));
|
||||
const isCsvFile = extension === 'csv';
|
||||
const readOptions = {
|
||||
filePath,
|
||||
@@ -960,8 +969,12 @@ Page({
|
||||
if (!picked) {
|
||||
return;
|
||||
}
|
||||
const filePath = picked.path;
|
||||
const fileName = picked.name || 'unknown.csv';
|
||||
const filePath = picked.path || picked.tempFilePath || '';
|
||||
const fileName =
|
||||
picked.name ||
|
||||
getBaseNameFromPath(filePath) ||
|
||||
// 无法识别文件名时,默认按二进制读取,交由解析器做内容识别。
|
||||
'upload.bin';
|
||||
that.readAndApplyFile(filePath, fileName, '读取文件失败');
|
||||
},
|
||||
fail(err) {
|
||||
|
||||
Reference in New Issue
Block a user