Browse Source

代码改造

master
Viviman 2 years ago
parent
commit
4067085d2b
  1. 3
      .gitignore
  2. 5
      conf/app.conf
  3. 41
      controllers/admin/DeptController.go
  4. 32
      controllers/admin/DictController.go
  5. 32
      controllers/admin/DictDetailController.go
  6. 39
      controllers/admin/JobController.go
  7. 28
      controllers/admin/LoginController.go
  8. 47
      controllers/admin/MenuController.go
  9. 54
      controllers/admin/RoleController.go
  10. 4
      controllers/admin/ToolsController.go
  11. 87
      controllers/admin/UserController.go
  12. 135
      controllers/vivib/LiCaiController.go
  13. 1
      main.go
  14. 4
      models/SysDept.go
  15. 9
      redis/pool.go
  16. 11
      routers/router.go
  17. 0
      sql/viviman_go.sql
  18. 8
      untils/tools.go
  19. 3
      web/.eslintignore
  20. 50
      web/src/api/vivib/licai.js
  21. 2
      web/src/layout/components/AppMain.vue
  22. 2
      web/src/layout/components/Navbar.vue
  23. 2
      web/src/layout/components/Settings/index.vue
  24. 2
      web/src/layout/components/Sidebar/Logo.vue
  25. 2
      web/src/layout/components/TagsView/ScrollPane.vue
  26. 2
      web/src/layout/components/TagsView/index.vue
  27. 2
      web/src/layout/index.vue
  28. 2
      web/src/views/components/icons/index.vue
  29. 2
      web/src/views/dashboard/OrderCount.vue
  30. 2
      web/src/views/features/401.vue
  31. 94
      web/src/views/vivib/licai/index.vue
  32. 170
      web/src/views/vivib/licai/licaiJs.js

3
.gitignore

@ -9,4 +9,5 @@ yshop.tar.gz
/desc/ /desc/
/web/node_modules/ /web/node_modules/
go.sum go.sum
lastupdate.tmp lastupdate.tmp
/static/upload/

5
conf/app.conf

@ -11,17 +11,18 @@ ignore_urls = "/admin/auth/login,/admin/auth/captcha"
[dev] [dev]
#数据库配置 #数据库配置
mysqluser = "beego" mysqluser = "hy_qggwy"
mysqlpass = "Asdfghjklm123." mysqlpass = "Asdfghjklm123."
mysqlhost = "nas.viviman.top" mysqlhost = "nas.viviman.top"
mysqlport = 35017 mysqlport = 35017
mysqldb = "beego_demo01" mysqldb = "viviman"
db_max_idle_conn = 30 db_max_idle_conn = 30
db_max_open_open = 100 db_max_open_open = 100
maxmemory = 1<<22 maxmemory = 1<<22
#redis #redis
redis_host = nas.viviman.top:20017 redis_host = nas.viviman.top:20017
redis_db = 2
redis_pwd = redis_pwd =
#日志等级 debug #日志等级 debug

41
controllers/admin/DeptController.go

@ -9,7 +9,7 @@ import (
"viviman.top/vo" "viviman.top/vo"
) )
// 部门api // DeptController 部门api
type DeptController struct { type DeptController struct {
controllers.BaseController controllers.BaseController
} }
@ -21,7 +21,7 @@ func (c *DeptController) URLMapping() {
c.Mapping("Delete", c.Delete) c.Mapping("Delete", c.Delete)
} }
// @Title 获取部门列表 // GetAll @Title获取部门列表
// @Description 获取部门列表 // @Description 获取部门列表
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [get] // @router / [get]
@ -30,17 +30,22 @@ func (c *DeptController) GetAll() {
enabled, _ := c.GetInt8("enabled", -1) enabled, _ := c.GetInt8("enabled", -1)
list := models.GetAllDepts(name, enabled) list := models.GetAllDepts(name, enabled)
c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: 0}) c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: 0})
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 添加部门 // Post @Title添加部门
// @Description 添加部门 // @Description 添加部门
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [post] // @router / [post]
func (c *DeptController) Post() { func (c *DeptController) Post() {
var model models.SysDept var model models.SysDept
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -52,17 +57,22 @@ func (c *DeptController) Post() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 修改部门 // Put @Title修改部门
// @Description 修改部门 // @Description 修改部门
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [put] // @router / [put]
func (c *DeptController) Put() { func (c *DeptController) Put() {
var model models.SysDept var model models.SysDept
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -74,21 +84,26 @@ func (c *DeptController) Put() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 删除部门 // Delete @Title 删除部门
// @Description 删除部门 // @Description 删除部门
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [delete] // @router / [delete]
func (c *DeptController) Delete() { func (c *DeptController) Delete() {
var ids []int64 var ids []int64
json.Unmarshal(c.Ctx.Input.RequestBody, &ids) err := json.Unmarshal(c.Ctx.Input.RequestBody, &ids)
logs.Info(ids) if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
logs.Info("获取对象:{}", ids)
e := models.DelByDept(ids) e := models.DelByDept(ids)
if e != nil { if e != nil {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }

32
controllers/admin/DictController.go

@ -8,7 +8,7 @@ import (
"viviman.top/vo" "viviman.top/vo"
) )
// 字典api // DictController 字典api
type DictController struct { type DictController struct {
controllers.BaseController controllers.BaseController
} }
@ -21,24 +21,29 @@ func (c *DictController) URLMapping() {
//c.Mapping("Delete", c.Delete) //c.Mapping("Delete", c.Delete)
} }
// @Title 获取字典列表 // GetAll @Title获取字典列表
// @Description 获取字典列表 // @Description 获取字典列表
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [get] // @router / [get]
func (c *DictController) GetAll() { func (c *DictController) GetAll() {
total, list := models.GetAllDict(c.GetParams()) total, list := models.GetAllDict(c.GetParams())
c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total}) c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total})
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 添加字典 // Post @Title添加字典
// @Description 添加字典 // @Description 添加字典
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [post] // @router / [post]
func (c *DictController) Post() { func (c *DictController) Post() {
var dictModel models.SysDict var dictModel models.SysDict
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &dictModel) err := json.Unmarshal(c.Ctx.Input.RequestBody, &dictModel)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&dictModel) b, _ := valid.Valid(&dictModel)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -50,17 +55,22 @@ func (c *DictController) Post() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 修改字典 // Put @Title修改字典
// @Description 修改字典 // @Description 修改字典
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [put] // @router / [put]
func (c *DictController) Put() { func (c *DictController) Put() {
var dictModel models.SysDict var dictModel models.SysDict
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &dictModel) err := json.Unmarshal(c.Ctx.Input.RequestBody, &dictModel)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&dictModel) b, _ := valid.Valid(&dictModel)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -72,10 +82,10 @@ func (c *DictController) Put() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 删除字典 // Delete @Title删除字典
// @Description 删除字典 // @Description 删除字典
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /:id [delete] // @router /:id [delete]
@ -86,5 +96,5 @@ func (c *DictController) Delete() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }

32
controllers/admin/DictDetailController.go

@ -9,7 +9,7 @@ import (
"viviman.top/vo" "viviman.top/vo"
) )
// 字典详情api // DictDetailController 字典详情api
type DictDetailController struct { type DictDetailController struct {
controllers.BaseController controllers.BaseController
} }
@ -21,7 +21,7 @@ func (c *DictDetailController) URLMapping() {
c.Mapping("Delete", c.Delete) c.Mapping("Delete", c.Delete)
} }
// @Title 获取字典详情列表 // GetAll @Title获取字典详情列表
// @Description 获取字典详情列表 // @Description 获取字典详情列表
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [get] // @router / [get]
@ -30,17 +30,22 @@ func (c *DictDetailController) GetAll() {
dictName := c.GetString("dictName") dictName := c.GetString("dictName")
total, list := models.GetAllDictDetail(c.GetParams(), dictId, dictName) total, list := models.GetAllDictDetail(c.GetParams(), dictId, dictName)
c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total}) c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total})
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 添加字典详情 // Post @Title添加字典详情
// @Description 添加字典详情 // @Description 添加字典详情
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [post] // @router / [post]
func (c *DictDetailController) Post() { func (c *DictDetailController) Post() {
var model models.SysDictDetail var model models.SysDictDetail
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
logs.Info(model) logs.Info(model)
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
@ -53,17 +58,22 @@ func (c *DictDetailController) Post() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 修改字典详情 // Put @Title修改字典详情
// @Description 修改字典详情 // @Description 修改字典详情
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [put] // @router / [put]
func (c *DictDetailController) Put() { func (c *DictDetailController) Put() {
var model models.SysDictDetail var model models.SysDictDetail
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -75,10 +85,10 @@ func (c *DictDetailController) Put() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 删除字典详情 // Delete @Title删除字典详情
// @Description 删除字典详情 // @Description 删除字典详情
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /:id [delete] // @router /:id [delete]
@ -89,5 +99,5 @@ func (c *DictDetailController) Delete() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }

39
controllers/admin/JobController.go

@ -9,7 +9,7 @@ import (
"viviman.top/vo" "viviman.top/vo"
) )
// 岗位api // JobController 岗位api
type JobController struct { type JobController struct {
controllers.BaseController controllers.BaseController
} }
@ -21,7 +21,7 @@ func (c *JobController) URLMapping() {
c.Mapping("Delete", c.Delete) c.Mapping("Delete", c.Delete)
} }
// @Title 岗位列表 // GetAll @Title 岗位列表
// @Description 岗位列表 // @Description 岗位列表
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [get] // @router / [get]
@ -29,17 +29,22 @@ func (c *JobController) GetAll() {
enabled, _ := c.GetInt64("enabled", -1) enabled, _ := c.GetInt64("enabled", -1)
total, list := models.GetAllJob(c.GetParams(), enabled) total, list := models.GetAllJob(c.GetParams(), enabled)
c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total}) c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total})
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 岗位添加 // Post @Title 岗位添加
// @Description 岗位添加 // @Description 岗位添加
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [post] // @router / [post]
func (c *JobController) Post() { func (c *JobController) Post() {
var model models.SysJob var model models.SysJob
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -51,17 +56,22 @@ func (c *JobController) Post() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 岗位修改 // Put @Title 岗位修改
// @Description 岗位修改 // @Description 岗位修改
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [put] // @router / [put]
func (c *JobController) Put() { func (c *JobController) Put() {
var model models.SysJob var model models.SysJob
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -73,21 +83,26 @@ func (c *JobController) Put() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 岗位删除 // Delete @Title 岗位删除
// @Description 岗位删除 // @Description 岗位删除
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [delete] // @router / [delete]
func (c *JobController) Delete() { func (c *JobController) Delete() {
var ids []int64 var ids []int64
json.Unmarshal(c.Ctx.Input.RequestBody, &ids) err := json.Unmarshal(c.Ctx.Input.RequestBody, &ids)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
logs.Info(ids) logs.Info(ids)
e := models.DelByJob(ids) e := models.DelByJob(ids)
if e != nil { if e != nil {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }

28
controllers/admin/LoginController.go

@ -15,7 +15,7 @@ import (
"viviman.top/vo" "viviman.top/vo"
) )
// 登录api // LoginController 登录api
type LoginController struct { type LoginController struct {
controllers.BaseController controllers.BaseController
} }
@ -36,7 +36,7 @@ func (c *LoginController) URLMapping() {
c.Mapping("Logout", c.Logout) c.Mapping("Logout", c.Logout)
} }
// @Title 登录 // Login @Title 登录验证
// @Description 登录 // @Description 登录
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /login [post] // @router /login [post]
@ -52,7 +52,7 @@ func (c *LoginController) Login() {
//校验验证码 //校验验证码
if !store.Verify(authUser.Id, authUser.Code, true) { if !store.Verify(authUser.Id, authUser.Code, true) {
c.Data["json"] = controllers.ErrMsg("验证码不对") c.Data["json"] = controllers.ErrMsg("验证码不对")
c.ServeJSON() _ = c.ServeJSON()
} }
if e != nil { if e != nil {
c.Data["json"] = controllers.ErrMsg("用户不存在") c.Data["json"] = controllers.ErrMsg("用户不存在")
@ -72,19 +72,19 @@ func (c *LoginController) Login() {
c.Data["json"] = controllers.ErrMsg(err.Error()) c.Data["json"] = controllers.ErrMsg(err.Error())
} }
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 获取用户信息 // Info @Title获取用户信息
// @Description 获取用户信息 // @Description 获取用户信息
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /info [get] // @router /info [get]
func (c *LoginController) Info() { func (c *LoginController) Info() {
c.Data["json"] = controllers.SuccessData(jwt.GetAdminDetailUser(c.Ctx.Input)) c.Data["json"] = controllers.SuccessData(jwt.GetAdminDetailUser(c.Ctx.Input))
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 退出登录 // Logout @Title退出登录
// @Description 退出登录 // @Description 退出登录
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /logout [delete] // @router /logout [delete]
@ -95,18 +95,18 @@ func (c *LoginController) Logout() {
} else { } else {
c.Data["json"] = controllers.SuccessData("退出成功") c.Data["json"] = controllers.SuccessData("退出成功")
} }
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 获取验证码 // Captcha @Title 获取验证码
// @Description 获取验证码 // @Description 获取验证码
// @router /captcha [get] // @router /captcha [get]
func (c *LoginController) Captcha() { func (c *LoginController) Captcha() {
GenerateCaptcha(c.Ctx) GenerateCaptcha(c.Ctx)
c.ServeJSON() _ = c.ServeJSON()
} }
// 生成图形化验证码 ctx *context.Context // GenerateCaptcha 生成图形化验证码 ctx *context.Context
func GenerateCaptcha(ctx *context.Context) { func GenerateCaptcha(ctx *context.Context) {
var driver base64Captcha.Driver var driver base64Captcha.Driver
var driverString base64Captcha.DriverMath var driverString base64Captcha.DriverMath
@ -140,5 +140,9 @@ func GenerateCaptcha(ctx *context.Context) {
Base64Blob: b64s, Base64Blob: b64s,
} }
ctx.Output.JSON(controllers.SuccessData(captchaResult), true, true) err = ctx.Output.JSON(controllers.SuccessData(captchaResult), true, true)
if err != nil {
logs.Error("输出时,发生异常!")
return
}
} }

47
controllers/admin/MenuController.go

@ -9,7 +9,7 @@ import (
"viviman.top/vo" "viviman.top/vo"
) )
// 菜单api // MenuController 菜单api
type MenuController struct { type MenuController struct {
controllers.BaseController controllers.BaseController
} }
@ -22,7 +22,7 @@ func (c *MenuController) URLMapping() {
c.Mapping("Delete", c.Delete) c.Mapping("Delete", c.Delete)
} }
// @Title 菜单列表 // GetAll @Title 菜单列表
// @Description 菜单列表 // @Description 菜单列表
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [get] // @router / [get]
@ -30,17 +30,22 @@ func (c *MenuController) GetAll() {
name := c.GetString("blurry") name := c.GetString("blurry")
menus := models.GetAllMenus(name) menus := models.GetAllMenus(name)
c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: menus, TotalElements: 0}) c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: menus, TotalElements: 0})
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 菜单添加 // Post @Title 菜单添加
// @Description 菜单添加 // @Description 菜单添加
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [post] // @router / [post]
func (c *MenuController) Post() { func (c *MenuController) Post() {
var model models.SysMenu var model models.SysMenu
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -52,17 +57,22 @@ func (c *MenuController) Post() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 菜单修改 // Put @Title 菜单修改
// @Description 菜单修改 // @Description 菜单修改
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [put] // @router / [put]
func (c *MenuController) Put() { func (c *MenuController) Put() {
var model models.SysMenu var model models.SysMenu
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -74,25 +84,30 @@ func (c *MenuController) Put() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 菜单删除 // Delete @Title 菜单删除
// @Description 菜单删除 // @Description 菜单删除
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [delete] // @router / [delete]
func (c *MenuController) Delete() { func (c *MenuController) Delete() {
var ids []int64 var ids []int64
json.Unmarshal(c.Ctx.Input.RequestBody, &ids) err := json.Unmarshal(c.Ctx.Input.RequestBody, &ids)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
e := models.DelByMenu(ids) e := models.DelByMenu(ids)
if e != nil { if e != nil {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 菜单构建 // Build @Title 菜单构建
// @Description 菜单构建 // @Description 菜单构建
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /build [get] // @router /build [get]
@ -100,15 +115,15 @@ func (c *MenuController) Build() {
uid, _ := jwt.GetAdminUserId(c.Ctx.Input) uid, _ := jwt.GetAdminUserId(c.Ctx.Input)
menus := models.BuildMenus(uid) menus := models.BuildMenus(uid)
c.Data["json"] = controllers.SuccessData(menus) c.Data["json"] = controllers.SuccessData(menus)
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 菜单树形 // GetTree @Title 菜单树形
// @Description 菜单树形 // @Description 菜单树形
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /tree [get] // @router /tree [get]
func (c *MenuController) GetTree() { func (c *MenuController) GetTree() {
menus := models.GetAllMenus("") menus := models.GetAllMenus("")
c.Data["json"] = controllers.SuccessData(menus) c.Data["json"] = controllers.SuccessData(menus)
c.ServeJSON() _ = c.ServeJSON()
} }

54
controllers/admin/RoleController.go

@ -11,7 +11,7 @@ import (
"viviman.top/vo" "viviman.top/vo"
) )
// 角色 API // RoleController 角色 API
type RoleController struct { type RoleController struct {
controllers.BaseController controllers.BaseController
} }
@ -23,7 +23,7 @@ func (c *RoleController) URLMapping() {
c.Mapping("Delete", c.Delete) c.Mapping("Delete", c.Delete)
} }
// @Title 获取单个角色 // GetOne @Title 获取单个角色
// @Description 获取单个角色 // @Description 获取单个角色
// @Param id path int true "角色ID" // @Param id path int true "角色ID"
// @Success 200 {object} models.Role // @Success 200 {object} models.Role
@ -33,27 +33,32 @@ func (c *RoleController) GetOne() {
id64, _ := strconv.ParseInt(id, 10, 64) id64, _ := strconv.ParseInt(id, 10, 64)
role := models.GetOneRole(id64) role := models.GetOneRole(id64)
c.Data["json"] = controllers.SuccessData(role) c.Data["json"] = controllers.SuccessData(role)
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 角色列表 // GetAll @Title 角色列表
// @Description 角色列表 // @Description 角色列表
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [get] // @router / [get]
func (c *RoleController) GetAll() { func (c *RoleController) GetAll() {
total, list := models.GetAllRole(c.GetParams()) total, list := models.GetAllRole(c.GetParams())
c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total}) c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total})
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 角色添加 // Post @Title 角色添加
// @Description 角色添加 // @Description 角色添加
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [post] // @router / [post]
func (c *RoleController) Post() { func (c *RoleController) Post() {
var model models.SysRole var model models.SysRole
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -65,14 +70,19 @@ func (c *RoleController) Post() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @router / [put] // Put @router / [put]
func (c *RoleController) Put() { func (c *RoleController) Put() {
var model models.SysRole var model models.SysRole
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -84,33 +94,43 @@ func (c *RoleController) Put() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 角色删除 // Delete @Title 角色删除
// @Description 角色删除 // @Description 角色删除
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [delete] // @router / [delete]
func (c *RoleController) Delete() { func (c *RoleController) Delete() {
var ids []int64 var ids []int64
json.Unmarshal(c.Ctx.Input.RequestBody, &ids) err := json.Unmarshal(c.Ctx.Input.RequestBody, &ids)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
logs.Info(ids) logs.Info(ids)
e := models.DelByRole(ids) e := models.DelByRole(ids)
if e != nil { if e != nil {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 角色菜单更新 // Menu @Title 角色菜单更新
// @Description 角色菜单更新 // @Description 角色菜单更新
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /menu [put] // @router /menu [put]
func (c *RoleController) Menu() { func (c *RoleController) Menu() {
var model dto.RoleMenu var model dto.RoleMenu
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
logs.Info("=======menu======") logs.Info("=======menu======")
logs.Info(model) logs.Info(model)
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
@ -121,5 +141,5 @@ func (c *RoleController) Menu() {
} }
models.BatchRoleMenuAdd(model) models.BatchRoleMenuAdd(model)
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }

4
controllers/admin/ToolsController.go

@ -8,9 +8,9 @@ type ToolsController struct {
controllers.BaseController controllers.BaseController
} }
// @router / [post] // Post @router / [post]
func (c *ToolsController) Post() { func (c *ToolsController) Post() {
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }

87
controllers/admin/UserController.go

@ -13,7 +13,7 @@ import (
"viviman.top/vo" "viviman.top/vo"
) )
// 用户 API // UserController 用户 API
type UserController struct { type UserController struct {
controllers.BaseController controllers.BaseController
} }
@ -25,7 +25,7 @@ func (c *UserController) URLMapping() {
c.Mapping("Delete", c.Delete) c.Mapping("Delete", c.Delete)
} }
// @Title 用户列表 // GetAll @Title 用户列表
// @Description 用户列表 // @Description 用户列表
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [get] // @router / [get]
@ -34,17 +34,22 @@ func (c *UserController) GetAll() {
enabled, _ := c.GetInt64("enabled", -1) enabled, _ := c.GetInt64("enabled", -1)
total, list := models.GetAllUser(c.GetParams(), deptId, enabled) total, list := models.GetAllUser(c.GetParams(), deptId, enabled)
c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total}) c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total})
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 用户添加 // Post @Title 用户添加
// @Description 用户添加 // @Description 用户添加
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [post] // @router / [post]
func (c *UserController) Post() { func (c *UserController) Post() {
var model models.SysUser var model models.SysUser
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -56,17 +61,22 @@ func (c *UserController) Post() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 用户编辑 // Put @Title 用户编辑
// @Description 用户编辑 // @Description 用户编辑
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [put] // @router / [put]
func (c *UserController) Put() { func (c *UserController) Put() {
var model models.SysUser var model models.SysUser
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
logs.Info("======start======") logs.Info("======start======")
logs.Info(model) logs.Info(model)
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
@ -80,25 +90,30 @@ func (c *UserController) Put() {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 用户删除 // Delete @Title 用户删除
// @Description 用户删除 // @Description 用户删除
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router / [delete] // @router / [delete]
func (c *UserController) Delete() { func (c *UserController) Delete() {
var ids []int64 var ids []int64
json.Unmarshal(c.Ctx.Input.RequestBody, &ids) err := json.Unmarshal(c.Ctx.Input.RequestBody, &ids)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
e := models.DelByUser(ids) e := models.DelByUser(ids)
if e != nil { if e != nil {
c.Data["json"] = controllers.ErrMsg(e.Error()) c.Data["json"] = controllers.ErrMsg(e.Error())
} }
c.Data["json"] = controllers.SuccessData("操作成功") c.Data["json"] = controllers.SuccessData("操作成功")
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 用户上传图像 // Avatar @Title 用户上传图像
// @Description 用户上传图像 // @Description 用户上传图像
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /updateAvatar [post] // @router /updateAvatar [post]
@ -122,20 +137,29 @@ func (c *UserController) Avatar() {
c.Data["json"] = controllers.ErrMsg("非法操作") c.Data["json"] = controllers.ErrMsg("非法操作")
} else { } else {
user.Avatar = avatarUrl user.Avatar = avatarUrl
models.UpdateCurrentUser(user) err := models.UpdateCurrentUser(user)
if err != nil {
logs.Error("更新时,发生异常!")
return
}
c.Data["json"] = controllers.SuccessData("ok") c.Data["json"] = controllers.SuccessData("ok")
} }
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 用户修改密码 // Pass @Title 用户修改密码
// @Description 用户修改密码 // @Description 用户修改密码
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /updatePass [post] // @router /updatePass [post]
func (c *UserController) Pass() { func (c *UserController) Pass() {
var model dto.UserPass var model dto.UserPass
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
@ -150,29 +174,38 @@ func (c *UserController) Pass() {
} else { } else {
if !untils.ComparePwd(user.Password, []byte(model.OldPass)) { if !untils.ComparePwd(user.Password, []byte(model.OldPass)) {
c.Data["json"] = controllers.ErrMsg("旧密码错误密码错误") c.Data["json"] = controllers.ErrMsg("旧密码错误密码错误")
c.ServeJSON() _ = c.ServeJSON()
} }
user.Password = untils.HashAndSalt([]byte(model.NewPass)) user.Password = untils.HashAndSalt([]byte(model.NewPass))
models.UpdateCurrentUser(user) err := models.UpdateCurrentUser(user)
if err != nil {
logs.Error("更新时,发生异常!")
return
}
c.Data["json"] = controllers.SuccessData("ok") c.Data["json"] = controllers.SuccessData("ok")
} }
c.ServeJSON() _ = c.ServeJSON()
} }
// @Title 用户修改个人信息 // Center @Title 用户修改个人信息
// @Description 用户修改个人信息 // @Description 用户修改个人信息
// @Success 200 {object} controllers.Result // @Success 200 {object} controllers.Result
// @router /center [put] // @router /center [put]
func (c *UserController) Center() { func (c *UserController) Center() {
var model dto.UserPost var model dto.UserPost
valid := validation.Validation{} valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model) err := json.Unmarshal(c.Ctx.Input.RequestBody, &model)
if err != nil {
c.Data["json"] = controllers.ErrMsg("转译时,发生异常!")
_ = c.ServeJSON()
return
}
b, _ := valid.Valid(&model) b, _ := valid.Valid(&model)
if !b { if !b {
for _, err := range valid.Errors { for _, err := range valid.Errors {
c.Data["json"] = controllers.ErrMsg(err.Message) c.Data["json"] = controllers.ErrMsg(err.Message)
} }
c.ServeJSON() _ = c.ServeJSON()
} }
//save user //save user
uid, _ := jwt.GetAdminUserId(c.Ctx.Input) uid, _ := jwt.GetAdminUserId(c.Ctx.Input)
@ -183,8 +216,12 @@ func (c *UserController) Center() {
user.Phone = model.Phone user.Phone = model.Phone
user.Sex = model.Sex user.Sex = model.Sex
user.NickName = model.NickName user.NickName = model.NickName
models.UpdateCurrentUser(user) err := models.UpdateCurrentUser(user)
if err != nil {
logs.Error("查询时,发生异常!")
return
}
c.Data["json"] = controllers.SuccessData("ok") c.Data["json"] = controllers.SuccessData("ok")
} }
c.ServeJSON() _ = c.ServeJSON()
} }

135
controllers/vivib/LiCaiController.go

@ -0,0 +1,135 @@
package vivib
import (
"encoding/json"
"github.com/beego/beego/v2/core/logs"
"github.com/beego/beego/v2/core/validation"
"strconv"
"viviman.top/controllers"
"viviman.top/dto"
"viviman.top/models"
"viviman.top/vo"
)
// LiCaiController 财务记录 API
type LiCaiController struct {
controllers.BaseController
}
func (c *LiCaiController) URLMapping() {
c.Mapping("Post", c.Post)
c.Mapping("CpPost", c.CpPost)
c.Mapping("GetAll", c.GetAll)
c.Mapping("Put", c.Put)
c.Mapping("Delete", c.Delete)
}
// GetOne @Title获取单个财务记录
// @Description 获取单个财务记录
// @Param id path int true "角色ID"
// @Success 200 {object} models.Role
// @router /:id [get]
func (c *LiCaiController) GetOne() {
id := c.Ctx.Input.Param(":id")
id64, _ := strconv.ParseInt(id, 10, 64)
role := models.GetOneRole(id64)
c.Data["json"] = controllers.SuccessData(role)
_ = c.ServeJSON()
}
// GetAll @Title角色列表
// @Description 角色列表
// @Success 200 {object} controllers.Result
// @router / [get]
func (c *LiCaiController) GetAll() {
total, list := models.GetAllRole(c.GetParams())
c.Data["json"] = controllers.SuccessData(vo.ResultList{Content: list, TotalElements: total})
_ = c.ServeJSON()
}
// CpPost @Title财务记录复制
// @Description 角色添加
// @Success 200 {object} controllers.Result
// @router / [post]
func (c *LiCaiController) CpPost() {
}
// Post @Title角色添加
// @Description 角色添加
// @Success 200 {object} controllers.Result
// @router / [post]
func (c *LiCaiController) Post() {
var model models.SysRole
valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model)
b, _ := valid.Valid(&model)
if !b {
for _, err := range valid.Errors {
c.Data["json"] = controllers.ErrMsg(err.Message)
}
}
_, e := models.AddRole(&model)
if e != nil {
c.Data["json"] = controllers.ErrMsg(e.Error())
}
c.Data["json"] = controllers.SuccessData("操作成功")
_ = c.ServeJSON()
}
// Put
// @router / [put]
func (c *LiCaiController) Put() {
var model models.SysRole
valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model)
b, _ := valid.Valid(&model)
if !b {
for _, err := range valid.Errors {
c.Data["json"] = controllers.ErrMsg(err.Message)
}
}
e := models.UpdateByRole(&model)
if e != nil {
c.Data["json"] = controllers.ErrMsg(e.Error())
}
c.Data["json"] = controllers.SuccessData("操作成功")
_ = c.ServeJSON()
}
// Delete @Title角色删除
// @Description 角色删除
// @Success 200 {object} controllers.Result
// @router / [delete]
func (c *LiCaiController) Delete() {
var ids []int64
json.Unmarshal(c.Ctx.Input.RequestBody, &ids)
logs.Info(ids)
e := models.DelByRole(ids)
if e != nil {
c.Data["json"] = controllers.ErrMsg(e.Error())
}
c.Data["json"] = controllers.SuccessData("操作成功")
_ = c.ServeJSON()
}
// Menu @Title角色菜单更新
// @Description 角色菜单更新
// @Success 200 {object} controllers.Result
// @router /menu [put]
func (c *LiCaiController) Menu() {
var model dto.RoleMenu
valid := validation.Validation{}
json.Unmarshal(c.Ctx.Input.RequestBody, &model)
logs.Info("=======menu======")
logs.Info(model)
b, _ := valid.Valid(&model)
if !b {
for _, err := range valid.Errors {
c.Data["json"] = controllers.ErrMsg(err.Message)
}
}
models.BatchRoleMenuAdd(model)
c.Data["json"] = controllers.SuccessData("操作成功")
_ = c.ServeJSON()
}

1
main.go

@ -59,7 +59,6 @@ func main() {
beego.BConfig.WebConfig.DirectoryIndex = true beego.BConfig.WebConfig.DirectoryIndex = true
beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger" beego.BConfig.WebConfig.StaticDir["/swagger"] = "swagger"
} }
//
beego.InsertFilterChain("/*", func(next beego.FilterFunc) beego.FilterFunc { beego.InsertFilterChain("/*", func(next beego.FilterFunc) beego.FilterFunc {
return func(ctx *context.Context) { return func(ctx *context.Context) {

4
models/SysDept.go

@ -34,7 +34,7 @@ func GetAllDepts(name string, enabled int8) []SysDept {
return RecursionDeptList(depts, 0) return RecursionDeptList(depts, 0)
} }
//递归函数 // RecursionDeptList 递归函数
func RecursionDeptList(data []SysDept, pid int64) []SysDept { func RecursionDeptList(data []SysDept, pid int64) []SysDept {
var listTree = make([]SysDept, 0) var listTree = make([]SysDept, 0)
for _, value := range data { for _, value := range data {
@ -61,7 +61,7 @@ func UpdateByDept(m *SysDept) (err error) {
func DelByDept(ids []int64) (err error) { func DelByDept(ids []int64) (err error) {
str := untils.ReturnQ(len(ids)) str := untils.ReturnQ(len(ids))
logs.Info(str) logs.Debug(str)
o := orm.NewOrm() o := orm.NewOrm()
_, err = o.Raw("UPDATE sys_dept SET is_del = ? WHERE id in("+str+")", 1, ids).Exec() _, err = o.Raw("UPDATE sys_dept SET is_del = ? WHERE id in("+str+")", 1, ids).Exec()
return return

9
redis/pool.go

@ -16,19 +16,20 @@ var (
func init() { func init() {
host, _ := beego.AppConfig.String("redis_host") host, _ := beego.AppConfig.String("redis_host")
pwd, _ := beego.AppConfig.String("redis_pwd") pwd, _ := beego.AppConfig.String("redis_pwd")
Pool = newPool(host, pwd) db, _ := beego.AppConfig.Int("redis_db")
Pool = newPool(host, pwd, db)
cleanupHook() cleanupHook()
} }
func newPool(server string, pwd string) *redis.Pool { func newPool(server string, pwd string, db int) *redis.Pool {
dialOption := redis.DialDatabase(db)
return &redis.Pool{ return &redis.Pool{
MaxIdle: 3, MaxIdle: 3,
IdleTimeout: 240 * time.Second, IdleTimeout: 240 * time.Second,
Dial: func() (redis.Conn, error) { Dial: func() (redis.Conn, error) {
c, err := redis.Dial("tcp", server) c, err := redis.Dial("tcp", server, dialOption)
if err != nil { if err != nil {
return nil, err return nil, err
} }

11
routers/router.go

@ -7,6 +7,7 @@ package routers
import ( import (
beego "github.com/beego/beego/v2/server/web" beego "github.com/beego/beego/v2/server/web"
"viviman.top/controllers/admin" "viviman.top/controllers/admin"
"viviman.top/controllers/vivib"
) )
func init() { func init() {
@ -60,7 +61,15 @@ func init() {
), ),
), ),
) )
beego.AddNamespace(ns1, ns2) //财务管理后台路由
ns3 := beego.NewNamespace("/vivib",
beego.NSNamespace("/licai",
beego.NSInclude(
&vivib.LiCaiController{},
),
),
)
beego.AddNamespace(ns1, ns2, ns3)
//beego.SetStaticPath("/swagger/", "swagger") //beego.SetStaticPath("/swagger/", "swagger")
} }

0
sql/yshop_go.sql → sql/viviman_go.sql

8
untils/tools.go

@ -8,7 +8,7 @@ import (
"viviman.top/controllers" "viviman.top/controllers"
) )
//加密 // HashAndSalt 加密
func HashAndSalt(pwd []byte) string { func HashAndSalt(pwd []byte) string {
hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost) hash, err := bcrypt.GenerateFromPassword(pwd, bcrypt.MinCost)
if err != nil { if err != nil {
@ -17,7 +17,7 @@ func HashAndSalt(pwd []byte) string {
return string(hash) return string(hash)
} }
//密码验证 // ComparePwd 密码验证
func ComparePwd(hashPwd string, plainPwd []byte) bool { func ComparePwd(hashPwd string, plainPwd []byte) bool {
byteHash := []byte(hashPwd) byteHash := []byte(hashPwd)
err := bcrypt.CompareHashAndPassword(byteHash, plainPwd) err := bcrypt.CompareHashAndPassword(byteHash, plainPwd)
@ -28,7 +28,7 @@ func ComparePwd(hashPwd string, plainPwd []byte) bool {
return true return true
} }
//判断array contain item // Contains 判断array contain item
func Contains(array interface{}, val interface{}) (index int) { func Contains(array interface{}, val interface{}) (index int) {
index = -1 index = -1
switch reflect.TypeOf(array).Kind() { switch reflect.TypeOf(array).Kind() {
@ -46,12 +46,14 @@ func Contains(array interface{}, val interface{}) (index int) {
return return
} }
// Convert 数组转字符串
//[a] -> a -> a //[a] -> a -> a
//[a b c] -> a b c -> a,b,c //[a b c] -> a b c -> a,b,c
func Convert(array interface{}) string { func Convert(array interface{}) string {
return strings.Replace(strings.Trim(fmt.Sprint(array), "[]"), " ", ",", -1) return strings.Replace(strings.Trim(fmt.Sprint(array), "[]"), " ", ",", -1)
} }
// IntToBool 数值转布尔
func IntToBool(num int8) bool { func IntToBool(num int8) bool {
if num > 0 { if num > 0 {
return true return true

3
web/.eslintignore

@ -1,8 +1,7 @@
build/*.js build/*.js
src/assets
public public
dist dist
src/views src/

50
web/src/api/vivib/licai.js

@ -0,0 +1,50 @@
import request from '@/utils/request'
// 获取所有的Role
export function getAll() {
return request({
url: 'admin/roles',
method: 'get'
})
}
export function add(data) {
return request({
url: 'admin/roles',
method: 'post',
data
})
}
export function get(id) {
return request({
url: 'admin/roles/' + id,
method: 'get'
})
}
export function del(ids) {
return request({
url: 'admin/roles',
method: 'delete',
data: ids
})
}
export function edit(data) {
return request({
url: 'admin/roles',
method: 'put',
data
})
}
export function editMenu(data) {
return request({
url: 'admin/roles/menu',
method: 'put',
data
})
}
export default { add, edit, del, get, editMenu }

2
web/src/layout/components/AppMain.vue

@ -27,7 +27,7 @@ export default {
} }
</script> </script>
<style lang="scss" scoped> <style type="text/scss" rel="stylesheet/scss" lang="scss" scoped>
.app-main { .app-main {
/* 50= navbar 50 */ /* 50= navbar 50 */
min-height: calc(100vh - 50px); min-height: calc(100vh - 50px);

2
web/src/layout/components/Navbar.vue

@ -120,7 +120,7 @@ export default {
} }
</script> </script>
<style lang="scss" scoped> <style type="text/scss" rel="stylesheet/scss" lang="scss" scoped>
.navbar { .navbar {
height: 50px; height: 50px;
overflow: hidden; overflow: hidden;

2
web/src/layout/components/Settings/index.vue

@ -97,7 +97,7 @@ export default {
} }
</script> </script>
<style lang="scss" scoped> <style type="text/scss" rel="stylesheet/scss" lang="scss" scoped>
.drawer-container { .drawer-container {
padding: 24px; padding: 24px;
font-size: 14px; font-size: 14px;

2
web/src/layout/components/Sidebar/Logo.vue

@ -32,7 +32,7 @@ export default {
} }
</script> </script>
<style lang="scss" scoped> <style type="text/scss" rel="stylesheet/scss" lang="scss" scoped>
.sidebarLogoFade-enter-active { .sidebarLogoFade-enter-active {
transition: opacity 1.5s; transition: opacity 1.5s;
} }

2
web/src/layout/components/TagsView/ScrollPane.vue

@ -67,7 +67,7 @@ export default {
} }
</script> </script>
<style lang="scss" scoped> <style type="text/scss" rel="stylesheet/scss" lang="scss" scoped>
.scroll-container { .scroll-container {
white-space: nowrap; white-space: nowrap;
position: relative; position: relative;

2
web/src/layout/components/TagsView/index.vue

@ -191,7 +191,7 @@ export default {
} }
</script> </script>
<style lang="scss" scoped> <style type="text/scss" rel="stylesheet/scss" lang="scss" scoped>
.tags-view-container { .tags-view-container {
height: 34px; height: 34px;
width: 100%; width: 100%;

2
web/src/layout/index.vue

@ -57,7 +57,7 @@ export default {
} }
</script> </script>
<style lang="scss" scoped> <style type="text/scss" rel="stylesheet/scss" lang="scss" scoped>
@import "~@/assets/styles/mixin.scss"; @import "~@/assets/styles/mixin.scss";
@import "~@/assets/styles/variables.scss"; @import "~@/assets/styles/variables.scss";

2
web/src/views/components/icons/index.vue

@ -62,7 +62,7 @@ export default {
} }
</script> </script>
<style lang="scss" scoped> <style type="text/scss" rel="stylesheet/scss" lang="scss" scoped>
.icons-container { .icons-container {
margin: 10px 20px 0; margin: 10px 20px 0;
overflow: hidden; overflow: hidden;

2
web/src/views/dashboard/OrderCount.vue

@ -83,7 +83,7 @@ export default {
</script> </script>
<style lang="scss" scoped> <style type="text/scss" rel="stylesheet/scss" lang="scss" scoped>
.acea-row{ .acea-row{
/deep/.el-avatar--small { /deep/.el-avatar--small {
width: 22px; width: 22px;

2
web/src/views/features/401.vue

@ -48,7 +48,7 @@ export default {
} }
</script> </script>
<style lang="scss" scoped> <style rel="stylesheet/scss" lang="scss" scoped>
.errPage-container { .errPage-container {
width: 800px; width: 800px;
max-width: 100%; max-width: 100%;

94
web/src/views/vivib/licai/index.vue

@ -0,0 +1,94 @@
<template>
<div class="app-container">
<!--工具栏-->
<div class="head-container">
<div v-if="crud.props.searchToggle">
<!-- 搜索 -->
<el-input v-model="query.blurry" size="small" clearable placeholder="输入名称搜索" style="width: 200px;" class="filter-item" @keyup.enter.native="crud.toQuery" />
<rrOperation :crud="crud" />
</div>
<crudOperation :permission="permission" />
</div>
<!-- 表单渲染 -->
<el-dialog append-to-body :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0" :title="crud.status.title" width="520px">
<el-form ref="form" :inline="true" :model="form" :rules="rules" size="small" label-width="80px">
<el-form-item label="角色名称" prop="name">
<el-input v-model="form.name" style="width: 145px;" />
</el-form-item>
<el-form-item label="角色权限" prop="permission">
<el-input v-model="form.permission" style="width: 145px;" />
</el-form-item>
<el-form-item v-if="form.dataScope === '自定义'" label="数据权限" prop="depts">
<treeselect v-model="form.depts" :options="depts" multiple style="width: 380px" placeholder="请选择"/>
</el-form-item>
<el-form-item label="描述信息" prop="remark">
<el-input v-model="form.remark" style="width: 380px;" rows="5" type="textarea"/>
</el-form-item>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button type="text" @click="crud.cancelCU">取消</el-button>
<el-button :loading="crud.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
</div>
</el-dialog>
<el-row :gutter="15">
<!--角色管理-->
<el-col :xs="24" :sm="24" :md="16" :lg="16" :xl="17" style="margin-bottom: 10px">
<el-card class="box-card" shadow="never">
<div slot="header" class="clearfix">
<span class="role-span">角色列表</span>
</div>
<el-table ref="table" v-loading="crud.loading" highlight-current-row style="width: 100%;" :data="crud.data"
@selection-change="crud.selectionChangeHandler" @current-change="handleCurrentChange">
<el-table-column :selectable="checkboxT" type="selection" width="55" />
<el-table-column v-if="columns.visible('name')" prop="name" label="名称" />
<el-table-column v-if="columns.visible('permission')" prop="permission" label="角色权限" />
<el-table-column v-if="columns.visible('remark')" :show-overflow-tooltip="true" prop="remark" label="描述" />
<el-table-column v-if="columns.visible('createTime')" :show-overflow-tooltip="true" width="135px" prop="createTime" label="创建日期">
<template slot-scope="scope">
<span>{{ parseTime(scope.row.createTime) }}</span>
</template>
</el-table-column>
<el-table-column v-permission="['admin','roles:edit','roles:del']" label="操作" width="130px" align="center" fixed="right">
<template slot-scope="scope">
<udOperation :data="scope.row" :permission="permission"/>
</template>
</el-table-column>
</el-table>
<!--分页组件-->
<pagination />
</el-card>
</el-col>
<!-- 菜单授权 -->
<el-col :xs="24" :sm="24" :md="8" :lg="8" :xl="7">
<el-card class="box-card" shadow="never">
<div slot="header" class="clearfix">
<el-tooltip class="item" effect="dark" content="选择指定角色分配菜单" placement="top">
<span class="role-span">菜单分配</span>
</el-tooltip>
<el-button v-permission="['admin','roles:edit']" :disabled="!showButton" :loading="menuLoading"
icon="el-icon-check" size="mini" style="float: right; padding: 6px 9px" type="primary" @click="saveMenu">保存</el-button>
</div>
<el-tree ref="menu" :data="menus" :default-checked-keys="menuIds" :props="defaultProps"
show-checkbox node-key="id"/>
</el-card>
</el-col>
</el-row>
</div>
</template>
<script type="text/javascript" src="./licaiJs.js"></script>
<style rel="stylesheet/scss" lang="scss">
.role-span {
font-weight: bold;color: #303133;
font-size: 15px;
}
/deep/ .el-input-number .el-input__inner {
text-align: left;
}
</style>

170
web/src/views/vivib/licai/licaiJs.js

@ -0,0 +1,170 @@
import crudRoles from '@/api/system/role'
import {getDepts} from '@/api/system/dept'
import {getMenusTree} from '@/api/system/menu'
import CRUD, {crud, form, header, presenter} from '@crud/crud'
import rrOperation from '@crud/RR.operation'
import crudOperation from '@crud/CRUD.operation'
import udOperation from '@crud/UD.operation'
import pagination from '@crud/Pagination'
import Treeselect from '@riophae/vue-treeselect'
import '@riophae/vue-treeselect/dist/vue-treeselect.css'
// crud交由presenter持有
const defaultCrud = CRUD({title: '角色', url: 'admin/roles', sort: 'level,asc', crudMethod: {...crudRoles}})
const defaultForm = {id: null, name: null, depts: [], remark: null, dataScope: '全部', level: 3, permission: null}
export default {
name: 'LiCai',
components: {Treeselect, pagination, crudOperation, rrOperation, udOperation},
mixins: [presenter(defaultCrud), header(), form(defaultForm), crud()],
data() {
return {
defaultProps: {children: 'children', label: 'label'},
dateScopes: ['全部', '本级', '自定义'], level: 3,
currentId: 0, menuLoading: false, showButton: false,
menus: [], menuIds: [], depts: [],
permission: {
add: ['admin', 'roles:add'],
edit: ['admin', 'roles:edit'],
del: ['admin', 'roles:del']
},
rules: {
name: [
{required: true, message: '请输入名称', trigger: 'blur'}
],
permission: [
{required: true, message: '请输入权限', trigger: 'blur'}
]
}
}
},
created() {
this.getMenus()
this.$nextTick(() => {
this.crud.toQuery()
})
},
methods: {
[CRUD.HOOK.afterRefresh]() {
this.$refs.menu.setCheckedKeys([])
},
// 编辑前
[CRUD.HOOK.beforeToEdit](crud, form) {
if (form.dataScope === '自定义') {
this.getDepts()
}
const depts = []
form.depts.forEach(function (dept, index) {
depts.push(dept.id)
})
form.depts = depts
},
// 提交前做的操作
[CRUD.HOOK.afterValidateCU](crud) {
if (crud.form.dataScope === '自定义' && crud.form.depts.length === 0) {
this.$message({
message: '自定义数据权限不能为空',
type: 'warning'
})
return false
} else if (crud.form.dataScope === '自定义') {
const depts = []
crud.form.depts.forEach(function (data, index) {
const dept = {id: data}
depts.push(dept)
})
crud.form.depts = depts
} else {
crud.form.depts = []
}
return true
},
[CRUD.HOOK.afterAddError](crud) {
this.afterErrorMethod(crud)
},
[CRUD.HOOK.afterEditError](crud) {
this.afterErrorMethod(crud)
},
afterErrorMethod(crud) {
const depts = []
crud.form.depts.forEach(function (dept, index) {
depts.push(dept.id)
})
crud.form.depts = depts
},
// 获取所有菜单
getMenus() {
getMenusTree().then(res => {
this.menus = res.data
})
},
// 触发单选
handleCurrentChange(val) {
if (val) {
const _this = this
// 清空菜单的选中
this.$refs.menu.setCheckedKeys([])
// 保存当前的角色id
this.currentId = val.id
this.showButton = val.level > 0
// 初始化
this.menuIds = []
// 菜单数据需要特殊处理
val.menus.forEach(function (data, index) {
if (data.pid != 0) {
_this.menuIds.push(data.id)
}
})
}
},
// 保存菜单
saveMenu() {
this.menuLoading = true
const role = {id: this.currentId, menus: []}
// 得到半选的父节点数据,保存起来
this.$refs.menu.getHalfCheckedNodes().forEach(function (data, index) {
const menu = {id: data.id}
role.menus.push(menu)
})
// 得到已选中的 key 值
this.$refs.menu.getCheckedKeys().forEach(function (data, index) {
const menu = {id: data}
role.menus.push(menu)
})
crudRoles.editMenu(role).then(res => {
this.crud.notify('保存成功', CRUD.NOTIFICATION_TYPE.SUCCESS)
this.menuLoading = false
this.update()
}).catch(err => {
this.menuLoading = false
console.log(err.response.data.message)
})
},
// 改变数据
update() {
// 无刷新更新 表格数据
crudRoles.get(this.currentId).then(res => {
for (let i = 0; i < this.crud.data.length; i++) {
if (res.data.id === this.crud.data[i].id) {
this.crud.data[i] = res.data
break
}
}
})
},
// 获取部门数据
getDepts() {
getDepts({enabled: true}).then(res => {
this.depts = res.content
})
},
// 如果数据权限为自定义则获取部门数据
changeScope() {
if (this.form.dataScope === '自定义') {
this.getDepts()
}
},
checkboxT(row, rowIndex) {
return row.level >= this.level
}
}
}
Loading…
Cancel
Save