|
|
@@ -1,15 +1,29 @@
|
|
1
|
1
|
<template>
|
|
2
|
2
|
<div>
|
|
3
|
3
|
<el-card class="list-query" shadow="hover">
|
|
4
|
|
- <el-form inline label-width="80px">
|
|
|
4
|
+ <el-form inline label-width="150px">
|
|
|
5
|
+ <el-form-item :label="T('LastOnlineTime')">
|
|
|
6
|
+ <el-select v-model="listQuery.time_ago" clearable>
|
|
|
7
|
+ <el-option
|
|
|
8
|
+ v-for="item in timeFilters"
|
|
|
9
|
+ :key="item.value"
|
|
|
10
|
+ :label="item.text"
|
|
|
11
|
+ :value="item.value"
|
|
|
12
|
+ :disabled="item.value === 0"
|
|
|
13
|
+ ></el-option>
|
|
|
14
|
+ </el-select>
|
|
|
15
|
+ </el-form-item>
|
|
5
|
16
|
<el-form-item>
|
|
6
|
17
|
<el-button type="primary" @click="handlerQuery">{{ T('Filter') }}</el-button>
|
|
7
|
18
|
<el-button type="danger" @click="toAdd">{{ T('Add') }}</el-button>
|
|
|
19
|
+ <el-button type="success" @click="toExport">{{ T('Export') }}</el-button>
|
|
|
20
|
+ <el-button type="danger" @click="toBatchDelete">{{ T('BatchDelete') }}</el-button>
|
|
8
|
21
|
</el-form-item>
|
|
9
|
22
|
</el-form>
|
|
10
|
23
|
</el-card>
|
|
11
|
24
|
<el-card class="list-body" shadow="hover">
|
|
12
|
|
- <el-table :data="listRes.list" v-loading="listRes.loading" border size="small">
|
|
|
25
|
+ <el-table :data="listRes.list" v-loading="listRes.loading" border size="small" @selection-change="handleSelectionChange">
|
|
|
26
|
+ <el-table-column type="selection" width="55" align="center"/>
|
|
13
|
27
|
<el-table-column prop="id" label="id" align="center"/>
|
|
14
|
28
|
<el-table-column prop="cpu" label="cpu" align="center"/>
|
|
15
|
29
|
<el-table-column prop="hostname" :label="T('Hostname')" align="center"/>
|
|
|
@@ -17,12 +31,21 @@
|
|
17
|
31
|
<el-table-column prop="os" :label="T('Os')" align="center"/>
|
|
18
|
32
|
<el-table-column prop="username" :label="T('Username')" align="center"/>
|
|
19
|
33
|
<el-table-column prop="uuid" :label="T('Uuid')" align="center"/>
|
|
20
|
|
- <el-table-column prop="version" :label="T('Version')" align="center"/>
|
|
|
34
|
+ <el-table-column prop="version" :label="T('Version')" align="center" width="80"/>
|
|
21
|
35
|
<el-table-column prop="created_at" :label="T('CreatedAt')" align="center"/>
|
|
22
|
36
|
<el-table-column prop="updated_at" :label="T('UpdatedAt')" align="center"/>
|
|
23
|
|
- <el-table-column :label="T('Actions')" align="center" width="400">
|
|
|
37
|
+ <el-table-column prop="last_online_time" :label="T('LastOnlineTime')" align="center">
|
|
|
38
|
+ <template #default="{row}">
|
|
|
39
|
+ <div class="last_oline_time">
|
|
|
40
|
+ <span> {{ row.last_online_time ? timeAgo(row.last_online_time * 1000) : '-' }}</span> <span class="dot" :class="{red: timeDis(row.last_online_time) >= 60, green: timeDis(row.last_online_time)< 60}"></span>
|
|
|
41
|
+ </div>
|
|
|
42
|
+
|
|
|
43
|
+ </template>
|
|
|
44
|
+ </el-table-column>
|
|
|
45
|
+ <el-table-column :label="T('Actions')" align="center" width="500">
|
|
24
|
46
|
<template #default="{row}">
|
|
25
|
47
|
<el-button type="success" @click="toWebClientLink(row)">Web-Client</el-button>
|
|
|
48
|
+ <el-button type="primary" @click="toAddressBook(row)">{{ T('AddToAddressBook') }}</el-button>
|
|
26
|
49
|
<el-button @click="toEdit(row)">{{ T('Edit') }}</el-button>
|
|
27
|
50
|
<el-button type="danger" @click="del(row)">{{ T('Delete') }}</el-button>
|
|
28
|
51
|
</template>
|
|
|
@@ -71,15 +94,73 @@
|
|
71
|
94
|
</el-form-item>
|
|
72
|
95
|
</el-form>
|
|
73
|
96
|
</el-dialog>
|
|
|
97
|
+
|
|
|
98
|
+ <el-dialog v-model="ABFormVisible" width="800" :title="T('Create')">
|
|
|
99
|
+ <el-form class="dialog-form" ref="form" :model="ABFormData" label-width="120px">
|
|
|
100
|
+ <el-form-item :label="T('Owner')" prop="user_ids" required>
|
|
|
101
|
+ <el-select v-model="ABFormData.user_ids" multiple>
|
|
|
102
|
+ <el-option
|
|
|
103
|
+ v-for="item in allUsers"
|
|
|
104
|
+ :key="item.id"
|
|
|
105
|
+ :label="item.username"
|
|
|
106
|
+ :value="item.id"
|
|
|
107
|
+ ></el-option>
|
|
|
108
|
+ </el-select>
|
|
|
109
|
+ </el-form-item>
|
|
|
110
|
+ <el-form-item label="id" prop="id" required>
|
|
|
111
|
+ <el-input v-model="ABFormData.id"></el-input>
|
|
|
112
|
+ </el-form-item>
|
|
|
113
|
+ <el-form-item :label="T('Username')" prop="username">
|
|
|
114
|
+ <el-input v-model="ABFormData.username"></el-input>
|
|
|
115
|
+ </el-form-item>
|
|
|
116
|
+ <el-form-item :label="T('Alias')" prop="alias">
|
|
|
117
|
+ <el-input v-model="ABFormData.alias"></el-input>
|
|
|
118
|
+ </el-form-item>
|
|
|
119
|
+ <el-form-item :label="T('Hostname')" prop="hostname">
|
|
|
120
|
+ <el-input v-model="ABFormData.hostname"></el-input>
|
|
|
121
|
+ </el-form-item>
|
|
|
122
|
+ <el-form-item :label="T('Platform')" prop="platform">
|
|
|
123
|
+ <el-select v-model="ABFormData.platform">
|
|
|
124
|
+ <el-option
|
|
|
125
|
+ v-for="item in ABPlatformList"
|
|
|
126
|
+ :key="item.value"
|
|
|
127
|
+ :label="item.label"
|
|
|
128
|
+ :value="item.value"
|
|
|
129
|
+ ></el-option>
|
|
|
130
|
+ </el-select>
|
|
|
131
|
+ </el-form-item>
|
|
|
132
|
+
|
|
|
133
|
+ <el-form-item :label="T('Tags')" prop="tags">
|
|
|
134
|
+ <el-select v-model="ABFormData.tags" multiple>
|
|
|
135
|
+ <el-option
|
|
|
136
|
+ v-for="item in tagList"
|
|
|
137
|
+ :key="item.name"
|
|
|
138
|
+ :label="item.name"
|
|
|
139
|
+ :value="item.name"
|
|
|
140
|
+ ></el-option>
|
|
|
141
|
+ </el-select>
|
|
|
142
|
+ </el-form-item>
|
|
|
143
|
+ <el-form-item>
|
|
|
144
|
+ <el-button @click="ABFormVisible = false">{{ T('Cancel') }}</el-button>
|
|
|
145
|
+ <el-button @click="ABSubmit" type="primary">{{ T('Submit') }}</el-button>
|
|
|
146
|
+ </el-form-item>
|
|
|
147
|
+ </el-form>
|
|
|
148
|
+ </el-dialog>
|
|
74
|
149
|
</div>
|
|
75
|
150
|
</template>
|
|
76
|
151
|
|
|
77
|
152
|
<script setup>
|
|
78
|
|
- import { onActivated, onMounted, reactive, ref, watch } from 'vue'
|
|
79
|
|
- import { create, list, remove, update } from '@/api/peer'
|
|
|
153
|
+ import { computed, onActivated, onMounted, reactive, ref, watch } from 'vue'
|
|
|
154
|
+ import { batchRemove, create, list, remove, update } from '@/api/peer'
|
|
80
|
155
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
81
|
156
|
import { toWebClientLink } from '@/utils/webclient'
|
|
82
|
157
|
import { T } from '@/utils/i18n'
|
|
|
158
|
+ import { timeAgo } from '@/utils/time'
|
|
|
159
|
+ import { jsonToCsv, downBlob } from '@/utils/file'
|
|
|
160
|
+ import { useRepositories as useABRepositories } from '@/views/address_book/index'
|
|
|
161
|
+ import { loadAllUsers } from '@/global'
|
|
|
162
|
+ import { list as fetchTagList } from '@/api/tag'
|
|
|
163
|
+ import { batchCreate } from '@/api/address_book'
|
|
83
|
164
|
|
|
84
|
165
|
const listRes = reactive({
|
|
85
|
166
|
list: [], total: 0, loading: false,
|
|
|
@@ -87,6 +168,7 @@
|
|
87
|
168
|
const listQuery = reactive({
|
|
88
|
169
|
page: 1,
|
|
89
|
170
|
page_size: 10,
|
|
|
171
|
+ time_ago: null,
|
|
90
|
172
|
})
|
|
91
|
173
|
|
|
92
|
174
|
const getList = async () => {
|
|
|
@@ -129,12 +211,6 @@
|
|
129
|
211
|
|
|
130
|
212
|
watch(() => listQuery.page_size, handlerQuery)
|
|
131
|
213
|
|
|
132
|
|
- const platformList = [
|
|
133
|
|
- { label: 'Windows', value: 'Windows' },
|
|
134
|
|
- { label: 'Linux', value: 'Linux' },
|
|
135
|
|
- { label: 'Mac OS', value: 'Mac OS' },
|
|
136
|
|
- { label: 'Android', value: 'Android' },
|
|
137
|
|
- ]
|
|
138
|
214
|
const formVisible = ref(false)
|
|
139
|
215
|
const formData = reactive({
|
|
140
|
216
|
row_id: 0,
|
|
|
@@ -178,33 +254,137 @@
|
|
178
|
254
|
}
|
|
179
|
255
|
}
|
|
180
|
256
|
|
|
|
257
|
+ const timeDis = (time) => {
|
|
|
258
|
+ let now = new Date().getTime()
|
|
|
259
|
+ let after = new Date(time * 1000).getTime()
|
|
|
260
|
+ return (now - after) / 1000
|
|
|
261
|
+ }
|
|
|
262
|
+
|
|
|
263
|
+ const timeFilters = computed(() => [
|
|
|
264
|
+ { text: T('MinutesLess', { param: 1 }, 1), value: -60 },
|
|
|
265
|
+ { text: T('HoursLess', { param: 1 }, 1), value: -3600 },
|
|
|
266
|
+ { text: T('DaysLess', { param: 1 }, 1), value: -86400 },
|
|
|
267
|
+ { text: '---------', value: 0 },
|
|
|
268
|
+ { text: T('MinutesAgo', { param: 1 }, 1), value: 60 },
|
|
|
269
|
+ { text: T('HoursAgo', { param: 1 }, 1), value: 3600 },
|
|
|
270
|
+ { text: T('DaysAgo', { param: 1 }, 1), value: 86400 },
|
|
|
271
|
+ { text: T('MonthsAgo', { param: 1 }, 1), value: 2592000 },
|
|
|
272
|
+ // { text: T('YearsAgo', { param: 1 }, 1), value: 31536000 },
|
|
|
273
|
+ ])
|
|
|
274
|
+
|
|
|
275
|
+ const toExport = async () => {
|
|
|
276
|
+ const q = { ...listQuery }
|
|
|
277
|
+ q.page_size = 10000
|
|
|
278
|
+ q.page = 1
|
|
|
279
|
+ const res = await list(q).catch(_ => false)
|
|
|
280
|
+ if (res) {
|
|
|
281
|
+ const data = res.data.list.map(item => {
|
|
|
282
|
+ item.last_online_time = item.last_online_time ? new Date(item.last_online_time * 1000).toLocaleString() : '-'
|
|
|
283
|
+ return item
|
|
|
284
|
+ })
|
|
|
285
|
+ const csv = jsonToCsv(data)
|
|
|
286
|
+ downBlob(csv, 'peers.csv')
|
|
|
287
|
+ }
|
|
|
288
|
+ }
|
|
|
289
|
+
|
|
|
290
|
+ const {
|
|
|
291
|
+ platformList: ABPlatformList,
|
|
|
292
|
+ formVisible: ABFormVisible,
|
|
|
293
|
+ formData: ABFormData,
|
|
|
294
|
+ } = useABRepositories()
|
|
|
295
|
+ const toAddressBook = (peer) => {
|
|
|
296
|
+ ABFormData.id = peer.id
|
|
|
297
|
+ ABFormData.username = peer.username
|
|
|
298
|
+ ABFormData.hostname = peer.hostname
|
|
|
299
|
+ //匹配os
|
|
|
300
|
+ if (peer.os.indexOf('windows') !== -1) {
|
|
|
301
|
+ ABFormData.platform = ABPlatformList.find(item => item.label === 'Windows').value
|
|
|
302
|
+ } else if (peer.os.indexOf('linux') !== -1) {
|
|
|
303
|
+ ABFormData.platform = ABPlatformList.find(item => item.label === 'Linux').value
|
|
|
304
|
+ } else if (peer.os.indexOf('android') !== -1) {
|
|
|
305
|
+ ABFormData.platform = ABPlatformList.find(item => item.label === 'Android').value
|
|
|
306
|
+ } else if (peer.os.indexOf('mac') !== -1) {
|
|
|
307
|
+ ABFormData.platform = ABPlatformList.find(item => item.label === 'Mac OS').value
|
|
|
308
|
+ }
|
|
|
309
|
+ ABFormData.uuid = peer.uuid
|
|
|
310
|
+ ABFormVisible.value = true
|
|
|
311
|
+
|
|
|
312
|
+ }
|
|
|
313
|
+ const ABSubmit = async () => {
|
|
|
314
|
+ const res = await batchCreate(ABFormData).catch(_ => false)
|
|
|
315
|
+ if (res) {
|
|
|
316
|
+ ElMessage.success(T('OperationSuccess'))
|
|
|
317
|
+ ABFormVisible.value = false
|
|
|
318
|
+ }
|
|
|
319
|
+ }
|
|
|
320
|
+
|
|
|
321
|
+ const { allUsers, getAllUsers } = loadAllUsers()
|
|
|
322
|
+ const tagList = ref([])
|
|
|
323
|
+ const fetchTagListData = async (user_id) => {
|
|
|
324
|
+ const res = await fetchTagList({ user_id }).catch(_ => false)
|
|
|
325
|
+ if (res) {
|
|
|
326
|
+ const ls = []
|
|
|
327
|
+ res.data.list.map(item => {
|
|
|
328
|
+ if (!ls.includes(item.name)) {
|
|
|
329
|
+ ls.push(item.name)
|
|
|
330
|
+ }
|
|
|
331
|
+ })
|
|
|
332
|
+ tagList.value = ls.map(item => ({ name: item }))
|
|
|
333
|
+ }
|
|
|
334
|
+ }
|
|
|
335
|
+ onMounted(getAllUsers)
|
|
|
336
|
+ onMounted(fetchTagListData)
|
|
|
337
|
+
|
|
|
338
|
+ const multipleSelection = ref([])
|
|
|
339
|
+ const handleSelectionChange = (val) => {
|
|
|
340
|
+ multipleSelection.value = val
|
|
|
341
|
+ }
|
|
|
342
|
+ const toBatchDelete = async () => {
|
|
|
343
|
+ if (!multipleSelection.value.length) {
|
|
|
344
|
+ ElMessage.warning(T('PleaseSelectData'))
|
|
|
345
|
+ return false
|
|
|
346
|
+ }
|
|
|
347
|
+ const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('BatchDelete') }), {
|
|
|
348
|
+ confirmButtonText: T('Confirm'),
|
|
|
349
|
+ cancelButtonText: T('Cancel'),
|
|
|
350
|
+ type: 'warning',
|
|
|
351
|
+ }).catch(_ => false)
|
|
|
352
|
+ if (!cf) {
|
|
|
353
|
+ return false
|
|
|
354
|
+ }
|
|
|
355
|
+
|
|
|
356
|
+ const res = await batchRemove({ row_ids: multipleSelection.value.map(i => i.row_id) }).catch(_ => false)
|
|
|
357
|
+ if (res) {
|
|
|
358
|
+ ElMessage.success(T('OperationSuccess'))
|
|
|
359
|
+ getList()
|
|
|
360
|
+ }
|
|
|
361
|
+ }
|
|
181
|
362
|
</script>
|
|
182
|
363
|
|
|
183
|
364
|
<style scoped lang="scss">
|
|
184
|
365
|
.list-query .el-select {
|
|
185
|
|
- --el-select-width: 160px;
|
|
|
366
|
+ --el-select-width: 180px;
|
|
186
|
367
|
}
|
|
187
|
368
|
|
|
188
|
|
-.colors {
|
|
|
369
|
+.last_oline_time {
|
|
189
|
370
|
display: flex;
|
|
190
|
371
|
justify-content: center;
|
|
191
|
372
|
align-items: center;
|
|
|
373
|
+}
|
|
192
|
374
|
|
|
193
|
|
- .colorbox {
|
|
194
|
|
- width: 50px;
|
|
195
|
|
- height: 30px;
|
|
196
|
|
- display: flex;
|
|
197
|
|
- justify-content: center;
|
|
198
|
|
- align-items: center;
|
|
199
|
|
-
|
|
200
|
|
- .dot {
|
|
201
|
|
- width: 10px;
|
|
202
|
|
- height: 10px;
|
|
203
|
|
- display: block;
|
|
204
|
|
- border-radius: 50%;
|
|
205
|
|
- }
|
|
|
375
|
+.dot {
|
|
|
376
|
+ width: 6px;
|
|
|
377
|
+ height: 6px;
|
|
|
378
|
+ display: block;
|
|
|
379
|
+ border-radius: 50%;
|
|
|
380
|
+ margin-left: 10px;
|
|
|
381
|
+
|
|
|
382
|
+ &.red {
|
|
|
383
|
+ background-color: red;
|
|
206
|
384
|
}
|
|
207
|
385
|
|
|
|
386
|
+ &.green {
|
|
|
387
|
+ background-color: green;
|
|
|
388
|
+ }
|
|
208
|
389
|
}
|
|
209
|
|
-
|
|
210
|
390
|
</style>
|