用户生日、性别、职业、地址、ntrp水平 Picker编辑

This commit is contained in:
2025-09-17 23:25:32 +08:00
parent bb2b31af67
commit 7958e4ee3e
6 changed files with 208 additions and 142 deletions

View File

@@ -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 [

View File

@@ -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

View File

@@ -19,7 +19,6 @@ export interface UserInfo {
participated: number;
};
personal_profile: string;
location: string;
occupation: string;
ntrp_level: string;
phone?: string;
@@ -31,6 +30,9 @@ export interface UserInfo {
is_following?: boolean;
tags?: string[];
ongoing_games?: string[];
country?: string;
province?: string;
city?: string;
}
// 用户信息卡片组件属性