0.3.1.3
This commit is contained in:
@@ -136,23 +136,6 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
const handleChange = (field: keyof FamilyMember, value: any) => {
|
||||
console.log('handleChange:', field, value)
|
||||
|
||||
// 防御性检查:防止 Select 组件意外清空 initialData 中已有的值
|
||||
// 这可能是由于 Select 组件在某些情况下(如选项尚未完全渲染)触发了无效的 onChange
|
||||
if ((field === 'motherId' || field === 'fatherId') && !value) {
|
||||
const initialValue = initialData?.[field]
|
||||
const currentValue = formData[field]
|
||||
// 只有当当前值等于初始值且尝试清空时才阻止
|
||||
if (initialValue && currentValue === initialValue) {
|
||||
console.warn(`Prevented accidental clearing of ${field}`)
|
||||
return
|
||||
}
|
||||
// 如果当前值不为空,但尝试清空为空字符串,也阻止(因为Select组件可能发送空字符串而不是undefined)
|
||||
if (currentValue && value === '') {
|
||||
console.warn(`Prevented clearing of ${field} to empty string`)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
setFormData((prev) => {
|
||||
const newData = { ...prev, [field]: value }
|
||||
|
||||
@@ -246,20 +229,8 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
newErrors.push("请填写正确的世系")
|
||||
}
|
||||
|
||||
// 关系验证:非始祖必须与家族建立联系
|
||||
if (!isFounder) {
|
||||
// 1. 检查是否有主要成员的父母
|
||||
const hasValidFather = formData.fatherId && existingMembers.some(m => m.id === formData.fatherId)
|
||||
const hasValidMother = formData.motherId && existingMembers.some(m => m.id === formData.motherId)
|
||||
|
||||
// 2. 检查是否有主要成员的配偶
|
||||
const hasValidSpouse = formData.spouseIds && formData.spouseIds.length > 0 &&
|
||||
formData.spouseIds.some(id => existingMembers.some(m => m.id === id))
|
||||
|
||||
if (!hasValidFather && !hasValidMother && !hasValidSpouse) {
|
||||
newErrors.push("孤立成员:请选择家族成员作为父母,或添加家族成员为配偶")
|
||||
}
|
||||
}
|
||||
// 注:允许孤立成员存在,可以后续通过族谱关联功能建立关系
|
||||
// 这样可以修正错误的关系设置
|
||||
|
||||
setErrors(newErrors)
|
||||
return newErrors.length === 0
|
||||
@@ -273,6 +244,8 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
}
|
||||
|
||||
// 确保所有必填字段都有值
|
||||
// 注意:fatherId/motherId 需要显式设为 null 而不是 undefined,
|
||||
// 否则 JSON.stringify 会忽略 undefined 值,导致后端收不到更新
|
||||
const memberData: FamilyMember = {
|
||||
id: formData.id || generateUUID(),
|
||||
surname: formData.surname || "",
|
||||
@@ -529,15 +502,8 @@ export function MemberForm({ initialData, existingMembers = [], onSubmit, onCanc
|
||||
<SelectItem value="none">无</SelectItem>
|
||||
{potentialRelatives
|
||||
.filter((m) => {
|
||||
if (m.id === formData.motherId) {
|
||||
console.log('Mother already selected, showing:', { id: m.id, name: m.fullName })
|
||||
return true
|
||||
}
|
||||
const isMatch = m.gender === "FEMALE" && m.generation === (formData.generation || 1) - 1
|
||||
if (isMatch) {
|
||||
console.log('Mother match found:', { id: m.id, name: m.fullName, gender: m.gender, generation: m.generation })
|
||||
}
|
||||
return isMatch
|
||||
if (m.id === formData.motherId) return true
|
||||
return m.gender === "FEMALE" && m.generation === (formData.generation || 1) - 1
|
||||
})
|
||||
.map((m) => (
|
||||
<SelectItem key={m.id} value={m.id}>
|
||||
|
||||
Reference in New Issue
Block a user