🎨 Переместил поле выбора ответа в свой компонент

This commit is contained in:
2021-03-28 15:51:48 +03:00
parent dc3f62197d
commit 8d0fe5788a
6 changed files with 144 additions and 46 deletions

View File

@@ -1 +1,2 @@
VUE_APP_BACKEND=Адрес бэкенда
VUE_APP_QUESTION=Вопрос для страницы авторизации VUE_APP_QUESTION=Вопрос для страницы авторизации

View File

@@ -1,5 +1,5 @@
<template> <template>
<h1>🎰 Flex Bingo 🎰</h1> <h1>🎰 Флекспатрульное Бинго 🎰</h1>
<Login id="login" @loggedIn="login" v-show="!loggedIn" /> <Login id="login" @loggedIn="login" v-show="!loggedIn" />
<Game id="game" v-if="loggedIn" /> <Game id="game" v-if="loggedIn" />
</template> </template>
@@ -43,11 +43,11 @@ body {
} }
#game { #game {
margin: auto;
margin-bottom: 100px; margin-bottom: 100px;
} }
.correct { .correct {
color: black;
background-color: rgb(124, 230, 124) !important; background-color: rgb(124, 230, 124) !important;
} }
.highlight_correct { .highlight_correct {
@@ -56,4 +56,11 @@ body {
.wrong { .wrong {
background-color: rgb(255, 71, 71) !important; background-color: rgb(255, 71, 71) !important;
} }
@media only screen and (max-width: 520) {
h1 {
display: none;
font-size: 10px;
}
}
</style> </style>

View File

@@ -1,50 +1,67 @@
<template> <template>
<div class="card" v-if="card !== null"> <div class="card" v-if="card !== null" v-on:click="nextCard()" v-bind:class="{clickable: showResult}">
<img class="meme" v-bind:src="card.image"> <img class="meme" v-bind:src="card.image">
<h2>Кто скинул этот мем?</h2> <h2>Кто скинул этот мем?</h2>
<div class="answers"> <div class="interactive">
<span class="option" v-for="name in options" :key="name" v-on:click="selectAnswer(name)" <transition name="fade-answers">
v-bind:class="{ <List v-if="selectedAnswer === null"
correct: correctAnswer && selectedAnswer === name, :options="options" @selectedAnswer="selectAnswer" />
wrong: selectedAnswer === name && !correctAnswer, </transition>
highlight_correct: correctAnswer !== null && name === card.name <transition name="spin-result">
}"> <Result v-if="showResult"
{{ name }} :name="card.name" :selectedName="selectedAnswer" :date="card.date" :correct="correctAnswer" />
</span> </transition>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
import axios from 'axios' import axios from 'axios'
import List from './List.vue'
import Result from './Result.vue'
export default { export default {
name: 'Game', name: 'Game',
components: {
List,
Result
},
data() { data() {
return { return {
options: null, options: null,
card: null, card: null,
correctAnswer: null, // True or False correctAnswer: null, // True or False
selectedAnswer: null // Чье-то имя selectedAnswer: null, // Чье-то имя
showResult: false
} }
}, },
methods: { methods: {
getCard: function() { getCard: function() {
this.correctAnswer = null
this.selectedAnswer = null
this.showResult = false
axios axios
.get('http://localhost:3000/card') .get(process.env.VUE_APP_BACKEND + '/card')
.then(response => (this.card = response.data)) .then(response => (this.card = response.data))
}, },
nextCard: function() {
if (this.showResult) {
this.getCard()
}
},
selectAnswer: function(selection) { selectAnswer: function(selection) {
if (this.correctAnswer === null) {
this.correctAnswer = selection === this.card.name this.correctAnswer = selection === this.card.name
this.selectedAnswer = selection this.selectedAnswer = selection
} let innerThis = this
setTimeout(function() {
innerThis.showResult = true
}, 800)
} }
}, },
mounted() { mounted() {
this.getCard() this.getCard()
axios axios
.get('http://localhost:3000/options') .get(process.env.VUE_APP_BACKEND + '/options')
.then(response => (this.options = response.data)) .then(response => (this.options = response.data))
} }
} }
@@ -52,11 +69,12 @@ export default {
<style scoped> <style scoped>
.card { .card {
width: 50%; width: 450px;
padding: 18px; padding: 18px;
border-radius: 17px; border-radius: 17px;
box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.6); box-shadow: 5px 5px 10px rgba(0, 0, 0, 0.6);
background-color: #121212; background-color: #121212;
margin: auto;
} }
.meme { .meme {
@@ -64,33 +82,33 @@ export default {
border-radius: 8px; border-radius: 8px;
} }
.answers { .clickable {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.option {
background-color: #5a5a5a;
border-radius: 6px;
margin: 3px;
padding: 5px 9px 5px 9px;
transition: transform 0.2s;
}
.option:hover {
transform: scale(1.06);
cursor: pointer; cursor: pointer;
} }
@keyframes correct-selected { .interactive {
0% { position: relative;
transform: scale(0); }
}
50% { .fade-answers-leave-active {
transform: scale(1.5); transition: all 0.8s ease;
} }
100% { .fade-answers-leave-to {
transform: scale(1); opacity: 0;
transform: scale(0.3);
}
.spin-result-enter-active {
transition: all 2s ease;
}
.spin-result-enter-from {
transform: scale(0.2);
transform: rotateY(120deg);
}
@media only screen and (max-width: 486) {
.card {
width: 100%;
} }
} }
</style> </style>

View File

@@ -0,0 +1,41 @@
<template>
<div class="answers">
<span class="option" v-for="name in options" :key="name" v-on:click="selectAnswer(name)">
{{ name }}
</span>
</div>
</template>
<script>
export default {
name: 'List',
props: {
options: Array
},
methods: {
selectAnswer: function(selection) {
this.$emit('selectedAnswer', selection)
}
}
}
</script>
<style scoped>
.answers {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
}
.option {
background-color: #5a5a5a;
border-radius: 6px;
margin: 3px;
padding: 5px 9px 5px 9px;
transition: transform 0.2s;
}
.option:hover {
transform: scale(1.06);
cursor: pointer;
}
</style>

View File

@@ -23,7 +23,7 @@ export default {
methods: { methods: {
login: function() { login: function() {
axios axios
.post('http://localhost:3000/auth', { .post(process.env.VUE_APP_BACKEND + '/auth', {
"pass": this.answer, "pass": this.answer,
}) })
.then(response => { .then(response => {
@@ -34,7 +34,6 @@ export default {
}, },
mounted() { mounted() {
this.question = process.env.VUE_APP_QUESTION this.question = process.env.VUE_APP_QUESTION
this.login() this.login()
} }
} }

View File

@@ -0,0 +1,32 @@
<template>
<div>
<span v-show="!correct" class="wrong-answr">Нет, это был не {{ selectedName }} 😢</span>
<div class="result" v-bind:class="{correct: correct}">
{{ name }} {{ date }}
</div>
</div>
</template>
<script>
export default {
name: "Result",
props: {
name: String,
selectedName: String,
date: String,
correct: Boolean
}
}
</script>
<style scoped>
.result {
padding: 30px 40px 30px 40px;
border-radius: 8px;
background-color: #5a5a5a;
}
.wrong-answr {
color: rgb(255, 71, 71);
}
</style>