SOURCE

console 命令行工具 X clear

                    
>
console
<!DOCTYPE html>
<html>
<head>
  <title>ESP32 SPIFFS Upload</title>
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <meta charset="UTF-8">
</head><style>
.b1{width:94%;border:1px solid #ccc;padding:10px 2%;margin:10px auto;font-size:15px;}
h6{margin:0 auto;padding:5px 0px;font-size:14px;}
</style>
<body style="max-width:600px;margin:0 auto;">
<h1 style="width:100%;margin-top:0;padding:30px 0;text-align: center;background: linear-gradient(145deg, #4d94ff 10%,#ff3385 60%,#ff4000 100%);">
    ESP32 SPIFFS UpLoad
    <div style="font-size:10px;text-align:center;color:#333;padding-top:15px;">DouYin:红薯(hong.wang)</div>
</h1>
<div class="b1" id="total"><h6></h6><h6></h6><h6></h6></div>
<form id="uf" method="post" action="/upload" enctype="multipart/form-data" class="b1">
  <input type="file" name="file" style="padding-left: 10px;width: 60%;font-size: 15px;float: left;">
  <input type="submit" value="上传" id="s" style="float: right;font-size: 15px;margin-right: 10px;">
  <div style="clear:both;font-size:0px;">&nbsp;</div>
</form>
<p class="b1">文件列表(文件字节/文件名称)<a onclick="f()" id="fm">(!!!格式化空间!!!)</a></p>
<div id="list"></div>
<script>
let rt = 0;
function rtf() {  
  document.getElementById('fm').innerHTML = '正在格式化('+rt+')';  
  if (rt <= 0) {  
    location.reload();  
  } else {  
    rt--;  
    setTimeout(rtf, 1000);  
  }  
}  
function f(){
    if(rt==0 && confirm("你确定要格式化吗?\r\n确定后芯片会重启\r\n请保持wifi正确链接.")){
        var xhr = new XMLHttpRequest();  
        xhr.open('GET', '/spiffsformat', true); 
        xhr.onreadystatechange = function() {  
            if (xhr.readyState === 4) {  rt = 20;rtf();
                // if (xhr.status === 200) {
                //     rt = 20;rtf();
                // } else {  
                //     // console.log('请求失败,状态码:' + xhr.status);   
                //     alert("数据请求失败" + xhr.status);   
                // }    
            }  
        };  
        xhr.send();
    }
}
function e(filename){
    var in = prompt("输入新的文件名",filename);
    if(in!=null && in!=""){
        var xhr = new XMLHttpRequest();  
        xhr.open('GET', '/spiffsrenamefile/?name='+filename+'&newname='+in, true);  
        xhr.onreadystatechange = function() {  
            if (xhr.readyState === 4) {  
                if (xhr.status === 200) {
                    alert(xhr.responseText);
                    t();
                } else {  
                    // console.log('请求失败,状态码:'+xhr.status);   
                    alert("数据请求失败"+xhr.status);   
                }    
            }  
        };  
        xhr.send();
    }
}
function d(filename){
    if(confirm("你确定要删除文件吗?")){
        var xhr = new XMLHttpRequest();  
        xhr.open('GET', '/spiffsdeletefile/?name='+filename, true);  
        xhr.onreadystatechange = function() {  
            if (xhr.readyState === 4) {  
                if (xhr.status === 200) {
                    alert(xhr.responseText);
                    t();
                } else {  
                    // console.log('请求失败,状态码:'+xhr.status);   
                    alert("数据请求失败"+xhr.status);   
                }    
            }  
        };  
        xhr.send();
    }
}
function t(){
    var xhr = new XMLHttpRequest();  
    xhr.open('GET', '/spiffsfilelist', true);  
    xhr.onreadystatechange = function() {  
        if (xhr.readyState === 4) {  
            if (xhr.status === 200) {  
                var jsonData = JSON.parse(xhr.responseText);   
                document.getElementById('total').innerHTML = "<h6>SPIFFS空间(字节):"+jsonData.t+"</h6>";   
                document.getElementById('total').innerHTML += "<h6>SPIFFS已用(字节):"+jsonData.u+"</h6>";   
                document.getElementById('total').innerHTML += "<h6>SPIFFS可用(字节):"+(jsonData.t-jsonData.u)+"</h6>";  
                var listbox="";
                for (const item of jsonData.list) {    
listbox += "<div class=\"b1\" style=\"border:0px;border-bottom:1px dashed #ccc;\"><div style=\"width:25%;float:left;\">"+item.b+"</div><a style=\"display:block;width:40%;float:left;\" target=\"_blank\" href=\"/downloadfile/"+item.n+"\">"+item.n+"</a><input type=\"submit\" value=\"改名\" onClick=\"e('"+item.n+"')\" style=\"float: right;font-size: 15px;margin-right: 10px;\"><div style=\"clear:both;font-size:0px;\">&nbsp;</div></div>";
                }
                document.getElementById('list').innerHTML = listbox;
            } else {  
                // console.log('请求失败,状态码:' + xhr.status);   
                alert("数据请求失败" + xhr.status);   
            }    
        }  
    };  
    xhr.send();
}
document.addEventListener('DOMContentLoaded', function() {  
    t();
    var uf = document.getElementById('uf');  
    uf.addEventListener('submit', function(event) {  
        event.preventDefault();  
        var s = document.getElementById('s');  
        s.disabled = true;  
  
        var fileInput = uf.querySelector('input[type=file]');  
        var file = fileInput.files[0];  
        var formData = new FormData();  
        formData.append('file', file);  
  
        var xhr = new XMLHttpRequest(); 
        xhr.open('POST', '/spiffsfileupload', true);  
  
        xhr.onload = function() {  
            if (xhr.status === 200) {
                // console.log('Response:', xhr.responseText);  
                alert(xhr.responseText);
                t();
            } else {  
                // console.log('Error:', xhr.status);  
                alert("上传失败" + xhr.status);  
            }  
            s.disabled = false;  
        };  
  
        xhr.send(formData);
    });  
});
</script>
</body>
</html>
body{
    /* border:1px #ccc dashed; */
}
a{
    
}