| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210 |
- // 全局 Loading 控制器
- window.GlobalLoading = (function() {
- let overlay = null;
- let loadingText = null;
-
- function init() {
- overlay = document.getElementById('globalLoadingOverlay');
- loadingText = overlay ? overlay.querySelector('.global-loading-text') : null;
- }
-
- function show(text = '正在处理...') {
- // console.log('[GlobalLoading] show() 被调用');
- // console.log('[GlobalLoading] 文本:', text);
-
- if (!overlay) {
- // console.log('[GlobalLoading] → 初始化overlay元素...');
- init();
- }
-
- if (!overlay) {
- // console.error('[GlobalLoading] ✗ overlay元素未找到!');
- return;
- }
-
- // console.log('[GlobalLoading] ✓ overlay元素存在');
-
- if (loadingText) {
- loadingText.textContent = text;
- // console.log('[GlobalLoading] ✓ 设置Loading文本:', text);
- }
-
- overlay.classList.add('is-visible');
- // console.log('[GlobalLoading] ✓ 添加is-visible类,Loading应该可见了');
- }
-
- function hide() {
- // console.log('[GlobalLoading] hide() 被调用');
-
- if (!overlay) {
- // console.error('[GlobalLoading] ✗ overlay元素不存在');
- return;
- }
-
- overlay.classList.remove('is-visible');
- // console.log('[GlobalLoading] ✓ 移除is-visible类,Loading已隐藏');
- }
-
- return {
- show,
- hide
- };
- })();
- // 全局 Alert 控制器
- window.GlobalAlert = (function() {
- let alertContainer = null;
- let alertMessage = null;
- let hideTimer = null;
-
- function init() {
- alertContainer = document.getElementById('globalAlert');
- alertMessage = alertContainer ? alertContainer.querySelector('#alertMessage') : null;
- }
-
- function show(text, duration = 1500) {
- if (!alertContainer) init();
- if (!alertContainer || !alertMessage) return;
-
- // 清除之前的自动隐藏定时器
- if (hideTimer) {
- clearTimeout(hideTimer);
- hideTimer = null;
- }
-
- alertMessage.textContent = text;
- alertContainer.classList.add('show');
-
- // 自动隐藏
- if (duration > 0) {
- hideTimer = setTimeout(() => {
- hide();
- }, duration);
- }
- }
-
- function hide() {
- if (!alertContainer) return;
- alertContainer.classList.remove('show');
- if (hideTimer) {
- clearTimeout(hideTimer);
- hideTimer = null;
- }
- }
-
- return {
- show,
- hide
- };
- })();
- // 页面管理:负责切换 iframe 中的子页面,并保持与导航栏状态同步
- (function () {
- const DEFAULT_PAGE = "assets";
- function getPageFrame() {
- return document.getElementById("pageFrame");
- }
- function getNavigationFrame() {
- return document.getElementById("navigationFrame");
- }
- function switchPage(page) {
- const frame = getPageFrame();
- if (!frame) {
- return;
- }
- switch (page) {
- case "store":
- frame.src = "page/store/store.html";
- break;
- case "assets":
- default:
- frame.src = "page/assets/assets.html";
- break;
- }
- const navigationFrame = getNavigationFrame();
- if (navigationFrame && navigationFrame.contentWindow) {
- navigationFrame.contentWindow.postMessage(
- { type: "navigation", page },
- "*"
- );
- }
- }
- window.addEventListener("message", (event) => {
- // console.log('[Index] ← 收到message事件:', event.data);
-
- if (event.origin !== window.location.origin) {
- // console.log('[Index] ⚠ origin不匹配,忽略:', event.origin);
- return;
- }
- const { data } = event;
- if (data && data.type === "navigation" && data.page) {
- switchPage(data.page);
- } else if (data && data.type === "global-loading") {
- // 处理全局loading显示/隐藏
- // console.log('[Index] 收到global-loading消息:', data);
- if (data.action === "show") {
- // console.log('[Index] 显示Loading:', data.text);
- window.GlobalLoading.show(data.text);
- } else if (data.action === "hide") {
- // console.log('[Index] 隐藏Loading');
- window.GlobalLoading.hide();
- }
- } else if (data && data.type === "global-alert") {
- // 处理全局alert提示
- // console.log('[Index] 收到global-alert消息:', data);
- if (data.text) {
- window.GlobalAlert.show(data.text, data.duration);
- }
- } else if (data && data.type === "global-confirm") {
- // 处理全局confirm对话框
- // console.log('[Index] 收到global-confirm消息:', data);
- if (data.message && window.GlobalConfirm) {
- // 确保 GlobalConfirm 初始化完成后再显示
- window.GlobalConfirm.show(data.message).then((confirmed) => {
- // console.log('[Index] 用户选择:', confirmed ? '确认' : '取消');
- // 将结果发送回请求的子窗口
- event.source.postMessage({
- type: 'global-confirm-response',
- id: data.id,
- confirmed: confirmed
- }, event.origin);
- }).catch(error => {
- // console.error('[Index] GlobalConfirm显示失败:', error);
- // 失败时返回取消
- event.source.postMessage({
- type: 'global-confirm-response',
- id: data.id,
- confirmed: false
- }, event.origin);
- });
- }
- } else if (data && data.type === "open-export-view") {
- // 处理打开导出弹出框
- // console.log('[Index] 收到open-export-view消息:', data);
- if (data.folderName && window.ExportViewManager) {
- // 直接打开弹出框,传递文件夹名称
- window.ExportViewManager.show(data.folderName).then((confirmed) => {
- // console.log('[Index] 用户选择:', confirmed ? '确认导出' : '取消');
- // 如果用户确认,可以在这里处理实际的导出下载逻辑
- if (confirmed) {
- // TODO: 处理实际的导出下载逻辑
- // console.log('[Index] 用户确认导出,文件夹:', data.folderName);
- }
- }).catch(error => {
- // console.error('[Index] ExportViewManager显示失败:', error);
- });
- }
- }
- });
- window.addEventListener("DOMContentLoaded", () => {
- switchPage(DEFAULT_PAGE);
- });
- })();
|