one
This commit is contained in:
@@ -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