k5web/assets/index.5b6bd672.js

2 lines
2.7 KiB
JavaScript
Raw Normal View History

2024-05-19 04:18:55 +00:00
import{h as B,Y as w,_ as E}from"./index.9ccc7a96.js";/* empty css *//* empty css *//* empty css *//* empty css */import{d as k,r as v,bD as A,C,D as $,aI as s,aH as r,aM as m,aN as p,G as N,n as f,a$ as D,ba as P,bB as S,bE as T,bJ as H}from"./arco.76776ef0.js";import{d as b,c as I,r as _,j as V,k as h,l as M,m as j}from"./serial.c741fbda.js";import"./chart.ce50b7a1.js";import"./vue.5cc47a17.js";const x={class:"container"},L=["innerHTML"],R={name:"Flash"},U=k({...R,setup(z){const l=B(),e=v({status:"\u70B9\u51FB\u66F4\u65B0\u6309\u94AE\u66F4\u65B0\u56FA\u4EF6\u5230\u8BBE\u5907<br/><br/>",binaryFile:void 0,binaryName:""}),y=()=>{const t=document.createElement("input");t.type="file",t.onchange=async()=>{const c=new Blob([t.files[0]],{type:"application/octet-stream"}),i=new Uint8Array(await c.arrayBuffer());e.binaryFile=i,e.binaryName=t.files[0].name},t.click()},F=async()=>{if(!e.binaryFile){alert("\u8BF7\u9009\u62E9\u6587\u4EF6");return}l.connectPort&&await b(l.connectPort);let t=await I();await _(t,24,1e3);const c=V(e.binaryFile),i=new Uint8Array([48,5,c.length,0,...c]);await h(t,i),await _(t,24);const o=M(e.binaryFile);if(o.length>61439)throw new Error("Last resort boundary check failed. Whoever touched the code is an idiot.");for(let a=0;a<o.length;a+=256){const u=o.slice(a,a+256),d=j(u,a,o.length);try{await h(t,d),await _(t,26)}catch(n){return console.log("Flash command rejected. Aborting."),Promise.reject(n)}e.status=e.status+`\u66F4\u65B0\u8FDB\u5EA6 ${(a/o.length*100).toFixed(1)}%<br/>`,f(()=>{const n=document==null?void 0:document.getElementById("statusArea");n&&(n.scrollTop=n==null?void 0:n.scrollHeight)})}e.status=e.status+"\u66F4\u65B0\u8FDB\u5EA6 100.0%<br/>",e.status=e.status+"\u56FA\u4EF6\u66F4\u65B0\u6210\u529F",f(()=>{const a=document==null?void 0:document.getElementById("statusArea");a&&(a.scrollTop=a==null?void 0:a.scrollHeight)}),b(t),l.updateSettings({connectState:!1})};return(t,c)=>{const i=w,o=D,a=P,u=S,d=A,n=T,g=H;return C(),$("div",x,[s(i,{items:[t.$t("menu.list"),t.$t("menu.flash")]},null,8,["items"]),s(g,{gutter:20,align:"stretch"},{default:r(()=>[s(n,{span:24},{default:r(()=>[s(d,{class:"general-card",title:t.$t("menu.flash")+t.$t("global.onBoot")},{default:r(()=>[s(a,null,{default:r(()=>[s(o,{onClick:y},{default:r(()=>[m(p(e.binaryFile?e.binaryName:t.$t("tool.selectFirmware")),1)]),_:1}),s(o,{type:"primary",disabled:!e.binaryFile,onClick:F},{default:r(()=>[m(p(t.$t("tool.flash")),1)]),_:1},8,["disabled"])]),_:1}),s(u),N("div",{id:"statusArea",style:{height:"20em","background-color":"azure",color:"silver",overflow:"auto",padding:"20px"},innerHTML:e.status},null,8,L)]),_:1},8,["title"])]),_:1})]),_:1})])}}});const Z=E(U,[["__scopeId","data-v-5675c10a"]]);export{Z as default};