import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import ParentView from '@/components/ParentView';
import LiveConsole from "@/views/live/liveConsole/index.vue";


/**
 * Note: 路由配置项
 *
 * hidden: true                     // 当设置 true 的时候该路由不会再侧边栏出现 如401，login等页面，或者如一些编辑页面/edit/1
 * alwaysShow: true                 // 当你一个路由下面的 children 声明的路由大于1个时，自动会变成嵌套的模式--如组件页面
 *                                  // 只有一个时，会将那个子路由当做根路由显示在侧边栏--如引导页面
 *                                  // 若你想不管路由下面的 children 声明的个数都显示你的根路由
 *                                  // 你可以设置 alwaysShow: true，这样它就会忽略之前定义的规则，一直显示根路由
 * redirect: noRedirect             // 当设置 noRedirect 的时候该路由在面包屑导航中不可被点击
 * name:'router-name'               // 设定路由的名字，一定要填写不然使用<keep-alive>时会出现各种问题
 * query: '{"id": 1, "name": "ry"}' // 访问路由的默认传递参数
 * meta : {
    noCache: true                   // 如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    title: 'title'                  // 设置该路由在侧边栏和面包屑中展示的名字
    icon: 'svg-name'                // 设置该路由的图标，对应路径src/assets/icons/svg
    breadcrumb: false               // 如果设置为false，则不会在breadcrumb面包屑中显示
    activeMenu: '/system/user'      // 当路由设置了该属性，则会高亮相对应的侧边栏。
  }
 */

