展品维保小程序前端代码接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

116 lines
2.1 KiB

  1. <template>
  2. <view class="search-input-container">
  3. <view class="search-box">
  4. <view class="search-icon">
  5. <uv-icon name="search" size="20"></uv-icon>
  6. </view>
  7. <input
  8. class="search-input"
  9. type="text"
  10. :placeholder="placeholder"
  11. v-model="inputValue"
  12. @input="handleInput"
  13. @confirm="handleSearch"
  14. @keyup.enter="handleSearch"
  15. />
  16. <text class="search-text" v-if="showSearchButton">{{ searchButtonText }}</text>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. name: 'SearchInput',
  23. props: {
  24. placeholder: {
  25. type: String,
  26. default: '请输入搜索内容'
  27. },
  28. showSearchButton: {
  29. type: Boolean,
  30. default: true
  31. },
  32. searchButtonText: {
  33. type: String,
  34. default: '搜索'
  35. },
  36. value: {
  37. type: String,
  38. default: ''
  39. }
  40. },
  41. data() {
  42. return {
  43. inputValue: this.value
  44. }
  45. },
  46. watch: {
  47. value(newVal) {
  48. this.inputValue = newVal
  49. },
  50. inputValue(newVal) {
  51. this.$emit('input', newVal)
  52. }
  53. },
  54. methods: {
  55. handleInput(e) {
  56. this.inputValue = e.detail.value || e.target.value
  57. this.$emit('input', this.inputValue)
  58. },
  59. handleSearch() {
  60. this.$emit('search', this.inputValue)
  61. }
  62. }
  63. }
  64. </script>
  65. <style lang="scss" scoped>
  66. .search-input-container {
  67. padding: 20rpx 30rpx;
  68. }
  69. .search-box {
  70. display: flex;
  71. align-items: center;
  72. background-color: #fff;
  73. border-radius: 37rpx;
  74. box-shadow: 0rpx 3rpx 6rpx 0rpx rgba(0,0,0,0.16);
  75. padding: 0 19rpx 0 29rpx;
  76. height: 79rpx;
  77. // transition: border-color 0.3s ease;
  78. // &:focus-within {
  79. // border: 1rpx solid $primary-color;
  80. // border-color: #c70019;
  81. // }
  82. }
  83. .search-icon {
  84. margin-right: 7rpx;
  85. display: flex;
  86. align-items: center;
  87. justify-content: center;
  88. }
  89. .search-input {
  90. flex: 1;
  91. border: none;
  92. outline: none;
  93. background: transparent;
  94. font-size: 28rpx;
  95. color: $secondary-text-color;
  96. height: 100%;
  97. &::placeholder {
  98. color: #999;
  99. }
  100. }
  101. .search-text {
  102. color: $primary-color;
  103. font-size: 28rpx;
  104. }
  105. </style>