diff --git a/backend/src/main/java/ltd/qubit/survey/controller/QuestionController.java b/backend/src/main/java/ltd/qubit/survey/controller/QuestionController.java index e983c75..f76a0e8 100644 --- a/backend/src/main/java/ltd/qubit/survey/controller/QuestionController.java +++ b/backend/src/main/java/ltd/qubit/survey/controller/QuestionController.java @@ -8,7 +8,7 @@ import ltd.qubit.survey.service.QuestionService; import ltd.qubit.survey.service.OptionService; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; /** @@ -52,9 +52,9 @@ public class QuestionController { */ @GetMapping("/question/next") public Question getNextQuestion( - @PathVariable Long userId, - @PathVariable Integer currentQuestionNumber, - @PathVariable List selectedOptions) { + @RequestParam Long userId, + @RequestParam(defaultValue = "0") Integer currentQuestionNumber, + @RequestParam(required = false) List selectedOptions) { return questionService.getNextQuestion(userId, currentQuestionNumber, selectedOptions) .orElseThrow(() -> new IllegalArgumentException("没有更多问题了")); } diff --git a/backend/src/main/java/ltd/qubit/survey/model/Question.java b/backend/src/main/java/ltd/qubit/survey/model/Question.java index 3df9dbd..163c795 100644 --- a/backend/src/main/java/ltd/qubit/survey/model/Question.java +++ b/backend/src/main/java/ltd/qubit/survey/model/Question.java @@ -16,7 +16,7 @@ public class Question { /** * 问题序号 */ - private Integer questionNumber; + private Integer number; /** * 问题内容 @@ -26,7 +26,7 @@ public class Question { /** * 问题类型(单选、多选、文本) */ - private QuestionType questionType; + private QuestionType type; /** * 针对的工作领域(为null表示通用问题) @@ -41,7 +41,7 @@ public class Question { /** * 跳转逻辑(JSON格式) */ - private String nextQuestionLogic; + private String next; /** * 创建时间 diff --git a/backend/src/main/java/ltd/qubit/survey/model/User.java b/backend/src/main/java/ltd/qubit/survey/model/User.java index 6dca0fa..39fde69 100644 --- a/backend/src/main/java/ltd/qubit/survey/model/User.java +++ b/backend/src/main/java/ltd/qubit/survey/model/User.java @@ -23,11 +23,6 @@ public class User { */ private String phone; - /** - * 工作领域 - */ - private WorkArea workArea; - /** * 岗位性质 */ diff --git a/backend/src/main/resources/mybatis/mapper/OptionMapper.xml b/backend/src/main/resources/mybatis/mapper/OptionMapper.xml index a0533ce..da7f3c3 100644 --- a/backend/src/main/resources/mybatis/mapper/OptionMapper.xml +++ b/backend/src/main/resources/mybatis/mapper/OptionMapper.xml @@ -2,7 +2,7 @@ - + @@ -13,18 +13,18 @@ - id, question_id, option_code, content, requires_text, created_at + `id`, `question_id`, `option_code`, `content`, `requires_text`, `created_at` - INSERT INTO options (question_id, option_code, content, requires_text) + INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (#{questionId}, #{optionCode}, #{content}, #{requiresText}) - INSERT INTO options (question_id, option_code, content, requires_text) + INSERT INTO `option` (`question_id`, `option_code`, `content`, `requires_text`) VALUES (#{item.questionId}, #{item.optionCode}, #{item.content}, #{item.requiresText}) @@ -33,51 +33,51 @@ - UPDATE options - SET question_id = #{questionId}, - option_code = #{optionCode}, - content = #{content}, - requires_text = #{requiresText} - WHERE id = #{id} + UPDATE `option` + SET `question_id` = #{questionId}, + `option_code` = #{optionCode}, + `content` = #{content}, + `requires_text` = #{requiresText} + WHERE `id` = #{id} - DELETE FROM options WHERE id = #{id} + DELETE FROM `option` WHERE `id` = #{id} - DELETE FROM options WHERE question_id = #{questionId} + DELETE FROM `option` WHERE `question_id` = #{questionId} - SELECT - FROM options - WHERE id = #{id} + FROM `option` + WHERE `id` = #{id} - SELECT - FROM options - ORDER BY question_id, option_code + FROM `option` + ORDER BY `question_id`, `option_code` - SELECT - FROM options - WHERE question_id = #{questionId} - ORDER BY option_code + FROM `option` + WHERE `question_id` = #{questionId} + ORDER BY `option_code` - SELECT - FROM options - WHERE question_id = #{questionId} - AND option_code = #{optionCode} + FROM `option` + WHERE `question_id` = #{questionId} + AND `option_code` = #{optionCode} \ No newline at end of file diff --git a/backend/src/main/resources/mybatis/mapper/QuestionMapper.xml b/backend/src/main/resources/mybatis/mapper/QuestionMapper.xml index 4d3d902..79c07ed 100644 --- a/backend/src/main/resources/mybatis/mapper/QuestionMapper.xml +++ b/backend/src/main/resources/mybatis/mapper/QuestionMapper.xml @@ -4,83 +4,84 @@ - + - + - + - id, question_number, content, question_type, work_area, is_required, next_question_logic, created_at + `id`, `number`, `content`, `type`, `work_area`, `is_required`, `next`, `created_at` - INSERT INTO questions (question_number, content, question_type, work_area, is_required, next_question_logic) - VALUES (#{questionNumber}, #{content}, #{questionType}, #{workArea}, #{isRequired}, #{nextQuestionLogic}) + INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `next`) + VALUES (#{number}, #{content}, #{type}, #{workArea}, #{isRequired}, + #{next,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}) - UPDATE questions - SET question_number = #{questionNumber}, - content = #{content}, - question_type = #{questionType}, - work_area = #{workArea}, - is_required = #{isRequired}, - next_question_logic = #{nextQuestionLogic} - WHERE id = #{id} + UPDATE `question` + SET `number` = #{number}, + `content` = #{content}, + `type` = #{type}, + `work_area` = #{workArea}, + `is_required` = #{isRequired}, + `next` = #{next,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler} + WHERE `id` = #{id} - DELETE FROM questions WHERE id = #{id} + DELETE FROM `question` WHERE `id` = #{id} \ No newline at end of file diff --git a/backend/src/main/resources/mybatis/mapper/SurveyResponseMapper.xml b/backend/src/main/resources/mybatis/mapper/SurveyResponseMapper.xml index a3b78aa..c954675 100644 --- a/backend/src/main/resources/mybatis/mapper/SurveyResponseMapper.xml +++ b/backend/src/main/resources/mybatis/mapper/SurveyResponseMapper.xml @@ -13,18 +13,18 @@ - id, user_id, question_id, selected_options, text_answer, created_at + `id`, `user_id`, `question_id`, `selected_options`, `text_answer`, `created_at` - INSERT INTO survey_responses (user_id, question_id, selected_options, text_answer) + INSERT INTO `survey_response` (`user_id`, `question_id`, `selected_options`, `text_answer`) VALUES (#{userId}, #{questionId}, #{selectedOptions,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}, #{textAnswer}) - INSERT INTO survey_responses (user_id, question_id, selected_options, text_answer) + INSERT INTO `survey_response` (`user_id`, `question_id`, `selected_options`, `text_answer`) VALUES (#{item.userId}, #{item.questionId}, @@ -35,59 +35,59 @@ - UPDATE survey_responses - SET user_id = #{userId}, - question_id = #{questionId}, - selected_options = #{selectedOptions,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}, - text_answer = #{textAnswer} - WHERE id = #{id} + UPDATE `survey_response` + SET `user_id` = #{userId}, + `question_id` = #{questionId}, + `selected_options` = #{selectedOptions,typeHandler=ltd.qubit.survey.common.mybatis.JsonTypeHandler}, + `text_answer` = #{textAnswer} + WHERE `id` = #{id} - DELETE FROM survey_responses WHERE id = #{id} + DELETE FROM `survey_response` WHERE `id` = #{id} - DELETE FROM survey_responses WHERE user_id = #{userId} + DELETE FROM `survey_response` WHERE `user_id` = #{userId} \ No newline at end of file diff --git a/backend/src/main/resources/mybatis/mapper/UserMapper.xml b/backend/src/main/resources/mybatis/mapper/UserMapper.xml index da8010d..431e6fd 100644 --- a/backend/src/main/resources/mybatis/mapper/UserMapper.xml +++ b/backend/src/main/resources/mybatis/mapper/UserMapper.xml @@ -6,63 +6,61 @@ - - id, name, phone, work_area, position_type, created_at + `id`, `name`, `phone`, `position_type`, `created_at` - INSERT INTO users (name, phone, work_area, position_type) - VALUES (#{name}, #{phone}, #{workArea}, #{positionType}) + INSERT INTO `user` (`name`, `phone`, `position_type`) + VALUES (#{name}, #{phone}, #{positionType}) - UPDATE users - SET name = #{name}, - phone = #{phone}, - work_area = #{workArea}, - position_type = #{positionType} - WHERE id = #{id} + UPDATE `user` + SET `name` = #{name}, + `phone` = #{phone}, + `position_type` = #{positionType} + WHERE `id` = #{id} - DELETE FROM users WHERE id = #{id} + DELETE FROM `user` WHERE `id` = #{id} \ No newline at end of file diff --git a/backend/target/classes/ltd/qubit/survey/controller/QuestionController.class b/backend/target/classes/ltd/qubit/survey/controller/QuestionController.class index 616664e..a7134cc 100644 Binary files a/backend/target/classes/ltd/qubit/survey/controller/QuestionController.class and b/backend/target/classes/ltd/qubit/survey/controller/QuestionController.class differ diff --git a/doc/大模型应用需求调研问卷.md b/doc/大模型应用需求调研问卷.md index b418d19..cefb1ba 100644 --- a/doc/大模型应用需求调研问卷.md +++ b/doc/大模型应用需求调研问卷.md @@ -1,156 +1,214 @@ -**(根据部门自动跳转专属问题)** +**(根据部门自动跳转专属问题)** --- -## 第一部分:基本信息(必填) -1. 您所属部门: - A. 研发部 - B. 项目部 - C. 保险部 - D. 财务部 - E. 客服部 - F. 运营部 - G. 综合管理部 +## 第一部分:通用认知调研(必答) -2. 岗位性质: - A. 管理岗 - B. 技术岗 - C. 业务岗 - D. 职能支持岗 +1. 您对大模型(如ChatGPT、通义千问、DeepSeek)的了解程度: + A. 从未接触过 + B. 仅在日常简单使用过通用功能(如问答) + C. 在工作中尝试过基础应用 + D. 深度研究过技术原理 + +2. 您觉得大模型可以做到下面哪些事?(多选) + A. 精准知识问答 + B. 文档撰写/报告生成/代码编写/图片视频生成等 + C. 数据清洗与分析 + D. 客户沟通与服务 + E. 风险识别与预警 + F. 流程自动化 + G. 如有其他答案,请详细说明:____________ + +3. 您最关注大模型应用的哪些风险?(多选) + A. 数据隐私泄露 + B. 生成内容不准确 + C. 合规审查风险 + D. 技术使用门槛高 + E. 如有其他答案,请详细说明:____________ (需填写内容) + +4. 您的主要工作内容是: + A. 研发(产品、开发、算法、测试、运维等) + B. 项目管理(项目立项、进度跟踪、风险管理等) + C. 保险(产品、核保、理赔、精算等) + D. 财务(会计、税务、审计等) + E. 客服(咨询、投诉、回访等) + F. 运营(新媒体运营、广告宣传、活动策划、数据分析等) + G. 市场拓展(渠道拓展、商务沟通、产品推广等) + H. 人力资源(招聘、培训、绩效、薪酬等) + I. 综合事务(行政、法务等) + J. 公司高管(战略规划、组织架构、制度建设等) --- -## 第二部分:通用认知调研(必答) -1. 您对大模型(如ChatGPT、通义千问、DeepSeek)的了解程度: - A. 从未接触过 - B. 仅简单使用过通用功能(如问答) - C. 在工作中尝试过基础应用 - D. 深度研究过技术原理 +## 第二部分:领域专属问题 +**(系统将根据第4题选择的工作领域自动跳转)** -2. 您认为以下哪些业务场景最需要效率提升?(多选) - A. 文档撰写/报告生成 - B. 数据清洗与分析 - C. 客户沟通与服务 - D. 风险识别与预警 - E. 流程自动化 - F. 其他:____________ +### 研发 +5. 您在开发过程中最耗时的重复性工作:(多选) + A. 文档编写(如需求文档、技术文档等) + B. 产品原型、界面设计(如使用图片生成模型自动生成等) + C. 代码编写 + D. 调试与测试 + E. 系统监控与维护 + F. 如有其他答案,请详细说明:____________ -3. 您最关注大模型应用的哪些风险?(多选) - A. 数据隐私泄露 - B. 生成内容不准确 - C. 合规审查风险 - D. 技术使用门槛高 - E. 其他:____________ (需填写内容) +6. 您希望大模型如何与现有系统集成:(多选) + A. 回答技术问题 + B. 自动生成代码片段(如 Github Copilot等) + C. 智能测试用例生成 + D. 生成需求文档、技术文档 + E. 完整项目生成(如Cursor等) + F. 代码重构与优化 + G. 辅助设计算法(如DeepSeek等) + H. 如有其他答案,请详细说明:____________ + +### 项目管理 + +7. 项目管理中最常遇到的挑战是: + A. 项目进度跟踪与更新 + B. 风险评估与管控 + C. 项目报告生成 + D. 如有其他答案,请详细说明:____________ + +8. 您希望如何利用大模型提升项目管理效率: + A. 自动生成立项报告、进度报告、总结报告等 + B. 风险预测与预警 + C. 项目资料自动化整理 + D. 知识库管理 + E. 如有其他答案,请详细说明:____________ + +### 保险 + +9.理赔处理中的主要瓶颈是: + A. 理赔文档处理 + B. 医疗票据审核与核对 + C. 客户资料信息录入与处理 + D. 理赔规则理解与应用 + E. 如有其他答案,请详细说明:____________ + +10. 大模型可以优化哪些保险工作环节: + A. 新员工入职培训 + B. 保险产品设计的优化 + B. 自动生成理赔报告与告知书 + C. 自动化资料审核(如OCR识别票据数据、自动识别既往症等) + D. 异常案件智能预警 + E. 如有其他答案,请详细说明:____________ + +### 财务 + +11. 日常工作中最重复的任务是: + A. 财务数据整理与报表生成 + B. 发票和报销单审核 + C. 财务审计与合规检查 + D. 如有其他答案,请详细说明:____________ + +12.大模型能如何协助提升财务工作效率: + A. 各种报表格式的自动转换 + B. 自动生成财务报表与分析摘要 + C. 自动化审计和合规检查 + D. 财务数据智能分析与预测 + E. 如有其他答案,请详细说明:____________ + +### 客服 + +13. 客户咨询中最常遇到的重复性问题: + A. 参保资格咨询 + B. 理赔进度查询 + C. 材料补交通知 + D. 如有其他答案,请详细说明:____________ + +14. 您希望大模型如何辅助客服工作: + A. 自动生成客户回复模板 + B. 客户咨询自动分类与转接 + C. 智能分析客户情绪与需求 + D. 如有其他答案,请详细说明:____________ + +### 运营 + +15. 在运营工作中,最需要自动化支持的任务是: + A. 热点讯息的获取和跟踪 + B. 数据分析与报告生成 + C. 社交媒体内容创作 + D. 活动效果评估与预测 + D. 如有其他答案,请详细说明:____________ + +16.大模型可以如何帮助提升运营效率: + A. 自动抓取热点讯息 + B. 自动生成社交媒体内容 + C. 用户评论分析与舆情监测 + D. 活动数据自动分析与报告生成 + E. 如有其他答案,请详细说明:____________ + +### 市场拓展 + +17. 在市场拓展和商务沟通中,您最常遇到的挑战是: + A. 市场分析和竞争对手跟踪 + B. 渠道拓展计划的自动化和优化 + C. 商务沟通中的信息处理与反馈跟踪 + D. 如有其他答案,请详细说明:____________ + +18.您希望大模型如何帮助提升市场拓展效率: + A. 自动生成市场分析报告与趋势预测 + B. 根据目标客户数据生成个性化营销策略 + C. 自动化生成商务沟通邮件和提案文档 + D. 如有其他答案,请详细说明:____________ + +### 人力资源 + +19. 人事部门最耗时的日常任务是: + A. 招聘简历筛选与面试安排 + B. 员工培训与学习进度管理 + C. 绩效评估与报告生成 + D. 如有其他答案,请详细说明:____________ + +20. 您希望大模型如何协助提升人事工作效率: + A. 自动筛选招聘简历并推荐候选人 + B. 自动化培训内容推送与学习路径规划 + C. 绩效评估与员工反馈的自动化分析 + D. 如有其他答案,请详细说明:____________ + +### 综合管理 + +21. 在行政工作中,最耗时的任务是: + A. 合同审查与管理 + B. 会议纪要整理 + C. 文档管理与更新 + D. 如有其他答案,请详细说明:____________ + +22. 您希望大模型如何协助提升行政工作效率: + A. 自动生成合同和协议模板 + B. 自动化会议纪要整理与分发 + C. 自动化文档归档与管理 + D. 如有其他答案,请详细说明:____________ + +### 公司高管 + +23. 您认为大模型在哪些战略层面的决策中可以发挥作用? + A. 市场趋势预测与分析 + B. 组织结构优化与调整 + C. 业务流程优化与重组 + D. 如有其他答案,请详细说明:____________ + +24. 在公司管理工作中,您最希望大模型协助哪些任务? + A. 数据分析与报告自动生成 + B. 战略规划与方案优化 + C. 业务协同与跨部门信息流通 + D. 如有其他答案,请详细说明:____________ --- -## 第三部分:部门专属问题 -**(系统将根据第一部分选择的部门自动跳转)** +## 第四部分:开放建议(选填) +25. 您对大模型培训的具体期待: + ____________________________ -### 研发部 -4. 您在开发过程中最耗时的重复性工作: - A. 保险条款文档编写 - B. 医疗知识图谱维护 - C. API接口调试 - D. 其他:____________ - -5. 您希望大模型如何与现有系统集成: - A. 自动生成代码片段(如DeepSeek-Coder) - B. 智能测试用例生成(如通义千问测试场景模拟) - C. 需求文档结构化(如ChatGPT生成PRD框架) - D. 其他:____________ - -### 项目部 -6. 惠民保产品设计中最需要数据支持的环节: - A. 参保人群画像分析 - B. 竞品方案快速解析(如通义千问政策解读) - C. 定价模型优化 - D. 其他:____________ - -7. 您希望如何用大模型提升方案输出效率: - A. 自动生成PPT框架(ChatGPT生成大纲) - B. 从政策文件中提取关键条款(DeepSeek语义解析) - C. 风险测算报告自动化 - D. 其他:____________ - -### 保险部 -8. 理赔处理中的主要效率瓶颈: - A. 材料完整性核验 - B. 医疗票据信息提取(如OCR+通义千问核对) - C. 案件风险分级 - D. 其他:____________ - -9. 您认为大模型可优化的理赔环节: - A. 自动生成理赔告知书(ChatGPT模板生成) - B. 异常案件预警提示(DeepSeek数据分析) - C. 保险规则智能问答 - D. 其他:____________ - -### 财务部 -10. 日常工作中重复性最高的任务: - A. 发票信息录入核对 - B. 报销单据合规审查 - C. 财务报表数据汇总 - D. 其他:____________ - -11. 您希望大模型协助完成的财务工作: - A. 自动提取票据关键字段(通义千问OCR识别) - B. 生成财务分析摘要(ChatGPT文本总结) - C. 异常收支模式检测(DeepSeek风险预测) - D. 其他:____________ - -### 客服部 -12. 客户咨询中最常遇到的重复性问题: - A. 理赔进度查询 - B. 参保资格咨询 - C. 材料补交通知 - D. 其他:____________ - -13. 您希望大模型如何辅助客服工作: - A. 自动生成个性化回复话术(ChatGPT对话生成) - B. 客户情绪实时识别(通义千问情感分析) - C. 咨询问题自动分类派单(DeepSeek意图分类) - D. 其他:____________ - -### 运营部 -14. 运营数据分析中的主要痛点: - A. 多平台数据整合 - B. 参保率预测模型优化(DeepSeek时序预测) - C. 宣传文案创意生成(通义千问文案生成) - D. 其他:____________ - -15. 您希望大模型赋能的运营场景: - A. 自动生成社交媒体图文(ChatGPT+通义万相) - B. 用户评论情感分析(DeepSeek语义分析) - C. 活动效果模拟预测 - D. 其他:____________ - -### 综合管理部 -16. 日常工作中最耗时的行政事务: - A. 合同条款审查 - B. 会议纪要整理 - C. 制度文档更新 - D. 其他:____________ - -17. 您希望大模型协助完成的行政工作: - A. 自动生成招投标文件模板(ChatGPT框架生成) - B. 合同风险点智能排查(通义千问法律审查) - C. 流程说明书自动更新(DeepSeek版本迭代) - D. 其他:____________ +26. 您认为公司引入AI需提前防范的风险: + ____________________________ --- -## 第四部分:开放建议(选填) -18. 您对大模型培训的具体期待: - ____________________________ +### 问卷说明 -19. 您认为公司引入AI需提前防范的风险: - ____________________________ - ---- - -### 问卷说明 -20. **逻辑跳转**:系统将根据所选部门显示专属问题,总题量约10-12题。 -21. **工具示例**: - - 通用大模型:ChatGPT(OpenAI)、通义千问(阿里云)、DeepSeek(深度求索) -22. **提交方式**:匿名填写,预计耗时5-8分钟。 \ No newline at end of file +- **逻辑跳转**:系统将根据第1题的答案显示专属问题,总题量约10-12题。 +- **工具示例**: + - 通用大模型:ChatGPT(OpenAI)、通义千问(阿里云)、DeepSeek(深度求索) +- **提交方式**:匿名填写,预计耗时5-8分钟。 \ No newline at end of file diff --git a/frontend/.eslintrc.js b/frontend/.eslintrc.js index 75bd048..751b88d 100644 --- a/frontend/.eslintrc.js +++ b/frontend/.eslintrc.js @@ -1,11 +1,7 @@ /* eslint-env node */ module.exports = { root: true, - extends: [ - 'plugin:vue/vue3-essential', - 'eslint:recommended', - '@vue/eslint-config-prettier', - ], + extends: ['plugin:vue/vue3-essential', 'eslint:recommended', '@vue/eslint-config-prettier'], parserOptions: { ecmaVersion: 'latest', }, diff --git a/frontend/src/stores/survey.js b/frontend/src/stores/survey.js index d983f81..f388aea 100644 --- a/frontend/src/stores/survey.js +++ b/frontend/src/stores/survey.js @@ -42,15 +42,17 @@ export const useSurveyStore = defineStore('survey', () => { // 获取下一个问题 async function fetchNextQuestion(userId, selectedOptions) { try { - const response = await getNextQuestion(userId, currentQuestionNumber.value, selectedOptions); - if (response.data) { - currentQuestion.value = response.data; - currentQuestionNumber.value++; - await fetchQuestionOptions(response.data.id); + // 如果是初始化(currentQuestionNumber为0),则从第3题开始 + const questionNumber = currentQuestionNumber.value === 0 ? 3 : currentQuestionNumber.value; + const response = await getNextQuestion(userId, questionNumber, selectedOptions); + if (response) { + currentQuestion.value = response; + currentQuestionNumber.value = response.questionNumber; + await fetchQuestionOptions(response.id); } else { isCompleted.value = true; } - return response.data; + return response; } catch (error) { showToast('获取下一个问题失败:' + error.message); throw error; diff --git a/frontend/src/stores/user.js b/frontend/src/stores/user.js index 0370090..88d4ad1 100644 --- a/frontend/src/stores/user.js +++ b/frontend/src/stores/user.js @@ -10,12 +10,37 @@ export const useUserStore = defineStore('user', () => { // 注册用户 async function registerUser(data) { try { + console.log('发送注册请求,数据:', data); const response = await register(data); - userId.value = response.data.id; + console.log('注册请求响应:', response); + + // 检查响应数据结构 + if (!response) { + throw new Error('注册失败:服务器无响应'); + } + + // 后端直接返回 User 对象,response 就是 User 对象 + const userData = response; + console.log('用户数据:', userData); + + if (!userData || !userData.id) { + throw new Error('注册失败:无效的用户数据'); + } + + // 保存用户信息 + userId.value = String(userData.id); + userInfo.value = userData; localStorage.setItem('userId', userId.value); - return response; + + console.log('用户信息已保存,userId:', userId.value); + return userData; } catch (error) { - showToast('注册失败:' + error.message); + console.error('注册请求失败:', error); + if (error.response) { + console.error('错误响应:', error.response); + } + const message = error.response?.data?.message || error.message || '注册失败,请稍后重试'; + showToast(message); throw error; } } @@ -23,10 +48,18 @@ export const useUserStore = defineStore('user', () => { // 检查手机号是否已注册 async function checkPhoneNumber(phone) { try { + console.log('检查手机号:', phone); const response = await checkPhone(phone); - return response.data; + console.log('检查手机号响应:', response); + // 如果响应是包装过的,尝试获取实际数据 + return response.data ?? response; } catch (error) { - showToast('检查手机号失败:' + error.message); + console.error('检查手机号失败:', error); + if (error.response) { + console.error('错误响应:', error.response); + } + const message = error.response?.data?.message || error.message || '检查手机号失败,请稍后重试'; + showToast(message); throw error; } } @@ -34,11 +67,20 @@ export const useUserStore = defineStore('user', () => { // 获取用户信息 async function fetchUserInfo(id) { try { + console.log('获取用户信息:', id); const response = await getUserInfo(id); - userInfo.value = response.data; - return response.data; + console.log('获取用户信息响应:', response); + // 如果响应是包装过的,尝试获取实际数据 + const userData = response.data || response; + userInfo.value = userData; + return userData; } catch (error) { - showToast('获取用户信息失败:' + error.message); + console.error('获取用户信息失败:', error); + if (error.response) { + console.error('错误响应:', error.response); + } + const message = error.response?.data?.message || error.message || '获取用户信息失败,请稍后重试'; + showToast(message); throw error; } } @@ -48,6 +90,7 @@ export const useUserStore = defineStore('user', () => { userId.value = ''; userInfo.value = null; localStorage.removeItem('userId'); + console.log('用户已登出'); } return { diff --git a/frontend/src/utils/request.js b/frontend/src/utils/request.js index 30feb5f..cecafca 100644 --- a/frontend/src/utils/request.js +++ b/frontend/src/utils/request.js @@ -4,15 +4,24 @@ import { showToast } from 'vant'; const request = axios.create({ baseURL: '/api', timeout: 10000, + headers: { + 'Content-Type': 'application/json' + } }); // 请求拦截器 request.interceptors.request.use( (config) => { - // 可以在这里添加 token 等认证信息 + console.log('发送请求:', { + url: config.url, + method: config.method, + data: config.data, + headers: config.headers + }); return config; }, (error) => { + console.error('请求错误:', error); return Promise.reject(error); } ); @@ -20,9 +29,25 @@ request.interceptors.request.use( // 响应拦截器 request.interceptors.response.use( (response) => { + console.log('收到响应:', { + status: response.status, + statusText: response.statusText, + data: response.data, + headers: response.headers + }); return response.data; }, (error) => { + console.error('响应错误:', { + message: error.message, + config: error.config, + response: error.response ? { + status: error.response.status, + statusText: error.response.statusText, + data: error.response.data, + headers: error.response.headers + } : null + }); const message = error.response?.data?.message || '请求失败,请稍后重试'; showToast(message); return Promise.reject(error); diff --git a/frontend/src/views/RegisterView.vue b/frontend/src/views/RegisterView.vue index ad78ec6..c30e569 100644 --- a/frontend/src/views/RegisterView.vue +++ b/frontend/src/views/RegisterView.vue @@ -24,26 +24,6 @@ :rules="[{ required: true, message: '请填写姓名' }]" /> - - - - - { - router.replace('/survey'); + console.log('准备跳转到问卷页面'); + router.push({ + name: 'survey', + replace: true + }).catch(err => { + console.error('路由跳转失败:', err); + showToast('页面跳转失败,请刷新重试'); + }); }, 500); } catch (error) { console.error('注册失败:', error); + showToast(error.message || '注册失败,请重试'); } }