Files
hack/tools/scripts/llm-key-hunter/results/_cache/content/bjtu-hospital_hospital-patient-frontend.json
T

1 line
81 KiB
JSON
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{"repo": "bjtu-hospital/hospital-patient-frontend", "files": {"src/components/ai-bot/tools/router-tool.js": {"8027b88274e431b0e7f837c3948d2fc28c4b8a28": {"t": 1785746667.7945518, "n": 20640, "h": "a95ee1d3a13fbef5", "c": "/**\r\n * 页面路由跳转工具\r\n * \r\n * 此文件为 AI 助手提供页面导航能力,供 DeepSeek Tool Calls 模式使用。\r\n * \r\n * @description\r\n * 该工具允许 AI 根据用户意图,自动跳转到医院预约系统的各个功能页面。\r\n * AI 可以根据用户的自然语言描述,智能匹配并导航到相应的页面。\r\n * \r\n * @example\r\n * 用户说:\"我想预约挂号\" → AI 调用 navigateToPage({ pageName: \"select-hospital\" })\r\n * 用户说:\"查看我的预约\" → AI 调用 navigateToPage({ pageName: \"appointments\" })\r\n */\r\n\r\n// ============================================================================\r\n// 页面路由配置表\r\n// ============================================================================\r\n\r\n/**\r\n * 所有可用页面的路由配置\r\n * \r\n * @typedef {Object} PageRoute\r\n * @property {string} path - 页面路径(不含前导斜杠)\r\n * @property {string} title - 页面标题(导航栏显示)\r\n * @property {string} description - 页面功能描述,供 AI 理解页面用途\r\n * @property {string[]} keywords - 触发关键词,帮助 AI 匹配用户意图\r\n * @property {boolean} isTabBar - 是否为 TabBar 页面(需使用 switchTab 跳转)\r\n * @property {string[]} [requiredParams] - 必需的 URL 参数(可选)\r\n * @property {string[]} [optionalParams] - 可选的 URL 参数(可选)\r\n */\r\n\r\n/**\r\n * 完整的页面路由配置列表\r\n * @type {PageRoute[]}\r\n */\r\nexport const PAGE_ROUTES = [\r\n // ==================== 认证相关页面 ====================\r\n {\r\n path: \"pages/auth/login\",\r\n title: \"登录\",\r\n description: \"用户登录页面,使用手机号和密码登录系统\",\r\n keywords: [\"登录\", \"登陆\", \"sign in\", \"login\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/auth/register\",\r\n title: \"注册\",\r\n description: \"新用户注册页面,创建新账号\",\r\n keywords: [\"注册\", \"注冊\", \"sign up\", \"register\", \"新用户\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 首页(TabBar) ====================\r\n {\r\n path: \"pages/home/index\",\r\n title: \"首页\",\r\n description: \"应用首页,展示主要功能入口和快捷操作\",\r\n keywords: [\"首页\", \"主页\", \"home\", \"回首页\", \"返回首页\"],\r\n isTabBar: true\r\n },\r\n\r\n // ==================== 预约挂号流程 ====================\r\n {\r\n path: \"pages/home/appointment/select-hospital\",\r\n title: \"选择院区\",\r\n description: \"预约挂号第一步:选择就诊的院区/医院\",\r\n keywords: [\"预约\", \"挂号\", \"选择医院\", \"选择院区\", \"预约挂号\", \"我要预约\", \"我想挂号\", \"看病\"],\r\n isTabBar: false,\r\n optionalParams: [\"hospitalId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/select-department\",\r\n title: \"选择科室\",\r\n description: \"预约挂号第二步:选择就诊的科室\",\r\n keywords: [\"选择科室\", \"选科室\", \"哪个科室\", \"什么科\"],\r\n isTabBar: false,\r\n requiredParams: [\"hospitalId\"],\r\n optionalParams: [\"departmentId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/select-doctor\",\r\n title: \"选择医生\",\r\n description: \"预约挂号第三步:选择就诊的医生和时间段\",\r\n keywords: [\"选择医生\", \"选医生\", \"哪个医生\", \"找医生\", \"看哪个医生\"],\r\n isTabBar: false,\r\n requiredParams: [\"hospitalId\", \"departmentId\"],\r\n optionalParams: [\"doctorId\", \"date\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/confirm\",\r\n title: \"确认预约\",\r\n description: \"预约挂号第四步:确认预约信息,选择就诊人\",\r\n keywords: [\"确认预约\", \"确认挂号\", \"提交预约\"],\r\n isTabBar: false,\r\n requiredParams: [\"scheduleId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/payment\",\r\n title: \"支付\",\r\n description: \"预约挂号第五步:支付挂号费用\",\r\n keywords: [\"支付\", \"付款\", \"缴费\", \"付费\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/success\",\r\n title: \"预约成功\",\r\n description: \"预约成功页面,显示预约单详情\",\r\n keywords: [\"预约成功\", \"预约详情\", \"预约单\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\"]\r\n },\r\n\r\n // ==================== 候补功能 ====================\r\n {\r\n path: \"pages/home/waitlist/confirm-waitlist\",\r\n title: \"候补号源\",\r\n description: \"当没有可用号源时,可以申请候补排队\",\r\n keywords: [\"候补\", \"候补挂号\", \"排队等号\", \"没号了\", \"候补号源\"],\r\n isTabBar: false,\r\n requiredParams: [\"doctorId\", \"date\"]\r\n },\r\n {\r\n path: \"pages/home/waitlist/waitlist-success\",\r\n title: \"候补成功\",\r\n description: \"候补申请成功页面,显示候补单详情\",\r\n keywords: [\"候补成功\", \"候补详情\", \"候补单\"],\r\n isTabBar: false,\r\n requiredParams: [\"waitlistId\"]\r\n },\r\n\r\n // ==================== 改约功能 ====================\r\n {\r\n path: \"pages/home/reschedule/select-schedule\",\r\n title: \"选择新的就诊时间\",\r\n description: \"改约第一步:选择新的就诊日期和时间段\",\r\n keywords: [\"改约\", \"改时间\", \"改预约\", \"更改预约\", \"换时间\", \"重新预约时间\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\"]\r\n },\r\n {\r\n path: \"pages/home/reschedule/confirm\",\r\n title: \"确认改约\",\r\n description: \"改约第二步:确认新的预约信息\",\r\n keywords: [\"确认改约\", \"确认更改\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\", \"newScheduleId\"]\r\n },\r\n\r\n // ==================== 个人中心(TabBar) ====================\r\n {\r\n path: \"pages/profile/index\",\r\n title: \"个人中心\",\r\n description: \"个人中心页面,管理个人信息和查看各类记录\",\r\n keywords: [\"个人中心\", \"我的\", \"个人\", \"用户中心\", \"profile\"],\r\n isTabBar: true\r\n },\r\n\r\n // ==================== 我的预约和候补 ====================\r\n {\r\n path: \"pages/profile/appointments\",\r\n title: \"我的预约\",\r\n description: \"查看和管理我的所有预约记录\",\r\n keywords: [\"我的预约\", \"预约记录\", \"预约列表\", \"查看预约\", \"预约历史\", \"挂号记录\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/profile/waitlist\",\r\n title: \"我的候补\",\r\n description: \"查看和管理我的所有候补记录\",\r\n keywords: [\"我的候补\", \"候补记录\", \"候补列表\", \"查看候补\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 就诊人管理 ====================\r\n {\r\n path: \"pages/profile/patients\",\r\n title: \"就诊人管理\",\r\n description: \"添加、编辑和管理就诊人信息(可为家人预约)\",\r\n keywords: [\"就诊人\", \"就诊人管理\", \"添加就诊人\", \"家人\", \"患者管理\", \"绑定就诊人\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 健康档案 ====================\r\n {\r\n path: \"pages/profile/health/index\",\r\n title: \"健康档案\",\r\n description: \"查看个人健康档案,包括基本信息、病历和就诊记录\",\r\n keywords: [\"健康档案\", \"健康记录\", \"我的档案\", \"健康信息\", \"体检记录\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/profile/health/basic-info\",\r\n title: \"编辑基本信息\",\r\n description: \"编辑个人健康基本信息,如身高、体重、血型等\",\r\n keywords: [\"编辑基本信息\", \"修改信息\", \"健康信息编辑\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/profile/health/medical-record/detail\",\r\n title: \"病历详情\",\r\n description: \"查看某次就诊的详细病历记录\",\r\n keywords: [\"病历详情\", \"病历\", \"就诊记录详情\", \"看病记录\"],\r\n isTabBar: false,\r\n requiredParams: [\"recordId\"]\r\n },\r\n\r\n // ==================== 身份认证 ====================\r\n {\r\n path: \"pages/profile/verify-identity\",\r\n title: \"校内身份认证\",\r\n description: \"进行校内身份认证,绑定学号/工号\",\r\n keywords: [\"身份认证\", \"实名认证\", \"校内认证\", \"认证\", \"绑定学号\", \"验证身份\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 账号设置 ====================\r\n {\r\n path: \"pages/profile/settings\",\r\n title: \"账号设置\",\r\n description: \"账号设置页面,修改密码、退出登录等\",\r\n keywords: [\"设置\", \"账号设置\", \"修改密码\", \"账户设置\", \"系统设置\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 消息中心(TabBar) ====================\r\n {\r\n path: \"pages/message/index\",\r\n title: \"消息中心\",\r\n description: \"查看系统消息、预约提醒、候补通知等\",\r\n keywords: [\"消息\", \"消息中心\", \"通知\", \"提醒\", \"消息列表\"],\r\n isTabBar: true\r\n },\r\n\r\n // ==================== 其他功能 ====================\r\n {\r\n path: \"pages/features/doctors\",\r\n title: \"科室专家\",\r\n description: \"浏览和搜索所有科室的专家医生,查看医生简介、职称、专长等信息\",\r\n keywords: [\"科室专家\", \"专家\", \"医生列表\", \"找专家\", \"所有医生\", \"专家介绍\", \"医生详情\", \"看看有哪些医生\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/features/feedback\",\r\n title: \"意见反馈\",\r\n description: \"提交意见和建议,反馈问题\",\r\n keywords: [\"意见反馈\", \"反馈\", \"建议\", \"投诉\", \"问题反馈\", \"提意见\"],\r\n isTabBar: false\r\n }\r\n];\r\n\r\n// ============================================================================\r\n// DeepSeek Tool 定义\r\n// ============================================================================\r\n\r\n/**\r\n * 供 DeepSeek API 使用的 Tool 定义\r\n * \r\n * 此定义遵循 DeepSeek Tool Calls 规范,可直接添加到 tools 数组中。\r\n * \r\n * @example\r\n * const TOOLS = [\r\n * ...otherTools,\r\n * NAVIGATE_TO_PAGE_TOOL\r\n * ];\r\n */\r\nexport const NAVIGATE_TO_PAGE_TOOL = {\r\n type: \"function\",\r\n function: {\r\n name: \"navigateToPage\",\r\n description: `导航到医院预约系统的指定页面。根据用户的意图,跳转到相应的功能页面。\r\n\r\n可用页面及其用途:\r\n【预约挂号流程】\r\n- \"select-hospital\": 开始预约挂号,选择院区\r\n- \"select-department\": 选择就诊科室\r\n- \"select-doctor\": 选择医生和时间\r\n- \"confirm-appointment\": 确认预约信息\r\n- \"payment\": 支付挂号费\r\n- \"appointment-success\": 查看预约成功详情\r\n\r\n【候补功能】\r\n- \"confirm-waitlist\": 申请候补号源\r\n- \"waitlist-success\": 查看候补成功详情\r\n\r\n【改约功能】\r\n- \"reschedule-select\": 选择新的就诊时间\r\n- \"reschedule-confirm\": 确认改约\r\n\r\n【个人中心】\r\n- \"home\": 返回首页\r\n- \"profile\": 个人中心\r\n- \"appointments\": 查看我的预约记录\r\n- \"waitlist\": 查看我的候补记录\r\n- \"patients\": 就诊人管理\r\n- \"health\": 健康档案\r\n- \"settings\": 账号设置\r\n- \"verify-identity\": 身份认证\r\n\r\n【消息和其他】\r\n- \"messages\": 消息中心\r\n- \"doctors\": 浏览科室专家\r\n- \"feedback\": 意见反馈\r\n- \"login\": 登录页面\r\n- \"register\": 注册页面`,\r\n parameters: {\r\n type: \"object\",\r\n properties: {\r\n pageName: {\r\n type: \"string\",\r\n description: \"目标页面的名称标识符\",\r\n enum: [\r\n \"home\",\r\n \"login\",\r\n \"register\",\r\n \"select-hospital\",\r\n \"select-department\",\r\n \"select-doctor\",\r\n \"confirm-appointment\",\r\n \"payment\",\r\n \"appointment-success\",\r\n \"confirm-waitlist\",\r\n \"waitlist-success\",\r\n \"reschedule-select\",\r\n \"reschedule-confirm\",\r\n \"profile\",\r\n \"appointments\",\r\n \"waitlist\",\r\n \"patients\",\r\n \"health\",\r\n \"health-basic-info\",\r\n \"medical-record-detail\",\r\n \"verify-identity\",\r\n \"settings\",\r\n \"messages\",\r\n \"doctors\",\r\n \"ai-assistant\",\r\n \"feedback\"\r\n ]\r\n },\r\n params: {\r\n type: \"object\",\r\n description: \"传递给目标页面的参数(键值对形式)。例如:{\\\"doctorId\\\": \\\"123\\\", \\\"date\\\": \\\"2024-01-15\\\"}\",\r\n properties: {\r\n hospitalId: {\r\n type: \"string\",\r\n description: \"医院/院区ID\"\r\n },\r\n departmentId: {\r\n type: \"string\",\r\n description: \"科室ID\"\r\n },\r\n doctorId: {\r\n type: \"string\",\r\n description: \"医生ID\"\r\n },\r\n scheduleId: {\r\n type: \"string\",\r\n description: \"排班ID\"\r\n },\r\n appointmentId: {\r\n type: \"string\",\r\n description: \"预约ID\"\r\n },\r\n waitlistId: {\r\n type: \"string\",\r\n description: \"候补ID\"\r\n },\r\n recordId: {\r\n type: \"string\",\r\n description: \"病历记录ID\"\r\n },\r\n date: {\r\n type: \"string\",\r\n description: \"日期,格式:YYYY-MM-DD\"\r\n }\r\n }\r\n }\r\n },\r\n required: [\"pageName\"],\r\n additionalProperties: false\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * 严格模式下的 Tool 定义(Beta功能)\r\n * \r\n * 使用 strict 模式时,模型输出会严格遵循 JSON Schema 格式。\r\n * 需要设置 base_url=\"https://api.deepseek.com/beta\" 来启用。\r\n */\r\nexport const NAVIGATE_TO_PAGE_TOOL_STRICT = {\r\n type: \"function\",\r\n function: {\r\n name: \"navigateToPage\",\r\n strict: true,\r\n description: NAVIGATE_TO_PAGE_TOOL.function.description,\r\n parameters: {\r\n type: \"object\",\r\n properties: {\r\n pageName: {\r\n type: \"string\",\r\n description: \"目标页面的名称标识符\",\r\n enum: NAVIGATE_TO_PAGE_TOOL.function.parameters.properties.pageName.enum\r\n },\r\n params: {\r\n type: \"object\",\r\n description: \"传递给目标页面的参数\",\r\n properties: {\r\n hospitalId: { type: \"string\", description: \"医院/院区ID\" },\r\n departmentId: { type: \"string\", description: \"科室ID\" },\r\n doctorId: { type: \"string\", description: \"医生ID\" },\r\n scheduleId: { type: \"string\", description: \"排班ID\" },\r\n appointmentId: { type: \"string\", description: \"预约ID\" },\r\n waitlistId: { type: \"string\", description: \"候补ID\" },\r\n recordId: { type: \"string\", description: \"病历记录ID\" },\r\n date: { type: \"string\", description: \"日期,格式:YYYY-MM-DD\" }\r\n },\r\n required: [],\r\n additionalProperties: false\r\n }\r\n },\r\n required: [\"pageName\", \"params\"],\r\n additionalProperties: false\r\n }\r\n }\r\n};\r\n\r\n// ============================================================================\r\n// 页面名称到路径的映射\r\n// ============================================================================\r\n\r\n/**\r\n * 页面名称标识符到路由配置的映射表\r\n * @type {Object.<string, {path: string, isTabBar: boolean}>}\r\n */\r\nconst PAGE_NAME_MAP = {\r\n // 首页和认证\r\n \"home\": { path: \"pages/home/index\", isTabBar: true },\r\n \"login\": { path: \"pages/auth/login\", isTabBar: false },\r\n \"register\": { path: \"pages/auth/register\", isTabBar: false },\r\n \r\n // 预约挂号流程\r\n \"select-hospital\": { path: \"pages/home/appointment/select-hospital\", isTabBar: false },\r\n \"select-department\": { path: \"pages/home/appointment/select-department\", isTabBar: false },\r\n \"select-doctor\": { path: \"pages/home/appointment/select-doctor\", isTabBar: false },\r\n \"confirm-appointment\": { path: \"pages/home/appointment/confirm\", isTabBar: false },\r\n \"payment\": { path: \"pages/home/appointment/payment\", isTabBar: false },\r\n \"appointment-success\": { path: \"pages/home/appointment/success\", isTabBar: false },\r\n \r\n // 候补功能\r\n \"confirm-waitlist\": { path: \"pages/home/waitlist/confirm-waitlist\", isTabBar: false },\r\n \"waitlist-success\": { path: \"pages/home/waitlist/waitlist-success\", isTabBar: false },\r\n \r\n // 改约功能\r\n \"reschedule-select\": { path: \"pages/home/reschedule/select-schedule\", isTabBar: false },\r\n \"reschedule-confirm\": { path: \"pages/home/reschedule/confirm\", isTabBar: false },\r\n \r\n // 个人中心\r\n \"profile\": { path: \"pages/profile/index\", isTabBar: true },\r\n \"appointments\": { path: \"pages/profile/appointments\", isTabBar: false },\r\n \"waitlist\": { path: \"pages/profile/waitlist\", isTabBar: false },\r\n \"patients\": { path: \"pages/profile/patients\", isTabBar: false },\r\n \"health\": { path: \"pages/profile/health/index\", isTabBar: false },\r\n \"health-basic-info\": { path: \"pages/profile/health/basic-info\", isTabBar: false },\r\n \"medical-record-detail\": { path: \"pages/profile/health/medical-record/detail\", isTabBar: false },\r\n \"verify-identity\": { path: \"pages/profile/verify-identity\", isTabBar: false },\r\n \"settings\": { path: \"pages/profile/settings\", isTabBar: false },\r\n \r\n // 消息中心\r\n \"messages\": { path: \"pages/message/index\", isTabBar: true },\r\n \r\n // 其他功能\r\n \"doctors\": { path: \"pages/features/doctors\", isTabBar: false },\r\n \"ai-assistant\": { path: \"pages/features/ai-assistant\", isTabBar: false },\r\n \"feedback\": { path: \"pages/features/feedback\", isTabBar: false }\r\n};\r\n\r\n// ============================================================================\r\n// 导航函数\r\n// ============================================================================\r\n\r\n/**\r\n * 构建带查询参数的 URL\r\n * @param {string} basePath - 基础路径\r\n * @param {Object} params - 查询参数对象\r\n * @returns {string} 完整的 URL 路径\r\n */\r\nfunction buildUrl(basePath, params = {}) {\r\n const queryString = Object.entries(params)\r\n .filter(([, value]) => value !== undefined && value !== null && value !== '')\r\n .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)\r\n .join('&');\r\n \r\n return queryString ? `/${basePath}?${queryString}` : `/${basePath}`;\r\n}\r\n\r\n/**\r\n * 执行页面导航\r\n * \r\n * 根据页面类型自动选择正确的导航方式:\r\n * - TabBar 页面使用 uni.switchTab\r\n * - 普通页面使用 uni.navigateTo\r\n * \r\n * @param {string} pageName - 页面名称标识符\r\n * @param {Object} params - 页面参数\r\n * @returns {Promise<{success: boolean, message: string, url?: string}>}\r\n */\r\nexport async function navigateToPage(pageName, params = {}) {\r\n const pageConfig = PAGE_NAME_MAP[pageName];\r\n \r\n if (!pageConfig) {\r\n return {\r\n success: false,\r\n message: `未知的页面: \"${pageName}\"。请使用有效的页面名称。`,\r\n availablePages: Object.keys(PAGE_NAME_MAP)\r\n };\r\n }\r\n \r\n const { path, isTabBar } = pageConfig;\r\n const url = buildUrl(path, params);\r\n \r\n return new Promise((resolve) => {\r\n if (isTabBar) {\r\n // TabBar 页面不支持传参,使用 switchTab\r\n uni.switchTab({\r\n url: `/${path}`,\r\n success: () => {\r\n resolve({\r\n success: true,\r\n message: `已跳转到${getPageTitle(pageName)}`,\r\n url: `/${path}`\r\n });\r\n },\r\n fail: (err) => {\r\n console.error('页面跳转失败:', err);\r\n resolve({\r\n success: false,\r\n message: `跳转失败: ${err.errMsg || '未知错误'}`\r\n });\r\n }\r\n });\r\n } else {\r\n // 普通页面使用 navigateTo\r\n uni.navigateTo({\r\n url: url,\r\n success: () => {\r\n resolve({\r\n success: true,\r\n message: `已跳转到${getPageTitle(pageName)}`,\r\n url: url\r\n });\r\n },\r\n fail: (err) => {\r\n console.error('页面跳转失败:', err);\r\n // 尝试使用 redirectTo\r\n uni.redirectTo({\r\n url: url,\r\n success: () => {\r\n resolve({\r\n success: true,\r\n message: `已跳转到${getPageTitle(pageName)}`,\r\n url: url\r\n });\r\n },\r\n fail: (err2) => {\r\n resolve({\r\n success: false,\r\n message: `跳转失败: ${err2.errMsg || err.errMsg || '未知错误'}`\r\n });\r\n }\r\n });\r\n }\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * 获取页面标题\r\n * @param {string} pageName - 页面名称标识符\r\n * @returns {string} 页面标题\r\n */\r\nfunction getPageTitle(pageName) {\r\n const titleMap = {\r\n \"home\": \"首页\",\r\n \"login\": \"登录\",\r\n \"register\": \"注册\",\r\n \"select-hospital\": \"选择院区\",\r\n \"select-department\": \"选择科室\",\r\n \"select-doctor\": \"选择医生\",\r\n \"confirm-appointment\": \"确认预约\",\r\n \"payment\": \"支付\",\r\n \"appointment-success\": \"预约成功\",\r\n \"confirm-waitlist\": \"候补号源\",\r\n \"waitlist-success\": \"候补成功\",\r\n \"reschedule-select\": \"选择新的就诊时间\",\r\n \"reschedule-confirm\": \"确认改约\",\r\n \"profile\": \"个人中心\",\r\n \"appointments\": \"我的预约\",\r\n \"waitlist\": \"我的候补\",\r\n \"patients\": \"就诊人管理\",\r\n \"health\": \"健康档案\",\r\n \"health-basic-info\": \"编辑基本信息\",\r\n \"medical-record-detail\": \"病历详情\",\r\n \"verify-identity\": \"校内身份认证\",\r\n \"settings\": \"账号设置\",\r\n \"messages\": \"消息中心\",\r\n \"doctors\": \"科室专家\",\r\n \"ai-assistant\": \"AI就医助手\",\r\n \"feedback\": \"意见反馈\"\r\n };\r\n \r\n return titleMap[pageName] || pageName;\r\n}\r\n\r\n/**\r\n * 供 AI Tool Call 使用的导航函数\r\n * \r\n * 此函数将被 context-manager.js 调用,用于处理 AI 的导航请求。\r\n * \r\n * @param {Object} args - AI 传递的参数\r\n * @param {string} args.pageName - 目标页面名称\r\n * @param {Object} [args.params] - 页面参数\r\n * @returns {Promise<string>} JSON 格式的执行结果\r\n * \r\n * @example\r\n * // AI 调用示例\r\n * const result = await handleNavigateToolCall({\r\n * pageName: \"appointments\",\r\n * params: {}\r\n * });\r\n * // 返回: {\"success\": true, \"message\": \"已跳转到我的预约\"}\r\n */\r\nexport async function handleNavigateToolCall(args) {\r\n const { pageName, params = {} } = args;\r\n \r\n console.log(`🧭 导航工具调用: pageName=${pageName}, params=`, params);\r\n \r\n const result = await navigateToPage(pageName, params);\r\n \r\n console.log(`🧭 导航结果:`, result);\r\n \r\n return JSON.stringify(result);\r\n}\r\n\r\n// ============================================================================\r\n// 辅助函数 - 用于 AI 智能匹配\r\n// ============================================================================\r\n\r\n/**\r\n * 根据用户意图智能匹配最合适的页面\r\n * \r\n * 此函数可用于预处理用户输入,帮助 AI 更准确地选择目标页面。\r\n * \r\n * @param {string} userIntent - 用户意图描述\r\n * @returns {Object|null} 匹配到的页面信息,或 null\r\n * \r\n * @example\r\n * matchPageByIntent(\"我想预约挂号\")\r\n * // 返回: { pageName: \"select-hospital\", confidence: 0.9, ... }\r\n */\r\nexport function matchPageByIntent(userIntent) {\r\n if (!userIntent) return null;\r\n \r\n const lowerIntent = userIntent.toLowerCase();\r\n \r\n for (const route of PAGE_ROUTES) {\r\n for (const keyword of route.keywords) {\r\n if (lowerIntent.includes(keyword.toLowerCase())) {\r\n return {\r\n pageName: getPageNameFromPath(route.path),\r\n path: route.path,\r\n title: route.title,\r\n description: route.description,\r\n matchedKeyword: keyword\r\n };\r\n }\r\n }\r\n }\r\n \r\n return null;\r\n}\r\n\r\n/**\r\n * 从路径获取页面名称\r\n * @param {string} path - 页面路径\r\n * @returns {string|null} 页面名称\r\n */\r\nfunction getPageNameFromPath(path) {\r\n for (const [name, config] of Object.entries(PAGE_NAME_MAP)) {\r\n if (config.path === path) {\r\n return name;\r\n }\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 获取所有可用页面的简要列表\r\n * 供 AI 查询可用页面时使用\r\n * \r\n * @returns {string} JSON 格式的页面列表\r\n */\r\nexport function getAvailablePages() {\r\n const pages = Object.entries(PAGE_NAME_MAP).map(([name, config]) => ({\r\n name,\r\n title: getPageTitle(name),\r\n isTabBar: config.isTabBar\r\n }));\r\n \r\n return JSON.stringify({\r\n message: \"可用页面列表\",\r\n pages\r\n });\r\n}\r\n\r\n// ============================================================================\r\n// 导出默认对象\r\n// ============================================================================\r\n\r\nexport default {\r\n // Tool 定义\r\n NAVIGATE_TO_PAGE_TOOL,\r\n NAVIGATE_TO_PAGE_TOOL_STRICT,\r\n \r\n // 路由配置\r\n PAGE_ROUTES,\r\n \r\n // 核心函数\r\n navigateToPage,\r\n handleNavigateToolCall,\r\n \r\n // 辅助函数\r\n matchPageByIntent,\r\n getAvailablePages\r\n};\r\n\r\n"}, "0cfa7dac6c0c988b3fed77de233bf3940114b232": {"t": 1785766704.5340252, "n": 20640, "h": "a95ee1d3a13fbef5", "c": "/**\r\n * 页面路由跳转工具\r\n * \r\n * 此文件为 AI 助手提供页面导航能力,供 DeepSeek Tool Calls 模式使用。\r\n * \r\n * @description\r\n * 该工具允许 AI 根据用户意图,自动跳转到医院预约系统的各个功能页面。\r\n * AI 可以根据用户的自然语言描述,智能匹配并导航到相应的页面。\r\n * \r\n * @example\r\n * 用户说:\"我想预约挂号\" → AI 调用 navigateToPage({ pageName: \"select-hospital\" })\r\n * 用户说:\"查看我的预约\" → AI 调用 navigateToPage({ pageName: \"appointments\" })\r\n */\r\n\r\n// ============================================================================\r\n// 页面路由配置表\r\n// ============================================================================\r\n\r\n/**\r\n * 所有可用页面的路由配置\r\n * \r\n * @typedef {Object} PageRoute\r\n * @property {string} path - 页面路径(不含前导斜杠)\r\n * @property {string} title - 页面标题(导航栏显示)\r\n * @property {string} description - 页面功能描述,供 AI 理解页面用途\r\n * @property {string[]} keywords - 触发关键词,帮助 AI 匹配用户意图\r\n * @property {boolean} isTabBar - 是否为 TabBar 页面(需使用 switchTab 跳转)\r\n * @property {string[]} [requiredParams] - 必需的 URL 参数(可选)\r\n * @property {string[]} [optionalParams] - 可选的 URL 参数(可选)\r\n */\r\n\r\n/**\r\n * 完整的页面路由配置列表\r\n * @type {PageRoute[]}\r\n */\r\nexport const PAGE_ROUTES = [\r\n // ==================== 认证相关页面 ====================\r\n {\r\n path: \"pages/auth/login\",\r\n title: \"登录\",\r\n description: \"用户登录页面,使用手机号和密码登录系统\",\r\n keywords: [\"登录\", \"登陆\", \"sign in\", \"login\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/auth/register\",\r\n title: \"注册\",\r\n description: \"新用户注册页面,创建新账号\",\r\n keywords: [\"注册\", \"注冊\", \"sign up\", \"register\", \"新用户\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 首页(TabBar) ====================\r\n {\r\n path: \"pages/home/index\",\r\n title: \"首页\",\r\n description: \"应用首页,展示主要功能入口和快捷操作\",\r\n keywords: [\"首页\", \"主页\", \"home\", \"回首页\", \"返回首页\"],\r\n isTabBar: true\r\n },\r\n\r\n // ==================== 预约挂号流程 ====================\r\n {\r\n path: \"pages/home/appointment/select-hospital\",\r\n title: \"选择院区\",\r\n description: \"预约挂号第一步:选择就诊的院区/医院\",\r\n keywords: [\"预约\", \"挂号\", \"选择医院\", \"选择院区\", \"预约挂号\", \"我要预约\", \"我想挂号\", \"看病\"],\r\n isTabBar: false,\r\n optionalParams: [\"hospitalId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/select-department\",\r\n title: \"选择科室\",\r\n description: \"预约挂号第二步:选择就诊的科室\",\r\n keywords: [\"选择科室\", \"选科室\", \"哪个科室\", \"什么科\"],\r\n isTabBar: false,\r\n requiredParams: [\"hospitalId\"],\r\n optionalParams: [\"departmentId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/select-doctor\",\r\n title: \"选择医生\",\r\n description: \"预约挂号第三步:选择就诊的医生和时间段\",\r\n keywords: [\"选择医生\", \"选医生\", \"哪个医生\", \"找医生\", \"看哪个医生\"],\r\n isTabBar: false,\r\n requiredParams: [\"hospitalId\", \"departmentId\"],\r\n optionalParams: [\"doctorId\", \"date\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/confirm\",\r\n title: \"确认预约\",\r\n description: \"预约挂号第四步:确认预约信息,选择就诊人\",\r\n keywords: [\"确认预约\", \"确认挂号\", \"提交预约\"],\r\n isTabBar: false,\r\n requiredParams: [\"scheduleId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/payment\",\r\n title: \"支付\",\r\n description: \"预约挂号第五步:支付挂号费用\",\r\n keywords: [\"支付\", \"付款\", \"缴费\", \"付费\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/success\",\r\n title: \"预约成功\",\r\n description: \"预约成功页面,显示预约单详情\",\r\n keywords: [\"预约成功\", \"预约详情\", \"预约单\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\"]\r\n },\r\n\r\n // ==================== 候补功能 ====================\r\n {\r\n path: \"pages/home/waitlist/confirm-waitlist\",\r\n title: \"候补号源\",\r\n description: \"当没有可用号源时,可以申请候补排队\",\r\n keywords: [\"候补\", \"候补挂号\", \"排队等号\", \"没号了\", \"候补号源\"],\r\n isTabBar: false,\r\n requiredParams: [\"doctorId\", \"date\"]\r\n },\r\n {\r\n path: \"pages/home/waitlist/waitlist-success\",\r\n title: \"候补成功\",\r\n description: \"候补申请成功页面,显示候补单详情\",\r\n keywords: [\"候补成功\", \"候补详情\", \"候补单\"],\r\n isTabBar: false,\r\n requiredParams: [\"waitlistId\"]\r\n },\r\n\r\n // ==================== 改约功能 ====================\r\n {\r\n path: \"pages/home/reschedule/select-schedule\",\r\n title: \"选择新的就诊时间\",\r\n description: \"改约第一步:选择新的就诊日期和时间段\",\r\n keywords: [\"改约\", \"改时间\", \"改预约\", \"更改预约\", \"换时间\", \"重新预约时间\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\"]\r\n },\r\n {\r\n path: \"pages/home/reschedule/confirm\",\r\n title: \"确认改约\",\r\n description: \"改约第二步:确认新的预约信息\",\r\n keywords: [\"确认改约\", \"确认更改\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\", \"newScheduleId\"]\r\n },\r\n\r\n // ==================== 个人中心(TabBar) ====================\r\n {\r\n path: \"pages/profile/index\",\r\n title: \"个人中心\",\r\n description: \"个人中心页面,管理个人信息和查看各类记录\",\r\n keywords: [\"个人中心\", \"我的\", \"个人\", \"用户中心\", \"profile\"],\r\n isTabBar: true\r\n },\r\n\r\n // ==================== 我的预约和候补 ====================\r\n {\r\n path: \"pages/profile/appointments\",\r\n title: \"我的预约\",\r\n description: \"查看和管理我的所有预约记录\",\r\n keywords: [\"我的预约\", \"预约记录\", \"预约列表\", \"查看预约\", \"预约历史\", \"挂号记录\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/profile/waitlist\",\r\n title: \"我的候补\",\r\n description: \"查看和管理我的所有候补记录\",\r\n keywords: [\"我的候补\", \"候补记录\", \"候补列表\", \"查看候补\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 就诊人管理 ====================\r\n {\r\n path: \"pages/profile/patients\",\r\n title: \"就诊人管理\",\r\n description: \"添加、编辑和管理就诊人信息(可为家人预约)\",\r\n keywords: [\"就诊人\", \"就诊人管理\", \"添加就诊人\", \"家人\", \"患者管理\", \"绑定就诊人\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 健康档案 ====================\r\n {\r\n path: \"pages/profile/health/index\",\r\n title: \"健康档案\",\r\n description: \"查看个人健康档案,包括基本信息、病历和就诊记录\",\r\n keywords: [\"健康档案\", \"健康记录\", \"我的档案\", \"健康信息\", \"体检记录\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/profile/health/basic-info\",\r\n title: \"编辑基本信息\",\r\n description: \"编辑个人健康基本信息,如身高、体重、血型等\",\r\n keywords: [\"编辑基本信息\", \"修改信息\", \"健康信息编辑\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/profile/health/medical-record/detail\",\r\n title: \"病历详情\",\r\n description: \"查看某次就诊的详细病历记录\",\r\n keywords: [\"病历详情\", \"病历\", \"就诊记录详情\", \"看病记录\"],\r\n isTabBar: false,\r\n requiredParams: [\"recordId\"]\r\n },\r\n\r\n // ==================== 身份认证 ====================\r\n {\r\n path: \"pages/profile/verify-identity\",\r\n title: \"校内身份认证\",\r\n description: \"进行校内身份认证,绑定学号/工号\",\r\n keywords: [\"身份认证\", \"实名认证\", \"校内认证\", \"认证\", \"绑定学号\", \"验证身份\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 账号设置 ====================\r\n {\r\n path: \"pages/profile/settings\",\r\n title: \"账号设置\",\r\n description: \"账号设置页面,修改密码、退出登录等\",\r\n keywords: [\"设置\", \"账号设置\", \"修改密码\", \"账户设置\", \"系统设置\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 消息中心(TabBar) ====================\r\n {\r\n path: \"pages/message/index\",\r\n title: \"消息中心\",\r\n description: \"查看系统消息、预约提醒、候补通知等\",\r\n keywords: [\"消息\", \"消息中心\", \"通知\", \"提醒\", \"消息列表\"],\r\n isTabBar: true\r\n },\r\n\r\n // ==================== 其他功能 ====================\r\n {\r\n path: \"pages/features/doctors\",\r\n title: \"科室专家\",\r\n description: \"浏览和搜索所有科室的专家医生,查看医生简介、职称、专长等信息\",\r\n keywords: [\"科室专家\", \"专家\", \"医生列表\", \"找专家\", \"所有医生\", \"专家介绍\", \"医生详情\", \"看看有哪些医生\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/features/feedback\",\r\n title: \"意见反馈\",\r\n description: \"提交意见和建议,反馈问题\",\r\n keywords: [\"意见反馈\", \"反馈\", \"建议\", \"投诉\", \"问题反馈\", \"提意见\"],\r\n isTabBar: false\r\n }\r\n];\r\n\r\n// ============================================================================\r\n// DeepSeek Tool 定义\r\n// ============================================================================\r\n\r\n/**\r\n * 供 DeepSeek API 使用的 Tool 定义\r\n * \r\n * 此定义遵循 DeepSeek Tool Calls 规范,可直接添加到 tools 数组中。\r\n * \r\n * @example\r\n * const TOOLS = [\r\n * ...otherTools,\r\n * NAVIGATE_TO_PAGE_TOOL\r\n * ];\r\n */\r\nexport const NAVIGATE_TO_PAGE_TOOL = {\r\n type: \"function\",\r\n function: {\r\n name: \"navigateToPage\",\r\n description: `导航到医院预约系统的指定页面。根据用户的意图,跳转到相应的功能页面。\r\n\r\n可用页面及其用途:\r\n【预约挂号流程】\r\n- \"select-hospital\": 开始预约挂号,选择院区\r\n- \"select-department\": 选择就诊科室\r\n- \"select-doctor\": 选择医生和时间\r\n- \"confirm-appointment\": 确认预约信息\r\n- \"payment\": 支付挂号费\r\n- \"appointment-success\": 查看预约成功详情\r\n\r\n【候补功能】\r\n- \"confirm-waitlist\": 申请候补号源\r\n- \"waitlist-success\": 查看候补成功详情\r\n\r\n【改约功能】\r\n- \"reschedule-select\": 选择新的就诊时间\r\n- \"reschedule-confirm\": 确认改约\r\n\r\n【个人中心】\r\n- \"home\": 返回首页\r\n- \"profile\": 个人中心\r\n- \"appointments\": 查看我的预约记录\r\n- \"waitlist\": 查看我的候补记录\r\n- \"patients\": 就诊人管理\r\n- \"health\": 健康档案\r\n- \"settings\": 账号设置\r\n- \"verify-identity\": 身份认证\r\n\r\n【消息和其他】\r\n- \"messages\": 消息中心\r\n- \"doctors\": 浏览科室专家\r\n- \"feedback\": 意见反馈\r\n- \"login\": 登录页面\r\n- \"register\": 注册页面`,\r\n parameters: {\r\n type: \"object\",\r\n properties: {\r\n pageName: {\r\n type: \"string\",\r\n description: \"目标页面的名称标识符\",\r\n enum: [\r\n \"home\",\r\n \"login\",\r\n \"register\",\r\n \"select-hospital\",\r\n \"select-department\",\r\n \"select-doctor\",\r\n \"confirm-appointment\",\r\n \"payment\",\r\n \"appointment-success\",\r\n \"confirm-waitlist\",\r\n \"waitlist-success\",\r\n \"reschedule-select\",\r\n \"reschedule-confirm\",\r\n \"profile\",\r\n \"appointments\",\r\n \"waitlist\",\r\n \"patients\",\r\n \"health\",\r\n \"health-basic-info\",\r\n \"medical-record-detail\",\r\n \"verify-identity\",\r\n \"settings\",\r\n \"messages\",\r\n \"doctors\",\r\n \"ai-assistant\",\r\n \"feedback\"\r\n ]\r\n },\r\n params: {\r\n type: \"object\",\r\n description: \"传递给目标页面的参数(键值对形式)。例如:{\\\"doctorId\\\": \\\"123\\\", \\\"date\\\": \\\"2024-01-15\\\"}\",\r\n properties: {\r\n hospitalId: {\r\n type: \"string\",\r\n description: \"医院/院区ID\"\r\n },\r\n departmentId: {\r\n type: \"string\",\r\n description: \"科室ID\"\r\n },\r\n doctorId: {\r\n type: \"string\",\r\n description: \"医生ID\"\r\n },\r\n scheduleId: {\r\n type: \"string\",\r\n description: \"排班ID\"\r\n },\r\n appointmentId: {\r\n type: \"string\",\r\n description: \"预约ID\"\r\n },\r\n waitlistId: {\r\n type: \"string\",\r\n description: \"候补ID\"\r\n },\r\n recordId: {\r\n type: \"string\",\r\n description: \"病历记录ID\"\r\n },\r\n date: {\r\n type: \"string\",\r\n description: \"日期,格式:YYYY-MM-DD\"\r\n }\r\n }\r\n }\r\n },\r\n required: [\"pageName\"],\r\n additionalProperties: false\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * 严格模式下的 Tool 定义(Beta功能)\r\n * \r\n * 使用 strict 模式时,模型输出会严格遵循 JSON Schema 格式。\r\n * 需要设置 base_url=\"https://api.deepseek.com/beta\" 来启用。\r\n */\r\nexport const NAVIGATE_TO_PAGE_TOOL_STRICT = {\r\n type: \"function\",\r\n function: {\r\n name: \"navigateToPage\",\r\n strict: true,\r\n description: NAVIGATE_TO_PAGE_TOOL.function.description,\r\n parameters: {\r\n type: \"object\",\r\n properties: {\r\n pageName: {\r\n type: \"string\",\r\n description: \"目标页面的名称标识符\",\r\n enum: NAVIGATE_TO_PAGE_TOOL.function.parameters.properties.pageName.enum\r\n },\r\n params: {\r\n type: \"object\",\r\n description: \"传递给目标页面的参数\",\r\n properties: {\r\n hospitalId: { type: \"string\", description: \"医院/院区ID\" },\r\n departmentId: { type: \"string\", description: \"科室ID\" },\r\n doctorId: { type: \"string\", description: \"医生ID\" },\r\n scheduleId: { type: \"string\", description: \"排班ID\" },\r\n appointmentId: { type: \"string\", description: \"预约ID\" },\r\n waitlistId: { type: \"string\", description: \"候补ID\" },\r\n recordId: { type: \"string\", description: \"病历记录ID\" },\r\n date: { type: \"string\", description: \"日期,格式:YYYY-MM-DD\" }\r\n },\r\n required: [],\r\n additionalProperties: false\r\n }\r\n },\r\n required: [\"pageName\", \"params\"],\r\n additionalProperties: false\r\n }\r\n }\r\n};\r\n\r\n// ============================================================================\r\n// 页面名称到路径的映射\r\n// ============================================================================\r\n\r\n/**\r\n * 页面名称标识符到路由配置的映射表\r\n * @type {Object.<string, {path: string, isTabBar: boolean}>}\r\n */\r\nconst PAGE_NAME_MAP = {\r\n // 首页和认证\r\n \"home\": { path: \"pages/home/index\", isTabBar: true },\r\n \"login\": { path: \"pages/auth/login\", isTabBar: false },\r\n \"register\": { path: \"pages/auth/register\", isTabBar: false },\r\n \r\n // 预约挂号流程\r\n \"select-hospital\": { path: \"pages/home/appointment/select-hospital\", isTabBar: false },\r\n \"select-department\": { path: \"pages/home/appointment/select-department\", isTabBar: false },\r\n \"select-doctor\": { path: \"pages/home/appointment/select-doctor\", isTabBar: false },\r\n \"confirm-appointment\": { path: \"pages/home/appointment/confirm\", isTabBar: false },\r\n \"payment\": { path: \"pages/home/appointment/payment\", isTabBar: false },\r\n \"appointment-success\": { path: \"pages/home/appointment/success\", isTabBar: false },\r\n \r\n // 候补功能\r\n \"confirm-waitlist\": { path: \"pages/home/waitlist/confirm-waitlist\", isTabBar: false },\r\n \"waitlist-success\": { path: \"pages/home/waitlist/waitlist-success\", isTabBar: false },\r\n \r\n // 改约功能\r\n \"reschedule-select\": { path: \"pages/home/reschedule/select-schedule\", isTabBar: false },\r\n \"reschedule-confirm\": { path: \"pages/home/reschedule/confirm\", isTabBar: false },\r\n \r\n // 个人中心\r\n \"profile\": { path: \"pages/profile/index\", isTabBar: true },\r\n \"appointments\": { path: \"pages/profile/appointments\", isTabBar: false },\r\n \"waitlist\": { path: \"pages/profile/waitlist\", isTabBar: false },\r\n \"patients\": { path: \"pages/profile/patients\", isTabBar: false },\r\n \"health\": { path: \"pages/profile/health/index\", isTabBar: false },\r\n \"health-basic-info\": { path: \"pages/profile/health/basic-info\", isTabBar: false },\r\n \"medical-record-detail\": { path: \"pages/profile/health/medical-record/detail\", isTabBar: false },\r\n \"verify-identity\": { path: \"pages/profile/verify-identity\", isTabBar: false },\r\n \"settings\": { path: \"pages/profile/settings\", isTabBar: false },\r\n \r\n // 消息中心\r\n \"messages\": { path: \"pages/message/index\", isTabBar: true },\r\n \r\n // 其他功能\r\n \"doctors\": { path: \"pages/features/doctors\", isTabBar: false },\r\n \"ai-assistant\": { path: \"pages/features/ai-assistant\", isTabBar: false },\r\n \"feedback\": { path: \"pages/features/feedback\", isTabBar: false }\r\n};\r\n\r\n// ============================================================================\r\n// 导航函数\r\n// ============================================================================\r\n\r\n/**\r\n * 构建带查询参数的 URL\r\n * @param {string} basePath - 基础路径\r\n * @param {Object} params - 查询参数对象\r\n * @returns {string} 完整的 URL 路径\r\n */\r\nfunction buildUrl(basePath, params = {}) {\r\n const queryString = Object.entries(params)\r\n .filter(([, value]) => value !== undefined && value !== null && value !== '')\r\n .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)\r\n .join('&');\r\n \r\n return queryString ? `/${basePath}?${queryString}` : `/${basePath}`;\r\n}\r\n\r\n/**\r\n * 执行页面导航\r\n * \r\n * 根据页面类型自动选择正确的导航方式:\r\n * - TabBar 页面使用 uni.switchTab\r\n * - 普通页面使用 uni.navigateTo\r\n * \r\n * @param {string} pageName - 页面名称标识符\r\n * @param {Object} params - 页面参数\r\n * @returns {Promise<{success: boolean, message: string, url?: string}>}\r\n */\r\nexport async function navigateToPage(pageName, params = {}) {\r\n const pageConfig = PAGE_NAME_MAP[pageName];\r\n \r\n if (!pageConfig) {\r\n return {\r\n success: false,\r\n message: `未知的页面: \"${pageName}\"。请使用有效的页面名称。`,\r\n availablePages: Object.keys(PAGE_NAME_MAP)\r\n };\r\n }\r\n \r\n const { path, isTabBar } = pageConfig;\r\n const url = buildUrl(path, params);\r\n \r\n return new Promise((resolve) => {\r\n if (isTabBar) {\r\n // TabBar 页面不支持传参,使用 switchTab\r\n uni.switchTab({\r\n url: `/${path}`,\r\n success: () => {\r\n resolve({\r\n success: true,\r\n message: `已跳转到${getPageTitle(pageName)}`,\r\n url: `/${path}`\r\n });\r\n },\r\n fail: (err) => {\r\n console.error('页面跳转失败:', err);\r\n resolve({\r\n success: false,\r\n message: `跳转失败: ${err.errMsg || '未知错误'}`\r\n });\r\n }\r\n });\r\n } else {\r\n // 普通页面使用 navigateTo\r\n uni.navigateTo({\r\n url: url,\r\n success: () => {\r\n resolve({\r\n success: true,\r\n message: `已跳转到${getPageTitle(pageName)}`,\r\n url: url\r\n });\r\n },\r\n fail: (err) => {\r\n console.error('页面跳转失败:', err);\r\n // 尝试使用 redirectTo\r\n uni.redirectTo({\r\n url: url,\r\n success: () => {\r\n resolve({\r\n success: true,\r\n message: `已跳转到${getPageTitle(pageName)}`,\r\n url: url\r\n });\r\n },\r\n fail: (err2) => {\r\n resolve({\r\n success: false,\r\n message: `跳转失败: ${err2.errMsg || err.errMsg || '未知错误'}`\r\n });\r\n }\r\n });\r\n }\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * 获取页面标题\r\n * @param {string} pageName - 页面名称标识符\r\n * @returns {string} 页面标题\r\n */\r\nfunction getPageTitle(pageName) {\r\n const titleMap = {\r\n \"home\": \"首页\",\r\n \"login\": \"登录\",\r\n \"register\": \"注册\",\r\n \"select-hospital\": \"选择院区\",\r\n \"select-department\": \"选择科室\",\r\n \"select-doctor\": \"选择医生\",\r\n \"confirm-appointment\": \"确认预约\",\r\n \"payment\": \"支付\",\r\n \"appointment-success\": \"预约成功\",\r\n \"confirm-waitlist\": \"候补号源\",\r\n \"waitlist-success\": \"候补成功\",\r\n \"reschedule-select\": \"选择新的就诊时间\",\r\n \"reschedule-confirm\": \"确认改约\",\r\n \"profile\": \"个人中心\",\r\n \"appointments\": \"我的预约\",\r\n \"waitlist\": \"我的候补\",\r\n \"patients\": \"就诊人管理\",\r\n \"health\": \"健康档案\",\r\n \"health-basic-info\": \"编辑基本信息\",\r\n \"medical-record-detail\": \"病历详情\",\r\n \"verify-identity\": \"校内身份认证\",\r\n \"settings\": \"账号设置\",\r\n \"messages\": \"消息中心\",\r\n \"doctors\": \"科室专家\",\r\n \"ai-assistant\": \"AI就医助手\",\r\n \"feedback\": \"意见反馈\"\r\n };\r\n \r\n return titleMap[pageName] || pageName;\r\n}\r\n\r\n/**\r\n * 供 AI Tool Call 使用的导航函数\r\n * \r\n * 此函数将被 context-manager.js 调用,用于处理 AI 的导航请求。\r\n * \r\n * @param {Object} args - AI 传递的参数\r\n * @param {string} args.pageName - 目标页面名称\r\n * @param {Object} [args.params] - 页面参数\r\n * @returns {Promise<string>} JSON 格式的执行结果\r\n * \r\n * @example\r\n * // AI 调用示例\r\n * const result = await handleNavigateToolCall({\r\n * pageName: \"appointments\",\r\n * params: {}\r\n * });\r\n * // 返回: {\"success\": true, \"message\": \"已跳转到我的预约\"}\r\n */\r\nexport async function handleNavigateToolCall(args) {\r\n const { pageName, params = {} } = args;\r\n \r\n console.log(`🧭 导航工具调用: pageName=${pageName}, params=`, params);\r\n \r\n const result = await navigateToPage(pageName, params);\r\n \r\n console.log(`🧭 导航结果:`, result);\r\n \r\n return JSON.stringify(result);\r\n}\r\n\r\n// ============================================================================\r\n// 辅助函数 - 用于 AI 智能匹配\r\n// ============================================================================\r\n\r\n/**\r\n * 根据用户意图智能匹配最合适的页面\r\n * \r\n * 此函数可用于预处理用户输入,帮助 AI 更准确地选择目标页面。\r\n * \r\n * @param {string} userIntent - 用户意图描述\r\n * @returns {Object|null} 匹配到的页面信息,或 null\r\n * \r\n * @example\r\n * matchPageByIntent(\"我想预约挂号\")\r\n * // 返回: { pageName: \"select-hospital\", confidence: 0.9, ... }\r\n */\r\nexport function matchPageByIntent(userIntent) {\r\n if (!userIntent) return null;\r\n \r\n const lowerIntent = userIntent.toLowerCase();\r\n \r\n for (const route of PAGE_ROUTES) {\r\n for (const keyword of route.keywords) {\r\n if (lowerIntent.includes(keyword.toLowerCase())) {\r\n return {\r\n pageName: getPageNameFromPath(route.path),\r\n path: route.path,\r\n title: route.title,\r\n description: route.description,\r\n matchedKeyword: keyword\r\n };\r\n }\r\n }\r\n }\r\n \r\n return null;\r\n}\r\n\r\n/**\r\n * 从路径获取页面名称\r\n * @param {string} path - 页面路径\r\n * @returns {string|null} 页面名称\r\n */\r\nfunction getPageNameFromPath(path) {\r\n for (const [name, config] of Object.entries(PAGE_NAME_MAP)) {\r\n if (config.path === path) {\r\n return name;\r\n }\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 获取所有可用页面的简要列表\r\n * 供 AI 查询可用页面时使用\r\n * \r\n * @returns {string} JSON 格式的页面列表\r\n */\r\nexport function getAvailablePages() {\r\n const pages = Object.entries(PAGE_NAME_MAP).map(([name, config]) => ({\r\n name,\r\n title: getPageTitle(name),\r\n isTabBar: config.isTabBar\r\n }));\r\n \r\n return JSON.stringify({\r\n message: \"可用页面列表\",\r\n pages\r\n });\r\n}\r\n\r\n// ============================================================================\r\n// 导出默认对象\r\n// ============================================================================\r\n\r\nexport default {\r\n // Tool 定义\r\n NAVIGATE_TO_PAGE_TOOL,\r\n NAVIGATE_TO_PAGE_TOOL_STRICT,\r\n \r\n // 路由配置\r\n PAGE_ROUTES,\r\n \r\n // 核心函数\r\n navigateToPage,\r\n handleNavigateToolCall,\r\n \r\n // 辅助函数\r\n matchPageByIntent,\r\n getAvailablePages\r\n};\r\n\r\n"}, "7e22c1c16c26ffefc03f1eada14659fc62e2795e": {"t": 1785766706.3333051, "n": 20803, "h": "201cc6110a52514d", "c": "/**\r\n * 页面路由跳转工具\r\n * \r\n * 此文件为 AI 助手提供页面导航能力,供 DeepSeek Tool Calls 模式使用。\r\n * \r\n * @description\r\n * 该工具允许 AI 根据用户意图,自动跳转到医院预约系统的各个功能页面。\r\n * AI 可以根据用户的自然语言描述,智能匹配并导航到相应的页面。\r\n * \r\n * @example\r\n * 用户说:\"我想预约挂号\" → AI 调用 navigateToPage({ pageName: \"select-hospital\" })\r\n * 用户说:\"查看我的预约\" → AI 调用 navigateToPage({ pageName: \"appointments\" })\r\n */\r\n\r\n// ============================================================================\r\n// 页面路由配置表\r\n// ============================================================================\r\n\r\n/**\r\n * 所有可用页面的路由配置\r\n * \r\n * @typedef {Object} PageRoute\r\n * @property {string} path - 页面路径(不含前导斜杠)\r\n * @property {string} title - 页面标题(导航栏显示)\r\n * @property {string} description - 页面功能描述,供 AI 理解页面用途\r\n * @property {string[]} keywords - 触发关键词,帮助 AI 匹配用户意图\r\n * @property {boolean} isTabBar - 是否为 TabBar 页面(需使用 switchTab 跳转)\r\n * @property {string[]} [requiredParams] - 必需的 URL 参数(可选)\r\n * @property {string[]} [optionalParams] - 可选的 URL 参数(可选)\r\n */\r\n\r\n/**\r\n * 完整的页面路由配置列表\r\n * @type {PageRoute[]}\r\n */\r\nexport const PAGE_ROUTES = [\r\n // ==================== 认证相关页面 ====================\r\n {\r\n path: \"pages/auth/login\",\r\n title: \"登录\",\r\n description: \"用户登录页面,使用手机号和密码登录系统\",\r\n keywords: [\"登录\", \"登陆\", \"sign in\", \"login\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/auth/register\",\r\n title: \"注册\",\r\n description: \"新用户注册页面,创建新账号\",\r\n keywords: [\"注册\", \"注冊\", \"sign up\", \"register\", \"新用户\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 首页(TabBar) ====================\r\n {\r\n path: \"pages/home/index\",\r\n title: \"首页\",\r\n description: \"应用首页,展示主要功能入口和快捷操作\",\r\n keywords: [\"首页\", \"主页\", \"home\", \"回首页\", \"返回首页\"],\r\n isTabBar: true\r\n },\r\n\r\n // ==================== 预约挂号流程 ====================\r\n {\r\n path: \"pages/home/appointment/select-hospital\",\r\n title: \"选择院区\",\r\n description: \"预约挂号第一步:选择就诊的院区/医院\",\r\n keywords: [\"预约\", \"挂号\", \"选择医院\", \"选择院区\", \"预约挂号\", \"我要预约\", \"我想挂号\", \"看病\"],\r\n isTabBar: false,\r\n optionalParams: [\"hospitalId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/select-department\",\r\n title: \"选择科室\",\r\n description: \"预约挂号第二步:选择就诊的科室\",\r\n keywords: [\"选择科室\", \"选科室\", \"哪个科室\", \"什么科\"],\r\n isTabBar: false,\r\n requiredParams: [\"hospitalId\"],\r\n optionalParams: [\"departmentId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/select-doctor\",\r\n title: \"选择医生\",\r\n description: \"预约挂号第三步:选择就诊的医生和时间段\",\r\n keywords: [\"选择医生\", \"选医生\", \"哪个医生\", \"找医生\", \"看哪个医生\"],\r\n isTabBar: false,\r\n requiredParams: [\"hospitalId\", \"departmentId\"],\r\n optionalParams: [\"doctorId\", \"date\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/confirm\",\r\n title: \"确认预约\",\r\n description: \"预约挂号第四步:确认预约信息,选择就诊人\",\r\n keywords: [\"确认预约\", \"确认挂号\", \"提交预约\"],\r\n isTabBar: false,\r\n requiredParams: [\"scheduleId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/payment\",\r\n title: \"支付\",\r\n description: \"预约挂号第五步:支付挂号费用\",\r\n keywords: [\"支付\", \"付款\", \"缴费\", \"付费\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\"]\r\n },\r\n {\r\n path: \"pages/home/appointment/success\",\r\n title: \"预约成功\",\r\n description: \"预约成功页面,显示预约单详情\",\r\n keywords: [\"预约成功\", \"预约详情\", \"预约单\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\"]\r\n },\r\n\r\n // ==================== 候补功能 ====================\r\n {\r\n path: \"pages/home/waitlist/confirm-waitlist\",\r\n title: \"候补号源\",\r\n description: \"当没有可用号源时,可以申请候补排队\",\r\n keywords: [\"候补\", \"候补挂号\", \"排队等号\", \"没号了\", \"候补号源\"],\r\n isTabBar: false,\r\n requiredParams: [\"doctorId\", \"date\"]\r\n },\r\n {\r\n path: \"pages/home/waitlist/waitlist-success\",\r\n title: \"候补成功\",\r\n description: \"候补申请成功页面,显示候补单详情\",\r\n keywords: [\"候补成功\", \"候补详情\", \"候补单\"],\r\n isTabBar: false,\r\n requiredParams: [\"waitlistId\"]\r\n },\r\n\r\n // ==================== 改约功能 ====================\r\n {\r\n path: \"pages/home/reschedule/select-schedule\",\r\n title: \"选择新的就诊时间\",\r\n description: \"改约第一步:选择新的就诊日期和时间段\",\r\n keywords: [\"改约\", \"改时间\", \"改预约\", \"更改预约\", \"换时间\", \"重新预约时间\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\"]\r\n },\r\n {\r\n path: \"pages/home/reschedule/confirm\",\r\n title: \"确认改约\",\r\n description: \"改约第二步:确认新的预约信息\",\r\n keywords: [\"确认改约\", \"确认更改\"],\r\n isTabBar: false,\r\n requiredParams: [\"appointmentId\", \"newScheduleId\"]\r\n },\r\n\r\n // ==================== 个人中心(TabBar) ====================\r\n {\r\n path: \"pages/profile/index\",\r\n title: \"个人中心\",\r\n description: \"个人中心页面,管理个人信息和查看各类记录\",\r\n keywords: [\"个人中心\", \"我的\", \"个人\", \"用户中心\", \"profile\"],\r\n isTabBar: true\r\n },\r\n\r\n // ==================== 我的预约和候补 ====================\r\n {\r\n path: \"pages/profile/appointments\",\r\n title: \"我的预约\",\r\n description: \"查看和管理我的所有预约记录\",\r\n keywords: [\"我的预约\", \"预约记录\", \"预约列表\", \"查看预约\", \"预约历史\", \"挂号记录\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/profile/waitlist\",\r\n title: \"我的候补\",\r\n description: \"查看和管理我的所有候补记录\",\r\n keywords: [\"我的候补\", \"候补记录\", \"候补列表\", \"查看候补\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 就诊人管理 ====================\r\n {\r\n path: \"pages/profile/patients\",\r\n title: \"就诊人管理\",\r\n description: \"添加、编辑和管理就诊人信息(可为家人预约)\",\r\n keywords: [\"就诊人\", \"就诊人管理\", \"添加就诊人\", \"家人\", \"患者管理\", \"绑定就诊人\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 健康档案 ====================\r\n {\r\n path: \"pages/profile/health/index\",\r\n title: \"健康档案\",\r\n description: \"查看个人健康档案,包括基本信息、病历和就诊记录\",\r\n keywords: [\"健康档案\", \"健康记录\", \"我的档案\", \"健康信息\", \"体检记录\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/profile/health/basic-info\",\r\n title: \"编辑基本信息\",\r\n description: \"编辑个人健康基本信息,如身高、体重、血型等\",\r\n keywords: [\"编辑基本信息\", \"修改信息\", \"健康信息编辑\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/profile/health/medical-record/detail\",\r\n title: \"病历详情\",\r\n description: \"查看某次就诊的详细病历记录\",\r\n keywords: [\"病历详情\", \"病历\", \"就诊记录详情\", \"看病记录\"],\r\n isTabBar: false,\r\n requiredParams: [\"recordId\"]\r\n },\r\n\r\n // ==================== 身份认证 ====================\r\n {\r\n path: \"pages/profile/verify-identity\",\r\n title: \"校内身份认证\",\r\n description: \"进行校内身份认证,绑定学号/工号\",\r\n keywords: [\"身份认证\", \"实名认证\", \"校内认证\", \"认证\", \"绑定学号\", \"验证身份\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 账号设置 ====================\r\n {\r\n path: \"pages/profile/settings\",\r\n title: \"账号设置\",\r\n description: \"账号设置页面,修改密码、退出登录等\",\r\n keywords: [\"设置\", \"账号设置\", \"修改密码\", \"账户设置\", \"系统设置\"],\r\n isTabBar: false\r\n },\r\n\r\n // ==================== 消息中心(TabBar) ====================\r\n {\r\n path: \"pages/message/index\",\r\n title: \"消息中心\",\r\n description: \"查看系统消息、预约提醒、候补通知等\",\r\n keywords: [\"消息\", \"消息中心\", \"通知\", \"提醒\", \"消息列表\"],\r\n isTabBar: true\r\n },\r\n\r\n // ==================== 其他功能 ====================\r\n {\r\n path: \"pages/features/doctors\",\r\n title: \"科室专家\",\r\n description: \"浏览和搜索所有科室的专家医生\",\r\n keywords: [\"科室专家\", \"专家\", \"医生列表\", \"找专家\", \"所有医生\", \"专家介绍\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/features/ai-assistant\",\r\n title: \"AI就医助手\",\r\n description: \"AI智能助手,帮助解答就医相关问题\",\r\n keywords: [\"AI助手\", \"智能助手\", \"就医助手\", \"AI\", \"人工智能\", \"智能问诊\"],\r\n isTabBar: false\r\n },\r\n {\r\n path: \"pages/features/feedback\",\r\n title: \"意见反馈\",\r\n description: \"提交意见和建议,反馈问题\",\r\n keywords: [\"意见反馈\", \"反馈\", \"建议\", \"投诉\", \"问题反馈\", \"提意见\"],\r\n isTabBar: false\r\n }\r\n];\r\n\r\n// ============================================================================\r\n// DeepSeek Tool 定义\r\n// ============================================================================\r\n\r\n/**\r\n * 供 DeepSeek API 使用的 Tool 定义\r\n * \r\n * 此定义遵循 DeepSeek Tool Calls 规范,可直接添加到 tools 数组中。\r\n * \r\n * @example\r\n * const TOOLS = [\r\n * ...otherTools,\r\n * NAVIGATE_TO_PAGE_TOOL\r\n * ];\r\n */\r\nexport const NAVIGATE_TO_PAGE_TOOL = {\r\n type: \"function\",\r\n function: {\r\n name: \"navigateToPage\",\r\n description: `导航到医院预约系统的指定页面。根据用户的意图,跳转到相应的功能页面。\r\n\r\n可用页面及其用途:\r\n【预约挂号流程】\r\n- \"select-hospital\": 开始预约挂号,选择院区\r\n- \"select-department\": 选择就诊科室\r\n- \"select-doctor\": 选择医生和时间\r\n- \"confirm-appointment\": 确认预约信息\r\n- \"payment\": 支付挂号费\r\n- \"appointment-success\": 查看预约成功详情\r\n\r\n【候补功能】\r\n- \"confirm-waitlist\": 申请候补号源\r\n- \"waitlist-success\": 查看候补成功详情\r\n\r\n【改约功能】\r\n- \"reschedule-select\": 选择新的就诊时间\r\n- \"reschedule-confirm\": 确认改约\r\n\r\n【个人中心】\r\n- \"home\": 返回首页\r\n- \"profile\": 个人中心\r\n- \"appointments\": 查看我的预约记录\r\n- \"waitlist\": 查看我的候补记录\r\n- \"patients\": 就诊人管理\r\n- \"health\": 健康档案\r\n- \"settings\": 账号设置\r\n- \"verify-identity\": 身份认证\r\n\r\n【消息和其他】\r\n- \"messages\": 消息中心\r\n- \"doctors\": 浏览科室专家\r\n- \"feedback\": 意见反馈\r\n- \"login\": 登录页面\r\n- \"register\": 注册页面`,\r\n parameters: {\r\n type: \"object\",\r\n properties: {\r\n pageName: {\r\n type: \"string\",\r\n description: \"目标页面的名称标识符\",\r\n enum: [\r\n \"home\",\r\n \"login\",\r\n \"register\",\r\n \"select-hospital\",\r\n \"select-department\",\r\n \"select-doctor\",\r\n \"confirm-appointment\",\r\n \"payment\",\r\n \"appointment-success\",\r\n \"confirm-waitlist\",\r\n \"waitlist-success\",\r\n \"reschedule-select\",\r\n \"reschedule-confirm\",\r\n \"profile\",\r\n \"appointments\",\r\n \"waitlist\",\r\n \"patients\",\r\n \"health\",\r\n \"health-basic-info\",\r\n \"medical-record-detail\",\r\n \"verify-identity\",\r\n \"settings\",\r\n \"messages\",\r\n \"doctors\",\r\n \"ai-assistant\",\r\n \"feedback\"\r\n ]\r\n },\r\n params: {\r\n type: \"object\",\r\n description: \"传递给目标页面的参数(键值对形式)。例如:{\\\"doctorId\\\": \\\"123\\\", \\\"date\\\": \\\"2024-01-15\\\"}\",\r\n properties: {\r\n hospitalId: {\r\n type: \"string\",\r\n description: \"医院/院区ID\"\r\n },\r\n departmentId: {\r\n type: \"string\",\r\n description: \"科室ID\"\r\n },\r\n doctorId: {\r\n type: \"string\",\r\n description: \"医生ID\"\r\n },\r\n scheduleId: {\r\n type: \"string\",\r\n description: \"排班ID\"\r\n },\r\n appointmentId: {\r\n type: \"string\",\r\n description: \"预约ID\"\r\n },\r\n waitlistId: {\r\n type: \"string\",\r\n description: \"候补ID\"\r\n },\r\n recordId: {\r\n type: \"string\",\r\n description: \"病历记录ID\"\r\n },\r\n date: {\r\n type: \"string\",\r\n description: \"日期,格式:YYYY-MM-DD\"\r\n }\r\n }\r\n }\r\n },\r\n required: [\"pageName\"],\r\n additionalProperties: false\r\n }\r\n }\r\n};\r\n\r\n/**\r\n * 严格模式下的 Tool 定义(Beta功能)\r\n * \r\n * 使用 strict 模式时,模型输出会严格遵循 JSON Schema 格式。\r\n * 需要设置 base_url=\"https://api.deepseek.com/beta\" 来启用。\r\n */\r\nexport const NAVIGATE_TO_PAGE_TOOL_STRICT = {\r\n type: \"function\",\r\n function: {\r\n name: \"navigateToPage\",\r\n strict: true,\r\n description: NAVIGATE_TO_PAGE_TOOL.function.description,\r\n parameters: {\r\n type: \"object\",\r\n properties: {\r\n pageName: {\r\n type: \"string\",\r\n description: \"目标页面的名称标识符\",\r\n enum: NAVIGATE_TO_PAGE_TOOL.function.parameters.properties.pageName.enum\r\n },\r\n params: {\r\n type: \"object\",\r\n description: \"传递给目标页面的参数\",\r\n properties: {\r\n hospitalId: { type: \"string\", description: \"医院/院区ID\" },\r\n departmentId: { type: \"string\", description: \"科室ID\" },\r\n doctorId: { type: \"string\", description: \"医生ID\" },\r\n scheduleId: { type: \"string\", description: \"排班ID\" },\r\n appointmentId: { type: \"string\", description: \"预约ID\" },\r\n waitlistId: { type: \"string\", description: \"候补ID\" },\r\n recordId: { type: \"string\", description: \"病历记录ID\" },\r\n date: { type: \"string\", description: \"日期,格式:YYYY-MM-DD\" }\r\n },\r\n required: [],\r\n additionalProperties: false\r\n }\r\n },\r\n required: [\"pageName\", \"params\"],\r\n additionalProperties: false\r\n }\r\n }\r\n};\r\n\r\n// ============================================================================\r\n// 页面名称到路径的映射\r\n// ============================================================================\r\n\r\n/**\r\n * 页面名称标识符到路由配置的映射表\r\n * @type {Object.<string, {path: string, isTabBar: boolean}>}\r\n */\r\nconst PAGE_NAME_MAP = {\r\n // 首页和认证\r\n \"home\": { path: \"pages/home/index\", isTabBar: true },\r\n \"login\": { path: \"pages/auth/login\", isTabBar: false },\r\n \"register\": { path: \"pages/auth/register\", isTabBar: false },\r\n \r\n // 预约挂号流程\r\n \"select-hospital\": { path: \"pages/home/appointment/select-hospital\", isTabBar: false },\r\n \"select-department\": { path: \"pages/home/appointment/select-department\", isTabBar: false },\r\n \"select-doctor\": { path: \"pages/home/appointment/select-doctor\", isTabBar: false },\r\n \"confirm-appointment\": { path: \"pages/home/appointment/confirm\", isTabBar: false },\r\n \"payment\": { path: \"pages/home/appointment/payment\", isTabBar: false },\r\n \"appointment-success\": { path: \"pages/home/appointment/success\", isTabBar: false },\r\n \r\n // 候补功能\r\n \"confirm-waitlist\": { path: \"pages/home/waitlist/confirm-waitlist\", isTabBar: false },\r\n \"waitlist-success\": { path: \"pages/home/waitlist/waitlist-success\", isTabBar: false },\r\n \r\n // 改约功能\r\n \"reschedule-select\": { path: \"pages/home/reschedule/select-schedule\", isTabBar: false },\r\n \"reschedule-confirm\": { path: \"pages/home/reschedule/confirm\", isTabBar: false },\r\n \r\n // 个人中心\r\n \"profile\": { path: \"pages/profile/index\", isTabBar: true },\r\n \"appointments\": { path: \"pages/profile/appointments\", isTabBar: false },\r\n \"waitlist\": { path: \"pages/profile/waitlist\", isTabBar: false },\r\n \"patients\": { path: \"pages/profile/patients\", isTabBar: false },\r\n \"health\": { path: \"pages/profile/health/index\", isTabBar: false },\r\n \"health-basic-info\": { path: \"pages/profile/health/basic-info\", isTabBar: false },\r\n \"medical-record-detail\": { path: \"pages/profile/health/medical-record/detail\", isTabBar: false },\r\n \"verify-identity\": { path: \"pages/profile/verify-identity\", isTabBar: false },\r\n \"settings\": { path: \"pages/profile/settings\", isTabBar: false },\r\n \r\n // 消息中心\r\n \"messages\": { path: \"pages/message/index\", isTabBar: true },\r\n \r\n // 其他功能\r\n \"doctors\": { path: \"pages/features/doctors\", isTabBar: false },\r\n \"ai-assistant\": { path: \"pages/features/ai-assistant\", isTabBar: false },\r\n \"feedback\": { path: \"pages/features/feedback\", isTabBar: false }\r\n};\r\n\r\n// ============================================================================\r\n// 导航函数\r\n// ============================================================================\r\n\r\n/**\r\n * 构建带查询参数的 URL\r\n * @param {string} basePath - 基础路径\r\n * @param {Object} params - 查询参数对象\r\n * @returns {string} 完整的 URL 路径\r\n */\r\nfunction buildUrl(basePath, params = {}) {\r\n const queryString = Object.entries(params)\r\n .filter(([, value]) => value !== undefined && value !== null && value !== '')\r\n .map(([key, value]) => `${key}=${encodeURIComponent(value)}`)\r\n .join('&');\r\n \r\n return queryString ? `/${basePath}?${queryString}` : `/${basePath}`;\r\n}\r\n\r\n/**\r\n * 执行页面导航\r\n * \r\n * 根据页面类型自动选择正确的导航方式:\r\n * - TabBar 页面使用 uni.switchTab\r\n * - 普通页面使用 uni.navigateTo\r\n * \r\n * @param {string} pageName - 页面名称标识符\r\n * @param {Object} params - 页面参数\r\n * @returns {Promise<{success: boolean, message: string, url?: string}>}\r\n */\r\nexport async function navigateToPage(pageName, params = {}) {\r\n const pageConfig = PAGE_NAME_MAP[pageName];\r\n \r\n if (!pageConfig) {\r\n return {\r\n success: false,\r\n message: `未知的页面: \"${pageName}\"。请使用有效的页面名称。`,\r\n availablePages: Object.keys(PAGE_NAME_MAP)\r\n };\r\n }\r\n \r\n const { path, isTabBar } = pageConfig;\r\n const url = buildUrl(path, params);\r\n \r\n return new Promise((resolve) => {\r\n if (isTabBar) {\r\n // TabBar 页面不支持传参,使用 switchTab\r\n uni.switchTab({\r\n url: `/${path}`,\r\n success: () => {\r\n resolve({\r\n success: true,\r\n message: `已跳转到${getPageTitle(pageName)}`,\r\n url: `/${path}`\r\n });\r\n },\r\n fail: (err) => {\r\n console.error('页面跳转失败:', err);\r\n resolve({\r\n success: false,\r\n message: `跳转失败: ${err.errMsg || '未知错误'}`\r\n });\r\n }\r\n });\r\n } else {\r\n // 普通页面使用 navigateTo\r\n uni.navigateTo({\r\n url: url,\r\n success: () => {\r\n resolve({\r\n success: true,\r\n message: `已跳转到${getPageTitle(pageName)}`,\r\n url: url\r\n });\r\n },\r\n fail: (err) => {\r\n console.error('页面跳转失败:', err);\r\n // 尝试使用 redirectTo\r\n uni.redirectTo({\r\n url: url,\r\n success: () => {\r\n resolve({\r\n success: true,\r\n message: `已跳转到${getPageTitle(pageName)}`,\r\n url: url\r\n });\r\n },\r\n fail: (err2) => {\r\n resolve({\r\n success: false,\r\n message: `跳转失败: ${err2.errMsg || err.errMsg || '未知错误'}`\r\n });\r\n }\r\n });\r\n }\r\n });\r\n }\r\n });\r\n}\r\n\r\n/**\r\n * 获取页面标题\r\n * @param {string} pageName - 页面名称标识符\r\n * @returns {string} 页面标题\r\n */\r\nfunction getPageTitle(pageName) {\r\n const titleMap = {\r\n \"home\": \"首页\",\r\n \"login\": \"登录\",\r\n \"register\": \"注册\",\r\n \"select-hospital\": \"选择院区\",\r\n \"select-department\": \"选择科室\",\r\n \"select-doctor\": \"选择医生\",\r\n \"confirm-appointment\": \"确认预约\",\r\n \"payment\": \"支付\",\r\n \"appointment-success\": \"预约成功\",\r\n \"confirm-waitlist\": \"候补号源\",\r\n \"waitlist-success\": \"候补成功\",\r\n \"reschedule-select\": \"选择新的就诊时间\",\r\n \"reschedule-confirm\": \"确认改约\",\r\n \"profile\": \"个人中心\",\r\n \"appointments\": \"我的预约\",\r\n \"waitlist\": \"我的候补\",\r\n \"patients\": \"就诊人管理\",\r\n \"health\": \"健康档案\",\r\n \"health-basic-info\": \"编辑基本信息\",\r\n \"medical-record-detail\": \"病历详情\",\r\n \"verify-identity\": \"校内身份认证\",\r\n \"settings\": \"账号设置\",\r\n \"messages\": \"消息中心\",\r\n \"doctors\": \"科室专家\",\r\n \"ai-assistant\": \"AI就医助手\",\r\n \"feedback\": \"意见反馈\"\r\n };\r\n \r\n return titleMap[pageName] || pageName;\r\n}\r\n\r\n/**\r\n * 供 AI Tool Call 使用的导航函数\r\n * \r\n * 此函数将被 context-manager.js 调用,用于处理 AI 的导航请求。\r\n * \r\n * @param {Object} args - AI 传递的参数\r\n * @param {string} args.pageName - 目标页面名称\r\n * @param {Object} [args.params] - 页面参数\r\n * @returns {Promise<string>} JSON 格式的执行结果\r\n * \r\n * @example\r\n * // AI 调用示例\r\n * const result = await handleNavigateToolCall({\r\n * pageName: \"appointments\",\r\n * params: {}\r\n * });\r\n * // 返回: {\"success\": true, \"message\": \"已跳转到我的预约\"}\r\n */\r\nexport async function handleNavigateToolCall(args) {\r\n const { pageName, params = {} } = args;\r\n \r\n console.log(`🧭 导航工具调用: pageName=${pageName}, params=`, params);\r\n \r\n const result = await navigateToPage(pageName, params);\r\n \r\n console.log(`🧭 导航结果:`, result);\r\n \r\n return JSON.stringify(result);\r\n}\r\n\r\n// ============================================================================\r\n// 辅助函数 - 用于 AI 智能匹配\r\n// ============================================================================\r\n\r\n/**\r\n * 根据用户意图智能匹配最合适的页面\r\n * \r\n * 此函数可用于预处理用户输入,帮助 AI 更准确地选择目标页面。\r\n * \r\n * @param {string} userIntent - 用户意图描述\r\n * @returns {Object|null} 匹配到的页面信息,或 null\r\n * \r\n * @example\r\n * matchPageByIntent(\"我想预约挂号\")\r\n * // 返回: { pageName: \"select-hospital\", confidence: 0.9, ... }\r\n */\r\nexport function matchPageByIntent(userIntent) {\r\n if (!userIntent) return null;\r\n \r\n const lowerIntent = userIntent.toLowerCase();\r\n \r\n for (const route of PAGE_ROUTES) {\r\n for (const keyword of route.keywords) {\r\n if (lowerIntent.includes(keyword.toLowerCase())) {\r\n return {\r\n pageName: getPageNameFromPath(route.path),\r\n path: route.path,\r\n title: route.title,\r\n description: route.description,\r\n matchedKeyword: keyword\r\n };\r\n }\r\n }\r\n }\r\n \r\n return null;\r\n}\r\n\r\n/**\r\n * 从路径获取页面名称\r\n * @param {string} path - 页面路径\r\n * @returns {string|null} 页面名称\r\n */\r\nfunction getPageNameFromPath(path) {\r\n for (const [name, config] of Object.entries(PAGE_NAME_MAP)) {\r\n if (config.path === path) {\r\n return name;\r\n }\r\n }\r\n return null;\r\n}\r\n\r\n/**\r\n * 获取所有可用页面的简要列表\r\n * 供 AI 查询可用页面时使用\r\n * \r\n * @returns {string} JSON 格式的页面列表\r\n */\r\nexport function getAvailablePages() {\r\n const pages = Object.entries(PAGE_NAME_MAP).map(([name, config]) => ({\r\n name,\r\n title: getPageTitle(name),\r\n isTabBar: config.isTabBar\r\n }));\r\n \r\n return JSON.stringify({\r\n message: \"可用页面列表\",\r\n pages\r\n });\r\n}\r\n\r\n// ============================================================================\r\n// 导出默认对象\r\n// ============================================================================\r\n\r\nexport default {\r\n // Tool 定义\r\n NAVIGATE_TO_PAGE_TOOL,\r\n NAVIGATE_TO_PAGE_TOOL_STRICT,\r\n \r\n // 路由配置\r\n PAGE_ROUTES,\r\n \r\n // 核心函数\r\n navigateToPage,\r\n handleNavigateToolCall,\r\n \r\n // 辅助函数\r\n matchPageByIntent,\r\n getAvailablePages\r\n};\r\n\r\n"}}}}