cwg-submenu.vue 2.3 KB

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