Browse Source

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

李志伟 3 years ago
parent
commit
f7e781e993

+ 10
- 15
src/components/List/index.jsx View File

@@ -99,16 +99,14 @@ export default React.forwardRef((props, ref) => {
99 99
   }))
100 100
 
101 101
   return (
102
-
103
-    <ScrollView
104
-      scrollY
105
-      enhanced
106
-      onScrollToLower={handleScrollToLower}
107
-      {...leftProps}
108
-      className={`${className} list-view`}
109
-    >
110
-      <SpinBox loading={loading} className='index-container' >
111
-
102
+    <SpinBox loading={loading}>
103
+      <ScrollView
104
+        scrollY
105
+        enhanced
106
+        onScrollToLower={handleScrollToLower}
107
+        {...leftProps}
108
+        className={`${className} list-view`}
109
+      >
112 110
         {!render
113 111
           ? props.children
114 112
           : list.map((item, index) => render({ item, index }))
@@ -116,12 +114,9 @@ export default React.forwardRef((props, ref) => {
116 114
         {!list || !list.length && noData}
117 115
 
118 116
         {list && list.length > 0 && !hasMore &&
119
-
120 117
           <view className='botton'>这是我的底线</view>
121
-
122 118
         }
123
-      </SpinBox>
124
-
125
-    </ScrollView>
119
+      </ScrollView>
120
+    </SpinBox>
126 121
   )
127 122
 })

+ 43
- 0
src/components/MasonryLayout/Item.jsx View File

@@ -0,0 +1,43 @@
1
+
2
+import React, { useMemo, useEffect } from 'react'
3
+import { View } from '@tarojs/components'
4
+import { classNames, getRect } from './utils';
5
+import './style.less'
6
+
7
+export default (props) => {
8
+  const { className, item, render, onRenderFinish } = props
9
+
10
+  const vid = item.__vid;
11
+  
12
+  useEffect(() => {
13
+    const calcHeight = () => {
14
+      getRect(`.${vid}`).then((res) => {
15
+        if (!res) {
16
+          // 找不到 node , 则一直重复查询
17
+          const t = setTimeout(() => {
18
+            clearTimeout(t)
19
+            calcHeight()
20
+          }, 300)
21
+        } else {
22
+          if (Array.isArray(res)) {
23
+            onRenderFinish(res[0])
24
+          } else {
25
+            onRenderFinish(res)
26
+          }
27
+        }
28
+      })
29
+    }
30
+
31
+    calcHeight()
32
+  })
33
+
34
+
35
+  return (
36
+    <View
37
+      key={vid}
38
+      className={classNames(className, 'masonry-item', vid)}
39
+    >
40
+      {render(item)}
41
+    </View>
42
+  )
43
+}

+ 24
- 53
src/components/MasonryLayout/index.jsx View File

@@ -1,6 +1,7 @@
1 1
 import React, { useEffect, useMemo, useRef, useState } from 'react';
2 2
 import Taro from '@tarojs/taro';
3 3
 import { View } from '@tarojs/components';
4
+import Item from './Item';
4 5
 import { useList } from './hooks';
5 6
 import { classNames, getRect } from './utils';
6 7
 
@@ -15,88 +16,58 @@ export default (props) => {
15 16
   const rightBottom = useRef(0)
16 17
   const [leftList, leftRef, setLeftList] = useList()
17 18
   const [rightList, rightRef, setRightList] = useList()
18
-  const vidRef = useRef()
19
-  const [cursor, setCursor] = useState(-1)
19
+  const [cursor, setCursor] = useState(0)
20 20
 
21 21
   const listRef = useRef([])
22 22
   listRef.current = list
23
-    
24
-  useEffect(() => {
25
-    if (list && list.length) {
26
-      setCursor(0)
23
+
24
+  const handleRenderFinish = (direct) => (rect) => {
25
+    const { bottom } = rect
26
+
27
+    if (direct === 'left') {
28
+      leftBottom.current = bottom
27 29
     } else {
28
-      setCursor(-1)
29
-      setLeftList([])
30
-      setRightList([])
30
+      rightBottom.current = bottom
31 31
     }
32
-  }, [list])
33 32
 
33
+    setCursor(cursor + 1)
34
+  }
35
+    
34 36
   useEffect(() => {
35
-    const len = !listRef.current ? 0 : listRef.current.length;
37
+    setCursor(0)
38
+    setLeftList([])
39
+    setRightList([])
40
+    listRef.current = list ? list.slice() : []
41
+  }, [list])
36 42
 
43
+  useEffect(() => {
44
+    const len = !list ? 0 : list.length;
37 45
     if (leftRef.current.length + rightRef.current.length >= len) return;
38 46
 
39
-    const item = listRef.current[cursor] || {}
47
+    const item = listRef.current.shift()
40 48
     item.__vid = `f-${Math.random().toString(36).substring(2)}`
41
-    vidRef.current = item.__vid
42 49
 
43 50
     if (leftBottom.current <= rightBottom.current) {
44 51
       setLeftList([...leftRef.current, item])
45 52
     } else {
46 53
       setRightList([...rightRef.current, item])
47 54
     }
48
-  }, [cursor])
49
-
50
-  useEffect(() => {
51
-    const setHeight = (rect) => {
52
-      const { bottom } = rect
53
-      if (cursor % 2 === 0) {
54
-        leftBottom.current = bottom
55
-      } else {
56
-        rightBottom.current = bottom
57
-      }
58
-      setCursor(cursor + 1)
59
-    }
60
-
61
-    const calcHeight = () => {
62
-      getRect(`.${vidRef.current}`).then((res) => {
63
-        if (!res) {
64
-          // 找不到 node , 则一直重复查询
65
-          const t = setTimeout(() => {
66
-            clearTimeout(t)
67
-            calcHeight()
68
-          }, 300)
69
-        } else {
70
-          if (Array.isArray(res)) {
71
-            setHeight(res[0])
72
-          } else {
73
-            setHeight(res)
74
-          }
75
-        }
76
-      })
77
-    }
78
-
79
-    calcHeight()
80
-  })
55
+  }, [cursor, list])
81 56
 
82 57
   return (
83 58
     <View
84
-      className={classNames(className, 'masonry-layout')}
85 59
       style={style}
60
+      className={classNames(className, 'masonry-layout')}
86 61
     >
87 62
       <View className='masonry-column'>
88 63
         {
89
-          leftList.map((item) => (
90
-            <View key={item.__vid} className={classNames(itemClassName, 'masonry-item', item.__vid)}>{render(item)}</View>
91
-          ))
64
+          leftList.map(item => <Item key={item.__vid} className={itemClassName} item={item} render={render} onRenderFinish={handleRenderFinish('left')} />)
92 65
         }
93 66
       </View>
94 67
       <View className='masonry-split' style={splitStyle} />
95 68
       <View className='masonry-column'>
96 69
         {
97
-          rightList.map((item) => (
98
-            <View key={item.__vid} className={classNames(itemClassName, 'masonry-item', item.__vid)}>{render(item)}</View>
99
-          ))
70
+          rightList.map(item => <Item key={item.__vid} className={itemClassName} item={item} render={render} onRenderFinish={handleRenderFinish('right')} />)
100 71
         }
101 72
       </View>
102 73
     </View>

+ 1
- 1
src/components/toggleRole/ToggleRole.jsx View File

@@ -31,7 +31,7 @@ export default (props) => {
31 31
   return (
32 32
 
33 33
     <Popup show={showCutover} maskClosable={maskClosable} onClose={onClose}>
34
-      <SpinBox loading={loading} className='index-container' >
34
+      <SpinBox loading={loading}>
35 35
         <view className='User-box-sths' >
36 36
           <view className='User-box-selectUser'>请选择身份:</view>
37 37
           <view className='User-box-tourist' onClick={goToPerson}>

+ 0
- 2
src/hotel/pages/landlord/roomOrder/roomOrder.jsx View File

@@ -9,8 +9,6 @@ import { getRoomOrderList,getHotelDetail } from '@/services/landlord'
9 9
 import './roomOrder.less'
10 10
 
11 11
 
12
-
13
-
14 12
 export default withLayout((props) => {
15 13
   const { hotelId, roomId, roomName } = props.router.params
16 14
   const [detail, setDetail] = useState([])

+ 1
- 1
src/pages/MineUserAll/RefundMoney/CheckRefund/index.jsx View File

@@ -124,7 +124,7 @@ export default withLayout((props) => {
124 124
       <View className='index-container'>
125 125
         <View className='box-content'>
126 126
           <scroll-view scroll-y style='height: 100%;' >
127
-            <SpinBox loading={loading} className='index-container' >
127
+            <SpinBox loading={loading}>
128 128
 
129 129
               <view className='Refund-Content-box'>
130 130
                 <view className='title-image'>

+ 1
- 1
src/pages/MineUserAll/RefundMoney/index.jsx View File

@@ -66,7 +66,7 @@ export default withLayout((props) => {
66 66
       <view className='index-navbar'>
67 67
         <CustomNav title='售后退款' />
68 68
       </view>
69
-      <SpinBox loading={loading} className='index-container' >
69
+      <SpinBox loading={loading}>
70 70
         <scroll-view
71 71
           scrollY
72 72
           style='height: calc(100vh - 176rpx);'

+ 28
- 32
src/pages/index/tabs/Guide.jsx View File

@@ -33,12 +33,6 @@ export default (props) => {
33 33
 
34 34
   const trackClick = useTrackClick(router)
35 35
 
36
-  // 住宿经纬度
37
-  const Roomlog = useRef('')
38
-  const Roomlat = useRef('')
39
-  // 停车场经纬度
40
-  const Parklog = useRef('')
41
-  const Parklat = useRef('')
42 36
   const [taRoomContent, setTaRoomContent] = useState([])
43 37
   const RoomLocation = taRoomContent?.location
44 38
   //没有停车 wifi的就不显示按钮
@@ -69,8 +63,8 @@ export default (props) => {
69 63
 
70 64
   useDidShow(() => {
71 65
     goContent()
72
-
73 66
   })
67
+  
74 68
   const geiZy = () => {
75 69
     setLoading(true)
76 70
     getExtendContent('room', roomId, {
@@ -90,10 +84,10 @@ export default (props) => {
90 84
       setLoading(true)
91 85
       // 点击’去这里‘跳转导航
92 86
       getTaRoom(roomId).then((res) => {
93
-        Roomlog.current = (!res.location).toString().split(',')[0]
94
-        Roomlat.current = (!res.location).toString().split(',')[1]
95
-        Parklog.current = (!res.parkingLocation).toString().split(',')[0]
96
-        Parklat.current = (!res.parkingLocation).toString().split(',')[1]
87
+        // Roomlog.current = (!res.location).toString().split(',')[0]
88
+        // Roomlat.current = (!res.location).toString().split(',')[1]
89
+        // Parklog.current = (!res.parkingLocation).toString().split(',')[0]
90
+        // Parklat.current = (!res.parkingLocation).toString().split(',')[1]
97 91
         setTaRoomContent(res || [])
98 92
         setLoading(false)
99 93
       })
@@ -127,28 +121,33 @@ export default (props) => {
127 121
 
128 122
 
129 123
   const goRoomMap = () => {
130
-    Taro.openLocation({
131
-      longitude: Roomlog.current - 0,
132
-      latitude: Roomlat.current - 0,
133
-      name: taRoomContent.roomName,
134
-      address: taRoomContent.address,
135
-      scale: 12,
136
-    })
124
+    if (taRoomContent.location) {
125
+      const [longitude, latitude] = taRoomContent.location.split(',').map(x => x - 0)
126
+      
127
+      Taro.openLocation({
128
+        longitude,
129
+        latitude,
130
+        name: taRoomContent.roomName,
131
+        address: taRoomContent.address,
132
+        scale: 12,
133
+      })
134
+    }
137 135
   }
138 136
 
139 137
   const goParkMap = () => {
140
-    Taro.openLocation({
141
-      longitude: Parklog.current - 0,
142
-      latitude: Parklat.current - 0,
143
-      name: taRoomContent.parkingAddress,
144
-      address: taRoomContent.parkingAddress,
145
-      scale: 12,
146
-    })
138
+    if (taRoomContent.parkingLocation) {
139
+      const [longitude, latitude] = taRoomContent.parkingLocation.split(',').map(x => x - 0)
140
+
141
+      Taro.openLocation({
142
+        longitude,
143
+        latitude,
144
+        name: taRoomContent.parkingAddress,
145
+        address: taRoomContent.parkingAddress,
146
+        scale: 12,
147
+      })
148
+    }
147 149
   }
148 150
 
149
-
150
-
151
-
152 151
   const wifiCopy = () => {
153 152
     Taro.setClipboardData({
154 153
       data: taRoomContent?.wifiPassword,
@@ -162,12 +161,9 @@ export default (props) => {
162 161
     })
163 162
   }
164 163
 
165
-
166
-
167
-
168 164
   return (
169 165
     <scroll-view scrollY style='height:100%;'  >
170
-      <SpinBox loading={loading} className='index-container' >
166
+      <SpinBox loading={loading}>
171 167
 
172 168
         <view className='Guide-Home-box'>
173 169
           {

+ 1
- 2
src/pages/index/tabs/Recommend.jsx View File

@@ -6,7 +6,7 @@ import locationimg from '@/assets/icons/housemantj/location.png'
6 6
 import Tip from '@/components/tip'
7 7
 import List from '@/components/List';
8 8
 import NoData from '@/components/NoData'
9
-import SpinBox from '@/components/Spin/SpinBox';
9
+import MasonryLayout from '@/components/MasonryLayout';
10 10
 import { getIndexType, getResourceList } from '@/services/home'
11 11
 import Card from '../components/Card'
12 12
 import './less/Recommend.less'
@@ -109,7 +109,6 @@ export default (props) => {
109 109
           onDataChange={setAllList}
110 110
         >
111 111
           {/* <MasonryLayout
112
-            className='waterfall'
113 112
             list={alllist}
114 113
             render={item => <Card item={item} />}
115 114
           /> */}