Commit 173c6eaf authored by wykolor's avatar wykolor

feat: 拆分组件下拉刷新上拉加载更多

parent 21ea442b
......@@ -61,7 +61,8 @@
"ecmaVersion": 2020
},
"rules": {
"@typescript-eslint/camelcase": "off"
"@typescript-eslint/camelcase": "off",
"@typescript-eslint/no-explicit-any": 0
}
},
"browserslist": [
......
<template>
<div class="tab-add">
<van-pull-refresh :modelValue="paging.refreshing" @refresh="refresh">
<van-list
:modelValue="paging.loading"
:finished="isFinished"
:finished-text="finishText"
@load="loadMore"
>
<div v-for="item in paging.list" :key="item.id" class="add-item">
<div class="flex">
<span>{{ item.bizTypeName }}</span>
</div>
<div class="flex add-item-desc-money">
<span class="gray">{{ item.creationTime }}</span>
<label>+¥{{ item.amountChange }}</label>
</div>
<pull-refresh-list v-slot="{ list }" :request="getBonusList" :paramsFn="paramsFn">
<div v-for="item in list" :key="item.id" class="add-item">
<div class="flex">
<span>{{ item.bizTypeName }}</span>
</div>
<van-empty key="2" image="search" v-if="paging.error" :description="paging.error" />
<van-empty v-else-if="paging.isLoad && paging.total < 1" />
<div class="list-footer">
<van-loading v-if="paging.loading" color="#1989fa" />
<div class="flex">
<span class="gray">{{ item.creationTime }}</span>
<label class="desc-money">+¥{{ item.amountChange }}</label>
</div>
</van-list>
</van-pull-refresh>
</div>
</pull-refresh-list>
</div>
</template>
<script lang="ts">
import { defineComponent, computed, onMounted } from "vue";
import { List, PullRefresh, Empty, Loading } from "vant";
import { usePaging } from "@/util/use-paging";
import { defineComponent, computed } from "vue";
import { getBonusList } from "@/server/api/bonus";
import { FlowType, BizType } from "@/model/bonus/constant";
import { useStore } from "vuex";
import { useRoute } from "vue-router";
import PullRefreshList from "../components/pullRefreshList.vue";
export default defineComponent({
components: {
[List.name]: List,
[PullRefresh.name]: PullRefresh,
[Empty.name]: Empty,
[Loading.name]: Loading
PullRefreshList
},
setup() {
const route = useRoute();
const store = useStore();
const bonusStoreState = computed(() => store.state.bonus);
const [paging, loadMore, refresh, helpers] = usePaging(getBonusList, () => ({
const paramsFn = () => ({
studentId: route.query.studentId || bonusStoreState.value.studentId,
flowType: "ADD"
}));
});
onMounted(refresh);
return { ...helpers, paging, loadMore, refresh, FlowType, BizType };
return { getBonusList, paramsFn };
}
});
</script>
......@@ -64,17 +46,6 @@ export default defineComponent({
min-height: calc(100vh - 80px);
}
}
.list-footer {
display: flex;
justify-content: center;
}
// @supports (bottom: constant(safe-area-inset-bottom)) or (bottom: env(safe-area-inset-bottom)) {
// .list-footer {
// padding-bottom: constant(safe-area-inset-bottom);
// padding-bottom: env(safe-area-inset-bottom);
// }
// }
.flex {
line-height: 47px;
......@@ -86,18 +57,18 @@ export default defineComponent({
color: #bdc4d1;
font-size: 24px;
}
.add-item {
background: #fff;
margin: 26px 20px;
padding: 20px;
border-radius: 10px;
box-shadow: 0px 10px 20px 0px rgba(221, 221, 221, 0.3);
&-desc-money {
label {
color: #f1551e;
font-size: 28px;
font-weight: 600;
}
}
}
.desc-money {
color: #f1551e;
font-size: 28px;
font-weight: 600;
}
</style>
<template>
<van-pull-refresh :modelValue="paging.refreshing" @refresh="refresh">
<van-list
:modelValue="paging.loading"
:finished="isFinished"
:finished-text="finishText"
@load="loadMore"
>
<slot :list="paging.list"></slot>
<van-empty key="2" image="search" v-if="paging.error" :description="paging.error" />
<van-empty v-else-if="paging.isLoad && paging.total < 1" />
<div class="list-footer">
<van-loading v-if="paging.loading" color="#1989fa" />
</div>
</van-list>
</van-pull-refresh>
</template>
<script lang="ts">
import { defineComponent, onMounted, PropType } from "vue";
import { PullRefresh, List, Empty, Loading } from "vant";
import { PagingFunc, usePaging } from "@/util/use-paging";
export default defineComponent({
components: {
[List.name]: List,
[PullRefresh.name]: PullRefresh,
[Empty.name]: Empty,
[Loading.name]: Loading
},
props: {
request: {
type: Function as PropType<PagingFunc<object, any>>,
required: true
},
paramsFn: {
type: Function as PropType<() => Partial<any>>
}
},
setup(props) {
const [paging, loadMore, refresh, helpers] = usePaging(props.request, props.paramsFn);
onMounted(refresh);
return { ...helpers, paging, loadMore, refresh };
}
});
</script>
<style lang="scss" scoped>
.list-footer {
display: flex;
justify-content: center;
}
</style>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment