123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- <template>
-
- <view>
-
-
-
- <view class="navTabBox" :class="{isFixed:isFixed}" :style="[boxStyle]">
- <view class="longTab">
- <scroll-view scroll-x="true" style="white-space: nowrap; display: flex;" scroll-with-animation
- :scroll-left="tabLeft" show-scrollbar="true">
- <view class="longItem"
- :style="'width:'+isWidth+'px;color:' + (index == tabClick ? checkColor : fontColor)+';--color:'+checkColor"
- :data-index="index" :class="index===tabClick?'click':''" v-for="(item,index) in tabList"
- :key="index" :id="'id'+index" @click="longClick(index,item)">{{ item.title }}
- </view>
- </scroll-view>
- </view>
- </view>
- <view style="height: 70rpx"></view>
- </view>
- </template>
- <script>
-
-
-
-
-
-
-
-
-
- import {
- getCategoryFirst,
- } from '@/api/api.js';
- let app = getApp();
- export default {
- name: 'tabNav',
- props: {
- dataConfig: {
- type: Object,
- default: () => {}
- },
-
- isFixed: {
- type: Boolean,
- default: false
- }
- },
- data() {
- return {
- tabClick: 0,
- isLeft: 0,
- isWidth: 0,
- mainWidth: 0,
- tabLeft: 0,
- isTop: 0,
- navHeight: 35,
- tabItem: null ,
- themeColor:this.$options.filters.filterTheme(app.globalData.theme)
- };
- },
- computed: {
-
- boxStyle() {
- return {
- borderRadius: this.dataConfig.bgStyle.val * 2 + 'rpx',
- background: `linear-gradient(${this.dataConfig.bgColor.color[0].item}, ${this.dataConfig.bgColor.color[1].item})`,
- }
- },
-
- fontColor() {
- return this.dataConfig.fontColor.color[0].item
- },
-
- checkColor() {
- return this.dataConfig.themeStyleConfig.tabVal?this.dataConfig.checkColor.color[0].item:this.themeColor
- },
- tabList() {
-
- let tabList = this.dataConfig.listConfig.list;
- tabList.unshift({
- title: '首页',
- type: 2,
- val: 0
- })
- return tabList
- },
- },
- created() {
- let that = this
-
- uni.getSystemInfo({
- success(e) {
-
- that.isWidth = (e.windowWidth) / 5
- }
- })
- setTimeout((e) => {
- let statusHeight = uni.getSystemInfoSync().statusBarHeight;
- const query = uni.createSelectorQuery().in(this);
- query.select('.navTabBox').boundingClientRect(data => {
- that.navHeight = (data.height + statusHeight) * 2;
- }).exec();
- }, 300)
- that.$nextTick(function() {
- uni.getSystemInfo({
- success: function(res) {
- that.windowHeight = res.windowHeight;
- }
- });
- })
-
- this.isTop = (uni.getSystemInfoSync().statusBarHeight + 43) + 'px'
-
-
- this.isTop = 0
-
- },
- watch: {
- tabClick: {
- handler(newValue, oldValue) {
- if (this.tabItem) this.$emit('changeTab', newValue, this.tabItem);
- },
- immediate: true
- }
- },
- methods: {
-
- longClick(index, item) {
- this.tabItem = item;
- this.tabClick = index;
- this.$nextTick(() => {
- let id = 'id' + index;
- this.tabLeft = (index - 2) * this.isWidth
-
- })
- },
- }
- }
- </script>
- <style lang="scss" scoped>
- .navTabBox {
- width: 100%;
- height: 70rpx;
- color: rgba(255, 255, 255, 1);
- position: fixed;
- z-index: 99;
- &.isFixed {
- z-index: 10;
- position: fixed;
- left: 0;
- width: 100%;
- /* #ifdef H5 */
- top: 0;
- /* #endif */
- }
- .click {
- color: white;
- }
- .longTab {
- .longItem {
- height: 70rpx;
- display: inline-block;
- line-height: 70rpx;
- text-align: center;
- font-size: 28rpx;
- color: #333333;
- white-space: nowrap;
- overflow: hidden;
- text-overflow: ellipsis;
- &.click {
- font-weight: bold;
- font-size: 30rpx;
- position: relative;
- &::after {
- content: '';
- width: 40rpx;
- height: 4rpx;
- background: var(--color);
- // background-color: #E93323;
- position: absolute;
- bottom: 0;
- left: 50%;
- transform: translateX(-50%);
- }
- }
- }
- }
- }
- </style>
|