Commit 1a4c30bf authored by xiaoye's avatar xiaoye

fix

parent a52713da
Pipeline #37789 passed with stages
in 3 minutes and 14 seconds
...@@ -24,6 +24,23 @@ ...@@ -24,6 +24,23 @@
<checkbox :checked = 'create.rule.settings.hasThirdPlaceMatch'/>季军赛 <checkbox :checked = 'create.rule.settings.hasThirdPlaceMatch'/>季军赛
</label> </label>
</checkbox-group> </checkbox-group>
<checkbox-group @change = 'create.import.select'>
<label>
<checkbox :checked = 'create.import.chk'/>是否继承瑞士轮
</label>
</checkbox-group>
<uni-easyinput
type = 'number'
placeholder = '瑞士轮比赛id'
v-show = 'create.import.chk'
v-model = 'create.import.id'
/>
<uni-easyinput
type = 'number'
placeholder = '出轮人数'
v-show = 'create.import.chk'
v-model = 'create.import.count'
/>
</view> </view>
<br> <br>
<uni-card <uni-card
...@@ -70,6 +87,12 @@ ...@@ -70,6 +87,12 @@
</uni-list> </uni-list>
</uni-card> </uni-card>
<br> <br>
<view class = 'button' @click = 'create.clear()'>
<view>
<span>清空</span>
<uni-icons type = 'trash'></uni-icons>
</view>
</view>
<view class = 'button' @click = 'create.update()'> <view class = 'button' @click = 'create.update()'>
<view> <view>
<span>创建</span> <span>创建</span>
...@@ -85,6 +108,8 @@ ...@@ -85,6 +108,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 Const from '../../script/const.ts' import Const from '../../script/const.ts'
import Tournament from '../../script/tournament.ts';
import UniApp from '../../script/uniapp.ts';
let create = reactive({ let create = reactive({
name : '', name : '',
...@@ -102,7 +127,7 @@ ...@@ -102,7 +127,7 @@
settings : { settings : {
winScore : 3, winScore : 3,
drawScore : 1, drawScore : 1,
byeScore : 0, byeScore : 3,
hasThirdPlaceMatch : true hasThirdPlaceMatch : true
} as ruleSettings, } as ruleSettings,
range : [ range : [
...@@ -112,7 +137,15 @@ ...@@ -112,7 +137,15 @@
}, },
hasThirdPlaceMatch : { hasThirdPlaceMatch : {
select : (e) => { select : (e) => {
create.rule.settings.hasThirdPlaceMatch = e.detail.value.length > 0 create.rule.settings.hasThirdPlaceMatch = e.detail.value.length > 0;
}
},
import : {
chk : false,
id : undefined as undefined | number,
count : undefined as undefined | number,
select : (e) => {
create.import.chk = e.detail.value.length > 0;
} }
}, },
collaborator : '', collaborator : '',
...@@ -125,27 +158,44 @@ ...@@ -125,27 +158,44 @@
create.rule.settings = { create.rule.settings = {
winScore : 3, winScore : 3,
drawScore : 1, drawScore : 1,
byeScore : 0, byeScore : 3,
hasThirdPlaceMatch : true hasThirdPlaceMatch : true
} as ruleSettings; } as ruleSettings;
create.collaborators = []; create.collaborators = [];
create.import.chk = false;
}, },
update : async() : Promise<void> => { update : async() : Promise<void> => {
if (!create.visibility.select) try {
// @ts-ignore if (!create.visibility.select)
create.visibility.select = 'SingleElimination'; // @ts-ignore
const collaborators = create.collaborators.map(user => user.id); create.visibility.select = 'SingleElimination';
if (await Tabulator.Tournament.Create(Mycard.token, { if (create.import.chk) {
if (!create.import.id || create.import.id <= 0)
throw new Error('请填写继承的比赛id');
if (!create.import.count || create.import.count <= 0)
throw new Error('请填写出轮的人数');
const n = Math.log2(create.import.count);
if (n > 0 && !Number.isInteger(n) || n <= 0)
throw new Error('出轮的人数必须是2的幂');
}
const collaborators = create.collaborators.map(user => user.id);
const id = await Tabulator.Tournament.Create(Mycard.token, {
name: create.name, name: create.name,
description: create.description, description: create.description,
rule: create.rule.select, rule: create.rule.select,
ruleSettings: create.rule.settings, ruleSettings: create.rule.settings,
visibility: create.visibility.select, visibility: create.visibility.select,
collaborators: collaborators collaborators: collaborators
}) });
) { if (id >= 0) {
emitter.emit(Const.createOff); if (create.import.chk)
create.clear(); // @ts-ignore
await Tabulator.Tournament.Import(Mycard.token, id, create.import.id, create.import.count);
emitter.emit(Const.createOff, id);
create.clear();
}
} catch (error) {
UniApp.error(error.message, '创建失败');
} }
}, },
remove : (v : number) : void => { remove : (v : number) : void => {
...@@ -162,14 +212,43 @@ ...@@ -162,14 +212,43 @@
throw new Error('协作者不可以是比赛创建者'); throw new Error('协作者不可以是比赛创建者');
create.collaborators.push(i); create.collaborators.push(i);
} catch(error) { } catch(error) {
uni.showModal({ UniApp.error(error.message, '添加失败');
title : '添加失败',
content : error.message,
showCancel : false
});
} finally { } finally {
create.collaborator = ''; create.collaborator = '';
} }
},
fromSwiss : (t : Tournament) : void => {
create.collaborators = [];
t.collaborators.forEach(async id => {
const i = await User.Find.Id(id);
if (i)
create.collaborators.push(i);
});
create.rule.select = 'SingleElimination'
create.visibility.select = 'SingleElimination';
create.visibility.select = t.visibility;
create.import.chk = true;
create.import.id = t.id;
create.name = t.name;
create.description = t.description;
} }
}); });
onBeforeMount(() => {
// @ts-ignore
emitter.on(Const.newTournament, create.fromSwiss);
});
onUnmounted(() => {
// @ts-ignore
emitter.off(Const.newTournament, create.fromSwiss);
});
watch(() => { return create.import.chk; }, () => {
if (!create.import.chk) {
create.import.id = undefined;
create.import.count = undefined;
}
})
</script> </script>
\ No newline at end of file
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<script setup lang = 'ts'> <script setup lang = 'ts'>
import { defineProps, onBeforeMount, reactive, watch } from 'vue'; import { defineProps, onBeforeMount, reactive, watch } from 'vue';
import Match from '../script/match'; import Match from '../script/match';
import Uniapp from '../script/uniapp.ts'; import UniApp from '../script/uniapp.ts';
import Participant from '../script/participant'; import Participant from '../script/participant';
import Bracket from "vue-tournament-bracket"; import Bracket from "vue-tournament-bracket";
...@@ -56,7 +56,7 @@ ...@@ -56,7 +56,7 @@
}> = reactive([]); }> = reactive([]);
onBeforeMount(() : void => { onBeforeMount(() : void => {
Uniapp.chkScreen(size.get); UniApp.chkScreen(size.get);
}); });
watch(() => { return props.matches; }, () => { watch(() => { return props.matches; }, () => {
......
...@@ -121,7 +121,7 @@ ...@@ -121,7 +121,7 @@
:note = 'search.rule.note.get(i.rule)' :note = 'search.rule.note.get(i.rule)'
:rightText = '`${i.createdAt.toLocaleDateString()}\n${i.count}`' :rightText = '`${i.createdAt.toLocaleDateString()}\n${i.count}`'
:clickable = true :clickable = true
@click = 'page.show.tournament(v)' @click = 'page.show.tournament(i.id)'
></uni-list-item> ></uni-list-item>
</uni-list> </uni-list>
</transition> </transition>
...@@ -146,7 +146,7 @@ ...@@ -146,7 +146,7 @@
<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 { TournamentFindObject, TournamentCreateObject, ruleSettings, UserObject } from '../script/type.ts'; import { TournamentFindObject, TournamentCreateObject, ruleSettings, UserObject } from '../script/type.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';
import Tournament from '../script/tournament.ts'; import Tournament from '../script/tournament.ts';
import Mycard from '../script/mycard.ts'; import Mycard from '../script/mycard.ts';
...@@ -179,9 +179,10 @@ ...@@ -179,9 +179,10 @@
if (!page.drawer && page.tournament) if (!page.drawer && page.tournament)
tournament.init(tournament.this as Tournament); tournament.init(tournament.this as Tournament);
}, },
tournament : (v : number = 0): void => { tournament : (id : number = 0): void => {
const url = window.location.href.split('/?'); const url = window.location.href.split('/?');
emitter.emit(Const.changeUrl, `${url[0].endsWith('/') ? url[0] : `${url[0]}/`}${search.result.tournaments[v].id}${url[1] ? `/?${url[1]}` : ''}`); const hash = url[0].replace(/\/#\/\d+\/?/, '/#');
emitter.emit(Const.changeUrl, `${hash.endsWith('/') ? hash : `${hash}/`}${id}${url[1] ? `/?${url[1]}` : ''}`);
}, },
menu : async(): Promise<void> => { menu : async(): Promise<void> => {
page.tournament = false; page.tournament = false;
...@@ -212,7 +213,7 @@ ...@@ -212,7 +213,7 @@
let inPage = false; let inPage = false;
let uniElement = false; let uniElement = false;
while (element) { while (element) {
if (['head', 'user', 'drawer'].includes(element.id) || element.classList.contains('click')) if (['head', 'user', 'drawer', 'newTournament'].includes(element.id) || element.classList.contains('click'))
chk = true; chk = true;
if (element.id == 'page') if (element.id == 'page')
inPage = true; inPage = true;
...@@ -356,9 +357,8 @@ ...@@ -356,9 +357,8 @@
description: tournament.description, description: tournament.description,
visibility: tournament.visibility.select, visibility: tournament.visibility.select,
collaborators : collaborators, collaborators : collaborators,
// PS:这里接口暂时不通 rule : tournament.this?.status == 'Ready' ? tournament.rule.select : undefined,
// rule : tournament.rule.select, ruleSettings : tournament.this?.status == 'Ready' ? tournament.rule.settings : undefined
// ruleSettings : tournament.rule.settings
} as TournamentCreateObject); } as TournamentCreateObject);
}, },
remove : (v : number) : void => { remove : (v : number) : void => {
...@@ -375,11 +375,7 @@ ...@@ -375,11 +375,7 @@
throw new Error('协作者不可以是比赛创建者'); throw new Error('协作者不可以是比赛创建者');
tournament.collaborators.push(i); tournament.collaborators.push(i);
} catch(error) { } catch(error) {
uni.showModal({ UniApp.error(error.message, '添加失败');
title : '添加失败',
content : error.message,
showCancel : false
});
} finally { } finally {
tournament.collaborator = ''; tournament.collaborator = '';
} }
...@@ -392,12 +388,15 @@ ...@@ -392,12 +388,15 @@
}); });
const creator = { const creator = {
off : async () : Promise<void> => { off : async (id : number) : Promise<void> => {
console.log(page.tournament)
page.show.drawer(); page.show.drawer();
if (page.tournament) if (page.tournament)
page.show.menu(); page.show.tournament(id);
search.mine(); else {
await search.on(); search.mine();
await search.on();
}
} }
}; };
...@@ -438,9 +437,10 @@ ...@@ -438,9 +437,10 @@
onBeforeMount(() : void => { onBeforeMount(() : void => {
loading(); loading();
Uniapp.chkScreen(size.get); UniApp.chkScreen(size.get);
document.addEventListener("click", page.show.clear); document.addEventListener("click", page.show.clear);
emitter.on(Const.tournamentInfo, page.show.drawer); emitter.on(Const.tournamentInfo, page.show.drawer);
emitter.on(Const.newTournament, page.show.create);
// @ts-ignore // @ts-ignore
emitter.on(Const.tournamentReload, tournament.init); emitter.on(Const.tournamentReload, tournament.init);
// @ts-ignore // @ts-ignore
...@@ -457,6 +457,7 @@ ...@@ -457,6 +457,7 @@
onUnmounted(() => { onUnmounted(() => {
document.removeEventListener("click", page.show.clear); document.removeEventListener("click", page.show.clear);
emitter.off(Const.tournamentInfo, page.show.drawer); emitter.off(Const.tournamentInfo, page.show.drawer);
emitter.off(Const.newTournament, page.show.create);
// @ts-ignore // @ts-ignore
emitter.off(Const.tournamentReload, tournament.init); emitter.off(Const.tournamentReload, tournament.init);
// @ts-ignore // @ts-ignore
......
...@@ -70,6 +70,14 @@ ...@@ -70,6 +70,14 @@
:is-full = 'true' :is-full = 'true'
:title = '`参与者:${participant.total}`' :title = '`参与者:${participant.total}`'
> >
<view
class = 'button'
id = 'newTournament'
@click = 'tournament.new()'
v-show = "tournament.this.rule == 'Swiss' && tournament.this.status == 'Finished'"
>
新建单淘赛
</view>
<transition name = 'switch'> <transition name = 'switch'>
<uni-list> <uni-list>
<uni-list-item <uni-list-item
...@@ -80,7 +88,7 @@ ...@@ -80,7 +88,7 @@
<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.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.player1Id == i.id || m.player2Id == 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}` : ''" :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}` : ''"
:clickable = true :clickable = true
> >
<template v-slot:header> <template v-slot:header>
...@@ -424,11 +432,7 @@ ...@@ -424,11 +432,7 @@
if (Mycard.id >= 0 && (Mycard.id == tournament.this?.creator || tournament.this?.collaborators.includes(Mycard.id))) if (Mycard.id >= 0 && (Mycard.id == tournament.this?.creator || tournament.this?.collaborators.includes(Mycard.id)))
f(...para); f(...para);
else else
uni.showModal({ UniApp.error('请先登陆或联系比赛主办方', '缺少权限');
title : '缺少权限',
content : '请先登陆或联系比赛主办方',
showCancel : false
});
}, },
upload : async () : Promise<void> => { upload : async () : Promise<void> => {
const f = async (res : UniApp.ChooseFileSuccessCallbackResult) : Promise<void> => { const f = async (res : UniApp.ChooseFileSuccessCallbackResult) : Promise<void> => {
...@@ -465,6 +469,10 @@ ...@@ -465,6 +469,10 @@
} }
string += '---------------------------------------------'; string += '---------------------------------------------';
UniApp.copy(string); UniApp.copy(string);
},
new : () : void => {
if (!tournament.this) return;
emitter.emit(Const.newTournament, tournament.this);
} }
}); });
...@@ -638,16 +646,14 @@ ...@@ -638,16 +646,14 @@
page.loading = true; page.loading = true;
participant.name = ''; participant.name = '';
if (await tournament.search()) { if (await tournament.search()) {
match.round = 0; if (match.round > match.maxRound)
match.round = match.maxRound;
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;
} else } else
uni.showModal({ UniApp.error('请重试或检查网络设置', '刷新失败');
title : '刷新失败',
content : '请重试或检查网络设置',
showCancel : false
});
}, },
clickClear : (e) : void => { clickClear : (e) : void => {
......
...@@ -11,6 +11,7 @@ class ConstData { ...@@ -11,6 +11,7 @@ class ConstData {
show = 'show'; show = 'show';
showTournament = 'showTournament'; showTournament = 'showTournament';
updateRounds = 'updateRounds'; updateRounds = 'updateRounds';
newTournament = 'newTournament';
pic = { pic = {
hajimi : ` hajimi : `
<pre> :==+++=-. <pre> :==+++=-.
......
...@@ -51,11 +51,7 @@ class TabulatorAPI { ...@@ -51,11 +51,7 @@ class TabulatorAPI {
return response.data.data.id; return response.data.data.id;
} }
catch(error) { catch(error) {
uni.showModal({ UniApp.error(error.message, '创建失败');
title : '创建失败',
content : error.message,
showCancel : false
});
console.error(error); console.error(error);
return -1; return -1;
} }
...@@ -99,6 +95,11 @@ class TabulatorAPI { ...@@ -99,6 +95,11 @@ class TabulatorAPI {
response.data.data.matches.forEach((i : MatchObject) => { response.data.data.matches.forEach((i : MatchObject) => {
matches.push(new Match(i)); matches.push(new Match(i));
}); });
if (response.data.data.status != 'Ready')
participants.sort((a, b) => {
const ct = b.score.score - a.score.score;
return ct != 0 ? ct : b.score.tieBreaker - a.score.tieBreaker;
});
return { return {
tournament : new Tournament(response.data.data), tournament : new Tournament(response.data.data),
participant : { participant : {
...@@ -310,6 +311,28 @@ class TabulatorAPI { ...@@ -310,6 +311,28 @@ class TabulatorAPI {
console.error(error); console.error(error);
return false; return false;
} }
},
Import : async (token : string, id : number, fromId : number, count : number) : Promise<boolean> => {
let response : {
data : {
success : boolean;
}
};
try {
response = await this.url.post(`/api/tournament/${id}/import-participants-from`, {
tournamentId : fromId,
swissMaxPlayers : count
}, {
headers : {
'x-user-token' : token
}
});
return response.data.success;
}
catch(error) {
console.error(error);
return false;
}
} }
} }
Participant = { Participant = {
...@@ -559,11 +582,7 @@ class TabulatorAPI { ...@@ -559,11 +582,7 @@ class TabulatorAPI {
return response.data.success; return response.data.success;
} }
catch(error) { catch(error) {
uni.showModal({ UniApp.error(error.message, '创建失败');
title : '创建失败',
content : error.message,
showCancel : false
});
console.error(error); console.error(error);
return false; return false;
} }
......
...@@ -85,6 +85,14 @@ class UniappFuncs { ...@@ -85,6 +85,14 @@ class UniappFuncs {
} }
}); });
} }
error (content : string, title : string) : void {
uni.showModal({
title : title,
content : content,
showCancel : false
});
}
} }
const UniApp = new UniappFuncs() const UniApp = new UniappFuncs()
......
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