NavCatHeader.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  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" target="_blank" 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 === 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. //跳转专题页
  113. let routeUrl = router.resolve({
  114. path: "/home/topic",
  115. query: {
  116. topicId: val.info.decoId,
  117. },
  118. });
  119. window.open(routeUrl.href, "_blank");
  120. } else if (val.link_type == "brand_home") {
  121. //品牌列表
  122. let routeUrl = router.resolve({
  123. path: "/brand",
  124. query: {},
  125. });
  126. window.open(routeUrl.href, "_blank");
  127. } else if (val.link_type == "store_list") {
  128. //店铺列表
  129. let routeUrl = router.resolve({
  130. path: "/store/list/current-1",
  131. });
  132. window.open(routeUrl.href, "_blank");
  133. } else if (val.link_type == "voucher_center") {
  134. //领券中心
  135. let routeUrl = router.resolve({
  136. path: "/coupon",
  137. });
  138. window.open(routeUrl.href, "_blank");
  139. } else if (val.link_type == "point_center") {
  140. let routeUrl = router.resolve({
  141. path: "/point/index",
  142. });
  143. window.open(routeUrl.href, "_blank");
  144. }
  145. };
  146. onMounted(() => {
  147. let path = route.path;
  148. if (path == "/") {
  149. showIndex.value = false;
  150. }
  151. });
  152. </script>
  153. <style lang="scss" scoped>
  154. .nav_cat {
  155. display: flex;
  156. align-items: center;
  157. width: 100%;
  158. background-color: #F6F8FA;
  159. }
  160. .header {
  161. width: 1440px;
  162. height: 45px;
  163. margin: 0 auto;
  164. display: flex;
  165. justify-content: center;
  166. overflow: visible;
  167. position: relative;
  168. .product_sort {
  169. position: relative;
  170. overflow: visible;
  171. width: max-content;
  172. height: 100%;
  173. letter-spacing: 0px;
  174. line-height: 45px;
  175. display: flex;
  176. align-items: center;
  177. cursor: pointer;
  178. box-sizing: border-box;
  179. z-index:888;
  180. a{
  181. // font-weight: bold;
  182. font-size: $fontE;
  183. color: #282E30;
  184. width: 100%;
  185. height: 100%;
  186. // padding: 0 20px;
  187. }
  188. .category_sort {
  189. position: absolute;
  190. top: 40px;
  191. display: none;
  192. }
  193. &:hover {
  194. background: #F6F8FA;
  195. .category_sort {
  196. display: block;
  197. }
  198. }
  199. img {
  200. width: 12px;
  201. height: 12px;
  202. margin-right: 7px;
  203. }
  204. }
  205. nav {
  206. flex: 1;
  207. width: 100%;
  208. display: flex;
  209. align-items: center;
  210. line-height: 30px;
  211. overflow: hidden;
  212. flex-wrap: wrap;
  213. a {
  214. height: 45px;
  215. display: inline-block;
  216. -webkit-box-sizing: border-box;
  217. box-sizing: border-box;
  218. // font-weight: bold;
  219. font-size: $fontE;
  220. color: #282E30;
  221. margin: 0 0 0 15px;
  222. line-height: 45px;
  223. padding: 0 5px;
  224. width: max-content;
  225. cursor: pointer;
  226. &.active {
  227. background-color: $colorMain;
  228. color: #fff;
  229. }
  230. }
  231. a:hover {
  232. // color: $colorMain;
  233. border-bottom: 3px solid $colorMain;
  234. }
  235. }
  236. }
  237. </style>