hide the add new tab button when not designable

This commit is contained in:
chenos 2021-08-05 18:53:44 +08:00
parent 8f746ae319
commit 6da37c6509

View File

@ -45,8 +45,15 @@ const useTabs = ({ singleton }) => {
export const Tabs: any = observer((props: any) => { export const Tabs: any = observer((props: any) => {
const { singleton, ...others } = props; const { singleton, ...others } = props;
const { schema, DesignableBar, appendChild, root, remove, insertAfter } = const {
useDesignable(); designable,
schema,
DesignableBar,
appendChild,
root,
remove,
insertAfter,
} = useDesignable();
const tabs = useTabs({ singleton }); const tabs = useTabs({ singleton });
const [dragOverlayContent, setDragOverlayContent] = useState(''); const [dragOverlayContent, setDragOverlayContent] = useState('');
@ -97,65 +104,67 @@ export const Tabs: any = observer((props: any) => {
{...others} {...others}
className={cls({ singleton })} className={cls({ singleton })}
tabBarExtraContent={ tabBarExtraContent={
<Button designable && (
type={'dashed'} <Button
icon={<PlusOutlined />} type={'dashed'}
onClick={async () => { icon={<PlusOutlined />}
const values = await FormDialog('新增标签页', () => { onClick={async () => {
return ( const values = await FormDialog('新增标签页', () => {
<FormLayout layout={'vertical'}> return (
<SchemaField <FormLayout layout={'vertical'}>
schema={{ <SchemaField
type: 'object', schema={{
properties: { type: 'object',
title: { properties: {
type: 'string', title: {
title: '标签名称', type: 'string',
required: true, title: '标签名称',
'x-decorator': 'FormItem', required: true,
'x-component': 'Input', 'x-decorator': 'FormItem',
'x-component': 'Input',
},
icon: {
type: 'string',
title: '标签图标',
'x-decorator': 'FormItem',
'x-component': 'IconPicker',
},
}, },
icon: { }}
type: 'string', />
title: '标签图标', </FormLayout>
'x-decorator': 'FormItem', );
'x-component': 'IconPicker', }).open({
}, initialValues: {
}, title: schema['title'],
}} icon: schema['x-component-props']?.['icon'],
/> },
</FormLayout> });
); const data = appendChild({
}).open({ type: 'void',
initialValues: { name: uid(),
title: schema['title'], title: values.title,
icon: schema['x-component-props']?.['icon'], 'x-component': 'Tabs.TabPane',
}, 'x-designable-bar': 'Tabs.TabPane.DesignableBar',
}); 'x-component-props': {
const data = appendChild({ icon: values.icon,
type: 'void', },
name: uid(), properties: {
title: values.title, [uid()]: {
'x-component': 'Tabs.TabPane', type: 'void',
'x-designable-bar': 'Tabs.TabPane.DesignableBar', 'x-component': 'Grid',
'x-component-props': { 'x-component-props': {
icon: values.icon, addNewComponent: 'AddNew.PaneItem',
}, },
properties: {
[uid()]: {
type: 'void',
'x-component': 'Grid',
'x-component-props': {
addNewComponent: 'AddNew.PaneItem',
}, },
}, },
}, });
}); await createSchema(data);
await createSchema(data); }}
}} >
>
</Button>
</Button> )
} }
> >
{tabs.map(({ props, schema, name }, key) => ( {tabs.map(({ props, schema, name }, key) => (