add share record

This commit is contained in:
lejianwen
2024-12-13 12:31:00 +08:00
parent 2ea5a6eab3
commit 502bea8dc3
10 changed files with 392 additions and 0 deletions
+131
View File
@@ -0,0 +1,131 @@
<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">
</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()
}
}
</script>
<style scoped lang="scss">
.list-query .el-select {
--el-select-width: 160px;
}
</style>
+156
View File
@@ -0,0 +1,156 @@
<template>
<div>
<el-card class="list-query" shadow="hover">
<el-form inline label-width="80px">
<el-form-item :label="T('User')">
<el-select v-model="listQuery.user_id" clearable>
<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>
<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 :label="T('User')" align="center" width="120">
<template #default="{row}">
<span v-if="row.user_id"> <el-tag>{{ allUsers?.find(u => u.id === row.user_id)?.username }}</el-tag> </span>
</template>
</el-table-column>
<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">
</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 { loadAllUsers } from '@/global'
import { T } from '@/utils/i18n'
import { remove, list, batchDelete } from '@/api/share_record'
import { ElMessage, ElMessageBox } from 'element-plus'
const { allUsers, getAllUsers } = loadAllUsers()
getAllUsers()
const listRes = reactive({
list: [], total: 0, loading: false,
})
const listQuery = reactive({
page: 1,
page_size: 10,
is_my: 0,
user_id: null,
})
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 expired = (row) => {
const now = new Date().getTime()
return row.expire * 1000 < now
}
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()
}
}
</script>
<style scoped lang="scss">
.list-query .el-select {
--el-select-width: 160px;
}
</style>