Browse Source

chore: 优化一下

es6
guy 3 years ago
parent
commit
a2f4b00b6e
  1. 105
      src/base/layer/layer.popover.js

105
src/base/layer/layer.popover.js

@ -8,7 +8,7 @@ BI.Popover = BI.inherit(BI.Widget, {
SIZE: { SIZE: {
SMALL: "small", SMALL: "small",
NORMAL: "normal", NORMAL: "normal",
BIG: "big", BIG: "big"
}, },
MAX_HEIGHT: 600 MAX_HEIGHT: 600
}, },
@ -17,7 +17,7 @@ BI.Popover = BI.inherit(BI.Widget, {
baseCls: "bi-popover bi-card bi-border-radius", baseCls: "bi-popover bi-card bi-border-radius",
size: "normal", // small, normal, big size: "normal", // small, normal, big
logic: { logic: {
dynamic: false, dynamic: false
}, },
header: null, header: null,
headerHeight: 40, headerHeight: 40,
@ -30,7 +30,8 @@ BI.Popover = BI.inherit(BI.Widget, {
}, },
render: function () { render: function () {
var self = this; var o = this.options; var self = this;
var o = this.options;
var c = this._constant; var c = this._constant;
this.startX = 0; this.startX = 0;
this.startY = 0; this.startY = 0;
@ -42,11 +43,11 @@ BI.Popover = BI.inherit(BI.Widget, {
self.startY += deltaY; self.startY += deltaY;
self.element.css({ self.element.css({
left: BI.clamp(self.startX, 0, W - self.element.width()) + "px", left: BI.clamp(self.startX, 0, W - self.element.width()) + "px",
top: BI.clamp(self.startY, 0, H - self.element.height()) + "px", top: BI.clamp(self.startY, 0, H - self.element.height()) + "px"
}); });
// BI-12134 没有什么特别好的方法 // BI-12134 没有什么特别好的方法
BI.Resizers._resize({ BI.Resizers._resize({
target: self.element[0], target: self.element[0]
}); });
}, function () { }, function () {
self.tracker.releaseMouseMoves(); self.tracker.releaseMouseMoves();
@ -55,22 +56,27 @@ BI.Popover = BI.inherit(BI.Widget, {
el: { el: {
type: "bi.htape", type: "bi.htape",
cls: "bi-message-title bi-header-background", cls: "bi-message-title bi-header-background",
ref: function (_ref) {
self.dragger = _ref;
},
items: [{ items: [{
el: BI.isPlainObject(o.header) ? BI.extend({}, o.header, { el: {
extraCls: "bi-font-bold", type: "bi.absolute",
}) : { ref: function (_ref) {
type: "bi.label", self.dragger = _ref;
cls: "bi-font-bold", },
height: o.headerHeight, items: [{
text: o.header, el: BI.isPlainObject(o.header) ? BI.extend({}, o.header, {
title: o.header, extraCls: "bi-font-bold"
textAlign: "left", }) : {
}, type: "bi.label",
lgap: 20, cls: "bi-font-bold",
rgap: o.closable ? 0 : 20 height: o.headerHeight,
text: o.header,
title: o.header,
textAlign: "left"
},
left: 20,
right: o.closable ? 0 : 20
}]
}
}, o.closable ? { }, o.closable ? {
el: { el: {
type: "bi.icon_button", type: "bi.icon_button",
@ -78,13 +84,13 @@ BI.Popover = BI.inherit(BI.Widget, {
height: o.headerHeight, height: o.headerHeight,
handler: function () { handler: function () {
self.close(); self.close();
}, }
}, },
width: 56, width: 56
}: null], } : null],
height: o.headerHeight, height: o.headerHeight
}, },
height: o.headerHeight, height: o.headerHeight
}, o.logic.dynamic ? { }, o.logic.dynamic ? {
el: { el: {
type: "bi.vertical", type: "bi.vertical",
@ -95,14 +101,14 @@ BI.Popover = BI.inherit(BI.Widget, {
}, },
css: { css: {
"max-height": this._getSuitableBodyHeight(c.MAX_HEIGHT - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap), "max-height": this._getSuitableBodyHeight(c.MAX_HEIGHT - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap),
"min-height": this._getSuitableBodyHeight(size.height - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap), "min-height": this._getSuitableBodyHeight(size.height - o.headerHeight - (o.footer ? o.footerHeight : 0) - o.bodyTgap)
}, },
items: [{ items: [{
el: o.body, el: o.body
}], }]
}, },
hgap: o.bodyHgap, hgap: o.bodyHgap,
tgap: o.bodyTgap, tgap: o.bodyTgap
} : { } : {
el: { el: {
type: "bi.absolute", type: "bi.absolute",
@ -111,9 +117,9 @@ BI.Popover = BI.inherit(BI.Widget, {
left: o.bodyHgap, left: o.bodyHgap,
top: o.bodyTgap, top: o.bodyTgap,
right: o.bodyHgap, right: o.bodyHgap,
bottom: 0, bottom: 0
}], }]
}, }
}]; }];
if (o.footer) { if (o.footer) {
items.push({ items.push({
@ -124,30 +130,31 @@ BI.Popover = BI.inherit(BI.Widget, {
left: 20, left: 20,
top: 0, top: 0,
right: 20, right: 20,
bottom: 0, bottom: 0
}], }],
height: o.footerHeight, height: o.footerHeight
}, },
height: o.footerHeight, height: o.footerHeight
}); });
} }
return BI.extend({ return BI.extend({
type: o.logic.dynamic ? "bi.vertical" : "bi.vtape", type: o.logic.dynamic ? "bi.vertical" : "bi.vtape",
items: items, items: items,
width: this._getSuitableWidth(size.width), width: this._getSuitableWidth(size.width)
}, o.logic.dynamic ? { }, o.logic.dynamic ? {
type: "bi.vertical", type: "bi.vertical",
scrolly: false, scrolly: false
} : { } : {
type: "bi.vtape", type: "bi.vtape",
height: this._getSuitableHeight(size.height), height: this._getSuitableHeight(size.height)
}); });
}, },
// mounted之后绑定事件 // mounted之后绑定事件
mounted: function () { mounted: function () {
var self = this; var o = this.options; var self = this;
var o = this.options;
this.dragger.element.mousedown(function (e) { this.dragger.element.mousedown(function (e) {
var pos = self.element.offset(); var pos = self.element.offset();
self.startX = pos.left; self.startX = pos.left;
@ -195,7 +202,7 @@ BI.Popover = BI.inherit(BI.Widget, {
return { return {
width: o.width || size.width, width: o.width || size.width,
height: o.height || size.height, height: o.height || size.height,
type: size.type || "default", type: size.type || "default"
}; };
}, },
@ -214,10 +221,11 @@ BI.Popover = BI.inherit(BI.Widget, {
}, },
setZindex: function (zindex) { setZindex: function (zindex) {
this.element.css({ "z-index": zindex }); this.element.css({"z-index": zindex});
}, },
destroyed: function () {}, destroyed: function () {
}
}); });
BI.shortcut("bi.popover", BI.Popover); BI.shortcut("bi.popover", BI.Popover);
@ -225,12 +233,13 @@ BI.shortcut("bi.popover", BI.Popover);
BI.BarPopover = BI.inherit(BI.Popover, { BI.BarPopover = BI.inherit(BI.Popover, {
_defaultConfig: function () { _defaultConfig: function () {
return BI.extend(BI.BarPopover.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.BarPopover.superclass._defaultConfig.apply(this, arguments), {
btns: [BI.i18nText("BI-Basic_Sure"), BI.i18nText("BI-Basic_Cancel")], btns: [BI.i18nText("BI-Basic_Sure"), BI.i18nText("BI-Basic_Cancel")]
}); });
}, },
beforeCreate: function () { beforeCreate: function () {
var self = this; var o = this.options; var self = this;
var o = this.options;
o.footer || (o.footer = { o.footer || (o.footer = {
type: "bi.right_vertical_adapt", type: "bi.right_vertical_adapt",
lgap: 10, lgap: 10,
@ -242,7 +251,7 @@ BI.BarPopover = BI.inherit(BI.Popover, {
handler: function (v) { handler: function (v) {
self.fireEvent(BI.Popover.EVENT_CANCEL, v); self.fireEvent(BI.Popover.EVENT_CANCEL, v);
self.close(v); self.close(v);
}, }
}, { }, {
type: "bi.button", type: "bi.button",
text: this.options.btns[0], text: this.options.btns[0],
@ -251,10 +260,10 @@ BI.BarPopover = BI.inherit(BI.Popover, {
handler: function (v) { handler: function (v) {
self.fireEvent(BI.Popover.EVENT_CONFIRM, v); self.fireEvent(BI.Popover.EVENT_CONFIRM, v);
self.close(v); self.close(v);
}, }
}], }]
}); });
}, }
}); });
BI.shortcut("bi.bar_popover", BI.BarPopover); BI.shortcut("bi.bar_popover", BI.BarPopover);

Loading…
Cancel
Save