mirror of
https://github.com/IoTManagerProject/IoTManagerWeb.git
synced 2026-03-29 16:32:32 +03:00
устранение бага импорта
This commit is contained in:
@@ -99,20 +99,15 @@
|
|||||||
exportJson.scenario = scenarioJson;
|
exportJson.scenario = scenarioJson;
|
||||||
}
|
}
|
||||||
|
|
||||||
//let files;
|
let template = null;
|
||||||
|
let files = null;
|
||||||
|
|
||||||
function previewFile() {
|
$: if (files) {
|
||||||
const [file] = document.querySelector("input[type=file]").files;
|
const fileText = files[0].text();
|
||||||
const reader = new FileReader();
|
fileText.then((text) => {
|
||||||
|
template = text;
|
||||||
if (file) {
|
if (IsJsonParse(template)) {
|
||||||
reader.readAsText(file);
|
let json = JSON.parse(template);
|
||||||
}
|
|
||||||
|
|
||||||
reader.onload = function () {
|
|
||||||
let result = reader.result;
|
|
||||||
if (IsJsonParse(result)) {
|
|
||||||
let json = JSON.parse(result);
|
|
||||||
configJson = [];
|
configJson = [];
|
||||||
scenarioJson = {};
|
scenarioJson = {};
|
||||||
configJson = json.config;
|
configJson = json.config;
|
||||||
@@ -121,7 +116,13 @@
|
|||||||
scenarioJson = scenarioJson;
|
scenarioJson = scenarioJson;
|
||||||
console.log(JSON.stringify(configJson));
|
console.log(JSON.stringify(configJson));
|
||||||
}
|
}
|
||||||
};
|
});
|
||||||
|
files = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
files = null;
|
||||||
|
document.getElementById("formFile").value = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
function IsJsonParse(str) {
|
function IsJsonParse(str) {
|
||||||
@@ -216,8 +217,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 class="btn-lg">
|
<label on:click={() => reset()} class="btn-lg">
|
||||||
<input on:change={() => previewFile()} accept="json" type="file" id="formFile" />
|
<input bind:files accept="json" type="file" id="formFile" />
|
||||||
{"Загрузить конфигурацию"}
|
{"Загрузить конфигурацию"}
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user