update at 2026-02-13 22:45:23
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
const { parseTableByFileName, buildSankeyData } = require('../../utils/sankey');
|
||||
const defaultSankeyTable = require('../../data/sankey.default.json');
|
||||
|
||||
/**
|
||||
* 将表头标准化,便于做中英文别名匹配。
|
||||
@@ -130,7 +131,12 @@ const TARGET_ALIGN_OPTIONS = [
|
||||
{ value: 'bottom', label: '底部' }
|
||||
];
|
||||
const DEFAULT_SANKEY_FILE_NAME = 'data/sankey.xlsx';
|
||||
const DEFAULT_SANKEY_FILE_PATHS = ['/data/sankey.xlsx', 'data/sankey.xlsx'];
|
||||
const DEFAULT_SANKEY_FILE_PATHS = [
|
||||
'/data/sankey.xlsx',
|
||||
'/miniapp/data/sankey.xlsx',
|
||||
'data/sankey.xlsx',
|
||||
'miniapp/data/sankey.xlsx'
|
||||
];
|
||||
|
||||
/**
|
||||
* 数值限制,避免 UI 参数导致布局异常。
|
||||
@@ -658,16 +664,31 @@ Page({
|
||||
*/
|
||||
loadDefaultSankeyFile() {
|
||||
const that = this;
|
||||
const tryReadByIndex = (index, lastErrorMessage) => {
|
||||
if (index >= DEFAULT_SANKEY_FILE_PATHS.length) {
|
||||
const applyBuiltInTableFallback = (reasonText) => {
|
||||
const hasRows =
|
||||
defaultSankeyTable &&
|
||||
Array.isArray(defaultSankeyTable.headers) &&
|
||||
Array.isArray(defaultSankeyTable.rows) &&
|
||||
defaultSankeyTable.rows.length > 0;
|
||||
|
||||
if (!hasRows) {
|
||||
that.setData({
|
||||
uploadMessage: '点击上传或将csv/xls文件拖到这里上传',
|
||||
parseError: `默认文件加载失败: ${lastErrorMessage || `未找到 ${DEFAULT_SANKEY_FILE_NAME}`}`
|
||||
parseError: `默认文件加载失败: ${reasonText || `未找到 ${DEFAULT_SANKEY_FILE_NAME}`}`
|
||||
});
|
||||
that.refreshInfoLogs();
|
||||
return;
|
||||
}
|
||||
|
||||
that.applyParsedTable(defaultSankeyTable, `${DEFAULT_SANKEY_FILE_NAME}(内置回退)`);
|
||||
};
|
||||
|
||||
const tryReadByIndex = (index, lastErrorMessage) => {
|
||||
if (index >= DEFAULT_SANKEY_FILE_PATHS.length) {
|
||||
applyBuiltInTableFallback(lastErrorMessage);
|
||||
return;
|
||||
}
|
||||
|
||||
const candidatePath = DEFAULT_SANKEY_FILE_PATHS[index];
|
||||
wx.getFileSystemManager().readFile({
|
||||
filePath: candidatePath,
|
||||
|
||||
Reference in New Issue
Block a user