通知 Notify
创建显示消息的通知,并且能自动淡出。类似Android中的Toast。
示例
基本形式
<button class="u-btn u-btn-primary" on-click={this.show()}>Notify</button>
var component = new RGUI.Component({
    template: template,
    show: function() {
        RGUI.Notify.show('This is a message.');
    }
});
状态扩展
<button class="u-btn u-btn-info" on-click={this.show('info')}>Info</button>
<button class="u-btn u-btn-success" on-click={this.show('success')}>Success</button>
<button class="u-btn u-btn-warning" on-click={this.show('warning')}>Warning</button>
<button class="u-btn u-btn-error" on-click={this.show('error')}>Error</button>
var component = new RGUI.Component({
    template: template,
    show: function(state) {
        RGUI.Notify[state](state + ' message.', state);
    }
});
位置扩展
<button class="u-btn" on-click={this.show(0)}>Top Center</button>
<button class="u-btn" on-click={this.show(1)}>Top Left</button>
<button class="u-btn" on-click={this.show(2)}>Top Right</button>
<button class="u-btn" on-click={this.show(3)}>Bottom Center</button>
<button class="u-btn" on-click={this.show(4)}>Bottom Left</button>
<button class="u-btn" on-click={this.show(5)}>Bottom Right</button>
var component = new RGUI.Component({
    template: template,
    config: function() {
        this.notifies = [
            new RGUI.Notify({data: {position: 'topcenter'} }),
            new RGUI.Notify({data: {position: 'topleft'} }),
            new RGUI.Notify({data: {position: 'topright'} }),
            new RGUI.Notify({data: {position: 'bottomcenter'} }),
            new RGUI.Notify({data: {position: 'bottomleft'} }),
            new RGUI.Notify({data: {position: 'bottomright'} })
        ];
    },
    show: function(index) {
        var notify = this.notifies[index];
        notify.show('Position: ' + notify.data.position + '.');
    }
});
嵌入文档流
上面的模式通知都是以fixed的形式固定在浏览器中,如果要将通知嵌入到文档流,先将notify注入到需要的位置,同时设置notify的position="static"。
<button class="u-btn u-btn-primary" on-click={this.show()}>Static</button>
<notify ref="notify" position="static" duration="0" />
var component = new RGUI.Component({
    template: template,
    show: function() {
        this.$refs.notify.show('Static notify.');
    }
});
消息停留时间
可以通过设置notify的duration参数设置所有消息的停留时间,也可以在show的时候单独设置该条消息的停留时间,单位为毫秒。
<button class="u-btn" on-click={this.show(500)}>0.5s</button>
<button class="u-btn" on-click={this.show(1000)}>1s</button>
<button class="u-btn" on-click={this.show(2000)}>2s</button>
<button class="u-btn" on-click={this.show(0)}>常驻</button>
var component = new RGUI.Component({
    template: template,
    show: function(duration) {
        RGUI.Notify.show('Duration: ' + duration + ' ms.', null, duration);
    }
});
始终显示一条
将single设置为true,可以让notify始终只显示一条消息。
<button class="u-btn u-btn-info" on-click={this.show('info')}>Info</button>
<button class="u-btn u-btn-success" on-click={this.show('success')}>Success</button>
<button class="u-btn u-btn-warning" on-click={this.show('warning')}>Warning</button>
<button class="u-btn u-btn-error" on-click={this.show('error')}>Error</button>
var component = new RGUI.Component({
    template: template,
    config: function() {
        this.notify = new RGUI.Notify({data: {single: true} });
    },
    number: 1,
    show: function(state) {
        this.notify[state]('Message ' + this.number + '.');
        this.number++;
    }
});
API
Class
Notify
继承自Component。
Options
new Notify()
| 参数 | 类型 | 默认值 | 数据流向 | 描述 | 
|---|---|---|---|---|
| data | object | 绑定属性 | ||
| data.position | string | 'topcenter' | outer => inner | 通知的位置,可选参数:`topcenter`、`topleft`、`topright`、`bottomcenter`、`bottomleft`、`bottomright`、`static` | 
| data.duration | number | 2000 | outer => inner | 每条消息默认的停留毫秒数,如果为0,则表示消息常驻不消失。 | 
| data.single | boolean | false | outer => inner | 是否始终显示一条 | 
| data.visible | boolean | true | outer => inner | 是否显示 | 
| data.class | string | '' | outer => inner | 补充class | 
Methods
notify.show(text[, state][, duration])
弹出一个消息
| 参数 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| text | string | '' | 消息内容 | 
| state | string | null | 消息状态,可选参数:`info`、`success`、`warning`、`error` | 
| duration | number | notify.duration | 该条消息的停留毫秒数。如果为0,则表示消息常驻不消失。如果不填,则使用notify默认的duration。 | 
| 返回值 | 类型 | 描述 | |
| 无返回值 | |||
notify.close(message)
关闭某条消息
| 参数 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| message | object | 需要关闭的消息对象 | |
| 返回值 | 类型 | 描述 | |
| 无返回值 | |||
notify.closeAll()
关闭所有消息
| 参数 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| 无参数 | |||
| 返回值 | 类型 | 描述 | |
| 无返回值 | |||
notify.[info|success|warning|error](text[, duration])
弹出特殊类型的消息。为show方法的简写方式。
| 参数 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| text | string | '' | 消息内容 | 
| duration | number | notify.duration | 该条消息的停留毫秒数。如果为0,则表示消息常驻不消失。如果不填,则使用notify默认的duration。 | 
| 返回值 | 类型 | 描述 | |
| 无返回值 | |||
Static Methods
Notify.show(text[, state][, duration])
弹出一个消息
| 参数 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| text | string | '' | 消息内容 | 
| state | string | null | 消息状态,可选参数:`info`、`success`、`warning`、`error` | 
| duration | number | notify.duration | 该条消息的停留毫秒数。如果为0,则表示消息常驻不消失。如果不填,则使用notify默认的duration。 | 
| 返回值 | 类型 | 描述 | |
| 无返回值 | |||
Notify.[info|success|warning|error](text[, duration])
弹出特殊类型的消息。为show方法的简写方式。
| 参数 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| text | string | '' | 消息内容 | 
| duration | number | notify.duration | 该条消息的停留毫秒数。如果为0,则表示消息常驻不消失。如果不填,则使用notify默认的duration。 | 
| 返回值 | 类型 | 描述 | |
| 无返回值 | |||
Notify.close(message)
关闭某条消息
| 参数 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| message | object | 需要关闭的消息对象 | |
| 返回值 | 类型 | 描述 | |
| 无返回值 | |||
Notify.closeAll()
关闭所有消息
| 参数 | 类型 | 默认值 | 描述 | 
|---|---|---|---|
| 无参数 | |||
| 返回值 | 类型 | 描述 | |
| 无返回值 | |||
Events
notify.$on('show')
弹出一个消息时触发
| 属性 | 类型 | 描述 | 
|---|---|---|
| sender | object | 事件发送对象 | 
| message | object | 弹出的消息对象 | 
notify.$on('close')
关闭某条消息时触发
| 属性 | 类型 | 描述 | 
|---|---|---|
| sender | object | 事件发送对象 | 
| message | object | 关闭了的消息对象 |