index.vue
8.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
<template>
<a-card class="content">
<!-- 查询条件 start-->
<a-row>
<a-col :flex="1" style="margin-top: 4px;">
<a-form :model="searchParams" :label-col-props="{ span: 6 }" :wrapper-col-props="{ span: 18 }"
label-align="left"
auto-label-width>
<a-row :gutter="16">
<a-col :span="8">
<a-form-item field="name" :label="$t('manage.logs.login.loginName')">
<a-input v-model="searchParams.userName" :placeholder="$t('manage.logs.login.loginNamePlaceholder')"
allow-clear/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item field="address" :label="$t('manage.logs.login.loginAddress')">
<a-input v-model="searchParams.ipaddr" :placeholder="$t('manage.logs.login.loginAddressPlaceholder')"
allow-clear/>
</a-form-item>
</a-col>
<a-col :span="8">
<a-form-item field="time" :label="$t('manage.logs.login.loginTime')">
<a-range-picker v-model="searchParams.loginTime"/>
</a-form-item>
</a-col>
</a-row>
</a-form>
</a-col>
<a-divider style="height: 35px" direction="vertical"/>
<a-col :flex="'86px'" style="margin-top: 4px;">
<a-space :size="18">
<a-button type="primary" @click="onQueryClick">
<template #icon>
<icon-search/>
</template>
{{ $t('global.search') }}
</a-button>
<a-button @click="reset">
<template #icon>
<icon-refresh/>
</template>
{{ $t('global.reset') }}
</a-button>
</a-space>
</a-col>
</a-row>
<!-- 查询条件 end-->
<a-divider style="margin-top: 0"/>
<!-- 操作条 start-->
<a-row style="margin-bottom: 16px;">
<a-col :span="24">
<a-space>
<a-button type="primary" @click="handleDeleteClick">
{{ $t('global.batchDeletion') }}
</a-button>
<a-button type="primary" status="danger" @click="handleDeleteAllClick">
{{ $t('global.empty') }}
</a-button>
</a-space>
</a-col>
</a-row>
<!-- 操作条 end-->
<!-- 表格 start-->
<a-table row-key="id" :loading="loading" :bordered="{ wrapper: true, cell: true }" :pagination="pagination"
:columns="(tabColumns as TableColumnData[])" :data="renderData" @page-change="onPageChange"
@page-size-change="onPageSizeChange" v-model:selectedKeys="selectedKeys" :row-selection="rowSelection"
:scroll="scroll">
</a-table>
<!-- 表格 end-->
<a-modal width="400px" v-model:visible="modalVisible" class="modal-box">
<template #title>
<icon-close-circle v-if="modalTitle == '删除'" size="18" style="color:rgb(var(--red-6)); margin-right: 5px;"/>
<icon-exclamation-circle v-else size="18" style="color:rgb(var(--orange-6)); margin-right: 5px;"/>
{{ $t('global.confirmTip') }}
</template>
<div style="text-align: center;">你确定要【{{ modalTitle }}】吗?</div>
<template #footer>
<div style="text-align: center">
<a-space>
<a-button type="primary" status="danger" @click="handleModalCancel">{{ $t('global.cancel') }}</a-button>
<a-button type="primary" @click="handleModalOk">{{ $t('global.confirm') }}</a-button>
</a-space>
</div>
</template>
</a-modal>
</a-card>
</template>
<script lang="ts" setup>
import {computed, onMounted, reactive, ref} from "vue";
import {BasePagination} from "@/api/common";
import {notification} from "@/hooks/my-design";
import {listLogininfor, delLogininfor, cleanLogininfor} from "@/api/system/logininfor";
import {PaginationProps, TableColumnData, TableRowSelection} from "@arco-design/web-vue";
import useLoading from "@/hooks/loading";
import dayjs from "dayjs";
//加载中
const {loading, setLoading} = useLoading(true);
//表格数据
const renderData = ref<any[]>([]);
//表格分页参数
const pagination: any = reactive({...BasePagination()});
//设置表格列
const tabColumns = computed<TableColumnData[]>(() => [
{
title: "登录账号",
dataIndex: "userName",
align: 'center',
width: 180,
},
{
title: "登录地址",
dataIndex: "ipaddr",
align: 'center',
width: 180,
},
{
title: "登录地点",
align: 'center',
width: 200,
ellipsis: true,
tooltip: {position: 'top'},
dataIndex: "loginLocation",
},
{
title: "浏览器",
align: 'center',
width: 200,
dataIndex: "browser",
},
{
title: "操作系统",
align: 'center',
width: 200,
dataIndex: "os",
},
{
title: "操作信息",
ellipsis: true,
align: 'left',
tooltip: {position: 'top'},
dataIndex: "msg",
},
{
title: "登录时间",
dataIndex: "loginTime",
align: 'center',
width: 180,
},
]);
const rowSelection: TableRowSelection = reactive({
type: "checkbox",
showCheckedAll: true,
onlyCurrent: false,
});
//选中的
const selectedKeys = ref();
const scroll = {
// x: 1500,
};
// 获取当前时间
var dateNow = dayjs().format("YYYY-MM-DD");
var dateBefore = dayjs().subtract(1, 'month').format("YYYY-MM-DD")
const modalVisible = ref(false);
const modalTitle = ref("");
const modalType = ref(1);
//生成查询条件
const generateFormModel = () => {
return {
//登录名称
userName: "",
//登陆地址
ipaddr: "",
//登录时间
loginTime: [dateBefore, dateNow],
};
};
//查询项
const searchParams = ref(generateFormModel());
//表格页码发生变化
const onPageChange = async (val: number) => {
pagination.current = val;
await fetchData();
}
//表格每页数量发生变化
const onPageSizeChange = async (val: number) => {
pagination.pageSize = val;
await fetchData();
}
// 查询
const onQueryClick = async () => {
pagination.current = 1;
await fetchData();
}
const reset = async () => {
pagination.current = 1;
searchParams.value = generateFormModel();
await fetchData();
}
//查询数据
const fetchData = async () => {
setLoading(true);
try {
const data: any = {
pageSize: pagination.pageSize,
pageNum: pagination.current,
...searchParams.value,
loginTime: '',
}
if(searchParams.value.loginTime && searchParams.value.loginTime.length>0){
data.params = {
beginTime: dayjs(searchParams.value.loginTime[0]).format("YYYY-MM-DD 00:00:00"),
endTime: dayjs(searchParams.value.loginTime[1]).format("YYYY-MM-DD 23:59:59")
}
}else{
data.params = {
beginTime: undefined,
endTime: undefined
}
}
const res: any = await listLogininfor(data);
renderData.value = res.rows;
pagination.total = res.total;
} catch (err) {
// you can report use errorHandler or other
} finally {
setLoading(false);
}
};
//确认框
/**
* 删除弹框
*/
const handleDeleteClick = () => {
if (!selectedKeys.value || selectedKeys.value.length <= 0) {
notification({code: 201, msg: "请选择要删除的数据"})
return;
}
modalVisible.value = true;
modalTitle.value = "删除所选记录";
modalType.value = 1;
console.log(selectedKeys.value);
};
/**
* 清空按钮
*/
const handleDeleteAllClick = () => {
modalVisible.value = true;
modalType.value = 2;
modalTitle.value = "清空所有数据";
};
/**
* 删除-确定
*/
const handleModalOk = async () => {
let res;
modalVisible.value = false;
setLoading(true);
try {
if (modalType.value == 1) {
if (!selectedKeys.value || selectedKeys.value.length <= 0) {
notification({code: 201, msg: "请选择要删除的数据"})
return;
}
res = await delLogininfor(selectedKeys.value);
} else {
res = await cleanLogininfor();
}
notification(res);
if (res.code == 200) {
await fetchData();
}
} catch (e) {
console.error(e);
} finally {
setLoading(false);
}
};
/**
* 删除弹框-取消
*/
const handleModalCancel = () => {
modalVisible.value = false;
console.log("取消");
}
/**
* 实例创建完成后立即执行
*/
onMounted(async () => {
await fetchData();
})
</script>
<style lang="less" scoped>
.row-mp-30 {
margin-top: 30px;
padding-right: 30px;
}
</style>