|
|
|
@ -5,16 +5,22 @@
|
|
|
|
|
* @class BI.Toast |
|
|
|
|
* @extends BI.Tip |
|
|
|
|
*/ |
|
|
|
|
BI.Toast = BI.inherit(BI.Tip, { |
|
|
|
|
_const: { |
|
|
|
|
|
|
|
|
|
import { shortcut } from "../../../core/decorator"; |
|
|
|
|
@shortcut() |
|
|
|
|
export class Toast extends BI.Tip { |
|
|
|
|
_const= { |
|
|
|
|
closableMinWidth: 146, |
|
|
|
|
minWidth: 100, |
|
|
|
|
closableMaxWidth: 410, |
|
|
|
|
maxWidth: 400, |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
static EVENT_DESTORY = "EVENT_DESTORY"; |
|
|
|
|
static xtype = "bi.toast"; |
|
|
|
|
|
|
|
|
|
_defaultConfig: function () { |
|
|
|
|
return BI.extend(BI.Toast.superclass._defaultConfig.apply(this, arguments), { |
|
|
|
|
_defaultConfig() { |
|
|
|
|
return BI.extend(super._defaultConfig(arguments), { |
|
|
|
|
extraCls: "bi-toast", |
|
|
|
|
text: "", |
|
|
|
|
level: "success", // success或warning
|
|
|
|
@ -25,15 +31,16 @@ BI.Toast = BI.inherit(BI.Tip, {
|
|
|
|
|
innerHgap: 4, |
|
|
|
|
hgap: 8, |
|
|
|
|
}); |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
render: function () { |
|
|
|
|
var self = this, o = this.options, c = this._const; |
|
|
|
|
render() { |
|
|
|
|
const { closable, level, autoClose, textHeight, text, hgap, vgap, innerHgap } = this.options; |
|
|
|
|
const { closableMinWidth, minWidth, maxWidth, closableMaxWidth } = this._const; |
|
|
|
|
this.element.css({ |
|
|
|
|
minWidth: BI.pixFormat(o.closable ? c.closableMinWidth : c.minWidth), |
|
|
|
|
maxWidth: BI.pixFormat(o.closable ? c.closableMaxWidth : c.maxWidth), |
|
|
|
|
minWidth: BI.pixFormat(closable ? closableMinWidth : minWidth), |
|
|
|
|
maxWidth: BI.pixFormat(closable ? closableMaxWidth : maxWidth), |
|
|
|
|
}); |
|
|
|
|
this.element.addClass("toast-" + o.level); |
|
|
|
|
this.element.addClass("toast-" + level); |
|
|
|
|
function fn(e) { |
|
|
|
|
e.stopPropagation(); |
|
|
|
|
e.stopEvent(); |
|
|
|
@ -49,8 +56,8 @@ BI.Toast = BI.inherit(BI.Tip, {
|
|
|
|
|
mouseleave: fn, |
|
|
|
|
mousemove: fn, |
|
|
|
|
}); |
|
|
|
|
var cls; |
|
|
|
|
switch (o.level) { |
|
|
|
|
let cls; |
|
|
|
|
switch (level) { |
|
|
|
|
case "success": |
|
|
|
|
cls = "toast-success-font"; |
|
|
|
|
break; |
|
|
|
@ -70,32 +77,32 @@ BI.Toast = BI.inherit(BI.Tip, {
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function hasCloseIcon() { |
|
|
|
|
return o.closable === true || (o.closable === null && o.autoClose === false); |
|
|
|
|
return closable === true || (closable === null && autoClose === false); |
|
|
|
|
} |
|
|
|
|
var items = [{ |
|
|
|
|
const items = [{ |
|
|
|
|
type: "bi.icon_label", |
|
|
|
|
cls: cls + " toast-icon", |
|
|
|
|
height: o.textHeight, |
|
|
|
|
height: textHeight, |
|
|
|
|
}, { |
|
|
|
|
el: BI.isPlainObject(o.text) ? o.text : { |
|
|
|
|
el: BI.isPlainObject(text) ? text : { |
|
|
|
|
type: "bi.label", |
|
|
|
|
whiteSpace: "normal", |
|
|
|
|
text: o.text, |
|
|
|
|
textHeight: o.textHeight, |
|
|
|
|
text: text, |
|
|
|
|
textHeight: textHeight, |
|
|
|
|
textAlign: "left", |
|
|
|
|
}, |
|
|
|
|
}]; |
|
|
|
|
|
|
|
|
|
var columnSize = ["", "fill"]; |
|
|
|
|
const columnSize = ["", "fill"]; |
|
|
|
|
|
|
|
|
|
if (hasCloseIcon()) { |
|
|
|
|
items.push({ |
|
|
|
|
type: "bi.icon_button", |
|
|
|
|
cls: "close-font toast-icon", |
|
|
|
|
handler: function () { |
|
|
|
|
self.destroy(); |
|
|
|
|
handler: ()=> { |
|
|
|
|
this.destroy(); |
|
|
|
|
}, |
|
|
|
|
height: o.textHeight, |
|
|
|
|
height: textHeight, |
|
|
|
|
}); |
|
|
|
|
columnSize.push(""); |
|
|
|
|
} |
|
|
|
@ -104,16 +111,17 @@ BI.Toast = BI.inherit(BI.Tip, {
|
|
|
|
|
type: "bi.horizontal", |
|
|
|
|
horizontalAlign: BI.HorizontalAlign.Stretch, |
|
|
|
|
items: items, |
|
|
|
|
hgap: o.hgap, |
|
|
|
|
vgap: o.vgap, |
|
|
|
|
innerHgap: o.innerHgap, |
|
|
|
|
hgap: hgap, |
|
|
|
|
vgap: vgap, |
|
|
|
|
innerHgap: innerHgap, |
|
|
|
|
columnSize: columnSize, |
|
|
|
|
}; |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
beforeDestroy: function () { |
|
|
|
|
this.fireEvent(BI.Toast.EVENT_DESTORY); |
|
|
|
|
}, |
|
|
|
|
}); |
|
|
|
|
BI.Toast.EVENT_DESTORY = "EVENT_DESTORY"; |
|
|
|
|
BI.shortcut("bi.toast", BI.Toast); |
|
|
|
|
beforeDestroy() { |
|
|
|
|
this.fireEvent(Toast.EVENT_DESTORY); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
BI.extend(BI, { Toast }); |
|
|
|
|