HotList.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <template>
  2. <div class="hot_search_wrap">
  3. <div class="hot_search_wrap__title">{{ L["猜你想要"] }}</div>
  4. <div class="hot_search_wrap__list">
  5. <div
  6. v-for="(item, index) in hotList.data"
  7. :key="index"
  8. class="hot_search_wrap__list-item"
  9. @click="quickSearch(index, 'quick')"
  10. :title="tmpHotList[index]"
  11. >
  12. {{ item }}
  13. </div>
  14. </div>
  15. </div>
  16. </template>
  17. <script setup>
  18. const L = getCurLanguage();
  19. const hotList = reactive({ data: [] }); //热门搜索词列表
  20. const tmpHotList = ref([]);
  21. const router = useRouter();
  22. const getInitData = async () => {
  23. const { data: res } = await useFetchRaw(
  24. apiUrl +
  25. "v3/system/front/setting/getSettings?names=hot_search_words,gz_code"
  26. );
  27. if (res._rawValue.state == 200) {
  28. hotList.data = res._rawValue.data;
  29. let tmp_data = hotList.data[0]
  30. ? hotList.data[0].split(",").filter((i) => i != "")
  31. : [];
  32. tmpHotList.value = tmp_data;
  33. hotList.data = tmp_data;
  34. hotList.data = hotList.data.map((key) => {
  35. if (key.length > 20) {
  36. return key.substring(0, 20) + "...";
  37. } else {
  38. return key;
  39. }
  40. });
  41. }
  42. };
  43. //热门搜索事件
  44. const quickSearch = (val, type) => {
  45. if (type == "quick") {
  46. router.push({
  47. path: `/goods/list/search_keyword-` + tmpHotList.value[val],
  48. });
  49. } else {
  50. // if (val == keyword.value) {
  51. // keyword.value = val;
  52. // } else {
  53. // router.push({
  54. // path: `/goods/list/search_keyword-`+val,
  55. // });
  56. // }
  57. }
  58. };
  59. getInitData();
  60. </script>
  61. <style lang="scss" scoped>
  62. .hot_search_wrap {
  63. width: 100%;
  64. max-height: 500px;
  65. overflow: auto;
  66. &__title {
  67. font-weight: 400;
  68. font-size: 14px;
  69. color: rgba(40, 46, 48, 0.6);
  70. margin-bottom: 15px;
  71. }
  72. &__list {
  73. display: flex;
  74. flex-wrap: wrap;
  75. &-item {
  76. width: max-content;
  77. height: 30px;
  78. line-height: 30px;
  79. text-align: center;
  80. background: #f6f8fa;
  81. font-weight: 400;
  82. font-size: 14px;
  83. color: #282e30;
  84. padding: 0px 15px;
  85. margin-right: 10px;
  86. margin-bottom: 10px;
  87. cursor: pointer;
  88. &:hover {
  89. background-color: $colorMain;
  90. color: #FFF;
  91. }
  92. }
  93. }
  94. }
  95. </style>