import re import os filepath = '/Users/fanhong/UGIT/shudao-main/shudao-vue-frontend/src/views/ExamWorkshop.vue' with open(filepath, 'r', encoding='utf-8') as f: content = f.read() parts = content.split('', rest) script_content_original = script_match.group(1) script_content = script_content_original # Add questionBasis if 'const questionBasis = ref("");' not in script_content: script_content = script_content.replace( 'const examName = ref("桥梁工程施工技术考核");', 'const examName = ref("");\nconst questionBasis = ref("");') # Modify questionTypes old_qtypes = """const questionTypes = ref([ { name: "单选题", scorePerQuestion: 5, questionCount: 5, romanNumeral: "一" }, { name: "判断题", scorePerQuestion: 3, questionCount: 5, romanNumeral: "二" }, { name: "多选题", scorePerQuestion: 8, questionCount: 5, romanNumeral: "三" }, { name: "简答题", scorePerQuestion: 10, questionCount: 2, romanNumeral: "四" }, ]);""" new_qtypes = """const questionTypes = ref([ { key: 'single', name: "单选题", scorePerQuestion: 2, questionCount: 15, romanNumeral: "一", max: 50 }, { key: 'judge', name: "判断题", scorePerQuestion: 2, questionCount: 10, romanNumeral: "二", max: 50 }, { key: 'multiple', name: "多选题", scorePerQuestion: 3, questionCount: 10, romanNumeral: "三", max: 50 }, { key: 'short', name: "简答题", scorePerQuestion: 10, questionCount: 2, romanNumeral: "四", max: 10 }, ]);""" script_content = script_content.replace(old_qtypes, new_qtypes) # Modify totalScore to be computed old_total_score = 'const totalScore = ref(100);' new_total_score = '''const totalScore = computed(() => { return questionTypes.value.reduce((total, type) => { return total + (type.scorePerQuestion * type.questionCount); }, 0); });''' script_content = script_content.replace(old_total_score, new_total_score) # Replace projectType usage in fetchExamPrompt script_content = script_content.replace( "projectType: projectTypes[selectedProjectType.value]?.name || '',", "projectType: questionBasis.value,") # Clear config logic script_content = script_content.replace("const clearSettings = () => {", """const clearSettings = () => { examName.value = ''; questionBasis.value = ''; removeSelectedFile(); questionTypes.value.forEach(t => t.questionCount = 0); """) # 2. Build new template new_template = """\n""" # Replace script content = content.replace(script_content_original, script_content) # We rebuild the content from parts using the new template. # But since we have `rest`, let's do this: # 1. Update `