pull/9/head
tangjinzhou 2018-01-18 18:58:36 +08:00
parent d9c893edb5
commit aebed8b169
5 changed files with 46 additions and 32 deletions

View File

@ -6,12 +6,13 @@ export default {
childProps: PropTypes.object.def({}), childProps: PropTypes.object.def({}),
}, },
render () { render () {
const { $attrs, $listeners, childProps } = this const { $attrs, $listeners, childProps, $slots } = this
let children = this.$slots.default[0] let children = $slots.default[0]
children = cloneElement(children, { children = cloneElement(children, {
attr: $attrs, attr: $attrs,
on: $listeners, on: $listeners,
props: childProps, props: childProps,
addChildren: $slots.addChildren,
}) })
return children return children
}, },

View File

@ -1,6 +1,11 @@
import cloneDeep from 'lodash.clonedeep' import cloneDeep from 'lodash.clonedeep'
export function cloneVNode (vnode, deep) { export function cloneVNode (vnode, deep) {
const componentOptions = vnode.componentOptions const componentOptions = vnode.componentOptions
// if (componentOptions && componentOptions.listeners) {
// componentOptions.listeners = cloneDeep(componentOptions.listeners)
// }
// const data = vnode.data ? cloneDeep(vnode.data) : vnode.data
const cloned = new vnode.constructor( const cloned = new vnode.constructor(
vnode.tag, vnode.tag,
vnode.data, vnode.data,
@ -54,9 +59,10 @@ export function cloneElement (n, nodeProps, clone) {
node.componentOptions.listeners = node.componentOptions.listeners || {} node.componentOptions.listeners = node.componentOptions.listeners || {}
node.componentOptions.propsData = { ...node.componentOptions.propsData, ...props } node.componentOptions.propsData = { ...node.componentOptions.propsData, ...props }
node.componentOptions.listeners = { ...node.componentOptions.listeners, ...on } node.componentOptions.listeners = { ...node.componentOptions.listeners, ...on }
addChildren && node.componentOptions.children.push(addChildren) node.componentOptions.children = node.componentOptions.children.filter(c => c.key !== '_ANT_PORTAL')
addChildren && node.componentOptions.children.push(...addChildren)
} else { } else {
addChildren && (node.children = [...(node.children || []), addChildren]) addChildren && (node.children = [...(node.children || []), ...addChildren])
node.data.on = { ...(node.data.on || {}), ...on } node.data.on = { ...(node.data.on || {}), ...on }
} }
@ -96,5 +102,5 @@ export function getEvents (child) {
} else if (child.data && child.data.on) { } else if (child.data && child.data.on) {
events = child.data.on events = child.data.on
} }
return { ...events } return events
} }

View File

