App.vue 2.3 KB

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