m-ExamWorkshop.vue 97 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218
  1. <template>
  2. <div class="mobile-exam-workshop">
  3. <!-- 移动端考试工坊页面 -->
  4. <MobileHeader title="考试工坊" @back="goBack" @menu="showHistoryDrawer" />
  5. <div class="mobile-content">
  6. <!-- 通用历史记录抽屉 -->
  7. <MobileHistoryDrawer
  8. :visible="!isGenerating && showHistory"
  9. title="历史记录"
  10. :historyData="historyData"
  11. :loading="isLoadingHistory"
  12. @close="showHistory = false"
  13. @createNewTask="createNewTask"
  14. @handleHistoryItem="handleHistoryItem"
  15. @deleteHistoryItem="deleteHistoryItem"
  16. />
  17. <!-- 移动端Toast提示组件 -->
  18. <MobileToast :visible="toastVisible" :message="toastMessage" @close="closeToast" />
  19. <!-- 主界面:考试工坊配置 -->
  20. <div v-if="!showExamDetail" class="exam-workshop-main">
  21. <!-- 试卷类型选择 -->
  22. <div class="config-section">
  23. <div class="config-header">
  24. <div class="step-number">1</div>
  25. <h3>选择试卷类型</h3>
  26. </div>
  27. <div class="type-cards">
  28. <div class="type-cards-row">
  29. <div
  30. v-for="(type, key) in projectTypes"
  31. :key="key"
  32. :class="['type-card', { active: selectedProjectType === key }]"
  33. @click="(isGenerating || selectedFile) ? null : selectProjectType(key)"
  34. :style="{ cursor: (isGenerating || selectedFile) ? 'not-allowed' : 'pointer', opacity: (isGenerating || selectedFile) ? '0.5' : '1' }"
  35. >
  36. <img :src="type.icon" :alt="type.name" class="type-icon" />
  37. <span>{{ type.name }}</span>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. <!-- 生成方式选择 -->
  43. <div class="config-section">
  44. <div class="config-header">
  45. <div class="step-number">2</div>
  46. <h3>选择生成方式</h3>
  47. </div>
  48. <div class="generation-methods">
  49. <div
  50. :class="['method-card', { active: selectedFunction === 'ai' }]"
  51. @click="(isGenerating || selectedFile) ? null : selectFunction('ai')"
  52. :style="{ cursor: (isGenerating || selectedFile) ? 'not-allowed' : 'pointer', opacity: (isGenerating || selectedFile) ? '0.5' : '1' }"
  53. >
  54. <img :src="aiIcon" alt="智能生成试卷" class="method-icon" />
  55. <div class="method-content">
  56. <h4>智能生成试卷</h4>
  57. <p>基于AI技术,根据所选类型自动生成完整试卷</p>
  58. </div>
  59. </div>
  60. <!-- PPT生成考题选项已隐藏 -->
  61. </div>
  62. </div>
  63. <!-- 试卷配置 -->
  64. <div class="config-section">
  65. <div class="config-header">
  66. <div class="step-number">3</div>
  67. <h3>试卷配置</h3>
  68. </div>
  69. <div class="exam-config-container">
  70. <div class="config-main">
  71. <div class="config-form">
  72. <div class="form-group">
  73. <label>试卷名称</label>
  74. <div class="input-wrapper">
  75. <input
  76. v-model="examName"
  77. type="text"
  78. placeholder="请输入试卷名称"
  79. class="config-input"
  80. maxlength="32"
  81. @input="validateExamName"
  82. :disabled="isGenerating || selectedFile"
  83. />
  84. <span class="char-count" :class="{ 'warning': examName.length >= 18 }">{{ examName.length }}/32</span>
  85. </div>
  86. </div>
  87. <div class="form-group">
  88. <label>试卷总分</label>
  89. <div class="score-input">
  90. <input
  91. v-model="totalScore"
  92. type="number"
  93. class="config-input"
  94. min="1"
  95. max="1000"
  96. @input="validateTotalScore"
  97. :disabled="isGenerating || selectedFile"
  98. />
  99. <span class="unit">分</span>
  100. </div>
  101. </div>
  102. </div>
  103. <!-- 题型配置 -->
  104. <div class="question-types-title">题型选择与分数分配</div>
  105. <div class="question-types">
  106. <div
  107. class="question-type"
  108. v-for="(type, index) in questionTypes"
  109. :key="index"
  110. >
  111. <div class="type-header">
  112. <span class="type-name">{{ type.name }}</span>
  113. <div class="progress-bar">
  114. <div class="progress-fill" :style="{ width: ((type.scorePerQuestion * type.questionCount) / totalScore) * 100 + '%' }"></div>
  115. </div>
  116. </div>
  117. <div class="score-config">
  118. <div class="config-item">
  119. <span>每题</span>
  120. <input
  121. v-model="type.scorePerQuestion"
  122. type="number"
  123. class="score-input-field"
  124. min="1"
  125. max="99"
  126. @input="validateScorePerQuestion(type)"
  127. :disabled="isGenerating || selectedFile"
  128. />
  129. <span>分</span>
  130. </div>
  131. <div class="config-item">
  132. <span>一共</span>
  133. <div class="count-stepper">
  134. <input
  135. v-model="type.questionCount"
  136. type="number"
  137. class="count-input-field"
  138. min="0"
  139. max="99"
  140. @input="validateQuestionCount(type)"
  141. :disabled="isGenerating || selectedFile"
  142. />
  143. <div class="stepper-buttons">
  144. <button
  145. class="stepper-btn stepper-btn-up"
  146. type="button"
  147. @click="adjustQuestionCount(type, 1)"
  148. :disabled="isGenerating || selectedFile || type.questionCount >= 99"
  149. aria-label="增加题目数量"
  150. ></button>
  151. <button
  152. class="stepper-btn stepper-btn-down"
  153. type="button"
  154. @click="adjustQuestionCount(type, -1)"
  155. :disabled="isGenerating || selectedFile || type.questionCount <= 0"
  156. aria-label="减少题目数量"
  157. ></button>
  158. </div>
  159. </div>
  160. <span>题</span>
  161. </div>
  162. </div>
  163. </div>
  164. </div>
  165. </div>
  166. <!-- 预览面板 -->
  167. <div class="preview-panel">
  168. <div class="preview-header">
  169. <img :src="previewIcon" alt="预览" class="preview-icon" />
  170. <h3>预览</h3>
  171. </div>
  172. <div class="preview-content">
  173. <h4 class="preview-title">{{ examName || "试卷名称" }}</h4>
  174. <div class="question-breakdown">
  175. <div
  176. class="breakdown-item"
  177. v-for="(type, index) in questionTypes"
  178. :key="index"
  179. >
  180. <div class="breakdown-row">
  181. <span class="breakdown-left">{{ type.romanNumeral }}、{{ type.name }} (每题{{ type.scorePerQuestion }}分,共{{ type.scorePerQuestion * type.questionCount }}分)</span>
  182. <span class="breakdown-right">{{ type.questionCount }}题</span>
  183. </div>
  184. </div>
  185. </div>
  186. <div class="divider"></div>
  187. <div class="calculated-score-row">
  188. <span class="calculated-label">配置总分</span>
  189. <span class="calculated-value">{{ calculatedTotalScore }}分</span>
  190. </div>
  191. <div class="total-score-row">
  192. <span class="total-label">试卷总分</span>
  193. <span class="total-value">{{ totalScore }}分</span>
  194. </div>
  195. </div>
  196. </div>
  197. </div>
  198. <!-- 底部操作按钮 -->
  199. <div class="bottom-actions">
  200. <button class="clear-btn" @click="clearSettings" :disabled="isGenerating || selectedFile">
  201. 一键清除
  202. </button>
  203. <button class="generate-btn" @click="generateExam" :disabled="isGenerating">
  204. <img v-if="!isGenerating" :src="generateIcon" alt="生成试卷" class="generate-icon" />
  205. <span v-else class="generating-text">生成中...</span>
  206. </button>
  207. </div>
  208. </div>
  209. </div>
  210. <!-- 考试详情页 -->
  211. <div v-if="showExamDetail" class="exam-detail-main">
  212. <!-- 详情页头部 -->
  213. <div class="detail-header">
  214. <button class="back-btn" @click="backToConfig" :disabled="isGenerating">
  215. <span class="back-arrow">←</span>
  216. 返回修改
  217. </button>
  218. <div class="download-dropdown" :class="{ 'disabled': isGenerating, 'show': showDownloadMenu }" @click.stop>
  219. <button class="download-btn" :disabled="isGenerating" @click="toggleDownloadMenu">
  220. <img :src="downloadIcon" alt="下载Word" class="download-icon" />
  221. </button>
  222. <div class="dropdown-menu">
  223. <div class="dropdown-item" @click="exportToWordWithAnswers" :disabled="isGenerating">
  224. <span class="item-text">有答案</span>
  225. </div>
  226. <div class="dropdown-item" @click="exportToWordWithoutAnswers" :disabled="isGenerating">
  227. <span class="item-text">无答案</span>
  228. </div>
  229. </div>
  230. </div>
  231. </div>
  232. <!-- 试卷信息 -->
  233. <div class="exam-info">
  234. <h1 class="exam-title">{{ currentExam.title }}</h1>
  235. <div class="exam-stats">
  236. <span class="total-score">总分: {{ currentExam.totalScore }}分</span>
  237. <span class="question-count">题量: {{ currentExam.totalQuestions }}题</span>
  238. </div>
  239. <div class="generation-time">生成时间: {{ currentTime }}</div>
  240. </div>
  241. <!-- 题型列表 -->
  242. <div class="question-sections">
  243. <!-- 单选题 -->
  244. <div class="question-section" v-if="currentExam.singleChoice && currentExam.singleChoice.questions.length > 0">
  245. <div class="section-header" @click="isGenerating ? null : toggleSection('single')" :style="{ cursor: isGenerating ? 'not-allowed' : 'pointer' }">
  246. <div class="section-title">
  247. <span class="section-number">一</span>
  248. <span class="section-name">单选题</span>
  249. <span class="section-score">(每题{{ currentExam.singleChoice.scorePerQuestion }}分, 共{{ currentExam.singleChoice.totalScore }}分)</span>
  250. </div>
  251. <div class="section-controls">
  252. <span class="question-count-text">{{ currentExam.singleChoice.count }}题</span>
  253. <img
  254. :src="expandIcon"
  255. alt="收起/展开"
  256. class="toggle-icon"
  257. :class="{ 'expanded': !expandedSections.single }"
  258. />
  259. </div>
  260. </div>
  261. <div v-if="expandedSections.single" class="section-content">
  262. <div
  263. v-for="(question, index) in currentExam.singleChoice.questions"
  264. :key="index"
  265. class="question-item"
  266. >
  267. <div class="question-header">
  268. <span class="question-number">{{ index + 1 }}.</span>
  269. <span class="question-text">{{ question.text }}</span>
  270. <button class="refresh-btn" @click="refreshQuestion('single', index)" :disabled="isGenerating">
  271. <img
  272. :src="collapseIcon"
  273. alt="刷新"
  274. class="refresh-icon"
  275. :class="{ 'rotating': isRefreshing['single_' + index] }"
  276. />
  277. </button>
  278. </div>
  279. <div class="options">
  280. <div
  281. v-for="option in question.options"
  282. :key="option.key"
  283. class="option"
  284. >
  285. <div class="radio-wrapper">
  286. <div class="radio-circle" :class="{ 'selected': question.selectedAnswer === option.key }">
  287. <div v-if="question.selectedAnswer === option.key" class="radio-dot"></div>
  288. </div>
  289. </div>
  290. <span class="option-key">{{ option.key }}.</span>
  291. <div class="option-content">
  292. <span class="option-text">{{ option.text }}</span>
  293. </div>
  294. </div>
  295. </div>
  296. </div>
  297. </div>
  298. </div>
  299. <!-- 判断题 -->
  300. <div class="question-section" v-if="currentExam.judge && currentExam.judge.questions.length > 0">
  301. <div class="section-header" @click="isGenerating ? null : toggleSection('judge')" :style="{ cursor: isGenerating ? 'not-allowed' : 'pointer' }">
  302. <div class="section-title">
  303. <span class="section-number">二</span>
  304. <span class="section-name">判断题</span>
  305. <span class="section-score">(每题{{ currentExam.judge.scorePerQuestion }}分, 共{{ currentExam.judge.totalScore }}分)</span>
  306. </div>
  307. <div class="section-controls">
  308. <span class="question-count-text">{{ currentExam.judge.count }}题</span>
  309. <img
  310. :src="expandIcon"
  311. alt="收起/展开"
  312. class="toggle-icon"
  313. :class="{ 'expanded': !expandedSections.judge }"
  314. />
  315. </div>
  316. </div>
  317. <div v-if="expandedSections.judge" class="section-content">
  318. <div
  319. v-for="(question, index) in currentExam.judge.questions"
  320. :key="index"
  321. class="question-item"
  322. >
  323. <div class="question-header">
  324. <span class="question-number">{{ index + 1 }}.</span>
  325. <span class="question-text">{{ question.text }}</span>
  326. <button class="refresh-btn" @click="refreshQuestion('judge', index)" :disabled="isGenerating">
  327. <img
  328. :src="collapseIcon"
  329. alt="刷新"
  330. class="refresh-icon"
  331. :class="{ 'rotating': isRefreshing['judge_' + index] }"
  332. />
  333. </button>
  334. </div>
  335. <div class="answer-section">
  336. <span class="answer-label">正确答案:</span>
  337. <span class="answer-value">{{ question.selectedAnswer }}</span>
  338. </div>
  339. </div>
  340. </div>
  341. </div>
  342. <!-- 多选题 -->
  343. <div class="question-section" v-if="currentExam.multiple && currentExam.multiple.questions.length > 0">
  344. <div class="section-header" @click="isGenerating ? null : toggleSection('multiple')" :style="{ cursor: isGenerating ? 'not-allowed' : 'pointer' }">
  345. <div class="section-title">
  346. <span class="section-number">三</span>
  347. <span class="section-name">多选题</span>
  348. <span class="section-score">(每题{{ currentExam.multiple.scorePerQuestion }}分, 共{{ currentExam.multiple.totalScore }}分)</span>
  349. </div>
  350. <div class="section-controls">
  351. <span class="question-count-text">{{ currentExam.multiple.count }}题</span>
  352. <img
  353. :src="expandIcon"
  354. alt="收起/展开"
  355. class="toggle-icon"
  356. :class="{ 'expanded': !expandedSections.multiple }"
  357. />
  358. </div>
  359. </div>
  360. <div v-if="expandedSections.multiple" class="section-content">
  361. <div
  362. v-for="(question, index) in currentExam.multiple.questions"
  363. :key="index"
  364. class="question-item"
  365. >
  366. <div class="question-header">
  367. <span class="question-number">{{ index + 1 }}.</span>
  368. <span class="question-text">{{ question.text }}</span>
  369. <button class="refresh-btn" @click="refreshQuestion('multiple', index)" :disabled="isGenerating">
  370. <img
  371. :src="collapseIcon"
  372. alt="刷新"
  373. class="refresh-icon"
  374. :class="{ 'rotating': isRefreshing['multiple_' + index] }"
  375. />
  376. </button>
  377. </div>
  378. <div class="options">
  379. <div
  380. v-for="option in question.options"
  381. :key="option.key"
  382. class="option"
  383. >
  384. <div class="radio-wrapper">
  385. <div class="radio-circle" :class="{ 'selected': (question.selectedAnswers || []).includes(option.key) }">
  386. <div v-if="(question.selectedAnswers || []).includes(option.key)" class="radio-dot"></div>
  387. </div>
  388. </div>
  389. <span class="option-key">{{ option.key }}.</span>
  390. <div class="option-content">
  391. <span class="option-text">{{ option.text }}</span>
  392. </div>
  393. </div>
  394. </div>
  395. <div class="answer-section">
  396. <span class="answer-label">正确答案:</span>
  397. <span class="answer-value">{{ (question.selectedAnswers || []).join(', ') }}</span>
  398. </div>
  399. </div>
  400. </div>
  401. </div>
  402. <!-- 简答题 -->
  403. <div class="question-section" v-if="currentExam.short && currentExam.short.questions.length > 0">
  404. <div class="section-header" @click="isGenerating ? null : toggleSection('short')" :style="{ cursor: isGenerating ? 'not-allowed' : 'pointer' }">
  405. <div class="section-title">
  406. <span class="section-number">四</span>
  407. <span class="section-name">简答题</span>
  408. <span class="section-score">(每题{{ currentExam.short.scorePerQuestion }}分, 共{{ currentExam.short.totalScore }}分)</span>
  409. </div>
  410. <div class="section-controls">
  411. <span class="question-count-text">{{ currentExam.short.count }}题</span>
  412. <img
  413. :src="expandIcon"
  414. alt="收起/展开"
  415. class="toggle-icon"
  416. :class="{ 'expanded': !expandedSections.short }"
  417. />
  418. </div>
  419. </div>
  420. <div v-if="expandedSections.short" class="section-content">
  421. <div
  422. v-for="(question, index) in currentExam.short.questions"
  423. :key="index"
  424. class="question-item"
  425. >
  426. <div class="question-header">
  427. <span class="question-number">{{ index + 1 }}.</span>
  428. <span class="question-text">{{ question.text }}</span>
  429. <button class="refresh-btn" @click="refreshQuestion('short', index)" :disabled="isGenerating">
  430. <img
  431. :src="collapseIcon"
  432. alt="刷新"
  433. class="refresh-icon"
  434. :class="{ 'rotating': isRefreshing['short_' + index] }"
  435. />
  436. </button>
  437. </div>
  438. <div v-if="question.outline" class="answer-outline">
  439. <div class="outline-section">
  440. <strong>关键要点:</strong>{{ cleanText(question.outline.keyFactors) }}
  441. </div>
  442. <div class="outline-section">
  443. <strong>具体措施:</strong>{{ cleanText(question.outline.measures) }}
  444. </div>
  445. </div>
  446. </div>
  447. </div>
  448. </div>
  449. </div>
  450. </div>
  451. <!-- 文件上传隐藏input -->
  452. <input
  453. ref="fileInput"
  454. type="file"
  455. accept=".ppt,.pptx"
  456. @change="handleFileSelect"
  457. style="display: none"
  458. />
  459. </div>
  460. </div>
  461. </template>
  462. <script setup>
  463. import { useRouter, useRoute } from 'vue-router'
  464. import MobileHeader from '@/components/MobileHeader.vue'
  465. import MobileHistoryDrawer from '@/components/MobileHistoryDrawer.vue'
  466. import { ref, onMounted, onUnmounted, watch, computed } from 'vue'
  467. import MobileToast from '@/components/MobileToast.vue'
  468. import { apis } from '@/request/apis.js'
  469. import { initNativeNavForSubPage } from '@/utils/nativeBridge.js'
  470. // ===== 已删除:getUserId - 不再需要,改用token =====
  471. // import { getUserId } from '@/utils/userManager.js'
  472. const router = useRouter()
  473. const route = useRoute()
  474. const goBack = () => {
  475. router.go(-1)
  476. }
  477. // 显示历史记录抽屉的方法
  478. const showHistoryDrawer = () => {
  479. if (!isGenerating.value) {
  480. showHistory.value = true
  481. }
  482. // AI处理中时不执行任何操作,不记录点击意图
  483. }
  484. const showHistory = ref(false)
  485. // Toast 状态管理(与其他移动端页面保持一致)
  486. const toastVisible = ref(false)
  487. const toastMessage = ref('')
  488. const showToast = (message, duration = 2000) => {
  489. toastMessage.value = message
  490. toastVisible.value = true
  491. if (duration > 0) {
  492. setTimeout(() => {
  493. toastVisible.value = false
  494. }, duration)
  495. }
  496. }
  497. const closeToast = () => {
  498. toastVisible.value = false
  499. }
  500. // 历史记录相关状态
  501. const historyData = ref([])
  502. const historyTotal = ref(0)
  503. const isLoadingHistory = ref(false)
  504. // 页面加载时不再自动加载历史记录,改为点击菜单时加载
  505. onMounted(async () => {
  506. // 保存初始配置
  507. initialConfig = {
  508. questionTypes: JSON.parse(JSON.stringify(questionTypes.value)),
  509. totalScore: totalScore.value,
  510. selectedProjectType: selectedProjectType.value,
  511. examName: examName.value
  512. };
  513. console.log('初始配置已保存:', initialConfig);
  514. // 添加全局点击事件监听器
  515. document.addEventListener('click', handleClickOutside);
  516. console.log('🚀 移动端考试工坊页面初始化完成')
  517. })
  518. onUnmounted(() => {
  519. // 清理事件监听器
  520. document.removeEventListener('click', handleClickOutside);
  521. })
  522. // ============ 移动端考试工坊核心功能 ============
  523. // 试卷类型图标和配置
  524. import bridgeIcon from '@/assets/Exam/4.png'
  525. import tunnelIcon from '@/assets/Exam/18.png'
  526. import equipmentIcon from '@/assets/Exam/5.png'
  527. import gasStationIcon from '@/assets/Exam/6.png'
  528. import highwayIcon from '@/assets/Exam/7.png'
  529. import comprehensiveIcon from '@/assets/Exam/8.png'
  530. import aiIcon from '@/assets/Exam/7.png'
  531. import pptIcon from '@/assets/Exam/8.png'
  532. import previewIcon from '@/assets/Exam/9.png'
  533. import clearIcon from '@/assets/Exam/10.png'
  534. import generateIcon from '@/assets/Exam/12.png'
  535. import downloadIcon from '@/assets/Exam/13.png'
  536. import expandIcon from '@/assets/Exam/17.png'
  537. import collapseIcon from '@/assets/Exam/16.png'
  538. import saveIcon from '@/assets/Exam/15.png'
  539. // 试卷类型配置
  540. const projectTypes = {
  541. bridge: { name: "桥梁", icon: bridgeIcon },
  542. tunnel: { name: "隧道", icon: tunnelIcon },
  543. equipment: { name: "特种设备", icon: equipmentIcon },
  544. "gas-station": { name: "加油站", icon: gasStationIcon },
  545. highway: { name: "高速运营公路", icon: highwayIcon },
  546. comprehensive: { name: "综合", icon: comprehensiveIcon },
  547. };
  548. // 题型配置
  549. const questionTypes = ref([
  550. { name: "单选题", scorePerQuestion: 5, questionCount: 5, romanNumeral: "一" },
  551. { name: "判断题", scorePerQuestion: 3, questionCount: 5, romanNumeral: "二" },
  552. { name: "多选题", scorePerQuestion: 8, questionCount: 5, romanNumeral: "三" },
  553. { name: "简答题", scorePerQuestion: 10, questionCount: 2, romanNumeral: "四" },
  554. ]);
  555. // 考试工坊状态
  556. const showExamDetail = ref(false)
  557. const isGenerating = ref(false)
  558. const isLoadingHistoryItem = ref(false)
  559. const ai_conversation_id = ref(0)
  560. const showDownloadMenu = ref(false) // 控制下载菜单显示状态
  561. // 试卷配置状态
  562. const selectedFunction = ref("ai")
  563. const selectedProjectType = ref("bridge")
  564. const examName = ref("桥梁工程施工技术考核")
  565. const totalScore = ref(100)
  566. const currentTime = ref("")
  567. // 文件上传相关
  568. const selectedFile = ref(null)
  569. const pptContentDescription = ref('')
  570. const fileInput = ref(null)
  571. // 展开/收起状态
  572. const expandedSections = ref({
  573. single: true,
  574. judge: true,
  575. multiple: true,
  576. short: true,
  577. })
  578. // 刷新状态记录
  579. const isRefreshing = ref({})
  580. // 当前试卷数据
  581. const currentExam = ref({
  582. title: "桥梁工程施工技术考核",
  583. totalScore: 100,
  584. totalQuestions: 37,
  585. singleChoice: {
  586. scorePerQuestion: 2,
  587. totalScore: 30,
  588. count: 15,
  589. questions: []
  590. },
  591. judge: {
  592. scorePerQuestion: 2,
  593. totalScore: 20,
  594. count: 10,
  595. questions: []
  596. },
  597. multiple: {
  598. scorePerQuestion: 3,
  599. totalScore: 30,
  600. count: 10,
  601. questions: []
  602. },
  603. short: {
  604. scorePerQuestion: 10,
  605. totalScore: 20,
  606. count: 2,
  607. questions: []
  608. }
  609. })
  610. // 保存初始配置
  611. let initialConfig = null
  612. // 计算总分(所有题目分数的总和)
  613. const calculatedTotalScore = computed(() => {
  614. return questionTypes.value.reduce((total, type) => {
  615. return total + (type.scorePerQuestion * type.questionCount);
  616. }, 0);
  617. })
  618. // ============ 历史记录相关方法 ============
  619. // 格式化时间函数
  620. const formatTime = (timestamp) => {
  621. if (!timestamp) return ''
  622. const date = new Date(timestamp)
  623. const now = new Date()
  624. const diff = now - date
  625. // 如果是今天
  626. if (diff < 24 * 60 * 60 * 1000 && date.getDate() === now.getDate()) {
  627. return date.toLocaleTimeString('zh-CN', {
  628. hour: '2-digit',
  629. minute: '2-digit'
  630. })
  631. }
  632. // 如果是昨天
  633. if (diff < 48 * 60 * 60 * 1000 && date.getDate() === now.getDate() - 1) {
  634. return '昨天 ' + date.toLocaleTimeString('zh-CN', {
  635. hour: '2-digit',
  636. minute: '2-digit'
  637. })
  638. }
  639. // 其他情况显示日期
  640. return date.toLocaleDateString('zh-CN', {
  641. month: '2-digit',
  642. day: '2-digit'
  643. })
  644. }
  645. // 生成对话标题
  646. const generateConversationTitle = (content) => {
  647. if (!content) return '新对话'
  648. // 取前30个字符作为标题
  649. const title = content.replace(/<[^>]*>/g, '').trim()
  650. return title.length > 30 ? title.substring(0, 30) + '...' : title
  651. }
  652. // 新建任务
  653. const createNewTask = () => {
  654. console.log('新建考试工坊任务')
  655. showHistory.value = false
  656. // 重置所有状态到新任务状态
  657. selectedFunction.value = "ai"
  658. selectedProjectType.value = "bridge"
  659. examName.value = "桥梁工程施工技术考核"
  660. totalScore.value = 100
  661. showExamDetail.value = false
  662. selectedFile.value = null
  663. pptContentDescription.value = ''
  664. ai_conversation_id.value = 0
  665. // 重置题型配置
  666. if (initialConfig) {
  667. questionTypes.value = JSON.parse(JSON.stringify(initialConfig.questionTypes))
  668. totalScore.value = initialConfig.totalScore
  669. selectedProjectType.value = initialConfig.selectedProjectType
  670. examName.value = initialConfig.examName
  671. }
  672. // 清除历史记录的激活状态
  673. historyData.value.forEach((item) => {
  674. item.isActive = false
  675. })
  676. }
  677. // 处理历史记录点击
  678. const handleHistoryItem = async (historyItem) => {
  679. if (isGenerating.value || isLoadingHistoryItem.value) return
  680. console.log("点击移动端考试工坊历史记录:", historyItem)
  681. ai_conversation_id.value = historyItem.id
  682. isLoadingHistoryItem.value = true
  683. try {
  684. historyData.value.forEach((item) => {
  685. item.isActive = item.id === historyItem.id
  686. })
  687. showHistory.value = false
  688. const response = await apis.getHistoryRecord({
  689. ai_conversation_id: historyItem.id,
  690. business_type: 3
  691. })
  692. if (response.statusCode === 200 && response.data && response.data.length > 0) {
  693. const latestAiRecord = [...response.data].reverse().find(record => record.type === 'ai' && record.content)
  694. if (latestAiRecord?.content) {
  695. try {
  696. const examData = extractExamDataFromContent(latestAiRecord.content)
  697. restoreExamFromHistory(examData)
  698. currentTime.value = historyItem.time
  699. showExamDetail.value = true
  700. return
  701. } catch (error) {
  702. console.error('解析移动端历史试卷数据失败:', error)
  703. }
  704. }
  705. }
  706. console.error('移动端历史记录缺少可恢复的试卷详情:', response)
  707. showToast('该历史记录暂无可恢复的试卷内容')
  708. } catch (error) {
  709. console.error('获取移动端历史记录详情失败:', error)
  710. showToast('获取历史记录详情失败,请重试')
  711. } finally {
  712. isLoadingHistoryItem.value = false
  713. }
  714. }
  715. // 删除历史记录
  716. const deleteHistoryItem = async (historyItem, index) => {
  717. try {
  718. console.log('开始删除移动端历史记录:', historyItem)
  719. const response = await apis.deleteHistoryRecord({
  720. ai_conversation_id: historyItem.id
  721. })
  722. if (response.statusCode === 200) {
  723. historyData.value.splice(index, 1)
  724. historyTotal.value = Math.max(0, historyTotal.value - 1)
  725. if (historyItem.isActive) {
  726. console.log('删除激活的历史记录,执行新建任务')
  727. createNewTask()
  728. }
  729. console.log('✅ 移动端历史记录删除成功')
  730. showToast('删除成功')
  731. } else {
  732. console.error('❌ 删除移动端历史记录失败:', response)
  733. }
  734. } catch (error) {
  735. console.error('❌ 删除移动端历史记录失败:', error)
  736. }
  737. }
  738. // 时间解析与格式化(容错更强)
  739. const parseToDate = (input) => {
  740. if (!input) return null
  741. if (typeof input === 'number') {
  742. const ms = input < 1e12 ? input * 1000 : input
  743. return new Date(ms)
  744. }
  745. if (typeof input === 'string') {
  746. let d = new Date(input)
  747. if (!isNaN(d)) return d
  748. const normalized = input.replace(/-/g, '/').replace('T', ' ')
  749. d = new Date(normalized)
  750. if (!isNaN(d)) return d
  751. }
  752. return new Date(input)
  753. }
  754. const formatHistoryTime = (timestamp) => {
  755. const date = parseToDate(timestamp)
  756. if (!date || isNaN(date)) return '未知时间'
  757. const now = new Date()
  758. const isToday = date.toDateString() === now.toDateString()
  759. const yesterday = new Date(now.getFullYear(), now.getMonth(), now.getDate() - 1)
  760. const isYesterday = date.toDateString() === yesterday.toDateString()
  761. if (isToday) {
  762. return date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  763. }
  764. if (isYesterday) {
  765. return '昨天 ' + date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  766. }
  767. const month = date.getMonth() + 1
  768. const day = date.getDate()
  769. const time = date.toLocaleTimeString('zh-CN', { hour: '2-digit', minute: '2-digit' })
  770. return `${month}月${day}日 ${time}`
  771. }
  772. const getHistoryRecordList = async () => {
  773. try {
  774. console.log('📋 开始获取移动端考试工坊历史记录列表...')
  775. isLoadingHistory.value = true
  776. const startTime = performance.now()
  777. const response = await apis.getHistoryRecord({
  778. ai_conversation_id: 0,
  779. business_type: 3
  780. })
  781. const endTime = performance.now()
  782. console.log('📋 移动端考试工坊历史记录API调用耗时: ' + (endTime - startTime).toFixed(2) + 'ms')
  783. console.log('📋 移动端历史记录列表响应:', response)
  784. if (response.statusCode === 200) {
  785. historyTotal.value = response.total || 0
  786. historyData.value = response.data.map(conversation => ({
  787. id: conversation.id,
  788. title: generateConversationTitle(conversation.content),
  789. time: formatHistoryTime(conversation.updated_at),
  790. businessType: conversation.business_type,
  791. isActive: false,
  792. rawData: conversation
  793. }))
  794. if (ai_conversation_id.value) {
  795. historyData.value.forEach(item => { item.isActive = item.id === ai_conversation_id.value })
  796. }
  797. console.log('✅ 移动端考试工坊历史记录列表已设置: ' + historyData.value.length + '条记录,总数: ' + historyTotal.value)
  798. } else {
  799. console.error('❌ 获取移动端历史记录列表失败:', response.statusCode)
  800. }
  801. } finally {
  802. isLoadingHistory.value = false
  803. }
  804. }
  805. // ============ 业务逻辑方法 ============
  806. // 选择功能方法
  807. const selectFunction = (functionType) => {
  808. selectedFunction.value = functionType;
  809. console.log("选择功能:", functionType);
  810. };
  811. // 选择项目类型方法
  812. const selectProjectType = (typeKey) => {
  813. selectedProjectType.value = typeKey;
  814. console.log("选择工程类型:", projectTypes[typeKey].name);
  815. // 自动更新试卷名称
  816. const projectTypeName = projectTypes[typeKey].name;
  817. examName.value = projectTypeName + '工程施工技术考核';
  818. // 同时更新当前试卷的标题
  819. if (currentExam.value) {
  820. currentExam.value.title = examName.value;
  821. }
  822. };
  823. // 验证试卷名称
  824. const validateExamName = () => {
  825. if (examName.value.length > 32) {
  826. examName.value = examName.value.slice(0, 32);
  827. }
  828. };
  829. // 验证总分
  830. const validateTotalScore = () => {
  831. if (totalScore.value > 1000) {
  832. totalScore.value = 1000;
  833. console.warn("试卷总分不能超过1000分");
  834. }
  835. if (totalScore.value < 1) {
  836. totalScore.value = 1;
  837. }
  838. };
  839. // 验证每题分数
  840. const validateScorePerQuestion = (type) => {
  841. if (type.scorePerQuestion > 99) {
  842. type.scorePerQuestion = 99;
  843. console.warn(`${type.name}每题分数不能超过99分`);
  844. }
  845. if (type.scorePerQuestion < 1) {
  846. type.scorePerQuestion = 1;
  847. }
  848. };
  849. // 验证题目数量
  850. const validateQuestionCount = (type) => {
  851. if (type.questionCount > 99) {
  852. type.questionCount = 99;
  853. console.warn(`${type.name}题目数量不能超过99题`);
  854. }
  855. if (type.questionCount < 0) {
  856. type.questionCount = 0;
  857. }
  858. };
  859. const adjustQuestionCount = (type, delta) => {
  860. type.questionCount = Number(type.questionCount || 0) + delta;
  861. validateQuestionCount(type);
  862. };
  863. // 清除设置
  864. const clearSettings = () => {
  865. // 根据当前选择的工程类型设置试卷名称
  866. const projectTypeName = projectTypes[selectedProjectType.value].name;
  867. examName.value = projectTypeName + '工程施工技术考核';
  868. totalScore.value = 100;
  869. questionTypes.value = [
  870. { name: "单选题", scorePerQuestion: 2, questionCount: 8, romanNumeral: "一" },
  871. { name: "判断题", scorePerQuestion: 2, questionCount: 5, romanNumeral: "二" },
  872. { name: "多选题", scorePerQuestion: 3, questionCount: 5, romanNumeral: "三" },
  873. { name: "简答题", scorePerQuestion: 10, questionCount: 2, romanNumeral: "四" },
  874. ];
  875. console.log("清除设置");
  876. };
  877. // 生成试卷
  878. const generateExam = async () => {
  879. if (!examName.value.trim()) {
  880. console.warn("请输入试卷名称");
  881. return;
  882. }
  883. if (examName.value.trim().length === 0) {
  884. console.warn("试卷名称不能为空");
  885. return;
  886. }
  887. // 检查总分是否超过限制
  888. if (totalScore.value > 1000) {
  889. console.warn("试卷总分不能超过1000分");
  890. return;
  891. }
  892. // 检查每题分数和题目数量是否超过限制
  893. for (const type of questionTypes.value) {
  894. if (type.scorePerQuestion > 99) {
  895. console.warn(`${type.name}每题分数不能超过99分`);
  896. return;
  897. }
  898. if (type.questionCount > 99) {
  899. console.warn(`${type.name}题目数量不能超过99题`);
  900. return;
  901. }
  902. }
  903. // 检查总分是否合理
  904. const calculatedScore = questionTypes.value.reduce((total, type) => {
  905. return total + (type.scorePerQuestion * type.questionCount);
  906. }, 0);
  907. if (calculatedScore !== totalScore.value) {
  908. showToast(`总分不匹配!`, 3000);
  909. return;
  910. }
  911. console.log("开始生成试卷:", {
  912. function: selectedFunction.value,
  913. projectType: projectTypes[selectedProjectType.value].name,
  914. examName: examName.value,
  915. totalScore: totalScore.value,
  916. questionTypes: questionTypes.value,
  917. pptContent: pptContentDescription.value
  918. });
  919. try {
  920. isGenerating.value = true;
  921. const mode = selectedFunction.value === 'ppt' ? 'ppt' : 'ai';
  922. const prompt = await fetchMobileExamPrompt(mode);
  923. console.log('发送给AI的考试生成提示词:', prompt);
  924. // 调用AI接口生成试卷 - 使用与PC端相同的接口
  925. const response = await apis.sendDeepseekMessage({
  926. // ===== 已删除:user_id - 后端从token解析 =====
  927. business_type: 3,
  928. message: prompt,
  929. exam_name: examName.value,
  930. ai_conversation_id: ai_conversation_id.value
  931. });
  932. if (response.statusCode === 200) {
  933. const aiReply = response.data.reply;
  934. const aiConversationId = response.data.ai_conversation_id;
  935. console.log('AI生成的考试试卷:', aiReply);
  936. console.log('AI对话ID:', aiConversationId);
  937. // 保存对话ID
  938. ai_conversation_id.value = aiConversationId;
  939. // 解析AI回复并生成试卷
  940. const generatedExam = parseAIExamResponse(aiReply);
  941. // 更新当前试卷数据
  942. currentExam.value = generatedExam;
  943. currentExam.value.title = examName.value;
  944. currentExam.value.totalScore = totalScore.value;
  945. currentTime.value = new Date().toLocaleString('zh-CN');
  946. // 试卷数据已通过AI接口自动保存到数据库
  947. console.log('✅ 试卷已通过AI接口保存到数据库');
  948. // 显示考试详情页
  949. showExamDetail.value = true;
  950. console.log('✅ 移动端试卷生成完成!');
  951. } else {
  952. throw new Error('AI接口调用失败');
  953. }
  954. } catch (error) {
  955. console.error('生成试卷失败:', error);
  956. } finally {
  957. isGenerating.value = false;
  958. }
  959. };
  960. // 从服务端获取移动端提示词
  961. const fetchMobileExamPrompt = async (mode = 'ai') => {
  962. const normalizedQuestionTypes = questionTypes.value.map(type => ({
  963. name: type.name,
  964. romanNumeral: type.romanNumeral,
  965. questionCount: Number(type.questionCount) || 0,
  966. scorePerQuestion: Number(type.scorePerQuestion) || 0,
  967. }));
  968. const payload = {
  969. mode,
  970. client: 'mobile',
  971. projectType: projectTypes[selectedProjectType.value]?.name || '',
  972. examTitle: examName.value,
  973. totalScore: totalScore.value,
  974. questionTypes: normalizedQuestionTypes,
  975. pptContent: pptContentDescription.value || ''
  976. };
  977. try {
  978. const response = await apis.buildExamPrompt(payload);
  979. if (!response?.data?.prompt) {
  980. throw new Error(response?.msg || '提示词构建失败');
  981. }
  982. return response.data.prompt;
  983. } catch (error) {
  984. console.error('获取移动端提示词失败:', error);
  985. throw error;
  986. }
  987. };
  988. // 解析AI考试回复
  989. const extractExamDataFromContent = (content) => {
  990. if (!content || typeof content !== 'string') {
  991. throw new Error('历史内容为空');
  992. }
  993. const directMatch = content.match(/\{[\s\S]*\}/);
  994. if (!directMatch) {
  995. throw new Error('未找到可解析的试卷JSON');
  996. }
  997. return JSON.parse(directMatch[0]);
  998. };
  999. const parseAIExamResponse = (aiReply) => {
  1000. try {
  1001. const examData = extractExamDataFromContent(aiReply);
  1002. const normalizedExam = normalizeGeneratedExam(examData);
  1003. ensureQuestionInitialValues(normalizedExam);
  1004. return normalizedExam;
  1005. } catch (error) {
  1006. console.error('解析AI回复失败:', error);
  1007. // 返回默认试卷结构
  1008. return generateDefaultExam();
  1009. }
  1010. };
  1011. const getQuestionTypeConfig = (index, fallbackScore = 0) => ({
  1012. scorePerQuestion: Number(questionTypes.value[index]?.scorePerQuestion) || fallbackScore,
  1013. questionCount: Number(questionTypes.value[index]?.questionCount) || 0,
  1014. });
  1015. const normalizeOptions = (options = []) => {
  1016. if (!Array.isArray(options)) {
  1017. return [];
  1018. }
  1019. return options.map((option, index) => {
  1020. if (typeof option === 'string') {
  1021. return {
  1022. key: String.fromCharCode(65 + index),
  1023. text: option,
  1024. };
  1025. }
  1026. return {
  1027. key: option?.key || String.fromCharCode(65 + index),
  1028. text: option?.text || option?.content || option?.label || "",
  1029. };
  1030. });
  1031. };
  1032. const normalizeQuestions = (questions = [], sectionKey) => {
  1033. if (!Array.isArray(questions)) {
  1034. return [];
  1035. }
  1036. return questions.map((question = {}) => {
  1037. if (sectionKey === 'singleChoice') {
  1038. return {
  1039. text: question.text || question.question_text || "",
  1040. options: normalizeOptions(question.options),
  1041. selectedAnswer: question.selectedAnswer || question.correct_answer || question.answer || "",
  1042. };
  1043. }
  1044. if (sectionKey === 'judge') {
  1045. return {
  1046. text: question.text || question.question_text || "",
  1047. selectedAnswer: question.selectedAnswer || question.correct_answer || question.answer || "",
  1048. };
  1049. }
  1050. if (sectionKey === 'multiple') {
  1051. const selectedAnswers = question.selectedAnswers || question.correct_answers || question.answers || [];
  1052. return {
  1053. text: question.text || question.question_text || "",
  1054. options: normalizeOptions(question.options),
  1055. selectedAnswers: Array.isArray(selectedAnswers) ? selectedAnswers : [selectedAnswers].filter(Boolean),
  1056. };
  1057. }
  1058. return {
  1059. text: question.text || question.question_text || "",
  1060. outline: question.outline || question.answer_outline || {
  1061. keyFactors: question.answer || "请参考相关教材和标准规范",
  1062. measures: "请结合实际工程案例进行解答"
  1063. },
  1064. };
  1065. });
  1066. };
  1067. const normalizeSection = (rawSection, sectionKey, index, fallbackScore = 0) => {
  1068. const section = rawSection || {};
  1069. const config = getQuestionTypeConfig(index, fallbackScore);
  1070. const sourceQuestions = Array.isArray(section)
  1071. ? section
  1072. : (section.questions || section.items || section.question_list || []);
  1073. const normalizedQuestions = normalizeQuestions(sourceQuestions, sectionKey);
  1074. const count = Number(section.count ?? section.question_count ?? normalizedQuestions.length ?? config.questionCount) || 0;
  1075. const scorePerQuestion = Number(section.scorePerQuestion ?? section.score_per_question ?? config.scorePerQuestion) || 0;
  1076. const totalScore = Number(section.totalScore ?? section.total_score ?? (scorePerQuestion * count)) || 0;
  1077. return {
  1078. scorePerQuestion,
  1079. totalScore,
  1080. count,
  1081. questions: normalizedQuestions,
  1082. };
  1083. };
  1084. const normalizeGeneratedExam = (examData = {}) => {
  1085. const normalizedExam = {
  1086. title: examData.title || examData.exam_name || examName.value,
  1087. totalScore: Number(examData.totalScore ?? examData.total_score ?? totalScore.value) || 0,
  1088. totalQuestions: Number(examData.totalQuestions ?? examData.total_questions) || 0,
  1089. singleChoice: normalizeSection(examData.singleChoice || examData.questions?.single_choice || examData.single_choice, 'singleChoice', 0, 2),
  1090. judge: normalizeSection(examData.judge || examData.questions?.judge, 'judge', 1, 2),
  1091. multiple: normalizeSection(examData.multiple || examData.questions?.multiple, 'multiple', 2, 3),
  1092. short: normalizeSection(examData.short || examData.questions?.short, 'short', 3, 10),
  1093. };
  1094. if (!normalizedExam.totalQuestions) {
  1095. normalizedExam.totalQuestions =
  1096. normalizedExam.singleChoice.count +
  1097. normalizedExam.judge.count +
  1098. normalizedExam.multiple.count +
  1099. normalizedExam.short.count;
  1100. }
  1101. return normalizedExam;
  1102. };
  1103. // 确保题目初始值正确
  1104. const ensureQuestionInitialValues = (examData) => {
  1105. // 确保单选题有正确的答案格式
  1106. if (examData.singleChoice && examData.singleChoice.questions) {
  1107. examData.singleChoice.questions.forEach(question => {
  1108. if (!question.selectedAnswer) {
  1109. question.selectedAnswer = question.options && question.options.length > 0 ? question.options[0].key : 'A';
  1110. }
  1111. });
  1112. }
  1113. // 确保判断题有正确答案
  1114. if (examData.judge && examData.judge.questions) {
  1115. examData.judge.questions.forEach(question => {
  1116. if (!question.selectedAnswer) {
  1117. question.selectedAnswer = Math.random() > 0.5 ? '正确' : '错误';
  1118. }
  1119. });
  1120. }
  1121. // 确保多选题有正确答案
  1122. if (examData.multiple && examData.multiple.questions) {
  1123. examData.multiple.questions.forEach(question => {
  1124. if (!question.selectedAnswers || !Array.isArray(question.selectedAnswers)) {
  1125. question.selectedAnswers = question.options && question.options.length > 1 ? [question.options[0].key, question.options[1].key] : [];
  1126. }
  1127. });
  1128. }
  1129. // 确保简答题有提纲
  1130. if (examData.short && examData.short.questions) {
  1131. examData.short.questions.forEach(question => {
  1132. if (!question.outline) {
  1133. question.outline = {
  1134. keyFactors: "请参考相关教材和标准规范",
  1135. measures: "请结合实际工程案例进行解答"
  1136. };
  1137. }
  1138. });
  1139. }
  1140. };
  1141. // 生成默认考试结构
  1142. const generateDefaultExam = () => {
  1143. return {
  1144. title: examName.value,
  1145. totalScore: totalScore.value,
  1146. totalQuestions: questionTypes.value.reduce((total, type) => total + type.questionCount, 0),
  1147. singleChoice: {
  1148. scorePerQuestion: questionTypes.value[0].scorePerQuestion,
  1149. totalScore: questionTypes.value[0].scorePerQuestion * questionTypes.value[0].questionCount,
  1150. count: questionTypes.value[0].questionCount,
  1151. questions: []
  1152. },
  1153. judge: {
  1154. scorePerQuestion: questionTypes.value[1].scorePerQuestion,
  1155. totalScore: questionTypes.value[1].scorePerQuestion * questionTypes.value[1].questionCount,
  1156. count: questionTypes.value[1].questionCount,
  1157. questions: []
  1158. },
  1159. multiple: {
  1160. scorePerQuestion: questionTypes.value[2].scorePerQuestion,
  1161. totalScore: questionTypes.value[2].scorePerQuestion * questionTypes.value[2].questionCount,
  1162. count: questionTypes.value[2].questionCount,
  1163. questions: []
  1164. },
  1165. short: {
  1166. scorePerQuestion: questionTypes.value[3].scorePerQuestion,
  1167. totalScore: questionTypes.value[3].scorePerQuestion * questionTypes.value[3].questionCount,
  1168. count: questionTypes.value[3].questionCount,
  1169. questions: []
  1170. }
  1171. }
  1172. };
  1173. const restoreExamFromHistory = (examData) => {
  1174. const exam = examData?.exam || examData || {}
  1175. const normalizedExam = normalizeGeneratedExam(exam)
  1176. examName.value = normalizedExam.title || examName.value
  1177. totalScore.value = normalizedExam.totalScore || totalScore.value
  1178. currentTime.value = exam.generation_time || currentTime.value
  1179. questionTypes.value = [
  1180. { name: "单选题", scorePerQuestion: normalizedExam.singleChoice.scorePerQuestion, questionCount: normalizedExam.singleChoice.count, romanNumeral: "一" },
  1181. { name: "判断题", scorePerQuestion: normalizedExam.judge.scorePerQuestion, questionCount: normalizedExam.judge.count, romanNumeral: "二" },
  1182. { name: "多选题", scorePerQuestion: normalizedExam.multiple.scorePerQuestion, questionCount: normalizedExam.multiple.count, romanNumeral: "三" },
  1183. { name: "简答题", scorePerQuestion: normalizedExam.short.scorePerQuestion, questionCount: normalizedExam.short.count, romanNumeral: "四" },
  1184. ]
  1185. currentExam.value = normalizedExam
  1186. }
  1187. // 返回配置页面
  1188. const backToConfig = () => {
  1189. showExamDetail.value = false;
  1190. };
  1191. // 展开/收起题型
  1192. const toggleSection = (sectionType) => {
  1193. expandedSections.value[sectionType] = !expandedSections.value[sectionType];
  1194. };
  1195. // 刷新题目 - 使用PC端的实现方式
  1196. const refreshQuestion = async (questionType, index) => {
  1197. try {
  1198. console.log(`刷新${questionType}类型第${index + 1}题`);
  1199. // 设置刷新状态
  1200. const key = `${questionType}_${index}`;
  1201. isRefreshing.value[key] = true;
  1202. // 构建单题重新生成的提示词
  1203. const prompt = buildSingleQuestionPrompt(questionType, index);
  1204. // 第一步:调用 /re_produce_single_question 接口,AI只生成题目
  1205. const response = await apis.reProduceSingleQuestion({
  1206. message: prompt
  1207. });
  1208. if (response.statusCode === 200) {
  1209. const aiReply = response.data.reply;
  1210. console.log('AI重新生成的题目:', aiReply);
  1211. // 解析AI回复并更新题目
  1212. const newQuestion = parseSingleQuestionResponse(aiReply, questionType);
  1213. console.log('解析后的新题目:', newQuestion);
  1214. if (newQuestion) {
  1215. updateQuestion(questionType, index, newQuestion);
  1216. console.log('准备保存到后端,对话ID:', ai_conversation_id.value);
  1217. // 第二步:使用 /re_modify_question 接口保存修改
  1218. await saveToReModifyQuestion(questionType, index, newQuestion);
  1219. showToast('题目重新生成成功!');
  1220. // AI回复完成后,获取最新的历史记录
  1221. await getHistoryRecordList();
  1222. // 如果是新对话,将最新的历史记录设为激活状态
  1223. if (ai_conversation_id.value > 0) {
  1224. historyData.value.forEach((item) => {
  1225. item.isActive = item.id === ai_conversation_id.value;
  1226. });
  1227. console.log('设置最新历史记录为激活状态,conversationId:', ai_conversation_id.value);
  1228. }
  1229. } else {
  1230. throw new Error('解析新题目失败');
  1231. }
  1232. } else {
  1233. throw new Error('AI接口调用失败');
  1234. }
  1235. } catch (error) {
  1236. console.error('刷新题目失败:', error);
  1237. showToast('重新生成题目失败,请重试');
  1238. } finally {
  1239. setTimeout(() => {
  1240. const key = `${questionType}_${index}`;
  1241. isRefreshing.value[key] = false;
  1242. }, 1000);
  1243. }
  1244. };
  1245. // 控制下载菜单显示/隐藏
  1246. const toggleDownloadMenu = () => {
  1247. if (!isGenerating.value) {
  1248. showDownloadMenu.value = !showDownloadMenu.value;
  1249. }
  1250. };
  1251. // 关闭下载菜单
  1252. const closeDownloadMenu = () => {
  1253. showDownloadMenu.value = false;
  1254. };
  1255. // 点击外部区域关闭下载菜单
  1256. const handleClickOutside = (event) => {
  1257. const dropdown = event.target.closest('.download-dropdown');
  1258. if (!dropdown) {
  1259. showDownloadMenu.value = false;
  1260. }
  1261. };
  1262. // 导出Word(有答案)
  1263. const exportToWordWithAnswers = async () => {
  1264. try {
  1265. closeDownloadMenu(); // 关闭下拉菜单
  1266. isGenerating.value = true;
  1267. console.log('开始导出Word格式试卷(有答案)...');
  1268. // 使用PC端的模拟Word导出功能
  1269. await simulateWordExport(true);
  1270. } catch (error) {
  1271. console.error('导出考试文件失败:', error);
  1272. showToast('导出失败,请重试');
  1273. } finally {
  1274. isGenerating.value = false;
  1275. }
  1276. };
  1277. // 导出Word(无答案)
  1278. const exportToWordWithoutAnswers = async () => {
  1279. try {
  1280. closeDownloadMenu(); // 关闭下拉菜单
  1281. isGenerating.value = true;
  1282. console.log('开始导出Word格式试卷(无答案)...');
  1283. // 使用PC端的模拟Word导出功能
  1284. await simulateWordExport(false);
  1285. } catch (error) {
  1286. console.error('导出考试文件失败:', error);
  1287. showToast('导出失败,请重试');
  1288. } finally {
  1289. isGenerating.value = false;
  1290. }
  1291. };
  1292. // 导出文件为Word格式(保留原函数以兼容其他可能的调用)
  1293. const exportToWord = async () => {
  1294. // 默认导出有答案版本
  1295. await exportToWordWithAnswers();
  1296. };
  1297. // 模拟Word导出功能(使用PC端实现)
  1298. const simulateWordExport = async (includeAnswers = true) => {
  1299. try {
  1300. // 创建Word文档内容(使用HTML格式,兼容WPS和Word)
  1301. const wordContent = createHTMLContent(currentExam.value, includeAnswers);
  1302. // 创建Blob对象 - 使用HTML格式
  1303. const blob = new Blob([wordContent], {
  1304. type: 'application/msword'
  1305. });
  1306. // 下载文件
  1307. const url = URL.createObjectURL(blob);
  1308. const link = document.createElement('a');
  1309. const fileName = includeAnswers
  1310. ? `${currentExam.value.title}_有答案_${currentTime.value.replace(/[:\s]/g, '_')}.doc`
  1311. : `${currentExam.value.title}_无答案_${currentTime.value.replace(/[:\s]/g, '_')}.doc`;
  1312. link.setAttribute('href', url);
  1313. link.setAttribute('download', fileName);
  1314. link.style.visibility = 'hidden';
  1315. document.body.appendChild(link);
  1316. link.click();
  1317. document.body.removeChild(link);
  1318. showToast(`导出成功${includeAnswers ? '(含答案)' : '(不含答案)'}`);
  1319. } catch (error) {
  1320. console.error('模拟Word导出失败:', error);
  1321. showToast('Word导出失败,请稍后重试');
  1322. }
  1323. };
  1324. // 创建HTML格式的Word文档内容(兼容WPS和Word)- 使用PC端实现
  1325. const createHTMLContent = (examData, includeAnswers = true) => {
  1326. const exam = currentExam.value;
  1327. // HTML文档内容,使用Word兼容的格式
  1328. let htmlContent = `<!DOCTYPE html>
  1329. <html xmlns:o="urn:schemas-microsoft-com:office:office"
  1330. xmlns:w="urn:schemas-microsoft-com:office:word"
  1331. xmlns="http://www.w3.org/TR/REC-html40">
  1332. <head>
  1333. <meta charset="utf-8">
  1334. <meta name="ProgId" content="Word.Document">
  1335. <meta name="Generator" content="Microsoft Word 15">
  1336. <meta name="Originator" content="Microsoft Word 15">
  1337. <title>${exam.title || '试卷'}</title>
  1338. <!--[if gte mso 9]>
  1339. <xml>
  1340. <w:WordDocument>
  1341. <w:View>Print</w:View>
  1342. <w:Zoom>100</w:Zoom>
  1343. <w:DoNotPromptForConvert/>
  1344. <w:DoNotShowRevisions/>
  1345. <w:DoNotPrintRevisions/>
  1346. <w:DoNotShowComments/>
  1347. <w:DoNotShowInsertionsAndDeletions/>
  1348. <w:DoNotShowPropertyChanges/>
  1349. <w:Compatibility>
  1350. <w:BreakWrappedTables/>
  1351. <w:SnapToGridInCell/>
  1352. <w:WrapTextWithPunct/>
  1353. <w:UseAsianBreakRules/>
  1354. <w:DontGrowAutofit/>
  1355. </w:Compatibility>
  1356. </w:WordDocument>
  1357. </xml>
  1358. <![endif]-->
  1359. <style>
  1360. body {
  1361. font-family: "Microsoft YaHei", "宋体", Arial, sans-serif;
  1362. font-size: 14px;
  1363. line-height: 1.6;
  1364. margin: 24px;
  1365. color: #000;
  1366. }
  1367. .header {
  1368. text-align: center;
  1369. margin-bottom: 14px;
  1370. }
  1371. .exam-title {
  1372. font-size: 24px;
  1373. font-weight: bold;
  1374. margin-bottom: 14px;
  1375. color: #000;
  1376. }
  1377. .exam-info {
  1378. font-size: 14px;
  1379. color: #666;
  1380. margin-bottom: 14px;
  1381. }
  1382. .section {
  1383. margin-bottom: 14px;
  1384. }
  1385. .section-title {
  1386. font-size: 18px;
  1387. font-weight: bold;
  1388. margin-bottom: 14px;
  1389. color: #000;
  1390. border-bottom: 2px solid #3e7bfa;
  1391. padding-bottom: 5px;
  1392. }
  1393. .question {
  1394. margin-bottom: 14px;
  1395. padding: 10px;
  1396. background-color: #f9f9f9;
  1397. border-left: 4px solid #3e7bfa;
  1398. }
  1399. .question-header {
  1400. display: flex;
  1401. align-items: flex-start;
  1402. gap: 8px;
  1403. margin-bottom: 14px;
  1404. }
  1405. .question-number {
  1406. font-weight: bold;
  1407. color: #3e7bfa;
  1408. flex-shrink: 0;
  1409. }
  1410. .question-text {
  1411. flex: 1;
  1412. }
  1413. .options {
  1414. margin-left: 12px;
  1415. }
  1416. .option {
  1417. margin-bottom: 5px;
  1418. }
  1419. .answer {
  1420. margin-top: 10px;
  1421. padding: 8px;
  1422. background: #e8f4fd;
  1423. border-left: 3px solid #3e7bfa;
  1424. font-weight: bold;
  1425. color: #0066cc;
  1426. }
  1427. .outline-section {
  1428. margin: 10px 0;
  1429. padding: 8px;
  1430. background: #f0f8ff;
  1431. border-radius: 4px;
  1432. }
  1433. </style>
  1434. </head>
  1435. <body>
  1436. <div class="header">
  1437. <div class="exam-title">${exam.title || '考试试卷'}</div>
  1438. <div class="exam-info">
  1439. 总分:${exam.totalScore || 0}分 | 总题数:${exam.totalQuestions || 0}题 | 生成时间:${currentTime.value}
  1440. </div>
  1441. </div>`;
  1442. // 单选题
  1443. if (exam.singleChoice && exam.singleChoice.questions.length > 0) {
  1444. htmlContent += `
  1445. <div class="section">
  1446. <div class="section-title">一、单选题(${exam.singleChoice.count}题,每题${exam.singleChoice.scorePerQuestion}分,共${exam.singleChoice.totalScore}分)</div>`;
  1447. exam.singleChoice.questions.forEach((question, index) => {
  1448. htmlContent += `
  1449. <div class="question">
  1450. <div class="question-header">
  1451. <span class="question-number">${index + 1}.</span>
  1452. <span class="question-text">${question.text}</span>
  1453. </div>
  1454. <div class="options">`;
  1455. question.options.forEach(option => {
  1456. htmlContent += `
  1457. <div class="option">${option.key}. ${option.text}</div>`;
  1458. });
  1459. htmlContent += `
  1460. </div>
  1461. ${includeAnswers ? `<div class="answer">正确答案:${question.selectedAnswer}</div>` : ''}
  1462. </div>`;
  1463. });
  1464. htmlContent += `
  1465. </div>`;
  1466. }
  1467. // 判断题
  1468. if (exam.judge && exam.judge.questions.length > 0) {
  1469. htmlContent += `
  1470. <div class="section">
  1471. <div class="section-title">二、判断题(${exam.judge.count}题,每题${exam.judge.scorePerQuestion}分,共${exam.judge.totalScore}分)</div>`;
  1472. exam.judge.questions.forEach((question, index) => {
  1473. htmlContent += `
  1474. <div class="question">
  1475. <div class="question-header">
  1476. <span class="question-number">${index + 1}.</span>
  1477. <span class="question-text">${question.text}</span>
  1478. </div>
  1479. ${includeAnswers ? `<div class="answer">正确答案:${question.selectedAnswer}</div>` : ''}
  1480. </div>`;
  1481. });
  1482. htmlContent += `
  1483. </div>`;
  1484. }
  1485. // 多选题
  1486. if (exam.multiple && exam.multiple.questions.length > 0) {
  1487. htmlContent += `
  1488. <div class="section">
  1489. <div class="section-title">三、多选题(${exam.multiple.count}题,每题${exam.multiple.scorePerQuestion}分,共${exam.multiple.totalScore}分)</div>`;
  1490. exam.multiple.questions.forEach((question, index) => {
  1491. htmlContent += `
  1492. <div class="question">
  1493. <div class="question-header">
  1494. <span class="question-number">${index + 1}.</span>
  1495. <span class="question-text">${question.text}</span>
  1496. </div>
  1497. <div class="options">`;
  1498. question.options.forEach(option => {
  1499. htmlContent += `
  1500. <div class="option">${option.key}. ${option.text}</div>`;
  1501. });
  1502. htmlContent += `
  1503. </div>
  1504. ${includeAnswers ? `<div class="answer">正确答案:${(question.selectedAnswers || []).join(', ')}</div>` : ''}
  1505. </div>`;
  1506. });
  1507. htmlContent += `
  1508. </div>`;
  1509. }
  1510. // 简答题
  1511. if (exam.short && exam.short.questions.length > 0) {
  1512. htmlContent += `
  1513. <div class="section">
  1514. <div class="section-title">四、简答题(${exam.short.count}题,每题${exam.short.scorePerQuestion}分,共${exam.short.totalScore}分)</div>`;
  1515. exam.short.questions.forEach((question, index) => {
  1516. htmlContent += `
  1517. <div class="question">
  1518. <div class="question-header">
  1519. <span class="question-number">${index + 1}.</span>
  1520. <span class="question-text">${question.text}</span>
  1521. </div>`;
  1522. if (question.outline && includeAnswers) {
  1523. htmlContent += `
  1524. <div class="outline-section">
  1525. <strong>关键要点:</strong>${cleanText(question.outline.keyFactors)}
  1526. </div>
  1527. <div class="outline-section">
  1528. <strong>具体措施:</strong>${cleanText(question.outline.measures)}
  1529. </div>`;
  1530. }
  1531. htmlContent += `
  1532. </div>`;
  1533. });
  1534. htmlContent += `
  1535. </div>`;
  1536. }
  1537. htmlContent += `
  1538. </body>
  1539. </html>`;
  1540. return htmlContent;
  1541. };
  1542. // 创建Word格式的考试文档内容(保留原函数以防其他地方使用)
  1543. const createExamWordContent = (examData) => {
  1544. const currentTime = new Date().toLocaleString('zh-CN');
  1545. let htmlContent = `<!DOCTYPE html>
  1546. <html xmlns:o="urn:schemas-microsoft-com:office:office"
  1547. xmlns:w="urn:schemas-microsoft-com:office:word"
  1548. xmlns="http://www.w3.org/TR/REC-html40">
  1549. <head>
  1550. <meta charset="utf-8">
  1551. <meta name="ProgId" content="Word.Document">
  1552. <meta name="Generator" content="Microsoft Word">
  1553. <meta name="Originator" content="Microsoft Word">
  1554. <meta name="ViewMode" content="PrintLayout">
  1555. <meta name="Zoom" content="100">
  1556. <meta name="DocumentProperties" content="false">
  1557. <meta name="DocumentSecurity" content="false">
  1558. <meta name="DocumentProtection" content="false">
  1559. <meta name="DocumentView" content="PrintLayout">
  1560. <title>${examData.title}</title>
  1561. <style>
  1562. body { font-family: '微软雅黑', 'Microsoft YaHei', sans-serif; line-height: 1.6; margin: 20px; }
  1563. .header { text-align: center; margin-bottom: 30px; }
  1564. .exam-title { font-size: 24px; font-weight: bold; margin-bottom: 10px; }
  1565. .exam-info { font-size: 14px; color: #666; margin-bottom: 30px; }
  1566. .section { margin-bottom: 25px; }
  1567. .section-title { font-size: 16px; font-weight: bold; margin-bottom: 15px; }
  1568. .question { margin-bottom: 20px; padding: 10px; }
  1569. .question-header { font-weight: bold; margin-bottom: 10px; }
  1570. .option { margin: 5px 0; }
  1571. .answer { color: #0066cc; font-weight: bold; margin-top: 10px; }
  1572. .outline-section { margin: 10px 0; }
  1573. </style>
  1574. </head>
  1575. <body>
  1576. <div class="header">
  1577. <div class="exam-title">${examData.title || '考试试卷'}</div>
  1578. <div class="exam-info">
  1579. 总分:${examData.totalScore || 0}分 | 总题数:${examData.totalQuestions || 0}题 | 生成时间:${currentTime}
  1580. </div>
  1581. </div>`;
  1582. // 单选题
  1583. if (examData.singleChoice && examData.singleChoice.questions.length > 0) {
  1584. htmlContent += `
  1585. <div class="section">
  1586. <div class="section-title">一、单选题(${examData.singleChoice.count}题,每题${examData.singleChoice.scorePerQuestion}分,共${examData.singleChoice.totalScore}分)</div>`;
  1587. examData.singleChoice.questions.forEach((question, index) => {
  1588. htmlContent += `
  1589. <div class="question">
  1590. <div class="question-header">
  1591. <span class="question-number">${index + 1}.</span> ${question.text}
  1592. </div>
  1593. <div class="options">`;
  1594. question.options.forEach(option => {
  1595. htmlContent += `
  1596. <div class="option">${option.key}. ${option.text}</div>`;
  1597. });
  1598. htmlContent += `
  1599. </div>
  1600. <div class="answer">正确答案:${question.selectedAnswer} </div>
  1601. </div>`;
  1602. });
  1603. htmlContent += `
  1604. </div>`;
  1605. }
  1606. // 判断题
  1607. if (examData.judge && examData.judge.questions.length > 0) {
  1608. htmlContent += `
  1609. <div class="section">
  1610. <div class="section-title">二、判断题(${examData.judge.count}题,每题${examData.judge.scorePerQuestion}分,共${examData.judge.totalScore}分)</div>`;
  1611. examData.judge.questions.forEach((question, index) => {
  1612. htmlContent += `
  1613. <div class="question">
  1614. <div class="question-header">
  1615. <span class="question-number">${index + 1}.</span> ${question.text}
  1616. </div>
  1617. <div class="answer">正确答案:${question.selectedAnswer} </div>
  1618. </div>`;
  1619. });
  1620. htmlContent += `
  1621. </div>`;
  1622. }
  1623. // 多选题
  1624. if (examData.multiple && examData.multiple.questions.length > 0) {
  1625. htmlContent += `
  1626. <div class="section">
  1627. <div class="section-title">三、多选题(${examData.multiple.count}题,每题${examData.multiple.scorePerQuestion}分,共${examData.multiple.totalScore}分)</div>`;
  1628. examData.multiple.questions.forEach((question, index) => {
  1629. htmlContent += `
  1630. <div class="question">
  1631. <div class="question-header">
  1632. <span class="question-number">${index + 1}.</span> ${question.text}
  1633. </div>
  1634. <div class="options">`;
  1635. question.options.forEach(option => {
  1636. htmlContent += `
  1637. <div class="option">${option.key}. ${option.text}</div>`;
  1638. });
  1639. htmlContent += `
  1640. </div>
  1641. <div class="answer">正确答案:${(question.selectedAnswers || []).join(', ')} </div>
  1642. </div>`;
  1643. });
  1644. htmlContent += `
  1645. </div>`;
  1646. }
  1647. // 简答题
  1648. if (examData.short && examData.short.questions.length > 0) {
  1649. htmlContent += `
  1650. <div class="section">
  1651. <div class="section-title">四、简答题(${examData.short.count}题,每题${examData.short.scorePerQuestion}分,共${examData.short.totalScore}分)</div>`;
  1652. examData.short.questions.forEach((question, index) => {
  1653. htmlContent += `
  1654. <div class="question">
  1655. <div class="question-header">
  1656. <span class="question-number">${index + 1}.</span> ${question.text}
  1657. </div>`;
  1658. if (question.outline) {
  1659. htmlContent += `
  1660. <div class="outline-section">
  1661. <strong>关键要点:</strong>${question.outline.keyFactors}
  1662. </div>
  1663. <div class="outline-section">
  1664. <strong>具体措施:</strong>${question.outline.measures}
  1665. </div>`;
  1666. }
  1667. htmlContent += `
  1668. </div>`;
  1669. });
  1670. htmlContent += `
  1671. </div>`;
  1672. }
  1673. htmlContent += `
  1674. </body>
  1675. </html>`;
  1676. return htmlContent;
  1677. };
  1678. // 文件上传相关方法
  1679. const triggerFileUpload = () => {
  1680. fileInput.value.click();
  1681. };
  1682. const handleFileSelect = async (event) => {
  1683. const file = event.target.files[0];
  1684. if (!file) return;
  1685. // 检查文件大小(20MB限制)
  1686. const maxSize = 20 * 1024 * 1024; // 20MB
  1687. if (file.size > maxSize) {
  1688. console.error('文件大小不能超过20MB');
  1689. return;
  1690. }
  1691. // 检查文件类型
  1692. const allowedTypes = ['application/vnd.ms-powerpoint', 'application/vnd.openxmlformats-officedocument.presentationml.presentation'];
  1693. if (!allowedTypes.includes(file.type)) {
  1694. console.error('请选择PPT文件(.ppt/.pptx)');
  1695. return;
  1696. }
  1697. try {
  1698. selectedFile.value = {
  1699. name: file.name,
  1700. size: file.size,
  1701. icon: '📋'
  1702. };
  1703. // 读取PPT内容
  1704. const pptContent = await readPPTFile(file);
  1705. pptContentDescription.value = pptContent;
  1706. // 自动更新试卷名称(使用文件名,去掉扩展名)
  1707. const fileName = file.name.replace(/\.[^/.]+$/, '');
  1708. examName.value = fileName + '培训考核';
  1709. console.log('✅ PPT文件上传成功:', file.name);
  1710. } catch (error) {
  1711. console.error('PPT文件处理失败:', error);
  1712. selectedFile.value = null;
  1713. }
  1714. };
  1715. const removeSelectedFile = () => {
  1716. selectedFile.value = null;
  1717. pptContentDescription.value = '';
  1718. fileInput.value.value = '';
  1719. // 恢复默认试卷名称
  1720. const projectTypeName = projectTypes[selectedProjectType.value].name;
  1721. examName.value = projectTypeName + '工程施工技术考核';
  1722. };
  1723. // 读取PPT文件的文本内容
  1724. const readPPTFile = async (file) => {
  1725. return new Promise((resolve, reject) => {
  1726. const reader = new FileReader();
  1727. reader.onload = async (e) => {
  1728. try {
  1729. console.log('开始解析PPT文件...');
  1730. // 这里使用JSZip来解压PPTX文件并提取文本
  1731. // 注意:这是一个简化版本的实现
  1732. const arrayBuffer = e.target.result;
  1733. // 提取第一页的文本内容作为示例
  1734. const content = await extractTextFromPPT(arrayBuffer);
  1735. resolve(content);
  1736. } catch (error) {
  1737. console.error('PPT解析失败:', error);
  1738. reject(error);
  1739. }
  1740. };
  1741. reader.onerror = () => {
  1742. reject(new Error('文件读取失败'));
  1743. };
  1744. reader.readAsArrayBuffer(file);
  1745. });
  1746. };
  1747. // 从PPT提取文本(简化版本)
  1748. const extractTextFromPPT = async (arrayBuffer) => {
  1749. // 这是一个简化的实现,实际项目中需要使用专门的PPT解析库
  1750. return "提取的文本内容:" +
  1751. "PPT培训课件主要包含以下内容:" +
  1752. "1. 安全培训概述" +
  1753. "- 培训目标和意义" +
  1754. "- 培训对象和要求" +
  1755. "- 培训计划和安排" +
  1756. "2. 基础知识" +
  1757. "- 安全规章制度" +
  1758. "- 危险源识别" +
  1759. "- 应急处理方法" +
  1760. "3. 操作技能" +
  1761. "- 标准化操作流程" +
  1762. "- 安全操作规范" +
  1763. "- 事故预防措施" +
  1764. "4. 考核要求" +
  1765. "- 理论知识考核" +
  1766. "- 实操技能考核" +
  1767. "- 综合评估标准" +
  1768. "此PPT内容涵盖了安全培训的各个方面,适合制作综合性的考试题目。";
  1769. };
  1770. // 格式化文件大小
  1771. const formatFileSize = (bytes) => {
  1772. if (bytes === 0) return '0 B';
  1773. const k = 1024;
  1774. const sizes = ['B', 'KB', 'MB', 'GB'];
  1775. const i = Math.floor(Math.log(bytes) / Math.log(k));
  1776. return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
  1777. };
  1778. // 清理文本中的中括号和双引号
  1779. const cleanText = (text) => {
  1780. if (!text) return '';
  1781. return text.toString()
  1782. .replace(/[\[\]]/g, '') // 移除中括号
  1783. .replace(/[""]/g, '') // 移除双引号
  1784. .replace(/['']/g, '') // 移除单引号
  1785. .trim();
  1786. };
  1787. // ============ PC端辅助函数(用于刷新题目) ============
  1788. // 构建单题重新生成的提示词
  1789. const buildSingleQuestionPrompt = (sectionType, questionIndex) => {
  1790. const projectType = projectTypes[selectedProjectType.value].name;
  1791. const questionType = getQuestionTypeName(sectionType);
  1792. const scorePerQuestion = getQuestionScore(sectionType);
  1793. // 获取当前题目作为参考
  1794. const currentQuestion = getCurrentQuestion(sectionType, questionIndex);
  1795. let prompt = `请基于以下${projectType}工程的${questionType}题目,重新生成一道相似主题的题目,要求如下:
  1796. 当前题目参考:
  1797. ${JSON.stringify(currentQuestion, null, 2)}
  1798. 题目类型:${questionType}
  1799. 每题分值:${scorePerQuestion}分
  1800. 题目序号:第${questionIndex + 1}题
  1801. 请严格按照以下JSON格式返回,不要包含任何其他文字:
  1802. `;
  1803. // 根据题目类型添加不同的格式要求
  1804. if (sectionType === 'single') {
  1805. prompt += `{
  1806. "text": "题目内容",
  1807. "options": [
  1808. {"key": "A", "text": "选项A"},
  1809. {"key": "B", "text": "选项B"},
  1810. {"key": "C", "text": "选项C"},
  1811. {"key": "D", "text": "选项D"}
  1812. ],
  1813. "selectedAnswer": "A"
  1814. }`;
  1815. } else if (sectionType === 'judge') {
  1816. prompt += `{
  1817. "text": "题目内容",
  1818. "selectedAnswer": "正确"
  1819. }`;
  1820. } else if (sectionType === 'multiple') {
  1821. prompt += `{
  1822. "text": "题目内容",
  1823. "options": [
  1824. {"key": "A", "text": "选项A"},
  1825. {"key": "B", "text": "选项B"},
  1826. {"key": "C", "text": "选项C"},
  1827. {"key": "D", "text": "选项D"}
  1828. ],
  1829. "selectedAnswers": ["A", "B"]
  1830. }`;
  1831. } else if (sectionType === 'short') {
  1832. prompt += `{
  1833. "text": "题目内容",
  1834. "outline": {
  1835. "keyFactors": "关键要点内容",
  1836. "measures": "具体措施内容"
  1837. }
  1838. }`;
  1839. }
  1840. return prompt;
  1841. };
  1842. // 获取题目类型名称
  1843. const getQuestionTypeName = (sectionType) => {
  1844. const typeMap = {
  1845. 'single': '单选题',
  1846. 'judge': '判断题',
  1847. 'multiple': '多选题',
  1848. 'short': '简答题'
  1849. };
  1850. return typeMap[sectionType] || sectionType;
  1851. };
  1852. // 获取题目分值
  1853. const getQuestionScore = (sectionType) => {
  1854. if (currentExam.value[sectionType]) {
  1855. return currentExam.value[sectionType].scorePerQuestion;
  1856. }
  1857. return 5; // 默认分值
  1858. };
  1859. // 获取当前题目
  1860. const getCurrentQuestion = (sectionType, questionIndex) => {
  1861. if (currentExam.value[sectionType] && currentExam.value[sectionType].questions) {
  1862. return currentExam.value[sectionType].questions[questionIndex];
  1863. }
  1864. return null;
  1865. };
  1866. // 解析单题AI回复
  1867. const parseSingleQuestionResponse = (aiReply, sectionType) => {
  1868. try {
  1869. console.log('AI回复内容:', aiReply);
  1870. console.log('题目类型:', sectionType);
  1871. // 尝试提取JSON内容
  1872. const jsonMatch = aiReply.match(/\{[\s\S]*\}/);
  1873. if (jsonMatch) {
  1874. const questionData = JSON.parse(jsonMatch[0]);
  1875. console.log('解析后的题目数据:', questionData);
  1876. // 如果是简答题,检查keyFactors字段
  1877. if (sectionType === 'short' && questionData.outline && questionData.outline.keyFactors) {
  1878. console.log('简答题keyFactors原始值:', questionData.outline.keyFactors);
  1879. // 如果keyFactors是数组,转换为字符串
  1880. if (Array.isArray(questionData.outline.keyFactors)) {
  1881. questionData.outline.keyFactors = questionData.outline.keyFactors.join(' ');
  1882. console.log('转换后的keyFactors:', questionData.outline.keyFactors);
  1883. }
  1884. }
  1885. return questionData;
  1886. } else {
  1887. console.error('未找到有效的JSON数据');
  1888. return null;
  1889. }
  1890. } catch (error) {
  1891. console.error('解析AI回复失败:', error);
  1892. return null;
  1893. }
  1894. };
  1895. // 更新题目
  1896. const updateQuestion = (sectionType, questionIndex, newQuestion) => {
  1897. let updatedQuestion;
  1898. if (sectionType === 'single') {
  1899. updatedQuestion = { ...newQuestion };
  1900. if (!updatedQuestion.selectedAnswer || updatedQuestion.selectedAnswer === "") {
  1901. updatedQuestion.selectedAnswer = updatedQuestion.options && updatedQuestion.options.length > 0 ? updatedQuestion.options[0].key : 'A';
  1902. }
  1903. currentExam.value.singleChoice.questions[questionIndex] = updatedQuestion;
  1904. } else if (sectionType === 'judge') {
  1905. updatedQuestion = { ...newQuestion };
  1906. if (!updatedQuestion.selectedAnswer || updatedQuestion.selectedAnswer === "") {
  1907. updatedQuestion.selectedAnswer = Math.random() > 0.5 ? '正确' : '错误';
  1908. }
  1909. currentExam.value.judge.questions[questionIndex] = updatedQuestion;
  1910. } else if (sectionType === 'multiple') {
  1911. updatedQuestion = { ...newQuestion };
  1912. if (!updatedQuestion.selectedAnswers || !Array.isArray(updatedQuestion.selectedAnswers)) {
  1913. updatedQuestion.selectedAnswers = updatedQuestion.options && updatedQuestion.options.length > 1 ? [updatedQuestion.options[0].key, updatedQuestion.options[1].key] : [];
  1914. }
  1915. currentExam.value.multiple.questions[questionIndex] = updatedQuestion;
  1916. } else if (sectionType === 'short') {
  1917. updatedQuestion = { ...newQuestion };
  1918. if (!updatedQuestion.outline) {
  1919. updatedQuestion.outline = {
  1920. keyFactors: "请参考相关教材和标准规范",
  1921. measures: "请结合实际工程案例进行解答"
  1922. };
  1923. }
  1924. currentExam.value.short.questions[questionIndex] = updatedQuestion;
  1925. }
  1926. console.log(`更新${sectionType}第${questionIndex + 1}题:`, updatedQuestion);
  1927. };
  1928. // 保存到reModifyQuestion接口
  1929. const saveToReModifyQuestion = async (sectionType, questionIndex, newQuestion) => {
  1930. console.log('对话id', ai_conversation_id.value);
  1931. try {
  1932. // 使用当前保存的对话ID
  1933. if (!ai_conversation_id.value) {
  1934. console.warn('没有找到对话ID,跳过保存');
  1935. return;
  1936. }
  1937. // 构建要保存的内容 - 保存整个试卷的JSON字符串
  1938. const content = JSON.stringify(currentExam.value);
  1939. console.log('保存到 /re_modify_question 的内容:', content);
  1940. // 调用后端接口保存修改
  1941. const response = await apis.reModifyQuestion({
  1942. ai_conversation_id: ai_conversation_id.value,
  1943. content: content
  1944. });
  1945. if (response.statusCode === 200) {
  1946. console.log('修改已保存到后端');
  1947. } else {
  1948. console.error('保存到后端失败:', response);
  1949. }
  1950. } catch (error) {
  1951. console.error('保存到后端失败:', error);
  1952. }
  1953. };
  1954. // 页面加载时不再自动加载历史记录,改为点击菜单时加载
  1955. onMounted(async () => {
  1956. try {
  1957. console.log('🚀 移动端考试工坊页面初始化完成')
  1958. // 初始化原生导航栏(子页面模式:返回按钮执行路由后退)
  1959. initNativeNavForSubPage(() => router.back())
  1960. // 检查URL参数是否有historyId需要加载
  1961. const historyId = route.query.historyId
  1962. if (historyId) {
  1963. // 需要先加载历史记录列表才能找到对应项
  1964. await getHistoryRecordList()
  1965. const targetItem = historyData.value.find(item => String(item.id) === String(historyId))
  1966. if (targetItem) {
  1967. await handleHistoryItem(targetItem)
  1968. }
  1969. }
  1970. } catch (error) {
  1971. console.error('❌ 移动端考试工坊页面初始化失败:', error)
  1972. }
  1973. })
  1974. // 监听历史记录抽屉显示状态,显示时加载数据
  1975. watch(showHistory, async (newVal) => {
  1976. if (newVal) {
  1977. console.log('📋 历史记录抽屉打开,开始刷新数据...')
  1978. await getHistoryRecordList()
  1979. }
  1980. })
  1981. </script>
  1982. <style lang="less" scoped>
  1983. .mobile-exam-workshop {
  1984. min-height: 100vh;
  1985. background: #EBF3FF;
  1986. font-family: "Alibaba PuHuiTi 3.0", sans-serif;
  1987. }
  1988. .mobile-content {
  1989. padding: 16px;
  1990. position: relative;
  1991. max-height: calc(100vh - 60px);
  1992. overflow-y: auto;
  1993. }
  1994. /* 考试工坊主界面样式 */
  1995. .exam-workshop-main {
  1996. .config-section {
  1997. background: white;
  1998. border-radius: 12px;
  1999. padding: 20px;
  2000. margin-bottom: 16px;
  2001. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  2002. .config-header {
  2003. display: flex;
  2004. align-items: center;
  2005. gap: 8px;
  2006. margin-bottom: 16px;
  2007. .step-number {
  2008. width: 28px;
  2009. height: 28px;
  2010. background: #3e7bfa;
  2011. color: white;
  2012. border-radius: 50%;
  2013. display: flex;
  2014. align-items: center;
  2015. justify-content: center;
  2016. font-size: 14px;
  2017. font-weight: 600;
  2018. }
  2019. h3 {
  2020. font-size: 20px;
  2021. font-weight: 600;
  2022. color: #1f2937;
  2023. margin: 0;
  2024. }
  2025. }
  2026. .type-cards {
  2027. .type-cards-row {
  2028. display: grid;
  2029. grid-template-columns: repeat(2, 1fr);
  2030. gap: 12px;
  2031. .type-card {
  2032. display: flex;
  2033. flex-direction: column;
  2034. align-items: center;
  2035. gap: 8px;
  2036. padding: 16px 12px;
  2037. border: 2px solid #e5e7eb;
  2038. border-radius: 12px;
  2039. background: white;
  2040. cursor: pointer;
  2041. transition: all 0.3s ease;
  2042. min-height: 80px;
  2043. justify-content: center;
  2044. &:hover {
  2045. border-color: #3e7bfa;
  2046. transform: translateY(-2px);
  2047. }
  2048. &.active {
  2049. border-color: #3e7bfa;
  2050. background: rgba(62, 123, 250, 0.1);
  2051. .type-icon {
  2052. filter: brightness(0) saturate(100%) invert(27%) sepia(51%)
  2053. saturate(2878%) hue-rotate(199deg) brightness(104%) contrast(97%);
  2054. }
  2055. span {
  2056. color: #3e7bfa;
  2057. }
  2058. }
  2059. .type-icon {
  2060. width: 32px;
  2061. height: 32px;
  2062. transition: filter 0.3s ease;
  2063. }
  2064. span {
  2065. font-size: 12px;
  2066. color: #374151;
  2067. font-weight: 500;
  2068. transition: color 0.3s ease;
  2069. text-align: center;
  2070. }
  2071. }
  2072. }
  2073. }
  2074. .generation-methods {
  2075. display: flex;
  2076. flex-direction: column;
  2077. gap: 12px;
  2078. .method-card {
  2079. display: flex;
  2080. align-items: flex-start;
  2081. gap: 12px;
  2082. padding: 16px;
  2083. border: 2px solid #e5e7eb;
  2084. border-radius: 12px;
  2085. background: white;
  2086. cursor: pointer;
  2087. transition: all 0.3s ease;
  2088. position: relative;
  2089. &:hover {
  2090. border-color: #3e7bfa;
  2091. }
  2092. &.active {
  2093. border-color: #3e7bfa;
  2094. background: rgba(62, 123, 250, 0.1);
  2095. .method-icon {
  2096. filter: brightness(0) saturate(100%) invert(27%) sepia(51%)
  2097. saturate(2878%) hue-rotate(199deg) brightness(104%) contrast(97%);
  2098. }
  2099. .method-content h4 {
  2100. color: #3e7bfa;
  2101. }
  2102. }
  2103. .method-icon {
  2104. width: 24px;
  2105. height: 24px;
  2106. flex-shrink: 0;
  2107. transition: filter 0.3s ease;
  2108. margin-top: 2px;
  2109. }
  2110. .method-content {
  2111. flex: 1;
  2112. h4 {
  2113. font-size: 14px;
  2114. font-weight: 600;
  2115. color: #1f2937;
  2116. margin: 0 0 4px 0;
  2117. transition: color 0.3s ease;
  2118. }
  2119. p {
  2120. font-size: 12px;
  2121. color: #6b7280;
  2122. margin: 0;
  2123. line-height: 1.4;
  2124. }
  2125. .ppt-file-preview {
  2126. margin-top: 8px;
  2127. .file-preview {
  2128. display: flex;
  2129. align-items: center;
  2130. background: #f9fafb;
  2131. border: 1px solid #e5e7eb;
  2132. border-radius: 8px;
  2133. padding: 8px;
  2134. .file-icon {
  2135. font-size: 16px;
  2136. margin-right: 8px;
  2137. width: 20px;
  2138. text-align: center;
  2139. }
  2140. .file-info {
  2141. flex: 1;
  2142. .file-name {
  2143. font-size: 11px;
  2144. font-weight: 500;
  2145. color: #374151;
  2146. overflow: hidden;
  2147. text-overflow: ellipsis;
  2148. white-space: nowrap;
  2149. max-width: 120px;
  2150. }
  2151. .file-size {
  2152. font-size: 10px;
  2153. color: #9ca3af;
  2154. }
  2155. }
  2156. .remove-file-btn {
  2157. background: none;
  2158. border: none;
  2159. cursor: pointer;
  2160. color: #6b7280;
  2161. padding: 2px;
  2162. .remove-icon {
  2163. font-size: 14px;
  2164. }
  2165. &:hover {
  2166. color: #ef4444;
  2167. }
  2168. }
  2169. }
  2170. }
  2171. }
  2172. }
  2173. }
  2174. .exam-config-container {
  2175. .config-main {
  2176. .config-form {
  2177. display: grid;
  2178. grid-template-columns: 2fr 1fr;
  2179. gap: 12px;
  2180. margin-bottom: 16px;
  2181. .form-group {
  2182. label {
  2183. display: block;
  2184. font-size: 16px;
  2185. font-weight: 600;
  2186. color: #374151;
  2187. margin-bottom: 6px;
  2188. }
  2189. .input-wrapper,
  2190. .score-input {
  2191. position: relative;
  2192. .config-input {
  2193. width: 100%;
  2194. height: 48px;
  2195. padding: 12px 50px 12px 16px;
  2196. border: 1px solid #d1d5db;
  2197. border-radius: 8px;
  2198. font-size: 16px !important;
  2199. background: white;
  2200. box-sizing: border-box;
  2201. line-height: 1.5;
  2202. &:focus {
  2203. outline: none;
  2204. border-color: #3e7bfa;
  2205. box-shadow: 0 0 0 2px rgba(62, 123, 250, 0.1);
  2206. }
  2207. &:disabled {
  2208. background: #f9fafb;
  2209. color: #9ca3af;
  2210. }
  2211. }
  2212. .char-count {
  2213. position: absolute;
  2214. right: 12px;
  2215. top: 50%;
  2216. transform: translateY(-50%);
  2217. font-size: 12px;
  2218. color: #6b7280;
  2219. font-weight: 500;
  2220. &.warning {
  2221. color: #f59e0b;
  2222. }
  2223. }
  2224. .unit {
  2225. position: absolute;
  2226. right: 12px;
  2227. top: 50%;
  2228. transform: translateY(-50%);
  2229. color: #6b7280;
  2230. font-size: 18px;
  2231. font-weight: 500;
  2232. }
  2233. }
  2234. .score-input {
  2235. .config-input {
  2236. padding-right: 50px;
  2237. }
  2238. }
  2239. }
  2240. }
  2241. .question-types-title {
  2242. font-size: 16px;
  2243. font-weight: 600;
  2244. color: #374151;
  2245. margin: 20px 0 12px 0;
  2246. }
  2247. .question-types {
  2248. .question-type {
  2249. background: #f9fafb;
  2250. border-radius: 8px;
  2251. padding: 12px;
  2252. margin-bottom: 8px;
  2253. .type-header {
  2254. display: flex;
  2255. align-items: center;
  2256. gap: 8px;
  2257. margin-bottom: 8px;
  2258. .type-name {
  2259. font-size: 14px;
  2260. font-weight: 600;
  2261. color: #374151;
  2262. white-space: nowrap;
  2263. }
  2264. .progress-bar {
  2265. flex: 1;
  2266. height: 4px;
  2267. background: #e5e7eb;
  2268. border-radius: 2px;
  2269. overflow: hidden;
  2270. .progress-fill {
  2271. height: 100%;
  2272. background: #3e7bfa;
  2273. transition: width 0.3s ease;
  2274. }
  2275. }
  2276. }
  2277. .score-config {
  2278. display: grid;
  2279. grid-template-columns: repeat(2, 1fr);
  2280. gap: 8px;
  2281. .config-item {
  2282. display: flex;
  2283. align-items: center;
  2284. gap: 4px;
  2285. font-size: 13px;
  2286. span {
  2287. color: #6b7280;
  2288. white-space: nowrap;
  2289. }
  2290. .score-input-field,
  2291. .count-input-field {
  2292. width: 50px;
  2293. padding: 6px 8px;
  2294. border: 1px solid #d1d5db;
  2295. border-radius: 4px;
  2296. font-size: 13px;
  2297. text-align: center;
  2298. &:focus {
  2299. outline: none;
  2300. border-color: #3e7bfa;
  2301. }
  2302. &:disabled {
  2303. background: #f3f4f6;
  2304. color: #9ca3af;
  2305. }
  2306. }
  2307. .count-stepper {
  2308. display: flex;
  2309. align-items: center;
  2310. gap: 6px;
  2311. }
  2312. .stepper-buttons {
  2313. display: flex;
  2314. flex-direction: column;
  2315. gap: 3px;
  2316. }
  2317. .stepper-btn {
  2318. width: 10px;
  2319. height: 7px;
  2320. padding: 0;
  2321. border: none;
  2322. outline: none;
  2323. appearance: none;
  2324. -webkit-appearance: none;
  2325. background: #3e7bfa;
  2326. display: block;
  2327. cursor: pointer;
  2328. transition: opacity 0.2s ease, transform 0.2s ease;
  2329. &:disabled {
  2330. opacity: 0.35;
  2331. cursor: not-allowed;
  2332. }
  2333. }
  2334. .stepper-btn-up {
  2335. clip-path: polygon(50% 0, 0 100%, 100% 100%);
  2336. }
  2337. .stepper-btn-down {
  2338. clip-path: polygon(0 0, 100% 0, 50% 100%);
  2339. }
  2340. }
  2341. }
  2342. }
  2343. }
  2344. }
  2345. .preview-panel {
  2346. background: #f8fafc;
  2347. border-radius: 8px;
  2348. padding: 16px;
  2349. margin-top: 16px;
  2350. border: 1px solid #e5e7eb;
  2351. .preview-header {
  2352. display: flex;
  2353. align-items: center;
  2354. gap: 6px;
  2355. margin-bottom: 12px;
  2356. .preview-icon {
  2357. width: 16px;
  2358. height: 16px;
  2359. }
  2360. h3 {
  2361. font-size: 16px;
  2362. font-weight: 600;
  2363. color: #374151;
  2364. margin: 0;
  2365. }
  2366. }
  2367. .preview-content {
  2368. .preview-title {
  2369. font-size: 16px;
  2370. font-weight: 600;
  2371. color: #1f2937;
  2372. margin: 0 0 12px 0;
  2373. line-height: 1.4;
  2374. }
  2375. .question-breakdown {
  2376. .breakdown-item {
  2377. margin-bottom: 6px;
  2378. .breakdown-row {
  2379. display: flex;
  2380. justify-content: space-between;
  2381. align-items: flex-start;
  2382. font-size: 13px;
  2383. .breakdown-left {
  2384. color: #4b5563;
  2385. flex: 1;
  2386. margin-right: 8px;
  2387. line-height: 1.3;
  2388. }
  2389. .breakdown-right {
  2390. color: #6b7280;
  2391. white-space: nowrap;
  2392. }
  2393. }
  2394. }
  2395. }
  2396. .divider {
  2397. height: 1px;
  2398. background: #e5e7eb;
  2399. margin: 8px 0;
  2400. }
  2401. .calculated-score-row,
  2402. .total-score-row {
  2403. display: flex;
  2404. justify-content: space-between;
  2405. margin-bottom: 4px;
  2406. font-size: 13px;
  2407. .calculated-label,
  2408. .total-label {
  2409. color: #6b7280;
  2410. }
  2411. .calculated-value,
  2412. .total-value {
  2413. color: #1f2937;
  2414. font-weight: 500;
  2415. }
  2416. }
  2417. }
  2418. }
  2419. }
  2420. .bottom-actions {
  2421. display: flex;
  2422. justify-content: center;
  2423. align-items: center;
  2424. gap: 24px;
  2425. margin-top: 20px;
  2426. width: 100%;
  2427. .clear-btn {
  2428. height: 34px;
  2429. padding: 0 16px;
  2430. border: 1px solid #d1d5db;
  2431. background: white;
  2432. color: #6b7280;
  2433. border-radius: 6px;
  2434. font-size: 14px;
  2435. font-weight: 500;
  2436. cursor: pointer;
  2437. transition: all 0.3s ease;
  2438. display: flex;
  2439. align-items: center;
  2440. justify-content: center;
  2441. &:disabled {
  2442. cursor: not-allowed !important;
  2443. pointer-events: none;
  2444. opacity: 0.5;
  2445. }
  2446. &:hover:not(:disabled) {
  2447. background: #f9fafb;
  2448. border-color: #9ca3af;
  2449. }
  2450. }
  2451. .generate-btn {
  2452. height: 34px;
  2453. padding: 0;
  2454. border: none;
  2455. background: none;
  2456. cursor: pointer;
  2457. transition: opacity 0.3s ease;
  2458. display: flex;
  2459. align-items: center;
  2460. justify-content: center;
  2461. &:disabled {
  2462. background: #f3f4f6;
  2463. color: #9ca3af;
  2464. cursor: not-allowed;
  2465. }
  2466. .generate-icon {
  2467. width: 107px;
  2468. height: 34px;
  2469. }
  2470. .generating-text {
  2471. width: 107px;
  2472. height: 34px;
  2473. display: flex;
  2474. align-items: center;
  2475. justify-content: center;
  2476. font-size: 16px;
  2477. font-weight: 600;
  2478. color: #374151;
  2479. background: #f3f4f6;
  2480. border-radius: 6px;
  2481. border: 1px solid #d1d5db;
  2482. }
  2483. &.disabled .generate-icon {
  2484. opacity: 0.5;
  2485. }
  2486. }
  2487. }
  2488. }
  2489. }
  2490. /* 考试详情页样式 */
  2491. .exam-detail-main {
  2492. .detail-header {
  2493. display: flex;
  2494. justify-content: space-between;
  2495. align-items: center;
  2496. padding: 12px 0;
  2497. margin-bottom: 16px;
  2498. .back-btn {
  2499. display: flex;
  2500. align-items: center;
  2501. gap: 6px;
  2502. padding: 8px 12px;
  2503. border-radius: 8px;
  2504. font-size: 13px;
  2505. cursor: pointer;
  2506. border: 1px solid #d1d5db;
  2507. background: white;
  2508. color: #374151;
  2509. transition: all 0.3s ease;
  2510. &:disabled {
  2511. opacity: 0.5;
  2512. cursor: not-allowed;
  2513. }
  2514. &:hover:not(:disabled) {
  2515. background: #f9fafb;
  2516. border-color: #9ca3af;
  2517. }
  2518. .back-arrow {
  2519. font-size: 14px;
  2520. }
  2521. }
  2522. .download-dropdown {
  2523. position: relative;
  2524. display: inline-block;
  2525. &.disabled {
  2526. opacity: 0.5;
  2527. cursor: not-allowed;
  2528. pointer-events: none;
  2529. }
  2530. .download-btn {
  2531. height: 34px;
  2532. padding: 0;
  2533. border: none;
  2534. background: transparent;
  2535. cursor: pointer;
  2536. transition: opacity 0.3s ease;
  2537. display: flex;
  2538. align-items: center;
  2539. justify-content: center;
  2540. &:disabled {
  2541. opacity: 0.5;
  2542. cursor: not-allowed !important;
  2543. pointer-events: none;
  2544. }
  2545. &:hover:not(:disabled) {
  2546. opacity: 0.8;
  2547. }
  2548. .download-icon {
  2549. width: 107px;
  2550. height: 34px;
  2551. }
  2552. }
  2553. .dropdown-menu {
  2554. position: absolute;
  2555. top: 100%;
  2556. right: 0;
  2557. background: white;
  2558. border: 1px solid #e5e7eb;
  2559. border-radius: 8px;
  2560. box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  2561. z-index: 1000;
  2562. min-width: 120px;
  2563. opacity: 0;
  2564. visibility: hidden;
  2565. transform: translateY(-10px);
  2566. transition: all 0.3s ease;
  2567. .dropdown-item {
  2568. padding: 12px 16px;
  2569. cursor: pointer;
  2570. transition: background-color 0.2s ease;
  2571. border-bottom: 1px solid #f3f4f6;
  2572. &:last-child {
  2573. border-bottom: none;
  2574. }
  2575. &:hover {
  2576. background: #f8fafc;
  2577. }
  2578. &:disabled {
  2579. opacity: 0.5;
  2580. cursor: not-allowed;
  2581. pointer-events: none;
  2582. }
  2583. .item-text {
  2584. font-size: 14px;
  2585. color: #374151;
  2586. }
  2587. }
  2588. }
  2589. &.show .dropdown-menu {
  2590. opacity: 1;
  2591. visibility: visible;
  2592. transform: translateY(0);
  2593. }
  2594. }
  2595. }
  2596. .exam-info {
  2597. background: white;
  2598. border-radius: 12px;
  2599. padding: 20px;
  2600. margin-bottom: 16px;
  2601. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  2602. .exam-title {
  2603. font-size: 20px;
  2604. font-weight: 600;
  2605. color: #1f2937;
  2606. margin: 0 0 12px 0;
  2607. line-height: 1.4;
  2608. }
  2609. .exam-stats {
  2610. display: flex;
  2611. gap: 16px;
  2612. margin-bottom: 8px;
  2613. .total-score,
  2614. .question-count {
  2615. font-size: 15px;
  2616. color: #6b7280;
  2617. font-weight: 500;
  2618. }
  2619. }
  2620. .generation-time {
  2621. font-size: 14px;
  2622. color: #9ca3af;
  2623. }
  2624. }
  2625. .question-sections {
  2626. .question-section {
  2627. background: white;
  2628. border-radius: 12px;
  2629. margin-bottom: 16px;
  2630. box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
  2631. overflow: hidden;
  2632. .section-header {
  2633. display: flex;
  2634. justify-content: space-between;
  2635. align-items: center;
  2636. padding: 16px 20px;
  2637. background: #f8fafc;
  2638. border-bottom: 1px solid #e5e7eb;
  2639. .section-title {
  2640. flex: 1;
  2641. .section-number {
  2642. font-size: 16px;
  2643. font-weight: 600;
  2644. color: #1f2937;
  2645. }
  2646. .section-name {
  2647. font-size: 16px;
  2648. font-weight: 600;
  2649. color: #1f2937;
  2650. margin: 0 8px;
  2651. }
  2652. .section-score {
  2653. font-size: 14px;
  2654. color: #6b7280;
  2655. }
  2656. }
  2657. .section-controls {
  2658. display: flex;
  2659. align-items: center;
  2660. gap: 8px;
  2661. .question-count-text {
  2662. font-size: 14px;
  2663. color: #6b7280;
  2664. font-weight: 500;
  2665. }
  2666. .toggle-icon {
  2667. width: 16px;
  2668. height: 16px;
  2669. transition: transform 0.3s ease;
  2670. &.expanded {
  2671. transform: rotate(180deg);
  2672. }
  2673. }
  2674. }
  2675. }
  2676. .section-content {
  2677. padding: 0;
  2678. .question-item {
  2679. border-bottom: 1px solid #f3f4f6;
  2680. padding: 16px 20px;
  2681. &:last-child {
  2682. border-bottom: none;
  2683. }
  2684. .question-header {
  2685. display: flex;
  2686. align-items: flex-start;
  2687. gap: 8px;
  2688. margin-bottom: 12px;
  2689. .question-number {
  2690. font-size: 16px;
  2691. font-weight: 600;
  2692. color: #3e7bfa;
  2693. flex-shrink: 0;
  2694. }
  2695. .question-text {
  2696. flex: 1;
  2697. font-size: 16px;
  2698. line-height: 1.5;
  2699. color: #374151;
  2700. font-weight: 500;
  2701. }
  2702. .refresh-btn {
  2703. background: none;
  2704. border: none;
  2705. cursor: pointer;
  2706. padding: 4px;
  2707. color: #6b7280;
  2708. flex-shrink: 0;
  2709. &:disabled {
  2710. cursor: not-allowed;
  2711. opacity: 0.5;
  2712. }
  2713. &:hover:not(:disabled) {
  2714. color: #3e7bfa;
  2715. }
  2716. .refresh-icon {
  2717. width: 16px;
  2718. height: 16px;
  2719. transition: transform 0.3s ease;
  2720. &.rotating {
  2721. transform: rotate(360deg);
  2722. }
  2723. }
  2724. }
  2725. }
  2726. .options {
  2727. margin-bottom: 12px;
  2728. .option {
  2729. display: flex;
  2730. align-items: flex-start;
  2731. gap: 8px;
  2732. margin-bottom: 8px;
  2733. .radio-wrapper {
  2734. flex-shrink: 0;
  2735. margin-top: 2px;
  2736. .radio-circle {
  2737. width: 14px;
  2738. height: 14px;
  2739. border: 1.5px solid #d1d5db;
  2740. border-radius: 50%;
  2741. display: flex;
  2742. align-items: center;
  2743. justify-content: center;
  2744. transition: all 0.3s ease;
  2745. &.selected {
  2746. border-color: #3e7bfa;
  2747. background: #3e7bfa;
  2748. .radio-dot {
  2749. width: 6px;
  2750. height: 6px;
  2751. background: white;
  2752. border-radius: 50%;
  2753. }
  2754. }
  2755. }
  2756. }
  2757. .option-key {
  2758. font-size: 15px;
  2759. font-weight: 600;
  2760. color: #374151;
  2761. flex-shrink: 0;
  2762. }
  2763. .option-content {
  2764. flex: 1;
  2765. .option-text {
  2766. font-size: 15px;
  2767. line-height: 1.4;
  2768. color: #374151;
  2769. font-weight: 500;
  2770. }
  2771. }
  2772. }
  2773. }
  2774. .answer-section {
  2775. padding: 8px 12px;
  2776. background: #f8fafc;
  2777. border-radius: 6px;
  2778. display: flex;
  2779. align-items: center;
  2780. gap: 8px;
  2781. .answer-label {
  2782. font-size: 14px;
  2783. color: #6b7280;
  2784. font-weight: 600;
  2785. }
  2786. .answer-value {
  2787. font-size: 14px;
  2788. color: #1f2937;
  2789. font-weight: 600;
  2790. }
  2791. }
  2792. .answer-outline {
  2793. .outline-section {
  2794. margin-bottom: 12px;
  2795. padding: 12px;
  2796. background: #f8fafc;
  2797. border-radius: 6px;
  2798. font-size: 14px;
  2799. line-height: 1.5;
  2800. strong {
  2801. color: #374151;
  2802. display: block;
  2803. margin-bottom: 4px;
  2804. font-weight: 600;
  2805. }
  2806. color: #6b7280;
  2807. }
  2808. }
  2809. }
  2810. }
  2811. }
  2812. }
  2813. }
  2814. </style>