DialogueChatView.vue 63 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936
  1. <template>
  2. <div class="dialogue-chat-view">
  3. <!-- ── 结束态全屏 loading ── -->
  4. <div v-if="reportFetchInflight" class="finalizing-screen">
  5. <div class="finalizing-spinner">
  6. <svg width="32" height="32" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  7. stroke-width="2" stroke-linecap="round">
  8. <path d="M21 12a9 9 0 1 1-6.219-8.56" />
  9. </svg>
  10. </div>
  11. <p class="finalizing-title">AI 正在为你整理报告...</p>
  12. <div class="finalizing-stats-card">
  13. <span class="finalizing-stat">{{ finalizingStats.rounds }} 轮</span>
  14. <span class="finalizing-stats-sep">·</span>
  15. <span class="finalizing-stat">{{ finalizingStats.sentences }} 句</span>
  16. <span class="finalizing-stats-sep">·</span>
  17. <span class="finalizing-stat">累计 {{ finalizingStats.durationText }}</span>
  18. </div>
  19. </div>
  20. <template v-else>
  21. <!-- ── HEADER ── -->
  22. <div class="chat-header">
  23. <div class="header-left">
  24. <div
  25. class="ai-avatar"
  26. :class="{ breathing: state === 'idle' || state === 'ai_thinking' }"
  27. >{{ aiAvatar }}</div>
  28. <span class="ai-name">{{ aiName }}</span>
  29. <span v-if="state === 'idle' && showIdleHint" class="idle-hint fade-in">
  30. 在等你的回答...
  31. </span>
  32. <span
  33. v-else-if="state !== 'idle' && state !== 'ai_thinking'"
  34. class="online-dot"
  35. title="在线"
  36. />
  37. </div>
  38. <div class="header-right">
  39. <span class="round-indicator">{{ currentRound }} / {{ totalRounds }} 轮</span>
  40. <span v-if="engine.countdownSeconds.value != null" class="total-time">
  41. {{ formatSeconds(engine.countdownSeconds.value) }}
  42. </span>
  43. <button class="icon-btn" title="更多操作" @click="showExitConfirm = true">
  44. <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  45. stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  46. <circle cx="12" cy="12" r="1" /><circle cx="19" cy="12" r="1" /><circle cx="5" cy="12" r="1" />
  47. </svg>
  48. </button>
  49. </div>
  50. </div>
  51. <!-- 麦克风权限引导 -->
  52. <div v-if="recorder.permissionState.value === 'denied'" class="permission-banner">
  53. <span class="permission-icon">🎤</span>
  54. <span>麦克风权限已被拒绝,请在浏览器设置中开启后刷新页面</span>
  55. </div>
  56. <!-- ── CHAT AREA ── -->
  57. <div ref="chatContainerRef" class="chat-area">
  58. <template v-for="message in engine.messages.value" :key="message.id">
  59. <!-- AI 消息 -->
  60. <div v-if="message.role === 'ai'" class="msg-row msg-ai fade-in">
  61. <div class="avatar-sm">{{ aiAvatar }}</div>
  62. <div class="msg-col">
  63. <!-- 音频条 -->
  64. <div v-if="message.content || message.status === 'done'" class="voice-bar voice-ai">
  65. <button
  66. class="play-btn play-ai"
  67. :class="{ 'play-btn-error': player.errorId.value === message.id }"
  68. @click="togglePlay(message.id)"
  69. >
  70. <svg
  71. v-if="player.loadingId.value === message.id"
  72. class="play-spinner"
  73. width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  74. stroke-width="2" stroke-linecap="round"
  75. >
  76. <path d="M21 12a9 9 0 1 1-6.219-8.56" />
  77. </svg>
  78. <svg
  79. v-else-if="player.playingId.value === message.id"
  80. width="12" height="12" viewBox="0 0 24 24" fill="currentColor"
  81. >
  82. <rect x="6" y="4" width="4" height="16" /><rect x="14" y="4" width="4" height="16" />
  83. </svg>
  84. <svg
  85. v-else-if="player.errorId.value === message.id"
  86. width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  87. stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  88. >
  89. <path d="M12 9v4" />
  90. <path d="M12 17h.01" />
  91. <path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z" />
  92. </svg>
  93. <svg
  94. v-else
  95. width="12" height="12" viewBox="0 0 24 24" fill="currentColor"
  96. >
  97. <polygon points="5 3 19 12 5 21 5 3" />
  98. </svg>
  99. </button>
  100. <div class="wave-bar-group">
  101. <div
  102. v-for="i in 14"
  103. :key="i"
  104. class="wave-bar wave-ai"
  105. :style="{ height: `${Math.abs(Math.sin(i * 0.7)) * 8 + 3}px` }"
  106. />
  107. </div>
  108. <span
  109. v-if="player.errorId.value === message.id"
  110. class="play-error-hint"
  111. >点击重试</span>
  112. </div>
  113. <!-- 英文文本 -->
  114. <div v-if="showEnglishText && message.content" class="bubble bubble-ai">
  115. {{ message.content }}
  116. </div>
  117. <!-- 流式加载中 -->
  118. <div v-if="message.status === 'loading' && !message.content" class="typing-bubble">
  119. <span class="typing-dot" style="animation-delay: 0ms" />
  120. <span class="typing-dot" style="animation-delay: 150ms" />
  121. <span class="typing-dot" style="animation-delay: 300ms" />
  122. </div>
  123. <!-- AI 错误 -->
  124. <div v-if="message.status === 'error'" class="error-card">
  125. <span class="error-text">{{ message.error || '生成失败' }}</span>
  126. <button
  127. v-if="hasRetryButton(message)"
  128. class="retry-btn"
  129. :disabled="engine.greetingInflight.value"
  130. @click="handleRetry(message)"
  131. >{{ retryButtonLabel(message) }}</button>
  132. </div>
  133. </div>
  134. </div>
  135. <!-- 学生消息 -->
  136. <div v-else class="msg-row msg-student fade-in">
  137. <!-- 音频条(橙色) -->
  138. <div v-if="message.content || message.status !== 'loading'" class="voice-bar voice-student">
  139. <span
  140. v-if="player.errorId.value === message.id"
  141. class="play-error-hint play-error-hint-student"
  142. >点击重试</span>
  143. <span
  144. v-else
  145. class="voice-duration voice-duration-student"
  146. >{{ formatDuration(message.audioDuration) }}</span>
  147. <div class="wave-bar-group">
  148. <div
  149. v-for="i in 14"
  150. :key="i"
  151. class="wave-bar wave-student"
  152. :style="{ height: `${Math.abs(Math.sin(i * 0.7)) * 8 + 3}px` }"
  153. />
  154. </div>
  155. <button
  156. class="play-btn play-student"
  157. :class="{ 'play-btn-error': player.errorId.value === message.id }"
  158. @click="togglePlay(message.id)"
  159. >
  160. <svg
  161. v-if="player.loadingId.value === message.id"
  162. class="play-spinner"
  163. width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  164. stroke-width="2" stroke-linecap="round"
  165. >
  166. <path d="M21 12a9 9 0 1 1-6.219-8.56" />
  167. </svg>
  168. <svg
  169. v-else-if="player.playingId.value === message.id"
  170. width="12" height="12" viewBox="0 0 24 24" fill="currentColor"
  171. >
  172. <rect x="6" y="4" width="4" height="16" /><rect x="14" y="4" width="4" height="16" />
  173. </svg>
  174. <svg
  175. v-else-if="player.errorId.value === message.id"
  176. width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  177. stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  178. >
  179. <path d="M12 9v4" />
  180. <path d="M12 17h.01" />
  181. <path d="M10.29 3.86 1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z" />
  182. </svg>
  183. <svg
  184. v-else
  185. width="12" height="12" viewBox="0 0 24 24" fill="currentColor"
  186. >
  187. <polygon points="5 3 19 12 5 21 5 3" />
  188. </svg>
  189. </button>
  190. </div>
  191. <!-- 学生 STT 加载中(与 AI typing-bubble 对称,避免按完成后 student 侧空白) -->
  192. <div v-if="message.status === 'loading' && !message.content" class="typing-bubble typing-bubble-student">
  193. <span class="typing-dot" style="animation-delay: 0ms" />
  194. <span class="typing-dot" style="animation-delay: 150ms" />
  195. <span class="typing-dot" style="animation-delay: 300ms" />
  196. </div>
  197. <!-- 英文识别文本(带高亮) -->
  198. <div v-if="showEnglishText && message.content" class="bubble bubble-student">
  199. <template v-if="message.evaluation?.wordAnalysis">
  200. <template v-for="(word, idx) in message.content.split(' ')" :key="idx">
  201. <span
  202. v-if="getWordAnalysis(message, word)?.status === 'improvable'"
  203. class="improvable-word"
  204. @click="openPhonemeDetail(getWordAnalysis(message, word)!)"
  205. >{{ word }}</span>
  206. <span v-else>{{ word }}</span>
  207. {{ ' ' }}
  208. </template>
  209. </template>
  210. <template v-else>{{ message.content }}</template>
  211. </div>
  212. <!-- 学生错误 -->
  213. <div v-if="message.status === 'error'" class="error-card">
  214. <span class="error-text">{{ message.error || '发送失败' }}</span>
  215. <button
  216. v-if="hasRetryButton(message)"
  217. class="retry-btn"
  218. @click="handleRetry(message)"
  219. >{{ retryButtonLabel(message) }}</button>
  220. <button
  221. v-if="hasRerecordButton(message)"
  222. class="rerecord-btn"
  223. @click="handleRerecord(message)"
  224. >重录</button>
  225. </div>
  226. <!-- L1 评分卡 -->
  227. <div v-if="message.evaluation" class="eval-card">
  228. <div class="eval-l1">
  229. <div class="dim-row">
  230. <span class="dim-label">准确</span>
  231. <DimBadge :level="message.evaluation.dimensions.accuracy" />
  232. <span class="dim-sep">|</span>
  233. <span class="dim-label">流畅</span>
  234. <DimBadge :level="message.evaluation.dimensions.fluency" />
  235. <span class="dim-sep">|</span>
  236. <span class="dim-label">完整</span>
  237. <DimBadge :level="message.evaluation.dimensions.completeness" />
  238. <span class="dim-sep">|</span>
  239. <span class="dim-label">节奏</span>
  240. <DimBadge :level="message.evaluation.dimensions.rhythm" />
  241. </div>
  242. <div class="sugg-row">
  243. <p class="sugg-text">
  244. <span class="sugg-icon">💡</span>
  245. <span class="truncate">{{ message.evaluation.suggestion }}</span>
  246. </p>
  247. <button class="detail-toggle" @click="toggleExpand(message.id)">
  248. {{ expandedMessageId === message.id ? '收起' : '详情' }}
  249. <svg width="10" height="10" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  250. stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
  251. :class="{ 'chev-up': expandedMessageId === message.id }">
  252. <polyline points="6 9 12 15 18 9" />
  253. </svg>
  254. </button>
  255. </div>
  256. </div>
  257. <div v-if="expandedMessageId === message.id" class="eval-l2 fade-in">
  258. <div v-if="message.evaluation.betterExpression" class="better-exp">
  259. <p class="detail-label"><span>✨</span> Better expression:</p>
  260. <p class="detail-content">{{ message.evaluation.betterExpression }}</p>
  261. </div>
  262. <div v-if="message.evaluation.suggestedWords?.length" class="suggested-words">
  263. <p class="detail-label"><span>🎯</span> Try these words:</p>
  264. <div class="word-tags">
  265. <span v-for="(w, i) in message.evaluation.suggestedWords" :key="i" class="word-tag">{{ w }}</span>
  266. </div>
  267. </div>
  268. </div>
  269. </div>
  270. </div>
  271. </template>
  272. </div>
  273. <!-- 沉默提示浮层 -->
  274. <div v-if="state === 'recording' && silenceHintText" class="silence-hint-wrap">
  275. <div class="silence-hint fade-in">
  276. <span class="silence-icon">💡</span>
  277. <p class="silence-text">{{ silenceHintText }}</p>
  278. <button class="silence-close" @click="silenceHintText = ''">
  279. <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  280. stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  281. <line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
  282. </svg>
  283. </button>
  284. </div>
  285. </div>
  286. <!-- ── CONTROL ZONE ── -->
  287. <div class="control-zone">
  288. <!-- 进度条(仅录音时可见) -->
  289. <div class="progress-wrap">
  290. <div
  291. class="progress-track"
  292. :style="{ background: state === 'recording' ? '#f3f4f6' : 'transparent' }"
  293. >
  294. <div
  295. class="progress-fill"
  296. :class="{ 'near-limit': isNearLimit }"
  297. :style="{
  298. width: state === 'recording' ? `${progressPct}%` : '0%',
  299. opacity: state === 'recording' ? 1 : 0,
  300. }"
  301. />
  302. </div>
  303. </div>
  304. <!-- 状态叠放区 -->
  305. <div class="state-stack">
  306. <!-- idle -->
  307. <div
  308. class="state-layer state-idle"
  309. :style="stateStyle('idle')"
  310. >
  311. <button class="hint-btn" @click="openTaskHint">
  312. <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  313. stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  314. <path d="M9 18h6" /><path d="M10 22h4" />
  315. <path d="M15.09 14c.18-.98.65-1.74 1.41-2.5A4.65 4.65 0 0 0 18 8 6 6 0 0 0 6 8c0 1 .23 2.23 1.5 3.5A4.61 4.61 0 0 1 8.91 14" />
  316. </svg>
  317. 提示
  318. </button>
  319. <button
  320. class="mic-btn"
  321. :disabled="!engine.canRecord.value"
  322. @click="handleStartRecording"
  323. >
  324. <svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  325. stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  326. <path d="M12 1a3 3 0 0 0-3 3v8a3 3 0 0 0 6 0V4a3 3 0 0 0-3-3z" />
  327. <path d="M19 10v2a7 7 0 0 1-14 0v-2" />
  328. <line x1="12" y1="19" x2="12" y2="23" />
  329. <line x1="8" y1="23" x2="16" y2="23" />
  330. </svg>
  331. 开始录音
  332. </button>
  333. </div>
  334. <!-- starting -->
  335. <div class="state-layer state-starting" :style="stateStyle('starting')">
  336. <div class="record-capsule">
  337. <button class="cancel-btn" @click="handleCancelStarting">
  338. <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  339. stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  340. <line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
  341. </svg>
  342. 取消
  343. </button>
  344. <div class="record-meter">
  345. <svg class="spinner" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  346. stroke-width="2" stroke-linecap="round">
  347. <path d="M21 12a9 9 0 1 1-6.219-8.56" />
  348. </svg>
  349. <span class="record-time">准备录音中...</span>
  350. </div>
  351. <button class="finish-btn" disabled>
  352. <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  353. stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  354. <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14" />
  355. <polyline points="22 4 12 14.01 9 11.01" />
  356. </svg>
  357. 完成
  358. </button>
  359. </div>
  360. </div>
  361. <!-- recording -->
  362. <div class="state-layer state-recording" :style="stateStyle('recording')">
  363. <div class="record-capsule">
  364. <button class="cancel-btn" @click="handleCancelRecording">
  365. <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  366. stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  367. <line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
  368. </svg>
  369. 取消
  370. </button>
  371. <div class="record-meter">
  372. <div class="animated-wave">
  373. <div
  374. v-for="i in 7"
  375. :key="i"
  376. class="aw-bar"
  377. :class="{ 'near-limit': isNearLimit }"
  378. :style="{
  379. height: `${Math.abs(Math.sin(i * 0.9)) * 9 + 3}px`,
  380. animationDelay: `${(i - 1) * 0.1}s`,
  381. }"
  382. />
  383. </div>
  384. <span class="record-time" :class="{ 'near-limit': isNearLimit }">
  385. {{ formatSeconds(recorder.recordingDuration.value) }}
  386. </span>
  387. <span class="record-time-max">/ {{ formatSeconds(MAX_RECORDING_SECONDS) }}</span>
  388. </div>
  389. <button class="finish-btn" @click="handleFinishRecording">
  390. <svg width="12" height="12" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  391. stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  392. <path d="M22 11.08V12a10 10 0 1 1-5.93-9.14" />
  393. <polyline points="22 4 12 14.01 9 11.01" />
  394. </svg>
  395. 完成
  396. </button>
  397. </div>
  398. </div>
  399. <!-- stt -->
  400. <div class="state-layer state-center" :style="stateStyle('stt')">
  401. <svg class="spinner" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  402. stroke-width="2" stroke-linecap="round">
  403. <path d="M21 12a9 9 0 1 1-6.219-8.56" />
  404. </svg>
  405. <span class="center-text">正在识别语音...</span>
  406. </div>
  407. <!-- ai_thinking -->
  408. <div class="state-layer state-center" :style="stateStyle('ai_thinking')">
  409. <div class="mini-avatar">{{ aiAvatar }}</div>
  410. <span class="center-text">{{ aiName }} 正在回复...</span>
  411. </div>
  412. <!-- error -->
  413. <div class="state-layer state-error" :style="stateStyle('error')">
  414. <div class="error-info">
  415. <span class="warn-icon">⚠️</span>
  416. <span class="warn-text">{{ lastErrorText }}</span>
  417. </div>
  418. <button
  419. v-if="lastErroredMessage && hasRetryButton(lastErroredMessage)"
  420. class="retry-pill"
  421. @click="handleRetry(lastErroredMessage)"
  422. >{{ retryButtonLabel(lastErroredMessage) }}</button>
  423. </div>
  424. </div>
  425. </div>
  426. <!-- ─────── OVERLAYS ─────── -->
  427. <!-- 任务提示弹窗 -->
  428. <TaskHintModal
  429. :visible="showHintModal"
  430. :loading="taskHintLoading"
  431. :error="taskHintError"
  432. :hint="taskHint"
  433. :ai-name="aiName"
  434. @close="showHintModal = false"
  435. @retry="loadTaskHint"
  436. />
  437. <!-- 音素详情弹窗 -->
  438. <div v-if="phonemeDetail" class="modal-mask" @click.self="phonemeDetail = null">
  439. <div class="modal phoneme-modal scale-in">
  440. <div class="modal-head">
  441. <div>
  442. <h3 class="phoneme-word">{{ phonemeDetail.word }}</h3>
  443. <p class="phoneme-sub">发音详情</p>
  444. </div>
  445. <button class="close-btn" @click="phonemeDetail = null">
  446. <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  447. stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  448. <line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
  449. </svg>
  450. </button>
  451. </div>
  452. <div class="phoneme-body">
  453. <div class="pho-card pho-user">
  454. <div>
  455. <p class="pho-label">你的发音</p>
  456. <p class="pho-value">{{ phonemeDetail.userPronunciation }}</p>
  457. </div>
  458. <button class="pho-play pho-play-user">
  459. <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><polygon points="5 3 19 12 5 21 5 3" /></svg>
  460. </button>
  461. </div>
  462. <div class="pho-card pho-standard">
  463. <div>
  464. <p class="pho-label">标准发音</p>
  465. <p class="pho-value pho-value-green">{{ phonemeDetail.standardPronunciation }}</p>
  466. </div>
  467. <button class="pho-play pho-play-standard">
  468. <svg width="14" height="14" viewBox="0 0 24 24" fill="currentColor"><polygon points="5 3 19 12 5 21 5 3" /></svg>
  469. </button>
  470. </div>
  471. <div v-if="phonemeDetail.tip" class="pho-card pho-tip">
  472. <p class="pho-label">小提示</p>
  473. <p class="pho-tip-text">{{ phonemeDetail.tip }}</p>
  474. </div>
  475. <button class="pho-practice-btn" @click="practiceThisWord">
  476. 针对这个词重练一次
  477. </button>
  478. </div>
  479. </div>
  480. </div>
  481. <!-- 退出/重开确认弹窗 -->
  482. <div v-if="showExitConfirm" class="modal-mask" @click.self="showExitConfirm = false">
  483. <div class="modal exit-modal scale-in">
  484. <div class="modal-head">
  485. <h3 class="modal-title">选择操作</h3>
  486. <button class="close-btn" @click="showExitConfirm = false">
  487. <svg width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor"
  488. stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
  489. <line x1="18" y1="6" x2="6" y2="18" /><line x1="6" y1="6" x2="18" y2="18" />
  490. </svg>
  491. </button>
  492. </div>
  493. <p class="exit-hint">请选择你的操作:</p>
  494. <div class="exit-actions">
  495. <button class="exit-secondary" @click="showExitConfirm = false">继续练习</button>
  496. <button class="exit-secondary" @click="handleRestart">重新开始</button>
  497. <button class="exit-primary" @click="handleExitConfirm">结束并查看报告</button>
  498. </div>
  499. </div>
  500. </div>
  501. <!-- 徽章弹窗 -->
  502. <div v-if="showBadge" class="badge-popup scale-in">
  503. <div class="badge-card">
  504. <span class="badge-icon">{{ showBadge.icon }}</span>
  505. <div>
  506. <p class="badge-name">{{ showBadge.name }}</p>
  507. <p class="badge-desc">{{ showBadge.description }}</p>
  508. </div>
  509. </div>
  510. </div>
  511. </template>
  512. </div>
  513. </template>
  514. <script lang="ts" setup>
  515. import { ref, computed, watch, onMounted, onUnmounted, nextTick, h, defineComponent } from 'vue'
  516. import type { PropType } from 'vue'
  517. import type { PreviewChatMessage, BadgeAchievement, DialogueReport, SessionStartInfo, TaskHint } from '@/types/englishSpeaking'
  518. import { useDialogueEngine } from '../composables/useDialogueEngine'
  519. import { useAudioRecorder } from '../composables/useAudioRecorder'
  520. import { useAudioPlayer } from '../composables/useAudioPlayer'
  521. import TaskHintModal from './TaskHintModal.vue'
  522. import { createDialogueApi } from '../services/llmService'
  523. import { SPEAKING_TRANSPORT } from '../services/speakingApiConfig'
  524. // ─────────────────────────────────────────────
  525. // Props / Emits
  526. // ─────────────────────────────────────────────
  527. interface Props {
  528. topic?: string
  529. keywords?: string[]
  530. aiName?: string
  531. aiAvatar?: string
  532. totalRounds?: number
  533. showEnglishText?: boolean
  534. showChineseText?: boolean
  535. sessionInfo?: SessionStartInfo | null
  536. }
  537. const props = withDefaults(defineProps<Props>(), {
  538. topic: '',
  539. keywords: () => ['animal', 'zoo', 'cute', 'favorite'],
  540. aiName: 'Amy',
  541. aiAvatar: '😊',
  542. totalRounds: 3,
  543. showEnglishText: true,
  544. showChineseText: false,
  545. sessionInfo: null,
  546. })
  547. const emit = defineEmits<{
  548. complete: [report: DialogueReport | null]
  549. restart: []
  550. }>()
  551. // ─────────────────────────────────────────────
  552. // Config
  553. // ─────────────────────────────────────────────
  554. const MAX_RECORDING_SECONDS = 60
  555. // 学生录音上送方式:'websocket'(默认,流式)或 'http'(单次 POST /speak)。
  556. // 由环境变量 VITE_SPEAKING_TRANSPORT 控制;未配置时默认 websocket。
  557. const speakTransport = SPEAKING_TRANSPORT
  558. const SILENCE_HINTS = [
  559. 'You could say: "I really like pandas because they are so cute!"',
  560. 'Try: "My favorite animal is the elephant. It\'s very smart."',
  561. 'You could say: "I went to the zoo last weekend with my family."',
  562. ]
  563. const BADGE_CONFIG: Record<string, BadgeAchievement> = {
  564. smooth_talker: { id: 'smooth_talker', name: '流畅达人', nameEn: 'Smooth Talker', icon: '💬', description: '连续3句流畅度优秀' },
  565. pronunciation_pro: { id: 'pronunciation_pro', name: '发音专家', nameEn: 'Pronunciation Pro', icon: '🎯', description: '连续5句发音准确' },
  566. perfect_round: { id: 'perfect_round', name: '完美一轮', nameEn: 'Perfect Round', icon: '⭐', description: '单轮四维度全优' },
  567. }
  568. // ─────────────────────────────────────────────
  569. // Composables
  570. // ─────────────────────────────────────────────
  571. const engine = useDialogueEngine()
  572. const recorder = useAudioRecorder()
  573. const player = useAudioPlayer()
  574. // ─────────────────────────────────────────────
  575. // Local UI State
  576. // ─────────────────────────────────────────────
  577. const chatContainerRef = ref<HTMLDivElement>()
  578. const expandedMessageId = ref<string | null>(null)
  579. const showHintModal = ref(false)
  580. const taskHint = ref<TaskHint | null>(null)
  581. const taskHintLoading = ref(false)
  582. const taskHintError = ref<string | null>(null)
  583. const taskHintApi = createDialogueApi()
  584. const showExitConfirm = ref(false)
  585. const phonemeDetail = ref<{
  586. word: string
  587. userPronunciation?: string
  588. standardPronunciation?: string
  589. tip?: string
  590. } | null>(null)
  591. const silenceHintText = ref('')
  592. const showIdleHint = ref(false)
  593. let idleHintTimer: ReturnType<typeof setTimeout> | null = null
  594. const isStarting = ref(false)
  595. const reportFetchInflight = ref(false)
  596. let startAbortController: AbortController | null = null
  597. // 徽章
  598. const showBadge = ref<BadgeAchievement | null>(null)
  599. const consecutiveFluent = ref(0)
  600. const consecutiveAccurate = ref(0)
  601. let badgeTimer: ReturnType<typeof setTimeout> | null = null
  602. // ─────────────────────────────────────────────
  603. // Derived State
  604. // ─────────────────────────────────────────────
  605. const currentRound = computed(() => engine.currentRound.value)
  606. // 状态机:starting → recording → stt → ai_thinking → idle / error / done
  607. const state = computed<
  608. 'idle' | 'starting' | 'recording' | 'stt' | 'ai_thinking' | 'error' | 'done'
  609. >(() => {
  610. if (isStarting.value) return 'starting'
  611. if (recorder.isRecording.value) return 'recording'
  612. if (engine.isComplete.value) return 'done'
  613. const msgs = engine.messages.value
  614. const last = msgs[msgs.length - 1]
  615. if (last?.status === 'error') return 'error'
  616. // 学生消息 loading 且无 content → 正在 STT
  617. if (last?.role === 'student' && last.status === 'loading' && !last.content) return 'stt'
  618. if (engine.isProcessing.value) return 'ai_thinking'
  619. return 'idle'
  620. })
  621. const progressPct = computed(() => Math.min((recorder.recordingDuration.value / MAX_RECORDING_SECONDS) * 100, 100))
  622. const isNearLimit = computed(() => recorder.recordingDuration.value >= MAX_RECORDING_SECONDS * 0.8)
  623. const lastErrorText = computed(() => {
  624. const msgs = engine.messages.value
  625. const last = msgs[msgs.length - 1]
  626. return last?.error || '请求异常,请稍后再试'
  627. })
  628. const finalizingStats = computed(() => {
  629. const studentMsgs = engine.messages.value.filter(m => m.role === 'student')
  630. const sentenceCount = studentMsgs.filter(m => m.status !== 'error').length
  631. const totalDurationSec = studentMsgs.reduce(
  632. (sum, m) => sum + (m.audioDuration ?? 0),
  633. 0,
  634. )
  635. return {
  636. rounds: engine.currentRound.value,
  637. sentences: sentenceCount,
  638. durationText: formatSeconds(Math.round(totalDurationSec)),
  639. }
  640. })
  641. // ─────────────────────────────────────────────
  642. // Sub-Component: DimBadge
  643. // ─────────────────────────────────────────────
  644. const DimBadge = defineComponent({
  645. props: { level: { type: String as PropType<'excellent' | 'good' | 'improve'>, required: true } },
  646. setup(p) {
  647. return () => {
  648. if (p.level === 'excellent') return h('span', { class: 'dim-badge dim-excellent' }, '✓✓')
  649. if (p.level === 'good') return h('span', { class: 'dim-badge dim-good' }, '✓')
  650. return h('span', { class: 'dim-badge dim-improve' }, '△')
  651. }
  652. },
  653. })
  654. // ─────────────────────────────────────────────
  655. // Helpers
  656. // ─────────────────────────────────────────────
  657. function formatSeconds(s: number): string {
  658. const m = Math.floor(s / 60)
  659. const sec = s % 60
  660. return `${m}:${sec.toString().padStart(2, '0')}`
  661. }
  662. function formatDuration(seconds: number | null | undefined): string {
  663. if (seconds == null || !Number.isFinite(seconds)) return '--:--'
  664. const total = Math.round(seconds)
  665. const mins = Math.floor(total / 60)
  666. const secs = total % 60
  667. return `${mins}:${String(secs).padStart(2, '0')}`
  668. }
  669. function getWordAnalysis(message: PreviewChatMessage, word: string) {
  670. const clean = word.replace(/[.,!?]/g, '')
  671. return message.evaluation?.wordAnalysis?.find(w => w.word === clean)
  672. }
  673. function stateStyle(target: string) {
  674. const active = state.value === target
  675. return {
  676. opacity: active ? 1 : 0,
  677. pointerEvents: active ? 'auto' : 'none',
  678. transition: 'opacity 0.18s ease-out',
  679. } as const
  680. }
  681. // ─────────────────────────────────────────────
  682. // Actions
  683. // ─────────────────────────────────────────────
  684. // 当前流式会话控制器(开始录音时打开 WebSocket,结束时收尾)
  685. let streamCtl: ReturnType<typeof engine.beginStudentStream> = null
  686. async function handleStartRecording() {
  687. if (!engine.canRecord.value || recorder.isRecording.value || isStarting.value) return
  688. player.stop()
  689. isStarting.value = true
  690. startAbortController = new AbortController()
  691. try {
  692. await recorder.startRecording(startAbortController.signal)
  693. // 学生录音上送方式由 speakingApiConfig.SPEAKING_TRANSPORT 决定:
  694. // - websocket(默认):开 WS 流式推 PCM;失败由 useDialogueEngine 暴露 error,用户点"重试"才走 HTTP。
  695. // - http:跳过 WS,handleFinishRecording 直接走 sendStudentMessage → /speak。
  696. if (speakTransport === 'websocket') {
  697. streamCtl = engine.beginStudentStream({
  698. sampleRate: recorder.sampleRate.value,
  699. bits: 16,
  700. channels: 1,
  701. })
  702. if (streamCtl) {
  703. recorder.onChunk.value = streamCtl.pushChunk
  704. }
  705. }
  706. } catch (err: any) {
  707. if (err.name === 'AbortError') {
  708. // User cancelled during getUserMedia. State naturally returns to idle.
  709. } else {
  710. console.error('Failed to start recording:', err)
  711. }
  712. } finally {
  713. isStarting.value = false
  714. startAbortController = null
  715. }
  716. }
  717. function handleCancelStarting() {
  718. startAbortController?.abort()
  719. // recorder.startRecording will reject with AbortError; no further cleanup needed.
  720. }
  721. function handleCancelRecording() {
  722. // 停止录音 + 中止流式会话(丢弃本次录音)
  723. recorder.onChunk.value = null
  724. if (streamCtl) {
  725. streamCtl.abort() // close WS; nothing on the message list to clean
  726. streamCtl = null
  727. }
  728. if (recorder.isRecording.value) {
  729. recorder.stopRecording().catch(() => {})
  730. }
  731. recorder.cleanup()
  732. }
  733. async function handleFinishRecording() {
  734. if (!recorder.isRecording.value) return
  735. const ctl = streamCtl
  736. streamCtl = null
  737. try {
  738. const blob = await recorder.stopRecording()
  739. recorder.onChunk.value = null
  740. if (ctl) {
  741. ctl.commit(blob) // pushes placeholders, attaches blob, sends 'stop'
  742. } else {
  743. // Fallback: direct HTTP path
  744. await engine.sendStudentMessage(blob, crypto.randomUUID())
  745. }
  746. } catch (err) {
  747. console.error('Recording/send failed:', err)
  748. }
  749. }
  750. function hasRetryButton(m: PreviewChatMessage): boolean {
  751. return m.recovery === 'retry' || m.recovery === 'restart'
  752. }
  753. function hasRerecordButton(m: PreviewChatMessage): boolean {
  754. return m.role === 'student' && (m.recovery === 'retry' || m.recovery === 'rerecord')
  755. }
  756. function retryButtonLabel(m: PreviewChatMessage): string {
  757. if (m.recovery === 'restart') return '返回重开'
  758. return '重试'
  759. }
  760. async function handleRetry(m: PreviewChatMessage) {
  761. if (m.recovery === 'restart') {
  762. emit('restart')
  763. return
  764. }
  765. if (m.role === 'student') {
  766. await engine.retryMessage(m.id)
  767. } else {
  768. // greeting case: first AI message with no prior student
  769. const idx = engine.messages.value.indexOf(m)
  770. const isGreeting = !engine.messages.value
  771. .slice(0, idx)
  772. .some(x => x.role === 'student')
  773. if (isGreeting) {
  774. await engine.retryGreeting()
  775. } else {
  776. await engine.regenerateAiMessage(m.id)
  777. }
  778. }
  779. }
  780. function handleRerecord(m: PreviewChatMessage) {
  781. engine.discardCurrentTurn(m.id)
  782. }
  783. const lastErroredMessage = computed<PreviewChatMessage | null>(() => {
  784. const msgs = engine.messages.value
  785. for (let i = msgs.length - 1; i >= 0; i--) {
  786. if (msgs[i].status === 'error') return msgs[i]
  787. }
  788. return null
  789. })
  790. function toggleExpand(id: string) {
  791. expandedMessageId.value = expandedMessageId.value === id ? null : id
  792. }
  793. function openTaskHint() {
  794. showHintModal.value = true
  795. if (!taskHint.value && !taskHintLoading.value) {
  796. loadTaskHint()
  797. }
  798. }
  799. async function loadTaskHint() {
  800. if (!props.sessionInfo?.sessionId) {
  801. taskHintError.value = '当前会话未准备好,请稍后重试'
  802. return
  803. }
  804. taskHintLoading.value = true
  805. taskHintError.value = null
  806. try {
  807. taskHint.value = await taskHintApi.generateTaskHint(props.sessionInfo.sessionId)
  808. } catch {
  809. taskHintError.value = '生成任务提示失败,请重试'
  810. } finally {
  811. taskHintLoading.value = false
  812. }
  813. }
  814. function togglePlay(id: string) {
  815. // Same id is currently playing or loading → stop.
  816. if (player.playingId.value === id || player.loadingId.value === id) {
  817. player.stop()
  818. return
  819. }
  820. const msg = engine.messages.value.find(m => m.id === id)
  821. if (!msg) return
  822. if (msg.role === 'student' && msg.audioBlob) {
  823. player.play(id, { kind: 'blob', blob: msg.audioBlob })
  824. }
  825. else if (msg.role === 'ai' && msg.content) {
  826. player.play(id, { kind: 'tts', text: msg.content })
  827. }
  828. }
  829. function openPhonemeDetail(wa: NonNullable<NonNullable<PreviewChatMessage['evaluation']>['wordAnalysis']>[0]) {
  830. phonemeDetail.value = {
  831. word: wa.word,
  832. userPronunciation: wa.userPronunciation,
  833. standardPronunciation: wa.standardPronunciation,
  834. tip: wa.tip,
  835. }
  836. }
  837. function practiceThisWord() {
  838. phonemeDetail.value = null
  839. handleStartRecording()
  840. }
  841. async function handleExitConfirm() {
  842. showExitConfirm.value = false
  843. emit('complete', await fetchReportSafe())
  844. }
  845. async function fetchReportSafe(): Promise<DialogueReport | null> {
  846. reportFetchInflight.value = true
  847. try {
  848. await engine.completeSession()
  849. return await engine.getReport()
  850. } catch (err) {
  851. console.warn('[speaking] getReport failed:', err)
  852. return null
  853. } finally {
  854. reportFetchInflight.value = false
  855. }
  856. }
  857. function handleRestart() {
  858. showExitConfirm.value = false
  859. engine.abort()
  860. player.stop()
  861. emit('restart')
  862. }
  863. // ─────────────────────────────────────────────
  864. // Badge detection
  865. // ─────────────────────────────────────────────
  866. function triggerBadge(id: string) {
  867. const badge = BADGE_CONFIG[id]
  868. if (!badge) return
  869. showBadge.value = badge
  870. if (badgeTimer) clearTimeout(badgeTimer)
  871. badgeTimer = setTimeout(() => { showBadge.value = null }, 2800)
  872. }
  873. function checkBadges(ev: NonNullable<PreviewChatMessage['evaluation']>) {
  874. const d = ev.dimensions
  875. if (d.fluency === 'excellent') {
  876. consecutiveFluent.value += 1
  877. if (consecutiveFluent.value === 3) triggerBadge('smooth_talker')
  878. } else {
  879. consecutiveFluent.value = 0
  880. }
  881. if (d.accuracy === 'excellent') {
  882. consecutiveAccurate.value += 1
  883. if (consecutiveAccurate.value === 5) triggerBadge('pronunciation_pro')
  884. } else {
  885. consecutiveAccurate.value = 0
  886. }
  887. if (d.accuracy === 'excellent' && d.fluency === 'excellent' && d.completeness === 'excellent' && d.rhythm === 'excellent') {
  888. setTimeout(() => triggerBadge('perfect_round'), 400)
  889. }
  890. }
  891. // ─────────────────────────────────────────────
  892. // Watchers
  893. // ─────────────────────────────────────────────
  894. // 自动滚动到底部
  895. watch(
  896. () => engine.messages.value.map(m => m.content + m.status).join('|'),
  897. () => {
  898. nextTick(() => {
  899. if (chatContainerRef.value) {
  900. chatContainerRef.value.scrollTop = chatContainerRef.value.scrollHeight
  901. }
  902. })
  903. },
  904. )
  905. // 自动播放:AI 消息流式 done 后,合成并播一次。
  906. // 用 Set 去重防止 watcher 因为不相关重渲染重复触发。
  907. const autoPlayedIds = new Set<string>()
  908. const seededHistoricalMessageIds = new Set<string>()
  909. watch(
  910. () => engine.messages.value.map(m => `${m.id}:${m.status}`).join('|'),
  911. () => {
  912. for (const m of engine.messages.value) {
  913. if (
  914. m.role === 'ai' &&
  915. m.status === 'done' &&
  916. m.content &&
  917. !seededHistoricalMessageIds.has(m.id) &&
  918. !autoPlayedIds.has(m.id)
  919. ) {
  920. autoPlayedIds.add(m.id)
  921. player.play(m.id, { kind: 'tts', text: m.content })
  922. }
  923. }
  924. },
  925. )
  926. // AI 消息 done 后,延迟 600ms 显示 "在等你的回答..."
  927. watch(
  928. () => {
  929. const msgs = engine.messages.value
  930. const last = msgs[msgs.length - 1]
  931. return last?.role === 'ai' && last.status === 'done' ? last.id : null
  932. },
  933. (val) => {
  934. if (idleHintTimer) clearTimeout(idleHintTimer)
  935. if (val) {
  936. showIdleHint.value = false
  937. idleHintTimer = setTimeout(() => { showIdleHint.value = true }, 600)
  938. } else {
  939. showIdleHint.value = false
  940. }
  941. },
  942. )
  943. // 学生消息产生 evaluation 时,检查徽章 + 清理沉默提示
  944. watch(
  945. () => engine.messages.value.filter(m => m.role === 'student' && m.evaluation).length,
  946. () => {
  947. const done = engine.messages.value.filter(m => m.role === 'student' && m.evaluation)
  948. const last = done[done.length - 1]
  949. if (last?.evaluation) checkBadges(last.evaluation)
  950. },
  951. )
  952. // 对话完成 → 通知父组件
  953. watch(
  954. () => engine.isComplete.value,
  955. async (complete) => {
  956. if (complete) emit('complete', await fetchReportSafe())
  957. },
  958. )
  959. // 沉默检测 → 随机提示
  960. watch(
  961. () => recorder.silenceDetected.value,
  962. (silent) => {
  963. if (silent && recorder.isRecording.value) {
  964. silenceHintText.value = SILENCE_HINTS[Math.floor(Math.random() * SILENCE_HINTS.length)]
  965. } else {
  966. silenceHintText.value = ''
  967. }
  968. },
  969. )
  970. // 录音时长达到上限,自动完成
  971. watch(
  972. () => recorder.recordingDuration.value,
  973. (v) => {
  974. if (v >= MAX_RECORDING_SECONDS && recorder.isRecording.value) {
  975. handleFinishRecording()
  976. }
  977. },
  978. )
  979. // ─────────────────────────────────────────────
  980. // Lifecycle
  981. // ─────────────────────────────────────────────
  982. onMounted(() => {
  983. if (props.sessionInfo) {
  984. const hasHistory = !!props.sessionInfo.messages?.length
  985. seededHistoricalMessageIds.clear()
  986. for (const message of props.sessionInfo.messages ?? []) {
  987. seededHistoricalMessageIds.add(message.id)
  988. }
  989. engine.attachSession({
  990. sessionId: props.sessionInfo.sessionId,
  991. expiresAt: props.sessionInfo.expiresAt,
  992. totalRounds: props.totalRounds,
  993. currentRound: props.sessionInfo.currentRound,
  994. messages: props.sessionInfo.messages,
  995. })
  996. if (!hasHistory) engine.generateGreeting()
  997. } else {
  998. console.warn('[DialogueChatView] mounted without sessionInfo; chat is inert. Parent must createSession before mounting.')
  999. }
  1000. // 无 sessionInfo 时聊天区保持空(父组件应当先创建 session 再挂载本组件)
  1001. })
  1002. onUnmounted(() => {
  1003. if (idleHintTimer) clearTimeout(idleHintTimer)
  1004. if (badgeTimer) clearTimeout(badgeTimer)
  1005. })
  1006. </script>
  1007. <style lang="scss" scoped>
  1008. // ─────────────────────────────────────────────
  1009. // Root
  1010. // ─────────────────────────────────────────────
  1011. .dialogue-chat-view {
  1012. width: 100%;
  1013. height: 100%;
  1014. display: flex;
  1015. flex-direction: column;
  1016. position: relative;
  1017. user-select: none;
  1018. background: #fff;
  1019. font-size: 12px;
  1020. }
  1021. // ─────────────────────────────────────────────
  1022. // Header
  1023. // ─────────────────────────────────────────────
  1024. .chat-header {
  1025. display: flex;
  1026. align-items: center;
  1027. justify-content: space-between;
  1028. padding: 8px 12px;
  1029. border-bottom: 1px solid #f3f4f6;
  1030. background: #fff;
  1031. flex-shrink: 0;
  1032. }
  1033. .header-left {
  1034. display: flex;
  1035. align-items: center;
  1036. gap: 8px;
  1037. min-width: 0;
  1038. }
  1039. .ai-avatar {
  1040. width: 24px; height: 24px;
  1041. border-radius: 50%;
  1042. background: #fff7ed;
  1043. border: 1px solid #fed7aa;
  1044. display: flex; align-items: center; justify-content: center;
  1045. font-size: 12px;
  1046. flex-shrink: 0;
  1047. &.breathing { animation: breathing 2.4s ease-in-out infinite; }
  1048. }
  1049. .ai-name { font-size: 12px; font-weight: 600; color: #1f2937; }
  1050. .idle-hint { font-size: 11px; color: #9ca3af; }
  1051. .online-dot {
  1052. width: 6px; height: 6px;
  1053. background: #10b981;
  1054. border-radius: 50%;
  1055. }
  1056. .header-right {
  1057. display: flex;
  1058. align-items: center;
  1059. gap: 12px;
  1060. }
  1061. .round-indicator { font-size: 11px; font-weight: 500; color: #f97316; }
  1062. .total-time { font-size: 11px; font-weight: 500; color: #6b7280; font-variant-numeric: tabular-nums; }
  1063. .icon-btn {
  1064. padding: 6px;
  1065. border: none; background: transparent;
  1066. color: #9ca3af;
  1067. border-radius: 6px;
  1068. display: flex; align-items: center; justify-content: center;
  1069. cursor: pointer;
  1070. transition: background 0.15s, color 0.15s;
  1071. &:hover { background: #f3f4f6; color: #4b5563; }
  1072. }
  1073. // ─────────────────────────────────────────────
  1074. // Permission banner
  1075. // ─────────────────────────────────────────────
  1076. .permission-banner {
  1077. display: flex;
  1078. align-items: center;
  1079. gap: 8px;
  1080. padding: 8px 12px;
  1081. background: #fef3c7;
  1082. border-bottom: 1px solid #fde68a;
  1083. font-size: 11px;
  1084. color: #92400e;
  1085. flex-shrink: 0;
  1086. }
  1087. .permission-icon { font-size: 14px; }
  1088. // ─────────────────────────────────────────────
  1089. // Chat area
  1090. // ─────────────────────────────────────────────
  1091. .chat-area {
  1092. flex: 1;
  1093. overflow-y: auto;
  1094. padding: 12px;
  1095. display: flex;
  1096. flex-direction: column;
  1097. gap: 12px;
  1098. background: #f7f8fa;
  1099. min-height: 0;
  1100. }
  1101. .msg-row {
  1102. display: flex;
  1103. align-items: flex-end;
  1104. gap: 8px;
  1105. }
  1106. .msg-ai { justify-content: flex-start; }
  1107. .msg-student {
  1108. flex-direction: column;
  1109. align-items: flex-end;
  1110. gap: 4px;
  1111. }
  1112. .msg-col {
  1113. max-width: 78%;
  1114. display: flex;
  1115. flex-direction: column;
  1116. gap: 4px;
  1117. }
  1118. .avatar-sm {
  1119. width: 28px; height: 28px;
  1120. border-radius: 50%;
  1121. background: #fff7ed;
  1122. border: 1px solid #fed7aa;
  1123. display: flex; align-items: center; justify-content: center;
  1124. font-size: 14px;
  1125. flex-shrink: 0;
  1126. margin-bottom: 2px;
  1127. }
  1128. // 语音条
  1129. .voice-bar {
  1130. display: flex;
  1131. align-items: center;
  1132. gap: 8px;
  1133. padding: 8px 12px;
  1134. width: clamp(140px, 44%, 210px);
  1135. }
  1136. .voice-ai {
  1137. background: #fff;
  1138. border: 1px solid #f3f4f6;
  1139. border-radius: 16px;
  1140. border-top-left-radius: 4px;
  1141. box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  1142. }
  1143. .voice-student {
  1144. background: #f97316;
  1145. border-radius: 16px;
  1146. border-top-right-radius: 4px;
  1147. }
  1148. .play-btn {
  1149. width: 24px; height: 24px;
  1150. border-radius: 50%;
  1151. border: none;
  1152. display: flex; align-items: center; justify-content: center;
  1153. flex-shrink: 0;
  1154. cursor: pointer;
  1155. transition: background 0.2s;
  1156. }
  1157. .play-ai {
  1158. background: rgba(249,115,22,0.1);
  1159. color: #f97316;
  1160. &:hover { background: rgba(249,115,22,0.2); }
  1161. }
  1162. .play-student {
  1163. background: rgba(255,255,255,0.2);
  1164. color: #fff;
  1165. &:hover { background: rgba(255,255,255,0.3); }
  1166. }
  1167. .play-btn-error {
  1168. background: #fef2f2 !important;
  1169. color: #dc2626 !important;
  1170. border: 1px solid #fecaca;
  1171. &:hover { background: #fee2e2 !important; }
  1172. }
  1173. .play-spinner {
  1174. animation: spin 1s linear infinite;
  1175. }
  1176. .play-error-hint {
  1177. font-size: 10px;
  1178. color: #dc2626;
  1179. font-weight: 500;
  1180. flex-shrink: 0;
  1181. white-space: nowrap;
  1182. }
  1183. .play-error-hint-student {
  1184. color: #fff;
  1185. }
  1186. .wave-bar-group {
  1187. flex: 1;
  1188. display: flex;
  1189. align-items: center;
  1190. gap: 1px;
  1191. }
  1192. .wave-bar {
  1193. width: 2px;
  1194. border-radius: 999px;
  1195. flex-shrink: 0;
  1196. }
  1197. .wave-ai { background: rgba(249,115,22,0.4); }
  1198. .wave-student { background: rgba(255,255,255,0.5); }
  1199. .voice-duration { font-size: 10px; flex-shrink: 0; }
  1200. .voice-duration-ai { color: #9ca3af; }
  1201. .voice-duration-student { color: rgba(255,255,255,0.7); }
  1202. // 气泡
  1203. .bubble {
  1204. padding: 8px 12px;
  1205. border-radius: 12px;
  1206. font-size: 12px;
  1207. line-height: 1.55;
  1208. max-width: 100%;
  1209. }
  1210. .bubble-ai {
  1211. background: #fff;
  1212. border: 1px solid #f3f4f6;
  1213. border-top-left-radius: 4px;
  1214. color: #374151;
  1215. box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  1216. }
  1217. .bubble-student {
  1218. background: #fff7ed;
  1219. border: 1px solid #fed7aa;
  1220. border-top-right-radius: 4px;
  1221. color: #374151;
  1222. max-width: 78%;
  1223. padding: 6px 12px;
  1224. }
  1225. .improvable-word {
  1226. color: #d97706;
  1227. text-decoration: underline wavy #fbbf24;
  1228. cursor: pointer;
  1229. padding: 0 2px;
  1230. border-radius: 2px;
  1231. transition: background 0.2s;
  1232. &:hover { background: #fef3c7; }
  1233. }
  1234. // typing 指示器
  1235. .typing-bubble {
  1236. display: inline-flex;
  1237. align-items: center;
  1238. gap: 4px;
  1239. padding: 10px 14px;
  1240. background: #fff;
  1241. border: 1px solid #f3f4f6;
  1242. border-radius: 16px;
  1243. border-top-left-radius: 4px;
  1244. box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  1245. }
  1246. .typing-bubble-student {
  1247. border-top-left-radius: 16px;
  1248. border-top-right-radius: 4px;
  1249. }
  1250. .typing-dot {
  1251. width: 6px; height: 6px;
  1252. background: rgba(249,115,22,0.7);
  1253. border-radius: 50%;
  1254. animation: typing-bounce 1s ease-in-out infinite;
  1255. }
  1256. @keyframes typing-bounce {
  1257. 0%, 100% { transform: translateY(0); opacity: 0.5; }
  1258. 50% { transform: translateY(-3px); opacity: 1; }
  1259. }
  1260. // 错误卡
  1261. .error-card {
  1262. margin-top: 4px;
  1263. padding: 6px 10px;
  1264. background: #fef2f2;
  1265. border: 1px solid #fecaca;
  1266. border-radius: 10px;
  1267. display: inline-flex;
  1268. align-items: center;
  1269. gap: 8px;
  1270. }
  1271. .error-text { font-size: 11px; color: #dc2626; }
  1272. .retry-btn {
  1273. padding: 3px 10px;
  1274. background: #fff;
  1275. border: 1px solid #fecaca;
  1276. border-radius: 999px;
  1277. font-size: 11px;
  1278. color: #dc2626;
  1279. cursor: pointer;
  1280. &:hover { background: #fef2f2; border-color: #f87171; }
  1281. }
  1282. .rerecord-btn {
  1283. padding: 3px 10px;
  1284. background: transparent;
  1285. border: 1px solid #d1d5db;
  1286. border-radius: 999px;
  1287. font-size: 11px;
  1288. color: #6b7280;
  1289. cursor: pointer;
  1290. margin-left: 4px;
  1291. &:hover { background: #f9fafb; border-color: #9ca3af; color: #374151; }
  1292. }
  1293. // 评分卡
  1294. .eval-card {
  1295. background: #fff;
  1296. border: 1px solid #f3f4f6;
  1297. border-radius: 12px;
  1298. box-shadow: 0 1px 2px rgba(0,0,0,0.05);
  1299. overflow: hidden;
  1300. width: clamp(260px, 88%, 420px);
  1301. text-align: left;
  1302. margin-top: 2px;
  1303. }
  1304. .eval-l1 { padding: 8px 12px; }
  1305. .dim-row {
  1306. display: flex;
  1307. align-items: center;
  1308. gap: 6px;
  1309. font-size: 10px;
  1310. color: #6b7280;
  1311. flex-wrap: wrap;
  1312. }
  1313. .dim-label { color: #6b7280; }
  1314. .dim-sep { color: #e5e7eb; margin: 0 2px; }
  1315. .dim-badge {
  1316. font-size: 10px;
  1317. font-weight: 600;
  1318. padding: 1px 4px;
  1319. border-radius: 3px;
  1320. }
  1321. .dim-excellent { color: #059669; background: #ecfdf5; }
  1322. .dim-good { color: #10b981; background: #ecfdf5; }
  1323. .dim-improve { color: #f59e0b; background: #fffbeb; }
  1324. .sugg-row {
  1325. display: flex;
  1326. align-items: center;
  1327. justify-content: space-between;
  1328. gap: 8px;
  1329. margin-top: 6px;
  1330. }
  1331. .sugg-text {
  1332. flex: 1;
  1333. min-width: 0;
  1334. font-size: 10px;
  1335. color: #6b7280;
  1336. display: flex;
  1337. align-items: center;
  1338. gap: 4px;
  1339. margin: 0;
  1340. }
  1341. .sugg-icon { color: #f59e0b; flex-shrink: 0; }
  1342. .truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  1343. .detail-toggle {
  1344. font-size: 10px;
  1345. color: #f97316;
  1346. background: transparent;
  1347. border: none;
  1348. cursor: pointer;
  1349. display: flex;
  1350. align-items: center;
  1351. gap: 2px;
  1352. flex-shrink: 0;
  1353. &:hover { color: #ea580c; }
  1354. svg { transition: transform 0.2s; }
  1355. .chev-up { transform: rotate(180deg); }
  1356. }
  1357. .eval-l2 {
  1358. padding: 10px 12px;
  1359. border-top: 1px solid #f9fafb;
  1360. background: #fafbfc;
  1361. display: flex;
  1362. flex-direction: column;
  1363. gap: 10px;
  1364. }
  1365. .detail-label {
  1366. font-size: 10px;
  1367. color: #9ca3af;
  1368. margin: 0 0 4px;
  1369. display: flex;
  1370. align-items: center;
  1371. gap: 4px;
  1372. }
  1373. .detail-content {
  1374. font-size: 12px;
  1375. color: #374151;
  1376. background: #fff;
  1377. padding: 6px 10px;
  1378. border: 1px solid #f3f4f6;
  1379. border-radius: 8px;
  1380. margin: 0;
  1381. line-height: 1.5;
  1382. }
  1383. .word-tags { display: flex; flex-wrap: wrap; gap: 4px; }
  1384. .word-tag {
  1385. padding: 2px 8px;
  1386. background: #fff7ed;
  1387. color: #ea580c;
  1388. font-size: 10px;
  1389. border-radius: 999px;
  1390. border: 1px solid #fed7aa;
  1391. }
  1392. // ─────────────────────────────────────────────
  1393. // Silence hint
  1394. // ─────────────────────────────────────────────
  1395. .silence-hint-wrap {
  1396. position: absolute;
  1397. bottom: 76px;
  1398. left: 0; right: 0;
  1399. display: flex;
  1400. justify-content: center;
  1401. z-index: 10;
  1402. padding: 0 16px;
  1403. pointer-events: none;
  1404. }
  1405. .silence-hint {
  1406. background: rgba(255,255,255,0.95);
  1407. backdrop-filter: blur(6px);
  1408. border: 1px solid #fed7aa;
  1409. border-radius: 14px;
  1410. box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  1411. padding: 10px 14px;
  1412. display: flex;
  1413. align-items: flex-start;
  1414. gap: 10px;
  1415. max-width: 320px;
  1416. width: 100%;
  1417. pointer-events: auto;
  1418. }
  1419. .silence-icon { color: #fb923c; font-size: 14px; flex-shrink: 0; margin-top: 2px; }
  1420. .silence-text { font-size: 12px; color: #4b5563; margin: 0; line-height: 1.5; flex: 1; }
  1421. .silence-close {
  1422. background: transparent; border: none;
  1423. color: #d1d5db;
  1424. cursor: pointer;
  1425. padding: 2px;
  1426. flex-shrink: 0;
  1427. &:hover { color: #6b7280; }
  1428. }
  1429. // ─────────────────────────────────────────────
  1430. // Control zone
  1431. // ─────────────────────────────────────────────
  1432. .control-zone {
  1433. flex-shrink: 0;
  1434. border-top: 1px solid #f3f4f6;
  1435. background: #fff;
  1436. padding: 10px 16px 12px;
  1437. }
  1438. .progress-wrap {
  1439. max-width: 384px;
  1440. margin: 0 auto 8px;
  1441. }
  1442. .progress-track {
  1443. height: 1px;
  1444. border-radius: 999px;
  1445. overflow: hidden;
  1446. }
  1447. .progress-fill {
  1448. height: 100%;
  1449. background: #fb923c;
  1450. transition: width 1s linear, background-color 0.4s ease, opacity 0.2s ease;
  1451. &.near-limit { background: #f87171; }
  1452. }
  1453. .state-stack {
  1454. position: relative;
  1455. height: 36px;
  1456. max-width: 384px;
  1457. margin: 0 auto;
  1458. }
  1459. .state-layer {
  1460. position: absolute;
  1461. inset: 0;
  1462. display: flex;
  1463. align-items: center;
  1464. }
  1465. .state-idle {
  1466. justify-content: center;
  1467. gap: 12px;
  1468. }
  1469. .state-center { justify-content: center; gap: 8px; }
  1470. .state-error {
  1471. justify-content: space-between;
  1472. gap: 12px;
  1473. }
  1474. // idle buttons
  1475. .hint-btn {
  1476. display: inline-flex;
  1477. align-items: center;
  1478. gap: 5px;
  1479. padding: 5px 14px;
  1480. border-radius: 999px;
  1481. background: #f9fafb;
  1482. border: 1px solid #e5e7eb;
  1483. color: #6b7280;
  1484. font-size: 11px;
  1485. font-weight: 500;
  1486. cursor: pointer;
  1487. transition: background 0.2s, border-color 0.2s, color 0.2s;
  1488. &:hover {
  1489. background: #fff7ed;
  1490. border-color: #fed7aa;
  1491. color: #f97316;
  1492. }
  1493. }
  1494. .mic-btn {
  1495. display: inline-flex;
  1496. align-items: center;
  1497. gap: 8px;
  1498. padding: 7px 24px;
  1499. border-radius: 999px;
  1500. background: #f97316;
  1501. border: none;
  1502. color: #fff;
  1503. font-size: 13px;
  1504. font-weight: 500;
  1505. cursor: pointer;
  1506. box-shadow: 0 4px 10px rgba(249,115,22,0.25);
  1507. transition: background 0.2s, transform 0.15s;
  1508. &:hover { background: #ea580c; }
  1509. &:active { transform: scale(0.96); }
  1510. &:disabled { opacity: 0.5; cursor: not-allowed; background: #d1d5db; box-shadow: none; }
  1511. }
  1512. // recording capsule
  1513. .record-capsule {
  1514. width: 100%;
  1515. display: flex;
  1516. align-items: center;
  1517. gap: 8px;
  1518. padding: 5px 10px;
  1519. border-radius: 999px;
  1520. background: #f9fafb;
  1521. border: 1px solid #f3f4f6;
  1522. }
  1523. .cancel-btn, .finish-btn {
  1524. display: inline-flex;
  1525. align-items: center;
  1526. gap: 4px;
  1527. padding: 4px 10px;
  1528. border-radius: 999px;
  1529. font-size: 11px;
  1530. font-weight: 500;
  1531. cursor: pointer;
  1532. flex-shrink: 0;
  1533. transition: background 0.2s, border-color 0.2s, color 0.2s;
  1534. }
  1535. .cancel-btn {
  1536. background: #fff;
  1537. border: 1px solid #e5e7eb;
  1538. color: #6b7280;
  1539. &:hover { background: #fef2f2; border-color: #fecaca; color: #ef4444; }
  1540. }
  1541. .finish-btn {
  1542. background: #f97316;
  1543. border: none;
  1544. color: #fff;
  1545. &:hover:not(:disabled) { background: #ea580c; }
  1546. &:disabled {
  1547. background: #d1d5db;
  1548. color: #9ca3af;
  1549. cursor: not-allowed;
  1550. }
  1551. }
  1552. .record-meter {
  1553. flex: 1;
  1554. display: flex;
  1555. align-items: center;
  1556. justify-content: center;
  1557. gap: 6px;
  1558. }
  1559. .animated-wave { display: flex; align-items: center; gap: 1px; }
  1560. .aw-bar {
  1561. width: 2px;
  1562. border-radius: 999px;
  1563. background: #f97316;
  1564. animation: aw-pulse 1.2s ease-in-out infinite;
  1565. &.near-limit { background: #ef4444; }
  1566. }
  1567. @keyframes aw-pulse {
  1568. 0%, 100% { opacity: 0.55; }
  1569. 50% { opacity: 1; }
  1570. }
  1571. .record-time {
  1572. font-size: 12px;
  1573. font-family: monospace;
  1574. font-weight: 600;
  1575. color: #1f2937;
  1576. font-variant-numeric: tabular-nums;
  1577. &.near-limit { color: #ef4444; }
  1578. }
  1579. .record-time-max { font-size: 10px; color: #d1d5db; }
  1580. // stt / thinking
  1581. .spinner {
  1582. color: #fb923c;
  1583. animation: spin 1s linear infinite;
  1584. }
  1585. @keyframes spin {
  1586. to { transform: rotate(360deg); }
  1587. }
  1588. .mini-avatar {
  1589. width: 16px; height: 16px;
  1590. border-radius: 50%;
  1591. background: #fff7ed;
  1592. display: flex; align-items: center; justify-content: center;
  1593. font-size: 10px;
  1594. }
  1595. .center-text { font-size: 12px; color: #9ca3af; }
  1596. // error
  1597. .error-info { display: flex; align-items: center; gap: 6px; }
  1598. .warn-icon { color: #f59e0b; font-size: 12px; }
  1599. .warn-text { font-size: 12px; color: #4b5563; }
  1600. .retry-pill {
  1601. padding: 5px 14px;
  1602. border-radius: 999px;
  1603. background: #f97316;
  1604. color: #fff;
  1605. border: none;
  1606. font-size: 12px;
  1607. font-weight: 500;
  1608. cursor: pointer;
  1609. &:hover { background: #ea580c; }
  1610. }
  1611. // ─────────────────────────────────────────────
  1612. // Modals
  1613. // ─────────────────────────────────────────────
  1614. .modal-mask {
  1615. position: fixed;
  1616. inset: 0;
  1617. background: rgba(0,0,0,0.3);
  1618. backdrop-filter: blur(2px);
  1619. display: flex;
  1620. align-items: center;
  1621. justify-content: center;
  1622. z-index: 50;
  1623. padding: 16px;
  1624. }
  1625. .modal {
  1626. background: #fff;
  1627. border-radius: 16px;
  1628. width: 100%;
  1629. max-height: 80vh;
  1630. overflow-y: auto;
  1631. box-shadow: 0 20px 60px rgba(0,0,0,0.15);
  1632. }
  1633. .phoneme-modal { max-width: 320px; }
  1634. .exit-modal { max-width: 320px; padding: 20px; }
  1635. .modal-head {
  1636. display: flex;
  1637. align-items: center;
  1638. justify-content: space-between;
  1639. margin-bottom: 12px;
  1640. }
  1641. .modal-title {
  1642. font-size: 14px;
  1643. font-weight: 600;
  1644. color: #111827;
  1645. display: flex;
  1646. align-items: center;
  1647. gap: 6px;
  1648. margin: 0;
  1649. }
  1650. .close-btn {
  1651. width: 26px; height: 26px;
  1652. background: #f3f4f6;
  1653. border: none;
  1654. border-radius: 8px;
  1655. color: #6b7280;
  1656. cursor: pointer;
  1657. display: flex; align-items: center; justify-content: center;
  1658. &:hover { background: #e5e7eb; }
  1659. }
  1660. // 音素
  1661. .phoneme-word { text-align: left; font-size: 16px; font-weight: 700; color: #111827; margin: 0; }
  1662. .phoneme-sub { font-size: 11px; color: #9ca3af; margin: 2px 0 0; }
  1663. .phoneme-body {
  1664. padding: 0 20px 20px;
  1665. display: flex;
  1666. flex-direction: column;
  1667. gap: 10px;
  1668. }
  1669. .modal-head + .phoneme-body { padding-top: 0; }
  1670. .phoneme-modal .modal-head { padding: 20px 20px 12px; margin-bottom: 0; }
  1671. .pho-card {
  1672. border-radius: 12px;
  1673. padding: 12px;
  1674. display: flex;
  1675. align-items: center;
  1676. justify-content: space-between;
  1677. gap: 12px;
  1678. }
  1679. .pho-user { background: #fffbeb; border: 1px solid #fde68a; }
  1680. .pho-standard { background: #ecfdf5; border: 1px solid #bbf7d0; }
  1681. .pho-tip { background: #eff6ff; border: 1px solid #bfdbfe; display: block; }
  1682. .pho-label { font-size: 10px; font-weight: 500; margin: 0 0 2px; }
  1683. .pho-user .pho-label { color: #d97706; }
  1684. .pho-standard .pho-label { color: #059669; }
  1685. .pho-tip .pho-label { color: #2563eb; }
  1686. .pho-value { font-size: 14px; font-family: monospace; color: #b45309; margin: 0; }
  1687. .pho-value-green { color: #15803d; }
  1688. .pho-tip-text { font-size: 12px; color: #1d4ed8; margin: 0; line-height: 1.5; }
  1689. .pho-play {
  1690. width: 30px; height: 30px;
  1691. border-radius: 8px;
  1692. border: 1px solid;
  1693. display: flex; align-items: center; justify-content: center;
  1694. cursor: pointer;
  1695. }
  1696. .pho-play-user { background: #fef3c7; border-color: #fde68a; color: #d97706; &:hover { background: #fde68a; } }
  1697. .pho-play-standard { background: #d1fae5; border-color: #bbf7d0; color: #059669; &:hover { background: #bbf7d0; } }
  1698. .pho-practice-btn {
  1699. width: 100%;
  1700. padding: 9px;
  1701. border-radius: 12px;
  1702. background: #f97316;
  1703. color: #fff;
  1704. border: none;
  1705. font-size: 12px;
  1706. font-weight: 500;
  1707. cursor: pointer;
  1708. &:hover { background: #ea580c; }
  1709. }
  1710. // 退出弹窗
  1711. .exit-hint { font-size: 11px; color: #9ca3af; margin: 0 0 14px; }
  1712. .exit-actions { display: flex; flex-direction: column; gap: 10px; }
  1713. .exit-secondary {
  1714. padding: 9px 0;
  1715. border-radius: 12px;
  1716. background: transparent;
  1717. border: 1px solid #e5e7eb;
  1718. color: #4b5563;
  1719. font-size: 12px;
  1720. font-weight: 500;
  1721. cursor: pointer;
  1722. &:hover { background: #f9fafb; }
  1723. }
  1724. .exit-primary {
  1725. padding: 9px 0;
  1726. border-radius: 12px;
  1727. background: #f97316;
  1728. border: none;
  1729. color: #fff;
  1730. font-size: 12px;
  1731. font-weight: 500;
  1732. cursor: pointer;
  1733. &:hover { background: #ea580c; }
  1734. }
  1735. // 徽章
  1736. .badge-popup {
  1737. position: fixed;
  1738. top: 64px;
  1739. right: 16px;
  1740. z-index: 60;
  1741. }
  1742. .badge-card {
  1743. display: flex;
  1744. align-items: center;
  1745. gap: 12px;
  1746. padding: 10px 16px;
  1747. background: linear-gradient(to right, #f97316, #f59e0b);
  1748. border-radius: 16px;
  1749. box-shadow: 0 8px 24px rgba(249,115,22,0.3);
  1750. }
  1751. .badge-icon { font-size: 24px; }
  1752. .badge-name { font-size: 12px; font-weight: 600; color: #fff; margin: 0; }
  1753. .badge-desc { font-size: 10px; color: rgba(255,255,255,0.8); margin: 2px 0 0; }
  1754. // ─────────────────────────────────────────────
  1755. // Animations
  1756. // ─────────────────────────────────────────────
  1757. @keyframes breathing {
  1758. 0%, 100% { transform: scale(1); }
  1759. 50% { transform: scale(1.06); box-shadow: 0 0 0 3px rgba(249,115,22,0.12); }
  1760. }
  1761. @keyframes fade-in-frames {
  1762. from { opacity: 0; transform: translateY(4px); }
  1763. to { opacity: 1; transform: translateY(0); }
  1764. }
  1765. .fade-in { animation: fade-in-frames 0.22s ease-out; }
  1766. @keyframes scale-in-frames {
  1767. from { opacity: 0; transform: scale(0.96); }
  1768. to { opacity: 1; transform: scale(1); }
  1769. }
  1770. .scale-in { animation: scale-in-frames 0.22s ease-out; }
  1771. // ─────────────────────────────────────────────
  1772. // Finalizing screen (full-view loading while fetching report)
  1773. // ─────────────────────────────────────────────
  1774. .finalizing-screen {
  1775. flex: 1;
  1776. display: flex;
  1777. flex-direction: column;
  1778. align-items: center;
  1779. justify-content: center;
  1780. gap: 16px;
  1781. padding: 24px;
  1782. background: #fff;
  1783. }
  1784. .finalizing-spinner {
  1785. color: #fb923c;
  1786. display: flex;
  1787. align-items: center;
  1788. justify-content: center;
  1789. svg { animation: spin 1s linear infinite; }
  1790. }
  1791. .finalizing-title {
  1792. font-size: 14px;
  1793. color: #374151;
  1794. margin: 0;
  1795. font-weight: 500;
  1796. }
  1797. .finalizing-stats-card {
  1798. display: flex;
  1799. align-items: center;
  1800. gap: 8px;
  1801. padding: 12px 18px;
  1802. background: #f9fafb;
  1803. border: 1px solid #f3f4f6;
  1804. border-radius: 12px;
  1805. font-size: 12px;
  1806. color: #6b7280;
  1807. font-variant-numeric: tabular-nums;
  1808. }
  1809. .finalizing-stat { white-space: nowrap; }
  1810. .finalizing-stats-sep { color: #d1d5db; }
  1811. </style>