Browse Source

Merge branch 'gin-vue-admin_v2_dev' of https://github.com/flipped-aurora/gin-vue-admin into gin-vue-admin_v2_dev

main
klausY 5 years ago
parent
commit
c75b550328
  1. 2
      server/api/v1/sys_menu.go
  2. 2
      server/core/server.go
  3. 3631
      server/db/qmplus.sql
  4. 4
      server/router/sys_user.go
  5. 68
      server/service/sys_menu.go
  6. 2
      web/src/store/module/router.js
  7. 4
      web/src/view/layout/aside/asideComponent/index.vue
  8. 2
      web/src/view/superAdmin/authority/authority.vue
  9. 2
      web/src/view/superAdmin/authority/components/datas.vue
  10. 2
      web/src/view/superAdmin/menu/menu.vue
  11. 2
      web/src/view/superAdmin/user/user.vue

2
server/api/v1/sys_menu.go

@ -39,7 +39,7 @@ func GetMenu(c *gin.Context) {
func GetMenuList(c *gin.Context) { func GetMenuList(c *gin.Context) {
var pageInfo request.PageInfo var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo) _ = c.ShouldBindJSON(&pageInfo)
err, menuList, total := service.GetInfoList(pageInfo)
err, menuList, total := service.GetInfoList()
if err != nil { if err != nil {
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c) response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c)
} else { } else {

2
server/core/server.go

@ -23,6 +23,8 @@ func RunWindowsServer() {
WriteTimeout: 10 * time.Second, WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20, MaxHeaderBytes: 1 << 20,
} }
// 保证文本顺序输出
// In order to ensure that the text order output can be deleted
time.Sleep(10 * time.Microsecond) time.Sleep(10 * time.Microsecond)
global.GVA_LOG.Debug("server run success on ", address) global.GVA_LOG.Debug("server run success on ", address)

3631
server/db/qmplus.sql
File diff suppressed because it is too large
View File

4
server/router/sys_user.go

@ -2,12 +2,12 @@ package router
import ( import (
"gin-vue-admin/api/v1" "gin-vue-admin/api/v1"
"gin-vue-admin/middleware"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
) )
func InitUserRouter(Router *gin.RouterGroup) { func InitUserRouter(Router *gin.RouterGroup) {
UserRouter := Router.Group("user")
//.Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
UserRouter := Router.Group("user").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler())
{ {
UserRouter.POST("changePassword", v1.ChangePassword) // 修改密码 UserRouter.POST("changePassword", v1.ChangePassword) // 修改密码
UserRouter.POST("uploadHeaderImg", v1.UploadHeaderImg) //上传头像 UserRouter.POST("uploadHeaderImg", v1.UploadHeaderImg) //上传头像

68
server/service/sys_menu.go

@ -4,9 +4,26 @@ import (
"errors" "errors"
"gin-vue-admin/global" "gin-vue-admin/global"
"gin-vue-admin/model" "gin-vue-admin/model"
"gin-vue-admin/model/request"
"strconv"
) )
// @title getMenuTreeMap
// @description 获取路由总树map
// @auth qm (2020/05/06 10:26)
// @return err error
// @return menusMsp map{string}[]SysBaseMenu
func getMenuTreeMap(authorityId string)(err error,treeMap map[string][]model.SysMenu){
var allMenus []model.SysMenu
treeMap = make(map[string][]model.SysMenu)
sql := "SELECT authority_menu.keep_alive,authority_menu.default_menu,authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? ORDER BY authority_menu.sort ASC"
err = global.GVA_DB.Raw(sql,authorityId).Scan(&allMenus).Error
for _,v := range allMenus{
treeMap[v.ParentId] = append(treeMap[v.ParentId], v)
}
return err,treeMap
}
// @title GetMenuTree // @title GetMenuTree
// @description 获取动态菜单树 // @description 获取动态菜单树
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
@ -15,10 +32,10 @@ import (
// @return menus []model.SysMenu // @return menus []model.SysMenu
func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) { func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) {
sql := "SELECT authority_menu.keep_alive,authority_menu.default_menu,authority_menu.created_at,authority_menu.updated_at,authority_menu.deleted_at,authority_menu.menu_level,authority_menu.parent_id,authority_menu.path,authority_menu.`name`,authority_menu.hidden,authority_menu.component,authority_menu.title,authority_menu.icon,authority_menu.sort,authority_menu.menu_id,authority_menu.authority_id FROM authority_menu WHERE authority_menu.authority_id = ? AND authority_menu.parent_id = ? ORDER BY authority_menu.sort ASC"
err = global.GVA_DB.Raw(sql, authorityId, 0).Scan(&menus).Error
err,menuTree := getMenuTreeMap(authorityId)
menus = menuTree["0"]
for i := 0; i < len(menus); i++ { for i := 0; i < len(menus); i++ {
err = getChildrenList(&menus[i], sql)
err = getChildrenList(&menus[i], menuTree)
} }
return err, menus return err, menus
} }
@ -30,10 +47,10 @@ func GetMenuTree(authorityId string) (err error, menus []model.SysMenu) {
// @param sql string // @param sql string
// @return err error // @return err error
func getChildrenList(menu *model.SysMenu, sql string) (err error) {
err = global.GVA_DB.Raw(sql, menu.AuthorityId, menu.MenuId).Scan(&menu.Children).Error
func getChildrenList(menu *model.SysMenu,treeMap map[string][]model.SysMenu) (err error) {
menu.Children = treeMap[menu.MenuId]
for i := 0; i < len(menu.Children); i++ { for i := 0; i < len(menu.Children); i++ {
err = getChildrenList(&menu.Children[i], sql)
err = getChildrenList(&menu.Children[i], treeMap)
} }
return err return err
} }
@ -46,14 +63,12 @@ func getChildrenList(menu *model.SysMenu, sql string) (err error) {
// @return list interface{} // @return list interface{}
// @return total int // @return total int
func GetInfoList(info request.PageInfo) (err error, list interface{}, total int) {
limit := info.PageSize
offset := info.PageSize * (info.Page - 1)
db := global.GVA_DB
func GetInfoList() (err error, list interface{}, total int) {
var menuList []model.SysBaseMenu var menuList []model.SysBaseMenu
err = db.Limit(limit).Offset(offset).Where("parent_id = 0").Order("sort", true).Find(&menuList).Error
err,treeMap := getBaseMenuTreeMap()
menuList = treeMap["0"]
for i := 0; i < len(menuList); i++ { for i := 0; i < len(menuList); i++ {
err = getBaseChildrenList(&menuList[i])
err = getBaseChildrenList(&menuList[i],treeMap)
} }
return err, menuList, total return err, menuList, total
} }
@ -64,10 +79,10 @@ func GetInfoList(info request.PageInfo) (err error, list interface{}, total int)
// @param menu *model.SysBaseMenu // @param menu *model.SysBaseMenu
// @return err error // @return err error
func getBaseChildrenList(menu *model.SysBaseMenu) (err error) {
err = global.GVA_DB.Where("parent_id = ?", menu.ID).Order("sort", true).Find(&menu.Children).Error
func getBaseChildrenList(menu *model.SysBaseMenu ,treeMap map[string][]model.SysBaseMenu) (err error) {
menu.Children = treeMap[strconv.Itoa(int(menu.ID))]
for i := 0; i < len(menu.Children); i++ { for i := 0; i < len(menu.Children); i++ {
err = getBaseChildrenList(&menu.Children[i])
err = getBaseChildrenList(&menu.Children[i],treeMap)
} }
return err return err
} }
@ -89,6 +104,22 @@ func AddBaseMenu(menu model.SysBaseMenu) (err error) {
return err return err
} }
// @title getBaseMenuTreeMap
// @description 获取路由总树map
// @auth qm (2020/05/06 10:26)
// @return err error
// @return menusMsp map{string}[]SysBaseMenu
func getBaseMenuTreeMap()(err error,treeMap map[string][]model.SysBaseMenu){
var allMenus []model.SysBaseMenu
treeMap = make(map[string][]model.SysBaseMenu)
err = global.GVA_DB.Order("sort", true).Find(&allMenus).Error
for _,v := range allMenus{
treeMap[v.ParentId] = append(treeMap[v.ParentId], v)
}
return err,treeMap
}
// @title GetBaseMenuTree // @title GetBaseMenuTree
// @description 获取基础路由树 // @description 获取基础路由树
// @auth (2020/04/05 20:22) // @auth (2020/04/05 20:22)
@ -96,9 +127,10 @@ func AddBaseMenu(menu model.SysBaseMenu) (err error) {
// @return menus []SysBaseMenu // @return menus []SysBaseMenu
func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) { func GetBaseMenuTree() (err error, menus []model.SysBaseMenu) {
err = global.GVA_DB.Where(" parent_id = ?", 0).Order("sort", true).Find(&menus).Error
err,treeMap := getBaseMenuTreeMap()
menus = treeMap["0"]
for i := 0; i < len(menus); i++ { for i := 0; i < len(menus); i++ {
err = getBaseChildrenList(&menus[i])
err = getBaseChildrenList(&menus[i],treeMap)
} }
return err, menus return err, menus
} }

2
web/src/store/module/router.js

@ -6,7 +6,7 @@ import { asyncMenu } from '@/api/menu'
const formatRouter = (routes) => { const formatRouter = (routes) => {
routes && routes.map(item => { routes && routes.map(item => {
item.meta.hidden = item.hidden item.meta.hidden = item.hidden
if (item.children.length > 0) {
if (item.children && item.children.length > 0) {
formatRouter(item.children) formatRouter(item.children)
} }
}) })

4
web/src/view/layout/aside/asideComponent/index.vue

@ -1,6 +1,6 @@
<template> <template>
<component :is="menuComponent" :routerInfo="routerInfo" v-if="!routerInfo.hidden"> <component :is="menuComponent" :routerInfo="routerInfo" v-if="!routerInfo.hidden">
<template v-if="routerInfo.children.length">
<template v-if="routerInfo.children&&routerInfo.children.length">
<AsideComponent :key="item.name" :routerInfo="item" v-for="item in routerInfo.children" /> <AsideComponent :key="item.name" :routerInfo="item" v-for="item in routerInfo.children" />
</template> </template>
</component> </component>
@ -14,7 +14,7 @@ export default {
name: 'AsideComponent', name: 'AsideComponent',
computed: { computed: {
menuComponent() { menuComponent() {
if (this.routerInfo.children.filter(item=>!item.hidden).length) {
if (this.routerInfo.children&&this.routerInfo.children.filter(item=>!item.hidden).length) {
return 'AsyncSubmenu' return 'AsyncSubmenu'
} else { } else {
return 'MenuItem' return 'MenuItem'

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

@ -266,7 +266,7 @@ export default {
}, },
setAuthorityOptions(AuthorityData,optionsData,disabled){ setAuthorityOptions(AuthorityData,optionsData,disabled){
AuthorityData&&AuthorityData.map(item=>{ AuthorityData&&AuthorityData.map(item=>{
if(item.children.length){
if(item.children&&item.children.length){
const option = { const option = {
authorityId:item.authorityId, authorityId:item.authorityId,
authorityName:item.authorityName, authorityName:item.authorityName,

2
web/src/view/superAdmin/authority/components/datas.vue

@ -78,7 +78,7 @@ export default {
obj.authorityId = item.authorityId obj.authorityId = item.authorityId
obj.authorityName = item.authorityName obj.authorityName = item.authorityName
this.authoritys.push(obj) this.authoritys.push(obj)
if(item.children.length){
if(item.children&&item.children.length){
this.roundAuthority(item.children) this.roundAuthority(item.children)
} }
}) })

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

@ -157,7 +157,7 @@ export default {
setMenuOptions(menuData, optionsData, disabled) { setMenuOptions(menuData, optionsData, disabled) {
menuData && menuData &&
menuData.map(item => { menuData.map(item => {
if (item.children.length) {
if (item.children&&item.children.length) {
const option = { const option = {
title: item.meta.title, title: item.meta.title,
ID: String(item.ID), ID: String(item.ID),

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

@ -149,7 +149,7 @@ export default {
setAuthorityOptions(AuthorityData, optionsData) { setAuthorityOptions(AuthorityData, optionsData) {
AuthorityData && AuthorityData &&
AuthorityData.map(item => { AuthorityData.map(item => {
if (item.children.length) {
if (item.children&&item.children.length) {
const option = { const option = {
authorityId: item.authorityId, authorityId: item.authorityId,
authorityName: item.authorityName, authorityName: item.authorityName,

Loading…
Cancel
Save