diff --git a/backend/microservice-common/pom.xml b/backend/microservice-common/pom.xml index c466565..903d0b8 100644 --- a/backend/microservice-common/pom.xml +++ b/backend/microservice-common/pom.xml @@ -28,5 +28,14 @@ spring-beans 5.3.22 + + + com.github.pagehelper + pagehelper-spring-boot-starter + + + com.alibaba.fastjson2 + fastjson2 + diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/enums/EditType.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/enums/EditType.java new file mode 100644 index 0000000..3ca99d4 --- /dev/null +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/enums/EditType.java @@ -0,0 +1,17 @@ +package com.cxyxiaomo.epp.common.enums; + +public enum EditType { + PLAIN_TEXT("plainText"), + INPUT("input"), + SELECT("select"); + + private final String value; + + private EditType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/enums/SearchType.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/enums/SearchType.java new file mode 100644 index 0000000..9e82621 --- /dev/null +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/enums/SearchType.java @@ -0,0 +1,17 @@ +package com.cxyxiaomo.epp.common.enums; + +public enum SearchType { + CAN_NOT_SEARCH(null), + INPUT("input"), + SELECT("select"); + + private final String value; + + private SearchType(String value) { + this.value = value; + } + + public String getValue() { + return value; + } +} diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/Role.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/Role.java new file mode 100644 index 0000000..3634277 --- /dev/null +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/Role.java @@ -0,0 +1,18 @@ +package com.cxyxiaomo.epp.common.pojo; + +import lombok.Data; +import lombok.NoArgsConstructor; +import lombok.experimental.Accessors; + +import java.io.Serializable; + +// 数据库关系映射 + +@Data +@NoArgsConstructor +@Accessors(chain = true) // 链式写法 +// 微服务必须要实现Serializable +public class Role implements Serializable { + private Integer id; + private String roleName; +} diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/User.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/User.java index a805fa0..55d3614 100644 --- a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/User.java +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/pojo/User.java @@ -20,7 +20,7 @@ public class User implements Serializable { private String realname; private String idNumber; private String phoneNumber; - private Integer role; + private Integer roleId; private String buildingId; private String doorplate; private String permission; diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/query/PageQuery.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/query/PageQuery.java new file mode 100644 index 0000000..d22f711 --- /dev/null +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/query/PageQuery.java @@ -0,0 +1,27 @@ +package com.cxyxiaomo.epp.common.query; + +import lombok.Getter; + +@Getter +public class PageQuery { + + private int pageIndex = 1; // 第几页 + private int pageSize = 10; // 每页几条数据 + + public void setPageIndex(int page) { + if (page < 1) { + page = 1; + } + this.pageIndex = page; + } + + public void setPageSize(int pageSize) { + if (pageSize < 1) { + pageSize = 1; + } + if (pageSize > 20) { + pageSize = 20; + } + this.pageSize = pageSize; + } +} diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/utils/PageTableFieldBuilder.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/utils/PageTableFieldBuilder.java new file mode 100644 index 0000000..020d241 --- /dev/null +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/utils/PageTableFieldBuilder.java @@ -0,0 +1,58 @@ +package com.cxyxiaomo.epp.common.utils; + +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.cxyxiaomo.epp.common.enums.EditType; +import com.cxyxiaomo.epp.common.enums.SearchType; + +public class PageTableFieldBuilder { + + private JSONArray columns; + + public static PageTableFieldBuilder create() { + PageTableFieldBuilder builder = new PageTableFieldBuilder(); + builder.columns = new JSONArray(); + return builder; + } + + /** + * @param field 对应 POJO 中的属性名称
+ * 用于新增/修改弹窗
+ * @param prop 显示的字段名 如果需要翻译(例如roleId->roleName)则填写翻译后的字段
+ * 用于渲染表格时指定显示列
+ * @param label 列的显示名称
+ * @param canSearch 该字段能否在表格上方被筛选
+ * @param searchType 该筛选字段显示为什么类型
+ * @param canEdit 该字段能否在新增/修改弹窗中被修改
+ * @param editType 新增/修改弹窗中该字段显示为什么类型
+ * @param defaultWhenAdd 新增弹窗中的默认值
+ * @return + */ + public PageTableFieldBuilder add(String field, String prop, String label, + Boolean canSearch, SearchType searchType, + Boolean canEdit, EditType editType, Object defaultWhenAdd) { + JSONObject jsonObject = new JSONObject(2); + // 表格数据 + jsonObject.put("prop", prop); + jsonObject.put("label", label); + + // 上方筛选条件 + jsonObject.put("canSearch", canSearch); + jsonObject.put("searchType", searchType.getValue()); + + // 新增、修改弹窗 + jsonObject.put("field", field); + jsonObject.put("canEdit", canEdit); + jsonObject.put("editType", editType.getValue()); + + // 新增弹窗 字段默认值 + jsonObject.put("default", defaultWhenAdd); + + columns.add(jsonObject); + return this; + } + + public JSONArray build() { + return columns; + } +} diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/utils/PageTableFieldMapperBuilder.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/utils/PageTableFieldMapperBuilder.java new file mode 100644 index 0000000..e972085 --- /dev/null +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/utils/PageTableFieldMapperBuilder.java @@ -0,0 +1,42 @@ +package com.cxyxiaomo.epp.common.utils; + +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; + +import java.util.HashMap; + +public class PageTableFieldMapperBuilder { + + private JSONArray columns; + + public static PageTableFieldMapperBuilder create() { + PageTableFieldMapperBuilder builder = new PageTableFieldMapperBuilder(); + builder.columns = new JSONArray(); + return builder; + } + + // public PageTableFieldMapperBuilder add(String prop, String label, List mapper) { + // if (mapper == null || mapper.size() == 0) { + // return this; + // } + // JSONObject jsonObject = new JSONObject(2); + // jsonObject.put("key", prop); + // jsonObject.put("value", label); + // jsonObject.put("mapper", mapper); + // columns.add(jsonObject); + // return this; + // } + + public PageTableFieldMapperBuilder add(String prop, String label, HashMap mapper) { + JSONObject jsonObject = new JSONObject(2); + jsonObject.put("key", prop); + jsonObject.put("value", label); + jsonObject.put("mapper", mapper); + columns.add(jsonObject); + return this; + } + + public JSONArray build() { + return columns; + } +} diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/utils/PageUtils.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/utils/PageUtils.java new file mode 100644 index 0000000..bfce4f8 --- /dev/null +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/utils/PageUtils.java @@ -0,0 +1,32 @@ +package com.cxyxiaomo.epp.common.utils; + +import com.github.pagehelper.PageInfo; +import org.springframework.beans.BeanUtils; + +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class PageUtils { + + /** + * 转换PageInfo中的List + * + * @param pageInfoPo 原来的pageInfo + * @param convert 转换方式 + * @param

原来的类型 + * @param 转换后的类型 + * @return 转换后的pageInfo + */ + public static PageInfo convert(PageInfo

pageInfoPo, Function convert) { + //视图pageInfo + PageInfo vPageInfo = new PageInfo<>(); + //copy属性 + BeanUtils.copyProperties(pageInfoPo, vPageInfo); + //转化 + List vList = pageInfoPo.getList().stream().map(convert).collect(Collectors.toList()); + //赋值 + vPageInfo.setList(vList); + return vPageInfo; + } +} diff --git a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/UserVO.java b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/UserVO.java index 98da3bb..0cd8ba4 100644 --- a/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/UserVO.java +++ b/backend/microservice-common/src/main/java/com/cxyxiaomo/epp/common/vo/UserVO.java @@ -8,6 +8,8 @@ import org.springframework.beans.BeanUtils; import java.io.Serializable; import java.time.LocalDateTime; +import java.util.List; +import java.util.stream.Collectors; // 数据库关系映射 @@ -21,7 +23,7 @@ public class UserVO implements Serializable { private String realname; private String idNumber; private String phoneNumber; - private Integer role; + private Integer roleId; private String buildingId; private String doorplate; private String permission; @@ -35,4 +37,12 @@ public class UserVO implements Serializable { BeanUtils.copyProperties(user, userVO); return userVO; } + + public static List convertFrom(List userList) { + if (userList == null) { + return null; + } + List userVOList = userList.stream().map(UserVO::convertFrom).collect(Collectors.toList()); + return userVOList; + } } diff --git a/backend/microservice-provider-user-8001/pom.xml b/backend/microservice-provider-user-8001/pom.xml index bfa0d1d..f27fa54 100644 --- a/backend/microservice-provider-user-8001/pom.xml +++ b/backend/microservice-provider-user-8001/pom.xml @@ -82,6 +82,16 @@ spring-cloud-starter-alibaba-nacos-discovery + + + com.github.pagehelper + pagehelper-spring-boot-starter + + + com.alibaba.fastjson2 + fastjson2 + + commons-codec @@ -89,11 +99,10 @@ - - - - - + + org.springframework.boot + spring-boot-devtools + diff --git a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/controller/UserController.java b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/controller/UserController.java index fa29739..7bb9570 100644 --- a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/controller/UserController.java +++ b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/controller/UserController.java @@ -1,25 +1,37 @@ package com.cxyxiaomo.epp.user.controller; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; +import com.cxyxiaomo.epp.common.enums.EditType; +import com.cxyxiaomo.epp.common.enums.SearchType; +import com.cxyxiaomo.epp.common.pojo.Role; import com.cxyxiaomo.epp.common.pojo.User; +import com.cxyxiaomo.epp.common.query.PageQuery; import com.cxyxiaomo.epp.common.response.Res; +import com.cxyxiaomo.epp.common.utils.PageTableFieldBuilder; +import com.cxyxiaomo.epp.common.utils.PageTableFieldMapperBuilder; import com.cxyxiaomo.epp.common.vo.UserVO; -import com.cxyxiaomo.epp.user.service.UserServiceImpl; +import com.cxyxiaomo.epp.user.service.RoleService; +import com.cxyxiaomo.epp.user.service.UserService; +import com.github.pagehelper.PageHelper; +import com.github.pagehelper.PageInfo; import org.apache.commons.codec.digest.DigestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.*; import java.util.HashMap; +import java.util.List; @Controller @RequestMapping("/user") public class UserController { @Autowired - private UserServiceImpl userService; + private UserService userService; + + @Autowired + private RoleService roleService; /** * 用户登录 @@ -58,6 +70,71 @@ public class UserController { return userService.getUserById(id); } + /** + * 获取用户列表 + * + * @return + */ + @GetMapping("/manage/getUserList") + @ResponseBody + public Res getUserList(PageQuery pageQuery, UserVO userVO) { + + // 查询分页数据 + PageHelper.startPage(pageQuery.getPageIndex(), pageQuery.getPageSize()); + List userList = userService.getUserList(userVO); + PageInfo userPageInfo = new PageInfo<>(userList); + List list = userPageInfo.getList(); + List voList = UserVO.convertFrom(list); + + // 指定前端表格显示列 + JSONArray columns = PageTableFieldBuilder.create() + .add("username", "username", "用户名", + true, SearchType.INPUT, + false, EditType.PLAIN_TEXT, null) + .add("roleId", "roleName", "角色", + true, SearchType.SELECT, + true, EditType.SELECT, 0) + .add("realname", "realname", "真实姓名", + true, SearchType.INPUT, + true, EditType.INPUT, "") + .add("phoneNumber", "phoneNumber", "电话", + true, SearchType.INPUT, + true, EditType.INPUT, "") + .add("idNumber", "idNumber", "身份证号", + true, SearchType.INPUT, + true, EditType.INPUT, "") + .add("buildingId", "buildingId", "门栋/单元号", + true, SearchType.INPUT, + true, EditType.INPUT, "") + .add("doorplate", "doorplate", "门牌号", + true, SearchType.INPUT, + true, EditType.INPUT, "") + .build(); + + // 指定需要翻译的字段 + // role -> roleName + List roleList = roleService.getRoleList(); + HashMap roleMap = new HashMap(); + for (Role role : roleList) { + roleMap.put(role.getId(), role.getRoleName()); + } + // build + JSONArray fieldMapper = PageTableFieldMapperBuilder.create() + .add("roleId", "roleName", roleMap) + .build(); + + // 拼装返回结果 + JSONObject map = new JSONObject(2); + map.put("total", userPageInfo.getTotal()); + map.put("list", voList); + map.put("columns", columns); + map.put("fieldMapper", fieldMapper); + + // 返回结果 + return Res.success(map); + } + + @RequestMapping("/person") @ResponseBody public User person(String username) { diff --git a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/dao/RoleDao.java b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/dao/RoleDao.java new file mode 100644 index 0000000..6a79466 --- /dev/null +++ b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/dao/RoleDao.java @@ -0,0 +1,14 @@ +package com.cxyxiaomo.epp.user.dao; + +import com.cxyxiaomo.epp.common.pojo.Role; +import org.apache.ibatis.annotations.Mapper; +import org.springframework.stereotype.Repository; + +import java.util.List; + +@Mapper +@Repository +public interface RoleDao { + + public List getRoleList(); +} diff --git a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/dao/UserDao.java b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/dao/UserDao.java index 8188446..83fe076 100644 --- a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/dao/UserDao.java +++ b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/dao/UserDao.java @@ -1,9 +1,12 @@ package com.cxyxiaomo.epp.user.dao; import com.cxyxiaomo.epp.common.pojo.User; +import com.cxyxiaomo.epp.common.vo.UserVO; import org.apache.ibatis.annotations.Mapper; import org.springframework.stereotype.Repository; +import java.util.List; + @Mapper @Repository public interface UserDao { @@ -13,4 +16,6 @@ public interface UserDao { public User getUserById(Long id); User getUserByUsername(String username); + + public List getUserList(UserVO userVO); } diff --git a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/service/RoleService.java b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/service/RoleService.java new file mode 100644 index 0000000..c9f15d7 --- /dev/null +++ b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/service/RoleService.java @@ -0,0 +1,20 @@ +package com.cxyxiaomo.epp.user.service; + +import com.cxyxiaomo.epp.common.pojo.Role; +import com.cxyxiaomo.epp.user.dao.RoleDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class RoleService { + + @Autowired + private RoleDao roleDao; + + public List getRoleList() { + List roleList = roleDao.getRoleList(); + return roleList; + } +} diff --git a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/service/UserService.java b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/service/UserService.java index b45c815..1ad9a4d 100644 --- a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/service/UserService.java +++ b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/service/UserService.java @@ -1,10 +1,29 @@ package com.cxyxiaomo.epp.user.service; import com.cxyxiaomo.epp.common.pojo.User; +import com.cxyxiaomo.epp.common.vo.UserVO; +import com.cxyxiaomo.epp.user.dao.UserDao; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; -public interface UserService { +import java.util.List; - User getUserByUsername(String username); +@Service +public class UserService { - User getUserById(Long id); + @Autowired + private UserDao userDao; + + public User getUserByUsername(String username) { + return userDao.getUserByUsername(username); + } + + public User getUserById(Long id) { + return userDao.getUserById(id); + } + + public List getUserList(UserVO userVO) { + List userList = userDao.getUserList(userVO); + return userList; + } } diff --git a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/service/UserServiceImpl.java b/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/service/UserServiceImpl.java deleted file mode 100644 index c53d533..0000000 --- a/backend/microservice-provider-user-8001/src/main/java/com/cxyxiaomo/epp/user/service/UserServiceImpl.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.cxyxiaomo.epp.user.service; - -import com.cxyxiaomo.epp.common.pojo.User; -import com.cxyxiaomo.epp.user.dao.UserDao; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.stereotype.Service; - -@Service -public class UserServiceImpl implements UserService { - - @Autowired - private UserDao userDao; - - @Override - public User getUserByUsername(String username) { - return userDao.getUserByUsername(username); - } - - @Override - public User getUserById(Long id) { - return userDao.getUserById(id); - } -} diff --git a/backend/microservice-provider-user-8001/src/main/resources/mybatis/mapper/RoleMapper.xml b/backend/microservice-provider-user-8001/src/main/resources/mybatis/mapper/RoleMapper.xml new file mode 100644 index 0000000..d202cb1 --- /dev/null +++ b/backend/microservice-provider-user-8001/src/main/resources/mybatis/mapper/RoleMapper.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/backend/microservice-provider-user-8001/src/main/resources/mybatis/mapper/UserMapper.xml b/backend/microservice-provider-user-8001/src/main/resources/mybatis/mapper/UserMapper.xml index 9c5917b..2576600 100644 --- a/backend/microservice-provider-user-8001/src/main/resources/mybatis/mapper/UserMapper.xml +++ b/backend/microservice-provider-user-8001/src/main/resources/mybatis/mapper/UserMapper.xml @@ -8,10 +8,39 @@ VALUES (#{username}, #{password}) + diff --git a/backend/pom.xml b/backend/pom.xml index c15df97..ca1b5fa 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -135,6 +135,13 @@ 2.7.6 + + + com.github.pagehelper + pagehelper-spring-boot-starter + 1.4.6 + + com.alibaba.fastjson2 diff --git a/database/epp.sql b/database/epp.sql index 8d4d63d..71502aa 100644 --- a/database/epp.sql +++ b/database/epp.sql @@ -11,7 +11,7 @@ Target Server Version : 80012 File Encoding : 65001 - Date: 28/03/2023 13:51:00 + Date: 28/03/2023 22:11:06 */ SET NAMES utf8mb4; @@ -348,6 +348,26 @@ INSERT INTO `report` VALUES (59, 3, '用户 密码user', '2023-03-17 00:27:21', INSERT INTO `report` VALUES (60, 3, '用户 密码user', '2023-03-20 00:47:22', '0', '湖北省武汉市武昌区武车路'); INSERT INTO `report` VALUES (61, 3, '用户 密码user', '2023-03-23 22:24:14', '0', '湖北省武汉市武昌区修远路'); +-- ---------------------------- +-- Table structure for role +-- ---------------------------- +DROP TABLE IF EXISTS `role`; +CREATE TABLE `role` ( + `id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'role_id', + `role_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT 'roleName', + PRIMARY KEY (`id`) USING BTREE +) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; + +-- ---------------------------- +-- Records of role +-- ---------------------------- +INSERT INTO `role` VALUES (1, '系统管理员'); +INSERT INTO `role` VALUES (2, '社区管理员'); +INSERT INTO `role` VALUES (3, '社区居民_房主'); +INSERT INTO `role` VALUES (4, '社区居民_家庭成员'); +INSERT INTO `role` VALUES (5, '社区居民_租客'); +INSERT INTO `role` VALUES (6, '访客'); + -- ---------------------------- -- Table structure for setting -- ---------------------------- @@ -375,20 +395,30 @@ CREATE TABLE `user` ( `realname` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '真实姓名', `id_number` varchar(18) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '身份证号', `phone_number` varchar(11) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '手机号', - `role` int(11) NOT NULL COMMENT '角色 (1-超级管理员 2-工作人员 3-社区居民_房主 4-社区居民_家庭成员 5-社区居民_租客 6-访客)', + `role_id` int(11) NOT NULL COMMENT '角色id', `building_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '门栋号+单元号', `doorplate` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '门牌号', `permission` int(11) NOT NULL DEFAULT 0 COMMENT '进出权限 (0-无 1-继承(普通居民) 2-永久 3-限时)', `permission_time` datetime NULL DEFAULT NULL COMMENT '进出权限失效时间', - PRIMARY KEY (`id`) USING BTREE + PRIMARY KEY (`id`) USING BTREE, + UNIQUE INDEX `username`(`username`) USING BTREE ) ENGINE = InnoDB AUTO_INCREMENT = 4 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = DYNAMIC; -- ---------------------------- -- Records of user -- ---------------------------- -INSERT INTO `user` VALUES (1, 'root', '99adc231b045331e514a516b4b7680f588e3823213abe901738bc3ad67b2f6fcb3c64efb93d18002588d3ccc1a49efbae1ce20cb43df36b38651f11fa75678e8', '管理员 密码root', '420111111111111111', NULL, 1, NULL, NULL, 0, NULL); -INSERT INTO `user` VALUES (2, 'admin', 'c7ad44cbad762a5da0a452f9e854fdc1e0e7a52a38015f23f3eab1d80b931dd472634dfac71cd34ebc35d16ab7fb8a90c81f975113d6c7538dc69dd8de9077ec', '社区管理员 密码admin', '420111111111111111', NULL, 2, NULL, NULL, 0, NULL); -INSERT INTO `user` VALUES (3, 'user', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户 密码user', '420111111111111111', NULL, 3, NULL, NULL, 0, NULL); +INSERT INTO `user` VALUES (1, 'root', '99adc231b045331e514a516b4b7680f588e3823213abe901738bc3ad67b2f6fcb3c64efb93d18002588d3ccc1a49efbae1ce20cb43df36b38651f11fa75678e8', '管理员 密码root', '420111111111111111', '110', 1, '28-1', '1101', 0, NULL); +INSERT INTO `user` VALUES (2, 'admin', 'c7ad44cbad762a5da0a452f9e854fdc1e0e7a52a38015f23f3eab1d80b931dd472634dfac71cd34ebc35d16ab7fb8a90c81f975113d6c7538dc69dd8de9077ec', '社区管理员 密码admin', '420111111111111111', '111', 2, '16-3', '0203', 0, NULL); +INSERT INTO `user` VALUES (3, 'user', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户 密码user', '420111111111111111', '112', 3, '20-2', '0802', 0, NULL); +INSERT INTO `user` VALUES (4, 'user2', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户2 密码user', '420111111111111111', '112', 3, '20-2', '0802', 0, NULL); +INSERT INTO `user` VALUES (5, 'user3', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户3 密码user', '420111111111111111', '112', 3, '20-2', '0802', 0, NULL); +INSERT INTO `user` VALUES (6, 'user4', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户4 密码user', '420111111111111111', '112', 3, '20-2', '0802', 0, NULL); +INSERT INTO `user` VALUES (7, 'user5', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户5 密码user', '420111111111111111', '112', 3, '20-2', '0802', 0, NULL); +INSERT INTO `user` VALUES (8, 'user6', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户6 密码user', '420111111111111111', '112', 3, '20-2', '0802', 0, NULL); +INSERT INTO `user` VALUES (9, 'user7', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户7 密码user', '420111111111111111', '112', 3, '20-2', '0802', 0, NULL); +INSERT INTO `user` VALUES (10, 'user8', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户8 密码user', '420111111111111111', '112', 3, '20-2', '0802', 0, NULL); +INSERT INTO `user` VALUES (11, 'user9', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户9 密码user', '420111111111111111', '112', 3, '20-2', '0802', 0, NULL); +INSERT INTO `user` VALUES (12, 'user10', 'b14361404c078ffd549c03db443c3fede2f3e534d73f78f77301ed97d4a436a9fd9db05ee8b325c0ad36438b43fec8510c204fc1c1edb21d0941c00e9e2c1ce2', '用户10 密码user', '420111111111111111', '112', 3, '20-2', '0802', 0, NULL); -- ---------------------------- -- Table structure for visitor1 diff --git a/frontend/components.d.ts b/frontend/components.d.ts index a72999d..858af70 100644 --- a/frontend/components.d.ts +++ b/frontend/components.d.ts @@ -51,6 +51,7 @@ declare module '@vue/runtime-core' { ElTree: typeof import('element-plus/es')['ElTree'] ElUpload: typeof import('element-plus/es')['ElUpload'] Header: typeof import('./src/components/header.vue')['default'] + ManageList: typeof import('./src/components/manage-list.vue')['default'] Popover: typeof import('./src/components/popover.vue')['default'] RouterLink: typeof import('vue-router')['RouterLink'] RouterView: typeof import('vue-router')['RouterView'] diff --git a/frontend/src/api/user.js b/frontend/src/api/user.js index fcdd613..04f0ede 100644 --- a/frontend/src/api/user.js +++ b/frontend/src/api/user.js @@ -12,6 +12,26 @@ export function userLogin({ username, password }) { params: { "username": username, "password": password, - } + }, + }); +}; + +/** + * 用户退出登录 + * @returns + */ +export function userLogout() { + return null; +}; + +/** + * 获取用户列表 + * @returns + */ +export function getUserList(params) { + return send_request({ + url: '/user/manage/getUserList', + method: 'GET', + params: params, }); }; diff --git a/frontend/src/components/header.vue b/frontend/src/components/header.vue index 5cd228e..27d861f 100644 --- a/frontend/src/components/header.vue +++ b/frontend/src/components/header.vue @@ -52,6 +52,7 @@ import { ElMessage } from 'element-plus'; import send_request from '../utils/send_request'; import imgurl from '../assets/img/img.jpg'; import settings from '../utils/settings'; +import * as userApi from '../api/user'; const username: string | null = localStorage.getItem('ms_username'); const message: number = 2; @@ -74,10 +75,7 @@ const router = useRouter(); const handleCommand = (command: string) => { if (command == 'loginout') { // 发送退出登录请求 - send_request({ - url: 'v1/user/logout', - method: "POST", - } as any); + userApi.userLogout() // 关闭全部标签 (销毁页面对象) const tags = useTagsStore(); tags.clearTags(); diff --git a/frontend/src/components/manage-list.vue b/frontend/src/components/manage-list.vue new file mode 100644 index 0000000..4ab7483 --- /dev/null +++ b/frontend/src/components/manage-list.vue @@ -0,0 +1,305 @@ + + + + + diff --git a/frontend/src/main.ts b/frontend/src/main.ts index 79a66ff..2fe3d6f 100644 --- a/frontend/src/main.ts +++ b/frontend/src/main.ts @@ -20,8 +20,9 @@ for (const [key, component] of Object.entries(ElementPlusIconsVue)) { const permiss = usePermissStore(); app.directive('permiss', { // 元素级权限控制 mounted(el, binding) { - const role = localStorage.getItem('ms_role_id'); - if (!permiss[role as string] || !permiss[role as string].includes(binding.value as string)) { + const roleId = localStorage.getItem('ms_role_id'); + const currentUserPermiss = permiss[roleId as string]; + if (!currentUserPermiss || !currentUserPermiss.includes(binding.value as string)) { el['hidden'] = true; } }, diff --git a/frontend/src/router/index.ts b/frontend/src/router/index.ts index 8bc74b6..92cf19a 100644 --- a/frontend/src/router/index.ts +++ b/frontend/src/router/index.ts @@ -199,9 +199,9 @@ const router = createRouter({ router.beforeEach((to, from, next) => { document.title = `${to.meta.title} | ${settings.siteTitle}`; const username = localStorage.getItem('ms_username'); - const role = localStorage.getItem('ms_role_id'); + const roleId = localStorage.getItem('ms_role_id'); const permiss = usePermissStore(); - const currentUserPermiss = permiss[role as string]; + const currentUserPermiss = permiss[roleId as string]; // console.log("currentUserPermiss", currentUserPermiss) if (!username && to.path !== '/login') { next({ diff --git a/frontend/src/views/login.vue b/frontend/src/views/login.vue index 1549221..2413d1e 100644 --- a/frontend/src/views/login.vue +++ b/frontend/src/views/login.vue @@ -121,7 +121,7 @@ const submitForm = (formEl: FormInstance | undefined) => { localStorage.setItem('ms_username', data.userInfo?.username); localStorage.setItem('ms_realname', data.userInfo?.realname); localStorage.setItem('ms_user_id', data.userInfo?.id); - localStorage.setItem('ms_role_id', data.userInfo?.role); + localStorage.setItem('ms_role_id', data.userInfo?.roleId); let targetRoute: any = router.currentRoute?.value?.query?.redirectTo if (targetRoute && !targetRoute.includes('/login')) { diff --git a/frontend/src/views/privilege-user-setting.vue b/frontend/src/views/privilege-user-setting.vue index 03d0bbc..fd3d60e 100644 --- a/frontend/src/views/privilege-user-setting.vue +++ b/frontend/src/views/privilege-user-setting.vue @@ -1,221 +1,11 @@ - - diff --git a/postman-collection/epp.postman_collection.json b/postman-collection/epp.postman_collection.json index d3a3230..5dcbaea 100644 --- a/postman-collection/epp.postman_collection.json +++ b/postman-collection/epp.postman_collection.json @@ -130,6 +130,49 @@ } }, "response": [] + }, + { + "name": "[微服务] 管理后台 获取用户列表", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://localhost:8001/user/manage/getUserList", + "protocol": "http", + "host": [ + "localhost" + ], + "port": "8001", + "path": [ + "user", + "manage", + "getUserList" + ] + } + }, + "response": [] + }, + { + "name": "[线上] 管理后台 获取用户列表", + "request": { + "method": "GET", + "header": [], + "url": { + "raw": "http://epp.only4.work/user/manage/getUserList", + "protocol": "http", + "host": [ + "epp", + "only4", + "work" + ], + "path": [ + "user", + "manage", + "getUserList" + ] + } + }, + "response": [] } ] }, diff --git a/weixin-miniprogram/pages/index/index.js b/weixin-miniprogram/pages/index/index.js index 84d4ad3..fdcbe36 100644 --- a/weixin-miniprogram/pages/index/index.js +++ b/weixin-miniprogram/pages/index/index.js @@ -32,7 +32,7 @@ Page({ return } else { // 用户已登录 - let userGroup = getUserGroupByRole(userInfo.role) + let userGroup = getUserGroupByRole(userInfo.roleId) this.setData({ debugText: JSON.stringify(options, null, 4), userInfo: userInfo, diff --git a/weixin-miniprogram/pages/index/login.js b/weixin-miniprogram/pages/index/login.js index 91e2406..5f0faf5 100644 --- a/weixin-miniprogram/pages/index/login.js +++ b/weixin-miniprogram/pages/index/login.js @@ -114,13 +114,13 @@ Page({ let result = d.data; if (result.success) { // 登录成功 - if ([3, 4, 5, 6].includes(result.data.userInfo.role)) { + if (![3, 4, 5, 6].includes(result.data.userInfo.roleId)) { wx.showModal({ title: '你不是社区居民', content: '管理员请前往网页版登录', showCancel: false, complete: (res) => { - // + // } }) return diff --git a/weixin-miniprogram/utils/const.js b/weixin-miniprogram/utils/const.js index b093d86..813f8f4 100644 --- a/weixin-miniprogram/utils/const.js +++ b/weixin-miniprogram/utils/const.js @@ -1,12 +1,12 @@ module.exports = { user: { role: { - ADMIN: 0, - STAFF: 1, - RESIDENTS_OWNER: 2, - RESIDENTS_MEMBER: 3, - RESIDENTS_TENENT: 4, - VISITOR: 5 + ADMIN: 1, + STAFF: 2, + RESIDENTS_OWNER: 3, + RESIDENTS_MEMBER: 4, + RESIDENTS_TENENT: 5, + VISITOR: 6 } } }