From 4e8516ffcd28464341e73bea780085218448655f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Thu, 19 Jul 2018 13:30:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwatch=E6=95=B0=E7=BB=84?= =?UTF-8?q?=E5=9B=9E=E8=B0=83=E6=89=A7=E8=A1=8C=E6=97=B6=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=9C=AA=E6=94=B9=E5=8F=98=E7=9A=84bug;=E7=A7=BB=E9=99=A4$fire?= =?UTF-8?q?=E7=9A=84component!=E6=8C=87=E4=BB=A4;=E4=BF=AE=E5=A4=8Dvm?= =?UTF-8?q?=E7=9A=84$up,$children,$components=E5=B1=9E=E6=80=A7;=E4=BC=98?= =?UTF-8?q?=E5=8C=96=E7=BB=84=E4=BB=B6=E7=9A=84=E5=87=A0=E4=B8=AA=E7=89=B9?= =?UTF-8?q?=E6=AE=8A=E6=8C=87=E4=BB=A4;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/anot-touch.js | 87 +++++++++++++++++++++++++-------------- src/js/anot-touch.shim.js | 87 +++++++++++++++++++++++++-------------- src/js/anot.js | 87 +++++++++++++++++++++++++-------------- src/js/anot.shim.js | 87 +++++++++++++++++++++++++-------------- src/js/form/index.js | 12 +++++- src/js/store/index.js | 4 +- src/js/tree/index.js | 81 +++++++++++++++++++++--------------- src/js/tree/main.scss | 2 +- 8 files changed, 281 insertions(+), 166 deletions(-) diff --git a/src/js/anot-touch.js b/src/js/anot-touch.js index dca7a90..0c51430 100644 --- a/src/js/anot-touch.js +++ b/src/js/anot-touch.js @@ -1724,8 +1724,10 @@ const _Anot = (function() { hideProperty($vmodel, '$active', false) hideProperty($vmodel, '$pathname', old ? old.$pathname : '') hideProperty($vmodel, '$accessors', accessors) + hideProperty($vmodel, '$events', {}) hideProperty($vmodel, '$refs', {}) hideProperty($vmodel, '$children', []) + hideProperty($vmodel, '$components', []) hideProperty($vmodel, 'hasOwnProperty', trackBy) hideProperty($vmodel, '$mounted', mounted) if (options.watch) { @@ -1745,16 +1747,6 @@ const _Anot = (function() { var v = $vmodel.$children[i] v.$fire && v.$fire.apply(v, [ee, a]) } - // component! 这是一个特殊的标识,可以直接修改子组件的state值 - // 且只针对指定子组件有效 - } else if (path.indexOf('component!') === 0) { - var ee = path.slice(10).split('!') - for (var i in $vmodel.$children) { - if ($vmodel.$children[i].$id === ee[0]) { - $vmodel.$children[i][ee[1]] = a - break - } - } } else { $emit.call($vmodel, path, [a]) } @@ -1987,8 +1979,9 @@ const _Anot = (function() { throw Error(index + 'set方法的第一个参数不能大于原数组长度') } if (this[index] !== val) { - $emit.call(this.$up, this.$pathname + '.*', [val, this[index]]) + var old = this[index] this.splice(index, 1, val) + $emit.call(this.$up, this.$pathname + '.*', [val, old, null, index]) } }, contains: function(el) { @@ -3545,11 +3538,11 @@ const _Anot = (function() { } } - function scanTag(elem, vmodels, node) { + function scanTag(elem, vmodels) { //扫描顺序 skip(0) --> anot(1) --> :if(10) --> :repeat(90) //--> :if-loop(110) --> :attr(970) ...--> :duplex(2000)垫后 var skip = elem.getAttribute('skip') - node = elem.getAttributeNode('anot') + var node = elem.getAttributeNode('anot') var vm = vmodels.concat() if (typeof skip === 'string') { return @@ -3566,7 +3559,10 @@ const _Anot = (function() { elem.removeAttribute(node.name) //removeAttributeNode不会刷新xx[anot]样式规则 createSignalTower(elem, newVmodel) hideProperty(newVmodel, '$elem', elem) + if (vmodels.length) { + newVmodel.$up = vmodels[0] + vmodels[0].$children.push(newVmodel) var props = {} attrs.forEach(function(attr) { if (/^:/.test(attr.name)) { @@ -3787,7 +3783,13 @@ const _Anot = (function() { function parseVmValue(vm, key, val) { if (arguments.length === 2) { - return Function('o', 'return o.' + key)(vm) + var oval = Function('o', 'return o.' + key)(vm) + if (oval && typeof oval === 'object') { + try { + return oval.$model + } catch (err) {} + } + return oval } else if (arguments.length === 3) { Function('o', 'v', 'return o.' + key + ' = v')(vm, val) } @@ -3852,7 +3854,7 @@ const _Anot = (function() { if (disabledKeyReverse) { val = !val } - parentVm.$fire('component!' + $id + '!disabled', val) + Anot.vmodels[$id].disabled = val }) delete props[':disabled'] @@ -3872,7 +3874,7 @@ const _Anot = (function() { if (loadingKeyReverse) { val = !val } - parentVm.$fire('component!' + $id + '!loading', val) + Anot.vmodels[$id].loading = val }) delete props[':loading'] } @@ -3880,22 +3882,43 @@ const _Anot = (function() { // :value可实现双向同步值 if (props.hasOwnProperty(':value')) { var valueKey = props[':value'] + var valueWatcher = function() { + var val = parseVmValue(parentVm, valueKey) + Anot.vmodels[$id].value = val + } + var childValueWatcher = function() { + var val = this.value + if (val && typeof val === 'object') { + val = val.$model || val + } + parseVmValue(parentVm, valueKey, val) + } state.value = parseVmValue(parentVm, valueKey) - parentVm.$watch(valueKey, function(val) { - parentVm.$fire('component!' + $id + '!value', val) - }) - if (Array.isArray(state.value)) { - hooks.watch['value.length'] = hooks.watch['value.length'] - ? [hooks.watch['value.length']] - : [] - hooks.watch['value.length'].push(function(val) { - parseVmValue(parentVm, valueKey, this.value.$model) - }) + + parentVm.$watch(valueKey, valueWatcher) + parentVm.$watch(valueKey + '.*', valueWatcher) + parentVm.$watch(valueKey + '.length', valueWatcher) + + if (hooks.watch.value) { + hooks.watch.value = [hooks.watch.value] } else { - hooks.watch.value = hooks.watch.value ? [hooks.watch.value] : [] - hooks.watch.value.push(function(val) { - parseVmValue(parentVm, valueKey, val) - }) + hooks.watch.value = [] + } + if (hooks.watch['value.length']) { + hooks.watch['value.length'] = [hooks.watch['value.length']] + } else { + hooks.watch['value.length'] = [] + } + if (hooks.watch['value.*']) { + hooks.watch['value.*'] = [hooks.watch['value.*']] + } else { + hooks.watch['value.*'] = [] + } + if (Array.isArray(state.value)) { + hooks.watch['value.*'].push(childValueWatcher) + hooks.watch['value.length'].push(childValueWatcher) + } else { + hooks.watch.value.push(childValueWatcher) } delete props[':value'] @@ -3952,7 +3975,7 @@ const _Anot = (function() { var vmodel = Anot(hooks) delete vmodel.$mounted - parentVm.$children.push(vmodel) + parentVm.$components.push(vmodel) elem.msResolved = 1 //防止二进扫描此元素 @@ -3991,7 +4014,7 @@ const _Anot = (function() { if (ev.childReady) { dependencies += ev.childReady if (vmodel !== ev.vm) { - vmodel.$children.push(ev.vm) + vmodel.$components.push(ev.vm) ev.vm.$up = vmodel if (ev.childReady === -1) { children++ diff --git a/src/js/anot-touch.shim.js b/src/js/anot-touch.shim.js index 8695473..94b03b0 100644 --- a/src/js/anot-touch.shim.js +++ b/src/js/anot-touch.shim.js @@ -1739,8 +1739,10 @@ hideProperty($vmodel, '$active', false) hideProperty($vmodel, '$pathname', old ? old.$pathname : '') hideProperty($vmodel, '$accessors', accessors) + hideProperty($vmodel, '$events', {}) hideProperty($vmodel, '$refs', {}) hideProperty($vmodel, '$children', []) + hideProperty($vmodel, '$components', []) hideProperty($vmodel, 'hasOwnProperty', trackBy) hideProperty($vmodel, '$mounted', mounted) if (options.watch) { @@ -1760,16 +1762,6 @@ var v = $vmodel.$children[i] v.$fire && v.$fire.apply(v, [ee, a]) } - // component! 这是一个特殊的标识,可以直接修改子组件的state值 - // 且只针对指定子组件有效 - } else if (path.indexOf('component!') === 0) { - var ee = path.slice(10).split('!') - for (var i in $vmodel.$children) { - if ($vmodel.$children[i].$id === ee[0]) { - $vmodel.$children[i][ee[1]] = a - break - } - } } else { $emit.call($vmodel, path, [a]) } @@ -2002,8 +1994,9 @@ throw Error(index + 'set方法的第一个参数不能大于原数组长度') } if (this[index] !== val) { - $emit.call(this.$up, this.$pathname + '.*', [val, this[index]]) + var old = this[index] this.splice(index, 1, val) + $emit.call(this.$up, this.$pathname + '.*', [val, old, null, index]) } }, contains: function(el) { @@ -3560,11 +3553,11 @@ } } - function scanTag(elem, vmodels, node) { + function scanTag(elem, vmodels) { //扫描顺序 skip(0) --> anot(1) --> :if(10) --> :repeat(90) //--> :if-loop(110) --> :attr(970) ...--> :duplex(2000)垫后 var skip = elem.getAttribute('skip') - node = elem.getAttributeNode('anot') + var node = elem.getAttributeNode('anot') var vm = vmodels.concat() if (typeof skip === 'string') { return @@ -3581,7 +3574,10 @@ elem.removeAttribute(node.name) //removeAttributeNode不会刷新xx[anot]样式规则 createSignalTower(elem, newVmodel) hideProperty(newVmodel, '$elem', elem) + if (vmodels.length) { + newVmodel.$up = vmodels[0] + vmodels[0].$children.push(newVmodel) var props = {} attrs.forEach(function(attr) { if (/^:/.test(attr.name)) { @@ -3802,7 +3798,13 @@ function parseVmValue(vm, key, val) { if (arguments.length === 2) { - return Function('o', 'return o.' + key)(vm) + var oval = Function('o', 'return o.' + key)(vm) + if (oval && typeof oval === 'object') { + try { + return oval.$model + } catch (err) {} + } + return oval } else if (arguments.length === 3) { Function('o', 'v', 'return o.' + key + ' = v')(vm, val) } @@ -3867,7 +3869,7 @@ if (disabledKeyReverse) { val = !val } - parentVm.$fire('component!' + $id + '!disabled', val) + Anot.vmodels[$id].disabled = val }) delete props[':disabled'] @@ -3887,7 +3889,7 @@ if (loadingKeyReverse) { val = !val } - parentVm.$fire('component!' + $id + '!loading', val) + Anot.vmodels[$id].loading = val }) delete props[':loading'] } @@ -3895,22 +3897,43 @@ // :value可实现双向同步值 if (props.hasOwnProperty(':value')) { var valueKey = props[':value'] + var valueWatcher = function() { + var val = parseVmValue(parentVm, valueKey) + Anot.vmodels[$id].value = val + } + var childValueWatcher = function() { + var val = this.value + if (val && typeof val === 'object') { + val = val.$model || val + } + parseVmValue(parentVm, valueKey, val) + } state.value = parseVmValue(parentVm, valueKey) - parentVm.$watch(valueKey, function(val) { - parentVm.$fire('component!' + $id + '!value', val) - }) - if (Array.isArray(state.value)) { - hooks.watch['value.length'] = hooks.watch['value.length'] - ? [hooks.watch['value.length']] - : [] - hooks.watch['value.length'].push(function(val) { - parseVmValue(parentVm, valueKey, this.value.$model) - }) + + parentVm.$watch(valueKey, valueWatcher) + parentVm.$watch(valueKey + '.*', valueWatcher) + parentVm.$watch(valueKey + '.length', valueWatcher) + + if (hooks.watch.value) { + hooks.watch.value = [hooks.watch.value] } else { - hooks.watch.value = hooks.watch.value ? [hooks.watch.value] : [] - hooks.watch.value.push(function(val) { - parseVmValue(parentVm, valueKey, val) - }) + hooks.watch.value = [] + } + if (hooks.watch['value.length']) { + hooks.watch['value.length'] = [hooks.watch['value.length']] + } else { + hooks.watch['value.length'] = [] + } + if (hooks.watch['value.*']) { + hooks.watch['value.*'] = [hooks.watch['value.*']] + } else { + hooks.watch['value.*'] = [] + } + if (Array.isArray(state.value)) { + hooks.watch['value.*'].push(childValueWatcher) + hooks.watch['value.length'].push(childValueWatcher) + } else { + hooks.watch.value.push(childValueWatcher) } delete props[':value'] @@ -3967,7 +3990,7 @@ var vmodel = Anot(hooks) delete vmodel.$mounted - parentVm.$children.push(vmodel) + parentVm.$components.push(vmodel) elem.msResolved = 1 //防止二进扫描此元素 @@ -4006,7 +4029,7 @@ if (ev.childReady) { dependencies += ev.childReady if (vmodel !== ev.vm) { - vmodel.$children.push(ev.vm) + vmodel.$components.push(ev.vm) ev.vm.$up = vmodel if (ev.childReady === -1) { children++ diff --git a/src/js/anot.js b/src/js/anot.js index 1d45c2d..9356a5c 100644 --- a/src/js/anot.js +++ b/src/js/anot.js @@ -1724,8 +1724,10 @@ const _Anot = (function() { hideProperty($vmodel, '$active', false) hideProperty($vmodel, '$pathname', old ? old.$pathname : '') hideProperty($vmodel, '$accessors', accessors) + hideProperty($vmodel, '$events', {}) hideProperty($vmodel, '$refs', {}) hideProperty($vmodel, '$children', []) + hideProperty($vmodel, '$components', []) hideProperty($vmodel, 'hasOwnProperty', trackBy) hideProperty($vmodel, '$mounted', mounted) if (options.watch) { @@ -1745,16 +1747,6 @@ const _Anot = (function() { var v = $vmodel.$children[i] v.$fire && v.$fire.apply(v, [ee, a]) } - // component! 这是一个特殊的标识,可以直接修改子组件的state值 - // 且只针对指定子组件有效 - } else if (path.indexOf('component!') === 0) { - var ee = path.slice(10).split('!') - for (var i in $vmodel.$children) { - if ($vmodel.$children[i].$id === ee[0]) { - $vmodel.$children[i][ee[1]] = a - break - } - } } else { $emit.call($vmodel, path, [a]) } @@ -1987,8 +1979,9 @@ const _Anot = (function() { throw Error(index + 'set方法的第一个参数不能大于原数组长度') } if (this[index] !== val) { - $emit.call(this.$up, this.$pathname + '.*', [val, this[index]]) + var old = this[index] this.splice(index, 1, val) + $emit.call(this.$up, this.$pathname + '.*', [val, old, null, index]) } }, contains: function(el) { @@ -3545,11 +3538,11 @@ const _Anot = (function() { } } - function scanTag(elem, vmodels, node) { + function scanTag(elem, vmodels) { //扫描顺序 skip(0) --> anot(1) --> :if(10) --> :repeat(90) //--> :if-loop(110) --> :attr(970) ...--> :duplex(2000)垫后 var skip = elem.getAttribute('skip') - node = elem.getAttributeNode('anot') + var node = elem.getAttributeNode('anot') var vm = vmodels.concat() if (typeof skip === 'string') { return @@ -3566,7 +3559,10 @@ const _Anot = (function() { elem.removeAttribute(node.name) //removeAttributeNode不会刷新xx[anot]样式规则 createSignalTower(elem, newVmodel) hideProperty(newVmodel, '$elem', elem) + if (vmodels.length) { + newVmodel.$up = vmodels[0] + vmodels[0].$children.push(newVmodel) var props = {} attrs.forEach(function(attr) { if (/^:/.test(attr.name)) { @@ -3787,7 +3783,13 @@ const _Anot = (function() { function parseVmValue(vm, key, val) { if (arguments.length === 2) { - return Function('o', 'return o.' + key)(vm) + var oval = Function('o', 'return o.' + key)(vm) + if (oval && typeof oval === 'object') { + try { + return oval.$model + } catch (err) {} + } + return oval } else if (arguments.length === 3) { Function('o', 'v', 'return o.' + key + ' = v')(vm, val) } @@ -3852,7 +3854,7 @@ const _Anot = (function() { if (disabledKeyReverse) { val = !val } - parentVm.$fire('component!' + $id + '!disabled', val) + Anot.vmodels[$id].disabled = val }) delete props[':disabled'] @@ -3872,7 +3874,7 @@ const _Anot = (function() { if (loadingKeyReverse) { val = !val } - parentVm.$fire('component!' + $id + '!loading', val) + Anot.vmodels[$id].loading = val }) delete props[':loading'] } @@ -3880,22 +3882,43 @@ const _Anot = (function() { // :value可实现双向同步值 if (props.hasOwnProperty(':value')) { var valueKey = props[':value'] + var valueWatcher = function() { + var val = parseVmValue(parentVm, valueKey) + Anot.vmodels[$id].value = val + } + var childValueWatcher = function() { + var val = this.value + if (val && typeof val === 'object') { + val = val.$model || val + } + parseVmValue(parentVm, valueKey, val) + } state.value = parseVmValue(parentVm, valueKey) - parentVm.$watch(valueKey, function(val) { - parentVm.$fire('component!' + $id + '!value', val) - }) - if (Array.isArray(state.value)) { - hooks.watch['value.length'] = hooks.watch['value.length'] - ? [hooks.watch['value.length']] - : [] - hooks.watch['value.length'].push(function(val) { - parseVmValue(parentVm, valueKey, this.value.$model) - }) + + parentVm.$watch(valueKey, valueWatcher) + parentVm.$watch(valueKey + '.*', valueWatcher) + parentVm.$watch(valueKey + '.length', valueWatcher) + + if (hooks.watch.value) { + hooks.watch.value = [hooks.watch.value] } else { - hooks.watch.value = hooks.watch.value ? [hooks.watch.value] : [] - hooks.watch.value.push(function(val) { - parseVmValue(parentVm, valueKey, val) - }) + hooks.watch.value = [] + } + if (hooks.watch['value.length']) { + hooks.watch['value.length'] = [hooks.watch['value.length']] + } else { + hooks.watch['value.length'] = [] + } + if (hooks.watch['value.*']) { + hooks.watch['value.*'] = [hooks.watch['value.*']] + } else { + hooks.watch['value.*'] = [] + } + if (Array.isArray(state.value)) { + hooks.watch['value.*'].push(childValueWatcher) + hooks.watch['value.length'].push(childValueWatcher) + } else { + hooks.watch.value.push(childValueWatcher) } delete props[':value'] @@ -3952,7 +3975,7 @@ const _Anot = (function() { var vmodel = Anot(hooks) delete vmodel.$mounted - parentVm.$children.push(vmodel) + parentVm.$components.push(vmodel) elem.msResolved = 1 //防止二进扫描此元素 @@ -3991,7 +4014,7 @@ const _Anot = (function() { if (ev.childReady) { dependencies += ev.childReady if (vmodel !== ev.vm) { - vmodel.$children.push(ev.vm) + vmodel.$components.push(ev.vm) ev.vm.$up = vmodel if (ev.childReady === -1) { children++ diff --git a/src/js/anot.shim.js b/src/js/anot.shim.js index 592e22d..89233e2 100644 --- a/src/js/anot.shim.js +++ b/src/js/anot.shim.js @@ -1739,8 +1739,10 @@ hideProperty($vmodel, '$active', false) hideProperty($vmodel, '$pathname', old ? old.$pathname : '') hideProperty($vmodel, '$accessors', accessors) + hideProperty($vmodel, '$events', {}) hideProperty($vmodel, '$refs', {}) hideProperty($vmodel, '$children', []) + hideProperty($vmodel, '$components', []) hideProperty($vmodel, 'hasOwnProperty', trackBy) hideProperty($vmodel, '$mounted', mounted) if (options.watch) { @@ -1760,16 +1762,6 @@ var v = $vmodel.$children[i] v.$fire && v.$fire.apply(v, [ee, a]) } - // component! 这是一个特殊的标识,可以直接修改子组件的state值 - // 且只针对指定子组件有效 - } else if (path.indexOf('component!') === 0) { - var ee = path.slice(10).split('!') - for (var i in $vmodel.$children) { - if ($vmodel.$children[i].$id === ee[0]) { - $vmodel.$children[i][ee[1]] = a - break - } - } } else { $emit.call($vmodel, path, [a]) } @@ -2002,8 +1994,9 @@ throw Error(index + 'set方法的第一个参数不能大于原数组长度') } if (this[index] !== val) { - $emit.call(this.$up, this.$pathname + '.*', [val, this[index]]) + var old = this[index] this.splice(index, 1, val) + $emit.call(this.$up, this.$pathname + '.*', [val, old, null, index]) } }, contains: function(el) { @@ -3560,11 +3553,11 @@ } } - function scanTag(elem, vmodels, node) { + function scanTag(elem, vmodels) { //扫描顺序 skip(0) --> anot(1) --> :if(10) --> :repeat(90) //--> :if-loop(110) --> :attr(970) ...--> :duplex(2000)垫后 var skip = elem.getAttribute('skip') - node = elem.getAttributeNode('anot') + var node = elem.getAttributeNode('anot') var vm = vmodels.concat() if (typeof skip === 'string') { return @@ -3581,7 +3574,10 @@ elem.removeAttribute(node.name) //removeAttributeNode不会刷新xx[anot]样式规则 createSignalTower(elem, newVmodel) hideProperty(newVmodel, '$elem', elem) + if (vmodels.length) { + newVmodel.$up = vmodels[0] + vmodels[0].$children.push(newVmodel) var props = {} attrs.forEach(function(attr) { if (/^:/.test(attr.name)) { @@ -3802,7 +3798,13 @@ function parseVmValue(vm, key, val) { if (arguments.length === 2) { - return Function('o', 'return o.' + key)(vm) + var oval = Function('o', 'return o.' + key)(vm) + if (oval && typeof oval === 'object') { + try { + return oval.$model + } catch (err) {} + } + return oval } else if (arguments.length === 3) { Function('o', 'v', 'return o.' + key + ' = v')(vm, val) } @@ -3867,7 +3869,7 @@ if (disabledKeyReverse) { val = !val } - parentVm.$fire('component!' + $id + '!disabled', val) + Anot.vmodels[$id].disabled = val }) delete props[':disabled'] @@ -3887,7 +3889,7 @@ if (loadingKeyReverse) { val = !val } - parentVm.$fire('component!' + $id + '!loading', val) + Anot.vmodels[$id].loading = val }) delete props[':loading'] } @@ -3895,22 +3897,43 @@ // :value可实现双向同步值 if (props.hasOwnProperty(':value')) { var valueKey = props[':value'] + var valueWatcher = function() { + var val = parseVmValue(parentVm, valueKey) + Anot.vmodels[$id].value = val + } + var childValueWatcher = function() { + var val = this.value + if (val && typeof val === 'object') { + val = val.$model || val + } + parseVmValue(parentVm, valueKey, val) + } state.value = parseVmValue(parentVm, valueKey) - parentVm.$watch(valueKey, function(val) { - parentVm.$fire('component!' + $id + '!value', val) - }) - if (Array.isArray(state.value)) { - hooks.watch['value.length'] = hooks.watch['value.length'] - ? [hooks.watch['value.length']] - : [] - hooks.watch['value.length'].push(function(val) { - parseVmValue(parentVm, valueKey, this.value.$model) - }) + + parentVm.$watch(valueKey, valueWatcher) + parentVm.$watch(valueKey + '.*', valueWatcher) + parentVm.$watch(valueKey + '.length', valueWatcher) + + if (hooks.watch.value) { + hooks.watch.value = [hooks.watch.value] } else { - hooks.watch.value = hooks.watch.value ? [hooks.watch.value] : [] - hooks.watch.value.push(function(val) { - parseVmValue(parentVm, valueKey, val) - }) + hooks.watch.value = [] + } + if (hooks.watch['value.length']) { + hooks.watch['value.length'] = [hooks.watch['value.length']] + } else { + hooks.watch['value.length'] = [] + } + if (hooks.watch['value.*']) { + hooks.watch['value.*'] = [hooks.watch['value.*']] + } else { + hooks.watch['value.*'] = [] + } + if (Array.isArray(state.value)) { + hooks.watch['value.*'].push(childValueWatcher) + hooks.watch['value.length'].push(childValueWatcher) + } else { + hooks.watch.value.push(childValueWatcher) } delete props[':value'] @@ -3967,7 +3990,7 @@ var vmodel = Anot(hooks) delete vmodel.$mounted - parentVm.$children.push(vmodel) + parentVm.$components.push(vmodel) elem.msResolved = 1 //防止二进扫描此元素 @@ -4006,7 +4029,7 @@ if (ev.childReady) { dependencies += ev.childReady if (vmodel !== ev.vm) { - vmodel.$children.push(ev.vm) + vmodel.$components.push(ev.vm) ev.vm.$up = vmodel if (ev.childReady === -1) { children++ diff --git a/src/js/form/index.js b/src/js/form/index.js index 539eaeb..59a2b8a 100644 --- a/src/js/form/index.js +++ b/src/js/form/index.js @@ -202,6 +202,17 @@ Anot.component('checkbox', { props: { label: '' }, + watch: { + 'value.*'(val, old, k, kk) { + this.checked = this.value.indexOf(this.props.label) > -1 + }, + 'value.length'(val, old, k, kk) { + this.checked = this.value.indexOf(this.props.label) > -1 + }, + value(val, old, k, kk) { + this.checked = this.value.indexOf(this.props.label) > -1 + } + }, methods: { onClick() { if (this.disabled) { @@ -218,7 +229,6 @@ Anot.component('checkbox', { } this.checked = true this.value.push(label) - // this.value = !this.value } } }) diff --git a/src/js/store/index.js b/src/js/store/index.js index 286e2e5..53d7687 100644 --- a/src/js/store/index.js +++ b/src/js/store/index.js @@ -118,7 +118,7 @@ class AnotStore { } // 查询多条记录,返回数组 - getAll({ filter, limit = [] }) { + getAll({ filter, limit = [] } = {}) { const collection = __STORE__[this.__name__] let result = [] let forceLimited = false // 强制限制查询结果集 @@ -171,7 +171,7 @@ class AnotStore { } // 查询总数 - count({ filter }) { + count({ filter } = {}) { if (filter) { if (this.__LAST_QUERY__ === JSON.stringify(filter)) { return this.__QUERY_HISTORY__.length diff --git a/src/js/tree/index.js b/src/js/tree/index.js index c5b2739..e44b993 100644 --- a/src/js/tree/index.js +++ b/src/js/tree/index.js @@ -11,10 +11,12 @@ import './main.scss' //储存版本信息 Anot.ui.tree = '1.0.0' +const log = console.log function format(arr, { id, parent, label, children }) { let tmp = {} let farr = [] + arr = Anot.deepCopy(arr) arr.sort(function(a, b) { return a[parent] === b[parent] ? a.sort - b.sort : a[parent] - b[parent] }) @@ -36,15 +38,32 @@ function format(arr, { id, parent, label, children }) { } export default Anot.component('tree', { - render: function() { - if (!this.list.size()) { - return null + __init__: function(props, state, next) { + this.classList.add('do-tree') + this.setAttribute(':visible', 'list.size()') + props.id = props.id || 'id' + props.label = props.label || 'label' + props.parent = props.parent || 'parent' + props.children = props.children || 'children' + if (props.list) { + for (let it of props.list) { + state.__LIST__.push(it) + state.__LIST_DICT__[it[props.id]] = it + } } + state.list = format(props.list || [], props) + state.multiCheck = props.hasOwnProperty('multiCheck') + delete props.list + delete props.multiCheck + next() + }, + render: function() { + let { multiCheck } = this return `
-