Commit 60951143 authored by xiaoye's avatar xiaoye

fix

parent 4286fbcd
...@@ -162,13 +162,13 @@ ...@@ -162,13 +162,13 @@
<uni-number-box <uni-number-box
v-model = 'match.round' v-model = 'match.round'
:min = '1' :min = '0'
:max = 'match.maxRound' :max = 'match.maxRound'
:disabled = "tournament.this.status == 'Ready'" :disabled = "tournament.this.status == 'Ready'"
></uni-number-box> ></uni-number-box>
</div> </div>
<view class = 'button' @click = '() => { match.chk = true; match.page = 1; match.search(true); }'>全部轮次</view> <view class = 'button' @click = '() => { match.round = 0; }'>全部轮次</view>
</view> </view>
<transition name = 'switch'> <transition name = 'switch'>
<uni-list> <uni-list>
...@@ -177,7 +177,9 @@ ...@@ -177,7 +177,9 @@
title = '暂无比赛' title = '暂无比赛'
> >
</uni-list-item> </uni-list-item>
<view v-for = '(i, v) in match.array'> <view
v-for = '(i, v) in (match.round == 0) ? match.array.slice((match.page - 1) * 20, match.page * 20) : match.array.filter(m => m.round == match.round).slice((match.page - 1) * 20, match.page * 20)'
>
<view <view
class = 'match' class = 'match'
v-show = "match.submit.page === i && (i.status == 'Running' || i.status == 'Finished')" v-show = "match.submit.page === i && (i.status == 'Running' || i.status == 'Finished')"
...@@ -205,7 +207,7 @@ ...@@ -205,7 +207,7 @@
</view> </view>
<uni-list-item <uni-list-item
:clickable = true :clickable = true
@click = 'match.submit.show(v)' @click = 'match.submit.show(i)'
id = 'matchList' id = 'matchList'
> >
<template v-slot:body> <template v-slot:body>
...@@ -270,8 +272,7 @@ ...@@ -270,8 +272,7 @@
:current = 'match.page' :current = 'match.page'
v-model = 'match.page' v-model = 'match.page'
pageSize = 20 pageSize = 20
:total = 'match.total' :total = '(match.round == 0) ? match.total : match.array.filter(m => m.round == match.round).length'
@change = 'match.search()'
> >
</uni-pagination> </uni-pagination>
</uni-card> </uni-card>
...@@ -282,7 +283,6 @@ ...@@ -282,7 +283,6 @@
</template> </template>
<script setup lang = 'ts'> <script setup lang = 'ts'>
import {ref, reactive, onMounted, onUnmounted, onBeforeMount, watch} from 'vue'; import {ref, reactive, onMounted, onUnmounted, onBeforeMount, watch} from 'vue';
import YGOProDeck from 'ygopro-deck-encode';
import emitter from '../script/emitter.ts' import emitter from '../script/emitter.ts'
import UniApp from '../script/uniapp.ts'; import UniApp from '../script/uniapp.ts';
import {Tabulator, User} from '../script/post.ts'; import {Tabulator, User} from '../script/post.ts';
...@@ -291,7 +291,7 @@ ...@@ -291,7 +291,7 @@
import Match from '../script/match.ts'; import Match from '../script/match.ts';
import Const from '../script/const.ts' import Const from '../script/const.ts'
import Mycard from '../script/mycard.ts'; import Mycard from '../script/mycard.ts';
import {TournamentCreateObject, MatchUpdateObject, TournamentAParticipant, ParticipantUpdateObject} from '../script/type.ts' import {TournamentCreateObject, MatchUpdateObject, TournamentGet, ParticipantUpdateObject} from '../script/type.ts'
let tournament = reactive({ let tournament = reactive({
this : undefined as undefined | Tournament, this : undefined as undefined | Tournament,
status : { status : {
...@@ -306,6 +306,25 @@ ...@@ -306,6 +306,25 @@
['Finished', 'darkgray'] ['Finished', 'darkgray']
]) as Map<string, string>, ]) as Map<string, string>,
}, },
search : async () : Promise<boolean> => {
const url = window.location.hash.match(/#\/(.*?)(?:\?|$)/);
// @ts-ignore
const id = url[1];
// @ts-ignore
const t : TournamentGet = await Tabulator.Tournament.Find(Mycard.token, id);
if (t.tournament) {
tournament.this = t.tournament;
emitter.emit(Const.tournamentReload, tournament.this)
const participants = t.participant;
participant.array = participants.participants;
participant.total = participants.total;
const matches = t.match;
match.array = matches.matches;
match.total = matches.total;
return true;
}
return false;
},
on : () : void => { on : () : void => {
switch(tournament.this?.status) { switch(tournament.this?.status) {
case 'Ready': case 'Ready':
...@@ -367,7 +386,7 @@ ...@@ -367,7 +386,7 @@
if (!res.confirm) return; if (!res.confirm) return;
// @ts-ignore // @ts-ignore
if (await Tabulator.Tournament.Shuffle(Mycard.token, tournament.this.id)) if (await Tabulator.Tournament.Shuffle(Mycard.token, tournament.this.id))
participant.search(); tournament.search();
} }
}); });
}, },
...@@ -394,7 +413,7 @@ ...@@ -394,7 +413,7 @@
if (await Tabulator.Tournament.UpdateYdk(Mycard.token, tournament.this.id, res)) { if (await Tabulator.Tournament.UpdateYdk(Mycard.token, tournament.this.id, res)) {
for (const i of del_list) for (const i of del_list)
await participant.del(i); await participant.del(i);
await participant.search(); await tournament.search();
} }
}; };
await UniApp.selectFile(['.ydk', '.txt'], f); await UniApp.selectFile(['.ydk', '.txt'], f);
...@@ -407,7 +426,6 @@ ...@@ -407,7 +426,6 @@
page : 1, page : 1,
round : 1, round : 1,
maxRound : 2, maxRound : 2,
chk : false,
status : { status : {
color : new Map([ color : new Map([
['Running', 'rgb(84, 200, 17)'], ['Running', 'rgb(84, 200, 17)'],
...@@ -417,8 +435,8 @@ ...@@ -417,8 +435,8 @@
}, },
submit : { submit : {
page : undefined as Match | undefined, page : undefined as Match | undefined,
show : (v : number) : void => { show : (i : Match) : void => {
match.submit.page = match.submit.page == match.array[v] ? undefined : match.array[v]; match.submit.page = match.submit.page === i ? undefined : i;
if (!match.submit.page) if (!match.submit.page)
match.submit.chk = match.array.map(i => [i.player1Score ?? 0, i.player2Score ?? 0]); match.submit.chk = match.array.map(i => [i.player1Score ?? 0, i.player2Score ?? 0]);
}, },
...@@ -448,12 +466,6 @@ ...@@ -448,12 +466,6 @@
} }
}, },
chk : [] as Array<Array<number>> chk : [] as Array<Array<number>>
},
search : async (chk : boolean = match.chk) : Promise<void> => {
// @ts-ignore
const matchs = await Tabulator.Match.FindALL(Mycard.token, {tournamentId : tournament.this.id, statusIn : 'Running,Finished', pageCount : match.page, round : chk ? undefined : match.round});
match.array = matchs.matchs;
match.total = matchs.total;
} }
}); });
...@@ -466,7 +478,7 @@ ...@@ -466,7 +478,7 @@
// @ts-ignore // @ts-ignore
if (await Tabulator.Participant.Create(Mycard.token, { name : participant.name, tournamentId : tournament.this.id}, participant.array)) { if (await Tabulator.Participant.Create(Mycard.token, { name : participant.name, tournamentId : tournament.this.id}, participant.array)) {
participant.name = ''; participant.name = '';
await participant.search(); await tournament.search();
} }
}, },
del : async(i : Participant) : Promise<void> => { del : async(i : Participant) : Promise<void> => {
...@@ -482,29 +494,13 @@ ...@@ -482,29 +494,13 @@
} }
// @ts-ignore // @ts-ignore
if (tournament.this.status == 'Ready' ? await del() : await update()) if (tournament.this.status == 'Ready' ? await del() : await update())
await participant.search(); await tournament.search();
}, },
update : async (Data : TournamentCreateObject) : Promise<void> => { update : async (Data : TournamentCreateObject) : Promise<void> => {
// @ts-ignore // @ts-ignore
if (await Tabulator.Tournament.Update(Mycard.token, tournament.this.id, Data)) if (await Tabulator.Tournament.Update(Mycard.token, tournament.this.id, Data))
page.reload(); page.reload();
}, },
search : async () : Promise<boolean> => {
const url = window.location.hash.match(/#\/(.*?)(?:\?|$)/);
// @ts-ignore
const id = url[1];
// @ts-ignore
const t : TournamentAParticipant = await Tabulator.Tournament.Find(Mycard.token, id);
if (t.tournament) {
tournament.this = t.tournament;
emitter.emit(Const.tournamentReload, tournament.this)
const participants = t.participant;
participant.array = participants.participants;
participant.total = participants.total;
return true;
}
return false;
},
upload : async (i : Participant) : Promise<void> => { upload : async (i : Participant) : Promise<void> => {
const f = async (res : UniApp.ChooseFileSuccessCallbackResult) : Promise<void> => { const f = async (res : UniApp.ChooseFileSuccessCallbackResult) : Promise<void> => {
if (res.tempFiles[0].size < Const.maxSize) { if (res.tempFiles[0].size < Const.maxSize) {
...@@ -513,7 +509,7 @@ ...@@ -513,7 +509,7 @@
name : i.name, name : i.name,
deckbuf : i.deckbuf deckbuf : i.deckbuf
} as ParticipantUpdateObject)) } as ParticipantUpdateObject))
await participant.search(); await tournament.search();
} }
}; };
await UniApp.selectFile(['.ydk', '.txt'], f, 1); await UniApp.selectFile(['.ydk', '.txt'], f, 1);
...@@ -545,7 +541,7 @@ ...@@ -545,7 +541,7 @@
if (v1 - v2 != 1) { if (v1 - v2 != 1) {
// @ts-ignore // @ts-ignore
if (await participant.move.change(participant.array[v1].id, v2 >= 1 ? participant.array[v2 - 1].id : 0) && await participant.move.change(participant.array[v2].id, v1 >= 1 ? participant.array[v1 - 1].id : 0)) if (await participant.move.change(participant.array[v1].id, v2 >= 1 ? participant.array[v2 - 1].id : 0) && await participant.move.change(participant.array[v2].id, v1 >= 1 ? participant.array[v1 - 1].id : 0))
await participant.search(); await tournament.search();
} else { } else {
const v = v1 > v2 ? v1 : v2; const v = v1 > v2 ? v1 : v2;
await participant.move.down(participant.array[v - 1].id, participant.array[v].id); await participant.move.down(participant.array[v - 1].id, participant.array[v].id);
...@@ -560,7 +556,7 @@ ...@@ -560,7 +556,7 @@
down : async (from : number, to : number) : Promise<void> => { down : async (from : number, to : number) : Promise<void> => {
// @ts-ignore // @ts-ignore
if (await Tabulator.Tournament.Drag(Mycard.token, tournament.this?.id, from, to)) if (await Tabulator.Tournament.Drag(Mycard.token, tournament.this?.id, from, to))
await participant.search(); await tournament.search();
} }
} }
}); });
...@@ -579,10 +575,8 @@ ...@@ -579,10 +575,8 @@
emitter.emit(Const.show); emitter.emit(Const.show);
}, },
get : async () : Promise<void> => { get : async () : Promise<void> => {
if (await participant.search()) { if (await tournament.search())
await match.search();
page.show(); page.show();
}
else else
page.clear(true); page.clear(true);
}, },
...@@ -594,8 +588,7 @@ ...@@ -594,8 +588,7 @@
}).exec(); }).exec();
page.loading = true; page.loading = true;
participant.name = ''; participant.name = '';
if (await participant.search()) { if (await tournament.search()) {
await match.search();
await (new Promise(resolve => setTimeout(resolve, 500))); await (new Promise(resolve => setTimeout(resolve, 500)));
page.loading = false; page.loading = false;
page.height = 0; page.height = 0;
...@@ -644,8 +637,6 @@ ...@@ -644,8 +637,6 @@
watch(() => { return match.round; }, async () : Promise<void> => { watch(() => { return match.round; }, async () : Promise<void> => {
match.page = 1; match.page = 1;
match.chk = false;
await match.search();
}); });
watch(() => { return match.array; }, async () : Promise<void> => { watch(() => { return match.array; }, async () : Promise<void> => {
......
...@@ -22,7 +22,7 @@ import { ...@@ -22,7 +22,7 @@ import {
AllMatch, AllMatch,
AllAPI, AllAPI,
UserObject, UserObject,
TournamentAParticipant TournamentGet
} from './type.ts' } from './type.ts'
import UniApp from './uniapp.ts'; import UniApp from './uniapp.ts';
...@@ -79,7 +79,7 @@ class TabulatorAPI { ...@@ -79,7 +79,7 @@ class TabulatorAPI {
return false; return false;
} }
}, },
Find : async (token : string, id : number) : Promise<TournamentAParticipant> => { Find : async (token : string, id : number) : Promise<TournamentGet> => {
let response : { let response : {
data : { data : {
data : TournamentObject; data : TournamentObject;
...@@ -92,14 +92,22 @@ class TabulatorAPI { ...@@ -92,14 +92,22 @@ class TabulatorAPI {
} }
}); });
let participants : Array<Participant> = []; let participants : Array<Participant> = [];
let matches : Array<Match> = [];
response.data.data.participants.forEach((i : ParticipantObject) => { response.data.data.participants.forEach((i : ParticipantObject) => {
participants.push(new Participant(i)); participants.push(new Participant(i));
}); });
response.data.data.matches.forEach((i : MatchObject) => {
matches.push(new Match(i));
});
return { return {
tournament : new Tournament(response.data.data), tournament : new Tournament(response.data.data),
participant : { participant : {
participants : participants, participants : participants,
total : participants.length total : participants.length
},
match : {
matches : matches,
total : matches.length
} }
}; };
} }
...@@ -110,6 +118,10 @@ class TabulatorAPI { ...@@ -110,6 +118,10 @@ class TabulatorAPI {
participant : { participant : {
participants : [], participants : [],
total : 0 total : 0
},
match : {
matches : [],
total : 0
} }
}; };
} }
...@@ -496,14 +508,14 @@ class TabulatorAPI { ...@@ -496,14 +508,14 @@ class TabulatorAPI {
}) })
return { return {
total : response.data.total, total : response.data.total,
matchs : matchs matches : matchs
}; };
} }
catch(error) { catch(error) {
console.error(error); console.error(error);
return { return {
total : 0, total : 0,
matchs : [] matches : []
}; };
} }
}, },
......
...@@ -64,6 +64,7 @@ interface TournamentObject extends TournamentCreateObject { ...@@ -64,6 +64,7 @@ interface TournamentObject extends TournamentCreateObject {
creator : number; creator : number;
createdAt : string; createdAt : string;
participants : Array<ParticipantObject>; participants : Array<ParticipantObject>;
matches : Array<MatchObject>
} }
interface TournamentFindObject { interface TournamentFindObject {
...@@ -144,16 +145,17 @@ interface AllParticipant extends All { ...@@ -144,16 +145,17 @@ interface AllParticipant extends All {
} }
interface AllMatch extends All { interface AllMatch extends All {
matchs : Array<Match>; matches : Array<Match>;
} }
interface AllAPI extends All { interface AllAPI extends All {
api : Array<ApiKey>; api : Array<ApiKey>;
} }
interface TournamentAParticipant { interface TournamentGet {
tournament : Tournament | undefined; tournament : Tournament | undefined;
participant : AllParticipant participant : AllParticipant,
match : AllMatch
} }
interface UserObject { interface UserObject {
...@@ -189,6 +191,6 @@ export { ...@@ -189,6 +191,6 @@ export {
AllAPI, AllAPI,
ruleSettings, ruleSettings,
UserObject, UserObject,
TournamentAParticipant, TournamentGet,
Deck Deck
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment