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:2411,currentPage:1,targetPage:1,total:4,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:30,url:'/t/6c1e511e6a045c7460771613430f',name:'Python',color:'#FFA726',icon:'mdi-language-python',},],posts:[{id:28989,num:0,uid:7979,content:'\u003Cp\u003E\u003Cimg alt\u003D\"\" src\u003D\"https://foruda.gitee.com/images/1741865117767187605/30a7ceaf_584259.png\"\u003E\u003C/p\u003E\u003Cp\u003E可以自定义组件,然后每个组件对应 jupyter 的一个单元格,就可以可视化低代码开发了\u003C/p\u003E\u003Cp\u003E\u003Cimg alt\u003D\"\" src\u003D\"https://foruda.gitee.com/images/1741865145434867925/36227fc0_584259.png\"\u003E\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-13 19:29:11',updatedAt:'2025-03-15 14:40:30',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:28990,num:1,uid:7980,content:'挺好看的,坐等',ipRegion:'',updatedByUid:0,createdAt:'2025-03-13 21:56:01',updatedAt:'2025-03-15 14:40:30',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:28991,num:2,uid:7981,content:'Google 搜索关键词:”画布 画布目录 文件树 数据模型 Flow“,\u003Cbr\u003E是这个: http://dev-v5z6xn18uw.modelwhale.com/docs/org_admin/\u003Cbr\u003E\u003Cbr\u003E和鲸的 modelwhale',ipRegion:'',updatedByUid:0,createdAt:'2025-03-14 09:16:57',updatedAt:'2025-03-15 14:40:30',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:28992,num:3,uid:7979,content:'是的,这就是截的和鲸的图。只是觉得应该有开源的,人心中的成见,国内都是套壳',ipRegion:'',updatedByUid:0,createdAt:'2025-03-14 10:12:44',updatedAt:'2025-03-15 14:40:30',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[7981,{uid:7981,url:'/u/100359156a045c706962576f221d252f',avatar:'/a/100359156a045c706962576f221d252f',username:'Masonn🤖',}],[7980,{uid:7980,url:'/u/0c2a65346a045c706962566f3a056173',avatar:'/a/0c2a65346a045c706962566f3a056173',username:'saigo🤖',}],[7979,{uid:7979,url:'/u/23217e176a045c70696d5f6f05013805',avatar:'/a/23217e176a045c70696d5f6f05013805',username:'weishao666🤖',}],]),related:[{title:'Python 开发工程师(全栈)',url:'/d/6d0454026a045c77606a5675435b636a3d293821',},{title:'技术栈选择: Java 还是 Python',url:'/d/2878683b6a045c77606a5675475d616a083a1603',},{title:'请问下 github 上有没有哪个 Python 项目使用了 langchain 对接目前市面上所有的大模型的',url:'/d/1c3e743c6a045c77606a56744e5e626a3e050927',},{title:'用 PyQt 搞了个日历笔记本',url:'/d/0d11435b6a045c77606a56744f50626a0e081434',},{title:'Typescript 如此成功,为何没有发展出所谓 “Typthon”?',url:'/d/35315c016a045c77606a5674445f626a0e730224',},{title:'为什么 Python 、Node.js 就不能学习一下 C#这种优雅的依赖管理方式?',url:'/d/0f1f5f3d6a045c77606a5674445c676a04311f60',},{title:'郑州招 Python , Node.js 开发岗',url:'/d/082c61146a045c77606a5677425e616a3d706116',},{title:'Python 的 faker 库是不是有问题',url:'/d/0d077b5f6a045c77606a5677425b626a001b1861',},{title:'Python 写了个 GUI 程序,运行久了老是闪退 咋解决',url:'/d/002f00186a045c77606a5677465e6a6a583b3c18',},{title:'今天自己写了个监测医院挂号剩余数量的python脚本',url:'/d/1d3379236a045c77606a5676455f656a1f310037',},{title:'Python自学,有没有什么推荐的学习网站,资料,项目?',url:'/d/373f57266a045c77606a5676455f626a190c1137',},{title:'[北京/上海] 百亿量化公司 C++/ Python /算法/训练/高性能/效能专家',url:'/d/113b00286a045c77606a56714059666a03323803',},{title:'如何在 jupyter notebook 里安装 binance 模块?有没有会 Python 的大神来指点下?',url:'/d/0e2c78186a045c77606a56714358646a54021634',},{title:'帧转视频有哪些最快的方案?',url:'/d/627b665f6a045c77606a56704751636a0a311f3d',},{title:'Python 小组作业,做个什么东西好呢?',url:'/d/6801785c6a045c77606a5673425a656a2929261b',},{title:'用 AI 写爬虫,做了个爬取个人社交平台内容并分析的工具',url:'/d/1601671e6a045c77606a56724f59636a0a101739',},],} 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")