2024-09-13 16:34:15 +08:00
|
|
|
<template>
|
|
|
|
|
<div>
|
|
|
|
|
<el-card class="list-query" shadow="hover">
|
2024-09-29 11:50:23 +08:00
|
|
|
<el-form inline label-width="150px">
|
|
|
|
|
<el-form-item :label="T('LastOnlineTime')">
|
|
|
|
|
<el-select v-model="listQuery.time_ago" clearable>
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="item in timeFilters"
|
|
|
|
|
:key="item.value"
|
|
|
|
|
:label="item.text"
|
|
|
|
|
:value="item.value"
|
|
|
|
|
:disabled="item.value === 0"
|
|
|
|
|
></el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
2024-09-13 16:34:15 +08:00
|
|
|
<el-form-item>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-button type="primary" @click="handlerQuery">{{ T('Filter') }}</el-button>
|
|
|
|
|
<el-button type="danger" @click="toAdd">{{ T('Add') }}</el-button>
|
2024-09-29 11:50:23 +08:00
|
|
|
<el-button type="success" @click="toExport">{{ T('Export') }}</el-button>
|
|
|
|
|
<el-button type="danger" @click="toBatchDelete">{{ T('BatchDelete') }}</el-button>
|
2024-09-13 16:34:15 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</el-card>
|
|
|
|
|
<el-card class="list-body" shadow="hover">
|
2024-09-29 11:50:23 +08:00
|
|
|
<el-table :data="listRes.list" v-loading="listRes.loading" border size="small" @selection-change="handleSelectionChange">
|
|
|
|
|
<el-table-column type="selection" width="55" align="center"/>
|
2024-09-13 16:34:15 +08:00
|
|
|
<el-table-column prop="id" label="id" align="center"/>
|
|
|
|
|
<el-table-column prop="cpu" label="cpu" align="center"/>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-table-column prop="hostname" :label="T('Hostname')" align="center"/>
|
|
|
|
|
<el-table-column prop="memory" :label="T('Memory')" align="center"/>
|
|
|
|
|
<el-table-column prop="os" :label="T('Os')" align="center"/>
|
|
|
|
|
<el-table-column prop="username" :label="T('Username')" align="center"/>
|
|
|
|
|
<el-table-column prop="uuid" :label="T('Uuid')" align="center"/>
|
2024-09-29 11:50:23 +08:00
|
|
|
<el-table-column prop="version" :label="T('Version')" align="center" width="80"/>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-table-column prop="created_at" :label="T('CreatedAt')" align="center"/>
|
|
|
|
|
<el-table-column prop="updated_at" :label="T('UpdatedAt')" align="center"/>
|
2024-09-29 11:50:23 +08:00
|
|
|
<el-table-column prop="last_online_time" :label="T('LastOnlineTime')" align="center">
|
|
|
|
|
<template #default="{row}">
|
|
|
|
|
<div class="last_oline_time">
|
|
|
|
|
<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>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
<el-table-column :label="T('Actions')" align="center" width="500">
|
2024-09-13 16:34:15 +08:00
|
|
|
<template #default="{row}">
|
|
|
|
|
<el-button type="success" @click="toWebClientLink(row)">Web-Client</el-button>
|
2024-09-29 11:50:23 +08:00
|
|
|
<el-button type="primary" @click="toAddressBook(row)">{{ T('AddToAddressBook') }}</el-button>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-button @click="toEdit(row)">{{ T('Edit') }}</el-button>
|
|
|
|
|
<el-button type="danger" @click="del(row)">{{ T('Delete') }}</el-button>
|
2024-09-13 16:34:15 +08:00
|
|
|
</template>
|
|
|
|
|
</el-table-column>
|
|
|
|
|
</el-table>
|
|
|
|
|
</el-card>
|
|
|
|
|
<el-card class="list-page" shadow="hover">
|
|
|
|
|
<el-pagination background
|
|
|
|
|
layout="prev, pager, next, sizes, jumper"
|
|
|
|
|
:page-sizes="[10,20,50,100]"
|
|
|
|
|
v-model:page-size="listQuery.page_size"
|
|
|
|
|
v-model:current-page="listQuery.page"
|
|
|
|
|
:total="listRes.total">
|
|
|
|
|
</el-pagination>
|
|
|
|
|
</el-card>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-dialog v-model="formVisible" :title="!formData.row_id?T('Create'):T('Update')" width="800">
|
2024-09-13 16:34:15 +08:00
|
|
|
<el-form class="dialog-form" ref="form" :model="formData" label-width="120px">
|
|
|
|
|
<el-form-item label="id" prop="id" required>
|
|
|
|
|
<el-input v-model="formData.id"></el-input>
|
|
|
|
|
</el-form-item>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-form-item :label="T('Username')" prop="username">
|
2024-09-13 16:34:15 +08:00
|
|
|
<el-input v-model="formData.username"></el-input>
|
|
|
|
|
</el-form-item>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-form-item :label="T('Hostname')" prop="hostname">
|
2024-09-13 16:34:15 +08:00
|
|
|
<el-input v-model="formData.hostname"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="cpu" prop="cpu">
|
|
|
|
|
<el-input v-model="formData.cpu"></el-input>
|
|
|
|
|
</el-form-item>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-form-item :label="T('Memory')" prop="memory">
|
2024-09-13 16:34:15 +08:00
|
|
|
<el-input v-model="formData.memory"></el-input>
|
|
|
|
|
</el-form-item>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-form-item :label="T('Os')" prop="os">
|
2024-09-13 16:34:15 +08:00
|
|
|
<el-input v-model="formData.os"></el-input>
|
|
|
|
|
</el-form-item>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-form-item :label="T('Uuid')" prop="uuid">
|
2024-09-13 16:34:15 +08:00
|
|
|
<el-input v-model="formData.uuid"></el-input>
|
|
|
|
|
</el-form-item>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-form-item :label="T('Version')" prop="version">
|
2024-09-13 16:34:15 +08:00
|
|
|
<el-input v-model="formData.version"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item>
|
2024-09-25 22:24:16 +08:00
|
|
|
<el-button @click="formVisible = false">{{ T('Cancel') }}</el-button>
|
|
|
|
|
<el-button @click="submit" type="primary">{{ T('Submit') }}</el-button>
|
2024-09-13 16:34:15 +08:00
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</el-dialog>
|
2024-09-29 11:50:23 +08:00
|
|
|
|
|
|
|
|
<el-dialog v-model="ABFormVisible" width="800" :title="T('Create')">
|
|
|
|
|
<el-form class="dialog-form" ref="form" :model="ABFormData" label-width="120px">
|
|
|
|
|
<el-form-item :label="T('Owner')" prop="user_ids" required>
|
|
|
|
|
<el-select v-model="ABFormData.user_ids" multiple>
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="item in allUsers"
|
|
|
|
|
:key="item.id"
|
|
|
|
|
:label="item.username"
|
|
|
|
|
:value="item.id"
|
|
|
|
|
></el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item label="id" prop="id" required>
|
|
|
|
|
<el-input v-model="ABFormData.id"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="T('Username')" prop="username">
|
|
|
|
|
<el-input v-model="ABFormData.username"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="T('Alias')" prop="alias">
|
|
|
|
|
<el-input v-model="ABFormData.alias"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="T('Hostname')" prop="hostname">
|
|
|
|
|
<el-input v-model="ABFormData.hostname"></el-input>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item :label="T('Platform')" prop="platform">
|
|
|
|
|
<el-select v-model="ABFormData.platform">
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="item in ABPlatformList"
|
|
|
|
|
:key="item.value"
|
|
|
|
|
:label="item.label"
|
|
|
|
|
:value="item.value"
|
|
|
|
|
></el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
|
|
|
|
|
<el-form-item :label="T('Tags')" prop="tags">
|
|
|
|
|
<el-select v-model="ABFormData.tags" multiple>
|
|
|
|
|
<el-option
|
|
|
|
|
v-for="item in tagList"
|
|
|
|
|
:key="item.name"
|
|
|
|
|
:label="item.name"
|
|
|
|
|
:value="item.name"
|
|
|
|
|
></el-option>
|
|
|
|
|
</el-select>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
<el-form-item>
|
|
|
|
|
<el-button @click="ABFormVisible = false">{{ T('Cancel') }}</el-button>
|
|
|
|
|
<el-button @click="ABSubmit" type="primary">{{ T('Submit') }}</el-button>
|
|
|
|
|
</el-form-item>
|
|
|
|
|
</el-form>
|
|
|
|
|
</el-dialog>
|
2024-09-13 16:34:15 +08:00
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script setup>
|
2024-09-29 11:50:23 +08:00
|
|
|
import { computed, onActivated, onMounted, reactive, ref, watch } from 'vue'
|
|
|
|
|
import { batchRemove, create, list, remove, update } from '@/api/peer'
|
2024-09-13 16:34:15 +08:00
|
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
|
|
|
import { toWebClientLink } from '@/utils/webclient'
|
2024-09-25 22:24:16 +08:00
|
|
|
import { T } from '@/utils/i18n'
|
2024-09-29 11:50:23 +08:00
|
|
|
import { timeAgo } from '@/utils/time'
|
|
|
|
|
import { jsonToCsv, downBlob } from '@/utils/file'
|
|
|
|
|
import { useRepositories as useABRepositories } from '@/views/address_book/index'
|
|
|
|
|
import { loadAllUsers } from '@/global'
|
|
|
|
|
import { list as fetchTagList } from '@/api/tag'
|
|
|
|
|
import { batchCreate } from '@/api/address_book'
|
2024-09-13 16:34:15 +08:00
|
|
|
|
|
|
|
|
const listRes = reactive({
|
|
|
|
|
list: [], total: 0, loading: false,
|
|
|
|
|
})
|
|
|
|
|
const listQuery = reactive({
|
|
|
|
|
page: 1,
|
|
|
|
|
page_size: 10,
|
2024-09-29 11:50:23 +08:00
|
|
|
time_ago: null,
|
2024-09-13 16:34:15 +08:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const getList = async () => {
|
|
|
|
|
listRes.loading = true
|
|
|
|
|
const res = await list(listQuery).catch(_ => false)
|
|
|
|
|
listRes.loading = false
|
|
|
|
|
if (res) {
|
|
|
|
|
listRes.list = res.data.list
|
|
|
|
|
listRes.total = res.data.total
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
const handlerQuery = () => {
|
|
|
|
|
if (listQuery.page === 1) {
|
|
|
|
|
getList()
|
|
|
|
|
} else {
|
|
|
|
|
listQuery.page = 1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const del = async (row) => {
|
2024-09-25 22:24:16 +08:00
|
|
|
const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('Delete') }), {
|
|
|
|
|
confirmButtonText: T('Confirm'),
|
|
|
|
|
cancelButtonText: T('Cancel'),
|
2024-09-13 16:34:15 +08:00
|
|
|
type: 'warning',
|
|
|
|
|
}).catch(_ => false)
|
|
|
|
|
if (!cf) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const res = await remove({ row_id: row.row_id }).catch(_ => false)
|
|
|
|
|
if (res) {
|
2024-09-25 22:24:16 +08:00
|
|
|
ElMessage.success(T('OperationSuccess'))
|
2024-09-13 16:34:15 +08:00
|
|
|
getList()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onMounted(getList)
|
|
|
|
|
onActivated(getList)
|
|
|
|
|
|
|
|
|
|
watch(() => listQuery.page, getList)
|
|
|
|
|
|
|
|
|
|
watch(() => listQuery.page_size, handlerQuery)
|
|
|
|
|
|
|
|
|
|
const formVisible = ref(false)
|
|
|
|
|
const formData = reactive({
|
|
|
|
|
row_id: 0,
|
|
|
|
|
cpu: '',
|
|
|
|
|
hostname: '',
|
|
|
|
|
id: '',
|
|
|
|
|
memory: '',
|
|
|
|
|
os: '',
|
|
|
|
|
username: '',
|
|
|
|
|
uuid: '',
|
|
|
|
|
version: '',
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
const toEdit = (row) => {
|
|
|
|
|
formVisible.value = true
|
|
|
|
|
//将row中的数据赋值给formData
|
|
|
|
|
Object.keys(formData).forEach(key => {
|
|
|
|
|
formData[key] = row[key]
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
const toAdd = () => {
|
|
|
|
|
formVisible.value = true
|
|
|
|
|
//重置formData
|
|
|
|
|
formData.row_id = 0
|
|
|
|
|
formData.cpu = ''
|
|
|
|
|
formData.hostname = ''
|
|
|
|
|
formData.id = ''
|
|
|
|
|
formData.memory = ''
|
|
|
|
|
formData.os = ''
|
|
|
|
|
formData.username = ''
|
|
|
|
|
formData.uuid = ''
|
|
|
|
|
formData.version = ''
|
|
|
|
|
}
|
|
|
|
|
const submit = async () => {
|
|
|
|
|
const api = formData.row_id ? update : create
|
|
|
|
|
const res = await api(formData).catch(_ => false)
|
|
|
|
|
if (res) {
|
2024-09-25 22:24:16 +08:00
|
|
|
ElMessage.success(T('OperationSuccess'))
|
2024-09-13 16:34:15 +08:00
|
|
|
formVisible.value = false
|
|
|
|
|
getList()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-29 11:50:23 +08:00
|
|
|
const timeDis = (time) => {
|
|
|
|
|
let now = new Date().getTime()
|
|
|
|
|
let after = new Date(time * 1000).getTime()
|
|
|
|
|
return (now - after) / 1000
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const timeFilters = computed(() => [
|
|
|
|
|
{ text: T('MinutesLess', { param: 1 }, 1), value: -60 },
|
|
|
|
|
{ text: T('HoursLess', { param: 1 }, 1), value: -3600 },
|
|
|
|
|
{ text: T('DaysLess', { param: 1 }, 1), value: -86400 },
|
|
|
|
|
{ text: '---------', value: 0 },
|
|
|
|
|
{ text: T('MinutesAgo', { param: 1 }, 1), value: 60 },
|
|
|
|
|
{ text: T('HoursAgo', { param: 1 }, 1), value: 3600 },
|
|
|
|
|
{ text: T('DaysAgo', { param: 1 }, 1), value: 86400 },
|
|
|
|
|
{ text: T('MonthsAgo', { param: 1 }, 1), value: 2592000 },
|
|
|
|
|
// { text: T('YearsAgo', { param: 1 }, 1), value: 31536000 },
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
const toExport = async () => {
|
|
|
|
|
const q = { ...listQuery }
|
|
|
|
|
q.page_size = 10000
|
|
|
|
|
q.page = 1
|
|
|
|
|
const res = await list(q).catch(_ => false)
|
|
|
|
|
if (res) {
|
|
|
|
|
const data = res.data.list.map(item => {
|
|
|
|
|
item.last_online_time = item.last_online_time ? new Date(item.last_online_time * 1000).toLocaleString() : '-'
|
2024-09-29 14:12:37 +08:00
|
|
|
delete item.user_id
|
|
|
|
|
delete item.user
|
2024-09-29 11:50:23 +08:00
|
|
|
return item
|
|
|
|
|
})
|
|
|
|
|
const csv = jsonToCsv(data)
|
|
|
|
|
downBlob(csv, 'peers.csv')
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const {
|
|
|
|
|
platformList: ABPlatformList,
|
|
|
|
|
formVisible: ABFormVisible,
|
|
|
|
|
formData: ABFormData,
|
|
|
|
|
} = useABRepositories()
|
|
|
|
|
const toAddressBook = (peer) => {
|
|
|
|
|
ABFormData.id = peer.id
|
|
|
|
|
ABFormData.username = peer.username
|
|
|
|
|
ABFormData.hostname = peer.hostname
|
|
|
|
|
//匹配os
|
|
|
|
|
if (peer.os.indexOf('windows') !== -1) {
|
|
|
|
|
ABFormData.platform = ABPlatformList.find(item => item.label === 'Windows').value
|
|
|
|
|
} else if (peer.os.indexOf('linux') !== -1) {
|
|
|
|
|
ABFormData.platform = ABPlatformList.find(item => item.label === 'Linux').value
|
|
|
|
|
} else if (peer.os.indexOf('android') !== -1) {
|
|
|
|
|
ABFormData.platform = ABPlatformList.find(item => item.label === 'Android').value
|
|
|
|
|
} else if (peer.os.indexOf('mac') !== -1) {
|
|
|
|
|
ABFormData.platform = ABPlatformList.find(item => item.label === 'Mac OS').value
|
|
|
|
|
}
|
|
|
|
|
ABFormData.uuid = peer.uuid
|
|
|
|
|
ABFormVisible.value = true
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
const ABSubmit = async () => {
|
|
|
|
|
const res = await batchCreate(ABFormData).catch(_ => false)
|
|
|
|
|
if (res) {
|
|
|
|
|
ElMessage.success(T('OperationSuccess'))
|
|
|
|
|
ABFormVisible.value = false
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const { allUsers, getAllUsers } = loadAllUsers()
|
|
|
|
|
const tagList = ref([])
|
|
|
|
|
const fetchTagListData = async (user_id) => {
|
|
|
|
|
const res = await fetchTagList({ user_id }).catch(_ => false)
|
|
|
|
|
if (res) {
|
|
|
|
|
const ls = []
|
|
|
|
|
res.data.list.map(item => {
|
|
|
|
|
if (!ls.includes(item.name)) {
|
|
|
|
|
ls.push(item.name)
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
tagList.value = ls.map(item => ({ name: item }))
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
onMounted(getAllUsers)
|
|
|
|
|
onMounted(fetchTagListData)
|
|
|
|
|
|
|
|
|
|
const multipleSelection = ref([])
|
|
|
|
|
const handleSelectionChange = (val) => {
|
|
|
|
|
multipleSelection.value = val
|
|
|
|
|
}
|
|
|
|
|
const toBatchDelete = async () => {
|
|
|
|
|
if (!multipleSelection.value.length) {
|
|
|
|
|
ElMessage.warning(T('PleaseSelectData'))
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('BatchDelete') }), {
|
|
|
|
|
confirmButtonText: T('Confirm'),
|
|
|
|
|
cancelButtonText: T('Cancel'),
|
|
|
|
|
type: 'warning',
|
|
|
|
|
}).catch(_ => false)
|
|
|
|
|
if (!cf) {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const res = await batchRemove({ row_ids: multipleSelection.value.map(i => i.row_id) }).catch(_ => false)
|
|
|
|
|
if (res) {
|
|
|
|
|
ElMessage.success(T('OperationSuccess'))
|
|
|
|
|
getList()
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-09-13 16:34:15 +08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="scss">
|
|
|
|
|
.list-query .el-select {
|
2024-09-29 11:50:23 +08:00
|
|
|
--el-select-width: 180px;
|
2024-09-13 16:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-29 11:50:23 +08:00
|
|
|
.last_oline_time {
|
2024-09-13 16:34:15 +08:00
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
2024-09-29 11:50:23 +08:00
|
|
|
}
|
2024-09-13 16:34:15 +08:00
|
|
|
|
2024-09-29 11:50:23 +08:00
|
|
|
.dot {
|
|
|
|
|
width: 6px;
|
|
|
|
|
height: 6px;
|
|
|
|
|
display: block;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
margin-left: 10px;
|
|
|
|
|
|
|
|
|
|
&.red {
|
|
|
|
|
background-color: red;
|
2024-09-13 16:34:15 +08:00
|
|
|
}
|
|
|
|
|
|
2024-09-29 11:50:23 +08:00
|
|
|
&.green {
|
|
|
|
|
background-color: green;
|
|
|
|
|
}
|
2024-09-13 16:34:15 +08:00
|
|
|
}
|
|
|
|
|
</style>
|