useTargetTenantIdSetting.ts 904 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import { useUserStore } from '@/store/modules/user';
  2. import { computed, watch } from 'vue';
  3. export const SYS_TENANT_ID = 0;
  4. /** 设置targetTenantId */
  5. export function useTargetTenantIdSetting() {
  6. let fullKey = '';
  7. const userStore = useUserStore();
  8. watch(
  9. () => [userStore.info.username, userStore.info.tenantCode],
  10. ([username, tenantCode]) => {
  11. fullKey = `${tenantCode || ''}_${username}_targetTenantId`;
  12. },
  13. { immediate: true },
  14. );
  15. function setValue(tenantId: string | string) {
  16. if (!fullKey) {
  17. return;
  18. }
  19. localStorage.setItem(fullKey, String(tenantId));
  20. }
  21. function getValue() {
  22. if (!fullKey) {
  23. return;
  24. }
  25. return localStorage.getItem(fullKey);
  26. }
  27. const isSysTenant = computed(() => getValue() !== SYS_TENANT_ID.toString())
  28. return { setValue, getValue, isSysTenant };
  29. }