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:225,currentPage:1,targetPage:1,total:7,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:58,url:'/t/372d7d5a6a045c72687754112f19',name:'文生图',color:'#66BB6A',icon:'mdi-tag-heart',},],posts:[{id:3297,num:0,uid:1738,content:'\u003Cp\u003E䏿˜¯åœ¨çº¿æ¨¡åž‹ï¼Œè¦å¯ä»¥æœ¬åœ°éƒ¨ç½²çš„ï¼Œèƒ½æŒ‰è¦æ±‚准确显示指定的文å—ï¼ŒåŽ»å¹´æ˜¯æ²¡æ‰¾åˆ°è¿™æ ·çš„æ¨¡åž‹ï¼Œä¸çŸ¥é“ä»Šå¹´æ€Žä¹ˆæ ·äº†\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-09 23:10:49',updatedAt:'2025-03-10 22:34:17',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:3298,num:1,uid:1585,content:'\u003Cp\u003E阿里的万相å¯ä»¥è¯•试\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-09 23:16:56',updatedAt:'2025-03-10 22:34:17',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:3299,num:2,uid:1738,content:'\u003Cp\u003E好的,谢谢,我去瞅瞅\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-09 23:17:43',updatedAt:'2025-03-10 22:34:17',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:3300,num:3,uid:1828,content:'\u003Cp\u003E一直用comfyui , æ¨¡åž‹çš„è¯ è‡ªå·±é€‰ï¼Œå“ªç§ç±»åž‹éƒ½æœ‰ï¼Œä¸åˆé€‚的还能自己lora微调。\u003Cbr\u003E我觉得挺好用的图片生æˆï¼Œè§†é¢‘ç”Ÿæˆ ã€æ¢è„¸ã€æ¢è¡£ï¼Œpsç±»ä¼¼çš„å¤„ç†æ•ˆæžœ ç‰ç‰ã€‚\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-09 23:19:59',updatedAt:'2025-03-10 22:34:17',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:3301,num:4,uid:1738,content:'\u003Cp\u003Eä¸çŸ¥é“çŽ°åœ¨å“ªä¸ªæ¨¡åž‹åœ¨æˆ‘è¦æ±‚çš„æ–¹é¢æ¯”è¾ƒå¥½ï¼Œåˆšçœ‹äº†ä¸‹ä¸‡ç›¸ï¼Œé‚£ä¸ªå¥½åƒæ˜¯è§†é¢‘模型\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-09 23:32:13',updatedAt:'2025-03-10 22:34:17',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:3302,num:5,uid:1829,content:'\u003Cp\u003E阿里的万相\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-10 01:51:31',updatedAt:'2025-03-10 22:34:17',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:3303,num:6,uid:1830,content:'\u003Cp\u003E ä¹Ÿæœ‰ä¸ªç”Ÿå›¾çš„çš„ä¸‡ç›¸ï¼Œé—æºçš„,百炼上有api\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-10 01:53:55',updatedAt:'2025-03-10 22:34:17',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[1828,{uid:1828,url:'/u/152c603f6a045c7668685e6f060e1d0c',avatar:'/a/152c603f6a045c7668685e6f060e1d0c',username:'ixdog🤖',}],[1829,{uid:1829,url:'/u/123e583e6a045c7668685f6f3f11252a',avatar:'/a/123e583e6a045c7668685f6f3f11252a',username:'flyblack🤖',}],[1830,{uid:1830,url:'/u/2a03501c6a045c766869566f12186a32',avatar:'/a/2a03501c6a045c766869566f12186a32',username:'rammiah🤖',}],[1585,{uid:1585,url:'/u/3b0b445d6a045c766562536f222c3c1e',avatar:'/a/3b0b445d6a045c766562536f222c3c1e',username:'Mofeng🤖',}],[1738,{uid:1738,url:'/u/3026780b6a045c7667695e6f442c0913',avatar:'/a/3026780b6a045c7667695e6f442c0913',username:'hkfires🤖',}],]),related:[{title:'基于 GPT 4o å¼€å‘完æˆäº†å…·æœ‰å‰åœåŠ›ã€3D 版ç‰å¤šé£Žæ ¼å›¾ç‰‡ç”Ÿæˆå™¨ï¼Œä¹‹å‰å¤ªå¿™æ”¹ç¨‹åºï¼Œæ‰æ¥åˆ†äº«',url:'/d/630e77046a045c77606a567a4458646a1e103560',},{title:'æ•´ç†äº†ä¸€ä»½ã€ŠGPT-4o 生图大全》',url:'/d/0e267b0f6a045c77606a567a4650666a39193007',},{title:'gpt4o 图åƒç”Ÿæˆçš„æŠ€æœ¯è®¨è®º(自回归模型åˆå¥½èµ·æ¥äº†?)',url:'/d/6e0103146a045c77606a567a4758656a07116714',},{title:'å¼€å‘了一个动作人å¶å›¾ç‰‡ç”Ÿæˆå™¨ï¼Œå…费试用',url:'/d/3b3d40016a045c77606a56754f51646a3c220519',},{title:'我的网站上线啦ï¼å–œæ¬¢ AI 生图的朋å‹ä¸€å®šå–œæ¬¢ï¼',url:'/d/313b503e6a045c77606a56754f5a666a3a1a326b',},{title:'GPT-4o 多模æ€ç”Ÿå›¾æœ‰æŒ‰æ¬¡æ”¶è´¹çš„ä¸ï¼Ÿ',url:'/d/287079286a045c77606a56754f5a616a047b1105',},{title:'基于 GPT-4o æ“了一个的图片生æˆå™¨,帮助自己实现嘴图自由',url:'/d/021a431a6a045c77606a56754550606a14213e18',},{title:'å‘现一个å¯ä»¥å…è´¹ç”Ÿæˆ AI 图片 / 视频的网站',url:'/d/342a55546a045c77606a5675455e626a0221301d',},{title:'GPT-4o 生æˆå‰åœåŠ›é£Žæ ¼æ¼«ç”»',url:'/d/1c074a546a045c77606a56744e506b6a3e122a3f',},{title:'哪个ä¸è½¬ç«™ï¼Œæ”¯æŒèŠå¤©ä¸ç›´æŽ¥ç”Ÿæˆå›¾ç‰‡çš„ï¼Œæ”¯æŒ chatGPT4o çš„',url:'/d/327979236a045c77606a56744e51666a2b14643f',},{title:'åˆ†äº«ä¸ªæœ‰æ„æ€çš„图åƒç”ŸæˆåŠ©æ‰‹',url:'/d/3d2663266a045c77606a5674405a646a382d1035',},{title:'完全å…费的 AI 生æˆå›¾ç‰‡ç½‘站,蹲一个蹲',url:'/d/152e030f6a045c77606a5676425c6b6a1f351062',},{title:'动动嘴就能 P 图,快æ¥è¯•试我åšçš„「è¯éŸ³ç‰ˆ PSã€å§',url:'/d/347101206a045c77606a567143596a6a16366301',},{title:'[é€ç ]动动嘴皮, AI ç§’å‡ºå›¾ï¼ 2025 æœ€ç‚¸è£‚å›¾æ ‡ç¥žå™¨ï¼šå…费生æˆ+手机实时预览',url:'/d/190f463c6a045c77606a5673405e646a0a352961',},{title:'求推èå…费的 AI 画图',url:'/d/1e067f086a045c77606a5673405c6b6a00001f1b',},{title:'è¶ç€ AI 大ç«ï¼Œç©ºé—²æ—¶é—´æŠ˜è…¾ä¸ª AI 绘画应用玩玩,昨天刚å‘出æ¥å°±æœ‰å¥½å¤šäººæ¥çŽ©ï¼Œå¤§å®¶è¿˜æ˜¯æ„Ÿå…´è¶£çš„å˜›ï¼',url:'/d/221e7a3c6a045c77606a5673475c626a5d0e0a06',},{title:'æžäº†ä¸ª AI 绘画应用,拿去玩玩。',url:'/d/162c502f6a045c77606a56724f58656a03171c26',},{title:'大家Ai绘画都是用的什么方å¼ï¼Ÿ',url:'/d/222103036a045c77606a5672455b636a200a2739',},],}
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")