index.vue 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <template>
  2. <div class="bg-[#fff] border-b-[2px] border-b-[var(--el-color-primary)] border-solid">
  3. <div class="flex items-center w-[1200px] mx-auto h-[46px] leading-[46px] bg-[#fff]" >
  4. <div class="category w-[200px] bg-primary text-[#fff] flex items-center justify-center cursor-pointer text-[16px] leading-[46px] relative rounded-t-[12px]" @click="router.push({ path: '/goods/list' })">
  5. <span class="iconfont icon-fenleiV6xx mr-[8px] "></span>
  6. <span>商品分类</span>
  7. </div>
  8. <div class="px-20px flex item-center flex-1 overflow-x-auto">
  9. <template v-for="(item,index) in navList" :key="index" >
  10. <div class="px-[20px] text-[#333] text-[16px] leading-[46px] cursor-pointer" :class="{'!text-[var(--el-color-primary)]':activeName == item.nav_url}" @click="handleClick(item)">{{ item.nav_title }}</div>
  11. </template>
  12. </div>
  13. </div>
  14. </div>
  15. </template>
  16. <script setup lang="ts">
  17. import { ref,reactive, watch} from "vue";
  18. import { isUrl } from '@/utils/common'
  19. import { getNavList } from '@/app/api/index'
  20. import { useRouter, useRoute } from 'vue-router'
  21. const router = useRouter()
  22. const route = useRoute()
  23. const activeName = ref('')
  24. const navList = ref([])
  25. // 获取导航链接
  26. const getNavListFn = () =>{
  27. getNavList().then((res: any)=>{
  28. navList.value = res.data
  29. navList.value.forEach((item:any) =>{
  30. if(item.nav_url && item.nav_url.url){
  31. if(route.path == item.nav_url.url){
  32. activeName.value = item.nav_url
  33. }
  34. }
  35. })
  36. })
  37. }
  38. getNavListFn()
  39. const handleClick = (item: any) => {
  40. activeName.value = item.nav_url
  41. if (item.nav_url && item.nav_url.url) {
  42. if(isUrl(item.nav_url.url)){
  43. window.open(item.nav_url.url)
  44. }else{
  45. if (item.is_blank == 1) {
  46. const url = router.resolve({
  47. path: item.nav_url.url
  48. })
  49. window.open(url.href)
  50. } else {
  51. router.push({ path: item.nav_url.url })
  52. }
  53. }
  54. }
  55. }
  56. </script>
  57. <style lang="scss" scoped>
  58. .bg-color{
  59. background-color: rgba(0,0,0,.4);
  60. }
  61. :deep(.popover-box){
  62. top:200px !important;
  63. }
  64. </style>