33 <el-card class =" container-card" shadow =" always" >
44 <el-form size =" mini" :inline =" true" :model =" params" class =" demo-form-inline" >
55 <el-form-item label =" 请求人" >
6- <el-input v-model.trim =" params.username" clearable placeholder =" 请求人" @keyup.enter.native =" search" @clear =" search" />
6+ <el-input
7+ v-model.trim =" params.username"
8+ clearable
9+ placeholder =" 请求人"
10+ @keyup.enter.native =" search"
11+ @clear =" search"
12+ />
713 </el-form-item >
814 <el-form-item label =" IP地址" >
915 <el-input v-model.trim =" params.ip" clearable placeholder =" IP地址" @keyup.enter.native =" search" @clear =" search" />
1016 </el-form-item >
1117 <el-form-item label =" 请求路径" >
12- <el-input v-model.trim =" params.path" clearable placeholder =" 请求路径" @keyup.enter.native =" search" @clear =" search" />
18+ <el-input
19+ v-model.trim =" params.path"
20+ clearable
21+ placeholder =" 请求路径"
22+ @keyup.enter.native =" search"
23+ @clear =" search"
24+ />
1325 </el-form-item >
26+ <!-- <el-form-item label="请求方式">
27+ <el-input v-model.trim="params.method" clearable placeholder="请求方式" @keyup.enter.native="search"
28+ @clear="search" />
29+ </el-form-item> -->
30+ <el-form-item prop =" method" label =" 请求方式" >
31+ <el-select v-model =" params.method" placeholder =" 请选择请求状态" clearable @change =" search" @clear =" search" >
32+ <el-option v-for =" item in RequestList" :key =" item.value" :label =" item.label" :value =" item.value" />
33+ </el-select >
34+ </el-form-item >
35+
1436 <el-form-item label =" 请求状态" >
15- <el-input v-model.trim =" params.status" clearable placeholder =" 请求状态" @keyup.enter.native =" search" @clear =" search" />
37+ <el-input
38+ v-model.trim =" params.status"
39+ clearable
40+ placeholder =" 请求状态"
41+ @keyup.enter.native =" search"
42+ @clear =" search"
43+ />
1644 </el-form-item >
1745 <el-form-item >
1846 <el-button :loading =" loading" icon =" el-icon-search" type =" primary" @click =" search" >查询</el-button >
1947 </el-form-item >
2048 <el-form-item >
21- <el-button :disabled =" multipleSelection.length === 0" :loading =" loading" icon =" el-icon-delete" type =" danger" @click =" batchDelete" >批量删除</el-button >
49+ <el-button
50+ :disabled =" multipleSelection.length === 0"
51+ :loading =" loading"
52+ icon =" el-icon-delete"
53+ type =" danger"
54+ @click =" batchDelete"
55+ >批量删除</el-button >
56+ </el-form-item >
57+ <el-form-item >
58+ <el-button type =" danger" plain icon =" el-icon-delete" size =" mini" @click =" handleClean" >清空日志</el-button >
2259 </el-form-item >
2360 </el-form >
2461
25- <el-table v-loading =" loading" :data =" tableData" border stripe style =" width : 100% " @selection-change =" handleSelectionChange" >
62+ <el-table
63+ v-loading =" loading"
64+ :data =" tableData"
65+ border
66+ stripe
67+ style =" width : 100% "
68+ @selection-change =" handleSelectionChange"
69+ >
2670 <el-table-column type =" selection" width =" 55" align =" center" />
2771 <el-table-column show-overflow-tooltip sortable prop =" username" label =" 请求人" />
2872 <el-table-column show-overflow-tooltip sortable prop =" ip" label =" IP地址" />
2973 <el-table-column show-overflow-tooltip sortable prop =" path" label =" 请求路径" />
74+ <el-table-column show-overflow-tooltip sortable prop =" method" label =" 请求方式" align =" center" >
75+ <template slot-scope="scope">
76+ <el-tag v-if =" scope.row.method === 'GET'" type =" success" >GET</el-tag >
77+ <el-tag v-else-if =" scope.row.method === 'POST'" type =" warning" >POST</el-tag >
78+ <el-tag v-else-if =" scope.row.method === 'PUT'" type =" primary" >PUT</el-tag >
79+ <el-tag v-else-if =" scope.row.method === 'DELETE'" type =" danger" >DELETE</el-tag >
80+ <el-tag v-else type =" info" >{{ scope.row.method }}</el-tag >
81+ </template >
82+ </el-table-column >
3083 <el-table-column show-overflow-tooltip sortable prop =" status" label =" 请求状态" align =" center" >
3184 <template slot-scope="scope">
32- <el-tag size =" small" :type =" scope.row.status | statusTagFilter" disable-transitions >{{ scope.row.status }}</el-tag >
85+ <el-tag size =" small" :type =" scope.row.status | statusTagFilter" disable-transitions >{{ scope.row.status
86+ }}</el-tag >
3387 </template >
3488 </el-table-column >
3589 <el-table-column show-overflow-tooltip sortable prop =" startTime" label =" 发起时间" >
3993 </el-table-column >
4094 <el-table-column show-overflow-tooltip sortable prop =" timeCost" label =" 请求耗时(ms)" align =" center" >
4195 <template slot-scope="scope">
42- <el-tag size =" small" :type =" scope.row.timeCost | timeCostTagFilter" disable-transitions >{{ scope.row.timeCost }}</el-tag >
96+ <el-tag size =" small" :type =" scope.row.timeCost | timeCostTagFilter" disable-transitions >{{ scope.row.timeCost
97+ }}</el-tag >
4398 </template >
4499 </el-table-column >
45100 <el-table-column show-overflow-tooltip sortable prop =" desc" label =" 说明" />
70125</template >
71126
72127<script >
73- import { getOperationLogs , batchDeleteOperationLogByIds } from ' @/api/log/operationLog'
128+ import { getOperationLogs , batchDeleteOperationLogByIds , CleanOperationLog } from ' @/api/log/operationLog'
74129import { parseGoTime } from ' @/utils/index'
75130import { Message } from ' element-ui'
76131
@@ -123,7 +178,20 @@ export default {
123178 // 删除按钮弹出框
124179 popoverVisible: false ,
125180 // 表格多选
126- multipleSelection: []
181+ multipleSelection: [],
182+ RequestList: [{
183+ value: ' GET' ,
184+ label: ' GET'
185+ }, {
186+ value: ' POST' ,
187+ label: ' POST'
188+ }, {
189+ value: ' DELETE' ,
190+ label: ' DELETE'
191+ }, {
192+ value: ' PUT' ,
193+ label: ' PUT'
194+ }]
127195 }
128196 },
129197 created () {
@@ -150,14 +218,36 @@ export default {
150218 },
151219
152220 // 判断结果
153- judgeResult (res ){
154- if (res .code == 0 ){
155- Message ({
156- showClose: true ,
157- message: " 操作成功" ,
158- type: ' success'
159- })
221+ judgeResult (res ) {
222+ if (res .code === 0 ) {
223+ Message ({
224+ showClose: true ,
225+ message: ' 操作成功' ,
226+ type: ' success'
227+ })
228+ }
229+ },
230+ // 清空日志
231+ handleClean () {
232+ this .$confirm (' 此操作将永久删除, 是否继续?' , ' 提示' , {
233+ confirmButtonText: ' 确定' ,
234+ cancelButtonText: ' 取消' ,
235+ type: ' warning'
236+ }).then (async res => {
237+ this .loading = true
238+ try {
239+ await CleanOperationLog ()
240+ } finally {
241+ this .loading = false
160242 }
243+ this .getTableData ()
244+ }).catch (() => {
245+ Message ({
246+ showClose: true ,
247+ type: ' info' ,
248+ message: ' 已取消删除'
249+ })
250+ })
161251 },
162252
163253 // 批量删除
@@ -173,7 +263,7 @@ export default {
173263 operationLogIds .push (x .ID )
174264 })
175265 try {
176- await batchDeleteOperationLogByIds ({ operationLogIds: operationLogIds }).then (res => {
266+ await batchDeleteOperationLogByIds ({ operationLogIds: operationLogIds }).then (res => {
177267 this .judgeResult (res)
178268 })
179269 } finally {
@@ -198,7 +288,7 @@ export default {
198288 async singleDelete (Id ) {
199289 this .loading = true
200290 try {
201- await batchDeleteOperationLogByIds ({ operationLogIds: [Id] }).then (res => {
291+ await batchDeleteOperationLogByIds ({ operationLogIds: [Id] }).then (res => {
202292 this .judgeResult (res)
203293 })
204294 } finally {
@@ -221,12 +311,12 @@ export default {
221311 </script >
222312
223313<style scoped>
224- .container-card {
225- margin : 10px ;
226- margin-bottom : 100px ;
227- }
314+ .container-card {
315+ margin : 10px ;
316+ margin-bottom : 100px ;
317+ }
228318
229- .delete-popover {
230- margin-left : 10px ;
231- }
319+ .delete-popover {
320+ margin-left : 10px ;
321+ }
232322 </style >
0 commit comments