App.vue 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <template>
  2. <StyleProvider hash-priority="high" :transformers="[legacyLogicalPropertiesTransformer]">
  3. <ConfigProvider :locale="getAntdLocale" :theme="getTheme">
  4. <AppProvider prefixCls="jeesite">
  5. <RouterView />
  6. </AppProvider>
  7. </ConfigProvider>
  8. </StyleProvider>
  9. </template>
  10. <script lang="ts" setup>
  11. import { computed, onMounted, unref, watch } from 'vue';
  12. import { StyleProvider, legacyLogicalPropertiesTransformer, ConfigProvider, theme } from 'ant-design-vue';
  13. import { authorizationInfoApi } from '@/core/api/sys/login';
  14. import { AppProvider } from '@/core/components/Application';
  15. import { useRootSetting } from '@/core/hooks/setting/useRootSetting';
  16. import { useUserStore } from '@/core/store/modules/case';
  17. import { ThemeEnum } from '@/core/enums/appEnum';
  18. import { useLocale } from '@/core/locales/useLocale';
  19. import { useTitle } from '@/core/hooks/web/useTitle';
  20. import { useWatermark } from '@/core/hooks/web/useWatermark';
  21. import { extractAuthorizationCache } from '@/core/utils/license';
  22. import { darkPrimaryColor } from '@build/theme/themeConfig';
  23. import 'dayjs/locale/zh-cn';
  24. // support Multi-language
  25. const { getAntdLocale } = useLocale();
  26. const { getDarkMode, getThemeColor } = useRootSetting();
  27. const userStore = useUserStore();
  28. const { setWatermark, clear } = useWatermark();
  29. const authorizationUnit = computed(() => String(userStore.getPageCacheByKey('authorizationUnit', '') || '').trim());
  30. const getTheme = computed(() => {
  31. const isDark = unref(getDarkMode) === ThemeEnum.DARK;
  32. return {
  33. algorithm: isDark ? theme.darkAlgorithm : theme.defaultAlgorithm,
  34. token: {
  35. colorPrimary: isDark ? darkPrimaryColor : unref(getThemeColor),
  36. colorLink: isDark ? darkPrimaryColor : unref(getThemeColor),
  37. colorInfo: isDark ? darkPrimaryColor : unref(getThemeColor),
  38. borderRadius: 6,
  39. },
  40. };
  41. });
  42. // Listening to page changes and dynamically changing site titles
  43. useTitle();
  44. async function ensureAuthorizationUnit() {
  45. if (unref(authorizationUnit)) return;
  46. try {
  47. const res = await authorizationInfoApi();
  48. const { authorizationUnit: unit } = extractAuthorizationCache(res);
  49. userStore.setPageCache('authorizationUnit', unit);
  50. } catch {
  51. clear();
  52. }
  53. }
  54. watch(
  55. authorizationUnit,
  56. (unit) => {
  57. if (!unit) {
  58. clear();
  59. return;
  60. }
  61. setWatermark(unit);
  62. },
  63. { immediate: true },
  64. );
  65. onMounted(() => {
  66. void ensureAuthorizationUnit();
  67. });
  68. </script>
  69. <style lang="less">
  70. body {
  71. line-height: 1.5715;
  72. font-family:
  73. -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Noto Sans', sans-serif,
  74. 'Apple Color Emoji', 'Segoe UI Emoji', 'Segoe UI Symbol', 'Noto Color Emoji';
  75. }
  76. </style>