This commit is contained in:
HongRun Liu
2026-05-26 15:52:30 +08:00
commit b0744c8ab6
849 changed files with 130587 additions and 0 deletions
@@ -0,0 +1,140 @@
<template>
<view v-show="props.i === props.index" class="h100">
<mescroll-uni
@init="mescrollInit"
top="0"
:down="downOption"
@down="downCallback"
:up="upOption"
@up="upCallback"
@emptyclick="emptyClick"
:height="props.height"
>
<slot></slot>
</mescroll-uni>
</view>
</template>
<script setup>
import { ref, watch, getCurrentInstance } from 'vue';
import useMescroll from '@/uni_modules/mescroll-uni/hooks/useMescroll.js';
const { proxy } = getCurrentInstance();
const props = defineProps({
i: {
// 每个tab页的专属下标
type: Number,
default() {
return 0;
},
},
index: {
// 当前tab的下标
type: Number,
default() {
return 0;
},
},
tabs: {
// 为了请求数据,演示用,可根据自己的项目判断是否要传
type: Array,
default() {
return [];
},
},
pageSize: {
type: Number,
default: 10,
},
height: {
type: String,
default: '100%',
},
});
watch(
() => props.i,
() => {
},
{
immediate: true,
deep: true,
},
);
const { mescrollInit, downCallback, getMescroll } = useMescroll(); // 调用mescroll的hook
const isAutoInit = props.i === props.index; // 自动加载当前tab的数据
const downOption = {
auto: isAutoInit, // 自动加载当前tab的数据
bottomOffset: 20, // 当手指touchmove位置在距离body底部20upx范围内的时候结束上拉刷新,避免Webview嵌套导致touchend事件不执行
};
const upOption = {
auto: true, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
empty: {
tip: '~ 空空如也 ~', // 提示
},
page: {
num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
size: props.pageSize, // 每页数据的数量
},
};
const isInit = ref(isAutoInit); // 当前tab是否已初始化
// 监听下标的变化
watch(
() => props.index,
(val) => {
if (props.i === val && !isInit.value) mescrollTrigger();
},
);
// 主动触发下拉加载
const mescrollTrigger = () => {
isInit.value = true; // 标记为true
const mescroll = getMescroll();
if (mescroll) {
if (mescroll.optDown.use) {
mescroll.triggerDownScroll();
} else {
mescroll.triggerUpScroll();
}
}
};
//点击空布局按钮的回调
const emptyClick = () => {
uni.showToast({
title: '点击了按钮,具体逻辑自行实现',
});
};
const upCallback = (mescroll) => {
setTimeout(() => {
proxy.$emit('upCallback', {
...mescroll,
dataObj: {
status: props.tabs.length ? props.tabs[props.i].value : null,
i: props.i,
index: props.index,
},
});
}, 500);
};
/**
* 根据状态更新 Mescroll 组件的状态
*
* @param state 布尔值,表示 Mescroll 组件的状态,默认为 true
* @param num 数字,表示数据长度,默认为 0
*/
const getState = (state = true, num = 0) => {
const mescroll = getMescroll();
if (state) {
mescroll.endSuccess(num);
} else {
mescroll.endErr();
}
};
defineExpose({ getMescroll, getState, mescrollTrigger }); // 使父组件可以通过ref调用到getMescroll方法 (必须)
</script>
<style lang="scss" scoped></style>
+144
View File
@@ -0,0 +1,144 @@
<template>
<view v-show="props.i === props.index" class="h100">
<mescroll-uni @init="mescrollInit" top="0" :down="downOption" @down="downCallback" :up="upOption"
@up="upCallback" @emptyclick="emptyClick" :height="props.height">
<slot></slot>
</mescroll-uni>
</view>
</template>
<script setup>
import {
ref,
watch,
getCurrentInstance
} from 'vue';
import useMescroll from '@/uni_modules/mescroll-uni/hooks/useMescroll.js';
const {
proxy
} = getCurrentInstance();
const props = defineProps({
i: {
// 每个tab页的专属下标
type: Number,
default () {
return 0;
},
},
index: {
// 当前tab的下标
type: Number,
default () {
return 0;
},
},
tabs: {
// 为了请求数据,演示用,可根据自己的项目判断是否要传
type: Array,
default () {
return [];
},
},
pageSize: {
type: Number,
default: 10,
},
height: {
type: String,
default: '100%',
},
});
watch(
() => props.i,
() => {}, {
immediate: true,
deep: true,
},
);
const {
mescrollInit,
downCallback,
getMescroll
} = useMescroll(); // 调用mescroll的hook
const isAutoInit = props.i === props.index; // 自动加载当前tab的数据
const downOption = {
auto: isAutoInit, // 自动加载当前tab的数据
bottomOffset: 20, // 当手指touchmove位置在距离body底部20upx范围内的时候结束上拉刷新,避免Webview嵌套导致touchend事件不执行
};
const upOption = {
auto: true, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
noMoreSize: 1, // 总数量小于该值也展示“无更多”,设为0确保少于10条时也显示结束
empty: {
tip: '~ 空空如也 ~', // 提示
},
page: {
num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
size: props.pageSize, // 每页数据的数量
},
};
const isInit = ref(isAutoInit); // 当前tab是否已初始化
// 监听下标的变化
watch(
() => props.index,
(val) => {
if (props.i === val && !isInit.value) mescrollTrigger();
},
);
// 主动触发下拉加载
const mescrollTrigger = () => {
isInit.value = true; // 标记为true
const mescroll = getMescroll();
if (mescroll) {
if (mescroll.optDown.use) {
mescroll.triggerDownScroll();
} else {
mescroll.triggerUpScroll();
}
}
};
//点击空布局按钮的回调
const emptyClick = () => {
uni.showToast({
title: '点击了按钮,具体逻辑自行实现',
});
};
const upCallback = (mescroll) => {
setTimeout(() => {
proxy.$emit('upCallback', {
...mescroll,
dataObj: {
status: props.tabs.length ? props.tabs[props.i].value : null,
i: props.i,
index: props.index,
},
});
}, 500);
};
/**
* 根据状态更新 Mescroll 组件的状态
*
* @param state 布尔值,表示 Mescroll 组件的状态,默认为 true
* @param num 数字,表示数据长度,默认为 0
*/
const getState = (state = true, num = 0) => {
const mescroll = getMescroll();
if (state) {
mescroll.endSuccess(num);
} else {
mescroll.endErr();
}
};
defineExpose({
getMescroll,
getState,
mescrollTrigger
}); // 使父组件可以通过ref调用到getMescroll方法 (必须)
</script>
<style lang="scss" scoped></style>
+140
View File
@@ -0,0 +1,140 @@
<template>
<view v-show="props.i === props.index" class="h100">
<mescroll-body
@init="mescrollInit"
top="0"
:down="downOption"
@down="downCallback"
:up="upOption"
@up="upCallback"
@emptyclick="emptyClick"
:height="props.height"
>
<slot></slot>
</mescroll-body>
</view>
</template>
<script setup>
import { ref, watch, getCurrentInstance } from 'vue';
import useMescroll from '@/uni_modules/mescroll-uni/hooks/useMescroll.js';
const { proxy } = getCurrentInstance();
const props = defineProps({
i: {
// 每个tab页的专属下标
type: Number,
default() {
return 0;
},
},
index: {
// 当前tab的下标
type: Number,
default() {
return 0;
},
},
tabs: {
// 为了请求数据,演示用,可根据自己的项目判断是否要传
type: Array,
default() {
return [];
},
},
pageSize: {
type: Number,
default: 10,
},
height: {
type: String,
default: '100%',
},
});
watch(
() => props.i,
() => {
},
{
immediate: true,
deep: true,
},
);
const { mescrollInit, downCallback, getMescroll } = useMescroll(); // 调用mescroll的hook
const isAutoInit = props.i === props.index; // 自动加载当前tab的数据
const downOption = {
auto: isAutoInit, // 自动加载当前tab的数据
bottomOffset: 20, // 当手指touchmove位置在距离body底部20upx范围内的时候结束上拉刷新,避免Webview嵌套导致touchend事件不执行
};
const upOption = {
auto: true, // 是否在初始化完毕之后自动执行下拉刷新的回调; 默认true
noMoreSize: 4, //如果列表已无数据,可设置列表的总数量要大于半页才显示无更多数据;避免列表数据过少(比如只有一条数据),显示无更多数据会不好看; 默认5
empty: {
tip: '~ 空空如也 ~', // 提示
},
page: {
num: 0, // 当前页码,默认0,回调之前会加1,即callback(page)会从1开始
size: props.pageSize, // 每页数据的数量
},
};
const isInit = ref(isAutoInit); // 当前tab是否已初始化
// 监听下标的变化
watch(
() => props.index,
(val) => {
if (props.i === val && !isInit.value) mescrollTrigger();
},
);
// 主动触发下拉加载
const mescrollTrigger = () => {
isInit.value = true; // 标记为true
const mescroll = getMescroll();
if (mescroll) {
if (mescroll.optDown.use) {
mescroll.triggerDownScroll();
} else {
mescroll.triggerUpScroll();
}
}
};
//点击空布局按钮的回调
const emptyClick = () => {
uni.showToast({
title: '点击了按钮,具体逻辑自行实现',
});
};
const upCallback = (mescroll) => {
setTimeout(() => {
proxy.$emit('upCallback', {
...mescroll,
dataObj: {
status: props.tabs.length ? props.tabs[props.i].value : null,
i: props.i,
index: props.index,
},
});
}, 500);
};
/**
* 根据状态更新 Mescroll 组件的状态
*
* @param state 布尔值,表示 Mescroll 组件的状态,默认为 true
* @param num 数字,表示数据长度,默认为 0
*/
const getState = (state = true, num = 0) => {
const mescroll = getMescroll();
if (state) {
mescroll.endSuccess(num);
} else {
mescroll.endErr();
}
};
defineExpose({ getMescroll, getState, mescrollTrigger }); // 使父组件可以通过ref调用到getMescroll方法 (必须)
</script>
<style lang="scss" scoped></style>
+119
View File
@@ -0,0 +1,119 @@
<template>
<view class="card_pages flex1 flex-column h100">
<view v-if="props.type == 1" class="flex1 flex-column">
<slot name="nav"></slot>
<view class="flex1">
<!-- props.oneShow -->
<view v-for="(tab, i) in props.navList" :key="tab.id || i">
<card_mescroll
v-if="props.oneShow?props.currentTab == i:true"
:ref="(el) => mescrollItems[i] && (mescrollItems[i].value = el)"
:i="i"
:index="props.currentTab"
:tabs="props.navList"
@upCallback="upCallback"
:pageSize="props.pageSize"
:height="props.height"
>
<slot name="content"></slot>
</card_mescroll>
</view>
</view>
</view>
</view>
</template>
<script setup>
import { ref, reactive, watch, onMounted, onUnmounted, getCurrentInstance } from 'vue';
import card_mescroll from './card_mescroll.vue';
import card_mescroll1 from './card_mescroll1.vue';
import { onPageScroll, onReachBottom, onShow } from '@dcloudio/uni-app';
import useMescrollMore from '@/uni_modules/mescroll-uni/hooks/useMescrollMore.js';
const { proxy } = getCurrentInstance();
const props = defineProps({
type: {
type: Number,
default: 1,
},
navList: {
//菜单列表
type: Array,
default: () => [],
},
currentTab: {
//当前选中的菜单
type: Number,
default: 0,
},
pageSize: {
type: Number,
default: 10,
},
height: {
type: String,
default: '100%',
},
oneShow: {
//滚动的时候根据全局滚动测算
type: Boolean,
default: false,
},
});
let mescrollRef = ref(null);
watch(
() => {
props.currentTab;
},
(val) => {
if (props.oneShow && mescrollRef.value) {
mescrollRef.value.mescrollTrigger();
}
},
{
immediate: true,
deep: true,
},
);
// 动态生成与 tabs 同步的 refs 数组,供 useMescrollMore 使用
const mescrollItems = props.navList.map(() => ref(null));
const { getMescroll, scrollToLastY } = useMescrollMore(
mescrollItems,
onPageScroll,
onReachBottom,
);
// 下拉刷新回调
const downCallback = () => {
if (props.oneShow && mescrollRef.value) {
mescrollRef.value.mescrollTrigger();
return;
}
if (mescrollItems.length && mescrollItems[props.currentTab]) {
mescrollItems[props.currentTab].value.mescrollTrigger();
}
};
// 上拉加载回调
const upCallback = (mescroll) => {
//获取数据
proxy.$emit('upCallback', mescroll);
};
const getState = (state = true, num = 0) => {
// console.log(mescrollItems[props.currentTab].value)
if (props.oneShow && mescrollRef.value) {
return mescrollRef.value.getState(state, num);
}
if (mescrollItems.length && mescrollItems[props.currentTab]) {
return mescrollItems[props.currentTab].value.getState(state, num);
}
};
defineExpose({
getMescroll,
scrollToLastY,
getState,
downCallback,
});
</script>
<style lang="scss" scoped></style>