one
This commit is contained in:
@@ -1,333 +1,252 @@
|
||||
<template>
|
||||
<view class="container">
|
||||
<!-- 顶部表头 -->
|
||||
<view class="table-header">
|
||||
<view class="header-player">玩家</view>
|
||||
<view class="header-result">胜负</view>
|
||||
<view class="header-score">得分</view>
|
||||
</view>
|
||||
|
||||
<!-- 玩家信息区域 -->
|
||||
<view class="player-row">
|
||||
<view class="player-info">
|
||||
<view class="player-avatar">
|
||||
<!-- 兔子头像 SVG -->
|
||||
<svg width="30" height="30" viewBox="0 0 30 30">
|
||||
<ellipse cx="15" cy="20" rx="9" ry="6" fill="#ffffff"/>
|
||||
<circle cx="15" cy="12" r="7" fill="#ffffff"/>
|
||||
<ellipse cx="12" cy="8" rx="2" ry="4" fill="#ffffff"/>
|
||||
<ellipse cx="18" cy="8" rx="2" ry="4" fill="#ffffff"/>
|
||||
<ellipse cx="12" cy="8" rx="1" ry="3" fill="#ffb6c1"/>
|
||||
<ellipse cx="18" cy="8" rx="1" ry="3" fill="#ffb6c1"/>
|
||||
<circle cx="13" cy="12" r="1" fill="#333333"/>
|
||||
<circle cx="17" cy="12" r="1" fill="#333333"/>
|
||||
<circle cx="15" cy="14" r="0.8" fill="#ff69b4"/>
|
||||
<path d="M14,16 Q15,17 16,16" stroke="#ff69b4" stroke-width="0.5" fill="none"/>
|
||||
<circle cx="11" cy="13" r="1.5" fill="#ffb6c1" opacity="0.6"/>
|
||||
<circle cx="19" cy="13" r="1.5" fill="#ffb6c1" opacity="0.6"/>
|
||||
<rect x="10" cy="19" width="10" height="4" fill="#4169e1" rx="1"/>
|
||||
<circle cx="20" cy="21" r="2" fill="#ffd700"/>
|
||||
</svg>
|
||||
</view>
|
||||
<text class="player-name">玩家59306</text>
|
||||
</view>
|
||||
|
||||
<view class="result-buttons">
|
||||
<view
|
||||
class="result-btn"
|
||||
:class="{ active: result === 'win' }"
|
||||
@tap="setResult('win')"
|
||||
>胜</view>
|
||||
<view
|
||||
class="result-btn"
|
||||
:class="{ active: result === 'lose' }"
|
||||
@tap="setResult('lose')"
|
||||
>负</view>
|
||||
</view>
|
||||
|
||||
<view class="score-display">
|
||||
<text class="score-value">{{ score }}</text>
|
||||
<button class="sum-btn" @tap="sumScore">Σ 合分</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
<!-- 固定在底部的数字键盘 -->
|
||||
<view class="keyboard">
|
||||
<view
|
||||
v-for="key in keys"
|
||||
:key="key.value"
|
||||
class="key"
|
||||
:class="{
|
||||
'operator': key.type === 'operator',
|
||||
'minus': key.value === '-',
|
||||
'submit-key': key.type === 'submit'
|
||||
}"
|
||||
@tap="pressKey(key.value, key.type)"
|
||||
>{{ key.display }}</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="compute">
|
||||
<view class="compute-lan">
|
||||
<text class="player">玩家</text>
|
||||
<text class="vd">胜负</text>
|
||||
<text class="score">得分</text>
|
||||
</view>
|
||||
<view
|
||||
class="compute-detail"
|
||||
v-for="(item,index) in players1"
|
||||
:key="usersData.useId"
|
||||
>
|
||||
<view class="compute-detail-player">
|
||||
<image :src='item.avatars' mode="widthFix"></image>
|
||||
<text>{{item.nickName}}</text>
|
||||
</view>
|
||||
<view class="compute-detail-vd">
|
||||
<view
|
||||
class="result-btn"
|
||||
:class="{ active: item.result === 'win' }"
|
||||
@tap="setResult(index, 'win')"
|
||||
>胜</view>
|
||||
<view
|
||||
class="result-btn"
|
||||
:class="{ active: item.result === 'lose' }"
|
||||
@tap="setResult(index,'lose')"
|
||||
>负</view>
|
||||
</view>
|
||||
<view class="compute-detail-score">
|
||||
<input
|
||||
class="score-input"
|
||||
:class="item.result === 'win' ? 'positive' : 'negative'"
|
||||
v-model="item.score"
|
||||
@input="validateScore(index)"
|
||||
placeholder="0"
|
||||
type="number" />
|
||||
</view>
|
||||
</view>
|
||||
<view class="">
|
||||
{{round1}}
|
||||
</view>
|
||||
|
||||
<button @click="onsubmit()">
|
||||
提交
|
||||
</button>
|
||||
</view>
|
||||
</template>
|
||||
|
||||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { onMounted, ref, computed } from 'vue';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
|
||||
const result = ref('win');
|
||||
const score = ref('0');
|
||||
const players1 = ref([]);
|
||||
const round1 = ref();
|
||||
//存储当前局每个玩家的得分
|
||||
const currentScores = ref([]);
|
||||
|
||||
// 键盘布局 - 提交按钮在0的左侧
|
||||
const keys = [
|
||||
{ value: '1', display: '1', type: 'number' },
|
||||
{ value: '2', display: '2', type: 'number' },
|
||||
{ value: '3', display: '3', type: 'number' },
|
||||
{ value: '+', display: '+', type: 'operator' },
|
||||
{ value: '×', display: '×', type: 'delete' },
|
||||
{ value: '4', display: '4', type: 'number' },
|
||||
{ value: '5', display: '5', type: 'number' },
|
||||
{ value: '6', display: '6', type: 'number' },
|
||||
{ value: '-', display: '-', type: 'operator' },
|
||||
{ value: '√', display: '√', type: 'operator' },
|
||||
{ value: '7', display: '7', type: 'number' },
|
||||
{ value: '8', display: '8', type: 'number' },
|
||||
{ value: '9', display: '9', type: 'number' },
|
||||
{ value: 'submit', display: '提交', type: 'submit' }, // 提交按钮在0的左侧
|
||||
{ value: '0', display: '0', type: 'number' }
|
||||
];
|
||||
//设置胜负结果
|
||||
const setResult = (index, result) => {
|
||||
players1.value[index].result = result;
|
||||
//如果有分数则进行跳转
|
||||
if(players1.value[index].score) {
|
||||
validateScore(index);
|
||||
}
|
||||
}
|
||||
|
||||
const setResult = (res) => {
|
||||
result.value = res;
|
||||
};
|
||||
//分数输入验证
|
||||
const validateScore = (index) => {
|
||||
const player = players1.value[index];
|
||||
const score = parseFloat(player.score);
|
||||
//检验是否为有效数字
|
||||
if (isNaN(score)) {
|
||||
player.score = '';
|
||||
return;
|
||||
}
|
||||
//根据胜负结果调整分数
|
||||
if (player.result === 'win' && score <0) {
|
||||
player.score = Math.abs(score).toString();
|
||||
} else if (player.result === 'lose' && score >0) {
|
||||
player.score = (-score).toString();
|
||||
}
|
||||
}
|
||||
|
||||
const pressKey = (key, type) => {
|
||||
if (type === 'submit') {
|
||||
// 提交分数
|
||||
if (score.value !== '0') {
|
||||
uni.showToast({
|
||||
title: `分数 ${score.value} 已提交`,
|
||||
icon: 'success'
|
||||
// 计算最大局数(确保表头列数正确)
|
||||
const maxRounds = computed(() => {
|
||||
if (!players1.value.length) return 0;
|
||||
let max = 0;
|
||||
players1.value.forEach(user => {
|
||||
if (user.details && user.details.length > 0) {
|
||||
user.details.forEach(detail => {
|
||||
if (detail.gameTime > max) max = detail.gameTime;
|
||||
});
|
||||
|
||||
// 实际应用中,这里应该调用API提交分数
|
||||
console.log('提交分数:', score.value);
|
||||
|
||||
// 重置分数
|
||||
setTimeout(() => {
|
||||
score.value = '0';
|
||||
}, 1500);
|
||||
}
|
||||
} else if (key === '×') {
|
||||
// 删除最后一个字符
|
||||
if (score.value.length > 1) {
|
||||
score.value = score.value.slice(0, -1);
|
||||
} else {
|
||||
score.value = '0';
|
||||
}
|
||||
} else if (key === '√') {
|
||||
// 计算平方根
|
||||
try {
|
||||
const result = Math.sqrt(parseFloat(score.value));
|
||||
score.value = result.toString();
|
||||
} catch (error) {
|
||||
score.value = '错误';
|
||||
setTimeout(() => {
|
||||
score.value = '0';
|
||||
}, 1000);
|
||||
}
|
||||
} else {
|
||||
// 添加数字或运算符
|
||||
if (score.value === '0') {
|
||||
score.value = key;
|
||||
} else {
|
||||
score.value += key;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const sumScore = () => {
|
||||
uni.showToast({
|
||||
title: '合分功能需要与后端API交互',
|
||||
icon: 'none'
|
||||
});
|
||||
};
|
||||
return max;
|
||||
});
|
||||
|
||||
|
||||
|
||||
onMounted( () => {
|
||||
|
||||
})
|
||||
|
||||
onLoad((options) => {
|
||||
try {
|
||||
const rawData = JSON.parse(decodeURIComponent(options.players));
|
||||
// players1.value = JSON.parse(decodeURIComponent(options.players));
|
||||
round1.value = JSON.parse(decodeURIComponent(options.round));
|
||||
|
||||
console.log("round:",round1.value);
|
||||
players1.value = rawData.map(player => ({
|
||||
...player,
|
||||
result: "win",
|
||||
score: "",
|
||||
gameTime: round1.value,
|
||||
}))
|
||||
|
||||
|
||||
// console.log('数据已更新:', updataScore);
|
||||
}
|
||||
|
||||
|
||||
// console.log('数据已更新:', rawData);
|
||||
catch (error) {
|
||||
console.error('解析失败:', error);
|
||||
players1.value = []; // 确保是数组
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
const onsubmit = async () => {
|
||||
const updataScore = players1.value.map(updata => ({
|
||||
roomId: updata.roomId,
|
||||
userId: updata.userId,
|
||||
score: updata.score,
|
||||
}))
|
||||
|
||||
console.log("输入框的值:",updataScore);
|
||||
|
||||
}
|
||||
|
||||
const usersData = ref([
|
||||
{
|
||||
id: 1,
|
||||
nickName: '玩家12324',
|
||||
image: 'https://img1.baidu.com/it/u=3612220943,2414740890&fm=253&app=138&f=JPEG?w=526&h=500',
|
||||
result: 'win',
|
||||
score: '',
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
nickName: '赵云',
|
||||
image: 'https://q3.itc.cn/q_70/images03/20250110/1e71eecf56b34344bcae6a5b85c0bec2.jpeg',
|
||||
result: 'win',
|
||||
score: '',
|
||||
},
|
||||
{
|
||||
id: 3,
|
||||
nickName: '刘备',
|
||||
image: 'https://q3.itc.cn/q_70/images03/20250110/1e71eecf56b34344bcae6a5b85c0bec2.jpeg',
|
||||
result: 'win',
|
||||
score: '',
|
||||
}
|
||||
])
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.container {
|
||||
min-height: 100vh;
|
||||
background-color: #f5f5f5;
|
||||
padding-bottom: 240rpx; /* 为底部键盘留出空间 */
|
||||
<style scoped lang="less">
|
||||
.compute{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.compute-lan{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
height: 80rpx;
|
||||
padding: 0 15rpx;
|
||||
border-bottom: 1px solid #eee;
|
||||
.player{
|
||||
margin-right: 270rpx;
|
||||
}
|
||||
.vd{
|
||||
margin-right: 210rpx;
|
||||
}
|
||||
}
|
||||
.compute-detail{
|
||||
display: flex;
|
||||
padding: 20rpx 0;
|
||||
align-items: center;
|
||||
margin-top: 10rpx;
|
||||
.compute-detail-player{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 230rpx;
|
||||
text{
|
||||
font-size: 27rpx;
|
||||
}
|
||||
image{
|
||||
width: 70rpx;
|
||||
padding: 0 16rpx;
|
||||
}
|
||||
}
|
||||
.compute-detail-vd{
|
||||
display: flex;
|
||||
align-items: center;
|
||||
width: 200rpx;
|
||||
padding-left: 50rpx;
|
||||
.result-btn {
|
||||
flex: 1;
|
||||
padding: 12rpx 0;
|
||||
text-align: center;
|
||||
font-size: 28rpx;
|
||||
border-radius: 6rpx;
|
||||
}
|
||||
|
||||
.result-btn.active {
|
||||
background-color:rgb(55, 47, 172);
|
||||
color: white;
|
||||
}
|
||||
}
|
||||
.compute-detail-score{
|
||||
padding-left: 133rpx;
|
||||
.score-input{
|
||||
width: 50rpx;
|
||||
border-radius: 10rpx;
|
||||
border: 1px solid #eee;
|
||||
padding-left: 30rpx;
|
||||
}
|
||||
.score-input.positive {
|
||||
border-color: #4caf50;
|
||||
background-color: rgba(76, 175, 80, 0.05);
|
||||
}
|
||||
|
||||
.score-input.negative {
|
||||
border-color: #f44336;
|
||||
background-color: rgba(244, 67, 54, 0.05);
|
||||
}
|
||||
}
|
||||
}
|
||||
button{
|
||||
position: fixed;
|
||||
bottom: 40rpx;
|
||||
left: 0;
|
||||
right: 0;
|
||||
border-radius: 15rpx;
|
||||
background-color: rgb(55, 47, 172);
|
||||
color: #fff;
|
||||
// margin-top: 30rpx;
|
||||
// margin-left: 450rpx;
|
||||
width: 650rpx;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* 顶部表头 */
|
||||
.table-header {
|
||||
display: flex;
|
||||
background-color: white;
|
||||
padding: 30rpx 40rpx;
|
||||
border-bottom: 1px solid #e0e0e0;
|
||||
position: sticky;
|
||||
top: 0;
|
||||
z-index: 10;
|
||||
}
|
||||
|
||||
.header-player {
|
||||
flex: 1;
|
||||
font-size: 32rpx;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.header-result {
|
||||
width: 200rpx;
|
||||
font-size: 32rpx;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.header-score {
|
||||
width: 200rpx;
|
||||
font-size: 32rpx;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/* 玩家信息区域 */
|
||||
.player-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
padding: 30rpx 40rpx;
|
||||
border-bottom: 1px solid #f5f5f5;
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
.player-info {
|
||||
flex: 1;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.player-avatar {
|
||||
width: 80rpx;
|
||||
height: 80rpx;
|
||||
border-radius: 16rpx;
|
||||
background-color: #1e3a8a;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
margin-right: 20rpx;
|
||||
}
|
||||
|
||||
.player-name {
|
||||
font-size: 32rpx;
|
||||
color: #333;
|
||||
}
|
||||
|
||||
.result-buttons {
|
||||
width: 200rpx;
|
||||
display: flex;
|
||||
background-color: #f0f0f0;
|
||||
border-radius: 8rpx;
|
||||
padding: 4rpx;
|
||||
}
|
||||
|
||||
.result-btn {
|
||||
flex: 1;
|
||||
padding: 12rpx 0;
|
||||
text-align: center;
|
||||
font-size: 28rpx;
|
||||
border-radius: 6rpx;
|
||||
}
|
||||
|
||||
.result-btn.active {
|
||||
background-color: #6a5acd;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.score-display {
|
||||
width: 200rpx;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.score-value {
|
||||
font-size: 36rpx;
|
||||
color: #333;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.sum-btn {
|
||||
background-color: #6a5acd;
|
||||
color: white;
|
||||
border: none;
|
||||
border-radius: 8rpx;
|
||||
padding: 12rpx 20rpx;
|
||||
font-size: 28rpx;
|
||||
}
|
||||
|
||||
/* 固定在底部的数字键盘 */
|
||||
.keyboard {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(5, 1fr);
|
||||
gap: 1px;
|
||||
background-color: #e0e0e0;
|
||||
padding: 1px;
|
||||
position: fixed;
|
||||
bottom: 0;
|
||||
left: 0;
|
||||
right: 0;
|
||||
max-width: 750rpx;
|
||||
margin: 0 auto;
|
||||
}
|
||||
|
||||
.key {
|
||||
background-color: white;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 120rpx;
|
||||
font-size: 40rpx;
|
||||
}
|
||||
|
||||
.key:active {
|
||||
background-color: #f0f0f0;
|
||||
}
|
||||
|
||||
.operator {
|
||||
color: #6a5acd;
|
||||
}
|
||||
|
||||
.minus {
|
||||
color: #ff4757;
|
||||
}
|
||||
|
||||
.submit-key {
|
||||
background-color: #8a2be2;
|
||||
color: white;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
/* 调整键盘布局,使提交按钮在0的左侧 */
|
||||
.keyboard {
|
||||
grid-template-areas:
|
||||
"num1 num2 num3 plus delete"
|
||||
"num4 num5 num6 minus sqrt"
|
||||
"num7 num8 num9 submit num0";
|
||||
}
|
||||
|
||||
.key:nth-child(1) { grid-area: num1; }
|
||||
.key:nth-child(2) { grid-area: num2; }
|
||||
.key:nth-child(3) { grid-area: num3; }
|
||||
.key:nth-child(4) { grid-area: plus; }
|
||||
.key:nth-child(5) { grid-area: delete; }
|
||||
.key:nth-child(6) { grid-area: num4; }
|
||||
.key:nth-child(7) { grid-area: num5; }
|
||||
.key:nth-child(8) { grid-area: num6; }
|
||||
.key:nth-child(9) { grid-area: minus; }
|
||||
.key:nth-child(10) { grid-area: sqrt; }
|
||||
.key:nth-child(11) { grid-area: num7; }
|
||||
.key:nth-child(12) { grid-area: num8; }
|
||||
.key:nth-child(13) { grid-area: num9; }
|
||||
.key:nth-child(14) { grid-area: submit; }
|
||||
.key:nth-child(15) { grid-area: num0; }
|
||||
</style>
|
||||
@@ -62,6 +62,10 @@
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
<view class="">
|
||||
{{roomData}}
|
||||
|
||||
</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -69,8 +73,47 @@
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue'
|
||||
import { getOpenId } from '@/utils/wxutils.js'
|
||||
import { GET, POST } from '../../utils/request'
|
||||
import StaticValue from '@/utils/StaticValue.js';
|
||||
const loading = ref(false);
|
||||
//定义承接本地用户信息对象
|
||||
const roomData = ref([]);
|
||||
|
||||
const gotoNewPage = () => {
|
||||
onMounted(() => {
|
||||
const getUserInfo = StaticValue.getUserInfo;
|
||||
roomData.value = getUserInfo();
|
||||
})
|
||||
|
||||
|
||||
const gotoNewPage = async () => {
|
||||
//判断有无历史房间记录
|
||||
const response = await GET('/system/room/createUser/'+ roomData.value.userId);
|
||||
//检查是否请求成功
|
||||
if (response.code = 200) {
|
||||
//检查数组是否有对象
|
||||
const dataArray = response.data;
|
||||
if (dataArray && dataArray.length > 0) {
|
||||
console.log(`查询到 ${dataArray.length} 条房间记录`);
|
||||
|
||||
} else {
|
||||
// 数据条数为0,执行B方法
|
||||
console.log('未查询到房间记录,新建个人房间');
|
||||
//创建新房间
|
||||
POST('/system/room', {
|
||||
createUser: roomData.value.userId,
|
||||
odds: 1,
|
||||
roomStatus: 1,
|
||||
bossId: roomData.value.userId,
|
||||
roomName: `${roomData.value.nickName}的房间`,
|
||||
});
|
||||
}
|
||||
} else {
|
||||
console.error('接口请求失败:', response.msg);
|
||||
uni.showToast({
|
||||
title: '查询失败',
|
||||
icon: 'none'
|
||||
});
|
||||
}
|
||||
wx.navigateTo({
|
||||
url: '/pages/single/single'
|
||||
})
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
<view class="info-content">
|
||||
<view class="top-user-name" :style="{'height': topHeight, 'line-height': topHeight}">
|
||||
{{userInfo.nickName}}
|
||||
|
||||
</view>
|
||||
<view class="avatars">
|
||||
<image class="avatar-img" :src="userInfo.avatarUrl ? userInfo.avatarUrl : 'https://pic.rmb.bdstatic.com/bjh/down/1742bc3845cbbcf0c78c01eb59bb1c1a.jpeg'"></image>
|
||||
|
||||
@@ -22,32 +22,37 @@
|
||||
<text class="sing-detail-title">对局记录</text>
|
||||
<text>点击对局分数进行修改</text>
|
||||
</view>
|
||||
<view class="single-score">
|
||||
|
||||
|
||||
<scroll-view class="single-score" scroll-x="true" >
|
||||
<text style="color: red;" class="score-remind">
|
||||
点击头像编辑自己的昵称和性别~
|
||||
</text>
|
||||
<view class="single-score-record">
|
||||
<view class="score-record-player">
|
||||
<text class="score-head">玩家</text>
|
||||
<view v-for="(item,index) in players" :key="index" class="player" @click="gotoNewPage">
|
||||
<image :src="item.avatar" mode="widthFix"></image>
|
||||
<text>{{item.name}}</text>
|
||||
</view>
|
||||
<view class="tab-head">
|
||||
<text class="tab-head-player">玩家</text>
|
||||
<text class="tab-head-total">总分</text>
|
||||
<view class="tab-head-detail" v-for="n in maxRounds" :key="n">
|
||||
第{{n}}局
|
||||
</view>
|
||||
<view class="score-record-all">
|
||||
<text class="score-head">总分</text>
|
||||
<view class="all-score" v-for="(item,index) in allscores" :key="item.id">
|
||||
{{item.allscore}}
|
||||
</view>
|
||||
</view>
|
||||
<view v-for="(item,index) in userScores" :key="item.userId" class="tab-body">
|
||||
<view class="tab-body-player">
|
||||
<image :src=item.avatars mode="widthFix"></image>
|
||||
<text>{{item.nickName}}</text>
|
||||
</view>
|
||||
<view class="score-record-all" v-for="match in matchs" :key="match.id">
|
||||
<text class="score-head">第{{match.gametime}}局</text>
|
||||
<view class="all-score" v-for="(item,index) in match.details" :key="item.id">
|
||||
{{item.score}}
|
||||
</view>
|
||||
<view class="tab-total-score">
|
||||
{{formatScore(item.totalScore)}}
|
||||
</view>
|
||||
<view v-for="detail in item.details" :key="detail.gameTime" class="round-score">
|
||||
{{formatScore(detail.detailScore)}}
|
||||
</view>
|
||||
</view>
|
||||
{{userScores}}
|
||||
</view>
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
|
||||
<view class="single-bottom">
|
||||
<button
|
||||
style="color: aliceblue;
|
||||
@@ -88,12 +93,12 @@
|
||||
</view>
|
||||
<view class="line"></view>
|
||||
<view class="lan-input">
|
||||
<uni-easyinput v-model="value" placeholder="请输入名称" style="width: 500rpx;"></uni-easyinput>
|
||||
<uni-easyinput v-model="newPlayerName" placeholder="请输入名称" style="width: 500rpx;" @confirm="confirmAddPlayer"></uni-easyinput>
|
||||
</view>
|
||||
|
||||
<view class="lan-button">
|
||||
<button @click="closevirtue">取消</button>
|
||||
<button @click="closevirtue">确定</button>
|
||||
<button @click="confirmAddPlayer">确定</button>
|
||||
</view>
|
||||
</view>
|
||||
</l-popup>
|
||||
@@ -113,10 +118,143 @@
|
||||
</view>
|
||||
</view>
|
||||
</l-popup>
|
||||
<!-- 加载提示 -->
|
||||
<uni-load-more v-if="isLoading" status="loading" />
|
||||
</view>
|
||||
</template>
|
||||
<script setup>
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { ref, onMounted, computed} from 'vue';
|
||||
import { GET, POST } from '../../utils/request';
|
||||
import { onLoad } from '@dcloudio/uni-app';
|
||||
import StaticValue from '@/utils/StaticValue.js';
|
||||
//获取本地用户数据
|
||||
|
||||
const roomData = ref([]);
|
||||
|
||||
//加载动画
|
||||
const isLoading = ref(false);
|
||||
//添加玩家输入框
|
||||
const newPlayerName = ref('');
|
||||
//接收后端返回的表格数组
|
||||
const userScores = ref([]);
|
||||
|
||||
//确认添加玩家按钮
|
||||
const confirmAddPlayer = async () => {
|
||||
|
||||
//拿到本地用户所在的房间id
|
||||
const response = await GET('/system/room/createUser/'+ roomData.value.userId);
|
||||
//show信息
|
||||
console.log(response);
|
||||
if (response.code === 200) {
|
||||
uni.showToast({
|
||||
title: '查询roomId成功',
|
||||
icon: 'success'
|
||||
});
|
||||
|
||||
const dataArray = response.data;
|
||||
console.log('dataArray.roomId:', dataArray[0].roomId);
|
||||
// 使用 trim() 去除前后空格
|
||||
const trimmedName = newPlayerName.value.trim();
|
||||
|
||||
const userData = {
|
||||
nickName: trimmedName, // 使用 trim() 处理后的名称
|
||||
avatars: "https://img1.baidu.com/it/u=3612220943,2414740890&fm=253&app=138&f=JPEG?w=526&h=500",
|
||||
openId: generateTenDigitRandom().toString(),
|
||||
};
|
||||
|
||||
const userResponse = await POST('/system/score/user/add', userData);
|
||||
|
||||
if (userResponse.code === 200) {
|
||||
// 关键修改:正确获取后端返回的userId
|
||||
const userId1 = userResponse.data.userId; // 从响应数据的data中获取
|
||||
|
||||
console.log('新创建的用户ID:', userId1);
|
||||
|
||||
// 2. 然后插入 score_room_user 表
|
||||
const roomUserData = {
|
||||
roomId: dataArray[0].roomId,
|
||||
userId: userId1, // 使用后端返回的userId
|
||||
totalScore: 0,
|
||||
playerType: 'robot',
|
||||
nickName: trimmedName,
|
||||
avatars: "https://img1.baidu.com/it/u=3612220943,2414740890&fm=253&app=138&f=JPEG?w=526&h=500",
|
||||
};
|
||||
//插入room_user表中
|
||||
const response = await POST('/system/score/room/user', roomUserData);
|
||||
console.log("返回结果: ", response)
|
||||
if (response.code === 200) {
|
||||
// 2. 插入成功后立即刷新数据
|
||||
fetchUserScores();
|
||||
console.log('添加新玩家成功');
|
||||
uni.showToast({
|
||||
title: '添加成功,数据已更新',
|
||||
icon: 'success'
|
||||
});
|
||||
}
|
||||
virtueplayer.value = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 生成10位随机数(范围:1000000000 - 9999999999)
|
||||
function generateTenDigitRandom() {
|
||||
return Math.floor(Math.random() * 9000000000) + 1000000000;
|
||||
}
|
||||
|
||||
// 计算最大局数(确保表头列数正确)
|
||||
const maxRounds = computed(() => {
|
||||
if (!userScores.value.length) return 0;
|
||||
let max = 0;
|
||||
userScores.value.forEach(user => {
|
||||
if (user.details && user.details.length > 0) {
|
||||
user.details.forEach(detail => {
|
||||
if (detail.gameTime > max) max = detail.gameTime;
|
||||
});
|
||||
}
|
||||
});
|
||||
return max;
|
||||
});
|
||||
|
||||
const round = computed(() => {
|
||||
const rounds = maxRounds.value;
|
||||
return isNaN(rounds) ? 0 : Math.max(0, rounds + 1);
|
||||
});
|
||||
console.log("round:",round);
|
||||
// 分数格式化
|
||||
const formatScore = (score) => {
|
||||
return score > 0 ? `+${score}` : `${score}`;
|
||||
};
|
||||
|
||||
// 获取分数数据的函数
|
||||
const fetchUserScores = async () => {
|
||||
try {
|
||||
//拿到本地用户所在的房间id
|
||||
const response2 = await GET('/system/room/createUser/'+ roomData.value.userId);
|
||||
//show信息
|
||||
console.log(response2);
|
||||
|
||||
const dataArray1 = response2.data;
|
||||
console.log('房间号为:', dataArray1[0].roomId);
|
||||
var roomId1 = dataArray1[0].roomId;
|
||||
|
||||
const response3 = await GET(`/system/score/room/user/user-details/${roomId1}`);
|
||||
if (response3.code === 200) {
|
||||
userScores.value = response3.data;
|
||||
|
||||
console.log('用户得分数据加载成功');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取用户得分失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
onMounted(() => {
|
||||
const getUserInfo = StaticValue.getUserInfo;
|
||||
roomData.value = getUserInfo();
|
||||
fetchUserScores();
|
||||
console.log("userScores为:",userScores);
|
||||
})
|
||||
|
||||
//跳转至user-detail
|
||||
const gotoNewPage = () => {
|
||||
wx.navigateTo({
|
||||
@@ -126,8 +264,14 @@ const gotoNewPage = () => {
|
||||
|
||||
//跳转至compute
|
||||
const gotoNewPage1 = () => {
|
||||
const roomUserData1 = ref(userScores);
|
||||
|
||||
|
||||
const encodedPlayers = encodeURIComponent(JSON.stringify(roomUserData1.value));
|
||||
const encodedRound = encodeURIComponent(JSON.stringify(round.value));
|
||||
|
||||
wx.navigateTo({
|
||||
url: '/pages/compute/compute'
|
||||
url: `/pages/compute/compute?players=${encodedPlayers}&round=${encodedRound}`
|
||||
})
|
||||
}
|
||||
|
||||
@@ -177,60 +321,63 @@ const closemultiple = ()=>{
|
||||
isPopupVisible2.value = false;
|
||||
}
|
||||
|
||||
const matchs = ref([
|
||||
{
|
||||
id: 1,
|
||||
gametime: 1,
|
||||
details: [
|
||||
{id: 101, score: "+"+10},
|
||||
{id: 102, score: "+"+20},
|
||||
{id: 103, score: "-"+30}
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
gametime: 2,
|
||||
details: [
|
||||
{id: 201, score: "+"+10},
|
||||
{id: 202, score: "+"+20},
|
||||
{id: 203, score: "-"+30}
|
||||
]
|
||||
}
|
||||
])
|
||||
// const matchs = ref([
|
||||
// {
|
||||
// id: 1,
|
||||
// gametime: 1,
|
||||
// details: [
|
||||
// {id: 101, score: "+"+10},
|
||||
// {id: 102, score: "+"+20},
|
||||
// {id: 103, score: "-"+30}
|
||||
// ],
|
||||
// },
|
||||
// {
|
||||
// id: 2,
|
||||
// gametime: 2,
|
||||
// details: [
|
||||
// {id: 201, score: "+"+10},
|
||||
// {id: 202, score: "+"+20},
|
||||
// {id: 203, score: "-"+30}
|
||||
// ]
|
||||
// }
|
||||
// ])
|
||||
|
||||
const allscores = ref([
|
||||
{
|
||||
id: 301,
|
||||
allscore: "+"+ 20,
|
||||
},
|
||||
{
|
||||
id: 302,
|
||||
allscore: "+"+ 40,
|
||||
},
|
||||
{ id: 303,
|
||||
allscore: "-"+ 60,
|
||||
}
|
||||
])
|
||||
// const allscores = ref([
|
||||
// {
|
||||
// id: 301,
|
||||
// allscore: "+"+ 20,
|
||||
// },
|
||||
// {
|
||||
// id: 302,
|
||||
// allscore: "+"+ 40,
|
||||
// },
|
||||
// { id: 303,
|
||||
// allscore: "-"+ 60,
|
||||
// }
|
||||
// ])
|
||||
// const details = ref(
|
||||
// score[1,2,3]
|
||||
// )
|
||||
const players = ref([
|
||||
{
|
||||
id: 401,
|
||||
name: '刘备',
|
||||
avatar: 'https://img1.baidu.com/it/u=3612220943,2414740890&fm=253&app=138&f=JPEG?w=526&h=500'
|
||||
},
|
||||
{
|
||||
id: 401,
|
||||
name: "赵云",
|
||||
avatar: 'https://q3.itc.cn/q_70/images03/20250110/1e71eecf56b34344bcae6a5b85c0bec2.jpeg'
|
||||
},
|
||||
{
|
||||
id: 401,
|
||||
name: "张飞",
|
||||
avatar: 'https://q1.itc.cn/q_70/images03/20241119/197701bb9ef34b20b6497720081a9972.jpeg'
|
||||
}
|
||||
])
|
||||
// const players = ref([
|
||||
// {
|
||||
// id: 401,
|
||||
// name: '刘备',
|
||||
// avatar: 'https://img1.baidu.com/it/u=3612220943,2414740890&fm=253&app=138&f=JPEG?w=526&h=500',
|
||||
// playerType: 'user'
|
||||
// },
|
||||
// {
|
||||
// id: 401,
|
||||
// name: "赵云",
|
||||
// avatar: 'https://q3.itc.cn/q_70/images03/20250110/1e71eecf56b34344bcae6a5b85c0bec2.jpeg',
|
||||
// playerType: 'user'
|
||||
// },
|
||||
// {
|
||||
// id: 401,
|
||||
// name: "张飞",
|
||||
// avatar: 'https://q1.itc.cn/q_70/images03/20241119/197701bb9ef34b20b6497720081a9972.jpeg',
|
||||
// playerType: 'user'
|
||||
// }
|
||||
// ])
|
||||
|
||||
</script>
|
||||
|
||||
@@ -288,6 +435,64 @@ const players = ref([
|
||||
padding-top: 20rpx;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
.single-score-record{
|
||||
display: flex;
|
||||
margin-top: 20rpx;
|
||||
.tab-head{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
margin-left: 20rpx;
|
||||
margin-right: 30rpx;
|
||||
width: 100rpx;
|
||||
align-items: center;
|
||||
.tab-head-player{
|
||||
padding-top: 30rpx;
|
||||
height: 90rpx;
|
||||
width: 100rpx;
|
||||
|
||||
}
|
||||
.tab-head-total{
|
||||
padding-top: 20rpx;
|
||||
width: 100rpx;
|
||||
}
|
||||
.tab-head-detail{
|
||||
margin-top: 60rpx;
|
||||
width: 100rpx;
|
||||
}
|
||||
}
|
||||
.tab-body{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-right: 60rpx;
|
||||
.tab-body-player{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
height: 120rpx;
|
||||
width: 100rpx;
|
||||
image{
|
||||
width: 80rpx;
|
||||
}
|
||||
text{
|
||||
font-size: 30rpx;
|
||||
}
|
||||
}
|
||||
.tab-total-score{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-top: 20rpx;
|
||||
}
|
||||
.round-score{
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
margin-top: 60rpx;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.score-remind{
|
||||
align-self: center;
|
||||
font-size: 29rpx;
|
||||
|
||||
Reference in New Issue
Block a user