QuestionInput.vue 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. <template>
  2. <div class="question-input-bottom">
  3. <!-- 快捷标签 -->
  4. <transition name="tags-slide">
  5. <div v-if="showQuickTags && !loading" class="quick-tags-row">
  6. <el-space wrap :size="12" class="tags-center">
  7. <el-tag
  8. v-for="(tag, index) in quickTags"
  9. :key="index"
  10. type="info"
  11. effect="plain"
  12. size="large"
  13. class="quick-tag"
  14. @click="handleTagClick(tag)"
  15. >
  16. <el-icon class="tag-icon">
  17. <component :is="tag.icon" />
  18. </el-icon>
  19. <span>{{ tag.text }}</span>
  20. </el-tag>
  21. </el-space>
  22. </div>
  23. </transition>
  24. <!-- 输入框容器 -->
  25. <div class="input-row">
  26. <div class="input-wrapper">
  27. <div class="input-container">
  28. <el-button circle class="icon-button">
  29. <el-icon><Link /></el-icon>
  30. </el-button>
  31. <el-button circle class="icon-button">
  32. <el-icon><Paperclip /></el-icon>
  33. </el-button>
  34. <el-input
  35. v-model="form.question"
  36. type="textarea"
  37. :rows="1"
  38. :autosize="{ minRows: 1, maxRows: 4 }"
  39. placeholder="请在此处发送消息 (Enter键可立即发送)"
  40. :disabled="loading"
  41. @keydown.enter="handleEnterKey"
  42. class="message-input"
  43. />
  44. <el-button circle class="icon-button">
  45. <el-icon><Microphone /></el-icon>
  46. </el-button>
  47. <el-button
  48. type="primary"
  49. :loading="loading"
  50. :disabled="!form.question.trim()"
  51. @click="handleSubmit"
  52. class="send-button"
  53. size="large"
  54. >
  55. <span v-if="!loading">发送</span>
  56. <el-icon v-if="!loading"><Position /></el-icon>
  57. </el-button>
  58. </div>
  59. </div>
  60. </div>
  61. </div>
  62. </template>
  63. <script setup>
  64. import { reactive, ref } from 'vue'
  65. import { Position, Link, Paperclip, Microphone, Setting, Document, Files } from '@element-plus/icons-vue'
  66. import { handleChatInputEnterKey } from '@/utils/chatInputKeydown.js'
  67. const emit = defineEmits(['submit', 'cancel'])
  68. const props = defineProps({
  69. loading: {
  70. type: Boolean,
  71. default: false
  72. }
  73. })
  74. const form = reactive({
  75. question: '',
  76. windowSize: 3,
  77. nResults: 10
  78. })
  79. const showQuickTags = ref(true)
  80. const quickTags = [
  81. { text: '工程建设质量的要求', icon: Setting },
  82. { text: '施工安全生产责任的规定', icon: Document },
  83. { text: '公路桥梁加固设计规范', icon: Files }
  84. ]
  85. const handleTagClick = (tag) => {
  86. form.question = tag.text
  87. }
  88. const handleSubmit = () => {
  89. if (!form.question.trim()) {
  90. return
  91. }
  92. showQuickTags.value = false
  93. emit('submit', {
  94. question: form.question.trim(),
  95. windowSize: form.windowSize,
  96. nResults: form.nResults
  97. })
  98. }
  99. const handleEnterKey = (event) => {
  100. handleChatInputEnterKey(event, {
  101. submit: handleSubmit,
  102. updateValue: (value) => {
  103. form.question = value
  104. }
  105. })
  106. }
  107. const handleCancel = () => {
  108. emit('cancel')
  109. }
  110. </script>
  111. <style scoped>
  112. .question-input-bottom {
  113. width: 100%;
  114. }
  115. .quick-tags-row {
  116. margin-bottom: 16px;
  117. }
  118. .tags-center {
  119. display: flex;
  120. justify-content: center;
  121. width: 100%;
  122. }
  123. .quick-tag {
  124. cursor: pointer;
  125. transition: all 0.3s ease;
  126. padding: 8px 16px;
  127. border-radius: 16px;
  128. background: white;
  129. border: 1px solid #e0e6ed;
  130. }
  131. .quick-tag:hover {
  132. background: #f0f4ff;
  133. border-color: #5b8def;
  134. color: #5b8def;
  135. transform: translateY(-2px);
  136. box-shadow: 0 4px 8px rgba(91, 141, 239, 0.15);
  137. }
  138. .tag-icon {
  139. margin-right: 6px;
  140. font-size: 14px;
  141. }
  142. .input-row {
  143. display: flex;
  144. justify-content: center;
  145. width: 100%;
  146. }
  147. .input-wrapper {
  148. max-width: 900px;
  149. width: 100%;
  150. }
  151. .input-container {
  152. display: flex;
  153. align-items: center;
  154. gap: 12px;
  155. background: white;
  156. border-radius: 24px;
  157. padding: 8px 12px;
  158. box-shadow: 0 2px 12px rgba(0, 0, 0, 0.08);
  159. }
  160. .icon-button {
  161. flex-shrink: 0;
  162. border: none;
  163. background: transparent;
  164. color: #8b92a7;
  165. transition: all 0.3s ease;
  166. width: 36px;
  167. height: 36px;
  168. }
  169. .icon-button:hover {
  170. background: #f0f4ff;
  171. color: #5b8def;
  172. }
  173. .message-input {
  174. flex: 1;
  175. min-width: 0;
  176. }
  177. :deep(.message-input .el-textarea__inner) {
  178. border: none;
  179. box-shadow: none;
  180. padding: 8px 4px;
  181. font-size: 14px;
  182. line-height: 1.5;
  183. resize: none;
  184. background: transparent;
  185. color: #2d3748;
  186. min-height: 36px;
  187. }
  188. :deep(.message-input .el-textarea__inner::placeholder) {
  189. color: #a0aec0;
  190. }
  191. :deep(.message-input .el-textarea__inner:focus) {
  192. border: none;
  193. box-shadow: none;
  194. }
  195. .send-button {
  196. background: linear-gradient(135deg, #5b8def 0%, #0063f7 100%);
  197. border: none;
  198. border-radius: 20px;
  199. padding: 10px 24px;
  200. font-size: 14px;
  201. font-weight: 500;
  202. height: 40px;
  203. display: flex;
  204. align-items: center;
  205. gap: 6px;
  206. transition: all 0.3s ease;
  207. flex-shrink: 0;
  208. }
  209. .send-button:hover:not(:disabled) {
  210. background: linear-gradient(135deg, #4a7de8 0%, #0056e0 100%);
  211. transform: translateY(-2px);
  212. box-shadow: 0 4px 12px rgba(91, 141, 239, 0.4);
  213. }
  214. .send-button:disabled {
  215. background: #e2e8f0;
  216. color: #a0aec0;
  217. cursor: not-allowed;
  218. }
  219. .send-button .el-icon {
  220. font-size: 16px;
  221. }
  222. /* 动画 */
  223. .tags-slide-enter-active,
  224. .tags-slide-leave-active {
  225. transition: all 0.3s ease;
  226. }
  227. .tags-slide-enter-from {
  228. opacity: 0;
  229. transform: translateY(10px);
  230. }
  231. .tags-slide-leave-to {
  232. opacity: 0;
  233. transform: translateY(-10px);
  234. }
  235. @media (max-width: 768px) {
  236. .input-container {
  237. gap: 8px;
  238. padding: 6px 8px;
  239. }
  240. .icon-button {
  241. width: 32px;
  242. height: 32px;
  243. }
  244. .send-button {
  245. padding: 8px 20px;
  246. height: 36px;
  247. }
  248. }
  249. </style>