From 4e41638b2ca7efb5b7dcd21097067197d0314e91 Mon Sep 17 00:00:00 2001 From: dchaofei Date: Thu, 17 Jan 2019 16:50:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=89=8D=E7=AB=AF=E6=A3=80=E6=9F=A5=E8=A7=92?= =?UTF-8?q?=E8=89=B2=E5=90=8D=E7=A7=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.go | 1 + module/user/group.go | 15 +++++++++++ route/handler.go | 1 + service/user/priv.go | 2 ++ web/src/api/user.js | 4 +++ web/src/views/user/Group.vue | 2 +- web/src/views/user/GroupUpdateComponent.js | 30 +++++++++++++++++++++- 7 files changed, 53 insertions(+), 2 deletions(-) diff --git a/api.go b/api.go index 285172e..03e9f6a 100644 --- a/api.go +++ b/api.go @@ -33,6 +33,7 @@ const ( API_USER_MY_UPDATE = "POST /api/user/my/update" API_USER_MY_PASSWORD = "POST /api/user/my/password" + API_USER_GROUP_EXISTS = "GET /api/user/group/checkexists" API_USER_GROUP_NEW = "POST /api/user/group/new" API_USER_GROUP_UPDATE = "POST /api/user/group/update" API_USER_GROUP_PRIV = "GET /api/user/group/priv" diff --git a/module/user/group.go b/module/user/group.go index 31d25ba..d9d8cb8 100644 --- a/module/user/group.go +++ b/module/user/group.go @@ -84,3 +84,18 @@ func GroupDelete(c *goweb.Context) error { } return syncd.RenderJson(c, nil) } + +func GroupExists(c *goweb.Context) error { + keyword, id := c.Query("keyword"), c.QueryInt("id") + group := userService.Group{ + ID: id, + Name: keyword, + } + exists, err := group.CheckGroupExists() + if err != nil { + return syncd.RenderAppError(err.Error()) + } + return syncd.RenderJson(c, goweb.JSON{ + "exists": exists, + }) +} \ No newline at end of file diff --git a/route/handler.go b/route/handler.go index cb4cbb2..2ce0e30 100644 --- a/route/handler.go +++ b/route/handler.go @@ -56,6 +56,7 @@ func handler() { syncd.API_USER_MY_UPDATE: userModule.MyUpdate, syncd.API_USER_MY_PASSWORD: userModule.MyPasswordUpdate, + syncd.API_USER_GROUP_EXISTS: userModule.GroupExists, syncd.API_USER_GROUP_NEW: userModule.GroupNew, syncd.API_USER_GROUP_UPDATE: userModule.GroupEdit, syncd.API_USER_GROUP_PRIV: userModule.GroupPlainPriv, diff --git a/service/user/priv.go b/service/user/priv.go index 0910f4f..ce04aad 100644 --- a/service/user/priv.go +++ b/service/user/priv.go @@ -44,11 +44,13 @@ var privToApiMap = map[int][]string{ USER_ROLE_NEW: []string{ syncd.API_USER_GROUP_NEW, syncd.API_USER_GROUP_PRIV, + syncd.API_USER_GROUP_EXISTS, }, USER_ROLE_EDIT: []string{ syncd.API_USER_GROUP_PRIV, syncd.API_USER_GROUP_DETAIL, syncd.API_USER_GROUP_UPDATE, + syncd.API_USER_GROUP_EXISTS, }, USER_ROLE_DEL: []string{ syncd.API_USER_GROUP_DELETE, diff --git a/web/src/api/user.js b/web/src/api/user.js index fa581b1..e3af598 100644 --- a/web/src/api/user.js +++ b/web/src/api/user.js @@ -1,5 +1,9 @@ import {get, post} from './fetch.js' +export function checkGroupExistsApi(data) { + return get('/user/group/checkexists', data) +} + export function newGroupApi(data) { return post('/user/group/new', data) } diff --git a/web/src/views/user/Group.vue b/web/src/views/user/Group.vue index 0783150..7bfe7eb 100644 --- a/web/src/views/user/Group.vue +++ b/web/src/views/user/Group.vue @@ -94,7 +94,7 @@ export default { this.dialogDetail = {} }, handleOpenEditDialog(id) { - this.dialogTitle = '编辑服务器信息' + this.dialogTitle = '编辑角色信息' this.dialogVisible = true this.dialogDetail = {} this.getDataDetail(id) diff --git a/web/src/views/user/GroupUpdateComponent.js b/web/src/views/user/GroupUpdateComponent.js index 9cbefb5..e082a81 100644 --- a/web/src/views/user/GroupUpdateComponent.js +++ b/web/src/views/user/GroupUpdateComponent.js @@ -1,5 +1,5 @@ import { Form } from 'ant-design-vue' -import { getPrivListApi } from '@/api/user.js' +import { getPrivListApi, checkGroupExistsApi } from '@/api/user.js' const GroupUpdate = { render() { const { getFieldDecorator, getFieldValue } = this.form @@ -30,16 +30,43 @@ const GroupUpdate = { ) }) + let vm = this + let groupExistsCb = function(type, errmsg) { + return function(rule, value, callback) { + if (!value) { + callback() + return + } + let title = '角色名称' + vm.$set(vm.helps, type, `正在验证 ${value} 是否被占用...`) + checkGroupExistsApi({id: vm.detail.id, keyword: value}).then(res => { + if (!res.exists) { + vm.$set(vm.helps, type, undefined) + callback() + } else { + vm.$set(vm.helps, type, `抱歉!${title}已被占用,请重新输入`) + callback(errmsg) + } + }).catch(err => { + vm.$set(vm.helps, type, '网络错误, 校验失败') + callback('网络错误, 校验失败') + }) + } + } + return ( {getFieldDecorator('name', { rules: [ { required: true, message: '角色名称不能为空' }, + { validator: groupExistsCb('name', '角色名称已经存在')}, ], initialValue: this.detail.name, + validateTrigger: 'blur', })( )} @@ -84,6 +111,7 @@ const GroupUpdate = { indeterminate: false, checkedPrivList: [], plainPrivCheckList: [], + helps: {}, } }, methods: {