import http from './http' import type { WizardOptions, DeploymentProfileDto, SaveWizardRequest, EffectivePagesDto } from '@/types/wizard' // 与 api/auth.ts 一致:VITE_USE_MOCK==='true' 时走本地假数据,便于无后端联调。 const MOCK = import.meta.env.VITE_USE_MOCK === 'true' const MOCK_OPTIONS: WizardOptions = { navigationKinds: [ { id: 'magnetic', name: '磁导航', group: 'navigation', description: '磁条循迹 + 地标 / RFID 定位' }, { id: 'qrcode', name: '二维码导航', group: 'navigation', description: '二维码地标 + 码值地图' }, { id: 'laser', name: '激光导航', group: 'navigation', description: '反光板 / SLAM + 激光避障' } ], modules: [ { id: 'wms', name: 'WMS 仓储管理', group: 'module', description: '库位 / 库存 / 出入库管理' }, { id: 'ptl', name: 'PTL 拣选系统', group: 'module', description: 'Pick-to-Light 亮灯拣选与播种' } ], scenarios: { templates: [ { id: 'tpl-sps', name: 'SPS 物料配送', category: 'SPS' }, { id: 'tpl-pack', name: '电池 Pack 自动化产线', category: 'BatteryPack' }, { id: 'tpl-loop', name: '环线运行', category: 'Loop' }, { id: 'tpl-p2p', name: '点对点柔性搬运', category: 'P2P' } ] } } const NAV_SCENE: Record = { magnetic: 'scene.mag', qrcode: 'scene.qrlidar', laser: 'scene.qrlidar' } function toLauncherSceneIds(kinds: string[]): string[] { const result: string[] = [] for (const k of kinds) { const id = NAV_SCENE[k] ?? `scene.${k}` if (!result.includes(id)) result.push(id) } if (kinds.some((k) => k.toLowerCase() === 'magnetic') && !result.includes('scene.signal')) { result.push('scene.signal') } if (result.length > 0 && !result.includes('scene.device')) result.push('scene.device') return result } let mockProfile: DeploymentProfileDto = { configured: false, platformType: 'standard', modules: [], navigationKinds: [], scenarios: [], updatedBy: 'mock', activeSceneIds: [], hiddenPages: [] } export async function getWizardOptions(): Promise { if (MOCK) return MOCK_OPTIONS const { data } = await http.get('/wizard/options') return data } export async function getWizardProfile(): Promise { if (MOCK) return mockProfile const { data } = await http.get('/wizard/profile') return data } export async function saveWizardProfile(req: SaveWizardRequest): Promise { if (MOCK) { mockProfile = { ...mockProfile, platformType: req.platformType ?? mockProfile.platformType, modules: req.modules ?? [], navigationKinds: req.navigationKinds ?? [], scenarios: req.scenarios ?? [], configured: true, activeSceneIds: toLauncherSceneIds(req.navigationKinds ?? []) } return mockProfile } const { data } = await http.put('/wizard/profile', req) return data } export async function getEffectivePages(): Promise { if (MOCK) { return { configured: mockProfile.configured, tailorablePages: [], enabledPages: [], hiddenPages: [] } } const { data } = await http.get('/wizard/effective-pages') return data }