修复组件子父vm关系在某些特定场景下为null的bug
parent
4e8516ffcd
commit
e5b4f7e739
|
@ -3348,7 +3348,7 @@ const _Anot = (function() {
|
||||||
return a.priority - b.priority
|
return a.priority - b.priority
|
||||||
}
|
}
|
||||||
|
|
||||||
var rnoCollect = /^(:\S+|data-\S+|on[a-z]+|id|style|class)$/
|
var rnoCollect = /^(:\S+|data-\S+|on[a-z]+|style|class)$/
|
||||||
var ronattr = '__fn__'
|
var ronattr = '__fn__'
|
||||||
var specifiedVars = [':disabled', ':loading', ':value']
|
var specifiedVars = [':disabled', ':loading', ':value']
|
||||||
var filterTypes = ['html', 'text', 'attr', 'data']
|
var filterTypes = ['html', 'text', 'attr', 'data']
|
||||||
|
@ -3501,6 +3501,8 @@ const _Anot = (function() {
|
||||||
var widget = isWidget(elem)
|
var widget = isWidget(elem)
|
||||||
|
|
||||||
if (widget) {
|
if (widget) {
|
||||||
|
elem.removeAttribute(':if')
|
||||||
|
elem.removeAttribute(':if-loop')
|
||||||
componentQueue.push({
|
componentQueue.push({
|
||||||
element: elem,
|
element: elem,
|
||||||
vmodels: vmodels,
|
vmodels: vmodels,
|
||||||
|
@ -3821,7 +3823,7 @@ const _Anot = (function() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hooks.watch = hooks.watch || {}
|
hooks.watch = hooks.watch || {}
|
||||||
var parentVm = host.vmodels[0]
|
var parentVm = host.vmodels.concat().pop()
|
||||||
var state = {}
|
var state = {}
|
||||||
var props = getOptionsFromTag(elem, host.vmodels)
|
var props = getOptionsFromTag(elem, host.vmodels)
|
||||||
var $id = props.uuid || generateID(widget)
|
var $id = props.uuid || generateID(widget)
|
||||||
|
@ -3974,8 +3976,12 @@ const _Anot = (function() {
|
||||||
delete hooks.componentWillUnmount
|
delete hooks.componentWillUnmount
|
||||||
|
|
||||||
var vmodel = Anot(hooks)
|
var vmodel = Anot(hooks)
|
||||||
|
hideProperty(vmodel, '__WIDGET__', name)
|
||||||
delete vmodel.$mounted
|
delete vmodel.$mounted
|
||||||
parentVm.$components.push(vmodel)
|
parentVm.$components.push(vmodel)
|
||||||
|
if (parentVm.__WIDGET__ === name) {
|
||||||
|
vmodel.$up = parentVm
|
||||||
|
}
|
||||||
|
|
||||||
elem.msResolved = 1 //防止二进扫描此元素
|
elem.msResolved = 1 //防止二进扫描此元素
|
||||||
|
|
||||||
|
@ -4014,8 +4020,6 @@ const _Anot = (function() {
|
||||||
if (ev.childReady) {
|
if (ev.childReady) {
|
||||||
dependencies += ev.childReady
|
dependencies += ev.childReady
|
||||||
if (vmodel !== ev.vm) {
|
if (vmodel !== ev.vm) {
|
||||||
vmodel.$components.push(ev.vm)
|
|
||||||
ev.vm.$up = vmodel
|
|
||||||
if (ev.childReady === -1) {
|
if (ev.childReady === -1) {
|
||||||
children++
|
children++
|
||||||
childComponentDidMount.call(vmodel, ev.vm)
|
childComponentDidMount.call(vmodel, ev.vm)
|
||||||
|
|
|
@ -3363,7 +3363,7 @@
|
||||||
return a.priority - b.priority
|
return a.priority - b.priority
|
||||||
}
|
}
|
||||||
|
|
||||||
var rnoCollect = /^(:\S+|data-\S+|on[a-z]+|id|style|class)$/
|
var rnoCollect = /^(:\S+|data-\S+|on[a-z]+|style|class)$/
|
||||||
var ronattr = '__fn__'
|
var ronattr = '__fn__'
|
||||||
var specifiedVars = [':disabled', ':loading', ':value']
|
var specifiedVars = [':disabled', ':loading', ':value']
|
||||||
var filterTypes = ['html', 'text', 'attr', 'data']
|
var filterTypes = ['html', 'text', 'attr', 'data']
|
||||||
|
@ -3516,6 +3516,8 @@
|
||||||
var widget = isWidget(elem)
|
var widget = isWidget(elem)
|
||||||
|
|
||||||
if (widget) {
|
if (widget) {
|
||||||
|
elem.removeAttribute(':if')
|
||||||
|
elem.removeAttribute(':if-loop')
|
||||||
componentQueue.push({
|
componentQueue.push({
|
||||||
element: elem,
|
element: elem,
|
||||||
vmodels: vmodels,
|
vmodels: vmodels,
|
||||||
|
@ -3836,7 +3838,7 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hooks.watch = hooks.watch || {}
|
hooks.watch = hooks.watch || {}
|
||||||
var parentVm = host.vmodels[0]
|
var parentVm = host.vmodels.concat().pop()
|
||||||
var state = {}
|
var state = {}
|
||||||
var props = getOptionsFromTag(elem, host.vmodels)
|
var props = getOptionsFromTag(elem, host.vmodels)
|
||||||
var $id = props.uuid || generateID(widget)
|
var $id = props.uuid || generateID(widget)
|
||||||
|
@ -3989,8 +3991,12 @@
|
||||||
delete hooks.componentWillUnmount
|
delete hooks.componentWillUnmount
|
||||||
|
|
||||||
var vmodel = Anot(hooks)
|
var vmodel = Anot(hooks)
|
||||||
|
hideProperty(vmodel, '__WIDGET__', name)
|
||||||
delete vmodel.$mounted
|
delete vmodel.$mounted
|
||||||
parentVm.$components.push(vmodel)
|
parentVm.$components.push(vmodel)
|
||||||
|
if (parentVm.__WIDGET__ === name) {
|
||||||
|
vmodel.$up = parentVm
|
||||||
|
}
|
||||||
|
|
||||||
elem.msResolved = 1 //防止二进扫描此元素
|
elem.msResolved = 1 //防止二进扫描此元素
|
||||||
|
|
||||||
|
@ -4029,8 +4035,6 @@
|
||||||
if (ev.childReady) {
|
if (ev.childReady) {
|
||||||
dependencies += ev.childReady
|
dependencies += ev.childReady
|
||||||
if (vmodel !== ev.vm) {
|
if (vmodel !== ev.vm) {
|
||||||
vmodel.$components.push(ev.vm)
|
|
||||||
ev.vm.$up = vmodel
|
|
||||||
if (ev.childReady === -1) {
|
if (ev.childReady === -1) {
|
||||||
children++
|
children++
|
||||||
childComponentDidMount.call(vmodel, ev.vm)
|
childComponentDidMount.call(vmodel, ev.vm)
|
||||||
|
|
|
@ -3348,7 +3348,7 @@ const _Anot = (function() {
|
||||||
return a.priority - b.priority
|
return a.priority - b.priority
|
||||||
}
|
}
|
||||||
|
|
||||||
var rnoCollect = /^(:\S+|data-\S+|on[a-z]+|id|style|class)$/
|
var rnoCollect = /^(:\S+|data-\S+|on[a-z]+|style|class)$/
|
||||||
var ronattr = '__fn__'
|
var ronattr = '__fn__'
|
||||||
var specifiedVars = [':disabled', ':loading', ':value']
|
var specifiedVars = [':disabled', ':loading', ':value']
|
||||||
var filterTypes = ['html', 'text', 'attr', 'data']
|
var filterTypes = ['html', 'text', 'attr', 'data']
|
||||||
|
@ -3501,6 +3501,8 @@ const _Anot = (function() {
|
||||||
var widget = isWidget(elem)
|
var widget = isWidget(elem)
|
||||||
|
|
||||||
if (widget) {
|
if (widget) {
|
||||||
|
elem.removeAttribute(':if')
|
||||||
|
elem.removeAttribute(':if-loop')
|
||||||
componentQueue.push({
|
componentQueue.push({
|
||||||
element: elem,
|
element: elem,
|
||||||
vmodels: vmodels,
|
vmodels: vmodels,
|
||||||
|
@ -3821,7 +3823,7 @@ const _Anot = (function() {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hooks.watch = hooks.watch || {}
|
hooks.watch = hooks.watch || {}
|
||||||
var parentVm = host.vmodels[0]
|
var parentVm = host.vmodels.concat().pop()
|
||||||
var state = {}
|
var state = {}
|
||||||
var props = getOptionsFromTag(elem, host.vmodels)
|
var props = getOptionsFromTag(elem, host.vmodels)
|
||||||
var $id = props.uuid || generateID(widget)
|
var $id = props.uuid || generateID(widget)
|
||||||
|
@ -3974,8 +3976,12 @@ const _Anot = (function() {
|
||||||
delete hooks.componentWillUnmount
|
delete hooks.componentWillUnmount
|
||||||
|
|
||||||
var vmodel = Anot(hooks)
|
var vmodel = Anot(hooks)
|
||||||
|
hideProperty(vmodel, '__WIDGET__', name)
|
||||||
delete vmodel.$mounted
|
delete vmodel.$mounted
|
||||||
parentVm.$components.push(vmodel)
|
parentVm.$components.push(vmodel)
|
||||||
|
if (parentVm.__WIDGET__ === name) {
|
||||||
|
vmodel.$up = parentVm
|
||||||
|
}
|
||||||
|
|
||||||
elem.msResolved = 1 //防止二进扫描此元素
|
elem.msResolved = 1 //防止二进扫描此元素
|
||||||
|
|
||||||
|
@ -4014,8 +4020,6 @@ const _Anot = (function() {
|
||||||
if (ev.childReady) {
|
if (ev.childReady) {
|
||||||
dependencies += ev.childReady
|
dependencies += ev.childReady
|
||||||
if (vmodel !== ev.vm) {
|
if (vmodel !== ev.vm) {
|
||||||
vmodel.$components.push(ev.vm)
|
|
||||||
ev.vm.$up = vmodel
|
|
||||||
if (ev.childReady === -1) {
|
if (ev.childReady === -1) {
|
||||||
children++
|
children++
|
||||||
childComponentDidMount.call(vmodel, ev.vm)
|
childComponentDidMount.call(vmodel, ev.vm)
|
||||||
|
|
|
@ -3363,7 +3363,7 @@
|
||||||
return a.priority - b.priority
|
return a.priority - b.priority
|
||||||
}
|
}
|
||||||
|
|
||||||
var rnoCollect = /^(:\S+|data-\S+|on[a-z]+|id|style|class)$/
|
var rnoCollect = /^(:\S+|data-\S+|on[a-z]+|style|class)$/
|
||||||
var ronattr = '__fn__'
|
var ronattr = '__fn__'
|
||||||
var specifiedVars = [':disabled', ':loading', ':value']
|
var specifiedVars = [':disabled', ':loading', ':value']
|
||||||
var filterTypes = ['html', 'text', 'attr', 'data']
|
var filterTypes = ['html', 'text', 'attr', 'data']
|
||||||
|
@ -3516,6 +3516,8 @@
|
||||||
var widget = isWidget(elem)
|
var widget = isWidget(elem)
|
||||||
|
|
||||||
if (widget) {
|
if (widget) {
|
||||||
|
elem.removeAttribute(':if')
|
||||||
|
elem.removeAttribute(':if-loop')
|
||||||
componentQueue.push({
|
componentQueue.push({
|
||||||
element: elem,
|
element: elem,
|
||||||
vmodels: vmodels,
|
vmodels: vmodels,
|
||||||
|
@ -3836,7 +3838,7 @@
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
hooks.watch = hooks.watch || {}
|
hooks.watch = hooks.watch || {}
|
||||||
var parentVm = host.vmodels[0]
|
var parentVm = host.vmodels.concat().pop()
|
||||||
var state = {}
|
var state = {}
|
||||||
var props = getOptionsFromTag(elem, host.vmodels)
|
var props = getOptionsFromTag(elem, host.vmodels)
|
||||||
var $id = props.uuid || generateID(widget)
|
var $id = props.uuid || generateID(widget)
|
||||||
|
@ -3989,8 +3991,12 @@
|
||||||
delete hooks.componentWillUnmount
|
delete hooks.componentWillUnmount
|
||||||
|
|
||||||
var vmodel = Anot(hooks)
|
var vmodel = Anot(hooks)
|
||||||
|
hideProperty(vmodel, '__WIDGET__', name)
|
||||||
delete vmodel.$mounted
|
delete vmodel.$mounted
|
||||||
parentVm.$components.push(vmodel)
|
parentVm.$components.push(vmodel)
|
||||||
|
if (parentVm.__WIDGET__ === name) {
|
||||||
|
vmodel.$up = parentVm
|
||||||
|
}
|
||||||
|
|
||||||
elem.msResolved = 1 //防止二进扫描此元素
|
elem.msResolved = 1 //防止二进扫描此元素
|
||||||
|
|
||||||
|
@ -4029,8 +4035,6 @@
|
||||||
if (ev.childReady) {
|
if (ev.childReady) {
|
||||||
dependencies += ev.childReady
|
dependencies += ev.childReady
|
||||||
if (vmodel !== ev.vm) {
|
if (vmodel !== ev.vm) {
|
||||||
vmodel.$components.push(ev.vm)
|
|
||||||
ev.vm.$up = vmodel
|
|
||||||
if (ev.childReady === -1) {
|
if (ev.childReady === -1) {
|
||||||
children++
|
children++
|
||||||
childComponentDidMount.call(vmodel, ev.vm)
|
childComponentDidMount.call(vmodel, ev.vm)
|
||||||
|
|
|
@ -13,7 +13,7 @@ import './main.scss'
|
||||||
Anot.ui.tree = '1.0.0'
|
Anot.ui.tree = '1.0.0'
|
||||||
const log = console.log
|
const log = console.log
|
||||||
|
|
||||||
function format(arr, { id, parent, label, children }) {
|
function format(arr, { id, parent, label }) {
|
||||||
let tmp = {}
|
let tmp = {}
|
||||||
let farr = []
|
let farr = []
|
||||||
arr = Anot.deepCopy(arr)
|
arr = Anot.deepCopy(arr)
|
||||||
|
@ -31,8 +31,8 @@ function format(arr, { id, parent, label, children }) {
|
||||||
if (!parentItem) {
|
if (!parentItem) {
|
||||||
return farr.push(tmp[it[id]])
|
return farr.push(tmp[it[id]])
|
||||||
}
|
}
|
||||||
parentItem[children] = parentItem[children] || []
|
parentItem.children = parentItem.children || []
|
||||||
parentItem[children].push(it)
|
parentItem.children.push(it)
|
||||||
})
|
})
|
||||||
return farr
|
return farr
|
||||||
}
|
}
|
||||||
|
@ -40,17 +40,15 @@ function format(arr, { id, parent, label, children }) {
|
||||||
export default Anot.component('tree', {
|
export default Anot.component('tree', {
|
||||||
__init__: function(props, state, next) {
|
__init__: function(props, state, next) {
|
||||||
this.classList.add('do-tree')
|
this.classList.add('do-tree')
|
||||||
this.setAttribute(':visible', 'list.size()')
|
// 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) {
|
if (props.list) {
|
||||||
for (let it of props.list) {
|
for (let it of props.list) {
|
||||||
state.__LIST__.push(it)
|
state.__LIST__.push(it)
|
||||||
state.__LIST_DICT__[it[props.id]] = it
|
state.__LIST_DICT__[it[props.id]] = it
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
state.value = state.value || []
|
||||||
state.list = format(props.list || [], props)
|
state.list = format(props.list || [], props)
|
||||||
state.multiCheck = props.hasOwnProperty('multiCheck')
|
state.multiCheck = props.hasOwnProperty('multiCheck')
|
||||||
delete props.list
|
delete props.list
|
||||||
|
@ -59,34 +57,38 @@ export default Anot.component('tree', {
|
||||||
},
|
},
|
||||||
render: function() {
|
render: function() {
|
||||||
let { multiCheck } = this
|
let { multiCheck } = this
|
||||||
|
|
||||||
return `
|
return `
|
||||||
<section class="do-tree__item" :repeat="list" :class="{open: el.open, dir: el[props.children]}">
|
<section class="do-tree__item" :repeat="list" :class="{open: el.open, dir: el.children}">
|
||||||
<em
|
<em
|
||||||
:class="{
|
:class="{
|
||||||
'do-icon-txt': !el[props.children],
|
'do-icon-txt': !el.children,
|
||||||
'do-icon-folder-close': el[props.children] && !el.open,
|
'do-icon-folder-close': el.children && !el.open,
|
||||||
'do-icon-folder-open': el[props.children] && el.open,
|
'do-icon-folder-open': el.children && el.open,
|
||||||
}"
|
}"
|
||||||
:click="__toggle(el)"></em>
|
:click="__toggle(el)"></em>
|
||||||
<span
|
<span
|
||||||
class="checkbox"
|
class="checkbox"
|
||||||
:class="{'do-icon-get': el.__checked__}"
|
:class="{'do-icon-get': value.includes(el[props.id])}"
|
||||||
:if="multiCheck"
|
:if="multiCheck"
|
||||||
:click="__check(el, null, $event)"></span>
|
:click="__check(el, null, $event)"></span>
|
||||||
<span
|
<span
|
||||||
:click="__select(el)"
|
:click="__select(el)"
|
||||||
:class="{active: el[props.id] === currItem}"
|
:class="{active: el[props.id] === currItem}"
|
||||||
:text="el[props.label]"></span>
|
:text="el[props.label]"></span>
|
||||||
|
|
||||||
|
<div class="sub-tree" :if-loop="el.children">
|
||||||
<anot-tree ${multiCheck ? 'multi-check' : ''}
|
<anot-tree ${multiCheck ? 'multi-check' : ''}
|
||||||
|
:value="value"
|
||||||
:attr="{
|
:attr="{
|
||||||
list: el[props.children],
|
list: el.children,
|
||||||
'@itemClick': props.itemClick,
|
'@itemClick': props.itemClick,
|
||||||
'@itemPicked': __check,
|
'@itemPicked': __check,
|
||||||
id: props.id,
|
id: props.id,
|
||||||
label: props.label,
|
label: props.label,
|
||||||
parent: props.parent,
|
parent: props.parent,
|
||||||
children: props.children,
|
|
||||||
}"></anot-tree>
|
}"></anot-tree>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
`
|
`
|
||||||
},
|
},
|
||||||
|
@ -105,16 +107,16 @@ export default Anot.component('tree', {
|
||||||
__LIST__: [],
|
__LIST__: [],
|
||||||
__LIST_DICT__: {},
|
__LIST_DICT__: {},
|
||||||
list: [],
|
list: [],
|
||||||
|
value: [],
|
||||||
multiCheck: false,
|
multiCheck: false,
|
||||||
currItem: -1,
|
currItem: -1,
|
||||||
checkedItems: {}
|
checkedItems: {}
|
||||||
},
|
},
|
||||||
skip: ['checkedItems', '__LIST__', '__LIST_DICT__'],
|
skip: ['checkedItems', '__LIST__', '__LIST_DICT__'],
|
||||||
props: {
|
props: {
|
||||||
id: '',
|
id: 'id',
|
||||||
label: '',
|
label: 'label',
|
||||||
parent: '',
|
parent: 'parent',
|
||||||
children: '',
|
|
||||||
created: Anot.PropsTypes.isFunction(),
|
created: Anot.PropsTypes.isFunction(),
|
||||||
itemClick: Anot.PropsTypes.isFunction(),
|
itemClick: Anot.PropsTypes.isFunction(),
|
||||||
itemPicked: Anot.PropsTypes.isFunction()
|
itemPicked: Anot.PropsTypes.isFunction()
|
||||||
|
@ -122,7 +124,7 @@ export default Anot.component('tree', {
|
||||||
methods: {
|
methods: {
|
||||||
// 子目录的开关
|
// 子目录的开关
|
||||||
__toggle: function(obj) {
|
__toggle: function(obj) {
|
||||||
if (!obj[this.props.children]) {
|
if (!obj.children) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
obj.open = !obj.open
|
obj.open = !obj.open
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
|
|
||||||
&__item {overflow:hidden; min-height:35px;margin:1px 0; white-space:nowrap; text-overflow:ellipsis;
|
&__item {overflow:hidden; min-height:35px;margin:1px 0; white-space:nowrap; text-overflow:ellipsis;
|
||||||
|
|
||||||
.do-tree {display:none;margin-left:20px;}
|
.sub-tree {display:none;margin-left:20px;}
|
||||||
|
|
||||||
em,span {display:inline-block;cursor:pointer;color:nth($cd, 1);}
|
em,span {display:inline-block;cursor:pointer;color:nth($cd, 1);}
|
||||||
em {float:left;padding:0 5px;font-size:20px;}
|
em {float:left;padding:0 5px;font-size:20px;}
|
||||||
|
@ -25,6 +25,6 @@
|
||||||
&.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;}
|
&.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;}
|
&__item.open>.sub-tree {display:block;}
|
||||||
|
|
||||||
}
|
}
|
Reference in New Issue