| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- import { useUserStore } from '@/store/modules/user';
- import { watch } from 'vue';
- /** 系统租户的id为0 */
- export const SYS_TENANT_ID = 0;
- /** 设置targetTenantId */
- export function useTargetTenantIdSetting() {
- let fullKey = '';
- const userStore = useUserStore();
- watch(
- () => [userStore.info.username, userStore.info.tenantCode],
- ([username, tenantCode]) => {
- fullKey = `${tenantCode || ''}_${username}_targetTenantId`;
- },
- { immediate: true },
- );
- function setValue(tenantId: string | string) {
- if (!fullKey) {
- return;
- }
- localStorage.setItem(fullKey, String(tenantId));
- }
- function getValue() {
- if (!fullKey) {
- return;
- }
- return localStorage.getItem(fullKey);
- }
- // 系统租户
- const sysTenantId = getValue() || userStore.info.tenantId?.toString();
- /** 当前选择的租户是否是系统租户 */
- const isTargetTenantSys = sysTenantId === SYS_TENANT_ID.toString();
- return { setValue, getValue, isTargetTenantSys };
- }
|