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'>
<transition name = 'switch'>
<uni-card <uni-card
id = 'PageTournament' id = 'PageTournament'
:style = "page.height > 0 ? { height: `${page.height}px` } : { height: '100%' }" :style = "page.height > 0 ? { height: `${page.height}px` } : { height: '100%' }"
...@@ -192,6 +193,7 @@ ...@@ -192,6 +193,7 @@
</uni-card> </uni-card>
</transition> </transition>
</uni-card> </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 = [];
participant.total = 0;
participant.page = 1;
match.array = [];
match.total = 0;
match.page = 1;
tournament.this = undefined; tournament.this = undefined;
participant.name = ''; await (new Promise(resolve => setTimeout(resolve, 450)));
window.location.replace(window.location.href.replace(url[1], ''));
}
}, },
get : async (t : Tournament) : Promise<void> => { get : async (id : number) : Promise<void> => {
const t = await Tabulator.Tournament.Find(Mycard.token, id);
if (t) {
tournament.this = t; tournament.this = t;
emitter.emit(tournamentReload, t)
const participants : AllParticipant = await Tabulator.Participant.FindALL(Mycard.token, {tournamentId : t.id}); const participants : AllParticipant = await Tabulator.Participant.FindALL(Mycard.token, {tournamentId : t.id});
participant.array = participants.participants; participant.array = participants.participants;
participant.total = participants.total; participant.total = participants.total;
const matchs = await Tabulator.Match.FindALL(Mycard.token, {tournamentId : t.id, statusIn : 'Running,Finished'}); const matchs = await Tabulator.Match.FindALL(Mycard.token, {tournamentId : t.id, statusIn : 'Running,Finished'});
match.array = matchs.matchs; match.array = matchs.matchs;
match.total = matchs.total; 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