Skip to content

全局弹框 · AntDesign ​

核心 API 请查阅 全局弹框-基础篇,本文档仅说明 AntDesign 框架下的特化配置。

导入路径 ​

javascript
import { $initHook, $JiessDialog } from '@jiess/plus/react';

const hook = $initHook({
    ui: antd,            // antd 根对象
    ...React,            // React API
});

AntDesign 特化属性 ​

基于 AntDesign Modal,以下属性可透传:

属性类型默认值说明
widthstring|number960弹框宽度(数字为 px)
centeredbooleanfalse垂直居中
maskClosablebooleanfalse点击遮罩是否关闭
keyboardbooleantrue按 ESC 是否关闭
destroyOnClosebooleanfalse关闭时销毁内容
closablebooleantrue是否显示关闭按钮
okTextstring'确定'确定按钮文字
cancelTextstring'取消'取消按钮文字
confirmLoadingbooleanfalse确定按钮 loading
javascript
$JiessDialog({
    $title: '编辑',
    $content: { /* ... */ },
    width: 600,
    centered: true,        // 垂直居中显示
    maskClosable: false,
});

AntDesign 特有配置 ​

确认对话框 ​

javascript
$JiessDialog({
    $title: '删除确认',
    $content: '确定要删除该记录吗?',
    $footer: {
        $Btns: {
            children: [
                { $Button: { children: '取消', onClick: 'cancel' } },
                {
                    $Button: {
                        children: '确定',
                        type: 'primary',
                        danger: true,
                        onClick: 'submit',
                    },
                },
            ],
        },
    },
    width: 420,
});

加载弹框 ​

javascript
$JiessDialog({
    $title: '处理中...',
    $content: {
        $Spin: { tip: '正在提交数据,请稍候...' },
    },
    closable: false,
    maskClosable: false,
    keyboard: false,
    width: 300,
});

注意事项 ​

事项说明
弹框嵌套内部使用 state.instances 数组管理层级
Antd Modal v4兼容 Ant Design 4.x(适配层处理了 API 差异)
getContainerJiess 内部自动设置挂载节点为 document.body

实战示例 ​

示例 1:弹框内嵌表单 ​

javascript
import { Modal, Button, message } from 'antd';
import { $JiessDialog } from '@jiess/plus/react';

const dialogConfig = $JiessDialog({
    $title: '新增用户',
    $content: {
        children: {
            $Form: {
                layout: 'horizontal',
                labelCol: { span: 6 },
                wrapperCol: { span: 18 },
                children: {
                    name: { $label: '姓名', $name: 'name', $rules: ['required'], $Input: { placeholder: '请输入姓名', allowClear: true } },
                    email: { $label: '邮箱', $name: 'email', $rules: ['required', 'email'], $Input: { placeholder: '请输入邮箱' } },
                    status: {
                        $label: '状态', $name: 'status', $value: 1,
                        $Select: { options: [{ label: '启用', value: 1 }, { label: '禁用', value: 0 }] },
                    },
                },
            },
        },
    },
    $footer: {
        $Btns: {
            children: [
                { $Button: { children: '取消', onClick: 'cancel' } },
                {
                    $Button: {
                        children: '确定', type: 'primary',
                        onClick() { this.validate().then(data => api.createUser(data)).then(() => this.close()); },
                    },
                },
            ],
        },
    },
    width: 600,
    centered: true,
    destroyOnClose: true,     // 关闭时销毁,避免数据残留
    maskClosable: false,
});

示例 2:确认对话框(含异步 loading) ​

javascript
const confirmDialog = $JiessDialog({
    $title: '删除确认',
    $content: '确定要删除该用户吗?此操作不可撤销。',
    $footer: {
        $Btns: {
            children: [
                { $Button: { children: '取消', onClick: 'cancel' } },
                {
                    $Button: {
                        children: '确定删除', danger: true,
                        async onClick() {
                            this.setLoading?.(true);
                            await api.deleteUser(userId);
                            message.success('删除成功');
                            this.close();
                        },
                    },
                },
            ],
        },
    },
    width: 420,
    centered: true,
    icon: <ExclamationCircleOutlined />,
});

示例 3:加载中弹框 ​

javascript
$JiessDialog({
    $content: {
        $Spin: {
            spinning: true,
            tip: '正在处理数据,请稍候...',
            size: 'large',
            children: { tag: 'div', style: { height: '120px' } },
        },
    },
    closable: false,
    maskClosable: false,
    keyboard: false,
    footer: null,
    width: 300,
    centered: true,
});

下一步 ​