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

73 lines
1.8 KiB
JavaScript
Raw Normal View History

2024-09-19 10:46:07 +08:00
import { reactive } from 'vue'
import { list, remove } from '@/api/login_log'
2024-10-31 22:27:30 +08:00
import { list as fetchPeers } from '@/api/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-09-19 10:46:07 +08:00
export function useRepositories () {
const route = useRoute()
const user_id = route.query?.user_id
const listRes = reactive({
list: [], total: 0, loading: false,
})
const listQuery = reactive({
page: 1,
page_size: 10,
is_my: 0,
user_id: user_id ? parseInt(user_id) : null,
})
const getList = async () => {
listRes.loading = true
const res = await list(listQuery).catch(_ => false)
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)
const peers = await fetchPeers({ uuids }).catch(_ => false)
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
}
const res = await remove({ id: row.id }).catch(_ => false)
if (res) {
2024-10-21 21:07:11 +08:00
ElMessage.success(T('OperationSuccess'))
2024-09-19 10:46:07 +08:00
getList()
}
}
return {
listRes,
listQuery,
getList,
handlerQuery,
del,
}
}