Files
im_manager/web/src/views/imPolicyShared.ts
T

33 lines
897 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { ref } from 'vue';
import { List as TenantList } from '@/api/imTenant';
export const policyTenantOptions = ref<any[]>([{ label: '全局默认', value: 0 }]);
export async function loadPolicyTenantOptions(includeGlobal = true) {
const res = await TenantList({ page: 1, perPage: 100 });
const tenants = (res?.list || []).map((item) => ({
label: `${item.name}(${item.code})`,
value: item.id,
}));
policyTenantOptions.value = includeGlobal
? [{ label: '全局默认', value: 0 }, ...tenants]
: tenants;
return policyTenantOptions.value;
}
export function parseJSON(value: string, fallback: any) {
try {
return value ? JSON.parse(value) : fallback;
} catch {
return fallback;
}
}
export function stringifyJSON(value: any, fallback = '{}') {
try {
return JSON.stringify(value ?? JSON.parse(fallback));
} catch {
return fallback;
}
}