Index.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. // 导出动画弹出框管理器
  2. window.ExportViewManager = (function() {
  3. let frame = null;
  4. let isShowing = false;
  5. let resolveCallback = null;
  6. function init() {
  7. frame = document.getElementById('exportViewFrame');
  8. if (!frame) {
  9. return;
  10. }
  11. // 监听来自 export-view 的消息
  12. window.addEventListener('message', (event) => {
  13. if (event.origin !== window.location.origin) {
  14. return;
  15. }
  16. const { data } = event;
  17. if (data && data.type === 'close-export-view') {
  18. hide();
  19. } else if (data && data.type === 'export-confirmed') {
  20. handleExportConfirmed(data);
  21. }
  22. });
  23. }
  24. function show(folderName) {
  25. if (!frame) {
  26. init();
  27. }
  28. if (!frame) {
  29. return Promise.resolve(false);
  30. }
  31. return new Promise((resolve) => {
  32. resolveCallback = resolve;
  33. isShowing = true;
  34. // 显示 iframe
  35. frame.style.display = 'block';
  36. frame.style.pointerEvents = 'auto';
  37. frame.style.visibility = 'visible';
  38. // 等待 iframe 加载完成后发送文件夹名称
  39. const sendFolderName = () => {
  40. if (frame.contentWindow) {
  41. frame.contentWindow.postMessage({
  42. type: 'generate-export-preview',
  43. folderName: folderName
  44. }, '*');
  45. } else {
  46. setTimeout(sendFolderName, 100);
  47. }
  48. };
  49. // 监听 iframe 加载完成
  50. const handleLoad = () => {
  51. setTimeout(() => {
  52. sendFolderName();
  53. }, 100);
  54. };
  55. frame.onload = handleLoad;
  56. // 如果 iframe 已经加载,立即发送
  57. if (frame.contentDocument && frame.contentDocument.readyState === 'complete') {
  58. handleLoad();
  59. } else {
  60. const baseSrc = frame.src.split('?')[0];
  61. frame.src = baseSrc + '?t=' + Date.now();
  62. }
  63. });
  64. }
  65. function hide() {
  66. if (frame) {
  67. frame.style.display = 'none';
  68. frame.style.pointerEvents = 'none';
  69. frame.style.visibility = 'hidden';
  70. }
  71. isShowing = false;
  72. if (resolveCallback) {
  73. resolveCallback(false);
  74. resolveCallback = null;
  75. }
  76. }
  77. function handleExportConfirmed(data) {
  78. if (resolveCallback) {
  79. resolveCallback(true);
  80. resolveCallback = null;
  81. }
  82. hide();
  83. }
  84. // 初始化
  85. if (document.readyState === 'loading') {
  86. document.addEventListener('DOMContentLoaded', init);
  87. } else {
  88. init();
  89. }
  90. return {
  91. show,
  92. hide
  93. };
  94. })();
  95. // 全局 Loading 控制器
  96. window.GlobalLoading = (function() {
  97. let overlay = null;
  98. let loadingText = null;
  99. function init() {
  100. overlay = document.getElementById('globalLoadingOverlay');
  101. loadingText = overlay ? overlay.querySelector('.global-loading-text') : null;
  102. }
  103. function show(text = '正在处理...') {
  104. // console.log('[GlobalLoading] show() 被调用');
  105. // console.log('[GlobalLoading] 文本:', text);
  106. if (!overlay) {
  107. // console.log('[GlobalLoading] → 初始化overlay元素...');
  108. init();
  109. }
  110. if (!overlay) {
  111. // console.error('[GlobalLoading] ✗ overlay元素未找到!');
  112. return;
  113. }
  114. // console.log('[GlobalLoading] ✓ overlay元素存在');
  115. if (loadingText) {
  116. loadingText.textContent = text;
  117. // console.log('[GlobalLoading] ✓ 设置Loading文本:', text);
  118. }
  119. overlay.classList.add('is-visible');
  120. // console.log('[GlobalLoading] ✓ 添加is-visible类,Loading应该可见了');
  121. }
  122. function hide() {
  123. // console.log('[GlobalLoading] hide() 被调用');
  124. if (!overlay) {
  125. // console.error('[GlobalLoading] ✗ overlay元素不存在');
  126. return;
  127. }
  128. overlay.classList.remove('is-visible');
  129. // console.log('[GlobalLoading] ✓ 移除is-visible类,Loading已隐藏');
  130. }
  131. return {
  132. show,
  133. hide
  134. };
  135. })();
  136. // 全局 Alert 控制器
  137. window.GlobalAlert = (function() {
  138. let alertContainer = null;
  139. let alertMessage = null;
  140. let hideTimer = null;
  141. function init() {
  142. alertContainer = document.getElementById('globalAlert');
  143. alertMessage = alertContainer ? alertContainer.querySelector('#alertMessage') : null;
  144. }
  145. function show(text, duration = 1500) {
  146. console.log('[GlobalAlert] show() 被调用:', { text, duration });
  147. if (!alertContainer) {
  148. console.log('[GlobalAlert] 初始化 alertContainer');
  149. init();
  150. }
  151. if (!alertContainer) {
  152. console.error('[GlobalAlert] alertContainer 未找到!');
  153. return;
  154. }
  155. if (!alertMessage) {
  156. console.error('[GlobalAlert] alertMessage 未找到!');
  157. return;
  158. }
  159. console.log('[GlobalAlert] 设置消息:', text);
  160. // 清除之前的自动隐藏定时器
  161. if (hideTimer) {
  162. clearTimeout(hideTimer);
  163. hideTimer = null;
  164. }
  165. alertMessage.textContent = text;
  166. alertContainer.classList.add('show');
  167. console.log('[GlobalAlert] 已添加 show 类,alert 应该可见了');
  168. // 自动隐藏
  169. if (duration > 0) {
  170. hideTimer = setTimeout(() => {
  171. hide();
  172. }, duration);
  173. }
  174. }
  175. function hide() {
  176. if (!alertContainer) return;
  177. alertContainer.classList.remove('show');
  178. if (hideTimer) {
  179. clearTimeout(hideTimer);
  180. hideTimer = null;
  181. }
  182. }
  183. return {
  184. show,
  185. hide
  186. };
  187. })();
  188. // 页面管理:负责切换 iframe 中的子页面,并保持与导航栏状态同步
  189. (function () {
  190. console.log('[Index] index.js 已加载');
  191. const DEFAULT_PAGE = "store";
  192. function getPageFrame() {
  193. return document.getElementById("pageFrame");
  194. }
  195. function getNavigationFrame() {
  196. return document.getElementById("navigationFrame");
  197. }
  198. function switchPage(page) {
  199. // 只处理实际的页面切换,不处理login/register
  200. if (page === "login" || page === "register") {
  201. return;
  202. }
  203. // profile页面是独立页面,直接跳转
  204. if (page === "profile") {
  205. window.location.href = "page/profile/profile.html";
  206. return;
  207. }
  208. const frame = getPageFrame();
  209. if (!frame) {
  210. return;
  211. }
  212. switch (page) {
  213. case "store":
  214. frame.src = "page/store/store.html";
  215. break;
  216. case "assets":
  217. frame.src = "page/assets/assets.html";
  218. break;
  219. default:
  220. frame.src = "page/store/store.html";
  221. break;
  222. }
  223. // 同步导航栏状态
  224. syncNavigationState(page);
  225. }
  226. // 同步导航栏状态
  227. function syncNavigationState(page) {
  228. const navigationFrame = getNavigationFrame();
  229. if (navigationFrame && navigationFrame.contentWindow) {
  230. // 使用setTimeout确保iframe已加载
  231. setTimeout(() => {
  232. navigationFrame.contentWindow.postMessage(
  233. { type: "navigation", page },
  234. "*"
  235. );
  236. }, 100);
  237. }
  238. }
  239. window.addEventListener("message", (event) => {
  240. // 调试:记录所有收到的消息
  241. console.log('[Index] 收到message事件:', {
  242. origin: event.origin,
  243. expectedOrigin: window.location.origin,
  244. data: event.data,
  245. source: event.source,
  246. type: event.data?.type
  247. });
  248. // 检查 origin(允许同源或 localhost,或者来自 iframe)
  249. const isSameOrigin = event.origin === window.location.origin;
  250. const isLocalhost = event.origin === 'http://localhost:3000' ||
  251. event.origin === 'http://127.0.0.1:3000' ||
  252. event.origin.startsWith('http://localhost:') ||
  253. event.origin.startsWith('http://127.0.0.1:');
  254. // 允许来自同源的 iframe(即使 origin 不完全匹配)
  255. const isFromIframe = event.source && event.source !== window;
  256. console.log('[Index] Origin 检查:', {
  257. eventOrigin: event.origin,
  258. windowOrigin: window.location.origin,
  259. isSameOrigin,
  260. isLocalhost,
  261. isFromIframe,
  262. willPass: isSameOrigin || isLocalhost || isFromIframe
  263. });
  264. // 对于 global-alert 消息,放宽 origin 检查(允许来自任何同源 iframe)
  265. if (event.data && event.data.type === 'global-alert') {
  266. console.log('[Index] 这是 global-alert 消息,放宽 origin 检查');
  267. // 允许来自任何 iframe 的消息(只要 source 存在且不是 window 本身)
  268. if (isFromIframe || isSameOrigin || isLocalhost) {
  269. console.log('[Index] global-alert 消息通过检查');
  270. } else {
  271. console.warn('[Index] global-alert 消息被 origin 检查过滤:', event.origin);
  272. // 即使 origin 不匹配,也允许 global-alert 消息通过(因为来自同源 iframe)
  273. console.log('[Index] 但允许通过(来自 iframe)');
  274. }
  275. } else if (!isSameOrigin && !isLocalhost && !isFromIframe) {
  276. console.log('[Index] 消息被 origin 检查过滤:', event.origin);
  277. return;
  278. }
  279. console.log('[Index] 消息通过 origin 检查,继续处理');
  280. const { data } = event;
  281. if (data && data.type === "navigation" && (data.page === "login" || data.page === "register")) {
  282. // console.log('[2-Index] 收到login/register消息');
  283. const loginFrame = document.getElementById('loginViewFrame');
  284. if (loginFrame) {
  285. const mode = data.page === "register" ? "register" : "login";
  286. loginFrame.style.display = 'block';
  287. // console.log('[3-Index] iframe已显示');
  288. const sendMode = () => {
  289. if (loginFrame.contentWindow) {
  290. loginFrame.contentWindow.postMessage({
  291. type: 'open-login-view',
  292. mode: mode
  293. }, '*');
  294. // console.log('[4-Index] 消息已发送到login iframe');
  295. } else {
  296. setTimeout(sendMode, 100);
  297. }
  298. };
  299. sendMode();
  300. const handleLoad = () => {
  301. setTimeout(() => {
  302. sendMode();
  303. }, 50);
  304. };
  305. if (loginFrame.contentDocument && loginFrame.contentDocument.readyState === 'complete') {
  306. handleLoad();
  307. } else {
  308. loginFrame.addEventListener('load', handleLoad, { once: true });
  309. }
  310. }
  311. } else if (data && data.type === "navigation" && data.page) {
  312. switchPage(data.page);
  313. }
  314. // 注意:global-alert、global-loading、global-confirm 消息不再通过 index.js 处理
  315. // 各个 view 现在直接调用父窗口的 GlobalAlert/GlobalLoading/GlobalConfirm
  316. else if (data && data.type === "open-export-view") {
  317. // 处理打开导出弹出框
  318. console.log('[Index] 收到open-export-view消息:', data);
  319. if (!data.folderName) {
  320. console.error('[Index] 缺少文件夹名称');
  321. return;
  322. }
  323. if (!window.ExportViewManager) {
  324. console.error('[Index] ExportViewManager 未初始化');
  325. return;
  326. }
  327. // 直接打开弹出框,传递文件夹名称
  328. window.ExportViewManager.show(data.folderName).then((confirmed) => {
  329. console.log('[Index] 用户选择:', confirmed ? '确认导出' : '取消');
  330. // 如果用户确认,可以在这里处理实际的导出下载逻辑
  331. if (confirmed) {
  332. // TODO: 处理实际的导出下载逻辑
  333. console.log('[Index] 用户确认导出,文件夹:', data.folderName);
  334. }
  335. }).catch(error => {
  336. console.error('[Index] ExportViewManager显示失败:', error);
  337. });
  338. } else if (data && data.type === "close-login-view") {
  339. const loginFrame = document.getElementById('loginViewFrame');
  340. if (loginFrame) {
  341. loginFrame.style.display = 'none';
  342. }
  343. } else if (data && data.type === "open-ai-generate-view") {
  344. // 处理打开AI生图界面
  345. console.log('[Index] 收到open-ai-generate-view消息:', data);
  346. const aiGenerateFrame = document.getElementById('aiGenerateViewFrame');
  347. if (aiGenerateFrame) {
  348. aiGenerateFrame.style.display = 'block';
  349. aiGenerateFrame.style.pointerEvents = 'auto';
  350. aiGenerateFrame.style.visibility = 'visible';
  351. const sendAIData = () => {
  352. if (aiGenerateFrame.contentWindow) {
  353. aiGenerateFrame.contentWindow.postMessage({
  354. type: 'show-ai-generate',
  355. folderName: data.folderName,
  356. spritesheetData: data.spritesheetData,
  357. spritesheetLayout: data.spritesheetLayout
  358. }, '*');
  359. } else {
  360. setTimeout(sendAIData, 100);
  361. }
  362. };
  363. sendAIData();
  364. }
  365. } else if (data && data.type === "close-ai-generate-view") {
  366. const aiGenerateFrame = document.getElementById('aiGenerateViewFrame');
  367. if (aiGenerateFrame) {
  368. aiGenerateFrame.style.display = 'none';
  369. aiGenerateFrame.style.pointerEvents = 'none';
  370. aiGenerateFrame.style.visibility = 'hidden';
  371. }
  372. } else if (data && data.type === "open-pay-view") {
  373. // 处理打开支付界面
  374. const payFrame = document.getElementById('payViewFrame');
  375. if (payFrame) {
  376. payFrame.style.display = 'block';
  377. payFrame.style.pointerEvents = 'auto';
  378. payFrame.style.visibility = 'visible';
  379. const sendPayData = () => {
  380. if (payFrame.contentWindow) {
  381. payFrame.contentWindow.postMessage({
  382. type: 'open-pay-view',
  383. itemName: data.itemName,
  384. price: data.price,
  385. resourcePath: data.resourcePath,
  386. categoryDir: data.categoryDir
  387. }, '*');
  388. } else {
  389. setTimeout(sendPayData, 100);
  390. }
  391. };
  392. sendPayData();
  393. const handleLoad = () => {
  394. setTimeout(() => {
  395. sendPayData();
  396. }, 50);
  397. };
  398. if (payFrame.contentDocument && payFrame.contentDocument.readyState === 'complete') {
  399. handleLoad();
  400. } else {
  401. payFrame.addEventListener('load', handleLoad, { once: true });
  402. }
  403. }
  404. } else if (data && data.type === "close-pay-view") {
  405. const payFrame = document.getElementById('payViewFrame');
  406. if (payFrame) {
  407. payFrame.style.display = 'none';
  408. payFrame.style.pointerEvents = 'none';
  409. // 确保 iframe 不会遮挡其他元素
  410. payFrame.style.visibility = 'hidden';
  411. }
  412. } else if (data && data.type === "payment-success") {
  413. // 支付成功,刷新商店页面(如果需要)
  414. if (window.HintView) {
  415. window.HintView.success(`购买成功!${data.itemName} 已添加到网盘`, 3000);
  416. }
  417. } else if (data && data.type === "open-recharge-view") {
  418. // 处理打开充值界面
  419. const rechargeFrame = document.getElementById('rechargeViewFrame');
  420. if (rechargeFrame) {
  421. rechargeFrame.style.display = 'block';
  422. rechargeFrame.style.pointerEvents = 'auto';
  423. rechargeFrame.style.visibility = 'visible';
  424. const sendRechargeData = () => {
  425. if (rechargeFrame.contentWindow) {
  426. rechargeFrame.contentWindow.postMessage({
  427. type: 'open-recharge-view',
  428. needPoints: data.needPoints,
  429. currentPoints: data.currentPoints
  430. }, '*');
  431. } else {
  432. setTimeout(sendRechargeData, 100);
  433. }
  434. };
  435. sendRechargeData();
  436. const handleLoad = () => {
  437. setTimeout(() => {
  438. sendRechargeData();
  439. }, 50);
  440. };
  441. if (rechargeFrame.contentDocument && rechargeFrame.contentDocument.readyState === 'complete') {
  442. handleLoad();
  443. } else {
  444. rechargeFrame.addEventListener('load', handleLoad, { once: true });
  445. }
  446. }
  447. } else if (data && data.type === "close-recharge-view") {
  448. const rechargeFrame = document.getElementById('rechargeViewFrame');
  449. if (rechargeFrame) {
  450. rechargeFrame.style.display = 'none';
  451. rechargeFrame.style.pointerEvents = 'none';
  452. rechargeFrame.style.visibility = 'hidden';
  453. }
  454. } else if (data && data.type === "recharge-success") {
  455. // 充值成功,关闭充值界面
  456. const rechargeFrame = document.getElementById('rechargeViewFrame');
  457. if (rechargeFrame) {
  458. rechargeFrame.style.display = 'none';
  459. rechargeFrame.style.pointerEvents = 'none';
  460. rechargeFrame.style.visibility = 'hidden';
  461. }
  462. // 刷新点数显示
  463. if (window.postMessage) {
  464. window.postMessage({ type: 'refresh-points' }, '*');
  465. }
  466. // 显示成功提示
  467. if (window.HintView) {
  468. window.HintView.success(`充值成功!获得 ${data.points} Ani币`, 3000);
  469. }
  470. } else if (data && data.type === "avatar-updated") {
  471. // 头像更新,通知导航栏更新
  472. const navigationFrame = document.getElementById('navigationFrame');
  473. if (navigationFrame && navigationFrame.contentWindow) {
  474. // 从localStorage获取用户信息并更新头像
  475. try {
  476. const loginDataStr = localStorage.getItem('loginData');
  477. if (loginDataStr) {
  478. const loginData = JSON.parse(loginDataStr);
  479. if (loginData.user) {
  480. loginData.user.avatar = data.avatar;
  481. localStorage.setItem('loginData', JSON.stringify(loginData));
  482. // 通知导航栏更新
  483. navigationFrame.contentWindow.postMessage({
  484. type: 'login-success',
  485. user: loginData.user
  486. }, '*');
  487. }
  488. }
  489. } catch (error) {
  490. console.error('[Index] 更新头像信息失败:', error);
  491. }
  492. }
  493. } else if (data && data.type === "login-success" && data.user) {
  494. // 显示登录成功提示(在主窗口)
  495. if (window.HintView) {
  496. window.HintView.success('登录成功', 2000);
  497. }
  498. // 处理登录成功消息,转发给 navigation iframe 和 pageFrame
  499. const navigationFrame = getNavigationFrame();
  500. if (navigationFrame && navigationFrame.contentWindow) {
  501. navigationFrame.contentWindow.postMessage({
  502. type: 'login-success',
  503. user: data.user
  504. }, '*');
  505. }
  506. // 也转发给 pageFrame(store 页面)
  507. const pageFrame = getPageFrame();
  508. if (pageFrame && pageFrame.contentWindow) {
  509. pageFrame.contentWindow.postMessage({
  510. type: 'login-success',
  511. user: data.user
  512. }, '*');
  513. }
  514. // 转发给 assets iframe(如果存在),它会再转发给 disk iframe
  515. const assetsFrame = document.getElementById('assetsFrame');
  516. if (assetsFrame && assetsFrame.contentWindow) {
  517. assetsFrame.contentWindow.postMessage({
  518. type: 'login-success',
  519. user: data.user
  520. }, '*');
  521. }
  522. } else if (data && data.type === "refresh-points") {
  523. // 刷新用户点数显示
  524. console.log('[Index] 收到刷新点数请求');
  525. // 转发给导航栏更新点数
  526. const navigationFrame = getNavigationFrame();
  527. if (navigationFrame && navigationFrame.contentWindow) {
  528. navigationFrame.contentWindow.postMessage({ type: 'refresh-points' }, '*');
  529. }
  530. // 也转发给个人中心页面(如果打开的话)
  531. const pageFrame = getPageFrame();
  532. if (pageFrame && pageFrame.contentWindow) {
  533. pageFrame.contentWindow.postMessage({ type: 'refresh-points' }, '*');
  534. }
  535. } else if (data && data.type === "logout") {
  536. // 清除 localStorage 中的登录信息
  537. try {
  538. localStorage.removeItem('loginData');
  539. console.log('[Index] 登出,已清除登录信息');
  540. } catch (error) {
  541. console.error('[Index] 清除登录信息失败:', error);
  542. }
  543. // 处理登出消息,转发给所有 iframe
  544. const navigationFrame = getNavigationFrame();
  545. if (navigationFrame && navigationFrame.contentWindow) {
  546. navigationFrame.contentWindow.postMessage({
  547. type: 'logout'
  548. }, '*');
  549. }
  550. const pageFrame = getPageFrame();
  551. if (pageFrame && pageFrame.contentWindow) {
  552. pageFrame.contentWindow.postMessage({
  553. type: 'logout'
  554. }, '*');
  555. }
  556. const assetsFrame = document.getElementById('assetsFrame');
  557. if (assetsFrame && assetsFrame.contentWindow) {
  558. assetsFrame.contentWindow.postMessage({
  559. type: 'logout'
  560. }, '*');
  561. }
  562. }
  563. });
  564. // 检查并恢复登录状态
  565. function checkAndRestoreLogin() {
  566. try {
  567. const loginDataStr = localStorage.getItem('loginData');
  568. if (!loginDataStr) {
  569. return;
  570. }
  571. const loginData = JSON.parse(loginDataStr);
  572. const now = Date.now();
  573. // 检查是否过期(2小时)
  574. if (now >= loginData.expireTime) {
  575. // 已过期,清除登录信息
  576. localStorage.removeItem('loginData');
  577. console.log('[Index] 登录信息已过期(2小时),已清除');
  578. return;
  579. }
  580. // 未过期,恢复登录状态
  581. if (loginData.user) {
  582. console.log('[Index] 恢复登录状态,用户:', loginData.user.username);
  583. // 通知所有 iframe 登录成功
  584. const navigationFrame = getNavigationFrame();
  585. if (navigationFrame && navigationFrame.contentWindow) {
  586. navigationFrame.contentWindow.postMessage({
  587. type: 'login-success',
  588. user: loginData.user
  589. }, '*');
  590. }
  591. const pageFrame = getPageFrame();
  592. if (pageFrame && pageFrame.contentWindow) {
  593. pageFrame.contentWindow.postMessage({
  594. type: 'login-success',
  595. user: loginData.user
  596. }, '*');
  597. }
  598. const assetsFrame = document.getElementById('assetsFrame');
  599. if (assetsFrame && assetsFrame.contentWindow) {
  600. assetsFrame.contentWindow.postMessage({
  601. type: 'login-success',
  602. user: loginData.user
  603. }, '*');
  604. }
  605. }
  606. } catch (error) {
  607. console.error('[Index] 恢复登录状态失败:', error);
  608. localStorage.removeItem('loginData');
  609. }
  610. }
  611. window.addEventListener("DOMContentLoaded", () => {
  612. // 先检查并恢复登录状态
  613. checkAndRestoreLogin();
  614. switchPage(DEFAULT_PAGE);
  615. syncNavigationState(DEFAULT_PAGE);
  616. });
  617. })();