feat: add tooltip and confirm to the button

This commit is contained in:
chenos 2021-08-25 12:21:11 +08:00
parent 12ba06f89a
commit 4860cb019f
10 changed files with 105 additions and 53 deletions

View File

@ -246,6 +246,7 @@ const schema: ISchema = {
name: 'action', name: 'action',
'x-component': 'Action', 'x-component': 'Action',
'x-component-props': { 'x-component-props': {
tooltip: '权限配置',
className: 'nb-database-config', className: 'nb-database-config',
icon: 'LockOutlined', icon: 'LockOutlined',
type: 'primary', type: 'primary',

View File

@ -8,6 +8,7 @@ import {
Menu, Menu,
Collapse, Collapse,
Dropdown, Dropdown,
Tooltip,
} from 'antd'; } from 'antd';
import isEmpty from 'lodash/isEmpty'; import isEmpty from 'lodash/isEmpty';
import { import {
@ -43,16 +44,18 @@ import { AuthProvider } from './Auth';
function DesignableToggle() { function DesignableToggle() {
const { designable, setDesignable } = useDesignableSwitchContext(); const { designable, setDesignable } = useDesignableSwitchContext();
return ( return (
<Button <Tooltip title={'界面配置'}>
className={cls('nb-designable-toggle', { active: designable })} <Button
type={'primary'} className={cls('nb-designable-toggle', { active: designable })}
style={{ height: 46, border: 0 }} type={'primary'}
onClick={() => { style={{ height: 46, border: 0 }}
setDesignable(!designable); onClick={() => {
}} setDesignable(!designable);
> }}
<HighlightOutlined /> >
</Button> <HighlightOutlined />
</Button>
</Tooltip>
); );
} }

View File

@ -102,6 +102,10 @@ const schema = {
'x-designable-bar': 'Action.DesignableBar', 'x-designable-bar': 'Action.DesignableBar',
'x-component-props': { 'x-component-props': {
useAction: '{{ useAction }}', useAction: '{{ useAction }}',
tooltip: '提示信息',
confirm: {
title: 'Do you Want to delete these items?',
},
}, },
}; };

View File

@ -20,6 +20,7 @@ import {
Drawer, Drawer,
Modal, Modal,
Select, Select,
Tooltip,
} from 'antd'; } from 'antd';
import { Link, useHistory, LinkProps, Switch } from 'react-router-dom'; import { Link, useHistory, LinkProps, Switch } from 'react-router-dom';
import { import {
@ -49,8 +50,21 @@ import { useDisplayedMapContext } from '../../constate';
export const ButtonComponentContext = createContext(null); export const ButtonComponentContext = createContext(null);
function getTooltipProps(tooltip) {
if (typeof tooltip === 'string') {
return { title: tooltip };
}
return tooltip;
}
export const Action: any = observer((props: any) => { export const Action: any = observer((props: any) => {
const { useAction = useDefaultAction, icon, ...others } = props; const {
tooltip,
confirm,
useAction = useDefaultAction,
icon,
...others
} = props;
const { run } = useAction(); const { run } = useAction();
const field = useField(); const field = useField();
const { schema, DesignableBar } = useDesignable(); const { schema, DesignableBar } = useDesignable();
@ -59,19 +73,31 @@ export const Action: any = observer((props: any) => {
const isDropdownOrPopover = const isDropdownOrPopover =
child && child &&
['Action.Dropdown', 'Action.Popover'].includes(child['x-component']); ['Action.Dropdown', 'Action.Popover'].includes(child['x-component']);
const button = ( let button = (
<Button <Button
{...others} {...others}
icon={<IconPicker type={icon} />} icon={<IconPicker type={icon} />}
onClick={async () => { onClick={async () => {
setVisible(true); setVisible(true);
await run(); if (confirm) {
Modal.confirm({
...confirm,
async onOk() {
await run();
},
});
} else {
await run();
}
}} }}
> >
{schema.title} {schema.title}
<DesignableBar path={getSchemaPath(schema)} /> <DesignableBar path={getSchemaPath(schema)} />
</Button> </Button>
); );
if (tooltip) {
button = <Tooltip {...getTooltipProps(tooltip)}>{button}</Tooltip>;
}
return ( return (
<ButtonComponentContext.Provider value={button}> <ButtonComponentContext.Provider value={button}>
<VisibleContext.Provider value={[visible, setVisible]}> <VisibleContext.Provider value={[visible, setVisible]}>

View File

@ -175,6 +175,10 @@ function generateCardItemSchema(component) {
'x-component': 'Action', 'x-component': 'Action',
'x-designable-bar': 'Table.Action.DesignableBar', 'x-designable-bar': 'Table.Action.DesignableBar',
'x-component-props': { 'x-component-props': {
confirm: {
title: '删除数据',
content: '删除后无法恢复,确定要删除吗?'
},
useAction: '{{ Table.useTableDestroyAction }}', useAction: '{{ Table.useTableDestroyAction }}',
}, },
}, },
@ -312,17 +316,17 @@ function generateCardItemSchema(component) {
}, },
}, },
}, },
[uid()]: { // [uid()]: {
type: 'void', // type: 'void',
title: '删除', // title: '删除',
'x-component': 'Action', // 'x-component': 'Action',
'x-designable-bar': 'Table.Action.DesignableBar', // 'x-designable-bar': 'Table.Action.DesignableBar',
'x-action-type': 'destroy', // 'x-action-type': 'destroy',
'x-component-props': { // 'x-component-props': {
type: 'link', // type: 'link',
useAction: '{{ Table.useTableDestroyAction }}', // useAction: '{{ Table.useTableDestroyAction }}',
}, // },
}, // },
}, },
}, },
}, },

