Browse Source

增加删除用户功能 修正一些细节bug

main
pixel 5 years ago
parent
commit
8e8bdc5dc2
  1. 19
      server/api/v1/sys_user.go
  2. 1
      server/router/sys_user.go
  3. 11
      server/service/sys_base_menu.go
  4. 13
      server/service/sys_user.go
  5. 17
      web/src/api/user.js
  6. 217
      web/src/style/main.scss
  7. 2
      web/src/view/superAdmin/api/api.vue
  8. 7
      web/src/view/superAdmin/menu/menu.vue
  9. 24
      web/src/view/superAdmin/user/user.vue

19
server/api/v1/sys_user.go

@ -229,3 +229,22 @@ func SetUserAuthority(c *gin.Context) {
response.OkWithMessage("修改成功", c)
}
}
// @Tags SysUser
// @Summary 删除用户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SetUserAuth true "删除用户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/deleteUser [delete]
func DeleteUser(c *gin.Context) {
var reqId request.GetById
_ = c.ShouldBindJSON(&reqId)
err := service.DeleteUser(reqId.Id)
if err != nil {
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c)
} else {
response.OkWithMessage("删除成功", c)
}
}

1
server/router/sys_user.go

@ -13,5 +13,6 @@ func InitUserRouter(Router *gin.RouterGroup) {
UserRouter.POST("uploadHeaderImg", v1.UploadHeaderImg) //上传头像
UserRouter.POST("getUserList", v1.GetUserList) // 分页获取用户列表
UserRouter.POST("setUserAuthority", v1.SetUserAuthority) //设置用户权限
UserRouter.DELETE("deleteUser", v1.DeleteUser) //删除用户
}
}

11
server/service/sys_base_menu.go

@ -35,6 +35,7 @@ func DeleteBaseMenu(id float64) (err error) {
// @return err errorgetMenu
func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
var oldMenu model.SysBaseMenu
upDateMap := make(map[string]interface{})
upDateMap["keep_alive"] = menu.KeepAlive
upDateMap["default_menu"] = menu.DefaultMenu
@ -46,7 +47,15 @@ func UpdateBaseMenu(menu model.SysBaseMenu) (err error) {
upDateMap["title"] = menu.Title
upDateMap["icon"] = menu.Icon
upDateMap["sort"] = menu.Sort
err = global.GVA_DB.Where("id = ?", menu.ID).Find(&model.SysBaseMenu{}).Updates(upDateMap).Error
db := global.GVA_DB.Where("id = ?", menu.ID).Find(&oldMenu)
if oldMenu.Name != menu.Name {
notSame := global.GVA_DB.Where("id <> ? AND name = ?", menu.ID, menu.Name).First(&model.SysBaseMenu{}).RecordNotFound()
if !notSame {
global.GVA_LOG.Debug("存在相同name修改失败")
return errors.New("存在相同name修改失败")
}
}
err = db.Updates(upDateMap).Error
global.GVA_LOG.Debug("菜单修改时候,关联菜单err:%v", err)
return err
}

13
server/service/sys_user.go

@ -95,6 +95,19 @@ func SetUserAuthority(uuid uuid.UUID, authorityId string) (err error) {
return err
}
// @title SetUserAuthority
// @description set the authority of a certain user, 设置一个用户的权限
// @auth (2020/04/05 20:22)
// @param uuid UUID
// @param authorityId string
// @return err error
func DeleteUser(id float64) (err error) {
var user model.SysUser
err = global.GVA_DB.Where("id = ?", id).Delete(&user).Error
return err
}
// @title UploadHeaderImg
// @description upload avatar, 用户头像上传更新地址
// @auth (2020/04/05 20:22)

17
web/src/api/user.js

@ -78,3 +78,20 @@ export const setUserAuthority = (data) => {
data: data
})
}
// @Tags SysUser
// @Summary 删除用户
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SetUserAuth true "删除用户"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"修改成功"}"
// @Router /user/deleteUser [delete]
export const deleteUser = (data) => {
return service({
url: "/user/deleteUser",
method: 'delete',
data: data
})
}

217
web/src/style/main.scss

