用户生日、性别、职业、地址、ntrp水平 Picker编辑
This commit is contained in:
@@ -13,6 +13,26 @@ export const renderYearMonth = (minYear = 2020, maxYear = 2099) => {
|
||||
]
|
||||
}
|
||||
|
||||
export const renderYearMonthDay = (minYear = 2020, maxYear = 2099) => {
|
||||
return [
|
||||
// 年份列
|
||||
Array.from({ length: maxYear - minYear + 1 }, (_, index) => ({
|
||||
text: `${minYear + index}年`,
|
||||
value: minYear + index
|
||||
})),
|
||||
// 月份列
|
||||
Array.from({ length: 12 }, (_, index) => ({
|
||||
text: `${index + 1}月`,
|
||||
value: index + 1
|
||||
})),
|
||||
// 日期列 (默认31天,具体天数需在onChange时动态调整)
|
||||
Array.from({ length: 31 }, (_, index) => ({
|
||||
text: `${index + 1}日`,
|
||||
value: index + 1
|
||||
}))
|
||||
]
|
||||
}
|
||||
|
||||
export const renderHourMinute = (minHour = 0, maxHour = 23) => {
|
||||
// 生成小时和分钟的选项数据
|
||||
return [
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useState, useEffect, useCallback } from 'react'
|
||||
import CommonPopup from '@/components/CommonPopup'
|
||||
import Picker from './Picker'
|
||||
import { renderYearMonth, renderHourMinute } from './PickerData'
|
||||
import { renderYearMonth, renderYearMonthDay, renderHourMinute } from './PickerData'
|
||||
interface PickerOption {
|
||||
text: string | number
|
||||
value: string | number
|
||||
@@ -12,55 +12,74 @@ interface PickerProps {
|
||||
setvisible: (visible: boolean) => void
|
||||
options?: PickerOption[][]
|
||||
value?: (string | number)[]
|
||||
type?: 'month' | 'hour' | null
|
||||
type?: 'month' | 'day' | 'hour' | null
|
||||
onConfirm?: (options: PickerOption[], values: (string | number)[]) => void
|
||||
onChange?: ( value: (string | number)[] ) => void
|
||||
onChange?: (value: (string | number)[]) => void
|
||||
}
|
||||
|
||||
const PopupPicker = ({
|
||||
visible,
|
||||
setvisible,
|
||||
value = [],
|
||||
onConfirm,
|
||||
const PopupPicker = ({
|
||||
visible,
|
||||
setvisible,
|
||||
value = [],
|
||||
onConfirm,
|
||||
onChange,
|
||||
options = [],
|
||||
type = null
|
||||
}: PickerProps) => {
|
||||
|
||||
|
||||
const [defaultValue, setDefaultValue] = useState<(string | number)[]>([])
|
||||
const [defaultOptions, setDefaultOptions] = useState<PickerOption[][]>([])
|
||||
const changePicker = (options: any[], values: any, columnIndex: number) => {
|
||||
debugger
|
||||
if (onChange) {
|
||||
console.log('picker onChange', columnIndex, values, options)
|
||||
console.log('picker onChange', columnIndex, values, options);
|
||||
|
||||
setDefaultValue(values)
|
||||
if (type === 'day' && JSON.stringify(defaultValue) !== JSON.stringify(values)) {
|
||||
const [year, month] = values;
|
||||
const daysInMonth = new Date(Number(year), Number(month), 0).getDate();
|
||||
const dayOptions = Array.from({ length: daysInMonth }, (_, i) => ({
|
||||
text: i + 1 + '日',
|
||||
value: i + 1,
|
||||
}));
|
||||
const newOptions = [...defaultOptions];
|
||||
if (JSON.stringify(newOptions[2]) !== JSON.stringify(dayOptions)) {
|
||||
newOptions[2] = dayOptions;
|
||||
setDefaultOptions(newOptions);
|
||||
}
|
||||
}
|
||||
|
||||
if (JSON.stringify(defaultValue) !== JSON.stringify(values)) {
|
||||
setDefaultValue(values);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const handleConfirm = () => {
|
||||
console.log(defaultValue,'defaultValue');
|
||||
console.log(defaultValue, 'defaultValue');
|
||||
onChange(defaultValue)
|
||||
setvisible(false)
|
||||
}
|
||||
|
||||
|
||||
const dialogClose = () => {
|
||||
setvisible(false)
|
||||
}
|
||||
useEffect(() => {
|
||||
if (type === 'month') {
|
||||
setDefaultOptions(renderYearMonth())
|
||||
} else if (type === 'day') {
|
||||
setDefaultOptions(renderYearMonthDay())
|
||||
} else if (type === 'hour') {
|
||||
setDefaultOptions(renderHourMinute())
|
||||
} else {
|
||||
setDefaultOptions(options)
|
||||
}
|
||||
}, [type])
|
||||
|
||||
// useEffect(() => {
|
||||
// if (value.length > 0 && defaultOptions.length > 0) {
|
||||
// setDefaultValue([...value])
|
||||
// }
|
||||
// }, [value, defaultOptions])
|
||||
|
||||
// useEffect(() => {
|
||||
// if (value.length > 0 && defaultOptions.length > 0) {
|
||||
// setDefaultValue([...value])
|
||||
// }
|
||||
// }, [value, defaultOptions])
|
||||
return (
|
||||
<>
|
||||
<CommonPopup
|
||||
|
||||
Reference in New Issue
Block a user