fix: micropatch NodesStatus

This commit is contained in:
austnv
2026-06-21 21:50:00 +03:00
parent 3a38b3f7fa
commit e6ab2667c9
+20 -12
View File
@@ -44,7 +44,6 @@
</div> </div>
<div class="flex items-center gap-4"> <div class="flex items-center gap-4">
<!-- Пинг -->
<span <span
v-if="host.ping !== undefined && host.ping !== null" v-if="host.ping !== undefined && host.ping !== null"
class="font-mono font-semibold flex items-center gap-1 min-w-[60px] justify-end" class="font-mono font-semibold flex items-center gap-1 min-w-[60px] justify-end"
@@ -59,7 +58,6 @@
</span> </span>
<span v-else class="text-gray-300 min-w-[60px] text-right"></span> <span v-else class="text-gray-300 min-w-[60px] text-right"></span>
<!-- Кнопка пинга -->
<button <button
@click="pingSingleHost(host)" @click="pingSingleHost(host)"
:disabled="host.pinging" :disabled="host.pinging"
@@ -90,21 +88,31 @@ let interval = null
const countriesList = getAllCountries() const countriesList = getAllCountries()
const findCountryByName = (countryName) => { // Поиск страны по первому слову в названии
if (!countryName) return null const findCountryByFirstWord = (name) => {
const found = countriesList.find(c => c.label.toLowerCase() === countryName.toLowerCase()) if (!name) return null
if (found) return found
// Берём первое слово из названия
const firstWord = name.split(' ')[0]
if (!firstWord) return null
// Ищем точное совпадение
const exact = countriesList.find(c =>
c.label.toLowerCase() === firstWord.toLowerCase()
)
if (exact) return exact
// Ищем частичное совпадение
const partial = countriesList.find(c => const partial = countriesList.find(c =>
countryName.toLowerCase().includes(c.label.toLowerCase()) || firstWord.toLowerCase().includes(c.label.toLowerCase()) ||
c.label.toLowerCase().includes(countryName.toLowerCase()) c.label.toLowerCase().includes(firstWord.toLowerCase())
) )
return partial || null return partial || null
} }
// Сортировка по пингу (меньше -> выше) // Сортировка по пингу
const sortedHosts = computed(() => { const sortedHosts = computed(() => {
return [...hosts.value].sort((a, b) => { return [...hosts.value].sort((a, b) => {
// Если пинг null -> в конец
if (a.ping === null && b.ping === null) return 0 if (a.ping === null && b.ping === null) return 0
if (a.ping === null) return 1 if (a.ping === null) return 1
if (b.ping === null) return -1 if (b.ping === null) return -1
@@ -161,7 +169,7 @@ const fetchHosts = async () => {
const data = await res.json() const data = await res.json()
hosts.value = data.map((h) => { hosts.value = data.map((h) => {
const country = findCountryByName(h.name) const country = findCountryByFirstWord(h.name)
return { return {
...h, ...h,
countryCode: country?.code?.toLowerCase() || null, countryCode: country?.code?.toLowerCase() || null,
@@ -190,4 +198,4 @@ onMounted(() => {
interval = setInterval(refreshData, 30000) interval = setInterval(refreshData, 30000)
}) })
onUnmounted(() => clearInterval(interval)) onUnmounted(() => clearInterval(interval))
</script>s </script>