Commit 4b7de2b3 authored by Nature's avatar Nature

s-tab添加横向滚动支持

parent 47a7d413
<template> <template>
<section :class="[c(),tabCss, cusClass]"> <section :class="[c(),tabCss, cusClass,overFlow]">
<section :style="transform" class="tab-content">
<slot/> <slot/>
</section> </section>
</section>
</template> </template>
<script> <script>
import {base} from '../../common/mixins' import { base } from '../../common/mixins'
import stabItem from './tab-item' import stabItem from './tab-item'
export default { export default {
name: 'SwitchTab', name: 'SwitchTab',
mixins: [base], mixins: [base],
component: {stabItem}, component: { stabItem },
props: { props: {
position: { position: {
type: String, type: String,
...@@ -28,15 +30,24 @@ export default { ...@@ -28,15 +30,24 @@ export default {
type: Boolean, type: Boolean,
default: false, default: false,
}, },
overflowX: {
type: Boolean,
default: false,
},
}, },
data () { data () {
return { return {
items: [], items: [],
length: '', length: '',
activedIndex: '', activedIndex: '',
deviceWidth: window.innerWidth,
translate: 0,
} }
}, },
computed: { computed: {
overFlow () {
return this.overflowX ? 'auto-overflow-x' : ''
},
tabCss () { tabCss () {
return this.position === 'top' ? this.c('top') : this.c('bottom') return this.position === 'top' ? this.c('top') : this.c('bottom')
}, },
...@@ -54,37 +65,72 @@ export default { ...@@ -54,37 +65,72 @@ export default {
} }
return vm.index return vm.index
}, },
transform () {
return {
transform: 'translateX(' + this.translate + 'px' + ')',
}
},
}, },
mounted () { mounted () {
let vm = this let vm = this
this.items[vm.current].$el.classList.add('activated') this.items[vm.current].$el.classList.add('activated')
this.scrollToActiveTab(vm.current, this.items[vm.current].$el.clientWidth)
}, },
methods: { methods: {
actived (index) { actived (index, clientWidth) {
this.activedIndex = index this.activedIndex = index
this.$emit('tabClick', index) this.$emit('tabClick', index)
this.scrollToActiveTab(index, clientWidth)
},
scrollToActiveTab (index, width) {
index += 1
let vm = this
let count = Math.floor(vm.deviceWidth / width)
let overFlowWinth = vm.deviceWidth - count * width
let num
if (index > count) {
num = index - count
} else {
num = 0
}
if (num === 0) {
vm.translate = -num * width
} else {
vm.translate = -num * width + overFlowWinth
}
}, },
}, },
} }
</script> </script>
<style lang="less"> <style lang="less">
.auto-overflow-x {
overflow-x: auto;
}
.hls-switch-tab { .hls-switch-tab {
width: 100%; width: 100%;
position: absolute; position: absolute;
z-index: 1; z-index: 1;
display: flex; display: flex;
justify-content: space-around; // justify-content: space-around;
height: 40px; height: 40px;
background-color: #fff; background-color: #fff;
&-top { &-top {
top: 0; top: 0;
&:after { &:after {
.setBottomLine(); .setBottomLine();
} }
} }
&-bottom { &-bottom {
bottom: 0; bottom: 0;
&:before { &:before {
.setTopLine(); .setTopLine();
} }
......
<template> <template>
<section class="tab-content" @click="titleClick"> <section class="h-tab-item" @click="titleClick">
<section class="h-tab-item">
<div class="h-item"> <div class="h-item">
<slot/> <slot/>
</div> </div>
</section>
<div v-show="showDivider" class="tab-divider"/> <div v-show="showDivider" class="tab-divider"/>
</section> </section>
</template> </template>
<script> <script>
export default { export default {
name: 'TabItem', name: 'TabItem',
data () { data () {
return {} return {
}
}, },
computed: { computed: {
showDivider () { showDivider () {
...@@ -36,8 +37,10 @@ export default { ...@@ -36,8 +37,10 @@ export default {
let clickIndex = Number(event.currentTarget.getAttribute('data-index')) let clickIndex = Number(event.currentTarget.getAttribute('data-index'))
event.currentTarget.classList.remove('activated') event.currentTarget.classList.remove('activated')
event.currentTarget.classList.add('activated') event.currentTarget.classList.add('activated')
vm.$parent.actived(clickIndex) let clientWidth = event.currentTarget.clientWidth
vm.$parent.actived(clickIndex, clientWidth)
}, },
}, },
} }
</script> </script>
...@@ -48,7 +51,6 @@ export default { ...@@ -48,7 +51,6 @@ export default {
.tab-content { .tab-content {
width: 100%; width: 100%;
display: flex; display: flex;
justify-content: space-around;
align-items: center; align-items: center;
.h-tab-item { .h-tab-item {
...@@ -57,6 +59,7 @@ export default { ...@@ -57,6 +59,7 @@ export default {
display: flex; display: flex;
align-items: center; align-items: center;
justify-content: center; justify-content: center;
.h-item { .h-item {
//width: 100%; //width: 100%;
font-size: 14px; font-size: 14px;
...@@ -67,24 +70,21 @@ export default { ...@@ -67,24 +70,21 @@ export default {
align-items: center; align-items: center;
justify-content: center; justify-content: center;
padding: 0 3px; padding: 0 3px;
border-bottom: 1px solid rgba(255,255,255,.0); /*no*/ border-bottom: 1px solid rgba(255, 255, 255, .0); /*no*/
}
}
.tab-divider {
width: 1px; /*no*/
height: 50%;
background-color: rgb(214, 217, 218);
} }
&.activated { &.activated {
.h-tab-item {
.h-item { .h-item {
color: #1e8ceb; color: #1e8ceb;
border-bottom: 1px solid #1e8ceb; /*no*/ border-bottom: 1px solid #1e8ceb; /*no*/
} }
} }
.tab-divider {
width: 1px; /*no*/
height: 50%;
background-color: rgb(214, 217, 218);
} }
&:last-child { &:last-child {
.tab-divider { .tab-divider {
width: 0px; width: 0px;
...@@ -92,5 +92,6 @@ export default { ...@@ -92,5 +92,6 @@ export default {
} }
} }
} }
}
</style> </style>
...@@ -90,6 +90,14 @@ export default { ...@@ -90,6 +90,14 @@ export default {
type: Boolean, type: Boolean,
default: true, default: true,
}, },
defaultWidth: {
type: Number,
default: 0,
},
defaultHeight: {
type: Number,
default: 0,
},
cusClass: { cusClass: {
type: String, type: String,
default: '', default: '',
...@@ -161,7 +169,11 @@ export default { ...@@ -161,7 +169,11 @@ export default {
init () { init () {
let vm = this let vm = this
vm.clear() vm.clear()
if (vm.defaultWidth) {
vm.width = vm.defaultWidth
} else if (vm.defaultHeight) {
vm.hight = vm.defaultHeight
} else {
if (vm.$el) { if (vm.$el) {
vm.width = vm.$el.offsetWidth || document.documentElement.offsetWidth vm.width = vm.$el.offsetWidth || document.documentElement.offsetWidth
vm.height = vm.$el.offsetHeight || document.documentElement.offsetHeight vm.height = vm.$el.offsetHeight || document.documentElement.offsetHeight
...@@ -181,6 +193,7 @@ export default { ...@@ -181,6 +193,7 @@ export default {
vm.width = 375 vm.width = 375
vm.height = 667 vm.height = 667
} }
}
this.active = this.index this.active = this.index
this.offset = this.count > 1 ? -this.size * this.active : 0 this.offset = this.count > 1 ? -this.size * this.active : 0
this.swipes.forEach(swipe => { this.swipes.forEach(swipe => {
......
...@@ -9,11 +9,19 @@ ...@@ -9,11 +9,19 @@
操作 操作
</div> </div>
</h-header> </h-header>
<!-- <s-tab @tabClick="stablick" cusClass="popup-tab"> <!-- <s-tab :overflowX="true" :showDivider="true" class="has-header" :defaultActive="6">
<tab-item>测试</tab-item> <tab-item>工商资料</tab-item>
<tab-item>你好</tab-item> <tab-item>股东成员</tab-item>
<tab-item>再见</tab-item> <tab-item>对外投资</tab-item>
<tab-item>按钮</tab-item> <tab-item>工商变更</tab-item>
<tab-item>企业年报</tab-item>
<tab-item>关联情报</tab-item>
<tab-item>开庭公告</tab-item>
<tab-item>裁判文书</tab-item>
<tab-item>执行记录</tab-item>
<tab-item>失信记录</tab-item>
<tab-item>涉诉公告</tab-item>
<tab-item>司法协助</tab-item>
</s-tab>--> </s-tab>-->
<h-content <h-content
class="has-header has-footer"> class="has-header has-footer">
...@@ -72,7 +80,7 @@ ...@@ -72,7 +80,7 @@
<h-button class="button-class radius-small" disabled>基础按钮(禁用)</h-button> <h-button class="button-class radius-small" disabled>基础按钮(禁用)</h-button>
<h2 class="item-title">Swip基础使用</h2> <h2 class="item-title">Swip基础使用</h2>
<swipe :interval="5000" @start="start" @move="move" @change="change"> <swipe :interval="5000" @start="start" @move="move" @change="change" :defaultWidth="200">
<swipe-item> <swipe-item>
<div :style="{'background': bgColor[0]}" class="item-bg">0</div> <div :style="{'background': bgColor[0]}" class="item-bg">0</div>
</swipe-item> </swipe-item>
...@@ -660,6 +668,13 @@ export default { ...@@ -660,6 +668,13 @@ export default {
.hls-popup { .hls-popup {
height: 100%; height: 100%;
width: 100%; width: 100%;
.hls-switch-tab {
.tab-content .h-tab-item .h-item{
width: 80px;
}
}
.vue-better-scroll__wrapper { .vue-better-scroll__wrapper {
width: 100%; width: 100%;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment