#!/usr/bin/env python3 # -*- coding: utf-8 -*- import re print("开始修复industries数组的括号问题...") # 读取文件 with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js', 'r', encoding='utf-8') as f: lines = f.readlines() # 找到industries数组 start_line = -1 for i, line in enumerate(lines): if 'const industries = [' in line: start_line = i break if start_line == -1: print("未找到industries数组") exit(1) # 重新构建industries数组,确保括号正确 new_lines = lines[:start_line+1] # 保留到 const industries = [ bracket_depth = 1 # 已经有一个 [ brace_depth = 0 for i in range(start_line + 1, len(lines)): line = lines[i] # 检测是否到达数组结束 if '];' in line and bracket_depth == 1 and brace_depth == 0: # 这应该是industries数组的结束 new_lines.append('];\n') # 添加剩余的内容 new_lines.extend(lines[i+1:]) break # 统计这一行的括号 open_brackets = line.count('[') close_brackets = line.count(']') open_braces = line.count('{') close_braces = line.count('}') bracket_depth += open_brackets - close_brackets brace_depth += open_braces - close_braces # 添加这一行 new_lines.append(line) # 如果括号深度有问题,尝试修复 if i == 866: # 第867行(索引866)之前应该平衡 if brace_depth > 0: # 需要添加闭合括号 while brace_depth > 0: new_lines.append(' }\n') brace_depth -= 1 if bracket_depth > 1: while bracket_depth > 1: new_lines.append(']\n') bracket_depth -= 1 # 写回文件 with open('/Users/apple/Documents/cursor/教务系统/frontend_大健康/src/mocks/resumeInterviewMock.js', 'w', encoding='utf-8') as f: f.writelines(new_lines) print("✓ 修复完成")