MessageItem.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. <!--
  2. 消息项组件
  3. 统一显示所有类型的消息(记者提问、用户回答、语法点评、系统提示等)
  4. -->
  5. <template>
  6. <div class="message-item" :class="messageTypeClass">
  7. <div class="message-header">
  8. <span class="message-avatar">{{ avatar }}</span>
  9. <span class="message-sender">{{ senderName }}</span>
  10. <span v-if="showStageBadge" class="stage-badge">{{ stageTitle }}</span>
  11. </div>
  12. <div class="message-content" :class="contentClass">
  13. <p class="message-text">{{ message }}</p>
  14. <div v-if="expandedSentence" class="expanded-section">
  15. <span class="expanded-label">✨ 扩写结果</span>
  16. <p class="expanded-text">{{ expandedSentence }}</p>
  17. </div>
  18. </div>
  19. </div>
  20. </template>
  21. <script setup lang="ts">
  22. import { computed } from 'vue';
  23. import type { Stage } from '../types/expand';
  24. const props = defineProps<{
  25. type: 'question' | 'user' | 'evaluation' | 'system' | 'thinking';
  26. message: string;
  27. stage?: Stage;
  28. expandedSentence?: string;
  29. }>();
  30. const avatar = computed(() => {
  31. const avatars = {
  32. question: '🎤',
  33. user: '👤',
  34. evaluation: '📝',
  35. system: '🔔',
  36. thinking: '💭'
  37. };
  38. return avatars[props.type];
  39. });
  40. const senderName = computed(() => {
  41. const names = {
  42. question: '记者',
  43. user: '你',
  44. evaluation: '语法点评',
  45. system: '系统',
  46. thinking: '正在思考'
  47. };
  48. return names[props.type];
  49. });
  50. const messageTypeClass = computed(() => `message-${props.type}`);
  51. const contentClass = computed(() => `content-${props.type}`);
  52. const showStageBadge = computed(() => props.type === 'question' && props.stage);
  53. const stageTitle = computed(() => {
  54. if (!props.stage) return '';
  55. const titles: Record<Stage, string> = {
  56. stage1: '阶段 1',
  57. stage2: '阶段 2',
  58. stage3: '阶段 3',
  59. done: '完成'
  60. };
  61. return titles[props.stage];
  62. });
  63. </script>
  64. <style scoped>
  65. .message-item {
  66. margin-bottom: 1rem;
  67. animation: slideIn 0.3s ease-out;
  68. }
  69. @keyframes slideIn {
  70. from {
  71. opacity: 0;
  72. transform: translateY(10px);
  73. }
  74. to {
  75. opacity: 1;
  76. transform: translateY(0);
  77. }
  78. }
  79. .message-header {
  80. display: flex;
  81. align-items: center;
  82. gap: 0.5rem;
  83. margin-bottom: 0.5rem;
  84. }
  85. .message-avatar {
  86. font-size: 1.25rem;
  87. }
  88. .message-sender {
  89. font-weight: 600;
  90. color: #333;
  91. font-size: 0.9rem;
  92. }
  93. .stage-badge {
  94. margin-left: auto;
  95. padding: 0.25rem 0.75rem;
  96. background: #e8f4ff;
  97. color: #4a90e2;
  98. border-radius: 12px;
  99. font-size: 0.75rem;
  100. font-weight: 600;
  101. }
  102. .message-content {
  103. padding: 0.75rem 1rem;
  104. border-radius: 12px;
  105. box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  106. }
  107. .message-text {
  108. margin: 0;
  109. color: #333;
  110. line-height: 1.6;
  111. font-size: 0.95rem;
  112. }
  113. /* 记者提问样式 */
  114. .message-question .message-content {
  115. background: linear-gradient(135deg, #f8f9fa, #e9ecef);
  116. border-bottom-left-radius: 4px;
  117. }
  118. /* 用户消息样式 */
  119. .message-user .message-content {
  120. background: linear-gradient(135deg, #e3f2fd, #bbdefb);
  121. border-bottom-right-radius: 4px;
  122. }
  123. /* 语法点评样式 */
  124. .message-evaluation .message-content {
  125. background: linear-gradient(135deg, #fff9e6, #fff3cd);
  126. border-left: 4px solid #ffc107;
  127. }
  128. /* 系统消息样式 */
  129. .message-system .message-content {
  130. background: #f8f9fa;
  131. color: #666;
  132. font-size: 0.85rem;
  133. }
  134. /* 思考提示样式 */
  135. .message-thinking .message-content {
  136. background: #f0f4f8;
  137. color: #666;
  138. font-style: italic;
  139. }
  140. /* 扩写结果样式 */
  141. .expanded-section {
  142. margin-top: 0.75rem;
  143. padding-top: 0.75rem;
  144. border-top: 1px dashed rgba(0, 0, 0, 0.1);
  145. }
  146. .expanded-label {
  147. display: block;
  148. font-size: 0.75rem;
  149. font-weight: 600;
  150. color: #4a90e2;
  151. margin-bottom: 0.25rem;
  152. text-transform: uppercase;
  153. letter-spacing: 0.5px;
  154. }
  155. .expanded-text {
  156. margin: 0;
  157. color: #2c3e50;
  158. line-height: 1.6;
  159. font-size: 0.95rem;
  160. font-weight: 500;
  161. }
  162. </style>