| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410 |
- <template>
- <view
- class="tui-tabs-view"
- :class="[
- isFixed ? 'tui-tabs-fixed' : 'tui-tabs-relative',
- unlined ? 'tui-unlined' : '',
- isBoxShadow ? 'tui-tabs-view-shadow' : ''
- ]"
- :style="{
- height: height + 'rpx',
- padding: `0 ${padding}rpx`,
- background: bgColor,
- top: isFixed ? top + 'px' : 'auto'
- }"
- >
- <div
- class="item-wrap"
- :style="{ width: isAdd ? `calc(100% - ${addTabWidth + 30}rpx)` : '100%' }"
- >
- <!-- { 'border-left': borderLeft }, -->
- <view
- v-for="(item, index) in tabs"
- :key="index"
-
- :class="[
- 'tui-tabs-item',
- { active: currentTab == index },
- ]"
- :style="{ width: itemWidth }"
- @tap.stop="swichTabs(item, index)"
- >
- <view
- class="tui-tabs-title"
- :class="{
- 'tui-tabs-active': currentTab == index,
- 'tui-tabs-disabled': item.disabled,
- 'border-left': borderLeft && !(index == tabs.length -1)
- }"
- :style="{
- fontSize: size + 'rpx',
- lineHeight: size + 'rpx',
- fontWeight: bold && currentTab == index ? 'bold' : 'normal'
- }"
- >
- <div class="tabs-title">{{ item.name }}</div>
- <!-- tab value -->
- <div class="tabs-value" v-if="item.value || item.value == 0">
- {{ item.value }}
- </div>
- </view>
- </view>
- </div>
- <!-- tab add -->
- <div
- class="tabs-add"
- v-if="isAdd"
- :style="{ width: `${addTabWidth}rpx` }"
- @click="add"
- >
- <i class="iconfont" :class="[addIcon]"></i>
- <span>{{ addText }}</span>
- </div>
- <!-- <view
- class="tui-tabs-slider"
- :style="{
- transform: 'translateX(' + scrollLeft + 'px)',
- width: sliderWidth + 'rpx',
- height: sliderHeight + 'rpx',
- borderRadius: sliderRadius,
- bottom: bottom,
- marginBottom: bottom == '50%' ? '-' + sliderHeight / 2 + 'rpx' : 0
- }"
- ></view> -->
- </view>
- </template>
- <script>
- export default {
- name: "tuiTabs",
- props: {
- // 标签页
- tabs: {
- type: Array,
- default() {
- return [];
- }
- },
- // rpx
- height: {
- type: Number,
- default: 80
- },
- // rpx 只对左右padding起作用,上下为0
- padding: {
- type: Number,
- default: 30
- },
- // 背景色
- bgColor: {
- type: String,
- default: "#FFFFFF"
- },
- // 是否固定
- isFixed: {
- type: Boolean,
- default: false
- },
- // px
- top: {
- type: Number, // #ifndef H5
- default: 0, // #endif
- // #ifdef H5
- default: 0
- // #endif
- },
- // 是否去掉底部线条
- unlined: {
- type: Boolean,
- default: false
- },
- // 当前选项卡
- currentTab: {
- type: Number,
- default: 0
- },
- // 滑块宽度
- sliderWidth: {
- type: Number,
- default: 68
- },
- // 滑块高度
- sliderHeight: {
- type: Number,
- default: 6
- },
- sliderRadius: {
- type: String,
- default: "50rpx"
- },
- // 滑块bottom
- bottom: {
- type: String,
- default: "0"
- },
- // 标签页宽度
- itemWidth: {
- type: String,
- default: "25%"
- },
- // 字体颜色
- color: {
- type: String,
- default: "#999"
- },
- // 字体大小
- size: {
- type: Number,
- default: 28
- },
- // 选中后 是否加粗 ,未选中则无效
- bold: {
- type: Boolean,
- default: false
- },
- // 是否显示borer-right
- borderLeft: {
- type: Boolean,
- default: false
- },
- // 是否有新增按钮
- isAdd: {
- type: Boolean,
- default: false
- },
- // 新增按钮的icon
- addIcon: {
- type: String,
- default: "icontianjiakehu"
- },
- addText: {
- type: String,
- default: "添加"
- },
- // 是否显示box-shadow
- isBoxShadow: {
- type: Boolean,
- default: true
- }
- },
- watch: {
- currentTab() {
- this.checkCor();
- }
- },
- created() {
- setTimeout(() => {
- // 高度自适应
- uni.getSystemInfo({
- success: res => {
- this.winWidth = res.windowWidth;
- this.checkCor();
- }
- });
- }, 50);
- },
- data() {
- return {
- winWidth: 0,
- scrollLeft: 0,
- addTabWidth: 130
- };
- },
- computed: {
- // addTabWidth() {
- // return uni.upx2px(130)
- // }
- },
- methods: {
- checkCor: function() {
- let addTabWidth = this.isAdd ? uni.upx2px(this.addTabWidth + 30) : 0;
- let tabsNum = this.tabs.length;
- let padding = (this.winWidth / 750) * this.padding;
- let width = this.winWidth - padding * 2 - addTabWidth;
- let left =
- (width / tabsNum - (this.winWidth / 750) * this.sliderWidth) / 2 + padding;
- let scrollLeft = left;
- if (this.currentTab > 0) {
- scrollLeft = scrollLeft + (width / tabsNum) * this.currentTab;
- }
- this.scrollLeft = scrollLeft;
- },
- // 点击标题切换当前页时改变样式
- swichTabs: function(i, index) {
- let item = this.tabs[index];
- if (item && item.disabled) return;
- if (this.currentTab == index) {
- return false;
- } else {
- this.$emit("change", {
- index: Number(index),
- item: i
- });
- }
- },
- // 新增
- add() {
- uni.navigateTo({url:'/pagesClient/member/add'})
- // this.$emit("add");
- }
- }
- };
- </script>
- <style lang="scss" scoped>
- .tabs-add {
- @include disFlex(center, center);
- height: 60px;
- border-left: 1px solid $borderColor;
- padding-left: 30px;
- color: $fontColor3;
- .iconfont {
- margin-right: 10px;
- font-size: 30rpx;
- }
- }
- .tui-tabs-view {
- width: 100%;
- box-sizing: border-box;
- display: flex;
- align-items: center;
- justify-content: space-between;
- z-index: 9;
- .tui-tabs-item {
- &.border-left {
- position: relative;
- &::after {
- // content: '';
- // width: 2upx;
- // height: 65%;
- // position: absolute;
- // left: 0upx;
- // top: 50%;
- // transform: translate(0,-50%);
- // background-color: #ddd;
- }
- }
- }
- // .tui-tabs-item:first-child {
- // &.border-left {
- // &::after {
- // content: '';
- // }
- // }
- // }
- }
- .tui-tabs-view-shadow {
- box-shadow: 4px 4px 10px #eee;
- }
- .tui-tabs-relative {
- position: relative;
- }
- .tui-tabs-fixed {
- position: fixed;
- left: 0;
- }
- .tui-tabs-fixed::before,
- .tui-tabs-relative::before {
- content: "";
- position: absolute;
- border-bottom: 1upx solid #eaeef1;
- -webkit-transform: scaleY(0.5);
- transform: scaleY(0.5);
- bottom: 0;
- right: 0;
- left: 0;
- }
- .tui-unlined::before {
- border-bottom: 0 !important;
- }
- .item-wrap {
- width: 100%;
- height: 100%;
- display: flex;
- align-items: center;
- // justify-content: center;
- color: $fontColor3;
- overflow-x: scroll;
- }
- .tui-tabs-item {
- padding: 12upx 0;
- position: relative;
- display: flex;
- height: 100%;
- align-items: center;
- justify-content: center;
- flex-shrink: 0;
- &.active {
- &:after {
- display: block;
- position: absolute;
- width: 70upx;
- height: 6upx;
- bottom: 0;
- left: 50%;
- content: "";
- background-color: $mainColor;
- transform: translate(-50%, 0);
- }
- }
- }
- .tui-tabs-disabled {
- opacity: 0.6;
- }
- .tui-tabs-title {
- // display: flex;
- // align-items: center;
- // justify-content: center;
- position: relative;
- z-index: 2;
- width: 100%;
- &.border-left {
- &::after {
- content: '';
- width: 2upx;
- height: 40upx;
- position: absolute;
- right: 0upx;
- top: 50%;
- transform: translate(0,-50%);
- background-color: #ddd;
- }
- }
- &.border-left {
- }
- }
- .tabs-title {
- text-align: center;
- }
- .tabs-value {
- // @include disFlex(center, center);
- font-size: 24px;
- text-align: center;
- margin-top: 6px;
- }
- .tui-tabs-active {
- transition: all 0.15s ease-in-out;
- color: $mainColor;
- }
- .tui-tabs-slider {
- position: absolute;
- left: 0;
- transition: all 0.15s ease-in-out;
- z-index: 0;
- transform: translateZ(0);
- background: $mainColor;
- }
- </style>
|