search.vue 4.8 KB

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