обмен с есп

This commit is contained in:
Dmitry Borisenko
2021-12-30 23:58:35 +01:00
parent d48a7254ce
commit 305a11c2fd

View File

@@ -186,7 +186,7 @@
]; ];
//configuration //configuration
let config = []; let configJson = [];
let buf = []; let buf = [];
//web sockets //web sockets
@@ -317,9 +317,9 @@
if (data.includes("]}")) { if (data.includes("]}")) {
buf = buf.replace("]}", "]"); buf = buf.replace("]}", "]");
if (IsJsonParse(buf)) { if (IsJsonParse(buf)) {
config = JSON.parse(buf); configJson = JSON.parse(buf);
buf = []; buf = [];
config = config; configJson = configJson;
if (debug) console.log("[i]", "parsed"); if (debug) console.log("[i]", "parsed");
} }
} }
@@ -440,7 +440,7 @@
} }
function clearData() { function clearData() {
config = []; configJson = [];
buf = []; buf = [];
} }
@@ -544,12 +544,16 @@
if (debug) console.log("[i]", "user open add params ", id); if (debug) console.log("[i]", "user open add params ", id);
} }
function pushConfigToEsp() { function checkConfigJson() {
//config.forEach((element) => { //configJson.forEach((element) => {
wsSendMsg(wsSelected, "/changed" + JSON.stringify(config)); //});
}
function sendConfigJson() {
checkConfigJson();
wsSendMsg(wsSelected, "/gifnoc.json" + JSON.stringify(configJson));
clearData(); clearData();
sendCurrentPageName(); sendCurrentPageName();
//});
} }
function showModal() { function showModal() {
@@ -660,7 +664,7 @@
</tr> </tr>
</thead> </thead>
<tbody class="bg-white"> <tbody class="bg-white">
{#each config as element} {#each configJson as element}
<tr class="tbl-txt-sz tbl-txt-p"> <tr class="tbl-txt-sz tbl-txt-p">
<td class="tbl-bdy">{element.subtype}</td> <td class="tbl-bdy">{element.subtype}</td>
<td class="tbl-bdy"><input bind:value={element.id} class="tbl-ipt w-full" type="text" /></td> <td class="tbl-bdy"><input bind:value={element.id} class="tbl-ipt w-full" type="text" /></td>
@@ -698,7 +702,7 @@
{/each} {/each}
</tbody> </tbody>
</table> </table>
<button class="btn-lg" on:click={() => pushConfigToEsp()}>{"Сохранить"}</button> <button class="btn-lg" on:click={() => sendConfigJson()}>{"Сохранить"}</button>
</Card> </Card>
</div> </div>
</Route> </Route>