NavCatHeader.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  1. <template>
  2. <div class="nav_cat">
  3. <div class="header">
  4. <div class="product_sort" >
  5. <!-- <img :src="sortUrl" alt /> -->
  6. <nuxt-link to="/goods/Category" class="sort">
  7. <span >{{L['商品分类']}}</span>
  8. </nuxt-link>
  9. <div class="category_sort">
  10. <CategorySortTop />
  11. </div>
  12. </div>
  13. <nav>
  14. <!-- <li v-if="showIndex">
  15. <nuxt-link to="/" target="_blank">{{L['首页']}}</nuxt-link>
  16. </li> -->
  17. <li v-for="(item, index) in navList.data" :key="index">
  18. <a @click="(e) => navClick(e, item)" :class="{'active': getActive(item)}">{{
  19. item.navName
  20. }}</a>
  21. </li>
  22. </nav>
  23. </div>
  24. </div>
  25. </template>
  26. <script setup>
  27. import { getCurLanguage } from '@/composables/common.js';
  28. import { ElPopover,ElButton } from 'element-plus';
  29. // const L = lang_zn;
  30. const L = getCurLanguage();
  31. const router = useRouter();
  32. const route = useRoute();
  33. const showIndex = ref(true);
  34. const navList = reactive({ data: [] });
  35. const sortUrl = ref("/header/sort.png");
  36. const showTopMenu = ref(false)
  37. //展示一级全部菜单
  38. const showMenu = () => {
  39. showTopMenu.value = true
  40. }
  41. const routePath = computed(() => route.fullPath);
  42. const hideMenu = () => {
  43. setTimeout(() => {
  44. showTopMenu.value = false
  45. }, 1000)
  46. }
  47. const toGoodsList = () => {
  48. navigateTo({ path: "/goods/Category" });
  49. };
  50. const getNavData = async () => {
  51. const { data: value } = await useFetchRaw(
  52. apiUrl + "v3/system/front/navigation/list"
  53. );
  54. const res = value._rawValue;
  55. if (res.state == 200) {
  56. navList.data = res.data;
  57. }
  58. };
  59. getNavData();
  60. const getActive = (item) => {
  61. item = JSON.parse(item.data.replace(/&quot;/g, '"'));
  62. return item.link_type === 'url' && routePath.value !== '/' && routePath.value.includes(quillEscapeToHtml(item.link_value))
  63. }
  64. const navClick = (e, val) => {
  65. e.preventDefault()
  66. val = JSON.parse(val.data.replace(/&quot;/g, '"'));
  67. if (val.link_type == "url") {
  68. //跳转链接地址
  69. if (val.link_value) {
  70. val.link_value = quillEscapeToHtml(val.link_value);
  71. }
  72. router.push(val.link_value)
  73. // router.resolve({
  74. // path: val.link_value
  75. // })
  76. // window.open(val.link_value, "_blank");
  77. } else if (val.link_type == "goods") {
  78. //跳转商品详情页
  79. // let routeUrl = router.resolve({
  80. // path: "/goods/detail",
  81. // query: {
  82. // productId: val.info.defaultProductId,
  83. // },
  84. // });
  85. let href = "/goods/detail/"+ calcProductName(val.info.goodsName) +'_'+ val.info.defaultProductId
  86. // router.push(href)
  87. window.open(href, "_blank");
  88. } else if (val.link_type == "category") {
  89. // 分类列表
  90. let routeUrl = router.resolve({
  91. // path: "/goods/list",
  92. path:'/goods/list/_v-'+val.info.categoryId + '_gid-1_pid-0',
  93. // query: {
  94. // categoryId: val.info.categoryId,
  95. // },
  96. });
  97. window.open(routeUrl.href, "_blank");
  98. } else if (val.link_type == "keyword") {
  99. // 关键词
  100. let query = {
  101. keyword: val.link_value,
  102. };
  103. if (val.storeId) {
  104. query.storeId = val.storeId;
  105. }
  106. let routeUrl = router.resolve({
  107. path: "/goods/list",
  108. query,
  109. });
  110. window.open(routeUrl.href, "_blank");
  111. } else if (val.link_type == "topic") {
  112. let href = `/home/topic?topicId=${val.info.decoId}`
  113. window.open(href, "_blank");
  114. } else if (val.link_type == "brand_home") {
  115. //品牌列表
  116. let routeUrl = router.resolve({
  117. path: "/brand",
  118. query: {},
  119. });
  120. window.open(routeUrl.href, "_blank");
  121. } else if (val.link_type == "store_list") {
  122. //店铺列表
  123. let routeUrl = router.resolve({
  124. path: "/store/list/current-1",
  125. });
  126. window.open(routeUrl.href, "_blank");
  127. } else if (val.link_type == "voucher_center") {
  128. //领券中心
  129. let routeUrl = router.resolve({
  130. path: "/coupon",
  131. });
  132. window.open(routeUrl.href, "_blank");
  133. } else if (val.link_type == "point_center") {
  134. let routeUrl = router.resolve({
  135. path: "/point/index",
  136. });
  137. window.open(routeUrl.href, "_blank");
  138. }
  139. };
  140. onMounted(() => {
  141. let path = route.path;
  142. if (path == "/") {
  143. showIndex.value = false;
  144. }
  145. });
  146. </script>
  147. <style lang="scss" scoped>
  148. .nav_cat {
  149. display: flex;
  150. align-items: center;
  151. width: 100%;
  152. background-color: #F6F8FA;
  153. }
  154. .header {
  155. width: 1440px;
  156. height: 45px;
  157. margin: 0 auto;
  158. display: flex;
  159. justify-content: center;
  160. overflow: visible;
  161. position: relative;
  162. .product_sort {
  163. position: relative;
  164. overflow: visible;
  165. width: max-content;
  166. height: 100%;
  167. letter-spacing: 0px;
  168. line-height: 45px;
  169. display: flex;
  170. align-items: center;
  171. cursor: pointer;
  172. box-sizing: border-box;
  173. z-index:888;
  174. a{
  175. // font-weight: bold;
  176. font-size: $fontE;
  177. color: #282E30;
  178. width: 100%;
  179. height: 100%;
  180. // padding: 0 20px;
  181. }
  182. .category_sort {
  183. position: absolute;
  184. top: 40px;
  185. display: none;
  186. }
  187. &:hover {
  188. background: #F6F8FA;
  189. .category_sort {
  190. display: block;
  191. }
  192. }
  193. img {
  194. width: 12px;
  195. height: 12px;
  196. margin-right: 7px;
  197. }
  198. }
  199. nav {
  200. flex: 1;
  201. width: 100%;
  202. display: flex;
  203. align-items: center;
  204. line-height: 30px;
  205. overflow: hidden;
  206. flex-wrap: wrap;
  207. a {
  208. height: 45px;
  209. display: inline-block;
  210. -webkit-box-sizing: border-box;
  211. box-sizing: border-box;
  212. // font-weight: bold;
  213. font-size: $fontE;
  214. color: #282E30;
  215. margin: 0 0 0 15px;
  216. line-height: 45px;
  217. padding: 0 5px;
  218. width: max-content;
  219. cursor: pointer;
  220. &.active {
  221. background-color: $colorMain;
  222. color: #fff;
  223. }
  224. }
  225. a:hover {
  226. // color: $colorMain;
  227. border-bottom: 3px solid $colorMain;
  228. }
  229. }
  230. }
  231. </style>