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:6037,currentPage:1,targetPage:1,total:49,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:70573,num:0,uid:13216,content:'',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 15:41:43',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70574,num:1,uid:7490,content:'fiber',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 15:43:43',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70575,num:2,uid:13217,content:'resty v2/v3',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 15:44:55',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70576,num:3,uid:6217,content:'grequests go-resty',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 15:44:56',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70577,num:4,uid:849,content:'标准库',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 15:47:23',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70578,num:5,uid:7596,content:'标准库',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 15:47:50',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70579,num:6,uid:13218,content:'req',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 15:49:19',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70580,num:7,uid:13219,content:'beego',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 15:52:27',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70581,num:8,uid:12755,content:'gin',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 15:58:16',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70582,num:9,uid:708,content:'resty',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 16:12:20',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70583,num:10,uid:13220,content:'resty',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 16:17:54',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70584,num:11,uid:13221,content:'https://github.com/faceair/request',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 16:20:00',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70585,num:12,uid:13222,content:'标准库',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 16:26:11',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70586,num:13,uid:13223,content:'gohttp',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 16:32:49',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70587,num:14,uid:13223,content:'https://github.com/sunshineplan/gohttp',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 16:38:19',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70588,num:15,uid:7079,content:'https://github.com/imroc/req 和 resty 看需求用',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 16:38:53',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70589,num:16,uid:13224,content:'goframe 自带 gclient',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 16:43:55',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70590,num:17,uid:4970,content:'resty',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 16:45:45',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70591,num:18,uid:2949,content:'gin',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 16:46:53',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:70592,num:19,uid:8205,content:'resty',ipRegion:'',updatedByUid:0,createdAt:'2025-03-20 17:06:32',updatedAt:'2025-03-23 11:51:21',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[7490,{uid:7490,url:'/u/232177556a045c706463566f1c232224',avatar:'/a/232177556a045c706463566f1c232224',username:'helone🤖',}],[8205,{uid:8205,url:'/u/6d115d356a045c7f626a536f062d3e14',avatar:'/a/6d115d356a045c7f626a536f062d3e14',username:'yushenglin🤖',}],[13221,{uid:13221,url:'/u/2e067e196a045d746268576f002a3700',avatar:'/a/2e067e196a045d746268576f002a3700',username:'faceair🤖',}],[7596,{uid:7596,url:'/u/2801590c6a045c706563506f415a3412',avatar:'/a/2801590c6a045c706563506f415a3412',username:'qW7bo2FbzbC0🤖',}],[12755,{uid:12755,url:'/u/3e7b03096a045d75676f536f043a2222',avatar:'/a/3e7b03096a045d75676f536f043a2222',username:'a**oker🤖',}],[13218,{uid:13218,url:'/u/2e1158286a045d74626b5e6f12212b08',avatar:'/a/2e1158286a045d74626b5e6f12212b08',username:'chimojiacai🤖',}],[7079,{uid:7079,url:'/u/36217f2c6a045c70606d5f6f06042522',avatar:'/a/36217f2c6a045c70606d5f6f06042522',username:'viking602🤖',}],[849,{uid:849,url:'/u/1f187e076a045c77686e5f6f141b172d',avatar:'/a/1f187e076a045c77686e5f6f141b172d',username:'strobber16🤖',}],[13219,{uid:13219,url:'/u/6d78631d6a045d74626b5f6f3d063a77',avatar:'/a/6d78631d6a045d74626b5f6f3d063a77',username:'proxychains🤖',}],[2949,{uid:2949,url:'/u/3e7b041a6a045c75696e5f6f31216420',avatar:'/a/3e7b041a6a045c75696e5f6f31216420',username:'sn0wdr1am🤖',}],[13217,{uid:13217,url:'/u/287068186a045d74626b516f04051636',avatar:'/a/287068186a045d74626b516f04051636',username:'hteen🤖',}],[4970,{uid:4970,url:'/u/18227c2b6a045c73696d566f3d390332',avatar:'/a/18227c2b6a045c73696d566f3d390332',username:'chengxiao🤖',}],[13222,{uid:13222,url:'/u/2c0b583e6a045d746268546f152e2213',avatar:'/a/2c0b583e6a045d746268546f152e2213',username:'yrzs🤖',}],[6217,{uid:6217,url:'/u/1f1c46206a045c71626b516f410f0b77',avatar:'/a/1f1c46206a045c71626b516f410f0b77',username:'kxg3030🤖',}],[13223,{uid:13223,url:'/u/091865296a045d746268556f41252922',avatar:'/a/091865296a045d746268556f41252922',username:'Sunshineplan🤖',}],[13216,{uid:13216,url:'/u/2219401d6a045d74626b506f23260b0f',avatar:'/a/2219401d6a045d74626b506f23260b0f',username:'inSpring🤖',}],[13224,{uid:13224,url:'/u/2c2244586a045d746268526f03280472',avatar:'/a/2c2244586a045d746268526f03280472',username:'lanceadd🤖',}],[13220,{uid:13220,url:'/u/342a5e346a045d746268566f35196675',avatar:'/a/342a5e346a045d746268566f35196675',username:'brucedone🤖',}],[708,{uid:708,url:'/u/6f7c451c6a045c77676a5e6f46506017',avatar:'/a/6f7c451c6a045c77676a5e6f46506017',username:'crackidz🤖',}],]),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:'大家 golang 项目里目前在用哪个 log 库打印日志呢?',url:'/d/623a67086a045c77606a5674455c646a5d0c1f65',},{title:'朋友们,有哪些基于 Gin 框架的优秀开源项目,用来学习?',url:'/d/28116a596a045c77606a5674455d656a3c326135',},{title:'新手提问, Go 作为一个 GC 语言,为什么要设计成带指针类型的呢?',url:'/d/12067f176a045c77606a5674455b626a072a2734',},{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")