diff --git a/QMPlusServer/controller/api/menu.go b/QMPlusServer/controller/api/menu.go index c9b3afbc00e6703bb54cdf714b621932f19d9809..44a91c5cf9cca4f73f5413baa1b4155b9f2261aa 100644 --- a/QMPlusServer/controller/api/menu.go +++ b/QMPlusServer/controller/api/menu.go @@ -9,7 +9,7 @@ import ( "main/model/modelInterface" ) -// @Tags Menu +// @Tags authorityAndMenu // @Summary 获取用户动态路由 // @Security ApiKeyAuth // @Produce application/json @@ -27,7 +27,7 @@ func GetMenu(c *gin.Context) { } } -// @Tags authority +// @Tags menu // @Summary 分页获取基础menu列表 // @Security ApiKeyAuth // @accept application/json @@ -51,7 +51,7 @@ func GetMenuList(c *gin.Context) { } } -// @Tags authority +// @Tags menu // @Summary 分页获取基础menu列表 // @Security ApiKeyAuth // @accept application/json @@ -70,7 +70,7 @@ func AddBaseMenu(c *gin.Context) { } } -// @Tags Menu +// @Tags authorityAndMenu // @Summary 获取用户动态路由 // @Security ApiKeyAuth // @Produce application/json @@ -91,7 +91,7 @@ type AddMenuAuthorityInfo struct { AuthorityId string } -// @Tags authority +// @Tags authorityAndMenu // @Summary 增加menu和角色关联关系 // @Security ApiKeyAuth // @accept application/json @@ -114,7 +114,7 @@ type AuthorityIdInfo struct { AuthorityId string } -// @Tags authority +// @Tags authorityAndMenu // @Summary 获取指定角色menu // @Security ApiKeyAuth // @accept application/json @@ -132,3 +132,26 @@ func GetMenuAuthority(c *gin.Context) { servers.ReportFormat(c, true, "获取成功", gin.H{"menus": menus}) } } + + +type IdInfo struct { + Id float64 +} +// @Tags menu +// @Summary 获取指定角色menu +// @Security ApiKeyAuth +// @accept application/json +// @Produce application/json +// @Param data body modelInterface.IdInfo true "删除菜单" +// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}" +// @Router /menu/deleteBaseMenu [post] +func DeleteBaseMenu(c *gin.Context) { + var idInfo IdInfo + _ = c.BindJSON(&idInfo) + err :=new(dbModel.BaseMenu).DeleteBaseMenu(idInfo.Id) + if err != nil { + servers.ReportFormat(c, false, fmt.Sprintf("删除失败:%v", err), gin.H{}) + } else { + servers.ReportFormat(c, true, "删除成功", gin.H{}) + } +} \ No newline at end of file diff --git a/QMPlusServer/model/dbModel/baseMenu.go b/QMPlusServer/model/dbModel/baseMenu.go index 3b3a3c5e6841a72428798a84ed88e08245b4d7dd..4328d8f523c323544e3956c9232f2787c6790451 100644 --- a/QMPlusServer/model/dbModel/baseMenu.go +++ b/QMPlusServer/model/dbModel/baseMenu.go @@ -32,8 +32,14 @@ func (b *BaseMenu) AddBaseMenu() (err error) { return err } -func (b *BaseMenu) DeleteBaseMenu(name string) (err error) { - err = qmsql.DEFAULTDB.Where("name = ?", name).Delete(&b).Delete(&Menu{}).Error +func (b *BaseMenu) DeleteBaseMenu(id float64) (err error) { + err = qmsql.DEFAULTDB.Where("parent_id = ?",id).First(&BaseMenu{}).Error + if(err!=nil){ + err = qmsql.DEFAULTDB.Where("id = ?", id).Delete(&b).Error + err = qmsql.DEFAULTDB.Where("menu_id = ?", id).Delete(&Menu{}).Error + }else{ + return errors.New("此菜单存在子菜单不可删除") + } return err } diff --git a/QMPlusServer/router/menu.go b/QMPlusServer/router/menu.go index a74eb1fea8a95cf7f9594da0684f1fbc22b044e2..3769235de1bb99598eacb74b33e7904caa7fd64b 100644 --- a/QMPlusServer/router/menu.go +++ b/QMPlusServer/router/menu.go @@ -15,5 +15,6 @@ func InitMenuRouter(Router *gin.Engine) { MenuRouter.POST("getBaseMenuTree", api.GetBaseMenuTree) MenuRouter.POST("addMenuAuthority", api.AddMenuAuthority) MenuRouter.POST("getMenuAuthority", api.GetMenuAuthority) + MenuRouter.POST("deleteBaseMenu",api.DeleteBaseMenu) } } diff --git a/QMPlusVuePage/src/api/menu.js b/QMPlusVuePage/src/api/menu.js index c6f97f1a0a20deb16a0410a815d45158340fbb26..f361bfde9e32fcca1c9ee8b977aeec89fde7a3a7 100644 --- a/QMPlusVuePage/src/api/menu.js +++ b/QMPlusVuePage/src/api/menu.js @@ -72,4 +72,16 @@ export const getMenuAuthority = (data) => { method: 'post', data }) +} + +// @Summary 获取用户menu关联关系 +// @Produce application/json +// @Param ID float64 +// @Router /menu/deleteBaseMenu [post] +export const deleteBaseMenu = (data) => { + return service({ + url: "/menu/deleteBaseMenu", + method: 'post', + data + }) } \ No newline at end of file diff --git a/QMPlusVuePage/src/view/superAdmin/authority/authority.vue b/QMPlusVuePage/src/view/superAdmin/authority/authority.vue index efee867dc8f6bfb30b0c97d56e6642fd336bed97..e20ed1fcad584c49a5911c8d29947e537e319a15 100644 --- a/QMPlusVuePage/src/view/superAdmin/authority/authority.vue +++ b/QMPlusVuePage/src/view/superAdmin/authority/authority.vue @@ -44,11 +44,11 @@ @@ -67,6 +67,7 @@ import { createAuthority } from '@/api/authority' import { getBaseMenuTree, addMenuAuthority, getMenuAuthority } from '@/api/menu' +import { mapActions } from 'vuex' export default { name: 'Authority', data() { @@ -77,7 +78,7 @@ export default { pageSize: 10, tableData: [], treeData: [], - treeIds:[], + treeIds: [], defaultProps: { children: 'children', label: 'nickName' @@ -91,6 +92,8 @@ export default { } }, methods: { + ...mapActions('router', ['SetAsyncRouter']), + // 条数 handleSizeChange(val) { this.pageSize = val @@ -109,19 +112,12 @@ export default { type: 'warning' }) .then(async () => { - try { - const res = await deleteAuthority({ authorityId: row.authorityId }) - this.$message({ - type: 'success', - message: '删除成功!' - }) - this.getAuthList() - } catch (err) { - this.$message({ - type: 'error', - message: '删除失败!' + err - }) - } + const res = await deleteAuthority({ authorityId: row.authorityId }) + this.$message({ + type: 'success', + message: '删除成功!' + }) + this.getAuthList() }) .catch(() => { this.$message({ @@ -152,12 +148,6 @@ export default { }) this.getAuthList() this.closeDialog() - } else { - this.$message({ - type: 'error', - message: '添加失败!' - }) - this.closeDialog() } this.initForm() this.dialogFormVisible = false @@ -168,26 +158,24 @@ export default { }, // 获取用户列表 async getAuthList(page = this.page, pageSize = this.pageSize) { - try { - const table = await getAuthorityList({ page, pageSize }) - this.tableData = table.data.authList - } catch (err) { - console.log(err) - } + const table = await getAuthorityList({ page, pageSize }) + this.tableData = table.data.authList }, + // 关联用户列表关系 async addAuthMenu(row) { - const res1 = await getMenuAuthority({authorityId:row.authorityId}) + const res1 = await getMenuAuthority({ authorityId: row.authorityId }) const menus = res1.data.menus const arr = [] - menus.map(item=>{arr.push(Number(item.menuId))}) + menus.map(item => { + arr.push(Number(item.menuId)) + }) this.treeIds = arr const res2 = await getBaseMenuTree() this.treeData = res2.data.menus - console.log(this.treeData) this.activeUserId = row.authorityId this.menuDialogFlag = true }, - // 关联树 + // 关联树 确认方法 async relation() { const checkArr = this.$refs.tree .getCheckedNodes() @@ -201,6 +189,7 @@ export default { type: 'success', message: '添加成功!' }) + this.SetAsyncRouter() } this.closeDialog() } @@ -208,7 +197,6 @@ export default { }, created() { this.getAuthList() - } } diff --git a/QMPlusVuePage/src/view/superAdmin/menu/menu.vue b/QMPlusVuePage/src/view/superAdmin/menu/menu.vue index c31686caca763e22dda8066a32218be43e6ba168..651660ad7cdb4a38aa9a20f7e494085cc9274be2 100644 --- a/QMPlusVuePage/src/view/superAdmin/menu/menu.vue +++ b/QMPlusVuePage/src/view/superAdmin/menu/menu.vue @@ -4,24 +4,29 @@ 新增根菜单 - - - - - - - + + + + + + + + + - + - + @@ -74,7 +79,8 @@