index-d43fb3b2.js 3.0 KB

1
  1. import{d as T,g as x,r as y,o as h,s as e,J as N,x as b,b as d,M as w,R as M,S as f,U as k,V as L,W as B,X as P,O as R,n as C,Y as D,Z as X,Q as I,_ as A,$ as E,a0 as J}from"./instrument-9c068536.js";const O="_skeleton_li4n4_4",V="_detail_li4n4_15",q="_mask_li4n4_23",Q="_container_li4n4_29",U="_whiteBg_li4n4_48",l={skeleton:O,detail:V,mask:q,container:Q,whiteBg:U},G=T({name:"simple-detail",setup(){const o=x(),n=y({isLoading:!0,currentTime:0,totalTime:0,backgroundRendMode:""}),u=i=>{var a,r,p,g;let t={};try{t=typeof(i==null?void 0:i.data)=="string"?JSON.parse(i.data):i.data}catch(s){console.error("parse_error: Invalid JSON data received")}if((t==null?void 0:t.api)==="api_play"&&(console.log("h5开始播放"),e.playState="play",m()),(t==null?void 0:t.api)==="api_paused"){const s=(a=t==null?void 0:t.content)==null?void 0:a.currentTime;console.log("暂停播放",s),e.playState="paused",s===0&&setTimeout(()=>{n.currentTime=0,e.activeNoteIndex=0,e.activeMeasureIndex=e.times[0].MeasureNumberXML,c(!0)},200)}if((t==null?void 0:t.api)==="api_updateProgress"&&(console.log("拖动的进度",e.playState),e.playState==="paused"&&(n.currentTime=(p=(r=t==null?void 0:t.content)==null?void 0:r.currentTime)!=null?p:n.currentTime,e.activeNoteIndex=0,e.activeMeasureIndex=e.times[0].MeasureNumberXML,c(!0))),(t==null?void 0:t.api)==="api_playProgress"){const s=(g=t==null?void 0:t.content)==null?void 0:g.currentTime;if(s){if(s<n.currentTime){e.activeNoteIndex=0;let S=M(s)||e.times[0];S.i===e.activeNoteIndex&&(e.activeMeasureIndex=S.MeasureNumberXML);const v=e.times[0].fixtime;s<=v&&f(!0)}n.currentTime=s}}};h(async()=>{const i=o.id||"",t=o.userMusicId||"";n.backgroundRendMode=o.backgroundRendMode,e.isSimplePage=!0,e.partIndex=o["part-index"]?Number(o["part-index"]):0,await N(i,"open",t),n.isLoading=!1,e.isSingleLine=!0,window.addEventListener("message",u)}),b(()=>{e.isSimplePage=!1,window.removeEventListener("message",u)});const _=async i=>{var r;const t=(r=document.getElementById("scrollContainer"))==null?void 0:r.getBoundingClientRect().height;e.osmd=i,e.originSpeed===0&&(e.originSpeed=e.speed=i.bpm||i.Sheet.userStartTempoInBPM||100);const a=(k.get("speeds")||{})[e.examSongId]||e.speed||i.bpm||i.Sheet.userStartTempoInBPM;a&&L(a),B(),P(),e.times=R(i),console.log("🚀 ~ state.times:",e.times,e),C(()=>{e.activeMeasureIndex=e.times[0].MeasureNumberXML}),D(e.times),X(),I(),console.log("渲染完成",t),window.parent.postMessage({api:"api_musicPage",height:t},"*"),A({height:t})},c=i=>{const t=n.currentTime;let a=M(t)||e.times[0];a&&E(a,i),e.activeNoteIndex=(a==null?void 0:a.i)||0,e.isSingleLine&&J(t,!0)},m=()=>{if(e.playState!=="play"){console.log("暂停播放");return}let i=Date.now();requestAnimationFrame(()=>{Date.now()-i<16.7?(c(),m()):setTimeout(()=>{c(),m()},16.7)})};return()=>d("div",{class:[l.detail,n.backgroundRendMode==="video"&&l.whiteBg]},[d("div",{class:l.mask},null),d("div",{id:"scrollContainer",class:[l.container]},[!n.isLoading&&d(w,{onRendered:_,musicColor:"#000000"},null)])])}});export{G as default};