From e5b4f7e739cb9b188d9f86e3faabb7cd14962f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=87=E5=A4=A9?= Date: Fri, 20 Jul 2018 04:45:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E7=BB=84=E4=BB=B6=E5=AD=90?= =?UTF-8?q?=E7=88=B6vm=E5=85=B3=E7=B3=BB=E5=9C=A8=E6=9F=90=E4=BA=9B?= =?UTF-8?q?=E7=89=B9=E5=AE=9A=E5=9C=BA=E6=99=AF=E4=B8=8B=E4=B8=BAnull?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/js/anot-touch.js | 12 +++++--- src/js/anot-touch.shim.js | 12 +++++--- src/js/anot.js | 12 +++++--- src/js/anot.shim.js | 12 +++++--- src/js/tree/index.js | 58 ++++++++++++++++++++------------------- src/js/tree/main.scss | 4 +-- 6 files changed, 64 insertions(+), 46 deletions(-) diff --git a/src/js/anot-touch.js b/src/js/anot-touch.js index 0c51430..5fca328 100644 --- a/src/js/anot-touch.js +++ b/src/js/anot-touch.js @@ -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) diff --git a/src/js/anot-touch.shim.js b/src/js/anot-touch.shim.js index 94b03b0..95bd1aa 100644 --- a/src/js/anot-touch.shim.js +++ b/src/js/anot-touch.shim.js @@ -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) diff --git a/src/js/anot.js b/src/js/anot.js index 9356a5c..c7c9873 100644 --- a/src/js/anot.js +++ b/src/js/anot.js @@ -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) diff --git a/src/js/anot.shim.js b/src/js/anot.shim.js index 89233e2..86508e1 100644 --- a/src/js/anot.shim.js +++ b/src/js/anot.shim.js @@ -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) diff --git a/src/js/tree/index.js b/src/js/tree/index.js index e44b993..d224ccb 100644 --- a/src/js/tree/index.js +++ b/src/js/tree/index.js @@ -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 ` -
+
- + +
+ +
` }, @@ -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 diff --git a/src/js/tree/main.scss b/src/js/tree/main.scss index 27c003a..4fc48fb 100644 --- a/src/js/tree/main.scss +++ b/src/js/tree/main.scss @@ -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;} } \ No newline at end of file