feat: 增加一个随机事件

master
Spark 2 months ago
parent 2b728168d3
commit 918e3031af

@ -7,6 +7,7 @@ import {listStudent, rollCall, updatePoints} from "@/api/student.js";
const loading = ref(false) const loading = ref(false)
const cards = ref([]) const cards = ref([])
const canSelect = ref(true) const canSelect = ref(true)
const disableClick = ref(false)
const isResetting = ref(false) const isResetting = ref(false)
const dialogVisible = ref(false) const dialogVisible = ref(false)
const dialogVisible2 = ref(false) const dialogVisible2 = ref(false)
@ -16,6 +17,7 @@ const avatarUrl = ref('https://api.aspark.cc')
const avatarKey = ref(0) const avatarKey = ref(0)
const pointChange = ref(0) const pointChange = ref(0)
const pointChange2 = ref(0) const pointChange2 = ref(0)
const nothingToDo = ref(false)
const randomEvents = ref([ const randomEvents = ref([
{ {
title: "放他一马", title: "放他一马",
@ -24,6 +26,10 @@ const randomEvents = ref([
{ {
title: "天选之子", title: "天选之子",
content: "成为天选之子,看似幸运加身,实则背负孤独。所有人羡慕你的光环,却无人懂得你走过的黑暗。被命运选中,不是因为强大,而是因为只能独自面对那些无人能解的重担。(同学化身天选之子,本次点名积分 +10 )" content: "成为天选之子,看似幸运加身,实则背负孤独。所有人羡慕你的光环,却无人懂得你走过的黑暗。被命运选中,不是因为强大,而是因为只能独自面对那些无人能解的重担。(同学化身天选之子,本次点名积分 +10 )"
},
{
title: "无事发生",
content: "有时候,无事发生比风浪更让人心酸。日子在静默中悄然滑过,没有意外,也没有惊喜,连时间都像失去了温度。原以为平静是安全的,却不知这无声的流逝中,埋藏着无数未曾到来的期望和悄然消散的热情。"
} }
]) ])
@ -104,8 +110,7 @@ const handleRestart = () => {
dialogVisible2.value = false dialogVisible2.value = false
if (isResetting.value) return if (isResetting.value) return
isResetting.value = true isResetting.value = true
canSelect.value = false disableClick.value = false
cards.value.forEach(card => { cards.value.forEach(card => {
card.isFlipped = false card.isFlipped = false
}) })
@ -207,7 +212,7 @@ const handlePointsChange = async () => {
return return
} }
let response; let response;
console.log(pointChange.value + ' ' + pointChange2.value) // console.log(pointChange.value + ' ' + pointChange2.value)
if(pointChange2.value !== 0){ if(pointChange2.value !== 0){
response = await updatePoints(cardResult.value.id, pointChange2.value) response = await updatePoints(cardResult.value.id, pointChange2.value)
pointChange2.value = 0 pointChange2.value = 0
@ -221,17 +226,33 @@ const handlePointsChange = async () => {
dialogVisible.value = false dialogVisible.value = false
} }
const luckThing = () => { const luckThing = () => {
const lens = randomEvents.value.length disableClick.value = true
const randomIndex = Math.floor(Math.random() * lens); const lens = 3
currentRandomEvent.value = randomEvents.value[randomIndex] let randomIndex = Math.floor((Date.now() * Math.random()) % lens);
console.log(randomIndex)
if (randomIndex === 1) { if (randomIndex === 1) {
pointChange2.value = 10 pointChange2.value = 10
} else if (randomIndex >= 2) {
nothingToDo.value = true
randomIndex = 2
} }
currentRandomEvent.value = randomEvents.value[randomIndex]
dialogVisible2.value = true; dialogVisible2.value = true;
}; };
const handleRandomEvents = () => {
console.log(disableClick.value)
console.log()
if (!nothingToDo.value) {
handleRestart()
handlePointsChange()
} else {
dialogVisible2.value = false
nothingToDo.value = false
}
}
</script> </script>
<template> <template>
@ -319,7 +340,7 @@ const luckThing = () => {
type="primary" type="primary"
@click="luckThing" @click="luckThing"
class="round-button" class="round-button"
:disabled="disableClick"
> >
<i class="iconfont yaya-touzi" style="font-size: 24px;;" /> <i class="iconfont yaya-touzi" style="font-size: 24px;;" />
</el-button> </el-button>
@ -340,7 +361,7 @@ const luckThing = () => {
height="700px" height="700px"
:align-center="true" :align-center="true"
class="profile-dialog" class="profile-dialog"
@close="handleRestart" @close="handleRandomEvents"
> >
<div class="profile-content"> <div class="profile-content">
<!-- 显示随机事件的标题原本头像位置替换为标题 --> <!-- 显示随机事件的标题原本头像位置替换为标题 -->
@ -352,7 +373,7 @@ const luckThing = () => {
<div class="button-container"> <div class="button-container">
<el-button <el-button
type="success" type="success"
@click="handlePointsChange" @click="dialogVisible2 = false"
class="round-button" class="round-button"
> >
<i class="iconfont yaya-duigou" style="font-size: 24px;" /> <i class="iconfont yaya-duigou" style="font-size: 24px;" />

Loading…
Cancel
Save