search.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. <template>
  2. <Theme>
  3. <view class="wrap">
  4. <Navbar
  5. border
  6. autoBack
  7. fixed
  8. @leftClick="leftClick"
  9. @rightClick="rightClick"
  10. >
  11. <template #center>
  12. <view class="nav_center">
  13. <Search
  14. v-model="searchValue"
  15. focus
  16. :placeholder="t('商品的链接或名称')"
  17. confirm-type="search"
  18. >
  19. <template #prefix>
  20. <i class="icon-font icon-search"></i>
  21. </template>
  22. <template #suffix>
  23. <i class="icon-font icon-camera" @click="openCamera"></i>
  24. </template>
  25. </Search>
  26. </view>
  27. </template>
  28. <template #right>
  29. <view class="nav_right">
  30. <trans _t="搜索" />
  31. </view>
  32. </template>
  33. </Navbar>
  34. <view class="content">
  35. <template v-if="search_list.length">
  36. <view class="search_info_title">
  37. <trans _t="搜索历史" />
  38. <i class="icon-font icon-delete" @click="remove"></i>
  39. </view>
  40. <view class="search_item_list mb-24">
  41. <view
  42. class="_list"
  43. v-for="(item, index) in search_list"
  44. :key="index"
  45. @click="searchClick(item)"
  46. >
  47. {{ item }}
  48. </view>
  49. </view>
  50. </template>
  51. <view class="search_info_title">
  52. <trans _t="热门搜索" />
  53. </view>
  54. <view class="search_item_list">
  55. <view
  56. class="_list"
  57. v-for="(item, index) in hot_list"
  58. :key="index"
  59. @click="searchClick(item.title)"
  60. >
  61. {{ item.title }}
  62. </view>
  63. </view>
  64. </view>
  65. <CameraUpload @confirm="getUrl" ref="cameraUploadRef" />
  66. </view>
  67. </Theme>
  68. </template>
  69. <script setup>
  70. import { ref, computed } from "vue";
  71. import Navbar from "@/components/navbar";
  72. import Search from "@/components/input";
  73. // import popOver from "@/components/popover";
  74. import CameraUpload from "@/components/CameraUpload";
  75. import singleImageUploader from "@/components/singleImageUploader";
  76. import { t } from "@/locale";
  77. import { useShopStore } from "@/store";
  78. import { setStorage, getStorage, removeStorage } from "@/utils";
  79. const useShop = useShopStore();
  80. const searchValue = ref("");
  81. // const optionsList = ref(['拍照', '相册'])
  82. const hot_list = computed(() => useShop.getHotLink);
  83. const searchList = ref(JSON.parse(getStorage("search_list") || "[]"));
  84. const search_list = computed(() => searchList.value || []);
  85. const cameraUploadRef = ref(null);
  86. const openCamera = () => {
  87. cameraUploadRef.value && cameraUploadRef.value.open();
  88. };
  89. const getUrl = (url) => {
  90. uni.navigateTo({ url: `/pages/index/products?searchImg=${url}` });
  91. };
  92. const leftClick = () => {
  93. uni.switchTab({ url: "/pages/index/index" });
  94. };
  95. const searchClick = (item) => {
  96. const searchText = item.length > 20 ? item.substring(0, 20) + "..." : item;
  97. search_list.value.unshift(searchText);
  98. let arr = search_list.value.slice(0, 8);
  99. setStorage("search_list", JSON.stringify([...new Set(arr)]));
  100. searchList.value = JSON.parse(getStorage("search_list") || "[]");
  101. uni.navigateTo({ url: `/pages/index/products?searchText=${item}` });
  102. };
  103. const rightClick = () => {
  104. if (!searchValue.value) return;
  105. const searchText =
  106. searchValue.value.length > 20
  107. ? searchValue.value.substring(0, 20) + "..."
  108. : searchValue.value;
  109. search_list.value.unshift(searchText);
  110. let arr = search_list.value.slice(0, 8);
  111. setStorage("search_list", JSON.stringify([...new Set(arr)]));
  112. searchList.value = JSON.parse(getStorage("search_list") || "[]");
  113. uni.navigateTo({
  114. url: `/pages/index/products?searchText=${searchValue.value}`,
  115. });
  116. };
  117. const remove = () => {
  118. removeStorage("search_list");
  119. searchList.value = JSON.parse(getStorage("search_list") || "[]");
  120. };
  121. </script>
  122. <style lang="less" scoped>
  123. @import url("@/style.less");
  124. .mb-24 {
  125. margin-bottom: 48rpx;
  126. }
  127. .wrap {
  128. min-height: 100vh;
  129. .nav_center {
  130. // width: calc(100% - 46px - 50px);
  131. flex: 1;
  132. .icon-camera {
  133. color: #adb8cc;
  134. font-size: 56rpx;
  135. }
  136. }
  137. /deep/ .u-navbar {
  138. .u-navbar__content__left,
  139. .u-navbar__content__right {
  140. position: unset;
  141. }
  142. }
  143. .nav_right {
  144. color: var(--black);
  145. .size(12px);
  146. font-weight: 700;
  147. }
  148. .content {
  149. padding: 24rpx;
  150. .search_info_title {
  151. .flex_position(space-between, center);
  152. .size(28rpx);
  153. font-weight: 700;
  154. height: 60rpx;
  155. color: var(--text);
  156. .icon-delete {
  157. color: #c3cad9;
  158. cursor: pointer;
  159. .size(40rpx);
  160. font-weight: 400;
  161. padding: 10rpx;
  162. }
  163. }
  164. .search_item_list {
  165. .flex();
  166. flex-wrap: wrap;
  167. gap: 16rpx;
  168. margin-top: 16rpx;
  169. ._list {
  170. .ver();
  171. background-color: var(--bg-primary);
  172. border-radius: 16rpx;
  173. color: var(--text-02);
  174. .size(24rpx);
  175. height: 48rpx;
  176. padding: 0 16rpx;
  177. }
  178. }
  179. }
  180. }
  181. </style>