generated from VLADIMIR/template_frontend
up
This commit is contained in:
@@ -8,18 +8,24 @@ import BeltBlock from './BeltBlock.vue'
|
||||
import HeaderText from './HeaderText.vue'
|
||||
import MetalPlate from './MetalPlate.vue'
|
||||
|
||||
const code = ref('')
|
||||
|
||||
const props = defineProps<{
|
||||
addAction: (param: string) => void
|
||||
addAction: (param: string) => Promise<boolean>
|
||||
allPlacesCount: number
|
||||
newPlacesCount: number
|
||||
gameStatus: string
|
||||
}>()
|
||||
|
||||
const code = ref('')
|
||||
const isSubmitting = ref(false)
|
||||
|
||||
async function addClickButton() {
|
||||
await props.addAction(code.value)
|
||||
code.value = ''
|
||||
if (isSubmitting.value || props.gameStatus != 'run' || code.value.length == 0) return
|
||||
isSubmitting.value = true
|
||||
try {
|
||||
if (await props.addAction(code.value)) code.value = ''
|
||||
} finally {
|
||||
isSubmitting.value = false
|
||||
}
|
||||
}
|
||||
|
||||
function getTextForCounter(count: number): string[] {
|
||||
@@ -87,14 +93,14 @@ function getTextForCounter(count: number): string[] {
|
||||
v-model="code"
|
||||
type="text"
|
||||
:placeholder="props.gameStatus == 'run' ? 'Место назначения' : 'Ходы запрещены'"
|
||||
:disabled="props.gameStatus != 'run'"
|
||||
:disabled="props.gameStatus != 'run' || isSubmitting"
|
||||
/>
|
||||
</div>
|
||||
<div class="game-button-run-shadow"></div>
|
||||
<button
|
||||
class="game-button-run"
|
||||
type="submit"
|
||||
:disabled="code.length == 0"
|
||||
:disabled="props.gameStatus != 'run' || code.length == 0 || isSubmitting"
|
||||
v-on:click="addClickButton"
|
||||
>
|
||||
<HeaderText v-if="props.gameStatus == 'run'">Поехали</HeaderText>
|
||||
|
||||
@@ -1028,27 +1028,57 @@ useSimplePolling(() => {
|
||||
</n-tag>
|
||||
</n-space>
|
||||
<n-flex justify="end">
|
||||
<n-button type="info" v-if="game.status != 'draft'" dashed @click="resetGame()">
|
||||
<n-button
|
||||
type="info"
|
||||
v-if="game.status != 'draft'"
|
||||
dashed
|
||||
aria-label="Сбросить игру"
|
||||
@click="resetGame()"
|
||||
>
|
||||
<Icon>
|
||||
<Reset />
|
||||
</Icon>
|
||||
</n-button>
|
||||
<n-button type="info" v-if="game.status == 'draft'" dashed @click="startGame()">
|
||||
<n-button
|
||||
type="info"
|
||||
v-if="game.status == 'draft'"
|
||||
dashed
|
||||
aria-label="Начать игру"
|
||||
@click="startGame()"
|
||||
>
|
||||
<Icon>
|
||||
<Play />
|
||||
</Icon>
|
||||
</n-button>
|
||||
<n-button type="info" v-if="game.status == 'pause'" dashed @click="playGame()">
|
||||
<n-button
|
||||
type="info"
|
||||
v-if="game.status == 'pause'"
|
||||
dashed
|
||||
aria-label="Продолжить игру"
|
||||
@click="playGame()"
|
||||
>
|
||||
<Icon>
|
||||
<Play />
|
||||
</Icon>
|
||||
</n-button>
|
||||
<n-button type="info" v-if="game.status == 'run'" dashed @click="pauseGame()">
|
||||
<n-button
|
||||
type="info"
|
||||
v-if="game.status == 'run'"
|
||||
dashed
|
||||
aria-label="Поставить игру на паузу"
|
||||
@click="pauseGame()"
|
||||
>
|
||||
<Icon>
|
||||
<Pause />
|
||||
</Icon>
|
||||
</n-button>
|
||||
<n-button type="info" v-if="game.status != 'finish'" dashed @click="finishGame()">
|
||||
<n-button
|
||||
type="info"
|
||||
v-if="game.status != 'finish'"
|
||||
dashed
|
||||
aria-label="Завершить игру"
|
||||
@click="finishGame()"
|
||||
>
|
||||
<Icon>
|
||||
<Flag />
|
||||
</Icon>
|
||||
|
||||
@@ -126,17 +126,22 @@ async function getStory() {
|
||||
getStory()
|
||||
getAnswers()
|
||||
|
||||
async function addAction(newCode: string) {
|
||||
await client.AddTeamAction({
|
||||
ID: Number(teamId),
|
||||
password: password as string,
|
||||
code: newCode,
|
||||
})
|
||||
await getStory()
|
||||
code.value = ''
|
||||
|
||||
await nextTick()
|
||||
newPlacesCount.value = 0
|
||||
async function addAction(newCode: string): Promise<boolean> {
|
||||
try {
|
||||
await client.AddTeamAction({
|
||||
ID: Number(teamId),
|
||||
password: password as string,
|
||||
code: newCode,
|
||||
})
|
||||
await getStory()
|
||||
code.value = ''
|
||||
await nextTick()
|
||||
newPlacesCount.value = 0
|
||||
return true
|
||||
} catch (err) {
|
||||
message.error(err instanceof Error ? err.message : 'Не удалось сделать ход')
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
type AdvancedStory = {
|
||||
|
||||
Reference in New Issue
Block a user