index.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <template>
  2. <view class="searchLayout">
  3. <view class="search">
  4. <uni-search-bar
  5. @confirm="onSearch"
  6. @cancel="onClear"
  7. @clear="onClear"
  8. focus
  9. placeholder="搜索"
  10. v-model="queryParams.keyword">
  11. </uni-search-bar>
  12. </view>
  13. <view v-if="!classList.length || noSearch">
  14. <view class="history" v-if="historySearch.length">
  15. <view class="topTitle">
  16. <view class="text">最近搜索</view>
  17. <view class="icon" @click="removeHistory">
  18. <uni-icons type="trash" size="25"></uni-icons>
  19. </view>
  20. </view>
  21. <view class="tabs">
  22. <view class="tab" v-for="tab in historySearch" :key="tab" @click="clickTab(tab)">{{tab}}</view>
  23. </view>
  24. </view>
  25. <view class="recommend">
  26. <view class="topTitle">
  27. <view class="text">热门搜索</view>
  28. </view>
  29. <view class="tabs">
  30. <view class="tab" v-for="tab in recommendList" :key="tab" @click="clickTab(tab)">{{tab}}</view>
  31. </view>
  32. </view>
  33. </view>
  34. <view class="noSearch" v-if="noSearch">
  35. <!-- <uv-empty mode="search" icon="http://cdn.uviewui.com/uview/empty/search.png"></uv-empty> -->
  36. 没有符合你的东西拉~
  37. </view>
  38. <view v-else>
  39. <view class="list">
  40. <navigator :url="`/pages/preview/preview?id=${item._id}`" class="item"
  41. v-for="item in classList" :key="item._id">
  42. <image :src="item.smallPicurl" mode="aspectFill"></image>
  43. </navigator>
  44. </view>
  45. <view class="lodinglayout" v-if="noData || classList.length"><!-- <uni-load-more :status="noData?'noMore':'loading'"/> --></view>
  46. </view>
  47. </view>
  48. </template>
  49. <script>
  50. export default {
  51. data() {
  52. return {
  53. //查询参数
  54. queryParams:{
  55. pageNum:1,
  56. pageSize:12,
  57. keyword:""
  58. },
  59. //搜索历史词
  60. historySearch:uni.getStorageSync("historySearch") || [],
  61. //热门搜索词
  62. recommendList:["美女","帅哥","宠物","卡通"],
  63. //没有更多
  64. noData : false,
  65. //没有搜索结果
  66. noSearch : false,
  67. //搜索结果列表
  68. classList : [],
  69. }
  70. },
  71. methods: {
  72. }
  73. }
  74. </script>
  75. <style lang="less">
  76. .searchLayout{
  77. .search{
  78. padding:0 10rpx;
  79. }
  80. .topTitle{
  81. display: flex;
  82. justify-content: space-between;
  83. align-items: center;
  84. font-size: 32rpx;
  85. color:#999;
  86. }
  87. .history{
  88. padding:30rpx;
  89. }
  90. .recommend{
  91. padding:30rpx;
  92. }
  93. .tabs{
  94. display: flex;
  95. align-items: center;
  96. flex-wrap: wrap;
  97. padding-top:20rpx;
  98. .tab{
  99. background: #F4F4F4;
  100. font-size: 28rpx;
  101. color:#333;
  102. padding:10rpx 28rpx;
  103. border-radius: 50rpx;
  104. margin-right: 20rpx;
  105. margin-top: 20rpx;
  106. }
  107. }
  108. .list{
  109. display: grid;
  110. grid-template-columns: repeat(3,1fr);
  111. gap: 5rpx;
  112. padding:20rpx 5rpx;
  113. .item{
  114. height: 440rpx;
  115. image{
  116. width: 100%;
  117. height: 100%;
  118. display: block;
  119. }
  120. }
  121. }
  122. }
  123. </style>