2024-04-28 02:13:49 +00:00
|
|
|
<template>
|
|
|
|
|
|
|
|
|
|
<div class="login">
|
2024-05-21 11:08:55 +00:00
|
|
|
<h1>Login Page</h1>
|
|
|
|
|
<ul class="button-group">
|
|
|
|
|
<li v-for="person in persons" :key="person.id">
|
|
|
|
|
<button type="button" class="btn btn-primary" @click="login(person)">
|
|
|
|
|
{{ person.name }}
|
|
|
|
|
</button>
|
|
|
|
|
</li>
|
|
|
|
|
</ul>
|
2024-04-28 02:13:49 +00:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</template>
|
|
|
|
|
|
2024-05-21 11:08:55 +00:00
|
|
|
<style scoped>
|
|
|
|
|
|
|
|
|
|
/* Remove the default list styling */
|
|
|
|
|
ul {
|
|
|
|
|
list-style-type: none;
|
|
|
|
|
padding: 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Center the buttons in the middle of the page, and let them wrap */
|
|
|
|
|
|
|
|
|
|
.button-group {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-wrap: wrap;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Display each button as a large round circle */
|
|
|
|
|
|
|
|
|
|
button {
|
|
|
|
|
width: 100px;
|
|
|
|
|
height: 100px;
|
|
|
|
|
border-radius: 50%;
|
|
|
|
|
margin: 10px;
|
|
|
|
|
font-size: 1.5em;
|
|
|
|
|
|
|
|
|
|
/* Center the text in the middle of the button */
|
|
|
|
|
display: flex;
|
|
|
|
|
justify-content: center;
|
|
|
|
|
align-items: center;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
</style>
|
|
|
|
|
|
2024-04-28 02:13:49 +00:00
|
|
|
<script>
|
|
|
|
|
import data from '@/data';
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
name: 'LoginVue',
|
|
|
|
|
props: {
|
|
|
|
|
redirect: {
|
|
|
|
|
type: String,
|
|
|
|
|
default: '/'
|
2024-05-21 11:08:55 +00:00
|
|
|
},
|
2024-04-28 02:13:49 +00:00
|
|
|
},
|
|
|
|
|
data() {
|
|
|
|
|
return {
|
2024-05-21 11:08:55 +00:00
|
|
|
persons: [],
|
2024-04-28 02:13:49 +00:00
|
|
|
}
|
|
|
|
|
},
|
2024-05-21 11:08:55 +00:00
|
|
|
async beforeMount() {
|
|
|
|
|
this.persons = await data.getPersonsInHome();
|
|
|
|
|
},
|
2024-04-28 02:13:49 +00:00
|
|
|
methods: {
|
2024-05-21 11:08:55 +00:00
|
|
|
async login(selectedPerson) {
|
|
|
|
|
const person = await data.login(selectedPerson.name);
|
2024-05-20 12:16:39 +00:00
|
|
|
if (person?.id >= 0) {
|
2024-04-28 02:13:49 +00:00
|
|
|
this.$router.push(this.redirect);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
alert('Login failed');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-05-21 11:08:55 +00:00
|
|
|
</script>
|