1
0

aSidebar.html 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. {{define "component/sidebar/content"}}
  2. <template>
  3. <div class="ant-sidebar">
  4. <a-layout-sider :theme="themeSwitcher.currentTheme" collapsible :collapsed="collapsed"
  5. @collapse="(isCollapsed, type) => collapseHandle(isCollapsed, type)" breakpoint="md">
  6. <a-theme-switch></a-theme-switch>
  7. <a-menu :theme="themeSwitcher.currentTheme" mode="inline" :selected-keys="activeTab"
  8. @click="({key}) => openLink(key)">
  9. <a-menu-item v-for="tab in tabs" :key="tab.key">
  10. <a-icon :type="tab.icon"></a-icon>
  11. <span v-text="tab.title"></span>
  12. </a-menu-item>
  13. </a-menu>
  14. </a-layout-sider>
  15. <a-drawer placement="left" :closable="false" @close="closeDrawer" :visible="visible"
  16. :wrap-class-name="themeSwitcher.currentTheme" :wrap-style="{ padding: 0 }" :style="{ height: '100%' }">
  17. <div class="drawer-handle" @click="toggleDrawer" slot="handle">
  18. <a-icon :type="visible ? 'close' : 'menu-fold'"></a-icon>
  19. </div>
  20. <a-theme-switch></a-theme-switch>
  21. <a-menu :theme="themeSwitcher.currentTheme" mode="inline" :selected-keys="activeTab"
  22. @click="({key}) => openLink(key)">
  23. <a-menu-item v-for="tab in tabs" :key="tab.key">
  24. <a-icon :type="tab.icon"></a-icon>
  25. <span v-text="tab.title"></span>
  26. </a-menu-item>
  27. </a-menu>
  28. </a-drawer>
  29. </div>
  30. </template>
  31. {{end}}
  32. {{define "component/aSidebar"}}
  33. <style>
  34. .ant-sidebar>.ant-layout-sider {
  35. height: 100%;
  36. }
  37. </style>
  38. <script>
  39. const SIDEBAR_COLLAPSED_KEY = "isSidebarCollapsed"
  40. Vue.component('a-sidebar', {
  41. data() {
  42. return {
  43. tabs: [{
  44. key: '{{ .base_path }}panel/',
  45. icon: 'dashboard',
  46. title: '{{ i18n "menu.dashboard"}}'
  47. },
  48. {
  49. key: '{{ .base_path }}panel/inbounds',
  50. icon: 'user',
  51. title: '{{ i18n "menu.inbounds"}}'
  52. },
  53. {
  54. key: '{{ .base_path }}panel/settings',
  55. icon: 'setting',
  56. title: '{{ i18n "menu.settings"}}'
  57. },
  58. {
  59. key: '{{ .base_path }}panel/xray',
  60. icon: 'tool',
  61. title: '{{ i18n "menu.xray"}}'
  62. },
  63. {
  64. key: '{{ .base_path }}logout/',
  65. icon: 'logout',
  66. title: '{{ i18n "menu.logout"}}'
  67. },
  68. ],
  69. activeTab: [
  70. '{{ .request_uri }}'
  71. ],
  72. visible: false,
  73. collapsed: JSON.parse(localStorage.getItem(SIDEBAR_COLLAPSED_KEY)),
  74. }
  75. },
  76. methods: {
  77. openLink(key) {
  78. return key.startsWith('http') ?
  79. window.open(key) :
  80. location.href = key
  81. },
  82. closeDrawer() {
  83. this.visible = false;
  84. },
  85. toggleDrawer() {
  86. this.visible = !this.visible;
  87. },
  88. collapseHandle(collapsed, type) {
  89. if (type === "clickTrigger") {
  90. localStorage.setItem(SIDEBAR_COLLAPSED_KEY, collapsed);
  91. this.collapsed = JSON.parse(localStorage.getItem(SIDEBAR_COLLAPSED_KEY));
  92. }
  93. }
  94. },
  95. template: `{{template "component/sidebar/content"}}`,
  96. });
  97. </script>
  98. {{end}}