searchActivity.vue 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <template>
  2. <view class="common_page adffc" :style="{'height':h+'px', 'padding-top':mt+'px'}">
  3. <cus-header title="搜索" bgColor="transparent"></cus-header>
  4. <image src="https://oss.familydaf.cn/sxsnfile/20251218/ff31a76e0e1148378a318382b998a51f.png" class="top_bg_img" mode="widthFix"></image>
  5. <view class="top-search">
  6. <cus-search :isCancel="true" @handleSearch="handleSearch" @handleCancel="handleCancel"></cus-search>
  7. </view>
  8. <view class="text">最近搜索</view>
  9. <view class="list">
  10. <view class="pre" v-for="(item,index) in list" :key="index" @click="handleSearch(item)">{{item}}</view>
  11. </view>
  12. </view>
  13. </template>
  14. <script setup name="">
  15. import CusHeader from '@/components/CusHeader/index.vue'
  16. import CusSearch from '@/components/CusSearch/index.vue'
  17. import { ref, getCurrentInstance, onMounted } from 'vue'
  18. import { onLoad } from '@dcloudio/uni-app'
  19. const { proxy } = getCurrentInstance()
  20. const list = ref([])
  21. const queryText = ref('')
  22. const fromHome = ref(false)
  23. onLoad(options => {
  24. if (options?.from === 'home') fromHome.value = true
  25. })
  26. const handleSearch = data => {
  27. let sh = uni.getStorageSync('searchHistory');
  28. try{
  29. let sh_arr = [];
  30. if(sh) sh_arr = JSON.parse(sh);
  31. let arr = Array.from(new Set(sh_arr.concat([data])));
  32. uni.setStorageSync('searchHistory',JSON.stringify(arr));
  33. }catch(e){
  34. console.log(e,'e');
  35. }
  36. if (fromHome.value) {
  37. uni.redirectTo({ url: '/pagesHome/allActivity?keyword=' + encodeURIComponent(data) })
  38. } else {
  39. proxy.getOpenerEventChannel().emit('confirmSearch', data)
  40. uni.navigateBack();
  41. }
  42. }
  43. const getSearchHistory = () => {
  44. let sh = uni.getStorageSync('searchHistory');
  45. try{
  46. list.value = JSON.parse(sh?sh:'[]')
  47. }catch(e){
  48. console.log(e,'e');
  49. }
  50. }
  51. const handleCancel = () => {
  52. uni.navigateBack()
  53. }
  54. onMounted(()=>{
  55. getSearchHistory()
  56. })
  57. </script>
  58. <style scoped lang="scss">
  59. ::v-deep .u-navbar>view{
  60. background: url('https://oss.familydaf.cn/sxsnfile/20251223/d07237024c5e4f00a63b9089abbf5a3c.png') no-repeat;
  61. background-size: 100% 100%;
  62. }
  63. .common_page{
  64. .top-search{
  65. position: relative;
  66. margin-top: 20rpx;
  67. }
  68. .text{
  69. font-family: PingFang-SC, PingFang-SC;
  70. font-weight: bold;
  71. font-size: 36rpx;
  72. color: #252525;
  73. line-height: 50rpx;
  74. margin-top: 40rpx;
  75. position: relative;
  76. }
  77. .list{
  78. position: relative;
  79. flex: 1;
  80. margin-top: 4rpx;
  81. overflow-y: auto;
  82. .pre{
  83. background: #FFFFFF;
  84. border-radius: 24rpx;
  85. padding: 25rpx 24rpx;
  86. font-family: PingFangSC, PingFang SC;
  87. font-weight: 400;
  88. font-size: 28rpx;
  89. color: #252525;
  90. line-height: 40rpx;
  91. margin-top: 24rpx;
  92. }
  93. }
  94. }
  95. </style>