@ -21,14 +21,13 @@ export default {
const itemProps = { const itemProps = {
props, props,
attrs, attrs,
on: { ...$listeners }, on: $listeners,
class: getClass(this), class: getClass(this),
style: getStyle(this), style: getStyle(this),
} }
const toolTipProps = { const toolTipProps = {
props: { props: {
placement: 'right', placement: 'right',
trigger: 'click',
overlayClassName: `${props.rootPrefixCls}-inline-collapsed-tooltip`, overlayClassName: `${props.rootPrefixCls}-inline-collapsed-tooltip`,
}, },
on: {}, on: {},
@ -37,8 +36,7 @@ export default {
{...toolTipProps} {...toolTipProps}
> >
<template slot='title'> <template slot='title'>
jdjjdj {inlineCollapsed && props.level === 1 ? $slots.default : ''}
{inlineCollapsed && props.level === 1 ? <span>$slots</span> : ''}
</template> </template>
<Item {...itemProps} ref='menuItem'> <Item {...itemProps} ref='menuItem'>
{$slots.default} {$slots.default}

View File

@ -9,10 +9,6 @@
<AntButton type="primary" @click="toggleCollapsed" style="margin-bottom: 16px"> <AntButton type="primary" @click="toggleCollapsed" style="margin-bottom: 16px">
<Icon :type="collapsed ? 'menu-unfold' : 'menu-fold'" /> <Icon :type="collapsed ? 'menu-unfold' : 'menu-fold'" />
</AntButton> </AntButton>
<MenuItem key="1">
<Icon type="pie-chart" />
<span>Option 1</span>
</MenuItem>
<Menu <Menu
:defaultSelectedKeys="['1']" :defaultSelectedKeys="['1']"
:defaultOpenKeys="['sub1']" :defaultOpenKeys="['sub1']"
@ -20,11 +16,11 @@
theme="dark" theme="dark"
:inlineCollapsed="collapsed" :inlineCollapsed="collapsed"
> >
<!-- <MenuItem key="1"> <MenuItem key="1">
<Icon type="pie-chart" /> <Icon type="pie-chart" />
<span>Option 1</span> <span>Option 1</span>
</MenuItem> --> </MenuItem>
<!-- <MenuItem key="2"> <MenuItem key="2">
<Icon type="desktop" /> <Icon type="desktop" />
<span>Option 2</span> <span>Option 2</span>
</MenuItem> </MenuItem>
@ -51,7 +47,7 @@
<MenuItem key="11">Option 11</MenuItem> <MenuItem key="11">Option 11</MenuItem>
<MenuItem key="12">Option 12</MenuItem> <MenuItem key="12">Option 12</MenuItem>
</SubMenu> </SubMenu>
</SubMenu> --> </SubMenu>
</Menu> </Menu>
</div> </div>
</div> </div>
@ -71,6 +67,15 @@ export default {
toggleCollapsed () { toggleCollapsed () {
this.collapsed = !this.collapsed this.collapsed = !this.collapsed
}, },
con1 () {
console.log(111)
},
con2 () {
console.log(222)
},
con3 () {
console.log(333)
},
}, },
components: { components: {
Menu, Menu,

View File

@ -16,7 +16,6 @@ function returnEmptyString () {
function returnDocument () { function returnDocument () {
return window.document return window.document
} }
const ALL_HANDLERS = ['click', 'mousedown', 'touchStart', 'mouseenter', const ALL_HANDLERS = ['click', 'mousedown', 'touchStart', 'mouseenter',
'mouseleave', 'focus', 'blur', 'contextMenu'] 'mouseleave', 'focus', 'blur', 'contextMenu']
@ -262,6 +261,7 @@ export default {
getRootDomNode () { getRootDomNode () {
return this.$el return this.$el
// return this.$el.children[0] || this.$el
}, },
handleGetPopupClassFromAlign (align) { handleGetPopupClassFromAlign (align) {
@ -322,11 +322,11 @@ export default {
}, },
ref: 'popup', ref: 'popup',
style: popupStyle, style: popupStyle,
key: '_ANT_PORTAL',
} }
return ( return (
<Popup <Popup
{...popupProps} {...popupProps}
ref='popup'
> >
{typeof popup === 'function' ? popup(h) : popup} {typeof popup === 'function' ? popup(h) : popup}
{popup === undefined ? $slots.popup : null} {popup === undefined ? $slots.popup : null}
@ -396,7 +396,7 @@ export default {
} }
}, },
createTwoChains (event, child) { createTwoChains (event) {
let fn = () => { let fn = () => {
} }
const events = this.$listeners const events = this.$listeners
@ -463,17 +463,21 @@ export default {
warning(false, 'Trigger $slots.default.length > 1, just support only one default', true) warning(false, 'Trigger $slots.default.length > 1, just support only one default', true)
} }
const child = children[0] const child = children[0]
this.childOriginEvents = getEvents(child) const events = getEvents(child)
// vue使_ANT_EVENT_HACK
if (!events._ANT_EVENT_HACK) {
this.childOriginEvents = events
}
const newChildProps = { const newChildProps = {
props: {}, props: {},
on: {}, on: { _ANT_EVENT_HACK: () => {} },
key: 'trigger', key: 'trigger',
} }
if (this.isContextMenuToShow()) { if (this.isContextMenuToShow()) {
newChildProps.on.contextMenu = this.onContextMenu newChildProps.on.contextMenu = this.onContextMenu
} else { } else {
newChildProps.on.contextMenu = this.createTwoChains('contextMenu', child) newChildProps.on.contextMenu = this.createTwoChains('contextMenu')
} }
if (this.isClickToHide() || this.isClickToShow()) { if (this.isClickToHide() || this.isClickToShow()) {
@ -481,27 +485,27 @@ export default {
newChildProps.on.mousedown = this.onMousedown newChildProps.on.mousedown = this.onMousedown
// newChildProps.on.touchStart = this.onTouchStart // newChildProps.on.touchStart = this.onTouchStart
} else { } else {
newChildProps.on.click = this.createTwoChains('click', child) newChildProps.on.click = this.createTwoChains('click')
newChildProps.on.mousedown = this.createTwoChains('mousedown', child) newChildProps.on.mousedown = this.createTwoChains('mousedown')
// newChildProps.on.TouchStart = this.createTwoChains('onTouchStart', child) // newChildProps.on.TouchStart = this.createTwoChains('onTouchStart')
} }
if (this.isMouseEnterToShow()) { if (this.isMouseEnterToShow()) {
newChildProps.on.mouseenter = this.onMouseenter newChildProps.on.mouseenter = this.onMouseenter
} else { } else {
newChildProps.on.mouseenter = this.createTwoChains('mouseenter', child) newChildProps.on.mouseenter = this.createTwoChains('mouseenter')
} }
if (this.isMouseLeaveToHide()) { if (this.isMouseLeaveToHide()) {
newChildProps.on.mouseleave = this.onMouseleave newChildProps.on.mouseleave = this.onMouseleave
} else { } else {
newChildProps.on.mouseleave = this.createTwoChains('mouseleave', child) newChildProps.on.mouseleave = this.createTwoChains('mouseleave')
} }
if (this.isFocusToShow() || this.isBlurToHide()) { if (this.isFocusToShow() || this.isBlurToHide()) {
newChildProps.on.focus = this.onFocus newChildProps.on.focus = this.onFocus
newChildProps.on.blur = this.onBlur newChildProps.on.blur = this.onBlur
} else { } else {
newChildProps.on.focus = this.createTwoChains('focus', child) newChildProps.on.focus = this.createTwoChains('focus')
newChildProps.on.blur = this.createTwoChains('blur', child) newChildProps.on.blur = this.createTwoChains('blur')
} }
const { sPopupVisible, forceRender } = this const { sPopupVisible, forceRender } = this
if (sPopupVisible || forceRender || this._component) { if (sPopupVisible || forceRender || this._component) {
@ -509,8 +513,8 @@ export default {
} else { } else {
this._component = null this._component = null
} }
newChildProps.addChildren = this._component this._component && (newChildProps.addChildren = [this._component])
const trigger = cloneElement(child, newChildProps, true) const trigger = cloneElement(child, newChildProps)
return trigger return trigger
}, },
} }