Browse Source

feature: disabled

es6
guy 3 years ago
parent
commit
b6af34cf34
  1. 32
      src/core/4.widget.js

32
src/core/4.widget.js

@ -42,11 +42,11 @@
key: null, key: null,
tag: null, tag: null,
disabled: false, disabled: null,
invisible: false, invisible: false,
animation: "", animation: "",
animationDuring: 0, animationDuring: 0,
invalid: false, invalid: null,
baseCls: "", baseCls: "",
extraCls: "", extraCls: "",
cls: "", cls: "",
@ -398,6 +398,10 @@
lifeHook !== false && !this.__async && callLifeHook(this, "beforeMount"); lifeHook !== false && !this.__async && callLifeHook(this, "beforeMount");
this._isMounted = true; this._isMounted = true;
this.__isMounting = false; this.__isMounting = false;
for (var key in this._children) {
var child = this._children[key];
child._mount && child._mount(deep ? force : false, deep, lifeHook, predicate, layer + 1);
}
if (this._parent) { if (this._parent) {
if (!this._parent.isEnabled()) { if (!this._parent.isEnabled()) {
this._setEnable(false); this._setEnable(false);
@ -406,10 +410,6 @@
this._setValid(false); this._setValid(false);
} }
} }
for (var key in this._children) {
var child = this._children[key];
child._mount && child._mount(deep ? force : false, deep, lifeHook, predicate, layer + 1);
}
this._mountChildren && this._mountChildren(); this._mountChildren && this._mountChildren();
if (layer === 0) { if (layer === 0) {
// mounted里面会执行scrollTo之类的方法,如果放宏任务里会闪 // mounted里面会执行scrollTo之类的方法,如果放宏任务里会闪
@ -461,9 +461,9 @@
_setEnable: function (enable) { _setEnable: function (enable) {
if (enable === true) { if (enable === true) {
this.options.disabled = false; this.options._disabled = false;
} else if (enable === false) { } else if (enable === false) {
this.options.disabled = true; this.options._disabled = true;
} }
// 递归将所有子组件使能 // 递归将所有子组件使能
BI.each(this._children, function (i, child) { BI.each(this._children, function (i, child) {
@ -473,9 +473,9 @@
_setValid: function (valid) { _setValid: function (valid) {
if (valid === true) { if (valid === true) {
this.options.invalid = false; this.options._invalid = false;
} else if (valid === false) { } else if (valid === false) {
this.options.invalid = true; this.options._invalid = true;
} }
// 递归将所有子组件使有效 // 递归将所有子组件使有效
BI.each(this._children, function (i, child) { BI.each(this._children, function (i, child) {
@ -493,6 +493,7 @@
setEnable: function (enable) { setEnable: function (enable) {
this._manualSetEnable = true; this._manualSetEnable = true;
this.options.disabled = !enable;
this._setEnable(enable); this._setEnable(enable);
if (enable === true) { if (enable === true) {
this.element.removeClass("base-disabled disabled"); this.element.removeClass("base-disabled disabled");
@ -555,6 +556,7 @@
setValid: function (valid) { setValid: function (valid) {
this._manualSetValid = true; this._manualSetValid = true;
this.options.invalid = !valid;
this._setValid(valid); this._setValid(valid);
if (valid === true) { if (valid === true) {
this.element.removeClass("base-invalid invalid"); this.element.removeClass("base-invalid invalid");
@ -597,12 +599,6 @@
throw new Error("组件:组件名已存在,不能进行添加"); throw new Error("组件:组件名已存在,不能进行添加");
} }
widget._setParent && widget._setParent(this); widget._setParent && widget._setParent(this);
// if (this.options.disabled) {
// widget.options && (widget.options.disabled = true);
// }
// if (this.options.invalid) {
// widget.options && (widget.options.invalid = true);
// }
widget.on(BI.Events.DESTROY, function () { widget.on(BI.Events.DESTROY, function () {
BI.remove(self._children, this); BI.remove(self._children, this);
}); });
@ -689,11 +685,11 @@
}, },
isEnabled: function () { isEnabled: function () {
return !this.options.disabled; return this.options.disabled !== null ? !this.options.disabled : !this.options._disabled;
}, },
isVisible: function () { isVisible: function () {
return !this.options.invisible; return this.options.invalid !== null ? !this.options.invalid : !this.options._invalid;
}, },
disable: function () { disable: function () {

Loading…
Cancel
Save