李志伟 vor 3 Jahren
Ursprung
Commit
a2cc04dc41

+ 2
- 1
config/dev.js Datei anzeigen

@@ -3,7 +3,8 @@ module.exports = {
3 3
     NODE_ENV: '"development"',
4 4
   },
5 5
   defineConstants: {
6
-    HOST: '"https://machine.njyunzhi.com"',
6
+    HOST: '"http://192.168.89.147:7080"',
7
+    // HOST: '"https://machine.njyunzhi.com"',
7 8
     // OSS: '"yz-shigongli.oss-accelerate.aliyuncs.com"',
8 9
     // VERSION: '"3.0.3_2021-12-23"',
9 10
   },

+ 1
- 2
src/pages/index/index.jsx Datei anzeigen

@@ -1,9 +1,8 @@
1 1
 import Taro from "@tarojs/taro";
2
-import { useEffect, useState } from "react";
2
+import { useEffect } from "react";
3 3
 import { View, Image } from "@tarojs/components"
4 4
 import withLayout from '@/layouts'
5 5
 import CustomNav from "@/components/CustomNav";
6
-import LoginModel from "@/components/LoginModel";
7 6
 import indexImg from "@/assets/comm/index.png";
8 7
 import indexActive from "@/assets/comm/indexActive.png";
9 8
 import job from "@/assets/comm/job.png";

+ 4
- 0
src/pages/machineryList/Card/style.less Datei anzeigen

@@ -17,6 +17,10 @@
17 17
     .machineryName{
18 18
       font-size: 36px;
19 19
       color: #222222;
20
+      width: 65vw;
21
+      text-overflow: ellipsis;
22
+      white-space: nowrap;
23
+      overflow: hidden;
20 24
     }
21 25
     .goMap{
22 26
       position: absolute;

+ 38
- 10
src/pages/machineryList/index.jsx Datei anzeigen

@@ -1,40 +1,68 @@
1 1
 import { useEffect, useState } from "react"
2
-import Taro from "@tarojs/taro"
2
+import Taro, {useDidShow}from "@tarojs/taro"
3 3
 import { View, ScrollView } from "@tarojs/components"
4 4
 import CustomNav from "@/components/CustomNav"
5 5
 import NullCard from "@/components/NullCard";
6
+import Footer from "@/components/Footer";
6 7
 import withLayout from '@/layouts'
7
-import { getMachineryList } from '@/services/machinery'
8 8
 import { useModel } from "@/store"
9
+import { getMachineryList } from '@/services/machinery'
9 10
 import MachineryCard from './Card'
10 11
 import './style.less'
11 12
 
12 13
 export default withLayout((props) => {
13 14
   const { location } = useModel('location')
14 15
   const [machinery, setMachinery] = useState([])
16
+  const [currentPage, setCurrentPage] = useState(1)
17
+  const [isMore, setIsMore] = useState(false)
18
+
15 19
   const goDetail = (val) => {
16 20
     Taro.navigateTo({ url: `/pages/machineryDetail/index?id=${val}` });
17 21
   }
18 22
   const goMap = (val) => {
19 23
     Taro.navigateTo({ url: `/pages/machineryMap/index?id=${val}` });
20 24
   }
21
-  useEffect(() => {
22
-    getMachineryList({ location: location }).then((res) => {
23
-      setMachinery(res.records)
25
+   // 上拉加载
26
+   const handleScrollToLower = () => {
27
+    setCurrentPage(currentPage + 1)
28
+  }
29
+  const getList = () => {
30
+    getMachineryList({ location: location,pageNum: currentPage }).then(res => {
31
+      const lst = currentPage === 1 ? res.records || [] : machinery.concat(res.records || [])
32
+      //长列表加载当下一页没有数据时
33
+      if (res.records.length == 0 && currentPage != 1) {
34
+        setIsMore(true)
35
+        return
36
+      }
37
+      setMachinery(lst)
24 38
     })
25
-  }, [location])
39
+  }
40
+  useDidShow(() => {
41
+    getList();
42
+  })
43
+  useEffect(() => {
44
+    getList();
45
+  }, [currentPage,location])
46
+  
26 47
   return (
27 48
     <View className='page-index'>
28 49
       <View className='index-navbar'>
29 50
         <CustomNav title='农机列表' />
30 51
       </View>
31 52
       <View className='index-container machineryListContent'>
32
-        <ScrollView scrollY style={{ height: '100%' }}>
53
+        <ScrollView scrollY
54
+          enhanced
55
+          onScrollToLower={isMore ? '' : handleScrollToLower}
56
+          style={{ height: '100%' }}
57
+        >
33 58
           {
34 59
             machinery.length === 0 ? <NullCard value='您还没有农机!' /> :
35
-            machinery?.map((item) => {
36
-              return <MachineryCard value={item} key={item.machineryId} onClick={() => goDetail(item.machineryId)} goMap={() => goMap(item.machineryId)} />
37
-            })
60
+              machinery?.map((item) => {
61
+                return <MachineryCard value={item} key={item.machineryId} onClick={() => goDetail(item.machineryId)} goMap={() => goMap(item.machineryId)} />
62
+              })
63
+          }
64
+          {
65
+            machinery.length === 0 || isMore && <Footer />
38 66
           }
39 67
         </ScrollView>
40 68
       </View>