mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-29 08:22:32 +03:00
запустил кнопки в веб интерфейсе
This commit is contained in:
@@ -511,12 +511,7 @@
|
|||||||
topic = topic.substring(topic.lastIndexOf("/") + 1, topic.length);
|
topic = topic.substring(topic.lastIndexOf("/") + 1, topic.length);
|
||||||
if (key === topic) {
|
if (key === topic) {
|
||||||
console.log("[i]", "value " + topic + " updated");
|
console.log("[i]", "value " + topic + " updated");
|
||||||
//if (devLayout[i].widget == "toggle") {
|
|
||||||
//if (value == "1") devLayout[i].status = 1;
|
|
||||||
//if (value == "0") devLayout[i].status = 0;
|
|
||||||
//} else {
|
|
||||||
devLayout[i].status = value;
|
devLayout[i].status = value;
|
||||||
//}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -542,6 +537,8 @@
|
|||||||
let topic = layoutJson[i].topic;
|
let topic = layoutJson[i].topic;
|
||||||
if (topic === newStatusJson.topic) {
|
if (topic === newStatusJson.topic) {
|
||||||
layoutJson[i].status = newStatusJson.status;
|
layoutJson[i].status = newStatusJson.status;
|
||||||
|
//получен ответ - выключаем красный цвет
|
||||||
|
layoutJson[i].sent = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1125,7 +1122,7 @@
|
|||||||
<Route path="/">
|
<Route path="/">
|
||||||
<DashboardPage show={dashReady} layoutJson={layoutJson} pages={pages} wsPush={(ws, topic, status) => wsPush(ws, topic, status)} />
|
<DashboardPage show={dashReady} layoutJson={layoutJson} pages={pages} wsPush={(ws, topic, status) => wsPush(ws, topic, status)} />
|
||||||
<!--<button class="btn-lg" on:click={() => createFinalLayout()}>{"Test"}</button>-->
|
<!--<button class="btn-lg" on:click={() => createFinalLayout()}>{"Test"}</button>-->
|
||||||
<textarea value={JSON.stringify(layoutJson)} class="ipt-big h-40 w-full" />
|
<!--<textarea value={JSON.stringify(layoutJson)} class="ipt-big h-40 w-full" />-->
|
||||||
</Route>
|
</Route>
|
||||||
<Route path="/config">
|
<Route path="/config">
|
||||||
<ConfigPage show={configReady} configJson={configJson} widgetsJson={widgetsJson} itemsJson={itemsJson} bind:scenarioTxt saveConfig={() => saveConfig()} rebootEsp={() => rebootEsp()} />
|
<ConfigPage show={configReady} configJson={configJson} widgetsJson={widgetsJson} itemsJson={itemsJson} bind:scenarioTxt saveConfig={() => saveConfig()} rebootEsp={() => rebootEsp()} />
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
<script>
|
<script>
|
||||||
export let widget;
|
export let widget;
|
||||||
export let wsPush = (ws, topic, status) => {};
|
export let wsPush = (ws, topic, status) => {};
|
||||||
export let value;
|
|
||||||
value = value;
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="crd-itm-psn">
|
<div class="crd-itm-psn">
|
||||||
@@ -12,16 +10,16 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="flex justify-end w-1/3">
|
<div class="flex justify-end w-1/3">
|
||||||
{#if widget.type == "number"}
|
{#if widget.type == "number"}
|
||||||
<input class={widget["send"] == true ? "ipt-rnd text-right border-red-500" : "ipt-rnd text-right focus:border-indigo-500"} on:change={() => ((widget["send"] = true), wsPush(widget.ws, widget.topic, widget.status))} bind:value={widget.status} step="0.1" type="number" />
|
<input class={widget.sent ? "ipt-rnd text-right border-red-500" : "ipt-rnd text-right focus:border-indigo-500"} on:change={() => ((widget.sent = true), wsPush(widget.ws, widget.topic, widget.status))} bind:value={widget.status} step="0.01" type="number" />
|
||||||
{/if}
|
{/if}
|
||||||
{#if widget.type == "text"}
|
{#if widget.type == "text"}
|
||||||
<input class={widget["send"] == true ? "ipt-rnd text-right border-red-500" : "ipt-rnd text-right focus:border-indigo-500"} on:change={() => ((widget["send"] = true), wsPush(widget.ws, widget.topic, widget.status))} bind:value={widget.status} type="text" />
|
<input class={widget.sent ? "ipt-rnd text-right border-red-500" : "ipt-rnd text-right focus:border-indigo-500"} on:change={() => ((widget.sent = true), wsPush(widget.ws, widget.topic, widget.status))} bind:value={widget.status} type="text" />
|
||||||
{/if}
|
{/if}
|
||||||
{#if widget.type == "date"}
|
{#if widget.type == "date"}
|
||||||
<input class={widget["send"] == true ? "ipt-rnd text-right border-red-500" : "ipt-rnd text-right focus:border-indigo-500"} on:change={() => ((widget["send"] = true), wsPush(widget.ws, widget.topic, widget.status))} bind:value={widget.status} type="date" />
|
<input class={widget.sent ? "ipt-rnd text-right border-red-500" : "ipt-rnd text-right focus:border-indigo-500"} on:change={() => ((widget.sent = true), wsPush(widget.ws, widget.topic, widget.status))} bind:value={widget.status} type="date" />
|
||||||
{/if}
|
{/if}
|
||||||
{#if widget.type == "time"}
|
{#if widget.type == "time"}
|
||||||
<input class={widget["send"] == true ? "ipt-rnd text-right border-red-500" : "ipt-rnd text-right focus:border-indigo-500"} on:change={() => ((widget["send"] = true), wsPush(widget.ws, widget.topic, widget.status))} bind:value={widget.status} type="time" />
|
<input class={widget.sent ? "ipt-rnd text-right border-red-500" : "ipt-rnd text-right focus:border-indigo-500"} on:change={() => ((widget.sent = true), wsPush(widget.ws, widget.topic, widget.status))} bind:value={widget.status} type="time" />
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -1,26 +1,22 @@
|
|||||||
<script>
|
<script>
|
||||||
import App from "../App.svelte";
|
import App from "../App.svelte";
|
||||||
import { onMount } from "svelte";
|
|
||||||
import { handle_promise } from "svelte/internal";
|
|
||||||
onMount(async () => {
|
|
||||||
setDefaultValue();
|
|
||||||
});
|
|
||||||
export let widget;
|
export let widget;
|
||||||
|
export let toggleState = false;
|
||||||
export let wsPush = (ws, topic, status) => {};
|
export let wsPush = (ws, topic, status) => {};
|
||||||
|
|
||||||
let st = false;
|
$: widget.status, setValue();
|
||||||
|
|
||||||
function setDefaultValue() {
|
function setValue() {
|
||||||
if (widget.status == "1") {
|
if (widget.status == "1") {
|
||||||
st = true;
|
toggleState = true;
|
||||||
} else if (widget.status == "0") {
|
} else if (widget.status == "0") {
|
||||||
st = false;
|
toggleState = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeValue() {
|
function changeValue() {
|
||||||
if (st) {
|
widget.sent = true;
|
||||||
|
if (toggleState) {
|
||||||
widget.status = "1";
|
widget.status = "1";
|
||||||
} else {
|
} else {
|
||||||
widget.status = "0";
|
widget.status = "0";
|
||||||
@@ -36,9 +32,9 @@
|
|||||||
<div class="flex justify-end w-1/3">
|
<div class="flex justify-end w-1/3">
|
||||||
<label for={widget.topic} class="items-center cursor-pointer">
|
<label for={widget.topic} class="items-center cursor-pointer">
|
||||||
<div class="relative">
|
<div class="relative">
|
||||||
<input bind:checked={st} on:change={() => (changeValue(), wsPush(widget.ws, widget.topic, widget.status))} id={widget.topic} type="checkbox" class="sr-only" />
|
<input bind:checked={toggleState} on:change={() => (changeValue(), wsPush(widget.ws, widget.topic, widget.status))} id={widget.topic} type="checkbox" class="sr-only" />
|
||||||
<div class="block bg-gray-600 w-10 h-6 rounded-full" />
|
<div class="block bg-gray-600 w-10 h-6 rounded-full" />
|
||||||
<div class="dot {widget['send'] == true ? 'bg-red-400' : 'bg-white'} absolute left-1 top-1 w-4 h-4 rounded-full transition" />
|
<div class="dot {widget.sent ? 'bg-red-400' : 'bg-white'} absolute left-1 top-1 w-4 h-4 rounded-full transition" />
|
||||||
</div>
|
</div>
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user