Commit 02e6308a authored by xiaoye's avatar xiaoye

fix 通过url储存id

parent 0407444e
......@@ -231,7 +231,7 @@
</uni-pagination>
</transition>
<transition name = 'switch'>
<PageTournament v-show = 'page.tournament'/>
<PageTournament v-if = 'page.tournament'/>
</transition>
</view>
</transition>
......@@ -247,10 +247,8 @@
import Mycard from '../script/mycard.ts';
import emitter from '../script/emitter.ts'
import {
selectTournament,
updateTournament ,
tournamentInfo,
tournamentExit,
tournamentReload
} from '../script/const.ts'
import PageTournament from './tournament.vue';
......@@ -276,8 +274,8 @@
page.menu = false;
await (new Promise(resolve => setTimeout(resolve, 500)));
page.tournament = true;
emitter.emit(selectTournament, search.result.tournaments[v]);
tournament.init(search.result.tournaments[v]);
const url = window.location.href.split('/?');
window.location.replace(`${url[0]}/tournament/${search.result.tournaments[v].id}/?${url[1] ?? ''}`)
},
menu : async(): Promise<void> => {
page.tournament = false;
......@@ -530,20 +528,25 @@
}
});
onBeforeMount(() => {
onBeforeMount(() : void => {
Uniapp.chkScreen(size.get);
search.on();
document.addEventListener("click", page.show.clear);
emitter.on(tournamentInfo, page.show.drawer);
emitter.on(tournamentExit, page.show.menu);
// @ts-ignore
emitter.on(tournamentReload, tournament.init);
const url = window.location.href.match(/tournament\/(\d+)[^\/]*\/\?/);
if (url && !isNaN(parseInt(url[1]))) {
page.menu = false;
page.tournament = true;
} else {
search.on();
}
});
onUnmounted(() => {
document.removeEventListener("click", page.show.clear);
emitter.off(tournamentInfo, page.show.drawer);
emitter.off(tournamentExit, page.show.menu);
// @ts-ignore
emitter.off(tournamentReload, tournament.init);
});
......
<template>
<view class = 'PageTournament'>
<uni-card
id = 'PageTournament'
:style = "page.height > 0 ? { height: `${page.height}px` } : { height: '100%' }"
v-if = 'tournament.this'
:is-full = 'true'
:title = 'tournament.this.name'
:sub-title = 'tournament.this.description'
:extra = 'tournament.this.createdAt.toLocaleDateString()'
>
<uni-forms>
<view class = 'button_list' >
<view class = 'button click' @click = 'emitter.emit(tournamentInfo)'>
<span>设置</span>
<uni-icons type = 'info'></uni-icons>
<transition name = 'switch'>
<uni-card
id = 'PageTournament'
:style = "page.height > 0 ? { height: `${page.height}px` } : { height: '100%' }"
v-if = 'tournament.this'
:is-full = 'true'
:title = 'tournament.this.name'
:sub-title = 'tournament.this.description'
:extra = 'tournament.this.createdAt.toLocaleDateString()'
>
<uni-forms>
<view class = 'button_list' >
<view class = 'button click' @click = 'emitter.emit(tournamentInfo)'>
<span>设置</span>
<uni-icons type = 'info'></uni-icons>
</view>
<view class = 'button' @click = 'page.reload()'>
<span>刷新</span>
<uni-icons type = 'reload'></uni-icons>
</view>
<view class = 'button' @click = 'page.clear()'>
<span>关闭</span>
<uni-icons type = 'close'></uni-icons>
</view>
</view>
<view class = 'button' @click = 'page.reload()'>
<span>刷新</span>
<uni-icons type = 'reload'></uni-icons>
<br>
<view class = 'button_list' >
<view class = 'button click' @click = 'tournament.on()'>
<span>{{ tournament.status.text.get(tournament.this.status) }}</span>
<uni-icons type = 'circle-filled' :color = 'tournament.status.color.get(tournament.this.status)'></uni-icons>
</view>
<view class = 'button click' @click = 'tournament.reset()'>
<span>重置</span>
<uni-icons type = 'loop'></uni-icons>
</view>
<view class = 'button click' @click = 'tournament.del()'>
<span>删除</span>
<uni-icons type = 'trash' color = 'red'></uni-icons>
</view>
</view>
<view class = 'button' @click = 'page.clear()'>
<span>关闭</span>
<uni-icons type = 'close'></uni-icons>
</view>
</view>
</uni-forms>
<br>
<view class = 'button_list' >
<view class = 'button click' @click = 'tournament.on()'>
<span>{{ tournament.status.text.get(tournament.this.status) }}</span>
<uni-icons type = 'circle-filled' :color = 'tournament.status.color.get(tournament.this.status)'></uni-icons>
</view>
<view class = 'button click' @click = 'tournament.reset()'>
<span>重置</span>
<uni-icons type = 'loop'></uni-icons>
</view>
<view class = 'button click' @click = 'tournament.del()'>
<span>删除</span>
<uni-icons type = 'trash' color = 'red'></uni-icons>
</view>
</view>
</uni-forms>
<br>
<transition name = 'switch'>
<uni-card
v-show = '!page.loading'
:is-full = 'true'
title = '参与者'
>
<transition name = 'switch'>
<uni-list>
<uni-list-item
v-show = 'participant.array.length == 0'
title = '暂无选手'
>
</uni-list-item>
<uni-list-item
v-for = '(i, v) in participant.array'
:note = "i.score ? i.score.rank : ''"
:title = "i.score ? `${i.score.score}\n${i.score.win + i.score.bye}-${i.score.draw}-${i.score.lose}` : ''"
:clickable = true
>
<template v-slot:header>
<view id = 'header'>
<span>{{ i.name }}</span>
<br>
<span class = 'rank'>{{ i.score ? i.score.rank : '' }}</span>
</view>
</template>
<template v-slot:footer>
<view id = 'footer'>
<view
class = 'button'
:style = "{ '--color' : 'red' }"
@click = 'participant.del(v)'
v-show = '!i.quit'
>
<uni-icons type = 'trash' color = 'red'></uni-icons>
</view>
<span v-show = 'i.quit'>已退赛</span>
</view>
</template>
</uni-list-item>
<uni-list-item>
<template v-slot:header>
<uni-forms>
<uni-forms-item id = 'header'>
<uni-easyinput type = 'text' placeholder = '添加选手' v-model = 'participant.name' :disabled = "tournament.this.status != 'Ready'"/>
</uni-forms-item>
</uni-forms>
</template>
<template v-slot:footer>
<view id = 'footer'>
<view
class = 'button'
:style = "{ '--color' : '#409eff' }"
@click = 'participant.add()'
>
<uni-icons type = 'personadd'></uni-icons>
</view>
</view>
</template>
</uni-list-item>
</uni-list>
</transition>
<uni-pagination
:current = 'participant.page'
v-model = 'participant.page'
pageSize = 20
:total = 'participant.total'
<transition name = 'switch'>
<uni-card
v-show = '!page.loading'
:is-full = 'true'
title = '参与者'
>
</uni-pagination>
</uni-card>
</transition>
<transition name = 'switch'>
<uni-card
v-show = '!page.loading'
:is-full = 'true'
title = '比赛'
>
<transition name = 'switch'>
<uni-list>
<uni-list-item
v-show = 'match.array.length == 0'
title = '暂无比赛'
>
</uni-list-item>
<uni-list-item
v-for = '(i, v) in match.array'
:clickable = true
>
<template v-slot:header>
</template>
<template v-slot:body>
<view id = 'body'>
<view id = 'left'>
{{ participant.array.find(p => p.id == i.player1Id)?.name }}
<transition name = 'switch'>
<uni-list>
<uni-list-item
v-show = 'participant.array.length == 0'
title = '暂无选手'
>
</uni-list-item>
<uni-list-item
v-for = '(i, v) in participant.array'
:note = "i.score ? i.score.rank : ''"
:title = "i.score ? `${i.score.score}\n${i.score.win + i.score.bye}-${i.score.draw}-${i.score.lose}` : ''"
:clickable = true
>
<template v-slot:header>
<view id = 'header'>
<span>{{ i.name }}</span>
<br>
<span
v-if = '
// @ts-ignore
participant.array.find(p => p.id == i.player1Id) && participant.array.find(p => p.id == i.player1Id).score
'>
{{
`${
// @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.player1Id)?.score.draw
}-${
participant.array.find(p => p.id == i.player1Id)?.score.lose
}`
}}
</span>
<span class = 'rank'>{{ i.score ? i.score.rank : '' }}</span>
</view>
<view id = 'center'>
{{ `第${i.round}轮` }}
</template>
<template v-slot:footer>
<view id = 'footer'>
<view
class = 'button'
:style = "{ '--color' : 'red' }"
@click = 'participant.del(v)'
v-show = '!i.quit'
>
<uni-icons type = 'trash' color = 'red'></uni-icons>
</view>
<span v-show = 'i.quit'>已退赛</span>
</view>
<view id = 'right'>
{{ participant.array.find(p => p.id == i.player2Id)?.name }}
<br>
<span v-if = '
// @ts-ignore
participant.array.find(p => p.id == i.player2Id) && participant.array.find(p => p.id == i.player2Id).score
'>
{{
`${
// @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.player2Id)?.score.draw
}-${
participant.array.find(p => p.id == i.player2Id)?.score.lose
}`
}}
</span>
</template>
</uni-list-item>
<uni-list-item>
<template v-slot:header>
<uni-forms>
<uni-forms-item id = 'header'>
<uni-easyinput type = 'text' placeholder = '添加选手' v-model = 'participant.name' :disabled = "tournament.this.status != 'Ready'"/>
</uni-forms-item>
</uni-forms>
</template>
<template v-slot:footer>
<view id = 'footer'>
<view
class = 'button'
:style = "{ '--color' : '#409eff' }"
@click = 'participant.add()'
>
<uni-icons type = 'personadd'></uni-icons>
</view>
</view>
</view>
</template>
<template v-slot:footer>
</template>
</uni-list-item>
</uni-list>
</transition>
<uni-pagination
:current = 'match.page'
v-model = 'match.page'
pageSize = 20
:total = 'match.total'
</template>
</uni-list-item>
</uni-list>
</transition>
<uni-pagination
:current = 'participant.page'
v-model = 'participant.page'
pageSize = 20
:total = 'participant.total'
>
</uni-pagination>
</uni-card>
</transition>
<transition name = 'switch'>
<uni-card
v-show = '!page.loading'
:is-full = 'true'
title = '比赛'
>
</uni-pagination>
</uni-card>
</transition>
</uni-card>
<transition name = 'switch'>
<uni-list>
<uni-list-item
v-show = 'match.array.length == 0'
title = '暂无比赛'
>
</uni-list-item>
<uni-list-item
v-for = '(i, v) in match.array'
:clickable = true
>
<template v-slot:header>
</template>
<template v-slot:body>
<view id = 'body'>
<view id = 'left'>
{{ participant.array.find(p => p.id == i.player1Id)?.name }}
<br>
<span
v-if = '
// @ts-ignore
participant.array.find(p => p.id == i.player1Id) && participant.array.find(p => p.id == i.player1Id).score
'>
{{
`${
// @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.player1Id)?.score.draw
}-${
participant.array.find(p => p.id == i.player1Id)?.score.lose
}`
}}
</span>
</view>
<view id = 'center'>
{{ `第${i.round}轮` }}
</view>
<view id = 'right'>
{{ participant.array.find(p => p.id == i.player2Id)?.name }}
<br>
<span v-if = '
// @ts-ignore
participant.array.find(p => p.id == i.player2Id) && participant.array.find(p => p.id == i.player2Id).score
'>
{{
`${
// @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.player2Id)?.score.draw
}-${
participant.array.find(p => p.id == i.player2Id)?.score.lose
}`
}}
</span>
</view>
</view>
</template>
<template v-slot:footer>
</template>
</uni-list-item>
</uni-list>
</transition>
<uni-pagination
:current = 'match.page'
v-model = 'match.page'
pageSize = 20
:total = 'match.total'
>
</uni-pagination>
</uni-card>
</transition>
</uni-card>
</transition>
</view>
</template>
<script setup lang = 'ts'>
......@@ -202,10 +204,8 @@
import Participant from '../script/participant.ts';
import Match from '../script/match.ts';
import {
selectTournament,
updateTournament ,
tournamentInfo,
tournamentExit,
tournamentReload
} from '../script/const.ts'
import Mycard from '../script/mycard.ts';
......@@ -328,26 +328,28 @@
let page = reactive({
height : 0,
loading : false,
clear : async() : Promise<void> => {
emitter.emit(tournamentExit);
await (new Promise(resolve => setTimeout(resolve, 500)));
participant.array = [];
participant.total = 0;
participant.page = 1;
match.array = [];
match.total = 0;
match.page = 1;
tournament.this = undefined;
participant.name = '';
clear : async () : Promise<void>=> {
const url = window.location.href.match(/(\/tournament\/[^\/]+)(?=\/\?)/);
if (url) {
tournament.this = undefined;
await (new Promise(resolve => setTimeout(resolve, 450)));
window.location.replace(window.location.href.replace(url[1], ''));
}
},
get : async (t : Tournament) : Promise<void> => {
tournament.this = t;
const participants : AllParticipant = await Tabulator.Participant.FindALL(Mycard.token, {tournamentId : t.id});
participant.array = participants.participants;
participant.total = participants.total;
const matchs = await Tabulator.Match.FindALL(Mycard.token, {tournamentId : t.id, statusIn : 'Running,Finished'});
match.array = matchs.matchs;
match.total = matchs.total;
get : async (id : number) : Promise<void> => {
const t = await Tabulator.Tournament.Find(Mycard.token, id);
if (t) {
tournament.this = t;
emitter.emit(tournamentReload, t)
const participants : AllParticipant = await Tabulator.Participant.FindALL(Mycard.token, {tournamentId : t.id});
participant.array = participants.participants;
participant.total = participants.total;
const matchs = await Tabulator.Match.FindALL(Mycard.token, {tournamentId : t.id, statusIn : 'Running,Finished'});
match.array = matchs.matchs;
match.total = matchs.total;
} else {
page.clear();
}
},
reload : async () : Promise<void> => {
const query = uni.createSelectorQuery().in(this);
......@@ -375,17 +377,15 @@
});
onBeforeMount(() => {
// @ts-ignore
emitter.on(selectTournament, page.get);
const url = window.location.href.match(/tournament\/(\d+)[^\/]*\/\?/);
url && !isNaN(parseInt(url[1])) ? page.get(parseInt(url[1])) : page.clear();
// @ts-ignore
emitter.on(updateTournament, participant.update);
});
onUnmounted(() => {
// @ts-ignore
emitter.off(selectTournament, page.get);
// @ts-ignore
emitter.off(selectTournament, participant.update);
emitter.off(updateTournament, participant.update);
});
</script>
......
......@@ -6,9 +6,7 @@ const tournamentExit = 'tournamentExit';
const tournamentReload = 'tournamentReload'
export {
selectTournament,
updateTournament ,
tournamentInfo,
tournamentExit,
tournamentReload
};
\ 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