Files
sbnews/server/public/mobile/assets/pages-channel-channel-manage.WKk2BfHQ.js
T

2 lines
4.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{d as a,u as e,r as l,g as n,b as s,c as t,w as c,m as i,W as u,X as o,j as d,k as _,P as r,o as f,l as h,q as g,t as v,S as p,v as m,x as y,F as x,y as k,z as S,D as w,N as C,e as b,Y as j,s as L,Z as z,a0 as A,_ as E}from"./index-DXU7LX1r.js";import{g as I}from"./news.CmjhWsFJ.js";const M="user_my_channels",T=E(a({__name:"channel-manage",setup(a){const E=e(),T=l(0),W=l(!1),q=l([]),D=l([]),F=l(-1),N=l([]),P=l(!1);n({success:a=>{T.value=0}});const X=()=>{const a=new Set(q.value.map(a=>String(a.id))),e=D.value.filter(e=>!a.has(String(e.id)));N.value=e.length?[{title:"推荐频道",channels:e}]:[]},Y=()=>{W.value||E.isLogin?(W.value&&P.value&&(Z(),P.value=!1),W.value=!W.value):C({title:"提示",content:"登录后才能编辑频道,是否前往登录?",confirmText:"去登录",success:a=>{a.confirm&&b({url:"/pages/login/login"})}})},Z=()=>{const a=q.value.filter(a=>a.id).map(a=>a.id);E.isLogin?j({channel_ids:a}).catch(a=>{console.log("保存频道配置失败=>",a),d({title:"保存失败",icon:"none"})}):L(M,a)},B=a=>{P.value&&Z(),z("channelChanged",{channels:P.value?[...q.value]:null,selectIndex:a??-1}),A()},G=()=>{B()};return s(()=>{P.value=!1,(async()=>{try{const e=await I();D.value=e||[];const l=(e||[]).map(a=>({...a,fixed:!1}));if(E.isLogin)try{const a=await u();if(a&&Array.isArray(a.channel_ids)){const l=a.channel_ids,n=new Map(e.map(a=>[String(a.id),a])),s=[];return l.forEach(a=>{const e=n.get(String(a));e&&s.push({...e,fixed:!1})}),q.value=s,void X()}}catch(a){console.log("获取用户频道配置失败=>",a)}else{const a=o(M);if(a&&a.length){const l=new Map(e.map(a=>[String(a.id),a])),n=[];if(a.forEach(a=>{const e=l.get(String(a));e&&n.push({...e,fixed:!1})}),n.length)return q.value=n,void X()}}q.value=l,X()}catch(a){console.log("获取分类失败=>",a),q.value.length||d({title:"加载失败,请重试",icon:"none"})}})()}),(a,e)=>{const l=r("u-icon"),n=_,s=g,u=p;return f(),t(n,{class:"channel-manage-page",style:i({paddingTop:T.value+"px"})},{default:c(()=>[h(n,{class:"page-header"},{default:c(()=>[h(n,{class:"page-header__back",onClick:G},{default:c(()=>[h(l,{name:"arrow-left",size:"36",color:"#333"})]),_:1}),h(s,{class:"page-header__title"},{default:c(()=>[v("频道管理")]),_:1}),h(n,{class:"page-header__right"})]),_:1}),h(u,{"scroll-y":"",class:"page-scroll"},{default:c(()=>[h(n,{class:"channel-section"},{default:c(()=>[h(n,{class:"channel-section__header"},{default:c(()=>[h(s,{class:"channel-section__title"},{default:c(()=>[v("我的频道")]),_:1}),h(s,{class:"channel-section__tip"},{default:c(()=>[v(m(W.value?"拖拽可排序":"点击进入频道"),1)]),_:1}),h(s,{class:"channel-section__edit",onClick:Y},{default:c(()=>[v(m(W.value?"完成":"编辑"),1)]),_:1})]),_:1}),h(n,{class:"channel-grid"},{default:c(()=>[(f(!0),y(x,null,k(q.value,(a,e)=>(f(),t(n,{key:a.id||"__recommend__",class:S(["channel-tag",{"channel-tag--active":e===F.value,"channel-tag--fixed":a.fixed}]),onClick:a=>(a=>{if(W.value){if(q.value[a].fixed)return;q.value.splice(a,1),X(),P.value=!0}else F.value=a,B(a)})(e)},{default:c(()=>[h(s,null,{default:c(()=>[v(m(a.name),1)]),_:2},1024),W.value&&!a.fixed?(f(),t(n,{key:0,class:"channel-tag__remove-btn"},{default:c(()=>[h(s,{class:"channel-tag__remove"},{default:c(()=>[v("×")]),_:1})]),_:1})):w("",!0)]),_:2},1032,["class","onClick"]))),128))]),_:1})]),_:1}),(f(!0),y(x,null,k(N.value,a=>(f(),t(n,{key:a.title,class:"channel-section"},{default:c(()=>[h(n,{class:"channel-section__header"},{default:c(()=>[h(s,{class:"channel-section__title"},{default:c(()=>[v(m(a.title),1)]),_:2},1024)]),_:2},1024),h(n,{class:"channel-grid"},{default:c(()=>[(f(!0),y(x,null,k(a.channels,a=>(f(),t(n,{key:a.id,class:"channel-tag channel-tag--add",onClick:e=>(a=>{W.value&&(q.value.some(e=>String(e.id)===String(a.id))||(q.value.push({...a,fixed:!1}),X(),P.value=!0))})(a)},{default:c(()=>[h(s,null,{default:c(()=>[v(m(a.name),1)]),_:2},1024),W.value?(f(),t(s,{key:0,class:"channel-tag__add"},{default:c(()=>[v("+")]),_:1})):w("",!0)]),_:2},1032,["onClick"]))),128))]),_:2},1024)]),_:2},1024))),128))]),_:1})]),_:1},8,["style"])}}}),[["__scopeId","data-v-a65f7fdf"]]);export{T as default};