特效-暂存

This commit is contained in:
zpc 2025-07-24 22:42:17 +08:00
parent 3954f0162c
commit a103146953
5 changed files with 385 additions and 252 deletions

3
components.d.ts vendored
View File

@ -10,12 +10,13 @@ declare module 'vue' {
export interface GlobalComponents {
Container: typeof import('./components/guyu/home/container.vue')['default']
GoodsItem: typeof import('./components/guyu/home/goods-item.vue')['default']
GoodsList: typeof import('./components/guyu/home/goods-list.vue')['default']
Notice: typeof import('./components/guyu/home/notice.vue')['default']
Recommend: typeof import('./components/guyu/home/recommend.vue')['default']
RouterLink: typeof import('vue-router')['RouterLink']
RouterView: typeof import('vue-router')['RouterView']
Search: typeof import('./components/guyu/home/search.vue')['default']
StickySwiperNextItem: typeof import('./components/sticky-swiper-next-item/sticky-swiper-next-item.vue')['default']
Swiper: typeof import('./components/guyu/home/swiper.vue')['default']
Tabs: typeof import('./components/guyu/home/tabs.vue')['default']
}
}

View File

@ -0,0 +1,143 @@
<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
<view class="content">
<!-- 这里设置了z-paging加载时禁止自动调用reload方法自行控制何时reload懒加载-->
<z-paging ref="paging" v-model="dataList" @query="queryList" use-page-scroll :scrollable="false"
:hide-empty-view="hideEmptyView" :refresher-enabled="false" @contentHeightChanged="contentHeightChanged"
:auto="false" :auto-clean-list-when-reload="false">
<!-- 如果希望其他view跟着页面滚动可以放在z-paging标签内 -->
<view class="item" v-for="(item, index) in dataList" :key="index">
<view class="item-title">{{ item.title }}</view>
<view class="item-detail">{{ item.detail }}</view>
<view class="item-line"></view>
</view>
</z-paging>
</view>
</template>
<script>
export default {
data() {
return {
// v-model
dataList: [],
height: 0,
hideEmptyView: true,
completeFunc: null
}
},
props: {
// indexswiper
tabIndex: {
type: Number,
default: function () {
return 0
}
},
// swiperindex
currentIndex: {
type: Number,
default: function () {
return 0
}
}
},
watch: {
currentIndex: {
handler(newVal) {
if (newVal === this.tabIndex) {
// item
this.$nextTick(() => {
setTimeout(() => {
this.$refs.paging.reload();
}, 100);
})
}
},
immediate: true
}
},
methods: {
queryList(pageNo, pageSize) {
//
// pageNopageSize
//
const params = {
pageNo: pageNo,
pageSize: pageSize,
type: this.tabIndex + 1
}
let c = [];
for (let i = 0; i < 10; i++) {
c.push({
title: '测试' + i,
detail: '详情' + i
})
}
this.$refs.paging.complete(c);
this.hideEmptyView = false;
//使z-paging
if (this.completeFunc) {
this.completeFunc();
}
},
//
reload(completeFunc) {
//
this.completeFunc = completeFunc;
// z-pagingreload
this.$refs.paging.reload();
},
// swiper
contentHeightChanged(height) {
const finalHeight = this.dataList.length ? height : 0;
// z-tabs使slot="top"viewminHeightslot="top"view
const minHeight = uni.getSystemInfoSync().windowHeight - uni.upx2px(80);
this.$emit('heightChanged', Math.max(finalHeight, minHeight));
},
//
doLoadMore() {
this.$refs.paging.doLoadMore();
},
//
clear() {
this.$refs.paging.clear();
this.hideEmptyView = true;
}
}
}
</script>
<style>
/* 注意1、父节点需要固定高度z-paging的height:100%才会生效 */
/* 注意2、请确保z-paging与同级的其他view的总高度不得超过屏幕宽度以避免超出屏幕高度时页面的滚动与z-paging内部的滚动冲突 */
.content {
height: 100%;
}
.item {
position: relative;
height: 150rpx;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0rpx 30rpx;
}
.item-detail {
padding: 5rpx 15rpx;
border-radius: 10rpx;
font-size: 28rpx;
color: white;
background-color: #007AFF;
}
.item-line {
position: absolute;
bottom: 0rpx;
left: 0rpx;
height: 1px;
width: 100%;
background-color: #eeeeee;
}
</style>

View File

