Browse Source

Pull request #1858: 无JIRA任务 left_right_vertical_adapt布局当右边元素出现invisible的时候的情况

Merge in VISUAL/fineui from ~GUY/fineui:master to master

* commit 'a0897e74f95e44b0a9a44f063d85222d0c8a30b9':
  left_right_vertical_adapt布局当右边元素出现invisible的时候的情况
  left_right_vertical_adapt布局当右边元素出现invisible的时候的情况
  left_right_vertical_adapt布局当右边元素出现invisible的时候的情况
es6
guy 4 years ago
parent
commit
63bab37f9c
  1. 3
      src/core/widget.js
  2. 4
      src/core/wrapper/layout/flex/flex.leftrightvertical.center.js
  3. 11
      src/core/wrapper/layout/layout.td.js
  4. 11
      src/less/core/wrapper/flex.leftrightvertical.center.less

3
src/core/widget.js

@ -183,6 +183,7 @@
if (o.invisible) { if (o.invisible) {
// 用display属性做显示和隐藏,否则jquery会在显示时将display设为block会覆盖掉display:flex属性 // 用display属性做显示和隐藏,否则jquery会在显示时将display设为block会覆盖掉display:flex属性
this.element.css("display", "none"); this.element.css("display", "none");
this.element.addClass("invisible");
} }
}, },
@ -354,9 +355,11 @@
if (visible === true) { if (visible === true) {
// 用this.element.show()会把display属性改成block // 用this.element.show()会把display属性改成block
this.element.css("display", ""); this.element.css("display", "");
this.element.removeClass("invisible");
this._mount(); this._mount();
} else if (visible === false) { } else if (visible === false) {
this.element.css("display", "none"); this.element.css("display", "none");
this.element.addClass("invisible");
} }
this.fireEvent(BI.Events.VIEW, visible); this.fireEvent(BI.Events.VIEW, visible);
}, },

4
src/core/wrapper/layout/flex/flex.leftrightvertical.center.js

@ -55,14 +55,14 @@ BI.FlexLeftRightVerticalAdaptLayout = BI.inherit(BI.Layout, {
return json; return json;
}); });
rightItems = BI.map(rightItems, function (i, item) { rightItems = BI.map(rightItems, function (i, item) {
if (i === 0) { // if (i === 0) {
if (BI.isWidget(item)) { if (BI.isWidget(item)) {
item.element.addClass("flex-left-auto"); item.element.addClass("flex-left-auto");
} else { } else {
var t = BI.stripEL(item); var t = BI.stripEL(item);
t.cls = (t.cls || "") + " flex-left-auto"; t.cls = (t.cls || "") + " flex-left-auto";
} }
} // }
var json = { var json = {
el: BI.stripEL(item) el: BI.stripEL(item)
}; };

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

@ -8,6 +8,7 @@ BI.TdLayout = BI.inherit(BI.Layout, {
return BI.extend(BI.TdLayout.superclass.props.apply(this, arguments), { return BI.extend(BI.TdLayout.superclass.props.apply(this, arguments), {
baseCls: "bi-td", baseCls: "bi-td",
columnSize: [], columnSize: [],
verticalAlign: BI.VerticalAlign.Middle,
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
tgap: 0, tgap: 0,
@ -101,15 +102,21 @@ BI.TdLayout = BI.inherit(BI.Layout, {
}); });
} }
first(w, this.rows++, i); first(w, this.rows++, i);
var width = o.columnSize[i] === "" ? "" : (o.columnSize[i] <= 1 ? ((o.columnSize[i] * 100).toFixed(1) + "%") : (i === 0 ? o.hgap : 0) + o.hgap + o.lgap + o.rgap + o.columnSize[i]);
var td = BI._lazyCreateWidget({ var td = BI._lazyCreateWidget({
type: "bi.default", type: "bi.default",
width: o.columnSize[i] === "" ? "" : (o.columnSize[i] <= 1 ? ((o.columnSize[i] * 100).toFixed(1) + "%") : (i === 0 ? o.hgap : 0) + o.hgap + o.lgap + o.rgap + o.columnSize[i]), width: width,
tagName: "td", tagName: "td",
items: [w] items: [w]
}); });
// 对于表现为td的元素设置最大宽度,有几点需要注意
// 1、由于直接对td设置最大宽度是在规范中未定义的, 所以要使用类似td:firstChild来迂回实现
// 2、不能给多个td设置最大宽度,这样只会平分宽度
// 3、多百分比宽度就算了
td.element.css({ td.element.css({
"max-width": BI.isNumber(o.columnSize[i]) ? (o.columnSize[i] <= 1 ? width : width / BI.pixRatio + BI.pixUnit) : width,
position: "relative", position: "relative",
"vertical-align": "middle", "vertical-align": o.verticalAlign,
margin: "0", margin: "0",
padding: "0", padding: "0",
border: "none" border: "none"

11
src/less/core/wrapper/flex.leftrightvertical.center.less

@ -1,5 +1,16 @@
.bi-f-lr-v-c { .bi-f-lr-v-c {
> .flex-left-auto { > .flex-left-auto {
margin-left: auto; margin-left: auto;
// 当隐藏的元素出现在中间某个元素的情况
+ .flex-left-auto.invisible {
+ .flex-left-auto {
margin-left: initial;
}
}
&:not(.invisible) + .flex-left-auto {
margin-left: initial;
}
} }
} }

Loading…
Cancel
Save