fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

172 lines
4.9 KiB

8 years ago
/**
* guy
7 years ago
* popover弹出层控制器, z-index在100w层级
* @class BI.popoverController
8 years ago
* @extends BI.Controller
*/
import { Controller } from "./0.controller";
export class PopoverController extends Controller {
constructor() {
super();
this._constructor();
this.modal = this.options.modal;
}
props = {
modal: true, // 模态窗口
render: "body"
}
8 years ago
init() {
8 years ago
this.floatManager = {};
this.floatLayer = {};
this.floatContainer = {};
8 years ago
this.floatOpened = {};
this.zindex = BI.zIndex_popover;
8 years ago
this.zindexMap = {};
}
8 years ago
create(name, options, context) {
4 years ago
if (this.has(name)) {
8 years ago
return this;
}
const popover = BI.createWidget(options || {}, {
7 years ago
type: "bi.popover"
7 years ago
}, context);
7 years ago
this.add(name, popover, options, context);
8 years ago
return this;
}
8 years ago
open(name) {
4 years ago
if (!this.has(name)) {
8 years ago
return this;
}
8 years ago
if (!this.floatOpened[name]) {
this.floatOpened[name] = true;
const container = this.floatContainer[name];
container.element.css("zIndex", this.zindex++);
8 years ago
this.modal && container.element.__hasZIndexMask__(this.zindexMap[name]) && container.element.__releaseZIndexMask__(this.zindexMap[name]);
this.zindexMap[name] = this.zindex;
this.modal && container.element.__buildZIndexMask__(this.zindex++);
this.get(name).setZindex(this.zindex++);
8 years ago
this.floatContainer[name].visible();
const popover = this.get(name);
7 years ago
popover.show && popover.show();
const W = BI.Widget._renderEngine.createElement(this.options.render).width(),
H = BI.Widget._renderEngine.createElement(this.options.render).height();
const w = popover.element.width(), h = popover.element.height();
let left = (W - w) / 2, top = (H - h) / 2;
8 years ago
if (left < 0) {
left = 0;
}
if (top < 0) {
top = 0;
}
7 years ago
popover.element.css({
// 这里直接用px就可以
left: left + "px",
top: top + "px"
8 years ago
});
8 years ago
}
return this;
}
8 years ago
close(name) {
4 years ago
if (!this.has(name)) {
8 years ago
return this;
}
8 years ago
if (this.floatOpened[name]) {
delete this.floatOpened[name];
8 years ago
this.floatContainer[name].invisible();
this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
}
8 years ago
return this;
}
8 years ago
show(name) {
4 years ago
return this.open(name);
}
4 years ago
hide(name) {
4 years ago
return this.close(name);
}
4 years ago
isVisible(name) {
4 years ago
return this.has(name) && this.floatOpened[name] === true;
}
4 years ago
add(name, popover, options, context) {
4 years ago
options || (options = {});
if (this.has(name)) {
return this;
}
this.floatContainer[name] = BI.createWidget({
type: "bi.absolute",
cls: "bi-popup-view",
items: [{
el: (this.floatLayer[name] = BI.createWidget({
type: "bi.absolute",
items: [popover]
}, context)),
left: 0,
right: 0,
top: 0,
bottom: 0
}]
});
this.floatManager[name] = popover;
popover.on(BI.Popover.EVENT_CLOSE, () => this.close(name));
4 years ago
BI.createWidget({
type: "bi.absolute",
element: options.container || this.options.render,
items: [{
el: this.floatContainer[name],
left: 0,
right: 0,
top: 0,
bottom: 0
}]
});
return this;
}
4 years ago
get(name) {
8 years ago
return this.floatManager[name];
}
8 years ago
has(name) {
4 years ago
return BI.isNotNull(this.floatManager[name]);
}
4 years ago
remove(name) {
if (!this.has(name)) {
8 years ago
return this;
}
this.floatContainer[name].destroy();
this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
delete this.floatManager[name];
delete this.floatLayer[name];
delete this.zindexMap[name];
delete this.floatContainer[name];
8 years ago
delete this.floatOpened[name];
8 years ago
return this;
}
removeAll() {
BI.each(this.floatContainer, (name, container) => {
container.destroy();
this.modal && this.floatContainer[name].element.__releaseZIndexMask__(this.zindexMap[name]);
});
this.floatManager = {};
this.floatLayer = {};
this.floatContainer = {};
this.floatOpened = {};
this.zindexMap = {};
return this;
}
_getZIndex() {
return this.zindex++;
8 years ago
}
}