mirror of
https://github.com/go-admin-team/go-admin.git
synced 2026-09-21 10:13:01 +00:00
refactor🎨 : 系统登录日志和操作日志代码优化
This commit is contained in:
@@ -1,134 +0,0 @@
|
|||||||
package log
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/gin-gonic/gin/binding"
|
|
||||||
|
|
||||||
"go-admin/app/admin/models"
|
|
||||||
"go-admin/tools"
|
|
||||||
"go-admin/tools/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// @Summary 登录日志列表
|
|
||||||
// @Description 获取JSON
|
|
||||||
// @Tags 登录日志
|
|
||||||
// @Param status query string false "status"
|
|
||||||
// @Param dictCode query string false "dictCode"
|
|
||||||
// @Param dictType query string false "dictType"
|
|
||||||
// @Param pageSize query int false "页条数"
|
|
||||||
// @Param pageIndex query int false "页码"
|
|
||||||
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
|
|
||||||
// @Router /api/v1/loginloglist [get]
|
|
||||||
// @Security Bearer
|
|
||||||
func GetLoginLogList(c *gin.Context) {
|
|
||||||
var data models.LoginLog
|
|
||||||
var err error
|
|
||||||
var pageSize = 10
|
|
||||||
var pageIndex = 1
|
|
||||||
|
|
||||||
size := c.Request.FormValue("pageSize")
|
|
||||||
if size != "" {
|
|
||||||
pageSize, err = tools.StringToInt(size)
|
|
||||||
}
|
|
||||||
|
|
||||||
index := c.Request.FormValue("pageIndex")
|
|
||||||
if index != "" {
|
|
||||||
pageIndex, err = tools.StringToInt(index)
|
|
||||||
}
|
|
||||||
|
|
||||||
data.Username = c.Request.FormValue("username")
|
|
||||||
data.Status = c.Request.FormValue("status")
|
|
||||||
data.Ipaddr = c.Request.FormValue("ipaddr")
|
|
||||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
|
||||||
tools.HasError(err, "", -1)
|
|
||||||
|
|
||||||
var mp = make(map[string]interface{}, 3)
|
|
||||||
mp["list"] = result
|
|
||||||
mp["count"] = count
|
|
||||||
mp["pageIndex"] = pageIndex
|
|
||||||
mp["pageSize"] = pageSize
|
|
||||||
|
|
||||||
var res app.Response
|
|
||||||
res.Data = mp
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Summary 通过编码获取登录日志
|
|
||||||
// @Description 获取JSON
|
|
||||||
// @Tags 登录日志
|
|
||||||
// @Param infoId path int true "infoId"
|
|
||||||
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
|
|
||||||
// @Router /api/v1/loginlog/{infoId} [get]
|
|
||||||
// @Security Bearer
|
|
||||||
func GetLoginLog(c *gin.Context) {
|
|
||||||
var LoginLog models.LoginLog
|
|
||||||
LoginLog.InfoId, _ = tools.StringToInt(c.Param("infoId"))
|
|
||||||
result, err := LoginLog.Get()
|
|
||||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
|
||||||
|
|
||||||
var res app.Response
|
|
||||||
res.Data = result
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Summary 添加登录日志
|
|
||||||
// @Description 获取JSON
|
|
||||||
// @Tags 登录日志
|
|
||||||
// @Accept application/json
|
|
||||||
// @Product application/json
|
|
||||||
// @Param data body models.LoginLog true "data"
|
|
||||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
|
||||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
|
||||||
// @Router /api/v1/loginlog [post]
|
|
||||||
// @Security Bearer
|
|
||||||
func InsertLoginLog(c *gin.Context) {
|
|
||||||
var data models.LoginLog
|
|
||||||
err := c.BindWith(&data, binding.JSON)
|
|
||||||
tools.HasError(err, "", 500)
|
|
||||||
result, err := data.Create()
|
|
||||||
tools.HasError(err, "", -1)
|
|
||||||
var res app.Response
|
|
||||||
res.Data = result
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Summary 修改登录日志
|
|
||||||
// @Description 获取JSON
|
|
||||||
// @Tags 登录日志
|
|
||||||
// @Accept application/json
|
|
||||||
// @Product application/json
|
|
||||||
// @Param data body models.LoginLog true "body"
|
|
||||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
|
||||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
|
||||||
// @Router /api/v1/loginlog [put]
|
|
||||||
// @Security Bearer
|
|
||||||
func UpdateLoginLog(c *gin.Context) {
|
|
||||||
var data models.LoginLog
|
|
||||||
err := c.BindWith(&data, binding.JSON)
|
|
||||||
tools.HasError(err, "", -1)
|
|
||||||
result, err := data.Update(data.InfoId)
|
|
||||||
tools.HasError(err, "", -1)
|
|
||||||
var res app.Response
|
|
||||||
res.Data = result
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Summary 批量删除登录日志
|
|
||||||
// @Description 删除数据
|
|
||||||
// @Tags 登录日志
|
|
||||||
// @Param infoId path string true "以逗号(,)分割的infoId"
|
|
||||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
|
||||||
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
|
|
||||||
// @Router /api/v1/loginlog/{infoId} [delete]
|
|
||||||
func DeleteLoginLog(c *gin.Context) {
|
|
||||||
var data models.LoginLog
|
|
||||||
data.UpdateBy = tools.GetUserIdStr(c)
|
|
||||||
IDS := tools.IdsStrToIdsIntGroup("infoId", c)
|
|
||||||
_, err := data.BatchDelete(IDS)
|
|
||||||
tools.HasError(err, "修改失败", 500)
|
|
||||||
var res app.Response
|
|
||||||
res.Msg = "删除成功"
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
|
||||||
@@ -1,113 +0,0 @@
|
|||||||
package log
|
|
||||||
|
|
||||||
import (
|
|
||||||
"net/http"
|
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
|
||||||
"github.com/gin-gonic/gin/binding"
|
|
||||||
|
|
||||||
"go-admin/app/admin/models"
|
|
||||||
"go-admin/tools"
|
|
||||||
"go-admin/tools/app"
|
|
||||||
)
|
|
||||||
|
|
||||||
// @Summary 登录日志列表
|
|
||||||
// @Description 获取JSON
|
|
||||||
// @Tags 登录日志
|
|
||||||
// @Param status query string false "status"
|
|
||||||
// @Param dictCode query string false "dictCode"
|
|
||||||
// @Param dictType query string false "dictType"
|
|
||||||
// @Param pageSize query int false "页条数"
|
|
||||||
// @Param pageIndex query int false "页码"
|
|
||||||
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
|
|
||||||
// @Router /api/v1/operloglist [get]
|
|
||||||
// @Security Bearer
|
|
||||||
func GetOperLogList(c *gin.Context) {
|
|
||||||
var data models.SysOperLog
|
|
||||||
var err error
|
|
||||||
var pageSize = 10
|
|
||||||
var pageIndex = 1
|
|
||||||
|
|
||||||
size := c.Request.FormValue("pageSize")
|
|
||||||
if size != "" {
|
|
||||||
pageSize, err = tools.StringToInt(size)
|
|
||||||
}
|
|
||||||
|
|
||||||
index := c.Request.FormValue("pageIndex")
|
|
||||||
if index != "" {
|
|
||||||
pageIndex, err = tools.StringToInt(index)
|
|
||||||
}
|
|
||||||
|
|
||||||
data.OperName = c.Request.FormValue("operName")
|
|
||||||
data.Status = c.Request.FormValue("status")
|
|
||||||
data.OperIp = c.Request.FormValue("operIp")
|
|
||||||
result, count, err := data.GetPage(pageSize, pageIndex)
|
|
||||||
tools.HasError(err, "", -1)
|
|
||||||
|
|
||||||
var mp = make(map[string]interface{}, 3)
|
|
||||||
mp["list"] = result
|
|
||||||
mp["count"] = count
|
|
||||||
mp["pageIndex"] = pageIndex
|
|
||||||
mp["pageSize"] = pageSize
|
|
||||||
|
|
||||||
var res app.Response
|
|
||||||
res.Data = mp
|
|
||||||
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Summary 通过编码获取登录日志
|
|
||||||
// @Description 获取JSON
|
|
||||||
// @Tags 登录日志
|
|
||||||
// @Param infoId path int true "infoId"
|
|
||||||
// @Success 200 {object} app.Response "{"code": 200, "data": [...]}"
|
|
||||||
// @Router /api/v1/operlog/{infoId} [get]
|
|
||||||
// @Security Bearer
|
|
||||||
func GetOperLog(c *gin.Context) {
|
|
||||||
var OperLog models.SysOperLog
|
|
||||||
OperLog.OperId, _ = tools.StringToInt(c.Param("operId"))
|
|
||||||
result, err := OperLog.Get()
|
|
||||||
tools.HasError(err, "抱歉未找到相关信息", -1)
|
|
||||||
var res app.Response
|
|
||||||
res.Data = result
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Summary 添加操作日志
|
|
||||||
// @Description 获取JSON
|
|
||||||
// @Tags 操作日志
|
|
||||||
// @Accept application/json
|
|
||||||
// @Product application/json
|
|
||||||
// @Param data body models.SysOperLog true "data"
|
|
||||||
// @Success 200 {string} string "{"code": 200, "message": "添加成功"}"
|
|
||||||
// @Success 200 {string} string "{"code": -1, "message": "添加失败"}"
|
|
||||||
// @Router /api/v1/operlog [post]
|
|
||||||
// @Security Bearer
|
|
||||||
func InsertOperLog(c *gin.Context) {
|
|
||||||
var data models.SysOperLog
|
|
||||||
err := c.BindWith(&data, binding.JSON)
|
|
||||||
tools.HasError(err, "", 500)
|
|
||||||
result, err := data.Create()
|
|
||||||
tools.HasError(err, "", -1)
|
|
||||||
var res app.Response
|
|
||||||
res.Data = result
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
|
||||||
|
|
||||||
// @Summary 批量删除操作日志
|
|
||||||
// @Description 删除数据
|
|
||||||
// @Tags 操作日志
|
|
||||||
// @Param operId path string true "以逗号(,)分割的operId"
|
|
||||||
// @Success 200 {string} string "{"code": 200, "message": "删除成功"}"
|
|
||||||
// @Success 200 {string} string "{"code": -1, "message": "删除失败"}"
|
|
||||||
// @Router /api/v1/operlog/{operId} [delete]
|
|
||||||
func DeleteOperLog(c *gin.Context) {
|
|
||||||
var data models.SysOperLog
|
|
||||||
data.UpdateBy = tools.GetUserIdStr(c)
|
|
||||||
IDS := tools.IdsStrToIdsIntGroup("operId", c)
|
|
||||||
_, err := data.BatchDelete(IDS)
|
|
||||||
tools.HasError(err, "删除失败", 500)
|
|
||||||
var res app.Response
|
|
||||||
res.Msg = "删除成功"
|
|
||||||
c.JSON(http.StatusOK, res.ReturnOK())
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
package sys_login_log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"go-admin/app/admin/models/system"
|
||||||
|
|
||||||
|
"go-admin/app/admin/service"
|
||||||
|
"go-admin/app/admin/service/dto"
|
||||||
|
"go-admin/common/apis"
|
||||||
|
"go-admin/common/log"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
"go-admin/tools"
|
||||||
|
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysLoginLog struct {
|
||||||
|
apis.Api
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysLoginLog) GetSysLoginLogList(c *gin.Context) {
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
d := new(dto.SysLoginLogSearch)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
req := d.Generate()
|
||||||
|
|
||||||
|
//查询列表
|
||||||
|
err = req.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]system.SysLoginLog, 0)
|
||||||
|
var count int64
|
||||||
|
serviceStudent := service.SysLoginlog{}
|
||||||
|
serviceStudent.MsgID = msgID
|
||||||
|
serviceStudent.Orm = db
|
||||||
|
err = serviceStudent.GetSysLoginlogPage(req, &list, &count)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysLoginLog) GetSysLoginLog(c *gin.Context) {
|
||||||
|
control := new(dto.SysLoginLogById)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
//查看详情
|
||||||
|
req := control.Generate()
|
||||||
|
err = req.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object system.SysLoginLog
|
||||||
|
|
||||||
|
serviceSysLoginLog := service.SysLoginlog{}
|
||||||
|
serviceSysLoginLog.MsgID = msgID
|
||||||
|
serviceSysLoginLog.Orm = db
|
||||||
|
err = serviceSysLoginLog.GetSysLoginlog(req, &object)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(c, object, "查看成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysLoginLog) InsertSysLoginLog(c *gin.Context) {
|
||||||
|
control := new(dto.SysLoginLogControl)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
//新增操作
|
||||||
|
req := control.Generate()
|
||||||
|
err = req.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object common.ActiveRecord
|
||||||
|
object, err = req.GenerateM()
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 设置创建人
|
||||||
|
object.SetCreateBy(tools.GetUserIdUint(c))
|
||||||
|
|
||||||
|
serviceSysLoginLog := service.SysLoginlog{}
|
||||||
|
serviceSysLoginLog.Orm = db
|
||||||
|
serviceSysLoginLog.MsgID = msgID
|
||||||
|
err = serviceSysLoginLog.InsertSysLoginlog(object)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "创建失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(c, object.GetId(), "创建成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysLoginLog) UpdateSysLoginLog(c *gin.Context) {
|
||||||
|
control := new(dto.SysLoginLogControl)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
req := control.Generate()
|
||||||
|
//更新操作
|
||||||
|
err = req.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object common.ActiveRecord
|
||||||
|
object, err = req.GenerateM()
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
object.SetUpdateBy(tools.GetUserIdUint(c))
|
||||||
|
|
||||||
|
serviceSysLoginLog := service.SysLoginlog{}
|
||||||
|
serviceSysLoginLog.Orm = db
|
||||||
|
serviceSysLoginLog.MsgID = msgID
|
||||||
|
err = serviceSysLoginLog.UpdateSysLoginlog(object)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(c, object.GetId(), "更新成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysLoginLog) DeleteSysLoginLog(c *gin.Context) {
|
||||||
|
control := new(dto.SysLoginLogById)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
//删除操作
|
||||||
|
req := control.Generate()
|
||||||
|
err = req.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("MsgID[%s] Bind error: %s", msgID, err)
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object common.ActiveRecord
|
||||||
|
object, err = req.GenerateM()
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置编辑人
|
||||||
|
object.SetUpdateBy(tools.GetUserIdUint(c))
|
||||||
|
|
||||||
|
serviceSysLoginLog := service.SysLoginlog{}
|
||||||
|
serviceSysLoginLog.Orm = db
|
||||||
|
serviceSysLoginLog.MsgID = msgID
|
||||||
|
err = serviceSysLoginLog.RemoveSysLoginlog(req, object)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(c, object.GetId(), "删除成功")
|
||||||
|
}
|
||||||
@@ -0,0 +1,192 @@
|
|||||||
|
package sys_opera_log
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
|
"go-admin/app/admin/models/system"
|
||||||
|
"go-admin/app/admin/service"
|
||||||
|
"go-admin/app/admin/service/dto"
|
||||||
|
"go-admin/common/apis"
|
||||||
|
"go-admin/common/log"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
"go-admin/tools"
|
||||||
|
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysOperaLog struct {
|
||||||
|
apis.Api
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysOperaLog) GetSysOperaLogList(c *gin.Context) {
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
d := new(dto.SysOperaLogSearch)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
req := d.Generate()
|
||||||
|
|
||||||
|
//查询列表
|
||||||
|
err = req.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
list := make([]system.SysOperaLog, 0)
|
||||||
|
var count int64
|
||||||
|
serviceStudent := service.SysOperaLog{}
|
||||||
|
serviceStudent.MsgID = msgID
|
||||||
|
serviceStudent.Orm = db
|
||||||
|
err = serviceStudent.GetSysOperaLogPage(req, &list, &count)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.PageOK(c, list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysOperaLog) GetSysOperaLog(c *gin.Context) {
|
||||||
|
control := new(dto.SysOperaLogById)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
//查看详情
|
||||||
|
req := control.Generate()
|
||||||
|
err = req.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object system.SysOperaLog
|
||||||
|
|
||||||
|
serviceSysOperlog := service.SysOperaLog{}
|
||||||
|
serviceSysOperlog.MsgID = msgID
|
||||||
|
serviceSysOperlog.Orm = db
|
||||||
|
err = serviceSysOperlog.GetSysOperaLog(req, &object)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "查询失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(c, object, "查看成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysOperaLog) InsertSysOperaLog(c *gin.Context) {
|
||||||
|
control := new(dto.SysOperaLogControl)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
//新增操作
|
||||||
|
req := control.Generate()
|
||||||
|
err = req.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object common.ActiveRecord
|
||||||
|
object, err = req.GenerateM()
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 设置创建人
|
||||||
|
object.SetCreateBy(tools.GetUserIdUint(c))
|
||||||
|
|
||||||
|
serviceSysOperaLog := service.SysOperaLog{}
|
||||||
|
serviceSysOperaLog.Orm = db
|
||||||
|
serviceSysOperaLog.MsgID = msgID
|
||||||
|
err = serviceSysOperaLog.InsertSysOperaLog(object)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "创建失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
e.OK(c, object.GetId(), "创建成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysOperaLog) UpdateSysOperaLog(c *gin.Context) {
|
||||||
|
control := new(dto.SysOperaLogControl)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
req := control.Generate()
|
||||||
|
//更新操作
|
||||||
|
err = req.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object common.ActiveRecord
|
||||||
|
object, err = req.GenerateM()
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
object.SetUpdateBy(tools.GetUserIdUint(c))
|
||||||
|
|
||||||
|
serviceSysOperaLog := service.SysOperaLog{}
|
||||||
|
serviceSysOperaLog.Orm = db
|
||||||
|
serviceSysOperaLog.MsgID = msgID
|
||||||
|
err = serviceSysOperaLog.UpdateSysOperaLog(object)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(c, object.GetId(), "更新成功")
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysOperaLog) DeleteSysOperaLog(c *gin.Context) {
|
||||||
|
control := new(dto.SysOperaLogById)
|
||||||
|
db, err := tools.GetOrm(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(c)
|
||||||
|
//删除操作
|
||||||
|
req := control.Generate()
|
||||||
|
err = req.Bind(c)
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("MsgID[%s] Bind error: %s", msgID, err)
|
||||||
|
e.Error(c, http.StatusUnprocessableEntity, err, "参数验证失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
var object common.ActiveRecord
|
||||||
|
object, err = req.GenerateM()
|
||||||
|
if err != nil {
|
||||||
|
e.Error(c, http.StatusInternalServerError, err, "模型生成失败")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置编辑人
|
||||||
|
object.SetUpdateBy(tools.GetUserIdUint(c))
|
||||||
|
|
||||||
|
serviceSysOperaLog := service.SysOperaLog{}
|
||||||
|
serviceSysOperaLog.Orm = db
|
||||||
|
serviceSysOperaLog.MsgID = msgID
|
||||||
|
err = serviceSysOperaLog.RemoveSysOperaLog(req, object)
|
||||||
|
if err != nil {
|
||||||
|
log.Error(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
e.OK(c, object.GetId(), "删除成功")
|
||||||
|
}
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
package handler
|
package handler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"go-admin/app/admin/models/system"
|
||||||
|
"go-admin/app/admin/service"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
@@ -98,7 +100,8 @@ func Authenticator(c *gin.Context) (interface{}, error) {
|
|||||||
// Write log to database
|
// Write log to database
|
||||||
func LoginLogToDB(c *gin.Context, status string, msg string, username string) {
|
func LoginLogToDB(c *gin.Context, status string, msg string, username string) {
|
||||||
if config.LoggerConfig.EnabledDB {
|
if config.LoggerConfig.EnabledDB {
|
||||||
var loginlog models.LoginLog
|
var loginlog system.SysLoginLog
|
||||||
|
serviceLoginLog :=service.SysLoginlog{}
|
||||||
ua := user_agent.New(c.Request.UserAgent())
|
ua := user_agent.New(c.Request.UserAgent())
|
||||||
loginlog.Ipaddr = c.ClientIP()
|
loginlog.Ipaddr = c.ClientIP()
|
||||||
loginlog.Username = username
|
loginlog.Username = username
|
||||||
@@ -112,7 +115,7 @@ func LoginLogToDB(c *gin.Context, status string, msg string, username string) {
|
|||||||
loginlog.Os = ua.OS()
|
loginlog.Os = ua.OS()
|
||||||
loginlog.Msg = msg
|
loginlog.Msg = msg
|
||||||
loginlog.Platform = ua.Platform()
|
loginlog.Platform = ua.Platform()
|
||||||
_, _ = loginlog.Create()
|
_ = serviceLoginLog.InsertSysLoginlog(loginlog.Generate())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +129,7 @@ func LoginLogToDB(c *gin.Context, status string, msg string, username string) {
|
|||||||
// @Router /logout [post]
|
// @Router /logout [post]
|
||||||
// @Security Bearer
|
// @Security Bearer
|
||||||
func LogOut(c *gin.Context) {
|
func LogOut(c *gin.Context) {
|
||||||
var loginlog models.LoginLog
|
var loginlog system.SysLoginLog
|
||||||
ua := user_agent.New(c.Request.UserAgent())
|
ua := user_agent.New(c.Request.UserAgent())
|
||||||
loginlog.Ipaddr = c.ClientIP()
|
loginlog.Ipaddr = c.ClientIP()
|
||||||
location := tools.GetLocation(c.ClientIP())
|
location := tools.GetLocation(c.ClientIP())
|
||||||
@@ -140,7 +143,8 @@ func LogOut(c *gin.Context) {
|
|||||||
loginlog.Platform = ua.Platform()
|
loginlog.Platform = ua.Platform()
|
||||||
loginlog.Username = tools.GetUserName(c)
|
loginlog.Username = tools.GetUserName(c)
|
||||||
loginlog.Msg = "退出成功"
|
loginlog.Msg = "退出成功"
|
||||||
loginlog.Create()
|
serviceLoginLog:=service.SysLoginlog{}
|
||||||
|
_ = serviceLoginLog.InsertSysLoginlog(loginlog.Generate())
|
||||||
|
|
||||||
c.JSON(http.StatusOK, gin.H{
|
c.JSON(http.StatusOK, gin.H{
|
||||||
"code": 200,
|
"code": 200,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package middleware
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"go-admin/app/admin/models/system"
|
||||||
|
"go-admin/app/admin/service"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -66,45 +68,46 @@ func SetDBOperLog(c *gin.Context, clientIP string, statusCode int, reqUri string
|
|||||||
menu.Path = reqUri
|
menu.Path = reqUri
|
||||||
menu.Action = reqMethod
|
menu.Action = reqMethod
|
||||||
menuList, _ := menu.Get()
|
menuList, _ := menu.Get()
|
||||||
sysOperLog := models.SysOperLog{}
|
sysOperaLog := system.SysOperaLog{}
|
||||||
sysOperLog.OperIp = clientIP
|
sysOperaLog.OperIp = clientIP
|
||||||
sysOperLog.OperLocation = tools.GetLocation(clientIP)
|
sysOperaLog.OperLocation = tools.GetLocation(clientIP)
|
||||||
sysOperLog.Status = tools.IntToString(statusCode)
|
sysOperaLog.Status = tools.IntToString(statusCode)
|
||||||
sysOperLog.OperName = tools.GetUserName(c)
|
sysOperaLog.OperName = tools.GetUserName(c)
|
||||||
sysOperLog.RequestMethod = c.Request.Method
|
sysOperaLog.RequestMethod = c.Request.Method
|
||||||
sysOperLog.OperUrl = reqUri
|
sysOperaLog.OperUrl = reqUri
|
||||||
if reqUri == "/login" {
|
if reqUri == "/login" {
|
||||||
sysOperLog.BusinessType = "10"
|
sysOperaLog.BusinessType = "10"
|
||||||
sysOperLog.Title = "用户登录"
|
sysOperaLog.Title = "用户登录"
|
||||||
sysOperLog.OperName = "-"
|
sysOperaLog.OperName = "-"
|
||||||
} else if strings.Contains(reqUri, "/api/v1/logout") {
|
} else if strings.Contains(reqUri, "/api/v1/logout") {
|
||||||
sysOperLog.BusinessType = "11"
|
sysOperaLog.BusinessType = "11"
|
||||||
} else if strings.Contains(reqUri, "/api/v1/getCaptcha") {
|
} else if strings.Contains(reqUri, "/api/v1/getCaptcha") {
|
||||||
sysOperLog.BusinessType = "12"
|
sysOperaLog.BusinessType = "12"
|
||||||
sysOperLog.Title = "验证码"
|
sysOperaLog.Title = "验证码"
|
||||||
} else {
|
} else {
|
||||||
if reqMethod == "POST" {
|
if reqMethod == "POST" {
|
||||||
sysOperLog.BusinessType = "1"
|
sysOperaLog.BusinessType = "1"
|
||||||
} else if reqMethod == "PUT" {
|
} else if reqMethod == "PUT" {
|
||||||
sysOperLog.BusinessType = "2"
|
sysOperaLog.BusinessType = "2"
|
||||||
} else if reqMethod == "DELETE" {
|
} else if reqMethod == "DELETE" {
|
||||||
sysOperLog.BusinessType = "3"
|
sysOperaLog.BusinessType = "3"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sysOperLog.Method = reqMethod
|
sysOperaLog.Method = reqMethod
|
||||||
if len(menuList) > 0 {
|
if len(menuList) > 0 {
|
||||||
sysOperLog.Title = menuList[0].Title
|
sysOperaLog.Title = menuList[0].Title
|
||||||
}
|
}
|
||||||
b, _ := c.Get("body")
|
b, _ := c.Get("body")
|
||||||
sysOperLog.OperParam, _ = tools.StructToJsonStr(b)
|
sysOperaLog.OperParam, _ = tools.StructToJsonStr(b)
|
||||||
sysOperLog.CreateBy = tools.GetUserName(c)
|
sysOperaLog.CreateBy = tools.GetUserIdUint(c)
|
||||||
sysOperLog.OperTime = tools.GetCurrentTime()
|
sysOperaLog.OperTime = tools.GetCurrentTime()
|
||||||
sysOperLog.LatencyTime = (latencyTime).String()
|
sysOperaLog.LatencyTime = (latencyTime).String()
|
||||||
sysOperLog.UserAgent = c.Request.UserAgent()
|
sysOperaLog.UserAgent = c.Request.UserAgent()
|
||||||
if c.Err() == nil {
|
if c.Err() == nil {
|
||||||
sysOperLog.Status = "0"
|
sysOperaLog.Status = "0"
|
||||||
} else {
|
} else {
|
||||||
sysOperLog.Status = "1"
|
sysOperaLog.Status = "1"
|
||||||
}
|
}
|
||||||
_, _ = sysOperLog.Create()
|
serviceOperaLog:=service.SysOperaLog{}
|
||||||
|
_ = serviceOperaLog.InsertSysOperaLog(sysOperaLog.Generate())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,105 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
orm "go-admin/common/global"
|
|
||||||
)
|
|
||||||
|
|
||||||
type LoginLog struct {
|
|
||||||
InfoId int `json:"infoId" gorm:"primary_key;auto_increment;"` //主键
|
|
||||||
Username string `json:"username" gorm:"size:128;"` //用户名
|
|
||||||
Status string `json:"status" gorm:"size:4;"` //状态
|
|
||||||
Ipaddr string `json:"ipaddr" gorm:"size:255;"` //ip地址
|
|
||||||
LoginLocation string `json:"loginLocation" gorm:"size:255;"` //归属地
|
|
||||||
Browser string `json:"browser" gorm:"size:255;"` //浏览器
|
|
||||||
Os string `json:"os" gorm:"size:255;"` //系统
|
|
||||||
Platform string `json:"platform" gorm:"size:255;"` // 固件
|
|
||||||
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;"` //登录时间
|
|
||||||
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
|
||||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
|
||||||
DataScope string `json:"dataScope" gorm:"-"` //数据
|
|
||||||
Params string `json:"params" gorm:"-"` //
|
|
||||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
|
||||||
Msg string `json:"msg" gorm:"size:255;"`
|
|
||||||
BaseModel
|
|
||||||
}
|
|
||||||
|
|
||||||
func (LoginLog) TableName() string {
|
|
||||||
return "sys_loginlog"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *LoginLog) Get() (LoginLog, error) {
|
|
||||||
var doc LoginLog
|
|
||||||
|
|
||||||
table := orm.Eloquent.Table(e.TableName())
|
|
||||||
if e.Ipaddr != "" {
|
|
||||||
table = table.Where("ipaddr = ?", e.Ipaddr)
|
|
||||||
}
|
|
||||||
if e.InfoId != 0 {
|
|
||||||
table = table.Where("info_id = ?", e.InfoId)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := table.First(&doc).Error; err != nil {
|
|
||||||
return doc, err
|
|
||||||
}
|
|
||||||
return doc, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *LoginLog) GetPage(pageSize int, pageIndex int) ([]LoginLog, int, error) {
|
|
||||||
var doc []LoginLog
|
|
||||||
|
|
||||||
table := orm.Eloquent.Table(e.TableName())
|
|
||||||
if e.Ipaddr != "" {
|
|
||||||
table = table.Where("ipaddr = ?", e.Ipaddr)
|
|
||||||
}
|
|
||||||
if e.Status != "" {
|
|
||||||
table = table.Where("status = ?", e.Status)
|
|
||||||
}
|
|
||||||
if e.Username != "" {
|
|
||||||
table = table.Where("userName = ?", e.Username)
|
|
||||||
}
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
|
|
||||||
if err := table.Order("info_id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
|
||||||
return doc, int(count), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *LoginLog) Create() (LoginLog, error) {
|
|
||||||
var doc LoginLog
|
|
||||||
e.CreateBy = "0"
|
|
||||||
e.UpdateBy = "0"
|
|
||||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
|
||||||
if result.Error != nil {
|
|
||||||
err := result.Error
|
|
||||||
return doc, err
|
|
||||||
}
|
|
||||||
doc = *e
|
|
||||||
return doc, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *LoginLog) Update(id int) (update LoginLog, err error) {
|
|
||||||
|
|
||||||
if err = orm.Eloquent.Table(e.TableName()).First(&update, id).Error; err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//参数1:是要修改的数据
|
|
||||||
//参数2:是修改的数据
|
|
||||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *LoginLog) BatchDelete(id []int) (Result bool, err error) {
|
|
||||||
if err = orm.Eloquent.Table(e.TableName()).Where("info_id in (?)", id).Delete(&LoginLog{}).Error; err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Result = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -1,116 +0,0 @@
|
|||||||
package models
|
|
||||||
|
|
||||||
import (
|
|
||||||
"time"
|
|
||||||
|
|
||||||
orm "go-admin/common/global"
|
|
||||||
)
|
|
||||||
|
|
||||||
//sys_operlog
|
|
||||||
type SysOperLog struct {
|
|
||||||
OperId int `json:"operId" gorm:"primary_key;AUTO_INCREMENT"` //日志编码
|
|
||||||
Title string `json:"title" gorm:"size:255;"` //操作模块
|
|
||||||
BusinessType string `json:"businessType" gorm:"size:128;"` //操作类型
|
|
||||||
BusinessTypes string `json:"businessTypes" gorm:"size:128;"`
|
|
||||||
Method string `json:"method" gorm:"size:128;"` //函数
|
|
||||||
RequestMethod string `json:"requestMethod" gorm:"size:128;"` //请求方式
|
|
||||||
OperatorType string `json:"operatorType" gorm:"size:128;"` //操作类型
|
|
||||||
OperName string `json:"operName" gorm:"size:128;"` //操作者
|
|
||||||
DeptName string `json:"deptName" gorm:"size:128;"` //部门名称
|
|
||||||
OperUrl string `json:"operUrl" gorm:"size:255;"` //访问地址
|
|
||||||
OperIp string `json:"operIp" gorm:"size:128;"` //客户端ip
|
|
||||||
OperLocation string `json:"operLocation" gorm:"size:128;"` //访问位置
|
|
||||||
OperParam string `json:"operParam" gorm:"size:255;"` //请求参数
|
|
||||||
Status string `json:"status" gorm:"size:4;"` //操作状态
|
|
||||||
OperTime time.Time `json:"operTime" gorm:"type:timestamp;"` //操作时间
|
|
||||||
JsonResult string `json:"jsonResult" gorm:"size:255;"` //返回数据
|
|
||||||
CreateBy string `json:"createBy" gorm:"size:128;"` //创建人
|
|
||||||
UpdateBy string `json:"updateBy" gorm:"size:128;"` //更新者
|
|
||||||
DataScope string `json:"dataScope" gorm:"-"` //数据
|
|
||||||
Params string `json:"params" gorm:"-"` //参数
|
|
||||||
Remark string `json:"remark" gorm:"size:255;"` //备注
|
|
||||||
LatencyTime string `json:"latencyime" gorm:"size:128;"` //耗时
|
|
||||||
UserAgent string `json:"userAgent" gorm:"size:255;"` //ua
|
|
||||||
BaseModel
|
|
||||||
}
|
|
||||||
|
|
||||||
func (SysOperLog) TableName() string {
|
|
||||||
return "sys_operlog"
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *SysOperLog) Get() (SysOperLog, error) {
|
|
||||||
var doc SysOperLog
|
|
||||||
|
|
||||||
table := orm.Eloquent.Table(e.TableName())
|
|
||||||
if e.OperIp != "" {
|
|
||||||
table = table.Where("oper_ip = ?", e.OperIp)
|
|
||||||
}
|
|
||||||
if e.OperId != 0 {
|
|
||||||
table = table.Where("oper_id = ?", e.OperId)
|
|
||||||
}
|
|
||||||
|
|
||||||
if err := table.First(&doc).Error; err != nil {
|
|
||||||
return doc, err
|
|
||||||
}
|
|
||||||
return doc, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *SysOperLog) GetPage(pageSize int, pageIndex int) ([]SysOperLog, int, error) {
|
|
||||||
var doc []SysOperLog
|
|
||||||
|
|
||||||
table := orm.Eloquent.Table(e.TableName())
|
|
||||||
if e.OperIp != "" {
|
|
||||||
table = table.Where("oper_ip = ?", e.OperIp)
|
|
||||||
}
|
|
||||||
if e.Status != "" {
|
|
||||||
table = table.Where("status = ?", e.Status)
|
|
||||||
}
|
|
||||||
if e.OperName != "" {
|
|
||||||
table = table.Where("oper_name = ?", e.OperName)
|
|
||||||
}
|
|
||||||
if e.BusinessType != "" {
|
|
||||||
table = table.Where("business_type = ?", e.BusinessType)
|
|
||||||
}
|
|
||||||
|
|
||||||
var count int64
|
|
||||||
|
|
||||||
if err := table.Order("oper_id desc").Offset((pageIndex - 1) * pageSize).Limit(pageSize).Find(&doc).Offset(-1).Limit(-1).Count(&count).Error; err != nil {
|
|
||||||
return nil, 0, err
|
|
||||||
}
|
|
||||||
//table.Where("`deleted_at` IS NULL").Count(&count)
|
|
||||||
return doc, int(count), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *SysOperLog) Create() (SysOperLog, error) {
|
|
||||||
var doc SysOperLog
|
|
||||||
e.CreateBy = "0"
|
|
||||||
e.UpdateBy = "0"
|
|
||||||
result := orm.Eloquent.Table(e.TableName()).Create(&e)
|
|
||||||
if result.Error != nil {
|
|
||||||
err := result.Error
|
|
||||||
return doc, err
|
|
||||||
}
|
|
||||||
doc = *e
|
|
||||||
return doc, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *SysOperLog) Update(id int) (update SysOperLog, err error) {
|
|
||||||
if err = orm.Eloquent.Table(e.TableName()).First(&update, id).Error; err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
//参数1:是要修改的数据
|
|
||||||
//参数2:是修改的数据
|
|
||||||
if err = orm.Eloquent.Table(e.TableName()).Model(&update).Updates(&e).Error; err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
func (e *SysOperLog) BatchDelete(id []int) (Result bool, err error) {
|
|
||||||
if err = orm.Eloquent.Table(e.TableName()).Where(" oper_id in (?)", id).Delete(&SysOperLog{}).Error; err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
Result = true
|
|
||||||
return
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,38 @@
|
|||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"go-admin/common/models"
|
||||||
|
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysLoginLog struct {
|
||||||
|
gorm.Model
|
||||||
|
models.ControlBy
|
||||||
|
|
||||||
|
Username string `json:"username" gorm:"type:varchar(128);comment:用户名"` //
|
||||||
|
Status string `json:"status" gorm:"type:varchar(4);comment:状态"` //
|
||||||
|
Ipaddr string `json:"ipaddr" gorm:"type:varchar(255);comment:ip地址"` //
|
||||||
|
LoginLocation string `json:"loginLocation" gorm:"type:varchar(255);comment:归属地"` //
|
||||||
|
Browser string `json:"browser" gorm:"type:varchar(255);comment:浏览器"` //
|
||||||
|
Os string `json:"os" gorm:"type:varchar(255);comment:系统"` //
|
||||||
|
Platform string `json:"platform" gorm:"type:varchar(255);comment:固件"` //
|
||||||
|
LoginTime time.Time `json:"loginTime" gorm:"type:timestamp;comment:登录时间"` //
|
||||||
|
Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"` //
|
||||||
|
Msg string `json:"msg" gorm:"type:varchar(255);comment:信息"` //
|
||||||
|
}
|
||||||
|
|
||||||
|
func (SysLoginLog) TableName() string {
|
||||||
|
return "sys_login_log"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysLoginLog) Generate() models.ActiveRecord {
|
||||||
|
o := *e
|
||||||
|
return &o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysLoginLog) GetId() interface{} {
|
||||||
|
return e.ID
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package system
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"go-admin/common/models"
|
||||||
|
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysOperaLog struct {
|
||||||
|
gorm.Model
|
||||||
|
models.ControlBy
|
||||||
|
|
||||||
|
Title string `json:"title" gorm:"type:varchar(255);comment:操作模块"` //
|
||||||
|
BusinessType string `json:"businessType" gorm:"type:varchar(128);comment:操作类型"` //
|
||||||
|
BusinessTypes string `json:"businessTypes" gorm:"type:varchar(128);comment:BusinessTypes"` //
|
||||||
|
Method string `json:"method" gorm:"type:varchar(128);comment:函数"` //
|
||||||
|
RequestMethod string `json:"requestMethod" gorm:"type:varchar(128);comment:请求方式"` //
|
||||||
|
OperatorType string `json:"operatorType" gorm:"type:varchar(128);comment:操作类型"` //
|
||||||
|
OperName string `json:"operName" gorm:"type:varchar(128);comment:操作者"` //
|
||||||
|
DeptName string `json:"deptName" gorm:"type:varchar(128);comment:部门名称"` //
|
||||||
|
OperUrl string `json:"operUrl" gorm:"type:varchar(255);comment:访问地址"` //
|
||||||
|
OperIp string `json:"operIp" gorm:"type:varchar(128);comment:客户端ip"` //
|
||||||
|
OperLocation string `json:"operLocation" gorm:"type:varchar(128);comment:访问位置"` //
|
||||||
|
OperParam string `json:"operParam" gorm:"type:varchar(255);comment:请求参数"` //
|
||||||
|
Status string `json:"status" gorm:"type:varchar(4);comment:操作状态"` //
|
||||||
|
OperTime time.Time `json:"operTime" gorm:"type:timestamp;comment:操作时间"` //
|
||||||
|
JsonResult string `json:"jsonResult" gorm:"type:varchar(255);comment:返回数据"` //
|
||||||
|
Remark string `json:"remark" gorm:"type:varchar(255);comment:备注"` //
|
||||||
|
LatencyTime string `json:"latencyTime" gorm:"type:varchar(128);comment:耗时"` //
|
||||||
|
UserAgent string `json:"userAgent" gorm:"type:varchar(255);comment:ua"` //
|
||||||
|
}
|
||||||
|
|
||||||
|
func (SysOperaLog) TableName() string {
|
||||||
|
return "sys_opera_log"
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysOperaLog) Generate() models.ActiveRecord {
|
||||||
|
o := *e
|
||||||
|
return &o
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e *SysOperaLog) GetId() interface{} {
|
||||||
|
return e.ID
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"go-admin/app/admin/apis/system/sys_login_log"
|
||||||
|
"go-admin/app/admin/middleware"
|
||||||
|
jwt "go-admin/pkg/jwtauth"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
routerCheckRole = append(routerCheckRole, registerSysLoginLogRouter)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 需认证的路由代码
|
||||||
|
func registerSysLoginLogRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||||
|
api := &sys_login_log.SysLoginLog{}
|
||||||
|
r := v1.Group("/sys-login-log").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||||
|
{
|
||||||
|
r.GET("", api.GetSysLoginLogList)
|
||||||
|
r.GET("/:id", api.GetSysLoginLog)
|
||||||
|
r.POST("", api.InsertSysLoginLog)
|
||||||
|
r.PUT("/:id", api.UpdateSysLoginLog)
|
||||||
|
r.DELETE("", api.DeleteSysLoginLog)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
package router
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"go-admin/app/admin/apis/system/sys_opera_log"
|
||||||
|
"go-admin/app/admin/middleware"
|
||||||
|
jwt "go-admin/pkg/jwtauth"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
routerCheckRole = append(routerCheckRole, registerSysOperaLogRouter)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 需认证的路由代码
|
||||||
|
func registerSysOperaLogRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||||
|
api := &sys_opera_log.SysOperaLog{}
|
||||||
|
r := v1.Group("/sys-opera-log").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||||
|
{
|
||||||
|
r.GET("", api.GetSysOperaLogList)
|
||||||
|
r.GET("/:id", api.GetSysOperaLog)
|
||||||
|
r.POST("", api.InsertSysOperaLog)
|
||||||
|
r.PUT("/:id", api.UpdateSysOperaLog)
|
||||||
|
r.DELETE("", api.DeleteSysOperaLog)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,6 @@ package router
|
|||||||
import (
|
import (
|
||||||
"mime"
|
"mime"
|
||||||
|
|
||||||
log2 "go-admin/app/admin/apis/log"
|
|
||||||
"go-admin/app/admin/apis/monitor"
|
"go-admin/app/admin/apis/monitor"
|
||||||
"go-admin/app/admin/apis/public"
|
"go-admin/app/admin/apis/public"
|
||||||
"go-admin/app/admin/apis/system"
|
"go-admin/app/admin/apis/system"
|
||||||
@@ -112,8 +111,6 @@ func sysCheckRoleRouterInit(r *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddle
|
|||||||
registerUserCenterRouter(v1, authMiddleware)
|
registerUserCenterRouter(v1, authMiddleware)
|
||||||
registerPostRouter(v1, authMiddleware)
|
registerPostRouter(v1, authMiddleware)
|
||||||
registerMenuRouter(v1, authMiddleware)
|
registerMenuRouter(v1, authMiddleware)
|
||||||
registerLoginLogRouter(v1, authMiddleware)
|
|
||||||
registerOperLogRouter(v1, authMiddleware)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
func registerBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||||
@@ -127,8 +124,6 @@ func registerBaseRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar
|
|||||||
|
|
||||||
v1auth.POST("/logout", handler.LogOut)
|
v1auth.POST("/logout", handler.LogOut)
|
||||||
v1auth.GET("/menuids", system.GetMenuIDS)
|
v1auth.GET("/menuids", system.GetMenuIDS)
|
||||||
|
|
||||||
v1auth.GET("/operloglist", log2.GetOperLogList)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -142,7 +137,6 @@ func registerPageRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddlewar
|
|||||||
//v1auth.GET("/configList", system.GetConfigList)
|
//v1auth.GET("/configList", system.GetConfigList)
|
||||||
v1auth.GET("/postlist", system.GetPostList)
|
v1auth.GET("/postlist", system.GetPostList)
|
||||||
v1auth.GET("/menulist", system.GetMenuList)
|
v1auth.GET("/menulist", system.GetMenuList)
|
||||||
v1auth.GET("/loginloglist", log2.GetLoginLogList)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -155,24 +149,6 @@ func registerUserCenterRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMid
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func registerOperLogRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
|
||||||
operlog := v1.Group("/operlog").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
|
||||||
{
|
|
||||||
operlog.GET("/:operId", log2.GetOperLog)
|
|
||||||
operlog.DELETE("/:operId", log2.DeleteOperLog)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func registerLoginLogRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
|
||||||
loginlog := v1.Group("/loginlog").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
|
||||||
{
|
|
||||||
loginlog.GET("/:infoId", log2.GetLoginLog)
|
|
||||||
loginlog.POST("", log2.InsertLoginLog)
|
|
||||||
loginlog.PUT("", log2.UpdateLoginLog)
|
|
||||||
loginlog.DELETE("/:infoId", log2.DeleteLoginLog)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func registerPostRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
func registerPostRouter(v1 *gin.RouterGroup, authMiddleware *jwt.GinJWTMiddleware) {
|
||||||
post := v1.Group("/post").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
post := v1.Group("/post").Use(authMiddleware.MiddlewareFunc()).Use(middleware.AuthCheckRole())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"go-admin/app/admin/models/system"
|
||||||
|
"go-admin/common/dto"
|
||||||
|
"go-admin/common/log"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
"go-admin/tools"
|
||||||
|
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysLoginLogSearch struct {
|
||||||
|
dto.Pagination `search:"-"`
|
||||||
|
Username string `form:"username" search:"type:exact;column:username;table:sys_loginlog" comment:"用户名"`
|
||||||
|
|
||||||
|
Status string `form:"status" search:"type:exact;column:status;table:sys_loginlog" comment:"状态"`
|
||||||
|
|
||||||
|
Ipaddr string `form:"ipaddr" search:"type:exact;column:ipaddr;table:sys_loginlog" comment:"ip地址"`
|
||||||
|
|
||||||
|
LoginLocation string `form:"loginLocation" search:"type:exact;column:login_location;table:sys_loginlog" comment:"归属地"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SysLoginLogSearch) GetNeedSearch() interface{} {
|
||||||
|
return *m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SysLoginLogSearch) Bind(ctx *gin.Context) error {
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||||
|
err := ctx.ShouldBind(m)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBind error: %s", msgID, err.Error())
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SysLoginLogSearch) Generate() dto.Index {
|
||||||
|
o := *m
|
||||||
|
return &o
|
||||||
|
}
|
||||||
|
|
||||||
|
type SysLoginLogControl struct {
|
||||||
|
ID uint `uri:"ID" comment:"主键"` // 主键
|
||||||
|
Username string `json:"username" comment:"用户名"`
|
||||||
|
Status string `json:"status" comment:"状态"`
|
||||||
|
Ipaddr string `json:"ipaddr" comment:"ip地址"`
|
||||||
|
LoginLocation string `json:"loginLocation" comment:"归属地"`
|
||||||
|
Browser string `json:"browser" comment:"浏览器"`
|
||||||
|
Os string `json:"os" comment:"系统"`
|
||||||
|
Platform string `json:"platform" comment:"固件"`
|
||||||
|
LoginTime time.Time `json:"loginTime" comment:"登录时间"`
|
||||||
|
Remark string `json:"remark" comment:"备注"`
|
||||||
|
Msg string `json:"msg" comment:"信息"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysLoginLogControl) Bind(ctx *gin.Context) error {
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||||
|
err := ctx.ShouldBindUri(s)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ctx.ShouldBind(s)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysLoginLogControl) Generate() dto.Control {
|
||||||
|
cp := *s
|
||||||
|
return &cp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysLoginLogControl) GenerateM() (common.ActiveRecord, error) {
|
||||||
|
return &system.SysLoginLog{
|
||||||
|
|
||||||
|
Model: gorm.Model{ID: s.ID},
|
||||||
|
Username: s.Username,
|
||||||
|
Status: s.Status,
|
||||||
|
Ipaddr: s.Ipaddr,
|
||||||
|
LoginLocation: s.LoginLocation,
|
||||||
|
Browser: s.Browser,
|
||||||
|
Os: s.Os,
|
||||||
|
Platform: s.Platform,
|
||||||
|
LoginTime: s.LoginTime,
|
||||||
|
Remark: s.Remark,
|
||||||
|
Msg: s.Msg,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysLoginLogControl) GetId() interface{} {
|
||||||
|
return s.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
type SysLoginLogById struct {
|
||||||
|
dto.ObjectById
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysLoginLogById) Generate() dto.Control {
|
||||||
|
cp := *s
|
||||||
|
return &cp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysLoginLogById) GenerateM() (common.ActiveRecord, error) {
|
||||||
|
return &system.SysLoginLog{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,124 @@
|
|||||||
|
package dto
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"go-admin/app/admin/models/system"
|
||||||
|
"go-admin/common/dto"
|
||||||
|
"go-admin/common/log"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
"go-admin/tools"
|
||||||
|
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysOperaLogSearch struct {
|
||||||
|
dto.Pagination `search:"-"`
|
||||||
|
|
||||||
|
Title string `form:"title" search:"type:contains;column:title;table:sys_operlog" comment:"操作模块"`
|
||||||
|
Method string `form:"method" search:"type:contains;column:method;table:sys_operlog" comment:"函数"`
|
||||||
|
RequestMethod string `form:"requestMethod" search:"type:contains;column:request_method;table:sys_operlog" comment:"请求方式"`
|
||||||
|
OperUrl string `form:"operUrl" search:"type:contains;column:oper_url;table:sys_operlog" comment:"访问地址"`
|
||||||
|
OperIp string `form:"operIp" search:"type:exact;column:oper_ip;table:sys_operlog" comment:"客户端ip"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SysOperaLogSearch) GetNeedSearch() interface{} {
|
||||||
|
return *m
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SysOperaLogSearch) Bind(ctx *gin.Context) error {
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||||
|
err := ctx.ShouldBind(m)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBind error: %s", msgID, err.Error())
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *SysOperaLogSearch) Generate() dto.Index {
|
||||||
|
o := *m
|
||||||
|
return &o
|
||||||
|
}
|
||||||
|
|
||||||
|
type SysOperaLogControl struct {
|
||||||
|
ID uint `uri:"ID" comment:"编码"` // 编码
|
||||||
|
Title string `json:"title" comment:"操作模块"`
|
||||||
|
BusinessType string `json:"businessType" comment:"操作类型"`
|
||||||
|
BusinessTypes string `json:"businessTypes" comment:""`
|
||||||
|
Method string `json:"method" comment:"函数"`
|
||||||
|
RequestMethod string `json:"requestMethod" comment:"请求方式"`
|
||||||
|
OperatorType string `json:"operatorType" comment:"操作类型"`
|
||||||
|
OperName string `json:"operName" comment:"操作者"`
|
||||||
|
DeptName string `json:"deptName" comment:"部门名称"`
|
||||||
|
OperUrl string `json:"operUrl" comment:"访问地址"`
|
||||||
|
OperIp string `json:"operIp" comment:"客户端ip"`
|
||||||
|
OperLocation string `json:"operLocation" comment:"访问位置"`
|
||||||
|
OperParam string `json:"operParam" comment:"请求参数"`
|
||||||
|
Status string `json:"status" comment:"操作状态"`
|
||||||
|
OperTime time.Time `json:"operTime" comment:"操作时间"`
|
||||||
|
JsonResult string `json:"jsonResult" comment:"返回数据"`
|
||||||
|
Remark string `json:"remark" comment:"备注"`
|
||||||
|
LatencyTime string `json:"latencyTime" comment:"耗时"`
|
||||||
|
UserAgent string `json:"userAgent" comment:"ua"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysOperaLogControl) Bind(ctx *gin.Context) error {
|
||||||
|
msgID := tools.GenerateMsgIDFromContext(ctx)
|
||||||
|
err := ctx.ShouldBindUri(s)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBindUri error: %s", msgID, err.Error())
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
err = ctx.ShouldBind(s)
|
||||||
|
if err != nil {
|
||||||
|
log.Debugf("MsgID[%s] ShouldBind error: %#v", msgID, err.Error())
|
||||||
|
}
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysOperaLogControl) Generate() dto.Control {
|
||||||
|
cp := *s
|
||||||
|
return &cp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysOperaLogControl) GenerateM() (common.ActiveRecord, error) {
|
||||||
|
return &system.SysOperaLog{
|
||||||
|
Model: gorm.Model{ID: s.ID},
|
||||||
|
Title: s.Title,
|
||||||
|
BusinessType: s.BusinessType,
|
||||||
|
BusinessTypes: s.BusinessTypes,
|
||||||
|
Method: s.Method,
|
||||||
|
RequestMethod: s.RequestMethod,
|
||||||
|
OperatorType: s.OperatorType,
|
||||||
|
OperName: s.OperName,
|
||||||
|
DeptName: s.DeptName,
|
||||||
|
OperUrl: s.OperUrl,
|
||||||
|
OperIp: s.OperIp,
|
||||||
|
OperLocation: s.OperLocation,
|
||||||
|
OperParam: s.OperParam,
|
||||||
|
Status: s.Status,
|
||||||
|
OperTime: s.OperTime,
|
||||||
|
JsonResult: s.JsonResult,
|
||||||
|
Remark: s.Remark,
|
||||||
|
LatencyTime: s.LatencyTime,
|
||||||
|
UserAgent: s.UserAgent,
|
||||||
|
}, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysOperaLogControl) GetId() interface{} {
|
||||||
|
return s.ID
|
||||||
|
}
|
||||||
|
|
||||||
|
type SysOperaLogById struct {
|
||||||
|
dto.ObjectById
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysOperaLogById) Generate() dto.Control {
|
||||||
|
cp := *s
|
||||||
|
return &cp
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *SysOperaLogById) GenerateM() (common.ActiveRecord, error) {
|
||||||
|
return &system.SysOperaLog{}, nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"go-admin/app/admin/models/system"
|
||||||
|
cDto "go-admin/common/dto"
|
||||||
|
"go-admin/common/log"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
"go-admin/common/service"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysLoginlog struct {
|
||||||
|
service.Service
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSysLoginlogPage 获取SysLoginlog列表
|
||||||
|
func (e *SysLoginlog) GetSysLoginlogPage(c cDto.Index, list *[]system.SysLoginLog, count *int64) error {
|
||||||
|
var err error
|
||||||
|
var data system.SysLoginLog
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
err = e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
cDto.MakeCondition(c.GetNeedSearch()),
|
||||||
|
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
||||||
|
).
|
||||||
|
Find(list).Limit(-1).Offset(-1).
|
||||||
|
Count(count).Error
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSysLoginlog 获取SysLoginlog对象
|
||||||
|
func (e *SysLoginlog) GetSysLoginlog(d cDto.Control, model *system.SysLoginLog) error {
|
||||||
|
var err error
|
||||||
|
var data system.SysLoginLog
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
First(model, d.GetId())
|
||||||
|
err = db.Error
|
||||||
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
err = errors.New("查看对象不存在或无权查看")
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.Error != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// InsertSysLoginlog 创建SysLoginlog对象
|
||||||
|
func (e *SysLoginlog) InsertSysLoginlog(model common.ActiveRecord) error {
|
||||||
|
var err error
|
||||||
|
var data system.SysLoginLog
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
err = e.Orm.Model(&data).
|
||||||
|
Create(model).Error
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSysLoginlog 修改SysLoginlog对象
|
||||||
|
func (e *SysLoginlog) UpdateSysLoginlog(c common.ActiveRecord) error {
|
||||||
|
var err error
|
||||||
|
var data system.SysLoginLog
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
Where(c.GetId()).Updates(c)
|
||||||
|
if db.Error != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
return errors.New("无权更新该数据")
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSysLoginlog 删除SysLoginlog
|
||||||
|
func (e *SysLoginlog) RemoveSysLoginlog(d cDto.Control, c common.ActiveRecord) error {
|
||||||
|
var err error
|
||||||
|
var data system.SysLoginLog
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
Where(d.GetId()).Delete(c)
|
||||||
|
if db.Error != nil {
|
||||||
|
err = db.Error
|
||||||
|
log.Errorf("MsgID[%s] Delete error: %s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
err = errors.New("无权删除该数据")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,110 @@
|
|||||||
|
package service
|
||||||
|
|
||||||
|
import (
|
||||||
|
"errors"
|
||||||
|
"go-admin/app/admin/models/system"
|
||||||
|
cDto "go-admin/common/dto"
|
||||||
|
"go-admin/common/log"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
"go-admin/common/service"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SysOperaLog struct {
|
||||||
|
service.Service
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSysOperaLogPage 获取SysOperaLog列表
|
||||||
|
func (e *SysOperaLog) GetSysOperaLogPage(c cDto.Index, list *[]system.SysOperaLog, count *int64) error {
|
||||||
|
var err error
|
||||||
|
var data system.SysOperaLog
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
err = e.Orm.Model(&data).
|
||||||
|
Scopes(
|
||||||
|
cDto.MakeCondition(c.GetNeedSearch()),
|
||||||
|
cDto.Paginate(c.GetPageSize(), c.GetPageIndex()),
|
||||||
|
).
|
||||||
|
Find(list).Limit(-1).Offset(-1).
|
||||||
|
Count(count).Error
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetSysOperaLog 获取SysOperaLog对象
|
||||||
|
func (e *SysOperaLog) GetSysOperaLog(d cDto.Control, model *system.SysOperaLog) error {
|
||||||
|
var err error
|
||||||
|
var data system.SysOperaLog
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
First(model, d.GetId())
|
||||||
|
err = db.Error
|
||||||
|
if err != nil && errors.Is(err, gorm.ErrRecordNotFound) {
|
||||||
|
err = errors.New("查看对象不存在或无权查看")
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.Error != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// InsertSysOperaLog 创建SysOperaLog对象
|
||||||
|
func (e *SysOperaLog) InsertSysOperaLog(model common.ActiveRecord) error {
|
||||||
|
var err error
|
||||||
|
var data system.SysOperaLog
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
err = e.Orm.Model(&data).
|
||||||
|
Create(model).Error
|
||||||
|
if err != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// UpdateSysOperaLog 修改SysOperaLog对象
|
||||||
|
func (e *SysOperaLog) UpdateSysOperaLog(c common.ActiveRecord) error {
|
||||||
|
var err error
|
||||||
|
var data system.SysOperaLog
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
Where(c.GetId()).Updates(c)
|
||||||
|
if db.Error != nil {
|
||||||
|
log.Errorf("msgID[%s] db error:%s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
return errors.New("无权更新该数据")
|
||||||
|
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// RemoveSysOperaLog 删除SysOperaLog
|
||||||
|
func (e *SysOperaLog) RemoveSysOperaLog(d cDto.Control, c common.ActiveRecord) error {
|
||||||
|
var err error
|
||||||
|
var data system.SysOperaLog
|
||||||
|
msgID := e.MsgID
|
||||||
|
|
||||||
|
db := e.Orm.Model(&data).
|
||||||
|
Where(d.GetId()).Delete(c)
|
||||||
|
if db.Error != nil {
|
||||||
|
err = db.Error
|
||||||
|
log.Errorf("MsgID[%s] Delete error: %s", msgID, err)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if db.RowsAffected == 0 {
|
||||||
|
err = errors.New("无权删除该数据")
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -25,8 +25,8 @@ func _1599190683659Tables(db *gorm.DB, version string) error {
|
|||||||
new(tools.SysTables),
|
new(tools.SysTables),
|
||||||
new(tools.SysColumns),
|
new(tools.SysColumns),
|
||||||
new(models.Menu),
|
new(models.Menu),
|
||||||
new(models.LoginLog),
|
new(system.SysLoginLog),
|
||||||
new(models.SysOperLog),
|
new(system.SysOperaLog),
|
||||||
new(models.RoleMenu),
|
new(models.RoleMenu),
|
||||||
new(models.SysRoleDept),
|
new(models.SysRoleDept),
|
||||||
new(models.SysUser),
|
new(models.SysUser),
|
||||||
|
|||||||
@@ -20,11 +20,6 @@ func init() {
|
|||||||
func _1599190683670Test(db *gorm.DB, version string) error {
|
func _1599190683670Test(db *gorm.DB, version string) error {
|
||||||
return db.Transaction(func(tx *gorm.DB) error {
|
return db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
|
||||||
list1 := []models.RoleMenu{
|
|
||||||
}
|
|
||||||
list2 := []models.CasbinRule{
|
|
||||||
}
|
|
||||||
|
|
||||||
list3 := []models.SysDept{
|
list3 := []models.SysDept{
|
||||||
{DeptId: 1, ParentId: 0, DeptPath: "/0/1", DeptName: "爱拓科技", Sort: 0, Leader: "aituo", Phone: "13782218188", Email: "atuo@aituo.com", Status: "0", CreateBy: "1", UpdateBy: "1", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
{DeptId: 1, ParentId: 0, DeptPath: "/0/1", DeptName: "爱拓科技", Sort: 0, Leader: "aituo", Phone: "13782218188", Email: "atuo@aituo.com", Status: "0", CreateBy: "1", UpdateBy: "1", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||||
{DeptId: 7, ParentId: 1, DeptPath: "/0/1/7", DeptName: "研发部", Sort: 1, Leader: "aituo", Phone: "13782218188", Email: "atuo@aituo.com", Status: "0", CreateBy: "1", UpdateBy: "1", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
{DeptId: 7, ParentId: 1, DeptPath: "/0/1/7", DeptName: "研发部", Sort: 1, Leader: "aituo", Phone: "13782218188", Email: "atuo@aituo.com", Status: "0", CreateBy: "1", UpdateBy: "1", BaseModel: models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}},
|
||||||
@@ -109,16 +104,7 @@ func _1599190683670Test(db *gorm.DB, version string) error {
|
|||||||
{2, "函数测试", "DEFAULT", 2, "0/5 * * * * ", "ExamplesOne", "参数", 1, 1, 1, 0, "", "", models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}, ""},
|
{2, "函数测试", "DEFAULT", 2, "0/5 * * * * ", "ExamplesOne", "参数", 1, 1, 1, 0, "", "", models.BaseModel{CreatedAt: time.Now(), UpdatedAt: time.Now()}, ""},
|
||||||
}
|
}
|
||||||
|
|
||||||
err := tx.Create(list1).Error
|
err := tx.Create(list3).Error
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = tx.Create(list2).Error
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
err = tx.Create(list3).Error
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"go-admin/app/admin/models"
|
||||||
|
//"go-admin/app/admin/models"
|
||||||
|
"gorm.io/gorm"
|
||||||
|
"runtime"
|
||||||
|
|
||||||
|
"go-admin/cmd/migrate/migration"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
_, fileName, _, _ := runtime.Caller(0)
|
||||||
|
migration.Migrate.SetVersion(migration.GetFilename(fileName), _1603465014697Test)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _1603465014697Test(db *gorm.DB, version string) error {
|
||||||
|
return db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
err := tx.Debug().Model(&models.Menu{}).Where("path = ?", "/api/v1/syscategoryList").Update("path", "/api/v1/syscategory").Error
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return tx.Create(&common.Migration{
|
||||||
|
Version: version,
|
||||||
|
}).Error
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package version
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gorm.io/gorm"
|
||||||
|
|
||||||
|
"go-admin/app/admin/models/system"
|
||||||
|
"go-admin/cmd/migrate/migration"
|
||||||
|
common "go-admin/common/models"
|
||||||
|
|
||||||
|
"runtime"
|
||||||
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
_, fileName, _, _ := runtime.Caller(0)
|
||||||
|
migration.Migrate.SetVersion(migration.GetFilename(fileName), _1603516925109Test)
|
||||||
|
}
|
||||||
|
|
||||||
|
func _1603516925109Test(db *gorm.DB, version string) error {
|
||||||
|
return db.Transaction(func(tx *gorm.DB) error {
|
||||||
|
_ = tx.Migrator().RenameTable("sys_operlog", "sys_opera_log")
|
||||||
|
_ = tx.Migrator().RenameTable("sys_loginlog", "sys_login_log")
|
||||||
|
|
||||||
|
if tx.Migrator().HasColumn(&system.SysLoginLog{}, "info_id") {
|
||||||
|
err := tx.Migrator().RenameColumn(&system.SysLoginLog{}, "info_id", "id")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if tx.Migrator().HasColumn(&system.SysOperaLog{}, "oper_id") {
|
||||||
|
err := tx.Migrator().RenameColumn(&system.SysOperaLog{}, "oper_id", "id")
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tx.Create(&common.Migration{
|
||||||
|
Version: version,
|
||||||
|
}).Error
|
||||||
|
})
|
||||||
|
}
|
||||||
@@ -1,47 +0,0 @@
|
|||||||
import request from '@/utils/request'
|
|
||||||
|
|
||||||
// 查询SysCategory列表
|
|
||||||
export function listSysCategory(query) {
|
|
||||||
return request({
|
|
||||||
url: '/api/v1/cms',
|
|
||||||
method: 'get',
|
|
||||||
params: query
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 查询SysCategory详细
|
|
||||||
export function getSysCategory (ID) {
|
|
||||||
return request({
|
|
||||||
url: '/api/v1/cms/' + ID,
|
|
||||||
method: 'get'
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// 新增SysCategory
|
|
||||||
export function addSysCategory(data) {
|
|
||||||
return request({
|
|
||||||
url: '/api/v1/cms',
|
|
||||||
method: 'post',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 修改SysCategory
|
|
||||||
export function updateSysCategory(data) {
|
|
||||||
return request({
|
|
||||||
url: '/api/v1/cms/'+data.ID,
|
|
||||||
method: 'put',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
// 删除SysCategory
|
|
||||||
export function delSysCategory(data) {
|
|
||||||
return request({
|
|
||||||
url: '/api/v1/cms',
|
|
||||||
method: 'delete',
|
|
||||||
data: data
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -1,329 +0,0 @@
|
|||||||
|
|
||||||
<template>
|
|
||||||
<BasicLayout>
|
|
||||||
<template #wrapper>
|
|
||||||
<el-card class="box-card">
|
|
||||||
<el-form ref="queryForm" :model="queryParams" :inline="true" label-width="68px">
|
|
||||||
<el-form-item label="名称" prop="name"><el-input v-model="queryParams.name" placeholder="请输入名称" clearable
|
|
||||||
size="small" @keyup.enter.native="handleQuery"/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="状态" prop="status"><el-select v-model="queryParams.status"
|
|
||||||
placeholder="分类管理状态" clearable size="small">
|
|
||||||
<el-option
|
|
||||||
v-for="dict in statusOptions"
|
|
||||||
:key="dict.dictValue"
|
|
||||||
:label="dict.dictLabel"
|
|
||||||
:value="dict.dictValue"
|
|
||||||
/>
|
|
||||||
</el-select>
|
|
||||||
</el-form-item>
|
|
||||||
|
|
||||||
<el-form-item>
|
|
||||||
<el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
|
|
||||||
<el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
|
|
||||||
<el-row :gutter="10" class="mb8">
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
|
||||||
v-permisaction="['admin:cms:add']"
|
|
||||||
type="primary"
|
|
||||||
icon="el-icon-plus"
|
|
||||||
size="mini"
|
|
||||||
@click="handleAdd"
|
|
||||||
>新增
|
|
||||||
</el-button>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
|
||||||
v-permisaction="['admin:cms:edit']"
|
|
||||||
type="success"
|
|
||||||
icon="el-icon-edit"
|
|
||||||
size="mini"
|
|
||||||
:disabled="single"
|
|
||||||
@click="handleUpdate"
|
|
||||||
>修改
|
|
||||||
</el-button>
|
|
||||||
</el-col>
|
|
||||||
<el-col :span="1.5">
|
|
||||||
<el-button
|
|
||||||
v-permisaction="['admin:cms:remove']"
|
|
||||||
type="danger"
|
|
||||||
icon="el-icon-delete"
|
|
||||||
size="mini"
|
|
||||||
:disabled="multiple"
|
|
||||||
@click="handleDelete"
|
|
||||||
>删除
|
|
||||||
</el-button>
|
|
||||||
</el-col>
|
|
||||||
</el-row>
|
|
||||||
|
|
||||||
<el-table v-loading="loading" :data="cmsList" @selection-change="handleSelectionChange">
|
|
||||||
<el-table-column type="selection" width="55" align="center"/><el-table-column label="名称" align="center" prop="name"
|
|
||||||
:show-overflow-tooltip="true"/><el-table-column label="排序" align="center" prop="sort"
|
|
||||||
:show-overflow-tooltip="true"/><el-table-column label="状态" align="center" prop="status"
|
|
||||||
:formatter="statusFormat" width="100">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
{{ statusFormat(scope.row) }}
|
|
||||||
</template>
|
|
||||||
</el-table-column><el-table-column label="创建时间" align="center" prop="createdAt"
|
|
||||||
:show-overflow-tooltip="true"/>
|
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<el-button
|
|
||||||
v-permisaction="['admin:cms:edit']"
|
|
||||||
size="mini"
|
|
||||||
type="text"
|
|
||||||
icon="el-icon-edit"
|
|
||||||
@click="handleUpdate(scope.row)"
|
|
||||||
>修改
|
|
||||||
</el-button>
|
|
||||||
<el-button
|
|
||||||
v-permisaction="['admin:cms:remove']"
|
|
||||||
size="mini"
|
|
||||||
type="text"
|
|
||||||
icon="el-icon-delete"
|
|
||||||
@click="handleDelete(scope.row)"
|
|
||||||
>删除
|
|
||||||
</el-button>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
</el-table>
|
|
||||||
|
|
||||||
<pagination
|
|
||||||
v-show="total>0"
|
|
||||||
:total="total"
|
|
||||||
:page.sync="queryParams.pageIndex"
|
|
||||||
:limit.sync="queryParams.pageSize"
|
|
||||||
@pagination="getList"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- 添加或修改对话框 -->
|
|
||||||
<el-dialog :title="title" :visible.sync="open" width="500px">
|
|
||||||
<el-form ref="form" :model="form" :rules="rules" label-width="80px">
|
|
||||||
|
|
||||||
<el-form-item label="名称" prop="name">
|
|
||||||
<el-input v-model="form.name" placeholder="名称"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="图标" prop="img">
|
|
||||||
<el-input v-model="form.img" placeholder="图标"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="排序" prop="sort">
|
|
||||||
<el-input v-model="form.sort" placeholder="排序"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="状态" prop="status">
|
|
||||||
<el-radio-group v-model="form.status">
|
|
||||||
<el-radio
|
|
||||||
v-for="dict in statusOptions"
|
|
||||||
:key="dict.dictValue"
|
|
||||||
:label="dict.dictValue"
|
|
||||||
>{{ dict.dictLabel }}</el-radio>
|
|
||||||
</el-radio-group>
|
|
||||||
</el-form-item>
|
|
||||||
<el-form-item label="备注" prop="remark">
|
|
||||||
<el-input v-model="form.remark" placeholder="备注"
|
|
||||||
/>
|
|
||||||
</el-form-item>
|
|
||||||
</el-form>
|
|
||||||
<div slot="footer" class="dialog-footer">
|
|
||||||
<el-button type="primary" @click="submitForm">确 定</el-button>
|
|
||||||
<el-button @click="cancel">取 消</el-button>
|
|
||||||
</div>
|
|
||||||
</el-dialog>
|
|
||||||
<FileChoose ref="fileChoose" :dialog-form-visible="fileOpen" @confirm="getImgList" @close="fileClose" />
|
|
||||||
</el-card>
|
|
||||||
</template>
|
|
||||||
</BasicLayout>
|
|
||||||
</template>
|
|
||||||
|
|
||||||
<script>
|
|
||||||
import {addSysCategory, delSysCategory, getSysCategory, listSysCategory, updateSysCategory} from '@/api/syscategory'
|
|
||||||
import FileChoose from '@/components/FileChoose'
|
|
||||||
|
|
||||||
export default {
|
|
||||||
name: 'SysCategory',
|
|
||||||
components: {
|
|
||||||
FileChoose
|
|
||||||
},
|
|
||||||
data() {
|
|
||||||
return {
|
|
||||||
// 遮罩层
|
|
||||||
loading: true,
|
|
||||||
// 选中数组
|
|
||||||
ids: [],
|
|
||||||
// 非单个禁用
|
|
||||||
single: true,
|
|
||||||
// 非多个禁用
|
|
||||||
multiple: true,
|
|
||||||
// 总条数
|
|
||||||
total: 0,
|
|
||||||
// 弹出层标题
|
|
||||||
title: '',
|
|
||||||
// 是否显示弹出层
|
|
||||||
open: false,
|
|
||||||
isEdit: false,
|
|
||||||
fileOpen: false,
|
|
||||||
fileIndex: undefined,
|
|
||||||
// 类型数据字典
|
|
||||||
typeOptions: [],
|
|
||||||
cmsList: [],
|
|
||||||
statusOptions: [],
|
|
||||||
// 关系表类型
|
|
||||||
|
|
||||||
// 查询参数
|
|
||||||
queryParams: {
|
|
||||||
pageIndex: 1,
|
|
||||||
pageSize: 10,
|
|
||||||
name:undefined,
|
|
||||||
status:undefined,
|
|
||||||
|
|
||||||
},
|
|
||||||
// 表单参数
|
|
||||||
form: {
|
|
||||||
},
|
|
||||||
// 表单校验
|
|
||||||
rules: {name:
|
|
||||||
[
|
|
||||||
{required: true, message: '名称不能为空', trigger: 'blur'}
|
|
||||||
],
|
|
||||||
status:
|
|
||||||
[
|
|
||||||
{required: true, message: '状态不能为空', trigger: 'blur'}
|
|
||||||
],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
created() {
|
|
||||||
this.getList()
|
|
||||||
this.getDicts('sys_common_status').then(response => {
|
|
||||||
this.statusOptions = response.data
|
|
||||||
})
|
|
||||||
|
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
/** 查询参数列表 */
|
|
||||||
getList() {
|
|
||||||
this.loading = true
|
|
||||||
listSysCategory(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
|
|
||||||
this.cmsList = response.data.list
|
|
||||||
this.total = response.data.count
|
|
||||||
this.loading = false
|
|
||||||
}
|
|
||||||
)
|
|
||||||
},
|
|
||||||
// 取消按钮
|
|
||||||
cancel() {
|
|
||||||
this.open = false
|
|
||||||
this.reset()
|
|
||||||
},
|
|
||||||
// 表单重置
|
|
||||||
reset() {
|
|
||||||
this.form = {
|
|
||||||
|
|
||||||
ID: undefined,
|
|
||||||
name: undefined,
|
|
||||||
img: undefined,
|
|
||||||
sort: undefined,
|
|
||||||
status: undefined,
|
|
||||||
remark: undefined,
|
|
||||||
}
|
|
||||||
this.resetForm('form')
|
|
||||||
},
|
|
||||||
getImgList: function() {
|
|
||||||
this.form[this.fileIndex] = this.$refs['fileChoose'].resultList[0].fullUrl
|
|
||||||
},
|
|
||||||
fileClose: function() {
|
|
||||||
this.fileOpen = false
|
|
||||||
},
|
|
||||||
statusFormat(row) {
|
|
||||||
return this.selectDictLabel(this.statusOptions, row.status)
|
|
||||||
},
|
|
||||||
// 关系
|
|
||||||
// 文件
|
|
||||||
/** 搜索按钮操作 */
|
|
||||||
handleQuery() {
|
|
||||||
this.queryParams.pageIndex = 1
|
|
||||||
this.getList()
|
|
||||||
},
|
|
||||||
/** 重置按钮操作 */
|
|
||||||
resetQuery() {
|
|
||||||
this.dateRange = []
|
|
||||||
this.resetForm('queryForm')
|
|
||||||
this.handleQuery()
|
|
||||||
},
|
|
||||||
/** 新增按钮操作 */
|
|
||||||
handleAdd() {
|
|
||||||
this.reset()
|
|
||||||
this.open = true
|
|
||||||
this.title = '添加分类管理'
|
|
||||||
this.isEdit = false
|
|
||||||
},
|
|
||||||
// 多选框选中数据
|
|
||||||
handleSelectionChange(selection) {
|
|
||||||
this.ids = selection.map(item => item.ID)
|
|
||||||
this.single = selection.length !== 1
|
|
||||||
this.multiple = !selection.length
|
|
||||||
},
|
|
||||||
/** 修改按钮操作 */
|
|
||||||
handleUpdate(row) {
|
|
||||||
this.reset()
|
|
||||||
const ID =
|
|
||||||
row.ID || this.ids
|
|
||||||
getSysCategory(ID).then(response => {
|
|
||||||
this.form = response.data
|
|
||||||
this.open = true
|
|
||||||
this.title = '修改分类管理'
|
|
||||||
this.isEdit = true
|
|
||||||
})
|
|
||||||
},
|
|
||||||
/** 提交按钮 */
|
|
||||||
submitForm: function () {
|
|
||||||
this.$refs['form'].validate(valid => {
|
|
||||||
if (valid) {
|
|
||||||
if (this.form.ID !== undefined) {
|
|
||||||
updateSysCategory(this.form).then(response => {
|
|
||||||
if (response.code === 200) {
|
|
||||||
this.msgSuccess('修改成功')
|
|
||||||
this.open = false
|
|
||||||
this.getList()
|
|
||||||
} else {
|
|
||||||
this.msgError(response.msg)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
addSysCategory(this.form).then(response => {
|
|
||||||
if (response.code === 200) {
|
|
||||||
this.msgSuccess('新增成功')
|
|
||||||
this.open = false
|
|
||||||
this.getList()
|
|
||||||
} else {
|
|
||||||
this.msgError(response.msg)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
/** 删除按钮操作 */
|
|
||||||
handleDelete(row) {
|
|
||||||
var Ids = (row.ID && [row.ID]) || this.ids
|
|
||||||
|
|
||||||
this.$confirm('是否确认删除编号为"' + Ids + '"的数据项?', '警告', {
|
|
||||||
confirmButtonText: '确定',
|
|
||||||
cancelButtonText: '取消',
|
|
||||||
type: 'warning'
|
|
||||||
}).then(function () {
|
|
||||||
return delSysCategory( { 'ids': Ids })
|
|
||||||
}).then(() => {
|
|
||||||
this.getList()
|
|
||||||
this.msgSuccess('删除成功')
|
|
||||||
}).catch(function () {
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</script>
|
|
||||||
Reference in New Issue
Block a user