Commit 02e6308a authored by xiaoye's avatar xiaoye

fix 通过url储存id

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