lauched_games.vue 3.67 KB
Newer Older
孙谢炜's avatar
孙谢炜 committed
1 2
<template>
    <v-app>
sunxiwei's avatar
sunxiwei committed
3 4 5
        <v-data-table-server :headers="headers" :items="filteredMatches" item-key="id" :search="search"
            v-model:items-per-page="itemsPerPage" @update:options="loadGames" :items-length="totalGames"
            :loading="loading">
孙谢炜's avatar
孙谢炜 committed
6 7 8 9 10 11 12 13 14
            <template v-slot:top>
                <v-toolbar flat>
                    <v-toolbar-title>比赛</v-toolbar-title>
                    <v-divider class="mx-4" inset vertical></v-divider>
                    <v-spacer></v-spacer>
                    <v-text-field v-model="search" append-icon="mdi-magnify" label="搜索" single-line
                        hide-details></v-text-field>
                </v-toolbar>
            </template>
sunxiwei's avatar
sunxiwei committed
15
            <template v-slot:item.date="{ item }">
sunxiwei's avatar
sunxiwei committed
16
                <p style="width:60px">{{ item.date }}</p>
sunxiwei's avatar
sunxiwei committed
17
            </template>
孙谢炜's avatar
孙谢炜 committed
18
            <template v-slot:item.name="{ item }">
19
                <p style="width:120px">{{ item.username }} VS {{ item.opponentname }}</p>
孙谢炜's avatar
孙谢炜 committed
20 21
            </template>
            <template v-slot:item.score="{ item }">
22
                <p style="width:30px">{{ item.userScore }} - {{ item.opponentScore }}</p>
孙谢炜's avatar
孙谢炜 committed
23 24
            </template>
            <template v-slot:item.verified="{ item }">
25
                <div style="width:80px"><v-icon v-if="item.verified === 'WAITING'" color="blue">mdi-help-circle</v-icon>
sunxiwei's avatar
sunxiwei committed
26 27 28
                    <v-icon v-else-if="item.verified === 'PASSED'" color="green">mdi-check-circle</v-icon>
                    <v-icon v-else-if="item.verified === 'REJECT'" color="red">mdi-close-circle</v-icon>
                </div>
孙谢炜's avatar
孙谢炜 committed
29
            </template>
sunxiwei's avatar
sunxiwei committed
30
        </v-data-table-server>
孙谢炜's avatar
孙谢炜 committed
31 32 33 34 35 36
    </v-app>
</template>

<script setup>
import { ref } from 'vue';
import { reactive } from 'vue';
孙谢炜's avatar
孙谢炜 committed
37
import { computed } from 'vue';
sunxiwei's avatar
sunxiwei committed
38
import axios from 'axios';
孙谢炜's avatar
孙谢炜 committed
39

孙谢炜's avatar
孙谢炜 committed
40
const search = ref('');
孙谢炜's avatar
孙谢炜 committed
41

孙谢炜's avatar
孙谢炜 committed
42
const headers = reactive([
sunxiwei's avatar
sunxiwei committed
43 44 45
    { title: '日期', key: 'date', sortable: false },
    { title: '比赛', key: 'name', sortable: false },
    { title: '比分', key: 'score', sortable: false },
孙谢炜's avatar
孙谢炜 committed
46 47
    { title: '审核状态', key: 'verified' },
]);
sunxiwei's avatar
sunxiwei committed
48
const matches = ref(new Array());
sunxiwei's avatar
sunxiwei committed
49 50 51
const loading = ref(true);
const totalGames = ref(0);
const itemsPerPage = ref(5);
sunxiwei's avatar
sunxiwei committed
52 53 54
// matches = [
//     { id: 1, username: '张三', opponentname: '零', userScore: 3, opponentScore: 2, verified: "PASSED" },
// ];
孙谢炜's avatar
孙谢炜 committed
55

孙谢炜's avatar
孙谢炜 committed
56 57 58 59 60 61 62 63 64 65
const filteredMatches = computed(() => {
    // return matches.value
    return matches.value.filter(match =>
        match.username.includes(search.value) ||
        match.opponentname.includes(search.value) ||
        match.userScore === parseInt(search.value) ||
        match.opponentScore === parseInt(search.value)
    );
})

sunxiwei's avatar
sunxiwei committed
66 67 68 69 70
function loadGames({ page, itemsPerPage }) {
    axios.get('/api/myLauchedGames',{
        params:{
            pages: page,
            lim: itemsPerPage,
sunxiwei's avatar
sunxiwei committed
71 72
        }
    })
sunxiwei's avatar
sunxiwei committed
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
        .then(function (response) {
            loading.value = true;
            const data = response.data;
            totalGames.value = data.totalGames;
            matches.value.length = 0; 
            for (var i = 0; i < data.Games.length; i++) {
                // matches.value[i].id = i+1;
                var match = {
                    id: data.Games[i].id,
                    date: data.Games[i].game_date,
                    username: data.Games[i].player1_real_name,
                    opponentname: data.Games[i].player2_real_name,
                    userScore: data.Games[i].score1,
                    opponentScore: data.Games[i].score2,
                    verified: data.Games[i].status,
                }
                matches.value[i] = match;
            }
            loading.value = false;
        })
        .catch(function (error) {
            console.log(error);
        })
}


孙谢炜's avatar
孙谢炜 committed
99
</script>