From 93818c3a3e2bd6eb2c75a1153f3586de82bf3c99 Mon Sep 17 00:00:00 2001 From: gotika Date: Sat, 21 Sep 2024 18:39:58 +0300 Subject: [PATCH] glistik v popke --- src/App.js | 31 +++---- src/DeviceGroups.css | 48 ++++++++++ src/Devices.css | 38 ++++++++ src/Sidebar.css | 77 ++++++++++------ src/Sidebar.js | 65 ++++---------- src/pages/DeviceGroups.js | 87 ++++++++++++++++++ src/pages/Devices.js | 93 ++++++++++++++++++++ src/pages/DevicesPage.js | 180 -------------------------------------- 8 files changed, 349 insertions(+), 270 deletions(-) create mode 100644 src/DeviceGroups.css create mode 100644 src/Devices.css create mode 100644 src/pages/DeviceGroups.js create mode 100644 src/pages/Devices.js delete mode 100644 src/pages/DevicesPage.js diff --git a/src/App.js b/src/App.js index cfd1aab..804bd00 100644 --- a/src/App.js +++ b/src/App.js @@ -1,23 +1,24 @@ -import React from "react"; -import { BrowserRouter as Router, Route, Routes } from "react-router-dom"; +import React, { useState } from 'react'; +import DeviceGroups from "./pages/DeviceGroups"; +import Devices from "./pages/Devices"; import Sidebar from "./Sidebar"; -import Dashboard from "./pages/Dashboard"; -import DevicesPage from "./pages/DevicesPage"; // Добавляем страницу для управления устройствами +import Dashboard from './pages/Dashboard'; const App = () => { + const [activeTab, setActiveTab] = useState('map'); // По умолчанию активная вкладка "Карта" + return ( - -
- -
- - } /> {/* Главная страница с картой */} - } /> {/* Страница управления устройствами */} - -
+
+ {/* Передаем активную вкладку */} +
+ {activeTab === 'map' && } {/* Подключаем компонент Dashboard */} + {activeTab === 'connection' &&
Подключение
} + {activeTab === 'account' &&
Аккаунт пользователя
} + {activeTab === 'groups' && } {/* Группы устройств */} + {activeTab === 'devices' && } {/* Устройства */}
- +
); }; -export default App; +export default App; \ No newline at end of file diff --git a/src/DeviceGroups.css b/src/DeviceGroups.css new file mode 100644 index 0000000..607c540 --- /dev/null +++ b/src/DeviceGroups.css @@ -0,0 +1,48 @@ +.device-groups { + padding: 20px; +} + +.device-groups h2 { + margin-bottom: 20px; +} + +.group-creation { + margin-bottom: 20px; +} + +.group-creation input { + padding: 5px; + margin-right: 10px; +} + +.group-creation button { + padding: 5px 10px; +} + +ul { + list-style-type: none; + padding: 0; +} + +li { + margin-bottom: 20px; + padding: 10px; + border: 1px solid #ddd; + border-radius: 5px; +} + +.active { + background-color: #e8f5e9; +} + +.inactive { + background-color: #ffebee; +} + +li div { + margin-bottom: 10px; +} + +li button { + margin-right: 10px; +} \ No newline at end of file diff --git a/src/Devices.css b/src/Devices.css new file mode 100644 index 0000000..d63e831 --- /dev/null +++ b/src/Devices.css @@ -0,0 +1,38 @@ +.devices { + padding: 20px; +} + +.devices h2 { + margin-bottom: 20px; +} + +.devices table { + width: 100%; + border-collapse: collapse; +} + +.devices table, .devices th, .devices td { + border: 1px solid #ddd; +} + +.devices th, .devices td { + padding: 8px; + text-align: left; +} + +.devices th { + background-color: #34495e; + color: white; +} + +.devices tr:hover { + background-color: #f1f1f1; +} + +.buttons { + margin-top: 20px; +} + +.buttons button { + margin-right: 10px; +} \ No newline at end of file diff --git a/src/Sidebar.css b/src/Sidebar.css index 9b15b64..60f8b09 100644 --- a/src/Sidebar.css +++ b/src/Sidebar.css @@ -1,29 +1,50 @@ .sidebar { - width: 250px; - height: 100vh; - background-color: #2c3e50; - color: white; - padding: 20px; - box-shadow: 2px 0 5px rgba(0, 0, 0, 0.5); - } - - .sidebar h2 { - font-size: 24px; - margin-bottom: 20px; - } - - .sidebar ul { - list-style-type: none; - padding: 0; - } - - .sidebar li { - margin: 15px 0; - cursor: pointer; - } - - .sidebar li:hover { - background-color: #34495e; - padding: 10px; - border-radius: 5px; - } \ No newline at end of file + width: 250px; + height: 100vh; + background-color: #2c3e50; + color: white; + padding: 20px; + box-shadow: 2px 0 5px rgba(0, 0, 0, 0.5); +} + +.sidebar h2 { + font-size: 24px; + margin-bottom: 20px; +} + +.sidebar ul { + list-style-type: none; + padding: 0; +} + +.sidebar li { + margin: 15px 0; + cursor: pointer; +} + +.sidebar li:hover { + background-color: #34495e; + padding: 10px; + border-radius: 5px; +} +.sidebar ul { + list-style-type: none; + padding: 0; +} + +.sidebar li { + margin: 15px 0; + cursor: pointer; + padding: 10px; + border-radius: 5px; + transition: background-color 0.3s; +} + +.sidebar li:hover { + background-color: #34495e; +} + +.sidebar li.active { + background-color: #2980b9; + color: white; +} \ No newline at end of file diff --git a/src/Sidebar.js b/src/Sidebar.js index 910678c..1a288f0 100644 --- a/src/Sidebar.js +++ b/src/Sidebar.js @@ -1,58 +1,29 @@ -import React from "react"; -import { Link } from "react-router-dom"; +import React from 'react'; +import './Sidebar.css'; -const Sidebar = () => { +const Sidebar = ({ onSelectTab, activeTab }) => { return ( -
-

Навигация

-
    -
  • - Карта всех устройств +
    +

    Меню

    +
      +
    • onSelectTab('map')}> + Карта в реальном времени
    • -
    • - Устройства +
    • onSelectTab('connection')}> + Подключение
    • -
    • - Группы устройств +
    • onSelectTab('account')}> + Аккаунт пользователя +
    • +
    • onSelectTab('groups')}> + Группы устройств +
    • +
    • onSelectTab('devices')}> + Устройства
    ); }; -// Объект с инлайн-стилями -const styles = { - sidebar: { - width: '250px', - backgroundColor: '#2c3e50', - padding: '20px', - height: '100vh', - color: 'white', - boxShadow: '2px 0 5px rgba(0, 0, 0, 0.1)', - }, - heading: { - fontSize: '24px', - marginBottom: '20px', - color: '#ecf0f1', - borderBottom: '2px solid #34495e', - paddingBottom: '10px', - }, - list: { - listStyleType: 'none', - padding: '0', - }, - listItem: { - marginBottom: '15px', - }, - link: { - color: '#ecf0f1', - textDecoration: 'none', - fontSize: '18px', - display: 'block', - padding: '10px', - borderRadius: '4px', - transition: 'background-color 0.3s', - }, -}; - export default Sidebar; \ No newline at end of file diff --git a/src/pages/DeviceGroups.js b/src/pages/DeviceGroups.js new file mode 100644 index 0000000..2bc3609 --- /dev/null +++ b/src/pages/DeviceGroups.js @@ -0,0 +1,87 @@ +import React, { useState } from 'react'; +import '../DeviceGroups.css'; + +const DeviceGroups = () => { + const [groups, setGroups] = useState([]); + const [newGroupName, setNewGroupName] = useState(''); + + const createGroup = () => { + if (newGroupName) { + const newGroup = { + name: newGroupName, + devices: [], + active: true, + }; + setGroups([...groups, newGroup]); + setNewGroupName(''); + } + }; + + const deleteGroup = (groupName) => { + setGroups(groups.filter(group => group.name !== groupName)); + }; + + const toggleGroupStatus = (groupName) => { + setGroups(groups.map(group => + group.name === groupName ? { ...group, active: !group.active } : group + )); + }; + + const addDeviceToGroup = (groupName, device) => { + setGroups(groups.map(group => + group.name === groupName ? { ...group, devices: [...group.devices, device] } : group + )); + }; + + const removeDeviceFromGroup = (groupName, device) => { + setGroups(groups.map(group => + group.name === groupName ? { ...group, devices: group.devices.filter(d => d !== device) } : group + )); + }; + + return ( +
    +

    Группы устройств

    + +
    + setNewGroupName(e.target.value)} + placeholder="Название новой группы" + /> + +
    + +
      + {groups.map(group => ( +
    • +
      + {group.name} + + +
      + +
      +

      Устройства в группе:

      +
        + {group.devices.map((device, index) => ( +
      • + {device} +
      • + ))} +
      + +
      +
    • + ))} +
    +
    + ); +}; + +export default DeviceGroups; \ No newline at end of file diff --git a/src/pages/Devices.js b/src/pages/Devices.js new file mode 100644 index 0000000..adb5992 --- /dev/null +++ b/src/pages/Devices.js @@ -0,0 +1,93 @@ +import React, { useState } from 'react'; +import { QRCodeCanvas } from "qrcode.react"; +import '../Devices.css'; + +const Devices = () => { + const [devices, setDevices] = useState([]); + const [selectedDevice, setSelectedDevice] = useState(null); + const [deviceName, setDeviceName] = useState(''); + const [deviceStatus, setDeviceStatus] = useState(''); + + const addDevice = () => { + if (deviceName) { + const newDevice = { name: deviceName, status: deviceStatus || 'Неактивен', id: Date.now() }; + setDevices([...devices, newDevice]); + setDeviceName(''); + setDeviceStatus(''); + } + }; + + const removeDevice = () => { + if (selectedDevice) { + setDevices(devices.filter(device => device.id !== selectedDevice.id)); + setSelectedDevice(null); + } + }; + + const editDevice = () => { + if (selectedDevice) { + const updatedDevices = devices.map(device => + device.id === selectedDevice.id + ? { ...device, name: deviceName, status: deviceStatus } + : device + ); + setDevices(updatedDevices); + setSelectedDevice(null); + setDeviceName(''); + setDeviceStatus(''); + } + }; + + const generateQR = (device) => { + return ( + + ); + }; + + return ( +
    +

    Устройства

    + setDeviceName(e.target.value)} + /> + setDeviceStatus(e.target.value)} + /> + + + + + + + + + + + {devices.map((device) => ( + setSelectedDevice(device)}> + + + + + + ))} + +
    НазваниеСтатусQR КодДействия
    {device.name}{device.status}{generateQR(device)} + +
    +
    + + + +
    +
    + ); +}; + +export default Devices; \ No newline at end of file diff --git a/src/pages/DevicesPage.js b/src/pages/DevicesPage.js deleted file mode 100644 index e919589..0000000 --- a/src/pages/DevicesPage.js +++ /dev/null @@ -1,180 +0,0 @@ -import React, { useState } from "react"; -import { QRCodeCanvas } from "qrcode.react"; - -const DevicesPage = () => { - const [devices, setDevices] = useState([]); - const [newDeviceName, setNewDeviceName] = useState(""); - const [editDeviceId, setEditDeviceId] = useState(null); - const [editDeviceName, setEditDeviceName] = useState(""); - - const addDevice = () => { - if (newDeviceName) { - setDevices([...devices, { name: newDeviceName, id: Date.now() }]); - setNewDeviceName(""); - } - }; - - const removeDevice = (id) => { - setDevices(devices.filter((device) => device.id !== id)); - }; - - const startEditDevice = (device) => { - setEditDeviceId(device.id); - setEditDeviceName(device.name); - }; - - const saveDeviceEdit = () => { - setDevices( - devices.map((device) => - device.id === editDeviceId ? { ...device, name: editDeviceName } : device - ) - ); - setEditDeviceId(null); - setEditDeviceName(""); - }; - - return ( -
    -

    Устройства

    -
    - setNewDeviceName(e.target.value)} - placeholder="Название нового устройства" - style={styles.input} - /> - -
    - -
      - {devices.map((device) => ( -
    • - {editDeviceId === device.id ? ( -
      - setEditDeviceName(e.target.value)} - placeholder="Новое имя устройства" - style={styles.input} - /> - - -
      - ) : ( - <> - {device.name} - - - {/* Генерация QR-кода для устройства */} - - - )} -
    • - ))} -
    -
    - ); -}; - -const styles = { - container: { - padding: "20px", - backgroundColor: "#f5f5f5", - borderRadius: "8px", - boxShadow: "0 2px 10px rgba(0, 0, 0, 0.1)", - }, - title: { - marginBottom: "20px", - color: "#333", - }, - addDevice: { - marginBottom: "20px", - display: "flex", - alignItems: "center", - }, - input: { - padding: "10px", - marginRight: "10px", - border: "1px solid #ccc", - borderRadius: "4px", - flexGrow: 1, - }, - addButton: { - padding: "10px 15px", - backgroundColor: "#3498db", - color: "white", - border: "none", - borderRadius: "4px", - cursor: "pointer", - transition: "background-color 0.3s", - }, - addButtonHover: { - backgroundColor: "#2980b9", - }, - deviceList: { - listStyleType: "none", - padding: "0", - }, - deviceItem: { - backgroundColor: "white", - borderRadius: "5px", - padding: "15px", - marginBottom: "10px", - boxShadow: "0 1px 5px rgba(0, 0, 0, 0.1)", - display: "flex", - alignItems: "center", - justifyContent: "space-between", - }, - editContainer: { - display: "flex", - alignItems: "center", - }, - deviceName: { - flexGrow: 1, - fontWeight: "bold", - }, - editButton: { - marginLeft: "10px", - padding: "5px 10px", - backgroundColor: "#f39c12", - color: "white", - border: "none", - borderRadius: "4px", - cursor: "pointer", - }, - deleteButton: { - marginLeft: "10px", - padding: "5px 10px", - backgroundColor: "#e74c3c", - color: "white", - border: "none", - borderRadius: "4px", - cursor: "pointer", - }, - saveButton: { - marginLeft: "10px", - padding: "5px 10px", - backgroundColor: "#2ecc71", - color: "white", - border: "none", - borderRadius: "4px", - cursor: "pointer", - }, - cancelButton: { - marginLeft: "10px", - padding: "5px 10px", - backgroundColor: "#95a5a6", - color: "white", - border: "none", - borderRadius: "4px", - cursor: "pointer", - }, -}; - -export default DevicesPage; \ No newline at end of file