App.vue 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. <script setup lang="ts">
  2. // This starter template is using Vue 3 <script setup> SFCs
  3. // Check out https://vuejs.org/api/sfc-script-setup.html#script-setup
  4. import { computed, provide } from 'vue'
  5. import { theme } from 'ant-design-vue'
  6. import zh_CN from 'ant-design-vue/es/locale/zh_CN'
  7. import zh_TW from 'ant-design-vue/es/locale/zh_TW'
  8. import en_US from 'ant-design-vue/es/locale/en_US'
  9. import gettext from '@/gettext'
  10. import { useSettingsStore } from '@/pinia'
  11. const media = window.matchMedia('(prefers-color-scheme: dark)')
  12. const 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 is_theme_dark = computed(() => settings.theme === 'dark')
  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>