diff --git a/src/hjm/BestSellers.tsx b/src/hjm/BestSellers.tsx
index e58b323..4647d3a 100644
--- a/src/hjm/BestSellers.tsx
+++ b/src/hjm/BestSellers.tsx
@@ -1,10 +1,15 @@
import {useEffect} from "react";
import {Image, Space} from '@nutui/nutui-react-taro'
import Taro from '@tarojs/taro'
+import {HjmCar} from "@/api/hjm/hjmCar/model";
-const BestSellers = (props: any) => {
+interface BestSellersProps {
+ data: HjmCar[];
+}
+
+const BestSellers = (props: BestSellersProps) => {
const reload = () => {
-
+ // 可以在这里添加重新加载逻辑
}
useEffect(() => {
@@ -16,7 +21,7 @@ const BestSellers = (props: any) => {
{props.data?.map((item, index) => {
return (
-
Taro.navigateTo({url: '/hjm/query?id=' + item.code})}>
{ item.image && (
{
)
})}
- {props.data.length === 0 && (
-
+ {(!props.data || props.data.length === 0) && (
+
)}
@@ -50,4 +55,4 @@ const BestSellers = (props: any) => {
)
}
-export default BestSellers
+export default BestSellers
\ No newline at end of file
diff --git a/src/hjm/list.tsx b/src/hjm/list.tsx
index 7541ef8..903daef 100644
--- a/src/hjm/list.tsx
+++ b/src/hjm/list.tsx
@@ -1,4 +1,4 @@
-import {useEffect, useState} from "react";
+import {useEffect, useState, CSSProperties} from "react";
import {Search} from '@nutui/icons-react-taro'
import {Button, Input, InfiniteLoading} from '@nutui/nutui-react-taro'
import {pageHjmCar} from "@/api/hjm/hjmCar";
@@ -8,6 +8,14 @@ import './location.scss'
import BestSellers from "./BestSellers";
import {getUserInfo} from "@/api/layout";
+const InfiniteUlStyle: CSSProperties = {
+ height: '80vh',
+ width: '100%',
+ padding: '0',
+ overflowY: 'auto',
+ overflowX: 'hidden',
+}
+
/**
* 文章终极列表
* @constructor
@@ -15,14 +23,20 @@ import {getUserInfo} from "@/api/layout";
const List = () => {
const [keywords, setKeywords] = useState
('')
const [list, setList] = useState([])
+ const [page, setPage] = useState(1)
+ const [hasMore, setHasMore] = useState(true)
+ const [loading, setLoading] = useState(false)
const onKeywords = (keywords: string) => {
setKeywords(keywords)
}
- const reload = async () => {
+ const loadList = async (pageNum: number, isRefresh = false) => {
+ if (loading) return;
+
+ setLoading(true)
// 搜索条件
- const where = {status: 1, deleted: 0, keywords}
+ const where = {status: 1, deleted: 0, keywords, page: pageNum, limit: 10}
// 读取用户信息
const user = await getUserInfo();
@@ -46,20 +60,53 @@ const List = () => {
where.installerId = user.userId;
}
if(roleCode == 'user'){
+ setLoading(false)
return false;
}
// 获取车辆列表
- pageHjmCar(where).then(res => {
- setList(res?.list || [])
- })
+ try {
+ const res = await pageHjmCar(where);
+ if (res?.list && res?.list.length > 0) {
+ if (isRefresh) {
+ setList(res.list);
+ } else {
+ setList(prevList => [...prevList, ...res.list]);
+ }
+ setHasMore(res.list.length >= 10); // 如果返回的数据少于10条,说明没有更多了
+ } else {
+ if (isRefresh) {
+ setList([]);
+ }
+ setHasMore(false);
+ }
+ } catch (error) {
+ console.error('获取车辆列表失败:', error);
+ if (isRefresh) {
+ setList([]);
+ }
+ setHasMore(false);
+ } finally {
+ setLoading(false);
+ }
+ }
+
+ const reload = async () => {
+ setPage(1);
+ await loadList(1, true);
+ }
+
+ const loadMore = async () => {
+ if (!hasMore || loading) return;
+ const nextPage = page + 1;
+ setPage(nextPage);
+ await loadList(nextPage);
}
useEffect(() => {
reload()
}, [])
-
return (
<>
@@ -90,12 +137,19 @@ const List = () => {
-