replace_layout2.py 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. import re
  2. with open('src/views/ExamWorkshop.vue', 'r', encoding='utf-8') as f:
  3. content = f.read()
  4. pattern = re.compile(r'(<!-- 考试工坊主界面 -->\s*<div v-if="!showExamDetail" class="exam-workshop-card">)(.*?)(^\s*<!-- 考试详情页 -->)', re.DOTALL | re.MULTILINE)
  5. new_content = """
  6. <div v-if="!showExamDetail" class="flex-1 flex flex-row w-full h-full relative overflow-hidden" style="background-color: #f7f9fb; margin: -20px;">
  7. <-5 中间主要工作区 -->
  8. <div class="flex-1 flex flex-col h-full relative min-w-0">
  9. <div class="flex-1 overflow-y-auto p-10 pb-32">
  10. <div class="max-w-4xl mx-auto w-full space-y-8">
  11. <-5 试卷名称 -->
  12. <section class="space-y-3">
  13. <label class="block text-[15px] font-bold text-gray-800">试卷名称</label>
  14. <div class="relative">
  15. <input v-model="examName" class="w-full bg-white border border-gray-100 shadow-sm rounded-2xl px-5 py-4 text-[15px] focus:border-blue-500 focus:ring-2 focus:ring-blue-100 transition-all outline-none text-gray-800 placeholder-gray-400" maxlength="32" placeholder="请输入试卷名称..." type="text" :disabled="isGenerating"/>
  16. <span class="absolute right-5 bottom-4 text-xs text-gray-400">{{ examName?.length || 0 }}/32</span>
  17. </div>
  18. </section>
  19. <-5 出题依据内容 -->
  20. <section class="space-y-3">
  21. <label class="block text-[15px] font-bold text-gray-800">出题依据内容</label>
  22. <textarea v-model="questionBasis" class="w-full h-48 bg-white border border-gray-100 shadow-sm rounded-2xl px-5 py-4 text-[15px] focus:border-blue-500 focus:ring-2 focus:ring-blue-100 transition-all outline-none resize-none text-gray-800 placeholder-gray-400 leading-relaxed" placeholder="在此输入知识点、章节或培训内容..." :disabled="isGenerating || selectedFile"></textarea>
  23. <-5 从PPT生成考题 -->
  24. <div class="w-full bg-white border border-gray-100 shadow-sm rounded-2xl p-5 flex items-center gap-5 cursor-pointer hover:shadow-md transition-all group mt-6" @click="!isGenerating && !selectedFile ? triggerFileUpload() : null">
  25. <div class="w-14 h-14 rounded-2xl bg-[#f3f4f6] flex items-center justify-center text-gray-500 group-hover:text-blue-600 transition-colors">
  26. <span class="material-symbols-outlined text-3xl">cloud_upload</span>
  27. </div>
  28. <div class="flex-1">
  29. <div class="flex items-center gap-2 mb-1">
  30. <h3 class="text-base font-bold text-gray-900">从PPT生成考题</h3>
  31. </div>
  32. <p class="text-[13px] text-gray-500">上传培训PPT,智能提取关键内容生成考题(单个文件可上传20M内)</p>
  33. <div v-if="selectedFile" class="mt-3 p-2.5 bg-blue-50/80 rounded-xl text-blue-600 text-sm flex justify-between items-center border border-blue-100">
  34. <span class="font-medium truncate mr-4">已上传: {{ selectedFile.name }}</span>
  35. <span @click.stop="removeSelectedFile" class="cursor-pointer text-red-400 hover:text-red-600 font-bold px-2 py-1 bg-red-50 hover:bg-red-100 rounded-lg transition-colors">×</span>
  36. </div>
  37. </div>
  38. <span class="material-symbols-outlined text-gray-300">chevron_right</span>
  39. </div>
  40. </section>
  41. <-5 题型配置 -->
  42. <section class="space-y-4 pt-4">
  43. <div class="flex items-center justify-between w-full mb-6">
  44. <span class="text-[15px] font-bold text-gray-800">题型配置</span>
  45. <div class="flex items-center gap-3">
  46. <span class="text-[13px] text-gray-500">试卷总分</span>
  47. <div class="bg-white border border-gray-100 shadow-sm rounded-xl px-6 py-2.5 text-lg font-bold text-gray-900 min-w-[80px] text-center">
  48. {{ calculatedTotalScore }}
  49. </div>
  50. </div>
  51. </div>
  52. <div class="grid grid-cols-2 gap-5">
  53. <div v-for="(type, index) in questionTypes" :key="index" class="bg-white rounded-2xl border border-gray-100 shadow-sm p-6 hover:shadow-md transition-shadow">
  54. <div class="flex justify-between items-center mb-8">
  55. <span class="text-[15px] font-bold text-gray-900">{{ type.name }}</span>
  56. <span class="text-[13px] font-medium bg-[#ebf3ff] text-blue-600 px-3.5 py-1.5 rounded-full">每题 {{ type.scorePerQuestion }} 分</span>
  57. </div>
  58. <div class="space-y-4">
  59. <div class="flex justify-between items-center text-[13px] font-bold mb-2">
  60. <span class="text-gray-500">数量</span>
  61. <span class="text-blue-600 text-base">{{ type.questionCount }}</span>
  62. </div>
  63. <div class="relative w-full h-1.5 bg-gray-100 rounded-full mt-2">
  64. <input type="range" v-model.number="type.questionCount" min="0" :max="type.max || 50" class="absolute top-0 left-0 w-full h-full opacity-0 cursor-pointer z-10" :disabled="isGenerating">
  65. <div class="absolute top-0 left-0 h-full bg-blue-600 rounded-full pointer-events-none" :style="{ width: (type.questionCount / (type.max || 50) * 100) + '%' }"></div>
  66. <div class="absolute top-1/2 -translate-y-1/2 w-4 h-4 bg-white border-[3px] border-blue-600 rounded-full shadow-sm pointer-events-none transition-all" :style="{ left: (type.questionCount / (type.max || 50) * 100) + '%', transform: 'translate(-50%, -50%)' }"></div>
  67. </div>
  68. </div>
  69. </div>
  70. </div>
  71. </section>
  72. </div>
  73. </div>
  74. <-5 底部悬浮操作栏 -->
  75. <footer class="absolute bottom-0 left-0 w-full bg-white/95 backdrop-blur-xl border-t border-gray-100 px-8 py-5 flex items-center justify-between z-40">
  76. <div class="flex items-center gap-4">
  77. <button class="flex items-center gap-2.5 text-gray-500 hover:text-red-500 transition-colors px-2" @click="clearSettings" :disabled="isGenerating">
  78. <span class="material-symbols-outlined text-[20px]">delete</span>
  79. <span class="text-[14px] font-medium">清空当前配置</span>
  80. </button>
  81. </div>
  82. <button v-if="!isGenerating" class="bg-blue-600 hover:bg-blue-700 text-white px-8 py-3 rounded-xl text-[15px] font-bold shadow-lg shadow-blue-600/20 flex items-center justify-center transition-all active:scale-[0.98]" @click="generateExam">
  83. 开始智能生成试卷
  84. </button>
  85. <button v-else class="bg-blue-400 text-white px-8 py-3 rounded-xl text-[15px] font-bold shadow-md flex items-center justify-center cursor-not-allowed">
  86. <span class="flex items-center gap-2">
  87. <span class="material-symbols-outlined animate-spin text-lg">autorenew</span>
  88. 生成中...
  89. </span>
  90. </button>
  91. </footer>
  92. </div>
  93. <-5 右侧边栏 (实时预览) -->
  94. <aside class="w-[280px] bg-[#f7f9fb] border-l border-gray-200 flex flex-col h-full flex-shrink-0 z-30">
  95. <div class="p-7">
  96. <h2 class="text-gray-900 font-bold text-[17px] mb-7">实时预览</h2>
  97. <div class="space-y-8">
  98. <-5 试卷名称 -->
  99. <div class="bg-white p-5 rounded-2xl shadow-sm border border-gray-100">
  100. <h3 class="text-[13px] font-bold text-gray-500 mb-3.5">试卷名称</h3>
  101. <p class="text-gray-800 font-medium text-[15px] italic leading-relaxed" :class="{'opacity-40': !examName}">{{ examName || '未命名试卷...' }}</p>
  102. </div>
  103. <-5 结构大纲 -->
  104. <div class="space-y-5">
  105. <h3 class="text-[13px] font-bold text-gray-500">结构大纲</h3>
  106. <ul class="space-y-5">
  107. <li v-for="(type, index) in questionTypes" :key="index" class="flex flex-col gap-1.5 group">
  108. <div class="flex items-center justify-between">
  109. <div class="flex items-center gap-2.5">
  110. <div class="w-1.5 h-1.5 rounded-full" :style="{ backgroundColor: ['#2563eb', '#60a5fa', '#93c5fd', '#dbeafe'][index % 4] }"></div>
  111. <span class="text-[14px] font-medium text-gray-800">{{ type.name }}</span>
  112. </div>
  113. <span class="text-[14px] font-bold text-gray-800">{{ type.questionCount }}题</span>
  114. </div>
  115. <span class="text-[12px] text-gray-400 ml-4">{{ type.questionCount * type.scorePerQuestion }} 分</span>
  116. </li>
  117. </ul>
  118. </div>
  119. <-5 总分统计 -->
  120. <div class="pt-8 border-t border-gray-200 space-y-4">
  121. <div class="flex justify-between items-center">
  122. <span class="text-[13px] text-gray-500 font-medium">配置总分</span>
  123. <span class="text-[15px] font-bold text-gray-900">{{ totalScore }}</span>
  124. </div>
  125. <div class="flex justify-between items-center">
  126. <span class="text-[13px] text-gray-500 font-medium">试卷总分</span>
  127. <span class="text-[15px] font-bold text-gray-900">{{ calculatedTotalScore }}</span>
  128. </div>
  129. </div>
  130. </div>
  131. </div>
  132. </aside>
  133. </div>
  134. """
  135. replaced = pattern.sub(r'\1\n' + new_content + r'\n\3', content)
  136. # 隐藏原来的 work-header 并修改 work-content 的样式
  137. replaced = replaced.replace('<div class="work-header">', '<div class="work-header" v-if="showExamDetail">')
  138. replaced = replaced.replace('<div class="work-content" :class="{ \'exam-detail-mode\': showExamDetail }">', '<div class="work-content" :class="{ \'exam-detail-mode\': showExamDetail }" :style="showExamDetail ? {} : { padding: 0, height: \'100%\', display: \'flex\', flexDirection: \'column\' }">')
  139. with open('src/views/ExamWorkshop.vue', 'w', encoding='utf-8') as f:
  140. f.write(replaced)
  141. print("Replacement complete.")