添加上传面板、事件机制

master
cflsxjw 1 month ago
parent 0ecda66057
commit ab8ad7873f

@ -9,7 +9,6 @@
<body>
<div class="container">
<div class="main-menu" id="menu-sidebar"></div>
<script type="module" src="src/javascript/main-menu.js"></script>
<div class="main-content">
<div class="header">Roller</div>

@ -1,25 +1,61 @@
<script setup>
function OnClick()
{
document.getElementById('myid').click()
import {watchEffect, onMounted} from "vue";
const props = defineProps(['description'])
function DescriptionToHTML(description) {
let html = "";
const words = description.split('/');
for (let i in words) {
html += words[i] + '<br>';
}
return html;
}
onMounted(() => {
watchEffect(() => {
document.getElementById('description').innerHTML = DescriptionToHTML(props.description);
})
})
</script>
<template>
<div class="event-description">
<button @click="OnClick">
open file selection
</button>
<form>
<input type="file" style="display:none" id="myid"/>
</form>
<div class="container">
<div class="title">
event<br>description
</div>
<div id="description">
</div>
</div>
</template>
<style scoped>
.event-description {
@import url('https://fonts.googleapis.com/css2?family=Itim&display=swap');
@import url('https://fonts.googleapis.com/css2?family=ZCOOL+QingKe+HuangYou&display=swap');
.container {
width: 20.33%;
height: 100%;
background-color: #537045A5;
background-color: #718B64;
display: flex;
flex-direction: column;
align-items: center;
}
.title {
font-size: 40px;
height: 8.3vh;
width: 13.46vw;
background-color: #58767C;
margin-top: 5.3vh;
font-family: Itim,serif;
text-align: center;
line-height: 40px;
border-radius: 20px;
}
#description {
font-size: 40px;
margin-top: 5.3vh;
text-align: center;
font-family: "ZCOOL QingKe HuangYou",serif;
}
</style>

@ -5,13 +5,31 @@ import {ref} from "vue";
import EventDescriptionBoard from "./event-description-board.vue";
const number=ref(0);
const enable=ref(false);
const score=ref(0);
const score=ref(0.0);
const sno=ref("");
const sname=ref("");
function getStuInfo()
const eventID=ref(0);
const eventDescription=ref("")
let init=false;
let score_variation = 0.0;
function start()
{
let res = fetch("http://127.0.0.1:8000/get_random_stu",{method: "GET"});
res.then((res)=>{
if(init)
{
fetch("http://localhost:8000/api/post/update_score",{
method: "POST",
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify({
sno: sno.value,
variation: score.value - score_variation})
})
}
init=true;
fetch("http://127.0.0.1:8000/api/get/get_random_stu",{method: "GET"})
.then((res)=>{
return res.json()
}).then((data)=>{
// noinspection JSUnresolvedReference
@ -19,6 +37,24 @@ function getStuInfo()
// noinspection JSUnresolvedReference
sname.value = data.sname
})
fetch("http://localhost:8000/api/get/get_random_event",{method: "GET"})
.then((res)=>{
return res.json()
}).then((data)=>{
// noinspection JSUnresolvedReference
eventID.value = data.event_id
enable.value = eventID.value !== 0;
// noinspection JSUnresolvedReference
eventDescription.value = data.event_description
})
switch (eventID.value) {
case 1:
score_variation = 1;
break;
case 2:
score_variation = -0.5;
break;
}
}
</script>
@ -27,9 +63,9 @@ function getStuInfo()
<score-board class="score-board" :current-score="score" @score-changed="(s)=>{score=s}"></score-board>
<div class="result-board-container">
<result-board class="result-board" :number :enable :sno :sname></result-board>
<button class="start-button" @click="getStuInfo">start</button>
<button class="start-button" @click="start">start</button>
</div>
<event-description-board class="event-description"></event-description-board>
<event-description-board class="event-description" :description="eventDescription"></event-description-board>
</div>
</template>
@ -51,7 +87,7 @@ function getStuInfo()
grid-template-columns:27.3% 52.37% 20.33%;
flex-direction: row;
width: 100%;
background-color: #7B8795;
background-color: #657A7E;
}
.score-board {
margin: 11.39vh 0 0 40.26%;

@ -1,10 +0,0 @@
<script setup>
</script>
<template>
</template>
<style scoped>
</style>

@ -0,0 +1,64 @@
<script setup>
function select()
{
let file_input = document.getElementById("file-input")
file_input.click();
}
function upload()
{
let file_input = document.getElementById("file-input")
const formData = new FormData();
formData.append("file", file_input.files[0]);
console.log(file_input.files[0]);
fetch("http://localhost:8000/api/post/upload_stu_info", {
method: 'POST',
body: formData
})
}
</script>
<template>
<div class="container">
<button class="file-selector" @click="select">select file</button>
<form>
<input type="file" id="file-input" accept=".csv">
<button type="submit" class="submit-button" @click.prevent="upload">U<br>P<br>L<br>O<br>A<br>D</button>
</form>
</div>
</template>
<style scoped>
@import url('https://fonts.googleapis.com/css2?family=Kalam:wght@300;400;700&display=swap');
.container {
height: 100%;
width: 100%;
background-color: #2F3B4A;
flex-direction: column;
align-items: center;
}
.file-selector {
margin-top: 3.5vh;
width: 6.94vw;
height: 4.3vh;
border-radius: 20px;
font-size: 1.25rem;
font-family: Itim,serif;
background-color: #BE8A7D;
}
#file-input {
display: none;
}
.submit-button {
margin-top: 3.5vh;
width: 6.94vw;
height: 80.3vh;
border-radius: 30px;
background-color: #2C3031;
border: 3px solid #2C3031;
font-size: 6rem;
text-align: center;
font-family: Kalam,serif;
line-height: 140px;
}
</style>

@ -1,5 +1,5 @@
import { createApp } from 'vue'
import MenuSidebar from '../components/menu-sidebar.vue'
import MenuSidebar from '../components/upload-panel.vue'
const app = createApp(MenuSidebar)
app.mount('#menu-sidebar')
Loading…
Cancel
Save