@ -0,0 +1,126 @@
<template>
<view class="tabs-container">
<view class="tabs-wrapper">
<template v-for="(item, index) in list" :key="index">
<view class="tab-item-wrapper" :style="{ width: getLableWidth(item.name) }">
<view class="tab-item" @click="clickTab(index)">
<text class="tab-text myZt-500w">{{ item.name }}</text>
</view>
<view style="position: relative;width:50%;height: 100%;overflow: hidden;top: -100%;"
:style="{ width: getNextWidth(index) }">
<view style="" :style="{ width: getLableWidth(item.name) }">
<view class="tab-item tab-item-active" @click="clickTab(index)">
<text class="tab-text myZt-500w">{{ item.name }}</text>
</view>
</view>
</view>
</view>
</template>
</view>
</view>
</template>
<script setup>
import { onMounted, ref } from 'vue';
const props = defineProps({
list: {
type: Array,
default: () => []
},
current: {
type: Number,
default: 0
}
});
onMounted(() => {
})
const getLableWidth = (name) => {
let t = name.length * 20 + 40;
if (t < 80) {
t = 80;
}
return t + "rpx";
}
const getNextWidth = (currendIndex) => {
if (swiperDx.value == 0) {
return "0%";
}
if (swiperDx.value < 0) {
}
if (currendIndex == props.current) {
return ((swiperDx.value / systemWidth).toFixed(2) * 100) + "%";
}
return "0%";
}
// computed()
const systemWidth = parseInt(uni.getSystemInfoSync().screenWidth * 0.96);
const emit = defineEmits(['change']);
//
const clickTab = (index) => {
emit("change", index)
};
let swiperDx = ref(0);
let throttleTimer = null;
const setDx = (dx) => {
if (!throttleTimer) {
swiperDx.value = parseInt(dx);
console.log(swiperDx.value, dx, systemWidth, getNextWidth(props.current));
throttleTimer = setTimeout(() => {
throttleTimer = null;
}, 20);
}
}
const unlockDx = () => {
swiperDx.value = 0;
}
//
defineExpose({
setDx,
unlockDx
});
</script>
<style lang="scss" scoped>
.tabs-container {
width: 100%;
}
.tabs-wrapper {
width: 100%;
display: flex;
flex-direction: row;
margin-top: 32.64rpx;
}
.tab-item-wrapper {
min-width: 80rpx;
margin-right: 26.39rpx;
text-align: center;
line-height: 40rpx;
height: 50rpx;
overflow: hidden;
}
.tab-item {
border-radius: 50rpx;
background-color: transparent;
border: 1rpx solid #9A8F79;
}
.tab-item-active {
background-color: #F5D677;
border: 1rpx solid transparent;
}
.tab-text {
font-size: 22rpx;
}
</style>

View File

@ -1,142 +0,0 @@
<!-- 在这个文件对每个tab对应的列表进行渲染 -->
<template>
<view class="content">
<!-- 这里设置了z-paging加载时禁止自动调用reload方法自行控制何时reload懒加载-->
<z-paging ref="paging" v-model="dataList" @query="queryList" use-page-scroll :scrollable="false" :hide-empty-view="hideEmptyView"
:refresher-enabled="false" @contentHeightChanged="contentHeightChanged" :auto="false" :auto-clean-list-when-reload="false">
<!-- 如果希望其他view跟着页面滚动可以放在z-paging标签内 -->
<view class="item" v-for="(item,index) in dataList" :key="index">
<view class="item-title">{{item.title}}</view>
<view class="item-detail">{{item.detail}}</view>
<view class="item-line"></view>
</view>
</z-paging>
</view>
</template>
<script>
export default {
data() {
return {
// v-model
dataList: [],
height: 0,
hideEmptyView: true,
completeFunc: null
}
},
props: {
// indexswiper
tabIndex: {
type: Number,
default: function(){
return 0
}
},
// swiperindex
currentIndex: {
type: Number,
default: function(){
return 0
}
}
},
watch: {
currentIndex: {
handler(newVal) {
if (newVal === this.tabIndex) {
// item
this.$nextTick(() => {
setTimeout(() => {
this.$refs.paging.reload();
}, 100);
})
}
},
immediate: true
}
},
methods: {
queryList(pageNo, pageSize) {
//
// pageNopageSize
//
const params = {
pageNo: pageNo,
pageSize: pageSize,
type: this.tabIndex + 1
}
let c=[];
for(let i=0;i<10;i++){
c.push({
title: '测试' + i,
detail: '详情' + i
})
}
this.$refs.paging.complete(c);
this.hideEmptyView = false;
//使z-paging
if (this.completeFunc) {
this.completeFunc();
}
},
//
reload(completeFunc) {
//
this.completeFunc = completeFunc;
// z-pagingreload
this.$refs.paging.reload();
},
// swiper
contentHeightChanged(height){
const finalHeight = this.dataList.length ? height : 0;
// z-tabs使slot="top"viewminHeightslot="top"view
const minHeight = uni.getSystemInfoSync().windowHeight - uni.upx2px(80);
this.$emit('heightChanged',Math.max(finalHeight, minHeight));
},
//
doLoadMore(){
this.$refs.paging.doLoadMore();
},
//
clear(){
this.$refs.paging.clear();
this.hideEmptyView = true;
}
}
}
</script>
<style>
/* 注意1、父节点需要固定高度z-paging的height:100%才会生效 */
/* 注意2、请确保z-paging与同级的其他view的总高度不得超过屏幕宽度以避免超出屏幕高度时页面的滚动与z-paging内部的滚动冲突 */
.content {
height: 100%;
}
.item {
position: relative;
height: 150rpx;
display: flex;
align-items: center;
justify-content: space-between;
padding: 0rpx 30rpx;
}
.item-detail {
padding: 5rpx 15rpx;
border-radius: 10rpx;
font-size: 28rpx;
color: white;
background-color: #007AFF;
}
.item-line {
position: absolute;
bottom: 0rpx;
left: 0rpx;
height: 1px;
width: 100%;
background-color: #eeeeee;
}
</style>

