Files
online_sys/frontend_财经商贸/fix_positions_data.py
KQL a7242f0c69 Initial commit: 教务系统在线平台
- 包含4个产业方向的前端项目:智能开发、智能制造、大健康、财经商贸
- 已清理node_modules、.yoyo等大文件,项目大小从2.6GB优化至631MB
- 配置完善的.gitignore文件

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2025-12-12 18:16:55 +08:00

121 lines
3.7 KiB
Python

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import json
import re
# 读取原始的mock文件来获取项目列表中的positions数据
with open('src/mocks/projectLibraryMock.js', 'r', encoding='utf-8') as f:
content = f.read()
# 提取projects数组
projects_match = re.search(r'const projects = (\[[\s\S]*?\]);', content)
if not projects_match:
print("未找到projects数组")
exit(1)
# 解析projects数组
projects_list = json.loads(projects_match.group(1))
# 创建ID到positions的映射
positions_map = {}
for project in projects_list:
project_id = project['id']
positions = []
# 将positions字符串数组转换为对象数组
if 'positions' in project and project['positions']:
for pos in project['positions']:
# 根据岗位名称判断等级
if '助理' in pos or '技术员' in pos or 'CAD制图员' in pos:
level = '普通岗'
elif '工程师' in pos or '主管' in pos or '设计师' in pos and '助理' not in pos:
level = '技术骨干岗'
elif '经理' in pos or '总监' in pos:
level = '储备干部岗'
else:
level = '技术骨干岗' # 默认为技术骨干岗
positions.append({
'level': level,
'position': pos
})
positions_map[project_id] = positions
# 现在更新getMockProjectDetail函数
# 找到getMockProjectDetail函数的起始位置
function_start = content.find('export const getMockProjectDetail = (id) => {')
if function_start == -1:
print("未找到getMockProjectDetail函数")
exit(1)
# 找到函数结束位置
function_end = content.find('\n};', function_start) + 3
# 提取函数内部的projects数组
inner_match = re.search(r'const projects = (\[[\s\S]*?\]);', content[function_start:function_end])
if not inner_match:
print("未找到函数内的projects数组")
exit(1)
# 解析内部projects数组
inner_projects = json.loads(inner_match.group(1))
# 更新每个项目的positions字段
for project in inner_projects:
if project['id'] in positions_map:
project['positions'] = positions_map[project['id']]
# 重新构建函数
new_function = '''// 项目详情Mock数据 - 智能制造
export const getMockProjectDetail = (id) => {
// 直接根据ID返回对应项目的详情
const projects = '''
new_function += json.dumps(inner_projects, ensure_ascii=False, indent=2)
new_function += ''';
const project = projects.find(p => p.id === parseInt(id));
if (project) {
return {
success: true,
data: {
id: project.id,
title: project.name,
overview: project.overview || '暂无项目概述',
applicablePositions: project.positions || [],
units: [project.unit],
process: project.process || '项目流程详情暂未录入',
keyPoints: project.keyPoints || '关键技术点暂未录入',
// 附件板块保留,但显示暂无附件
attachments: []
}
};
}
return {
success: false,
message: "项目不存在"
};
};'''
# 替换函数
new_content = content[:function_start] + new_function + content[function_end:]
# 写回文件
with open('src/mocks/projectLibraryMock.js', 'w', encoding='utf-8') as f:
f.write(new_content)
print("✅ 成功修复项目详情中的岗位数据!")
# 打印一些示例
for i in range(min(3, len(inner_projects))):
project = inner_projects[i]
print(f"\n项目 {project['id']}: {project['name']}")
print(f" 岗位数量: {len(project['positions'])}")
if project['positions']:
for pos in project['positions'][:3]:
print(f" - {pos['position']} ({pos['level']})")