模态框 Modal

含有遮罩层的对话框,用于模拟浏览器的alertconfirmprompt

模态框通过遮罩层来阻止用户的其他行为。

示例

基本形式

<button class="u-btn u-btn-primary" on-click={this.show()}>Modal</button>
let component = new RGUI.Component({
    template,
    show() {
        let modal = new RGUI.Modal({
            data: {
                title: 'Modal标题',
                content: 'Modal内容',
            },
        });
    },
});

Alert

<button class="u-btn u-btn-error" on-click={this.show()}>Alert</button>
let component = new RGUI.Component({
    template,
    show() {
        RGUI.Modal.alert('Alert内容');
    },
});

Confirm

<button class="u-btn u-btn-success" on-click={this.show()}>Confirm</button>
let component = new RGUI.Component({
    template,
    show() {
        RGUI.Modal.confirm('Confirm内容');
    },
});

Disabled

设置disabledtrue,可以禁用确定按钮。

<button class="u-btn u-btn-warning" on-click={this.show()}>Modal</button>
let component = new RGUI.Component({
    template,
    show() {
        let modal = new RGUI.Modal({
            data: {
                title: 'Modal标题',
                content: 'Modal内容',
                disabled: true
            },
        });
    },
});

事件

请打开浏览器的控制台查看结果。

<button class="u-btn u-btn-primary" on-click={this.show()}>Modal</button>
let component = new RGUI.Component({
    template,
    show() {
        let modal = new RGUI.Modal({
            data: {
                title: 'Modal标题',
                content: 'Modal内容',
                cancelButton: '',
            },
        }).$on('close', () => console.log('on-close'))
          .$on('ok', () => console.log('on-ok'))
          .$on('cancel', () => console.log('on-cancel'));
    },
});

API

Class

Modal

继承自

Options

new Modal()

参数类型默认值数据流向描述
dataObject绑定属性
data.titlestring'提示'outside => inside模态框标题
data.contentstring''outside => inside模态框内容
data.contentTemplatestring''outside @=> inside模态框内容模板,用于支持复杂内容的自定义。
data.okButtonstring'确定'outside => inside确定按钮的文字,如果为空则不显示。
data.cancelButtonstring'取消'outside => inside取消按钮的文字,如果为空则不显示。
data.disabledbooleanfalseoutside => inside是否禁用。禁用时,确定按钮不可点。
data.classstring''outside => inside补充class
data.submittingbooleanfalseoutside => inside是否处于提交中状态。

Methods

modal.close()

关闭模态框

参数类型默认值描述
无参数
返回值类型描述
无返回值

modal.ok()

确定模态框

参数类型默认值描述
无参数
返回值类型描述
无返回值

modal.cancel()

取消模态框

参数类型默认值描述
无参数
返回值类型描述
无返回值

Static Methods

Modal.alert(content[, title])

弹出一个alert模态框。关闭时始终触发确定事件。

参数类型默认值描述
contentstring''模态框内容
titlestring'提示'模态框标题
返回值类型描述
modalModal返回该模态框

Modal.confirm(content[, title])

弹出一个confirm模态框

参数类型默认值描述
contentstring''模态框内容
titlestring'提示'模态框标题
返回值类型描述
modalModal返回该模态框

Events

modal.$on('close')

关闭模态框时触发

属性类型描述
senderobject事件发送对象

modal.$on('ok')

确定模态框时触发

属性类型描述
senderobject事件发送对象

modal.$on('cancel')

取消模态框时触发

属性类型描述
senderobject事件发送对象