421 lines
14 KiB
HTML
421 lines
14 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="ru" translate="no" class="notranslate">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="google" content="notranslate">
|
|
<meta name="googlebot" content="notranslate">
|
|
<meta http-equiv="Content-Language" content="ru">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Main</title>
|
|
<style>
|
|
:root {
|
|
--bg-color: #f5f5f5;
|
|
--text-color: #333;
|
|
--weight-color: #121a22;
|
|
--modal-bg: white;
|
|
--button-shadow: rgba(0, 0, 0, 0.2);
|
|
}
|
|
|
|
[data-theme="dark"] {
|
|
--bg-color: #1a1a1a;
|
|
--text-color: #e0e0e0;
|
|
--weight-color: #ffffff;
|
|
--modal-bg: #2d2d2d;
|
|
--button-shadow: rgba(255, 255, 255, 0.1);
|
|
}
|
|
|
|
body, html {
|
|
margin: 0;
|
|
padding: 0;
|
|
height: 100%;
|
|
font-family: Arial, sans-serif;
|
|
background-color: var(--bg-color);
|
|
color: var(--text-color);
|
|
display: flex;
|
|
flex-direction: column;
|
|
align-items: center;
|
|
justify-content: center;
|
|
transition: background-color 0.3s ease, color 0.3s ease;
|
|
}
|
|
|
|
.nav-button {
|
|
position: fixed;
|
|
top: 25px;
|
|
right: 25px;
|
|
background-color: #3498db;
|
|
color: white;
|
|
border: none;
|
|
padding: 15px;
|
|
border-radius: 50%;
|
|
width: 60px;
|
|
height: 60px;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
cursor: pointer;
|
|
z-index: 1000;
|
|
transition: background-color 0.3s ease, transform 0.2s ease;
|
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
|
|
font-size: 32px;
|
|
}
|
|
|
|
.nav-button:hover {
|
|
background-color: #2980b9;
|
|
transform: scale(1.1);
|
|
}
|
|
|
|
|
|
.modal-overlay {
|
|
display: none;
|
|
position: fixed;
|
|
top: 0;
|
|
left: 0;
|
|
width: 100%;
|
|
height: 100%;
|
|
background-color: rgba(0, 0, 0, 0.5);
|
|
z-index: 999;
|
|
}
|
|
|
|
.modal {
|
|
position: fixed;
|
|
top: 50%;
|
|
left: 50%;
|
|
transform: translate(-50%, -50%);
|
|
background-color: var(--modal-bg);
|
|
padding: 20px;
|
|
border-radius: 10px;
|
|
box-shadow: 0 2px 10px var(--button-shadow);
|
|
z-index: 1000;
|
|
width: 300px;
|
|
text-align: center;
|
|
}
|
|
|
|
.modal a {
|
|
display: block;
|
|
color: #3498db;
|
|
text-decoration: none;
|
|
font-weight: 500;
|
|
padding: 10px;
|
|
border-radius: 5px;
|
|
transition: background 0.3s ease;
|
|
margin: 10px 0;
|
|
}
|
|
|
|
.modal a:hover {
|
|
background: #f0f0f0;
|
|
}
|
|
|
|
.modal-logo {
|
|
height: 40px;
|
|
width: auto;
|
|
margin-bottom: 15px;
|
|
/* Делаем логотип белым */
|
|
}
|
|
|
|
.current-weight {
|
|
width: 100%;
|
|
font-size: 30vw;
|
|
font-weight: bold;
|
|
color: var(--weight-color);
|
|
transition: all 0.5s ease;
|
|
text-align: center;
|
|
line-height: 1;
|
|
display: flex;
|
|
align-items: center;
|
|
justify-content: center;
|
|
padding: 20px;
|
|
flex-grow: 1;
|
|
}
|
|
|
|
.controls {
|
|
margin-bottom: 40px;
|
|
display: flex;
|
|
gap: 20px;
|
|
margin-top: auto;
|
|
padding-bottom: 40px;
|
|
}
|
|
|
|
.control-button {
|
|
color: white;
|
|
border: none;
|
|
padding: 15px 30px;
|
|
border-radius: 8px;
|
|
font-size: 1.8rem;
|
|
cursor: pointer;
|
|
transition: all 0.3s ease;
|
|
min-width: 200px;
|
|
text-align: center;
|
|
}
|
|
|
|
.reset-button {
|
|
background-color: #3498db;
|
|
}
|
|
|
|
.start-button {
|
|
background-color: #2ecc71;
|
|
}
|
|
|
|
.reset-button:hover {
|
|
background-color: #2980b9;
|
|
transform: scale(1.05);
|
|
}
|
|
|
|
.start-button:hover {
|
|
background-color: #27ae60;
|
|
transform: scale(1.05);
|
|
}
|
|
|
|
.connection-status {
|
|
position: fixed;
|
|
bottom: 10px;
|
|
left: 10px;
|
|
padding: 5px 10px;
|
|
border-radius: 15px;
|
|
font-size: 12px;
|
|
background-color: #e74c3c;
|
|
color: white;
|
|
transition: all 0.3s;
|
|
}
|
|
|
|
.connection-status.connected {
|
|
background-color: #2ecc71;
|
|
}
|
|
|
|
/* Переключатель темы из kiosk-theme.js: правый нижний угол, ниже блока веса */
|
|
#wespThemeToggleWrap {
|
|
top: auto !important;
|
|
left: auto !important;
|
|
right: 16px;
|
|
bottom: 52px;
|
|
}
|
|
|
|
@media (max-width: 768px) {
|
|
#wespThemeToggleWrap {
|
|
right: 12px;
|
|
bottom: 48px;
|
|
}
|
|
|
|
.current-weight {
|
|
font-size: 25vw;
|
|
}
|
|
|
|
.controls {
|
|
flex-direction: column;
|
|
gap: 15px;
|
|
}
|
|
|
|
.control-button {
|
|
padding: 12px 24px;
|
|
font-size: 1.4rem;
|
|
min-width: 160px;
|
|
}
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<button class="nav-button" id="kioskMenuButton" title="Меню">☰</button>
|
|
|
|
<div class="current-weight" id="currentWeight">×﹏×</div>
|
|
|
|
<div class="controls">
|
|
<button class="control-button reset-button" onclick="resetWeight()">Обнулить</button>
|
|
<a href="/api/recipes_wibor"><button class="control-button start-button">Начать работу</button></a>
|
|
</div>
|
|
|
|
<div class="connection-status" id="connectionStatus">Нет соединения</div>
|
|
|
|
<script src="/static/js/kiosk-dialog.js"></script>
|
|
<script>
|
|
let kioskPaired = false;
|
|
const DEVICE_TOKEN_KEY = 'wespDeviceToken';
|
|
function getDeviceToken() {
|
|
const params = new URLSearchParams(window.location.search);
|
|
const tokenFromQuery = (params.get('device_token') || '').trim();
|
|
if (tokenFromQuery) {
|
|
localStorage.setItem(DEVICE_TOKEN_KEY, tokenFromQuery);
|
|
return tokenFromQuery;
|
|
}
|
|
return (localStorage.getItem(DEVICE_TOKEN_KEY) || '').trim();
|
|
}
|
|
function withDeviceToken(url) {
|
|
const token = getDeviceToken();
|
|
if (!token) return url;
|
|
const u = new URL(url, window.location.origin);
|
|
u.searchParams.set('device_token', token);
|
|
return `${u.pathname}${u.search}`;
|
|
}
|
|
function buildHeaders(extra = {}) {
|
|
const headers = { ...extra };
|
|
const token = getDeviceToken();
|
|
if (token) headers['X-Device-Token'] = token;
|
|
return headers;
|
|
}
|
|
|
|
let eventSource;
|
|
let reconnectAttempts = 0;
|
|
const maxReconnectAttempts = 5;
|
|
const reconnectDelay = 3000;
|
|
const statusElement = document.getElementById('connectionStatus');
|
|
|
|
async function fetchCurrentWeight() {
|
|
if (!kioskPaired) return;
|
|
try {
|
|
const response = await fetch(withDeviceToken('/current_weight'), { headers: buildHeaders() });
|
|
if (!response.ok) return;
|
|
const data = await response.json();
|
|
const weight = Number(data.weight ?? 0);
|
|
document.getElementById('currentWeight').textContent = String(Math.round(weight));
|
|
} catch (e) {
|
|
console.error('current_weight:', e);
|
|
}
|
|
}
|
|
|
|
function initSSE() {
|
|
if (!kioskPaired) {
|
|
return;
|
|
}
|
|
// Закрываем предыдущее соединение, если оно есть
|
|
if (eventSource) {
|
|
eventSource.close();
|
|
}
|
|
|
|
// Добавляем случайный параметр для предотвращения кеширования
|
|
const url = withDeviceToken('/stream_weight?r=' + Math.random().toString(36).substring(7));
|
|
|
|
eventSource = new EventSource(url);
|
|
fetchCurrentWeight();
|
|
|
|
eventSource.onopen = () => {
|
|
console.log('SSE соединение установлено');
|
|
statusElement.textContent = 'Подключено';
|
|
statusElement.classList.add('connected');
|
|
reconnectAttempts = 0;
|
|
fetchCurrentWeight();
|
|
};
|
|
|
|
eventSource.onmessage = (e) => {
|
|
const payload = JSON.parse(e.data || '{}');
|
|
const weight = Number(payload.weight || 0);
|
|
document.getElementById('currentWeight').textContent = String(Math.round(weight));
|
|
};
|
|
|
|
eventSource.onerror = (e) => {
|
|
console.error('Ошибка SSE:', e);
|
|
statusElement.textContent = 'Переподключение...';
|
|
statusElement.classList.remove('connected');
|
|
|
|
eventSource.close();
|
|
|
|
if (reconnectAttempts < maxReconnectAttempts) {
|
|
setTimeout(initSSE, reconnectDelay);
|
|
reconnectAttempts++;
|
|
} else {
|
|
statusElement.textContent = 'Соединение потеряно';
|
|
void WespKioskDialog.alert(
|
|
'Не удалось подключиться к терминалу. Пожалуйста, проверьте WIFI и обновите страницу.',
|
|
{ variant: 'danger' }
|
|
);
|
|
}
|
|
};
|
|
}
|
|
|
|
// Обработчик видимости страницы
|
|
document.addEventListener('visibilitychange', () => {
|
|
if (document.visibilityState === 'visible') {
|
|
initSSE();
|
|
} else {
|
|
if (eventSource) {
|
|
eventSource.close();
|
|
statusElement.textContent = 'Фоновый режим';
|
|
statusElement.classList.remove('connected');
|
|
}
|
|
}
|
|
});
|
|
|
|
// Инициализация SSE выполняется только после успешной проверки pairing.
|
|
|
|
let bratEasterEggClicks = 0;
|
|
|
|
function maybeBratEasterEgg() {
|
|
bratEasterEggClicks += 1;
|
|
if (bratEasterEggClicks < 10) return;
|
|
bratEasterEggClicks = 0;
|
|
const text =
|
|
'Короче избранный, я тебя спас и в благородства играть не буду. Лучше делом займись!';
|
|
void WespKioskDialog.alert(text, {
|
|
title: 'Брат',
|
|
variant: 'success',
|
|
timerOnly: true,
|
|
});
|
|
setTimeout(function () {
|
|
if (typeof WespKioskDialog.closeActive === 'function') {
|
|
WespKioskDialog.closeActive();
|
|
}
|
|
}, 10000);
|
|
}
|
|
|
|
async function resetWeight() {
|
|
maybeBratEasterEgg();
|
|
if (!kioskPaired) return;
|
|
try {
|
|
const response = await fetch('/tare', { method: 'POST', headers: buildHeaders() });
|
|
const data = await response.json();
|
|
// Обнуление выполнено без отображения уведомления
|
|
} catch (error) {
|
|
console.error('Ошибка:', error);
|
|
}
|
|
}
|
|
|
|
// Закрываем соединение при выходе
|
|
window.addEventListener('beforeunload', () => {
|
|
if (eventSource) {
|
|
eventSource.close();
|
|
}
|
|
});
|
|
|
|
// Периодическая проверка соединения
|
|
setInterval(() => {
|
|
if (eventSource && eventSource.readyState === EventSource.CLOSED) {
|
|
initSSE();
|
|
}
|
|
}, 10000);
|
|
|
|
</script>
|
|
<script src="/static/js/kiosk-theme.js"></script>
|
|
<script src="/static/js/kiosk-nav-menu.js"></script>
|
|
<script src="/static/js/kiosk-pairing.js"></script>
|
|
<script src="/static/js/kiosk-db-check.js"></script>
|
|
<script src="/static/js/kiosk-calibration.js"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
window.WespKioskTheme.setup({ withToggle: true });
|
|
window.WespKioskMenu.setup({ menuButtonSelector: '#kioskMenuButton' });
|
|
window.WespKioskDbCheck.setup({ menuLinkSelector: '#dbCheckLink' });
|
|
window.WespKioskCalibration.setup({ menuLinkSelector: '#calibrationLink' });
|
|
window.WespKioskPairing.setup({
|
|
menuLinkSelector: '#pairTerminalLink',
|
|
onPaired: function () {
|
|
kioskPaired = true;
|
|
fetchCurrentWeight();
|
|
initSSE();
|
|
},
|
|
onUnpaired: function () {
|
|
kioskPaired = false;
|
|
if (eventSource) {
|
|
eventSource.close();
|
|
}
|
|
}
|
|
});
|
|
});
|
|
</script>
|
|
<link href="/static/css/wesp-update-banner.css" rel="stylesheet">
|
|
<script src="/static/js/wesp-update-notifier.js"></script>
|
|
<script>
|
|
document.addEventListener("DOMContentLoaded", function () {
|
|
if (window.WespUpdateNotifier) {
|
|
WespUpdateNotifier.init({ dialog: window.WespKioskDialog || window.WespDialog });
|
|
}
|
|
});
|
|
</script>
|
|
</body>
|
|
</html> |