searchActivity.vue 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. 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. ::v-deep .u-navbar>view{
  51. background: url('https://oss.familydaf.cn/sxsnfile/20251223/d07237024c5e4f00a63b9089abbf5a3c.png') no-repeat;
  52. background-size: 100% 100%;
  53. }
  54. .common_page{
  55. .top-search{
  56. position: relative;
  57. margin-top: 20rpx;
  58. }
  59. .text{
  60. font-family: PingFang-SC, PingFang-SC;
  61. font-weight: bold;
  62. font-size: 36rpx;
  63. color: #252525;
  64. line-height: 50rpx;
  65. margin-top: 40rpx;
  66. position: relative;
  67. }
  68. .list{
  69. position: relative;
  70. flex: 1;
  71. margin-top: 4rpx;
  72. overflow-y: auto;
  73. .pre{
  74. background: #FFFFFF;
  75. border-radius: 24rpx;
  76. padding: 25rpx 24rpx;
  77. font-family: PingFangSC, PingFang SC;
  78. font-weight: 400;
  79. font-size: 28rpx;
  80. color: #252525;
  81. line-height: 40rpx;
  82. margin-top: 24rpx;
  83. }
  84. }
  85. }
  86. </style>