This repository has been archived on 2023-08-30. You can view files and clone it, but cannot push or open issues/pull-requests.
bytedo
/
wcui
Archived
1
0
Fork 0

修复组件子父vm关系在某些特定场景下为null的bug

old
宇天 2018-07-20 04:45:47 +08:00
parent 4e8516ffcd
commit e5b4f7e739
6 changed files with 64 additions and 46 deletions

View File

@ -3348,7 +3348,7 @@ const _Anot = (function() {
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 specifiedVars = [':disabled', ':loading', ':value']
var filterTypes = ['html', 'text', 'attr', 'data']
@ -3501,6 +3501,8 @@ const _Anot = (function() {
var widget = isWidget(elem)
if (widget) {
elem.removeAttribute(':if')
elem.removeAttribute(':if-loop')
componentQueue.push({
element: elem,
vmodels: vmodels,
@ -3821,7 +3823,7 @@ const _Anot = (function() {
return
}
hooks.watch = hooks.watch || {}
var parentVm = host.vmodels[0]
var parentVm = host.vmodels.concat().pop()
var state = {}
var props = getOptionsFromTag(elem, host.vmodels)
var $id = props.uuid || generateID(widget)
@ -3974,8 +3976,12 @@ const _Anot = (function() {
delete hooks.componentWillUnmount
var vmodel = Anot(hooks)
hideProperty(vmodel, '__WIDGET__', name)
delete vmodel.$mounted
parentVm.$components.push(vmodel)
if (parentVm.__WIDGET__ === name) {
vmodel.$up = parentVm
}
elem.msResolved = 1 //防止二进扫描此元素
@ -4014,8 +4020,6 @@ const _Anot = (function() {
if (ev.childReady) {
dependencies += ev.childReady
if (vmodel !== ev.vm) {
vmodel.$components.push(ev.vm)
ev.vm.$up = vmodel
if (ev.childReady === -1) {
children++
childComponentDidMount.call(vmodel, ev.vm)

View File

@ -3363,7 +3363,7 @@
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 specifiedVars = [':disabled', ':loading', ':value']
var filterTypes = ['html', 'text', 'attr', 'data']
@ -3516,6 +3516,8 @@
var widget = isWidget(elem)
if (widget) {
elem.removeAttribute(':if')
elem.removeAttribute(':if-loop')
componentQueue.push({
element: elem,
vmodels: vmodels,
@ -3836,7 +3838,7 @@
return
}
hooks.watch = hooks.watch || {}
var parentVm = host.vmodels[0]
var parentVm = host.vmodels.concat().pop()
var state = {}
var props = getOptionsFromTag(elem, host.vmodels)
var $id = props.uuid || generateID(widget)
@ -3989,8 +3991,12 @@
delete hooks.componentWillUnmount
var vmodel = Anot(hooks)
hideProperty(vmodel, '__WIDGET__', name)
delete vmodel.$mounted
parentVm.$components.push(vmodel)
if (parentVm.__WIDGET__ === name) {
vmodel.$up = parentVm
}
elem.msResolved = 1 //防止二进扫描此元素
@ -4029,8 +4035,6 @@
if (ev.childReady) {
dependencies += ev.childReady
if (vmodel !== ev.vm) {
vmodel.$components.push(ev.vm)
ev.vm.$up = vmodel
if (ev.childReady === -1) {
children++
childComponentDidMount.call(vmodel, ev.vm)

View File

@ -3348,7 +3348,7 @@ const _Anot = (function() {
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 specifiedVars = [':disabled', ':loading', ':value']
var filterTypes = ['html', 'text', 'attr', 'data']
@ -3501,6 +3501,8 @@ const _Anot = (function() {
var widget = isWidget(elem)
if (widget) {
elem.removeAttribute(':if')
elem.removeAttribute(':if-loop')
componentQueue.push({
element: elem,
vmodels: vmodels,
@ -3821,7 +3823,7 @@ const _Anot = (function() {
return
}
hooks.watch = hooks.watch || {}
var parentVm = host.vmodels[0]
var parentVm = host.vmodels.concat().pop()
var state = {}
var props = getOptionsFromTag(elem, host.vmodels)
var $id = props.uuid || generateID(widget)
@ -3974,8 +3976,12 @@ const _Anot = (function() {
delete hooks.componentWillUnmount
var vmodel = Anot(hooks)
hideProperty(vmodel, '__WIDGET__', name)
delete vmodel.$mounted
parentVm.$components.push(vmodel)
if (parentVm.__WIDGET__ === name) {
vmodel.$up = parentVm
}
elem.msResolved = 1 //防止二进扫描此元素
@ -4014,8 +4020,6 @@ const _Anot = (function() {
if (ev.childReady) {
dependencies += ev.childReady
if (vmodel !== ev.vm) {
vmodel.$components.push(ev.vm)
ev.vm.$up = vmodel
if (ev.childReady === -1) {
children++
childComponentDidMount.call(vmodel, ev.vm)

View File

@ -3363,7 +3363,7 @@
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 specifiedVars = [':disabled', ':loading', ':value']
var filterTypes = ['html', 'text', 'attr', 'data']
@ -3516,6 +3516,8 @@
var widget = isWidget(elem)
if (widget) {
elem.removeAttribute(':if')
elem.removeAttribute(':if-loop')
componentQueue.push({
element: elem,
vmodels: vmodels,
@ -3836,7 +3838,7 @@
return
}
hooks.watch = hooks.watch || {}
var parentVm = host.vmodels[0]
var parentVm = host.vmodels.concat().pop()
var state = {}
var props = getOptionsFromTag(elem, host.vmodels)
var $id = props.uuid || generateID(widget)
@ -3989,8 +3991,12 @@
delete hooks.componentWillUnmount
var vmodel = Anot(hooks)
hideProperty(vmodel, '__WIDGET__', name)
delete vmodel.$mounted
parentVm.$components.push(vmodel)
if (parentVm.__WIDGET__ === name) {
vmodel.$up = parentVm
}
elem.msResolved = 1 //防止二进扫描此元素
@ -4029,8 +4035,6 @@
if (ev.childReady) {
dependencies += ev.childReady
if (vmodel !== ev.vm) {
vmodel.$components.push(ev.vm)
ev.vm.$up = vmodel
if (ev.childReady === -1) {
children++
childComponentDidMount.call(vmodel, ev.vm)

View File

@ -13,7 +13,7 @@ import './main.scss'
Anot.ui.tree = '1.0.0'
const log = console.log
function format(arr, { id, parent, label, children }) {
function format(arr, { id, parent, label }) {
let tmp = {}
let farr = []
arr = Anot.deepCopy(arr)
@ -31,8 +31,8 @@ function format(arr, { id, parent, label, children }) {
if (!parentItem) {
return farr.push(tmp[it[id]])
}
parentItem[children] = parentItem[children] || []
parentItem[children].push(it)
parentItem.children = parentItem.children || []
parentItem.children.push(it)
})
return farr
}
@ -40,17 +40,15 @@ function format(arr, { id, parent, label, children }) {
export default Anot.component('tree', {
__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'
// this.setAttribute(':visible', 'list.size()')
if (props.list) {
for (let it of props.list) {
state.__LIST__.push(it)
state.__LIST_DICT__[it[props.id]] = it
}
}
state.value = state.value || []
state.list = format(props.list || [], props)
state.multiCheck = props.hasOwnProperty('multiCheck')
delete props.list
@ -59,34 +57,38 @@ export default Anot.component('tree', {
},
render: function() {
let { multiCheck } = this
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
:class="{
'do-icon-txt': !el[props.children],
'do-icon-folder-close': el[props.children] && !el.open,
'do-icon-folder-open': el[props.children] && el.open,
'do-icon-txt': !el.children,
'do-icon-folder-close': el.children && !el.open,
'do-icon-folder-open': el.children && el.open,
}"
:click="__toggle(el)"></em>
<span
class="checkbox"
:class="{'do-icon-get': el.__checked__}"
:class="{'do-icon-get': value.includes(el[props.id])}"
:if="multiCheck"
:click="__check(el, null, $event)"></span>
<span
:click="__select(el)"
:class="{active: el[props.id] === currItem}"
:text="el[props.label]"></span>
<div class="sub-tree" :if-loop="el.children">
<anot-tree ${multiCheck ? 'multi-check' : ''}
:value="value"
:attr="{
list: el[props.children],
list: el.children,
'@itemClick': props.itemClick,
'@itemPicked': __check,
id: props.id,
label: props.label,
parent: props.parent,
children: props.children,
}"></anot-tree>
</div>
</section>
`
},
@ -105,16 +107,16 @@ export default Anot.component('tree', {
__LIST__: [],
__LIST_DICT__: {},
list: [],
value: [],
multiCheck: false,
currItem: -1,
checkedItems: {}
},
skip: ['checkedItems', '__LIST__', '__LIST_DICT__'],
props: {
id: '',
label: '',
parent: '',
children: '',
id: 'id',
label: 'label',
parent: 'parent',
created: Anot.PropsTypes.isFunction(),
itemClick: Anot.PropsTypes.isFunction(),
itemPicked: Anot.PropsTypes.isFunction()
@ -122,7 +124,7 @@ export default Anot.component('tree', {
methods: {
// 子目录的开关
__toggle: function(obj) {
if (!obj[this.props.children]) {
if (!obj.children) {
return
}
obj.open = !obj.open

View File

@ -13,7 +13,7 @@
&__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 {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;}
}
}
&__item.open>.do-tree {display:block;}
&__item.open>.sub-tree {display:block;}
}