добавление метки файла

This commit is contained in:
Dmitry Borisenko
2022-09-29 15:14:37 +02:00
parent fe32a201e5
commit 3d7a51e793

View File

@@ -95,26 +95,40 @@
}; };
function createExportFile() { function createExportFile() {
exportJson.mark = "iotm";
exportJson.config = configJson; exportJson.config = configJson;
exportJson.scenario = scenarioJson; exportJson.scenario = scenarioJson;
//exportJson.settings = settingsJson;
} }
let template = null; let template = null;
let files = null; let files = null;
const alertErr = "Файл не является файлом конфигурации";
const alertOk = "Применить конфигурацию?\nне забудьте нажать кнопку 'сохранить'";
$: if (files) { $: if (files) {
const fileText = files[0].text(); const fileText = files[0].text();
fileText.then((text) => { fileText.then((text) => {
template = text; template = text;
if (IsJsonParse(template)) { if (IsJsonParse(template)) {
let json = JSON.parse(template); let json = JSON.parse(template);
configJson = []; if (json.mark === "iotm") {
scenarioJson = {}; if (window.confirm(alertOk)) {
configJson = json.config; configJson = [];
scenarioJson = json.scenario; scenarioJson = {};
configJson = configJson; configJson = json.config;
scenarioJson = scenarioJson; scenarioJson = json.scenario;
console.log(JSON.stringify(configJson)); configJson = configJson;
scenarioJson = scenarioJson;
console.log(JSON.stringify(configJson));
}
} else {
window.alert(alertErr);
}
} else {
window.alert(alertErr);
} }
}); });
files = null; files = null;
@@ -217,8 +231,8 @@
<button class="btn-lg" on:click={() => saveConfig()}>{"Сохранить"}</button> <button class="btn-lg" on:click={() => saveConfig()}>{"Сохранить"}</button>
<button class="btn-lg" on:click={() => rebootEsp()}>{"Перезагрузить"}</button> <button class="btn-lg" on:click={() => rebootEsp()}>{"Перезагрузить"}</button>
<button class="btn-lg" on:click={() => (createExportFile(), download(syntaxHighlight(JSON.stringify(exportJson)), "export.json", "application/json"))}>{"Сохранить конфигурацию"}</button> <button class="btn-lg" on:click={() => (createExportFile(), download(syntaxHighlight(JSON.stringify(exportJson)), "export.json", "application/json"))}>{"Сохранить конфигурацию"}</button>
<label on:click={() => reset()} class="btn-lg"> <label on:click={() => reset()} class="btn-lg cursor-pointer">
<input bind:files accept="json" type="file" id="formFile" /> <input bind:files accept="application/JSON" type="file" id="formFile" />
{"Загрузить конфигурацию"} {"Загрузить конфигурацию"}
</label> </label>
</div> </div>