ChatMessageInput.vue 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <script setup lang="ts">
  2. import { SendOutlined } from '@ant-design/icons-vue'
  3. import { storeToRefs } from 'pinia'
  4. import { useChatGPTStore } from './chatgpt'
  5. const chatGPTStore = useChatGPTStore()
  6. const { loading, askBuffer, messages } = storeToRefs(chatGPTStore)
  7. const messagesLength = computed(() => messages.value?.length ?? 0)
  8. </script>
  9. <template>
  10. <div class="input-msg">
  11. <div class="control-btn">
  12. <ASpace v-show="!loading">
  13. <APopconfirm
  14. :cancel-text="$gettext('No')"
  15. :ok-text="$gettext('OK')"
  16. :title="$gettext('Are you sure you want to clear the record of chat?')"
  17. @confirm="chatGPTStore.clearRecord()"
  18. >
  19. <AButton type="text">
  20. {{ $gettext('Clear') }}
  21. </AButton>
  22. </APopconfirm>
  23. <AButton
  24. type="text"
  25. @click="chatGPTStore.regenerate(messagesLength - 1)"
  26. >
  27. {{ $gettext('Regenerate response') }}
  28. </AButton>
  29. </ASpace>
  30. </div>
  31. <ATextarea
  32. v-model:value="askBuffer"
  33. auto-size
  34. @press-enter="chatGPTStore.send(askBuffer)"
  35. />
  36. <div class="send-btn">
  37. <AButton
  38. size="small"
  39. type="text"
  40. :loading="loading"
  41. @click="chatGPTStore.send(askBuffer)"
  42. >
  43. <SendOutlined />
  44. </AButton>
  45. </div>
  46. </div>
  47. </template>
  48. <style lang="less" scoped>
  49. .input-msg {
  50. position: sticky;
  51. bottom: 0;
  52. left: 0;
  53. right: 0;
  54. background: rgba(255, 255, 255, 0.8);
  55. backdrop-filter: blur(10px);
  56. -webkit-backdrop-filter: blur(10px);
  57. padding: 16px;
  58. border-radius: 0 0 8px 8px;
  59. .control-btn {
  60. display: flex;
  61. justify-content: center;
  62. }
  63. .send-btn {
  64. position: absolute;
  65. right: 16px;
  66. bottom: 19px;
  67. }
  68. }
  69. .dark {
  70. .input-msg {
  71. background: rgba(30, 30, 30, 0.8);
  72. }
  73. }
  74. </style>