Browse Source

Merge branch 'dev' of http://git.ycjcjy.com/shigongli/miniapp-v2 into dev

吃个甘蔗嚼一年 3 years ago
parent
commit
395de8bb01

+ 37
- 0
src/app.less View File

@@ -0,0 +1,37 @@
1
+.page-index {
2
+  display: flex;
3
+  flex-direction: column;
4
+  width: 100vw;
5
+  height: 100vh;
6
+  overflow: hidden;
7
+  box-sizing: border-box;
8
+
9
+  .index-navbar {
10
+    flex: none;
11
+  }
12
+
13
+  .index-tabber {
14
+    flex: none;
15
+  }
16
+
17
+  .index-container {
18
+    flex: auto;
19
+    overflow: hidden;
20
+    position: relative;
21
+  }
22
+}
23
+
24
+.custom-tabbar {
25
+  background: #ffffff;
26
+  box-shadow: 0px -4px 6px 0px rgba(0, 0, 0, 0.08);
27
+
28
+  .weui-tabbar__label {
29
+    color: #c0c8d3;
30
+  }
31
+
32
+  .weui-bar__item_on {
33
+    .weui-tabbar__label {
34
+      color: #202020;
35
+    }
36
+  }
37
+}

BIN
src/assets/icons/housemantj/dp.jpg View File


BIN
src/assets/icons/housemantj/fd.jpg View File


BIN
src/assets/icons/housemantj/gl.jpg View File


BIN
src/assets/icons/housemantj/mj.jpg View File


BIN
src/assets/icons/housemantj/mj2.jpg View File


BIN
src/assets/icons/housemantj/mj3.jpg View File


+ 81
- 0
src/components/List/index.jsx View File

@@ -0,0 +1,81 @@
1
+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+import { ScrollView } from '@tarojs/components';
3
+import Taro from '@tarojs/taro';
4
+
5
+export default (props) => {
6
+  const {
7
+    render,
8
+    request,
9
+    params,
10
+    pageSize = 10,
11
+    onError,
12
+    onDataChange,
13
+    ...leftProps
14
+  } = props
15
+
16
+  const loadingRef = useRef(false)
17
+  const [payload, setPayload] = useState({})
18
+  const [list, setList] = useState([])
19
+  const pageRef = useRef({ current: 1, pages: 0 })
20
+
21
+  // 滚动
22
+  const handleScrollToLower = (e) => {
23
+    const loading = loadingRef.current
24
+    const hasMore = pageRef.current.current < pageRef.current.pages
25
+
26
+    if (!loading && hasMore) {
27
+      setPayload({
28
+        ...payload,
29
+        pageNum: pageRef.current.current + 1
30
+      })
31
+    }
32
+  }
33
+
34
+  // 联动状态, 设置查询参数
35
+  useEffect(() => {
36
+    setPayload({
37
+      ...params,
38
+      pageNum: 1,
39
+      pageSize,
40
+    })
41
+  }, [pageSize, params])
42
+
43
+  // 请求数据
44
+  useEffect(() => {
45
+    Taro.showLoading()
46
+    loadingRef.current = true
47
+    request(payload).then((res) => {
48
+      const { records, ...pageInfo } = res || {}
49
+
50
+      const lst = pageInfo.current === 1 ? records || [] : list.concat(records || [])
51
+      setList(lst)
52
+      if (onDataChange) {
53
+        onDataChange(lst)
54
+      }
55
+
56
+      pageRef.current = pageInfo
57
+      loadingRef.current = false
58
+      Taro.hideLoading()
59
+    }).catch((err) => {
60
+      loadingRef.current = false
61
+      console.error(err)
62
+      Taro.hideLoading()
63
+      if (onError) {
64
+        onError(err)
65
+      }
66
+    })
67
+  }, [payload])
68
+
69
+  return (
70
+    <ScrollView
71
+      scrollY
72
+      onScrollToLower={handleScrollToLower}
73
+      {...leftProps}
74
+    >
75
+      { !render
76
+          ? props.children
77
+          : list.map((item, index) => render({ item, index }))
78
+      }
79
+    </ScrollView>
80
+  )
81
+}

+ 1
- 0
src/pages/details/mjDetails/sceneryDetails.jsx View File

@@ -16,6 +16,7 @@ import useSave from "@/utils/hooks/useSave"
16 16
 import useLike from "@/utils/hooks/useLike"
17 17
 import Cards from '@/components/foodCards/foodCards.jsx'
18 18
 import Taro,{ useShareAppMessage } from '@tarojs/taro'
19
+import { getResourceList } from '@/services/home'
19 20
 import Extend from '../components/Extend/extend'
20 21
 import './sceneryDetails.less'
21 22
 

+ 4
- 4
src/pages/index/components/Card.js View File

@@ -10,20 +10,20 @@ import love from '@/assets/icons/housemantj/爱心.png'
10 10
 
