-
Notifications
You must be signed in to change notification settings - Fork 273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: picker #2990
refactor: picker #2990
Changes from 51 commits
1c1ef86
3acf368
2e3a00a
c651e62
e60df8e
43fc55a
4ce2688
28c4e2c
bc3fb35
b0b635c
85d5d40
7a27934
a030ff4
f436c51
6a6bc39
10be5cd
80f20a1
8ad7392
95b5423
fe66362
aa5f2ea
b5987b9
0ae1a26
ce3b37b
26f9319
d5118f6
a787f7d
c10fcc7
9e32bcd
ae272de
f539b83
f06ec00
b67dfca
9905564
0c448c8
cc30cb0
b699d60
7760169
86855f0
88d4f80
654d1e0
507f18c
d9628e7
38296d3
dc14741
65238d3
15630d6
369fec3
eb899ee
b458e92
ffba77f
f6edf91
9688104
f81ef99
f278479
3fbf988
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
import React, { FunctionComponent, useState, useEffect } from 'react' | ||
import { View } from '@tarojs/components' | ||
import Picker, { PickerOption, PickerProps } from '@/packages/picker/index.taro' | ||
import Picker, { PickerProps } from '@/packages/picker/index.taro' | ||
import { useConfig } from '@/packages/configprovider/index.taro' | ||
import { usePropsValue } from '@/hooks/use-props-value' | ||
import { BasicComponent, ComponentDefaults } from '@/utils/typings' | ||
import { isDate } from '@/utils/is-date' | ||
import { padZero } from '@/utils/pad-zero' | ||
import { PickerOptionItem, PickerValue } from '@/packages/pickerview/index.taro' | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里是否可以直接引用 types.ts There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
已修改 |
||
|
||
export interface DatePickerProps extends BasicComponent { | ||
value?: Date | ||
|
@@ -38,17 +39,17 @@ export interface DatePickerProps extends BasicComponent { | |
| 'onChange' | ||
> | ||
> | ||
formatter: (type: string, option: PickerOption) => PickerOption | ||
filter: (type: string, option: PickerOption[]) => PickerOption[] | ||
formatter: (type: string, option: PickerOptionItem) => PickerOptionItem | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 我个人理解这里不需要突出 item,PickerOption 和 PickerOptions 可以标明他们的单复数~ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
已修改 |
||
filter: (type: string, option: PickerOptionItem[]) => PickerOptionItem[] | ||
onClose: () => void | ||
onCancel: () => void | ||
onConfirm: ( | ||
selectedOptions: PickerOption[], | ||
selectedValue: (string | number)[] | ||
selectedOptions: PickerOptionItem[], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 这里 可以直接使用 PickerOptions 了,types 有定义。 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
已修改 |
||
selectedValue: PickerValue[] | ||
) => void | ||
onChange?: ( | ||
selectedOptions: PickerOption[], | ||
selectedValue: (string | number)[], | ||
selectedOptions: PickerOptionItem[], | ||
selectedValue: PickerValue[], | ||
columnIndex: number | ||
) => void | ||
} | ||
|
@@ -104,8 +105,8 @@ export const DatePicker: FunctionComponent< | |
minute: lang.min, | ||
seconds: lang.seconds, | ||
} | ||
const [pickerValue, setPickerValue] = useState<(string | number)[]>([]) | ||
const [pickerOptions, setPickerOptions] = useState<PickerOption[][]>([]) | ||
const [pickerValue, setPickerValue] = useState<PickerValue[]>([]) | ||
const [pickerOptions, setPickerOptions] = useState<PickerOptionItem[][]>([]) | ||
const formatValue = (value: Date | null) => { | ||
if (!value || (value && !isDate(value))) { | ||
value = startDate | ||
|
@@ -218,7 +219,7 @@ export const DatePicker: FunctionComponent< | |
const compareDateChange = ( | ||
currentDate: number, | ||
newDate: Date | null, | ||
selectedOptions: PickerOption[], | ||
selectedOptions: PickerOptionItem[], | ||
index: number | ||
) => { | ||
const isEqual = new Date(currentDate)?.getTime() === newDate?.getTime() | ||
|
@@ -238,8 +239,8 @@ export const DatePicker: FunctionComponent< | |
} | ||
} | ||
const handlePickerChange = ( | ||
selectedOptions: PickerOption[], | ||
selectedValue: (number | string)[], | ||
selectedOptions: PickerOptionItem[], | ||
selectedValue: PickerValue[], | ||
index: number | ||
) => { | ||
const rangeType = type.toLocaleLowerCase() | ||
|
@@ -248,7 +249,7 @@ export const DatePicker: FunctionComponent< | |
rangeType | ||
) | ||
) { | ||
const formatDate: (number | string)[] = [] | ||
const formatDate: PickerValue[] = [] | ||
selectedValue.forEach((item) => { | ||
formatDate.push(item) | ||
}) | ||
|
@@ -313,13 +314,13 @@ export const DatePicker: FunctionComponent< | |
const formatOption = (type: string, value: string | number) => { | ||
if (formatter) { | ||
return formatter(type, { | ||
text: padZero(value, 2), | ||
label: padZero(value, 2), | ||
value: padZero(value, 2), | ||
}) | ||
} | ||
const padMin = padZero(value, 2) | ||
const fatter = showChinese ? zhCNType[type] : '' | ||
return { text: padMin + fatter, value: padMin } | ||
return { label: padMin + fatter, value: padMin } | ||
} | ||
|
||
const generateColumn = ( | ||
|
@@ -330,7 +331,7 @@ export const DatePicker: FunctionComponent< | |
columnIndex: number | ||
) => { | ||
let cmin = min | ||
const arr: Array<PickerOption> = [] | ||
const arr: Array<PickerOptionItem> = [] | ||
let index = 0 | ||
while (cmin <= max) { | ||
arr.push(formatOption(type, cmin)) | ||
|
@@ -412,14 +413,13 @@ export const DatePicker: FunctionComponent< | |
onClose={onClose} | ||
onCancel={onCancel} | ||
value={pickerValue} | ||
onConfirm={(options: PickerOption[], value: (string | number)[]) => | ||
onConfirm && onConfirm(options, value) | ||
} | ||
onChange={( | ||
options: PickerOption[], | ||
value: (number | string)[], | ||
index: number | ||
) => handlePickerChange(options, value, index)} | ||
onConfirm={( | ||
selectedOptions: PickerOptionItem[], | ||
selectedValue: PickerValue[] | ||
) => onConfirm && onConfirm(selectedOptions, selectedValue)} | ||
onChange={({ value, index, selectedOptions }) => { | ||
handlePickerChange(selectedOptions, value, index) | ||
}} | ||
threeDimensional={threeDimensional} | ||
/> | ||
)} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
参考 ai 反馈
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改