From b6af34cf347278646c55ab2cf8fe9bb75650e49a Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 28 Mar 2022 18:25:18 +0800 Subject: [PATCH] feature: disabled --- src/core/4.widget.js | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/core/4.widget.js b/src/core/4.widget.js index deb7758ab..306975294 100644 --- a/src/core/4.widget.js +++ b/src/core/4.widget.js @@ -42,11 +42,11 @@ key: null, tag: null, - disabled: false, + disabled: null, invisible: false, animation: "", animationDuring: 0, - invalid: false, + invalid: null, baseCls: "", extraCls: "", cls: "", @@ -398,6 +398,10 @@ lifeHook !== false && !this.__async && callLifeHook(this, "beforeMount"); this._isMounted = true; 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.isEnabled()) { this._setEnable(false); @@ -406,10 +410,6 @@ 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(); if (layer === 0) { // mounted里面会执行scrollTo之类的方法,如果放宏任务里会闪 @@ -461,9 +461,9 @@ _setEnable: function (enable) { if (enable === true) { - this.options.disabled = false; + this.options._disabled = false; } else if (enable === false) { - this.options.disabled = true; + this.options._disabled = true; } // 递归将所有子组件使能 BI.each(this._children, function (i, child) { @@ -473,9 +473,9 @@ _setValid: function (valid) { if (valid === true) { - this.options.invalid = false; + this.options._invalid = false; } else if (valid === false) { - this.options.invalid = true; + this.options._invalid = true; } // 递归将所有子组件使有效 BI.each(this._children, function (i, child) { @@ -493,6 +493,7 @@ setEnable: function (enable) { this._manualSetEnable = true; + this.options.disabled = !enable; this._setEnable(enable); if (enable === true) { this.element.removeClass("base-disabled disabled"); @@ -555,6 +556,7 @@ setValid: function (valid) { this._manualSetValid = true; + this.options.invalid = !valid; this._setValid(valid); if (valid === true) { this.element.removeClass("base-invalid invalid"); @@ -597,12 +599,6 @@ throw new Error("组件:组件名已存在,不能进行添加"); } 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 () { BI.remove(self._children, this); }); @@ -689,11 +685,11 @@ }, isEnabled: function () { - return !this.options.disabled; + return this.options.disabled !== null ? !this.options.disabled : !this.options._disabled; }, isVisible: function () { - return !this.options.invisible; + return this.options.invalid !== null ? !this.options.invalid : !this.options._invalid; }, disable: function () {