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:6257,currentPage:1,targetPage:1,total:22,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:27,url:'/t/0e2e58346a045c7567770b2b3120',name:'Go',color:'#FFA726',icon:'mdi-language-go',},],posts:[{id:73930,num:0,uid:13216,content:'',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 16:59:12',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73931,num:1,uid:5869,content:'新项目推荐官方库,1.20 还是多少版本引入那个',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 17:00:12',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73932,num:2,uid:13655,content:'现在在用 slog',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 17:02:54',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73933,num:3,uid:1143,content:'1.21',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 17:11:22',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73934,num:4,uid:9342,content:'因为啥',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 17:38:53',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73935,num:5,uid:6857,content:'log',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 17:42:13',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73936,num:6,uid:6597,content:'zap/标准库',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 17:42:39',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73937,num:7,uid:708,content:'zerolog',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 17:47:26',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73938,num:8,uid:2497,content:'官方 slog',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 17:50:44',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73939,num:9,uid:13564,content:'slog +1',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 18:22:06',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73940,num:10,uid:13656,content:'zap',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 18:28:31',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73941,num:11,uid:8188,content:'zap',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 18:40:13',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73942,num:12,uid:13657,content:'老项目 zap ,新项目 slog',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 22:28:18',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73943,num:13,uid:811,content:'zerolog',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 22:29:55',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73944,num:14,uid:64,content:'现在都切 slog 了吧,剩下就是 zap 大头了',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 22:49:30',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73945,num:15,uid:6569,content:'昨天面试还被问过这个问题,说官网的 log 日志库效率低下。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 23:06:45',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73946,num:16,uid:6569,content:'goos: darwin\u003Cbr\u003Egoarch: amd64\u003Cbr\u003Epkg: chat/cmd/test\u003Cbr\u003Ecpu: VirtualApple 58846005 19.53 ns/op 0 B/op 0 allocs/op\u003Cbr\u003EBenchmarkLogLogrus-8 10966239 104.2 ns/op 272 B/op 3 allocs/op\u003Cbr\u003EBenchmarkLogZap-8 1452225 830.7 ns/op 1609 B/op 9 allocs/op\u003Cbr\u003EPASS\u003Cbr\u003Eok chat/cmd/test 5.445s\u003Cbr\u003E\u003Cbr\u003E这是我单元测试的结果,是哪里理解排查了?',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 23:13:07',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73947,num:17,uid:4896,content:'zerolog 。slog 的 API 实在是丑陋。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-21 23:24:27',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73948,num:18,uid:8665,content:'slog +1',ipRegion:'',updatedByUid:0,createdAt:'2025-03-22 00:47:09',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:73949,num:19,uid:13658,content:'go-spew 打印',ipRegion:'',updatedByUid:0,createdAt:'2025-03-22 12:20:01',updatedAt:'2025-03-24 23:57:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[13657,{uid:13657,url:'/u/6b2d022c6a045d74666f516f3b226421',avatar:'/a/6b2d022c6a045d74666f516f3b226421',username:'wangee🤖',}],[13216,{uid:13216,url:'/u/2219401d6a045d74626b506f23260b0f',avatar:'/a/2219401d6a045d74626b506f23260b0f',username:'inSpring🤖',}],[13658,{uid:13658,url:'/u/693966156a045d74666f5e6f3f2a3e28',avatar:'/a/693966156a045d74666f5e6f3f2a3e28',username:'ziyeziye🤖',}],[811,{uid:811,url:'/u/6327551d6a045c77686b576f230b0028',avatar:'/a/6327551d6a045c77686b576f230b0028',username:'dcalsky🤖',}],[708,{uid:708,url:'/u/6f7c451c6a045c77676a5e6f46506017',avatar:'/a/6f7c451c6a045c77676a5e6f46506017',username:'crackidz🤖',}],[8665,{uid:8665,url:'/u/372e5a2b6a045c7f666c536f025a6409',avatar:'/a/372e5a2b6a045c7f666c536f025a6409',username:'SeleiXi🤖',}],[6569,{uid:6569,url:'/u/167841346a045c71656c5f6f390f6b72',avatar:'/a/167841346a045c71656c5f6f390f6b72',username:'awanganddong🤖',}],[13564,{uid:13564,url:'/u/397146586a045d74656c526f38506577',avatar:'/a/397146586a045d74656c526f38506577',username:'southwolf🤖',}],[13656,{uid:13656,url:'/u/1610441b6a045d74666f506f353a3872',avatar:'/a/1610441b6a045d74666f506f353a3872',username:'yidev🤖',}],[5869,{uid:5869,url:'/u/0f7102046a045c72686c5f6f3d5e0913',avatar:'/a/0f7102046a045c72686c5f6f3d5e0913',username:'Jinnrry🤖',}],[6597,{uid:6597,url:'/u/6d2774196a045c716563516f27101016',avatar:'/a/6d2774196a045c716563516f27101016',username:'LitterGopher🤖',}],[9342,{uid:9342,url:'/u/122501076a045c7e636e546f24502676',avatar:'/a/122501076a045c7e636e546f24502676',username:'a66243766🤖',}],[64,{uid:64,url:'/u/200101596a045c77606c526f31313604',avatar:'/a/200101596a045c77606c526f31313604',username:'k9982874🤖',}],[6857,{uid:6857,url:'/u/1d2665276a045c71686f516f380c052b',avatar:'/a/1d2665276a045c71686f516f380c052b',username:'laikick🤖',}],[1143,{uid:1143,url:'/u/1b0643096a045c76616e556f210b1b74',avatar:'/a/1b0643096a045c76616e556f210b1b74',username:'zong400🤖',}],[2497,{uid:2497,url:'/u/12397d176a045c756463516f010d2222',avatar:'/a/12397d176a045c756463516f010d2222',username:'sardina🤖',}],[4896,{uid:4896,url:'/u/280a740a6a045c736863506f21213137',avatar:'/a/280a740a6a045c736863506f21213137',username:'Trim21🤖',}],[8188,{uid:8188,url:'/u/6b0e6a386a045c7f61625e6f1b5a6b2e',avatar:'/a/6b0e6a386a045c7f61625e6f1b5a6b2e',username:'Tsunayoshi🤖',}],[13655,{uid:13655,url:'/u/231a7f0a6a045d74666f536f1c043720',avatar:'/a/231a7f0a6a045d74666f536f1c043720',username:'yangheng4922🤖',}],]),related:[{title:'大佬们平时都是怎样调试查看变量变化的? go 有哪些方便实时展示变量的库或工具?',url:'/d/221f67216a045c77606a567a455c636a23050963',},{title:'Cursor Go 开发,有哪些必装的插件?',url:'/d/337a733f6a045c77606a56754f5b6b6a39061e13',},{title:'在 Go 项目里,涉及到金额计算,大家一般用什么方式?',url:'/d/30267d146a045c77606a5675425d606a3f732227',},{title:'[全职]广州 - 潮汐 App - Golang 开发工程师',url:'/d/022a75356a045c77606a5675445d666a3b301504',},{title:'goland 如何远程开发?',url:'/d/1e1845056a045c77606a56754550676a29726b65',},{title:'开发了一个开箱即用的本地终端 Ztty',url:'/d/0c045a2e6a045c77606a5675455e6b6a3e200734',},{title:'go 部署到 1panel 上,是用源码运行 还是编译二进制运行!',url:'/d/193a435c6a045c77606a5675455c626a38360005',},{title:'[go 分布式定时任务框架] xxljob',url:'/d/357904216a045c77606a5675475f636a041a1663',},{title:'关于 Go 并发获取数据的问题,请教大家',url:'/d/687d67226a045c77606a5674415b646a1d3a3138',},{title:'macOS Goland 经常在双击 shift 全局搜索的时候,出现彩虹球,只能强制退出',url:'/d/380f58206a045c77606a5674435b666a15111c2a',},{title:'今天有个面试官和我讲 go 的协程比系统的线程更慢,这个我不能理解',url:'/d/182459046a045c77606a56744359626a1412041a',},{title:'Java 和 go 都会,以后找工作偏向哪个方面好呢',url:'/d/000b7b1b6a045c77606a5674445e656a1977262a',},{title:'作为一个传统开发者,如何使用 ai 或者机器学习实现一些简单事情',url:'/d/34015f186a045c77606a5674445e626a25016611',},{title:'朋友们,有哪些基于 Gin 框架的优秀开源项目,用来学习?',url:'/d/28116a596a045c77606a5674455d656a3c326135',},{title:'新手提问, Go 作为一个 GC 语言,为什么要设计成带指针类型的呢?',url:'/d/12067f176a045c77606a5674455b626a072a2734',},{title:'做个调研, go 语言,大家在用哪个 http 请求库?',url:'/d/337155556a045c77606a5674475a646a262a0b10',},{title:'[golang] 后端开发工程师|海外电商 AI+ SaaS 招长期远程兼职/全职',url:'/d/1d277d2a6a045c77606a5677425b616a1a211a39',},{title:'仓颉编程语言的这个反序列化和序列化比 go 复杂好多',url:'/d/361d472b6a045c77606a567745506b6a5a1a6160',},{title:'作为 Java 狗的我,学习 rust 的时候为啥总念着 go 的好呢?',url:'/d/6f2a02176a045c77606a5671435d636a2f121465',},{title:'原 Java 刚学习 go, 自己在写项目, 针对 go 日志方面的疑惑',url:'/d/6b2c02596a045c77606a56714359626a0f361626',},],} 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")