searchActivity.vue 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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://transcend.ringzle.com/xiaozhi-app/profile/2025/09/19/54b75bc8-d926-449b-95a5-1126f700b481.png" class="top_bg_img" mode="widthFix"></image>
  5. <div class="top-search">
  6. <cus-search :isCancel="true" @handleSearch="handleSearch"></cus-search>
  7. </div>
  8. <div class="text">最近搜索</div>
  9. <div class="list">
  10. <div class="pre" v-for="(item,index) in list" :key="index">{{item}}</div>
  11. </div>
  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. const { proxy } = getCurrentInstance()
  19. const list = ref([])
  20. const handleSearch = data => {
  21. let sh = uni.getStorageSync('searchHistory');
  22. try{
  23. let sh_arr = [];
  24. if(sh) sh_arr = JSON.parse(sh);
  25. let arr = Array.from(new Set(sh_arr.concat([data])));
  26. uni.setStorageSync('searchHistory',JSON.stringify(arr));
  27. }catch(e){
  28. console.log(e,'e');
  29. }
  30. proxy.getOpenerEventChannel().emit('confirmSearch',{
  31. data
  32. })
  33. uni.navigateBack();
  34. }
  35. const getSearchHistory = () => {
  36. let sh = uni.getStorageSync('searchHistory');
  37. try{
  38. list.value = JSON.parse(sh?sh:'[]')
  39. }catch(e){
  40. console.log(e,'e');
  41. }
  42. }
  43. onMounted(()=>{
  44. getSearchHistory()
  45. })
  46. </script>
  47. <style scoped lang="scss">
  48. .common_page{
  49. .top-search{
  50. position: relative;
  51. margin-top: 20rpx;
  52. }
  53. .text{
  54. font-family: PingFang-SC, PingFang-SC;
  55. font-weight: bold;
  56. font-size: 36rpx;
  57. color: #252525;
  58. line-height: 50rpx;
  59. margin-top: 40rpx;
  60. position: relative;
  61. }
  62. .list{
  63. position: relative;
  64. flex: 1;
  65. margin-top: 4rpx;
  66. overflow-y: auto;
  67. .pre{
  68. background: #FFFFFF;
  69. border-radius: 24rpx;
  70. padding: 25rpx 24rpx;
  71. font-family: PingFangSC, PingFang SC;
  72. font-weight: 400;
  73. font-size: 28rpx;
  74. color: #252525;
  75. line-height: 40rpx;
  76. margin-top: 24rpx;
  77. }
  78. }
  79. }
  80. </style>