fix: 移除 work_area 字段,修复用户登录/注册功能 - 1. 移除数据库中 question 表的 work_area 字段 2. 移除 WorkArea 枚举类 3. 修复 UserDao 和 UserServiceImpl 中的返回类型问题 4. 修复前端用户登录/注册功能 5. 修复 van-popup 组件的 ESLint 告警

This commit is contained in:
胡海星 2025-02-23 17:11:49 +08:00
parent cebbef1d53
commit f66549ee61
12 changed files with 235 additions and 186 deletions

View File

@ -6,6 +6,7 @@ import ltd.qubit.survey.service.UserService;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -40,6 +41,33 @@ public class UserController {
.orElseThrow(() -> new IllegalArgumentException("用户不存在")); .orElseThrow(() -> new IllegalArgumentException("用户不存在"));
} }
/**
* 根据手机号查询用户
*
* @param phone 手机号
* @return 用户信息
*/
@GetMapping("/user/phone/{phone}")
public User findByPhone(@PathVariable String phone) {
return userService.findByPhone(phone)
.orElse(null);
}
/**
* 更新用户信息
*
* @param id 用户ID
* @param user 用户信息
* @return 更新后的用户信息
*/
@PutMapping("/user/{id}")
public User update(@PathVariable Long id, @RequestBody User user) {
if (!id.equals(user.getId())) {
throw new IllegalArgumentException("用户ID不匹配");
}
return userService.update(user);
}
/** /**
* 检查手机号是否已注册 * 检查手机号是否已注册
* *
@ -48,6 +76,6 @@ public class UserController {
*/ */
@GetMapping("/user/check/{phone}") @GetMapping("/user/check/{phone}")
public boolean checkPhone(@PathVariable String phone) { public boolean checkPhone(@PathVariable String phone) {
return userService.isPhoneRegistered(phone); return userService.findByPhone(phone).isPresent();
} }
} }

View File

@ -3,17 +3,19 @@ package ltd.qubit.survey.dao;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import ltd.qubit.survey.model.User; import ltd.qubit.survey.model.User;
import ltd.qubit.survey.model.WorkArea; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
/** /**
* 用户DAO接口 * 用户DAO
*/ */
@Mapper
public interface UserDao extends BaseDao<User, Long> { public interface UserDao extends BaseDao<User, Long> {
/** /**
* 根据手机号查询用户 * 根据手机号查询用户
* *
* @param phone 手机号 * @param phone 手机号
* @return 用户对象 * @return 用户信息
*/ */
Optional<User> findByPhone(String phone); Optional<User> findByPhone(@Param("phone") String phone);
} }

View File

