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 = """ 历史记录 正在加载历史记录... {{ item.title }} {{ item.time }} 暂无数据 试卷名称 {{ examName.length }}/32 出题依据内容 cloud_upload 从PPT生成考题 上传培训PPT,智能提取关键内容生成考题(单个文件可上传20M内) 已上传: {{ selectedFile.name }} × chevron_right 题型配置 试卷总分 {{ totalScore }} {{ type.name }} 每题 {{ type.scorePerQuestion }} 分 数量 {{ type.questionCount }} {{ currentExam?.title || examName }} download 下载Word {{ currentExam?.title || examName }} 总分: {{ currentExam?.totalScore || totalScore }}分 题量: {{ currentExam?.totalQuestions || 0 }}题 生成时间: {{ currentTime }} {{ expandedSections.single ? 'remove' : 'add' }} 单选题 (每题{{ currentExam.singleChoice.scorePerQuestion }}分, 共{{ currentExam.singleChoice.totalScore }}分) {{ currentExam.singleChoice.count }}题 {{ expandedSections.single ? 'expand_less' : 'expand_more' }} {{ qIndex + 1 }}.{{ q.text }} {{ opt.key }}.{{ opt.text }} 正确答案:{{ q.selectedAnswer }} {{ expandedSections.judge ? 'remove' : 'add' }} 判断题 (每题{{ currentExam.judge.scorePerQuestion }}分, 共{{ currentExam.judge.totalScore }}分) {{ currentExam.judge.count }}题 {{ expandedSections.judge ? 'expand_less' : 'expand_more' }} {{ qIndex + 1 }}.{{ q.text }} 正确答案:{{ q.selectedAnswer }} {{ expandedSections.multiple ? 'remove' : 'add' }} 多选题 (每题{{ currentExam.multiple.scorePerQuestion }}分, 共{{ currentExam.multiple.totalScore }}分) {{ currentExam.multiple.count }}题 {{ expandedSections.multiple ? 'expand_less' : 'expand_more' }} {{ qIndex + 1 }}.{{ q.text }} check {{ opt.key }}.{{ opt.text }} 正确答案:{{ q.selectedAnswers.join(', ') }} {{ expandedSections.short ? 'remove' : 'add' }} 简答题 (每题{{ currentExam.short.scorePerQuestion }}分, 共{{ currentExam.short.totalScore }}分) {{ currentExam.short.count }}题 {{ expandedSections.short ? 'expand_less' : 'expand_more' }} {{ qIndex + 1 }}.{{ q.text }} lightbulb答题要点: \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 `
上传培训PPT,智能提取关键内容生成考题(单个文件可上传20M内)