App.vue 2.2 KB

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