View File

@ -1,29 +1,28 @@
<!-- 滑动切换选项卡+吸顶演示(上一个tab数据不保留滚动流畅) -->
<template>
<view class="content">
<view>
<z-paging ref="pagePaging" refresher-only @onRefresh="onRefresh" @scrolltolower="scrolltolower"
@scroll="scroll">
<view class="content">
<guyu-home-search style="width: 100%;"></guyu-home-search>
<!-- 公告 -->
<guyu-home-notice :notice-info="homeData?.noticeInfo" />
<!-- 轮播图 -->
<guyu-home-swiper :advert-list="homeData?.advertList" style="width: 100%;" />
<!-- 推荐位 -->
<guyu-home-recommend :rec-list="homeData?.recList" @item-click="toDetails" style="width: 100%;" />
<view class="banner-view" style="height: 250rpx;">
<view style="font-size: 40rpx;font-weight: 700;">这是一个banner</view>
<view style="font-size: 24rpx;margin-top: 5rpx;">下方tab滚动时可吸附在顶部</view>
</view>
<view>
<!-- 小程序中直接修改组件style为position: sticky;无效需要在组件外层套一层view -->
<view class="bar-view" style="z-index:97;position: sticky;top :0;background-color: #fff;">
<view :style="{ height: tabsBarHeight + 'px' }" class="status-bar">
</view>
<z-tabs ref="tabs" :current="current" :list="tabList" @change="tabsChange" />
<view :style="{ height: tabsBarHeight + 'px' }" class="status-bar"> </view>
<guyu-home-tabs ref="tabs" :list="homeData.categories" @change="tabsChange" :current="current" />
</view>
<swiper class="swiper" :style="[{ height: swiperHeight + 'px' }]" :current="current"
@transition="swiperTransition" @animationfinish="swiperAnimationfinish">
<swiper-item class="swiper-item" v-for="(item, index) in tabList" :key="index">
<!-- 这里的sticky-swiper-next-item为demo中为演示用定义的组件列表及分页代码在sticky-swiper-next-item组件内 -->
<!-- 请注意sticky-swiper-next-item非z-paging内置组件在自己的项目中必须自己创建若未创建则会报组件不存在的错误 -->
<stickySwiperNextItemVue ref="swiperList" :tabIndex="index" :currentIndex="current"
<guyu-home-goods-list ref="swiperList" :tabIndex="index" :currentIndex="current"
@heightChanged="heightChanged">
</stickySwiperNextItemVue>
</guyu-home-goods-list>
</swiper-item>
</swiper>
</view>
@ -31,108 +30,114 @@
</view>
</template>
<script>
<script setup>
import { ref, onMounted } from 'vue';
import {
homeData,
isLoading,
error,
preloadHomeData,
refreshHomeData
} from '@/common/server/home';
//
const swiperHeight = ref(0);
const tabList = ref(['测试1', '测试2', '测试3', '测试4']);
const current = ref(0); // tabscurrenttab
const tabsBarHeight = ref(0);
const statusBarHeight = ref(uni.getSystemInfoSync().statusBarHeight);
const isQuerying = ref(false);
import stickySwiperNextItemVue from '../../components/sticky-swiper-next-item/sticky-swiper-next-item.vue';
export default {
components: {
stickySwiperNextItemVue
},
data() {
let statusBarHeight = uni.getSystemInfoSync().statusBarHeight;
return {
swiperHeight: 0,
tabList: ['测试1', '测试2', '测试3', '测试4'],
current: 0, // tabscurrenttab
swiperHeight: 0,
tabsBarHeight: 0,
observer: null,
statusBarHeight,
isQuerying: false
//
const pagePaging = ref(null);
const tabs = ref(null);
const swiperList = ref(null);
onLoad(() => {
});
//
onMounted(() => {
if (!homeData.value) preloadHomeData();
});
//
const scroll = (e) => {
// #ifdef MP
if (e.detail.scrollTop < 700 && statusBarHeight.value > 0) {
if (isQuerying.value) {
return;
}
},
methods: {
scroll(e) {
// #ifdef MP
if (e.detail.scrollTop < 700 && this.statusBarHeight > 0) {
if (this.isQuerying) {
return;
isQuerying.value = true;
const query = uni.createSelectorQuery();
query.select('.bar-view').boundingClientRect(rect => {
if (rect) {
//
if (rect.top <= 0 && tabsBarHeight.value == 0) {
tabsBarHeight.value = statusBarHeight.value;
} else if (rect.top > 30 && statusBarHeight.value > 0) {
tabsBarHeight.value = 0;
}
this.isQuerying = true;
const query = uni.createSelectorQuery().in(this);
query.select('.bar-view').boundingClientRect(rect => {
if (rect) {
//
if (rect.top <= 30) {
this.tabsBarHeight = this.statusBarHeight;
} else if (rect.top > 30 && this.statusBarHeight > 0) {
this.tabsBarHeight = 0;
}
}
this.isQuerying = false;
}).exec();
}
// #endif
},
// tabsswiper
tabsChange(index) {
this._setCurrent(index);
},
// reload
onRefresh() {
this.$refs.swiperList[this.current].reload(() => {
//
this.$refs.pagePaging.endRefresh();
});
},
//
scrolltolower() {
this.$refs.swiperList[this.current].doLoadMore();
},
// swiper
swiperTransition(e) {
this.$refs.tabs.setDx(e.detail.dx);
},
// swiper
swiperAnimationfinish(e) {
this._setCurrent(e.detail.current);
this.$refs.tabs.unlockDx();
},
// swiper
heightChanged(height) {
if (height === 0) {
// swiper-tabsView-slot="top"view
// uni.upx2px(80)slot="top"viewslot="top"view80rpx
height = uni.getSystemInfoSync().windowHeight - uni.upx2px(80);
}
this.swiperHeight = height;
},
_setCurrent(current) {
if (current !== this.current) {
//tabtab
this.$refs.swiperList[this.current].clear();
}
this.current = current;
}
isQuerying.value = false;
}).exec();
}
}
// #endif
};
// tabsswiper
const tabsChange = (index) => {
_setCurrent(index);
};
// reload
const onRefresh = () => {
swiperList.value[current.value].reload(() => {
//
pagePaging.value.endRefresh();
});
};
//
const scrolltolower = () => {
swiperList.value[current.value].doLoadMore();
};
// swiper
const swiperTransition = (e) => {
tabs.value.setDx(e.detail.dx);
};
// swiper
const swiperAnimationfinish = (e) => {
_setCurrent(e.detail.current);
tabs.value.unlockDx();
};
// swiper
const heightChanged = (height) => {
if (height === 0) {
// swiper-tabsView-slot="top"view
// uni.upx2px(80)slot="top"viewslot="top"view80rpx
height = uni.getSystemInfoSync().windowHeight - uni.upx2px(80);
}
swiperHeight.value = height;
};
const _setCurrent = (currentVal) => {
if (currentVal !== current.value) {
//tabtab
swiperList.value[current.value].clear();
}
current.value = currentVal;
};
</script>
<style>
.banner-view {
background-color: #007AFF;
color: white;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
}
.paging-content {
flex: 1;
display: flex;
flex-direction: column;
<style lang="scss" scoped>
.content {
width: 96%;
margin-left: 2%;
background-color: url('@@:static/bg.png');
background-size: 100% 100%;
background-repeat: no-repeat;
}
.swiper {