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