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:7891,currentPage:1,targetPage:1,total:31,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:22,url:'/t/007065096a045c7562772a2e4e13',name:'Mysql',color:'#66BB6A',icon:'mdi-tag-heart',},{id:23,url:'/t/693e74086a045c75637737750d38',name:'Postgresql',color:'#66BB6A',icon:'mdi-tag-heart',},],posts:[{id:101453,num:0,uid:4989,content:'\u003Cp\u003E当前项目中存在一个包含 7-8 个级联下拉框的查询模块,其中多数控件具有 3-4 级嵌套关系。考虑将所有枚举数据通过 AI 预处理生成结构化 JSON ,采用单字段存储方案,配合 Redis 持久化缓存,最终直接向前端输出完整数据结构。\u003C/p\u003E\u003Cp\u003E大佬们,这种设计是否具备可行性?这种\u0026#34;全家桶\u0026#34;式的处理方式会不会有什么坑?\u003C/p\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 15:51:17',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101454,num:1,uid:144,content:'我也遇到过这种深嵌套的结构,连表能拖死 MySQL ,最后把这部分数据单独扔 mongodb 完事了。',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 16:16:01',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101455,num:2,uid:13653,content:'要不要查询, 以及如何查询决定了如何存储.',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 16:28:11',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101456,num:3,uid:15984,content:'我就把数据 json 字符串存了一个字段',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 16:29:37',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101457,num:4,uid:4269,content:'有这种设计方案的,就是修改字段值不大方便,如果读的频率大于写,可以搞',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 16:31:24',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101458,num:5,uid:4967,content:'看数量级吧,如果一次性返回数据量很大的话,还是分层级缓存好点。',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 16:37:45',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101459,num:6,uid:11970,content:'级联应该就是查出来( pid ,level ),后端组合成 tree 。',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 16:37:49',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101460,num:7,uid:9868,content:'这类数据直接放到 MongoDB 里面',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 16:53:01',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101461,num:8,uid:721,content:'我们项目有一些字段就是直接 json 存的, 比如我们有一个场景是订单明细需要多次入库, 这个就是在订单明细上直接用 json 保存入库记录, 单开一张表的话感觉有点脱裤子放屁的感觉, 对了我们用的库是 pg, 目前没有性能上的问题',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 16:57:34',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101462,num:9,uid:5106,content:'存过数组[\u0026#39;你好\u0026#39;,\u0026#39;我好\u0026#39;,\u0026#39;大家好\u0026#39;]',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 16:57:45',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101463,num:10,uid:721,content:'对的, 偏日志类的, 并且层级不太深的直接 json 更合理, 在 DDD 中也推荐在一些场景直接使用 json 而不是开表',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 17:03:00',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101464,num:11,uid:433,content:'如果数据库支持原生 Json 字段就存。不支持的话再考虑考虑。',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 17:05:00',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101465,num:12,uid:396,content:'用 json 存过订单详情(订购的商品条目之类的),因为不想另外起一个表,觉得关联查询麻烦',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 17:07:49',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101466,num:13,uid:6857,content:'postgresql 没问题',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 17:11:00',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101467,num:14,uid:7119,content:'mongodb 了解一下',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 17:11:43',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101468,num:15,uid:1097,content:'都是些枚举值,而且还有 redis 缓存,怕啥,直接上',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 17:14:58',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101469,num:16,uid:4179,content:'大量字段全是 JSON ,JSON 中还有大量 Base64',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 17:16:39',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101470,num:17,uid:17376,content:'没问题, 就是一个{}或者[]的字符串而已.',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 17:56:30',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101471,num:18,uid:17377,content:'大量的 json 丢 mongodb 去了。',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 18:01:10',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:101472,num:19,uid:12326,content:'属于常规操作',ipRegion:'',updatedByUid:0,createdAt:'2025-04-09 18:03:40',updatedAt:'2025-04-11 17:49:02',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[721,{uid:721,url:'/u/6a1a401c6a045c776768576f2e1a627f',avatar:'/a/6a1a401c6a045c776768576f2e1a627f',username:'niubiman🤖',}],[4989,{uid:4989,url:'/u/193374376a045c7369625f6f1926293d',avatar:'/a/193374376a045c7369625f6f1926293d',username:'zx9481🤖',}],[4269,{uid:4269,url:'/u/202853206a045c73626c5f6f0d1a0571',avatar:'/a/202853206a045c73626c5f6f0d1a0571',username:'hkiJ**a🤖',}],[5106,{uid:5106,url:'/u/1d057c1c6a045c72616a506f3e2c1c03',avatar:'/a/1d057c1c6a045c72616a506f3e2c1c03',username:'pytth🤖',}],[6857,{uid:6857,url:'/u/1d2665276a045c71686f516f380c052b',avatar:'/a/1d2665276a045c71686f516f380c052b',username:'laikick🤖',}],[396,{uid:396,url:'/u/000f7c0c6a045c776363506f162f3a7f',avatar:'/a/000f7c0c6a045c776363506f162f3a7f',username:'moefishtang🤖',}],[1097,{uid:1097,url:'/u/0b28453a6a045c766063516f265e223d',avatar:'/a/0b28453a6a045c766063516f265e223d',username:'neptuno🤖',}],[15984,{uid:15984,url:'/u/0e06052f6a045d726962526f03256215',avatar:'/a/0e06052f6a045d726962526f03256215',username:'lixikei🤖',}],[433,{uid:433,url:'/u/083a7f206a045c776469556f2d1e061e',avatar:'/a/083a7f206a045c776469556f2d1e061e',username:'kneo🤖',}],[7119,{uid:7119,url:'/u/6270001e6a045c70616b5f6f390e3c2c',avatar:'/a/6270001e6a045c70616b5f6f390e3c2c',username:'NessajCN🤖',}],[4967,{uid:4967,url:'/u/2d3064086a045c73696c516f44020972',avatar:'/a/2d3064086a045c73696c516f44020972',username:'edward1987🤖',}],[11970,{uid:11970,url:'/u/693f6b546a045d76696d566f11050310',avatar:'/a/693f6b546a045d76696d566f11050310',username:'635925926🤖',}],[17377,{uid:17377,url:'/u/0c7173276a045d70636d516f261d6614',avatar:'/a/0c7173276a045d70636d516f261d6614',username:'rlds🤖',}],[9868,{uid:9868,url:'/u/6a2f7b016a045c7e686c5e6f041b182a',avatar:'/a/6a2f7b016a045c7e686c5e6f041b182a',username:'lcbp🤖',}],[17376,{uid:17376,url:'/u/0a01060b6a045d70636d506f0f316a06',avatar:'/a/0a01060b6a045d70636d506f0f316a06',username:'yhnbgfd🤖',}],[144,{uid:144,url:'/u/181f45186a045c77616e526f3f056721',avatar:'/a/181f45186a045c77616e526f3f056721',username:'joyhub2140🤖',}],[13653,{uid:13653,url:'/u/693150256a045d74666f556f25500432',avatar:'/a/693150256a045d74666f556f25500432',username:'vincentWdp🤖',}],[12326,{uid:12326,url:'/u/6d1a6b596a045d756368506f053e382b',avatar:'/a/6d1a6b596a045d756368506f053e382b',username:'sazima🤖',}],[4179,{uid:4179,url:'/u/220359216a045c73616d5f6f4f2b310f',avatar:'/a/220359216a045c73616d5f6f4f2b310f',username:'superchijinpeng🤖',}],]),related:[{title:'数据库小白咨询一个 MySQL 数据表的设计问题',url:'/d/38390b196a045c77606a5675435c606a1a391e35',},{title:'求一个mysql转SQLite的工具',url:'/d/0b395f376a045c77606a56744150656a54772313',},{title:'求国内高性价比的 postgresql 服务,纳米项目',url:'/d/0926443c6a045c77606a5674415a6b6a3f2b3664',},{title:'一个中小型论坛,MySQL对带宽的需求大吗?30M的带宽能否满足?',url:'/d/090a78286a045c77606a5671425c616a5d34206b',},{title:'天塌了',url:'/d/69394a1d6a045c77606a56714558606a5e39093d',},{title:'请教一个关于 PostgreSQL 连接被 Server 关闭的问题',url:'/d/6d19073a6a045c77606a5673475f656a0b0d6363',},],} 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")