EasyGoAdmin_GoFrame_EleVue-1

原文地址

main.go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
package main

import (
_ "easygoadmin/boot"
_ "easygoadmin/router"
"github.com/gogf/gf/frame/g"
)

// @title EasyGoAdmin前后端分离旗舰版框架
// @version 1.0
// @description EasyGoAdmin前后端分离旗舰版框架
// @schemes http
func main() {
g.Server().Run()
}

router

router.go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/**
* 系统路由
* @File : submit
*/
package router

import (
"easygoadmin/app/controller"
"easygoadmin/middleware"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/net/ghttp"
)

func init() {
s := g.Server()
// 跨域处理
s.Use(middleware.CORS)
// 登录验证中间件
s.Use(middleware.CheckLogin)
// 操作日志中间件
s.Use(middleware.OperLog)
// 登录日志中间件
s.Use(middleware.LoginLog)

/* 文件上传 */
s.Group("/upload", func(group *ghttp.RouterGroup) {
// 上传图片
group.POST("/uploadImage", controller.Upload.UploadImage)
})

/* 登录注册 */
s.Group("/", func(group *ghttp.RouterGroup) {
group.GET("/", controller.Login.Login)
group.ALL("/login", controller.Login.Login)
group.GET("/captcha", controller.Login.Captcha)
group.ALL("/updateUserInfo", controller.Index.UpdateUserInfo)
group.ALL("/updatePwd", controller.Index.UpdatePwd)
group.GET("/logout", controller.Index.Logout)
})

s.Group("index", func(group *ghttp.RouterGroup) {
group.GET("/menu", controller.Index.Menu)
group.GET("/user", controller.Index.User)
})

/* 用户管理 */
s.Group("user", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.User.List)
group.GET("/detail", controller.User.Detail)
group.POST("/add", controller.User.Add)
group.PUT("/update", controller.User.Update)
group.DELETE("/delete/:ids", controller.User.Delete)
group.PUT("/status", controller.User.Status)
group.PUT("/resetPwd", controller.User.ResetPwd)
group.GET("/checkUser", controller.User.CheckUser)
})

/* 职级管理 */
s.Group("level", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Level.List)
group.POST("/add", controller.Level.Add)
group.PUT("/update", controller.Level.Update)
group.DELETE("/delete/:ids", controller.Level.Delete)
group.PUT("/status", controller.Level.Status)
group.GET("/getLevelList", controller.Level.GetLevelList)
group.GET("/exportExcel", controller.Level.ExportExcel)
group.POST("/importExcel", controller.Level.ImportExcel)
group.GET("/downloadExcel", controller.Level.DownloadExcel)
})

/* 岗位路由 */
s.Group("position", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Position.List)
group.POST("/add", controller.Position.Add)
group.PUT("/update", controller.Position.Update)
group.DELETE("/delete/:ids", controller.Position.Delete)
group.PUT("/status", controller.Position.Status)
group.GET("/getPositionList", controller.Position.GetPositionList)
})

/* 角色路由 */
s.Group("role", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Role.List)
group.POST("/add", controller.Role.Add)
group.PUT("/update", controller.Role.Update)
group.DELETE("/delete/:ids", controller.Role.Delete)
group.PUT("/status", controller.Role.Status)
group.GET("/getRoleList", controller.Role.GetRoleList)
})

/* 角色菜单权限 */
s.Group("rolemenu", func(group *ghttp.RouterGroup) {
group.GET("/index", controller.RoleMenu.Index)
group.POST("/save", controller.RoleMenu.Save)
})

/* 部门管理 */
s.Group("dept", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Dept.List)
group.POST("/add", controller.Dept.Add)
group.PUT("/update", controller.Dept.Update)
group.DELETE("/delete/:ids", controller.Dept.Delete)
group.GET("/getDeptList", controller.Dept.GetDeptList)
})

/* 菜单管理 */
s.Group("menu", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Menu.List)
group.GET("/detail", controller.Menu.Detail)
group.POST("/add", controller.Menu.Add)
group.PUT("/update", controller.Menu.Update)
group.DELETE("/delete/:ids", controller.Menu.Delete)
})

/* 操作日志 */
s.Group("operlog", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.OperLog.List)
})

/* 登录日志 */
s.Group("loginlog", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.LoginLog.List)
group.DELETE("/delete/:ids", controller.LoginLog.Delete)
})

/* 城市管理 */
s.Group("city", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.City.List)
group.POST("/add", controller.City.Add)
group.PUT("/update", controller.City.Update)
group.DELETE("/delete/:ids", controller.City.Delete)
group.POST("/getChilds", controller.City.GetChilds)
})

/* 字典管理 */
s.Group("dict", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Dict.List)
group.POST("/add", controller.Dict.Add)
group.PUT("/update", controller.Dict.Update)
group.DELETE("/delete/:ids", controller.Dict.Delete)
})

/* 字典项管理 */
s.Group("dictdata", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.DictData.List)
group.POST("/add", controller.DictData.Add)
group.PUT("/update", controller.DictData.Update)
group.DELETE("/delete/:ids", controller.DictData.Delete)
})

