张延森 3 years ago
parent
commit
241c0555d4
3 changed files with 26 additions and 25 deletions
  1. 4
    4
      src/components/List/index.jsx
  2. 14
    7
      src/components/Spin/SpinBox.jsx
  3. 8
    14
      src/components/Spin/style.less

+ 4
- 4
src/components/List/index.jsx View File

27
 
27
 
28
   // 滚动
28
   // 滚动
29
   const handleScrollToLower = (e) => {
29
   const handleScrollToLower = (e) => {
30
-    const loading = loadingRef.current
30
+    // const loading = loadingRef.current
31
 
31
 
32
     if (!loading && hasMore) {
32
     if (!loading && hasMore) {
33
       setPayload({
33
       setPayload({
41
     if (!request) return;
41
     if (!request) return;
42
 
42
 
43
     setLoading(true)
43
     setLoading(true)
44
-    loadingRef.current = true
44
+    // loadingRef.current = true
45
     request(params).then((res) => {
45
     request(params).then((res) => {
46
       const { records, ...pageInfo } = res || {}
46
       const { records, ...pageInfo } = res || {}
47
       const lst = pageInfo.current === 1 ? records || [] : list.concat(records || [])
47
       const lst = pageInfo.current === 1 ? records || [] : list.concat(records || [])
51
       }
51
       }
52
 
52
 
53
       pageRef.current = pageInfo
53
       pageRef.current = pageInfo
54
-      loadingRef.current = false
54
+      // loadingRef.current = false
55
 
55
 
56
       setLoading(false)
56
       setLoading(false)
57
 
57
 
58
     }).catch((err) => {
58
     }).catch((err) => {
59
-      loadingRef.current = false
59
+      // loadingRef.current = false
60
       console.error(err)
60
       console.error(err)
61
       setLoading(false)
61
       setLoading(false)
62
 
62
 

+ 14
- 7
src/components/Spin/SpinBox.jsx View File

4
 import Spin from '.'
4
 import Spin from '.'
5
 import './style.less'
5
 import './style.less'
6
 
6
 
7
+const Loading = (props) => {
8
+  const { loading, size = '64rpx', ...leftProps } = props
9
+
10
+  const cls = ['loading-box', loading? 'active' : undefined].filter(Boolean).join(' ')
11
+
12
+  return (
13
+    <View className={cls}>
14
+      <Spin size={size} {...leftProps} />
15
+    </View>
16
+  )
17
+}
18
+
19
+
7
 export default (props) => {
20
 export default (props) => {
8
   const { className, style, loading, size = '64rpx', ...leftProps } = props
21
   const { className, style, loading, size = '64rpx', ...leftProps } = props
9
 
22
 
11
 
24
 
12
   return (
25
   return (
13
     <View className={cls} style={style}>
26
     <View className={cls} style={style}>
14
-      {
15
-        loading && (
16
-          <View className='loading-box'>
17
-            <Spin size={size} {...leftProps} />
18
-          </View>
19
-        )
20
-      }
21
       {props.children}
27
       {props.children}
28
+      <Loading loading={loading} size={size} {...leftProps} />
22
     </View>
29
     </View>
23
   )
30
   )
24
 }
31
 }

+ 8
- 14
src/components/Spin/style.less View File

140
 .loading-wrapper {
140
 .loading-wrapper {
141
   height: 100%;
141
   height: 100%;
142
   position: relative;
142
   position: relative;
143
+  overflow: hidden;
143
 
144
 
144
   .loading-box {
145
   .loading-box {
145
-    // position: absolute;
146
-    // z-index: 10;
147
-    // top: 0;
148
-    // left: 0;
149
-    // width: 100%;
150
-    // height: 100%;
151
-    // min-height: 72px;
152
-    // padding-top: 60%;
153
-    // padding-left: 50%;
154
-    // background: rgba(255, 255, 255, .95);
155
-    // box-sizing: border-box;
156
-
157
     position: absolute;
146
     position: absolute;
158
-    z-index: 10;
147
+    z-index: -10;
159
     top: 0;
148
     top: 0;
160
     left: 0;
149
     left: 0;
161
     width: 100%;
150
     width: 100%;
164
     padding-top: 35%;
153
     padding-top: 35%;
165
     padding-left: 50%;
154
     padding-left: 50%;
166
     background: rgba(255, 255, 255, 0.95);
155
     background: rgba(255, 255, 255, 0.95);
167
-    -webkit-box-sizing: border-box;
168
     box-sizing: border-box;
156
     box-sizing: border-box;
157
+    opacity: 0;
158
+
159
+    &.active {
160
+      opacity: 1;
161
+      z-index: 10;
162
+    }
169
   }
163
   }
170
 }
164
 }