ChatInputArea.vue 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. <template>
  2. <div class="chat-input-area">
  3. <div v-if="pendingFile" class="pending-file-display">
  4. <div class="pending-file-card">
  5. <div class="file-icon-pending"></div>
  6. <div class="file-info-pending">
  7. <div class="file-name-pending">{{ pendingFile.name }}</div>
  8. <div class="file-size-pending">{{ formatFileSize(pendingFile.size) }}</div>
  9. </div>
  10. <div class="remove-pending" @click="emit('remove-pending-file')">
  11. <CloseOutlined />
  12. </div>
  13. </div>
  14. </div>
  15. <a-textarea
  16. :value="modelValue"
  17. @update:value="emit('update:modelValue', $event)"
  18. :rows="3"
  19. class="chat-input"
  20. placeholder="请输入你的问题"
  21. :auto-size="{ minRows: 3, maxRows: 6 }"
  22. @keydown.enter.prevent="handleEnterKey"
  23. />
  24. <div class="input-actions">
  25. <div class="action-left">
  26. <a-tooltip title="从本地上传">
  27. <div class="btn-upload" @click="emit('file-upload')">
  28. <div class="plus-icon"></div>
  29. </div>
  30. </a-tooltip>
  31. <input ref="fileInputRef" type="file" style="display: none" @change="emit('file-change', $event)" accept=".pdf" />
  32. </div>
  33. <div class="action-right">
  34. <div class="btn-send" :class="{ loading, disabled: !modelValue.trim() }" @click="handleSend">
  35. <div class="send-icon"></div>
  36. </div>
  37. </div>
  38. </div>
  39. </div>
  40. </template>
  41. <script setup lang="ts">
  42. import { ref } from 'vue';
  43. import { CloseOutlined } from '@ant-design/icons-vue';
  44. import { formatFileSize } from './utils';
  45. import type { AttachedFile } from './types';
  46. const props = defineProps<{
  47. modelValue: string;
  48. pendingFile: AttachedFile | null;
  49. loading: boolean;
  50. }>();
  51. const emit = defineEmits<{
  52. (e: 'update:modelValue', value: string): void;
  53. (e: 'send'): void;
  54. (e: 'file-upload'): void;
  55. (e: 'file-change', event: Event): void;
  56. (e: 'remove-pending-file'): void;
  57. }>();
  58. const fileInputRef = ref<HTMLInputElement>();
  59. const handleEnterKey = (e: KeyboardEvent) => {
  60. if (!e.shiftKey && props.modelValue.trim()) {
  61. emit('send');
  62. }
  63. };
  64. const handleSend = () => {
  65. if (props.modelValue.trim() && !props.loading) {
  66. emit('send');
  67. }
  68. };
  69. defineExpose({ fileInputRef });
  70. </script>
  71. <style scoped lang="less">
  72. .chat-input-area {
  73. padding: 5px 10px;
  74. flex-shrink: 0;
  75. background-color: #002f4a;
  76. border: 1px solid #005482;
  77. border-radius: 4px;
  78. margin: 10px 16px 16px 16px;
  79. .pending-file-display {
  80. margin-bottom: 5px;
  81. .pending-file-card {
  82. display: flex;
  83. align-items: center;
  84. gap: 10px;
  85. padding: 10px 12px;
  86. background: rgba(10, 132, 255, 0.06);
  87. border: 1px solid rgba(63, 80, 106, 0.5);
  88. border-radius: 6px;
  89. transition: all 0.3s;
  90. &:hover {
  91. background: rgba(10, 132, 255, 0.1);
  92. }
  93. .file-icon-pending {
  94. width: 32px;
  95. height: 32px;
  96. background-image: var(--img-chat-attach-icon);
  97. background-repeat: no-repeat;
  98. background-size: 100% 100%;
  99. flex-shrink: 0;
  100. }
  101. .file-info-pending {
  102. flex: 1;
  103. min-width: 0;
  104. .file-name-pending {
  105. font-size: 12px;
  106. font-weight: 400;
  107. line-height: 1.4;
  108. color: #e0e6ed;
  109. overflow: hidden;
  110. text-overflow: ellipsis;
  111. white-space: nowrap;
  112. margin-bottom: 2px;
  113. }
  114. .file-size-pending {
  115. font-size: 11px;
  116. font-weight: 400;
  117. line-height: 1.3;
  118. color: #8b949e;
  119. }
  120. }
  121. .remove-pending {
  122. cursor: pointer;
  123. color: #8b949e;
  124. font-size: 14px;
  125. padding: 4px;
  126. border-radius: 4px;
  127. transition: all 0.3s;
  128. &:hover {
  129. color: #ff4d4f;
  130. background: rgba(220, 38, 38, 0.1);
  131. }
  132. }
  133. }
  134. }
  135. :deep(.chat-input) {
  136. color: #e0e6ed;
  137. background-color: transparent !important;
  138. border: none !important;
  139. &::placeholder {
  140. color: #8b949e !important;
  141. opacity: 1 !important;
  142. }
  143. &:focus,
  144. &:hover,
  145. &:active {
  146. border: none !important;
  147. box-shadow: none !important;
  148. outline: none !important;
  149. }
  150. }
  151. .input-actions {
  152. display: flex;
  153. justify-content: space-between;
  154. align-items: center;
  155. margin-top: 12px;
  156. .action-left,
  157. .action-right {
  158. display: flex;
  159. gap: 8px;
  160. .btn-upload {
  161. width: 30px;
  162. height: 30px;
  163. border-radius: 6px;
  164. margin-right: 10px;
  165. display: flex;
  166. align-items: center;
  167. justify-content: center;
  168. }
  169. .plus-icon {
  170. width: 20px;
  171. height: 20px;
  172. background-image: var(--img-chat-input-bg);
  173. background-repeat: no-repeat;
  174. background-size: 100% 100%;
  175. cursor: pointer;
  176. }
  177. .btn-send {
  178. width: 32px;
  179. height: 32px;
  180. display: flex;
  181. align-items: center;
  182. justify-content: center;
  183. cursor: pointer;
  184. opacity: 1;
  185. transition: opacity 0.2s;
  186. &.disabled {
  187. opacity: 0.4;
  188. cursor: not-allowed;
  189. }
  190. .send-icon {
  191. width: 24px;
  192. height: 24px;
  193. background-image: var(--img-chat-send-icon);
  194. background-repeat: no-repeat;
  195. background-size: 100% 100%;
  196. }
  197. }
  198. }
  199. }
  200. }
  201. </style>