const{createApp}=Vue const{createVuetify,useGoTo,useDisplay}=Vuetify var data={alert:{show:false,color:'success',text:'',timeout:0,},theme:{dark:false,},nav:{showDrawer:false,showTOC:true,tocPanel:0,tab:'account',post:{discussionId:5445,currentPage:1,targetPage:1,total:7,anchor:0,goToOptions:{container:null,duration:0,easing:'easeInOutCubic',offset:-100,},worker:null,task:[],active:[],apiLock:[],originLike:new Map([]),},related:{block:1,}},search:{width:80,text:null,loading:false,},tags:[{id:34,url:'/t/0e24610c6a045c74647716303804',name:'NAS',color:'#66BB6A',icon:'mdi-nas',},{id:37,url:'/t/383344386a045c74677716241d0f',name:'云盘',color:'#66BB6A',icon:'mdi-content-save',},{id:50,url:'/t/32715a296a045c7260770f713010',name:'图床',color:'#66BB6A',icon:'mdi-tag-heart',},],posts:[{id:62498,num:0,uid:12156,content:'\u003Cp\u003E有说放本地nas的,有说lsky挂alsit。我就是想我的图床照片如果图床炸了或者换迁移,方便恢复。各位大佬 \u003Cimg src\u003D\"/z/img/ac/01.webp\"\u003E\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 14:01:12',updatedAt:'2025-03-20 14:32:06',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:62499,num:1,uid:1919,content:'\u003Cp\u003E没有最好,够用就行。\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 14:13:48',updatedAt:'2025-03-20 14:32:06',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:62500,num:2,uid:2215,content:'\u003Cp\u003E够用就行,自用啥都可以\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 14:16:32',updatedAt:'2025-03-20 14:32:06',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:62501,num:3,uid:1470,content:'\u003Cp\u003E稳大于好\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 14:21:32',updatedAt:'2025-03-20 14:32:06',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:62502,num:4,uid:12156,content:'\u003Cp\u003E求个方案\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 14:21:48',updatedAt:'2025-03-20 14:32:06',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:62503,num:5,uid:1847,content:'\u003Cp\u003ER2\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 14:24:33',updatedAt:'2025-03-20 14:32:06',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:62504,num:6,uid:3386,content:'\u003Cp\u003E自己写一个,只需要把图片文件和路径对映就行了,反正是自己用。\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-19 14:28:06',updatedAt:'2025-03-20 14:32:06',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[2215,{uid:2215,url:'/u/2c1e7f556a045c75626b536f35230a2e',avatar:'/a/2c1e7f556a045c75626b536f35230a2e',username:'mengta🤖',}],[1847,{uid:1847,url:'/u/38796a396a045c76686e516f1b131c3e',avatar:'/a/38796a396a045c76686e516f1b131c3e',username:'Nidongwoma🤖',}],[1919,{uid:1919,url:'/u/14234b066a045c76696b5f6f473b602f',avatar:'/a/14234b066a045c76696b5f6f473b602f',username:'玩具🤖',}],[12156,{uid:12156,url:'/u/2a7a65296a045d75616f506f343c3d7e',avatar:'/a/2a7a65296a045d75616f506f343c3d7e',username:'kidoneself🤖',}],[3386,{uid:3386,url:'/u/140574016a045c746362506f450a3912',avatar:'/a/140574016a045c746362506f450a3912',username:'SpeXialNetwork🤖',}],[1470,{uid:1470,url:'/u/221966176a045c76646d566f4e502a2a',avatar:'/a/221966176a045c76646d566f4e502a2a',username:'石原里美🤖',}],]),related:[{title:'兰空图床马上要涨价了!',url:'/d/2f78602b6a045c77606a567a445d6b6a1d2a3b0a',},{title:'回顾 2024 年及以前你入手的迷你主机',url:'/d/690846086a045c77606a567a4551616a542d3d03',},{title:'玩 NAS 的人到底是被它的什么吸引了?',url:'/d/3c3150186a045c77606a567a455a6b6a2d2d323e',},{title:'晚上睡觉大家是否被光猫/路由器/Nas 的网口灯闪烁困扰?',url:'/d/3b1146396a045c77606a567a4758666a09083117',},{title:'过客图床测试',url:'/d/33105d076a045c77606a5675405a6b6a1a73623e',},{title:'有大佬会minio接入CloudFlare-ImgBed',url:'/d/091e5f206a045c77606a5675405b606a2e39113c',},{title:'ts-464c 便宜不',url:'/d/3633045e6a045c77606a5675425d666a3c2c2514',},{title:'问一个关于 alist 的问题',url:'/d/2f2605276a045c77606a56754451606a27001518',},{title:'阿里云盘 WebDAV 体验如何?',url:'/d/3419615b6a045c77606a5675445a626a050a1e33',},{title:'寻找一款支持 SSD 的 NAS 升级现有 DS218+',url:'/d/6f7a412e6a045c77606a5675445b636a3412231a',},{title:'发几个馒头药',url:'/d/037e7c2b6a045c77606a5675455b666a3e042321',},{title:'qnap 威联通 nas 是我用过最难用的 nas,谨慎避坑',url:'/d/1b0a763a6a045c77606a5675475e646a1d112a63',},{title:'NAS 求推荐,绿联 DXP2800 vs 群晖 DS224+ (轻度使用+注重隐私)',url:'/d/303864176a045c77606a5675475e656a0e190418',},{title:'Nas 求推荐 少折腾、备份文件、至少 8t、不算盘 3000 左右',url:'/d/363150086a045c77606a5675475d6a6a2f160125',},{title:'小体积低功耗+ECC 内存的 NAS 有没有解',url:'/d/1d3a6a556a045c77606a5675475b606a08131522',},{title:'n150 的性能是物理飞牛还是虚拟飞牛?',url:'/d/220f56596a045c77606a56744e59626a20310b37',},{title:'[求] NAS 备份盘推荐🙏',url:'/d/127b035b6a045c77606a56744f5c646a1a0c6667',},{title:'没有 nas, win10 电脑里的片,能刮削么?',url:'/d/343a7b586a045c77606a56744f5d616a00752b23',},{title:'用 ZeroTier 访问家里 NAS 的数据,感觉网速很慢,有什么办法提升访问速度吗',url:'/d/207d5a346a045c77606a56744f586a6a2b2b3b1a',},{title:'玩bt必备——PeerBanHelper',url:'/d/08257a0f6a045c77606a5674405c646a0e3b2a18',},],} const App={setup(){const goTo=useGoTo() const{mdAndUp}=useDisplay() return{goTo,mdAndUp}},data(){return data;},mounted(){const themeDark=localStorage.getItem("themeDark") if(themeDark!==null){this.theme.dark=JSON.parse(themeDark)} if(this.nav.post.total>(this.nav.post.currentPage-1)*100+20){let moreLen=100 if(this.nav.post.total({id:null,num:(this.nav.post.currentPage-1)*100+v,uid:null,content:null,ipRegion:null,updatedByUid:null,createdAt:null,updatedAt:null,mentionNum:null,mentionedBy:null,mentionUsers:null,likeUsers:null,})) this.posts.push(...morePosts.slice(20))} this.workerStart() const hash=window.location.hash const match=hash.match(/#(\d+)/) if(match){const n=parseInt(match[1],10) if(n>=(this.nav.post.currentPage-1)*100&&n{this.jumpTo(n)})}} this.$nextTick(()=>{this.addHeadingIds() tocbot.init({tocSelector:'.toc',contentSelector:'#post-content-0',headingSelector:'h2, h3, h4',headingsOffset:100,scrollSmoothOffset:-100,scrollSmooth:true,collapseDepth:6,onClick:function(e){setTimeout(()=>{history.replaceState(null,'',window.location.pathname+window.location.search)},0)},}) tocbot.refresh()});},beforeUnmount(){this.workerStop() if(this.quill){this.quill.destroy() this.quill=null}},computed:{dposts(){return this.posts.slice(20);},},created(){},methods:{successAlert(msg){this.alert={show:true,color:'success',text:msg,timeout:1500,}},failureAlert(msg){this.alert={show:true,color:'error',text:msg,timeout:5000,}},flipThemeDark(){this.theme.dark=!this.theme.dark localStorage.setItem("themeDark",JSON.stringify(this.theme.dark))},toSearch(){if(!this.search.text){this.failureAlert('搜索词不能为空') return} let keywords=this.search.text.trim() if(keywords.length<1){this.failureAlert('搜索词不能为空') return} if(keywords.length>100){this.failureAlert('搜索词过长') return} this.doSearch(keywords)},toReg(){window.location.href="/reg"},toLogin(){window.location.href="/login"},toPage(){let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,this.nav.post.targetPage>1?`/${this.nav.post.targetPage}`:'') window.location.href=url},toLoadRelated({done}){if(this.my&&this.my.uid){this.apiLoadRelated({done})}else{done('ok')}},workerStart(){this.nav.post.worker=setInterval(()=>{this.workerLoad()},500);},workerStop(){if(this.nav.post.worker){clearInterval(this.nav.post.worker);this.nav.post.worker=null;}},async jumpTo(num){const page=Math.floor(num/100)+1 const i=num-(page-1)*100 if(page===this.nav.post.currentPage){this.goTo("#post-"+num,this.nav.post.goToOptions) if(!this.posts[i].id){const block=Math.floor(num/20)+1 this.nav.post.apiLock[block]=true await this.apiLoadPosts(block) this.$nextTick(()=>{this.goTo("#post-"+num,this.nav.post.goToOptions)})}}else{let url=window.location.href url=url.replace(/(\/\d+)?(#[0-9]+)?$/,page>1?`/${page}`:'') url=url+"#"+num window.location.href=url}},postIntersect(num){return(isIntersecting,entries,observer)=>{if(isIntersecting){this.nav.post.task.push(num) this.nav.post.active.push(num) this.nav.post.active=this.nav.post.active.filter(item=>Math.abs(item-num)<=5) this.nav.post.active.sort((a,b)=>a-b)}else{this.nav.post.active=this.nav.post.active.filter(item=>item!==num)} if(this.nav.post.active[0]){this.nav.post.anchor=this.nav.post.active[0]}else{this.nav.post.anchor=0}}},async apiLoadPosts(block){try{const response=await axios.post('/fapi/v1/post/block/'+block,{discussionId:this.nav.post.discussionId,}) if(response.data.code===0){response.data.data.posts.forEach(post=>{const i=post.num%100 Object.assign(this.posts[i],post)}) response.data.data.users.forEach(user=>{this.usersMap.set(user.uid,user)})}else{this.failureAlert('回帖数据加载失败: '+response.data.msg)}}catch(error){this.failureAlert('回帖数据加载失败: '+error)} this.nav.post.apiLock[block]=false},workerLoad(){while(this.nav.post.task.length){const num=this.nav.post.task.pop() const i=num-(this.nav.post.currentPage-1)*100 if(!this.posts[i].id){const block=Math.floor(num/20)+1 if(!this.nav.post.apiLock[block]){this.nav.post.apiLock[block]=true this.apiLoadPosts(block)}}}},getTimeInfo(t){if(!t){return ""} const now=new Date();const then=new Date(t);const diff=now-then;const minute=60*1000;const hour=minute*60;const day=hour*24;const month=day*30;const year=month*12;if(diffpost.num===num) if(!post){return "#"+num} const uid=post.uid const username=this.usersMap.get(uid)?.username if(!username){return "#"+num} return username},getUsernameByPostId(id){const post=this.posts.find(post=>post.id===id) if(!post){return "#"+this.getPostNumByPostId(id)} const uid=post.uid const username=this.usersMap.get(uid).username if(!username){return "#"+this.getPostNumByPostId(id)} return username},getPostNumByPostId(id){const post=this.posts.find(post=>post.id===id) return post.num},getPostById(id){const post=this.posts.find(post=>post.id===id) return post},getPostByNum(num){const post=this.posts.find(post=>post.num===num) return post},getAvatarByUid(uid){const avatar=this.usersMap.get(uid)?.avatar if(!avatar){return this.getRandomAvatar()} return avatar},getAvatarByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post){return this.getRandomAvatar()} const uid=post.uid return this.getAvatarByUid(uid)},getRandomAvatar(){const num=Math.floor(Math.random()*100) return "https://randomuser.me/api/portraits/men/"+num+".jpg"},getUrlByUid(uid){const url=this.usersMap.get(uid)?.url if(!url){return ""} return url},getTextByPostNum(num){const post=this.posts.find(post=>post.num===num) if(!post||!post.content){return '点击跳转到#'+num+'查看'} const parser=new DOMParser() const doc=parser.parseFromString(post.content,'text/html') const text=doc.body.textContent||'' return text.slice(0,100)},addHeadingIds(){const content=document.getElementById('post-content-0') if(!content){this.nav.showTOC=false return} const headings=content.querySelectorAll('h2, h3, h4') headings.forEach((heading,index)=>{if(!heading.id){heading.id=`toc-nav-${index}`}}) if(headings.length==0){this.nav.showTOC=false}},async doSearch(keywords){this.search.loading=true try{const response=await axios.post('/fapi/v1/search',{keywords:keywords,}) if(response.data.code===0){if(response.data.data.hash&&response.data.data.hash.length===32){window.location.href="/s/"+response.data.data.hash}else{this.failureAlert('搜索失败: 搜索服务异常')}}else{this.failureAlert('搜索失败: '+response.data.msg)}}catch(error){this.failureAlert('搜索失败: '+error)} this.search.loading=false},debounce(fn,delay){let timer=null return function(...args){if(timer)clearTimeout(timer) timer=setTimeout(()=>{fn.apply(this,args)},delay);};},},watch:{'nav.post.targetPage':{handler:async function(newV,oldV){this.toPage()},immediate:false},},} const vuetify=createVuetify({defaults:{global:{ripple:true,},},}) const app=createApp(App) app.use(vuetify).mount("#app")