feat: 对接后端数据接口

main
刘隽霖 1 month ago
parent 89dbf0979f
commit 2814a708c1

@ -1,6 +0,0 @@
import Mock from 'mockjs'
Mock.mock('http://localhost:8080/upload', 'post', {
status: 200,
message: '文件上传成功!'
})

@ -2,7 +2,7 @@
<div class="container"> <div class="container">
<h1 class="heading"> <h1 class="heading">
就决定是你了<br /> 就决定是你了<br />
田所浩二 {{ stopName }}
</h1> </h1>
<h2 class="sub-heading">你成功的复述了所提的问题吗</h2> <h2 class="sub-heading">你成功的复述了所提的问题吗</h2>
<div class="buttons"> <div class="buttons">
@ -10,7 +10,7 @@
<el-button class="ax_default button" @click="showRating = true" <el-button class="ax_default button" @click="showRating = true"
><span class="button-text"></span></el-button ><span class="button-text"></span></el-button
> >
<el-button class="ax_default button" @click="showAngryFace = true" <el-button class="ax_default button" @click="updateScoreMinus"
><span class="button-text"></span></el-button ><span class="button-text"></span></el-button
> >
</div> </div>
@ -22,7 +22,7 @@
v-model="currentRating" v-model="currentRating"
:max="5" :max="5"
:disabled="isRatingDisabled" :disabled="isRatingDisabled"
@change="disableRating" @change="updateScore"
/> />
<!-- 再抽一次按钮 --> <!-- 再抽一次按钮 -->
@ -50,22 +50,88 @@
<script setup> <script setup>
import { ref } from 'vue' import { ref } from 'vue'
import { useRouter } from 'vue-router' // useRouter import { useRouter } from 'vue-router'
import { useRoute } from 'vue-router'
import axios from 'axios'
const route = useRoute()
// 使 ref
const currentRating = ref(0) const currentRating = ref(0)
const showRating = ref(false) const showRating = ref(false)
const isRatingDisabled = ref(false) // const isRatingDisabled = ref(false) //
const showAngryFace = ref(false) // const showAngryFace = ref(false) //
const stopNumbers = route.query.stopNumbers
const stopName = route.query.stopName
const studentScore = ref(parseInt(route.query.studentScore) || 0)
// stopNumbers user_id
const userId = parseInt(
Array.isArray(stopNumbers) ? stopNumbers.join('') : stopNumbers
)
// router // router
const router = useRouter() const router = useRouter()
// // studentScore
const disableRating = () => { const updateScore = (value) => {
// studentScore
studentScore.value += value
//
isRatingDisabled.value = true isRatingDisabled.value = true
}
// stopNumbers studentScore JSON
const data = JSON.stringify({
user_id: userId,
user_score: studentScore.value
})
// config
var config = {
method: 'post',
url: 'http://localhost:8080/change-score',
data: data
}
// POST
axios(config)
.then((response) => {
console.log('数据成功发送到后端:', response.data)
})
.catch((error) => {
console.error('发送数据到后端时出错:', error)
})
}
// studentScore 1
const updateScoreMinus = () => {
// 1
studentScore.value -= 1
//
const data = JSON.stringify({
user_id: userId,
user_score: studentScore.value
})
// config
var config = {
method: 'post',
url: 'http://localhost:8080/change-score',
data: data
}
// POST
axios(config)
.then((response) => {
console.log('扣分数据成功发送到后端:', response.data)
})
.catch((error) => {
console.error('发送扣分数据到后端时出错:', error)
})
//
showAngryFace.value = true
}
// /roll-call // /roll-call
const goToRollCall = () => { const goToRollCall = () => {
router.push('/roll-call') // /roll-call router.push('/roll-call') // /roll-call

@ -24,12 +24,15 @@
<script setup> <script setup>
import { ref, onUnmounted } from 'vue' import { ref, onUnmounted } from 'vue'
import { useRouter } from 'vue-router' import { useRouter } from 'vue-router'
import axios from 'axios'
import RollingNumber from '@/components/scrollingNumber.vue' import RollingNumber from '@/components/scrollingNumber.vue'
const router = useRouter() const router = useRouter()
const isScrolling = ref(true) const isScrolling = ref(false)
const stopNumbers = ref([1, 0, 1, 1, 4, 5, 1, 4, 1]) // stopNumber const stopNumbers = ref([1, 0, 1, 1, 4, 5, 1, 4, 1]) // stopNumber
const stopName = ref('')
const studentScore = ref(0)
// duration 80-120 // duration 80-120
const durations = ref( const durations = ref(
@ -40,9 +43,33 @@ const completedRolls = ref(new Array(stopNumbers.value.length).fill(false))
const confirmed = ref(false) const confirmed = ref(false)
const isButtonPressed = ref(false) const isButtonPressed = ref(false)
const toggleScrolling = () => { const toggleScrolling = async () => {
isButtonPressed.value = true isButtonPressed.value = true
if (isScrolling.value == false) { if (isScrolling.value == false) {
//
axios
.get('http://localhost:8080/get-random', {})
.then(function (response) {
console.log(JSON.stringify(response.data))
// User_id
if (response.data.data) {
const userId = response.data.data.User_id.toString()
.split('')
.map(Number)
stopNumbers.value = userId
stopName.value = response.data.data.User_name
studentScore.value = response.data.data.User_score
durations.value = stopNumbers.value.map(
() => Math.floor(Math.random() * (120 - 80 + 1)) + 80
)
} else {
console.error('User_id not found in response data')
}
})
.catch(function (error) {
console.log(error)
})
setTimeout(() => { setTimeout(() => {
isButtonPressed.value = false isButtonPressed.value = false
}, 10) }, 10)
@ -64,10 +91,21 @@ const handleRollCompleted = (index) => {
isButtonPressed.value = false // isButtonPressed.value = false //
if ( if (
!confirmed.value && !confirmed.value &&
confirm(`抽到了: ${stopNumbers.value.join('')},确定后跳转`) confirm(
`抽到了: ${stopNumbers.value.join('')}, ${stopName.value},确定后跳转`
)
) { ) {
confirmed.value = true confirmed.value = true
router.push('/rating') confirmed.value = true
// query
router.push({
path: '/rating',
query: {
stopNumbers: stopNumbers.value.join(''),
stopName: stopName.value,
studentScore: studentScore.value
}
})
} }
}, 800) }, 800)
} }

Loading…
Cancel
Save