You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
189 lines
5.6 KiB
189 lines
5.6 KiB
// 统一任务配置入口文件
|
|
|
|
import type { TaskConfig, FieldConfig } from './taskConfigTypes';
|
|
import { DOCUMENT_TASK_CONFIGS, getDocumentTaskConfig } from './documentTaskConfigs';
|
|
import { CONTRACT_TASK_CONFIGS, getContractTaskConfig } from './contractTaskConfigs';
|
|
import { TENDER_TASK_CONFIGS, getTenderTaskConfig } from './tenderTaskConfigs';
|
|
import {
|
|
loadDocumentTaskConfigs,
|
|
loadContractTaskConfigs,
|
|
loadTenderTaskConfigs,
|
|
isJsonConfigAvailable,
|
|
clearConfigCache
|
|
} from './jsonConfigLoader';
|
|
|
|
// 合并所有任务配置
|
|
const ALL_TASK_CONFIGS: Record<string, TaskConfig> = {
|
|
...DOCUMENT_TASK_CONFIGS,
|
|
...CONTRACT_TASK_CONFIGS,
|
|
...TENDER_TASK_CONFIGS
|
|
};
|
|
|
|
// JSON配置缓存
|
|
let jsonConfigsLoaded = false;
|
|
let jsonDocumentConfigs: Record<string, TaskConfig> | null = null;
|
|
let jsonContractConfigs: Record<string, TaskConfig> | null = null;
|
|
let jsonTenderConfigs: Record<string, TaskConfig> | null = null;
|
|
|
|
/**
|
|
* 初始化JSON配置加载
|
|
*/
|
|
async function initJsonConfigs(): Promise<void> {
|
|
if (jsonConfigsLoaded) return;
|
|
|
|
try {
|
|
// 检查JSON配置是否可用
|
|
const isAvailable = await isJsonConfigAvailable();
|
|
if (!isAvailable) {
|
|
console.log('JSON配置文件不可用,使用默认TypeScript配置');
|
|
jsonConfigsLoaded = true;
|
|
return;
|
|
}
|
|
|
|
// 并行加载所有JSON配置文件
|
|
const [docConfigs, contractConfigs, tenderConfigs] = await Promise.all([
|
|
loadDocumentTaskConfigs(),
|
|
loadContractTaskConfigs(),
|
|
loadTenderTaskConfigs()
|
|
]);
|
|
|
|
jsonDocumentConfigs = docConfigs;
|
|
jsonContractConfigs = contractConfigs;
|
|
jsonTenderConfigs = tenderConfigs;
|
|
|
|
jsonConfigsLoaded = true;
|
|
|
|
const loadedCount = [docConfigs, contractConfigs, tenderConfigs].filter(Boolean).length;
|
|
console.log(`成功加载 ${loadedCount} 个JSON配置文件`);
|
|
|
|
} catch (error) {
|
|
console.error('加载JSON配置时出错:', error);
|
|
jsonConfigsLoaded = true; // 设置为已加载,避免重复尝试
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 从JSON配置中获取任务配置
|
|
*/
|
|
function getJsonTaskConfig(taskType: string): TaskConfig | null {
|
|
// 依次检查各个JSON配置
|
|
if (jsonDocumentConfigs?.[taskType]) {
|
|
return jsonDocumentConfigs[taskType];
|
|
}
|
|
|
|
if (jsonContractConfigs?.[taskType]) {
|
|
return jsonContractConfigs[taskType];
|
|
}
|
|
|
|
if (jsonTenderConfigs?.[taskType]) {
|
|
return jsonTenderConfigs[taskType];
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 从TypeScript配置中获取任务配置(原有逻辑)
|
|
*/
|
|
function getTypescriptTaskConfig(taskType: string): TaskConfig | null {
|
|
// 首先尝试从文档任务配置中获取
|
|
let config = getDocumentTaskConfig(taskType);
|
|
if (config) return config;
|
|
|
|
// 然后尝试从合同任务配置中获取
|
|
config = getContractTaskConfig(taskType);
|
|
if (config) return config;
|
|
|
|
// 最后尝试从招投标任务配置中获取
|
|
config = getTenderTaskConfig(taskType);
|
|
if (config) return config;
|
|
|
|
return null;
|
|
}
|
|
|
|
// 统一的获取任务配置函数
|
|
export async function getTaskConfig(taskType: string): Promise<TaskConfig | null> {
|
|
// 确保JSON配置已初始化
|
|
await initJsonConfigs();
|
|
|
|
// 优先从JSON配置获取
|
|
const jsonConfig = getJsonTaskConfig(taskType);
|
|
if (jsonConfig) {
|
|
console.log(`使用JSON配置: ${taskType}`);
|
|
return jsonConfig;
|
|
}
|
|
|
|
// 回退到TypeScript配置
|
|
const tsConfig = getTypescriptTaskConfig(taskType);
|
|
if (tsConfig) {
|
|
console.log(`使用TypeScript配置: ${taskType}`);
|
|
return tsConfig;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 同步版本的获取配置函数(用于向后兼容)
|
|
* 注意:这个函数只会返回TypeScript配置,建议迁移到异步版本
|
|
*/
|
|
export function getTaskConfigSync(taskType: string): TaskConfig | null {
|
|
console.warn('使用同步配置获取,建议迁移到 getTaskConfig 异步版本');
|
|
return getTypescriptTaskConfig(taskType);
|
|
}
|
|
|
|
/**
|
|
* 重新加载JSON配置
|
|
*/
|
|
export async function reloadJsonConfigs(): Promise<void> {
|
|
clearConfigCache();
|
|
jsonConfigsLoaded = false;
|
|
jsonDocumentConfigs = null;
|
|
jsonContractConfigs = null;
|
|
jsonTenderConfigs = null;
|
|
await initJsonConfigs();
|
|
}
|
|
|
|
// 获取所有可用配置
|
|
export function getAvailableConfigs(): TaskConfig[] {
|
|
return Object.values(ALL_TASK_CONFIGS);
|
|
}
|
|
|
|
// 检查字段是否应该显示对比按钮
|
|
export function shouldShowComparison(fieldConfig: FieldConfig, item: any): boolean {
|
|
if (!fieldConfig.showComparison) return false;
|
|
|
|
// 获取对比字段名,默认为 modificationDisplay
|
|
const comparisonField = fieldConfig.comparisonConfig?.comparisonField || 'modificationDisplay';
|
|
|
|
// 检查对比字段是否有内容
|
|
return !!(item[comparisonField] && item[comparisonField].trim());
|
|
}
|
|
|
|
// 获取对比字段名
|
|
export function getComparisonField(fieldConfig: FieldConfig): string {
|
|
return fieldConfig.comparisonConfig?.comparisonField || 'modificationDisplay';
|
|
}
|
|
|
|
// 获取对比标题
|
|
export function getComparisonTitle(fieldConfig: FieldConfig): string {
|
|
return fieldConfig.comparisonConfig?.comparisonTitle || '修改情况展示';
|
|
}
|
|
|
|
// 检查是否应该显示对比按钮
|
|
export function shouldShowComparisonButton(fieldConfig: FieldConfig): boolean {
|
|
return fieldConfig.comparisonConfig?.showButton !== false; // 默认为true
|
|
}
|
|
|
|
// 获取字段的PDF源
|
|
export function getFieldPdfSource(fieldConfig: FieldConfig): string | null {
|
|
return fieldConfig.pdfSource || null;
|
|
}
|
|
|
|
// 检查字段是否支持PDF定位
|
|
export function supportsPdfLocation(fieldConfig: FieldConfig): boolean {
|
|
return !!(fieldConfig.pdfSource && fieldConfig.pdfSource !== 'auto');
|
|
}
|
|
|
|
// 重新导出类型
|
|
export type { TaskConfig, FieldConfig, TabConfig, PdfSourceConfig } from './taskConfigTypes';
|