11 11
 export default (props) => {
12 12
 
13
-  const { item } = props
13
+  const { item, style } = props
14 14
 
15 15
   const [isSaved, toggleSave] = useSave(item.isSaved, item.targetType, item.targetId)
16 16
   const Detail = () => {
17 17
     if (item.targetType == 'tourist') {
18
-      let location = item.lng + ',' + item.lat
19
-      Taro.navigateTo({ url: `/pages/details/mjDetails/sceneryDetails?id=${item.targetId}&distance=${(item.distance / 1000).toFixed(2)}&location=${location}` });
18
+      let loc = item.lng + ',' + item.lat
19
+      Taro.navigateTo({ url: `/pages/details/mjDetails/sceneryDetails?id=${item.targetId}&distance=${(item.distance / 1000).toFixed(2)}&location=${loc}` });
20 20
     }
21 21
     else {
22 22
       Taro.navigateTo({ url: `/pages/details/foodDetails/foodDetails?id=${item.targetId}` })
23 23
     }
24 24
   }
25 25
   return (
26
-    <view className='contentCard'>
26
+    <view className='contentCard' style={style}>
27 27
       <view className='cardTop'>
28 28
         <image mode='widthFix' onClick={Detail} src={item.poster} className='cCardimg' />
29 29
         <image className='lefttips' src={item.targetType === 'tourist' ? mjTip : msTip} />

+ 0
- 37
src/pages/index/index.less View File

@@ -1,37 +0,0 @@
1
-.page-index {
2
-  display: flex;
3
-  flex-direction: column;
4
-  width: 100vw;
5
-  height: 100vh;
6
-  overflow: hidden;
7
-  box-sizing: border-box;
8
-
9
-  .index-navbar {
10
-    flex: none;
11
-  }
12
-
13
-  .index-tabber {
14
-    flex: none;
15
-  }
16
-
17
-  .index-container {
18
-    flex: auto;
19
-    overflow: hidden;
20
-    position: relative;
21
-  }
22
-}
23
-
24
-.custom-tabbar {
25
-  background: #ffffff;
26
-  box-shadow: 0px -4px 6px 0px rgba(0, 0, 0, 0.08);
27
-
28
-  .weui-tabbar__label {
29
-    color: #c0c8d3;
30
-  }
31
-
32
-  .weui-bar__item_on {
33
-    .weui-tabbar__label {
34
-      color: #202020;
35
-    }
36
-  }
37
-}

+ 10
- 13
src/pages/index/tabs/Recommend.jsx View File

@@ -3,6 +3,7 @@ import { React, useState, useEffect } from 'react'
3 3
 import iconsearch from '@/assets/icons/housemantj/search.png'
4 4
 import locationimg from '@/assets/icons/housemantj/location.png'
5 5
 import Tip from '@/components/tip'
6
+import List from '@/components/List';
6 7
 import { getIndexType,  getResourceList } from '@/services/home'
7 8
 import Card from '../components/Card'
8 9
 import './less/Recommend.less'
@@ -34,26 +35,19 @@ export default (props) => {
34 35
     }
35 36
   }
36 37
 
37
-  useEffect(() => {    
38
+  useEffect(() => {
38 39
     //查询分类标签表
39 40
     getIndexType({ pageSize: 20 }).then((res) => {
40 41
       setTypeList(res.records || [])
41 42
     })    
42 43
   }, [])
43
-
44
-  useEffect(() => {
45
-      getResourceList(queryParams).then((res) => {
46
-        setAllList(res.records || [])
47
-      })
48
-    }, [queryParams])
49
-
50 44
   const onSearch = () => {
51 45
     // 用绝对路径
52 46
     Taro.navigateTo({ url: '/pages/search/search' });
53 47
   }
54 48
 
55 49
   return (
56
-    <view style={{ height: '100%', overflow: 'auto' }}>
50
+    <view style={{ height: '100%', overflow: 'hidden' }}>
57 51
       <view className='search' onClick={onSearch}>
58 52
         <input className='searchInput' disabled />
59 53
         <image className='searchicon' src={iconsearch} />
@@ -79,16 +73,19 @@ export default (props) => {
79 73
           </mp-tabs>
80 74
         </scroll-view>
81 75
       </view>
82
-      <scroll-view scroll-y='true' scroll-view='true'  	bindscrolltolower='lower' bindscrolltoupper='upper'	 bindscroll='scroll'
83
-      
76
+
77
+      <List
78
+        style={{ height: 'calc(100% - 160px)' }}
79
+        request={getResourceList}
80
+        params={queryParams}
81
+        onDataChange={setAllList}
84 82
       >
85 83
         <view className='waterfall'>
86 84
           {
87 85
             alllist.map((item) => <Card key={item.resourceNo} item={item} />)
88 86
           }
89 87
         </view>
90
-        <view className='botton'>已经到底了~</view>
91
-      </scroll-view>
88
+      </List>
92 89
     </view>
93 90
   )
94 91
 }

+ 0
- 15
src/pages/search/search.jsx View File

@@ -37,21 +37,6 @@ export default withLayout((props) => {
37 37
                     {
38 38
                         hotList?.map((item) => <view onClick={()=>hotSearch(item.word)}>{item.word}</view>)
39 39
                     }
40
-                    {/* <view onClick={goLook}>小龙虾</view>
41
-                    <view>小笼包</view>
42
-                    <view>小笼包</view>
43
-                    <view>小笼包</view>
44
-                    <view>小笼包</view>
45
-                    <view>小笼包</view>
46
-                    <view>小笼包</view>
47
-                    <view>小笼包</view>
48
-                    <view>小笼包</view>
49
-                    <view>小笼包</view>
50
-                    <view>小笼包</view>
51
-                    <view>小笼包</view>
52
-                    <view>小笼包</view>
53
-                    <view>小笼包</view>
54
-                    <view>小笼包</view> */}
55 40
                 </view>
56 41
             </view>
57 42
 

+ 9
- 13
src/pages/searchResult/searchResult.jsx View File

@@ -1,17 +1,10 @@
1 1
 import { React, useState, useEffect, } from 'react'
2 2
 // .就是当前路径
3 3
 import iconsearch from '../../assets/icons/housemantj/search.png'
4
-import msImage from '../../assets/icons/housemantj/ms.jpg'
5
-import mjImage from '../../assets/icons/housemantj/mj.jpg'
6
-import glImage from '../../assets/icons/housemantj/gl.jpg'
7
-import msTip from '../../assets/icons/housemantj/foodtip.png'
8
-import mjTip from '../../assets/icons/housemantj/mjtip.png'
9
-import glTip from '../../assets/icons/housemantj/gltip.png'
10
-import onlove from '../../assets/icons/housemantj/onlove.png'
11 4
 import CustomNav from '@/components/CustomNav'
12 5
 import Taro from '@tarojs/taro'
13 6
 import Card from '../index/components/Card'
14
-
7
+import {getResourceList } from '@/services/home'
15 8
 import './searchResult.less'
16 9
 import withLayout from '@/layouts'
17 10
 
@@ -21,7 +14,6 @@ export default withLayout((props) => {
21 14
   const { router, person,location } = props
22 15
   const { q} = props.router.params
23 16
 
24
-console.log(location,q)
25 17
   // 横向tab
26 18
   const [activeTab, setActiveTab] = useState(0)
27 19
   const [queryParams, setQueryParams] = useState({q:q, location: location, pageNum: 1, pageSize: 10, typeId: '' })
@@ -45,8 +37,12 @@ console.log(location,q)
45 37
     if (index == 0) {
46 38
       setQueryParams({q:q, location: location, pageNum: 1, pageSize: 10, typeId: '' })
47 39
     }
48
-    // else if(index==1){}
49
-    // else{}
40
+    else if(index==1){
41
+      setQueryParams({q:q,targetType:'shop', location: location, pageNum: 1, pageSize: 10, typeId: '' })      
42
+    }
43
+    else{
44
+      setQueryParams({q:q,targetType:'tourist', location: location, pageNum: 1, pageSize: 10, typeId: '' })
45
+    }
50 46
   }
51 47
 
52 48
 
@@ -69,7 +65,7 @@ console.log(location,q)
69 65
       <view className='index-navbar'>
70 66
         <CustomNav title='搜索' />
71 67
       </view>
72
-      <view style={{ height: '100%', overflow: 'auto' }}>
68
+      <view className='index-container'>
73 69
         <view className='search'>
74 70
           <input className='searchInput' placeholder='请输入景区/城市搜索' disabled onClick={onSearch} />
75 71
           <image className='searchicon' src={iconsearch} />
@@ -87,7 +83,7 @@ console.log(location,q)
87 83
           </mp-tabs>
88 84
         </view>
89 85
 
90
-        <scroll-view scroll-y="true" scroll-view='true' bindscrolltoupper="upper" bindscrolltolower="lower" bindscroll="scroll" >
86
+        <scroll-view scroll-y="true" scroll-view='true' bindscrolltoupper="upper" bindscrolltolower="lower" bindscroll="scroll" style={{height:'100vh'}} >
91 87
           <view className="waterfall">
92 88
             {
93 89
               alllist?.map((item) => <Card key={item.resourceNo} item={item} />)

+ 1
- 0
src/pages/searchResult/searchResult.less View File

@@ -53,6 +53,7 @@
53 53
         height:37px;
54 54
         position: absolute;
55 55
         left: 0;
56
+        top: 0;
56 57
       }
57 58
       .loveharde{
58 59
         width: 22px;