DialogueChatView.vue 54 KB

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