From 68eaf0321d89021f28d942ad993f1ac4ce187e35 Mon Sep 17 00:00:00 2001 From: p6fxi93qh <1240380517@qq.com> Date: Sat, 12 Oct 2024 22:15:44 +0800 Subject: [PATCH] Update startNaming.js --- .../pages/startNaming/startNaming.js | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/Roll_Students/pages/startNaming/startNaming.js b/Roll_Students/pages/startNaming/startNaming.js index 20ef0f3..8b0f630 100644 --- a/Roll_Students/pages/startNaming/startNaming.js +++ b/Roll_Students/pages/startNaming/startNaming.js @@ -183,16 +183,35 @@ Page({ return shuffled.slice(0, count); // 选择前 count 个学生 }, - // 浮窗4 投掷骰子 - onRollDice() { - console.log("投掷骰子按钮被点击"); - // 生成1-6随机数 - const rolledValue = Math.floor(Math.random()*6)+1; - this.setData({ - dice: rolledValue, - diceImage: `/assets/img/RollClass/RollClass5_${rolledValue}.png`, // 更新图像 - }); - }, + +onRollDice() { + console.log("投掷骰子按钮被点击"); + // 向后端发送POST请求 + wx.request({ + url: 'http://10.133.8.121:8000/choose/style/', // 替换为实际的后端URL + method: 'POST', + data: {}, + header: { + 'content-type': 'application/json' // 根据后端要求设置请求头 + }, + success: (res) => { + console.log('服务器返回的数据:', res.data); + if (res.data.number) { + // 更新骰子图像 + const rolledValue = res.data.number; + this.setData({ + dice: rolledValue, + diceImage: `/assets/img/RollClass/RollClass5_${rolledValue}.png` + }); + } else { + console.error('返回数据格式错误'); + } + }, + fail: (err) => { + console.error('请求失败:', err); + } + }); +}, // 浮窗5 加分 处理分数按钮点击 onScoreChange(event) {