index.vue 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <template>
  2. <n-layout has-sider>
  3. <n-layout-sider
  4. v-model:collapsed="isTrigger"
  5. bordered
  6. show-trigger
  7. collapse-mode="width"
  8. width="216"
  9. :native-scrollbar="false"
  10. >
  11. <n-menu
  12. v-model:value="selectedKey"
  13. accordion
  14. :collapsed-icon-size="24"
  15. :options="menuOptions"
  16. />
  17. </n-layout-sider>
  18. <n-layout>
  19. <router-view />
  20. </n-layout>
  21. </n-layout>
  22. </template>
  23. <script setup lang="ts">
  24. import {
  25. h, onMounted, onUnmounted, ref
  26. } from 'vue'
  27. import Icon from '@/components/icon.vue'
  28. import { RouterLink, useRoute } from 'vue-router'
  29. const isTrigger = ref(false)
  30. const menuOptions = [
  31. {
  32. label: () => h('img', {
  33. src: new URL('@/assets/icons/1.svg', import.meta.url).href,
  34. width: '100%',
  35. height: '100%'
  36. }),
  37. icon: () => h(Icon, {
  38. name: '2',
  39. size: 24
  40. }),
  41. disabled: true,
  42. key: ''
  43. },
  44. {
  45. icon: () => h('img', {
  46. src: new URL('@/assets/icons/3.svg', import.meta.url).href,
  47. width: (isTrigger.value ? '24px' : '60px'),
  48. height: (isTrigger.value ? '24px' : '60px'),
  49. style: {
  50. transition: '0.2s'
  51. }
  52. }),
  53. label: () => h('div', {
  54. style: {
  55. margin: '0 0 0 15px'
  56. }
  57. }, [
  58. h('p', {
  59. style: {
  60. margin: 0
  61. }
  62. }, { default: () => '欢迎回家' }),
  63. h('p', {
  64. style: {
  65. margin: 0
  66. }
  67. }, { default: () => '捷克' })
  68. ]),
  69. disabled: true,
  70. key: ''
  71. },
  72. {
  73. label: () => h(RouterLink, { to: { path: '/room' } }, { default: () => '房间' }),
  74. key: 'room',
  75. icon: () => h(Icon, { name: '4', size: 24 })
  76. },
  77. {
  78. label: () => h(RouterLink, { to: { path: '/device' } }, { default: () => '设备' }),
  79. key: 'device',
  80. icon: () => h(Icon, { name: '5', size: 24 })
  81. },
  82. {
  83. label: () => h(RouterLink, { to: { path: '/person' } }, { default: () => '成员' }),
  84. key: 'person',
  85. icon: () => h(Icon, { name: '6', size: 24 })
  86. },
  87. {
  88. label: () => h(RouterLink, { to: { path: '/static' } }, { default: () => '统计' }),
  89. key: 'static',
  90. icon: () => h(Icon, { name: '7', size: 24 })
  91. },
  92. {
  93. label: () => h(RouterLink, { to: { path: '/seting' } }, { default: () => '设置' }),
  94. key: 'seting',
  95. icon: () => h(Icon, { name: '8', size: 24 })
  96. },
  97. {
  98. label: () => h(RouterLink, { to: { path: '/' } }, { default: () => '退出' }),
  99. key: 'logout',
  100. icon: () => h(Icon, { name: '9', size: 24 })
  101. }
  102. ]
  103. const route = useRoute()
  104. const selectedKey = ref(route.name)
  105. function changeTrigger() {
  106. isTrigger.value = document.documentElement.clientWidth < 550
  107. }
  108. window.addEventListener('resize', changeTrigger, false)
  109. onMounted(() => changeTrigger())
  110. onUnmounted(() => window.removeEventListener('resize', changeTrigger, false))
  111. </script>
  112. <style lang="scss" scoped>
  113. :deep(.n-menu) {
  114. --n-item-height: 55px;
  115. height: 100%;
  116. padding: 0;
  117. .n-menu-item-content {
  118. padding-right: 32px;
  119. }
  120. &>div {
  121. &:first-child {
  122. margin: 0;
  123. --n-item-height: 80px;
  124. &>div {
  125. height: 80px;
  126. position: relative;
  127. opacity: 1;
  128. &::after {
  129. content: '';
  130. width: 80%;
  131. height: 2px;
  132. background: var(--n-border-color);
  133. position: absolute;
  134. left: 50%;
  135. transform: translate(-50%, 0);
  136. bottom: 0;
  137. }
  138. }
  139. }
  140. &:nth-child(2) {
  141. --n-item-height: 80px;
  142. margin: 20px 0 60px 0;
  143. &>div {
  144. opacity: 1;
  145. }
  146. }
  147. }
  148. }
  149. </style>