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:4261,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:30,url:'/t/6c1e511e6a045c7460771613430f',name:'Python',color:'#FFA726',icon:'mdi-language-python',},],posts:[{id:48142,num:0,uid:8484,content:'\u003Cp\u003Ert\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 22:43:58',updatedAt:'2025-03-18 18:28:23',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48143,num:1,uid:1626,content:'\u003Cp\u003Ehttps://www.runoob.com/\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 22:45:03',updatedAt:'2025-03-18 18:28:23',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48144,num:2,uid:10389,content:'\u003Cp\u003E有编程基础直接上手就行了\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 22:45:04',updatedAt:'2025-03-18 18:28:23',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48145,num:3,uid:1531,content:'\u003Cp\u003E我是用智谱清言,让他给你写,你就说自己想法就行了,不用会代码,写写你就自己也会了\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 22:47:11',updatedAt:'2025-03-18 18:28:23',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48146,num:4,uid:4392,content:'\u003Cp\u003EPython有官方文档的,而且还有中文版本的,找资料我个人觉得没有什么资料能比得过官方的 \u003Cimg src\u003D\"/z/img/xhj/015.webp\"\u003E\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 22:53:59',updatedAt:'2025-03-18 18:28:23',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48147,num:5,uid:10390,content:'\u003Cp\u003E想学谢谢大家\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:08:24',updatedAt:'2025-03-18 18:28:24',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48148,num:6,uid:1417,content:'\u003Cp\u003Ebd\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:08:50',updatedAt:'2025-03-18 18:28:24',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48149,num:7,uid:10391,content:'\u003Cp\u003Ehttps://docs.python.org/zh-cn/3.13/index.html\u003Cbr\u003E不过个人觉得 python 不太必要按部就班的学,用到的时候搜就可以了\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:11:24',updatedAt:'2025-03-18 18:28:24',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48150,num:8,uid:1817,content:'\u003Cp\u003E直接上手,现在有 AI 的情况下,Python 等几个脚本语言入门门槛低了太多太多了。\u003C/p\u003E\u003Cp\u003E直接设计一个你需要实现的场景,然后结合 AI,边和 AI 沟通,边根据 AI 给出的答案做定向、有目的的学习,我觉得对于新手来说这是一个不错的入门方法了。\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:29:39',updatedAt:'2025-03-18 18:28:24',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48151,num:9,uid:1817,content:'\u003Cp\u003E我在小飞机群里,已经见过几个没有任何编程基础的人,靠不停的和 AI 沟通,已经能写出一些像模像样的 Python 程序了。\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:30:28',updatedAt:'2025-03-18 18:28:24',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:48152,num:10,uid:1783,content:'\u003Cp\u003E不要看网上资料,买本实体书进步很快\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-17 23:30:34',updatedAt:'2025-03-18 18:28:24',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[10391,{uid:10391,url:'/u/372674246a045d776363576f203d3800',avatar:'/a/372674246a045d776363576f203d3800',username:'Martin98🤖',}],[8484,{uid:8484,url:'/u/032647216a045c7f6462526f38051c7e',avatar:'/a/032647216a045c7f6462526f38051c7e',username:'chengjiu🤖',}],[1817,{uid:1817,url:'/u/022b43286a045c76686b516f13203b22',avatar:'/a/022b43286a045c76686b516f13203b22',username:'mreleven🤖',}],[10390,{uid:10390,url:'/u/6f036b2a6a045d776363566f43210b13',avatar:'/a/6f036b2a6a045d776363566f43210b13',username:'taul🤖',}],[4392,{uid:4392,url:'/u/2c20460e6a045c736363546f070a0436',avatar:'/a/2c20460e6a045c736363546f070a0436',username:'coolnom🤖',}],[10389,{uid:10389,url:'/u/0d304b146a045d7763625f6f232e042c',avatar:'/a/0d304b146a045d7763625f6f232e042c',username:'n32313🤖',}],[1783,{uid:1783,url:'/u/31087b3f6a045c766762556f1a2f2517',avatar:'/a/31087b3f6a045c766762556f1a2f2517',username:'lxz07🤖',}],[1626,{uid:1626,url:'/u/107f62206a045c766668506f12036324',avatar:'/a/107f62206a045c766668506f12036324',username:'Mmo🤖',}],[1417,{uid:1417,url:'/u/6f7e485f6a045c76646b516f351d3170',avatar:'/a/6f7e485f6a045c76646b516f351d3170',username:'MoonCDN🤖',}],[1531,{uid:1531,url:'/u/22195c2e6a045c766569576f200c392d',avatar:'/a/22195c2e6a045c766569576f200c392d',username:'997284979🤖',}],]),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:'[北京/上海] 百亿量化公司 C++/ Python /算法/训练/高性能/效能专家',url:'/d/113b00286a045c77606a56714059666a03323803',},{title:'如何在 jupyter notebook 里安装 binance 模块?有没有会 Python 的大神来指点下?',url:'/d/0e2c78186a045c77606a56714358646a54021634',},{title:'这是什么 jupyter 插件,感觉挺酷',url:'/d/683e7a296a045c77606a56704358626a2570262b',},{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")