Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
FLIPPED-AURORA
gin-vue-admin
提交
9f17f71e
G
gin-vue-admin
项目概览
FLIPPED-AURORA
/
gin-vue-admin
10 个月 前同步成功
通知
324
Star
18154
Fork
5505
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gin-vue-admin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
9f17f71e
编写于
9月 08, 2019
作者:
Mr.奇淼(
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
权限初步模板
上级
1b1ceefa
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
664 addition
and
58 deletion
+664
-58
QMPlusServer/controller/api/api.go
QMPlusServer/controller/api/api.go
+56
-0
QMPlusServer/controller/api/authority.go
QMPlusServer/controller/api/authority.go
+60
-0
QMPlusServer/controller/api/menu.go
QMPlusServer/controller/api/menu.go
+1
-0
QMPlusServer/docs/docs.go
QMPlusServer/docs/docs.go
+171
-18
QMPlusServer/docs/swagger.json
QMPlusServer/docs/swagger.json
+170
-17
QMPlusServer/docs/swagger.yaml
QMPlusServer/docs/swagger.yaml
+112
-17
QMPlusServer/init/initRouter/initRouter.go
QMPlusServer/init/initRouter/initRouter.go
+5
-3
QMPlusServer/init/registTable/registTable.go
QMPlusServer/init/registTable/registTable.go
+1
-1
QMPlusServer/model/dbModel/api.go
QMPlusServer/model/dbModel/api.go
+43
-0
QMPlusServer/model/dbModel/authority.go
QMPlusServer/model/dbModel/authority.go
+14
-2
QMPlusServer/model/dbModel/menu.go
QMPlusServer/model/dbModel/menu.go
+1
-0
QMPlusServer/router/api.go
QMPlusServer/router/api.go
+15
-0
QMPlusServer/router/authority.go
QMPlusServer/router/authority.go
+15
-0
未找到文件。
QMPlusServer/controller/api/api.go
0 → 100644
浏览文件 @
9f17f71e
package
api
import
(
"fmt"
"github.com/gin-gonic/gin"
"main/controller/servers"
"main/model/dbModel"
)
type
CreateApiParams
struct
{
AuthorityId
uint
`json:"-"`
Path
string
`json:"path"`
Description
string
`json:"description"`
}
type
DeleteApiParams
struct
{
AuthorityId
uint
`json:"-"`
}
// @Tags Api
// @Summary 为指定角色创建api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.CreateApiParams true "创建api"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/createApi [post]
func
CreateApi
(
c
*
gin
.
Context
)
{
var
api
dbModel
.
Api
_
=
c
.
BindJSON
(
&
api
)
err
:=
api
.
CreateApi
()
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"创建失败:%v"
,
err
),
gin
.
H
{})
}
else
{
servers
.
ReportFormat
(
c
,
true
,
"创建成功"
,
gin
.
H
{})
}
}
// @Tags Api
// @Summary 删除指定角色api
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.DeleteApiParams true "删除api"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /api/deleteApi [post]
func
DeleteApi
(
c
*
gin
.
Context
)
{
var
a
dbModel
.
Api
_
=
c
.
BindJSON
(
&
a
)
err
:=
a
.
DeleteApi
()
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"删除失败:%v"
,
err
),
gin
.
H
{})
}
else
{
servers
.
ReportFormat
(
c
,
true
,
"删除成功"
,
gin
.
H
{})
}
}
QMPlusServer/controller/api/authority.go
0 → 100644
浏览文件 @
9f17f71e
package
api
import
(
"fmt"
"github.com/gin-gonic/gin"
"main/controller/servers"
"main/model/dbModel"
)
type
CreateAuthorityPatams
struct
{
AuthorityId
uint
`json:"authorityId"`
AuthorityName
string
`json:"authorityName"`
}
// @Tags authority
// @Summary 创建角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.CreateAuthorityPatams true "创建角色"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /authority/createAuthority [post]
func
CreateAuthority
(
c
*
gin
.
Context
)
{
var
auth
dbModel
.
Authority
_
=
c
.
BindJSON
(
&
auth
)
err
,
authBack
:=
auth
.
CreateAuthority
()
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"创建失败:%v"
,
err
),
gin
.
H
{
"authority"
:
authBack
,
})
}
else
{
servers
.
ReportFormat
(
c
,
true
,
"创建成功"
,
gin
.
H
{
"authority"
:
authBack
,
})
}
}
type
DeleteAuthorityPatams
struct
{
AuthorityId
uint
`json:"authorityId"`
}
// @Tags authority
// @Summary 删除角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body api.DeleteAuthorityPatams true "删除角色"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /authority/deleteAuthority [post]
func
DeleteAuthority
(
c
*
gin
.
Context
)
{
var
a
dbModel
.
Authority
_
=
c
.
BindJSON
(
&
a
)
//删除角色之前需要判断是否有用户正在使用此角色
err
:=
a
.
DeleteAuthority
()
if
err
!=
nil
{
servers
.
ReportFormat
(
c
,
false
,
fmt
.
Sprintf
(
"删除失败:%v"
,
err
),
gin
.
H
{})
}
else
{
servers
.
ReportFormat
(
c
,
true
,
"删除成功"
,
gin
.
H
{})
}
}
QMPlusServer/controller/api/menu.go
浏览文件 @
9f17f71e
...
...
@@ -15,6 +15,7 @@ import (
// @Param data body api.RegistAndLoginStuct true "可以什么都不填"
// @Success 200 {string} json "{"success":true,"data":{},"msg":"返回成功"}"
// @Router /menu/getMenu [post]
func
GetMenu
(
c
*
gin
.
Context
)
{
claims
,
_
:=
c
.
Get
(
"claims"
)
waitUse
:=
claims
.
(
*
middleware
.
CustomClaims
)
...
...
QMPlusServer/docs/docs.go
浏览文件 @
9f17f71e
// GENERATED BY THE COMMAND ABOVE; DO NOT EDIT
// This file was generated by swaggo/swag at
// 2019-09-0
7 22:49:45.2497438 +0800 CST m=+0.0409198
01
// 2019-09-0
8 16:14:12.6903257 +0800 CST m=+0.1065633
01
package
docs
...
...
@@ -26,30 +26,38 @@ var doc = `{
"host": "{{.Host}}",
"basePath": "{{.BasePath}}",
"paths": {
"/
base/login
": {
"/
api/createApi
": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"
Base
"
"
Api
"
],
"summary": "
用户登录
",
"summary": "
为指定角色创建api
",
"parameters": [
{
"description": "
用户登录接口
",
"description": "
创建api
",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/api.
RegistAndLoginStuct
"
"$ref": "#/definitions/api.
CreateApiParams
"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"
登陆
成功\"}",
"description": "{\"success\":true,\"data\":{},\"msg\":\"
获取
成功\"}",
"schema": {
"type": "string"
}
...
...
@@ -57,30 +65,77 @@ var doc = `{
}
}
},
"/
base/regist
": {
"/
api/deleteApi
": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"
Base
"
"
Api
"
],
"summary": "
用户注册账号
",
"summary": "
删除指定角色api
",
"parameters": [
{
"description": "
用户注册接口
",
"description": "
删除api
",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/api.
RegistAndLoginStuct
"
"$ref": "#/definitions/api.
DeleteApiParams
"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"注册成功\"}",
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/authority/createAuthority": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"authority"
],
"summary": "创建角色",
"parameters": [
{
"description": "创建角色",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/api.CreateAuthorityPatams"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
...
...
@@ -88,23 +143,88 @@ var doc = `{
}
}
},
"/
menu/getMenu
": {
"/
authority/deleteAuthority
": {
"post": {
"security": [
{
"ApiKeyAuth": []
}
],
"consumes": [
"application/json"
],
"produces": [
"application/json"
],
"tags": [
"authority"
],
"summary": "删除角色",
"parameters": [
{
"description": "删除角色",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/api.DeleteAuthorityPatams"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"获取成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/base/login": {
"post": {
"produces": [
"application/json"
],
"tags": [
"Base"
],
"summary": "用户登录",
"parameters": [
{
"description": "用户登录接口",
"name": "data",
"in": "body",
"required": true,
"schema": {
"type": "object",
"$ref": "#/definitions/api.RegistAndLoginStuct"
}
}
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"登陆成功\"}",
"schema": {
"type": "string"
}
}
}
}
},
"/base/regist": {
"post": {
"produces": [
"application/json"
],
"tags": [
"
Menu
"
"
Base
"
],
"summary": "
获取用户动态路由
",
"summary": "
用户注册账号
",
"parameters": [
{
"description": "
可以什么都不填
",
"description": "
用户注册接口
",
"name": "data",
"in": "body",
"required": true,
...
...
@@ -116,7 +236,7 @@ var doc = `{
],
"responses": {
"200": {
"description": "{\"success\":true,\"data\":{},\"msg\":\"
返回
成功\"}",
"description": "{\"success\":true,\"data\":{},\"msg\":\"
注册
成功\"}",
"schema": {
"type": "string"
}
...
...
@@ -258,6 +378,39 @@ var doc = `{
}
}
},
"api.CreateApiParams": {
"type": "object",
"properties": {
"description": {
"type": "string"
},
"path": {
"type": "string"
}
}
},
"api.CreateAuthorityPatams": {
"type": "object",
"properties": {
"authorityId": {
"type": "integer"
},
"authorityName": {
"type": "string"
}
}
},
"api.DeleteApiParams": {
"type": "object"
},
"api.DeleteAuthorityPatams": {
"type": "object",
"properties": {
"authorityId": {
"type": "integer"
}
}
},
"api.RegistAndLoginStuct": {
"type": "object",
"properties": {
...
...
QMPlusServer/docs/swagger.json
浏览文件 @
9f17f71e
...
...
@@ -9,30 +9,38 @@
},
"basePath"
:
"/"
,
"paths"
:
{
"/
base/login
"
:
{
"/
api/createApi
"
:
{
"post"
:
{
"security"
:
[
{
"ApiKeyAuth"
:
[]
}
],
"consumes"
:
[
"application/json"
],
"produces"
:
[
"application/json"
],
"tags"
:
[
"
Base
"
"
Api
"
],
"summary"
:
"
用户登录
"
,
"summary"
:
"
为指定角色创建api
"
,
"parameters"
:
[
{
"description"
:
"
用户登录接口
"
,
"description"
:
"
创建api
"
,
"name"
:
"data"
,
"in"
:
"body"
,
"required"
:
true
,
"schema"
:
{
"type"
:
"object"
,
"$ref"
:
"#/definitions/api.
RegistAndLoginStuct
"
"$ref"
:
"#/definitions/api.
CreateApiParams
"
}
}
],
"responses"
:
{
"200"
:
{
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
登陆
成功
\"
}"
,
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
获取
成功
\"
}"
,
"schema"
:
{
"type"
:
"string"
}
...
...
@@ -40,30 +48,77 @@
}
}
},
"/
base/regist
"
:
{
"/
api/deleteApi
"
:
{
"post"
:
{
"security"
:
[
{
"ApiKeyAuth"
:
[]
}
],
"consumes"
:
[
"application/json"
],
"produces"
:
[
"application/json"
],
"tags"
:
[
"
Base
"
"
Api
"
],
"summary"
:
"
用户注册账号
"
,
"summary"
:
"
删除指定角色api
"
,
"parameters"
:
[
{
"description"
:
"
用户注册接口
"
,
"description"
:
"
删除api
"
,
"name"
:
"data"
,
"in"
:
"body"
,
"required"
:
true
,
"schema"
:
{
"type"
:
"object"
,
"$ref"
:
"#/definitions/api.
RegistAndLoginStuct
"
"$ref"
:
"#/definitions/api.
DeleteApiParams
"
}
}
],
"responses"
:
{
"200"
:
{
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
注册成功
\"
}"
,
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
获取成功
\"
}"
,
"schema"
:
{
"type"
:
"string"
}
}
}
}
},
"/authority/createAuthority"
:
{
"post"
:
{
"security"
:
[
{
"ApiKeyAuth"
:
[]
}
],
"consumes"
:
[
"application/json"
],
"produces"
:
[
"application/json"
],
"tags"
:
[
"authority"
],
"summary"
:
"创建角色"
,
"parameters"
:
[
{
"description"
:
"创建角色"
,
"name"
:
"data"
,
"in"
:
"body"
,
"required"
:
true
,
"schema"
:
{
"type"
:
"object"
,
"$ref"
:
"#/definitions/api.CreateAuthorityPatams"
}
}
],
"responses"
:
{
"200"
:
{
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
获取成功
\"
}"
,
"schema"
:
{
"type"
:
"string"
}
...
...
@@ -71,23 +126,88 @@
}
}
},
"/
menu/getMenu
"
:
{
"/
authority/deleteAuthority
"
:
{
"post"
:
{
"security"
:
[
{
"ApiKeyAuth"
:
[]
}
],
"consumes"
:
[
"application/json"
],
"produces"
:
[
"application/json"
],
"tags"
:
[
"authority"
],
"summary"
:
"删除角色"
,
"parameters"
:
[
{
"description"
:
"删除角色"
,
"name"
:
"data"
,
"in"
:
"body"
,
"required"
:
true
,
"schema"
:
{
"type"
:
"object"
,
"$ref"
:
"#/definitions/api.DeleteAuthorityPatams"
}
}
],
"responses"
:
{
"200"
:
{
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
获取成功
\"
}"
,
"schema"
:
{
"type"
:
"string"
}
}
}
}
},
"/base/login"
:
{
"post"
:
{
"produces"
:
[
"application/json"
],
"tags"
:
[
"Base"
],
"summary"
:
"用户登录"
,
"parameters"
:
[
{
"description"
:
"用户登录接口"
,
"name"
:
"data"
,
"in"
:
"body"
,
"required"
:
true
,
"schema"
:
{
"type"
:
"object"
,
"$ref"
:
"#/definitions/api.RegistAndLoginStuct"
}
}
],
"responses"
:
{
"200"
:
{
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
登陆成功
\"
}"
,
"schema"
:
{
"type"
:
"string"
}
}
}
}
},
"/base/regist"
:
{
"post"
:
{
"produces"
:
[
"application/json"
],
"tags"
:
[
"
Menu
"
"
Base
"
],
"summary"
:
"
获取用户动态路由
"
,
"summary"
:
"
用户注册账号
"
,
"parameters"
:
[
{
"description"
:
"
可以什么都不填
"
,
"description"
:
"
用户注册接口
"
,
"name"
:
"data"
,
"in"
:
"body"
,
"required"
:
true
,
...
...
@@ -99,7 +219,7 @@
],
"responses"
:
{
"200"
:
{
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
返回
成功
\"
}"
,
"description"
:
"{
\"
success
\"
:true,
\"
data
\"
:{},
\"
msg
\"
:
\"
注册
成功
\"
}"
,
"schema"
:
{
"type"
:
"string"
}
...
...
@@ -241,6 +361,39 @@
}
}
},
"api.CreateApiParams"
:
{
"type"
:
"object"
,
"properties"
:
{
"description"
:
{
"type"
:
"string"
},
"path"
:
{
"type"
:
"string"
}
}
},
"api.CreateAuthorityPatams"
:
{
"type"
:
"object"
,
"properties"
:
{
"authorityId"
:
{
"type"
:
"integer"
},
"authorityName"
:
{
"type"
:
"string"
}
}
},
"api.DeleteApiParams"
:
{
"type"
:
"object"
},
"api.DeleteAuthorityPatams"
:
{
"type"
:
"object"
,
"properties"
:
{
"authorityId"
:
{
"type"
:
"integer"
}
}
},
"api.RegistAndLoginStuct"
:
{
"type"
:
"object"
,
"properties"
:
{
...
...
QMPlusServer/docs/swagger.yaml
浏览文件 @
9f17f71e
...
...
@@ -9,6 +9,27 @@ definitions:
userName
:
type
:
string
type
:
object
api.CreateApiParams
:
properties
:
description
:
type
:
string
path
:
type
:
string
type
:
object
api.CreateAuthorityPatams
:
properties
:
authorityId
:
type
:
integer
authorityName
:
type
:
string
type
:
object
api.DeleteApiParams
:
type
:
object
api.DeleteAuthorityPatams
:
properties
:
authorityId
:
type
:
integer
type
:
object
api.RegistAndLoginStuct
:
properties
:
passWord
:
...
...
@@ -30,30 +51,106 @@ info:
title
:
Swagger Example API
version
:
0.0.1
paths
:
/
base/login
:
/
api/createApi
:
post
:
consumes
:
-
application/json
parameters
:
-
description
:
用户登录接口
-
description
:
创建api
in
:
body
name
:
data
required
:
true
schema
:
$ref
:
'
#/definitions/api.
RegistAndLoginStuct
'
$ref
:
'
#/definitions/api.
CreateApiParams
'
type
:
object
produces
:
-
application/json
responses
:
"
200"
:
description
:
'
{"success":true,"data":{},"msg":"
登陆
成功"}'
description
:
'
{"success":true,"data":{},"msg":"
获取
成功"}'
schema
:
type
:
string
summary
:
用户登录
security
:
-
ApiKeyAuth
:
[]
summary
:
为指定角色创建api
tags
:
-
Base
/
base/regist
:
-
Api
/
api/deleteApi
:
post
:
consumes
:
-
application/json
parameters
:
-
description
:
用户注册接口
-
description
:
删除api
in
:
body
name
:
data
required
:
true
schema
:
$ref
:
'
#/definitions/api.DeleteApiParams'
type
:
object
produces
:
-
application/json
responses
:
"
200"
:
description
:
'
{"success":true,"data":{},"msg":"获取成功"}'
schema
:
type
:
string
security
:
-
ApiKeyAuth
:
[]
summary
:
删除指定角色api
tags
:
-
Api
/authority/createAuthority
:
post
:
consumes
:
-
application/json
parameters
:
-
description
:
创建角色
in
:
body
name
:
data
required
:
true
schema
:
$ref
:
'
#/definitions/api.CreateAuthorityPatams'
type
:
object
produces
:
-
application/json
responses
:
"
200"
:
description
:
'
{"success":true,"data":{},"msg":"获取成功"}'
schema
:
type
:
string
security
:
-
ApiKeyAuth
:
[]
summary
:
创建角色
tags
:
-
authority
/authority/deleteAuthority
:
post
:
consumes
:
-
application/json
parameters
:
-
description
:
删除角色
in
:
body
name
:
data
required
:
true
schema
:
$ref
:
'
#/definitions/api.DeleteAuthorityPatams'
type
:
object
produces
:
-
application/json
responses
:
"
200"
:
description
:
'
{"success":true,"data":{},"msg":"获取成功"}'
schema
:
type
:
string
security
:
-
ApiKeyAuth
:
[]
summary
:
删除角色
tags
:
-
authority
/base/login
:
post
:
parameters
:
-
description
:
用户登录接口
in
:
body
name
:
data
required
:
true
...
...
@@ -64,16 +161,16 @@ paths:
-
application/json
responses
:
"
200"
:
description
:
'
{"success":true,"data":{},"msg":"
注册
成功"}'
description
:
'
{"success":true,"data":{},"msg":"
登陆
成功"}'
schema
:
type
:
string
summary
:
用户
注册账号
summary
:
用户
登录
tags
:
-
Base
/
menu/getMenu
:
/
base/regist
:
post
:
parameters
:
-
description
:
可以什么都不填
-
description
:
用户注册接口
in
:
body
name
:
data
required
:
true
...
...
@@ -84,14 +181,12 @@ paths:
-
application/json
responses
:
"
200"
:
description
:
'
{"success":true,"data":{},"msg":"
返回
成功"}'
description
:
'
{"success":true,"data":{},"msg":"
注册
成功"}'
schema
:
type
:
string
security
:
-
ApiKeyAuth
:
[]
summary
:
获取用户动态路由
summary
:
用户注册账号
tags
:
-
Menu
-
Base
/user/changePassWord
:
post
:
parameters
:
...
...
QMPlusServer/init/initRouter/initRouter.go
浏览文件 @
9f17f71e
...
...
@@ -13,8 +13,10 @@ func InitRouter() *gin.Engine {
var
Router
=
gin
.
Default
()
Router
.
GET
(
"/swagger/*any"
,
ginSwagger
.
WrapHandler
(
swaggerFiles
.
Handler
))
//Router.Use(middleware.Logger())
router
.
InitUserRouter
(
Router
)
router
.
InitBaseRouter
(
Router
)
router
.
InitMenuRouter
(
Router
)
router
.
InitUserRouter
(
Router
)
// 注册用户路由
router
.
InitBaseRouter
(
Router
)
// 注册基础功能路由
router
.
InitMenuRouter
(
Router
)
// 注册menu路由
router
.
InitAuthorityRouter
(
Router
)
// 注册角色路由
router
.
InitApiRouter
(
Router
)
// 注册功能api路由
return
Router
}
QMPlusServer/init/registTable/registTable.go
浏览文件 @
9f17f71e
...
...
@@ -7,5 +7,5 @@ import (
//注册数据库表专用
func
RegistTable
(
db
*
gorm
.
DB
)
{
db
.
AutoMigrate
(
dbModel
.
User
{},
dbModel
.
Authority
{},
dbModel
.
Menu
{})
db
.
AutoMigrate
(
dbModel
.
User
{},
dbModel
.
Authority
{},
dbModel
.
Menu
{}
,
dbModel
.
Api
{}
)
}
QMPlusServer/model/dbModel/api.go
0 → 100644
浏览文件 @
9f17f71e
package
dbModel
import
(
"github.com/jinzhu/gorm"
"main/controller/servers"
"main/init/qmsql"
"main/model/modelInterface"
)
type
Api
struct
{
gorm
.
Model
`json:"-"`
AuthorityId
uint
`json:"-"`
Path
string
`json:"path"`
Description
string
`json:"description"`
}
func
(
a
*
Api
)
CreateApi
()
(
err
error
)
{
err
=
qmsql
.
DEFAULTDB
.
Create
(
a
)
.
Error
return
err
}
func
(
a
*
Api
)
DeleteApi
()
(
err
error
)
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"id = ?"
,
a
.
AuthorityId
)
.
Delete
(
a
)
.
Error
return
err
}
func
(
a
*
Api
)
EditApi
()
(
err
error
)
{
err
=
qmsql
.
DEFAULTDB
.
Update
(
a
)
.
Error
return
err
}
// 分页获取数据 需要分页实现这个接口即可
func
(
a
*
Api
)
GetInfoList
(
info
modelInterface
.
PageInfo
)
(
err
error
,
list
interface
{},
total
int
)
{
// 封装分页方法 调用即可 传入 当前的结构体和分页信息
err
,
db
,
total
:=
servers
.
PagingServer
(
a
,
info
)
if
err
!=
nil
{
return
}
else
{
var
apiList
[]
Api
err
=
db
.
Find
(
&
apiList
)
.
Error
return
err
,
apiList
,
total
}
}
QMPlusServer/model/dbModel/authority.go
浏览文件 @
9f17f71e
...
...
@@ -2,17 +2,29 @@ package dbModel
import
(
"github.com/jinzhu/gorm"
"github.com/pkg/errors"
"main/init/qmsql"
)
type
Authority
struct
{
gorm
.
Model
`json:"-"`
AuthorityId
uint
`json:"authorityId"`
AuthorityId
uint
`json:"authorityId"
gorm:"not null;unique"
`
AuthorityName
string
`json:"authorityName"`
Menus
[]
Menu
`json:"_"`
}
// 创建角色
func
(
a
*
Authority
)
CreateAuthority
()
(
err
error
,
authority
*
Authority
)
{
err
=
qmsql
.
DEFAULTDB
.
Create
(
a
)
.
Error
return
err
,
a
}
// 删除角色
func
(
a
*
Authority
)
DeleteAuthority
()
(
err
error
)
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"authority_id = ?"
,
a
.
AuthorityId
)
.
Find
(
&
User
{})
.
Error
if
err
!=
nil
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"authority_id = ?"
,
a
.
AuthorityId
)
.
Delete
(
a
)
.
Error
}
else
{
err
=
errors
.
New
(
"此角色有用户正在使用禁止删除"
)
}
return
err
}
QMPlusServer/model/dbModel/menu.go
浏览文件 @
9f17f71e
...
...
@@ -23,6 +23,7 @@ type Meta struct {
Icon
string
`json:"icon"`
}
//获取动态路由树
func
(
m
*
Menu
)
GetMenuTree
(
authorityId
float64
)
(
err
error
,
menus
[]
Menu
)
{
err
=
qmsql
.
DEFAULTDB
.
Where
(
"authority_id = ? AND parent_id = ?"
,
authorityId
,
0
)
.
Find
(
&
menus
)
.
Error
for
i
:=
0
;
i
<
len
(
menus
);
i
++
{
...
...
QMPlusServer/router/api.go
0 → 100644
浏览文件 @
9f17f71e
package
router
import
(
"github.com/gin-gonic/gin"
"main/controller/api"
"main/middleware"
)
func
InitApiRouter
(
Router
*
gin
.
Engine
)
{
UserRouter
:=
Router
.
Group
(
"api"
)
.
Use
(
middleware
.
JWTAuth
())
{
UserRouter
.
POST
(
"createApi"
,
api
.
CreateApi
)
UserRouter
.
POST
(
"deleteApi"
,
api
.
DeleteApi
)
}
}
QMPlusServer/router/authority.go
0 → 100644
浏览文件 @
9f17f71e
package
router
import
(
"github.com/gin-gonic/gin"
"main/controller/api"
"main/middleware"
)
func
InitAuthorityRouter
(
Router
*
gin
.
Engine
)
{
AuthorityRouter
:=
Router
.
Group
(
"authority"
)
.
Use
(
middleware
.
JWTAuth
())
{
AuthorityRouter
.
POST
(
"createAuthority"
,
api
.
CreateAuthority
)
AuthorityRouter
.
POST
(
"deleteAuthority"
,
api
.
DeleteAuthority
)
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录