HistorySearchInput.vue 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <template>
  2. <div class="conversation-search-input">
  3. <div class="search-input-content">
  4. <slot></slot>
  5. <div class="search-input-icon icon-search">
  6. <icon-search />
  7. </div>
  8. <div class="search-input-container">
  9. <input
  10. type="text"
  11. class="search-input"
  12. :placeholder="$t('conversation.search_history')"
  13. v-model="search_text"
  14. @input="handleInputInput"
  15. @change="handleInputChange"
  16. @keyup="handleKeyUp"
  17. />
  18. </div>
  19. <div class="search-input-icon icon-clear" v-if="show_clear" @click="handleInputClear">
  20. <icon-close />
  21. </div>
  22. </div>
  23. </div>
  24. </template>
  25. <script setup>
  26. import { ref, computed } from 'vue';
  27. const emit = defineEmits(['search']);
  28. const search_text = ref('');
  29. const show_clear = computed(() => {
  30. return search_text.value.length !== 0;
  31. });
  32. /**
  33. * 输入事件
  34. * @param e
  35. */
  36. const handleInputInput = (e) => {
  37. search_text.value = e.target.value;
  38. };
  39. /**
  40. * change事件
  41. * @param e
  42. */
  43. const handleInputChange = (e) => {
  44. search_text.value = e.target.value;
  45. };
  46. const handleKeyUp = (e) => {
  47. const k_code = e.keyCode;
  48. if (k_code === 13) {
  49. // enter: 确定搜索
  50. emit('search', search_text.value);
  51. } else {
  52. // 其他键位
  53. }
  54. };
  55. /**
  56. * 清空表单
  57. */
  58. const handleInputClear = () => {
  59. search_text.value = '';
  60. emit('search', search_text.value);
  61. };
  62. </script>
  63. <style lang="css" scoped>
  64. .conversation-search-input {
  65. text-align: center;
  66. font-size: 32px;
  67. font-weight: bold;
  68. color: var(--color-text-1);
  69. background-color: var(--color-bg-1);
  70. padding: 20px 30px 20px 30px;
  71. border-radius: 20px;
  72. }
  73. .search-input-content {
  74. display: flex;
  75. align-items: center;
  76. justify-content: flex-start;
  77. }
  78. .search-input-icon {
  79. display: flex;
  80. justify-content: center;
  81. align-items: center;
  82. width: 26px;
  83. height: 26px;
  84. }
  85. .search-input-icon.icon-search {
  86. margin-left: 5px;
  87. }
  88. .search-input-container {
  89. flex-grow: 1;
  90. margin-left: 10px;
  91. display: flex;
  92. align-items: center;
  93. }
  94. .search-input {
  95. flex-grow: 1;
  96. outline: none;
  97. border: none;
  98. font-size: 20px;
  99. caret-color: var(--color-text-1);
  100. background-color: var(--color-bg-1);
  101. color: var(--color-text-1);
  102. }
  103. .search-input-icon.icon-clear {
  104. cursor: pointer;
  105. }
  106. </style>