Files
rustdesk-api-web/src/views/login/log.js
T

101 lines
2.8 KiB
JavaScript
Raw Normal View History

2024-11-12 09:07:42 +08:00
import { reactive, ref } from 'vue'
2024-12-27 19:25:22 +08:00
import { list as admin_fetchPeers } from '@/api/peer'
import { list as my_fetchPeers } from '@/api/my/peer'
2024-09-19 10:46:07 +08:00
import { ElMessage, ElMessageBox } from 'element-plus'
import { useRoute } from 'vue-router'
2024-10-21 21:07:11 +08:00
import { T } from '@/utils/i18n'
2024-12-27 19:25:22 +08:00
import { batchDelete as admin_batchDelete, list as admin_list, remove as admin_remove } from '@/api/login_log'
import { batchDelete as my_batchDelete, list as my_list, remove as my_remove } from '@/api/my/login_log'
2024-09-19 10:46:07 +08:00
2024-12-27 19:25:22 +08:00
const apis = {
admin: { batchDelete: admin_batchDelete, list: admin_list, remove: admin_remove, fetchPeers: admin_fetchPeers },
my: { batchDelete: my_batchDelete, list: my_list, remove: my_remove, fetchPeers: my_fetchPeers },
}
export function useRepositories (api_type = 'my') {
2024-09-19 10:46:07 +08:00
const listRes = reactive({
list: [], total: 0, loading: false,
})
const listQuery = reactive({
page: 1,
page_size: 10,
is_my: 0,
2024-12-27 19:25:22 +08:00
user_id: null,
2024-09-19 10:46:07 +08:00
})
const getList = async () => {
listRes.loading = true
2024-12-27 19:25:22 +08:00
const res = await apis[api_type].list(listQuery).catch(_ => false)
2024-09-19 10:46:07 +08:00
listRes.loading = false
if (res) {
2024-10-31 22:27:30 +08:00
const uuids = res.data.list.filter(item => item.uuid).map(item => item.uuid)
2024-12-27 19:25:22 +08:00
const peers = await apis[api_type].fetchPeers({ uuids }).catch(_ => false)
2024-10-31 22:27:30 +08:00
if (peers?.data?.list) {
res.data.list.forEach(item => {
if (item.uuid) {
item.peer = peers.data.list.find(peer => peer.uuid === item.uuid)
}
})
}
2024-09-19 10:46:07 +08:00
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-10-21 21:07:11 +08:00
const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('Delete') }), {
confirmButtonText: T('Confirm'),
cancelButtonText: T('Cancel'),
2024-09-19 10:46:07 +08:00
type: 'warning',
}).catch(_ => false)
if (!cf) {
return false
}
2024-12-27 19:25:22 +08:00
const res = await apis[api_type].remove({ id: row.id }).catch(_ => false)
2024-09-19 10:46:07 +08:00
if (res) {
2024-10-21 21:07:11 +08:00
ElMessage.success(T('OperationSuccess'))
2024-09-19 10:46:07 +08:00
getList()
}
}
2024-11-12 09:07:42 +08:00
const batchdel = async (rows) => {
const ids = rows.map(r => r.id)
if (!ids.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
}
2024-12-27 19:25:22 +08:00
const res = await apis[api_type].batchDelete({ ids }).catch(_ => false)
2024-11-12 09:07:42 +08:00
if (res) {
ElMessage.success(T('OperationSuccess'))
getList()
}
}
2024-09-19 10:46:07 +08:00
return {
listRes,
listQuery,
getList,
handlerQuery,
del,
2024-11-12 09:07:42 +08:00
batchdel,
2024-09-19 10:46:07 +08:00
}
}