diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java index 8a6f828232..504860cc92 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.java @@ -14,4 +14,6 @@ public interface ExtUserMapper { String getDefaultLanguage(String paramKey); + List searchUser(String condition); + } diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml index ef7a81a3fe..7fd23b5be4 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtUserMapper.xml @@ -3,23 +3,23 @@ - - - - - - - - - - - + + + + + + + + + + + + + \ No newline at end of file diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index d674014dbd..e4872aee44 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -284,4 +284,10 @@ public class UserController { return userService.getTestManagerAndTestUserList(request); } + @GetMapping("/search/{condition}") + @RequiresRoles(value = {RoleConstants.ADMIN, RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER}, logical = Logical.OR) + public List searchUser(@PathVariable String condition) { + return userService.searchUser(condition); + } + } diff --git a/backend/src/main/java/io/metersphere/service/UserService.java b/backend/src/main/java/io/metersphere/service/UserService.java index f61843832b..0aacecce89 100644 --- a/backend/src/main/java/io/metersphere/service/UserService.java +++ b/backend/src/main/java/io/metersphere/service/UserService.java @@ -384,7 +384,7 @@ public class UserService { userRoleExample.createCriteria().andUserIdEqualTo(userId).andSourceIdEqualTo(request.getOrganizationId()); List userRoles = userRoleMapper.selectByExample(userRoleExample); if (userRoles.size() > 0) { - MSException.throwException(Translator.get("user_already_exists")); + MSException.throwException(Translator.get("user_already_exists") + ": " + userId); } else { for (String roleId : request.getRoleIds()) { UserRole userRole = new UserRole(); @@ -568,4 +568,8 @@ public class UserService { MSException.throwException(msg); return null; } + + public List searchUser(String condition) { + return extUserMapper.searchUser(condition); + } } diff --git a/frontend/src/business/components/settings/organization/OrganizationMember.vue b/frontend/src/business/components/settings/organization/OrganizationMember.vue index aa7a946008..0c5135db61 100644 --- a/frontend/src/business/components/settings/organization/OrganizationMember.vue +++ b/frontend/src/business/components/settings/organization/OrganizationMember.vue @@ -28,23 +28,31 @@ - - + - - + :remote-method="remoteMethod" + :loading="loading"> + + + + + @@ -136,6 +144,9 @@ currentPage: 1, pageSize: 5, total: 0, + options: [], + loading: false, + ids: [] } }, methods: { @@ -165,6 +176,7 @@ }, handleClose() { this.form = {}; + this.options = []; }, edit(row) { this.updateVisible = true; @@ -217,9 +229,9 @@ } this.form = {}; this.createVisible = true; - this.result = this.$get('/user/list/', response => { - this.userList = response.data; - }); + // this.result = this.$get('/user/list/', response => { + // this.userList = response.data; + // }); this.result = this.$get('/role/list/org', response => { this.$set(this.form, "roles", response.data); }) @@ -228,19 +240,8 @@ this.$refs[formName].validate((valid) => { let orgId = this.currentUser().lastOrganizationId; if (valid) { - let userIds = []; - let userId = this.form.userId; - let email = this.form.memberSign; - let member = this.userList.find(user => user.id === email || user.email === email); - if (!member) { - this.$warning(this.$t('member.no_such_user')); - return false; - } else { - userId = member.id; - } - userIds.push(userId); let param = { - userIds: userIds, + userIds: this.form.ids, roleIds: this.form.roleIds, organizationId: orgId }; @@ -254,21 +255,21 @@ } }); }, - querySearch(queryString, cb) { - var userList = this.userList; - var results = queryString ? userList.filter(this.createFilter(queryString)) : userList; - // 调用 callback 返回建议列表的数据 - cb(results); - }, - createFilter(queryString) { - return (user) => { - return (user.email.indexOf(queryString.toLowerCase()) === 0 || user.id.indexOf(queryString.toLowerCase()) === 0); - }; - }, - handleSelect(item) { - this.$set(this.form, "userId", item.id); + remoteMethod(query) { + query = query.trim() + if (query !== '') { + this.loading = true; + setTimeout(() => { + this.loading = false; + this.$get("/user/search/" + query, response => { + this.options = response.data; + }) + }, 200); + } else { + this.options = []; + } } - } + }, }