1 |
- import{T as y}from"./index-7941bfe4-1716977058336.js";import{d as T,u as S,e as p,p as C,f as s,w as f,F as h,j as m,k as B,aB as N,D as w,v as b}from"./index-70c8ab8f-1716977058336.js";import{a as W,b as j}from"./api-9a664c2f-1716977058336.js";import{T as O}from"./index-32c8a13d-1716977058336.js";import{u as E}from"./catchData-cc91cb99-1716977058336.js";const J="_container_1n8ok_1",F="_tools_1n8ok_8",z="_tagWrap_1n8ok_26",L="_tags_1n8ok_30",D="_firstButton_1n8ok_33",P="_content_1n8ok_51",V="_loadingContent_1n8ok_61",q="_itemWrap_1n8ok_64",M="_itemWrapBox_1n8ok_69",R="_item_1n8ok_64",U="_cover_1n8ok_84",X="_itemImg_1n8ok_101",$="_itemBg_1n8ok_131",G="_itemName_1n8ok_156",H="_popSelect1_1n8ok_164",K="_textBtn_1n8ok_174",Q="_iconArrow_1n8ok_174",Y="_textBtnActive_1n8ok_186",o={container:J,tools:F,tagWrap:z,tags:L,firstButton:D,content:P,loadingContent:V,itemWrap:q,itemWrapBox:M,item:R,cover:U,itemImg:X,itemBg:$,itemName:G,popSelect1:H,textBtn:K,iconArrow:Q,textBtnActive:Y},nt=T({name:"XiaokuAi",setup(){const I=E(),_=S(),v=localStorage.getItem("xiaoku-ai-search"),u=v?JSON.parse(v):{},i=p({musicTagIds:u.musicTagIds?u.musicTagIds:[],enable:!0,instrumentId:u.instrumentId||null,keyword:"",page:1,rows:9999}),e=p({tags:[],tagChildren:[],tagActiveId:u.tagActiveId||"",tagActive:{},tagIndex:u.instrumentId||0,list:[],loading:!1}),k=async()=>{const t=await W();if(Array.isArray(t==null?void 0:t.data)&&t.data.length){e.tags=t.data||[];const a=e.tags.findIndex(n=>n.id==e.tagActiveId);if(a>-1){e.tagActiveId=t.data[a].id;const n=[];g(t.data[a].children,n),e.tagChildren=n}else{e.tagActiveId=t.data[0].id;const n=[];g(t.data[0].children,n),e.tagChildren=n}}},d=async()=>{var t;e.loading=!0;try{const a=await j({...i,musicTagIds:[e.tagActiveId,...i.musicTagIds].filter(Boolean)});Array.isArray((t=a==null?void 0:a.data)==null?void 0:t.rows)&&(e.list=a.data.rows)}catch(a){}e.loading=!1},g=(t,a)=>{if(!(t!=null&&t.length))return;const n={columnName:t[0].columnName,list:[]},r=[];for(let c=0;c<t.length;c++)n.list.push({name:t[c].name,id:t[c].id,activeIndex:-1}),t[c].children&&r.push(...t[c].children);a.push(n),r.length&&g(r,a)};C(async()=>{e.loading=!0;try{if(await k(),await d(),await I.getSubjects(),localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:i.instrumentId,musicTagIds:i.musicTagIds})),console.log(i.instrumentId,"forms.instrumentId"),i.instrumentId){let t=[];I.getSubjectInstruments.forEach(a=>{Array.isArray(a.instruments)&&a.instruments.forEach(n=>{i.instrumentId===n.value&&(t=a.instruments||[])})}),console.log(t,"childInstruments"),t.length>0&&l(t)}}catch(t){}e.loading=!1});const x=(t,a)=>{e.tagActiveId=t.id,i.musicTagIds=[],localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:t.id,instrumentId:i.instrumentId,musicTagIds:i.musicTagIds}));const n=[];g(e.tags[a].children,n),e.tagChildren=n,d()},A=(t,a)=>{const n=e.tagChildren[t].list[e.tagChildren[t].activeIndex],r=e.tagChildren[t].list[a];n&&n.id!==r.id&&(i.musicTagIds=i.musicTagIds.filter(c=>c!==n.id)),i.musicTagIds.includes(r.id)?(i.musicTagIds=i.musicTagIds.filter(c=>c!==r.id),e.tagChildren[t].activeIndex=-1):(i.musicTagIds.push(r.id),e.tagChildren[t].activeIndex=a),localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:i.instrumentId,musicTagIds:i.musicTagIds})),d()},l=t=>{const a={};return t==null||t.forEach(n=>{n.id===e.tagIndex&&(a.selected=!0,a.name=n.name)}),a};return()=>s("div",{class:o.container},[s("div",{class:o.tools},[s("div",{class:o.tagWrap},[s("div",{class:o.tags},[s(f,{size:[20,12]},{default:()=>{var t,a;return[s("span",{class:o.firstButton},[(a=(t=e.tags)==null?void 0:t[0])==null?void 0:a.columnName]),e.tags.map((n,r)=>s(h,null,[s(m,{round:!0,secondary:e.tagActiveId!==n.id,type:e.tagActiveId===n.id?"primary":"default",onClick:()=>x(n,r)},{default:()=>[n.name]})]))]}})]),e.tagChildren.map((t,a)=>s("div",{class:o.tags},[s(f,{size:[20,12]},{default:()=>[s("span",{class:o.firstButton},[t.columnName]),t.list.map((n,r)=>s(h,null,[s(m,{round:!0,secondary:t.activeIndex!==r,type:t.activeIndex===r?"primary":"default",onClick:()=>A(a,r)},{default:()=>[n.name]})]))]})])),s("div",{class:o.tags},[s(f,{size:[20,12]},{default:()=>[s("span",{class:o.firstButton},[B("乐器")]),I.getSubjectInstruments.map(t=>t.instruments&&t.instruments.length>1?s(N,{options:t.instruments,trigger:"hover",value:e.tagIndex,"onUpdate:value":[a=>e.tagIndex=a,()=>{i.instrumentId=e.tagIndex,localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:e.tagIndex,musicTagIds:i.musicTagIds})),d()}],scrollable:!0,key:t.value,class:[o.popSelect1]},{default:()=>[s(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:[o.textBtn,l(t.instruments).selected&&o.textBtnActive]},{default:()=>[l(t.instruments).name||t.name,s("i",{class:o.iconArrow},null)]})]}):s(m,{round:!0,textColor:e.tagIndex===(t.value||0)?"#fff":"#000",color:e.tagIndex===(t.value||0)?"#198CFE":"rgba(46, 51, 56, .05)",type:e.tagIndex===(t.value||0)?"primary":"default",onClick:()=>{e.tagIndex=t.value||0,i.instrumentId=t.value,localStorage.setItem("xiaoku-ai-search",JSON.stringify({tagActiveId:e.tagActiveId,instrumentId:t.value,musicTagIds:i.musicTagIds})),d()}},{default:()=>[t.name]}))]})])]),s(y,{round:!0,onSearch:t=>{i.keyword=t,d()}},null)]),s(w,{show:e.loading},{default:()=>[s("div",{class:[o.content,e.loading?o.loadingContent:""]},[e.list.length>0?e.list.map((t,a)=>s("div",{class:o.itemWrap},[s("div",{class:o.itemWrapBox},[s("div",{class:o.item,key:"item-".concat(a),onClick:()=>{sessionStorage.setItem("musicSubjectList",JSON.stringify(t.subjects)),_.push({path:"/xiaoku-music",query:{id:t.id,name:t.name}})}},[s("div",{class:o.cover},[s("div",{class:o.itemImg},[s("div",{class:o.itemBg},null),s(b,{objectFit:"cover",src:t.coverImg,lazy:!0,previewDisabled:!0,onLoad:n=>{n.target.dataset.loaded="true"}},null)])]),s("div",{class:o.itemName},[t.name])])])])):"",!e.loading&&e.list.length<=0&&s(O,null,null)])]})])}});export{nt as default};
|