Commit 9d194e19 authored by xiaoye's avatar xiaoye

update searcher in tournament

parent 7f023636
...@@ -65,14 +65,14 @@ ...@@ -65,14 +65,14 @@
id : i.id, id : i.id,
next : i.childMatchId, next : i.childMatchId,
player1: { player1: {
id: i.player1Id ? i.player1Id.toString() : '', id: i.player1.id ? i.player1.id.toString() : '',
name: i.player1Id ? getName(i.player1Id) : '', name: i.player1.id ? getName(i.player1.id) : '',
winner: i.winnerId ? i.player1Id == i.winnerId : undefined winner: i.winnerId ? i.player1.id == i.winnerId : undefined
}, },
player2: { player2: {
id: i.player2Id ? i.player2Id.toString() : '', id: i.player2.id ? i.player2.id.toString() : '',
name: i.player2Id ? getName(i.player2Id) : '', name: i.player2.id ? getName(i.player2.id) : '',
winner: i.winnerId ? i.player2Id == i.winnerId : undefined winner: i.winnerId ? i.player2.id == i.winnerId : undefined
} }
}); });
}); });
......
...@@ -97,6 +97,9 @@ ...@@ -97,6 +97,9 @@
</view> </view>
</div> </div>
</view> </view>
<view>
<uni-easyinput type = 'text' placeholder = '搜索选手' v-model = 'searcher.participant'></uni-easyinput>
</view>
<transition name = 'switch'> <transition name = 'switch'>
<uni-list> <uni-list>
<uni-list-item <uni-list-item
...@@ -105,9 +108,9 @@ ...@@ -105,9 +108,9 @@
> >
</uni-list-item> </uni-list-item>
<uni-list-item <uni-list-item
v-for = '(i, v) in participant.array.slice((participant.page - 1) * 20, participant.page * 20)' v-for = '(i, v) in participant.array.filter(i => searcher.filterParticipant(i)).slice((participant.page - 1) * 20, participant.page * 20)'
:title = "i.score && match.array.findIndex(m => (m.status == 'Finished' || m.status == 'Abandoned') && (m.player1Id == i.id || m.player2Id == i.id)) > -1 ? `胜平负:${i.score.win + i.score.bye}-${i.score.draw}-${i.score.lose}` : ''" :title = "i.score && match.array.findIndex(m => (m.status == 'Finished' || m.status == 'Abandoned') && (m.player1.id == i.id || m.player2.id == i.id)) > -1 ? `胜平负:${i.score.win + i.score.bye}-${i.score.draw}-${i.score.lose}` : ''"
:note = "i.score && match.array.findIndex(m => (m.status == 'Finished' || m.status == 'Abandoned') && (m.player1Id == i.id || m.player2Id == i.id)) > -1 ? `分数:${i.score.score}\n小分:${i.score.tieBreaker}` : ''" :note = "i.score && match.array.findIndex(m => (m.status == 'Finished' || m.status == 'Abandoned') && (m.player1.id == i.id || m.player2.id == i.id)) > -1 ? `分数:${i.score.score}\n小分:${i.score.tieBreaker}` : ''"
:clickable = true :clickable = true
> >
<template v-slot:header> <template v-slot:header>
...@@ -191,7 +194,7 @@ ...@@ -191,7 +194,7 @@
:current = 'participant.page' :current = 'participant.page'
v-model = 'participant.page' v-model = 'participant.page'
pageSize = 20 pageSize = 20
:total = 'participant.total' :total = 'searcher.participant ? participant.array.filter(i => searcher.filterParticipant(i)).length : participant.total'
> >
</uni-pagination> </uni-pagination>
</uni-card> </uni-card>
...@@ -219,6 +222,9 @@ ...@@ -219,6 +222,9 @@
<view class = 'button' @click = 'tournament.operatorChk(tournament.copy)'>复制对战表</view> <view class = 'button' @click = 'tournament.operatorChk(tournament.copy)'>复制对战表</view>
</div> </div>
</view> </view>
<view>
<uni-easyinput type = 'text' placeholder = '搜索比赛' v-model = 'searcher.match'></uni-easyinput>
</view>
<transition name = 'switch'> <transition name = 'switch'>
<uni-list> <uni-list>
<uni-list-item <uni-list-item
...@@ -227,7 +233,7 @@ ...@@ -227,7 +233,7 @@
> >
</uni-list-item> </uni-list-item>
<view <view
v-for = 'i 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)' v-for = 'i in match.array.filter(i => searcher.filterMatch(i)).slice((match.page - 1) * 20, match.page * 20)'
> >
<view <view
class = 'match' class = 'match'
...@@ -237,7 +243,7 @@ ...@@ -237,7 +243,7 @@
<uni-easyinput <uni-easyinput
:clearable = 'false' :clearable = 'false'
type = 'number' type = 'number'
:placeholder = 'participant.array.find(p => p.id == i.player1Id)?.name' :placeholder = 'i.player1.name'
v-model = 'match.submit.chk[match.array.findIndex(m => m === i)][0]' v-model = 'match.submit.chk[match.array.findIndex(m => m === i)][0]'
:disabled = "i.status != 'Running'" :disabled = "i.status != 'Running'"
></uni-easyinput> ></uni-easyinput>
...@@ -247,7 +253,7 @@ ...@@ -247,7 +253,7 @@
<uni-easyinput <uni-easyinput
:clearable = 'false' :clearable = 'false'
type = 'number' type = 'number'
:placeholder = 'participant.array.find(p => p.id == i.player2Id)?.name' :placeholder = 'i.player2.name'
v-model = 'match.submit.chk[match.array.findIndex(m => m === i)][1]' v-model = 'match.submit.chk[match.array.findIndex(m => m === i)][1]'
:disabled = "i.status != 'Running'" :disabled = "i.status != 'Running'"
></uni-easyinput> ></uni-easyinput>
...@@ -263,22 +269,18 @@ ...@@ -263,22 +269,18 @@
<view id = 'body'> <view id = 'body'>
<view id = 'left'> <view id = 'left'>
<span <span
:class = "{ 'winner': i.winnerId == i.player1Id }" :class = "{ 'winner': i.winnerId == i.player1.id }"
>{{ participant.array.find(p => p.id == i.player1Id)?.name }}</span> >{{ i.player1.name }}</span>
<br> <br>
<span <span v-if = 'participant.array.find(p => p.id == i.player1.id)?.score'>
v-if = '
// @ts-ignore
participant.array.find(p => p.id == i.player1Id) && participant.array.find(p => p.id == i.player1Id).score
'>
{{ {{
`${ `${
// @ts-ignore // @ts-ignore
participant.array.find(p => p.id == i.player1Id)?.score.win + participant.array.find(p => p.id == i.player1Id)?.score.bye participant.array.find(p => p.id == i.player1.id)?.score.win + participant.array.find(p => p.id == i.player1.id)?.score.bye
}-${ }-${
participant.array.find(p => p.id == i.player1Id)?.score.draw participant.array.find(p => p.id == i.player1.id)?.score.draw
}-${ }-${
participant.array.find(p => p.id == i.player1Id)?.score.lose participant.array.find(p => p.id == i.player1.id)?.score.lose
}` }`
}} }}
</span> </span>
...@@ -291,21 +293,18 @@ ...@@ -291,21 +293,18 @@
</view> </view>
<view id = 'right'> <view id = 'right'>
<span <span
:class = "{ 'winner': i.winnerId == i.player2Id }" :class = "{ 'winner': i.winnerId == i.player2.id }"
>{{ participant.array.find(p => p.id == i.player2Id)?.name }}</span> >{{ i.player2.name }}</span>
<br> <br>
<span v-if = ' <span v-if = 'participant.array.find(p => p.id == i.player2.id)?.score'>
// @ts-ignore
participant.array.find(p => p.id == i.player2Id) && participant.array.find(p => p.id == i.player2Id).score
'>
{{ {{
`${ `${
// @ts-ignore // @ts-ignore
participant.array.find(p => p.id == i.player2Id)?.score.win + participant.array.find(p => p.id == i.player2Id)?.score.bye participant.array.find(p => p.id == i.player2.id)?.score.win + participant.array.find(p => p.id == i.player2.id)?.score.bye
}-${ }-${
participant.array.find(p => p.id == i.player2Id)?.score.draw participant.array.find(p => p.id == i.player2.id)?.score.draw
}-${ }-${
participant.array.find(p => p.id == i.player2Id)?.score.lose participant.array.find(p => p.id == i.player2.id)?.score.lose
}` }`
}} }}
</span> </span>
...@@ -325,7 +324,7 @@ ...@@ -325,7 +324,7 @@
:current = 'match.page' :current = 'match.page'
v-model = 'match.page' v-model = 'match.page'
pageSize = 20 pageSize = 20
:total = '(match.round == 0) ? match.total : match.array.filter(m => m.round == match.round).length' :total = 'match.array.filter(i => searcher.filterMatch(i)).length'
> >
</uni-pagination> </uni-pagination>
</uni-card> </uni-card>
...@@ -486,11 +485,11 @@ ...@@ -486,11 +485,11 @@
if (match.round > 0 && match.round != round) continue; if (match.round > 0 && match.round != round) continue;
string += `---------------------------------------------\n第[ ${round} ]轮对决战况表\n---------------------------------------------\n` string += `---------------------------------------------\n第[ ${round} ]轮对决战况表\n---------------------------------------------\n`
match.array.filter(i => i.round == round).forEach((i, v) => { match.array.filter(i => i.round == round).forEach((i, v) => {
if (i.player1Id || i.player2Id) { if (i.player1.id || i.player2.id) {
string += `[${v + 1}]组\n`; string += `[${v + 1}]组\n`;
string += `\t[选手A][${participant.array.find(p => p.id == i.player1Id)?.name ?? ''}]\n`; string += `\t[选手A][${i.player1.name ?? ''}]\n`;
string += `\t[比 分][${i.status == 'Finished' ? `${i.player1Score} : ${i.player2Score}` : 'VS'}]\n`; string += `\t[比 分][${i.status == 'Finished' ? `${i.player1.score} : ${i.player2.score}` : 'VS'}]\n`;
string += `\t[选手B][${participant.array.find(p => p.id == i.player2Id)?.name ?? ''}]\n`; string += `\t[选手B][${i.player2.name ?? ''}]\n`;
} }
}); });
} }
...@@ -524,7 +523,7 @@ ...@@ -524,7 +523,7 @@
show : (i : Match) : void => { show : (i : Match) : void => {
match.submit.page = match.submit.page === i ? undefined : i; 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.player1.score ?? 0, i.player2.score ?? 0]);
}, },
on : async (i : Match) : Promise<void> => { on : async (i : Match) : Promise<void> => {
const v = match.array.findIndex(m => m === i); const v = match.array.findIndex(m => m === i);
...@@ -532,7 +531,7 @@ ...@@ -532,7 +531,7 @@
case 'Running': case 'Running':
const player1 : number = match.submit.chk[v][0] ?? 0; const player1 : number = match.submit.chk[v][0] ?? 0;
const player2 : number = match.submit.chk[v][1] ?? 0; const player2 : number = match.submit.chk[v][1] ?? 0;
const id : null | number = player1 > player2 ? i.player1Id : player1 == player2 ? null : i.player2Id const id : null | number = player1 > player2 ? i.player1.id : player1 == player2 ? null : i.player2.id;
// @ts-ignore // @ts-ignore
if (await Tabulator.Match.Update(Mycard.token, i.id, { if (await Tabulator.Match.Update(Mycard.token, i.id, {
player1Score : player1, player1Score : player1,
...@@ -718,13 +717,26 @@ ...@@ -718,13 +717,26 @@
element = element.parentElement; element = element.parentElement;
} }
match.submit.page = undefined; match.submit.page = undefined;
match.submit.chk = match.array.map(i => [i.player1Score ?? 0, i.player2Score ?? 0]); match.submit.chk = match.array.map(i => [i.player1.score ?? 0, i.player2.score ?? 0]);
}, },
copyUrl : () => { copyUrl : () => {
UniApp.copy(`${window.location.href.split('/?')[0]}`); UniApp.copy(`${window.location.href.split('/?')[0]}`);
} }
}); });
let searcher = reactive({
participant : '',
match : '',
filterMatch : (i : Match) : boolean => {
if ((i.round != match.round && match.round != 0) || (i.status == 'Abandoned' && !i.player1.name || !i.player2.name))
return false;
return searcher.match ? i.player1.name.toUpperCase().includes(searcher.match.toUpperCase()) || i.player2.name.toUpperCase().includes(searcher.match.toUpperCase()) : true;
},
filterParticipant : (i : Participant) : boolean => {
return searcher.participant ? i.name.toUpperCase().includes(searcher.participant.toUpperCase()) : true;
}
});
let creator = reactive({ let creator = reactive({
name : '', name : '',
avatar : '' avatar : ''
...@@ -755,7 +767,7 @@ ...@@ -755,7 +767,7 @@
}); });
watch(() => { return match.array; }, async () : Promise<void> => { watch(() => { return match.array; }, async () : Promise<void> => {
match.submit.chk = match.array.map(i => [i.player1Score ?? 0, i.player2Score ?? 0]); match.submit.chk = match.array.map(i => [i.player1.score ?? 0, i.player2.score ?? 0]);
if (match.array.length > 0) if (match.array.length > 0)
match.maxRound = match.array.reduce((a, b) => (a.round > b.round) ? a : b)?.round ?? 0; match.maxRound = match.array.reduce((a, b) => (a.round > b.round) ? a : b)?.round ?? 0;
else match.maxRound = 0; else match.maxRound = 0;
......
import { MatchObject } from './type.ts'; import { MatchObject } from './type.ts';
import Participant from './participant.ts' import Participant from './participant.ts';
interface player {
id : number;
score : number;
name : string;
}
class Match { class Match {
id : number; id : number;
...@@ -7,10 +13,8 @@ class Match { ...@@ -7,10 +13,8 @@ class Match {
round : number; round : number;
isThirdPlaceMatch : boolean; isThirdPlaceMatch : boolean;
status : string; status : string;
player1Score : number; player1 : player;
player2Score : number; player2 : player;
player1Id : number;
player2Id : number;
winnerId : number | null; winnerId : number | null;
childMatchId : number; childMatchId : number;
...@@ -20,10 +24,18 @@ class Match { ...@@ -20,10 +24,18 @@ class Match {
this.round = obj.round; this.round = obj.round;
this.isThirdPlaceMatch = obj.isThirdPlaceMatch; this.isThirdPlaceMatch = obj.isThirdPlaceMatch;
this.status = obj.status; this.status = obj.status;
this.player1Id = obj.player1Id; const name1 = obj.player1?.name.split('+') ?? [];
this.player2Id = obj.player2Id; this.player1 = {
this.player1Score = obj.player1Score; id : obj.player1Id,
this.player2Score = obj.player2Score; name : (name1.length == 2 && !Number.isNaN(name1[0]) && name1[0].length > 3) ? name1[1] : obj.player1?.name ?? '',
score : obj.player1Score
};
const name2 = obj.player2?.name.split('+') ?? [];
this.player2 = {
id : obj.player2Id,
name : (name2.length == 2 && !Number.isNaN(name2[0]) && name2[0].length > 3) ? name2[1] : obj.player2?.name ?? '',
score : obj.player2Score
};
this.winnerId = obj.winnerId as number | null; this.winnerId = obj.winnerId as number | null;
this.childMatchId = obj.childMatchId; this.childMatchId = obj.childMatchId;
} }
......
...@@ -12,7 +12,7 @@ class Participant { ...@@ -12,7 +12,7 @@ class Participant {
deck : YGOProDeck | undefined; deck : YGOProDeck | undefined;
constructor(obj: ParticipantObject) { constructor(obj: ParticipantObject) {
const name = obj.name.split('+') const name = obj.name.split('+');
this.name = (name.length == 2 && !Number.isNaN(name[0]) && name[0].length > 3) ? name[1] : obj.name; this.name = (name.length == 2 && !Number.isNaN(name[0]) && name[0].length > 3) ? name[1] : obj.name;
this.tournamentId = obj.tournamentId; this.tournamentId = obj.tournamentId;
this.id = obj.id; this.id = obj.id;
......
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