This commit is contained in:
cookfront 2017-03-24 12:04:54 +08:00
parent e8d1bd41d3
commit 429e6e129a
4 changed files with 125 additions and 79 deletions

View File

@ -1,7 +1,7 @@
<style> <style>
@component-namespace demo { @component-namespace demo {
@b tab { @b tab {
.zan-tabs-pane { .zan-tab__pane {
background-color: #fff; background-color: #fff;
padding: 20px; padding: 20px;
} }
@ -9,6 +9,26 @@
} }
</style> </style>
<script>
export default {
data() {
return {
active: 2
};
},
mounted() {
setTimeout(() => {
this.active = 3;
}, 1000);
},
methods: {
popalert() {
alert('haha')
}
}
};
</script>
## Tab 组件 ## Tab 组件
### 基础用法 ### 基础用法
@ -24,20 +44,11 @@
</zan-tabs> </zan-tabs>
``` ```
<script>
export default {
methods: {
popalert() {
alert('haha')
}
}
};
</script>
::: :::
### 禁用用法 ### 禁用用法
:::demo 禁用用法 :::demo 禁用用法
```html ```html
<zan-tabs> <zan-tabs :active="active">
<zan-tab title="选项一">内容一</zan-tab> <zan-tab title="选项一">内容一</zan-tab>
<zan-tab disable title="选项二" @disable="popalert">内容二</zan-tab> <zan-tab disable title="选项二" @disable="popalert">内容二</zan-tab>
<zan-tab title="选项三">内容三</zan-tab> <zan-tab title="选项三">内容三</zan-tab>

View File

@ -1,5 +1,5 @@
<template> <template>
<div class="zan-tabs-pane" :class="classNames"> <div class="zan-tab__pane" :class="classNames">
<slot></slot> <slot></slot>
</div> </div>
</template> </template>
@ -17,7 +17,7 @@
}, },
computed: { computed: {
classNames() { classNames() {
return { 'is-select': this.$parent.tabs.indexOf(this) === this.$parent.switchActiveTabKey }; return { 'zan-tab__pane--select': this.$parent.tabs.indexOf(this) === this.$parent.switchActiveTabKey };
} }
}, },
created() { created() {

View File

@ -1,24 +1,25 @@
<template> <template>
<div class="zan-tabs"> <div class="zan-tabs">
<div class="zan-tabs-nav" :class="classNames"> <div class="zan-tabs__nav" :class="classNames">
<div class="zan-tabs-nav-bar" :style="navBarStyle"></div> <div class="zan-tabs__nav-bar" :style="navBarStyle"></div>
<div <div
v-for="(tab, index) in tabs" v-for="(tab, index) in tabs"
class="zan-tab" class="zan-tab"
:class="{'zan-tab-active': index == switchActiveTabKey}" :class="{'zan-tab--active': index == switchActiveTabKey}"
ref="tabkey" ref="tabkey"
@click="handleTabClick(index,tab)" @click="handleTabClick(index,tab)"
> >
{{ tab.title }} {{ tab.title }}
</div> </div>
</div> </div>
<div class="zan-tabs-content"><slot></slot></div> <div class="zan-tabs__content"><slot></slot></div>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: 'zan-tabs', name: 'zan-tabs',
props: { props: {
// tab // tab
active: { active: {
@ -36,17 +37,26 @@
default: '' default: ''
} }
}, },
data() { data() {
return { return {
tabs: [], tabs: [],
isReady: false, isReady: false,
switchActiveTabKey: this.active switchActiveTabKey: +this.active
}; };
}, },
watch: {
active(val) {
this.switchActiveTabKey = +val;
}
},
computed: { computed: {
classNames() { classNames() {
return [`zan-tabs-${this.type}`, this.navclass]; return [`zan-tabs__nav--${this.type}`, `zan-tabs--col-${this.tabs.length}`, this.navclass];
}, },
navBarStyle() { navBarStyle() {
if (!this.isReady) return; if (!this.isReady) return;
const tabKey = this.switchActiveTabKey; const tabKey = this.switchActiveTabKey;
@ -59,6 +69,7 @@
}; };
} }
}, },
methods: { methods: {
handleTabClick(index, el) { handleTabClick(index, el) {
if (el.disable) { if (el.disable) {
@ -68,6 +79,7 @@
this.switchActiveTabKey = index; this.switchActiveTabKey = index;
} }
}, },
mounted() { mounted() {
// //
this.$nextTick(() => { this.$nextTick(() => {

View File

@ -2,86 +2,109 @@
@import './mixins/border_retina.css'; @import './mixins/border_retina.css';
@component-namespace zan { @component-namespace zan {
@b tabs { @b tabs {
position: relative; position: relative;
@m col-2 {
.zan-tab {
width: 50%;
}
} }
@b tabs-line {
@m col-3 {
.zan-tab {
width: 33.33333333333333%;
}
}
@m col-4 {
.zan-tab {
width: 25%;
}
}
@m col-5 {
.zan-tab {
width: 20%;
}
}
@e nav {
overflow: hidden;
transition: transform .5s cubic-bezier(.645, .045, .355, 1);
position: relative;
@m line {
height: 44px; height: 44px;
background-color: $c-white; background-color: $c-white;
&::after { &::after {
@mixin border-retina (top); @mixin border-retina (top);
@mixin border-retina (bottom); @mixin border-retina (bottom);
} }
@b tabs-nav-bar { @b tabs-nav-bar {
display: block; display: block;
} }
} }
@b tabs-card {
@m card {
height: 28px; height: 28px;
margin: 0 15px; margin: 0 15px;
background-color: $c-white; background-color: $c-white;
border-radius: 2px; border-radius: 2px;
border: 1px solid #666666; border: 1px solid #666666;
overflow: hidden; overflow: hidden;
.zan-tabs-nav-bar { .zan-tabs__nav-bar {
display: none; display: none;
} }
.zan-tab { .zan-tab {
color: #666666; color: #666666;
line-height: 28px; line-height: 28px;
border-right: 1px solid #666666; border-right: 1px solid #666666;
&:last-child { &:last-child {
border-right: none; border-right: none;
} }
&.zan-tab-active { &.zan-tab--active {
background-color: #666666; background-color: #666666;
color: $c-white; color: $c-white;
} }
} }
}
} }
@b tabs-nav {
display: flex; @e nav-bar {
transition: transform .5s cubic-bezier(.645, .045, .355, 1); z-index: 1;
position: relative; position: absolute;
/*float: left*/ left: 0;
&::after, &::before { bottom: 0;
display: table; height: 2px;
content: " " background-color: #f13e3a;
} transition: transform .3s cubic-bezier(.645, .045, .355, 1);
&::after { transform-origin: 0 0;
clear: both
}
} }
@b tabs-nav-bar { }
z-index: 1;
position: absolute; @b tab {
left: 0; color: $c-black;
bottom: 0; font-size: 14px;
height: 2px; line-height: 44px;
background-color: #f13e3a; box-sizing: border-box;
transition: transform .3s cubic-bezier(.645, .045, .355, 1); transition: color .3s cubic-bezier(.645, .045, .355, 1);
transform-origin: 0 0; cursor: pointer;
text-align: center;
float: left;
@m active {
color: #FF4444;
} }
@b tab {
color: $c-black; @e pane {
font-size: 14px; display: none;
line-height: 44px;
flex: 1; @m select {
display: inline-block; display: block;
box-sizing: border-box; }
transition: color .3s cubic-bezier(.645, .045, .355, 1);
cursor: pointer;
text-align: center;
}
@b tab-active {
color: #FF4444;
}
@b tabs-pane {
display: none;
@when select {
display: block;
}
} }
}
} }