_app.ts 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import type { AppConfig } from "@@/types/AppConfig"
  2. import apis from "@a"
  3. export const LS_APP_CONFIG_NAME_KEY = `app_config_${import.meta.env.VITE_APP_NAME}_${
  4. import.meta.env.VITE_APP_VERSION
  5. }`
  6. export const useAppConfigStore = defineStore("appConfig", () => {
  7. const config = ref<AppConfig>(
  8. localCache.getJSON(LS_APP_CONFIG_NAME_KEY) ?? {
  9. registerEnabled: false,
  10. captchaEnabled: true,
  11. workflowEnabled: true,
  12. ossPreviewEnabled: true
  13. }
  14. )
  15. function loadConfig() {
  16. return new Promise((resolve) => {
  17. apis.loginApi.getAppConfig().then((res: any) => {
  18. config.value = res.data
  19. localCache.setJSON(LS_APP_CONFIG_NAME_KEY, res.data)
  20. resolve(true)
  21. })
  22. })
  23. }
  24. function getConfig(): AppConfig {
  25. return config.value
  26. }
  27. function getPlatformName() {
  28. return getConfig().platformName
  29. }
  30. function isTenant() {
  31. return getConfig().tenantEnabled
  32. }
  33. function isRegister() {
  34. return getConfig().registerEnabled
  35. }
  36. function isCaptcha() {
  37. return getConfig().captchaEnabled
  38. }
  39. function isWorkflow() {
  40. return getConfig().workflowEnabled
  41. }
  42. function isOssPreview() {
  43. return getConfig().ossPreviewEnabled
  44. }
  45. return {
  46. loadConfig,
  47. getConfig,
  48. getPlatformName,
  49. isTenant,
  50. isRegister,
  51. isCaptcha,
  52. isWorkflow,
  53. isOssPreview
  54. }
  55. })