s-search-block.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <view
  3. class="search-content ss-flex ss-col-center ss-row-between"
  4. @tap="click"
  5. :style="[
  6. {
  7. borderRadius: radius + 'px',
  8. background: elBackground,
  9. height: height + 'px',
  10. width: width,
  11. },
  12. ]"
  13. :class="[{ 'border-content': navbar }]"
  14. >
  15. <view class="ss-flex ss-col-center" v-if="navbar">
  16. <view class="search-icon _icon-search ss-m-l-10" :style="[{ color: props.iconColor }]"></view>
  17. <view class="search-input ss-flex-1 ss-line-1" :style="[{ color: fontColor, width: width }]">
  18. {{ placeholder }}
  19. </view>
  20. </view>
  21. <uni-search-bar
  22. v-if="!navbar"
  23. class="ss-flex-1"
  24. :radius="data.borderRadius"
  25. :placeholder="data.placeholder"
  26. cancelButton="none"
  27. clearButton="none"
  28. @confirm="onSearch"
  29. />
  30. <view class="keyword-link ss-flex">
  31. <view v-for="(item, index) in data.keywords" :key="index">
  32. <view
  33. class="ss-m-r-16"
  34. :style="[{ color: item.color }]"
  35. @tap.stop="sheep.$router.go('/pages/goods/list', { keyword: item.text })"
  36. >{{ item.text }}</view
  37. >
  38. </view>
  39. </view>
  40. <view v-if="data.keywords && data.keywords.length && navbar" class="ss-flex">
  41. <button
  42. class="ss-reset-button keyword-btn"
  43. v-for="(item, index) in data.keywords"
  44. :key="index"
  45. :style="[{ color: item.color, marginRight: '10rpx' }]"
  46. >
  47. {{ item.text }}
  48. </button>
  49. </view>
  50. </view>
  51. </template>
  52. <script setup>
  53. /**
  54. * 基础组件 - 搜索栏
  55. *
  56. * @property {String} elBackground - 输入框背景色
  57. * @property {String} iconColor - 图标颜色
  58. * @property {String} fontColor - 字体颜色
  59. * @property {Number} placeholder - 默认placeholder
  60. * @property {Number} topRadius - 组件上圆角
  61. * @property {Number} bottomRadius - 组件下圆角
  62. *
  63. * @slot keywords - 关键字
  64. * @event {Function} click - 点击组件时触发
  65. */
  66. import { computed, reactive } from 'vue';
  67. import sheep from '@/sheep';
  68. // 组件数据
  69. const state = reactive({
  70. searchVal: '',
  71. });
  72. // 事件页面
  73. const emits = defineEmits(['click']);
  74. // 接收参数
  75. const props = defineProps({
  76. data: {
  77. type: Object,
  78. default: () => ({}),
  79. },
  80. // 输入框背景色
  81. elBackground: {
  82. type: String,
  83. default: '',
  84. },
  85. height: {
  86. type: Number,
  87. default: 36,
  88. },
  89. // 图标颜色
  90. iconColor: {
  91. type: String,
  92. default: '#b0b3bf',
  93. },
  94. // 字体颜色
  95. fontColor: {
  96. type: String,
  97. default: '#b0b3bf',
  98. },
  99. // placeholder
  100. placeholder: {
  101. type: String,
  102. default: '这是一个搜索框',
  103. },
  104. radius: {
  105. type: Number,
  106. default: 10,
  107. },
  108. width: {
  109. type: String,
  110. default: '100%',
  111. },
  112. navbar: {
  113. type: Boolean,
  114. default: true,
  115. },
  116. });
  117. // 点击
  118. const click = () => {
  119. emits('click');
  120. };
  121. function onSearch(e) {
  122. if (e.value) {
  123. sheep.$router.go('/pages/goods/list', { keyword: e.value });
  124. }
  125. }
  126. </script>
  127. <style lang="scss" scoped>
  128. .border-content {
  129. border: 2rpx solid #eee;
  130. }
  131. .search-content {
  132. flex: 1;
  133. // height: 80rpx;
  134. position: relative;
  135. .search-icon {
  136. font-size: 38rpx;
  137. margin-right: 20rpx;
  138. }
  139. .keyword-link {
  140. position: absolute;
  141. right: 16rpx;
  142. top: 18rpx;
  143. }
  144. .search-input {
  145. font-size: 28rpx;
  146. }
  147. }
  148. </style>