js kinda sucks a lot
This commit is contained in:
@@ -8,16 +8,13 @@
|
||||
</div>
|
||||
<v-data-table-server
|
||||
:headers="headers"
|
||||
v-model:items-per-page="resltsPerPage"
|
||||
v-model:items-per-page="resultsPerPage"
|
||||
:items="games"
|
||||
:items-length="count"
|
||||
v-model:page="page"
|
||||
@update:options="loadData"
|
||||
>
|
||||
|
||||
|
||||
|
||||
<template v-slot:item.id="{ item }">
|
||||
<template v-slot:item.id="{ item }">
|
||||
<a v-bind:href="`/#/games/${item.id}`">{{ item.id }}</a>
|
||||
</template>
|
||||
<template v-slot:item.title="{ item }">
|
||||
@@ -27,7 +24,6 @@
|
||||
{{ new Date(item.postdate * 1000).toISOString().split('T')[0] }}
|
||||
</template>
|
||||
|
||||
|
||||
<template #bottom></template>
|
||||
</v-data-table-server>
|
||||
<v-pagination
|
||||
@@ -52,8 +48,11 @@ import GameTable from './GameTable.vue'
|
||||
import { onMounted, watch, ref } from 'vue'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import axios from 'axios'
|
||||
import { VDataTable } from 'vuetify/components'
|
||||
|
||||
const headers = [
|
||||
type ReadonlyHeaders = VDataTable['$props']['headers']
|
||||
|
||||
const headers: ReadonlyHeaders = [
|
||||
{ title: 'ID', align: 'start', sortable: true, key: 'id' },
|
||||
{ title: 'Title', align: 'start', sortable: true, key: 'title' },
|
||||
{ title: 'Status', align: 'start', sortable: true, key: 'status' },
|
||||
@@ -66,13 +65,13 @@ const router = useRouter()
|
||||
const games = ref<Game[]>([])
|
||||
const pageCount = ref(1)
|
||||
let page = ref(1)
|
||||
const resultePerPage = ref(10)
|
||||
const resultsPerPage = ref(10)
|
||||
|
||||
let count = ref(10)
|
||||
|
||||
const filtervalue = ref<string>('')
|
||||
|
||||
async function loadData({ page, itemsPerPage, sortBy }) {
|
||||
async function loadData({ page, itemsPerPage, sortBy }: any) {
|
||||
let sortString = 'id'
|
||||
if (sortBy[0]) {
|
||||
console.log(sortBy[0].key)
|
||||
@@ -80,15 +79,15 @@ async function loadData({ page, itemsPerPage, sortBy }) {
|
||||
sortString = `${sortBy[0].key} ${sortBy[0].order}`
|
||||
}
|
||||
|
||||
console.log(page)
|
||||
console.log(itemsPerPage)
|
||||
console.log(page)
|
||||
console.log(itemsPerPage)
|
||||
console.log(sortBy)
|
||||
|
||||
const response = await axios.post('/api/game', {
|
||||
page: `${page - 1}`,
|
||||
count: `${itemsPerPage}`,
|
||||
orderBy: sortString,
|
||||
filter: filtervalue.value ? `title:"${filtervalue.value}"` : '',
|
||||
filter: filtervalue.value ? `title:"${filtervalue.value}"` : ''
|
||||
})
|
||||
|
||||
games.value = response.data.gameData
|
||||
@@ -111,7 +110,7 @@ watch(route, (newValue, oldValue) => {
|
||||
if (route.query.filter) {
|
||||
filtervalue.value = route.query.filter.toString()
|
||||
}
|
||||
loadData({page: page.value, itemsPerPage: resultePerPage.value, sortBy:[]})
|
||||
loadData({ page: page.value, itemsPerPage: resultsPerPage.value, sortBy: [] })
|
||||
})
|
||||
|
||||
let debounce: ReturnType<typeof setTimeout>
|
||||
@@ -120,7 +119,7 @@ watch(filtervalue, (newFilter: string, oldFilter: string) => {
|
||||
debounce = setTimeout(() => {
|
||||
router.replace({ query: { page: route.query.page, filter: newFilter } })
|
||||
}, 500)
|
||||
loadData({page: page.value, itemsPerPage: resultePerPage.value, sortBy:[]})
|
||||
loadData({ page: page.value, itemsPerPage: resultsPerPage.value, sortBy: [] })
|
||||
})
|
||||
|
||||
onMounted(async () => {
|
||||
|
||||
Reference in New Issue
Block a user