Commit faf8744b authored by xiaoye's avatar xiaoye

fix

parent 60fa8bc0
...@@ -39,6 +39,12 @@ ...@@ -39,6 +39,12 @@
class = 'user' class = 'user'
><span>获取api_key</span></view> ><span>获取api_key</span></view>
<hr v-show = 'Mycard.id >= 0'> <hr v-show = 'Mycard.id >= 0'>
<view
v-show = 'Mycard.id >= 0'
class = 'user'
@click = 'page.show.create()'
><span>新建比赛</span></view>
<hr v-show = 'Mycard.id >= 0'>
<view <view
class = 'user' class = 'user'
@click = '() => { @click = '() => {
...@@ -51,29 +57,35 @@ ...@@ -51,29 +57,35 @@
<uni-card <uni-card
class = 'click' class = 'click'
id = 'drawer' id = 'drawer'
v-show = 'page.drawer && page.menu' v-show = 'page.drawer && page.menu && !page.create'
title = '搜索' title = '搜索'
:style = "{ '--size' : `${size.width > size.height ? size.width / 4 : size.width / 2}px` }" :style = "{ '--size' : `${size.width > size.height ? size.width / 4 : size.width / 2}px` }"
> >
<uni-datetime-picker type = 'daterange' v-model = 'search.date'/> <uni-datetime-picker type = 'daterange' v-model = 'search.date'/>
<uni-search-bar <uni-easyinput
prefixIcon = 'search'
type = 'number'
placeholder = '组织者id' placeholder = '组织者id'
cancelButton = 'none' cancelButton = 'none'
v-model = 'search.creator' v-model = 'search.creator'
> ></uni-easyinput>
</uni-search-bar> <view class = 'button' @click = 'search.mine()'>
<uni-search-bar 我组织的比赛
</view>
<uni-easyinput
prefixIcon = 'search'
type = 'text'
placeholder = '比赛名称' placeholder = '比赛名称'
cancelButton = 'none' cancelButton = 'none'
v-model = 'search.info.name' v-model = 'search.info.name'
> ></uni-easyinput>
</uni-search-bar> <uni-easyinput
<uni-search-bar prefixIcon = 'search'
type = 'number'
placeholder = '比赛id' placeholder = '比赛id'
cancelButton = 'none' cancelButton = 'none'
v-model = 'search.id' v-model = 'search.id'
> ></uni-easyinput>
</uni-search-bar>
<uni-data-select <uni-data-select
placeholder = '比赛规则' placeholder = '比赛规则'
v-model = 'search.info.rule' v-model = 'search.info.rule'
...@@ -106,7 +118,7 @@ ...@@ -106,7 +118,7 @@
<uni-card <uni-card
class = 'click' class = 'click'
id = 'drawer' id = 'drawer'
v-show = 'page.drawer && page.tournament' v-show = 'page.drawer && page.tournament && !page.create'
title = '比赛设置' title = '比赛设置'
:style = "{ '--size' : `${size.width > size.height ? size.width / 4 : size.width / 2}px` }" :style = "{ '--size' : `${size.width > size.height ? size.width / 4 : size.width / 2}px` }"
> >
...@@ -121,17 +133,18 @@ ...@@ -121,17 +133,18 @@
placeholder = '规则' placeholder = '规则'
v-model = 'tournament.rule.select' v-model = 'tournament.rule.select'
:localdata = 'tournament.rule.range' :localdata = 'tournament.rule.range'
:disabled = "tournament.this?.status != 'Ready'"
></uni-data-select> ></uni-data-select>
<view v-show = "tournament.rule.select == 'Swiss'"> <view v-show = "tournament.rule.select == 'Swiss'">
<uni-easyinput type = 'number' placeholder = '轮数' v-model = 'tournament.rule.settings.rounds'/> <uni-easyinput type = 'number' placeholder = '轮数' v-model = 'tournament.rule.settings.rounds' :disabled = "tournament.this?.status != 'Ready'"/>
<uni-easyinput type = 'number' placeholder = '胜利分' v-model = 'tournament.rule.settings.winScore'/> <uni-easyinput type = 'number' placeholder = '胜利分' v-model = 'tournament.rule.settings.winScore' :disabled = "tournament.this?.status != 'Ready'"/>
<uni-easyinput type = 'number' placeholder = '平局分' v-model = 'tournament.rule.settings.drawScore'/> <uni-easyinput type = 'number' placeholder = '平局分' v-model = 'tournament.rule.settings.drawScore' :disabled = "tournament.this?.status != 'Ready'"/>
<uni-easyinput type = 'number' placeholder = '轮空分' v-model = 'tournament.rule.settings.byeScore'/> <uni-easyinput type = 'number' placeholder = '轮空分' v-model = 'tournament.rule.settings.byeScore' :disabled = "tournament.this?.status != 'Ready'"/>
</view> </view>
<view v-show = "tournament.rule.select == 'SingleElimination'"> <view v-show = "tournament.rule.select == 'SingleElimination'">
<checkbox-group @change = 'tournament.hasThirdPlaceMatch.select'> <checkbox-group @change = 'tournament.hasThirdPlaceMatch.select'>
<label> <label>
<checkbox :checked = 'tournament.rule.settings.hasThirdPlaceMatch'/>季军赛 <checkbox :checked = 'tournament.rule.settings.hasThirdPlaceMatch' :disabled = "tournament.this?.status != 'Ready'"/>季军赛
</label> </label>
</checkbox-group> </checkbox-group>
</view> </view>
...@@ -139,7 +152,49 @@ ...@@ -139,7 +152,49 @@
<view class = 'button' @click = 'tournament.update()'> <view class = 'button' @click = 'tournament.update()'>
<view> <view>
<span>设置</span> <span>设置</span>
<uni-icons type = 'search'></uni-icons> <uni-icons type = 'calendar'></uni-icons>
</view>
</view>
</uni-card>
</transition>
<transition name = 'move_left'>
<uni-card
class = 'click'
id = 'drawer'
v-show = 'page.drawer && page.create'
title = '比赛创建'
:style = "{ '--size' : `${size.width > size.height ? size.width / 4 : size.width / 2}px` }"
>
<uni-easyinput type = 'text' placeholder = '比赛名称' v-model = 'create.name'/>
<uni-easyinput type = 'text' placeholder = '比赛描述' v-model = 'create.description'/>
<uni-data-select
placeholder = '可见性'
v-model = 'create.visibility.select'
:localdata = 'tournament.visibility.range'
></uni-data-select>
<uni-data-select
placeholder = '规则'
v-model = 'create.rule.select'
:localdata = 'tournament.rule.range'
></uni-data-select>
<view v-show = "create.rule.select == 'Swiss'">
<!-- <uni-easyinput type = 'number' placeholder = '轮数' v-model = 'create.rule.settings.rounds'/> -->
<uni-easyinput type = 'number' placeholder = '胜利分' v-model = 'create.rule.settings.winScore'/>
<uni-easyinput type = 'number' placeholder = '平局分' v-model = 'create.rule.settings.drawScore'/>
<uni-easyinput type = 'number' placeholder = '轮空分' v-model = 'create.rule.settings.byeScore'/>
</view>
<view v-show = "create.rule.select == 'SingleElimination'">
<checkbox-group @change = 'create.hasThirdPlaceMatch.select'>
<label>
<checkbox :checked = 'create.rule.settings.hasThirdPlaceMatch'/>季军赛
</label>
</checkbox-group>
</view>
<br>
<view class = 'button' @click = 'create.update()'>
<view>
<span>创建</span>
<uni-icons type = 'calendar'></uni-icons>
</view> </view>
</view> </view>
</uni-card> </uni-card>
...@@ -184,7 +239,7 @@ ...@@ -184,7 +239,7 @@
</template> </template>
<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, TournamentUpdateObject, ruleSettings } from '../script/type.ts'; import { TournamentFindObject, TournamentCreateObject, ruleSettings } from '../script/type.ts';
import Uniapp from '../script/uniapp.ts'; import Uniapp from '../script/uniapp.ts';
import Tabulator from '../script/post.ts'; import Tabulator from '../script/post.ts';
import Tournament from '../script/tournament.ts'; import Tournament from '../script/tournament.ts';
...@@ -205,12 +260,15 @@ ...@@ -205,12 +260,15 @@
drawer : false, drawer : false,
menu : true, menu : true,
tournament : false, tournament : false,
create : false,
show : { show : {
user : () : void => { user : () : void => {
page.user = !page.user; page.user = !page.user;
}, },
drawer : () : void => { drawer : () : void => {
page.drawer = !page.drawer; page.drawer = !page.drawer;
if (!page.drawer && page.create)
page.create = false;
if (!page.drawer && page.tournament) if (!page.drawer && page.tournament)
tournament.init(tournament.this as Tournament); tournament.init(tournament.this as Tournament);
}, },
...@@ -228,6 +286,14 @@ ...@@ -228,6 +286,14 @@
await (new Promise(resolve => setTimeout(resolve, 500))); await (new Promise(resolve => setTimeout(resolve, 500)));
page.menu = true; page.menu = true;
}, },
create : async(): Promise<void> => {
if (page.drawer) {
page.show.drawer();
await (new Promise(resolve => setTimeout(resolve, 500)));
}
page.create = true;
page.show.drawer();
},
clear : (e) : void => { clear : (e) : void => {
let element = e.target; let element = e.target;
let chk = false; let chk = false;
...@@ -238,16 +304,16 @@ ...@@ -238,16 +304,16 @@
chk = true; chk = true;
if (element.id == 'page') if (element.id == 'page')
inPage = true; inPage = true;
if (element.className.includes('uni')) if (typeof element.className == 'string' && element.className.includes('uni'))
uniElement = true; uniElement = true;
element = element.parentElement; element = element.parentElement;
} }
if (chk || (!inPage && uniElement)) if (chk || (!inPage && uniElement))
return undefined; return undefined;
if (page.user) if (page.user)
page.show.user() page.show.user();
if (page.drawer) if (page.drawer)
page.show.drawer() page.show.drawer();
} }
} }
}); });
...@@ -304,6 +370,9 @@ ...@@ -304,6 +370,9 @@
const result = await Tabulator.Tournament.FindALL(Mycard.token, search.info); const result = await Tabulator.Tournament.FindALL(Mycard.token, search.info);
search.result.total = result.total; search.result.total = result.total;
search.result.tournaments = result.tournaments; search.result.tournaments = result.tournaments;
},
mine : () => {
search.creator = Mycard.id.toString();
} }
}); });
...@@ -326,21 +395,22 @@ ...@@ -326,21 +395,22 @@
{ value: 'Swiss', text: '瑞士轮' } { value: 'Swiss', text: '瑞士轮' }
], ],
settings : { settings : {
hasThirdPlaceMatch : true
} as ruleSettings } as ruleSettings
}, },
hasThirdPlaceMatch : { hasThirdPlaceMatch : {
select : (e) => { select : (e) => {
tournament.rule.settings.hasThirdPlaceMatch = e.detail.value.length > 0 tournament.rule.settings.hasThirdPlaceMatch = e.detail.value.length > 0
console.log(tournament.rule.settings.hasThirdPlaceMatch)
} }
}, },
collaborators : [] as Array<number>, collaborators : [] as Array<number>,
init : (t : Tournament) : void => { init : (t : Tournament) : void => {
if (!t) return;
tournament.this = t; tournament.this = t;
tournament.name = t.name; tournament.name = t.name;
tournament.description = t.description; tournament.description = t.description;
tournament.visibility.select = t.visibility; tournament.visibility.select = t.visibility;
tournament.rule.select = t.rule;
tournament.rule.settings = Object.assign({}, t.ruleSettings);
tournament.collaborators = t.collaborators; tournament.collaborators = t.collaborators;
}, },
clear : () : void => { clear : () : void => {
...@@ -348,6 +418,8 @@ ...@@ -348,6 +418,8 @@
tournament.name = ''; tournament.name = '';
tournament.description = ''; tournament.description = '';
tournament.visibility.select = ''; tournament.visibility.select = '';
tournament.rule.select = '';
tournament.rule.settings = {} as ruleSettings;
tournament.collaborators = []; tournament.collaborators = [];
}, },
update : () : void => { update : () : void => {
...@@ -358,8 +430,57 @@ ...@@ -358,8 +430,57 @@
name: tournament.name, name: tournament.name,
description: tournament.description, description: tournament.description,
visibility: tournament.visibility.select, visibility: tournament.visibility.select,
collaborators : tournament.collaborators collaborators : tournament.collaborators,
} as TournamentUpdateObject); rule : tournament.rule.select,
ruleSettings : tournament.rule.settings
} as TournamentCreateObject);
}
});
let create = reactive({
name : '',
description : '',
visibility : {
select : ''
},
rule : {
select : '',
settings : {
} as ruleSettings
},
hasThirdPlaceMatch : {
select : (e) => {
create.rule.settings.hasThirdPlaceMatch = e.detail.value.length > 0
}
},
collaborators : [] as Array<number>,
clear : () : void => {
create.name = '';
create.description = '';
create.visibility.select = '';
create.rule.select = '';
create.rule.settings = {} as ruleSettings;
create.collaborators = [];
},
update : async() : Promise<void> => {
if (create.visibility.select == '')
// @ts-ignore
create.visibility.select = 'SingleElimination';
if (await Tabulator.Tournament.Create(Mycard.token, {
name: create.name,
description: create.description,
rule: create.rule.select,
ruleSettings: create.rule.settings,
visibility: create.visibility.select,
collaborators: create.collaborators
})
) {
page.show.drawer();
if (page.tournament)
page.show.menu();
create.clear();
await search.on();
}
} }
}); });
......
...@@ -127,7 +127,6 @@ ...@@ -127,7 +127,6 @@
</uni-list-item> </uni-list-item>
<uni-list-item <uni-list-item
v-for = '(i, v) in match.array' v-for = '(i, v) in match.array'
v-show = 'participant.array.findIndex(p => p.id == i.player1Id) >= 0'
:clickable = true :clickable = true
> >
<template v-slot:header> <template v-slot:header>
...@@ -181,7 +180,7 @@ ...@@ -181,7 +180,7 @@
tournamentReload tournamentReload
} from '../script/const.ts' } from '../script/const.ts'
import Mycard from '../script/mycard.ts'; import Mycard from '../script/mycard.ts';
import { AllParticipant, AllMatch, TournamentUpdateObject } from '../script/type.ts' import { AllParticipant, AllMatch, TournamentCreateObject } from '../script/type.ts'
let tournament = reactive({ let tournament = reactive({
this : undefined as undefined | Tournament, this : undefined as undefined | Tournament,
...@@ -241,7 +240,7 @@ ...@@ -241,7 +240,7 @@
if (!res.confirm) return; if (!res.confirm) return;
// @ts-ignore // @ts-ignore
if (await Tabulator.Tournament.Delete(Mycard.token, tournament.this.id)) if (await Tabulator.Tournament.Delete(Mycard.token, tournament.this.id))
page.reload(); page.clear();
} }
}); });
}, },
...@@ -290,7 +289,7 @@ ...@@ -290,7 +289,7 @@
participant.total = participants.total; participant.total = participants.total;
} }
}, },
update : async (Data : TournamentUpdateObject) : Promise<void> => { update : async (Data : TournamentCreateObject) : Promise<void> => {
// @ts-ignore // @ts-ignore
if (await Tabulator.Tournament.Update(Mycard.token, tournament.this.id, Data)) if (await Tabulator.Tournament.Update(Mycard.token, tournament.this.id, Data))
page.reload(); page.reload();
...@@ -317,7 +316,7 @@ ...@@ -317,7 +316,7 @@
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}); 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;
}, },
...@@ -336,7 +335,7 @@ ...@@ -336,7 +335,7 @@
participant.array = participants.participants; participant.array = participants.participants;
participant.total = participants.total; participant.total = participants.total;
// @ts-ignore // @ts-ignore
const matchs : AllMatch = await Tabulator.Match.FindALL(Mycard.token, {tournamentId : tournament.this.id}); const matchs : AllMatch = await Tabulator.Match.FindALL(Mycard.token, {tournamentId : tournament.this.id, statusIn : 'Running,Finished'});
match.array = matchs.matchs; match.array = matchs.matchs;
match.total = matchs.total; match.total = matchs.total;
emitter.emit(tournamentReload, tournament.this) emitter.emit(tournamentReload, tournament.this)
......
...@@ -6,7 +6,6 @@ import ApiKey from '../script/apikey.ts'; ...@@ -6,7 +6,6 @@ import ApiKey from '../script/apikey.ts';
import { import {
TournamentObject, TournamentObject,
TournamentCreateObject, TournamentCreateObject,
TournamentUpdateObject,
TournamentFindObject, TournamentFindObject,
MatchObject, MatchObject,
MatchUpdateObject, MatchUpdateObject,
...@@ -48,6 +47,11 @@ class TabulatorAPI { ...@@ -48,6 +47,11 @@ class TabulatorAPI {
return response.data.data.id; return response.data.data.id;
} }
catch(error) { catch(error) {
uni.showModal({
title : '创建失败',
content : error.message,
showCancel : false
})
console.error(error); console.error(error);
return -1; return -1;
} }
...@@ -136,7 +140,7 @@ class TabulatorAPI { ...@@ -136,7 +140,7 @@ class TabulatorAPI {
}; };
} }
}, },
Update : async (token : string, id : number, Data : TournamentUpdateObject) : Promise<boolean> => { Update : async (token : string, id : number, Data : TournamentCreateObject) : Promise<boolean> => {
let response : { let response : {
data : { data : {
success : boolean; success : boolean;
...@@ -400,7 +404,8 @@ class TabulatorAPI { ...@@ -400,7 +404,8 @@ class TabulatorAPI {
player2Id : obj.player2Id, player2Id : obj.player2Id,
player2Score : obj.player2Score, player2Score : obj.player2Score,
winnerId : obj.winnerId, winnerId : obj.winnerId,
childMatchId : obj.childMatchId childMatchId : obj.childMatchId,
statusIn : obj.statusIn
}, },
headers : { headers : {
'x-user-token' : token 'x-user-token' : token
......
...@@ -16,6 +16,7 @@ interface MatchFindObject { ...@@ -16,6 +16,7 @@ interface MatchFindObject {
player2Score ?: number; player2Score ?: number;
winnerId ?: number; winnerId ?: number;
childMatchId ?: number; childMatchId ?: number;
statusIn ?: string
} }
interface MatchUpdateObject { interface MatchUpdateObject {
...@@ -40,13 +41,6 @@ interface MatchObject extends MatchUpdateObject { ...@@ -40,13 +41,6 @@ interface MatchObject extends MatchUpdateObject {
parentMatches ?: MatchObject; parentMatches ?: MatchObject;
} }
interface TournamentUpdateObject {
name : string;
description : string;
visibility : string;
collaborators : Array<number>;
}
interface ruleSettings { interface ruleSettings {
rounds : number; rounds : number;
winScore : number; winScore : number;
...@@ -55,7 +49,11 @@ interface ruleSettings { ...@@ -55,7 +49,11 @@ interface ruleSettings {
hasThirdPlaceMatch : boolean; hasThirdPlaceMatch : boolean;
} }
interface TournamentCreateObject extends TournamentUpdateObject { interface TournamentCreateObject {
name : string;
description : string;
visibility : string;
collaborators : Array<number>;
rule : string; rule : string;
ruleSettings : ruleSettings; ruleSettings : ruleSettings;
} }
...@@ -152,7 +150,6 @@ export { ...@@ -152,7 +150,6 @@ export {
Score, Score,
TournamentObject, TournamentObject,
TournamentCreateObject, TournamentCreateObject,
TournamentUpdateObject,
TournamentFindObject, TournamentFindObject,
MatchObject, MatchObject,
MatchUpdateObject, MatchUpdateObject,
......
...@@ -52,6 +52,7 @@ ...@@ -52,6 +52,7 @@
justify-items: center; justify-items: center;
align-items: center; align-items: center;
&:hover { &:hover {
background-color: #e6e6e6;
cursor: pointer; cursor: pointer;
} }
} }
......
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