cwg-submenu.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <view class="cwg-submenu">
  3. <view class="submenu">
  4. <view class="cwg-submenu-item" :class="{ 'active': activePath === item.path }" v-for="item in submenuItems"
  5. :key="item.path" @click="handleClick(item.path)">
  6. <text v-t="item.label"></text>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script lang="ts" setup>
  12. import { computed, watch, nextTick } from 'vue';
  13. import useRouter from "@/hooks/useRouter";
  14. const router = useRouter();
  15. import useRoute from '@/hooks/useRoute'
  16. const route = useRoute()
  17. interface MenuItem {
  18. key: string;
  19. label: string;
  20. icon?: string;
  21. children?: MenuItem[];
  22. }
  23. const props = defineProps({
  24. submenuItems: {
  25. type: Array as () => MenuItem[],
  26. default: () => []
  27. }
  28. })
  29. const activePath = computed(() => route.path + (route.query?.type ? `?type=${route.query.type}` : '') || '')
  30. const emit = defineEmits(['submenu-click']);
  31. function handleClick(path: string) {
  32. if (route.path !== path) {
  33. router.push(path);
  34. }
  35. }
  36. </script>
  37. <style scoped lang="scss">
  38. @import "@/uni.scss";
  39. .cwg-submenu {
  40. width: 100%;
  41. .submenu {
  42. width: 100%;
  43. display: flex;
  44. flex-direction: column;
  45. align-items: center;
  46. gap: px2rpx(8);
  47. padding: px2rpx(8) px2rpx(8) px2rpx(8) px2rpx(32);
  48. box-sizing: border-box;
  49. }
  50. .cwg-submenu-item {
  51. width: 100%;
  52. height: px2rpx(40);
  53. cursor: pointer;
  54. display: flex;
  55. align-items: center;
  56. gap: 12px;
  57. padding: px2rpx(10);
  58. box-sizing: border-box;
  59. font-size: 14px;
  60. &:hover {
  61. background: rgba(108, 133, 149, 0.12) !important;
  62. border: 1px solid rgb(145, 163, 176) !important;
  63. border-radius: px2rpx(4);
  64. }
  65. &.active {
  66. background: rgba(108, 133, 149, 0.12) !important;
  67. border-radius: px2rpx(4);
  68. }
  69. }
  70. }
  71. </style>