k5web/assets/index.64c80731.js
2024-07-20 11:04:32 +08:00

2 lines
7.5 KiB
JavaScript

import{m as j,ak as K,_ as G}from"./index.12bdcbda.js";/* empty css *//* empty css *//* empty css */import{d as W,r as q,o as Q,bI as X,C as h,D as E,aI as c,aH as i,aM as m,aN as b,G as d,aK as B,aJ as S,F as N,aE as Y,u as Z,a6 as ee,a$ as te,ba as ae,bJ as oe,bL as ne,be as re,bf as le,n as se}from"./arco.7f845a67.js";import{u as ie}from"./loading.1a4e75f4.js";import{i as ce,e as ue,s as D,h as M,g as de,l as pe,b as me}from"./serial.c6b76da8.js";import{B as fe}from"./index.014c7ae3.js";import{I as _e}from"./index.d1cb55ec.js";import{C as ge}from"./index.c07a5fc8.js";import{S as he}from"./index.bb7e4ef6.js";import"./chart.95d38b48.js";import"./vue.0bef8fc5.js";import"./useConfig.8e3dba5c.js";import"./index.211f6b2b.js";import"./helper.b36c554d.js";import"./useDisabled.5453a5a8.js";import"./useGlobalIcon.1badd75e.js";import"./slot.5ae8b203.js";const x=F=>(re("data-v-7fa0c45f"),F=F(),le(),F),be={class:"container"},Fe=x(()=>d("div",{style:{color:"red","font-weight":"bold"}},"\u26A0\uFF1A\u5B9E\u9A8C\u6027\u529F\u80FD \u4F7F\u7528\u53EF\u80FD\u4F1A\u635F\u574F\u624B\u53F0",-1)),we={style:{display:"flex","justify-content":"space-between","margin-left":"10px","margin-right":"10px","align-items":"flex-end","margin-bottom":"3px"}},ye=x(()=>d("div",null,"EEPROM\uFF1A",-1)),Ae={style:{width:"100%",overflow:"scroll","user-select":"none"}},Ee={style:{height:"328px",display:"flex","flex-direction":"column",margin:"0",padding:"0","flex-wrap":"wrap"}},ve=["onClick","ondragover","ondrop","title"],Ce=x(()=>d("br",null,null,-1)),xe=["innerHTML"],ke={name:"BL"},Be=W({...ke,setup(F){const p=j(),{loading:U,setLoading:w}=ie(!0),t=q({calendar:[],rom:[],bl:void 0,blName:"",nowDrag:-1,showAdd:"",status:""}),_=async(e=0,a,n="")=>{var s;for(let r=e;r<a.length+e;r+=192)await me(p.connectPort,r,a.slice(r-e,r-e+192),a.slice(r-e,r-e+192).length,(s=p.configuration)==null?void 0:s.uart),t.status=t.status+n+"\u5199\u5165\u8FDB\u5EA6\uFF1A"+((r-e)/a.length*100).toFixed(1)+"%<br/>",se(()=>{const o=document==null?void 0:document.getElementById("statusArea");o&&(o.scrollTop=o==null?void 0:o.scrollHeight)})},$=async e=>{t.showAdd=(e*64+262144).toString(16).toUpperCase(),setTimeout(()=>{t.showAdd=""},5e3)};Q(()=>{I();const e=[];for(let a=0;a<262144/64;a++)a<278528/64/16-16?e.push(-2):e.push(-1);t.calendar=e});const I=async()=>{const e=JSON.parse(await(await fetch("https://k5.vicicode.cn/diyapi/bl.json")).text()).latest;t.blName=e;const a=await fetch("https://k5.vicicode.cn/diyapi/"+e);if(a.body){const n=a.body.getReader(),s=[];for(;;){const{done:o,value:f}=await n.read();if(o)break;s.push(...f)}let r=new Uint8Array(12288);r.set(s,0),t.bl=r,w(!1)}},P=async()=>{var r;if(p.connectState!=!0){alert(sessionStorage.getItem("noticeConnectK5"));return}const e=await ce(p.connectPort,(r=p.configuration)==null?void 0:r.uart);if(w(!0),e<524288){alert("\u53EA\u652F\u6301 4Mbit \u4EE5\u4E0A EEPROM \u5199\u5165"),w(!1);return}await ue(p.connectPort),await _(266240,t.bl,"\u5F15\u5BFC\u7A0B\u5E8F");const a=[];for(let o=256;o<4096;o++)t.calendar[o]>=0&&(console.log(o),a.push({...t.rom[t.calendar[o]],start:262144+o*64,end:262144+(o+Math.ceil(t.rom[t.calendar[o]].binaryFile.length/64))*64-1}),o+=Math.ceil(t.rom[t.calendar[o]].binaryFile.length/64)-1);await _(262144,new Uint8Array([a.length]),"\u56FA\u4EF6\u6570\u91CF");const n=new Uint8Array(8);n.set(D(t.blName.split(".")[0])),await _(262152,n,"\u5F15\u5BFC\u7A0B\u5E8F\u7248\u672C");const s=[];a.map(o=>{const f=new Uint8Array(16),y=new Uint8Array(4),A=new Uint8Array(4);f.set(D(o.binaryName.replace(/[^\x00-\xff]/g,""))),y.set(M(o.start.toString(16))),A.set(M(o.end.toString(16))),s.push(...f,...y,...A,...new Uint8Array(8))}),await _(262176,s,"\u56FA\u4EF6\u5143\u6570\u636E");for(let o=0;o<a.length;o++)await _(a[o].start,a[o].binaryFile,a[o].binaryName+" \u56FA\u4EF6\u6587\u4EF6");await de(p.connectPort),t.status=t.status+"\u5199\u5165\u5B8C\u6210<br/>",w(!1)},L=()=>{const e=document.createElement("input");e.type="file",e.multiple=!0,e.onchange=async()=>{if(e.files)for(let a=0;a<e.files.length;a++){const n=new Blob([e.files[a]],{type:"application/octet-stream"}),s=new Uint8Array(await n.arrayBuffer()),r={binaryFile:pe(s),binaryName:e.files[a].name.replace(/[^\x00-\xff]/g,""),color:T()};t.rom.push(r)}},e.click()},R=(e,a)=>{if(!(a<256)&&!(a+Math.ceil(t.rom[t.nowDrag].binaryFile.length/64)>4096)&&e!=2){for(let n=a;n<a+Math.ceil(t.rom[t.nowDrag].binaryFile.length/64);n+=1)v(n);for(let n=a;n<a+Math.ceil(t.rom[t.nowDrag].binaryFile.length/64);n+=1)t.calendar[n]=t.nowDrag;console.log((a*64+262144).toString(16)),console.log((Math.ceil(t.rom[t.nowDrag].binaryFile.length/64)*64+(a*64+262144)-1).toString(16))}},T=()=>{for(var e="0123456789ABCDEF",a="#",n=0;n<6;n++)a+=e[Math.floor(Math.random()*16)];return a},v=e=>{if(e>4095||e<256)return;let a=0;t.calendar[e]!=-1&&(a=1,t.calendar[e]=-1),a&&(t.calendar[e-1]!=-1&&v(e-1),t.calendar[e+1]!=-1&&v(e+1))},C=e=>{if(e>4095||e<256)return;let a=-99;t.calendar[e]!=-1&&(a=t.calendar[e],t.calendar[e]=-1),t.calendar[e-1]===a&&C(e-1),t.calendar[e+1]===a&&C(e+1)},k=e=>{e>4095||e<256||(t.calendar[e]=-1,k(e+1))},V=e=>{t.rom[e].binaryName=t.rom[e].binaryName.replace(/[^\x00-\xff]/g,"")};return(e,a)=>{const n=K,s=ee,r=te,o=ae,f=oe,y=ne,A=fe,O=_e,z=ge,H=he,J=X;return h(),E("div",be,[c(n,{items:[e.$t("menu.list"),e.$t("bl")]},null,8,["items"]),c(J,{class:"general-card",loading:Z(U)},{title:i(()=>[Fe,m(" "+b(e.$t("bl"))+" "+b(e.$t("global.onStart")),1)]),default:i(()=>[c(y,{style:{"margin-bottom":"16px"}},{default:i(()=>[c(f,{span:12},{default:i(()=>[c(o,{style:{width:"130%"}},{default:i(()=>[c(r,{onClick:P},{icon:i(()=>[c(s)]),default:i(()=>[m(" "+b(e.$t("cps.onDeviceWrite")),1)]),_:1}),m(" \uFF08\u56FA\u4EF6\u540D\u79F0\u4EC5\u652F\u6301\u82F1\u6587\uFF09 ")]),_:1})]),_:1})]),_:1}),d("div",we,[ye,d("div",null,[m(b(t.showAdd)+" ",1),c(A,{size:"small",variant:"outline",onClick:a[0]||(a[0]=l=>k(256))},{default:i(()=>[m("\u6E05\u7A7A")]),_:1})])]),d("div",Ae,[d("div",Ee,[(h(!0),E(B,null,S(t.calendar,(l,u)=>(h(),E("div",{onClick:g=>C(u),ondragover:g=>{$(u),g.preventDefault()},ondrop:()=>{R(l,u)},title:l==-2?"\u5F15\u5BFC\u7A0B\u5E8F\u5360\u7528\u533A":l!=-1?t.rom[l].binaryName:(u*64+262144).toString(16).toUpperCase()+" - "+(u*64+262144+63).toString(16).toUpperCase(),style:N(l==-1?"background-color: white; border: 1px solid #ddd; height: 10px;":l==-2?"background-color: #373737; border: 1px solid #ddd; height: 10px;":"background-color: "+t.rom[l].color+"; border: 1px solid #ddd; height: 10px;"),key:u}," \xA0 ",12,ve))),128))])]),c(r,{style:{"margin-bottom":"10px"},onClick:L},{default:i(()=>[m(b(t.binaryFile?t.binaryName:e.$t("tool.selectFirmware")),1)]),_:1}),m("\uFF08\u9009\u62E9\u56FA\u4EF6\u540E\u5C06\u56FA\u4EF6\u5361\u7247\u62D6\u62FD\u5230\u4E0A\u65B9 EEPROM\uFF09 "),Ce,c(H,{"break-line":""},{default:i(()=>[(h(!0),E(B,null,S(t.rom,(l,u)=>(h(),Y(z,{draggable:"true",ondragstart:()=>{t.nowDrag=u},title:l.binaryName,bordered:!0,"hover-shadow":"",style:{width:"400px"}},{actions:i(()=>[d("div",{style:N("width: 10px; height: 10px; background-color: "+l.color+";")},null,4)]),default:i(()=>[c(O,{modelValue:l.binaryName,"onUpdate:modelValue":g=>l.binaryName=g,onChange:g=>V(u),"show-limit-number":"",maxlength:13},null,8,["modelValue","onUpdate:modelValue","onChange"])]),_:2},1032,["ondragstart","title"]))),256))]),_:1})]),_:1},8,["loading"]),d("div",{id:"statusArea",style:{height:"20em","background-color":"azure",color:"silver",overflow:"auto",padding:"20px","margin-top":"10px"},innerHTML:t.status},null,8,xe)])}}});const We=G(Be,[["__scopeId","data-v-7fa0c45f"]]);export{We as default};