import { Modal } from 'ant-design-vue'; import { initCellLocalPathFromServer } from '@jeesite/core/utils/cell/cellLocalInit'; import { getCellLocalPath } from '@jeesite/core/utils/cell/cellLocal'; import { hydratePersistedCaseGlobalConfig } from '@jeesite/core/utils/caseGlobalConfig'; import { initOfflineMapDirFromServer } from '@jeesite/core/utils/map/offlineMapInit'; import { getOfflineMapDir } from '@jeesite/core/utils/map/offlineMap'; export const OPEN_SETTING_DRAWER_EVENT = 'layout-setting:open-drawer'; export const OPEN_OFFLINE_MAP_MODAL_EVENT = 'layout-setting:open-offline-map-modal'; export const OPEN_CELL_LOCAL_MODAL_EVENT = 'layout-setting:open-cell-local-modal'; const GUIDE_MODAL_DELAY = 180; let globalCaseConfigInitPromise: Promise | null = null; let hasPromptedGlobalCaseConfigGuide = false; function dispatchGuideEvent(eventName: string) { if (typeof window === 'undefined') return; window.dispatchEvent(new CustomEvent(eventName)); } export function openSettingDrawerByGuide() { dispatchGuideEvent(OPEN_SETTING_DRAWER_EVENT); } export function openOfflineMapModalByGuide() { openSettingDrawerByGuide(); window.setTimeout(() => { dispatchGuideEvent(OPEN_OFFLINE_MAP_MODAL_EVENT); }, GUIDE_MODAL_DELAY); } export function openCellLocalModalByGuide() { openSettingDrawerByGuide(); window.setTimeout(() => { dispatchGuideEvent(OPEN_CELL_LOCAL_MODAL_EVENT); }, GUIDE_MODAL_DELAY); } export function initGlobalCaseConfig() { if (!globalCaseConfigInitPromise) { globalCaseConfigInitPromise = hydratePersistedCaseGlobalConfig() .catch(() => undefined) .then(() => Promise.all([initOfflineMapDirFromServer(), initCellLocalPathFromServer()])) .then(() => undefined) .catch(() => undefined); } return globalCaseConfigInitPromise; } export function resetCaseConfigGuideState() { globalCaseConfigInitPromise = null; hasPromptedGlobalCaseConfigGuide = false; } export function promptCaseConfigGuide() { if (typeof window === 'undefined') return false; const missingOfflineMap = !getOfflineMapDir(); const missingCellLocal = !getCellLocalPath(); if (!missingOfflineMap && !missingCellLocal) { return false; } const missingItems = [missingOfflineMap ? '离线地图文件' : '', missingCellLocal ? '基站包文件' : ''].filter(Boolean); const content = `当前系统还未配置${missingItems.join('、')}。`; Modal.confirm({ title: '全局配置提醒', content, centered: true, okText: '去配置', cancelText: '稍后', onOk: () => { if (missingOfflineMap) { openOfflineMapModalByGuide(); return; } openCellLocalModalByGuide(); }, }); return true; } export async function promptCaseConfigGuideOnce() { if (typeof window === 'undefined' || hasPromptedGlobalCaseConfigGuide) { return false; } hasPromptedGlobalCaseConfigGuide = true; await initGlobalCaseConfig(); return promptCaseConfigGuide(); }