@gm-mobile/mp 3.9.3-beta.25 → 3.9.3-beta.29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +5 -5
- package/src/component/page/page.tsx +53 -57
- package/src/router/index.ts +2 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-mobile/mp",
|
|
3
|
-
"version": "3.9.3-beta.
|
|
3
|
+
"version": "3.9.3-beta.29",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "liyatang <liyatang@qq.com>",
|
|
6
6
|
"homepage": "https://github.com/gmfe/gm-mobile#readme",
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
"url": "https://github.com/gmfe/gm-mobile/issues"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@gm-mobile/c-react": "^3.9.3-beta.
|
|
25
|
-
"@gm-mobile/c-tool": "^3.9.3-beta.
|
|
26
|
-
"@gm-mobile/locales": "^3.9.3-beta.
|
|
24
|
+
"@gm-mobile/c-react": "^3.9.3-beta.29",
|
|
25
|
+
"@gm-mobile/c-tool": "^3.9.3-beta.29",
|
|
26
|
+
"@gm-mobile/locales": "^3.9.3-beta.29"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"@tarojs/components": "3.0.18",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"prop-types": "^15.7.2",
|
|
34
34
|
"react": "^16.13.1"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "216ad1a8f7127b895838785f208455768b382ba2"
|
|
37
37
|
}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import React, { useEffect, useRef, FC, useState, ReactNode } from 'react'
|
|
2
|
-
import { Flex, LayoutRoot, LayoutRootV1 } from '@gm-mobile/c-react'
|
|
2
|
+
import { Flex, LayoutRoot, LayoutRootV1, Loading } from '@gm-mobile/c-react'
|
|
3
3
|
import { ScrollView } from '@tarojs/components'
|
|
4
4
|
import PageBase, { PageProps } from './base'
|
|
5
|
-
import {
|
|
5
|
+
import { pxTransform } from '@tarojs/taro'
|
|
6
6
|
|
|
7
7
|
interface PageMPProps extends PageProps {
|
|
8
8
|
onRefresh?: () => Promise<any>
|
|
9
|
-
|
|
9
|
+
/** 上滑加载更多事件。如果promise返回一个空数组,表示没有更多了 */
|
|
10
|
+
onLoadMore?: () => Promise<Array<any> | undefined>
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
const PageMP: FC<PageMPProps> = ({
|
|
@@ -19,9 +20,10 @@ const PageMP: FC<PageMPProps> = ({
|
|
|
19
20
|
refreshing: false,
|
|
20
21
|
loadingMore: false,
|
|
21
22
|
})
|
|
23
|
+
|
|
24
|
+
// Page加载状态
|
|
22
25
|
const refLoading = useRef<boolean | undefined>(false)
|
|
23
26
|
useEffect(() => {
|
|
24
|
-
// 和之前的不一样
|
|
25
27
|
if (props.loading !== refLoading.current) {
|
|
26
28
|
if (props.loading) {
|
|
27
29
|
wx.showNavigationBarLoading()
|
|
@@ -32,82 +34,76 @@ const PageMP: FC<PageMPProps> = ({
|
|
|
32
34
|
refLoading.current = props.loading
|
|
33
35
|
}
|
|
34
36
|
}, [props.loading])
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
37
|
+
|
|
38
|
+
const refresh = async () => {
|
|
39
|
+
setState((state) => {
|
|
40
|
+
return {
|
|
41
|
+
...state,
|
|
42
|
+
refreshing: true,
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
try {
|
|
46
|
+
onRefresh && (await onRefresh())
|
|
47
|
+
} catch (err) {
|
|
48
|
+
console.error(err)
|
|
49
|
+
}
|
|
50
|
+
setState((state) => {
|
|
51
|
+
return {
|
|
52
|
+
...state,
|
|
53
|
+
refreshing: false,
|
|
54
|
+
}
|
|
55
|
+
})
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const loadMore = async () => {
|
|
59
|
+
console.log('load more')
|
|
60
|
+
setState((state) => {
|
|
61
|
+
return {
|
|
62
|
+
...state,
|
|
63
|
+
loadingMore: true,
|
|
64
|
+
}
|
|
65
|
+
})
|
|
66
|
+
try {
|
|
67
|
+
onLoadMore && (await onLoadMore())
|
|
68
|
+
} catch (err) {
|
|
69
|
+
console.error(err)
|
|
70
|
+
}
|
|
71
|
+
setState((state) => {
|
|
72
|
+
return {
|
|
73
|
+
...state,
|
|
74
|
+
loadingMore: false,
|
|
47
75
|
}
|
|
48
|
-
|
|
49
|
-
return {
|
|
50
|
-
...state,
|
|
51
|
-
refreshing: false,
|
|
52
|
-
}
|
|
53
|
-
})
|
|
54
|
-
},
|
|
55
|
-
loadMore: debounce(
|
|
56
|
-
async () => {
|
|
57
|
-
setState((state) => {
|
|
58
|
-
return {
|
|
59
|
-
...state,
|
|
60
|
-
refreshing: true,
|
|
61
|
-
}
|
|
62
|
-
})
|
|
63
|
-
try {
|
|
64
|
-
onLoadMore && (await onLoadMore())
|
|
65
|
-
} catch (err) {
|
|
66
|
-
console.error(err)
|
|
67
|
-
}
|
|
68
|
-
setState((state) => {
|
|
69
|
-
return {
|
|
70
|
-
...state,
|
|
71
|
-
refreshing: false,
|
|
72
|
-
}
|
|
73
|
-
})
|
|
74
|
-
},
|
|
75
|
-
1000,
|
|
76
|
-
{ leading: true }
|
|
77
|
-
),
|
|
76
|
+
})
|
|
78
77
|
}
|
|
78
|
+
const withScrollView = !!onRefresh || !!onLoadMore
|
|
79
79
|
|
|
80
80
|
return (
|
|
81
81
|
<>
|
|
82
82
|
<PageBase {...props}>
|
|
83
|
-
{
|
|
83
|
+
{withScrollView && (
|
|
84
84
|
<ScrollView
|
|
85
85
|
className='m-flex'
|
|
86
86
|
style={{ height: '100%' }}
|
|
87
87
|
enableBackToTop
|
|
88
88
|
scrollY
|
|
89
|
-
refresherEnabled
|
|
89
|
+
refresherEnabled={!!onRefresh}
|
|
90
90
|
scrollWithAnimation
|
|
91
91
|
scrollAnchoring
|
|
92
92
|
refresherBackground='transparent'
|
|
93
93
|
refresherTriggered={state.refreshing}
|
|
94
94
|
lowerThreshold={50}
|
|
95
|
-
onRefresherRefresh={() =>
|
|
96
|
-
onScrollToLower={() =>
|
|
95
|
+
onRefresherRefresh={onRefresh ? () => refresh() : undefined}
|
|
96
|
+
onScrollToLower={onLoadMore ? () => loadMore() : undefined}
|
|
97
97
|
>
|
|
98
98
|
{children}
|
|
99
99
|
{state.loadingMore && (
|
|
100
|
-
<Flex
|
|
101
|
-
|
|
102
|
-
alignCenter
|
|
103
|
-
justifyCenter
|
|
104
|
-
>
|
|
105
|
-
加载中...
|
|
100
|
+
<Flex height={pxTransform(60)} alignCenter justifyCenter>
|
|
101
|
+
<Loading style={{ opacity: 0.5 }} />
|
|
106
102
|
</Flex>
|
|
107
103
|
)}
|
|
108
104
|
</ScrollView>
|
|
109
105
|
)}
|
|
110
|
-
{!
|
|
106
|
+
{!withScrollView && children}
|
|
111
107
|
</PageBase>
|
|
112
108
|
<LayoutRoot />
|
|
113
109
|
<LayoutRootV1 />
|
package/src/router/index.ts
CHANGED