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:4299,currentPage:1,targetPage:1,total:11,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:14,url:'/t/3b3b75196a045c7664770d0c113c',name:'Linux',color:'#66BB6A',icon:'mdi-linux',},],posts:[{id:48460,num:0,uid:1802,content:'\u003Cp\u003E比如原来只有1G内存的小鸡,会分配多少Swap呢,对性能有多大的影响?我拿netcup1o鸡跑mailu邮局,给了2G Swap目前跑着还算正常,自用应该没问题,但如果真要大量首发邮件是不是性能会有影响? \u003Cimg src\u003D\"/z/img/xhj/001.webp\"\u003E\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:41:51',updatedAt:'2025-03-18 18:29:07',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48461,num:1,uid:3460,content:'\u003Cp\u003E硬盘和CPU好 就多开一些没事,都烂就少开\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:45:33',updatedAt:'2025-03-18 18:29:07',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48462,num:2,uid:1815,content:'\u003Cp\u003E内存小就开大点,内存大就开小点或者不开\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:47:12',updatedAt:'2025-03-18 18:29:07',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48463,num:3,uid:1953,content:'\u003Cp\u003E1:1\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:47:50',updatedAt:'2025-03-18 18:29:07',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48464,num:4,uid:1481,content:'\u003Cp\u003E不开 \u003Cimg src\u003D\"/z/img/xhj/007.webp\"\u003E\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:50:26',updatedAt:'2025-03-18 18:29:07',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48465,num:5,uid:5273,content:'\u003Cp\u003E内存多少开多少,最低开512mb\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:52:00',updatedAt:'2025-03-18 18:29:07',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48466,num:6,uid:9172,content:'\u003Cp\u003E1-2倍内存\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:58:58',updatedAt:'2025-03-18 18:29:08',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48467,num:7,uid:6832,content:'\u003Cp\u003E开2倍即可\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-18 00:30:57',updatedAt:'2025-03-18 18:29:08',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48468,num:8,uid:3529,content:'\u003Cp\u003Eswap是内存稀有的时代的产物,属于落后的技术\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-18 00:56:37',updatedAt:'2025-03-18 18:29:08',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48469,num:9,uid:10409,content:'\u003Cp\u003E512M 或 1G 差不多了,服务器和桌面端不一样不需要休眠,如果使用场景对性能要求不高的话,甚至不太需要开,不过开了也没什么坏事,可以在内存占用高的时候缓解压力\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-18 01:00:12',updatedAt:'2025-03-18 18:29:08',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48470,num:10,uid:5230,content:'\u003Cp\u003E 1直跑满swap会怎么样,属于长时间占用硬盘io?\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-18 01:48:21',updatedAt:'2025-03-18 18:29:08',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[5230,{uid:5230,url:'/u/6a1c63346a045c726269566f3c3e0b15',avatar:'/a/6a1c63346a045c726269566f3c3e0b15',username:'xlm🤖',}],[9172,{uid:9172,url:'/u/0d275b586a045c7e616d546f120d270d',avatar:'/a/0d275b586a045c7e616d546f120d270d',username:'666要什么自行车🤖',}],[3529,{uid:3529,url:'/u/187b77086a045c7465685f6f343d0573',avatar:'/a/187b77086a045c7465685f6f343d0573',username:'Ziggy🤖',}],[5273,{uid:5273,url:'/u/3b1f70396a045c72626d556f3e241b37',avatar:'/a/3b1f70396a045c72626d556f3e241b37',username:'上海联通9929🤖',}],[10409,{uid:10409,url:'/u/0e7060156a045d77646a5f6f1c23631d',avatar:'/a/0e7060156a045d77646a5f6f1c23631d',username:'Emphasis6191🤖',}],[3460,{uid:3460,url:'/u/182359076a045c74646c566f2622362c',avatar:'/a/182359076a045c74646c566f2622362c',username:'鸡哥兄贵🤖',}],[6832,{uid:6832,url:'/u/2f7b67186a045c716869546f03131b24',avatar:'/a/2f7b67186a045c716869546f03131b24',username:'mrfa🤖',}],[1815,{uid:1815,url:'/u/621c02006a045c76686b536f3411172a',avatar:'/a/621c02006a045c76686b536f3411172a',username:'Rain-沐辰🤖',}],[1802,{uid:1802,url:'/u/362d542a6a045c76686a546f1f056524',avatar:'/a/362d542a6a045c76686a546f1f056524',username:'yyndsk🤖',}],[1481,{uid:1481,url:'/u/6e11772f6a045c766462576f231c6221',avatar:'/a/6e11772f6a045c766462576f231c6221',username:'DeeDee🤖',}],[1953,{uid:1953,url:'/u/232445346a045c76696f556f26052a2d',avatar:'/a/232445346a045c76696f556f26052a2d',username:'p3nnn🤖',}],]),related:[{title:'有给 m2 mini 装 Linux 的吗',url:'/d/1c254b5b6a045c77606a56774e5f676a0e2d6318',},{title:'问个小白问题,debian删除软件包释放的空间变少了怎么回事',url:'/d/137c68346a045c77606a56774f5f636a39241419',},{title:'大家一般都在Linux上用哪个tun2socks项目?',url:'/d/190e76396a045c77606a5677415b616a5e20661d',},{title:'为什么在 Linux 下构建 APK 比用 Windows 快非常多',url:'/d/0c010b156a045c77606a5677445d616a06163131',},{title:'Linux 输入法推荐',url:'/d/322778026a045c77606a56774458646a05772922',},{title:'Ubuntu apt upgrade 升级逻辑是什么?',url:'/d/007f510e6a045c77606a567745506a6a02110514',},{title:'现在入行 Linux 运维还有希望吗?',url:'/d/682d7f016a045c77606a5671415e6a6a0407241b',},{title:'Android 15 现在也能用官方的 Linux 了',url:'/d/2d0b44556a045c77606a56734e5f606a061a606a',},],} 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")