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:4522,currentPage:1,targetPage:1,total:61,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:28,url:'/t/3d104b0f6a045c7568772c310313',name:'Java',color:'#FFA726',icon:'mdi-language-java',},{id:26,url:'/t/317a6a296a045c7566775e0c475c',name:'C|CPP',color:'#FFA726',icon:'mdi-language-cpp',},],posts:[{id:51440,num:0,uid:10758,content:'\u003Cp\u003E#c++\u003C/p\u003E\u003Ccode\u003E#include \u0026lt;iostream\u0026gt;int main() { std::cout \u0026lt;\u0026lt; \u0026#34;Hello, World!\u0026#34; \u0026lt;\u0026lt; std::endl; return 0;}\u003C/code\u003E\u003Cp\u003Evs\u003C/p\u003E\u003Cp\u003E#j**a\u003C/p\u003E\u003Ccode\u003Epublic class Main { public static void main(String[] args) { System.out.println(\u0026#34;Hello, World!\u0026#34;); }}\u003C/code\u003E',ipRegion:'',updatedByUid:0,createdAt:'2025-03-15 22:54:51',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51441,num:1,uid:10759,content:'你不能只看 hello world 啊。。\u003Cbr\u003E\u003Cbr\u003E得从实际业务中体会啊。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-15 23:01:24',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51442,num:2,uid:5851,content:'口算 1+1 确实比按计算器快',ipRegion:'',updatedByUid:0,createdAt:'2025-03-15 23:03:04',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51443,num:3,uid:10758,content:'能简单说一下吗,c++不是也有包/library 拿来直接用的吗',ipRegion:'',updatedByUid:0,createdAt:'2025-03-15 23:03:34',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51444,num:4,uid:2259,content:'效率在堆内存管理和并发编程上体现,j**a 是自动管理内存,c++要手动管理,智能指针之类的会限制一些写法。多线程也比较麻烦,没有官方线程池,协程。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-15 23:12:34',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51445,num:5,uid:10760,content:'1. 认识的 c 系的程序员一般都不太会直接使用开源的库, 而是参考开源自己造轮子; 2. 没有**回收会导致业务对大块内存的处理逻辑变得复杂.',ipRegion:'',updatedByUid:0,createdAt:'2025-03-15 23:14:34',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51446,num:6,uid:9929,content:'“也有包/library” 是也有,但是在某些领域比如说后端,可能不完善、功能少、bug 多、文档少。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-15 23:32:38',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51447,num:7,uid:10001,content:'对比一下 grpc 的 demo\u003Cbr\u003E用 c++的完成队列和 j**a 的实现比较一下 很直观',ipRegion:'',updatedByUid:0,createdAt:'2025-03-15 23:38:40',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51448,num:8,uid:6583,content:'都写个学生管理系统试试就知道了',ipRegion:'',updatedByUid:0,createdAt:'2025-03-15 23:52:58',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51449,num:9,uid:2620,content:'直接点说法:\u003Cbr\u003E 1. j**a 大量开元包导入直接用, 安全 稳定 无脑.\u003Cbr\u003E 2. cpp ?导入进去一套用法下来 还能出问题, 简单点就是说:照着说明书用都能出问题;人的问题占大比; 毕竟那点工资招聘一个真正会 cpp 的不大可能;\u003Cbr\u003E\u003Cbr\u003E 效率说的是 成本 \u0026amp; 维护 \u0026amp; 招聘人员。 不是说开发效率. 管理层懂点技术的会知道 公司是有钱不是傻,要的就是可复用性; 这个可复用包括人的复用; 不是 a 走了疯狂找个 b ,b 又不愿意吃屎山代码.\u003Cbr\u003E j**a go c# 都是那几个框架 不会也愿意学; cpp...你说招进来让他们学框架二次迭代开发维护, 他们只想造轮子. 给你推翻重写, 毕竟底子在那.',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 00:11:24',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51450,num:10,uid:2620,content:' 另外 市面上的都是杂牌程序员, 我也是; 喷的铁铁们别激动;\u003Cbr\u003E 正规军是什么: 科班出生 正儿八经学习了 操作系统 数据结构 努力点在刷刷 leetcode. 以及良好的数学底子,这种人很会写代码 但是也不甘心写代码; \u003Cbr\u003E 都用上杂牌军了,还用什么 cpp 那玩意, 半天喷不出一个屁, 老板哪里管什么效率,只知道出了点 到点要看到,别出岔子; 那不出岔子 就要稳定的库代码引用; 那就 j**a go c# 咯。反正全球那么多地方用过了 有问题都有问题;',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 00:17:04',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51451,num:11,uid:5610,content:'\u0026#34;开发效率高\u0026#34;是个项目完成后的最终评价,决定它的因素不仅限于开发语言的易写、啰嗦程度,还有更多因素比如:是否具有大量第三方高质量开源包避免重复造低质量轮子;在协作时开发框架是否能限制、显著减少引发崩溃的**代码;等。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 00:18:27',updatedAt:'2025-03-18 23:17:04',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51452,num:12,uid:10761,content:'![https://imgur.com/a/DLHwZvO]( \u003Cimg src\u003D\"https://i.imgur.com/ESQHBIA.jpeg\"\u003E)',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 00:19:46',updatedAt:'2025-03-18 23:17:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51453,num:13,uid:2620,content:'大晚上在唠嗑几句, 只是个人观点.\u003Cbr\u003E 1: 为什么说 c++ 难,难的不是语法糖; 而是语法糖背后的意义; \u003Cbr\u003E file.open(\u0026#34;file_name\u0026#34;, a). \u0026amp; file.open(\u0026#34;file_name\u0026#34;, a+) \u0026amp; 写文件要 4k 对齐 为什么要 4k 对齐 因为内存 为什么内存是 4k ?那就要设计到操作系统 \u0026amp; 特么的在去溯源, 都特么溯源到 第一台计算机的产生了; \u003Cbr\u003E 用 j**a go c# ?我管你几 k 对齐, 快速我就 github 下载 广泛推广使用;\u003Cbr\u003E \u003Cbr\u003E反正老板不听历史, 所以 也别纠结学什么语言了 你需要的是一个思维 而不是学习语言; 这个思维是:\u003Cbr\u003E 我目前做的项目 \u0026amp; 业务。 计算机 \u0026amp; 代码可以给我提供我什么帮助 让我更好的完成✅\u003Cbr\u003E \u003Cbr\u003E而不是:\u003Cbr\u003E 我要学会什么语言 这个语言什么好处 能做什么。\u003Cbr\u003E\u003Cbr\u003E 为什么会有这样的思维, 这是 西方国家 \u0026amp; 部分亚洲国家的差别;\u003Cbr\u003E 于当代科技而言, 西方在 0-1 的节点上作出的贡献占比很大很大\u003Cbr\u003E 亚洲地区 在 1-x 上实现的更多。\u003Cbr\u003E 至于你说哪个牛逼你说了算。 你非要我说 我说工人阶级最伟大.',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 00:25:20',updatedAt:'2025-03-18 23:17:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51454,num:14,uid:10762,content:'实际的业务可不是 hello world 这种复杂度, 复杂度高了之后差别就很大了',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 02:12:55',updatedAt:'2025-03-18 23:17:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51455,num:15,uid:10763,content:'J**a 自带的 string 是可用,C++标准库的 string 就是聊胜于无。\u003Cbr\u003E而工作中字符串操作太多了。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 02:29:36',updatedAt:'2025-03-18 23:17:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51456,num:16,uid:544,content:'C++每个第三方库都有自己的字符串实现\u003Cbr\u003E你可能会见到:\u003Cbr\u003EQString\u003Cbr\u003ECString\u003Cbr\u003E……',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 02:35:04',updatedAt:'2025-03-18 23:17:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51457,num:17,uid:17,content:'1. C++没有 GC\u003Cbr\u003E2. C++编译模型比较原始\u003Cbr\u003E3. C++构建会涉及大量依赖库、编译选项和目标平台 ABI 的细节,极容易踩坑\u003Cbr\u003E4. C++本身的语义就比 (一般的) J**a 程序复杂,模版之类要考虑的很多,心智负担大\u003Cbr\u003E5. C++适用的场景,代码本来就要比 J**a 更谨慎',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 02:38:35',updatedAt:'2025-03-18 23:17:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51458,num:18,uid:5791,content:'给你段 Windows C++ 窗口开发的“hello world”,你再看看。\u003Cbr\u003E\u003Cbr\u003E\u003Cbr\u003E#include \u0026lt;windows.h\u0026gt;\u003Cbr\u003E\u003Cbr\u003ELRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) {\u003Cbr\u003E switch (uMsg) {\u003Cbr\u003E case WM_DESTROY:\u003Cbr\u003E PostQuitMessage(0);\u003Cbr\u003E return 0;\u003Cbr\u003E }\u003Cbr\u003E return DefWindowProc(hwnd, uMsg, wParam, lParam);\u003Cbr\u003E}\u003Cbr\u003E\u003Cbr\u003Eint WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) {\u003Cbr\u003E // 注册窗口类\u003Cbr\u003E WNDCLASS wc \u003D {0};\u003Cbr\u003E wc.lpfnWndProc \u003D WindowProc;\u003Cbr\u003E wc.hInstance \u003D hInstance;\u003Cbr\u003E wc.lpszClassName \u003D L\u0026#34;MyWindowClass\u0026#34;;\u003Cbr\u003E RegisterClass(\u0026amp;wc);\u003Cbr\u003E\u003Cbr\u003E // 创建窗口\u003Cbr\u003E HWND hwnd \u003D CreateWindow(\u003Cbr\u003E L\u0026#34;MyWindowClass\u0026#34;, L\u0026#34;Sample Window\u0026#34;, WS_OVERLAPPEDWINDOW,\u003Cbr\u003E 0, 0, 800, 600, NULL, NULL, hInstance, NULL\u003Cbr\u003E );\u003Cbr\u003E\u003Cbr\u003E if (hwnd \u003D\u003D NULL) return 0;\u003Cbr\u003E\u003Cbr\u003E // 显示窗口\u003Cbr\u003E ShowWindow(hwnd, nCmdShow);\u003Cbr\u003E UpdateWindow(hwnd);\u003Cbr\u003E\u003Cbr\u003E // 消息循环\u003Cbr\u003E MSG msg \u003D {0};\u003Cbr\u003E while (GetMessage(\u0026amp;msg, NULL, 0, 0)) {\u003Cbr\u003E TranslateMessage(\u0026amp;msg);\u003Cbr\u003E DispatchMessage(\u0026amp;msg);\u003Cbr\u003E }\u003Cbr\u003E\u003Cbr\u003E return 0;\u003Cbr\u003E}',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 03:31:44',updatedAt:'2025-03-18 23:17:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},{id:51459,num:19,uid:140,content:'写文件 4K 对齐?对于调用标准库 fopen 、std::iostream 而言,并没有这种事。标准库的文件读写并没有 4K 对齐这种选项。\u003Cbr\u003E大概是想说现代硬盘的 4K 对齐吧?那是操作系统和文件系统的事情。调用标准库文件读写 API 的时候,操作系统已经帮调用者处理好背后的对齐了,调用者并不需要考虑硬盘“4K”对齐这种事。如果分区没做 4K 对齐,开发者想要干预也没法干预。',ipRegion:'',updatedByUid:0,createdAt:'2025-03-16 04:45:13',updatedAt:'2025-03-18 23:17:05',mentionNum:0,mentionedBy:[],mentionUsers:[],likeUsers:[],},],usersMap:new Map([[5791,{uid:5791,url:'/u/15106b5b6a045c726763576f01131c0a',avatar:'/a/15106b5b6a045c726763576f01131c0a',username:'cheng6563🤖',}],[10758,{uid:10758,url:'/u/3f04623a6a045d77676f5e6f27581901',avatar:'/a/3f04623a6a045d77676f5e6f27581901',username:'wanmyj🤖',}],[10763,{uid:10763,url:'/u/6e2b68256a045d77676c556f2621033f',avatar:'/a/6e2b68256a045d77676c556f2621033f',username:'neoblackcap🤖',}],[10761,{uid:10761,url:'/u/03305b396a045d77676c576f072d0712',avatar:'/a/03305b396a045d77676c576f072d0712',username:'lc1450🤖',}],[5610,{uid:5610,url:'/u/131f670f6a045c72666b566f222b1903',avatar:'/a/131f670f6a045c72666b566f222b1903',username:'tuimaochang🤖',}],[10760,{uid:10760,url:'/u/221356206a045d77676c566f46251b0b',avatar:'/a/221356206a045d77676c566f46251b0b',username:'midasfree🤖',}],[6583,{uid:6583,url:'/u/6801622e6a045c716562556f27052b72',avatar:'/a/6801622e6a045c716562556f27052b72',username:'inhzus🤖',}],[9929,{uid:9929,url:'/u/3d1e001d6a045c7e69685f6f39281c23',avatar:'/a/3d1e001d6a045c7e69685f6f39281c23',username:'abcdxe2v🤖',}],[2259,{uid:2259,url:'/u/180a02376a045c75626f5f6f3d31352c',avatar:'/a/180a02376a045c75626f5f6f3d31352c',username:'murmurkerman🤖',}],[544,{uid:544,url:'/u/3d1054016a045c77656e526f020a092a',avatar:'/a/3d1054016a045c77656e526f020a092a',username:'ShadowPower🤖',}],[5851,{uid:5851,url:'/u/36315f1e6a045c72686f576f030f2914',avatar:'/a/36315f1e6a045c72686f576f030f2914',username:'stimw🤖',}],[10762,{uid:10762,url:'/u/2e27502a6a045d77676c546f423e380a',avatar:'/a/2e27502a6a045d77676c546f423e380a',username:'nectar33🤖',}],[17,{uid:17,url:'/u/1f3a753d6a045c77606b516f070e0570',avatar:'/a/1f3a753d6a045c77606b516f070e0570',username:'agagega🤖',}],[2620,{uid:2620,url:'/u/1718032e6a045c756668566f41001b28',avatar:'/a/1718032e6a045c756668566f41001b28',username:'ugpu🤖',}],[140,{uid:140,url:'/u/2e317f3e6a045c77616e566f45116522',avatar:'/a/2e317f3e6a045c77616e566f45116522',username:'cnbatch🤖',}],[10001,{uid:10001,url:'/u/182c50186a045d77606a576f163a3b2b',avatar:'/a/182c50186a045d77606a576f163a3b2b',username:'ty29022🤖',}],[10759,{uid:10759,url:'/u/35390b176a045d77676f5f6f3003100b',avatar:'/a/35390b176a045d77676f5f6f3003100b',username:'flyqie🤖',}],]),related:[{title:'有在 vscode 上写 Java 的么?一个非常简单的扩展:可以一键复制 arthas 的 watch 命令。',url:'/d/0b26510b6a045c77606a567a455e606a5f011624',},{title:'c++调试遇到奇怪问题',url:'/d/2e707d5d6a045c77606a567a4658616a28306b21',},{title:'「郑州」招聘高级 Java 15K 上下,看个人水平',url:'/d/6a2d46346a045c77606a56754e58616a0e216467',},{title:'求推荐 C++ 高性能的 web 框架, curd 用',url:'/d/1431451d6a045c77606a56754f51616a07712204',},{title:'技术栈选择: Java 还是 Python',url:'/d/2878683b6a045c77606a5675475d616a083a1603',},{title:'Java 开发,接下来的路咋走啊?',url:'/d/1f78462e6a045c77606a5675475b656a1c37230a',},{title:'[全职招聘]C++精通 QT 开发',url:'/d/3e1e59396a045c77606a56744f586b6a140c1565',},{title:'windsurf 和 cursor 用来写 kotlin 后端还是不太行',url:'/d/2b780b5e6a045c77606a5674425a656a2d103a64',},{title:'重复造轮子了,用 c++写了个类 rustdesk demo 版本',url:'/d/347171556a045c77606a5674425b616a3f09301d',},{title:'Java 后端开发 , macbookAir m4 16+256G 入门款值得入手不,pdd6199 元,(之前那个 MacBookpro 2018 32G+512G 电脑坏了修起来要 4k 以上,没什么维修价值了)另外问一下够用不',url:'/d/200d00356a045c77606a5674435b6b6a0d276310',},{title:'C++ 开发不想 996,如何跳槽转到 Java ?',url:'/d/09207c086a045c77606a56744358646a1f292613',},{title:'今天有个面试官和我讲 go 的协程比系统的线程更慢,这个我不能理解',url:'/d/182459046a045c77606a56744359626a1412041a',},{title:'Java 和 go 都会,以后找工作偏向哪个方面好呢',url:'/d/000b7b1b6a045c77606a5674445e656a1977262a',},{title:'作为一个传统开发者,如何使用 ai 或者机器学习实现一些简单事情',url:'/d/34015f186a045c77606a5674445e626a25016611',},{title:'Java 生态下想搞大流量下的 ws,是不是暂时只能 netty?',url:'/d/6c7f0b1a6a045c77606a56774251626a5b761219',},{title:'为什么很多人喷 Java 开发者离了 spring 框架就不会写代码了',url:'/d/2c795a5c6a045c77606a56764051666a58303c13',},{title:'Java 找工作有感,行业经验大于一切',url:'/d/3d06072a6a045c77606a5676405c616a050b2611',},{title:'[北京/上海] 百亿量化公司 C++/ Python /算法/训练/高性能/效能专家',url:'/d/113b00286a045c77606a56714059666a03323803',},{title:'C++库脚手架项目及思考',url:'/d/232748546a045c77606a56714350616a5b766237',},{title:'作为 Java 狗的我,学习 rust 的时候为啥总念着 go 的好呢?',url:'/d/6f2a02176a045c77606a5671435d636a2f121465',},],} 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")