mirror of
https://github.com/silenty4ng/k5web
synced 2024-11-14 22:35:31 +00:00
2 lines
4.6 KiB
JavaScript
2 lines
4.6 KiB
JavaScript
import{e as L,as as P,_ as F}from"./index.b8b6f641.js";/* empty css *//* empty css *//* empty css */import{d as N,r as U,o as V,bH as j,bO as O,C as h,D as b,aI as p,aH as _,G as y,aK as C,aJ as D,F as A,aM as v,aN as E,a$ as H,ba as T,bI as q,bL as z,be as K,bf as G}from"./arco.f43727df.js";import{h as J}from"./vue.cbdb927d.js";import{e as Q,b as W,g as X}from"./serial.c741fbda.js";import"./chart.3c227ebb.js";const $=w=>(K("data-v-07ff6529"),w=w(),G(),w),Y={class:"container"},Z=$(()=>y("div",{id:"canvasDiv",style:{zoom:"250%",display:"none"}},null,-1)),tt={style:{padding:"0",margin:"0","border-spacing":"0"}},et=["onMousedown","onMouseover"],ot=$(()=>y("br",null,null,-1)),nt={name:"Backup"},at=N({...nt,setup(w){const f=L(),r=U({binaryFile:void 0,loading:!1,matrix:[],mousedown:!1}),x=J();V(async()=>{if(x.query.url){const n=await fetch(x.query.url,{responseType:"blob"});k(window.URL.createObjectURL(await n.blob()))}});const I=(n,o)=>{if(r.mousedown){const t=r.matrix;t[o][n]=r.matrix[o][n]=="#fff"?"#000":"#fff",r.matrix=t}},k=n=>{const o=document.createElement("canvas");o.width=128,o.height=64;const t=o.cloneNode(),s=document.getElementById("canvasDiv");s.innerHTML="",s==null||s.append(o,t);const l=new Image;l.src=n,l.onload=()=>{const a=o.getContext("2d");a==null||a.drawImage(l,0,0,128,64);const u=a==null?void 0:a.getImageData(0,0,o.width,o.height).data;function g(e,i){const c=(i*128+e)*4;return u[c]+u[c+1]+u[c+2]>128*3?0:1}const d=[];for(let e=0;e<64;e++){d.push([]),d[e]=[];for(let i=0;i<128;i++){const m=!g(i,e);d[e][i]=m?"#fff":"#000"}}r.matrix=d}},B=()=>{const n=document.createElement("input");n.type="file",n.onchange=async()=>{const o=new Blob([n.files[0]],{type:"application/octet-stream"}),t=URL.createObjectURL(o),s=document.createElement("canvas");s.width=128,s.height=64;const l=new Image;l.src=t,l.onload=()=>{const a=s.getContext("2d");a==null||a.drawImage(l,0,0,128,64);const u=a==null?void 0:a.getImageData(0,0,s.width,s.height).data;function g(e,i){const c=(i*128+e)*4;return u[c]+u[c+1]+u[c+2]>128*3?0:1}const d=[];for(let e=0;e<64;e++){d.push([]),d[e]=[];for(let i=0;i<128;i++){const m=!g(i,e);d[e][i]=m?"#fff":"#000"}}r.matrix=d}},n.click()},M=async()=>{const n=r.matrix,o=document.createElement("canvas");o.width=128,o.height=64;const t=o.getContext("2d");t&&(t.fillStyle="#fff",t.fillRect(0,0,o.width,o.height),t.fillStyle="#000");for(let l=0;l<64;l++)for(let a=0;a<128;a++)n[l][a]=="#000"&&(t==null||t.beginPath(),t==null||t.rect(a,l,1,1),t==null||t.fill());const s=document.createElement("a");s.href=o.toDataURL("image/jpeg",1),s.download="image.jpg",s.click()},R=async()=>{var l,a,u,g,d;const n=new Uint8Array(1024);let o=0;for(let e=0;e<64;e+=8)for(let i=0;i<128;i++){let m=0;for(let c=0;c<8;c++)m|=(r.matrix[e+c][i]=="#000"?1:0)<<c;n[o++]=m}if(r.binaryFile=n,f.connectState!=!0){alert(sessionStorage.getItem("noticeConnectK5"));return}if(((l=f.configuration)==null?void 0:l.uart)=="official"){alert(sessionStorage.getItem("noticeVersionNoSupport"));return}if(((a=f.configuration)==null?void 0:a.charset)!="losehu"&&((u=f.configuration)==null?void 0:u.charset)!="gb2312"){alert(sessionStorage.getItem("noticeVersionNoSupport"));return}r.loading=!0;let t=123728;((g=f.configuration)==null?void 0:g.charset)=="gb2312"&&(t=8320),await Q(f.connectPort);const s=r.binaryFile;for(let e=t;e<s.length+t;e+=128)await W(f.connectPort,e,s.slice(e-t,e-t+128),128,(d=f.configuration)==null?void 0:d.uart);await X(f.connectPort),r.loading=!1};return(n,o)=>{const t=P,s=H,l=T,a=j,u=O,g=q,d=z;return h(),b("div",Y,[p(t,{items:[n.$t("menu.list"),n.$t("menu.image")]},null,8,["items"]),p(d,{gutter:20,align:"stretch"},{default:_(()=>[p(g,{span:24},{default:_(()=>[p(u,{loading:r.loading,tip:"\u5199\u5165\u4E2D...",style:{width:"100%"}},{default:_(()=>[p(a,{class:"general-card",title:n.$t("menu.image")+n.$t("global.onStart")},{default:_(()=>[Z,y("div",null,[y("table",tt,[(h(!0),b(C,null,D(r.matrix,(e,i)=>(h(),b("tr",null,[(h(!0),b(C,null,D(e,(m,c)=>(h(),b("td",{onMousedown:S=>{r.mousedown=!0,I(c,i)},onMouseup:o[0]||(o[0]=S=>{r.mousedown=!1}),onMouseover:S=>I(c,i),style:A("background-color: "+m+"; height: 5px; width: 3.5px;")},null,44,et))),256))]))),256))])]),ot,p(l,null,{default:_(()=>[p(s,{onClick:B},{default:_(()=>[v(E(n.$t("tool.selectImage")),1)]),_:1}),p(s,{disabled:r.matrix.length<64,onClick:M},{default:_(()=>[v("\u4FDD\u5B58")]),_:1},8,["disabled"]),p(s,{type:"primary",disabled:r.matrix.length<64,onClick:R},{default:_(()=>[v(E(n.$t("tool.write")),1)]),_:1},8,["disabled"])]),_:1})]),_:1},8,["title"])]),_:1},8,["loading"])]),_:1})]),_:1})])}}});const ft=F(at,[["__scopeId","data-v-07ff6529"]]);export{ft as default};
|