granty1
4 years ago
13 changed files with 556 additions and 20 deletions
-
111server/api/v1/sys_operation_record.go
-
3server/config.yaml
-
1server/go.mod
-
1server/initialize/db_table.go
-
4server/initialize/router.go
-
42server/middleware/operation.go
-
8server/model/request/sys_operation_record.go
-
20server/model/sys_operation_record.go
-
18server/router/sys_operation_record.go
-
79server/service/sys_operation_record.go
-
84web/src/api/sys_operation_record.js
-
203web/src/view/superAdmin/operation/sys_operation_record.vue
-
2web/src/view/systemTools/autoCode/index.vue
@ -0,0 +1,111 @@ |
|||
package v1 |
|||
|
|||
import ( |
|||
"fmt" |
|||
"gin-vue-admin/global/response" |
|||
"gin-vue-admin/model" |
|||
"gin-vue-admin/model/request" |
|||
resp "gin-vue-admin/model/response" |
|||
"gin-vue-admin/service" |
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
// @Tags SysOperationRecord
|
|||
// @Summary 创建SysOperationRecord
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body model.SysOperationRecord true "创建SysOperationRecord"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /sysOperationRecord/createSysOperationRecord [post]
|
|||
func CreateSysOperationRecord(c *gin.Context) { |
|||
var sysOperationRecord model.SysOperationRecord |
|||
_ = c.ShouldBindJSON(&sysOperationRecord) |
|||
err := service.CreateSysOperationRecord(sysOperationRecord) |
|||
if err != nil { |
|||
response.FailWithMessage(fmt.Sprintf("创建失败,%v", err), c) |
|||
} else { |
|||
response.OkWithMessage("创建成功", c) |
|||
} |
|||
} |
|||
|
|||
// @Tags SysOperationRecord
|
|||
// @Summary 删除SysOperationRecord
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body model.SysOperationRecord true "删除SysOperationRecord"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
|||
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
|
|||
func DeleteSysOperationRecord(c *gin.Context) { |
|||
var sysOperationRecord model.SysOperationRecord |
|||
_ = c.ShouldBindJSON(&sysOperationRecord) |
|||
err := service.DeleteSysOperationRecord(sysOperationRecord) |
|||
if err != nil { |
|||
response.FailWithMessage(fmt.Sprintf("删除失败,%v", err), c) |
|||
} else { |
|||
response.OkWithMessage("删除成功", c) |
|||
} |
|||
} |
|||
|
|||
// @Tags SysOperationRecord
|
|||
// @Summary 更新SysOperationRecord
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body model.SysOperationRecord true "更新SysOperationRecord"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
|||
// @Router /sysOperationRecord/updateSysOperationRecord [put]
|
|||
func UpdateSysOperationRecord(c *gin.Context) { |
|||
var sysOperationRecord model.SysOperationRecord |
|||
_ = c.ShouldBindJSON(&sysOperationRecord) |
|||
err := service.UpdateSysOperationRecord(&sysOperationRecord) |
|||
if err != nil { |
|||
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c) |
|||
} else { |
|||
response.OkWithMessage("更新成功", c) |
|||
} |
|||
} |
|||
|
|||
// @Tags SysOperationRecord
|
|||
// @Summary 用id查询SysOperationRecord
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body model.SysOperationRecord true "用id查询SysOperationRecord"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
|||
// @Router /sysOperationRecord/findSysOperationRecord [get]
|
|||
func FindSysOperationRecord(c *gin.Context) { |
|||
var sysOperationRecord model.SysOperationRecord |
|||
_ = c.ShouldBindQuery(&sysOperationRecord) |
|||
err, resysOperationRecord := service.GetSysOperationRecord(sysOperationRecord.ID) |
|||
if err != nil { |
|||
response.FailWithMessage(fmt.Sprintf("查询失败,%v", err), c) |
|||
} else { |
|||
response.OkWithData(gin.H{"resysOperationRecord": resysOperationRecord}, c) |
|||
} |
|||
} |
|||
|
|||
// @Tags SysOperationRecord
|
|||
// @Summary 分页获取SysOperationRecord列表
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body request.SysOperationRecordSearch true "分页获取SysOperationRecord列表"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /sysOperationRecord/getSysOperationRecordList [get]
|
|||
func GetSysOperationRecordList(c *gin.Context) { |
|||
var pageInfo request.SysOperationRecordSearch |
|||
_ = c.ShouldBindQuery(&pageInfo) |
|||
err, list, total := service.GetSysOperationRecordInfoList(pageInfo) |
|||
if err != nil { |
|||
response.FailWithMessage(fmt.Sprintf("获取数据失败,%v", err), c) |
|||
} else { |
|||
response.OkWithData(resp.PageResult{ |
|||
List: list, |
|||
Total: total, |
|||
Page: pageInfo.Page, |
|||
PageSize: pageInfo.PageSize, |
|||
}, c) |
|||
} |
|||
} |
@ -0,0 +1,8 @@ |
|||
package request |
|||
|
|||
import "gin-vue-admin/model" |
|||
|
|||
type SysOperationRecordSearch struct { |
|||
model.SysOperationRecord |
|||
PageInfo |
|||
} |
@ -0,0 +1,20 @@ |
|||
// 自动生成模板SysOperationRecord
|
|||
package model |
|||
|
|||
import ( |
|||
"github.com/jinzhu/gorm" |
|||
"time" |
|||
) |
|||
|
|||
// 如果含有time.Time 请自行import time包
|
|||
type SysOperationRecord struct { |
|||
gorm.Model |
|||
Ip string `json:"ip" form:"ip" gorm:"column:ip;comment:'请求ip'"` |
|||
Method string `json:"method" form:"method" gorm:"column:method;comment:''"` |
|||
Path string `json:"path" form:"path" gorm:"column:path;comment:''"` |
|||
Status int `json:"status" form:"status" gorm:"column:status;comment:''"` |
|||
Latency time.Duration `json:"latency" form:"latency" gorm:"column:latency;comment:''"` |
|||
Agent string `json:"agent" form:"agent" gorm:"column:agent;comment:''"` |
|||
ErrorMessage string `json:"error_message" form:"error_message" gorm:"column:error_message;comment:''"` |
|||
UserId int `json:"user_id" form:"user_id" gorm:"column:user_id;comment:''"` |
|||
} |
@ -0,0 +1,18 @@ |
|||
package router |
|||
|
|||
import ( |
|||
"gin-vue-admin/api/v1" |
|||
"gin-vue-admin/middleware" |
|||
"github.com/gin-gonic/gin" |
|||
) |
|||
|
|||
func InitSysOperationRecordRouter(Router *gin.RouterGroup) { |
|||
SysOperationRecordRouter := Router.Group("sysOperationRecord").Use(middleware.JWTAuth()).Use(middleware.CasbinHandler()) |
|||
{ |
|||
SysOperationRecordRouter.POST("createSysOperationRecord", v1.CreateSysOperationRecord) // 新建SysOperationRecord
|
|||
SysOperationRecordRouter.DELETE("deleteSysOperationRecord", v1.DeleteSysOperationRecord) // 删除SysOperationRecord
|
|||
SysOperationRecordRouter.PUT("updateSysOperationRecord", v1.UpdateSysOperationRecord) // 更新SysOperationRecord
|
|||
SysOperationRecordRouter.GET("findSysOperationRecord", v1.FindSysOperationRecord) // 根据ID获取SysOperationRecord
|
|||
SysOperationRecordRouter.GET("getSysOperationRecordList", v1.GetSysOperationRecordList) // 获取SysOperationRecord列表
|
|||
} |
|||
} |
@ -0,0 +1,79 @@ |
|||
package service |
|||
|
|||
import ( |
|||
"gin-vue-admin/global" |
|||
"gin-vue-admin/model" |
|||
"gin-vue-admin/model/request" |
|||
) |
|||
|
|||
// @title CreateSysOperationRecord
|
|||
// @description create a SysOperationRecord
|
|||
// @param sysOperationRecord model.SysOperationRecord
|
|||
// @auth (2020/04/05 20:22)
|
|||
// @return err error
|
|||
|
|||
func CreateSysOperationRecord(sysOperationRecord model.SysOperationRecord) (err error) { |
|||
err = global.GVA_DB.Create(&sysOperationRecord).Error |
|||
return err |
|||
} |
|||
|
|||
// @title DeleteSysOperationRecord
|
|||
// @description delete a SysOperationRecord
|
|||
// @auth (2020/04/05 20:22)
|
|||
// @param sysOperationRecord model.SysOperationRecord
|
|||
// @return error
|
|||
|
|||
func DeleteSysOperationRecord(sysOperationRecord model.SysOperationRecord) (err error) { |
|||
err = global.GVA_DB.Delete(sysOperationRecord).Error |
|||
return err |
|||
} |
|||
|
|||
// @title UpdateSysOperationRecord
|
|||
// @description update a SysOperationRecord
|
|||
// @param sysOperationRecord *model.SysOperationRecord
|
|||
// @auth (2020/04/05 20:22)
|
|||
// @return error
|
|||
|
|||
func UpdateSysOperationRecord(sysOperationRecord *model.SysOperationRecord) (err error) { |
|||
err = global.GVA_DB.Save(sysOperationRecord).Error |
|||
return err |
|||
} |
|||
|
|||
// @title GetSysOperationRecord
|
|||
// @description get the info of a SysOperationRecord
|
|||
// @auth (2020/04/05 20:22)
|
|||
// @param id uint
|
|||
// @return error
|
|||
// @return SysOperationRecord SysOperationRecord
|
|||
|
|||
func GetSysOperationRecord(id uint) (err error, sysOperationRecord model.SysOperationRecord) { |
|||
err = global.GVA_DB.Where("id = ?", id).First(&sysOperationRecord).Error |
|||
return |
|||
} |
|||
|
|||
// @title GetSysOperationRecordInfoList
|
|||
// @description get SysOperationRecord list by pagination, 分页获取用户列表
|
|||
// @auth (2020/04/05 20:22)
|
|||
// @param info PageInfo
|
|||
// @return error
|
|||
|
|||
func GetSysOperationRecordInfoList(info request.SysOperationRecordSearch) (err error, list interface{}, total int) { |
|||
limit := info.PageSize |
|||
offset := info.PageSize * (info.Page - 1) |
|||
// 创建db
|
|||
db := global.GVA_DB.Model(&model.SysOperationRecord{}) |
|||
var sysOperationRecords []model.SysOperationRecord |
|||
// 如果有条件搜索 下方会自动创建搜索语句
|
|||
if info.Method != "" { |
|||
db = db.Where("method = ?", info.Method) |
|||
} |
|||
if info.Path != "" { |
|||
db = db.Where("path LIKE ?", "%"+info.Path+"%") |
|||
} |
|||
if info.Status != 0 { |
|||
db = db.Where("status = ?", info.Status) |
|||
} |
|||
err = db.Count(&total).Error |
|||
err = db.Limit(limit).Offset(offset).Find(&sysOperationRecords).Error |
|||
return err, sysOperationRecords, total |
|||
} |
@ -0,0 +1,84 @@ |
|||
import service from '@/utils/request' |
|||
|
|||
// @Tags SysOperationRecord
|
|||
// @Summary 创建SysOperationRecord
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body model.SysOperationRecord true "创建SysOperationRecord"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /sysOperationRecord/createSysOperationRecord [post]
|
|||
export const createSysOperationRecord = (data) => { |
|||
return service({ |
|||
url: "/sysOperationRecord/createSysOperationRecord", |
|||
method: 'post', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
|
|||
// @Tags SysOperationRecord
|
|||
// @Summary 删除SysOperationRecord
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body model.SysOperationRecord true "删除SysOperationRecord"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
|
|||
// @Router /sysOperationRecord/deleteSysOperationRecord [delete]
|
|||
export const deleteSysOperationRecord = (data) => { |
|||
return service({ |
|||
url: "/sysOperationRecord/deleteSysOperationRecord", |
|||
method: 'delete', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
// @Tags SysOperationRecord
|
|||
// @Summary 更新SysOperationRecord
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body model.SysOperationRecord true "更新SysOperationRecord"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
|
|||
// @Router /sysOperationRecord/updateSysOperationRecord [put]
|
|||
export const updateSysOperationRecord = (data) => { |
|||
return service({ |
|||
url: "/sysOperationRecord/updateSysOperationRecord", |
|||
method: 'put', |
|||
data |
|||
}) |
|||
} |
|||
|
|||
|
|||
// @Tags SysOperationRecord
|
|||
// @Summary 用id查询SysOperationRecord
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body model.SysOperationRecord true "用id查询SysOperationRecord"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
|
|||
// @Router /sysOperationRecord/findSysOperationRecord [get]
|
|||
export const findSysOperationRecord = (params) => { |
|||
return service({ |
|||
url: "/sysOperationRecord/findSysOperationRecord", |
|||
method: 'get', |
|||
params |
|||
}) |
|||
} |
|||
|
|||
|
|||
// @Tags SysOperationRecord
|
|||
// @Summary 分页获取SysOperationRecord列表
|
|||
// @Security ApiKeyAuth
|
|||
// @accept application/json
|
|||
// @Produce application/json
|
|||
// @Param data body request.PageInfo true "分页获取SysOperationRecord列表"
|
|||
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
|
|||
// @Router /sysOperationRecord/getSysOperationRecordList [get]
|
|||
export const getSysOperationRecordList = (params) => { |
|||
return service({ |
|||
url: "/sysOperationRecord/getSysOperationRecordList", |
|||
method: 'get', |
|||
params |
|||
}) |
|||
} |
@ -0,0 +1,203 @@ |
|||
<template> |
|||
<div> |
|||
<div class="search-term"> |
|||
<el-form :inline="true" :model="searchInfo" class="demo-form-inline"> |
|||
<el-form-item label="请求方法"> |
|||
<el-input placeholder="搜索条件" v-model="searchInfo.method"></el-input> |
|||
</el-form-item> |
|||
<el-form-item label="请求路径"> |
|||
<el-input placeholder="搜索条件" v-model="searchInfo.path"></el-input> |
|||
</el-form-item> |
|||
<el-form-item label="结果状态码"> |
|||
<el-input placeholder="搜索条件" v-model="searchInfo.status"></el-input> |
|||
</el-form-item> |
|||
<el-form-item> |
|||
<el-button @click="onSubmit" type="primary">查询</el-button> |
|||
</el-form-item> |
|||
<el-form-item> |
|||
<el-button @click="openDialog" type="primary">新增操作记录</el-button> |
|||
</el-form-item> |
|||
</el-form> |
|||
</div> |
|||
<el-table |
|||
:data="tableData" |
|||
border |
|||
ref="multipleTable" |
|||
stripe |
|||
style="width: 100%" |
|||
tooltip-effect="dark" |
|||
> |
|||
<el-table-column type="selection" width="55"></el-table-column> |
|||
<el-table-column label="日期" width="180"> |
|||
<template slot-scope="scope">{{scope.row.CreatedAt|formatDate}}</template> |
|||
</el-table-column> |
|||
|
|||
<el-table-column label="请求ip" prop="ip" width="120"></el-table-column> |
|||
|
|||
<el-table-column label="请求方法" prop="method" width="120"></el-table-column> |
|||
|
|||
<el-table-column label="请求路径" prop="path" width="120"></el-table-column> |
|||
|
|||
<el-table-column label="结果状态码" prop="status" width="120"></el-table-column> |
|||
|
|||
<el-table-column label="latency" prop="latency" width="120"></el-table-column> |
|||
|
|||
<el-table-column label="agent" prop="agent" width="120"></el-table-column> |
|||
|
|||
<el-table-column label="error_message" prop="error_message" width="120"></el-table-column> |
|||
|
|||
<el-table-column label="user_id" prop="user_id" width="120"></el-table-column> |
|||
|
|||
<el-table-column label="按钮组"> |
|||
<template slot-scope="scope"> |
|||
<el-button @click="updateSysOperationRecord(scope.row)" size="small" type="primary">变更</el-button> |
|||
<el-popover placement="top" width="160" v-model="scope.row.visible"> |
|||
<p>确定要删除吗?</p> |
|||
<div style="text-align: right; margin: 0"> |
|||
<el-button size="mini" type="text" @click="scope.row.visible = false">取消</el-button> |
|||
<el-button type="primary" size="mini" @click="deleteSysOperationRecord(scope.row)">确定</el-button> |
|||
</div> |
|||
<el-button type="danger" icon="el-icon-delete" size="mini" slot="reference">删除</el-button> |
|||
</el-popover> |
|||
</template> |
|||
</el-table-column> |
|||
</el-table> |
|||
|
|||
<el-pagination |
|||
:current-page="page" |
|||
:page-size="pageSize" |
|||
:page-sizes="[10, 30, 50, 100]" |
|||
:style="{float:'right',padding:'20px'}" |
|||
:total="total" |
|||
@current-change="handleCurrentChange" |
|||
@size-change="handleSizeChange" |
|||
layout="total, sizes, prev, pager, next, jumper" |
|||
></el-pagination> |
|||
|
|||
<el-dialog :before-close="closeDialog" :visible.sync="dialogFormVisible" title="弹窗操作"> |
|||
此处请使用表单生成器生成form填充 表单默认绑定 formData 如手动修改过请自行修改key |
|||
<div class="dialog-footer" slot="footer"> |
|||
<el-button @click="closeDialog">取 消</el-button> |
|||
<el-button @click="enterDialog" type="primary">确 定</el-button> |
|||
</div> |
|||
</el-dialog> |
|||
</div> |
|||
</template> |
|||
|
|||
<script> |
|||
import { |
|||
createSysOperationRecord, |
|||
deleteSysOperationRecord, |
|||
updateSysOperationRecord, |
|||
findSysOperationRecord, |
|||
getSysOperationRecordList |
|||
} from "@/api/sys_operation_record"; // 此处请自行替换地址 |
|||
import { formatTimeToStr } from "@/utils/data"; |
|||
import infoList from "@/components/mixins/infoList"; |
|||
|
|||
export default { |
|||
name: "SysOperationRecord", |
|||
mixins: [infoList], |
|||
data() { |
|||
return { |
|||
listApi: getSysOperationRecordList, |
|||
dialogFormVisible: false, |
|||
visible: false, |
|||
type: "", |
|||
formData: { |
|||
ip:null,method:null,path:null,status:null,latency:null,agent:null,error_message:null,user_id:null, |
|||
} |
|||
}; |
|||
}, |
|||
filters: { |
|||
formatDate: function(time) { |
|||
if (time != null && time != "") { |
|||
var date = new Date(time); |
|||
return formatTimeToStr(date, "yyyy-MM-dd hh:mm:ss"); |
|||
} else { |
|||
return ""; |
|||
} |
|||
}, |
|||
formatBoolean: function(bool) { |
|||
if (bool != null) { |
|||
return bool ? "是" :"否"; |
|||
} else { |
|||
return ""; |
|||
} |
|||
} |
|||
}, |
|||
methods: { |
|||
//条件搜索前端看此方法 |
|||
onSubmit() { |
|||
this.page = 1 |
|||
this.pageSize = 10 |
|||
this.getTableData() |
|||
}, |
|||
async updateSysOperationRecord(row) { |
|||
const res = await findSysOperationRecord({ ID: row.ID }); |
|||
this.type = "update"; |
|||
if (res.code == 0) { |
|||
this.formData = res.data.resysOperationRecord; |
|||
this.dialogFormVisible = true; |
|||
} |
|||
}, |
|||
closeDialog() { |
|||
this.dialogFormVisible = false; |
|||
this.formData = { |
|||
|
|||
ip:null, |
|||
method:null, |
|||
path:null, |
|||
status:null, |
|||
latency:null, |
|||
agent:null, |
|||
error_message:null, |
|||
user_id:null, |
|||
}; |
|||
}, |
|||
async deleteSysOperationRecord(row) { |
|||
this.visible = false; |
|||
const res = await deleteSysOperationRecord({ ID: row.ID }); |
|||
if (res.code == 0) { |
|||
this.$message({ |
|||
type: "success", |
|||
message: "删除成功" |
|||
}); |
|||
this.getTableData(); |
|||
} |
|||
}, |
|||
async enterDialog() { |
|||
let res; |
|||
switch (this.type) { |
|||
case "create": |
|||
res = await createSysOperationRecord(this.formData); |
|||
break; |
|||
case "update": |
|||
res = await updateSysOperationRecord(this.formData); |
|||
break; |
|||
default: |
|||
res = await createSysOperationRecord(this.formData); |
|||
break; |
|||
} |
|||
if (res.code == 0) { |
|||
this.$message({ |
|||
type:"success", |
|||
message:"创建/更改成功" |
|||
}) |
|||
this.closeDialog(); |
|||
this.getTableData(); |
|||
} |
|||
}, |
|||
openDialog() { |
|||
this.type = "create"; |
|||
this.dialogFormVisible = true; |
|||
} |
|||
}, |
|||
created() { |
|||
this.getTableData(); |
|||
} |
|||
}; |
|||
</script> |
|||
|
|||
<style> |
|||
</style> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue