Commit 4b5369f9 authored by xiaoye's avatar xiaoye

fix

parent 5b77ab4b
<template>
<uni-card class = 'Create'>
<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 = 'create.visibility.range'
></uni-data-select>
<uni-data-select
placeholder = '规则'
v-model = 'create.rule.select'
:localdata = 'create.rule.range'
></uni-data-select>
<view v-show = "create.rule.select == 'Swiss'">
<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>
<uni-card
id = 'collaborators'
title = '协作者'
:is-full = 'true'
>
<uni-list>
<uni-list-chat
v-for = '(i, v) in create.collaborators'
:avatarCircle = 'true'
:clickable = true
:avatar = 'i.avatar'
:title = 'i.username'
:note = "i.id >= 0 ? i.id.toString() : ''"
@click = 'create.remove(v)'
>
<view>
<view class = 'button'>
<uni-icons type = 'trash'></uni-icons>
</view>
</view>
</uni-list-chat>
<uni-list-item>
<template v-slot:header>
<uni-forms>
<uni-forms-item id = 'header'>
<uni-easyinput type = 'text' placeholder = '添加协作者' v-model = 'create.collaborator'/>
</uni-forms-item>
</uni-forms>
</template>
<template v-slot:footer>
<view id = 'footer'>
<view
class = 'button'
:style = "{ '--color' : '#409eff' }"
@click = 'create.add()'
>
<uni-icons type = 'personadd'></uni-icons>
</view>
</view>
</template>
</uni-list-item>
</uni-list>
</uni-card>
<br>
<view class = 'button' @click = 'create.update()'>
<view>
<span>创建</span>
<uni-icons type = 'calendar'></uni-icons>
</view>
</view>
</uni-card>
</template>
<script setup lang = 'ts'>
import { ref, reactive, onMounted, onUnmounted, onBeforeMount, watch} from 'vue';
import { TournamentFindObject, ruleSettings, UserObject } from '../script/type.ts';
import {Tabulator, User} from '../script/post.ts';
import Mycard from '../script/mycard.ts';
import emitter from '../script/emitter.ts'
import {
updateTournament ,
tournamentInfo,
tournamentReload,
createOff
} from '../script/const.ts'
let create = reactive({
name : '',
description : '',
visibility : {
select : '',
range : [
{ value: 'Public', text: '公开' },
{ value: 'Internal', text: '仅登陆可见' },
{ value: 'Private', text: '私密' }
]
},
rule : {
select : '',
settings : {
} as ruleSettings,
range : [
{ value: 'SingleElimination', text: '单淘' },
{ value: 'Swiss', text: '瑞士轮' }
]
},
hasThirdPlaceMatch : {
select : (e) => {
create.rule.settings.hasThirdPlaceMatch = e.detail.value.length > 0
}
},
collaborator : '',
collaborators : [] as Array<UserObject>,
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';
const collaborators = create.collaborators.map(user => user.id);
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: collaborators
})
) {
emitter.emit(createOff);
create.clear();
}
},
remove : (v : number) : void => {
create.collaborators.splice(v, 1);
},
add : async() : Promise<void> => {
try {
if (create.collaborators.findIndex(i => i.username == create.collaborator) >= 0)
throw new Error('协作者已存在');
const i = await User.Find.Name(create.collaborator);
if (!i)
throw new Error('未搜索到此用户');
if (Mycard.id == i.id)
throw new Error('协作者不可以是比赛创建者');
create.collaborators.push(i);
} catch(error) {
uni.showModal({
title : '添加失败',
content : error.message,
showCancel : false
});
} finally {
create.collaborator = '';
}
}
});
</script>
\ No newline at end of file
......@@ -202,89 +202,15 @@
</uni-card>
</transition>
<transition name = 'move_left'>
<uni-card
<Create
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.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>
<uni-card
id = 'collaborators'
title = '协作者'
:is-full = 'true'
>
<uni-list>
<uni-list-chat
v-for = '(i, v) in create.collaborators'
:avatarCircle = 'true'
:clickable = true
:avatar = 'i.avatar'
:title = 'i.username'
:note = "i.id >= 0 ? i.id.toString() : ''"
@click = 'create.remove(v)'
>
<view>
<view class = 'button'>
<uni-icons type = 'trash'></uni-icons>
</view>
</view>
</uni-list-chat>
<uni-list-item>
<template v-slot:header>
<uni-forms>
<uni-forms-item id = 'header'>
<uni-easyinput type = 'text' placeholder = '添加协作者' v-model = 'create.collaborator'/>
</uni-forms-item>
</uni-forms>
</template>
<template v-slot:footer>
<view id = 'footer'>
<view
class = 'button'
:style = "{ '--color' : '#409eff' }"
@click = 'create.add()'
>
<uni-icons type = 'personadd'></uni-icons>
</view>
</view>
</template>
</uni-list-item>
</uni-list>
</uni-card>
<br>
<view class = 'button' @click = 'create.update()'>
<view>
<span>创建</span>
<uni-icons type = 'calendar'></uni-icons>
</view>
</view>
</uni-card>
</Create>
</transition>
<br>
<transition name = 'switch'>
......@@ -336,9 +262,11 @@
import {
updateTournament ,
tournamentInfo,
tournamentReload
tournamentReload,
createOff
} from '../script/const.ts'
import PageTournament from './tournament.vue';
import Create from './drawer.vue';
let page = reactive({
user : false,
......@@ -438,6 +366,7 @@
pageCount : 1,
id : 0,
creator : 0,
name : '',
rule : '',
visibility : '',
......@@ -554,50 +483,11 @@
}
});
let create = reactive({
name : '',
description : '',
visibility : {
select : ''
},
rule : {
select : '',
settings : {
} as ruleSettings
},
hasThirdPlaceMatch : {
select : (e) => {
create.rule.settings.hasThirdPlaceMatch = e.detail.value.length > 0
}
},
collaborator : '',
collaborators : [] as Array<UserObject>,
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';
const collaborators = create.collaborators.map(user => user.id);
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: collaborators
})
) {
const creator = {
off : async () : Promise<void> => {
page.show.drawer();
if (page.tournament)
page.show.menu();
create.clear();
await search.on({
pageCount : 1,
id : 0,
......@@ -608,67 +498,7 @@
status : ''
} as TournamentFindObject);
}
},
remove : (v : number) : void => {
create.collaborators.splice(v, 1);
},
add : async() : Promise<void> => {
try {
if (create.collaborators.findIndex(i => i.username == create.collaborator) >= 0)
throw new Error('协作者已存在');
const i = await User.Find.Name(create.collaborator);
if (!i)
throw new Error('未搜索到此用户');
if (Mycard.id == i.id)
throw new Error('协作者不可以是比赛创建者');
create.collaborators.push(i);
} catch(error) {
uni.showModal({
title : '添加失败',
content : error.message,
showCancel : false
});
} finally {
create.collaborator = '';
}
}
});
const test = async () => {
// let response = await Tabulator.Tournament.Create(Mycard.token, {
// name: "test",
// description: "暂无介绍。",
// rule: "SingleElimination",
// ruleSettings: {
// rounds: 0,
// winScore: 0,
// drawScore: 0,
// byeScore: 0,
// hasThirdPlaceMatch: true
// },
// visibility: "Public",
// collaborators: [
// 1
// ]
// });
// await Tabulator.Tournament.Delete(token, 3);
// await Tabulator.Tournament.FindALL(token, {});
// await Tabulator.Tournament.Update(token, 3, {
// name: "update",
// description: "update",
// visibility: "Public",
// collaborators : [
// 1
// ]
// });
// console.log(await Tabulator.Tournament.Create(Mycard.token, { name : 'test'}))
// console.log(await Tabulator.Tournament.FindALL(token, {}))
// console.log(await Tabulator.Match.FindALL(token, { id : 5 }))
// console.log(await Tabulator.Participant.FindALL(token))
// let response = await Tabulator.Tournament.Find(token, 3);
// await Tabulator.Tournament.Start(token, 4);
}
};
let size = reactive({
width : 0,
......@@ -686,6 +516,7 @@
emitter.on(tournamentInfo, page.show.drawer);
// @ts-ignore
emitter.on(tournamentReload, tournament.init);
emitter.on(createOff, creator.off);
const url = window.location.pathname.match(/\/tournament\/([^\/]+)(?=\/|$)/);
if (url && !isNaN(parseInt(url[1]))) {
......@@ -706,6 +537,7 @@
emitter.off(tournamentInfo, page.show.drawer);
// @ts-ignore
emitter.off(tournamentReload, tournament.init);
emitter.off(createOff, creator.off);
});
watch(() => { return search.date; }, () => {
......@@ -729,7 +561,6 @@
</script>
<style scoped lang = 'scss'>
@import '../style/style.scss';
@import '../style/page.scss';
@import '../style/transition.scss';
</style>
\ No newline at end of file
......@@ -500,7 +500,6 @@
</script>
<style scoped lang = 'scss'>
@import '../style/style.scss';
@import '../style/tournament.scss';
@import '../style/transition.scss';
</style>
\ No newline at end of file
const selectTournament = 'selectTournament';
const updateTournament = 'updateTournament';
const tournamentInfo = 'tournamentInfo';
const tournamentExit = 'tournamentExit';
const tournamentReload = 'tournamentReload'
const tournamentReload = 'tournamentReload';
const createOff = 'createOff';
export {
updateTournament ,
tournamentInfo,
tournamentReload
tournamentReload,
createOff
};
\ No newline at end of file
......@@ -67,4 +67,18 @@
cursor: pointer;
}
}
button {
background-color: white;
color : #606266;
border-radius: 4px;
white-space: nowrap;
border: 0.02px solid #606266;
transition: all 0.3s ease;
&:hover {
color: #ecf5ff;
background-color: #ecf5ff;
border: 0.02px solid #409eff;
}
}
}
$color: #606266;
$background-color: white;
$color-hover: #409eff;
$background-color-hover: #ecf5ff;
$font-size: 1.3vw;
$font-family: Arial, sans-serif;
select, input, textarea {
font-family: $font-family;
line-height: normal;
font-size: $font-size;
background-color: $background-color;
color : $color;
border: 0.02px solid $color;
border-radius: 8px;
transition: all 0.3s ease;
}
button {
background-color: $background-color;
color : $color;
border-radius: 4px;
white-space: nowrap;
border: 0.02px solid $color;
transition: all 0.3s ease;
&:hover {
color: $color-hover;
background-color: $background-color-hover;
border: 0.02px solid $color-hover;
}
}
input {
:focus {
color: $color-hover;
background-color: $background-color-hover;
border: 0.02px solid $color-hover;
}
}
select {
&:focus {
color: $color-hover;
border-color: $color-hover;
}
}
textarea {
:focus {
color: $color-hover;
background-color: $background-color-hover;
}
}
ul {
display: flex;
list-style: none;
gap: 3%;
font-size: $font-size;
color : $color;
font-family: $font-family;
transition: all 0.3s ease;
:hover {
color: $color-hover;
transform: scale(1.2);
cursor: pointer;
}
}
\ 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