Browse Source

KERNEL-14035 refactor: layout相关es6

es6
Zhenfei.Li 2 years ago
parent
commit
5376192e59
  1. 3
      src/core/index.js
  2. 2
      src/core/wrapper/index.js
  3. 672
      src/core/wrapper/layout.js
  4. 51
      src/core/wrapper/layout/adapt/absolute.center.js
  5. 50
      src/core/wrapper/layout/adapt/absolute.horizontal.js
  6. 160
      src/core/wrapper/layout/adapt/absolute.leftrightvertical.js
  7. 48
      src/core/wrapper/layout/adapt/absolute.vertical.js
  8. 51
      src/core/wrapper/layout/adapt/adapt.center.js
  9. 11
      src/core/wrapper/layout/adapt/adapt.horizontal.js
  10. 177
      src/core/wrapper/layout/adapt/adapt.leftrightvertical.js
  11. 101
      src/core/wrapper/layout/adapt/adapt.table.js
  12. 47
      src/core/wrapper/layout/adapt/adapt.vertical.js
  13. 50
      src/core/wrapper/layout/adapt/auto.horizontal.js
  14. 13
      src/core/wrapper/layout/adapt/index.js
  15. 47
      src/core/wrapper/layout/adapt/inline.center.js
  16. 47
      src/core/wrapper/layout/adapt/inline.horizontal.js
  17. 47
      src/core/wrapper/layout/adapt/inline.vertical.js
  18. 17
      src/core/wrapper/layout/index.js
  19. 104
      src/core/wrapper/layout/layout.absolute.js
  20. 67
      src/core/wrapper/layout/layout.adaptive.js
  21. 102
      src/core/wrapper/layout/layout.border.js
  22. 215
      src/core/wrapper/layout/layout.card.js
  23. 48
      src/core/wrapper/layout/layout.default.js
  24. 122
      src/core/wrapper/layout/layout.division.js
  25. 181
      src/core/wrapper/layout/layout.flow.js
  26. 106
      src/core/wrapper/layout/layout.grid.js
  27. 14
      src/core/wrapper/layout/layout.horizontal.js
  28. 91
      src/core/wrapper/layout/layout.inline.js
  29. 55
      src/core/wrapper/layout/layout.lattice.js
  30. 85
      src/core/wrapper/layout/layout.table.js
  31. 246
      src/core/wrapper/layout/layout.tape.js
  32. 132
      src/core/wrapper/layout/layout.td.js
  33. 63
      src/core/wrapper/layout/layout.vertical.js
  34. 153
      src/core/wrapper/layout/layout.window.js

3
src/core/index.js

@ -16,6 +16,7 @@ import * as constant from "./constant";
import * as logic from "./logic"; import * as logic from "./logic";
import { Element } from "./element"; import { Element } from "./element";
import * as utils from "./utils"; import * as utils from "./utils";
import * as wrapper from "./wrapper";
export * from "./decorator"; export * from "./decorator";
export * from "./2.base"; export * from "./2.base";
@ -31,6 +32,7 @@ export * from "./h";
export * from "./constant"; export * from "./constant";
export * from "./logic"; export * from "./logic";
export * from "./utils"; export * from "./utils";
export * from "./wrapper";
export { export {
StyleLoaderManager, StyleLoaderManager,
@ -60,4 +62,5 @@ Object.assign(BI, {
useInWorker, useInWorker,
...h, ...h,
...utils, ...utils,
...wrapper,
}); });

2
src/core/wrapper/index.js

@ -0,0 +1,2 @@
export { Layout } from "./layout";
export * from "./layout/index";

672
src/core/wrapper/layout.js

File diff suppressed because it is too large Load Diff

51
src/core/wrapper/layout/adapt/absolute.center.js

@ -1,47 +1,54 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { extend, isFunction } from "../../../2.base";
/** /**
* absolute实现的居中布局 * absolute实现的居中布局
* @class BI.AbsoluteCenterLayout * @class AbsoluteCenterLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.AbsoluteCenterLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class AbsoluteCenterLayout extends Layout {
return BI.extend(BI.AbsoluteCenterLayout.superclass.props.apply(this, arguments), { static xtype ="bi.absolute_center_adapt";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-abs-c-a", baseCls: "bi-abs-c-a",
hgap: 0, hgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
vgap: 0, vgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render: function () { render() {
BI.AbsoluteCenterLayout.superclass.render.apply(this, arguments); super.render(...arguments);
var self = this, o = this.options; const o = this.options;
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (i, item) { _addElement(i, item) {
var o = this.options; const o = this.options;
var w = BI.AbsoluteCenterLayout.superclass._addElement.apply(this, arguments); const w = super._addElement(...arguments);
w.element.css({ w.element.css({
position: "absolute", position: "absolute",
left: this._optimiseGap(o.hgap + o.lgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item)), left: this._optimiseGap(o.hgap + o.lgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item)),
right: this._optimiseGap(o.hgap + o.rgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item)), right: this._optimiseGap(o.hgap + o.rgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item)),
top: this._optimiseGap(o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item)), top: this._optimiseGap(o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item)),
bottom: this._optimiseGap(o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item)), bottom: this._optimiseGap(o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item)),
margin: "auto" margin: "auto",
}); });
return w; return w;
}, }
populate: function (items) { populate(...args) {
BI.AbsoluteCenterLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.absolute_center_adapt", BI.AbsoluteCenterLayout);

50
src/core/wrapper/layout/adapt/absolute.horizontal.js

@ -1,26 +1,35 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { extend } from "../../../2.base";
import { HorizontalAlign } from "../../../constant";
/** /**
* absolute实现的居中布局 * absolute实现的水平布局
* @class BI.AbsoluteHorizontalLayout * @class AbsoluteHorizontalLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.AbsoluteHorizontalLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class AbsoluteHorizontalLayout extends Layout {
return BI.extend(BI.AbsoluteHorizontalLayout.superclass.props.apply(this, arguments), { static xtype = "bi.absolute_horizontal_adapt";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-abs-h-a", baseCls: "bi-abs-h-a",
horizontalAlign: BI.HorizontalAlign.Center, horizontalAlign: HorizontalAlign.Center,
rowSize: [], rowSize: [],
hgap: 0, hgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
vgap: 0, vgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render() {
const o = this.options;
super.render(...arguments);
render: function () {
var self = this, o = this.options;
BI.AbsoluteHorizontalLayout.superclass.render.apply(this, arguments);
return { return {
type: "bi.vtape", type: "bi.vtape",
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
@ -29,8 +38,8 @@ BI.AbsoluteHorizontalLayout = BI.inherit(BI.Layout, {
scrollx: o.scrollx, scrollx: o.scrollx,
scrolly: o.scrolly, scrolly: o.scrolly,
scrollable: o.scrollable, scrollable: o.scrollable,
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
hgap: o.hgap, hgap: o.hgap,
vgap: o.vgap, vgap: o.vgap,
@ -41,14 +50,13 @@ BI.AbsoluteHorizontalLayout = BI.inherit(BI.Layout, {
innerHgap: o.innerHgap, innerHgap: o.innerHgap,
innerVgap: o.innerVgap, innerVgap: o.innerVgap,
}; };
}, }
resize: function () { resize() {
this.layout.resize(); this.layout.resize();
}, }
populate: function (items) { populate(...args) {
this.layout.populate.apply(this, arguments); this.layout.populate(...args);
}
} }
});
BI.shortcut("bi.absolute_horizontal_adapt", BI.AbsoluteHorizontalLayout);

160
src/core/wrapper/layout/adapt/absolute.leftrightvertical.js

@ -1,8 +1,16 @@
BI.AbsoluteLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { import { shortcut } from "../../../decorator";
props: function () { import { Layout } from "../../layout";
return BI.extend(BI.AbsoluteLeftRightVerticalAdaptLayout.superclass.props.apply(this, arguments), { import { extend, isArray, each, map, stripEL } from "../../../2.base";
import { VerticalAlign } from "../../../constant";
@shortcut()
export class AbsoluteLeftRightVerticalAdaptLayout extends Layout {
static xtype = "bi.absolute_left_right_vertical_adapt";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-abs-lr-v-a", baseCls: "bi-abs-lr-v-a",
verticalAlign: BI.VerticalAlign.Middle, verticalAlign: VerticalAlign.Middle,
items: {}, items: {},
llgap: 0, llgap: 0,
lrgap: 0, lrgap: 0,
@ -15,32 +23,34 @@ BI.AbsoluteLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, {
rhgap: 0, rhgap: 0,
rtgap: 0, rtgap: 0,
rbgap: 0, rbgap: 0,
rvgap: 0 rvgap: 0,
}); });
}, }
render: function () {
var o = this.options, self = this; render() {
BI.AbsoluteLeftRightVerticalAdaptLayout.superclass.render.apply(this, arguments); const o = this.options;
super.render(...arguments);
return { return {
type: "bi.htape", type: "bi.htape",
innerHgap: o.innerHgap, innerHgap: o.innerHgap,
innerVgap: o.innerVgap, innerVgap: o.innerVgap,
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
verticalAlign: o.verticalAlign, verticalAlign: o.verticalAlign,
items: this._formatItems(o.items), items: this._formatItems(o.items),
scrollx: o.scrollx, scrollx: o.scrollx,
scrolly: o.scrolly, scrolly: o.scrolly,
scrollable: o.scrollable scrollable: o.scrollable,
}; };
}, }
_formatItems: function (items) { _formatItems(items) {
var self = this, o = this.options; const o = this.options;
var left, right; let left, right;
if (BI.isArray(items)) { if (isArray(items)) {
BI.each(items, function (i, item) { each(items, (i, item) => {
if (item.left) { if (item.left) {
left = item.left; left = item.left;
} }
@ -49,85 +59,92 @@ BI.AbsoluteLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, {
} }
}); });
} }
var leftItems = left || items.left || []; let leftItems = left || items.left || [];
var rightItems = right || items.right || []; let rightItems = right || items.right || [];
leftItems = BI.map(leftItems, function (i, item) { leftItems = map(leftItems, (i, item) => {
var json = { const json = {
el: BI.stripEL(item), el: stripEL(item),
width: item.width width: item.width,
}; };
if (o.lvgap + o.ltgap + self._optimiseItemTgap(item) + self._optimiseItemVgap(item) !== 0) { if (o.lvgap + o.ltgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item) !== 0) {
json.tgap = o.lvgap + o.ltgap + self._optimiseItemTgap(item) + self._optimiseItemVgap(item); json.tgap = o.lvgap + o.ltgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item);
} }
if (o.lhgap + o.llgap + self._optimiseItemLgap(item) + self._optimiseItemHgap(item) !== 0) { if (o.lhgap + o.llgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item) !== 0) {
json.lgap = (i === 0 ? o.lhgap : 0) + o.llgap + self._optimiseItemLgap(item) + self._optimiseItemHgap(item); json.lgap = (i === 0 ? o.lhgap : 0) + o.llgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item);
} }
if (o.lhgap + o.lrgap + self._optimiseItemRgap(item) + self._optimiseItemHgap(item) !== 0) { if (o.lhgap + o.lrgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item) !== 0) {
json.rgap = o.lhgap + o.lrgap + self._optimiseItemRgap(item) + self._optimiseItemHgap(item); json.rgap = o.lhgap + o.lrgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item);
} }
if (o.lvgap + o.lbgap + self._optimiseItemBgap(item) + self._optimiseItemVgap(item) !== 0) { if (o.lvgap + o.lbgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item) !== 0) {
json.bgap = o.lvgap + o.lbgap + self._optimiseItemBgap(item) + self._optimiseItemVgap(item); json.bgap = o.lvgap + o.lbgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item);
} }
return json; return json;
}); });
rightItems = BI.map(rightItems, function (i, item) { rightItems = map(rightItems, (i, item) => {
var json = { const json = {
el: BI.stripEL(item), el: stripEL(item),
width: item.width width: item.width,
}; };
if (o.rvgap + o.rtgap + self._optimiseItemTgap(item) + self._optimiseItemVgap(item) !== 0) { if (o.rvgap + o.rtgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item) !== 0) {
json.tgap = o.rvgap + o.rtgap + self._optimiseItemTgap(item) + self._optimiseItemVgap(item); json.tgap = o.rvgap + o.rtgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item);
} }
if (o.rhgap + o.rlgap + self._optimiseItemLgap(item) + self._optimiseItemHgap(item) !== 0) { if (o.rhgap + o.rlgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item) !== 0) {
json.lgap = (i === 0 ? o.rhgap : 0) + o.rlgap + self._optimiseItemLgap(item) + self._optimiseItemHgap(item); json.lgap = (i === 0 ? o.rhgap : 0) + o.rlgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item);
} }
if (o.rhgap + o.rrgap + self._optimiseItemRgap(item) + self._optimiseItemHgap(item) !== 0) { if (o.rhgap + o.rrgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item) !== 0) {
json.rgap = o.rhgap + o.rrgap + self._optimiseItemRgap(item) + self._optimiseItemHgap(item); json.rgap = o.rhgap + o.rrgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item);
} }
if (o.rvgap + o.rbgap + self._optimiseItemBgap(item) + self._optimiseItemVgap(item) !== 0) { if (o.rvgap + o.rbgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item) !== 0) {
json.bgap = o.rvgap + o.rbgap + self._optimiseItemBgap(item) + self._optimiseItemVgap(item); json.bgap = o.rvgap + o.rbgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item);
} }
return json; return json;
}); });
return leftItems.concat({}, rightItems); return leftItems.concat({}, rightItems);
}, }
resize: function () { resize() {
this.layout.stroke(this._formatItems(this.options.items)); this.layout.stroke(this._formatItems(this.options.items));
}, }
addItem: function () { addItem() {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
populate: function (items) { populate(items) {
this.layout.populate(this._formatItems(items)); this.layout.populate(this._formatItems(items));
} }
}); }
BI.shortcut("bi.absolute_left_right_vertical_adapt", BI.AbsoluteLeftRightVerticalAdaptLayout);
@shortcut()
export class AbsoluteRightVerticalAdaptLayout extends Layout {
static xtype = "bi.absolute_right_vertical_adapt";
BI.AbsoluteRightVerticalAdaptLayout = BI.inherit(BI.Layout, { props () {
props: function () { return extend(super.props(...arguments), {
return BI.extend(BI.AbsoluteRightVerticalAdaptLayout.superclass.props.apply(this, arguments), {
baseCls: "bi-abs-r-v-a", baseCls: "bi-abs-r-v-a",
verticalAlign: BI.VerticalAlign.Middle, verticalAlign: VerticalAlign.Middle,
items: [], items: [],
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
hgap: 0, hgap: 0,
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
vgap: 0 vgap: 0,
}); });
}, }
render: function () {
var o = this.options, self = this; render () {
BI.AbsoluteRightVerticalAdaptLayout.superclass.render.apply(this, arguments); const o = this.options;
super.render(...arguments);
return { return {
type: "bi.htape", type: "bi.htape",
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
verticalAlign: o.verticalAlign, verticalAlign: o.verticalAlign,
items: [{}].concat(o.items), items: [{}].concat(o.items),
@ -139,21 +156,20 @@ BI.AbsoluteRightVerticalAdaptLayout = BI.inherit(BI.Layout, {
vgap: o.vgap, vgap: o.vgap,
scrollx: o.scrollx, scrollx: o.scrollx,
scrolly: o.scrolly, scrolly: o.scrolly,
scrollable: o.scrollable scrollable: o.scrollable,
}; };
}, }
resize: function () { resize () {
this.layout.stroke([{}].concat(this.options.items)); this.layout.stroke([{}].concat(this.options.items));
}, }
addItem: function () { addItem () {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
populate: function (items) { populate (items) {
this.layout.populate([{}].concat(items)); this.layout.populate([{}].concat(items));
} }
}); }
BI.shortcut("bi.absolute_right_vertical_adapt", BI.AbsoluteRightVerticalAdaptLayout);

48
src/core/wrapper/layout/adapt/absolute.vertical.js

@ -1,26 +1,35 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { extend } from "../../../2.base";
import { VerticalAlign } from "../../../constant";
/** /**
* absolute实现的居中布局 * absolute实现的居中布局
* @class BI.AbsoluteVerticalLayout * @class AbsoluteVerticalLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.AbsoluteVerticalLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class AbsoluteVerticalLayout extends Layout {
return BI.extend(BI.AbsoluteVerticalLayout.superclass.props.apply(this, arguments), { static xtype = "bi.absolute_vertical_adapt";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-abs-v-a", baseCls: "bi-abs-v-a",
verticalAlign: BI.VerticalAlign.Middle, verticalAlign: VerticalAlign.Middle,
columnSize: [], columnSize: [],
hgap: 0, hgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
vgap: 0, vgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render() {
const o = this.options;
super.render(...arguments);
render: function () {
var self = this, o = this.options;
BI.AbsoluteVerticalLayout.superclass.render.apply(this, arguments);
return { return {
type: "bi.htape", type: "bi.htape",
verticalAlign: o.verticalAlign, verticalAlign: o.verticalAlign,
@ -29,8 +38,8 @@ BI.AbsoluteVerticalLayout = BI.inherit(BI.Layout, {
scrollx: o.scrollx, scrollx: o.scrollx,
scrolly: o.scrolly, scrolly: o.scrolly,
scrollable: o.scrollable, scrollable: o.scrollable,
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
hgap: o.hgap, hgap: o.hgap,
vgap: o.vgap, vgap: o.vgap,
@ -41,14 +50,13 @@ BI.AbsoluteVerticalLayout = BI.inherit(BI.Layout, {
innerHgap: o.innerHgap, innerHgap: o.innerHgap,
innerVgap: o.innerVgap, innerVgap: o.innerVgap,
}; };
}, }
resize: function () { resize() {
this.layout.resize(); this.layout.resize();
}, }
populate: function (items) { populate(...args) {
this.layout.populate.apply(this, arguments); this.layout.populate(...args);
}
} }
});
BI.shortcut("bi.absolute_vertical_adapt", BI.AbsoluteVerticalLayout);

51
src/core/wrapper/layout/adapt/adapt.center.js

@ -1,13 +1,21 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { extend } from "../../../2.base";
import { HorizontalAlign, VerticalAlign } from "../../../constant";
/** /**
* 自适应水平和垂直方向都居中容器 * 自适应水平和垂直方向都居中容器
* @class BI.CenterAdaptLayout * @class CenterAdaptLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.CenterAdaptLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class CenterAdaptLayout extends Layout {
return BI.extend(BI.CenterAdaptLayout.superclass.props.apply(this, arguments), { static xtype = "bi.center_adapt";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-c-a", baseCls: "bi-c-a",
horizontalAlign: BI.HorizontalAlign.Center, horizontalAlign: HorizontalAlign.Center,
columnSize: [], columnSize: [],
scrollx: false, scrollx: false,
hgap: 0, hgap: 0,
@ -15,23 +23,25 @@ BI.CenterAdaptLayout = BI.inherit(BI.Layout, {
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render: function () {
var o = this.options, self = this; render() {
BI.CenterAdaptLayout.superclass.render.apply(this, arguments); const o = this.options;
super.render(...arguments);
return { return {
type: "bi.horizontal", type: "bi.horizontal",
verticalAlign: BI.VerticalAlign.Middle, verticalAlign: VerticalAlign.Middle,
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
columnSize: o.columnSize, columnSize: o.columnSize,
scrollx: o.scrollx, scrollx: o.scrollx,
scrolly: o.scrolly, scrolly: o.scrolly,
scrollable: o.scrollable, scrollable: o.scrollable,
items: o.items, items: o.items,
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
hgap: o.hgap, hgap: o.hgap,
vgap: o.vgap, vgap: o.vgap,
@ -42,14 +52,13 @@ BI.CenterAdaptLayout = BI.inherit(BI.Layout, {
innerHgap: o.innerHgap, innerHgap: o.innerHgap,
innerVgap: o.innerVgap, innerVgap: o.innerVgap,
}; };
}, }
resize: function () { resize() {
this.layout.resize(); this.layout.resize();
}, }
populate: function (items) { populate(...args) {
this.layout.populate.apply(this, arguments); this.layout.populate(...args);
}
} }
});
BI.shortcut("bi.center_adapt", BI.CenterAdaptLayout);

11
src/core/wrapper/layout/adapt/adapt.horizontal.js

@ -1,8 +1,9 @@
import { shortcut } from "../../../decorator";
/** /**
* 水平方向居中容器 * 水平方向居中容器
* @class BI.HorizontalAdaptLayout
* @extends BI.Layout
*/ */
BI.HorizontalAdaptLayout = function () { @shortcut()
}; export class HorizontalAdaptLayout {
BI.shortcut("bi.horizontal_adapt", BI.HorizontalAdaptLayout); static xtype = "bi.horizontal_adapt";
}

