const fs = require('fs'); const path = require('path'); // 读取智能开发课程日历数据 const calendarData = JSON.parse( fs.readFileSync('./网页未导入数据/智能开发产业/智能开发课程日历.json', 'utf-8') ); // 读取智能开发单元背景数据 const unitBackgroundData = JSON.parse( fs.readFileSync('./网页未导入数据/智能开发产业/智能开发单元背景.json', 'utf-8') ); // 处理日历数据,转换为系统需要的格式 const allCalendarEvents = []; const unitPosters = {}; // 从单元背景数据中提取海报URL unitBackgroundData.forEach(unit => { unitPosters[unit['单元名称']] = unit['单元海报_url'] || ''; }); // 处理日历数据 let eventId = 1; calendarData.forEach((item, index) => { // 将日期格式从 YYYY/M/D 转换为 YYYY-MM-DD const dateParts = item['日期'].split('/'); const year = dateParts[0]; const month = dateParts[1].padStart(2, '0'); const day = dateParts[2].padStart(2, '0'); const formattedDate = `${year}-${month}-${day}`; // 处理时间格式 (20:00~21:00 转换为标准格式) const timeStr = item['上课时间'] || '19:30-21:30'; let startTime = '19:30'; let endTime = '21:30'; if (timeStr.includes('~')) { const timeParts = timeStr.split('~'); startTime = timeParts[0].trim(); endTime = timeParts[1].trim(); } else if (timeStr.includes('-')) { const timeParts = timeStr.split('-'); startTime = timeParts[0].trim(); endTime = timeParts[1].trim(); } // 处理个人课程 if (item['个人课程表'] && item['个人课程表'].trim()) { const courseType = item['课程阶段(个人课程)']; let eventType = 'class'; // 默认类型 // 根据课程阶段判断类型 if (courseType && courseType.includes('复合')) { eventType = 'compound-skill'; } else if (courseType && courseType.includes('垂直')) { eventType = 'vertical-skill'; } allCalendarEvents.push({ id: `event-${eventId++}`, title: item['个人课程表'], startTime: `${formattedDate} ${startTime}`, endTime: `${formattedDate} ${endTime}`, type: eventType, unit: item['所属单元(个人课程)'] || '未分类', teacher: item['导师姓名查询'] || '待定', location: item['上课地点'] || '线上', status: item['课程状态'] || '待开课', description: `${item['个人课程表']}课程`, courseStage: courseType || '复合课阶段' }); } // 处理公共课 if (item['公共课'] && item['公共课'].trim()) { allCalendarEvents.push({ id: `event-${eventId++}`, title: item['公共课'], startTime: `${formattedDate} ${startTime}`, endTime: `${formattedDate} ${endTime}`, type: 'public-course', unit: item['所属单元(公共课)'] || '公共课', teacher: item['导师姓名查询'] || '待定', location: item['上课地点'] || '线上', status: item['课程状态'] || '待开课', description: `${item['公共课']}课程`, courseStage: item['课程阶段(公共课)'] || '公共课' }); } // 处理企业高管公开课 if (item['企业高管公开课'] && item['企业高管公开课'].trim()) { allCalendarEvents.push({ id: `event-${eventId++}`, title: item['企业高管公开课'], startTime: `${formattedDate} 19:30`, endTime: `${formattedDate} 21:00`, type: 'public-course', unit: '企业高管公开课', teacher: '企业高管', location: '线上', status: item['课程状态'] || '待开课', description: `${item['企业高管公开课']}`, courseStage: '企业高管公开课' }); } // 处理1V1规划 if (item['1V1 规划阶段'] && item['1V1 规划阶段'].trim()) { allCalendarEvents.push({ id: `event-${eventId++}`, title: item['1V1 规划阶段'], startTime: `${formattedDate} 14:00`, endTime: `${formattedDate} 15:00`, type: 'one-on-one', unit: '1V1规划', teacher: '职业规划师', location: '线上', status: '待开课', description: `${item['1V1 规划阶段']}`, courseStage: '1V1规划' }); } // 处理模拟面试 if (item['模拟面试实战练习阶段'] && item['模拟面试实战练习阶段'].trim()) { allCalendarEvents.push({ id: `event-${eventId++}`, title: item['模拟面试实战练习阶段'], startTime: `${formattedDate} 15:00`, endTime: `${formattedDate} 16:30`, type: 'interview', unit: '模拟面试', teacher: '面试官', location: '线上', status: '待开课', description: `${item['模拟面试实战练习阶段']}`, courseStage: '模拟面试' }); } }); // 创建courseLiveDataImport.js文件内容 const courseLiveDataImportContent = `// 智能开发课程数据 import calendarData from "@/data/智能开发课程日历.json"; import unitBackgroundData from "@/data/智能开发单元背景.json"; // 处理日历数据 const allCalendarEvents = ${JSON.stringify(allCalendarEvents, null, 2)}; // 单元海报数据 const unitPosters = ${JSON.stringify(unitPosters, null, 2)}; export { allCalendarEvents, unitPosters };`; // 写入转换后的数据 fs.writeFileSync('./src/data/courseLiveDataImport.js', courseLiveDataImportContent, 'utf-8'); // 复制原始数据文件到src/data目录 fs.copyFileSync( './网页未导入数据/智能开发产业/智能开发课程日历.json', './src/data/智能开发课程日历.json' ); fs.copyFileSync( './网页未导入数据/智能开发产业/智能开发单元背景.json', './src/data/智能开发单元背景.json' ); console.log('✅ 日历数据转换完成!'); console.log(`- 共生成 ${allCalendarEvents.length} 个日历事件`); console.log(`- 包含 ${Object.keys(unitPosters).length} 个单元海报`); // 输出部分示例数据 console.log('\n前5个日历事件示例:'); allCalendarEvents.slice(0, 5).forEach(event => { console.log(` - ${event.startTime} | ${event.title} | ${event.type} | ${event.unit}`); });