1 |
- import{T as A}from"./index-0eb46008.js";import{d as w,u as S,e as v,n as b,f as s,w as m,F as I,j as h,k as C,A as j,t as N,aV as k}from"./index-1f06293b.js";import{a as x,b as B}from"./api-f96d3638.js";import{T as O}from"./index-fda8277d.js";import{u as J}from"./catchData-cbf1d846.js";const z="_container_hcm5w_1",F="_tools_hcm5w_8",L="_tagWrap_hcm5w_26",V="_tags_hcm5w_30",W="_firstButton_hcm5w_33",E="_content_hcm5w_48",q="_loadingContent_hcm5w_52",D="_item_hcm5w_55",M="_cover_hcm5w_61",P="_itemImg_hcm5w_78",R="_itemBg_hcm5w_108",X="_itemName_hcm5w_133",d={container:z,tools:F,tagWrap:L,tags:V,firstButton:W,content:E,loadingContent:q,item:D,cover:M,itemImg:P,itemBg:R,itemName:X};function $(r){return typeof r=="function"||Object.prototype.toString.call(r)==="[object Object]"&&!k(r)}const Y=w({name:"XiaokuAi",setup(){const r=J(),p=S(),f=localStorage.getItem("xiaoku-ai-search"),g=f?JSON.parse(f):{},c=v({musicTagIds:g.musicTagIds?g.musicTagIds:[],enable:!0,subjectId:g.subjectId||null,keyword:"",page:1,rows:9999}),a=v({tags:[],tagChildren:[],tagActiveId:g.tagActiveId||"",tagActive:{},list:[],loading:!1}),y=async()=>{const e=await x();if(Array.isArray(e==null?void 0:e.data)&&e.data.length){a.tags=e.data||[];const t=a.tags.findIndex(i=>i.id==a.tagActiveId);if(t>-1){a.tagActiveId=e.data[t].id;const i=[];u(e.data[t].children,i),a.tagChildren=i}else{a.tagActiveId=e.data[0].id;const i=[];u(e.data[0].children,i),a.tagChildren=i}}},l=async()=>{var e;a.loading=!0;try{const t=await B({...c,musicTagIds:[a.tagActiveId,...c.musicTagIds].filter(Boolean)});Array.isArray((e=t==null?void 0:t.data)==null?void 0:e.rows)&&(a.list=t.data.rows)}catch(t){}a.loading=!1},u=(e,t)=>{if(!(e!=null&&e.length))return;const i={columnName:e[0].columnName,list:[]},n=[];for(let o=0;o<e.length;o++)i.list.push({name:e[o].name,id:e[o].id,activeIndex:-1}),e[o].children&&n.push(...e[o].children);t.push(i),n.length&&u(n,t)};b(async()=>{a.loading=!0;try{await y(),await l(),await r.getSubjects(),localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:a.tagActiveId,subjectId:c.subjectId,musicTagIds:c.musicTagIds}))}catch(e){}a.loading=!1});const T=(e,t)=>{a.tagActiveId=e.id,c.musicTagIds=[],localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.id,subjectId:c.subjectId,musicTagIds:c.musicTagIds}));const i=[];u(a.tags[t].children,i),a.tagChildren=i,l()},_=(e,t)=>{const i=a.tagChildren[e].list[a.tagChildren[e].activeIndex],n=a.tagChildren[e].list[t];i&&i.id!==n.id&&(c.musicTagIds=c.musicTagIds.filter(o=>o!==i.id)),c.musicTagIds.includes(n.id)?(c.musicTagIds=c.musicTagIds.filter(o=>o!==n.id),a.tagChildren[e].activeIndex=-1):(c.musicTagIds.push(n.id),a.tagChildren[e].activeIndex=t),localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:a.tagActiveId,subjectId:c.subjectId,musicTagIds:c.musicTagIds})),l()};return()=>{let e;return s("div",{class:d.container},[s("div",{class:d.tools},[s("div",{class:d.tagWrap},[s("div",{class:d.tags},[s(m,{size:[20,12]},{default:()=>{var t,i;return[s("span",{class:d.firstButton},[(i=(t=a.tags)==null?void 0:t[0])==null?void 0:i.columnName]),a.tags.map((n,o)=>s(I,null,[s(h,{round:!0,secondary:a.tagActiveId!==n.id,type:a.tagActiveId===n.id?"primary":"default",onClick:()=>T(n,o)},{default:()=>[n.name]})]))]}})]),a.tagChildren.map((t,i)=>s("div",{class:d.tags},[s(m,{size:[20,12]},{default:()=>[s("span",{class:d.firstButton},[t.columnName]),t.list.map((n,o)=>s(I,null,[s(h,{round:!0,secondary:t.activeIndex!==o,type:t.activeIndex===o?"primary":"default",onClick:()=>_(i,o)},{default:()=>[n.name]})]))]})])),s("div",{class:d.tags},[s(m,{size:[20,12]},{default:()=>[s("span",{class:d.firstButton},[C("声部")]),r.getSubjectAllList.map(t=>s(I,null,[s(h,{round:!0,secondary:t.id!==c.subjectId,type:t.id===c.subjectId?"primary":"default",onClick:()=>{c.subjectId=t.id,localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:a.tagActiveId,subjectId:t.id,musicTagIds:c.musicTagIds})),l()}},{default:()=>[t.name]})]))]})])]),s(A,{round:!0,onSearch:t=>{c.keyword=t,l()}},null)]),s(j,{show:a.loading},{default:()=>[s("div",{class:[d.content,a.loading?d.loadingContent:""]},[a.list.length>0?s(m,{size:[50,40]},$(e=a.list.map((t,i)=>s("div",{class:d.item,key:"item-".concat(i),onClick:()=>{sessionStorage.setItem("musicSubjectList",JSON.stringify(t.subjects)),p.push({path:"/xiaoku-music",query:{id:t.id,name:t.name}})}},[s("div",{class:d.cover},[s("div",{class:d.itemImg},[s("div",{class:d.itemBg},null),s(N,{objectFit:"cover",src:t.coverImg,lazy:!0,previewDisabled:!0,onLoad:n=>{n.target.dataset.loaded="true"}},null)])]),s("div",{class:d.itemName},[t.name])])))?e:{default:()=>[e]}):"",!a.loading&&a.list.length<=0&&s(O,null,null)])]})])}}});export{Y as default};
|