From 03664d73fbfa0a1a6ba0e69506bc28418c9e0db8 Mon Sep 17 00:00:00 2001 From: tangjinzhou <415800467@qq.com> Date: Fri, 1 Dec 2017 12:21:43 +0800 Subject: [PATCH] fix --- components/tabs/InkTabBar.vue | 4 +-- components/tabs/InkTabBarMixin.js | 5 ++- components/tabs/ScrollableInkTabBar.vue | 4 +-- components/tabs/ScrollableTabBar.vue | 4 +-- components/tabs/ScrollableTabBarMixin.js | 13 ++++---- components/tabs/TabBar.vue | 6 ++-- components/tabs/TabBarMixin.js | 10 +++--- components/tabs/TabPane.vue | 8 +++-- components/tabs/Tabs.vue | 38 ++++++++++++---------- components/tabs/demo/basic.vue | 17 ++++------ components/tabs/demo/disabled.vue | 16 +++++++++ components/tabs/demo/icon.vue | 25 +++++++++++++++ components/tabs/demo/slide.vue | 41 ++++++++++++++++++++++++ components/tabs/index.vue | 37 +++++++++++---------- components/tabs/utils.js | 6 ++-- 15 files changed, 162 insertions(+), 72 deletions(-) create mode 100644 components/tabs/demo/disabled.vue create mode 100644 components/tabs/demo/icon.vue create mode 100644 components/tabs/demo/slide.vue diff --git a/components/tabs/InkTabBar.vue b/components/tabs/InkTabBar.vue index 501bf6c3e..48dafa1d2 100644 --- a/components/tabs/InkTabBar.vue +++ b/components/tabs/InkTabBar.vue @@ -5,9 +5,9 @@ import TabBarMixin from './TabBarMixin' export default { name: 'InkTabBar', mixins: [TabBarMixin, InkTabBarMixin], - render () { + render (h) { const inkBarNode = this.getInkBarNode() - const tabs = this.getTabs() + const tabs = this.getTabs(h) return this.getRootNode([inkBarNode, tabs]) }, } diff --git a/components/tabs/InkTabBarMixin.js b/components/tabs/InkTabBarMixin.js index fa27ce527..d09dc3839 100644 --- a/components/tabs/InkTabBarMixin.js +++ b/components/tabs/InkTabBarMixin.js @@ -35,7 +35,7 @@ function offset (elem) { } function componentDidUpdate (component, init) { - const { styles } = component.$props + const { styles = {}} = component.$props const wrapNode = component.$refs.nav || component.$refs.root const containerOffset = offset(wrapNode) const inkBarNode = component.$refs.inkBar @@ -111,9 +111,8 @@ export default { }, updated () { this.$nextTick(function () { - componentDidUpdate(this, true) + componentDidUpdate(this) }) - componentDidUpdate(this) }, mounted () { diff --git a/components/tabs/ScrollableInkTabBar.vue b/components/tabs/ScrollableInkTabBar.vue index e3a729727..292633176 100644 --- a/components/tabs/ScrollableInkTabBar.vue +++ b/components/tabs/ScrollableInkTabBar.vue @@ -6,9 +6,9 @@ import TabBarMixin from './TabBarMixin' export default { name: 'ScrollableInkTabBar', mixins: [TabBarMixin, InkTabBarMixin, ScrollableTabBarMixin], - render () { + render (h) { const inkBarNode = this.getInkBarNode() - const tabs = this.getTabs() + const tabs = this.getTabs(h) const scrollbarNode = this.getScrollBarNode([inkBarNode, tabs]) return this.getRootNode(scrollbarNode) }, diff --git a/components/tabs/ScrollableTabBar.vue b/components/tabs/ScrollableTabBar.vue index d041190e9..3a1e83071 100644 --- a/components/tabs/ScrollableTabBar.vue +++ b/components/tabs/ScrollableTabBar.vue @@ -5,9 +5,9 @@ import TabBarMixin from './TabBarMixin' export default { name: 'ScrollableTabBar', mixins: [TabBarMixin, ScrollableTabBarMixin], - render () { + render (h) { const inkBarNode = this.getInkBarNode() - const tabs = this.getTabs() + const tabs = this.getTabs(h) const scrollbarNode = this.getScrollBarNode([inkBarNode, tabs]) return this.getRootNode(scrollbarNode) }, diff --git a/components/tabs/ScrollableTabBarMixin.js b/components/tabs/ScrollableTabBarMixin.js index e2371a41b..3f91dd48a 100644 --- a/components/tabs/ScrollableTabBarMixin.js +++ b/components/tabs/ScrollableTabBarMixin.js @@ -53,9 +53,9 @@ export default { }, setNextPrev () { - const navNode = this.nav + const navNode = this.$refs.nav const navNodeWH = this.getOffsetWH(navNode) - const navWrapNode = this.navWrap + const navWrapNode = this.$refs.navWrap const navWrapNodeWH = this.getOffsetWH(navWrapNode) let { offset } = this const minOffset = navWrapNodeWH - navNodeWH @@ -110,7 +110,7 @@ export default { this.offset = target let navOffset = {} const tabBarPosition = this.$props.tabBarPosition - const navStyle = this.nav.style + const navStyle = this.$refs.nav.style const transformSupported = isTransformSupported(navStyle) if (tabBarPosition === 'left' || tabBarPosition === 'right') { if (transformSupported) { @@ -177,7 +177,8 @@ export default { }, scrollToActiveTab (e) { - const { activeTab, navWrap } = this + const { activeTab } = this + const navWrap = this.$refs.navWrap if (e && e.target !== e.currentTarget || !activeTab) { return } @@ -205,7 +206,7 @@ export default { prevClick (e) { this.$props.onPrevClick(e) - const navWrapNode = this.navWrap + const navWrapNode = this.$refs.navWrap const navWrapNodeWH = this.getOffsetWH(navWrapNode) const { offset } = this this.setOffset(offset + navWrapNodeWH) @@ -213,7 +214,7 @@ export default { nextClick (e) { this.$props.onNextClick(e) - const navWrapNode = this.navWrap + const navWrapNode = this.$refs.navWrap const navWrapNodeWH = this.getOffsetWH(navWrapNode) const { offset } = this this.setOffset(offset - navWrapNodeWH) diff --git a/components/tabs/TabBar.vue b/components/tabs/TabBar.vue index 4305e455b..423f97cc7 100644 --- a/components/tabs/TabBar.vue +++ b/components/tabs/TabBar.vue @@ -26,9 +26,9 @@ export default { activeKey: String, panels: Array, }, - render (createElement) { - const tabs = this.getTabs() - return this.getRootNode(tabs, createElement) + render (h) { + const tabs = this.getTabs(h) + return this.getRootNode(tabs, h) }, } diff --git a/components/tabs/TabBarMixin.js b/components/tabs/TabBarMixin.js index 93d6421c3..f70010914 100644 --- a/components/tabs/TabBarMixin.js +++ b/components/tabs/TabBarMixin.js @@ -21,14 +21,16 @@ export default { panels: Array, }, methods: { - getTabs () { + getTabs (h) { const { panels: children, activeKey, prefixCls } = this const rst = [] children.forEach((child) => { if (!child) { return } - const key = child.pKey + // componentOptions.propsData中获取的值disabled没有根据类型初始化, 会出现空字符串 + child.disabled = child.disabled === '' || child.disabled + const key = child.tabKey let cls = activeKey === key ? `${prefixCls}-tab-active` : '' cls += ` ${prefixCls}-tab` if (child.disabled) { @@ -52,7 +54,7 @@ export default { onClick={onClick} ref={activeKey === key ? 'activeTab' : undefined} > - {child.tab} + {typeof child.tab === 'function' ? child.tab(h, key) : child.tab} ) }) @@ -71,7 +73,7 @@ export default { let children = contents if ($slots.default) { children = [ -
+
{$slots.default}
, contents, diff --git a/components/tabs/TabPane.vue b/components/tabs/TabPane.vue index 33eaf3f2c..9375f89a6 100644 --- a/components/tabs/TabPane.vue +++ b/components/tabs/TabPane.vue @@ -12,12 +12,14 @@ export default { name: 'TabPane', props: { - pKey: [String, Number], - tab: [String, Number], + tabKey: [String, Number], + tab: [String, Number, Function], forceRender: Boolean, + disabled: Boolean, // placeholder: [Function, String, Number], }, data () { + console.log(this.disabled) return { } }, @@ -33,7 +35,7 @@ export default { }, active () { const { activeKey } = this.$parent - return activeKey === this.pKey + return activeKey === this.tabKey }, isRender () { const { diff --git a/components/tabs/Tabs.vue b/components/tabs/Tabs.vue index 0be95e314..94b61f883 100644 --- a/components/tabs/Tabs.vue +++ b/components/tabs/Tabs.vue @@ -1,21 +1,26 @@ diff --git a/components/tabs/demo/icon.vue b/components/tabs/demo/icon.vue new file mode 100644 index 000000000..ace4531fd --- /dev/null +++ b/components/tabs/demo/icon.vue @@ -0,0 +1,25 @@ + + diff --git a/components/tabs/demo/slide.vue b/components/tabs/demo/slide.vue new file mode 100644 index 000000000..514e7b1af --- /dev/null +++ b/components/tabs/demo/slide.vue @@ -0,0 +1,41 @@ + + diff --git a/components/tabs/index.vue b/components/tabs/index.vue index a9b345186..e4875a79c 100644 --- a/components/tabs/index.vue +++ b/components/tabs/index.vue @@ -56,10 +56,11 @@ export default { }, handleChange (activeKey) { - const onChange = this.$props.onChange - if (onChange) { - onChange(activeKey) - } + // const onChange = this.$props.onChange + // if (onChange) { + // onChange(activeKey) + // } + this.$emit('change', activeKey) }, }, @@ -77,7 +78,6 @@ export default { size, type = 'line', tabPosition, - children, tabBarStyle, // hideAdd, onTabClick, @@ -143,16 +143,16 @@ export default {
) : null - const renderTabBar = () => ( - - ) + // const renderTabBar = () => ( + // + // ) const tabBarProps = { inkBarAnimated, extraContent: tabBarExtraContent, @@ -161,15 +161,18 @@ export default { onNextClick, style: tabBarStyle, } + const tabContentProps = { + animated: tabPaneAnimated, + animatedWithMargin: true, + } return ( } onChange={this.handleChange} tabBarProps={tabBarProps} + tabContentProps={tabContentProps} > {childrenWithClose || this.$slots.default} diff --git a/components/tabs/utils.js b/components/tabs/utils.js index bb444f6ce..df344c5b5 100644 --- a/components/tabs/utils.js +++ b/components/tabs/utils.js @@ -12,8 +12,8 @@ export function toArray (children) { export function getActiveIndex (children, activeKey) { const c = toArray(children) for (let i = 0; i < c.length; i++) { - const pKey = c[i].pKey || c[i].componentOptions.propsData.pKey - if (pKey === activeKey) { + const tabKey = c[i].tabKey || c[i].componentOptions.propsData.tabKey + if (tabKey === activeKey) { return i } } @@ -22,7 +22,7 @@ export function getActiveIndex (children, activeKey) { export function getActiveKey (children, index) { const c = toArray(children) - return c[index].pKey + return c[index].tabKey } export function setTransform (style, v) {