init
This commit is contained in:
@@ -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>
|
||||
Reference in New Issue
Block a user