diff --git a/src/pages/sparring/index.vue b/src/pages/sparring/index.vue index 9b307a09..0136702b 100644 --- a/src/pages/sparring/index.vue +++ b/src/pages/sparring/index.vue @@ -2,7 +2,7 @@ - + @@ -14,11 +14,11 @@ - - @@ -66,7 +66,7 @@ - @@ -112,7 +112,8 @@ onUnmounted } from 'vue' import { - onShow + onShow, + onHide } from '@dcloudio/uni-app' import { useSocketStore @@ -136,6 +137,8 @@ borderRadius: '23rpx' } const catelogList = ref([]) + const currentTab = ref(0) + const currentTabSec = ref(0) const tabList = computed(() => { return [{ name: '全 部', @@ -226,21 +229,6 @@ // showFilterList.value = false } const activeLeftIndex = ref(-1) - const getActiveItemClass = () => { - let _class = '' - if ('生产线' === activeTab.value) { - _class = activeLeftIndex.value === 0 ? 'no-radius' : '' - } else if ('全部' === activeTab.value) { - _class = activeLeftIndex.value === 0 ? 'no-radius' : '' - } - return _class - } - // 点击生产线分类 - const changePrdLine = (item, index) => { - activePrdlineType.value = item.value === activePrdlineType.value ? '' : item.value - activeLeftIndex.value = index - getMoreList(1) - } // 点击课程分类 const tagsList = computed(() => { let _arr = [] @@ -367,7 +355,12 @@ }) } } + const reSeting = ref(false) onMounted(() => { + reSeting.value = true + setTimeout(()=>{reSeting.value = false}) + currentTab.value = 0 + currentTabSec.value = 0 queryTraPartnerCatelogList().then(res => { catelogList.value = res.body || [] }) @@ -386,20 +379,34 @@ onUnmounted(() => { uni.$off('refresh_sparring_list') }) - onActivated(() => { - // 重新获取标签信息 - getTraTagListApi().then(res => { - tagsTree.value = res.body || [] - }) - changeTab({ - name: activeTab.value || '全部' - }) - }) + // onActivated(() => { + // currentTab.value = 2 + // currentTabSec.value = 0 + // // 重新获取标签信息 + // getTraTagListApi().then(res => { + // tagsTree.value = res.body || [] + // }) + // changeTab({ + // name: activeTab.value || '全部' + // }) + // }) onShow(() => { + reSeting.value = true + setTimeout(()=>{reSeting.value = false}) + currentTab.value = 0 + currentTabSec.value = 0 changeTab({ name: activeTab.value || '全部' }) socketStore.closeSocket() + uni.$on('refresh_sparring_list', () => { + changeTab({ + name: activeTab.value || '全部' + }) + }) + }) + onHide(() => { + uni.$off('refresh_sparring_list') }) diff --git a/src/uni_modules/uv-tabs/components/uv-tabs/uv-tabs.vue b/src/uni_modules/uv-tabs/components/uv-tabs/uv-tabs.vue index cfbc3b70..77cbf997 100644 --- a/src/uni_modules/uv-tabs/components/uv-tabs/uv-tabs.vue +++ b/src/uni_modules/uv-tabs/components/uv-tabs/uv-tabs.vue @@ -251,6 +251,8 @@ }) }, setScrollLeft() { + setTimeout(()=> { + // 当前活动tab的布局信息,有tab菜单的width和left(为元素左边界到父元素左边界的距离)等信息 const tabRect = this.list[this.innerCurrent] // 累加得到当前item到左边的距离 @@ -261,12 +263,14 @@ }, 0) // 此处为屏幕宽度 const windowWidth = this.$uv.sys().windowWidth + let _rect = tabRect?.rect?.width||0 // 将活动的tabs-item移动到屏幕正中间,实际上是对scroll-view的移动 - let scrollLeft = offsetLeft - (this.tabsRect.width - tabRect.rect.width) / 2 - (windowWidth - this.tabsRect + let scrollLeft = offsetLeft - (this.tabsRect.width - _rect) / 2 - (windowWidth - this.tabsRect .right) / 2 + this.tabsRect.left / 2 // 这里做一个限制,限制scrollLeft的最大值为整个scroll-view宽度减去tabs组件的宽度 scrollLeft = Math.min(scrollLeft, this.scrollViewWidth - this.tabsRect.width) this.scrollLeft = Math.max(0, scrollLeft) + },200) }, // 获取所有标签的尺寸 resize() {