searchBar.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <!-- 搜索栏 -->
  3. <view class="search_container" :style="containerStyle">
  4. <view class="search_box">
  5. <image src="@/static/image/icon/search.png" class="search_icon" mode="aspectFit"></image>
  6. <input type="text" class="search_input" :value="modelValue" @input="handleInput"
  7. placeholder="请输入关键字搜索" />
  8. </view>
  9. </view>
  10. </template>
  11. <script setup>
  12. import { computed } from 'vue';
  13. const props = defineProps({
  14. modelValue: {
  15. type: String,
  16. default: ''
  17. },
  18. top: {
  19. type: [String, Number],
  20. default: ''
  21. },
  22. isFixed: {
  23. type: Boolean,
  24. default: false
  25. },
  26. zIndex: {
  27. type: [String, Number],
  28. default: '98'
  29. },
  30. border: {
  31. type: Boolean,
  32. default: true
  33. }
  34. });
  35. const emit = defineEmits(['update:modelValue', 'search']);
  36. const containerStyle = computed(() => {
  37. const style = {};
  38. if (props.isFixed) {
  39. style.position = 'fixed';
  40. style.left = '0';
  41. style.right = '0';
  42. style.zIndex = props.zIndex;
  43. }
  44. if (props.top) {
  45. style.top = typeof props.top === 'number' ? `${props.top}rpx` : props.top;
  46. }
  47. if (props.border) {
  48. style.borderBottom = '2rpx solid #F3F3F3';
  49. } else {
  50. style.borderBottom = 'none';
  51. }
  52. return style;
  53. });
  54. const handleInput = (e) => {
  55. const value = e.detail.value;
  56. emit('update:modelValue', value);
  57. emit('search', value);
  58. };
  59. </script>
  60. <style lang="scss">
  61. .search_container {
  62. padding: 0 24rpx;
  63. padding-bottom: 24rpx;
  64. border-bottom: 2rpx solid #F3F3F3;
  65. display: flex;
  66. background-color: #FFFFFF;
  67. .search_box {
  68. flex: 1;
  69. display: flex;
  70. align-items: center;
  71. padding: 0rpx 24rpx;
  72. height: 72rpx;
  73. line-height: 72rpx;
  74. border-radius: 8rpx;
  75. border: 2rpx solid #DCDFE6;
  76. .search_icon {
  77. width: 32rpx;
  78. height: 32rpx;
  79. margin-right: 8rpx;
  80. }
  81. .search_input {
  82. flex: 1;
  83. height: 72rpx;
  84. font-size: 28rpx;
  85. color: #333333;
  86. padding-right: 24rpx;
  87. box-sizing: border-box;
  88. }
  89. }
  90. }
  91. </style>