Verbessere die Sortierlogik in der Mitgliederliste für Namen, Nachnamen und Geburtstage mit robusteren Vergleichen
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 52s
Some checks failed
Code Analysis (JS/Vue) / analyze (push) Failing after 52s
This commit is contained in:
@@ -764,17 +764,45 @@ const sortedMembers = computed(() => {
|
||||
if (!Array.isArray(members.value)) return []
|
||||
const arr = [...members.value]
|
||||
if (sortMode.value === 'name') {
|
||||
arr.sort((a, b) => (a.name || '').localeCompare(b.name || ''))
|
||||
arr.sort((a, b) => {
|
||||
const an = (a.name || '').toLocaleLowerCase()
|
||||
const bn = (b.name || '').toLocaleLowerCase()
|
||||
return an.localeCompare(bn)
|
||||
})
|
||||
} else if (sortMode.value === 'lastname') {
|
||||
arr.sort((a, b) => (a.lastName || '').localeCompare(b.lastName || ''))
|
||||
arr.sort((a, b) => {
|
||||
// Fallback: lastName, dann firstName
|
||||
const al = (a.lastName || a.name?.split(' ').slice(-1)[0] || '').toLocaleLowerCase()
|
||||
const bl = (b.lastName || b.name?.split(' ').slice(-1)[0] || '').toLocaleLowerCase()
|
||||
if (al === bl) {
|
||||
const af = (a.firstName || a.name?.split(' ')[0] || '').toLocaleLowerCase()
|
||||
const bf = (b.firstName || b.name?.split(' ')[0] || '').toLocaleLowerCase()
|
||||
return af.localeCompare(bf)
|
||||
}
|
||||
return al.localeCompare(bl)
|
||||
})
|
||||
} else if (sortMode.value === 'birthday') {
|
||||
arr.sort((a, b) => {
|
||||
if (!a.birthday) return 1
|
||||
if (!b.birthday) return -1
|
||||
// Nur Tag und Monat vergleichen
|
||||
const [ay, am, ad] = a.birthday.split('-')
|
||||
const [by, bm, bd] = b.birthday.split('-')
|
||||
return (am + ad).localeCompare(bm + bd)
|
||||
// Robust: akzeptiere YYYY-MM-DD, DD.MM.YYYY, ggf. nur MM-TT
|
||||
function parseBirthday(val) {
|
||||
if (!val) return null
|
||||
if (val.includes('-')) {
|
||||
const parts = val.split('-')
|
||||
if (parts.length === 3) return { m: parts[1].padStart(2, '0'), d: parts[2].padStart(2, '0') }
|
||||
} else if (val.includes('.')) {
|
||||
const parts = val.split('.')
|
||||
if (parts.length >= 2) return { d: parts[0].padStart(2, '0'), m: parts[1].padStart(2, '0') }
|
||||
}
|
||||
return null
|
||||
}
|
||||
const ad = parseBirthday(a.birthday)
|
||||
const bd = parseBirthday(b.birthday)
|
||||
if (!ad && !bd) return 0
|
||||
if (!ad) return 1
|
||||
if (!bd) return -1
|
||||
// Monat zuerst, dann Tag
|
||||
if (ad.m === bd.m) return ad.d.localeCompare(bd.d)
|
||||
return ad.m.localeCompare(bd.m)
|
||||
})
|
||||
}
|
||||
return arr
|
||||
|
||||
Reference in New Issue
Block a user