index.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <script lang='ts' setup>
  2. import { computed, defineAsyncComponent, nextTick, onMounted, onUnmounted, ref, watch } from 'vue'
  3. defineProps({
  4. type: {
  5. type: String,
  6. default: 'brand',
  7. },
  8. isOpen: {
  9. type: Boolean,
  10. default: false,
  11. },
  12. })
  13. const emit = defineEmits(['click', 'onMainCategory'])
  14. const list = defineModel('list', {
  15. type: Array as PropType<any[]>,
  16. default: () => [],
  17. })
  18. const activeIndex = defineModel('activeIndex', {
  19. type: String,
  20. default: '',
  21. })
  22. const status = ref(true)
  23. const defaultOpeneds = computed(() => {
  24. return []
  25. })
  26. function handleSelect(value: any) {
  27. activeIndex.value = value
  28. emit('click', value)
  29. }
  30. function onClose() {
  31. activeIndex.value = ''
  32. emit('click', '')
  33. }
  34. function onClickAll() {
  35. status.value = false
  36. onClose()
  37. const timer = setTimeout(() => {
  38. status.value = true
  39. clearTimeout(timer)
  40. }, 0)
  41. }
  42. </script>
  43. <template>
  44. <div class="">
  45. <div v-if="type === 'brand'" class="px-20px py-12px text-16px cursor-pointer pos-relative after:pos-absolute after:content-empty after:bottom-0% after:left-20px after:right-20px after:h-1px after:bg-#DCDFE6" :class="!activeIndex && 'text-#CC9879'" @click="onClickAll">
  46. All brands
  47. </div>
  48. <el-menu
  49. v-if="status"
  50. :default-openeds="defaultOpeneds"
  51. :unique-opened="false"
  52. :default-active="activeIndex"
  53. active-text-color="#CC9879"
  54. class="el-menu-vertical-demo"
  55. @select="handleSelect"
  56. @close="onClose"
  57. >
  58. <el-sub-menu
  59. v-for="item, index in list" :key="index"
  60. :index="item.key"
  61. >
  62. <template #title>
  63. <span>{{ item.title }}</span>
  64. </template>
  65. <el-menu-item v-for="items, indexs in item.children" :index="items.key">
  66. {{ items.title }}
  67. </el-menu-item>
  68. <!-- <el-sub-menu index="1-4">
  69. <template #title>
  70. item four
  71. </template>
  72. <el-menu-item index="1-4-1">
  73. item one
  74. </el-menu-item>
  75. </el-sub-menu> -->
  76. </el-sub-menu>
  77. </el-menu>
  78. </div>
  79. </template>
  80. <style lang='less' scoped>
  81. ::v-deep(.el-menu-vertical-demo){
  82. .el-sub-menu{
  83. .el-sub-menu__title{
  84. position: relative;
  85. &:after{
  86. content: '';
  87. position: absolute;
  88. left: 20px;
  89. right: 20px;
  90. bottom:0;
  91. height: 1px;
  92. background: #DCDFE6;
  93. }
  94. }
  95. &:last-child{
  96. .el-sub-menu__title{
  97. &:after{
  98. content: unset;
  99. }
  100. }
  101. }
  102. }
  103. }
  104. </style>