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.

190 lines
5.1 KiB

8 years ago
/**
* 弹出层面板控制器, z-index在10w层级
*
* Created by GUY on 2015/6/24.
* @class
*/
import Controller from "./0.controller";
export default class LayerController extends Controller {
constructor() {
super();
this._constructor();
}
props = {
render: "body"
}
8 years ago
init() {
8 years ago
this.layerManager = {};
this.layouts = {};
this.zindex = BI.zIndex_layer;
}
_initResizer() {
this.resizer = BI.Resizers.add("layerController" + BI.uniqueId(), BI.bind(this._resize, this));
}
8 years ago
_resize() {
8 years ago
BI.each(this.layouts, function (i, layer) {
if (layer.element.is(":visible")) {
layer.element.trigger("__resize__");
}
7 years ago
});
}
8 years ago
make(name, container, op, context) {
7 years ago
if (BI.isWidget(container)) {
op = op || {};
op.container = container;
} else {
7 years ago
context = op;
7 years ago
op = container;
8 years ago
}
7 years ago
return this.create(name, null, op, context);
}
8 years ago
create(name, from, op, context) {
BI.isNull(this.resizer) && this._initResizer();
8 years ago
if (this.has(name)) {
return this.get(name);
}
op || (op = {});
const offset = op.offset || {};
let w = from;
8 years ago
if (BI.isWidget(from)) {
w = from.element;
}
if (BI.isNotEmptyString(w)) {
w = BI.Widget._renderEngine.createElement(w);
8 years ago
}
if (this.has(name)) {
return this.get(name);
}
const widget = BI.createWidget((op.render || {}), BI.extend({
7 years ago
type: "bi.layout"
}, op), context);
const layout = BI.createWidget({
8 years ago
type: "bi.absolute",
invisible: true,
items: [
{
el: widget,
left: 0,
right: 0,
top: 0,
bottom: 0
}
]
7 years ago
}, context);
8 years ago
BI.createWidget({
type: "bi.absolute",
element: op.container || this.options.render,
items: [
{
el: layout,
left: offset.left || 0,
right: offset.right || 0,
top: offset.top || 0,
bottom: offset.bottom || 0
}
]
8 years ago
});
if (w) {
8 years ago
layout.element.addClass("bi-popup-view");
function getComputedPosition() {
var css = {
8 years ago
left: w.offset().left + (offset.left || 0),
top: w.offset().top + (offset.top || 0),
7 years ago
width: offset.width || (w.outerWidth() - (offset.left || 0) - (offset.right || 0)) || "",
height: offset.height || (w.outerHeight() - (offset.top || 0) - (offset.bottom || 0)) || ""
};
const { top, left, scaleY, scaleX } = BI.DOM.getPositionRelativeContainingBlockRect(layout.element[0]);
css.top = (css.top - top) / scaleY;
css.left = (css.left - left) / scaleX;
return css;
}
layout.element.css(getComputedPosition());
layout.element.on("__resize__", function () {
w.is(":visible") &&
layout.element.css(getComputedPosition());
8 years ago
});
}
this.add(name, widget, layout);
return widget;
}
8 years ago
show(name, callback) {
8 years ago
if (!this.has(name)) {
return this;
}
4 years ago
this._getLayout(name).visible();
this._getLayout(name).element.css("z-index", this.zindex++).show(0, callback).trigger("__resize__");
8 years ago
return this;
}
8 years ago
hide(name, callback) {
8 years ago
if (!this.has(name)) {
return this;
}
4 years ago
this._getLayout(name).invisible();
this._getLayout(name).element.hide(0, callback);
8 years ago
return this;
}
8 years ago
isVisible(name) {
8 years ago
return this.has(name) && this._getLayout(name).isVisible();
}
8 years ago
add(name, layer, layout) {
8 years ago
if (this.has(name)) {
throw new Error("不能创建同名的Layer");
8 years ago
}
layout.setVisible(false);
this.layerManager[name] = layer;
this.layouts[name] = layout;
layout.element.css("z-index", this.zindex++);
8 years ago
return this;
}
8 years ago
_getLayout(name) {
8 years ago
return this.layouts[name];
}
8 years ago
get(name) {
8 years ago
return this.layerManager[name];
}
8 years ago
has(name) {
8 years ago
return this.layerManager[name] != null;
}
8 years ago
remove(name) {
8 years ago
if (!this.has(name)) {
return this;
}
this.layerManager[name].destroy();
this.layouts[name].destroy();
delete this.layerManager[name];
delete this.layouts[name];
return this;
}
removeAll() {
BI.each(BI.keys(this.layerManager), (index, name) => {
this.layerManager[name].destroy();
this.layouts[name].destroy();
});
this.layerManager = {};
this.layouts = {};
return this;
8 years ago
}
}