@gm-mobile/mp 3.9.3-beta.8 → 3.9.3
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/base.less +11 -0
- package/src/component/page/base.tsx +13 -6
- package/src/component/page/page.tsx +123 -37
- package/src/component/safe_bottom/safe_bottom.tsx +1 -1
- package/src/component/status_bar/status_bar.tsx +1 -2
- package/src/router/index.ts +6 -3
- package/src/router/stories.tsx +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gm-mobile/mp",
|
|
3
|
-
"version": "3.9.3
|
|
3
|
+
"version": "3.9.3",
|
|
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
|
|
25
|
-
"@gm-mobile/c-tool": "^3.9.3
|
|
26
|
-
"@gm-mobile/locales": "^3.9.3
|
|
24
|
+
"@gm-mobile/c-react": "^3.9.3",
|
|
25
|
+
"@gm-mobile/c-tool": "^3.9.3",
|
|
26
|
+
"@gm-mobile/locales": "^3.9.3"
|
|
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": "1f1d2b656046efe6479f05f9fde2e34cb99df4de"
|
|
37
37
|
}
|
|
@@ -14,12 +14,15 @@ interface PageProps extends HtmlHTMLAttributes<HTMLDivElement> {
|
|
|
14
14
|
top?: ReactNode
|
|
15
15
|
/** bottom位置自带底部安全边距,不需要和safeBottom同时使用 */
|
|
16
16
|
bottom?: ReactNode
|
|
17
|
+
/** 左侧内容 */
|
|
18
|
+
left?: ReactNode
|
|
17
19
|
pageClassName?: string
|
|
18
20
|
pageStyle?: CSSProperties
|
|
19
21
|
/** 底部安全区域 */
|
|
20
22
|
safeBottom?: boolean
|
|
21
23
|
/** 用于放置绝对定位组件 */
|
|
22
24
|
extra?: ReactNode
|
|
25
|
+
onRefresh?: () => Promise<any>
|
|
23
26
|
}
|
|
24
27
|
|
|
25
28
|
const Page: FC<PageProps> = ({
|
|
@@ -31,6 +34,7 @@ const Page: FC<PageProps> = ({
|
|
|
31
34
|
tabbar,
|
|
32
35
|
top,
|
|
33
36
|
bottom,
|
|
37
|
+
left,
|
|
34
38
|
children,
|
|
35
39
|
className,
|
|
36
40
|
pageClassName,
|
|
@@ -75,12 +79,15 @@ const Page: FC<PageProps> = ({
|
|
|
75
79
|
</Flex>
|
|
76
80
|
)}
|
|
77
81
|
{top && <View className='m-top m-flex-none'>{top}</View>}
|
|
78
|
-
<
|
|
79
|
-
className=
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
82
|
+
<Flex auto className='m-page-wrapper'>
|
|
83
|
+
<View className='m-page-side'>{left}</View>
|
|
84
|
+
<View
|
|
85
|
+
className={classNames('m-page-content', pageClassName)}
|
|
86
|
+
style={pageStyle}
|
|
87
|
+
>
|
|
88
|
+
{children}
|
|
89
|
+
</View>
|
|
90
|
+
</Flex>
|
|
84
91
|
{bottom && (
|
|
85
92
|
<SafeBottomMP className='m-bottom m-flex-none'>
|
|
86
93
|
{bottom}
|
|
@@ -1,19 +1,44 @@
|
|
|
1
|
-
import React, {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
import React, {
|
|
2
|
+
useEffect,
|
|
3
|
+
useRef,
|
|
4
|
+
FC,
|
|
5
|
+
useState,
|
|
6
|
+
ReactNode,
|
|
7
|
+
CSSProperties,
|
|
8
|
+
} from 'react'
|
|
9
|
+
import { Flex, LayoutRoot, LayoutRootV1, Loading } from '@gm-mobile/c-react'
|
|
10
|
+
import { ScrollView, View } from '@tarojs/components'
|
|
11
|
+
import PageBase, { PageProps } from './base'
|
|
12
|
+
import { pxTransform } from '@tarojs/taro'
|
|
13
|
+
|
|
14
|
+
interface PageMPProps extends PageProps {
|
|
15
|
+
/** 最大宽度,默认480(ipad),对ipad设备做居中变窄处理,设置1025(iPad pro 12.9 inch)可以跳过处理 */
|
|
16
|
+
maxWidth?: number
|
|
17
|
+
onRefresh?: () => Promise<any>
|
|
18
|
+
/** 上滑加载更多事件。如果promise返回一个空数组,表示没有更多了 */
|
|
19
|
+
onLoadMore?: () => Promise<Array<any> | undefined>
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const PageMP: FC<PageMPProps> = ({
|
|
23
|
+
children,
|
|
24
|
+
maxWidth = 480,
|
|
25
|
+
onRefresh,
|
|
26
|
+
onLoadMore,
|
|
27
|
+
style,
|
|
28
|
+
...props
|
|
29
|
+
}) => {
|
|
30
|
+
const { screenWidth } = wx.getSystemInfoSync()
|
|
31
|
+
const transformRatio = maxWidth / screenWidth
|
|
32
|
+
const transform = screenWidth > maxWidth
|
|
5
33
|
|
|
6
|
-
const PageMP: FC<
|
|
7
|
-
PageMPProps & {
|
|
8
|
-
onRefresh?: () => Promise<any>
|
|
9
|
-
}
|
|
10
|
-
> = ({ children, onRefresh, ...props }) => {
|
|
11
34
|
const [state, setState] = useState({
|
|
12
35
|
refreshing: false,
|
|
36
|
+
loadingMore: false,
|
|
13
37
|
})
|
|
38
|
+
|
|
39
|
+
// Page加载状态
|
|
14
40
|
const refLoading = useRef<boolean | undefined>(false)
|
|
15
41
|
useEffect(() => {
|
|
16
|
-
// 和之前的不一样
|
|
17
42
|
if (props.loading !== refLoading.current) {
|
|
18
43
|
if (props.loading) {
|
|
19
44
|
wx.showNavigationBarLoading()
|
|
@@ -24,50 +49,111 @@ const PageMP: FC<
|
|
|
24
49
|
refLoading.current = props.loading
|
|
25
50
|
}
|
|
26
51
|
}, [props.loading])
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
52
|
+
|
|
53
|
+
const refresh = async () => {
|
|
54
|
+
setState((state) => {
|
|
55
|
+
return {
|
|
56
|
+
...state,
|
|
57
|
+
refreshing: true,
|
|
58
|
+
}
|
|
59
|
+
})
|
|
60
|
+
try {
|
|
61
|
+
onRefresh && (await onRefresh())
|
|
62
|
+
} catch (err) {
|
|
63
|
+
console.error(err)
|
|
64
|
+
}
|
|
65
|
+
setState((state) => {
|
|
66
|
+
return {
|
|
67
|
+
...state,
|
|
68
|
+
refreshing: false,
|
|
39
69
|
}
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
...state,
|
|
43
|
-
refreshing: false,
|
|
44
|
-
}
|
|
45
|
-
})
|
|
46
|
-
},
|
|
70
|
+
})
|
|
47
71
|
}
|
|
48
72
|
|
|
49
|
-
|
|
73
|
+
const loadMore = async () => {
|
|
74
|
+
console.log('load more')
|
|
75
|
+
setState((state) => {
|
|
76
|
+
return {
|
|
77
|
+
...state,
|
|
78
|
+
loadingMore: true,
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
try {
|
|
82
|
+
onLoadMore && (await onLoadMore())
|
|
83
|
+
} catch (err) {
|
|
84
|
+
console.error(err)
|
|
85
|
+
}
|
|
86
|
+
setState((state) => {
|
|
87
|
+
return {
|
|
88
|
+
...state,
|
|
89
|
+
loadingMore: false,
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
const withScrollView = !!onRefresh || !!onLoadMore
|
|
94
|
+
|
|
95
|
+
const layoutStyle: CSSProperties = transform
|
|
96
|
+
? {
|
|
97
|
+
position: 'absolute',
|
|
98
|
+
width: '100%',
|
|
99
|
+
height: `calc(100vh / ${transformRatio})`,
|
|
100
|
+
}
|
|
101
|
+
: {}
|
|
102
|
+
|
|
103
|
+
const page = (
|
|
50
104
|
<>
|
|
51
|
-
<PageBase
|
|
52
|
-
{
|
|
105
|
+
<PageBase
|
|
106
|
+
{...props}
|
|
107
|
+
style={{
|
|
108
|
+
...style,
|
|
109
|
+
height: transform ? `calc(100vh / ${transformRatio})` : undefined,
|
|
110
|
+
}}
|
|
111
|
+
>
|
|
112
|
+
{withScrollView && (
|
|
53
113
|
<ScrollView
|
|
54
114
|
className='m-flex'
|
|
55
115
|
style={{ height: '100%' }}
|
|
116
|
+
enableBackToTop
|
|
56
117
|
scrollY
|
|
57
|
-
refresherEnabled
|
|
118
|
+
refresherEnabled={!!onRefresh}
|
|
119
|
+
scrollWithAnimation
|
|
120
|
+
scrollAnchoring
|
|
58
121
|
refresherBackground='transparent'
|
|
59
122
|
refresherTriggered={state.refreshing}
|
|
60
|
-
|
|
123
|
+
lowerThreshold={50}
|
|
124
|
+
onRefresherRefresh={onRefresh ? () => refresh() : undefined}
|
|
125
|
+
onScrollToLower={onLoadMore ? () => loadMore() : undefined}
|
|
61
126
|
>
|
|
62
127
|
{children}
|
|
128
|
+
{state.loadingMore && (
|
|
129
|
+
<Flex height={pxTransform(60)} alignCenter justifyCenter>
|
|
130
|
+
<Loading style={{ opacity: 0.5 }} />
|
|
131
|
+
</Flex>
|
|
132
|
+
)}
|
|
63
133
|
</ScrollView>
|
|
64
134
|
)}
|
|
65
|
-
{!
|
|
135
|
+
{!withScrollView && children}
|
|
66
136
|
</PageBase>
|
|
67
|
-
<LayoutRoot />
|
|
68
|
-
<LayoutRootV1 />
|
|
137
|
+
<LayoutRoot style={layoutStyle} />
|
|
138
|
+
<LayoutRootV1 style={layoutStyle} />
|
|
69
139
|
</>
|
|
70
140
|
)
|
|
141
|
+
|
|
142
|
+
if (transform) {
|
|
143
|
+
return (
|
|
144
|
+
<View className='transformer'>
|
|
145
|
+
<View
|
|
146
|
+
className='transformed-page'
|
|
147
|
+
style={{
|
|
148
|
+
transform: `scale(${transformRatio})`,
|
|
149
|
+
}}
|
|
150
|
+
>
|
|
151
|
+
{page}
|
|
152
|
+
</View>
|
|
153
|
+
</View>
|
|
154
|
+
)
|
|
155
|
+
}
|
|
156
|
+
return page
|
|
71
157
|
}
|
|
72
158
|
|
|
73
159
|
export default PageMP
|
|
@@ -12,7 +12,7 @@ const SafeBottomMP: FC<SafeBottomMPProps> = memo(
|
|
|
12
12
|
|
|
13
13
|
return (
|
|
14
14
|
<View className={classNames(className)} {...rest}>
|
|
15
|
-
{React.cloneElement(children as React.ReactElement
|
|
15
|
+
{React.cloneElement((children as React.ReactElement) || <View />, {
|
|
16
16
|
style: {
|
|
17
17
|
paddingBottom:
|
|
18
18
|
paddingBottom > 0 ? `${paddingBottom}px!important` : undefined,
|
|
@@ -5,10 +5,9 @@ import UtilMP from '../../util'
|
|
|
5
5
|
export type StatusBarMPProps = HTMLAttributes<HTMLDivElement>
|
|
6
6
|
|
|
7
7
|
const StatusBarMP: FC<StatusBarMPProps> = memo((style, ...rest) => {
|
|
8
|
-
const [height, setHeight] = useState(
|
|
8
|
+
const [height, setHeight] = useState(wx.getSystemInfoSync().statusBarHeight)
|
|
9
9
|
useEffect(() => {
|
|
10
10
|
const rect = UtilMP.getMenuButtonBoundingClientRect()
|
|
11
|
-
|
|
12
11
|
UtilMP.getSystemInfo().then((res) => {
|
|
13
12
|
// 不一定能读到胶囊,或者胶囊占据整个宽, 此时不需要设置statusBar
|
|
14
13
|
return setHeight(rect?.left ? res.statusBarHeight : 0)
|
package/src/router/index.ts
CHANGED
|
@@ -54,7 +54,7 @@ export default class Router {
|
|
|
54
54
|
} = {}
|
|
55
55
|
|
|
56
56
|
/** navigateTo传入的{data:值} */
|
|
57
|
-
private _data
|
|
57
|
+
private _data: { [key: string]: any } = {}
|
|
58
58
|
|
|
59
59
|
/** 最近一次的路由跳转动作是 */
|
|
60
60
|
currentAction?:
|
|
@@ -67,6 +67,7 @@ export default class Router {
|
|
|
67
67
|
/** 当前路由信息 */
|
|
68
68
|
get route() {
|
|
69
69
|
const page = getCurrentPages().reverse()[0]
|
|
70
|
+
const data = this._data['/' + this._urlToPath(page.route)]
|
|
70
71
|
return {
|
|
71
72
|
/** 页面config而配置的标题 */
|
|
72
73
|
title: page.config.navigationBarTitleText as string,
|
|
@@ -75,7 +76,7 @@ export default class Router {
|
|
|
75
76
|
/** url参数 */
|
|
76
77
|
options: page.options,
|
|
77
78
|
/** navigateTo传入的{data:值} */
|
|
78
|
-
data
|
|
79
|
+
data,
|
|
79
80
|
}
|
|
80
81
|
}
|
|
81
82
|
|
|
@@ -122,7 +123,9 @@ export default class Router {
|
|
|
122
123
|
const data = typeof option === 'object' ? option.data : undefined
|
|
123
124
|
// @ts-ignore
|
|
124
125
|
data && delete parsed.data
|
|
125
|
-
this._data = data
|
|
126
|
+
this._data[to] = data
|
|
127
|
+
} else {
|
|
128
|
+
this._data[to] = undefined
|
|
126
129
|
}
|
|
127
130
|
this._beforeChange(option, () => Taro.navigateTo(parsed))
|
|
128
131
|
})
|
package/src/router/stories.tsx
CHANGED