Files
rustdesk-api-web/src/views/my/share_record/index.vue
T

141 lines
4.2 KiB
Vue
Raw Normal View History

2024-12-13 12:31:00 +08:00
<template>
<div>
<el-card class="list-query" shadow="hover">
<el-form inline label-width="80px">
<el-form-item>
<el-button type="primary" @click="handlerQuery">{{ T('Filter') }}</el-button>
<el-button type="danger" @click="toBatchDelete">{{ T('BatchDelete') }}</el-button>
</el-form-item>
</el-form>
</el-card>
<el-card class="list-body" shadow="hover">
<el-table :data="listRes.list" v-loading="listRes.loading" border @selection-change="handleSelectionChange">
<el-table-column type="selection" align="center" width="50"/>
<el-table-column prop="id" label="ID" align="center" width="100"/>
<el-table-column prop="peer_id" :label="T('Peer')" align="center"/>
<el-table-column prop="created_at" :label="T('CreatedAt')" align="center"/>
<el-table-column :label="`${T('ExpireTime')}(${T('Second')})`" prop="expire" align="center">
2024-12-13 13:34:23 +08:00
<template #default="{row}">
<el-tag :type="expired(row)?'info':'success'">{{ row.expire ? row.expire : '-' }}</el-tag>
</template>
2024-12-13 12:31:00 +08:00
</el-table-column>
<el-table-column :label="T('Actions')" align="center" width="400">
<template #default="{row}">
<el-button type="danger" @click="del(row)">{{ T('Delete') }}</el-button>
</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>
</div>
</template>
<script setup>
import { onActivated, onMounted, ref, watch, reactive } from 'vue'
import { T } from '@/utils/i18n'
import { share_record_remove as remove, share_record_list as list, share_record_batchDelete as batchDelete } from '@/api/my'
import { ElMessage, ElMessageBox } from 'element-plus'
const listRes = reactive({
list: [], total: 0, loading: false,
})
const listQuery = reactive({
page: 1,
page_size: 10,
})
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) => {
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()
}
}
onMounted(getList)
onActivated(getList)
watch(() => listQuery.page, getList)
watch(() => listQuery.page_size, handlerQuery)
const multipleSelection = ref([])
const handleSelectionChange = (val) => {
multipleSelection.value = val
}
const toBatchDelete = () => {
if (multipleSelection.value.length === 0) {
return
}
batchdel(multipleSelection.value)
}
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
}
const res = await batchDelete({ ids }).catch(_ => false)
if (res) {
ElMessage.success(T('OperationSuccess'))
getList()
}
}
2024-12-13 13:34:23 +08:00
const expired = (row) => {
const now = new Date().getTime()
const created_at = new Date(row.created_at).getTime()
return row.expire * 1000 + created_at < now
}
2024-12-13 12:31:00 +08:00
</script>
<style scoped lang="scss">
.list-query .el-select {
--el-select-width: 160px;
}
</style>