index-65ce3d8e-1714059328110.js 5.7 KB

1
  1. import{T}from"./index-77b6086f-1714059328110.js";import{d as S,u as C,e as v,p as j,f as a,w as I,F as h,j as m,k as B,aA as N,C as k,v as w}from"./index-e9eb06c1-1714059328110.js";import{a as b,b as W}from"./api-03aa9c91-1714059328110.js";import{T as O}from"./index-3a6c73b8-1714059328110.js";import{u as J}from"./catchData-15ddf6d2-1714059328110.js";const E="_container_1ejaf_1",F="_tools_1ejaf_8",z="_tagWrap_1ejaf_26",L="_tags_1ejaf_30",P="_firstButton_1ejaf_33",V="_content_1ejaf_48",q="_loadingContent_1ejaf_58",D="_itemWrap_1ejaf_61",M="_itemWrapBox_1ejaf_66",R="_item_1ejaf_61",U="_cover_1ejaf_81",X="_itemImg_1ejaf_98",$="_itemBg_1ejaf_128",G="_itemName_1ejaf_153",H="_popSelect1_1ejaf_161",K="_textBtn_1ejaf_171",Q="_iconArrow_1ejaf_171",Y="_textBtnActive_1ejaf_183",n={container:E,tools:F,tagWrap:z,tags:L,firstButton:P,content:V,loadingContent:q,itemWrap:D,itemWrapBox:M,item:R,cover:U,itemImg:X,itemBg:$,itemName:G,popSelect1:H,textBtn:K,iconArrow:Q,textBtnActive:Y},it=S({name:"XiaokuAi",setup(){const f=J(),_=C(),p=localStorage.getItem("xiaoku-ai-search"),g=p?JSON.parse(p):{},c=v({musicTagIds:g.musicTagIds?g.musicTagIds:[],enable:!0,instrumentId:g.instrumentId||null,keyword:"",page:1,rows:9999}),e=v({tags:[],tagChildren:[],tagActiveId:g.tagActiveId||"",tagActive:{},tagIndex:0,list:[],loading:!1}),x=async()=>{const t=await b();if(Array.isArray(t==null?void 0:t.data)&&t.data.length){e.tags=t.data||[];const s=e.tags.findIndex(i=>i.id==e.tagActiveId);if(s>-1){e.tagActiveId=t.data[s].id;const i=[];u(t.data[s].children,i),e.tagChildren=i}else{e.tagActiveId=t.data[0].id;const i=[];u(t.data[0].children,i),e.tagChildren=i}}},d=async()=>{var t;e.loading=!0;try{const s=await W({...c,musicTagIds:[e.tagActiveId,...c.musicTagIds].filter(Boolean)});Array.isArray((t=s==null?void 0:s.data)==null?void 0:t.rows)&&(e.list=s.data.rows)}catch(s){}e.loading=!1},u=(t,s)=>{if(!(t!=null&&t.length))return;const i={columnName:t[0].columnName,list:[]},r=[];for(let o=0;o<t.length;o++)i.list.push({name:t[o].name,id:t[o].id,activeIndex:-1}),t[o].children&&r.push(...t[o].children);s.push(i),r.length&&u(r,s)};j(async()=>{e.loading=!0;try{await x(),await d(),await f.getSubjects(),localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:c.instrumentId,musicTagIds:c.musicTagIds}))}catch(t){}e.loading=!1});const A=(t,s)=>{e.tagActiveId=t.id,c.musicTagIds=[],localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:t.id,instrumentId:c.instrumentId,musicTagIds:c.musicTagIds}));const i=[];u(e.tags[s].children,i),e.tagChildren=i,d()},y=(t,s)=>{const i=e.tagChildren[t].list[e.tagChildren[t].activeIndex],r=e.tagChildren[t].list[s];i&&i.id!==r.id&&(c.musicTagIds=c.musicTagIds.filter(o=>o!==i.id)),c.musicTagIds.includes(r.id)?(c.musicTagIds=c.musicTagIds.filter(o=>o!==r.id),e.tagChildren[t].activeIndex=-1):(c.musicTagIds.push(r.id),e.tagChildren[t].activeIndex=s),localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:c.instrumentId,musicTagIds:c.musicTagIds})),d()},l=t=>{const s={};return t==null||t.forEach(i=>{i.id===e.tagIndex&&(s.selected=!0,s.name=i.name)}),s};return()=>a("div",{class:n.container},[a("div",{class:n.tools},[a("div",{class:n.tagWrap},[a("div",{class:n.tags},[a(I,{size:[20,12]},{default:()=>{var t,s;return[a("span",{class:n.firstButton},[(s=(t=e.tags)==null?void 0:t[0])==null?void 0:s.columnName]),e.tags.map((i,r)=>a(h,null,[a(m,{round:!0,secondary:e.tagActiveId!==i.id,type:e.tagActiveId===i.id?"primary":"default",onClick:()=>A(i,r)},{default:()=>[i.name]})]))]}})]),e.tagChildren.map((t,s)=>a("div",{class:n.tags},[a(I,{size:[20,12]},{default:()=>[a("span",{class:n.firstButton},[t.columnName]),t.list.map((i,r)=>a(h,null,[a(m,{round:!0,secondary:t.activeIndex!==r,type:t.activeIndex===r?"primary":"default",onClick:()=>y(s,r)},{default:()=>[i.name]})]))]})])),a("div",{class:n.tags},[a(I,{size:[20,12]},{default:()=>[a("span",{class:n.firstButton},[B("乐器")]),f.getSubjectAllList.map(t=>t.instruments&&t.instruments.length>1?a(N,{options:t.instruments,trigger:"hover",value:e.tagIndex,"onUpdate:value":[s=>e.tagIndex=s,()=>{c.instrumentId=e.tagIndex,localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:e.tagIndex,musicTagIds:c.musicTagIds})),d()}],scrollable:!0,key:t.value,class:[n.popSelect1]},{default:()=>[a(m,{round:!0,textColor:l(t.instruments).selected?"#fff":"#000",color:l(t.instruments).selected?"#198CFE":"rgba(46, 51, 56, .05)",type:l(t.instruments).selected?"primary":"default",class:[n.textBtn,l(t.instruments).selected&&n.textBtnActive]},{default:()=>[l(t.instruments).name||t.name,a("i",{class:n.iconArrow},null)]})]}):a(m,{round:!0,textColor:e.tagIndex===t.value?"#fff":"#000",color:e.tagIndex===t.value?"#198CFE":"rgba(46, 51, 56, .05)",type:e.tagIndex===t.value?"primary":"default",onClick:()=>{e.tagIndex=t.value||0,c.instrumentId=t.id,localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:t.id,musicTagIds:c.musicTagIds})),d()}},{default:()=>[t.name]}))]})])]),a(T,{round:!0,onSearch:t=>{c.keyword=t,d()}},null)]),a(k,{show:e.loading},{default:()=>[a("div",{class:[n.content,e.loading?n.loadingContent:""]},[e.list.length>0?e.list.map((t,s)=>a("div",{class:n.itemWrap},[a("div",{class:n.itemWrapBox},[a("div",{class:n.item,key:"item-".concat(s),onClick:()=>{sessionStorage.setItem("musicSubjectList",JSON.stringify(t.subjects)),_.push({path:"/xiaoku-music",query:{id:t.id,name:t.name}})}},[a("div",{class:n.cover},[a("div",{class:n.itemImg},[a("div",{class:n.itemBg},null),a(w,{objectFit:"cover",src:t.coverImg,lazy:!0,previewDisabled:!0,onLoad:i=>{i.target.dataset.loaded="true"}},null)])]),a("div",{class:n.itemName},[t.name])])])])):"",!e.loading&&e.list.length<=0&&a(O,null,null)])]})])}});export{it as default};