@ -29,11 +29,6 @@ public class Question {
*/ */
private QuestionType type; private QuestionType type;
/**
* 针对的工作领域为null表示通用问题
*/
private WorkArea workArea;
/** /**
* 是否必答 * 是否必答
*/ */

View File

@ -1,51 +0,0 @@
package ltd.qubit.survey.model;
/**
* 工作领域枚举
*/
public enum WorkArea {
/**
* 研发领域
*/
RD("研发"),
/**
* 项目领域
*/
PROJECT("项目"),
/**
* 保险领域
*/
INSURANCE("保险"),
/**
* 财务领域
*/
FINANCE("财务"),
/**
* 运营领域
*/
OPERATION("运营"),
/**
* 客服领域
*/
CUSTOMER_SERVICE("客服"),
/**
* 综合管理领域
*/
ADMIN("综合管理");
private final String displayName;
WorkArea(String displayName) {
this.displayName = displayName;
}
public String getDisplayName() {
return displayName;
}
}

View File

@ -3,18 +3,54 @@ package ltd.qubit.survey.service;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import ltd.qubit.survey.model.User; import ltd.qubit.survey.model.User;
import org.springframework.transaction.annotation.Transactional;
/** /**
* 用户服务接口 * 用户服务
*/ */
@Transactional(readOnly = true) public interface UserService {
public interface UserService extends BaseService<User, Long> { /**
* 创建用户
*
* @param user 用户信息
* @return 创建成功的用户信息
*/
User create(User user);
/**
* 删除用户
*
* @param id 用户ID
*/
void delete(Long id);
/**
* 更新用户信息
*
* @param user 用户信息
* @return 更新后的用户信息
*/
User update(User user);
/**
* 根据ID查询用户
*
* @param id 用户ID
* @return 用户信息
*/
Optional<User> findById(Long id);
/**
* 查询所有用户
*
* @return 用户列表
*/
List<User> findAll();
/** /**
* 根据手机号查询用户 * 根据手机号查询用户
* *
* @param phone 手机号 * @param phone 手机号
* @return 用户对象 * @return 用户信息
*/ */
Optional<User> findByPhone(String phone); Optional<User> findByPhone(String phone);
@ -22,16 +58,15 @@ public interface UserService extends BaseService<User, Long> {
* 用户注册 * 用户注册
* *
* @param user 用户信息 * @param user 用户信息
* @return 注册成功的用户 * @return 注册成功的用户信息
*/ */
@Transactional
User register(User user); User register(User user);
/** /**
* 检查手机号是否已被注册 * 用户登录或注册
* *
* @param phone 手机号 * @param user 用户信息
* @return 是否已注册 * @return 登录或注册成功的用户信息
*/ */
boolean isPhoneRegistered(String phone); User loginOrRegister(User user);
} }

View File

@ -8,6 +8,7 @@ import ltd.qubit.survey.dao.UserDao;
import ltd.qubit.survey.model.User; import ltd.qubit.survey.model.User;
import ltd.qubit.survey.service.UserService; import ltd.qubit.survey.service.UserService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
/** /**
* 用户服务实现类 * 用户服务实现类
@ -18,6 +19,7 @@ public class UserServiceImpl implements UserService {
private final UserDao userDao; private final UserDao userDao;
@Override @Override
@Transactional
public User create(User user) { public User create(User user) {
user.setCreatedAt(Instant.now()); user.setCreatedAt(Instant.now());
userDao.insert(user); userDao.insert(user);
@ -25,12 +27,18 @@ public class UserServiceImpl implements UserService {
} }
@Override @Override
@Transactional
public void delete(Long id) { public void delete(Long id) {
userDao.deleteById(id); userDao.deleteById(id);
} }
@Override @Override
@Transactional
public User update(User user) { public User update(User user) {
Optional<User> existingUser = findById(user.getId());
if (existingUser.isEmpty()) {
throw new IllegalArgumentException("用户不存在");
}
userDao.update(user); userDao.update(user);
return user; return user;
} }
@ -51,16 +59,25 @@ public class UserServiceImpl implements UserService {
} }
@Override @Override
@Transactional
public User register(User user) { public User register(User user) {
// 检查手机号是否已注册 Optional<User> existingUser = findByPhone(user.getPhone());
if (isPhoneRegistered(user.getPhone())) { if (existingUser.isPresent()) {
throw new IllegalArgumentException("手机号已被注册"); throw new IllegalArgumentException("手机号已被注册");
} }
return create(user); return create(user);
} }
@Override @Override
public boolean isPhoneRegistered(String phone) { @Transactional
return userDao.findByPhone(phone).isPresent(); public User loginOrRegister(User user) {
Optional<User> existingUser = findByPhone(user.getPhone());
if (existingUser.isPresent()) {
User updatedUser = existingUser.get();
updatedUser.setName(user.getName());
updatedUser.setPositionType(user.getPositionType());
return update(updatedUser);
}
return register(user);
} }
} }

View File

@ -4,55 +4,54 @@
<!-- 结果映射 --> <!-- 结果映射 -->
<resultMap id="userMap" type="ltd.qubit.survey.model.User"> <resultMap id="userMap" type="ltd.qubit.survey.model.User">
<id property="id" column="id"/> <id property="id" column="id"/>
<result property="name" column="name"/>
<result property="phone" column="phone"/> <result property="phone" column="phone"/>
<result property="name" column="name"/>
<result property="positionType" column="position_type"/> <result property="positionType" column="position_type"/>
<result property="createdAt" column="created_at"/> <result property="createdAt" column="created_at"/>
</resultMap> </resultMap>
<!-- 基础列 --> <!-- 基础列 -->
<sql id="baseColumns"> <sql id="columns">
`id`, `name`, `phone`, `position_type`, `created_at` id, phone, name, position_type, created_at
</sql> </sql>
<!-- 插入 --> <!-- 插入 -->
<insert id="insert" parameterType="ltd.qubit.survey.model.User" useGeneratedKeys="true" keyProperty="id"> <insert id="insert" parameterType="ltd.qubit.survey.model.User" useGeneratedKeys="true" keyProperty="id">
INSERT INTO `user` (`name`, `phone`, `position_type`) INSERT INTO user (phone, name, position_type, created_at)
VALUES (#{name}, #{phone}, #{positionType}) VALUES (#{phone}, #{name}, #{positionType}, NOW())
</insert> </insert>
<!-- 更新 --> <!-- 更新 -->
<update id="update" parameterType="ltd.qubit.survey.model.User"> <update id="update" parameterType="ltd.qubit.survey.model.User">
UPDATE `user` UPDATE user
SET `name` = #{name}, SET name = #{name},
`phone` = #{phone}, position_type = #{positionType}
`position_type` = #{positionType} WHERE id = #{id}
WHERE `id` = #{id}
</update> </update>
<!-- 删除 --> <!-- 删除 -->
<delete id="deleteById" parameterType="long"> <delete id="deleteById" parameterType="long">
DELETE FROM `user` WHERE `id` = #{id} DELETE FROM user WHERE id = #{id}
</delete> </delete>
<!-- 根据ID查询 --> <!-- 根据ID查询 -->
<select id="findById" parameterType="long" resultMap="userMap"> <select id="findById" parameterType="long" resultMap="userMap">
SELECT <include refid="baseColumns"/> SELECT <include refid="columns"/>
FROM `user` FROM user
WHERE `id` = #{id} WHERE id = #{id}
</select> </select>
<!-- 查询所有 --> <!-- 查询所有 -->
<select id="findAll" resultMap="userMap"> <select id="findAll" resultMap="userMap">
SELECT <include refid="baseColumns"/> SELECT <include refid="columns"/>
FROM `user` FROM user
ORDER BY `id` ORDER BY id
</select> </select>
<!-- 根据手机号查询 --> <!-- 根据手机号查询 -->
<select id="findByPhone" parameterType="string" resultMap="userMap"> <select id="findByPhone" parameterType="string" resultMap="userMap">
SELECT <include refid="baseColumns"/> SELECT <include refid="columns"/>
FROM `user` FROM user
WHERE `phone` = #{phone} WHERE phone = #{phone}
</select> </select>
</mapper> </mapper>

View File

@ -20,8 +20,6 @@
<!-- 类型处理器配置 --> <!-- 类型处理器配置 -->
<typeHandlers> <typeHandlers>
<!-- 枚举类型处理器 --> <!-- 枚举类型处理器 -->
<typeHandler handler="org.apache.ibatis.type.EnumTypeHandler"
javaType="ltd.qubit.survey.model.WorkArea"/>
<typeHandler handler="org.apache.ibatis.type.EnumTypeHandler" <typeHandler handler="org.apache.ibatis.type.EnumTypeHandler"
javaType="ltd.qubit.survey.model.PositionType"/> javaType="ltd.qubit.survey.model.PositionType"/>
<typeHandler handler="org.apache.ibatis.type.EnumTypeHandler" <typeHandler handler="org.apache.ibatis.type.EnumTypeHandler"

View File

@ -25,7 +25,6 @@ CREATE TABLE IF NOT EXISTS `question` (
`number` INT NOT NULL COMMENT '问题序号', `number` INT NOT NULL COMMENT '问题序号',
`content` TEXT NOT NULL COMMENT '问题内容', `content` TEXT NOT NULL COMMENT '问题内容',
`type` VARCHAR(20) NOT NULL COMMENT '问题类型', `type` VARCHAR(20) NOT NULL COMMENT '问题类型',
`work_area` VARCHAR(20) DEFAULT NULL COMMENT '针对的工作领域',
`is_required` BOOLEAN NOT NULL DEFAULT TRUE COMMENT '是否必答', `is_required` BOOLEAN NOT NULL DEFAULT TRUE COMMENT '是否必答',
`next` JSON DEFAULT NULL COMMENT '跳转逻辑', `next` JSON DEFAULT NULL COMMENT '跳转逻辑',
`is_last` BOOLEAN NOT NULL DEFAULT FALSE COMMENT '是否是最后一题', `is_last` BOOLEAN NOT NULL DEFAULT FALSE COMMENT '是否是最后一题',
@ -113,8 +112,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`) VALUES
(LAST_INSERT_ID(), 'J', '公司高管(战略规划、组织架构、制度建设等)'); (LAST_INSERT_ID(), 'J', '公司高管(战略规划、组织架构、制度建设等)');
-- 研发部门专属问题 -- 研发部门专属问题
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (5, '您在开发过程中最耗时的重复性工作:', 'MULTIPLE_CHOICE', 'RD', TRUE, FALSE); VALUES (5, '您在开发过程中最耗时的重复性工作:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '文档编写(如需求文档、技术文档等)', FALSE), (LAST_INSERT_ID(), 'A', '文档编写(如需求文档、技术文档等)', FALSE),
@ -124,8 +123,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'E', '系统监控与维护', FALSE), (LAST_INSERT_ID(), 'E', '系统监控与维护', FALSE),
(LAST_INSERT_ID(), 'F', '其他', TRUE); (LAST_INSERT_ID(), 'F', '其他', TRUE);
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (6, '您希望大模型如何与现有系统集成:', 'MULTIPLE_CHOICE', 'RD', TRUE, FALSE); VALUES (6, '您希望大模型如何与现有系统集成:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '回答技术问题', FALSE), (LAST_INSERT_ID(), 'A', '回答技术问题', FALSE),
@ -138,8 +137,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'H', '其他', TRUE); (LAST_INSERT_ID(), 'H', '其他', TRUE);
-- 项目管理专属问题 -- 项目管理专属问题
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (7, '项目管理中最常遇到的挑战是:', 'MULTIPLE_CHOICE', 'PROJECT', TRUE, FALSE); VALUES (7, '项目管理中最常遇到的挑战是:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '项目进度跟踪与更新', FALSE), (LAST_INSERT_ID(), 'A', '项目进度跟踪与更新', FALSE),
@ -147,8 +146,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'C', '项目报告生成', FALSE), (LAST_INSERT_ID(), 'C', '项目报告生成', FALSE),
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (8, '您希望如何利用大模型提升项目管理效率:', 'MULTIPLE_CHOICE', 'PROJECT', TRUE, FALSE); VALUES (8, '您希望如何利用大模型提升项目管理效率:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '自动生成立项报告、进度报告、总结报告等', FALSE), (LAST_INSERT_ID(), 'A', '自动生成立项报告、进度报告、总结报告等', FALSE),
@ -158,8 +157,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'E', '其他', TRUE); (LAST_INSERT_ID(), 'E', '其他', TRUE);
-- 保险专属问题 -- 保险专属问题
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (9, '理赔处理中的主要瓶颈是:', 'MULTIPLE_CHOICE', 'INSURANCE', TRUE, FALSE); VALUES (9, '理赔处理中的主要瓶颈是:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '理赔文档处理', FALSE), (LAST_INSERT_ID(), 'A', '理赔文档处理', FALSE),
@ -168,8 +167,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'D', '理赔规则理解与应用', FALSE), (LAST_INSERT_ID(), 'D', '理赔规则理解与应用', FALSE),
(LAST_INSERT_ID(), 'E', '其他', TRUE); (LAST_INSERT_ID(), 'E', '其他', TRUE);
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (10, '大模型可以优化哪些保险工作环节:', 'MULTIPLE_CHOICE', 'INSURANCE', TRUE, FALSE); VALUES (10, '大模型可以优化哪些保险工作环节:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '新员工入职培训', FALSE), (LAST_INSERT_ID(), 'A', '新员工入职培训', FALSE),
@ -180,8 +179,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'F', '其他', TRUE); (LAST_INSERT_ID(), 'F', '其他', TRUE);
-- 财务专属问题 -- 财务专属问题
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (11, '日常工作中最重复的任务是:', 'MULTIPLE_CHOICE', 'FINANCE', TRUE, FALSE); VALUES (11, '日常工作中最重复的任务是:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '财务数据整理与报表生成', FALSE), (LAST_INSERT_ID(), 'A', '财务数据整理与报表生成', FALSE),
@ -189,8 +188,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'C', '财务审计与合规检查', FALSE), (LAST_INSERT_ID(), 'C', '财务审计与合规检查', FALSE),
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (12, '大模型能如何协助提升财务工作效率:', 'MULTIPLE_CHOICE', 'FINANCE', TRUE, FALSE); VALUES (12, '大模型能如何协助提升财务工作效率:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '各种报表格式的自动转换', FALSE), (LAST_INSERT_ID(), 'A', '各种报表格式的自动转换', FALSE),
@ -200,8 +199,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'E', '其他', TRUE); (LAST_INSERT_ID(), 'E', '其他', TRUE);
-- 客服专属问题 -- 客服专属问题
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (13, '客户咨询中最常遇到的重复性问题:', 'MULTIPLE_CHOICE', 'CUSTOMER_SERVICE', TRUE, FALSE); VALUES (13, '客户咨询中最常遇到的重复性问题:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '参保资格咨询', FALSE), (LAST_INSERT_ID(), 'A', '参保资格咨询', FALSE),
@ -209,8 +208,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'C', '材料补交通知', FALSE), (LAST_INSERT_ID(), 'C', '材料补交通知', FALSE),
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (14, '您希望大模型如何辅助客服工作:', 'MULTIPLE_CHOICE', 'CUSTOMER_SERVICE', TRUE, FALSE); VALUES (14, '您希望大模型如何辅助客服工作:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '自动生成客户回复模板', FALSE), (LAST_INSERT_ID(), 'A', '自动生成客户回复模板', FALSE),
@ -219,8 +218,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
-- 运营专属问题 -- 运营专属问题
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (15, '在运营工作中,最需要自动化支持的任务是:', 'MULTIPLE_CHOICE', 'OPERATION', TRUE, FALSE); VALUES (15, '在运营工作中,最需要自动化支持的任务是:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '热点讯息的获取和跟踪', FALSE), (LAST_INSERT_ID(), 'A', '热点讯息的获取和跟踪', FALSE),
@ -229,8 +228,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'D', '活动效果评估与预测', FALSE), (LAST_INSERT_ID(), 'D', '活动效果评估与预测', FALSE),
(LAST_INSERT_ID(), 'E', '其他', TRUE); (LAST_INSERT_ID(), 'E', '其他', TRUE);
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (16, '大模型可以如何帮助提升运营效率:', 'MULTIPLE_CHOICE', 'OPERATION', TRUE, FALSE); VALUES (16, '大模型可以如何帮助提升运营效率:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '自动抓取热点讯息', FALSE), (LAST_INSERT_ID(), 'A', '自动抓取热点讯息', FALSE),
@ -240,8 +239,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'E', '其他', TRUE); (LAST_INSERT_ID(), 'E', '其他', TRUE);
-- 市场拓展专属问题 -- 市场拓展专属问题
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (17, '在市场拓展和商务沟通中,您最常遇到的挑战是:', 'MULTIPLE_CHOICE', 'MARKET', TRUE, FALSE); VALUES (17, '在市场拓展和商务沟通中,您最常遇到的挑战是:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '市场分析和竞争对手跟踪', FALSE), (LAST_INSERT_ID(), 'A', '市场分析和竞争对手跟踪', FALSE),
@ -249,8 +248,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'C', '商务沟通中的信息处理与反馈跟踪', FALSE), (LAST_INSERT_ID(), 'C', '商务沟通中的信息处理与反馈跟踪', FALSE),
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (18, '您希望大模型如何帮助提升市场拓展效率:', 'MULTIPLE_CHOICE', 'MARKET', TRUE, FALSE); VALUES (18, '您希望大模型如何帮助提升市场拓展效率:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '自动生成市场分析报告与趋势预测', FALSE), (LAST_INSERT_ID(), 'A', '自动生成市场分析报告与趋势预测', FALSE),
@ -259,8 +258,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
-- 人力资源专属问题 -- 人力资源专属问题
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (19, '人事部门最耗时的日常任务是:', 'MULTIPLE_CHOICE', 'HR', TRUE, FALSE); VALUES (19, '人事部门最耗时的日常任务是:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '招聘简历筛选与面试安排', FALSE), (LAST_INSERT_ID(), 'A', '招聘简历筛选与面试安排', FALSE),
@ -268,8 +267,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'C', '绩效评估与报告生成', FALSE), (LAST_INSERT_ID(), 'C', '绩效评估与报告生成', FALSE),
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (20, '您希望大模型如何协助提升人事工作效率:', 'MULTIPLE_CHOICE', 'HR', TRUE, FALSE); VALUES (20, '您希望大模型如何协助提升人事工作效率:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '自动筛选招聘简历并推荐候选人', FALSE), (LAST_INSERT_ID(), 'A', '自动筛选招聘简历并推荐候选人', FALSE),
@ -278,8 +277,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
-- 综合管理专属问题 -- 综合管理专属问题
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (21, '在行政工作中,最耗时的任务是:', 'MULTIPLE_CHOICE', 'ADMIN', TRUE, FALSE); VALUES (21, '在行政工作中,最耗时的任务是:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '合同审查与管理', FALSE), (LAST_INSERT_ID(), 'A', '合同审查与管理', FALSE),
@ -287,8 +286,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'C', '文档管理与更新', FALSE), (LAST_INSERT_ID(), 'C', '文档管理与更新', FALSE),
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (22, '您希望大模型如何协助提升行政工作效率:', 'MULTIPLE_CHOICE', 'ADMIN', TRUE, FALSE); VALUES (22, '您希望大模型如何协助提升行政工作效率:', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '自动生成合同和协议模板', FALSE), (LAST_INSERT_ID(), 'A', '自动生成合同和协议模板', FALSE),
@ -297,8 +296,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
-- 公司高管专属问题 -- 公司高管专属问题
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (23, '您认为大模型在哪些战略层面的决策中可以发挥作用?', 'MULTIPLE_CHOICE', 'EXECUTIVE', TRUE, FALSE); VALUES (23, '您认为大模型在哪些战略层面的决策中可以发挥作用?', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '市场趋势预测与分析', FALSE), (LAST_INSERT_ID(), 'A', '市场趋势预测与分析', FALSE),
@ -306,8 +305,8 @@ INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'C', '业务流程优化与重组', FALSE), (LAST_INSERT_ID(), 'C', '业务流程优化与重组', FALSE),
(LAST_INSERT_ID(), 'D', '其他', TRUE); (LAST_INSERT_ID(), 'D', '其他', TRUE);
INSERT INTO `question` (`number`, `content`, `type`, `work_area`, `is_required`, `is_last`) INSERT INTO `question` (`number`, `content`, `type`, `is_required`, `is_last`)
VALUES (24, '在公司管理工作中,您最希望大模型协助哪些任务?', 'MULTIPLE_CHOICE', 'EXECUTIVE', TRUE, FALSE); VALUES (24, '在公司管理工作中,您最希望大模型协助哪些任务?', 'MULTIPLE_CHOICE', TRUE, FALSE);
INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES INSERT INTO `option` (`question_id`, `code`, `content`, `requires_text`) VALUES
(LAST_INSERT_ID(), 'A', '数据分析与报告自动生成', FALSE), (LAST_INSERT_ID(), 'A', '数据分析与报告自动生成', FALSE),

View File

@ -9,10 +9,19 @@ export function register(data) {
}); });
} }
// 检查手机号是否已注册 // 更新用户信息
export function checkPhone(phone) { export function updateUser(data) {
return request({ return request({
url: `/user/check/${phone}`, url: `/user/${data.id}`,
method: 'put',
data,
});
}
// 根据手机号获取用户信息
export function getUserInfoByPhone(phone) {
return request({
url: `/user/phone/${phone}`,
method: 'get', method: 'get',
}); });
} }

View File

@ -1,6 +1,6 @@
import { defineStore } from 'pinia'; import { defineStore } from 'pinia';
import { ref } from 'vue'; import { ref } from 'vue';
import { register, checkPhone, getUserInfo } from '@/api/user'; import { register, getUserInfo, getUserInfoByPhone, updateUser } from '@/api/user';
import { showToast } from 'vant'; import { showToast } from 'vant';
import { useSurveyStore } from './survey'; import { useSurveyStore } from './survey';
@ -8,24 +8,31 @@ export const useUserStore = defineStore('user', () => {
const userId = ref(localStorage.getItem('userId') || ''); const userId = ref(localStorage.getItem('userId') || '');
const userInfo = ref(null); const userInfo = ref(null);
// 注册用户 // 用户登录/注册
async function registerUser(data) { async function loginOrRegister(data) {
try { try {
console.log('发送注册请求,数据:', data); console.log('发送登录/注册请求,数据:', data);
const response = await register(data); const response = await getUserInfoByPhone(data.phone);
console.log('注册请求响应:', response);
// 检查响应数据结构 let userData;
if (!response) { if (response) {
throw new Error('注册失败:服务器无响应'); // 用户存在,更新信息
console.log('用户已存在,更新信息');
userData = await updateUser({
...response,
name: data.name,
positionType: data.positionType
});
} else {
// 用户不存在,注册新用户
console.log('用户不存在,创建新用户');
userData = await register(data);
} }
// 后端直接返回 User 对象response 就是 User 对象
const userData = response;
console.log('用户数据:', userData); console.log('用户数据:', userData);
if (!userData || !userData.id) { if (!userData || !userData.id) {
throw new Error('注册失败:无效的用户数据'); throw new Error('登录失败:无效的用户数据');
} }
// 保存用户信息 // 保存用户信息
@ -36,30 +43,11 @@ export const useUserStore = defineStore('user', () => {
console.log('用户信息已保存userId:', userId.value); console.log('用户信息已保存userId:', userId.value);
return userData; return userData;
} catch (error) { } catch (error) {
console.error('注册请求失败:', error); console.error('登录/注册请求失败:', error);
if (error.response) { if (error.response) {
console.error('错误响应:', error.response); console.error('错误响应:', error.response);
} }
const message = error.response?.data?.message || error.message || '注册失败,请稍后重试'; const message = error.response?.data?.message || error.message || '登录失败,请稍后重试';
showToast(message);
throw error;
}
}
// 检查手机号是否已注册
async function checkPhoneNumber(phone) {
try {
console.log('检查手机号:', phone);
const response = await checkPhone(phone);
console.log('检查手机号响应:', response);
// 如果响应是包装过的,尝试获取实际数据
return response.data ?? response;
} catch (error) {
console.error('检查手机号失败:', error);
if (error.response) {
console.error('错误响应:', error.response);
}
const message = error.response?.data?.message || error.message || '检查手机号失败,请稍后重试';
showToast(message); showToast(message);
throw error; throw error;
} }
@ -71,7 +59,6 @@ export const useUserStore = defineStore('user', () => {
console.log('获取用户信息:', id); console.log('获取用户信息:', id);
const response = await getUserInfo(id); const response = await getUserInfo(id);
console.log('获取用户信息响应:', response); console.log('获取用户信息响应:', response);
// 如果响应是包装过的,尝试获取实际数据
const userData = response.data || response; const userData = response.data || response;
userInfo.value = userData; userInfo.value = userData;
return userData; return userData;
@ -86,10 +73,27 @@ export const useUserStore = defineStore('user', () => {
} }
} }
// 根据手机号获取用户信息
async function getUserInfoByPhoneNumber(phone) {
try {
console.log('根据手机号获取用户信息:', phone);
const response = await getUserInfoByPhone(phone);
console.log('获取用户信息响应:', response);
return response;
} catch (error) {
console.error('获取用户信息失败:', error);
if (error.response) {
console.error('错误响应:', error.response);
}
throw error;
}
}
// 退出登录 // 退出登录
function logout() { function logout() {
const surveyStore = useSurveyStore(); const surveyStore = useSurveyStore();
userId.value = null; userId.value = null;
userInfo.value = null;
localStorage.removeItem('userId'); localStorage.removeItem('userId');
surveyStore.resetSurvey(); surveyStore.resetSurvey();
} }
@ -97,9 +101,9 @@ export const useUserStore = defineStore('user', () => {
return { return {
userId, userId,
userInfo, userInfo,
registerUser, loginOrRegister,
checkPhoneNumber,
fetchUserInfo, fetchUserInfo,
getUserInfoByPhone: getUserInfoByPhoneNumber,
logout, logout,
}; };
}); });

View File

@ -1,6 +1,6 @@
<template> <template>
<div class="register-view"> <div class="register-view">
<van-nav-bar title="用户注册" /> <van-nav-bar title="用户登录" />
<van-form @submit="onSubmit" class="register-form"> <van-form @submit="onSubmit" class="register-form">
<van-cell-group inset> <van-cell-group inset>
@ -34,6 +34,7 @@
:rules="[{ required: true, message: '请选择岗位性质' }]" :rules="[{ required: true, message: '请选择岗位性质' }]"
@click="showPositionTypePicker = true" @click="showPositionTypePicker = true"
/> />
<!-- eslint-disable-next-line vue/no-v-model-argument -->
<van-popup v-model:show="showPositionTypePicker" position="bottom"> <van-popup v-model:show="showPositionTypePicker" position="bottom">
<van-picker <van-picker
:columns="positionTypeOptions" :columns="positionTypeOptions"
@ -47,8 +48,9 @@
<div class="submit-btn"> <div class="submit-btn">
<van-button round block type="primary" native-type="submit"> <van-button round block type="primary" native-type="submit">
注册 登录
</van-button> </van-button>
<p class="tip-text">首次登录的用户将自动完成注册</p>
</div> </div>
</van-form> </van-form>
</div> </div>
@ -79,16 +81,21 @@ const positionTypeOptions = [
{ text: '职能支持岗', value: 'SUPPORT' } { text: '职能支持岗', value: 'SUPPORT' }
]; ];
// //
async function onPhoneBlur() { async function onPhoneBlur() {
if (formData.phone && /^1[3-9]\d{9}$/.test(formData.phone)) { if (formData.phone && /^1[3-9]\d{9}$/.test(formData.phone)) {
try { try {
const isRegistered = await userStore.checkPhoneNumber(formData.phone); const userInfo = await userStore.getUserInfoByPhone(formData.phone);
if (isRegistered) { if (userInfo) {
showToast('该手机号已注册'); //
formData.name = userInfo.name;
formData.positionType = userInfo.positionType;
displayPositionType.value = positionTypeOptions.find(
opt => opt.value === userInfo.positionType
)?.text || '';
} }
} catch (error) { } catch (error) {
console.error('检查手机号失败:', error); console.error('获取用户信息失败:', error);
} }
} }
} }
@ -104,7 +111,7 @@ function onPositionTypeConfirm({ selectedOptions }) {
async function onSubmit() { async function onSubmit() {
try { try {
console.log('开始注册,表单数据:', formData); console.log('开始注册,表单数据:', formData);
const response = await userStore.registerUser(formData); const response = await userStore.loginOrRegister(formData);
console.log('注册成功,响应数据:', response); console.log('注册成功,响应数据:', response);
// 使 showNotify // 使 showNotify
@ -146,4 +153,11 @@ async function onSubmit() {
.submit-btn { .submit-btn {
margin: 16px; margin: 16px;
} }
.tip-text {
font-size: 14px;
color: #999;
text-align: center;
margin-top: 12px;
}
</style> </style>