mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-26 15:02:21 +03:00
добавил виджет range
This commit is contained in:
@@ -4,7 +4,7 @@
|
||||
<meta charset='utf-8'>
|
||||
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
||||
|
||||
<title>IoT Manager 4.1.3</title>
|
||||
<title>IoT Manager 4.1.4</title>
|
||||
|
||||
<link rel='icon' type='image/png' href='/favicon.ico'>
|
||||
<link rel='stylesheet' href='/build/bundle.css'>
|
||||
|
||||
@@ -37,6 +37,7 @@
|
||||
let opened = false;
|
||||
let preventMove = false;
|
||||
let devMode = true;
|
||||
let showWidjetJson = false;
|
||||
|
||||
//****************************************************variable section**********************************************************/
|
||||
//******************************************************************************************************************************/
|
||||
@@ -1122,7 +1123,7 @@
|
||||
<Route path="/">
|
||||
<DashboardPage show={dashReady} layoutJson={layoutJson} pages={pages} wsPush={(ws, topic, status) => wsPush(ws, topic, status)} />
|
||||
<!--<button class="btn-lg" on:click={() => createFinalLayout()}>{"Test"}</button>-->
|
||||
{#if devMode}
|
||||
{#if showWidjetJson}
|
||||
<textarea value={JSON.stringify(layoutJson)} class="ipt-big h-40 w-full" />
|
||||
{/if}
|
||||
</Route>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
<script>
|
||||
import Card from "../components/Card.svelte";
|
||||
import Input from "../widgets/Input.svelte";
|
||||
import Range from "../widgets/Range.svelte";
|
||||
import Toggle from "../widgets/Toggle.svelte";
|
||||
import Anydata from "../widgets/Anydata.svelte";
|
||||
import Alarm from "../components/Alarm.svelte";
|
||||
@@ -31,6 +32,9 @@
|
||||
{#if widget.widget === "anydata"}
|
||||
<Anydata bind:value={widget.status} widget={widget} />
|
||||
{/if}
|
||||
{#if widget.widget === "range"}
|
||||
<Range bind:value={widget.status} widget={widget} wsPush={(ws, topic, status) => wsPush(ws, topic, status)} />
|
||||
{/if}
|
||||
{/if}
|
||||
{/each}
|
||||
</Card>
|
||||
|
||||
28
src/widgets/Range.svelte
Normal file
28
src/widgets/Range.svelte
Normal file
@@ -0,0 +1,28 @@
|
||||
<script>
|
||||
export let widget;
|
||||
export let wsPush = (ws, topic, status) => {};
|
||||
export let val = 0;
|
||||
|
||||
function map(val, in_min, in_max, out_min, out_max) {
|
||||
return Math.round(((val - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min);
|
||||
}
|
||||
|
||||
$: widget.status, calc();
|
||||
|
||||
function calc() {
|
||||
val = map(widget.status, 0, 1024, widget.min, widget.max);
|
||||
}
|
||||
</script>
|
||||
|
||||
<!--<div class="text-center">-->
|
||||
<!-- svelte-ignore a11y-label-has-associated-control -->
|
||||
<label class="wgt-dscr-stl">{!widget.descr ? "" : widget.descr} {val} {widget.after}</label>
|
||||
<!--</div>-->
|
||||
<input
|
||||
bind:value={widget.status}
|
||||
on:change={() => ((widget.sent = true), wsPush(widget.ws, widget.topic, widget.status))}
|
||||
class="form-range range-secondary w-full h-2 p-0 rounded-lg {widget.sent ? 'bg-red-300' : 'bg-gray-300'}
|
||||
focus:outline-none appearance-none"
|
||||
type="range"
|
||||
min="0"
|
||||
max="1024" />
|
||||
Reference in New Issue
Block a user