// Main Admin SPA Application import { api } from './api.js'; import { renderDashboard } from './pages/dashboard.js'; import { renderRecords } from './pages/records.js?v=20260625-records-fix'; import { renderStores } from './pages/stores.js'; import { renderEmployees } from './pages/employees.js'; import { renderAgentConfigs } from './pages/agent-configs.js'; import { renderCrm } from './pages/crm.js'; import { initAiAssistant } from './ai-assistant.js?v=20260625-longchat-default'; import './form-copilot.js'; // ---- Router ---- function getRoute() { const hash = window.location.hash || '#/dashboard'; const [path] = hash.substring(2).split('?'); return path; } function navigate(route) { window.location.hash = `#/${route}`; } // ---- Auth Check ---- function isLoggedIn() { return !!api.token; } function getNavItems() { const items = [ { route: 'dashboard', icon: '📊', label: '统计概览' }, { route: 'crm', icon: '💎', label: 'CRM管理' }, { route: 'records', icon: '📋', label: '反馈记录' }, { route: 'employees', icon: '👥', label: '员工管理' }, ]; if (!api.isStoreManager) { items.splice(2, 0, { route: 'stores', icon: '🏪', label: '门店管理' }); items.push({ route: 'agent-configs', icon: '🤖', label: '智能体配置' }); } return items; } // ---- Render App Shell ---- function renderApp() { let route = getRoute(); const app = document.getElementById('app'); if (!isLoggedIn()) { renderLogin(app); return; } const username = localStorage.getItem('feedback_admin_user') || 'admin'; const displayName = localStorage.getItem('feedback_admin_display_name') || username; const storeName = localStorage.getItem('feedback_admin_store_name') || ''; const navItems = getNavItems(); if (!navItems.some(i => i.route === route)) { route = 'dashboard'; window.location.hash = '#/dashboard'; } app.innerHTML = `
管理后台登录