App.vue 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. <script setup lang="ts">
  2. import { theme } from 'ant-design-vue'
  3. import en_US from 'ant-design-vue/es/locale/en_US'
  4. import zh_CN from 'ant-design-vue/es/locale/zh_CN'
  5. import zh_TW from 'ant-design-vue/es/locale/zh_TW'
  6. import loadTranslations from '@/api/translations'
  7. import gettext from '@/gettext'
  8. import { useSettingsStore, useUserStore } from '@/pinia'
  9. const route = useRoute()
  10. const router = useRouter()
  11. const media = window.matchMedia('(prefers-color-scheme: dark)')
  12. function callback() {
  13. const settings = useSettingsStore()
  14. if (settings.preference_theme === 'auto') {
  15. if (media.matches)
  16. settings.set_theme('dark')
  17. else
  18. settings.set_theme('light')
  19. }
  20. else {
  21. settings.set_theme(settings.preference_theme)
  22. }
  23. }
  24. callback()
  25. const devicePrefersTheme = computed(() => {
  26. return media.matches ? 'dark' : 'light'
  27. })
  28. provide('devicePrefersTheme', devicePrefersTheme)
  29. media.addEventListener('change', callback)
  30. const lang = computed(() => {
  31. switch (gettext.current) {
  32. case 'zh_CN':
  33. return zh_CN
  34. case 'zh_TW':
  35. return zh_TW
  36. default:
  37. return en_US
  38. }
  39. })
  40. const settings = useSettingsStore()
  41. const user = useUserStore()
  42. const is_theme_dark = computed(() => settings.theme === 'dark')
  43. loadTranslations(route)
  44. if (user.isLogin) {
  45. watch(route, () => {
  46. settings.route_path = route.path
  47. })
  48. onMounted(() => {
  49. router.push(settings.route_path)
  50. })
  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>