app.vue 970 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <script lang="ts" setup>
  2. import { computed, watch } from 'vue';
  3. import { useAntdDesignTokens } from '@vben/hooks';
  4. import { preferences, usePreferences } from '@vben/preferences';
  5. import { App, ConfigProvider, theme } from 'antdv-next';
  6. import { antdLocale } from '#/locales';
  7. defineOptions({ name: 'App' });
  8. const { isDark } = usePreferences();
  9. const { tokens } = useAntdDesignTokens();
  10. const tokenTheme = computed(() => {
  11. const algorithm = isDark.value
  12. ? [theme.darkAlgorithm]
  13. : [theme.defaultAlgorithm];
  14. // antd 紧凑模式算法
  15. if (preferences.app.compact) {
  16. algorithm.push(theme.compactAlgorithm);
  17. }
  18. return {
  19. algorithm,
  20. token: tokens,
  21. };
  22. });
  23. watch(
  24. tokenTheme,
  25. (themeConfig) => {
  26. ConfigProvider.config({ theme: themeConfig });
  27. },
  28. { immediate: true },
  29. );
  30. </script>
  31. <template>
  32. <ConfigProvider :locale="antdLocale" :theme="tokenTheme">
  33. <App>
  34. <RouterView />
  35. </App>
  36. </ConfigProvider>
  37. </template>