Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6a9b2ca31d | ||
|
|
17a8db543e | ||
|
|
68aabbb361 | ||
|
|
6e841b12f5 | ||
|
|
7f227fcf05 | ||
|
|
a34a646c71 | ||
|
|
4a0ce08338 |
+3
-2
@@ -1,12 +1,13 @@
|
|||||||
{
|
{
|
||||||
"name": "frontend",
|
"name": "frontend",
|
||||||
"version": "0.9.5",
|
"version": "0.9.7",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"dev": "vite",
|
"dev": "vite",
|
||||||
"build": "vite build",
|
"build": "vite build",
|
||||||
"preview": "vite preview"
|
"preview": "vite preview",
|
||||||
|
"postbuild": "scp -r dist/. root@uvpn.shop:/opt/uvpn.shop/frontend"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@lucide/vue": "^1.16.0",
|
"@lucide/vue": "^1.16.0",
|
||||||
|
|||||||
@@ -1,18 +1,20 @@
|
|||||||
<template>
|
<template>
|
||||||
<section class="px-6 py-20 md:px-12 max-w-7xl mx-auto">
|
<section class="px-6 py-20 md:px-12 max-w-7xl mx-auto">
|
||||||
<div class="flex items-center justify-between mb-10 flex-wrap gap-4">
|
<div class="mb-10">
|
||||||
<h2 class="text-3xl md:text-4xl font-bold">
|
<h2 class="text-3xl md:text-4xl font-bold text-center mb-14">
|
||||||
Статус серверов
|
Статус серверов
|
||||||
</h2>
|
</h2>
|
||||||
|
<div class="flex justify-center mt-6">
|
||||||
<button
|
<button
|
||||||
@click="refreshData"
|
@click="refreshData"
|
||||||
:disabled="loading"
|
:disabled="loading"
|
||||||
class="px-5 py-2.5 bg-blue-600 hover:bg-blue-700 text-white rounded-xl text-sm font-medium transition disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2"
|
class="px-5 py-2.5 bg-blue-600 hover:bg-blue-700 text-white rounded-xl text-sm font-medium transition disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2 cursor-pointer"
|
||||||
>
|
>
|
||||||
<RefreshCw :size="16" :class="{ 'animate-spin': loading }" />
|
<RefreshCw :size="16" :class="{ 'animate-spin': loading }" />
|
||||||
{{ loading ? 'Обновление...' : 'Обновить пинг' }}
|
{{ loading ? 'Обновление...' : 'Обновить пинг' }}
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div v-if="loading && !hosts.length" class="flex justify-center py-12">
|
<div v-if="loading && !hosts.length" class="flex justify-center py-12">
|
||||||
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
|
<div class="animate-spin rounded-full h-12 w-12 border-b-2 border-blue-600"></div>
|
||||||
@@ -24,25 +26,26 @@
|
|||||||
<div
|
<div
|
||||||
v-for="host in sortedHosts"
|
v-for="host in sortedHosts"
|
||||||
:key="host.address"
|
:key="host.address"
|
||||||
class="flex items-center justify-between bg-white dark:bg-gray-900 rounded-xl px-4 py-2.5 border transition hover:shadow-md"
|
class="flex items-center justify-between bg-white dark:bg-gray-900 rounded-xl px-4 py-2.5 border"
|
||||||
:class="host.isOnline ? 'border-green-500/30' : 'border-red-500/30 opacity-60'"
|
:class="host.isOnline ? 'border-green-500/30' : 'border-red-500/30 opacity-60'"
|
||||||
>
|
>
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
<img
|
<img
|
||||||
v-if="host.countryCode"
|
v-if="host.countryCode"
|
||||||
:src="`https://cdn.jsdelivr.net/npm/flag-icons@7.2.3/flags/4x3/${host.countryCode}.svg`"
|
:src="`https://cdn.jsdelivr.net/npm/flag-icons@7.2.3/flags/4x3/${host.countryCode.toLowerCase()}.svg`"
|
||||||
class="h-5 w-auto rounded-sm"
|
class="h-5 w-auto rounded-sm"
|
||||||
|
:alt="host.name"
|
||||||
/>
|
/>
|
||||||
<span class="font-semibold text-gray-800 dark:text-white">{{ host.name }}</span>
|
<span class="font-semibold text-gray-800 dark:text-white">{{ host.name }}</span>
|
||||||
|
|
||||||
<!-- Индикатор состояния (вместо online/offline) -->
|
<!-- Индикатор состояния -->
|
||||||
<span class="relative flex h-3 w-3">
|
<span class="relative flex h-2 w-2">
|
||||||
<span
|
<span
|
||||||
class="animate-ping absolute inline-flex h-full w-full rounded-full opacity-75"
|
class="animate-ping absolute inline-flex h-full w-full rounded-full opacity-75"
|
||||||
:class="host.isOnline ? 'bg-green-500' : 'bg-red-500'"
|
:class="host.isOnline ? 'bg-green-500' : 'bg-red-500'"
|
||||||
></span>
|
></span>
|
||||||
<span
|
<span
|
||||||
class="relative inline-flex rounded-full h-3 w-3"
|
class="relative inline-flex rounded-full h-2 w-2"
|
||||||
:class="host.isOnline ? 'bg-green-600' : 'bg-red-600'"
|
:class="host.isOnline ? 'bg-green-600' : 'bg-red-600'"
|
||||||
></span>
|
></span>
|
||||||
</span>
|
</span>
|
||||||
@@ -71,58 +74,11 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted } from 'vue'
|
import { ref, computed, onMounted } from 'vue'
|
||||||
import { Wifi, RefreshCw } from '@lucide/vue'
|
import { Wifi, RefreshCw } from '@lucide/vue'
|
||||||
import { getAllCountries } from '@tw-labs/countries'
|
|
||||||
|
|
||||||
const hosts = ref([])
|
const hosts = ref([])
|
||||||
const loading = ref(true)
|
const loading = ref(true)
|
||||||
const error = ref(null)
|
const error = ref(null)
|
||||||
|
|
||||||
const countriesList = getAllCountries()
|
|
||||||
|
|
||||||
// Ручной маппинг для проблемных стран
|
|
||||||
const countryOverrides = {
|
|
||||||
'United States': 'us',
|
|
||||||
'USA': 'us',
|
|
||||||
'U.S.A.': 'us',
|
|
||||||
'America': 'us',
|
|
||||||
'United Arab Emirates': 'ae',
|
|
||||||
'UAE': 'ae',
|
|
||||||
}
|
|
||||||
|
|
||||||
const findCountryByFirstWord = (name) => {
|
|
||||||
if (!name) return null
|
|
||||||
|
|
||||||
// 1. Проверяем ручные override
|
|
||||||
const override = countryOverrides[name]
|
|
||||||
if (override) {
|
|
||||||
return { code: override.toUpperCase() }
|
|
||||||
}
|
|
||||||
|
|
||||||
// 2. Ищем по первому слову
|
|
||||||
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 =>
|
|
||||||
firstWord.toLowerCase().includes(c.label.toLowerCase()) ||
|
|
||||||
c.label.toLowerCase().includes(firstWord.toLowerCase())
|
|
||||||
)
|
|
||||||
if (partial) return partial
|
|
||||||
|
|
||||||
// 3. Пробуем найти по полному имени
|
|
||||||
const fullMatch = countriesList.find(c =>
|
|
||||||
name.toLowerCase().includes(c.label.toLowerCase()) ||
|
|
||||||
c.label.toLowerCase().includes(name.toLowerCase())
|
|
||||||
)
|
|
||||||
return fullMatch || null
|
|
||||||
}
|
|
||||||
|
|
||||||
const sortedHosts = computed(() => {
|
const sortedHosts = computed(() => {
|
||||||
return [...hosts.value].sort((a, b) => {
|
return [...hosts.value].sort((a, b) => {
|
||||||
if (a.ping === null && b.ping === null) return 0
|
if (a.ping === null && b.ping === null) return 0
|
||||||
@@ -155,17 +111,14 @@ const fetchHosts = async () => {
|
|||||||
if (!res.ok) throw new Error()
|
if (!res.ok) throw new Error()
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
|
|
||||||
hosts.value = data.map((h) => {
|
hosts.value = data.map((h) => ({
|
||||||
const country = findCountryByFirstWord(h.name)
|
|
||||||
return {
|
|
||||||
...h,
|
...h,
|
||||||
countryCode: country?.code?.toLowerCase() || null,
|
countryCode: h.country_code ? h.country_code.toLowerCase() : null,
|
||||||
isOnline: true,
|
isOnline: true,
|
||||||
ping: null,
|
ping: null,
|
||||||
}
|
}))
|
||||||
})
|
|
||||||
} catch {
|
} catch {
|
||||||
error.value = 'Ошибка загрузки'
|
error.value = 'Ошибка загрузки данных'
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
@@ -180,32 +133,28 @@ const refreshData = async () => {
|
|||||||
if (!res.ok) throw new Error()
|
if (!res.ok) throw new Error()
|
||||||
const data = await res.json()
|
const data = await res.json()
|
||||||
|
|
||||||
hosts.value = data.map((h) => {
|
hosts.value = data.map((h) => ({
|
||||||
const country = findCountryByFirstWord(h.name)
|
|
||||||
return {
|
|
||||||
...h,
|
...h,
|
||||||
countryCode: country?.code?.toLowerCase() || null,
|
countryCode: h.country_code ? h.country_code.toLowerCase() : null,
|
||||||
isOnline: true,
|
isOnline: true,
|
||||||
ping: null,
|
ping: null,
|
||||||
}
|
}))
|
||||||
})
|
|
||||||
|
|
||||||
|
// Пингуем все хосты параллельно
|
||||||
const pings = await Promise.all(hosts.value.map(h => pingHost(h)))
|
const pings = await Promise.all(hosts.value.map(h => pingHost(h)))
|
||||||
hosts.value.forEach((h, i) => {
|
hosts.value.forEach((h, i) => {
|
||||||
if (h.isOnline) h.ping = pings[i]
|
h.ping = pings[i]
|
||||||
})
|
})
|
||||||
|
|
||||||
} catch {
|
} catch {
|
||||||
error.value = 'Ошибка обновления'
|
error.value = 'Ошибка обновления данных'
|
||||||
} finally {
|
} finally {
|
||||||
loading.value = false
|
loading.value = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// При первом открытии — загружаем и пингуем
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
await fetchHosts()
|
await fetchHosts()
|
||||||
// Автоматический пинг только при первом открытии
|
|
||||||
await refreshData()
|
await refreshData()
|
||||||
})
|
})
|
||||||
</script>
|
</script>
|
||||||
Reference in New Issue
Block a user