View File

@ -26,6 +26,7 @@ import {
message, message,
Drawer, Drawer,
Space, Space,
Tooltip,
} from 'antd'; } from 'antd';
import { options, interfaces, getDefaultFields } from './interfaces'; import { options, interfaces, getDefaultFields } from './interfaces';
import { import {
@ -107,27 +108,29 @@ export const DatabaseCollection = observer((props) => {
return ( return (
<div> <div>
<Button <Tooltip title={'数据表配置'}>
className={'nb-database-config'} <Button
style={{ className={'nb-database-config'}
height: 46, style={{
borderRadius: 0, height: 46,
}} borderRadius: 0,
onClick={async () => { }}
setVisible(true); onClick={async () => {
// await run(); setVisible(true);
if (field.value?.length === 0) { // await run();
field.push({ if (field.value?.length === 0) {
name: `t_${uid()}`, field.push({
unsaved: true, name: `t_${uid()}`,
generalFields: getDefaultFields(), unsaved: true,
}); generalFields: getDefaultFields(),
} });
}} }
type={'primary'} }}
> type={'primary'}
<DatabaseOutlined /> >
</Button> <DatabaseOutlined />
</Button>
</Tooltip>
<Drawer <Drawer
width={'50%'} width={'50%'}
// bodyStyle={{ // bodyStyle={{

View File

@ -1,4 +1,4 @@
@bgcolor: #F18B62; @bgcolor: #f18b62;
.designable-info { .designable-info {
position: absolute; position: absolute;
@ -38,13 +38,17 @@
height: 16px !important; height: 16px !important;
vertical-align: top; vertical-align: top;
line-height: 16px !important; line-height: 16px !important;
// font-size: 10px; cursor: pointer;
// display: inline-flex; // font-size: 10px;
// display: inline-flex;
background-color: @bgcolor !important; background-color: @bgcolor !important;
border-bottom-left-radius: 1px; border-bottom-left-radius: 1px;
border-bottom-right-radius: 1px; border-bottom-right-radius: 1px;
// margin-left: 0 !important; // margin-left: 0 !important;
// margin-right: 2px !important; // margin-right: 2px !important;
&.anticon-drag {
cursor: grab;
}
} }
} }
} }

View File

@ -6,6 +6,8 @@ import {
useSensor, useSensor,
useSensors, useSensors,
rectIntersection, rectIntersection,
closestCenter,
closestCorners,
} from '@dnd-kit/core'; } from '@dnd-kit/core';
import { import {
SortableContext, SortableContext,

View File

@ -668,7 +668,7 @@ Menu.DesignableBar = (props) => {
overlayStyle={{ overlayStyle={{
minWidth: 150, minWidth: 150,
}} }}
trigger={['click']} trigger={['hover']}
overlay={ overlay={
<AntdMenu <AntdMenu
onClick={async (info) => { onClick={async (info) => {

View File

@ -942,6 +942,10 @@ function generateActionSchema(type) {
'x-component': 'Action', 'x-component': 'Action',
'x-designable-bar': 'Table.Action.DesignableBar', 'x-designable-bar': 'Table.Action.DesignableBar',
'x-component-props': { 'x-component-props': {
confirm: {
title: '删除数据',
content: '删除后无法恢复,确定要删除吗?'
},
useAction: '{{ Table.useTableDestroyAction }}', useAction: '{{ Table.useTableDestroyAction }}',
}, },
}, },
@ -1111,7 +1115,7 @@ function AddActionButton() {
className={'designable-btn designable-btn-dash'} className={'designable-btn designable-btn-dash'}
style={{ marginLeft: 8 }} style={{ marginLeft: 8 }}
type={'dashed'} type={'dashed'}
icon={<PlusOutlined />} icon={<SettingOutlined />}
> >
</Button> </Button>
@ -1779,6 +1783,7 @@ Table.Action.DesignableBar = () => {
bordered={false} bordered={false}
size={'small'} size={'small'}
defaultValue={popupComponent} defaultValue={popupComponent}
style={{ width: 100 }}
onChange={(value) => { onChange={(value) => {
const s = Object.values(schema.properties).shift(); const s = Object.values(schema.properties).shift();
s['x-component'] = value; s['x-component'] = value;
@ -1795,7 +1800,7 @@ Table.Action.DesignableBar = () => {
</Select.Option> </Select.Option>
<Select.Option value={'Action.Window'}> <Select.Option value={'Action.Window'}>
</Select.Option> </Select.Option>
</Select>{' '} </Select>{' '}