29
29
{{ formatDate(scope.row.time) }}
30
30
</template >
31
31
</el-table-column >
32
- <el-table-column label =" 类型" align =" center" prop =" type" width =" 120" >
33
- <template #default =" scope " >
34
- <dict-tag :type =" DICT_TYPE.IOT_MESSAGE_TYPE" :value =" scope.row.type" />
35
- </template >
36
- </el-table-column >
37
- <el-table-column label =" 名称(标识符)" align =" center" prop =" name" />
32
+ <el-table-column label =" 类型" align =" center" prop =" type" width =" 120" />
33
+ <el-table-column label =" 名称(标识符)" align =" center" prop =" subType" width =" 120" />
38
34
<el-table-column label =" 内容" align =" center" prop =" content" :show-overflow-tooltip =" true" />
39
35
</el-table >
40
36
41
37
<!-- 分页 -->
42
38
<div class =" mt-10px flex justify-end" >
43
- <el-pagination
44
- v-model:current-page =" queryParams.pageNo"
45
- v-model:page-size =" queryParams.pageSize"
39
+ <Pagination
46
40
:total =" total"
47
- :page-sizes =" [10, 20, 50, 100]"
48
- small
49
- background
50
- layout =" total, sizes, prev, pager, next, jumper"
51
- @size-change =" handleQuery"
52
- @current-change =" handleQuery"
41
+ v-model:page =" queryParams.pageNo"
42
+ v-model:limit =" queryParams.pageSize"
43
+ @pagination =" getLogList"
53
44
/>
54
45
</div >
55
46
</ContentWrap >
@@ -61,15 +52,17 @@ import { DICT_TYPE } from '@/utils/dict'
61
52
import { formatDate } from ' @/utils/formatTime'
62
53
63
54
const props = defineProps <{
64
- deviceId : number
55
+ deviceKey : number
65
56
}>()
66
57
67
- // 查询参数
58
+ // TODO:后续看看使用什么查询条件 目前后端是留了时间范围 type subType
59
+ // 查询参数
68
60
const queryParams = reactive ({
69
- type: ' ' ,
70
- keyword: ' ' ,
61
+ deviceKey: props .deviceKey ,
62
+ // type: '',
63
+ // keyword: '',
71
64
pageNo: 1 ,
72
- pageSize: 20
65
+ pageSize: 10
73
66
})
74
67
75
68
// 列表数据
@@ -90,30 +83,31 @@ const typeMap = {
90
83
91
84
/** 查询日志列表 */
92
85
const getLogList = async () => {
93
- // if (!props.deviceId) return
94
- // loading.value = true
95
- // try {
96
- // const res = await DeviceApi.getDeviceLogs(props.deviceId, queryParams)
97
- // total.value = res.total
98
- // logList.value = res.list.map((item: any) => {
99
- // const log = {
100
- // time: item.time,
101
- // type: typeMap[item.type as keyof typeof typeMap] || item.type,
102
- // name: getLogName(item),
103
- // content: item.content
104
- // }
105
- // return log
106
- // })
107
- // } finally {
108
- // loading.value = false
109
- // }
86
+ if (! props .deviceKey ) return
87
+ loading .value = true
88
+ try {
89
+ const res = await DeviceApi .getDeviceLogPage (queryParams )
90
+ total .value = res .total
91
+ logList .value = res .list .map ((item : any ) => {
92
+ const log = {
93
+ time: item .reportTime ,
94
+ type: item .type ,
95
+ subType: item .subType ,
96
+ content: item .content
97
+ }
98
+ return log
99
+ })
100
+ console .log (logList .value )
101
+ } finally {
102
+ loading .value = false
103
+ }
110
104
}
111
105
112
106
/** 获取日志名称 */
113
107
const getLogName = (log : any ) => {
114
108
const { type, identifier } = log
115
109
let name = ' 未知'
116
-
110
+
117
111
if (type === ' property' ) {
118
112
if (identifier === ' set_reply' ) name = ' 设置回复'
119
113
else if (identifier === ' report' ) name = ' 上报'
@@ -123,7 +117,7 @@ const getLogName = (log: any) => {
123
117
} else if (type === ' lifetime' ) {
124
118
name = identifier === ' register' ? ' 注册' : name
125
119
}
126
-
120
+
127
121
return ` ${name }(${identifier }) `
128
122
}
129
123
@@ -146,11 +140,14 @@ watch(autoRefresh, (newValue) => {
146
140
})
147
141
148
142
/** 监听设备ID变化 */
149
- watch (() => props .deviceId , (newValue ) => {
150
- if (newValue ) {
151
- handleQuery ()
143
+ watch (
144
+ () => props .deviceKey ,
145
+ (newValue ) => {
146
+ if (newValue ) {
147
+ handleQuery ()
148
+ }
152
149
}
153
- } )
150
+ )
154
151
155
152
/** 组件卸载时清除定时器 */
156
153
onBeforeUnmount (() => {
@@ -161,7 +158,7 @@ onBeforeUnmount(() => {
161
158
162
159
/** 初始化 */
163
160
onMounted (() => {
164
- if (props .deviceId ) {
161
+ if (props .deviceKey ) {
165
162
getLogList ()
166
163
}
167
164
})
0 commit comments