searchActivity.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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" @handleCancel="handleCancel"></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" @click="handleSearch(item)">{{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 queryText = ref('')
  21. const handleSearch = data => {
  22. let sh = uni.getStorageSync('searchHistory');
  23. try{
  24. let sh_arr = [];
  25. if(sh) sh_arr = JSON.parse(sh);
  26. let arr = Array.from(new Set(sh_arr.concat([data])));
  27. uni.setStorageSync('searchHistory',JSON.stringify(arr));
  28. }catch(e){
  29. console.log(e,'e');
  30. }
  31. proxy.getOpenerEventChannel().emit('confirmSearch',data)
  32. uni.navigateBack();
  33. }
  34. const getSearchHistory = () => {
  35. let sh = uni.getStorageSync('searchHistory');
  36. try{
  37. list.value = JSON.parse(sh?sh:'[]')
  38. }catch(e){
  39. console.log(e,'e');
  40. }
  41. }
  42. const handleCancel = () => {
  43. uni.navigateBack()
  44. }
  45. onMounted(()=>{
  46. getSearchHistory()
  47. })
  48. </script>
  49. <style scoped lang="scss">
  50. .common_page{
  51. .top-search{
  52. position: relative;
  53. margin-top: 20rpx;
  54. }
  55. .text{
  56. font-family: PingFang-SC, PingFang-SC;
  57. font-weight: bold;
  58. font-size: 36rpx;
  59. color: #252525;
  60. line-height: 50rpx;
  61. margin-top: 40rpx;
  62. position: relative;
  63. }
  64. .list{
  65. position: relative;
  66. flex: 1;
  67. margin-top: 4rpx;
  68. overflow-y: auto;
  69. .pre{
  70. background: #FFFFFF;
  71. border-radius: 24rpx;
  72. padding: 25rpx 24rpx;
  73. font-family: PingFangSC, PingFang SC;
  74. font-weight: 400;
  75. font-size: 28rpx;
  76. color: #252525;
  77. line-height: 40rpx;
  78. margin-top: 24rpx;
  79. }
  80. }
  81. }
  82. </style>