App.vue 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <script setup lang="ts">
  2. import loadTranslations from '@/api/translations'
  3. import gettext from '@/gettext'
  4. import { useSettingsStore } from '@/pinia'
  5. import { theme } from 'ant-design-vue'
  6. import en_US from 'ant-design-vue/es/locale/en_US'
  7. import zh_CN from 'ant-design-vue/es/locale/zh_CN'
  8. import zh_TW from 'ant-design-vue/es/locale/zh_TW'
  9. // This starter template is using Vue 3 <script setup> SFCs
  10. // Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
  11. import { computed, provide } from 'vue'
  12. import router from './routes'
  13. const route = useRoute()
  14. const media = window.matchMedia('(prefers-color-scheme: dark)')
  15. function callback() {
  16. const settings = useSettingsStore()
  17. if (settings.preference_theme === 'auto') {
  18. if (media.matches)
  19. settings.set_theme('dark')
  20. else
  21. settings.set_theme('light')
  22. }
  23. else {
  24. settings.set_theme(settings.preference_theme)
  25. }
  26. }
  27. callback()
  28. const devicePrefersTheme = computed(() => {
  29. return media.matches ? 'dark' : 'light'
  30. })
  31. provide('devicePrefersTheme', devicePrefersTheme)
  32. media.addEventListener('change', callback)
  33. const lang = computed(() => {
  34. switch (gettext.current) {
  35. case 'zh_CN':
  36. return zh_CN
  37. case 'zh_TW':
  38. return zh_TW
  39. default:
  40. return en_US
  41. }
  42. })
  43. const settings = useSettingsStore()
  44. const is_theme_dark = computed(() => settings.theme === 'dark')
  45. loadTranslations(route)
  46. watch(route, () => {
  47. settings.route_path = route.path
  48. })
  49. onMounted(() => {
  50. router.push(settings.route_path)
  51. })
  52. </script>
  53. <template>
  54. <AConfigProvider
  55. :theme="{
  56. algorithm: is_theme_dark ? theme.darkAlgorithm : theme.defaultAlgorithm,
  57. }"
  58. :locale="lang"
  59. :auto-insert-space-in-button="false"
  60. >
  61. <RouterView />
  62. </AConfigProvider>
  63. </template>
  64. <style lang="less">
  65. @import "ant-design-vue/dist/reset.css";
  66. .dark {
  67. h1, h2, h3, h4, h5, h6, p, div {
  68. color: #fafafa;
  69. }
  70. .ant-checkbox-indeterminate {
  71. .ant-checkbox-inner {
  72. background-color: transparent !important;
  73. }
  74. }
  75. .ant-layout-header {
  76. background-color: #141414 !important;
  77. }
  78. .ant-layout-sider {
  79. .ant-menu {
  80. border-right: 0 !important;
  81. }
  82. &.ant-layout-sider-has-trigger {
  83. padding-bottom: 0;
  84. }
  85. }
  86. }
  87. .ant-layout-header {
  88. padding: 0 !important;
  89. background-color: #fff !important;
  90. }
  91. .ant-layout-sider {
  92. .ant-menu {
  93. border-inline-end: none !important;
  94. }
  95. }
  96. @media (max-width: 512px) {
  97. .ant-card {
  98. border-radius: 0;
  99. }
  100. }
  101. </style>
  102. <style lang="less" scoped>
  103. </style>