// 公共路由
export const constantRoutes = [
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: (resolve) => require(['@/views/redirect'], resolve)
      }
    ]
  },
  {
    path: '/login',
    component: (resolve) => require(['@/views/login'], resolve),
    hidden: true
  },
  {
    path: '/register',
    component: (resolve) => require(['@/views/register'], resolve),
    hidden: true
  },
  {
    path: '/set-password',
    name: 'SetPassword',
    component: () => import('@/views/setPassword.vue'),
    hidden: true
  },
  {
    path: '/404',
    component: (resolve) => require(['@/views/error/404'], resolve),
    hidden: true
  },
  {
    path: '/401',
    component: (resolve) => require(['@/views/error/401'], resolve),
    hidden: true
  },
  // /wx 空壳路由已移除（个微管理路由在下方690行正确定义）
  {
    path: '',
    component: Layout,
    redirect: 'index',
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/index'], resolve),
        name: 'Index',
        meta: { title: '首页', icon: 'dashboard', affix: true }
      }
    ]
  },
  {
    path: '/user',
    component: Layout,
    hidden: true,
    redirect: 'noredirect',
    children: [
      {
        path: 'profile',
        component: (resolve) => require(['@/views/system/user/profile/index'], resolve),
        name: 'Profile',
        meta: { title: '个人中心', icon: 'user' }
      }
    ]
  },
  {
    path: '/system/user-auth',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'role/:userId(\\d+)',
        component: (resolve) => require(['@/views/system/user/authRole'], resolve),
        name: 'AuthRole',
        meta: { title: '分配角色', activeMenu: '/system/user'}
      }
    ]
  },
  {
    path: '/system/role-auth',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'user/:roleId(\\d+)',
        component: (resolve) => require(['@/views/system/role/authUser'], resolve),
        name: 'AuthUser',
        meta: { title: '分配用户', activeMenu: '/system/role'}
      }
    ]
  },
  {
    path: '/system/dict-data',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index/:dictId(\\d+)',
        component: (resolve) => require(['@/views/system/dict/data'], resolve),
        name: 'Data',
        meta: { title: '字典数据', activeMenu: '/system/dict'}
      }
    ]
  },
  {
    path: '/monitor/job-log',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/monitor/job/log'], resolve),
        name: 'JobLog',
        meta: { title: '调度日志', activeMenu: '/monitor/job'}
      }
    ]
  },
  {
    path: '/tool/gen-edit',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: (resolve) => require(['@/views/tool/gen/editTable'], resolve),
        name: 'GenEdit',
        meta: { title: '修改生成配置', activeMenu: '/tool/gen'}
      }
    ]
  },
  {
    path: '/watch/deviceInfo/details',
    component: Layout,
    hidden: true,
    children: [
      {
        path: ':deviceId(\\d+)',
        component: (resolve) => require(['@/views/watch/deviceInfo/details'], resolve),
        name: 'details',
        meta: { title: '设备详情', activeMenu: '/watch/deviceInfo'}
      }
    ]
  },
  {
    path: '/course/sopTempe',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'updateSopTemp/:id/:type(\\d+)', // 确保 :type 的正则匹配数字
        component: () => import('@/views/qw/sopTemp/updateSopTemp'),
        name: 'updateSopTemp',
        meta: { title: '改动SOP模板', activeMenu: '/course/addSopTemp' }
      },
      {
        path: 'updateTemp/:id/:type(\\d+)', // 确保 :type 的正则匹配数字
        component: () => import('@/views/qw/sopTemp/updateTemp'),
        name: 'updateTemp',
        meta: { title: '改动SOP模板', activeMenu: '/course/updateTemp' }
      },
      {
        path: 'updateAiChatTemp/:id/:type(\\d+)',
        component: () => import('@/views/qw/sopTemp/updateAiChatTemp'),
        name: 'updateAiChatTempCourse',
        meta: { title: '改动SOP模板', activeMenu: '/course/addSopTemp' }
      },
      {
        path: 'courseFinishTemp/:parentId',
        component: (resolve) => require(['@/views/course/courseFinishTemp/index'], resolve),
        name: 'courseFinishTempCourse',
        meta: { title: '模板详情', activeMenu: '/course'}
      }
    ]
  },
  {
    path: '/fastGpt/fastGptDataset/Collection',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'fastGptCollection/:datasetId',
        component: (resolve) => require(['@/views/fastGpt/fastGptDataset/fastGptCollection'], resolve),
        name: 'fastGptCollection',
        meta: { title: '知识库的集合', activeMenu: '/fastGpt/fastGptCollection'}
      }
    ]
  },
  {
    path: '/qw/sopTemp',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'addSopTemp/:command',
        component: (resolve) => require(['@/views/qw/sopTemp/addSopTemp'], resolve),
        name: 'addSopTemp',
        meta: { title: '新增SOP模板', activeMenu: '/qw/addSopTemp'}
      },
      {
        path: 'addTemp/:command',
        component: (resolve) => require(['@/views/qw/sopTemp/addTemp'], resolve),
        name: 'addTemp',
        meta: { title: '新增SOP模板', activeMenu: '/qw/addTemp'}
      },
      {
        path: 'addAiChatTemp',
        component: (resolve) => require(['@/views/qw/sopTemp/addAiChatTemp'], resolve),
        name: 'addAiChatTemp',
        meta: { title: '新增AI对话模板', activeMenu: '/qw/addSopTemp'}
      },
      {
        path: 'updateSopTemp/:id/:type(\\d+)',
        component: () => import('@/views/qw/sopTemp/updateSopTemp'),
        name: 'updateSopTempQw',
        meta: { title: '改动SOP模板', activeMenu: '/qw/addSopTemp' }
      },
      {
        path: 'updateTemp/:id/:type(\\d+)',
        component: () => import('@/views/qw/sopTemp/updateTemp'),
        name: 'updateTempQw',
        meta: { title: '改动SOP模板', activeMenu: '/qw/updateTemp' }
      },
      {
        path: 'updateAiChatTemp/:id/:type(\\d+)',
        component: () => import('@/views/qw/sopTemp/updateAiChatTemp'),
        name: 'updateAiChatTempQw',
        meta: { title: '改动SOP模板', activeMenu: '/qw/addSopTemp' }
      }
    ]
  },
  {
    path: '/qw/sop',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'addSop/:corpId/:type(\\d+)',
        component: (resolve) => require(['@/views/qw/sop/addSop'], resolve),
        name: 'addSop',
        meta: { title: '新增SOP任务', activeMenu: '/qw/sop'}
      },
      {
        path: 'addAiChatSop/:corpId',
        component: (resolve) => require(['@/views/qw/sop/addAiChatSop'], resolve),
        name: 'addAiChatSop',
        meta: { title: '新增聊天SOP任务', activeMenu: '/qw/sop'}
      },
      {
        path: 'updateSop/:id/:type',
        component: (resolve) => require(['@/views/qw/sop/updateSop.vue'], resolve),
        name: 'updateSop',
        meta: { title: '修改/查看SOP任务', activeMenu: '/qw/sop'}
      },
      {
        path: 'upAiChatDateSop/:id/:type',
        component: (resolve) => require(['@/views/qw/sop/upAiChatDateSop'], resolve),
        name: 'upDateAiChatSop',
        meta: { title: '修改/查看聊天SOP任务', activeMenu: '/qw/sop'}
      }
    ]
  },
  {
    path: '/qw/conversion',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'courseFinishTemp/:parentId',
        component: (resolve) => require(['@/views/course/courseFinishTemp/index'], resolve),
        name: 'courseFinishTempConversion',
      }
    ]
  },
  {
    path: '/fastGpt/fastGptRole1',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'updateFastGptRole/:command',
        component: (resolve) => require(['@/views/fastGpt/fastGptRole/fastGptRoleUpdate'], resolve),
        name: 'updateAiRole',
        meta: { title: '修改ai角色', activeMenu: '/fastGpt/fastGptRole'}
      }
    ]
  },
  // 已合并到 /course/sopTempe 路由中（删除重复定义）
  {
    path: '/qw/sopUserLogs',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'sopUserLogsSchedule/:id',
        component: () => import('@/views/qw/sopUserLogs/sopUserLogsSchedule.vue'),
        name: 'sopUserLogsSchedule',
        meta: { title: '查看营期', activeMenu: '/qw/sop' }
      }
    ]
  },
  // 独立页路由：不嵌套根布局，直接渲染目标组件
  {
    path: '/live/liveConsole/:liveId',
    name: 'LiveConsole',
    component: LiveConsole, // 直接渲染目标组件，无侧边栏
    meta: {
      isIndependentPage: true // 标记为“独立页”
    }
  },
  {
    path: '/his/aiWorkflow',
  component: () => import('@/layout/index'),
  hidden: true,
  children: [
    {
      path: '',
      component: () => import('@/views/his/aiWorkflow/index'),
      name: 'AiWorkflow',
      meta: { title: 'AI工作流', icon: 'workflow' }
    },
    {
      path: 'design',
      component: () => import('@/views/his/aiWorkflow/design'),
      name: 'AiWorkflowDesign',
      meta: { title: '工作流设计', activeMenu: '/his/aiWorkflow' }
    },
    {
      path: 'design/:id',
      component: () => import('@/views/his/aiWorkflow/design'),
      name: 'AiWorkflowEdit',
      meta: { title: '编辑工作流', activeMenu: '/his/aiWorkflow' }
    }
  ]
  },

  {
    path: '/company/aiWorkflow',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/company/aiWorkflow/index'),
        name: 'CompanyAiWorkflow',
        meta: { title: 'AI工作流', activeMenu: '/company/aiWorkflow' }
      }
    ]
  },
  {
    path: '/companyWx/companyWorkflow',
    component: () => import('@/layout/index'),
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/company/companyWorkflow/index'),
        name: 'CompanyWorkflowFull',
        meta: { title: 'AI外呼工作流', icon: 'workflow' }
      },
      {
        path: 'myList',
        component: () => import('@/views/company/companyWorkflow/myIndex'),
        name: 'MyCompanyWorkflow',
        meta: { title: '我的工作流', activeMenu: '/companyWx/companyWorkflow' }
      },
      {
        path: 'design',
        component: () => import('@/views/company/companyWorkflow/design'),
        name: 'CompanyWorkflowDesign',
        meta: { title: 'AI外呼工作流设计', activeMenu: '/companyWx/companyWorkflow' }
      },
      {
        path: 'design/:id',
        component: () => import('@/views/company/companyWorkflow/design'),
        name: 'CompanyWorkflowEdit',
        meta: { title: '编辑AI外呼工作流', activeMenu: '/companyWx/companyWorkflow' }
      }
    ]
  },
  {
    path: '/companyWorkflow/version-preview/:versionId',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/company/companyWorkflow/design'),
        name: 'WorkflowVersionPreview',
        meta: { title: '历史版本预览', activeMenu: '/companyWx/companyWorkflow' }
      }
    ]
  },
  {
    path: '/taskStatistics/wxClient',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/taskStatistics/wxClient/index'),
        name: 'WxClientStatistics',
        meta: { title: '加微统计', activeMenu: '/taskStatistics/wxClient' }
      }
    ]
  },
  {
    path: '/taskStatistics/sendMsgLog',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/taskStatistics/sendMsgLog/index'),
        name: 'sendMsgLogStatistics',
        meta: { title: '短信统计', activeMenu: '/taskStatistics/sendMsgLog' }
      }
    ]
  },
  {
    path: '/taskStatistics/callLog',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'index',
        component: () => import('@/views/taskStatistics/callLog/index'),
        name: 'callLogStatistics',
        meta: { title: '外呼统计', activeMenu: '/taskStatistics/callLog' }
      }
    ]
  },
  {
    path: '/crm/customer/detail/:customerId',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '',
        component: () => import('@/views/crm/customer/customerDetail.vue'),
        name: 'CustomerDetail',
        meta: { title: '客户详情', activeMenu: '/crm/customer' }
      }
    ]
  },
  {
    path: '/wxSop/sopUserLogsWx',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'sopUserLogsScheduleWx/:id',
        component: () => import('@/views/wx/sopUserLogsWx/sopUserLogsScheduleWx.vue'),
        name: 'sopUserLogsScheduleWx',
        meta: { title: '个微SOP营期', activeMenu: '/wx/wxSop' }
      },
      {
        path: 'detail',
        component: () => import('@/views/wx/sopUserLogsWx/detail.vue'),
        name: 'sopUserLogsDetailWx',
        meta: { title: '个微SOP营期详情', activeMenu: '/wx/wxSop' }
      }
    ]
  },
  {
    path: '/wxSop/wxSop',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'sopLogsList/:id',
        component: () => import('@/views/wx/wxSop/sopLogsList.vue'),
        name: 'WxSopLogsList',
        meta: { title: '个微SOP执行详情', activeMenu: '/wx/wxSop' }
      }
    ]
  },
  {
    path: '/companyVoiceRobotic',
    component: Layout,
    hidden: true,
    children: [
      {
        path: 'myIndex',
        component: () => import('@/views/company/companyVoiceRobotic/myIndex.vue'),
        name: 'MyCompanyVoiceRobotic',
        meta: { title: '我的音色任务', activeMenu: '/companyWx/companyVoiceRobotic' }
      }
    ]
  },

  // ======== 龙虾引擎 (Lobster Workflow Engine) ========
  {
    path: '/lobster',
    component: Layout,
    redirect: '/lobster/production-workflow',
    name: 'Lobster',
    meta: { title: '龙虾引擎', icon: 'system' },
    children: [
      {
        path: 'production-workflow',
        component: ParentView,
        redirect: '/lobster/production-workflow/template',
        name: 'ProductionWorkflow',
        meta: { title: 'AI生产工作流', icon: 'component' },
        children: [
          {
            // 工作流画布保留路由（编辑入口仍可用），不挂菜单
            path: 'canvas',
            component: () => import('@/views/lobster/workflow-canvas/index'),
            name: 'LobsterCanvas',
            meta: { title: '工作流画布', icon: 'chart', hidden: true }
          },
          {
            path: 'template',
            component: () => import('@/views/lobster/template/index'),
            name: 'LobsterTemplate',
            meta: { title: '工作流模板库', icon: 'documentation' }
          }
        ]
      },
      {
        // AI 生成工作流保留路由（被模板库或画布跳转使用），不挂菜单
        path: 'workflow-generate',
        component: () => import('@/views/lobster/workflow-generate/index'),
        name: 'LobsterGenerate',
        meta: { title: 'AI生成工作流', icon: 'build', hidden: true }
      },
      {
        path: 'instance',
        component: () => import('@/views/lobster/instance/index'),
        name: 'LobsterInstance',
        meta: { title: '任务执行（实例监控）', icon: 'monitor' }
      },
      {
        path: 'optimization',
        component: () => import('@/views/lobster/optimization/index'),
        name: 'LobsterOptimization',
        meta: { title: 'AI优化建议', icon: 'eye-open' }
      },
      {
        path: 'prompt',
        component: () => import('@/views/lobster/prompt/index'),
        name: 'LobsterPrompt',
        meta: { title: '提示词管理', icon: 'edit' }
      },
      {
        path: 'sales-corpus',
        component: () => import('@/views/lobster/sales-corpus/index'),
        name: 'SalesCorpus',
        meta: { title: '销冠语料学习', icon: 'star' }
      },
      {
        // 接口注册中心 = 外部工作流（节点中调用的外部 API 注册），统一为「接口注册中心」一处
        path: 'api-registry',
        component: () => import('@/views/lobster/api-registry/index'),
        name: 'LobsterApiRegistry',
        meta: { title: '接口注册中心', icon: 'nested' }
      },
      {
        path: 'dead-letter',
        component: () => import('@/views/lobster/dead-letter/index'),
        name: 'LobsterDeadLetter',
        meta: { title: '死信队列', icon: 'bug' }
      },
      {
        path: 'event-audit',
        component: () => import('@/views/lobster/event-audit/index'),
        name: 'LobsterEventAudit',
        meta: { title: '节点审核', icon: 'checkbox' }
      },
      {
        path: 'chat-aggregate',
        component: () => import('@/views/lobster/chat-aggregate/index'),
        name: 'ChatAggregate',
        meta: { title: '聚合聊天', icon: 'message' }
      },
      {
        path: 'channel-plugin',
        component: () => import('@/views/lobster/channel-plugin/index'),
        name: 'ChannelPlugin',
        meta: { title: '渠道插件', icon: 'connection' }
      },
      {
        path: 'chat-test',
        component: () => import('@/views/lobster/chat-test/index'),
        name: 'LobsterChatTest',
        meta: { title: '模拟聊天测试', icon: 'chat-dot-square' }
      },
      {
        path: 'quality-verify',
        component: () => import('@/views/lobster/quality-verify/index'),
        name: 'LobsterQualityVerify',
        meta: { title: '评分准确性验证', icon: 'data-analysis' }
      },
      {
        path: 'test-scenario',
        component: () => import('@/views/lobster/test-scenario/index'),
        name: 'LobsterTestScenario',
        meta: { title: '测试场景管理', icon: 'document-checked' }
      },
      {
        path: 'e2e-history',
        component: () => import('@/views/lobster/e2e-history/index'),
        name: 'LobsterE2eHistory',
        meta: { title: 'E2E运行历史', icon: 'time' }
      },
      {
        path: 'dynamic-impl',
        component: () => import('@/views/lobster/dynamic-impl/index'),
        name: 'LobsterDynamicImpl',
        meta: { title: '动态节点审批', icon: 'connection' }
      },
      {
        path: 'model-route',
        component: () => import('@/views/lobster/model-route/index'),
        name: 'LobsterModelRoute',
        meta: { title: '多模型路由配置', icon: 'guide' }
      },
      {
        path: 'token-stats',
        component: () => import('@/views/lobster/token-stats/index'),
        name: 'LobsterTokenStats',
        meta: { title: 'Token消耗统计', icon: 'coin' }
      },
      {
        path: 'node-detail/:instanceId/:nodeId',
        component: () => import('@/views/lobster/node-detail/index'),
        name: 'LobsterNodeDetail',
        meta: { title: '节点详情', icon: 'document' }
      },
      {
        path: 'profile-config',
        component: () => import('@/views/lobster/profile-config/index'),
        name: 'LobsterProfileConfig',
        meta: { title: '用户画像配置', icon: 'user' }
      },
      {
        path: 'summary-config',
        component: () => import('@/views/lobster/summary-config/index'),
        name: 'LobsterSummaryConfig',
        meta: { title: '摘要生成配置', icon: 'notebook' }
      },
      {
        path: 'dedup-config',
        component: () => import('@/views/lobster/dedup-config/index'),
        name: 'LobsterDedupConfig',
        meta: { title: '消息去重配置', icon: 'filter' }
      },
      {
        path: 'sensitive-words',
        component: () => import('@/views/lobster/sensitive-words/index'),
        name: 'LobsterSensitiveWords',
        meta: { title: '敏感词库', icon: 'warning' }
      },
      {
        path: 'dashboard',
        component: () => import('@/views/lobster/dashboard/index'),
        name: 'LobsterDashboard',
        meta: { title: '引擎看板', icon: 'dashboard' }
      },
      {
        path: 'evolution',
        component: () => import('@/views/lobster/evolution/index'),
        name: 'LobsterEvolution',
        meta: { title: 'AI进化引擎', icon: 'guide' }
      },
      {
        path: 'node-capabilities',
        component: () => import('@/views/lobster/node-capabilities/index'),
        name: 'LobsterNodeCapabilities',
        meta: { title: '节点能力矩阵', icon: 'tree-table' }
      },
      {
        path: 'ab-test',
        component: () => import('@/views/lobster/ab-test/index'),
        name: 'LobsterAbTest',
        meta: { title: 'A/B测试', icon: 'chart' }
      },
      {
        path: 'learning-results',
        component: () => import('@/views/lobster/learning-results/index'),
        name: 'LobsterLearningResults',
        meta: { title: '学习结果', icon: 'education' }
      },
      {
        path: 'pay-manage',
        component: () => import('@/views/lobster/pay-manage/index'),
        name: 'LobsterPayManage',
        meta: { title: '支付管理', icon: 'money' }
      },
      {
        path: 'channel-config',
        component: () => import('@/views/lobster/channel-config/index'),
        name: 'LobsterChannelConfig',
        meta: { title: '渠道配置', icon: 'connection' }
      },
      {
        path: 'integration-test',
        component: () => import('@/views/lobster/integration-test/index'),
        name: 'LobsterIntegrationTest',
        meta: { title: '集成测试', icon: 'bug' }
      }
    ]
  },

  // ======== AI聊天质量评分 ========
  {
    path: '/aiChatQuality',
    component: Layout,
    name: 'AiChatQuality',
    meta: { title: 'AI回复质量评分', icon: 'star' },
    redirect: '/aiChatQuality/index',
    children: [
      {
        path: 'index',
        component: () => import('@/views/aiChatQuality/index'),
        name: 'AiChatQualityIndex',
        meta: { title: '质量评分', icon: 'star' }
      }
    ]
  },

  // ======== CRM ========
  {
    path: '/crm',
    component: Layout, redirect: '/crm/customer', name: 'Crm',
    meta: { title: 'CRM', icon: 'crm' },
    children: [
      { path: 'customer', component: () => import('@/views/crm/customer/index'), name: 'CrmCustomer', meta: { title: '客户管理' } },
      { path: 'event', component: () => import('@/views/crm/event/index'), name: 'CrmEvent', meta: { title: '客户事件' } },
      { path: 'msg', component: () => import('@/views/crm/msg/index'), name: 'CrmMsg', meta: { title: '客户消息' } },
      { path: 'customerVisit', component: () => import('@/views/crm/customerVisit/index'), name: 'CrmVisit', meta: { title: '客户拜访', hidden: true } },
      { path: 'companyWorkflow', component: () => import('@/views/company/companyWorkflow/index'), name: 'CrmCompanyWorkflow', meta: { title: '公司工作流' } }
    ]
  },

  // ======== AI聊天 ========
  {
    path: '/chat',
    component: Layout, redirect: '/chat/chatSession', name: 'Chat',
    meta: { title: 'AI聊天', icon: 'message' },
    children: [
      { path: 'chatSession', component: () => import('@/views/chat/chatSession/index'), name: 'ChatSession', meta: { title: '会话列表' } },
      { path: 'chatRole', component: () => import('@/views/chat/chatRole/index'), name: 'ChatRole', meta: { title: 'AI角色' } },
      { path: 'chatDataset', component: () => import('@/views/chat/chatDataset/index'), name: 'ChatDataset', meta: { title: '知识库' } }
    ]
  },

  // ======== FastGpt ========
  {
    path: '/fastGpt',
    component: Layout, redirect: '/fastGpt/fastGptRole', name: 'FastGpt',
    meta: { title: 'FastGpt', icon: 'server' },
    children: [
      { path: 'fastGptRole', component: () => import('@/views/fastGpt/fastGptRole/index'), name: 'FastGptRole', meta: { title: '角色管理' } },
      { path: 'fastGptDataset', component: () => import('@/views/fastGpt/fastGptDataset/index'), name: 'FastGptData', meta: { title: '数据集', hidden: true } },
      { path: 'fastGptUser', component: () => import('@/views/fastGpt/fastGptUser/index'), name: 'FastGptUser', meta: { title: 'AI用户', hidden: true } }
    ]
  },

  // ======== 企业管理 ========
  {
    path: '/company',
    component: Layout, redirect: '/company/companyUser', name: 'Company',
    meta: { title: '企业管理', icon: 'people' },
    children: [
      { path: 'companyUser', component: () => import('@/views/company/companyUser/index'), name: 'CompUser', meta: { title: '员工管理' } },
      { path: 'companyRole', component: () => import('@/views/company/companyRole/index'), name: 'CompRole', meta: { title: '角色管理', hidden: true } },
      { path: 'companyMenu', component: () => import('@/views/company/companyMenu/index'), name: 'CompMenu', meta: { title: '菜单管理', hidden: true } },
      { path: 'companySms', component: () => import('@/views/company/companySms/index'), name: 'CompSms', meta: { title: '短信管理' } },
      { path: 'companyRecharge', component: () => import('@/views/company/companyRecharge/index'), name: 'CompRecharge', meta: { title: '充值记录' } },
      { path: 'companyMoneyLogs', component: () => import('@/views/company/companyMoneyLogs/index'), name: 'CompMoney', meta: { title: '资金流水', hidden: true } },
      { path: 'companyProfit', component: () => import('@/views/company/companyProfit/index'), name: 'CompProfit', meta: { title: '分账记录', hidden: true } },
      { path: 'aiWorkflow', component: () => import('@/views/company/aiWorkflow/index'), name: 'CompAiWorkflow', meta: { title: 'AI工作流' } },
      { path: 'aiModel', component: () => import('@/views/company/aiModel/index'), name: 'CompAiModel', meta: { title: 'AI模型管理', hidden: true } },
      { path: 'workflowLobster', component: () => import('@/views/company/workflowLobster/index'), name: 'CompLobster', meta: { title: '龙虾工作流', hidden: true } }
    ]
  },

  // ======== 企微管理 ========
  {
    path: '/companyWx',
    component: Layout, redirect: '/companyWx/companyWorkflow', name: 'CompanyWx',
    meta: { title: '企微管理', icon: 'wechat' },
    children: [
      { path: 'companyWorkflow', component: () => import('@/views/company/companyWorkflow/index'), name: 'CompWorkflow', meta: { title: 'AI外呼工作流' } }
    ]
  },

  // ======== 个微管理 ========
  {
    path: '/wx',
    component: Layout, redirect: '/wx/wxAccount', name: 'Wx',
    meta: { title: '个微管理', icon: 'user' },
    children: [
      { path: 'wxAccount', component: () => import('@/views/company/wxAccount/index'), name: 'WxAccount', meta: { title: '个微账号' } },
      { path: 'wxUser', component: () => import('@/views/company/wxUser/index'), name: 'WxUser', meta: { title: '个微用户', hidden: true } }
    ]
  },

  // ======== 商城管理 ========
  {
    path: '/store',
    component: Layout, redirect: '/store/storeProduct', name: 'Store',
    meta: { title: '商城管理', icon: 'shopping' },
    children: [
      { path: 'storeProduct', component: () => import('@/views/store/storeProduct/index'), name: 'StoreProduct', meta: { title: '商品管理' } },
      { path: 'storeOrder', component: () => import('@/views/store/storeOrder/list'), name: 'StoreOrder', meta: { title: '订单管理', hidden: true } },
      { path: 'storeCoupon', component: () => import('@/views/store/coupon/index'), name: 'StoreCoupon', meta: { title: '优惠券', hidden: true } },
      { path: 'storeAfterSales', component: () => import('@/views/store/storeAfterSales/list'), name: 'StoreAS', meta: { title: '售后', hidden: true } }
    ]
  },

  // ======== 隐藏页路由(CUD/详情页等) ========
  // 注意：/crm/customer/detail 已在上方476行定义，/companyWx/companyWorkflow 已在上方383行定义
  // 此处不再重复定义，避免路由覆盖问题

]

export default new Router({
  mode: 'history', // 去掉url中的#
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})