/* 配置管理 */
s.Group("config", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Config.List)
group.POST("/add", controller.Config.Add)
group.PUT("/update", controller.Config.Update)
group.DELETE("/delete/:ids", controller.Config.Delete)
})

/* 配置项管理 */
s.Group("configdata", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.ConfigData.List)
group.POST("/add", controller.ConfigData.Add)
group.PUT("/update", controller.ConfigData.Update)
group.DELETE("/delete/:ids", controller.ConfigData.Delete)
group.PUT("/status", controller.ConfigData.Status)
})

/* 友链管理 */
s.Group("link", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Link.List)
group.POST("/add", controller.Link.Add)
group.PUT("/update", controller.Link.Update)
group.DELETE("/delete/:ids", controller.Link.Delete)
group.PUT("/status", controller.Link.Status)
})

/* 站点管理 */
s.Group("item", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Item.List)
group.POST("/add", controller.Item.Add)
group.PUT("/update", controller.Item.Update)
group.DELETE("/delete/:ids", controller.Item.Delete)
group.PUT("/status", controller.Item.Status)
group.GET("/getItemList", controller.Item.GetItemList)
})

/* 栏目管理 */
s.Group("itemcate", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.ItemCate.List)
group.POST("/add", controller.ItemCate.Add)
group.PUT("/update", controller.ItemCate.Update)
group.DELETE("/delete/:ids", controller.ItemCate.Delete)
//group.GET("/getCateTreeList", controller.ItemCate.GetCateTreeList)
group.GET("/getCateList", controller.ItemCate.GetCateList)
})

/* 广告位管理 */
s.Group("adsort", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.AdSort.List)
group.POST("/add", controller.AdSort.Add)
group.PUT("/update", controller.AdSort.Update)
group.DELETE("/delete/:ids", controller.AdSort.Delete)
group.GET("/getAdSortList", controller.AdSort.GetAdSortList)
})

/* 广告管理 */
s.Group("ad", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Ad.List)
group.POST("/add", controller.Ad.Add)
group.PUT("/update", controller.Ad.Update)
group.DELETE("/delete/:ids", controller.Ad.Delete)
group.PUT("/status", controller.Ad.Status)
})

/* 通知管理 */
s.Group("notice", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Notice.List)
group.POST("/add", controller.Notice.Add)
group.PUT("/update", controller.Notice.Update)
group.DELETE("/delete/:ids", controller.Notice.Delete)
group.PUT("/status", controller.Notice.Status)
})

/* 网站设置 */
s.Group("configweb", func(group *ghttp.RouterGroup) {
group.GET("/index", controller.ConfigWeb.Index)
group.PUT("/save", controller.ConfigWeb.Save)
})

/* 会员等级 */
s.Group("memberlevel", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.MemberLevel.List)
group.POST("/add", controller.MemberLevel.Add)
group.PUT("/update", controller.MemberLevel.Update)
group.DELETE("/delete/:ids", controller.MemberLevel.Delete)
group.GET("/getMemberLevelList", controller.MemberLevel.GetMemberLevelList)
})

/* 会员管理 */
s.Group("member", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Member.List)
group.POST("/add", controller.Member.Add)
group.PUT("/update", controller.Member.Update)
group.DELETE("/delete/:ids", controller.Member.Delete)
group.PUT("/status", controller.Member.Status)
})

/* 统计分析 */
s.Group("analysis", func(group *ghttp.RouterGroup) {
group.GET("/index", controller.Analysis.Index)
})

/* 代码生成器 */
s.Group("generate", func(group *ghttp.RouterGroup) {
group.GET("/list", controller.Generate.List)
group.POST("/generate", controller.Generate.Generate)
group.POST("/batchGenerate", controller.Generate.BatchGenerate)
})

}

middleware

checklogin.go

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/**
* 登录验证中间件
* @File : checklogin
*/
package middleware

import (
"easygoadmin/app/utils"
"easygoadmin/app/utils/common"
"fmt"
"github.com/gogf/gf/net/ghttp"
"github.com/gogf/gf/text/gstr"
"time"
)

func CheckLogin(r *ghttp.Request) {
fmt.Println("登录验证中间件")
// 放行设置
urlItem := []string{"/captcha", "/login"}
if !utils.InStringArray(r.RequestURI, urlItem) {
// 从请求头中获取Token
token := r.GetHeader("Authorization")
// 字符串替换
token = gstr.Replace(token, "Bearer ", "")
claim, err := utils.ParseToken(token)
if err != nil {
fmt.Println("解析token出现错误:", err)
r.Response.WriteJsonExit(common.JsonResult{
Code: 401,
Msg: "Token已过期",
})
} else if time.Now().Unix() > claim.ExpiresAt {
fmt.Println("时间超时")
r.Response.WriteJsonExit(common.JsonResult{
Code: 401,
Msg: "时间超时",
})
}
}
// 前置中间件
r.Middleware.Next()
}
0%