修复watch数组回调执行时数据未改变的bug;移除$fire的component!指令;修复vm的$up,$children,$components属性;优化组件的几个特殊指令;
parent
c31c7cebba
commit
4e8516ffcd
|
@ -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']
|
||||
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)
|
||||
})
|
||||
} else {
|
||||
hooks.watch.value = hooks.watch.value ? [hooks.watch.value] : []
|
||||
hooks.watch.value.push(function(val) {
|
||||
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, valueWatcher)
|
||||
parentVm.$watch(valueKey + '.*', valueWatcher)
|
||||
parentVm.$watch(valueKey + '.length', valueWatcher)
|
||||
|
||||
if (hooks.watch.value) {
|
||||
hooks.watch.value = [hooks.watch.value]
|
||||
} else {
|
||||
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++
|
||||
|
|
|
@ -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']
|
||||
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)
|
||||
})
|
||||
} else {
|
||||
hooks.watch.value = hooks.watch.value ? [hooks.watch.value] : []
|
||||
hooks.watch.value.push(function(val) {
|
||||
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, valueWatcher)
|
||||
parentVm.$watch(valueKey + '.*', valueWatcher)
|
||||
parentVm.$watch(valueKey + '.length', valueWatcher)
|
||||
|
||||
if (hooks.watch.value) {
|
||||
hooks.watch.value = [hooks.watch.value]
|
||||
} else {
|
||||
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++
|
||||
|
|
|
@ -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']
|
||||
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)
|
||||
})
|
||||
} else {
|
||||
hooks.watch.value = hooks.watch.value ? [hooks.watch.value] : []
|
||||
hooks.watch.value.push(function(val) {
|
||||
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, valueWatcher)
|
||||
parentVm.$watch(valueKey + '.*', valueWatcher)
|
||||
parentVm.$watch(valueKey + '.length', valueWatcher)
|
||||
|
||||
if (hooks.watch.value) {
|
||||
hooks.watch.value = [hooks.watch.value]
|
||||
} else {
|
||||
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++
|
||||
|
|
|
@ -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']
|
||||
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)
|
||||
})
|
||||
} else {
|
||||
hooks.watch.value = hooks.watch.value ? [hooks.watch.value] : []
|
||||
hooks.watch.value.push(function(val) {
|
||||
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, valueWatcher)
|
||||
parentVm.$watch(valueKey + '.*', valueWatcher)
|
||||
parentVm.$watch(valueKey + '.length', valueWatcher)
|
||||
|
||||
if (hooks.watch.value) {
|
||||
hooks.watch.value = [hooks.watch.value]
|
||||
} else {
|
||||
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++
|
||||
|
|
|
@ -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
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 `
|
||||
<section class="do-tree__item" :repeat="list" :class="{open: el.open, dir: el[props.children]}">
|
||||
<em
|
||||
:class="{
|
||||
'do-icon-txt': !el.open && !el[props.children],
|
||||
'do-icon-txt': !el[props.children],
|
||||
'do-icon-folder-close': el[props.children] && !el.open,
|
||||
'do-icon-folder-open': el[props.children] && el.open,
|
||||
}"
|
||||
|
@ -58,12 +77,11 @@ export default Anot.component('tree', {
|
|||
:click="__select(el)"
|
||||
:class="{active: el[props.id] === currItem}"
|
||||
:text="el[props.label]"></span>
|
||||
<anot-tree
|
||||
<anot-tree ${multiCheck ? 'multi-check' : ''}
|
||||
:attr="{
|
||||
'multi-check': multiCheck,
|
||||
list: el[props.children],
|
||||
'@onActive': props.onActive,
|
||||
'@onPick': __check,
|
||||
'@itemClick': props.itemClick,
|
||||
'@itemPicked': __check,
|
||||
id: props.id,
|
||||
label: props.label,
|
||||
parent: props.parent,
|
||||
|
@ -72,19 +90,7 @@ export default Anot.component('tree', {
|
|||
</section>
|
||||
`
|
||||
},
|
||||
__init__: function(props, state, next) {
|
||||
this.classList.add('do-tree')
|
||||
this.setAttribute(':if', 'list.size()')
|
||||
props.id = props.id || 'id'
|
||||
props.label = props.label || 'label'
|
||||
props.parent = props.parent || 'parent'
|
||||
props.children = props.children || 'children'
|
||||
state.list = format(props.list || [], props)
|
||||
state.multiCheck = !!props.multiCheck
|
||||
delete props.list
|
||||
delete props.multiCheck
|
||||
next()
|
||||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
this.list.forEach(it => {
|
||||
if (it.__checked__) {
|
||||
|
@ -96,20 +102,22 @@ export default Anot.component('tree', {
|
|||
}
|
||||
},
|
||||
state: {
|
||||
__LIST__: [],
|
||||
__LIST_DICT__: {},
|
||||
list: [],
|
||||
multiCheck: false,
|
||||
currItem: -1,
|
||||
checkedItems: {}
|
||||
},
|
||||
skip: ['checkedItems'],
|
||||
skip: ['checkedItems', '__LIST__', '__LIST_DICT__'],
|
||||
props: {
|
||||
id: '',
|
||||
label: '',
|
||||
parent: '',
|
||||
children: '',
|
||||
created: Anot.PropsTypes.isFunction(),
|
||||
onActive: Anot.PropsTypes.isFunction(),
|
||||
onPick: Anot.PropsTypes.isFunction()
|
||||
itemClick: Anot.PropsTypes.isFunction(),
|
||||
itemPicked: Anot.PropsTypes.isFunction()
|
||||
},
|
||||
methods: {
|
||||
// 子目录的开关
|
||||
|
@ -128,17 +136,17 @@ export default Anot.component('tree', {
|
|||
// return
|
||||
let item = null
|
||||
let arr = []
|
||||
let vm, id, onPick, checkedItems
|
||||
let vm, id, itemPicked, checkedItems
|
||||
|
||||
if (this.props) {
|
||||
vm = this
|
||||
id = this.props.id
|
||||
onPick = this.props.onPick
|
||||
itemPicked = this.props.itemPicked
|
||||
checkedItems = this.checkedItems
|
||||
} else {
|
||||
vm = this.$up
|
||||
id = vm.props.id
|
||||
onPick = vm.props.onPick
|
||||
itemPicked = vm.props.itemPicked
|
||||
checkedItems = vm.checkedItems
|
||||
}
|
||||
|
||||
|
@ -164,23 +172,28 @@ export default Anot.component('tree', {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (typeof onPick === 'function') {
|
||||
onPick(item, arr)
|
||||
if (typeof itemPicked === 'function') {
|
||||
itemPicked(item, arr)
|
||||
}
|
||||
},
|
||||
// 单个条目的点击选择
|
||||
__select: function(el) {
|
||||
let { id, onActive } = this.props
|
||||
let { id, itemClick } = this.props
|
||||
this.currItem = el[id]
|
||||
if (typeof onActive === 'function') {
|
||||
onActive(el.$model)
|
||||
if (typeof itemClick === 'function') {
|
||||
itemClick(this.__LIST_DICT__[el[id]])
|
||||
// itemClick(el.$model)
|
||||
}
|
||||
},
|
||||
// 以给定的列表重置组件渲染
|
||||
resetWith: function(arr) {
|
||||
resetWith: function(arr = []) {
|
||||
this.checked = {}
|
||||
this.list.clear()
|
||||
this.list.pushArray(format(arr || []))
|
||||
for (let it of arr) {
|
||||
this.__LIST__.push(it)
|
||||
this.__LIST_DICT__[it[this.props.id]] = it
|
||||
}
|
||||
this.list.pushArray(format(arr || [], this.props))
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
&:hover {color:nth($cd, 1);}
|
||||
&.active {color:nth($cd, 3);font-weight:bold;}
|
||||
&.checkbox {float:left;position:relative;width:20px;height:20px;margin:8px 5px 8px 0;line-height:18px;border:1px solid nth($cd, 2);border-radius:3px; font-size:20px;text-align:center;}
|
||||
&.checkbox {float:left;position:relative;width:18px;height:18px;margin:8px 5px 8px 0;line-height:16px;border:1px solid nth($cd, 2);border-radius:3px; font-size:16px;text-align:center;}
|
||||
}
|
||||
}
|
||||
&__item.open>.do-tree {display:block;}
|
||||
|
|
Reference in New Issue