From 9a316738e3cab675815bd65ae5fbb0a89f8942d3 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Tue, 18 Feb 2020 22:43:13 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=A8=E6=88=B7=E5=88=97=E8=A1=A8=E5=88=86?= =?UTF-8?q?=E9=A1=B5=E5=92=8C=E7=BB=84=E7=BB=87=E5=88=97=E8=A1=A8=E5=88=86?= =?UTF-8?q?=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/OrganizationController.java | 11 +- .../controller/UserController.java | 9 +- .../components/settings/Organization.vue | 226 +++++++++----- .../performance/components/settings/User.vue | 293 ++++++++++-------- 4 files changed, 329 insertions(+), 210 deletions(-) diff --git a/backend/src/main/java/io/metersphere/controller/OrganizationController.java b/backend/src/main/java/io/metersphere/controller/OrganizationController.java index 85e635da9b..1a8cd6795e 100644 --- a/backend/src/main/java/io/metersphere/controller/OrganizationController.java +++ b/backend/src/main/java/io/metersphere/controller/OrganizationController.java @@ -1,9 +1,12 @@ package io.metersphere.controller; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.Organization; +import io.metersphere.commons.utils.PageUtils; +import io.metersphere.commons.utils.Pager; import io.metersphere.service.OrganizationService; import org.springframework.web.bind.annotation.*; - import javax.annotation.Resource; import java.util.List; @@ -20,6 +23,12 @@ public class OrganizationController { @GetMapping("/list") public List getOrganizationList() { return organizationService.getOrganizationList(); } + @PostMapping("/list/{goPage}/{pageSize}") + public Pager> getUserList(@PathVariable int goPage, @PathVariable int pageSize) { + Page page = PageHelper.startPage(goPage, pageSize, true); + return PageUtils.setPageInfo(page, organizationService.getOrganizationList()); + } + @GetMapping("/delete/{organizationId}") public void deleteOrganization(@PathVariable(value = "organizationId") String organizationId) { organizationService.deleteOrganization(organizationId); } diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index d68f14d03f..735d326dbe 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -4,7 +4,6 @@ import com.github.pagehelper.Page; import com.github.pagehelper.PageHelper; import io.metersphere.base.domain.Role; import io.metersphere.base.domain.User; -import io.metersphere.commons.constants.RoleConstants; import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.controller.request.member.AddMemberRequest; @@ -13,9 +12,7 @@ import io.metersphere.dto.UserDTO; import io.metersphere.dto.UserRoleDTO; import io.metersphere.service.UserService; import io.metersphere.user.SessionUtils; -import org.apache.shiro.authz.annotation.RequiresRoles; import org.springframework.web.bind.annotation.*; - import javax.annotation.Resource; import java.util.List; @@ -36,6 +33,12 @@ public class UserController { return userService.getUserList(); } + @PostMapping("/list/{goPage}/{pageSize}") + public Pager> getUserList(@PathVariable int goPage, @PathVariable int pageSize) { + Page page = PageHelper.startPage(goPage, pageSize, true); + return PageUtils.setPageInfo(page, userService.getUserList()); + } + @GetMapping("/delete/{userId}") public void deleteUser(@PathVariable(value = "userId") String userId) { userService.deleteUser(userId); diff --git a/frontend/src/performance/components/settings/Organization.vue b/frontend/src/performance/components/settings/Organization.vue index 9a6fc32667..56652e8fd2 100644 --- a/frontend/src/performance/components/settings/Organization.vue +++ b/frontend/src/performance/components/settings/Organization.vue @@ -13,16 +13,35 @@ - + + - + + +
+ + +
+ + +
+
+
+
@@ -62,92 +81,22 @@ export default { name: "MsOrganization", components: {MsCreateBox}, - created() { - this.getOrganizationList(); - }, - methods: { - create() { - this.createVisible = true; - }, - edit(row) { - window.console.log(row); - // this.loading = true; - this.updateVisible = true; - this.form = row; - }, - del(row) { - window.console.log(row); - this.$confirm('此操作将永久删除该组织, 是否继续?', '提示', { - confirmButtonText: '确定', - cancelButtonText: '取消', - type: 'warning' - }).then(() => { - this.$get(`/organization/delete/${row.id}`).then(() => { - this.getOrganizationList() - }); - this.$message({ - type: 'success', - message: '删除成功!' - }); - }).catch(() => { - this.$message({ - type: 'info', - message: '已取消删除' - }); - }); - }, - createOrganization(createOrganizationForm) { - this.$refs[createOrganizationForm].validate( valide => { - if (valide) { - this.$post("/organization/add", this.form) - .then(() => { - this.$message({ - type: 'success', - message: '添加成功!' - }, - this.createVisible = false, - this.getOrganizationList()) - }); - } else { - return false; - } - }) - }, - updateOrganization(udpateOrganizationForm) { - this.$refs[udpateOrganizationForm].validate(valide => { - if (valide) { - this.$post("/organization/update", this.form) - .then(() => { - this.$message({ - type: 'success', - message: '修改成功!' - }, - this.updateVisible = false, - this.getOrganizationList(), - self.loading = false) - }); - } else { - return false; - } - }) - }, - getOrganizationList() { - this.$get("/organization/list").then(response => { - this.items = response.data.data; - }) - }, - closeFunc() { - this.form = {}; - } - }, data() { return { + queryPath: '/organization/list', + deletePath: '/organization/delete/', + createPath: '/organization/add', + updatePath: '/organization/update', loading: false, createVisible: false, updateVisible: false, + multipleSelection: [], + currentPage: 1, + pageSize: 5, + total: 0, btnTips: "添加组织", condition: "", - items: [], + tableData: [], form: {}, rule: { name: [ @@ -165,7 +114,116 @@ ] } } + }, + created() { + this.initTableData(); + }, + methods: { + create() { + this.createVisible = true; + }, + edit(row) { + // this.loading = true; + this.updateVisible = true; + this.form = row; + }, + del(row) { + this.$confirm('是否删除组织' + row.name +' ?', '', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + }).then(() => { + this.$get(this.deletePath + row.id).then(response => { + if (response.data.success) { + this.$message({ + type: 'success', + message: '删除成功!' + }); + } else { + this.$message.error(response.message); + } + this.initTableData() + }); + }).catch(() => { + this.$message({ + type: 'info', + message: '已取消删除' + }); + }); + }, + createOrganization(createOrganizationForm) { + this.$refs[createOrganizationForm].validate( valide => { + if (valide) { + this.$post(this.createPath, this.form) + .then(response => { + if (response.data.success) { + this.$message({ + type: 'success', + message: '添加成功!' + }); + this.initTableData(); + } else { + this.$message.error(response.message); + } + this.createVisible = false; + }); + } else { + return false; + } + }) + }, + updateOrganization(udpateOrganizationForm) { + this.$refs[udpateOrganizationForm].validate(valide => { + if (valide) { + this.$post(this.updatePath, this.form) + .then(response => { + if (response.data.success) { + this.$message({ + type: 'success', + message: '修改成功!' + }); + this.updateVisible = false; + } else { + this.$message.error(response.message); + } + this.initTableData(); + self.loading = false; + }); + } else { + return false; + } + }) + }, + initTableData() { + this.$post(this.buildPagePath(this.queryPath)).then(response => { + if (response.data.success) { + let data = response.data.data; + this.total = data.itemCount; + this.tableData = data.listObject; + } else { + this.$message.error(response.message); + } + }) + }, + closeFunc() { + this.form = {}; + }, + buildPagePath(path) { + return path + "/" + this.currentPage + "/" + this.pageSize; + }, + handleSizeChange(size) { + this.pageSize = size; + this.initTableData(); + }, + handleCurrentChange(current) { + this.currentPage = current; + this.initTableData(); + }, + handleSelectionChange(val) { + this.multipleSelection = val; + } } + } @@ -173,4 +231,10 @@ .search { width: 240px; } + + .table-page { + padding-top: 20px; + margin-right: -9px; + float: right; + } diff --git a/frontend/src/performance/components/settings/User.vue b/frontend/src/performance/components/settings/User.vue index 12efa17805..771a599758 100644 --- a/frontend/src/performance/components/settings/User.vue +++ b/frontend/src/performance/components/settings/User.vue @@ -12,12 +12,13 @@ - - - + + + + - + - - + + + + + +
+ + +
+ + +
+
+
+
+ @@ -61,7 +85,7 @@ - + @@ -85,135 +109,27 @@ import MsCreateBox from "./CreateBox"; export default { - name: "MsUser", - components: {MsCreateBox}, - created() { - this.getUserList(); - }, - methods: { - create() { - this.createVisible = true; - }, - edit(row) { - window.console.log(row); - // this.loading = true; - this.updateVisible = true; - this.form = row; - /*let self = this; - let getUser1 = this.$get("/test/user"); - let getUser2 = this.$get("/test/sleep"); - this.$all([getUser1, getUser2], function (r1, r2) { - window.console.log(r1.data.data, r2.data.data); - self.loading = false; - });*/ - /*this.$post("/update", this.form).then(()=>{ - this.updateVisible = false; - this.getUserList(); - self.loading = false; - })*/ - }, - del(row) { - window.console.log(row); - this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', { - confirmButtonText: '确定', - cancelButtonText: '取消', - type: 'warning' - }).then(() => { - this.$get(`/user/delete/${row.id}`).then(() => { - this.getUserList() - }); - this.$message({ - type: 'success', - message: '删除成功!' - }); - }).catch(() => { - this.$message({ - type: 'info', - message: '已取消删除' - }); - }); - }, - createUser(createUserForm) { - this.$refs[createUserForm].validate(valide => { - if (valide) { - this.$post("/user/add", this.form) - .then(() => { - this.$message({ - type: 'success', - message: '添加成功!' - }, - this.createVisible = false, - this.getUserList()) - }); - } else { - return false; - } - }) - }, - updateUser(updateUserForm) { - this.$refs[updateUserForm].validate(valide => { - if (valide) { - this.$post("/user/update", this.form) - .then(() => { - this.$message({ - type: 'success', - message: '修改成功!' - }, - this.updateVisible = false, - this.getUserList(), - self.loading = false) - }); - } else { - return false; - } - }) - }, - getUserList() { - this.$get("/user/list").then(response => { - this.items = response.data.data; - }) - }, - closeFunc() { - this.form = {}; - }, - changeSwitch(row) { - this.$post('/user/update', row).then(() =>{ - this.$message({ - type: 'success', - message: '状态修改成功!' - }); - }) - }, - formatDate(row) { - let date = new Date(parseInt(row.createTime)); - let Y = date.getFullYear() + '-'; - let M = date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) + '-' : date.getMonth() + 1 + '-'; - let D = date.getDate() < 10 ? '0' + date.getDate() + ' ' : date.getDate() + ' '; - // let h = date.getHours() < 10 ? '0' + date.getHours() + ':' : date.getHours() + ':'; - // let m = date.getMinutes() < 10 ? '0' + date.getMinutes() + ':' : date.getMinutes() + ':'; - // let s = date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds(); - return Y + M + D; - } - }, data() { return { + queryPath: '/user/list', + deletePath: '/user/delete/', + createPath: '/user/add', + updatePath: '/user/update', loading: false, createVisible: false, updateVisible: false, + multipleSelection: [], + currentPage: 1, + pageSize: 5, + total: 0, btnTips: "添加用户", condition: "", - items: [], + tableData: [], form: {}, rule: { id: [ { required: true, message: '请输入ID', trigger: 'blur'}, - { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' }, - { - required: true, - pattern: /^[\u4e00-\u9fa5_a-zA-Z0-9.·-]+$/, - message: 'ID不支持特殊字符', - trigger: 'blur' - } + { min: 2, max: 10, message: '长度在 2 到 10 个字符', trigger: 'blur' } ], name: [ {required: true, message: '请输入姓名', trigger: 'blur'}, @@ -244,6 +160,127 @@ ] } } + }, + name: "MsUser", + components: {MsCreateBox}, + created() { + this.initTableData(); + }, + methods: { + create() { + this.createVisible = true; + }, + edit(row) { + this.updateVisible = true; + this.form = row; + }, + del(row) { + this.$confirm('是否删除用户 ' + row.name + ' ?', '', { + confirmButtonText: '确定', + cancelButtonText: '取消', + type: 'warning' + }).then(() => { + this.$get(this.deletePath + row.id).then(response => { + if (response.data.success) { + this.$message({ + type: 'success', + message: '删除成功!' + }); + this.initTableData() + } else { + this.$message.error(response.message) + } + }); + }).catch(() => { + this.$message({ + type: 'info', + message: '已取消删除' + }); + }); + }, + createUser(createUserForm) { + this.$refs[createUserForm].validate(valide => { + if (valide) { + this.$post(this.createPath, this.form) + .then(response => { + if (response.data.success) { + this.$message({ + type: 'success', + message: '添加成功!' + }); + this.initTableData(); + } else { + this.$message.error(response.message); + } + this.createVisible = false; + }); + } else { + return false; + } + }) + }, + updateUser(updateUserForm) { + this.$refs[updateUserForm].validate(valide => { + if (valide) { + this.$post(this.updatePath, this.form) + .then(response => { + if (response.data.success) { + this.$message({ + type: 'success', + message: '修改成功!' + }); + this.updateVisible = false; + } else { + this.$message.error(response.message); + } + this.initTableData(); + self.loading = false; + }); + } else { + return false; + } + }) + }, + initTableData() { + this.$post(this.buildPagePath(this.queryPath)).then(response => { + if (response.data.success) { + let data = response.data.data; + this.total = data.itemCount; + this.tableData = data.listObject; + } else { + this.$message.error(response.message); + } + }) + }, + closeFunc() { + this.form = {}; + }, + changeSwitch(row) { + this.$post(this.updatePath, row).then(response =>{ + if (response.data.success) { + this.$message({ + type: 'success', + message: '状态修改成功!' + }); + } else { + this.$message.error(response.message); + } + }) + }, + buildPagePath(path) { + return path + "/" + this.currentPage + "/" + this.pageSize; + }, + handleSizeChange(size) { + this.pageSize = size; + this.initTableData(); + }, + handleCurrentChange(current) { + this.currentPage = current; + this.initTableData(); + }, + handleSelectionChange(val) { + this.multipleSelection = val; + } } } @@ -252,4 +289,10 @@ .search { width: 240px; } + + .table-page { + padding-top: 20px; + margin-right: -9px; + float: right; + }