@gm-mobile/c-react 3.12.6 → 3.12.7-beta.1
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/c-react",
|
|
3
|
-
"version": "3.12.
|
|
3
|
+
"version": "3.12.7-beta.1",
|
|
4
4
|
"description": "> TODO: 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-font": "^3.12.
|
|
25
|
-
"@gm-mobile/c-tool": "^3.12.
|
|
26
|
-
"@gm-mobile/locales": "^3.12.
|
|
24
|
+
"@gm-mobile/c-font": "^3.12.7-beta.1",
|
|
25
|
+
"@gm-mobile/c-tool": "^3.12.7-beta.1",
|
|
26
|
+
"@gm-mobile/locales": "^3.12.7-beta.1",
|
|
27
27
|
"dayjs": "^1.11.6"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"prop-types": "^15.7.2",
|
|
35
35
|
"react": "^16.13.1"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "9b275d36b99b3612258531c0b44d59a14e672f60"
|
|
38
38
|
}
|
|
@@ -6,10 +6,36 @@ import { VList, VListRef } from '../v_list'
|
|
|
6
6
|
import Month from './month'
|
|
7
7
|
import { CALENDAR_TYPE } from './util'
|
|
8
8
|
import { MonthListProps } from './types'
|
|
9
|
+
import usePreviousObject from './use_previous'
|
|
9
10
|
|
|
10
11
|
// 目前只支持固定高度,定为265
|
|
11
12
|
const MONTH_HEIGHT = 265
|
|
12
13
|
|
|
14
|
+
function whichValueChanged(
|
|
15
|
+
prevArray: [Dayjs, Dayjs],
|
|
16
|
+
currentArray: [Dayjs, Dayjs]
|
|
17
|
+
) {
|
|
18
|
+
const changes: number[] = []
|
|
19
|
+
|
|
20
|
+
if (!prevArray) {
|
|
21
|
+
return 0
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (!moment(prevArray[0]).isSame(moment(currentArray[0]))) {
|
|
25
|
+
changes.push(0)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (!moment(prevArray[1]).isSame(moment(currentArray[1]))) {
|
|
29
|
+
changes.push(1)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** 没有变化 */
|
|
33
|
+
if (changes.length === 0) return 0
|
|
34
|
+
/** 两个都变化了 */
|
|
35
|
+
if (changes.length === 2) return 1
|
|
36
|
+
return 0
|
|
37
|
+
}
|
|
38
|
+
|
|
13
39
|
const MonthsList: FC<MonthListProps> = ({
|
|
14
40
|
min,
|
|
15
41
|
max,
|
|
@@ -19,8 +45,10 @@ const MonthsList: FC<MonthListProps> = ({
|
|
|
19
45
|
onSelectDay,
|
|
20
46
|
disabledDate,
|
|
21
47
|
showDateLabel,
|
|
48
|
+
canScrollWhenMaxOrMinChange = false,
|
|
22
49
|
}) => {
|
|
23
50
|
const refList = useRef<VListRef>(null)
|
|
51
|
+
const previous = usePreviousObject(selected)
|
|
24
52
|
|
|
25
53
|
const computedMonthList = () => {
|
|
26
54
|
// 优先 min,其次 begin ,其次 当前
|
|
@@ -50,7 +78,7 @@ const MonthsList: FC<MonthListProps> = ({
|
|
|
50
78
|
}
|
|
51
79
|
const monthsList = computedMonthList()
|
|
52
80
|
|
|
53
|
-
|
|
81
|
+
const scrollToTarget = (flag: boolean) => {
|
|
54
82
|
if (selected.length) {
|
|
55
83
|
const date = type === CALENDAR_TYPE.RANGE ? selected[1] : selected[0]
|
|
56
84
|
const targetId = _.findIndex(
|
|
@@ -60,12 +88,39 @@ const MonthsList: FC<MonthListProps> = ({
|
|
|
60
88
|
moment(item).month() === moment(date).month()
|
|
61
89
|
)
|
|
62
90
|
|
|
63
|
-
|
|
91
|
+
if (flag) {
|
|
92
|
+
setTimeout(() => {
|
|
93
|
+
refList.current && refList.current.apiDoScrollToKey(targetId)
|
|
94
|
+
}, 200)
|
|
95
|
+
} else {
|
|
64
96
|
refList.current && refList.current.apiDoScrollToKey(targetId)
|
|
65
|
-
}
|
|
97
|
+
}
|
|
66
98
|
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
useEffect(() => {
|
|
102
|
+
scrollToTarget(true)
|
|
67
103
|
}, [])
|
|
68
104
|
|
|
105
|
+
useEffect(() => {
|
|
106
|
+
if (!canScrollWhenMaxOrMinChange) {
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
if (max || min) {
|
|
110
|
+
const flagItem = whichValueChanged(previous as any, selected as any)
|
|
111
|
+
const date = selected[flagItem]
|
|
112
|
+
const targetId = _.findIndex(
|
|
113
|
+
monthsList,
|
|
114
|
+
(item) =>
|
|
115
|
+
moment(item).year() === moment(date).year() &&
|
|
116
|
+
moment(item).month() === moment(date).month()
|
|
117
|
+
)
|
|
118
|
+
if (targetId !== -1) {
|
|
119
|
+
refList.current && refList.current.apiDoScrollToKey(targetId)
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
}, [max, min])
|
|
123
|
+
|
|
69
124
|
return (
|
|
70
125
|
<VList
|
|
71
126
|
ref={refList}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react'
|
|
2
|
+
|
|
3
|
+
function usePreviousObject<T extends Record<string, any>>(obj: T): T {
|
|
4
|
+
const ref = useRef<T | null>(null)
|
|
5
|
+
|
|
6
|
+
useEffect(() => {
|
|
7
|
+
ref.current = obj
|
|
8
|
+
}, [obj])
|
|
9
|
+
|
|
10
|
+
return ref.current as T
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export default usePreviousObject
|