@gm-mobile/mp 3.9.3-beta.24 → 3.9.3-beta.28

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gm-mobile/mp",
3
- "version": "3.9.3-beta.24",
3
+ "version": "3.9.3-beta.28",
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.24",
25
- "@gm-mobile/c-tool": "^3.9.3-beta.24",
26
- "@gm-mobile/locales": "^3.9.3-beta.24"
24
+ "@gm-mobile/c-react": "^3.9.3-beta.28",
25
+ "@gm-mobile/c-tool": "^3.9.3-beta.28",
26
+ "@gm-mobile/locales": "^3.9.3-beta.28"
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": "a7a7b143572966c34912e2dad6d35c0f6de17e19"
36
+ "gitHead": "61ce731ea8dcab46f05d3435b7a21bf7b969c005"
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 { debounce } from 'lodash'
5
+ import { pxTransform } from '@tarojs/taro'
6
6
 
7
7
  interface PageMPProps extends PageProps {
8
8
  onRefresh?: () => Promise<any>
9
- onLoadMore?: () => Promise<any>
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,81 +34,76 @@ const PageMP: FC<PageMPProps> = ({
32
34
  refLoading.current = props.loading
33
35
  }
34
36
  }, [props.loading])
35
- const methods = {
36
- async refresh() {
37
- setState((state) => {
38
- return {
39
- ...state,
40
- refreshing: true,
41
- }
42
- })
43
- try {
44
- onRefresh && (await onRefresh())
45
- } catch (err) {
46
- console.error(err)
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
- setState((state) => {
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
- {onRefresh && (
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
+ scrollAnchoring
91
92
  refresherBackground='transparent'
92
93
  refresherTriggered={state.refreshing}
93
94
  lowerThreshold={50}
94
- onRefresherRefresh={() => methods.refresh()}
95
- onScrollToLower={() => methods.loadMore()}
95
+ onRefresherRefresh={onRefresh ? () => refresh() : undefined}
96
+ onScrollToLower={onLoadMore ? () => loadMore() : undefined}
96
97
  >
97
98
  {children}
98
99
  {state.loadingMore && (
99
- <Flex
100
- className='loading-more m-margin-tb-20 m-text-placeholder'
101
- alignCenter
102
- justifyCenter
103
- >
104
- 加载中...
100
+ <Flex height={pxTransform(60)} alignCenter justifyCenter>
101
+ <Loading style={{ opacity: 0.5 }} />
105
102
  </Flex>
106
103
  )}
107
104
  </ScrollView>
108
105
  )}
109
- {!onRefresh && children}
106
+ {!withScrollView && children}
110
107
  </PageBase>
111
108
  <LayoutRoot />
112
109
  <LayoutRootV1 />
@@ -124,6 +124,8 @@ export default class Router {
124
124
  // @ts-ignore
125
125
  data && delete parsed.data
126
126
  this._data[to] = data
127
+ } else {
128
+ this._data[to] = undefined
127
129
  }
128
130
  this._beforeChange(option, () => Taro.navigateTo(parsed))
129
131
  })