@ -530,11 +530,12 @@ ol,
li {
list-style-type: none;
}
.el-table__body-wrapper{
tr{
td{
.cell{
.el-button+.el-button{
.el-table__body-wrapper {
tr {
td {
.cell {
.el-button+.el-button {
margin-left: 0;
}
}
@ -542,42 +543,38 @@ li {
}
}
// navbar
.aside{
.el-scrollbar {
.aside {
.el-scrollbar {
.el-scrollbar__view {
.el-menu-vertical{
.el-menu-vertical {
background-color: #001529;
}
.el-menu-item:hover i,
.el-menu-item:hover span{
color:#fff;
.el-menu-item:hover span {
color: #fff;
}
li{
li {
background-color: #001529;
ul{
.el-menu-item{
ul {
.el-menu-item {
background-color: #000408;
height: 44px;
line-height: 44px;
}
.is-active{
background-color:#1890ff;
.is-active {
background-color: #1890ff;
}
}
}
.el-submenu__title:hover{
.el-submenu__title:hover {
background-color: #001529;
}
.el-submenu__title:hover i,
.el-submenu__title:hover span{
color:#fff;
.el-submenu__title:hover span {
color: #fff;
}
.el-menu--inline{
.el-menu--inline {
border-left: 5px solid #2c3b41;
}
}
@ -585,79 +582,79 @@ li {
}
// layout
.layout-cont{
.main-cont{
.layout-cont {
.main-cont {
position: relative;
&.el-main {
background-color: #ecf0f5;
padding: 0;
}
.breadcrumb{
.breadcrumb {
background-color: #fff;
padding: 0 0 15px 15px;
}
}
}
}
.admin-box {
.admin-box {
padding: 15px 20px;
.el-button{
.el-button {
padding: 7px 10px;
}
.el-input__inner{
.el-input__inner {
height: 30px;
line-height: 30px;
}
.el-input__icon{
.el-input__icon {
line-height: 30px;
}
}
.button-box{
}
.button-box {
background: #fff;
border: 1px solid #ebeef5;
border-bottom: none;
}
}
.search-term{
.search-term {
background: #fff;
padding: 0 15px;
border-left: 1px solid #ebeef5;
border-right: 1px solid #ebeef5;
}
}
// table
.has-gutter{
tr{
th{
.has-gutter {
tr {
th {
background-color: #fafafa;
}
}
}
.el-table--striped{
.el-table__body{
tr.el-table__row--striped{
td{
.el-table--striped {
.el-table__body {
tr.el-table__row--striped {
td {
background: #fff!important;
}
}
}
}
.el-table th, .el-table tr{
.el-table th,
.el-table tr {
background-color: #fafafa;
}
.el-pagination{
.el-pagination {
.btn-prev,
.btn-next{
.btn-next {
border: 1px solid #ddd;
border-radius: 4px;
}
.el-pager{
li{
.el-pager {
li {
color: #666;
font-size: 12px;
margin: 0 5px;
@ -667,85 +664,83 @@ li {
}
}
// el-form
.el-form{
.el-form {
background-color: #fff;
padding: 10px 0;
}
.el-row{
padding: 10px 0;
.el-col>label{
.el-row {
padding: 10px 0;
.el-col>label {
line-height: 30px;
text-align: right;
width: 80%;
padding-right: 15px;
display: inline-block;
}
.line{
.line {
line-height: 30px;
text-align: center;
}
}
// edit_container
.edit_container{
.edit_container {
background-color: #fff;
padding: 15px;
.el-button {
margin: 15px 0;
}
}
.edit{
.edit {
background-color: #fff;
padding: 15px;
.el-button {
margin: 15px 0;
}
}
// upload-demo
.upload-demo,
.upload{
.upload {
background-color: #fff;
padding: 15px;
.el-upload-list__item-status-label{
.el-upload-list__item-status-label {
right: 0;
left: 120px;
}
.el-upload__tip{
.el-upload__tip {
margin: 10px 0;
}
}
// system
.system{
.system {
padding: 15px;
.el-input__inner{
.el-input__inner {
width: 80%;
}
}
// 导航
#app {
.el-container{
.el-container {
position: relative;
height: 100%;
width: 100%;
}
.el-container.mobile.openside {
position: fixed;
top: 0;
}
.hideside{
.aside{
.hideside {
.aside {
width: 54px!important;
}
}
.el-aside{
.el-aside {
-webkit-transition: width .2s;
transition: width .2s;
width: 220px;
@ -759,66 +754,57 @@ li {
z-index: 1001;
overflow: hidden;
}
.mobile.hideside{
.el-aside{
.mobile.hideside {
.el-aside {
// pointer-events: none;
-webkit-transition-duration: .2s;
transition-duration: .2s;
-webkit-transform: translate3d(-210px,0,0);
transform: translate3d(-220px,0,0);
-webkit-transform: translate3d(-210px, 0, 0);
transform: translate3d(-220px, 0, 0);
}
}
.mobile{
.el-aside{
.mobile {
.el-aside {
-webkit-transition: -webkit-transform .28s;
transition: -webkit-transform .28s;
transition: transform .28s;
transition: transform .28s,-webkit-transform .28s;
transition: transform .28s, -webkit-transform .28s;
width: 210px!important
}
}
.el-container{
.el-container {
position: relative;
height: 100%;
width: 100%;
.el-aside{
.el-aside {
// transition: none;
.aside {
background: #000;
.el-menu{
.el-menu {
border-right: none;
}
}
}
}
.main-cont.el-main{
.main-cont.el-main {
min-height: 100%;
-webkit-transition: margin-left .28s;
transition: margin-left .28s;
margin-left: 220px;
position: relative;
}
.hideside{
.main-cont.el-main{
.hideside {
.main-cont.el-main {
margin-left: 54px;
}
}
.mobile {
.main-cont.el-main{
.main-cont.el-main {
margin-left: 0px;
}
}
.openside.mobile{
.shadowBg{
.openside.mobile {
.shadowBg {
background: #000;
opacity: .3;
width: 100%;
@ -829,22 +815,39 @@ li {
left: 0;
}
}
}
.el-menu .el-menu--inline {
background: #2c3b41;
}
.el-submenu .el-submenu {
background-color: #000408 !important;
}
.aside .el-scrollbar .el-scrollbar__view .el-submenu__title:hover {
background-color: #000408 !important;
}
.el-menu--vertical{
.el-menu{
.el-submenu {
.aside .el-scrollbar .el-scrollbar__view .el-submenu__title:hover {
background-color: #000408 !important;
}
}
.el-menu--vertical {
.el-menu {
margin-left: -8px;
background-color:rgb(48,65,86);
.el-menu-item{
background-color:rgb(48,65,86);
background-color: rgb(48, 65, 86);
.el-menu-item {
background-color: rgb(48, 65, 86);
}
.el-menu-item:focus,
.el-menu-item:hover{
.el-menu-item:hover {
background-color: #263445;
color: #fff;
}
}
}
// 导航*****
// 导航*****

2
web/src/view/superAdmin/api/api.vue

@ -259,7 +259,7 @@ export default {
if (res.code == 0) {
this.$message({
type: 'success',
message: '添加成功',
message: '编辑成功',
showClose: true
})
}

7
web/src/view/superAdmin/menu/menu.vue

@ -225,14 +225,9 @@ export default {
if (res.code == 0) {
this.$message({
type: 'success',
message: '添加成功!'
message: this.isEdit?'编辑成功':'添加成功!'
})
this.getTableData()
} else {
this.$message({
type: 'error',
message: '添加失败!'
})
}
this.initForm()
this.dialogFormVisible = false

24
web/src/view/superAdmin/user/user.vue

@ -30,6 +30,21 @@
</el-select>
</template>
</el-table-column>
<el-table-column label="操作" min-width="150">
<template slot-scope="scope">
<el-popover
placement="top"
width="160"
v-model="scope.row.visible">
<p>确定要删除此用户吗</p>
<div style="text-align: right; margin: 0">
<el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button>
<el-button type="primary" size="mini" @click="deleteUser(scope.row)">确定</el-button>
</div>
<el-button type="text" size="small" slot="reference">删除</el-button>
</el-popover>
</template>
</el-table-column>
</el-table>
<el-pagination
:current-page="page"
@ -89,7 +104,7 @@
<script>
// mixins getTableData
const path = process.env.VUE_APP_BASE_API
import { getUserList, setUserAuthority, register } from '@/api/user'
import { getUserList, setUserAuthority, register, deleteUser } from '@/api/user'
import { getAuthorityList } from '@/api/authority'
import infoList from '@/components/mixins/infoList'
import { mapGetters } from 'vuex'
@ -127,6 +142,13 @@ export default {
...mapGetters('user', ['token'])
},
methods: {
async deleteUser(row){
const res = await deleteUser({id:row.ID})
if(res.code == 0){
this.getTableData()
row.visible = false
}
},
getAuthorityList(AuthorityData){
AuthorityData.map(item=>{
this.authOptions.push({

Loading…
Cancel
Save