优化组件子父关系的定义;移除组件:if指令的支持;完成tree组件的移植
parent
e5b4f7e739
commit
2aaa7ad832
|
@ -227,14 +227,11 @@ const _Anot = (function() {
|
|||
} else {
|
||||
var _parent = $elem
|
||||
while ((_parent = _parent.parentNode)) {
|
||||
if (_parent.anotctrl) {
|
||||
if (_parent.__VM__) {
|
||||
break
|
||||
}
|
||||
}
|
||||
scanTag(
|
||||
$elem.parentNode,
|
||||
_parent ? [VMODELS[_parent.anotctrl]] : []
|
||||
)
|
||||
scanTag($elem.parentNode, _parent ? [_parent.__VM__] : [])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -3283,10 +3280,6 @@ const _Anot = (function() {
|
|||
})
|
||||
}
|
||||
|
||||
function createSignalTower(elem, vmodel) {
|
||||
elem.anotctrl = elem.anotctrl || vmodel.$id
|
||||
}
|
||||
|
||||
function getBindingCallback(elem, name, vmodels) {
|
||||
var callback = elem.getAttribute(name)
|
||||
if (callback) {
|
||||
|
@ -3559,7 +3552,8 @@ const _Anot = (function() {
|
|||
vm = [newVmodel]
|
||||
|
||||
elem.removeAttribute(node.name) //removeAttributeNode不会刷新xx[anot]样式规则
|
||||
createSignalTower(elem, newVmodel)
|
||||
// 挂载VM对象到相应的元素上
|
||||
elem.__VM__ = newVmodel
|
||||
hideProperty(newVmodel, '$elem', elem)
|
||||
|
||||
if (vmodels.length) {
|
||||
|
@ -3827,19 +3821,12 @@ const _Anot = (function() {
|
|||
var state = {}
|
||||
var props = getOptionsFromTag(elem, host.vmodels)
|
||||
var $id = props.uuid || generateID(widget)
|
||||
var __willpush__ = null
|
||||
var slots = null
|
||||
|
||||
if (elem.firstElementChild) {
|
||||
slots = parseSlot(elem.children)
|
||||
}
|
||||
|
||||
if (props.hasOwnProperty('hostPush')) {
|
||||
elem.removeAttribute('host-push')
|
||||
__willpush__ = props.hostPush
|
||||
props.hostPush = parseVmValue(parentVm, __willpush__)
|
||||
}
|
||||
|
||||
if (props.hasOwnProperty(':disabled')) {
|
||||
var disabledKey = props[':disabled']
|
||||
var disabledKeyReverse = false
|
||||
|
@ -3891,7 +3878,7 @@ const _Anot = (function() {
|
|||
var childValueWatcher = function() {
|
||||
var val = this.value
|
||||
if (val && typeof val === 'object') {
|
||||
val = val.$model || val
|
||||
val = val.$model
|
||||
}
|
||||
parseVmValue(parentVm, valueKey, val)
|
||||
}
|
||||
|
@ -3978,19 +3965,21 @@ const _Anot = (function() {
|
|||
var vmodel = Anot(hooks)
|
||||
hideProperty(vmodel, '__WIDGET__', name)
|
||||
delete vmodel.$mounted
|
||||
parentVm.$components.push(vmodel)
|
||||
if (parentVm.__WIDGET__ === name) {
|
||||
vmodel.$up = parentVm
|
||||
|
||||
// 对象组件的子父vm关系, 只存最顶层的$components对象中,
|
||||
// 而子vm, 无论向下多少级, 他们的$up对象也只存最顶层的组件vm
|
||||
var __pvm__ = parentVm
|
||||
while (__pvm__.$up && __pvm__.$up.__WIDGET__ === name) {
|
||||
__pvm__ = __pvm__.$up
|
||||
}
|
||||
__pvm__.$components.push(vmodel)
|
||||
if (__pvm__.__WIDGET__ === name) {
|
||||
vmodel.$up = __pvm__
|
||||
}
|
||||
__pvm__ = undefined
|
||||
|
||||
elem.msResolved = 1 //防止二进扫描此元素
|
||||
|
||||
if (__willpush__) {
|
||||
hideProperty(vmodel, '$push', function(val) {
|
||||
parseVmValue(parentVm, __willpush__, val)
|
||||
})
|
||||
}
|
||||
|
||||
componentWillMount.call(vmodel)
|
||||
globalHooks.componentWillMount.call(null, vmodel)
|
||||
|
||||
|
@ -4051,6 +4040,7 @@ const _Anot = (function() {
|
|||
}
|
||||
}
|
||||
})
|
||||
elem.__VM__ = vmodel
|
||||
scanTag(elem, [vmodel])
|
||||
Anot.vmodels[vmodel.$id] = vmodel
|
||||
if (!elem.childNodes.length) {
|
||||
|
|
|
@ -242,14 +242,11 @@
|
|||
} else {
|
||||
var _parent = $elem
|
||||
while ((_parent = _parent.parentNode)) {
|
||||
if (_parent.anotctrl) {
|
||||
if (_parent.__VM__) {
|
||||
break
|
||||
}
|
||||
}
|
||||
scanTag(
|
||||
$elem.parentNode,
|
||||
_parent ? [VMODELS[_parent.anotctrl]] : []
|
||||
)
|
||||
scanTag($elem.parentNode, _parent ? [_parent.__VM__] : [])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -3298,10 +3295,6 @@
|
|||
})
|
||||
}
|
||||
|
||||
function createSignalTower(elem, vmodel) {
|
||||
elem.anotctrl = elem.anotctrl || vmodel.$id
|
||||
}
|
||||
|
||||
function getBindingCallback(elem, name, vmodels) {
|
||||
var callback = elem.getAttribute(name)
|
||||
if (callback) {
|
||||
|
@ -3574,7 +3567,8 @@
|
|||
vm = [newVmodel]
|
||||
|
||||
elem.removeAttribute(node.name) //removeAttributeNode不会刷新xx[anot]样式规则
|
||||
createSignalTower(elem, newVmodel)
|
||||
// 挂载VM对象到相应的元素上
|
||||
elem.__VM__ = newVmodel
|
||||
hideProperty(newVmodel, '$elem', elem)
|
||||
|
||||
if (vmodels.length) {
|
||||
|
@ -3842,19 +3836,12 @@
|
|||
var state = {}
|
||||
var props = getOptionsFromTag(elem, host.vmodels)
|
||||
var $id = props.uuid || generateID(widget)
|
||||
var __willpush__ = null
|
||||
var slots = null
|
||||
|
||||
if (elem.firstElementChild) {
|
||||
slots = parseSlot(elem.children)
|
||||
}
|
||||
|
||||
if (props.hasOwnProperty('hostPush')) {
|
||||
elem.removeAttribute('host-push')
|
||||
__willpush__ = props.hostPush
|
||||
props.hostPush = parseVmValue(parentVm, __willpush__)
|
||||
}
|
||||
|
||||
if (props.hasOwnProperty(':disabled')) {
|
||||
var disabledKey = props[':disabled']
|
||||
var disabledKeyReverse = false
|
||||
|
@ -3906,7 +3893,7 @@
|
|||
var childValueWatcher = function() {
|
||||
var val = this.value
|
||||
if (val && typeof val === 'object') {
|
||||
val = val.$model || val
|
||||
val = val.$model
|
||||
}
|
||||
parseVmValue(parentVm, valueKey, val)
|
||||
}
|
||||
|
@ -3993,19 +3980,21 @@
|
|||
var vmodel = Anot(hooks)
|
||||
hideProperty(vmodel, '__WIDGET__', name)
|
||||
delete vmodel.$mounted
|
||||
parentVm.$components.push(vmodel)
|
||||
if (parentVm.__WIDGET__ === name) {
|
||||
vmodel.$up = parentVm
|
||||
|
||||
// 对象组件的子父vm关系, 只存最顶层的$components对象中,
|
||||
// 而子vm, 无论向下多少级, 他们的$up对象也只存最顶层的组件vm
|
||||
var __pvm__ = parentVm
|
||||
while (__pvm__.$up && __pvm__.$up.__WIDGET__ === name) {
|
||||
__pvm__ = __pvm__.$up
|
||||
}
|
||||
__pvm__.$components.push(vmodel)
|
||||
if (__pvm__.__WIDGET__ === name) {
|
||||
vmodel.$up = __pvm__
|
||||
}
|
||||
__pvm__ = undefined
|
||||
|
||||
elem.msResolved = 1 //防止二进扫描此元素
|
||||
|
||||
if (__willpush__) {
|
||||
hideProperty(vmodel, '$push', function(val) {
|
||||
parseVmValue(parentVm, __willpush__, val)
|
||||
})
|
||||
}
|
||||
|
||||
componentWillMount.call(vmodel)
|
||||
globalHooks.componentWillMount.call(null, vmodel)
|
||||
|
||||
|
@ -4066,6 +4055,7 @@
|
|||
}
|
||||
}
|
||||
})
|
||||
elem.__VM__ = vmodel
|
||||
scanTag(elem, [vmodel])
|
||||
Anot.vmodels[vmodel.$id] = vmodel
|
||||
if (!elem.childNodes.length) {
|
||||
|
|
|
@ -227,14 +227,11 @@ const _Anot = (function() {
|
|||
} else {
|
||||
var _parent = $elem
|
||||
while ((_parent = _parent.parentNode)) {
|
||||
if (_parent.anotctrl) {
|
||||
if (_parent.__VM__) {
|
||||
break
|
||||
}
|
||||
}
|
||||
scanTag(
|
||||
$elem.parentNode,
|
||||
_parent ? [VMODELS[_parent.anotctrl]] : []
|
||||
)
|
||||
scanTag($elem.parentNode, _parent ? [_parent.__VM__] : [])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -3283,10 +3280,6 @@ const _Anot = (function() {
|
|||
})
|
||||
}
|
||||
|
||||
function createSignalTower(elem, vmodel) {
|
||||
elem.anotctrl = elem.anotctrl || vmodel.$id
|
||||
}
|
||||
|
||||
function getBindingCallback(elem, name, vmodels) {
|
||||
var callback = elem.getAttribute(name)
|
||||
if (callback) {
|
||||
|
@ -3559,7 +3552,8 @@ const _Anot = (function() {
|
|||
vm = [newVmodel]
|
||||
|
||||
elem.removeAttribute(node.name) //removeAttributeNode不会刷新xx[anot]样式规则
|
||||
createSignalTower(elem, newVmodel)
|
||||
// 挂载VM对象到相应的元素上
|
||||
elem.__VM__ = newVmodel
|
||||
hideProperty(newVmodel, '$elem', elem)
|
||||
|
||||
if (vmodels.length) {
|
||||
|
@ -3827,19 +3821,12 @@ const _Anot = (function() {
|
|||
var state = {}
|
||||
var props = getOptionsFromTag(elem, host.vmodels)
|
||||
var $id = props.uuid || generateID(widget)
|
||||
var __willpush__ = null
|
||||
var slots = null
|
||||
|
||||
if (elem.firstElementChild) {
|
||||
slots = parseSlot(elem.children)
|
||||
}
|
||||
|
||||
if (props.hasOwnProperty('hostPush')) {
|
||||
elem.removeAttribute('host-push')
|
||||
__willpush__ = props.hostPush
|
||||
props.hostPush = parseVmValue(parentVm, __willpush__)
|
||||
}
|
||||
|
||||
if (props.hasOwnProperty(':disabled')) {
|
||||
var disabledKey = props[':disabled']
|
||||
var disabledKeyReverse = false
|
||||
|
@ -3891,7 +3878,7 @@ const _Anot = (function() {
|
|||
var childValueWatcher = function() {
|
||||
var val = this.value
|
||||
if (val && typeof val === 'object') {
|
||||
val = val.$model || val
|
||||
val = val.$model
|
||||
}
|
||||
parseVmValue(parentVm, valueKey, val)
|
||||
}
|
||||
|
@ -3978,19 +3965,21 @@ const _Anot = (function() {
|
|||
var vmodel = Anot(hooks)
|
||||
hideProperty(vmodel, '__WIDGET__', name)
|
||||
delete vmodel.$mounted
|
||||
parentVm.$components.push(vmodel)
|
||||
if (parentVm.__WIDGET__ === name) {
|
||||
vmodel.$up = parentVm
|
||||
|
||||
// 对象组件的子父vm关系, 只存最顶层的$components对象中,
|
||||
// 而子vm, 无论向下多少级, 他们的$up对象也只存最顶层的组件vm
|
||||
var __pvm__ = parentVm
|
||||
while (__pvm__.$up && __pvm__.$up.__WIDGET__ === name) {
|
||||
__pvm__ = __pvm__.$up
|
||||
}
|
||||
__pvm__.$components.push(vmodel)
|
||||
if (__pvm__.__WIDGET__ === name) {
|
||||
vmodel.$up = __pvm__
|
||||
}
|
||||
__pvm__ = undefined
|
||||
|
||||
elem.msResolved = 1 //防止二进扫描此元素
|
||||
|
||||
if (__willpush__) {
|
||||
hideProperty(vmodel, '$push', function(val) {
|
||||
parseVmValue(parentVm, __willpush__, val)
|
||||
})
|
||||
}
|
||||
|
||||
componentWillMount.call(vmodel)
|
||||
globalHooks.componentWillMount.call(null, vmodel)
|
||||
|
||||
|
@ -4051,6 +4040,7 @@ const _Anot = (function() {
|
|||
}
|
||||
}
|
||||
})
|
||||
elem.__VM__ = vmodel
|
||||
scanTag(elem, [vmodel])
|
||||
Anot.vmodels[vmodel.$id] = vmodel
|
||||
if (!elem.childNodes.length) {
|
||||
|
|
|
@ -242,14 +242,11 @@
|
|||
} else {
|
||||
var _parent = $elem
|
||||
while ((_parent = _parent.parentNode)) {
|
||||
if (_parent.anotctrl) {
|
||||
if (_parent.__VM__) {
|
||||
break
|
||||
}
|
||||
}
|
||||
scanTag(
|
||||
$elem.parentNode,
|
||||
_parent ? [VMODELS[_parent.anotctrl]] : []
|
||||
)
|
||||
scanTag($elem.parentNode, _parent ? [_parent.__VM__] : [])
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -3298,10 +3295,6 @@
|
|||
})
|
||||
}
|
||||
|
||||
function createSignalTower(elem, vmodel) {
|
||||
elem.anotctrl = elem.anotctrl || vmodel.$id
|
||||
}
|
||||
|
||||
function getBindingCallback(elem, name, vmodels) {
|
||||
var callback = elem.getAttribute(name)
|
||||
if (callback) {
|
||||
|
@ -3574,7 +3567,8 @@
|
|||
vm = [newVmodel]
|
||||
|
||||
elem.removeAttribute(node.name) //removeAttributeNode不会刷新xx[anot]样式规则
|
||||
createSignalTower(elem, newVmodel)
|
||||
// 挂载VM对象到相应的元素上
|
||||
elem.__VM__ = newVmodel
|
||||
hideProperty(newVmodel, '$elem', elem)
|
||||
|
||||
if (vmodels.length) {
|
||||
|
@ -3842,19 +3836,12 @@
|
|||
var state = {}
|
||||
var props = getOptionsFromTag(elem, host.vmodels)
|
||||
var $id = props.uuid || generateID(widget)
|
||||
var __willpush__ = null
|
||||
var slots = null
|
||||
|
||||
if (elem.firstElementChild) {
|
||||
slots = parseSlot(elem.children)
|
||||
}
|
||||
|
||||
if (props.hasOwnProperty('hostPush')) {
|
||||
elem.removeAttribute('host-push')
|
||||
__willpush__ = props.hostPush
|
||||
props.hostPush = parseVmValue(parentVm, __willpush__)
|
||||
}
|
||||
|
||||
if (props.hasOwnProperty(':disabled')) {
|
||||
var disabledKey = props[':disabled']
|
||||
var disabledKeyReverse = false
|
||||
|
@ -3906,7 +3893,7 @@
|
|||
var childValueWatcher = function() {
|
||||
var val = this.value
|
||||
if (val && typeof val === 'object') {
|
||||
val = val.$model || val
|
||||
val = val.$model
|
||||
}
|
||||
parseVmValue(parentVm, valueKey, val)
|
||||
}
|
||||
|
@ -3993,19 +3980,21 @@
|
|||
var vmodel = Anot(hooks)
|
||||
hideProperty(vmodel, '__WIDGET__', name)
|
||||
delete vmodel.$mounted
|
||||
parentVm.$components.push(vmodel)
|
||||
if (parentVm.__WIDGET__ === name) {
|
||||
vmodel.$up = parentVm
|
||||
|
||||
// 对象组件的子父vm关系, 只存最顶层的$components对象中,
|
||||
// 而子vm, 无论向下多少级, 他们的$up对象也只存最顶层的组件vm
|
||||
var __pvm__ = parentVm
|
||||
while (__pvm__.$up && __pvm__.$up.__WIDGET__ === name) {
|
||||
__pvm__ = __pvm__.$up
|
||||
}
|
||||
__pvm__.$components.push(vmodel)
|
||||
if (__pvm__.__WIDGET__ === name) {
|
||||
vmodel.$up = __pvm__
|
||||
}
|
||||
__pvm__ = undefined
|
||||
|
||||
elem.msResolved = 1 //防止二进扫描此元素
|
||||
|
||||
if (__willpush__) {
|
||||
hideProperty(vmodel, '$push', function(val) {
|
||||
parseVmValue(parentVm, __willpush__, val)
|
||||
})
|
||||
}
|
||||
|
||||
componentWillMount.call(vmodel)
|
||||
globalHooks.componentWillMount.call(null, vmodel)
|
||||
|
||||
|
@ -4066,6 +4055,7 @@
|
|||
}
|
||||
}
|
||||
})
|
||||
elem.__VM__ = vmodel
|
||||
scanTag(elem, [vmodel])
|
||||
Anot.vmodels[vmodel.$id] = vmodel
|
||||
if (!elem.childNodes.length) {
|
||||
|
|
|
@ -11,26 +11,26 @@ import './main.scss'
|
|||
|
||||
//储存版本信息
|
||||
Anot.ui.tree = '1.0.0'
|
||||
const log = console.log
|
||||
|
||||
function format(arr, { id, parent, label }) {
|
||||
function format(arr, expand, { id, parent, label } = {}) {
|
||||
let tmp = {}
|
||||
let farr = []
|
||||
this.__path__ = {}
|
||||
arr = Anot.deepCopy(arr)
|
||||
arr.sort(function(a, b) {
|
||||
return a[parent] === b[parent] ? a.sort - b.sort : a[parent] - b[parent]
|
||||
})
|
||||
arr.forEach(function(it) {
|
||||
// Anot.hideProperty(it, '__checked__', !!it.__checked__)
|
||||
it.__checked__ = !!it.__checked__
|
||||
it.open = !!it.open
|
||||
// console.log(it.hasOwnProperty('__checked__'), it.__checked__)
|
||||
arr.forEach(it => {
|
||||
this.__path__[it[id]] = []
|
||||
tmp[it[id]] = it
|
||||
var parentItem = tmp[it[parent]]
|
||||
let parentItem = tmp[it[parent]]
|
||||
|
||||
if (!parentItem) {
|
||||
return farr.push(tmp[it[id]])
|
||||
}
|
||||
this.__path__[it[id]] = this.__path__[parentItem[id]].concat(parentItem[id])
|
||||
parentItem.__open__ =
|
||||
typeof expand === 'boolean' ? expand : expand.includes(parentItem[id])
|
||||
parentItem.children = parentItem.children || []
|
||||
parentItem.children.push(it)
|
||||
})
|
||||
|
@ -40,41 +40,49 @@ function format(arr, { id, parent, label }) {
|
|||
export default Anot.component('tree', {
|
||||
__init__: function(props, state, next) {
|
||||
this.classList.add('do-tree')
|
||||
// this.setAttribute(':visible', 'list.size()')
|
||||
this.setAttribute(':visible', 'list.size()')
|
||||
|
||||
if (props.hasOwnProperty('expand')) {
|
||||
if (Array.isArray(props.expand)) {
|
||||
state.expand = props.expand
|
||||
} else {
|
||||
state.expand = true
|
||||
}
|
||||
}
|
||||
|
||||
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.list = format.call(this, props.list || [], state.expand, props)
|
||||
state.multiCheck = props.hasOwnProperty('multiCheck')
|
||||
|
||||
delete props.list
|
||||
delete props.multiCheck
|
||||
delete props.expand
|
||||
next()
|
||||
},
|
||||
render: function() {
|
||||
let { multiCheck } = this
|
||||
|
||||
return `
|
||||
<section class="do-tree__item" :repeat="list" :class="{open: el.open, dir: el.children}">
|
||||
<section class="do-tree__item" :repeat="list" :class="{open: el.__open__, dir: el.children}">
|
||||
<em
|
||||
:class="{
|
||||
'do-icon-txt': !el.children,
|
||||
'do-icon-folder-close': el.children && !el.open,
|
||||
'do-icon-folder-open': el.children && el.open,
|
||||
'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': value.includes(el[props.id])}"
|
||||
:class="{'do-icon-get': __isChecked(el)}"
|
||||
:if="multiCheck"
|
||||
:click="__check(el, null, $event)"></span>
|
||||
<span
|
||||
:click="__select(el)"
|
||||
:class="{active: el[props.id] === currItem}"
|
||||
:click="__check(el, $event)"></span>
|
||||
<span class="label"
|
||||
:click="__pick(el)"
|
||||
:class="{active: el[props.id] === value}"
|
||||
:text="el[props.label]"></span>
|
||||
|
||||
<div class="sub-tree" :if-loop="el.children">
|
||||
|
@ -82,8 +90,7 @@ export default Anot.component('tree', {
|
|||
:value="value"
|
||||
:attr="{
|
||||
list: el.children,
|
||||
'@itemClick': props.itemClick,
|
||||
'@itemPicked': __check,
|
||||
expand: expand,
|
||||
id: props.id,
|
||||
label: props.label,
|
||||
parent: props.parent,
|
||||
|
@ -94,108 +101,111 @@ export default Anot.component('tree', {
|
|||
},
|
||||
|
||||
componentDidMount: function() {
|
||||
this.list.forEach(it => {
|
||||
if (it.__checked__) {
|
||||
this.checkedItems[it[this.props.id]] = it.$model
|
||||
}
|
||||
})
|
||||
if (typeof this.props.created === 'function') {
|
||||
this.props.created(this)
|
||||
}
|
||||
},
|
||||
state: {
|
||||
__LIST__: [],
|
||||
__LIST_DICT__: {},
|
||||
list: [],
|
||||
value: [],
|
||||
multiCheck: false,
|
||||
currItem: -1,
|
||||
checkedItems: {}
|
||||
value: null,
|
||||
multiCheck: false
|
||||
},
|
||||
skip: ['checkedItems', '__LIST__', '__LIST_DICT__'],
|
||||
skip: ['__LIST_DICT__'],
|
||||
props: {
|
||||
id: 'id',
|
||||
label: 'label',
|
||||
parent: 'parent',
|
||||
checked: [],
|
||||
created: Anot.PropsTypes.isFunction(),
|
||||
itemClick: Anot.PropsTypes.isFunction(),
|
||||
itemPicked: Anot.PropsTypes.isFunction()
|
||||
itemCheck: Anot.PropsTypes.isFunction()
|
||||
},
|
||||
methods: {
|
||||
// 子目录的开关
|
||||
__toggle: function(obj) {
|
||||
if (!obj.children) {
|
||||
__toggle: function(item) {
|
||||
if (!item.children) {
|
||||
return
|
||||
}
|
||||
obj.open = !obj.open
|
||||
item.__open__ = !item.__open__
|
||||
},
|
||||
__isChecked(item) {
|
||||
let vm = this
|
||||
if (vm.$up) {
|
||||
vm = vm.$up
|
||||
}
|
||||
let { checked, id } = vm.props
|
||||
return checked.includes(item[id])
|
||||
},
|
||||
// 选中条目, 并将选中的列表向上冒泡, 直到最外层将结果通过回调返回给外部
|
||||
__check: function(el, itemsFromChild, ev) {
|
||||
if (ev) {
|
||||
__check: function(item, ev) {
|
||||
Anot(ev.target).toggleClass('do-icon-get')
|
||||
}
|
||||
|
||||
// return
|
||||
let item = null
|
||||
let arr = []
|
||||
let vm, id, itemPicked, checkedItems
|
||||
|
||||
if (this.props) {
|
||||
vm = this
|
||||
id = this.props.id
|
||||
itemPicked = this.props.itemPicked
|
||||
checkedItems = this.checkedItems
|
||||
} else {
|
||||
vm = this.$up
|
||||
id = vm.props.id
|
||||
itemPicked = vm.props.itemPicked
|
||||
checkedItems = vm.checkedItems
|
||||
}
|
||||
|
||||
if (itemsFromChild) {
|
||||
item = el
|
||||
Object.assign(checkedItems, itemsFromChild)
|
||||
} else {
|
||||
el.__checked__ = !el.__checked__
|
||||
// Anot.hideProperty(el, '__checked__', !el.__checked__)
|
||||
item = el.$model
|
||||
checkedItems[item[id]] = el.__checked__ ? item : null
|
||||
}
|
||||
|
||||
let vm = this
|
||||
if (vm.$up) {
|
||||
arr = checkedItems
|
||||
vm = vm.$up
|
||||
}
|
||||
let {
|
||||
props: { checked, id, itemCheck },
|
||||
__LIST_DICT__
|
||||
} = vm
|
||||
if (checked.includes(item[id])) {
|
||||
Anot.Array.remove(checked, item[id])
|
||||
} else {
|
||||
// 冒泡到最高一层时, 将对象转为数组
|
||||
for (let i in checkedItems) {
|
||||
if (checkedItems[i]) {
|
||||
arr.push(checkedItems[i])
|
||||
} else {
|
||||
delete checkedItems[i]
|
||||
checked.push(item[id])
|
||||
}
|
||||
}
|
||||
}
|
||||
if (typeof itemPicked === 'function') {
|
||||
itemPicked(item, arr)
|
||||
if (typeof itemCheck === 'function') {
|
||||
itemCheck(__LIST_DICT__[item[id]], checked)
|
||||
}
|
||||
},
|
||||
// 单个条目的点击选择
|
||||
__select: function(el) {
|
||||
let { id, itemClick } = this.props
|
||||
this.currItem = el[id]
|
||||
__pick: function(el) {
|
||||
let vm = this
|
||||
let id = this.props.id
|
||||
// 只取最顶层的VM的字典, 因为子VM的字典已经被污染了
|
||||
if (vm.$up) {
|
||||
vm = vm.$up
|
||||
}
|
||||
let {
|
||||
__LIST_DICT__,
|
||||
props: { itemClick }
|
||||
} = vm
|
||||
this.value = el[id]
|
||||
if (typeof itemClick === 'function') {
|
||||
itemClick(this.__LIST_DICT__[el[id]])
|
||||
// itemClick(el.$model)
|
||||
itemClick(__LIST_DICT__[el[id]])
|
||||
}
|
||||
},
|
||||
update(itemId, data) {
|
||||
let vm = this
|
||||
let path = this.$elem.__path__[itemId]
|
||||
let { id } = this.props
|
||||
// 主键ID不可修改
|
||||
delete data[id]
|
||||
|
||||
if (path.length) {
|
||||
for (let tmp of vm.$components) {
|
||||
if (tmp.__LIST_DICT__[itemId]) {
|
||||
vm = tmp
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (let it of vm.list) {
|
||||
if (it[id] === itemId) {
|
||||
Object.assign(it, data)
|
||||
}
|
||||
}
|
||||
},
|
||||
// 以给定的列表重置组件渲染
|
||||
resetWith: function(arr = []) {
|
||||
this.checked = {}
|
||||
this.list.clear()
|
||||
for (let it of arr) {
|
||||
this.__LIST__.push(it)
|
||||
this.__LIST_DICT__[it[this.props.id]] = it
|
||||
}
|
||||
this.list.pushArray(format(arr || [], this.props))
|
||||
this.list.pushArray(
|
||||
format.call(this.$elem, arr || [], this.expand, this.props)
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
@ -9,20 +9,21 @@
|
|||
@import '../../css/var.scss';
|
||||
|
||||
|
||||
.do-tree {overflow:hidden;overflow-y:auto;position:relative;display:inline-block;width:100%;height:100%;line-height:36px;font-size:15px;color:nth($cd, 2);
|
||||
.do-tree {overflow:hidden;overflow-y:auto;position:relative;display:block;width:100%;height:100%;line-height:34px;font-size:15px;color:nth($cd, 2);
|
||||
|
||||
&__item {overflow:hidden; min-height:35px;margin:1px 0; white-space:nowrap; text-overflow:ellipsis;
|
||||
&__item {overflow:hidden; min-height:34px;
|
||||
|
||||
.sub-tree {display:none;margin-left:20px;}
|
||||
.sub-tree {display:none;width:100%;padding-left:20px;}
|
||||
|
||||
em,span {display:inline-block;cursor:pointer;color:nth($cd, 1);}
|
||||
em {float:left;padding:0 5px;font-size:20px;}
|
||||
em,span {display:block;cursor:pointer;}
|
||||
em {float:left;padding:0 5px;font-size:20px;color:nth($cd, 1);}
|
||||
|
||||
span {
|
||||
|
||||
&:hover {color:nth($cd, 1);}
|
||||
&.active {color:nth($cd, 3);font-weight:bold;}
|
||||
&.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;}
|
||||
&.label { white-space:nowrap; text-overflow:ellipsis;}
|
||||
}
|
||||
}
|
||||
&__item.open>.sub-tree {display:block;}
|
||||
|
|
Reference in New Issue