Skip to content

Commit 2d4e7e7

Browse files
committed
Vue3 重构:REVIEW 错误日志
1 parent 944b70c commit 2d4e7e7

File tree

3 files changed

+62
-71
lines changed

3 files changed

+62
-71
lines changed

src/api/infra/apiErrorLog/index.ts

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,38 +27,20 @@ export interface ApiErrorLogVO {
2727
createTime: Date
2828
}
2929

30-
export interface ApiErrorLogPageReqVO extends PageParam {
31-
userId?: number
32-
userType?: number
33-
applicationName?: string
34-
requestUrl?: string
35-
exceptionTime?: Date[]
36-
processStatus: number
37-
}
38-
39-
export interface ApiErrorLogExportReqVO {
40-
userId?: number
41-
userType?: number
42-
applicationName?: string
43-
requestUrl?: string
44-
exceptionTime?: Date[]
45-
processStatus: number
46-
}
47-
4830
// 查询列表API 访问日志
49-
export const getApiErrorLogPageApi = (params: PageParam) => {
31+
export const getApiErrorLogPage = (params: PageParam) => {
5032
return request.get({ url: '/infra/api-error-log/page', params })
5133
}
5234

5335
// 更新 API 错误日志的处理状态
54-
export const updateApiErrorLogPageApi = (id: number, processStatus: number) => {
36+
export const updateApiErrorLogPage = (id: number, processStatus: number) => {
5537
return request.put({
5638
url: '/infra/api-error-log/update-status?id=' + id + '&processStatus=' + processStatus
5739
})
5840
}
5941

6042
// 导出API 访问日志
61-
export const exportApiErrorLogApi = (params) => {
43+
export const exportApiErrorLog = (params) => {
6244
return request.download({
6345
url: '/infra/api-error-log/export-excel',
6446
params

src/views/infra/apiErrorLog/detail.vue renamed to src/views/infra/apiErrorLog/ApiErrorLogDetail.vue

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@
1010
<el-descriptions-item label="应用名">
1111
{{ detailData.applicationName }}
1212
</el-descriptions-item>
13-
<el-descriptions-item label="用户信息">
14-
{{ detailData.userId }} |
13+
<el-descriptions-item label="用户编号">
14+
{{ detailData.userId }}
1515
<dict-tag :type="DICT_TYPE.USER_TYPE" :value="detailData.userType" />
16-
| {{ detailData.userIp }} | {{ detailData.userAgent }}
16+
</el-descriptions-item>
17+
<el-descriptions-item label="用户 IP">
18+
{{ detailData.userIp }}
19+
</el-descriptions-item>
20+
<el-descriptions-item label="用户 UA">
21+
{{ detailData.userAgent }}
1722
</el-descriptions-item>
1823
<el-descriptions-item label="请求信息">
19-
{{ detailData.requestMethod }} | {{ detailData.requestUrl }}
24+
{{ detailData.requestMethod }} {{ detailData.requestUrl }}
2025
</el-descriptions-item>
2126
<el-descriptions-item label="请求参数">
2227
{{ detailData.requestParams }}
@@ -27,7 +32,7 @@
2732
<el-descriptions-item label="异常名">
2833
{{ detailData.exceptionName }}
2934
</el-descriptions-item>
30-
<el-descriptions-item label="异常名" v-if="detailData.exceptionStackTrace">
35+
<el-descriptions-item label="异常堆栈" v-if="detailData.exceptionStackTrace">
3136
<el-input
3237
type="textarea"
3338
:readonly="true"
@@ -50,7 +55,6 @@
5055
</el-descriptions>
5156
</Dialog>
5257
</template>
53-
5458
<script setup lang="ts">
5559
import { DICT_TYPE } from '@/utils/dict'
5660
import { formatDate } from '@/utils/formatTime'
@@ -61,7 +65,7 @@ const detailLoading = ref(false) // 表单的加载中
6165
const detailData = ref() // 详情数据
6266
6367
/** 打开弹窗 */
64-
const openModal = async (data: ApiErrorLog.ApiErrorLogVO) => {
68+
const open = async (data: ApiErrorLog.ApiErrorLogVO) => {
6569
modelVisible.value = true
6670
// 设置数据
6771
detailLoading.value = true
@@ -71,6 +75,5 @@ const openModal = async (data: ApiErrorLog.ApiErrorLogVO) => {
7175
detailLoading.value = false
7276
}
7377
}
74-
75-
defineExpose({ openModal }) // 提供 openModal 方法,用于打开弹窗
78+
defineExpose({ open }) // 提供 open 方法,用于打开弹窗
7679
</script>

src/views/infra/apiErrorLog/index.vue

Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<content-wrap>
2+
<ContentWrap>
33
<!-- 搜索工作栏 -->
44
<el-form
55
class="-mb-15px"
@@ -25,10 +25,10 @@
2525
class="!w-240px"
2626
>
2727
<el-option
28-
v-for="dict in getDictOptions(DICT_TYPE.USER_TYPE)"
29-
:key="parseInt(dict.value)"
28+
v-for="dict in getIntDictOptions(DICT_TYPE.USER_TYPE)"
29+
:key="dict.value"
3030
:label="dict.label"
31-
:value="parseInt(dict.value)"
31+
:value="dict.value"
3232
/>
3333
</el-select>
3434
</el-form-item>
@@ -53,12 +53,17 @@
5353
/>
5454
</el-form-item>
5555
<el-form-item label="处理状态" prop="processStatus">
56-
<el-select v-model="queryParams.processStatus" placeholder="请选择处理状态" clearable>
56+
<el-select
57+
v-model="queryParams.processStatus"
58+
placeholder="请选择处理状态"
59+
clearable
60+
class="!w-240px"
61+
>
5762
<el-option
58-
v-for="dict in getDictOptions(DICT_TYPE.INFRA_API_ERROR_LOG_PROCESS_STATUS)"
59-
:key="parseInt(dict.value)"
63+
v-for="dict in getIntDictOptions(DICT_TYPE.INFRA_API_ERROR_LOG_PROCESS_STATUS)"
64+
:key="dict.value"
6065
:label="dict.label"
61-
:value="parseInt(dict.value)"
66+
:value="dict.value"
6267
/>
6368
</el-select>
6469
</el-form-item>
@@ -76,9 +81,10 @@
7681
</el-button>
7782
</el-form-item>
7883
</el-form>
79-
</content-wrap>
84+
</ContentWrap>
85+
8086
<!-- 列表 -->
81-
<content-wrap>
87+
<ContentWrap>
8288
<el-table v-loading="loading" :data="list">
8389
<el-table-column label="日志编号" align="center" prop="id" />
8490
<el-table-column label="用户编号" align="center" prop="userId" />
@@ -87,15 +93,17 @@
8793
<dict-tag :type="DICT_TYPE.USER_TYPE" :value="scope.row.userType" />
8894
</template>
8995
</el-table-column>
90-
<el-table-column label="应用名" align="center" prop="applicationName" />
91-
<el-table-column label="请求方法名" align="center" prop="requestMethod" />
92-
<el-table-column label="请求地址" align="center" prop="requestUrl" width="250" />
93-
<el-table-column label="异常发生时间" align="center" prop="exceptionTime" width="180">
94-
<template #default="scope">
95-
<span>{{ scope.row.exceptionTime }}</span>
96-
</template>
97-
</el-table-column>
98-
<el-table-column label="异常名" align="center" prop="exceptionName" width="250" />
96+
<el-table-column label="应用名" align="center" prop="applicationName" width="200" />
97+
<el-table-column label="请求方法" align="center" prop="requestMethod" width="80" />
98+
<el-table-column label="请求地址" align="center" prop="requestUrl" width="180" />
99+
<el-table-column
100+
label="异常发生时间"
101+
align="center"
102+
prop="exceptionTime"
103+
width="180"
104+
:formatter="dateFormatter"
105+
/>
106+
<el-table-column label="异常名" align="center" prop="exceptionName" width="180" />
99107
<el-table-column label="处理状态" align="center" prop="processStatus">
100108
<template #default="scope">
101109
<dict-tag
@@ -104,12 +112,12 @@
104112
/>
105113
</template>
106114
</el-table-column>
107-
<el-table-column label="操作" align="center">
115+
<el-table-column label="操作" align="center" width="200">
108116
<template #default="scope">
109117
<el-button
110118
link
111119
type="primary"
112-
@click="openModal(scope.row)"
120+
@click="openDetail(scope.row)"
113121
v-hasPermi="['infra:api-access-log:query']"
114122
>
115123
详细
@@ -118,48 +126,44 @@
118126
link
119127
type="primary"
120128
v-if="scope.row.processStatus === InfraApiErrorLogProcessStatusEnum.INIT"
121-
@click="
122-
handleProcessClick(InfraApiErrorLogProcessStatusEnum.DONE, '已处理', scope.row.id)
123-
"
129+
@click="handleProcess(scope.row.id, InfraApiErrorLogProcessStatusEnum.DONE)"
124130
v-hasPermi="['infra:api-error-log:update-status']"
125131
>
126132
已处理
127133
</el-button>
128134
<el-button
129135
link
130136
type="primary"
131-
icon="el-icon-check"
132137
v-if="scope.row.processStatus === InfraApiErrorLogProcessStatusEnum.INIT"
133-
@click="
134-
handleProcessClick(InfraApiErrorLogProcessStatusEnum.IGNORE, '已忽略', scope.row.id)
135-
"
138+
@click="handleProcess(scope.row.id, InfraApiErrorLogProcessStatusEnum.IGNORE)"
136139
v-hasPermi="['infra:api-error-log:update-status']"
137140
>
138141
已忽略
139142
</el-button>
140143
</template>
141144
</el-table-column>
142145
</el-table>
143-
144146
<!-- 分页组件 -->
145147
<Pagination
146148
:total="total"
147149
v-model:page="queryParams.pageNo"
148150
v-model:limit="queryParams.pageSize"
149151
@pagination="getList"
150152
/>
151-
</content-wrap>
153+
</ContentWrap>
152154

153155
<!-- 表单弹窗:详情 -->
154-
<api-error-log-detail ref="modalRef" />
156+
<ApiErrorLogDetail ref="detailRef" />
155157
</template>
156158

157159
<script setup lang="ts" name="ApiErrorLog">
158-
import { DICT_TYPE, getDictOptions } from '@/utils/dict'
160+
import { DICT_TYPE, getIntDictOptions } from '@/utils/dict'
161+
import { dateFormatter } from '@/utils/formatTime'
159162
import download from '@/utils/download'
160163
import * as ApiErrorLogApi from '@/api/infra/apiErrorLog'
161-
import ApiErrorLogDetail from './detail.vue'
164+
import ApiErrorLogDetail from './ApiErrorLogDetail.vue'
162165
import { InfraApiErrorLogProcessStatusEnum } from '@/utils/constants'
166+
163167
const message = useMessage() // 消息弹窗
164168
165169
const loading = ref(true) // 列表的加载中
@@ -182,13 +186,14 @@ const exportLoading = ref(false) // 导出的加载中
182186
const getList = async () => {
183187
loading.value = true
184188
try {
185-
const data = await ApiErrorLogApi.getApiErrorLogPageApi(queryParams)
189+
const data = await ApiErrorLogApi.getApiErrorLogPage(queryParams)
186190
list.value = data.list
187191
total.value = data.total
188192
} finally {
189193
loading.value = false
190194
}
191195
}
196+
192197
/** 搜索按钮操作 */
193198
const handleQuery = () => {
194199
queryParams.pageNo = 1
@@ -202,18 +207,19 @@ const resetQuery = () => {
202207
}
203208
204209
/** 详情操作 */
205-
const modalRef = ref()
206-
const openModal = (data: ApiErrorLogApi.ApiErrorLogVO) => {
207-
modalRef.value.openModal(data)
210+
const detailRef = ref()
211+
const openDetail = (data: ApiErrorLogApi.ApiErrorLogVO) => {
212+
detailRef.value.open(data)
208213
}
209214
210215
/** 处理已处理 / 已忽略的操作 **/
211-
const handleProcessClick = async (processStatus: number, type: string, id: number) => {
216+
const handleProcess = async (id: number, processStatus: number) => {
212217
try {
213218
// 操作的二次确认
219+
const type = processStatus === InfraApiErrorLogProcessStatusEnum.DONE ? '已处理' : '已忽略'
214220
await message.confirm('确认标记为' + type + '?')
215221
// 执行操作
216-
await ApiErrorLogApi.updateApiErrorLogPageApi(id, processStatus)
222+
await ApiErrorLogApi.updateApiErrorLogPage(id, processStatus)
217223
await message.success(type)
218224
// 刷新列表
219225
await getList()
@@ -227,8 +233,8 @@ const handleExport = async () => {
227233
await message.exportConfirm()
228234
// 发起导出
229235
exportLoading.value = true
230-
const data = await ApiErrorLogApi.exportApiErrorLogApi(queryParams)
231-
download.excel(data, '操作日志.xls')
236+
const data = await ApiErrorLogApi.exportApiErrorLog(queryParams)
237+
download.excel(data, '异常日志.xls')
232238
} catch {
233239
} finally {
234240
exportLoading.value = false

0 commit comments

Comments
 (0)