feat: 添加加载图标和分页逻辑,优化数据获取体验
This commit is contained in:
parent
a7a3a08ee3
commit
d4cbc2c562
|
|
@ -75,6 +75,15 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<u-loading-icon
|
||||||
|
v-if="!isBottom && loading"
|
||||||
|
mode="circle"
|
||||||
|
text="加载中..."
|
||||||
|
textSize="26rpx"
|
||||||
|
textColor="#999999"
|
||||||
|
color="rgba(23, 119, 255, 1)"
|
||||||
|
size="28rpx"
|
||||||
|
></u-loading-icon>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 登录弹窗 start -->
|
<!-- 登录弹窗 start -->
|
||||||
|
|
@ -91,8 +100,9 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getForeignList } from "@/api";
|
import { getForeignList } from "@/api";
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
import { computed, onMounted, ref } from "vue";
|
import { computed, onMounted, reactive, ref } from "vue";
|
||||||
import LoginDialog from "@/components/loginPopup/index.vue";
|
import LoginDialog from "@/components/loginPopup/index.vue";
|
||||||
|
import { onReachBottom } from "@dcloudio/uni-app";
|
||||||
|
|
||||||
// 导航栏路由返回
|
// 导航栏路由返回
|
||||||
const handleBack = () => {
|
const handleBack = () => {
|
||||||
|
|
@ -143,23 +153,40 @@ function goDetail(item: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = ref([]);
|
const data = ref([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
const keyword = ref("");
|
||||||
|
const isBottom = ref(false);
|
||||||
|
const pages = reactive({
|
||||||
|
page: 1,
|
||||||
|
size: 20,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
const result = await getForeignList({
|
const result = await getForeignList({
|
||||||
keyword: keyword.value,
|
keyword: keyword.value,
|
||||||
|
page: pages.page,
|
||||||
|
size: pages.size,
|
||||||
});
|
});
|
||||||
if (result.code === 200) {
|
if (result.code === 200) {
|
||||||
const { list, total } = result.data;
|
const { list, total } = result.data;
|
||||||
data.value = list;
|
data.value = [...data.value, ...list];
|
||||||
|
pages.total = Math.ceil(total / pages.size);
|
||||||
|
isBottom.value = pages.page >= pages.total;
|
||||||
} else {
|
} else {
|
||||||
data.value = [];
|
data.value = [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const keyword = ref("");
|
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
getList();
|
getList();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onReachBottom(() => {
|
||||||
|
if (isBottom.value) return;
|
||||||
|
pages.page++;
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!userStore.isLogin) {
|
if (!userStore.isLogin) {
|
||||||
handleShowLogin();
|
handleShowLogin();
|
||||||
|
|
|
||||||
|
|
@ -16,8 +16,7 @@
|
||||||
<!-- 标题 end -->
|
<!-- 标题 end -->
|
||||||
|
|
||||||
<view class="page-main">
|
<view class="page-main">
|
||||||
<u-loading-icon v-if="loading"></u-loading-icon>
|
<view class="news-list" v-if="data?.length > 0">
|
||||||
<view class="news-list" v-else-if="data?.length > 0">
|
|
||||||
<template v-for="(item, index) in data" :key="index">
|
<template v-for="(item, index) in data" :key="index">
|
||||||
<view
|
<view
|
||||||
:class="['news-item', { mask: !userStore.isLogin }]"
|
:class="['news-item', { mask: !userStore.isLogin }]"
|
||||||
|
|
@ -42,6 +41,15 @@
|
||||||
</template>
|
</template>
|
||||||
</view>
|
</view>
|
||||||
<u-empty v-else />
|
<u-empty v-else />
|
||||||
|
<u-loading-icon
|
||||||
|
v-if="!isBottom && loading"
|
||||||
|
mode="circle"
|
||||||
|
text="加载中..."
|
||||||
|
textSize="26rpx"
|
||||||
|
textColor="#999999"
|
||||||
|
color="rgba(23, 119, 255, 1)"
|
||||||
|
size="28rpx"
|
||||||
|
></u-loading-icon>
|
||||||
</view>
|
</view>
|
||||||
<!-- 登录弹窗 start -->
|
<!-- 登录弹窗 start -->
|
||||||
<LoginDialog
|
<LoginDialog
|
||||||
|
|
@ -57,8 +65,9 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getMacroList } from "@/api";
|
import { getMacroList } from "@/api";
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
import { computed, onMounted, ref } from "vue";
|
import { computed, onMounted, reactive, ref } from "vue";
|
||||||
import LoginDialog from "@/components/loginPopup/index.vue";
|
import LoginDialog from "@/components/loginPopup/index.vue";
|
||||||
|
import { onReachBottom } from "@dcloudio/uni-app";
|
||||||
// 导航栏路由返回
|
// 导航栏路由返回
|
||||||
const handleBack = () => {
|
const handleBack = () => {
|
||||||
uni.navigateBack({
|
uni.navigateBack({
|
||||||
|
|
@ -109,18 +118,37 @@ function goDetail(item: any) {
|
||||||
|
|
||||||
const data = ref([]);
|
const data = ref([]);
|
||||||
const loading = ref(false);
|
const loading = ref(false);
|
||||||
|
const keyword = ref("");
|
||||||
|
const isBottom = ref(false);
|
||||||
|
const pages = reactive({
|
||||||
|
page: 1,
|
||||||
|
size: 20,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
loading.value = true;
|
loading.value = true;
|
||||||
const result = await getMacroList({});
|
const result = await getMacroList({
|
||||||
|
keyword: keyword.value,
|
||||||
|
page: pages.page,
|
||||||
|
size: pages.size,
|
||||||
|
});
|
||||||
loading.value = false;
|
loading.value = false;
|
||||||
if (result.code === 200) {
|
if (result.code === 200) {
|
||||||
const { list, total } = result.data;
|
const { list, total } = result.data;
|
||||||
data.value = list;
|
data.value = [...data.value, ...list];
|
||||||
|
pages.total = Math.ceil(total / pages.size);
|
||||||
|
isBottom.value = pages.page >= pages.total;
|
||||||
} else {
|
} else {
|
||||||
data.value = [];
|
data.value = [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onReachBottom(() => {
|
||||||
|
if (isBottom.value) return;
|
||||||
|
pages.page++;
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!userStore.isLogin) {
|
if (!userStore.isLogin) {
|
||||||
handleShowLogin();
|
handleShowLogin();
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!-- 时间轴 start -->
|
<!-- 时间轴 start -->
|
||||||
|
|
||||||
<view class="page-timeline">
|
<view class="page-timeline">
|
||||||
<view
|
<view
|
||||||
:class="['timeline', { mask: !userStore.isLogin }]"
|
:class="['timeline', { mask: !userStore.isLogin }]"
|
||||||
|
|
@ -110,6 +111,15 @@
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
<u-loading-icon
|
||||||
|
v-if="!isBottom && loading"
|
||||||
|
mode="circle"
|
||||||
|
text="加载中..."
|
||||||
|
textSize="26rpx"
|
||||||
|
textColor="#999999"
|
||||||
|
color="rgba(23, 119, 255, 1)"
|
||||||
|
size="28rpx"
|
||||||
|
></u-loading-icon>
|
||||||
</view>
|
</view>
|
||||||
<!-- 时间轴 end -->
|
<!-- 时间轴 end -->
|
||||||
</view>
|
</view>
|
||||||
|
|
@ -128,8 +138,9 @@
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { getRecommendList } from "@/api";
|
import { getRecommendList } from "@/api";
|
||||||
import { useUserStore } from "@/stores/user";
|
import { useUserStore } from "@/stores/user";
|
||||||
import { computed, onMounted, ref } from "vue";
|
import { computed, onMounted, reactive, ref } from "vue";
|
||||||
import LoginDialog from "@/components/loginPopup/index.vue";
|
import LoginDialog from "@/components/loginPopup/index.vue";
|
||||||
|
import { onReachBottom } from "@dcloudio/uni-app";
|
||||||
// 导航栏路由返回
|
// 导航栏路由返回
|
||||||
const handleBack = () => {
|
const handleBack = () => {
|
||||||
uni.navigateBack({
|
uni.navigateBack({
|
||||||
|
|
@ -192,29 +203,46 @@ function goDetail(item: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const data = ref([]);
|
const data = ref([]);
|
||||||
|
const loading = ref(false);
|
||||||
|
const keyword = ref("");
|
||||||
|
const isBottom = ref(false);
|
||||||
|
const pages = reactive({
|
||||||
|
page: 1,
|
||||||
|
size: 20,
|
||||||
|
total: 0,
|
||||||
|
});
|
||||||
const getList = async () => {
|
const getList = async () => {
|
||||||
|
loading.value = true;
|
||||||
const result = await getRecommendList({
|
const result = await getRecommendList({
|
||||||
keyword: keyword.value,
|
keyword: keyword.value,
|
||||||
|
page: pages.page,
|
||||||
|
size: pages.size,
|
||||||
});
|
});
|
||||||
|
loading.value = false;
|
||||||
if (result.code === 200) {
|
if (result.code === 200) {
|
||||||
const { list, total } = result.data;
|
const { list, total } = result.data;
|
||||||
data.value = list;
|
data.value = [...data.value, ...list];
|
||||||
list.forEach((o) => {
|
list.forEach((o) => {
|
||||||
o.list.forEach((n) => {
|
o.list.forEach((n) => {
|
||||||
selectKeys.value.push(n.id)
|
selectKeys.value.push(n.id);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
pages.total = Math.ceil(total / pages.size);
|
||||||
|
isBottom.value = pages.page >= pages.total;
|
||||||
} else {
|
} else {
|
||||||
data.value = [];
|
data.value = [];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const keyword = ref("");
|
|
||||||
const handleSearch = () => {
|
const handleSearch = () => {
|
||||||
getList();
|
getList();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
onReachBottom(() => {
|
||||||
|
if (isBottom.value) return;
|
||||||
|
pages.page++;
|
||||||
|
getList();
|
||||||
|
});
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
if (!userStore.isLogin) {
|
if (!userStore.isLogin) {
|
||||||
handleShowLogin();
|
handleShowLogin();
|
||||||
|
|
@ -327,6 +355,7 @@ onMounted(async () => {
|
||||||
.page-timeline {
|
.page-timeline {
|
||||||
position: relative;
|
position: relative;
|
||||||
z-index: 3;
|
z-index: 3;
|
||||||
|
padding-bottom: 20rpx;
|
||||||
|
|
||||||
.mask {
|
.mask {
|
||||||
filter: blur(5px);
|
filter: blur(5px);
|
||||||
|
|
@ -364,6 +393,7 @@ onMounted(async () => {
|
||||||
}
|
}
|
||||||
|
|
||||||
.content {
|
.content {
|
||||||
|
flex: 1;
|
||||||
padding: 0 0 30rpx 15rpx;
|
padding: 0 0 30rpx 15rpx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue