Commit 372e5c40 by cen

fix: 样式修改

1 parent 86aec38a
<template>
<view class="type-tab">
<scroll-view class="type-box" scroll-x="true" show-scrollbar="false" scroll-with-animation>
<scroll-view class="type-box" scroll-x="true" show-scrollbar="false" scroll-with-animation @scroll="onScroll" ref="scrollView">
<view class="type-scroll-content">
<view class="tab-item" :class="[tabClass(index)]" v-for="(i, index) in typeList" :key="index" @click.stop="tabClick(index, i)">
<view v-if="tabIndex == index && index == 0" class="sprite-icon tab-first-left icon-first-left"></view>
<view v-if="tabIndex == index && index == 0" class="sprite-icon tab-first-right icon-first-right"></view>
<view v-if="tabIndex == index && index != 0 && index != typeList.length - 1" class="sprite-icon tab-second-right icon-second-right"></view>
<view v-if="tabIndex == index && index != 0 && index == typeList.length - 1" class="sprite-icon tab-end-right icon-end-right"></view>
<view v-if="tabIndex == index && index != 0 && (index != typeList.length - 1 || (index == typeList.length - 1 && !isOverflow))" class="sprite-icon tab-second-right icon-second-right"></view>
<view v-if="tabIndex == index && index != 0 && index == typeList.length - 1 && isOverflow" class="sprite-icon tab-end-right icon-end-right"></view>
<view v-if="tabIndex == index && index != 0" class="sprite-icon tab-second-left icon-second-left"></view>
<view class="text flex justify-center align-center" :class="[tabIndex == index ? `active` : '']">
<view>{{ i[nameKey] }}</view>
......@@ -39,6 +39,7 @@ export default {
data () {
return {
firstClass: Object.freeze(['first-nav', 'second-nav']),
isOverflow: false
}
},
computed: {
......@@ -48,8 +49,67 @@ export default {
},
},
mounted () {
// 延迟检测,确保 DOM 完全渲染
setTimeout(() => {
this.checkOverflow()
}, 300)
},
updated () {
// 延迟检测,确保 DOM 完全渲染
setTimeout(() => {
this.checkOverflow()
}, 300)
},
watch: {
typeList: {
handler () {
this.$nextTick(() => {
this.checkOverflow()
})
},
deep: true
}
},
methods: {
onScroll (e) {
// 通过滚动事件检测是否可以滚动
// 如果能滚动(scrollLeft > 0 或可以滚动到最右边),说明内容超出
const scrollLeft = e.detail.scrollLeft
const scrollWidth = e.detail.scrollWidth
// 如果 scrollLeft > 0,说明可以滚动,内容超出
// 或者如果 scrollWidth 存在且明显大于 0,也可能说明可以滚动
// 但为了更准确,我们还是使用 checkOverflow 方法
// 这里可以作为一个辅助检测
if (scrollLeft > 0 && !this.isOverflow) {
this.isOverflow = true
}
},
checkOverflow () {
this.$nextTick(() => {
// 增加延迟,确保 DOM 完全渲染
setTimeout(() => {
const query = uni.createSelectorQuery().in(this)
query.select('.type-box').boundingClientRect()
query.select('.type-scroll-content').boundingClientRect()
query.exec((res) => {
if (res && res[0] && res[1]) {
const boxRect = res[0]
const contentRect = res[1]
// 如果内容宽度大于容器宽度,说明可以滚动
// 添加一个小的容差值,避免因为像素精度问题导致判断错误
const overflow = contentRect.width > boxRect.width + 1
this.isOverflow = overflow
console.log('检测溢出状态:', {
boxWidth: boxRect.width,
contentWidth: contentRect.width,
isOverflow: this.isOverflow,
typeListLength: this.typeList.length
})
}
})
}, 300)
})
},
tabClass (index) {
let className = ''
if (this.tabIndex == index) {
......
......@@ -118,7 +118,7 @@
</template>
</view>
</view>
<view class="flex align-center justify-between">
<view class="flex align-center justify-between mt-108">
<checkbox-group @change="checkboxChange">
<label class="flex">
<checkbox value="cb" :checked="isConfirmChecked" activeBackgroundColor="#4673FF" iconColor="#fff" style="transform: scale(0.6)" />
......@@ -869,7 +869,7 @@ export default {
height: toRpx(672);
border-right: 2px solid #f7f7f6;
box-sizing: border-box;
padding-right: toRpx(24);
padding-right: toRpx(40);
flex-shrink: 0;
.tabItem {
border-radius: toRpx(24);
......@@ -899,7 +899,7 @@ export default {
}
.desc {
color: #666666;
font-size: toRpx(28);
font-size: toRpx(26);
font-weight: 400;
}
}
......@@ -1008,6 +1008,9 @@ export default {
font-weight: 500;
text-align: center;
}
.mt-108 {
margin-top: toRpx(68);
}
}
}
</style>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!