Files
ignis-core/static/index.html
Артём Кокос 298dcbc277 DELETE groups
2026-02-12 23:37:15 +07:00

200 lines
12 KiB
HTML

<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ignis Control Center</title>
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
<script src="https://cdn.tailwindcss.com"></script>
<style>
body { background: #0f172a; color: #f8fafc; font-family: 'Inter', sans-serif; }
.card { background: #1e293b; border: 1px solid #334155; }
.btn-primary { @apply bg-orange-600 hover:bg-orange-500 text-white px-4 py-2 rounded-xl font-bold transition-all disabled:opacity-50; }
/* ЖЕСТКО ЗАДАННЫЕ СТИЛИ ДЛЯ ИНПУТОВ */
.input-dark {
background-color: #0f172a !important;
color: #ffffff !important;
border: 1px solid #334155;
border-radius: 0.75rem;
padding: 0.75rem 1rem;
outline: none;
width: 100%;
}
.input-dark:focus { border-color: #f97316; }
.input-dark::placeholder { color: #64748b; }
.temp-gradient { background: linear-gradient(to right, #ffb366, #ffffff, #99ccff); }
input[type="range"] { -webkit-appearance: none; height: 8px; border-radius: 4px; background: #334155; }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; background: white; border-radius: 50%; border: 2px solid #f97316; cursor: pointer; }
</style>
</head>
<body>
<div id="app" class="p-4 md:p-8 max-w-5xl mx-auto">
<header class="mb-10 flex justify-between items-center">
<div class="flex items-center gap-3">
<span class="text-4xl">🔥</span>
<h1 class="text-3xl font-black text-orange-500 tracking-tighter uppercase">Ignis</h1>
</div>
<div class="flex gap-2 bg-slate-800/50 p-1 rounded-2xl border border-slate-700">
<button @click="tab = 'control'" :class="tab === 'control' ? 'bg-slate-700 text-white shadow-lg' : 'text-slate-400'" class="px-6 py-2 rounded-xl font-bold transition-all">Пульт</button>
<button @click="tab = 'admin'" :class="tab === 'admin' ? 'bg-slate-700 text-white shadow-lg' : 'text-slate-400'" class="px-6 py-2 rounded-xl font-bold transition-all">Настройки</button>
</div>
</header>
<main v-if="tab === 'control'" class="space-y-6">
<div v-if="Object.keys(groups).length === 0" class="text-center py-20 opacity-50 uppercase tracking-widest">Групп пока нет. Зайди в настройки.</div>
<div class="grid grid-cols-1 md:grid-cols-2 gap-8">
<div v-for="(group, id) in groups" :key="id" class="card p-6 rounded-3xl shadow-2xl">
<div class="flex justify-between items-center mb-6">
<h2 class="text-2xl font-bold text-slate-100">{{ group.name }}</h2>
<div class="flex gap-2">
<button @click="toggleGroup(id, true)" class="bg-orange-600 hover:bg-orange-500 px-4 py-1 rounded-lg text-sm font-bold transition-all">ВКЛ</button>
<button @click="toggleGroup(id, false)" class="bg-slate-700 hover:bg-slate-600 px-4 py-1 rounded-lg text-sm font-bold transition-all">ВЫКЛ</button>
</div>
</div>
<div class="space-y-6">
<div>
<div class="flex justify-between text-[10px] font-black uppercase text-slate-500 mb-2"><span>Яркость</span><span class="text-orange-400">{{ group.brightness || 100 }}%</span></div>
<input type="range" min="10" max="100" class="w-full" v-model="group.brightness" @change="setBrightness(id, $event.target.value)">
</div>
<div>
<div class="flex justify-between text-[10px] font-black uppercase text-slate-500 mb-2"><span>Температура</span><span class="text-blue-400">{{ group.temp || 3000 }}K</span></div>
<input type="range" min="2700" max="6500" step="100" class="w-full temp-gradient" v-model="group.temp" @change="setTemp(id, $event.target.value)">
</div>
<div class="grid grid-cols-2 gap-4">
<div>
<label class="text-[10px] font-black uppercase text-slate-500 mb-2 block">Цвет</label>
<input type="color" class="w-full h-10 bg-transparent border border-slate-700 rounded-lg cursor-pointer" @input="setColor(id, $event.target.value)">
</div>
<div>
<label class="text-[10px] font-black uppercase text-slate-500 mb-2 block">Сцены</label>
<div class="flex flex-wrap gap-1">
<button v-for="s in ['ocean', 'party', 'steampunk', 'fireplace']" @click="setScene(id, s)" class="text-[8px] font-bold border border-slate-700 px-2 py-1 rounded hover:bg-slate-800 uppercase transition-all">{{s}}</button>
</div>
</div>
</div>
</div>
</div>
</div>
</main>
<main v-if="tab === 'admin'" class="space-y-10">
<section class="card p-6 rounded-3xl">
<div class="flex justify-between items-center mb-6">
<h2 class="text-xl font-bold italic text-orange-400">Новая группа</h2>
<button @click="rescan" class="text-[10px] font-black bg-blue-600/10 text-blue-400 border border-blue-500/20 px-4 py-2 rounded-xl hover:bg-blue-600/20 transition-all">
🔄 ПЕРЕСКАН СЕТИ
</button>
</div>
<div class="flex flex-col md:flex-row gap-4 mb-8">
<input v-model="newGroup.id" placeholder="ID (например: kitchen)" class="input-dark">
<input v-model="newGroup.name" placeholder="Имя (например: Кухня)" class="input-dark">
<button @click="createGroup" :disabled="!newGroup.id || !newGroup.macs.length" class="btn-primary min-w-[140px]">СОЗДАТЬ</button>
</div>
<div>
<p class="text-xs font-black text-slate-500 mb-4 uppercase tracking-widest">Доступные лампы в сети:</p>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
<div v-for="dev in devices" :key="dev.id"
class="flex items-center justify-between p-4 bg-slate-900/50 rounded-2xl border border-slate-700 hover:border-slate-500 transition-all">
<label class="flex items-center gap-3 cursor-pointer flex-1">
<input type="checkbox" :value="dev.id" v-model="newGroup.macs" class="w-5 h-5 accent-orange-500">
<div class="text-xs">
<div class="font-bold text-slate-200">{{ dev.id }}</div>
<div class="text-slate-500 font-mono text-[10px]">{{ dev.ip }}</div>
</div>
</label>
<button @click="blink(dev.id)" class="p-2 hover:bg-orange-500/20 rounded-xl text-orange-400 transition-all">
👁️
</button>
</div>
</div>
</div>
</section>
<section class="card p-6 rounded-3xl">
<h2 class="text-xl font-bold mb-6 text-slate-400 uppercase tracking-tighter">Управление группами в базе</h2>
<div class="grid grid-cols-1 gap-3">
<div v-for="(group, id) in groups" :key="id" class="flex justify-between items-center p-5 bg-slate-900/30 rounded-2xl border border-slate-800">
<div>
<div class="font-bold text-slate-100 text-lg">{{ group.name }}</div>
<div class="text-[10px] text-slate-500 font-mono uppercase tracking-widest">{{ id }} • {{ group.device_ids.length }} ламп</div>
</div>
<button @click="deleteGroup(id)" class="text-red-500 text-[10px] font-black border border-red-500/20 px-4 py-2 rounded-xl hover:bg-red-500 hover:text-white transition-all">
УДАЛИТЬ
</button>
</div>
</div>
</section>
</main>
</div>
<script>
const { createApp } = Vue
createApp({
data() {
return {
tab: 'control',
groups: {},
devices: {},
newGroup: { id: '', name: '', macs: [] }
}
},
methods: {
async fetchData() {
try {
const gResp = await fetch('/groups');
this.groups = await gResp.json();
const dResp = await fetch('/devices');
this.devices = await dResp.json();
} catch (e) { console.error("Ошибка сети", e); }
},
async control(id, params) {
const query = new URLSearchParams(params).toString();
await fetch(`/control/group/${id}?${query}`, { method: 'POST' });
},
async createGroup() {
const resp = await fetch('/groups', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ id: this.newGroup.id, name: this.newGroup.name, macs: this.newGroup.macs })
});
if(resp.ok) {
this.newGroup = { id: '', name: '', macs: [] };
await this.fetchData();
this.tab = 'control';
}
},
async deleteGroup(id) {
if(!confirm(`Удалить группу "${id}" из базы навсегда?`)) return;
const resp = await fetch(`/groups/${id}`, { method: 'DELETE' });
if(resp.ok) await this.fetchData();
},
async rescan() {
await fetch('/discovery/rescan', { method: 'POST' });
await this.fetchData();
},
async blink(deviceId) {
await fetch(`/control/device/${deviceId}/blink`, { method: 'POST' });
},
toggleGroup(id, state) { this.control(id, { state }); },
setBrightness(id, val) { this.control(id, { brightness: val }); },
setTemp(id, val) { this.control(id, { temp: val }); },
setScene(id, scene) { this.control(id, { scene }); },
setColor(id, hex) {
const r = parseInt(hex.slice(1, 3), 16), g = parseInt(hex.slice(3, 5), 16), b = parseInt(hex.slice(5, 7), 16);
this.control(id, { r, g, b });
}
},
mounted() {
this.fetchData();
setInterval(this.fetchData, 5000);
}
}).mount('#app')
</script>
</body>
</html>