Files
ALL-teach_sys/frontend_化工/update_project_units.py
KQL cd2e307402 初始化12个产业教务系统项目
主要内容:
- 包含12个产业的完整教务系统前端代码
- 智能启动脚本 (start-industry.sh)
- 可视化产业导航页面 (index.html)
- 项目文档 (README.md)

优化内容:
- 删除所有node_modules和.yoyo文件夹,从7.5GB减少到2.7GB
- 添加.gitignore文件避免上传不必要的文件
- 自动依赖管理和智能启动系统

产业列表:
1. 文旅产业 (5150)
2. 智能制造 (5151)
3. 智能开发 (5152)
4. 财经商贸 (5153)
5. 视觉设计 (5154)
6. 交通物流 (5155)
7. 大健康 (5156)
8. 土木水利 (5157)
9. 食品产业 (5158)
10. 化工产业 (5159)
11. 能源产业 (5160)
12. 环保产业 (5161)

🤖 Generated with Claude Code
Co-Authored-By: Claude <noreply@anthropic.com>
2025-09-24 14:14:14 +08:00

135 lines
4.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import re
import datetime
import shutil
def get_correct_units_from_json():
"""从化工项目案例.json获取每个项目的正确单元名称"""
# 读取化工项目案例数据
with open('网页未导入数据/化工产业/化工项目案例.json', 'r', encoding='utf-8') as f:
data = json.load(f)
project_units = {}
for i, project in enumerate(data, 1):
unit_name = project.get('对应单元名称(复合能力课)', '').strip()
# 如果有多个单元名称,取第一个作为主要单元
if unit_name:
# 用逗号分割,取第一个
primary_unit = unit_name.split(',')[0].strip()
else:
primary_unit = '化工单元操作' # 默认单元
project_units[i] = primary_unit
return project_units
def update_project_units():
"""更新项目详情中的unit字段"""
# 获取正确的单元数据
correct_units = get_correct_units_from_json()
# 读取mock文件
with open('src/mocks/projectLibraryMock.js', 'r', encoding='utf-8') as f:
content = f.read()
# 统计更新
updates_made = 0
# 首先更新项目列表中的unit字段
print("更新项目列表中的unit字段")
for project_id, unit_name in correct_units.items():
print(f"\n项目 {project_id}: {unit_name}")
# 查找并替换项目列表中的unit字段
# 模式在projects数组中查找项目ID后的unit字段
pattern = rf'("id":\s*{project_id},[\s\S]*?"unit":\s*")[^"]*(")'
# 替换为新的单元名称
def replacer(match):
return f'{match.group(1)}{unit_name}{match.group(2)}'
new_content = re.sub(pattern, replacer, content)
if new_content != content:
content = new_content
updates_made += 1
print(f" ✅ 已更新项目列表")
else:
print(f" ⚠️ 未找到项目列表中的unit字段")
# 然后更新项目详情中的unit字段
print("\n更新项目详情中的unit字段")
for project_id, unit_name in correct_units.items():
print(f"\n项目详情 {project_id}: {unit_name}")
# 在getMockProjectDetail函数中查找并替换
# 查找模式在项目详情中的unit字段
detail_pattern = rf'({{[\s\S]*?"id":\s*{project_id},[\s\S]*?"unit":\s*")[^"]*(")'
# 在函数内容中查找
detail_match = re.search(r'export const getMockProjectDetail.*?const projects = \[([\s\S]*?)\];', content)
if detail_match:
detail_content = detail_match.group(1)
# 在详情内容中查找特定项目的unit字段
project_pattern = rf'({{[\s\S]*?"id":\s*{project_id},[\s\S]*?"unit":\s*")[^"]*(")'
def detail_replacer(match):
return f'{match.group(1)}{unit_name}{match.group(2)}'
new_detail_content = re.sub(project_pattern, detail_replacer, detail_content)
if new_detail_content != detail_content:
# 替换整个详情部分
full_detail_pattern = r'(export const getMockProjectDetail.*?const projects = \[)([\s\S]*?)(\];)'
content = re.sub(full_detail_pattern, rf'\1{new_detail_content}\3', content)
updates_made += 1
print(f" ✅ 已更新项目详情")
else:
print(f" ⚠️ 未找到项目详情中的unit字段")
# 保存更新后的文件
with open('src/mocks/projectLibraryMock.js', 'w', encoding='utf-8') as f:
f.write(content)
print(f"\n{'=' * 60}")
print(f"✅ 共更新了 {updates_made} 个项目的unit字段")
# 验证语法
import subprocess
result = subprocess.run(['node', '-c', 'src/mocks/projectLibraryMock.js'],
capture_output=True, text=True)
if result.returncode == 0:
print("✅ JavaScript语法检查通过")
else:
print(f"❌ JavaScript语法错误: {result.stderr}")
def show_unit_mapping():
"""显示项目单元名称映射"""
correct_units = get_correct_units_from_json()
print("项目单元名称映射:")
print("=" * 60)
for project_id, unit_name in correct_units.items():
print(f"项目 {project_id}: {unit_name}")
if __name__ == "__main__":
# 备份原文件
timestamp = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
backup_file = f"src/mocks/projectLibraryMock.js.backup_units_{timestamp}"
shutil.copy('src/mocks/projectLibraryMock.js', backup_file)
print(f"✅ 已备份到: {backup_file}")
# 显示映射关系
show_unit_mapping()
print("\n开始更新...")
# 执行更新
update_project_units()