common_sider.html 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. {{define "menuItems"}}
  2. <a-menu-item key="{{ .base_path }}xui/">
  3. <a-icon type="dashboard"></a-icon>
  4. <span>{{ i18n "menu.dashboard"}}</span>
  5. </a-menu-item>
  6. <a-menu-item key="{{ .base_path }}xui/inbounds">
  7. <a-icon type="user"></a-icon>
  8. <span>{{ i18n "menu.inbounds"}}</span>
  9. </a-menu-item>
  10. <a-menu-item key="{{ .base_path }}xui/setting">
  11. <a-icon type="setting"></a-icon>
  12. <span>{{ i18n "menu.setting"}}</span>
  13. </a-menu-item>
  14. <!--<a-menu-item key="{{ .base_path }}xui/clients">-->
  15. <!-- <a-icon type="laptop"></a-icon>-->
  16. <!-- <span>Client</span>-->
  17. <!--</a-menu-item>-->
  18. <a-menu-item key="{{ .base_path }}logout">
  19. <a-icon type="logout"></a-icon>
  20. <span>{{ i18n "menu.logout"}}</span>
  21. </a-menu-item>
  22. {{end}}
  23. {{define "commonSider"}}
  24. <a-layout-sider :theme="siderDrawer.theme" id="sider" collapsible breakpoint="md" collapsed-width="0">
  25. <a-menu :theme="siderDrawer.theme" mode="inline" selected-keys="">
  26. <a-menu-item mode="inline">
  27. <a-icon type="bg-colors"></a-icon>
  28. <a-switch :default-checked="siderDrawer.isDarkTheme"
  29. checked-children="☀"
  30. un-checked-children="🌙"
  31. @change="siderDrawer.changeTheme()"></a-switch>
  32. </a-menu-item>
  33. </a-menu>
  34. <a-menu :theme="siderDrawer.theme" mode="inline" :selected-keys="['{{ .request_uri }}']"
  35. @click="({key}) => key.startsWith('http') ? window.open(key) : location.href = key">
  36. {{template "menuItems" .}}
  37. </a-menu>
  38. </a-layout-sider>
  39. <a-drawer id="sider-drawer" placement="left" :closable="false"
  40. @close="siderDrawer.close()"
  41. :visible="siderDrawer.visible"
  42. :wrap-class-name="siderDrawer.isDarkTheme ? 'ant-drawer-dark' : ''"
  43. :wrap-style="{ padding: 0 }">
  44. <div class="drawer-handle" @click="siderDrawer.change()" slot="handle">
  45. <a-icon :type="siderDrawer.visible ? 'close' : 'menu-fold'"></a-icon>
  46. </div>
  47. <a-menu :theme="siderDrawer.theme" mode="inline" selected-keys="">
  48. <a-menu-item mode="inline">
  49. <a-icon type="bg-colors"></a-icon>
  50. <a-switch :default-checked="siderDrawer.isDarkTheme"
  51. checked-children="☀"
  52. un-checked-children="🌙"
  53. @change="siderDrawer.changeTheme()"></a-switch>
  54. </a-menu-item>
  55. </a-menu>
  56. <a-menu :theme="siderDrawer.theme" mode="inline" :selected-keys="['{{ .request_uri }}']"
  57. @click="({key}) => key.startsWith('http') ? window.open(key) : location.href = key">
  58. {{template "menuItems" .}}
  59. </a-menu>
  60. </a-drawer>
  61. <script>
  62. const darkClass = "ant-card-dark";
  63. const bgDarkStyle = "background-color: #242c3a";
  64. const siderDrawer = {
  65. visible: false,
  66. collapsed: false,
  67. isDarkTheme: localStorage.getItem("dark-mode") === 'true' ? true : false,
  68. show() {
  69. this.visible = true;
  70. },
  71. close() {
  72. this.visible = false;
  73. },
  74. change() {
  75. this.visible = !this.visible;
  76. },
  77. toggleCollapsed() {
  78. this.collapsed = !this.collapsed;
  79. },
  80. changeTheme() {
  81. this.isDarkTheme = ! this.isDarkTheme;
  82. localStorage.setItem("dark-mode", this.isDarkTheme);
  83. },
  84. get theme() {
  85. return this.isDarkTheme ? 'dark' : 'light';
  86. }
  87. };
  88. </script>
  89. {{end}}