search.vue 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. <template>
  2. <!-- 搜索组件 -->
  3. <div :class="meta.info ? 'search-bos1' : ''" class="search-bos" :style="{ 'background': meta.workbench ? '#F4F4F4' : '#ffffff' }">
  4. <div class="search-content">
  5. <img @click="onPath('/')" class="logo logo2" v-if="route.path == '/indexMro'" src="@/assets/images/mro.png" alt="" />
  6. <img @click="onPath('/')" class="logo logo2" v-else-if="route.path == '/indexFuli'" src="@/assets/images/fuli.png" alt="" />
  7. <template v-else-if="route.path == '/indexData'">
  8. <img class="logo logo3" src="@/assets/images/head.png" alt="" @click="onPath('/')" />
  9. <img class="logo logo4" src="@/assets/images/head2.png" alt="" @click="onPath('/')" />
  10. </template>
  11. <template v-else>
  12. <img @click="onPath('/')" class="logo logo1" src="@/assets/images/head.png" alt="" />
  13. <div style="width: 34px"></div>
  14. </template>
  15. <div class="search-box">
  16. <div class="search-div flex-row-start">
  17. <div class="search-input flex-row-center">
  18. <el-input class="el-input" v-model="input" placeholder="搜索商品、品牌、分类..." @change="onPath('/search?type=1&input=' + input)" />
  19. <div class="bnt flex-row-center" @click="onPath('/search?type=1&input=' + input)">
  20. <el-icon color="#ffffff" size="20">
  21. <Search />
  22. </el-icon>
  23. </div>
  24. </div>
  25. <div class="cat-bos flex-row-center">
  26. <el-badge :value="cartCount" v-if="cartCount > 0">
  27. <img src="@/assets/images/layout/layout4.png" alt="" />
  28. </el-badge>
  29. <img v-else src="@/assets/images/layout/layout4.png" alt="" />
  30. <span @click="onPath('/cart')" class="ml-[15px]">我的购物车</span>
  31. </div>
  32. </div>
  33. <div class="search-text">
  34. <div
  35. @click="onPath('/search?type=1&input=' + item.navigationName)"
  36. v-for="(item, index) in toplabel"
  37. :key="index"
  38. :class="{ 'hig': index == 0 }"
  39. >
  40. {{ item.navigationName }}
  41. </div>
  42. </div>
  43. </div>
  44. <img class="code" src="@/assets/images/code.png" alt="" />
  45. </div>
  46. </div>
  47. </template>
  48. <script setup lang="ts">
  49. import { onPath } from '@/utils/siteConfig';
  50. import { cartStore } from '@/store/modules/cart';
  51. import { getSearchTitle } from '@/api/home/index';
  52. const cartStoreData = cartStore();
  53. const cartCount = computed(() => cartStoreData.cartCount);
  54. const input = ref<any>('');
  55. const route = useRoute();
  56. const meta = ref<any>({});
  57. const toplabel = ref<any>([]);
  58. meta.value = route.meta;
  59. watch(route, () => {
  60. meta.value = route.meta;
  61. initData();
  62. });
  63. onMounted(() => {
  64. initData();
  65. });
  66. const initData = () => {
  67. if (route.path == '/search') {
  68. input.value = route.query.input;
  69. }
  70. };
  71. getSearchTitle(1).then((res) => {
  72. if (res.code == 200) {
  73. toplabel.value = res.data;
  74. }
  75. });
  76. </script>
  77. <style lang="scss" scoped>
  78. // 搜索栏
  79. .search-bos {
  80. width: 100%;
  81. background-color: #ffffff;
  82. .search-content {
  83. width: 100%;
  84. min-width: 1200px;
  85. max-width: 1500px;
  86. margin: 0 auto;
  87. display: flex;
  88. // padding: 0 30px;
  89. }
  90. &.search-bos1 {
  91. .search-content {
  92. min-width: 1200px;
  93. max-width: 1200px;
  94. @media (min-width: 1600px) {
  95. min-width: 1600px;
  96. max-width: 1600px;
  97. }
  98. }
  99. }
  100. .logo {
  101. cursor: pointer;
  102. border-radius: 4px;
  103. &.logo1 {
  104. width: 170px;
  105. height: 88px;
  106. margin-top: 10px;
  107. margin-right: 30px;
  108. }
  109. &.logo2 {
  110. width: 436px;
  111. height: 80px;
  112. margin-top: 10px;
  113. margin-right: 20px;
  114. }
  115. &.logo3 {
  116. width: 170px;
  117. height: 88px;
  118. margin-top: 10px;
  119. margin-right: 30px;
  120. }
  121. &.logo4 {
  122. width: 185px;
  123. height: 90px;
  124. margin-top: 20px;
  125. margin-right: 30px;
  126. }
  127. }
  128. .search-box {
  129. flex: 1;
  130. height: 88px;
  131. padding-top: 40px;
  132. .search-div {
  133. .search-input {
  134. flex: 1;
  135. height: 38px;
  136. border-radius: 3px;
  137. border: 2px solid #fb2c36;
  138. padding-right: 4px;
  139. font-size: 14px;
  140. .el-input {
  141. height: 30px;
  142. width: 100%;
  143. font-size: 16px;
  144. :deep(.el-input__wrapper) {
  145. border: none;
  146. /* 可选:去除聚焦时的高亮 */
  147. box-shadow: none;
  148. outline: none;
  149. }
  150. }
  151. .bnt {
  152. width: 50px;
  153. height: 30px;
  154. background: #e7000b;
  155. border-radius: 3px;
  156. font-weight: bold;
  157. cursor: pointer;
  158. }
  159. }
  160. .cat-bos {
  161. width: 143px;
  162. height: 38px;
  163. background: #ffffff;
  164. border-radius: 10px;
  165. border: 1px solid #e5e7eb;
  166. margin-left: 24px;
  167. font-size: 14px;
  168. color: #e7000b;
  169. cursor: pointer;
  170. img {
  171. width: 14px;
  172. height: 14px;
  173. margin-top: 2px;
  174. }
  175. }
  176. }
  177. .search-text {
  178. font-size: 12px;
  179. display: flex;
  180. margin-top: 4px;
  181. cursor: pointer;
  182. .hig {
  183. color: #e7000b;
  184. }
  185. div {
  186. margin-left: 10px;
  187. &:hover {
  188. color: #e7000b;
  189. }
  190. }
  191. }
  192. }
  193. .code {
  194. height: 90px;
  195. width: 90px;
  196. margin-top: 20px;
  197. margin-left: 70px;
  198. // border-radius: 4px;
  199. }
  200. }
  201. </style>