73 lines
1.8 KiB
JavaScript
73 lines
1.8 KiB
JavaScript
import { reactive } from 'vue'
|
|
import { list, remove } from '@/api/login_log'
|
|
import { list as fetchPeers } from '@/api/peer'
|
|
import { ElMessage, ElMessageBox } from 'element-plus'
|
|
import { useRoute } from 'vue-router'
|
|
import { T } from '@/utils/i18n'
|
|
|
|
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) {
|
|
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)
|
|
}
|
|
})
|
|
}
|
|
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) => {
|
|
const cf = await ElMessageBox.confirm(T('Confirm?', { param: T('Delete') }), {
|
|
confirmButtonText: T('Confirm'),
|
|
cancelButtonText: T('Cancel'),
|
|
type: 'warning',
|
|
}).catch(_ => false)
|
|
if (!cf) {
|
|
return false
|
|
}
|
|
|
|
const res = await remove({ id: row.id }).catch(_ => false)
|
|
if (res) {
|
|
ElMessage.success(T('OperationSuccess'))
|
|
getList()
|
|
}
|
|
}
|
|
|
|
return {
|
|
listRes,
|
|
listQuery,
|
|
getList,
|
|
handlerQuery,
|
|
del,
|
|
}
|
|
}
|