177
src/core/wrapper/layout/adapt/adapt.leftrightvertical.js

@ -1,15 +1,23 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { extend, isArray, each } from "../../../2.base";
import { HorizontalAlign } from "../../../constant";
/** /**
* 左右分离垂直方向居中容器 * 左右分离垂直方向居中容器
* items:{ * items:{
left: [{el:{type:"bi.button"}}], left: [{el:{type:"bi.button"}}],
right:[{el:{type:"bi.button"}}] right:[{el:{type:"bi.button"}}]
} }
* @class BI.LeftRightVerticalAdaptLayout * @class LeftRightVerticalAdaptLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class LeftRightVerticalAdaptLayout extends Layout {
return BI.extend(BI.LeftRightVerticalAdaptLayout.superclass.props.apply(this, arguments), { static xtype = "bi.left_right_vertical_adapt";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-lr-v-a", baseCls: "bi-lr-v-a",
items: {}, items: {},
llgap: 0, llgap: 0,
@ -23,14 +31,15 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, {
rhgap: 0, rhgap: 0,
rtgap: 0, rtgap: 0,
rbgap: 0, rbgap: 0,
rvgap: 0 rvgap: 0,
}); });
}, }
render: function () {
var o = this.options, self = this; render() {
BI.LeftRightVerticalAdaptLayout.superclass.render.apply(this, arguments); const o = this.options;
var leftRight = this._getLeftRight(o.items); super.render(...arguments);
var layoutArray = []; const leftRight = this._getLeftRight(o.items);
const layoutArray = [];
if (leftRight.left || "left" in o.items) { if (leftRight.left || "left" in o.items) {
layoutArray.push({ layoutArray.push({
type: "bi.left", type: "bi.left",
@ -39,8 +48,8 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, {
items: [{ items: [{
el: { el: {
type: "bi.vertical_adapt", type: "bi.vertical_adapt",
ref: function (_ref) { ref: _ref => {
self.left = _ref; this.left = _ref;
}, },
height: "100%", height: "100%",
items: leftRight.left || o.items.left, items: leftRight.left || o.items.left,
@ -49,9 +58,9 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, {
rgap: o.lrgap, rgap: o.lrgap,
tgap: o.ltgap, tgap: o.ltgap,
bgap: o.lbgap, bgap: o.lbgap,
vgap: o.lvgap vgap: o.lvgap,
} },
}] }],
}); });
} }
if (leftRight.right || "right" in o.items) { if (leftRight.right || "right" in o.items) {
@ -62,8 +71,8 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, {
items: [{ items: [{
el: { el: {
type: "bi.vertical_adapt", type: "bi.vertical_adapt",
ref: function (_ref) { ref: _ref => {
self.right = _ref; this.right = _ref;
}, },
height: "100%", height: "100%",
items: leftRight.right || o.items.right, items: leftRight.right || o.items.right,
@ -72,18 +81,19 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, {
rgap: o.rrgap, rgap: o.rrgap,
tgap: o.rtgap, tgap: o.rtgap,
bgap: o.rbgap, bgap: o.rbgap,
vgap: o.rvgap vgap: o.rvgap,
} },
}] }],
}); });
} }
return layoutArray; return layoutArray;
}, }
_getLeftRight: function (items) { _getLeftRight(items) {
var left, right; let left, right;
if (BI.isArray(items)) { if (isArray(items)) {
BI.each(items, function (i, item) { each(items, (i, item) => {
if (item.left) { if (item.left) {
left = item.left; left = item.left;
} }
@ -92,35 +102,37 @@ BI.LeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, {
} }
}); });
} }
return { return {
left: left, left,
right: right right,
}; };
}, }
resize: function () { resize() {
var leftRight = this._getLeftRight(this.options.items); const leftRight = this._getLeftRight(this.options.items);
this.left.stroke(leftRight.left || this.options.items.left); this.left.stroke(leftRight.left || this.options.items.left);
this.right.stroke(leftRight.right || this.options.items.right); this.right.stroke(leftRight.right || this.options.items.right);
}, }
addItem: function () { addItem() {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
populate: function (items) { populate(items) {
var leftRight = this._getLeftRight(items); const leftRight = this._getLeftRight(items);
this.left.populate(leftRight.left || items.left); this.left.populate(leftRight.left || items.left);
this.right.populate(leftRight.right || items.right); this.right.populate(leftRight.right || items.right);
} }
}); }
BI.shortcut("bi.left_right_vertical_adapt", BI.LeftRightVerticalAdaptLayout);
@shortcut()
export class LeftVerticalAdaptLayout extends Layout {
static xtype = "bi.left_vertical_adapt";
BI.LeftVerticalAdaptLayout = BI.inherit(BI.Layout, { props() {
props: function () { return extend(super.props(...arguments), {
return BI.extend(BI.LeftRightVerticalAdaptLayout.superclass.props.apply(this, arguments), {
baseCls: "bi-l-v-a", baseCls: "bi-l-v-a",
items: [], items: [],
columnSize: [], columnSize: [],
@ -129,16 +141,18 @@ BI.LeftVerticalAdaptLayout = BI.inherit(BI.Layout, {
hgap: 0, hgap: 0,
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
vgap: 0 vgap: 0,
}); });
}, }
render: function () {
var o = this.options, self = this; render() {
BI.LeftVerticalAdaptLayout.superclass.render.apply(this, arguments); const o = this.options;
super.render(...arguments);
return { return {
type: "bi.vertical_adapt", type: "bi.vertical_adapt",
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
items: o.items, items: o.items,
columnSize: o.columnSize, columnSize: o.columnSize,
@ -152,28 +166,30 @@ BI.LeftVerticalAdaptLayout = BI.inherit(BI.Layout, {
innerVgap: o.innerVgap, innerVgap: o.innerVgap,
scrollx: o.scrollx, scrollx: o.scrollx,
scrolly: o.scrolly, scrolly: o.scrolly,
scrollable: o.scrollable scrollable: o.scrollable,
}; };
}, }
resize: function () { resize() {
this.layout.resize(); this.layout.resize();
}, }
addItem: function () { addItem() {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
populate: function (items) { populate(items) {
this.layout.populate.apply(this, arguments); this.layout.populate(...arguments);
} }
}); }
BI.shortcut("bi.left_vertical_adapt", BI.LeftVerticalAdaptLayout);
@shortcut()
export class RightVerticalAdaptLayout extends Layout {
static xtype = "bi.right_vertical_adapt";
BI.RightVerticalAdaptLayout = BI.inherit(BI.Layout, { props() {
props: function () { return extend(super.props(...arguments), {
return BI.extend(BI.RightVerticalAdaptLayout.superclass.props.apply(this, arguments), {
baseCls: "bi-r-v-a", baseCls: "bi-r-v-a",
items: [], items: [],
columnSize: [], columnSize: [],
@ -182,18 +198,20 @@ BI.RightVerticalAdaptLayout = BI.inherit(BI.Layout, {
hgap: 0, hgap: 0,
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
vgap: 0 vgap: 0,
}); });
}, }
render: function () {
var o = this.options, self = this; render() {
BI.RightVerticalAdaptLayout.superclass.render.apply(this, arguments); const o = this.options;
super.render(...arguments);
return { return {
type: "bi.vertical_adapt", type: "bi.vertical_adapt",
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
horizontalAlign: BI.HorizontalAlign.Right, horizontalAlign: HorizontalAlign.Right,
items: o.items, items: o.items,
columnSize: o.columnSize, columnSize: o.columnSize,
hgap: o.hgap, hgap: o.hgap,
@ -206,21 +224,20 @@ BI.RightVerticalAdaptLayout = BI.inherit(BI.Layout, {
innerVgap: o.innerVgap, innerVgap: o.innerVgap,
scrollx: o.scrollx, scrollx: o.scrollx,
scrolly: o.scrolly, scrolly: o.scrolly,
scrollable: o.scrollable scrollable: o.scrollable,
}; };
}, }
resize: function () { resize() {
this.layout.resize(); this.layout.resize();
}, }
addItem: function () { addItem() {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
populate: function (items) { populate(...args) {
this.layout.populate(items); this.layout.populate(...args);
}
} }
});
BI.shortcut("bi.right_vertical_adapt", BI.RightVerticalAdaptLayout);

101
src/core/wrapper/layout/adapt/adapt.table.js

@ -1,78 +1,91 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { extend, isFunction, some, isNull } from "../../../2.base";
import { Widget } from "../../../4.widget";
import { _lazyCreateWidget } from "../../../5.inject";
import { HorizontalAlign, VerticalAlign } from "../../../constant";
/** /**
* 使用display:table和display:table-cell实现的horizontal布局 * 使用display:table和display:table-cell实现的horizontal布局
* @class BI.TableAdaptLayout * @class TableAdaptLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.TableAdaptLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class TableAdaptLayout extends Layout {
return BI.extend(BI.TableAdaptLayout.superclass.props.apply(this, arguments), { static xtype = "bi.table_adapt";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-t-a", baseCls: "bi-t-a",
columnSize: [], columnSize: [],
verticalAlign: BI.VerticalAlign.Top, verticalAlign: VerticalAlign.Top,
horizontalAlign: BI.HorizontalAlign.Left, horizontalAlign: HorizontalAlign.Left,
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render: function () {
BI.TableAdaptLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
this.$table = BI.Widget._renderEngine.createElement("<div>").css({ const o = this.options;
this.$table = Widget._renderEngine.createElement("<div>").css({
position: "relative", position: "relative",
display: "table", display: "table",
width: (o.horizontalAlign === BI.HorizontalAlign.Center || o.horizontalAlign === BI.HorizontalAlign.Stretch || this._hasFill()) ? "100%" : "auto", width: (o.horizontalAlign === HorizontalAlign.Center || o.horizontalAlign === HorizontalAlign.Stretch || this._hasFill()) ? "100%" : "auto",
height: (o.verticalAlign !== BI.VerticalAlign.Top) ? "100%" : "auto", height: (o.verticalAlign !== VerticalAlign.Top) ? "100%" : "auto",
"white-space": "nowrap" "white-space": "nowrap",
}); });
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_hasFill: function () { _hasFill() {
var o = this.options; const o = this.options;
if (o.columnSize.length > 0) { if (o.columnSize.length > 0) {
return o.columnSize.indexOf("fill") >= 0; return o.columnSize.indexOf("fill") >= 0;
} }
return BI.some(o.items, function (i, item) {
return some(o.items, (i, item) => {
if (item.width === "fill") { if (item.width === "fill") {
return true; return true;
} }
}); });
}, }
_addElement: function (i, item) { _addElement(i, item) {
var o = this.options; const o = this.options;
var td, width = ""; let td, width = "";
var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width; let w;
const columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width;
if (columnSize > 0) { if (columnSize > 0) {
width = this._optimiseGap(columnSize + (i === 0 ? o.hgap : 0) + o.hgap + o.lgap + o.rgap); width = this._optimiseGap(columnSize + (i === 0 ? o.hgap : 0) + o.hgap + o.lgap + o.rgap);
} }
if ((BI.isNull(columnSize) || columnSize === "") && this._hasFill()) { if ((isNull(columnSize) || columnSize === "") && this._hasFill()) {
width = 2; width = 2;
} }
if (!this.hasWidget(this._getChildName(i))) { if (!this.hasWidget(this._getChildName(i))) {
var w = BI._lazyCreateWidget(item); w = _lazyCreateWidget(item);
w.element.css({ position: "relative", top: "0", left: "0", margin: "0px auto" }); w.element.css({ position: "relative", top: "0", left: "0", margin: "0px auto" });
td = BI._lazyCreateWidget({ td = _lazyCreateWidget({
type: "bi.default", type: "bi.default",
width: width, width,
items: [w] items: [w],
}); });
this.addWidget(this._getChildName(i), td); this.addWidget(this._getChildName(i), td);
} else { } else {
td = this.getWidgetByName(this._getChildName(i)); td = this.getWidgetByName(this._getChildName(i));
td.element.width(width); td.element.width(width);
} }
if (o.verticalAlign === BI.VerticalAlign.Stretch) { if (o.verticalAlign === VerticalAlign.Stretch) {
var top = o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item), const top = o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item),
bottom = o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item); bottom = o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item);
w.element.css("height", "calc(100% - " + this._optimiseGap(top + bottom) + ")"); w.element.css("height", `calc(100% - ${this._optimiseGap(top + bottom)})`);
} }
// 对于表现为td的元素设置最大宽度,有几点需要注意 // 对于表现为td的元素设置最大宽度,有几点需要注意
// 1、由于直接对td设置最大宽度是在规范中未定义的, 所以要使用类似td:firstChild来迂回实现 // 1、由于直接对td设置最大宽度是在规范中未定义的, 所以要使用类似td:firstChild来迂回实现
@ -81,7 +94,7 @@ BI.TableAdaptLayout = BI.inherit(BI.Layout, {
if (columnSize > 0) { if (columnSize > 0) {
td.element.css({ td.element.css({
"max-width": width, "max-width": width,
"min-width": width "min-width": width,
}); });
} }
if (i === 0) { if (i === 0) {
@ -91,20 +104,20 @@ BI.TableAdaptLayout = BI.inherit(BI.Layout, {
position: "relative", position: "relative",
display: "table-cell", display: "table-cell",
"vertical-align": o.verticalAlign, "vertical-align": o.verticalAlign,
height: "100%" height: "100%",
}); });
this._handleGap(w, item, i); this._handleGap(w, item, i);
return td; return td;
}, }
appendFragment: function (frag) { appendFragment(frag) {
this.$table.append(frag); this.$table.append(frag);
this.element.append(this.$table); this.element.append(this.$table);
}, }
populate: function (items) { populate(...args) {
BI.TableAdaptLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.table_adapt", BI.TableAdaptLayout);

47
src/core/wrapper/layout/adapt/adapt.vertical.js

@ -1,13 +1,20 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { HorizontalAlign, VerticalAlign } from "../../../constant";
/** /**
* 垂直方向居中容器 * 垂直方向居中容器
* @class BI.VerticalAdaptLayout * @class VerticalAdaptLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.VerticalAdaptLayout = BI.inherit(BI.Layout, { @shortcut()
props: { export class VerticalAdaptLayout extends Layout {
static xtype = "bi.vertical_adapt";
props = {
baseCls: "bi-v-a", baseCls: "bi-v-a",
horizontalAlign: BI.HorizontalAlign.Left, horizontalAlign: HorizontalAlign.Left,
verticalAlign: BI.VerticalAlign.Middle, verticalAlign: VerticalAlign.Middle,
columnSize: [], columnSize: [],
scrollx: false, scrollx: false,
hgap: 0, hgap: 0,
@ -15,12 +22,13 @@ BI.VerticalAdaptLayout = BI.inherit(BI.Layout, {
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}, }
render() {
const o = this.options;
super.render(...arguments);
render: function () {
var self = this, o = this.options;
BI.VerticalAdaptLayout.superclass.render.apply(this, arguments);
return { return {
type: "bi.horizontal", type: "bi.horizontal",
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
@ -30,8 +38,8 @@ BI.VerticalAdaptLayout = BI.inherit(BI.Layout, {
scrollx: o.scrollx, scrollx: o.scrollx,
scrolly: o.scrolly, scrolly: o.scrolly,
scrollable: o.scrollable, scrollable: o.scrollable,
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
hgap: o.hgap, hgap: o.hgap,
vgap: o.vgap, vgap: o.vgap,
@ -42,14 +50,13 @@ BI.VerticalAdaptLayout = BI.inherit(BI.Layout, {
innerHgap: o.innerHgap, innerHgap: o.innerHgap,
innerVgap: o.innerVgap, innerVgap: o.innerVgap,
}; };
}, }
resize: function () { resize() {
this.layout.resize(); this.layout.resize();
}, }
populate: function (items) { populate(...args) {
this.layout.populate.apply(this, arguments); this.layout.populate(...args);
}
} }
});
BI.shortcut("bi.vertical_adapt", BI.VerticalAdaptLayout);

50
src/core/wrapper/layout/adapt/auto.horizontal.js

@ -1,44 +1,50 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { extend, isFunction } from "../../../2.base";
/** /**
* 水平方向居中自适应容器 * 水平方向居中自适应容器
* @class BI.HorizontalAutoLayout * @class HorizontalAutoLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.HorizontalAutoLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class HorizontalAutoLayout extends Layout {
return BI.extend(BI.HorizontalAutoLayout.superclass.props.apply(this, arguments), { static xtype = "bi.horizontal_auto";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-h-o", baseCls: "bi-h-o",
hgap: 0, hgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
vgap: 0, vgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render: function () { render() {
BI.HorizontalAutoLayout.superclass.render.apply(this, arguments); super.render(...arguments);
var self = this, o = this.options; const o = this.options;
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (i, item) { _addElement(i, item) {
var o = this.options; const w = super._addElement(...arguments);
var w = BI.HorizontalAutoLayout.superclass._addElement.apply(this, arguments);
w.element.css({ w.element.css({
position: "relative", position: "relative",
margin: "0px auto" margin: "0px auto",
}); });
this._handleGap(w, item, null, i); this._handleGap(w, item, null, i);
return w; return w;
}, }
populate: function (items) { populate(...args) {
BI.HorizontalAutoLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.horizontal_auto", BI.HorizontalAutoLayout);

13
src/core/wrapper/layout/adapt/index.js

@ -0,0 +1,13 @@
export { AbsoluteCenterLayout } from "./absolute.center";
export { AbsoluteHorizontalLayout } from "./absolute.horizontal";
export { AbsoluteLeftRightVerticalAdaptLayout, AbsoluteRightVerticalAdaptLayout } from "./absolute.leftrightvertical";
export { AbsoluteVerticalLayout } from "./absolute.vertical";
export { CenterAdaptLayout } from "./adapt.center";
export { HorizontalAdaptLayout } from "./adapt.horizontal";
export { LeftRightVerticalAdaptLayout, LeftVerticalAdaptLayout, RightVerticalAdaptLayout } from "./adapt.leftrightvertical";
export { TableAdaptLayout } from "./adapt.table";
export { VerticalAdaptLayout } from "./adapt.vertical";
export { HorizontalAutoLayout } from "./auto.horizontal";
export { InlineCenterAdaptLayout } from "./inline.center";
export { InlineHorizontalAdaptLayout } from "./inline.horizontal";
export { InlineVerticalAdaptLayout } from "./inline.vertical";

47
src/core/wrapper/layout/adapt/inline.center.js

@ -1,35 +1,43 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { extend } from "../../../2.base";
import { HorizontalAlign, VerticalAlign } from "../../../constant";
/** /**
* 内联布局 * 内联布局
* @class BI.InlineCenterAdaptLayout * @class InlineCenterAdaptLayout
* @extends BI.Layout * @extends Layout
* *
* @cfg {JSON} options 配置属性 * @cfg {JSON} options 配置属性
* @cfg {Number} [hgap=0] 水平间隙 * @cfg {Number} [hgap=0] 水平间隙
* @cfg {Number} [vgap=0] 垂直间隙 * @cfg {Number} [vgap=0] 垂直间隙
*/ */
BI.InlineCenterAdaptLayout = BI.inherit(BI.Layout, { @shortcut()
export class InlineCenterAdaptLayout extends Layout {
static xtype = "bi.inline_center_adapt";
props: function () { props() {
return BI.extend(BI.InlineCenterAdaptLayout.superclass.props.apply(this, arguments), { return extend(super.props(...arguments), {
baseCls: "bi-i-c-a", baseCls: "bi-i-c-a",
horizontalAlign: BI.HorizontalAlign.Center, horizontalAlign: HorizontalAlign.Center,
verticalAlign: BI.VerticalAlign.Middle, verticalAlign: VerticalAlign.Middle,
columnSize: [], columnSize: [],
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render() {
const o = this.options;
render: function () {
var self = this, o = this.options;
return { return {
type: "bi.inline", type: "bi.inline",
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
items: o.items, items: o.items,
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
@ -44,14 +52,13 @@ BI.InlineCenterAdaptLayout = BI.inherit(BI.Layout, {
innerHgap: o.innerHgap, innerHgap: o.innerHgap,
innerVgap: o.innerVgap, innerVgap: o.innerVgap,
}; };
}, }
resize: function () { resize() {
this.layout.resize(); this.layout.resize();
}, }
populate: function (items) { populate(...args) {
this.layout.populate.apply(this.layout, arguments); this.layout.populate(...args);
}
} }
});
BI.shortcut("bi.inline_center_adapt", BI.InlineCenterAdaptLayout);

47
src/core/wrapper/layout/adapt/inline.horizontal.js

@ -1,35 +1,43 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { extend } from "../../../2.base";
import { HorizontalAlign, VerticalAlign } from "../../../constant";
/** /**
* 内联布局 * 内联布局
* @class BI.InlineHorizontalAdaptLayout * @class InlineHorizontalAdaptLayout
* @extends BI.Layout * @extends Layout
* *
* @cfg {JSON} options 配置属性 * @cfg {JSON} options 配置属性
* @cfg {Number} [hgap=0] 水平间隙 * @cfg {Number} [hgap=0] 水平间隙
* @cfg {Number} [vgap=0] 垂直间隙 * @cfg {Number} [vgap=0] 垂直间隙
*/ */
BI.InlineHorizontalAdaptLayout = BI.inherit(BI.Layout, { @shortcut()
export class InlineHorizontalAdaptLayout extends Layout {
static xtype = "bi.inline_horizontal_adapt";
props: function () { props() {
return BI.extend(BI.InlineHorizontalAdaptLayout.superclass.props.apply(this, arguments), { return extend(super.props(...arguments), {
baseCls: "bi-i-h-a", baseCls: "bi-i-h-a",
horizontalAlign: BI.HorizontalAlign.Center, horizontalAlign: HorizontalAlign.Center,
verticalAlign: BI.VerticalAlign.Top, verticalAlign: VerticalAlign.Top,
columnSize: [], columnSize: [],
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render() {
const o = this.options;
render: function () {
var self = this, o = this.options;
return { return {
type: "bi.inline", type: "bi.inline",
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
items: o.items, items: o.items,
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
@ -44,14 +52,13 @@ BI.InlineHorizontalAdaptLayout = BI.inherit(BI.Layout, {
innerHgap: o.innerHgap, innerHgap: o.innerHgap,
innerVgap: o.innerVgap, innerVgap: o.innerVgap,
}; };
}, }
resize: function () { resize() {
this.layout.resize(); this.layout.resize();
}, }
populate: function (items) { populate(...args) {
this.layout.populate.apply(this.layout, arguments); this.layout.populate(...args);
}
} }
});
BI.shortcut("bi.inline_horizontal_adapt", BI.InlineHorizontalAdaptLayout);

47
src/core/wrapper/layout/adapt/inline.vertical.js

@ -1,35 +1,43 @@
import { shortcut } from "../../../decorator";
import { Layout } from "../../layout";
import { extend } from "../../../2.base";
import { HorizontalAlign, VerticalAlign } from "../../../constant";
/** /**
* 内联布局 * 内联布局
* @class BI.InlineVerticalAdaptLayout * @class InlineVerticalAdaptLayout
* @extends BI.Layout * @extends Layout
* *
* @cfg {JSON} options 配置属性 * @cfg {JSON} options 配置属性
* @cfg {Number} [hgap=0] 水平间隙 * @cfg {Number} [hgap=0] 水平间隙
* @cfg {Number} [vgap=0] 垂直间隙 * @cfg {Number} [vgap=0] 垂直间隙
*/ */
BI.InlineVerticalAdaptLayout = BI.inherit(BI.Layout, { @shortcut()
export class InlineVerticalAdaptLayout extends Layout {
static xtype = "bi.inline_vertical_adapt";
props: function () { props() {
return BI.extend(BI.InlineVerticalAdaptLayout.superclass.props.apply(this, arguments), { return extend(super.props(...arguments), {
baseCls: "bi-i-v-a", baseCls: "bi-i-v-a",
horizontalAlign: BI.HorizontalAlign.Left, horizontalAlign: HorizontalAlign.Left,
verticalAlign: BI.VerticalAlign.Middle, verticalAlign: VerticalAlign.Middle,
columnSize: [], columnSize: [],
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render() {
const o = this.options;
render: function () {
var self = this, o = this.options;
return { return {
type: "bi.inline", type: "bi.inline",
ref: function (_ref) { ref: _ref => {
self.layout = _ref; this.layout = _ref;
}, },
items: o.items, items: o.items,
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
@ -44,14 +52,13 @@ BI.InlineVerticalAdaptLayout = BI.inherit(BI.Layout, {
innerHgap: o.innerHgap, innerHgap: o.innerHgap,
innerVgap: o.innerVgap, innerVgap: o.innerVgap,
}; };
}, }
resize: function () { resize() {
this.layout.resize(); this.layout.resize();
}, }
populate: function (items) { populate(...args) {
this.layout.populate.apply(this.layout, arguments); this.layout.populate(...args);
}
} }
});
BI.shortcut("bi.inline_vertical_adapt", BI.InlineVerticalAdaptLayout);

17
src/core/wrapper/layout/index.js

@ -0,0 +1,17 @@
export { AbsoluteLayout } from "./layout.absolute";
export { AdaptiveLayout } from "./layout.adaptive";
export { BorderLayout } from "./layout.border";
export { CardLayout } from "./layout.card";
export { DefaultLayout } from "./layout.default";
export { DivisionLayout } from "./layout.division";
export { FloatLeftLayout, FloatRightLayout } from "./layout.flow";
export { GridLayout } from "./layout.grid";
export { HorizontalLayout } from "./layout.horizontal";
export { InlineLayout } from "./layout.inline";
export { LatticeLayout } from "./layout.lattice";
export { TableLayout } from "./layout.table";
export { HTapeLayout, VTapeLayout } from "./layout.tape";
export { TdLayout } from "./layout.td";
export { VerticalLayout } from "./layout.vertical";
export { WindowLayout } from "./layout.window";
export * from "./adapt";

104
src/core/wrapper/layout/layout.absolute.js

@ -1,115 +1,119 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction, map, parseFloat, isKey, pick, isNotNull, isNumber } from "../../2.base";
/** /**
* 固定子组件上下左右的布局容器 * 固定子组件上下左右的布局容器
* @class BI.AbsoluteLayout
* @extends BI.Layout
*/ */
BI.AbsoluteLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class AbsoluteLayout extends Layout {
return BI.extend(BI.AbsoluteLayout.superclass.props.apply(this, arguments), { static xtype = "bi.absolute";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-abs", baseCls: "bi-abs",
hgap: null, hgap: null,
vgap: null, vgap: null,
lgap: null, lgap: null,
rgap: null, rgap: null,
tgap: null, tgap: null,
bgap: null bgap: null,
}); });
}, }
render: function () {
BI.AbsoluteLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const o = this.options;
self.populate(newValue); const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (i, item) { _addElement(i, item) {
var o = this.options; const o = this.options;
var w = BI.AbsoluteLayout.superclass._addElement.apply(this, arguments); const w = super._addElement(...arguments);
var left = 0, right = 0, top = 0, bottom = 0; let left = 0, right = 0, top = 0, bottom = 0;
var offsets = BI.pick(item, ["top", "right", "bottom", "left"]); let offsets = pick(item, ["top", "right", "bottom", "left"]);
if (BI.isKey(item.inset)) { if (isKey(item.inset)) {
var insets = BI.map((item.inset + "").split(" "), function (i, str) { const insets = map((`${item.inset}`).split(" "), (i, str) => parseFloat(str));
return BI.parseFloat(str);
});
switch (insets.length) { switch (insets.length) {
case 1: case 1:
offsets = {top: insets[0], bottom: insets[0], left: insets[0], right: insets[0]} offsets = { top: insets[0], bottom: insets[0], left: insets[0], right: insets[0] };
break; break;
case 2: case 2:
offsets = {top: insets[0], bottom: insets[0], left: insets[1], right: insets[1]} offsets = { top: insets[0], bottom: insets[0], left: insets[1], right: insets[1] };
break; break;
case 3: case 3:
offsets = {top: insets[0], left: insets[1], right: insets[1], bottom: insets[2]} offsets = { top: insets[0], left: insets[1], right: insets[1], bottom: insets[2] };
break break;
case 4: case 4:
default: default:
offsets = {top: insets[0], right: insets[1], bottom: insets[2], left: insets[3]} offsets = { top: insets[0], right: insets[1], bottom: insets[2], left: insets[3] };
break; break;
} }
} }
if (BI.isNotNull(offsets.left)) { if (isNotNull(offsets.left)) {
w.element.css({left: BI.isNumber(offsets.left) ? this._optimiseGap(offsets.left) : offsets.left}); w.element.css({ left: isNumber(offsets.left) ? this._optimiseGap(offsets.left) : offsets.left });
left += offsets.left; left += offsets.left;
} }
if (BI.isNotNull(offsets.right)) { if (isNotNull(offsets.right)) {
w.element.css({right: BI.isNumber(offsets.right) ? this._optimiseGap(offsets.right) : offsets.right}); w.element.css({ right: isNumber(offsets.right) ? this._optimiseGap(offsets.right) : offsets.right });
right += offsets.right; right += offsets.right;
} }
if (BI.isNotNull(offsets.top)) { if (isNotNull(offsets.top)) {
w.element.css({top: BI.isNumber(offsets.top) ? this._optimiseGap(offsets.top) : offsets.top}); w.element.css({ top: isNumber(offsets.top) ? this._optimiseGap(offsets.top) : offsets.top });
top += offsets.top; top += offsets.top;
} }
if (BI.isNotNull(offsets.bottom)) { if (isNotNull(offsets.bottom)) {
w.element.css({bottom: BI.isNumber(offsets.bottom) ? this._optimiseGap(offsets.bottom) : offsets.bottom}); w.element.css({ bottom: isNumber(offsets.bottom) ? this._optimiseGap(offsets.bottom) : offsets.bottom });
bottom += offsets.bottom; bottom += offsets.bottom;
} }
if (BI.isNotNull(o.hgap)) { if (isNotNull(o.hgap)) {
left += o.hgap; left += o.hgap;
w.element.css({ left: this._optimiseGap(left) }); w.element.css({ left: this._optimiseGap(left) });
right += o.hgap; right += o.hgap;
w.element.css({ right: this._optimiseGap(right) }); w.element.css({ right: this._optimiseGap(right) });
} }
if (BI.isNotNull(o.vgap)) { if (isNotNull(o.vgap)) {
top += o.vgap; top += o.vgap;
w.element.css({ top: this._optimiseGap(top) }); w.element.css({ top: this._optimiseGap(top) });
bottom += o.vgap; bottom += o.vgap;
w.element.css({ bottom: this._optimiseGap(bottom) }); w.element.css({ bottom: this._optimiseGap(bottom) });
} }
if (BI.isNotNull(o.lgap)) { if (isNotNull(o.lgap)) {
left += o.lgap; left += o.lgap;
w.element.css({ left: this._optimiseGap(left) }); w.element.css({ left: this._optimiseGap(left) });
} }
if (BI.isNotNull(o.rgap)) { if (isNotNull(o.rgap)) {
right += o.rgap; right += o.rgap;
w.element.css({ right: this._optimiseGap(right) }); w.element.css({ right: this._optimiseGap(right) });
} }
if (BI.isNotNull(o.tgap)) { if (isNotNull(o.tgap)) {
top += o.tgap; top += o.tgap;
w.element.css({ top: this._optimiseGap(top) }); w.element.css({ top: this._optimiseGap(top) });
} }
if (BI.isNotNull(o.bgap)) { if (isNotNull(o.bgap)) {
bottom += o.bgap; bottom += o.bgap;
w.element.css({ bottom: this._optimiseGap(bottom) }); w.element.css({ bottom: this._optimiseGap(bottom) });
} }
if (BI.isNotNull(item.width)) { if (isNotNull(item.width)) {
w.element.css({width: BI.isNumber(item.width) ? this._optimiseGap(item.width) : item.width}); w.element.css({ width: isNumber(item.width) ? this._optimiseGap(item.width) : item.width });
} }
if (BI.isNotNull(item.height)) { if (isNotNull(item.height)) {
w.element.css({height: BI.isNumber(item.height) ? this._optimiseGap(item.height) : item.height}); w.element.css({ height: isNumber(item.height) ? this._optimiseGap(item.height) : item.height });
} }
w.element.css({ position: "absolute" }); w.element.css({ position: "absolute" });
return w; return w;
}, }
populate: function (items) { populate(...args) {
BI.AbsoluteLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.absolute", BI.AbsoluteLayout);

67
src/core/wrapper/layout/layout.adaptive.js

@ -1,63 +1,70 @@
BI.AdaptiveLayout = BI.inherit(BI.Layout, { import { shortcut } from "../../decorator";
props: function () { import { Layout } from "../layout";
return BI.extend(BI.AdaptiveLayout.superclass.props.apply(this, arguments), { import { extend, isNumber, isNotNull, isFunction } from "../../2.base";
@shortcut()
export class AdaptiveLayout extends Layout {
static xtype = "bi.adaptive";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-adaptive", baseCls: "bi-adaptive",
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render: function () {
BI.AdaptiveLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const self = this, o = this.options;
const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); self.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (i, item) { _addElement(i, item) {
var o = this.options; const w = super._addElement(...arguments);
var w = BI.AdaptiveLayout.superclass._addElement.apply(this, arguments);
w.element.css({ position: "relative" }); w.element.css({ position: "relative" });
if (BI.isNotNull(item.left)) { if (isNotNull(item.left)) {
w.element.css({ w.element.css({
left: BI.isNumber(item.left) ? this._optimiseGap(item.left) : item.left left: isNumber(item.left) ? this._optimiseGap(item.left) : item.left,
}); });
} }
if (BI.isNotNull(item.right)) { if (isNotNull(item.right)) {
w.element.css({ w.element.css({
right: BI.isNumber(item.right) ? this._optimiseGap(item.right) : item.right right: isNumber(item.right) ? this._optimiseGap(item.right) : item.right,
}); });
} }
if (BI.isNotNull(item.top)) { if (isNotNull(item.top)) {
w.element.css({ w.element.css({
top: BI.isNumber(item.top) ? this._optimiseGap(item.top) : item.top top: isNumber(item.top) ? this._optimiseGap(item.top) : item.top,
}); });
} }
if (BI.isNotNull(item.bottom)) { if (isNotNull(item.bottom)) {
w.element.css({ w.element.css({
bottom: BI.isNumber(item.bottom) ? this._optimiseGap(item.bottom) : item.bottom bottom: isNumber(item.bottom) ? this._optimiseGap(item.bottom) : item.bottom,
}); });
} }
this._handleGap(w, item); this._handleGap(w, item);
if (BI.isNotNull(item.width)) { if (isNotNull(item.width)) {
w.element.css({width: BI.isNumber(item.width) ? this._optimiseGap(item.width) : item.width}); w.element.css({ width: isNumber(item.width) ? this._optimiseGap(item.width) : item.width });
} }
if (BI.isNotNull(item.height)) { if (isNotNull(item.height)) {
w.element.css({height: BI.isNumber(item.height) ? this._optimiseGap(item.height) : item.height}); w.element.css({ height: isNumber(item.height) ? this._optimiseGap(item.height) : item.height });
} }
return w; return w;
}, }
populate: function (items) { populate(...args) {
BI.AbsoluteLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.adaptive", BI.AdaptiveLayout);

102
src/core/wrapper/layout/layout.border.js

@ -1,42 +1,51 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isNotNull, isFunction } from "../../2.base";
import { _lazyCreateWidget } from "../../5.inject";
/** /**
* 上下的高度固定/左右的宽度固定中间的高度/宽度自适应 * 上下的高度固定/左右的宽度固定中间的高度/宽度自适应
* *
* @class BI.BorderLayout * @class BorderLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.BorderLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class BorderLayout extends Layout {
return BI.extend(BI.BorderLayout.superclass.props.apply(this, arguments), { static xtype = "bi.border";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-border-layout", baseCls: "bi-border-layout",
items: {} items: {},
}); });
}, }
render: function () {
BI.BorderLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const self = this, o = this.options;
const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); self.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
addItem: function (item) { addItem(item) {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
stroke: function (regions) { stroke(regions) {
var item; let item;
var top = 0; let top = 0;
var bottom = 0; let bottom = 0;
var left = 0; let left = 0;
var right = 0; let right = 0;
if ("north" in regions) { if ("north" in regions) {
item = regions["north"]; item = regions.north;
if (item != null) { if (isNotNull(item)) {
if (item.el) { if (item.el) {
if (!this.hasWidget(this._getChildName("north"))) { if (!this.hasWidget(this._getChildName("north"))) {
var w = BI._lazyCreateWidget(item); const w = _lazyCreateWidget(item);
this.addWidget(this._getChildName("north"), w); this.addWidget(this._getChildName("north"), w);
} }
this.getWidgetByName(this._getChildName("north")).element.height(this._optimiseGap(item.height)) this.getWidgetByName(this._getChildName("north")).element.height(this._optimiseGap(item.height))
@ -45,18 +54,18 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
top: this._optimiseGap(item.top || 0), top: this._optimiseGap(item.top || 0),
left: this._optimiseGap(item.left || 0), left: this._optimiseGap(item.left || 0),
right: this._optimiseGap(item.right || 0), right: this._optimiseGap(item.right || 0),
bottom: "initial" bottom: "initial",
}); });
} }
top = (item.height || 0) + (item.top || 0) + (item.bottom || 0); top = (item.height || 0) + (item.top || 0) + (item.bottom || 0);
} }
} }
if ("south" in regions) { if ("south" in regions) {
item = regions["south"]; item = regions.south;
if (item != null) { if (isNotNull(item)) {
if (item.el) { if (item.el) {
if (!this.hasWidget(this._getChildName("south"))) { if (!this.hasWidget(this._getChildName("south"))) {
var w = BI._lazyCreateWidget(item); const w = _lazyCreateWidget(item);
this.addWidget(this._getChildName("south"), w); this.addWidget(this._getChildName("south"), w);
} }
this.getWidgetByName(this._getChildName("south")).element.height(this._optimiseGap(item.height)) this.getWidgetByName(this._getChildName("south")).element.height(this._optimiseGap(item.height))
@ -65,18 +74,18 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
bottom: this._optimiseGap(item.bottom || 0), bottom: this._optimiseGap(item.bottom || 0),
left: this._optimiseGap(item.left || 0), left: this._optimiseGap(item.left || 0),
right: this._optimiseGap(item.right || 0), right: this._optimiseGap(item.right || 0),
top: "initial" top: "initial",
}); });
} }
bottom = (item.height || 0) + (item.top || 0) + (item.bottom || 0); bottom = (item.height || 0) + (item.top || 0) + (item.bottom || 0);
} }
} }
if ("west" in regions) { if ("west" in regions) {
item = regions["west"]; item = regions.west;
if (item != null) { if (isNotNull(item)) {
if (item.el) { if (item.el) {
if (!this.hasWidget(this._getChildName("west"))) { if (!this.hasWidget(this._getChildName("west"))) {
var w = BI._lazyCreateWidget(item); const w = _lazyCreateWidget(item);
this.addWidget(this._getChildName("west"), w); this.addWidget(this._getChildName("west"), w);
} }
this.getWidgetByName(this._getChildName("west")).element.width(this._optimiseGap(item.width)) this.getWidgetByName(this._getChildName("west")).element.width(this._optimiseGap(item.width))
@ -85,18 +94,18 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
left: this._optimiseGap(item.left || 0), left: this._optimiseGap(item.left || 0),
top: this._optimiseGap(top), top: this._optimiseGap(top),
bottom: this._optimiseGap(bottom), bottom: this._optimiseGap(bottom),
right: "initial" right: "initial",
}); });
} }
left = (item.width || 0) + (item.left || 0) + (item.right || 0); left = (item.width || 0) + (item.left || 0) + (item.right || 0);
} }
} }
if ("east" in regions) { if ("east" in regions) {
item = regions["east"]; item = regions.east;
if (item != null) { if (isNotNull(item)) {
if (item.el) { if (item.el) {
if (!this.hasWidget(this._getChildName("east"))) { if (!this.hasWidget(this._getChildName("east"))) {
var w = BI._lazyCreateWidget(item); const w = _lazyCreateWidget(item);
this.addWidget(this._getChildName("east"), w); this.addWidget(this._getChildName("east"), w);
} }
this.getWidgetByName(this._getChildName("east")).element.width(this._optimiseGap(item.width)) this.getWidgetByName(this._getChildName("east")).element.width(this._optimiseGap(item.width))
@ -105,17 +114,17 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
right: this._optimiseGap(item.right || 0), right: this._optimiseGap(item.right || 0),
top: this._optimiseGap(top), top: this._optimiseGap(top),
bottom: this._optimiseGap(bottom), bottom: this._optimiseGap(bottom),
left: "initial" left: "initial",
}); });
} }
right = (item.width || 0) + (item.left || 0) + (item.right || 0); right = (item.width || 0) + (item.left || 0) + (item.right || 0);
} }
} }
if ("center" in regions) { if ("center" in regions) {
item = regions["center"]; item = regions.center;
if (item != null) { if (isNotNull(item)) {
if (!this.hasWidget(this._getChildName("center"))) { if (!this.hasWidget(this._getChildName("center"))) {
var w = BI._lazyCreateWidget(item); const w = _lazyCreateWidget(item);
this.addWidget(this._getChildName("center"), w); this.addWidget(this._getChildName("center"), w);
} }
this.getWidgetByName(this._getChildName("center")).element this.getWidgetByName(this._getChildName("center")).element
@ -124,19 +133,18 @@ BI.BorderLayout = BI.inherit(BI.Layout, {
top: this._optimiseGap(top), top: this._optimiseGap(top),
bottom: this._optimiseGap(bottom), bottom: this._optimiseGap(bottom),
left: this._optimiseGap(left), left: this._optimiseGap(left),
right: this._optimiseGap(right) right: this._optimiseGap(right),
}); });
} }
} }
}, }
update: function (opt) { update(opt) {
return this.forceUpdate(opt); return this.forceUpdate(opt);
}, }
populate: function (items) { populate(...args) {
BI.BorderLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.border", BI.BorderLayout);

215
src/core/wrapper/layout/layout.card.js

@ -1,211 +1,215 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, each, isNotNull, isFunction, findIndex, isWidget, some, map, isKey } from "../../2.base";
import { _lazyCreateWidget } from "../../5.inject";
import { Events } from "../../constant";
import { Action } from "../../action";
/** /**
* 卡片布局可以做到当前只显示一个组件其他的都隐藏 * 卡片布局可以做到当前只显示一个组件其他的都隐藏
* @class BI.CardLayout * @class CardLayout
* @extends BI.Layout * @extends Layout
* *
* @cfg {JSON} options 配置属性 * @cfg {JSON} options 配置属性
* @cfg {String} options.defaultShowName 默认展示的子组件名 * @cfg {String} options.defaultShowName 默认展示的子组件名
*/ */
BI.CardLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class CardLayout extends Layout {
return BI.extend(BI.CardLayout.superclass.props.apply(this, arguments), { static xtype = "bi.card";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-card-layout", baseCls: "bi-card-layout",
items: [] items: [],
}); });
}, }
render: function () { render() {
BI.CardLayout.superclass.render.apply(this, arguments); super.render(...arguments);
var self = this, o = this.options; const o = this.options;
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
stroke: function (items) { stroke(items) {
var self = this, o = this.options; const o = this.options;
this.showIndex = void 0; this.showIndex = void 0;
BI.each(items, function (i, item) { each(items, (i, item) => {
if (item) { if (item) {
if (!self.hasWidget(item.cardName)) { let w;
var w = BI._lazyCreateWidget(item); if (!this.hasWidget(item.cardName)) {
w.on(BI.Events.DESTROY, function () { w = _lazyCreateWidget(item);
var index = BI.findIndex(o.items, function (i, tItem) { w.on(Events.DESTROY, () => {
return tItem.cardName == item.cardName; const index = findIndex(o.items, (i, tItem) => tItem.cardName === item.cardName);
});
if (index > -1) { if (index > -1) {
o.items.splice(index, 1); o.items.splice(index, 1);
} }
}); });
self.addWidget(self._getChildName(item.cardName), w); this.addWidget(this._getChildName(item.cardName), w);
} else { } else {
var w = self.getWidgetByName(self._getChildName(item.cardName)); w = this.getWidgetByName(this._getChildName(item.cardName));
} }
w.element.css({ w.element.css({
position: "relative", position: "relative",
top: "0", top: "0",
left: "0", left: "0",
width: "100%", width: "100%",
height: "100%" height: "100%",
}); });
w.setVisible(false); w.setVisible(false);
} }
}); });
}, }
resize: function () { resize() {
// console.log("Card布局不需要resize"); // console.log("Card布局不需要resize");
}, }
update: function (opt) { update(opt) {
return this.forceUpdate(opt); return this.forceUpdate(opt);
}, }
empty: function () { empty(...args) {
BI.CardLayout.superclass.empty.apply(this, arguments); super.empty(...args);
this.options.items = []; this.options.items = [];
}, }
populate: function (items) { populate(...args) {
BI.CardLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
this.options.defaultShowName && this.showCardByName(this.options.defaultShowName); this.options.defaultShowName && this.showCardByName(this.options.defaultShowName);
}, }
isCardExisted: function (cardName) { isCardExisted(cardName) {
return BI.some(this.options.items, function (i, item) { return some(this.options.items, (i, item) => item.cardName === cardName && item.el);
return item.cardName == cardName && item.el; }
});
},
getCardByName: function (cardName) { getCardByName(cardName) {
if (!this.isCardExisted(cardName)) { if (!this.isCardExisted(cardName)) {
throw new Error("cardName不存在", cardName); throw new Error("cardName不存在", cardName);
} }
return this._children[this._getChildName(cardName)]; return this._children[this._getChildName(cardName)];
}, }
_deleteCardByName: function (cardName) { _deleteCardByName(cardName) {
delete this._children[this._getChildName(cardName)]; delete this._children[this._getChildName(cardName)];
var index = BI.findIndex(this.options.items, function (i, item) { const index = findIndex(this.options.items, (i, item) => item.cardName === cardName);
return item.cardName == cardName;
});
if (index > -1) { if (index > -1) {
this.options.items.splice(index, 1); this.options.items.splice(index, 1);
} }
}, }
deleteCardByName: function (cardName) { deleteCardByName(cardName) {
if (!this.isCardExisted(cardName)) { if (!this.isCardExisted(cardName)) {
throw new Error("cardName不存在", cardName); throw new Error("cardName不存在", cardName);
} }
var child = this._children[this._getChildName(cardName)]; const child = this._children[this._getChildName(cardName)];
this._deleteCardByName(cardName); this._deleteCardByName(cardName);
child && child._destroy(); child && child._destroy();
}, }
addCardByName: function (cardName, cardItem) { addCardByName(cardName, cardItem) {
if (this.isCardExisted(cardName)) { if (this.isCardExisted(cardName)) {
throw new Error("cardName 已存在", cardName); throw new Error("cardName 已存在", cardName);
} }
var widget = BI._lazyCreateWidget(cardItem, this); const widget = _lazyCreateWidget(cardItem, this);
widget.element.css({ widget.element.css({
position: "relative", position: "relative",
top: "0", top: "0",
left: "0", left: "0",
width: "100%", width: "100%",
height: "100%" height: "100%",
}).appendTo(this.element); }).appendTo(this.element);
widget.invisible(); widget.invisible();
this.addWidget(this._getChildName(cardName), widget); this.addWidget(this._getChildName(cardName), widget);
this.options.items.push({el: cardItem, cardName: cardName}); this.options.items.push({ el: cardItem, cardName });
return widget; return widget;
}, }
showCardByName: function (name, action, callback) { showCardByName(name, action, callback) {
var self = this;
// name不存在的时候全部隐藏 // name不存在的时候全部隐藏
var exist = this.isCardExisted(name); const exist = this.isCardExisted(name);
if (this.showIndex != null) { if (isNotNull(this.showIndex)) {
this.lastShowIndex = this.showIndex; this.lastShowIndex = this.showIndex;
} }
this.showIndex = name; this.showIndex = name;
var flag = false; let flag = false;
BI.each(this.options.items, function (i, item) { each(this.options.items, (i, item) => {
var el = self._children[self._getChildName(item.cardName)]; const el = this._children[this._getChildName(item.cardName)];
if (el) { if (el) {
if (name != item.cardName) { if (name !== item.cardName) {
// 动画效果只有在全部都隐藏的时候才有意义,且只要执行一次动画操作就够了 // 动画效果只有在全部都隐藏的时候才有意义,且只要执行一次动画操作就够了
!flag && !exist && (BI.Action && action instanceof BI.Action) ? (action.actionBack(el), flag = true) : el.invisible(); !flag && !exist && (Action && action instanceof Action) ? (action.actionBack(el), flag = true) : el.invisible();
} else { } else {
(BI.Action && action instanceof BI.Action) ? action.actionPerformed(void 0, el, callback) : (el.visible(), callback && callback()); (Action && action instanceof Action) ? action.actionPerformed(void 0, el, callback) : (el.visible(), callback && callback());
} }
} }
}); });
}, }
showLastCard: function () { showLastCard() {
var self = this;
this.showIndex = this.lastShowIndex; this.showIndex = this.lastShowIndex;
BI.each(this.options.items, function (i, item) { each(this.options.items, (i, item) => {
self._children[self._getChildName(item.cardName)].setVisible(self.showIndex == i); this._children[this._getChildName(item.cardName)].setVisible(this.showIndex === i);
}); });
}, }
setDefaultShowName: function (name) { setDefaultShowName(name) {
this.options.defaultShowName = name; this.options.defaultShowName = name;
return this; return this;
}, }
getDefaultShowName: function () { getDefaultShowName() {
return this.options.defaultShowName; return this.options.defaultShowName;
}, }
getAllCardNames: function () { getAllCardNames() {
return BI.map(this.options.items, function (i, item) { return map(this.options.items, (i, item) => item.cardName);
return item.cardName; }
});
},
getShowingCard: function () { getShowingCard() {
if (!BI.isKey(this.showIndex)) { if (!isKey(this.showIndex)) {
return void 0; return void 0;
} }
return this.getWidgetByName(this._getChildName(this.showIndex)); return this.getWidgetByName(this._getChildName(this.showIndex));
}, }
deleteAllCard: function () { deleteAllCard() {
var self = this; each(this.getAllCardNames(), (i, name) => {
BI.each(this.getAllCardNames(), function (i, name) { this.deleteCardByName(name);
self.deleteCardByName(name);
}); });
}, }
hideAllCard: function () { hideAllCard() {
var self = this; each(this.options.items, (i, item) => {
BI.each(this.options.items, function (i, item) { this._children[this._getChildName(item.cardName)].invisible();
self._children[self._getChildName(item.cardName)].invisible();
}); });
}, }
isAllCardHide: function () { isAllCardHide() {
var self = this; let flag = true;
var flag = true; some(this.options.items, (i, item) => {
BI.some(this.options.items, function (i, item) { if (this._children[this._getChildName(item.cardName)].isVisible()) {
if (self._children[self._getChildName(item.cardName)].isVisible()) {
flag = false; flag = false;
return false; return false;
} }
}); });
return flag; return flag;
}, }
removeWidget: function (nameOrWidget) { removeWidget(nameOrWidget) {
var removeName, self = this; let removeName;
if (BI.isWidget(nameOrWidget)) { if (isWidget(nameOrWidget)) {
BI.each(this._children, function (name, child) { each(this._children, (name, child) => {
if (child === nameOrWidget) { if (child === nameOrWidget) {
removeName = name; removeName = name;
} }
@ -217,5 +221,4 @@ BI.CardLayout = BI.inherit(BI.Layout, {
this._deleteCardByName(removeName); this._deleteCardByName(removeName);
} }
} }
}); }
BI.shortcut("bi.card", BI.CardLayout);

48
src/core/wrapper/layout/layout.default.js

@ -1,39 +1,47 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction } from "../../2.base";
/** /**
* 默认的布局方式 * 默认的布局方式
* *
* @class BI.DefaultLayout * @class DefaultLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.DefaultLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class DefaultLayout extends Layout {
return BI.extend(BI.DefaultLayout.superclass.props.apply(this, arguments), { static xtype = "bi.default";
props() {
return extend(super.props(...arguments), {
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
items: [] items: [],
}); });
}, }
render: function () {
BI.DefaultLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const o = this.options;
self.populate(newValue); const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (i, item) { _addElement(i, item) {
var w = BI.DefaultLayout.superclass._addElement.apply(this, arguments); const w = super._addElement(...arguments);
this._handleGap(w, item); this._handleGap(w, item);
return w; return w;
}, }
populate: function (items) { populate(...args) {
BI.DefaultLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.default", BI.DefaultLayout);

122
src/core/wrapper/layout/layout.division.js

@ -1,36 +1,46 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction, makeArray, each, isArray } from "../../2.base";
import { Widget } from "../../4.widget";
import { _lazyCreateWidget } from "../../5.inject";
/** /**
* 分隔容器的控件按照宽度和高度所占比平分整个容器 * 分隔容器的控件按照宽度和高度所占比平分整个容器
* *
* @class BI.DivisionLayout * @class DivisionLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.DivisionLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class DivisionLayout extends Layout {
return BI.extend(BI.DivisionLayout.superclass.props.apply(this, arguments), { static xtype = "bi.division";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-division", baseCls: "bi-division",
columns: null, columns: null,
rows: null, rows: null,
items: [] items: [],
}); });
}, }
render: function () {
BI.DivisionLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const o = this.options;
self.populate(newValue); const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
addItem: function (item) { addItem(item) {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
stroke: function (items) { stroke(items) {
var o = this.options, self = this; const o = this.options;
var rows = o.rows || o.items.length, columns = o.columns || ((o.items[0] && o.items[0].length) | 0); const rows = o.rows || o.items.length, columns = o.columns || ((o.items[0] && o.items[0].length) | 0);
var map = BI.makeArray(rows), widths = {}, heights = {}; const map = makeArray(rows), widths = {}, heights = {};
function firstElement (item, cls) { function firstElement (item, cls) {
item.addClass(cls); item.addClass(cls);
@ -45,9 +55,9 @@ BI.DivisionLayout = BI.inherit(BI.Layout, {
} }
function first (item, cls) { function first (item, cls) {
if (item instanceof BI.Widget) { if (item instanceof Widget) {
firstElement(item.element, cls); firstElement(item.element, cls);
} else if (item.el instanceof BI.Widget) { } else if (item.el instanceof Widget) {
firstElement(item.el.element, cls); firstElement(item.el.element, cls);
} else if (item.el) { } else if (item.el) {
firstObject(item.el, cls); firstObject(item.el, cls);
@ -56,12 +66,12 @@ BI.DivisionLayout = BI.inherit(BI.Layout, {
} }
} }
BI.each(map, function (i) { each(map, i => {
map[i] = BI.makeArray(columns); map[i] = makeArray(columns);
}); });
BI.each(items, function (i, item) { each(items, (i, item) => {
if (BI.isArray(item)) { if (isArray(item)) {
BI.each(item, function (j, el) { each(item, (j, el) => {
widths[i] = (widths[i] || 0) + item.width; widths[i] = (widths[i] || 0) + item.width;
heights[j] = (heights[j] || 0) + item.height; heights[j] = (heights[j] || 0) + item.height;
map[i][j] = el; map[i][j] = el;
@ -73,56 +83,56 @@ BI.DivisionLayout = BI.inherit(BI.Layout, {
heights[item.column] = (heights[item.column] || 0) + item.height; heights[item.column] = (heights[item.column] || 0) + item.height;
map[item.row][item.column] = item; map[item.row][item.column] = item;
}); });
for (var i = 0; i < rows; i++) { for (let i = 0; i < rows; i++) {
var totalW = 0; let totalW = 0;
for (var j = 0; j < columns; j++) { for (let j = 0; j < columns; j++) {
let w;
if (!map[i][j]) { if (!map[i][j]) {
throw new Error("item(" + i + "" + j + ") 必须", map); throw new Error(`item(${i}${j}) 必须`, map);
} }
if (!this.hasWidget(this._getChildName(i + "_" + j))) { if (!this.hasWidget(this._getChildName(`${i}_${j}`))) {
var w = BI._lazyCreateWidget(map[i][j]); w = _lazyCreateWidget(map[i][j]);
this.addWidget(this._getChildName(i + "_" + j), w); this.addWidget(this._getChildName(`${i}_${j}`), w);
} else { } else {
w = this.getWidgetByName(this._getChildName(i + "_" + j)); w = this.getWidgetByName(this._getChildName(`${i}_${j}`));
} }
var left = totalW * 100 / widths[i]; const left = totalW * 100 / widths[i];
w.element.css({position: "absolute", left: left + "%"}); w.element.css({ position: "absolute", left: `${left}%` });
if (j > 0) { if (j > 0) {
var lastW = this.getWidgetByName(this._getChildName(i + "_" + (j - 1))); const lastW = this.getWidgetByName(this._getChildName(`${i}_${j - 1}`));
lastW.element.css({right: (100 - left) + "%"}); lastW.element.css({ right: `${100 - left}%` });
} }
if (j == o.columns - 1) { if (j === o.columns - 1) {
w.element.css({ right: "0%" }); w.element.css({ right: "0%" });
} }
first(w, self.getRowColumnCls(i, j, rows - 1, columns - 1)); first(w, this.getRowColumnCls(i, j, rows - 1, columns - 1));
totalW += map[i][j].width; totalW += map[i][j].width;
} }
} }
for (var j = 0; j < o.columns; j++) { for (let j = 0; j < o.columns; j++) {
var totalH = 0; let totalH = 0;
for (var i = 0; i < o.rows; i++) { for (let i = 0; i < o.rows; i++) {
var w = this.getWidgetByName(this._getChildName(i + "_" + j)); const w = this.getWidgetByName(this._getChildName(`${i}_${j}`));
var top = totalH * 100 / heights[j]; const top = totalH * 100 / heights[j];
w.element.css({top: top + "%"}); w.element.css({ top: `${top}%` });
if (i > 0) { if (i > 0) {
var lastW = this.getWidgetByName(this._getChildName((i - 1) + "_" + j)); const lastW = this.getWidgetByName(this._getChildName(`${i - 1}_${j}`));
lastW.element.css({bottom: (100 - top) + "%"}); lastW.element.css({ bottom: `${100 - top}%` });
} }
if (i == o.rows - 1) { if (i === o.rows - 1) {
w.element.css({ bottom: "0%" }); w.element.css({ bottom: "0%" });
} }
totalH += map[i][j].height; totalH += map[i][j].height;
} }
} }
}, }
update: function (opt) { update(opt) {
return this.forceUpdate(opt); return this.forceUpdate(opt);
}, }
populate: function (items) { populate(...args) {
BI.DivisionLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.division", BI.DivisionLayout);

181
src/core/wrapper/layout/layout.flow.js

@ -1,183 +1,196 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction, isNotNull, isNumber } from "../../2.base";
import { pixFormat } from "../../constant";
/** /**
* 靠左对齐的自由浮动布局 * 靠左对齐的自由浮动布局
* @class BI.FloatLeftLayout * @class FloatLeftLayout
* @extends BI.Layout * @extends Layout
* *
* @cfg {JSON} options 配置属性 * @cfg {JSON} options 配置属性
* @cfg {Number} [hgap=0] 水平间隙 * @cfg {Number} [hgap=0] 水平间隙
* @cfg {Number} [vgap=0] 垂直间隙 * @cfg {Number} [vgap=0] 垂直间隙
*/ */
BI.FloatLeftLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class FloatLeftLayout extends Layout {
return BI.extend(BI.FloatLeftLayout.superclass.props.apply(this, arguments), { static xtype = "bi.left";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-left clearfix", baseCls: "bi-left clearfix",
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render: function () {
BI.FloatLeftLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
const o = this.options;
if (o.innerHgap !== 0) { if (o.innerHgap !== 0) {
this.element.css({ this.element.css({
paddingLeft: this._optimiseGap(o.innerHgap), paddingLeft: this._optimiseGap(o.innerHgap),
paddingRight: this._optimiseGap(o.innerHgap) paddingRight: this._optimiseGap(o.innerHgap),
}) });
} }
if (o.innerVgap !== 0) { if (o.innerVgap !== 0) {
this.element.css({ this.element.css({
paddingTop: this._optimiseGap(o.innerVgap), paddingTop: this._optimiseGap(o.innerVgap),
paddingBottom: this._optimiseGap(o.innerVgap) paddingBottom: this._optimiseGap(o.innerVgap),
}) });
} }
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (i, item) { _addElement(i, item) {
var o = this.options; const o = this.options;
var w = BI.FloatLeftLayout.superclass._addElement.apply(this, arguments); const w = super._addElement(...arguments);
w.element.css({position: "relative", float: "left"}); w.element.css({ position: "relative", "float": "left" });
if (BI.isNotNull(item.left)) { if (isNotNull(item.left)) {
w.element.css({left: BI.isNumber(item.left) ? this._optimiseGap(item.left) : item.left}); w.element.css({ left: isNumber(item.left) ? this._optimiseGap(item.left) : item.left });
} }
if (BI.isNotNull(item.right)) { if (isNotNull(item.right)) {
w.element.css({right: BI.isNumber(item.right) ? this._optimiseGap(item.right) : item.right}); w.element.css({ right: isNumber(item.right) ? this._optimiseGap(item.right) : item.right });
} }
if (BI.isNotNull(item.top)) { if (isNotNull(item.top)) {
w.element.css({top: BI.isNumber(item.top) ? this._optimiseGap(item.top) : item.top}); w.element.css({ top: isNumber(item.top) ? this._optimiseGap(item.top) : item.top });
} }
if (BI.isNotNull(item.bottom)) { if (isNotNull(item.bottom)) {
w.element.css({bottom: BI.isNumber(item.bottom) ? this._optimiseGap(item.bottom) : item.bottom}); w.element.css({ bottom: isNumber(item.bottom) ? this._optimiseGap(item.bottom) : item.bottom });
} }
if (o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item) !== 0) { if (o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item) !== 0) {
var top = o.vgap / 2 + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item); const top = o.vgap / 2 + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item);
w.element.css({ w.element.css({
"margin-top": this._optimiseGap(top) "margin-top": this._optimiseGap(top),
}); });
} }
if (o.hgap + o.lgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item) !== 0) { if (o.hgap + o.lgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item) !== 0) {
var left = o.hgap / 2 + o.lgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item); const left = o.hgap / 2 + o.lgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item);
w.element.css({ w.element.css({
"margin-left": this._optimiseGap(left) "margin-left": this._optimiseGap(left),
}); });
} }
if (o.hgap + o.rgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item) !== 0) { if (o.hgap + o.rgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item) !== 0) {
var right = o.hgap / 2 + o.rgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item); const right = o.hgap / 2 + o.rgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item);
w.element.css({ w.element.css({
"margin-right": this._optimiseGap(right) "margin-right": this._optimiseGap(right),
}); });
} }
if (o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item) !== 0) { if (o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item) !== 0) {
var bottom = o.vgap / 2 + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item); const bottom = o.vgap / 2 + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item);
w.element.css({ w.element.css({
"margin-bottom": this._optimiseGap(bottom) "margin-bottom": this._optimiseGap(bottom),
}); });
} }
return w; return w;
}, }
populate: function (items) { populate(...args) {
BI.FloatLeftLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.left", BI.FloatLeftLayout);
/** /**
* 靠右对齐的自由浮动布局 * 靠右对齐的自由浮动布局
* @class BI.FloatRightLayout * @class FloatRightLayout
* @extends BI.Layout * @extends Layout
* *
* @cfg {JSON} options 配置属性 * @cfg {JSON} options 配置属性
* @cfg {Number} [hgap=0] 水平间隙 * @cfg {Number} [hgap=0] 水平间隙
* @cfg {Number} [vgap=0] 垂直间隙 * @cfg {Number} [vgap=0] 垂直间隙
*/ */
BI.FloatRightLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class FloatRightLayout extends Layout {
return BI.extend(BI.FloatRightLayout.superclass.props.apply(this, arguments), { static xtype = "bi.right";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-right clearfix", baseCls: "bi-right clearfix",
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0 bgap: 0,
}); });
}, }
render: function () {
BI.FloatRightLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
const o = this.options;
if (o.innerHgap !== 0) { if (o.innerHgap !== 0) {
this.element.css({ this.element.css({
paddingLeft: this._optimiseGap(o.innerHgap), paddingLeft: this._optimiseGap(o.innerHgap),
paddingRight: this._optimiseGap(o.innerHgap) paddingRight: this._optimiseGap(o.innerHgap),
}) });
} }
if (o.innerVgap !== 0) { if (o.innerVgap !== 0) {
this.element.css({ this.element.css({
paddingTop: this._optimiseGap(o.innerVgap), paddingTop: this._optimiseGap(o.innerVgap),
paddingBottom: this._optimiseGap(o.innerVgap) paddingBottom: this._optimiseGap(o.innerVgap),
}) });
} }
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (i, item) { _addElement(i, item) {
var o = this.options; const o = this.options;
var w = BI.FloatRightLayout.superclass._addElement.apply(this, arguments); const w = super._addElement(...arguments);
w.element.css({position: "relative", float: "right"}); w.element.css({ position: "relative", "float": "right" });
if (BI.isNotNull(item.left)) { if (isNotNull(item.left)) {
w.element.css({left: BI.pixFormat(item.left)}); w.element.css({ left: pixFormat(item.left) });
} }
if (BI.isNotNull(item.right)) { if (isNotNull(item.right)) {
w.element.css({right: BI.pixFormat(item.right)}); w.element.css({ right: pixFormat(item.right) });
} }
if (BI.isNotNull(item.top)) { if (isNotNull(item.top)) {
w.element.css({top: BI.pixFormat(item.top)}); w.element.css({ top: pixFormat(item.top) });
} }
if (BI.isNotNull(item.bottom)) { if (isNotNull(item.bottom)) {
w.element.css({bottom: BI.pixFormat(item.bottom)}); w.element.css({ bottom: pixFormat(item.bottom) });
} }
if (o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item) !== 0) { if (o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item) !== 0) {
var top = o.vgap / 2 + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item); const top = o.vgap / 2 + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item);
w.element.css({ w.element.css({
"margin-top": this._optimiseGap(top) "margin-top": this._optimiseGap(top),
}); });
} }
if (o.hgap + o.lgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item) !== 0) { if (o.hgap + o.lgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item) !== 0) {
var left = o.hgap / 2 + o.lgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item); const left = o.hgap / 2 + o.lgap + this._optimiseItemLgap(item) + this._optimiseItemHgap(item);
w.element.css({ w.element.css({
"margin-left": this._optimiseGap(left) "margin-left": this._optimiseGap(left),
}); });
} }
if (o.hgap + o.rgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item) !== 0) { if (o.hgap + o.rgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item) !== 0) {
var right = o.hgap / 2 + o.rgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item); const right = o.hgap / 2 + o.rgap + this._optimiseItemRgap(item) + this._optimiseItemHgap(item);
w.element.css({ w.element.css({
"margin-right": this._optimiseGap(right) "margin-right": this._optimiseGap(right),
}); });
} }
if (o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item) !== 0) { if (o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item) !== 0) {
var bottom = o.vgap / 2 + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item); const bottom = o.vgap / 2 + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item);
w.element.css({ w.element.css({
"margin-bottom": this._optimiseGap(bottom) "margin-bottom": this._optimiseGap(bottom),
}); });
} }
return w; return w;
}, }
populate: function (items) { populate(...args) {
BI.FloatRightLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.right", BI.FloatRightLayout);

106
src/core/wrapper/layout/layout.grid.js

@ -1,38 +1,42 @@
/** import { shortcut } from "../../decorator";
* 上下的高度固定/左右的宽度固定中间的高度/宽度自适应 import { Layout } from "../layout";
* import { extend, isFunction, isArray, each } from "../../2.base";
* @class BI.BorderLayout import { Widget } from "../../4.widget";
* @extends BI.Layout import { _lazyCreateWidget } from "../../5.inject";
*/
BI.GridLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class GridLayout extends Layout {
return BI.extend(BI.GridLayout.superclass.props.apply(this, arguments), { static xtype = "bi.grid";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-grid", baseCls: "bi-grid",
columns: null, columns: null,
rows: null, rows: null,
items: [] items: [],
}); });
}, }
render: function () {
BI.GridLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const o = this.options;
self.populate(newValue); const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
addItem: function () { addItem() {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
stroke: function (items) { stroke(items) {
var self = this, o = this.options; const o = this.options;
var rows = o.rows || o.items.length, columns = o.columns || ((o.items[0] && o.items[0].length) | 0); const rows = o.rows || o.items.length, columns = o.columns || ((o.items[0] && o.items[0].length) | 0);
var width = 100 / columns, height = 100 / rows; const width = 100 / columns, height = 100 / rows;
var els = []; const els = [];
for (var i = 0; i < rows; i++) { for (let i = 0; i < rows; i++) {
els[i] = []; els[i] = [];
} }
@ -49,9 +53,9 @@ BI.GridLayout = BI.inherit(BI.Layout, {
} }
function first (item, row, col) { function first (item, row, col) {
if (item instanceof BI.Widget) { if (item instanceof Widget) {
firstElement(item.element, row, col); firstElement(item.element, row, col);
} else if (item.el instanceof BI.Widget) { } else if (item.el instanceof Widget) {
firstElement(item.el.element, row, col); firstElement(item.el.element, row, col);
} else if (item.el) { } else if (item.el) {
firstObject(item.el, row, col); firstObject(item.el, row, col);
@ -60,46 +64,46 @@ BI.GridLayout = BI.inherit(BI.Layout, {
} }
} }
BI.each(items, function (i, item) { each(items, (i, item) => {
if (BI.isArray(item)) { if (isArray(item)) {
BI.each(item, function (j, el) { each(item, (j, el) => {
els[i][j] = BI._lazyCreateWidget(el); els[i][j] = _lazyCreateWidget(el);
}); });
return; return;
} }
els[item.row][item.column] = BI._lazyCreateWidget(item); els[item.row][item.column] = _lazyCreateWidget(item);
}); });
for (var i = 0; i < rows; i++) { for (let i = 0; i < rows; i++) {
for (var j = 0; j < columns; j++) { for (let j = 0; j < columns; j++) {
if (!els[i][j]) { if (!els[i][j]) {
els[i][j] = BI._lazyCreateWidget({ els[i][j] = _lazyCreateWidget({
type: "bi.layout" type: "bi.layout",
}); });
} }
first(els[i][j], self.getRowColumnCls(i, j, rows - 1, columns - 1)); first(els[i][j], this.getRowColumnCls(i, j, rows - 1, columns - 1));
els[i][j].element.css({ els[i][j].element.css({
position: "absolute", position: "absolute",
top: height * i + "%", top: `${height * i}%`,
left: width * j + "%", left: `${width * j}%`,
right: (100 - (width * (j + 1))) + "%", right: `${100 - (width * (j + 1))}%`,
bottom: (100 - (height * (i + 1))) + "%" bottom: `${100 - (height * (i + 1))}%`,
}); });
this.addWidget(this._getChildName(i + "_" + j), els[i][j]); this.addWidget(this._getChildName(`${i}_${j}`), els[i][j]);
}
} }
} }
},
resize: function () { resize() {
// console.log("grid布局不需要resize") // console.log("grid布局不需要resize")
}, }
update: function (opt) { update(opt) {
return this.forceUpdate(opt); return this.forceUpdate(opt);
}, }
populate: function (items) { populate(...args) {
BI.GridLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.grid", BI.GridLayout);

14
src/core/wrapper/layout/layout.horizontal.js

@ -1,8 +1,6 @@
/** import { shortcut } from "../../decorator";
* 水平布局
* @class BI.HorizontalLayout @shortcut()
* @extends BI.Layout export class HorizontalLayout {
*/ static xtype = "bi.horizontal";
BI.HorizontalLayout = function () { }
};
BI.shortcut("bi.horizontal", BI.HorizontalLayout);

91
src/core/wrapper/layout/layout.inline.js

@ -1,19 +1,26 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction, isNull } from "../../2.base";
import { pixFormat, HorizontalAlign, VerticalAlign } from "../../constant";
/** /**
* 内联布局 * 内联布局
* @class BI.InlineLayout * @class InlineLayout
* @extends BI.Layout * @extends Layout
* *
* @cfg {JSON} options 配置属性 * @cfg {JSON} options 配置属性
* @cfg {Number} [hgap=0] 水平间隙 * @cfg {Number} [hgap=0] 水平间隙
* @cfg {Number} [vgap=0] 垂直间隙 * @cfg {Number} [vgap=0] 垂直间隙
*/ */
BI.InlineLayout = BI.inherit(BI.Layout, { @shortcut()
export class InlineLayout extends Layout {
static xtype = "bi.inline";
props: function () { props() {
return BI.extend(BI.InlineLayout.superclass.props.apply(this, arguments), { return extend(super.props(...arguments), {
baseCls: "bi-i", baseCls: "bi-i",
horizontalAlign: BI.HorizontalAlign.Left, horizontalAlign: HorizontalAlign.Left,
verticalAlign: BI.VerticalAlign.Top, verticalAlign: VerticalAlign.Top,
columnSize: [], columnSize: [],
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
@ -21,80 +28,80 @@ BI.InlineLayout = BI.inherit(BI.Layout, {
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
items: [] items: [],
}); });
}, }
render: function () { render() {
BI.InlineLayout.superclass.render.apply(this, arguments); super.render(...arguments);
var self = this, o = this.options; const o = this.options;
this.element.css({ this.element.css({
textAlign: o.horizontalAlign textAlign: o.horizontalAlign,
}); });
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (i, item) { _addElement(i, item) {
var o = this.options; const o = this.options;
var w = BI.InlineLayout.superclass._addElement.apply(this, arguments); const w = super._addElement(...arguments);
var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width; let columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width;
if (o.columnSize.length > 0) { if (o.columnSize.length > 0) {
if (item.width >= 1 && o.columnSize[i] >= 1 && o.columnSize[i] !== item.width) { if (item.width >= 1 && o.columnSize[i] >= 1 && o.columnSize[i] !== item.width) {
columnSize = null; columnSize = null;
} }
} }
if (columnSize > 0) { if (columnSize > 0) {
w.element.width(columnSize < 1 ? ((columnSize * 100).toFixed(1) + "%") : BI.pixFormat(columnSize)); w.element.width(columnSize < 1 ? (`${(columnSize * 100).toFixed(1)}%`) : pixFormat(columnSize));
} }
w.element.css({ w.element.css({
position: "relative", position: "relative",
"vertical-align": o.verticalAlign "vertical-align": o.verticalAlign,
}); });
w.element.addClass("i-item"); w.element.addClass("i-item");
if (columnSize === "fill" || columnSize === "") { if (columnSize === "fill" || columnSize === "") {
var length = 0, gap = o.hgap + o.innerHgap; let length = 0, gap = o.hgap + o.innerHgap;
var fillCount = 0, autoCount = 0; let fillCount = 0, autoCount = 0;
for (var k = 0, len = o.columnSize.length || o.items.length; k < len; k++) { for (let k = 0, len = o.columnSize.length || o.items.length; k < len; k++) {
var cz = o.columnSize.length > 0 ? o.columnSize[k] : o.items[k].width; let cz = o.columnSize.length > 0 ? o.columnSize[k] : o.items[k].width;
if (cz === "fill") { if (cz === "fill") {
fillCount++; fillCount++;
cz = 0; cz = 0;
} else if (cz === "" || BI.isNull(cz)) { } else if (cz === "" || isNull(cz)) {
autoCount++; autoCount++;
cz = 0; cz = 0;
} }
gap += o.hgap + o.lgap + o.rgap + this._optimiseItemLgap(o.items[k]) + this._optimiseItemRgap(o.items[k]) + this._optimiseItemHgap(o.items[k]); gap += o.hgap + o.lgap + o.rgap + this._optimiseItemLgap(o.items[k]) + this._optimiseItemRgap(o.items[k]) + this._optimiseItemHgap(o.items[k]);
length += cz; length += cz;
} }
length = length > 0 && length < 1 ? (length * 100).toFixed(1) + "%" : BI.pixFormat(length); length = length > 0 && length < 1 ? `${(length * 100).toFixed(1)}%` : pixFormat(length);
gap = gap > 0 && gap < 1 ? (gap * 100).toFixed(1) + "%" : BI.pixFormat(gap); gap = gap > 0 && gap < 1 ? `${(gap * 100).toFixed(1)}%` : pixFormat(gap);
if (columnSize === "fill") { if (columnSize === "fill") {
w.element.css("min-width", "calc((100% - " + length + " - " + gap + ")" + (fillCount > 1 ? "/" + fillCount : "") + ")"); w.element.css("min-width", `calc((100% - ${length} - ${gap})${fillCount > 1 ? `/${fillCount}` : ""})`);
} }
if (o.horizontalAlign === BI.HorizontalAlign.Stretch || !(o.scrollable === true || o.scrollx === true)) { if (o.horizontalAlign === HorizontalAlign.Stretch || !(o.scrollable === true || o.scrollx === true)) {
if (columnSize === "fill") { if (columnSize === "fill") {
w.element.css("max-width", "calc((100% - " + length + " - " + gap + ")" + (fillCount > 1 ? "/" + fillCount : "") + ")"); w.element.css("max-width", `calc((100% - ${length} - ${gap})${fillCount > 1 ? `/${fillCount}` : ""})`);
} else { } else {
w.element.css("max-width", "calc((100% - " + length + " - " + gap + ")" + (autoCount > 1 ? "/" + autoCount : "") + ")"); w.element.css("max-width", `calc((100% - ${length} - ${gap})${autoCount > 1 ? `/${autoCount}` : ""})`);
} }
} }
} }
this._handleGap(w, item, i); this._handleGap(w, item, i);
if (o.verticalAlign === BI.VerticalAlign.Stretch && BI.isNull(item.height)) { if (o.verticalAlign === VerticalAlign.Stretch && isNull(item.height)) {
var top = o.innerVgap + o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item), const top = o.innerVgap + o.vgap + o.tgap + this._optimiseItemTgap(item) + this._optimiseItemVgap(item),
bottom = o.innerVgap + o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item); bottom = o.innerVgap + o.vgap + o.bgap + this._optimiseItemBgap(item) + this._optimiseItemVgap(item);
var gap = (top + bottom) > 0 && (top + bottom) < 1 ? ((top + bottom) * 100).toFixed(1) + "%" : BI.pixFormat(top + bottom); const gap = (top + bottom) > 0 && (top + bottom) < 1 ? `${((top + bottom) * 100).toFixed(1)}%` : pixFormat(top + bottom);
w.element.css("height", "calc(100% - " + gap + ")"); w.element.css("height", `calc(100% - ${gap})`);
} }
return w; return w;
}, }
populate: function (items) { populate(...args) {
BI.InlineLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.inline", BI.InlineLayout);

55
src/core/wrapper/layout/layout.lattice.js

@ -1,43 +1,52 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction, sum } from "../../2.base";
/** /**
* 靠左对齐的自由浮动布局 * 靠左对齐的自由浮动布局
* @class BI.LatticeLayout * @class LatticeLayout
* @extends BI.Layout * @extends Layout
* *
* @cfg {JSON} options 配置属性 * @cfg {JSON} options 配置属性
* @cfg {Number} [hgap=0] 水平间隙 * @cfg {Number} [hgap=0] 水平间隙
* @cfg {Number} [vgap=0] 垂直间隙 * @cfg {Number} [vgap=0] 垂直间隙
*/ */
BI.LatticeLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class LatticeLayout extends Layout {
return BI.extend(BI.LatticeLayout.superclass.props.apply(this, arguments), { static xtype = "bi.lattice";
baseCls: "bi-lattice clearfix"
props() {
return extend(super.props(...arguments), {
baseCls: "bi-lattice clearfix",
// columnSize: [0.2, 0.2, 0.6], // columnSize: [0.2, 0.2, 0.6],
}); });
}, }
render: function () {
BI.LatticeLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const self = this, o = this.options;
const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); self.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (i, item) { _addElement(i, item) {
var o = this.options; const o = this.options;
var w = BI.LatticeLayout.superclass._addElement.apply(this, arguments); const w = super._addElement(...arguments);
let width;
if (o.columnSize && o.columnSize[i]) { if (o.columnSize && o.columnSize[i]) {
var width = o.columnSize[i] / BI.sum(o.columnSize) * 100 + "%"; width = `${o.columnSize[i] / sum(o.columnSize) * 100}%`;
} else { } else {
var width = 1 / this.options.items.length * 100 + "%"; width = `${1 / this.options.items.length * 100}%`;
} }
w.element.css({position: "relative", float: "left", width: width}); w.element.css({ position: "relative", "float": "left", width });
return w; return w;
}, }
populate: function (items) { populate(...args) {
BI.LatticeLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.lattice", BI.LatticeLayout);

85
src/core/wrapper/layout/layout.table.js

@ -1,36 +1,46 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction, range, isArray, map, reduce, isEmpty, formatEL } from "../../2.base";
import { Widget } from "../../4.widget";
import { HorizontalAlign, VerticalAlign } from "../../constant";
/** /**
* 上下的高度固定/左右的宽度固定中间的高度/宽度自适应 * 上下的高度固定/左右的宽度固定中间的高度/宽度自适应
* *
* @class BI.TableLayout * @class TableLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.TableLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class TableLayout extends Layout {
return BI.extend(BI.TableLayout.superclass.props.apply(this, arguments), { static xtype = "bi.table";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-t", baseCls: "bi-t",
// scrolly: true, // scrolly: true,
columnSize: [], columnSize: [],
rowSize: [], rowSize: [],
horizontalAlign: BI.HorizontalAlign.Stretch, horizontalAlign: HorizontalAlign.Stretch,
verticalAlign: BI.VerticalAlign.Stretch, verticalAlign: VerticalAlign.Stretch,
// rowSize: 30, // or [30,30,30] // rowSize: 30, // or [30,30,30]
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
items: [], items: [],
}); });
}, }
render: function () {
BI.TableLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const o = this.options;
self.populate(newValue); const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
this.populate(newValue);
}) : o.items; }) : o.items;
var columnSize = o.columnSize.length > 0 ? o.columnSize : BI.range(items[0].length).fill(""); const columnSize = o.columnSize.length > 0 ? o.columnSize : range(items[0].length).fill("");
if (columnSize.length > 0) { if (columnSize.length > 0) {
var template = []; const template = [];
for (var i = 0; i < columnSize.length; i++) { for (let i = 0; i < columnSize.length; i++) {
if (columnSize[i] === "") { if (columnSize[i] === "") {
template.push("auto"); template.push("auto");
} else if (columnSize[i] === "fill") { } else if (columnSize[i] === "fill") {
@ -41,9 +51,7 @@ BI.TableLayout = BI.inherit(BI.Layout, {
} }
this.element.css({ this.element.css({
"grid-template-columns": template.join(" "), "grid-template-columns": template.join(" "),
"grid-template-rows": BI.isArray(o.rowSize) ? BI.map(o.rowSize, function (i, size) { "grid-template-rows": isArray(o.rowSize) ? map(o.rowSize, (i, size) => this._optimiseGap(size)).join(" ") : range(o.items.length).fill(this._optimiseGap(o.rowSize)).join(" "),
return self._optimiseGap(size);
}).join(" ") : BI.range(o.items.length).fill(this._optimiseGap(o.rowSize)).join(" "),
"grid-row-gap": this._optimiseGap(o.vgap), "grid-row-gap": this._optimiseGap(o.vgap),
"grid-column-gap": this._optimiseGap(o.hgap), "grid-column-gap": this._optimiseGap(o.hgap),
}); });
@ -51,15 +59,15 @@ BI.TableLayout = BI.inherit(BI.Layout, {
return { return {
type: "bi.default", type: "bi.default",
ref: function (_ref) { ref(_ref) {
self.layout = _ref; this.layout = _ref;
}, },
items: this._formatItems(items), items: this._formatItems(items),
}; };
}, }
_formatItems: function (items) { _formatItems(items) {
var o = this.options, self = this; const o = this.options;
function firstElement (item, cls) { function firstElement (item, cls) {
item.addClass(cls); item.addClass(cls);
@ -74,9 +82,9 @@ BI.TableLayout = BI.inherit(BI.Layout, {
} }
function first (item, cls) { function first (item, cls) {
if (item instanceof BI.Widget) { if (item instanceof Widget) {
return firstElement(item.element, cls); return firstElement(item.element, cls);
} else if (item.el instanceof BI.Widget) { } else if (item.el instanceof Widget) {
return firstElement(item.el.element, cls); return firstElement(item.el.element, cls);
} else if (item.el) { } else if (item.el) {
return firstObject(item.el, cls); return firstObject(item.el, cls);
@ -91,30 +99,27 @@ BI.TableLayout = BI.inherit(BI.Layout, {
columnSize: ["fill"], columnSize: ["fill"],
horizontalAlign: o.horizontalAlign, horizontalAlign: o.horizontalAlign,
verticalAlign: o.verticalAlign, verticalAlign: o.verticalAlign,
items: [BI.formatEL(item)], items: [formatEL(item)],
}; };
} }
return BI.reduce(items, function (rowItems, result, rowIndex) { return reduce(items, (rowItems, result, rowIndex) => result.concat(map(rowItems, (colIndex, item) => {
return result.concat(BI.map(rowItems, function (colIndex, item) { const cls = this.getRowColumnCls(rowIndex, colIndex, items.length - 1, rowItems.length - 1);
var cls = self.getRowColumnCls(rowIndex, colIndex, items.length - 1, rowItems.length - 1); if (isEmpty(item)) {
if (BI.isEmpty(item)) {
return first(wrapLayout({ return first(wrapLayout({
type: "bi.layout", type: "bi.layout",
}), cls); }), cls);
} }
return first(wrapLayout(item), cls); return first(wrapLayout(item), cls);
})); })), []);
}, []); }
},
resize: function () { resize() {
// console.log("table布局不需要resize"); // console.log("table布局不需要resize");
}, }
populate: function (items) { populate(items) {
this.layout.populate(this._formatItems(items)); this.layout.populate(this._formatItems(items));
}, }
}); }
BI.shortcut("bi.table", BI.TableLayout);

246
src/core/wrapper/layout/layout.tape.js

@ -1,13 +1,22 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction, compact, each, isEmptyObject, isNumber, isNull, any, backAny } from "../../2.base";
import { _lazyCreateWidget } from "../../5.inject";
import { HorizontalAlign, VerticalAlign } from "../../constant";
/** /**
* 水平tape布局 * 水平tape布局
* @class BI.HTapeLayout * @class HTapeLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.HTapeLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class HTapeLayout extends Layout {
return BI.extend(BI.HTapeLayout.superclass.props.apply(this, arguments), { static xtype = "bi.htape";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-h-tape", baseCls: "bi-h-tape",
verticalAlign: BI.VerticalAlign.Top, verticalAlign: VerticalAlign.Top,
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
@ -15,37 +24,39 @@ BI.HTapeLayout = BI.inherit(BI.Layout, {
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
columnSize: [], columnSize: [],
items: [] items: [],
}); });
}, }
render: function () {
BI.HTapeLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const o = this.options;
self.populate(newValue); const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
addItem: function (item) { addItem(item) {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
stroke: function (items) { stroke(items) {
var self = this, o = this.options; const o = this.options;
items = BI.compact(items); items = compact(items);
BI.each(items, function (i, item) { each(items, (i, item) => {
if (BI.isEmptyObject(item)) { let w;
if (isEmptyObject(item)) {
return; return;
} }
if (!self.hasWidget(self._getChildName(i))) { if (!this.hasWidget(this._getChildName(i))) {
var w = BI._lazyCreateWidget(item); w = _lazyCreateWidget(item);
self.addWidget(self._getChildName(i), w); this.addWidget(this._getChildName(i), w);
} else { } else {
w = self.getWidgetByName(self._getChildName(i)); w = this.getWidgetByName(this._getChildName(i));
} }
var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width; let columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width;
if (o.columnSize.length > 0) { if (o.columnSize.length > 0) {
if (item.width >= 1 && o.columnSize[i] >= 1 && o.columnSize[i] !== item.width) { if (item.width >= 1 && o.columnSize[i] >= 1 && o.columnSize[i] !== item.width) {
columnSize = item.width; columnSize = item.width;
@ -53,90 +64,92 @@ BI.HTapeLayout = BI.inherit(BI.Layout, {
} }
w.element.css({ w.element.css({
position: "absolute", position: "absolute",
top: self._optimiseGap(self._optimiseItemTgap(item) + self._optimiseItemVgap(item) + o.innerVgap + o.vgap + o.tgap), top: this._optimiseGap(this._optimiseItemTgap(item) + this._optimiseItemVgap(item) + o.innerVgap + o.vgap + o.tgap),
bottom: self._optimiseGap(self._optimiseItemBgap(item) + self._optimiseItemVgap(item) + o.innerVgap + o.vgap + o.bgap), bottom: this._optimiseGap(this._optimiseItemBgap(item) + this._optimiseItemVgap(item) + o.innerVgap + o.vgap + o.bgap),
width: BI.isNumber(columnSize) ? self._optimiseGap(columnSize) : "" width: isNumber(columnSize) ? this._optimiseGap(columnSize) : "",
}); });
if (o.verticalAlign === BI.VerticalAlign.Middle) { if (o.verticalAlign === VerticalAlign.Middle) {
w.element.css({ w.element.css({
marginTop: "auto", marginTop: "auto",
marginBottom: "auto" marginBottom: "auto",
}); });
} else if (o.verticalAlign === BI.VerticalAlign.Bottom) { } else if (o.verticalAlign === VerticalAlign.Bottom) {
w.element.css({ w.element.css({
marginTop: "auto" marginTop: "auto",
}); });
} }
}); });
var left = {}, right = {}; const left = {}, right = {};
left[0] = o.innerHgap; left[0] = o.innerHgap;
right[items.length - 1] = o.innerHgap; right[items.length - 1] = o.innerHgap;
BI.any(items, function (i, item) { any(items, (i, item) => {
if (BI.isEmptyObject(item)) { if (isEmptyObject(item)) {
return true; return true;
} }
var w = self.getWidgetByName(self._getChildName(i)); const w = this.getWidgetByName(this._getChildName(i));
var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width; let columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width;
if (o.columnSize.length > 0) { if (o.columnSize.length > 0) {
if (item.width >= 1 && o.columnSize[i] >= 1 && o.columnSize[i] !== item.width) { if (item.width >= 1 && o.columnSize[i] >= 1 && o.columnSize[i] !== item.width) {
columnSize = item.width; columnSize = item.width;
} }
} }
if (BI.isNull(left[i])) { if (isNull(left[i])) {
var preColumnSize = o.columnSize.length > 0 ? o.columnSize[i - 1] : items[i - 1].width; const preColumnSize = o.columnSize.length > 0 ? o.columnSize[i - 1] : items[i - 1].width;
left[i] = left[i - 1] + preColumnSize + self._optimiseItemLgap(items[i - 1]) + self._optimiseItemRgap(items[i - 1]) + 2 * self._optimiseItemHgap(items[i - 1]) + o.hgap + o.lgap + o.rgap; left[i] = left[i - 1] + preColumnSize + this._optimiseItemLgap(items[i - 1]) + this._optimiseItemRgap(items[i - 1]) + 2 * this._optimiseItemHgap(items[i - 1]) + o.hgap + o.lgap + o.rgap;
} }
w.element.css({ w.element.css({
left: self._optimiseGap(left[i] + self._optimiseItemLgap(item) + self._optimiseItemHgap(item) + o.hgap + o.lgap) left: this._optimiseGap(left[i] + this._optimiseItemLgap(item) + this._optimiseItemHgap(item) + o.hgap + o.lgap),
}); });
if (BI.isNull(columnSize) || columnSize === "" || columnSize === "fill") { if (isNull(columnSize) || columnSize === "" || columnSize === "fill") {
return true; return true;
} }
}); });
BI.backAny(items, function (i, item) { backAny(items, (i, item) => {
if (BI.isEmptyObject(item)) { if (isEmptyObject(item)) {
return true; return true;
} }
var w = self.getWidgetByName(self._getChildName(i)); const w = this.getWidgetByName(this._getChildName(i));
var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width; const columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width;
if (BI.isNull(right[i])) { if (isNull(right[i])) {
var nextColumnSize = o.columnSize.length > 0 ? o.columnSize[i + 1] : items[i + 1].width; const nextColumnSize = o.columnSize.length > 0 ? o.columnSize[i + 1] : items[i + 1].width;
right[i] = right[i + 1] + nextColumnSize + self._optimiseItemLgap(items[i + 1]) + self._optimiseItemRgap(items[i + 1]) + 2 * self._optimiseItemHgap(items[i + 1]) + o.hgap + o.lgap + o.rgap; right[i] = right[i + 1] + nextColumnSize + this._optimiseItemLgap(items[i + 1]) + this._optimiseItemRgap(items[i + 1]) + 2 * this._optimiseItemHgap(items[i + 1]) + o.hgap + o.lgap + o.rgap;
} }
w.element.css({ w.element.css({
right: self._optimiseGap(right[i] + self._optimiseItemRgap(item) + self._optimiseItemHgap(item) + o.hgap + o.rgap) right: this._optimiseGap(right[i] + this._optimiseItemRgap(item) + this._optimiseItemHgap(item) + o.hgap + o.rgap),
}); });
if (BI.isNull(columnSize) || columnSize === "" || columnSize === "fill") { if (isNull(columnSize) || columnSize === "" || columnSize === "fill") {
return true; return true;
} }
}); });
}, }
update: function (opt) { update(opt) {
return this.forceUpdate(opt); return this.forceUpdate(opt);
}, }
populate: function (items) { populate(items) {
BI.HTapeLayout.superclass.populate.apply(this, arguments); super.populate(...arguments);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.htape", BI.HTapeLayout);
/** /**
* 垂直tape布局 * 垂直tape布局
* @class BI.VTapeLayout * @class VTapeLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.VTapeLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class VTapeLayout extends Layout {
return BI.extend(BI.VTapeLayout.superclass.props.apply(this, arguments), { static xtype = "bi.vtape";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-v-tape", baseCls: "bi-v-tape",
horizontalAlign: BI.HorizontalAlign.Left, horizontalAlign: HorizontalAlign.Left,
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
@ -144,33 +157,35 @@ BI.VTapeLayout = BI.inherit(BI.Layout, {
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
rowSize: [], rowSize: [],
items: [] items: [],
}); });
}, }
render: function () {
BI.VTapeLayout.superclass.render.apply(this, arguments); render() {
super.render(...arguments);
this.populate(this.options.items); this.populate(this.options.items);
}, }
addItem: function (item) { addItem(item) {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
stroke: function (items) { stroke(items) {
var self = this, o = this.options; const o = this.options;
items = BI.compact(items); items = compact(items);
BI.each(items, function (i, item) { each(items, (i, item) => {
if (BI.isEmptyObject(item)) { let w;
if (isEmptyObject(item)) {
return; return;
} }
if (!self.hasWidget(self._getChildName(i))) { if (!this.hasWidget(this._getChildName(i))) {
var w = BI._lazyCreateWidget(item); w = _lazyCreateWidget(item);
self.addWidget(self._getChildName(i), w); this.addWidget(this._getChildName(i), w);
} else { } else {
w = self.getWidgetByName(self._getChildName(i)); w = this.getWidgetByName(this._getChildName(i));
} }
var rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height; let rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height;
if (o.rowSize.length > 0) { if (o.rowSize.length > 0) {
if (item.height >= 1 && o.rowSize[i] >= 1 && o.rowSize[i] !== item.height) { if (item.height >= 1 && o.rowSize[i] >= 1 && o.rowSize[i] !== item.height) {
rowSize = item.height; rowSize = item.height;
@ -178,76 +193,75 @@ BI.VTapeLayout = BI.inherit(BI.Layout, {
} }
w.element.css({ w.element.css({
position: "absolute", position: "absolute",
left: self._optimiseGap(self._optimiseItemLgap(item) + self._optimiseItemHgap(item) + o.innerHgap + o.hgap + o.lgap), left: this._optimiseGap(this._optimiseItemLgap(item) + this._optimiseItemHgap(item) + o.innerHgap + o.hgap + o.lgap),
right: self._optimiseGap(self._optimiseItemRgap(item) + self._optimiseItemHgap(item) + o.innerHgap + o.hgap + o.rgap), right: this._optimiseGap(this._optimiseItemRgap(item) + this._optimiseItemHgap(item) + o.innerHgap + o.hgap + o.rgap),
height: BI.isNumber(rowSize) ? self._optimiseGap(rowSize) : "" height: isNumber(rowSize) ? this._optimiseGap(rowSize) : "",
}); });
if (o.horizontalAlign === BI.HorizontalAlign.Center) { if (o.horizontalAlign === HorizontalAlign.Center) {
w.element.css({ w.element.css({
marginLeft: "auto", marginLeft: "auto",
marginRight: "auto" marginRight: "auto",
}); });
} else if (o.horizontalAlign === BI.HorizontalAlign.Right) { } else if (o.horizontalAlign === HorizontalAlign.Right) {
w.element.css({ w.element.css({
marginLeft: "auto" marginLeft: "auto",
}); });
} }
}); });
var top = {}, bottom = {}; const top = {}, bottom = {};
top[0] = o.innerVgap; top[0] = o.innerVgap;
bottom[items.length - 1] = o.innerVgap; bottom[items.length - 1] = o.innerVgap;
BI.any(items, function (i, item) { any(items, (i, item) => {
if (BI.isEmptyObject(item)) { if (isEmptyObject(item)) {
return true; return true;
} }
var w = self.getWidgetByName(self._getChildName(i)); const w = this.getWidgetByName(this._getChildName(i));
var rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height; let rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height;
if (o.rowSize.length > 0) { if (o.rowSize.length > 0) {
if (item.height >= 1 && o.rowSize[i] >= 1 && o.rowSize[i] !== item.height) { if (item.height >= 1 && o.rowSize[i] >= 1 && o.rowSize[i] !== item.height) {
rowSize = item.height; rowSize = item.height;
} }
} }
if (BI.isNull(top[i])) { if (isNull(top[i])) {
var preRowSize = o.rowSize.length > 0 ? o.rowSize[i - 1] : items[i - 1].height; const preRowSize = o.rowSize.length > 0 ? o.rowSize[i - 1] : items[i - 1].height;
top[i] = top[i - 1] + preRowSize + self._optimiseItemTgap(items[i - 1]) + self._optimiseItemBgap(items[i - 1]) + 2 * self._optimiseItemVgap(items[i - 1]) + o.vgap + o.tgap + o.bgap; top[i] = top[i - 1] + preRowSize + this._optimiseItemTgap(items[i - 1]) + this._optimiseItemBgap(items[i - 1]) + 2 * this._optimiseItemVgap(items[i - 1]) + o.vgap + o.tgap + o.bgap;
} }
w.element.css({ w.element.css({
top: self._optimiseGap(top[i] + self._optimiseItemTgap(item) + self._optimiseItemVgap(item) + o.vgap + o.tgap) top: this._optimiseGap(top[i] + this._optimiseItemTgap(item) + this._optimiseItemVgap(item) + o.vgap + o.tgap),
}); });
if (BI.isNull(rowSize) || rowSize === "" || rowSize === "fill") { if (isNull(rowSize) || rowSize === "" || rowSize === "fill") {
return true; return true;
} }
}); });
BI.backAny(items, function (i, item) { backAny(items, (i, item) => {
if (BI.isEmptyObject(item)) { if (isEmptyObject(item)) {
return true; return true;
} }
var w = self.getWidgetByName(self._getChildName(i)); const w = this.getWidgetByName(this._getChildName(i));
var rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height; const rowSize = o.rowSize.length > 0 ? o.rowSize[i] : item.height;
if (BI.isNull(bottom[i])) { if (isNull(bottom[i])) {
var nextRowSize = o.rowSize.length > 0 ? o.rowSize[i + 1] : items[i + 1].height; const nextRowSize = o.rowSize.length > 0 ? o.rowSize[i + 1] : items[i + 1].height;
bottom[i] = bottom[i + 1] + nextRowSize + self._optimiseItemTgap(items[i + 1]) + self._optimiseItemBgap(items[i + 1]) + 2 * self._optimiseItemVgap(items[i + 1]) + o.vgap + o.tgap + o.bgap; bottom[i] = bottom[i + 1] + nextRowSize + this._optimiseItemTgap(items[i + 1]) + this._optimiseItemBgap(items[i + 1]) + 2 * this._optimiseItemVgap(items[i + 1]) + o.vgap + o.tgap + o.bgap;
} }
w.element.css({ w.element.css({
bottom: self._optimiseGap(bottom[i] + self._optimiseItemBgap(item) + self._optimiseItemVgap(item) + o.vgap + o.bgap) bottom: this._optimiseGap(bottom[i] + this._optimiseItemBgap(item) + this._optimiseItemVgap(item) + o.vgap + o.bgap),
}); });
if (BI.isNull(rowSize) || rowSize === "" || rowSize === "fill") { if (isNull(rowSize) || rowSize === "" || rowSize === "fill") {
return true; return true;
} }
}); });
}, }
update: function (opt) { update(opt) {
return this.forceUpdate(opt); return this.forceUpdate(opt);
}, }
populate: function (items) { populate(...args) {
BI.VTapeLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.vtape", BI.VTapeLayout);

132
src/core/wrapper/layout/layout.td.js

@ -1,45 +1,56 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction, isOdd, some, isNumber, isNull } from "../../2.base";
import { Widget } from "../../4.widget";
import { _lazyCreateWidget } from "../../5.inject";
import { HorizontalAlign, VerticalAlign } from "../../constant";
/** /**
* td布局 * td布局
* @class BI.TdLayout * @class TdLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.TdLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class TdLayout extends Layout {
return BI.extend(BI.TdLayout.superclass.props.apply(this, arguments), { static xtype = "bi.td";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-td", baseCls: "bi-td",
columnSize: [], columnSize: [],
rowSize: [], rowSize: [],
verticalAlign: BI.VerticalAlign.Middle, verticalAlign: VerticalAlign.Middle,
horizontalAlign: BI.HorizontalAlign.Stretch, horizontalAlign: HorizontalAlign.Stretch,
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
items: [] items: [],
}); });
}, }
render: function () {
BI.TdLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
this.$table = BI.Widget._renderEngine.createElement("<table>").attr({cellspacing: 0, cellpadding: 0}).css({ const o = this.options;
this.$table = Widget._renderEngine.createElement("<table>").attr({ cellspacing: 0, cellpadding: 0 }).css({
position: "relative", position: "relative",
width: (o.horizontalAlign === BI.HorizontalAlign.Center || o.horizontalAlign === BI.HorizontalAlign.Stretch) ? "100%" : "auto", width: (o.horizontalAlign === HorizontalAlign.Center || o.horizontalAlign === HorizontalAlign.Stretch) ? "100%" : "auto",
height: (o.verticalAlign !== BI.VerticalAlign.Top) ? "100%" : "auto", height: (o.verticalAlign !== VerticalAlign.Top) ? "100%" : "auto",
"border-spacing": "0px", "border-spacing": "0px",
border: "none", border: "none",
"border-collapse": "separate" "border-collapse": "separate",
}); });
this.rows = 0; this.rows = 0;
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
self.populate(newValue); this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (idx, arr) { _addElement(idx, arr) {
var o = this.options; const o = this.options;
function firstElement (item, row, col) { function firstElement (item, row, col) {
if (row === 0) { if (row === 0) {
@ -48,28 +59,28 @@ BI.TdLayout = BI.inherit(BI.Layout, {
if (col === 0) { if (col === 0) {
item.addClass("first-col"); item.addClass("first-col");
} }
item.addClass(BI.isOdd(row + 1) ? "odd-row" : "even-row"); item.addClass(isOdd(row + 1) ? "odd-row" : "even-row");
item.addClass(BI.isOdd(col + 1) ? "odd-col" : "even-col"); item.addClass(isOdd(col + 1) ? "odd-col" : "even-col");
item.addClass("center-element"); item.addClass("center-element");
} }
function firstObject (item, row, col) { function firstObject (item, row, col) {
var cls = ""; let cls = "";
if (row === 0) { if (row === 0) {
cls += " first-row"; cls += " first-row";
} }
if (col === 0) { if (col === 0) {
cls += " first-col"; cls += " first-col";
} }
BI.isOdd(row + 1) ? (cls += " odd-row") : (cls += " even-row"); isOdd(row + 1) ? (cls += " odd-row") : (cls += " even-row");
BI.isOdd(col + 1) ? (cls += " odd-col") : (cls += " even-col"); isOdd(col + 1) ? (cls += " odd-col") : (cls += " even-col");
item.cls = (item.cls || "") + cls + " center-element"; item.cls = `${(item.cls || "") + cls} center-element`;
} }
function first (item, row, col) { function first (item, row, col) {
if (item instanceof BI.Widget) { if (item instanceof Widget) {
firstElement(item.element, row, col); firstElement(item.element, row, col);
} else if (item.el instanceof BI.Widget) { } else if (item.el instanceof Widget) {
firstElement(item.el.element, row, col); firstElement(item.el.element, row, col);
} else if (item.el) { } else if (item.el) {
firstObject(item.el, row, col); firstObject(item.el, row, col);
@ -78,30 +89,30 @@ BI.TdLayout = BI.inherit(BI.Layout, {
} }
} }
var height = BI.isNumber(o.rowSize) ? this._optimiseGap(o.rowSize) : (o.rowSize[idx] === "" ? this._optimiseGap(1) : this._optimiseGap(o.rowSize[idx])); const height = isNumber(o.rowSize) ? this._optimiseGap(o.rowSize) : (o.rowSize[idx] === "" ? this._optimiseGap(1) : this._optimiseGap(o.rowSize[idx]));
var tr = BI._lazyCreateWidget({ const tr = _lazyCreateWidget({
type: "bi.default", type: "bi.default",
tagName: "tr", tagName: "tr",
height: height, height,
css: { css: {
"max-height": height, "max-height": height,
"min-height": height "min-height": height,
} },
}); });
for (var i = 0; i < arr.length; i++) { for (let i = 0; i < arr.length; i++) {
var w = BI._lazyCreateWidget(arr[i]); const w = _lazyCreateWidget(arr[i]);
if (o.verticalAlign === BI.VerticalAlign.Stretch) { if (o.verticalAlign === VerticalAlign.Stretch) {
var top = o.vgap + o.tgap + this._optimiseItemTgap(arr[i]) + this._optimiseItemVgap(arr[i]), const top = o.vgap + o.tgap + this._optimiseItemTgap(arr[i]) + this._optimiseItemVgap(arr[i]),
bottom = o.vgap + o.bgap + this._optimiseItemBgap(arr[i]) + this._optimiseItemVgap(arr[i]); bottom = o.vgap + o.bgap + this._optimiseItemBgap(arr[i]) + this._optimiseItemVgap(arr[i]);
w.element.css("height", "calc(100% - " + this._optimiseGap(top + bottom) + ")"); w.element.css("height", `calc(100% - ${this._optimiseGap(top + bottom)})`);
} }
w.element.css({ position: "relative", top: "0", left: "0", margin: "0px auto" }); w.element.css({ position: "relative", top: "0", left: "0", margin: "0px auto" });
var item = arr[i]; const item = arr[i];
this._handleGap(w, item, i); this._handleGap(w, item, i);
first(w, this.rows++, i); first(w, this.rows++, i);
var width = ""; let width = "";
var columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width; const columnSize = o.columnSize.length > 0 ? o.columnSize[i] : item.width;
if (columnSize > 0) { if (columnSize > 0) {
width = this._optimiseGap(columnSize + (i === 0 ? o.hgap : 0) + o.hgap + o.lgap + o.rgap); width = this._optimiseGap(columnSize + (i === 0 ? o.hgap : 0) + o.hgap + o.lgap + o.rgap);
} }
@ -109,20 +120,21 @@ BI.TdLayout = BI.inherit(BI.Layout, {
if (o.columnSize.length > 0) { if (o.columnSize.length > 0) {
return o.columnSize.indexOf("fill") >= 0; return o.columnSize.indexOf("fill") >= 0;
} }
return BI.some(arr, function (i, item) {
return some(arr, (i, item) => {
if (item.width === "fill") { if (item.width === "fill") {
return true; return true;
} }
}); });
} }
if ((BI.isNull(columnSize) || columnSize === "") && hasFill()) { if ((isNull(columnSize) || columnSize === "") && hasFill()) {
width = 2; width = 2;
} }
var td = BI._lazyCreateWidget({ const td = _lazyCreateWidget({
type: "bi.default", type: "bi.default",
width: width, width,
tagName: "td", tagName: "td",
items: [w] items: [w],
}); });
// 对于表现为td的元素设置最大宽度,有几点需要注意 // 对于表现为td的元素设置最大宽度,有几点需要注意
// 1、由于直接对td设置最大宽度是在规范中未定义的, 所以要使用类似td:firstChild来迂回实现 // 1、由于直接对td设置最大宽度是在规范中未定义的, 所以要使用类似td:firstChild来迂回实现
@ -131,7 +143,7 @@ BI.TdLayout = BI.inherit(BI.Layout, {
if (columnSize > 0) { if (columnSize > 0) {
td.element.css({ td.element.css({
"max-width": width, "max-width": width,
"min-width": width "min-width": width,
}); });
} }
td.element.css({ td.element.css({
@ -139,30 +151,30 @@ BI.TdLayout = BI.inherit(BI.Layout, {
"vertical-align": o.verticalAlign, "vertical-align": o.verticalAlign,
margin: "0", margin: "0",
padding: "0", padding: "0",
border: "none" border: "none",
}); });
tr.addItem(td); tr.addItem(td);
} }
this.addWidget(this._getChildName(idx), tr); this.addWidget(this._getChildName(idx), tr);
return tr; return tr;
}, }
appendFragment: function (frag) { appendFragment(frag) {
this.$table.append(frag); this.$table.append(frag);
this.element.append(this.$table); this.element.append(this.$table);
}, }
resize: function () { resize() {
// console.log("td布局不需要resize"); // console.log("td布局不需要resize");
}, }
update: function (opt) { update(opt) {
return this.forceUpdate(opt); return this.forceUpdate(opt);
}, }
populate: function (items) { populate(...args) {
BI.TdLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.td", BI.TdLayout);

63
src/core/wrapper/layout/layout.vertical.js

@ -1,54 +1,63 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction } from "../../2.base";
import { HorizontalAlign } from "../../constant";
/** /**
* 垂直布局 * 垂直布局
* @class BI.VerticalLayout * @class VerticalLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.VerticalLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class VerticalLayout extends Layout {
return BI.extend(BI.VerticalLayout.superclass.props.apply(this, arguments), { static xtype = "bi.vertical";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-v", baseCls: "bi-v",
horizontalAlign: BI.HorizontalAlign.Stretch, horizontalAlign: HorizontalAlign.Stretch,
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
lgap: 0, lgap: 0,
rgap: 0, rgap: 0,
tgap: 0, tgap: 0,
bgap: 0, bgap: 0,
scrolly: true scrolly: true,
}); });
}, }
render: function () {
BI.VerticalLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const o = this.options;
self.populate(newValue); const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
_addElement: function (i, item) { _addElement(i, item) {
var o = this.options; const o = this.options;
var w = BI.VerticalLayout.superclass._addElement.apply(this, arguments); const w = super._addElement(...arguments);
w.element.css({ w.element.css({
position: "relative" position: "relative",
}); });
this._handleGap(w, item, null, i); this._handleGap(w, item, null, i);
if (o.horizontalAlign === BI.HorizontalAlign.Center) { if (o.horizontalAlign === HorizontalAlign.Center) {
w.element.css({ w.element.css({
marginLeft: "auto", marginLeft: "auto",
marginRight: "auto" marginRight: "auto",
}); });
} else if (o.horizontalAlign === BI.HorizontalAlign.Right) { } else if (o.horizontalAlign === HorizontalAlign.Right) {
w.element.css({ w.element.css({
marginLeft: "auto" marginLeft: "auto",
}); });
} }
return w; return w;
}, }
populate: function (items) { populate(...args) {
BI.VerticalLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.vertical", BI.VerticalLayout);

153
src/core/wrapper/layout/layout.window.js

@ -1,11 +1,20 @@
import { shortcut } from "../../decorator";
import { Layout } from "../layout";
import { extend, isFunction, makeArray, isNumber, isNull } from "../../2.base";
import { Widget } from "../../4.widget";
import { _lazyCreateWidget } from "../../5.inject";
/** /**
* *
* @class BI.WindowLayout * @class WindowLayout
* @extends BI.Layout * @extends Layout
*/ */
BI.WindowLayout = BI.inherit(BI.Layout, { @shortcut()
props: function () { export class WindowLayout extends Layout {
return BI.extend(BI.WindowLayout.superclass.props.apply(this, arguments), { static xtype = "bi.window";
props() {
return extend(super.props(...arguments), {
baseCls: "bi-window", baseCls: "bi-window",
columns: 3, columns: 3,
rows: 2, rows: 2,
@ -17,30 +26,31 @@ BI.WindowLayout = BI.inherit(BI.Layout, {
bgap: 0, bgap: 0,
columnSize: [], columnSize: [],
rowSize: [], rowSize: [],
items: [] items: [],
}); });
}, }
render: function () {
BI.WindowLayout.superclass.render.apply(this, arguments); render() {
var self = this, o = this.options; super.render(...arguments);
var items = BI.isFunction(o.items) ? this.__watch(o.items, function (context, newValue) { const o = this.options;
self.populate(newValue); const items = isFunction(o.items) ? this.__watch(o.items, (context, newValue) => {
this.populate(newValue);
}) : o.items; }) : o.items;
this.populate(items); this.populate(items);
}, }
addItem: function (item) { addItem(item) {
// do nothing // do nothing
throw new Error("不能添加子组件"); throw new Error("不能添加子组件");
}, }
stroke: function (items) { stroke(items) {
var o = this.options, self = this; const o = this.options;
if (BI.isNumber(o.rowSize)) { if (isNumber(o.rowSize)) {
o.rowSize = BI.makeArray(o.items.length, 1 / o.items.length); o.rowSize = makeArray(o.items.length, 1 / o.items.length);
} }
if (BI.isNumber(o.columnSize)) { if (isNumber(o.columnSize)) {
o.columnSize = BI.makeArray(o.items[0].length, 1 / o.items[0].length); o.columnSize = makeArray(o.items[0].length, 1 / o.items[0].length);
} }
function firstElement (item, cls) { function firstElement (item, cls) {
@ -56,9 +66,9 @@ BI.WindowLayout = BI.inherit(BI.Layout, {
} }
function first (item, row, col) { function first (item, row, col) {
if (item instanceof BI.Widget) { if (item instanceof Widget) {
firstElement(item.element, row, col); firstElement(item.element, row, col);
} else if (item.el instanceof BI.Widget) { } else if (item.el instanceof Widget) {
firstElement(item.el.element, row, col); firstElement(item.el.element, row, col);
} else if (item.el) { } else if (item.el) {
firstObject(item.el, row, col); firstObject(item.el, row, col);
@ -67,108 +77,111 @@ BI.WindowLayout = BI.inherit(BI.Layout, {
} }
} }
for (var i = 0; i < o.rows; i++) { for (let i = 0; i < o.rows; i++) {
for (var j = 0; j < o.columns; j++) { for (let j = 0; j < o.columns; j++) {
if (!o.items[i][j]) { if (!o.items[i][j]) {
throw new Error("构造错误", o.items); throw new Error("构造错误", o.items);
} }
if (!this.hasWidget(this._getChildName(i + "_" + j))) { if (!this.hasWidget(this._getChildName(`${i}_${j}`))) {
var w = BI._lazyCreateWidget(o.items[i][j]); const w = _lazyCreateWidget(o.items[i][j]);
w.element.css({ position: "absolute" }); w.element.css({ position: "absolute" });
this.addWidget(this._getChildName(i + "_" + j), w); this.addWidget(this._getChildName(`${i}_${j}`), w);
} }
} }
} }
var left = {}, right = {}, top = {}, bottom = {}; const left = {}, right = {}, top = {}, bottom = {};
left[0] = 0; left[0] = 0;
top[0] = 0; top[0] = 0;
right[o.columns - 1] = 0; right[o.columns - 1] = 0;
bottom[o.rows - 1] = 0; bottom[o.rows - 1] = 0;
// 从上到下 // 从上到下
for (var i = 0; i < o.rows; i++) { for (let i = 0; i < o.rows; i++) {
for (var j = 0; j < o.columns; j++) { for (let j = 0; j < o.columns; j++) {
var wi = this.getWidgetByName(this._getChildName(i + "_" + j)); const wi = this.getWidgetByName(this._getChildName(`${i}_${j}`));
if (BI.isNull(top[i])) { if (isNull(top[i])) {
top[i] = top[i - 1] + (o.rowSize[i - 1] < 1 ? o.rowSize[i - 1] : o.rowSize[i - 1] + o.vgap + o.bgap); top[i] = top[i - 1] + (o.rowSize[i - 1] < 1 ? o.rowSize[i - 1] : o.rowSize[i - 1] + o.vgap + o.bgap);
} }
var t = this._optimiseGap(top[i] + o.vgap + o.tgap), h = ""; const t = this._optimiseGap(top[i] + o.vgap + o.tgap);
if (BI.isNumber(o.rowSize[i])) { let h = "";
if (isNumber(o.rowSize[i])) {
h = this._optimiseGap(o.rowSize[i]); h = this._optimiseGap(o.rowSize[i]);
} }
wi.element.css({ top: t, height: h }); wi.element.css({ top: t, height: h });
first(wi, self.getRowColumnCls(i, j, o.rows - 1, o.columns - 1)); first(wi, this.getRowColumnCls(i, j, o.rows - 1, o.columns - 1));
} }
if (!BI.isNumber(o.rowSize[i])) { if (!isNumber(o.rowSize[i])) {
break; break;
} }
} }
// 从下到上 // 从下到上
for (var i = o.rows - 1; i >= 0; i--) { for (let i = o.rows - 1; i >= 0; i--) {
for (var j = 0; j < o.columns; j++) { for (let j = 0; j < o.columns; j++) {
var wi = this.getWidgetByName(this._getChildName(i + "_" + j)); const wi = this.getWidgetByName(this._getChildName(`${i}_${j}`));
if (BI.isNull(bottom[i])) { if (isNull(bottom[i])) {
bottom[i] = bottom[i + 1] + (o.rowSize[i + 1] < 1 ? o.rowSize[i + 1] : o.rowSize[i + 1] + o.vgap + o.tgap); bottom[i] = bottom[i + 1] + (o.rowSize[i + 1] < 1 ? o.rowSize[i + 1] : o.rowSize[i + 1] + o.vgap + o.tgap);
} }
var b = this._optimiseGap(bottom[i] + o.vgap + o.bgap), h = ""; const b = this._optimiseGap(bottom[i] + o.vgap + o.bgap);
if (BI.isNumber(o.rowSize[i])) { let h = "";
if (isNumber(o.rowSize[i])) {
h = this._optimiseGap(o.rowSize[i]); h = this._optimiseGap(o.rowSize[i]);
} }
wi.element.css({ bottom: b, height: h }); wi.element.css({ bottom: b, height: h });
first(wi, self.getRowColumnCls(i, j, o.rows - 1, o.columns - 1)); first(wi, this.getRowColumnCls(i, j, o.rows - 1, o.columns - 1));
} }
if (!BI.isNumber(o.rowSize[i])) { if (!isNumber(o.rowSize[i])) {
break; break;
} }
} }
// 从左到右 // 从左到右
for (var j = 0; j < o.columns; j++) { for (let j = 0; j < o.columns; j++) {
for (var i = 0; i < o.rows; i++) { for (let i = 0; i < o.rows; i++) {
var wi = this.getWidgetByName(this._getChildName(i + "_" + j)); const wi = this.getWidgetByName(this._getChildName(`${i}_${j}`));
if (BI.isNull(left[j])) { if (isNull(left[j])) {
left[j] = left[j - 1] + (o.columnSize[j - 1] < 1 ? o.columnSize[j - 1] : o.columnSize[j - 1] + o.hgap + o.rgap); left[j] = left[j - 1] + (o.columnSize[j - 1] < 1 ? o.columnSize[j - 1] : o.columnSize[j - 1] + o.hgap + o.rgap);
} }
var l = this._optimiseGap(left[j] + o.hgap + o.lgap), w = ""; const l = this._optimiseGap(left[j] + o.hgap + o.lgap);
if (BI.isNumber(o.columnSize[j])) { let w = "";
if (isNumber(o.columnSize[j])) {
w = this._optimiseGap(o.columnSize[j]); w = this._optimiseGap(o.columnSize[j]);
} }
wi.element.css({ left: l, width: w }); wi.element.css({ left: l, width: w });
first(wi, self.getRowColumnCls(i, j, o.rows - 1, o.columns - 1)); first(wi, this.getRowColumnCls(i, j, o.rows - 1, o.columns - 1));
} }
if (!BI.isNumber(o.columnSize[j])) { if (!isNumber(o.columnSize[j])) {
break; break;
} }
} }
// 从右到左 // 从右到左
for (var j = o.columns - 1; j >= 0; j--) { for (let j = o.columns - 1; j >= 0; j--) {
for (var i = 0; i < o.rows; i++) { for (let i = 0; i < o.rows; i++) {
var wi = this.getWidgetByName(this._getChildName(i + "_" + j)); const wi = this.getWidgetByName(this._getChildName(`${i}_${j}`));
if (BI.isNull(right[j])) { if (isNull(right[j])) {
right[j] = right[j + 1] + (o.columnSize[j + 1] < 1 ? o.columnSize[j + 1] : o.columnSize[j + 1] + o.hgap + o.lgap); right[j] = right[j + 1] + (o.columnSize[j + 1] < 1 ? o.columnSize[j + 1] : o.columnSize[j + 1] + o.hgap + o.lgap);
} }
var r = this._optimiseGap(right[j] + o.hgap + o.rgap), w = ""; const r = this._optimiseGap(right[j] + o.hgap + o.rgap);
if (BI.isNumber(o.columnSize[j])) { let w = "";
if (isNumber(o.columnSize[j])) {
w = this._optimiseGap(o.columnSize[j]); w = this._optimiseGap(o.columnSize[j]);
} }
wi.element.css({ right: r, width: w }); wi.element.css({ right: r, width: w });
first(wi, self.getRowColumnCls(i, j, o.rows - 1, o.columns - 1)); first(wi, this.getRowColumnCls(i, j, o.rows - 1, o.columns - 1));
} }
if (!BI.isNumber(o.columnSize[j])) { if (!isNumber(o.columnSize[j])) {
break; break;
} }
} }
}, }
resize: function () { resize() {
// console.log("window布局不需要resize"); // console.log("window布局不需要resize");
}, }
update: function (opt) { update(opt) {
return this.forceUpdate(opt); return this.forceUpdate(opt);
}, }
populate: function (items) { populate(...args) {
BI.WindowLayout.superclass.populate.apply(this, arguments); super.populate(...args);
this._mount(); this._mount();
} }
}); }
BI.shortcut("bi.window", BI.WindowLayout);

Loading…
Cancel
Save