多租户与景区关系
This commit is contained in:
@@ -18,6 +18,8 @@ export interface SearchBarPlusProps {
|
||||
onTenantChanged?: (tenantId: string, includeChildren: boolean) => void;
|
||||
// 租户筛选放置位置:start 放在最前,end 放在最后(默认 start)
|
||||
tenantPosition?: 'start' | 'end';
|
||||
// 是否调用后端“切换查询租户”接口(默认不调用,避免跨页面副作用)
|
||||
useSwitchTenant?: boolean;
|
||||
}
|
||||
|
||||
const SearchBarPlus: React.FC<SearchBarPlusProps> = ({
|
||||
@@ -30,13 +32,14 @@ const SearchBarPlus: React.FC<SearchBarPlusProps> = ({
|
||||
showTenant = true,
|
||||
onTenantChanged,
|
||||
tenantPosition = 'start',
|
||||
useSwitchTenant = false,
|
||||
}) => {
|
||||
const handleFinish = async (values: Record<string, any>) => {
|
||||
try {
|
||||
if (showTenant && values && values.tenantId) {
|
||||
await tenantApi.switchTenant(values.tenantId);
|
||||
if (useSwitchTenant && showTenant && values && (values as any).tenantId) {
|
||||
await tenantApi.switchTenant((values as any).tenantId);
|
||||
}
|
||||
onTenantChanged?.(values?.tenantId, !!values?.includeChildren);
|
||||
onTenantChanged?.((values as any)?.tenantId, !!(values as any)?.includeChildren);
|
||||
} finally {
|
||||
await onFinish?.(values);
|
||||
}
|
||||
@@ -58,3 +61,4 @@ const SearchBarPlus: React.FC<SearchBarPlusProps> = ({
|
||||
};
|
||||
|
||||
export default SearchBarPlus;
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ export interface TenantSelectorProps {
|
||||
labelIncludeChildren?: React.ReactNode;
|
||||
// 是否隐藏“包含下级”复选框(用于仅需要选择租户的场景,如用户表单)
|
||||
hideIncludeChildren?: boolean;
|
||||
// 透传给租户选择项的校验规则(用于必填等)
|
||||
rulesTenant?: any[];
|
||||
}
|
||||
|
||||
const toTreeData = (nodes?: TenantTreeNode[] | any): any[] => {
|
||||
@@ -27,6 +29,7 @@ const TenantSelector: React.FC<TenantSelectorProps> = ({
|
||||
labelTenant = '租户',
|
||||
labelIncludeChildren = '包含下级',
|
||||
hideIncludeChildren = false,
|
||||
rulesTenant,
|
||||
}) => {
|
||||
const form = Form.useFormInstance?.();
|
||||
const [tree, setTree] = useState<TenantTreeNode[]>([]);
|
||||
@@ -89,7 +92,7 @@ const TenantSelector: React.FC<TenantSelectorProps> = ({
|
||||
|
||||
return (
|
||||
<>
|
||||
<Form.Item name={nameTenant} label={labelTenant}>
|
||||
<Form.Item name={nameTenant} label={labelTenant} rules={rulesTenant as any}>
|
||||
<TreeSelect
|
||||
style={{ minWidth: 260 }}
|
||||
treeDefaultExpandAll
|
||||
|
||||
Reference in New Issue
Block a user