one version
This commit is contained in:
@@ -45,10 +45,10 @@
|
||||
{{formatScore(item.totalScore)}}
|
||||
</view>
|
||||
<view v-for="detail in item.details" :key="detail.gameTime" class="round-score">
|
||||
{{formatScore(detail.detailScore)}}
|
||||
{{detail.detailScore}}
|
||||
</view>
|
||||
</view>
|
||||
{{userScores}}
|
||||
<!-- {{userScores}} -->
|
||||
</view>
|
||||
</scroll-view>
|
||||
|
||||
@@ -109,12 +109,12 @@
|
||||
</view>
|
||||
<view class="line"></view>
|
||||
<view class="lan-input">
|
||||
<uni-easyinput v-model="value" placeholder="请输入倍率" style="width: 400rpx;"></uni-easyinput>
|
||||
<uni-easyinput v-model="oddvalue" placeholder="请输入倍率" style="width: 400rpx;"></uni-easyinput>
|
||||
</view>
|
||||
|
||||
<view class="lan-button">
|
||||
<button @click="closemultiple">取消</button>
|
||||
<button @click="closemultiple">确定</button>
|
||||
<button @click="overmultiple">确定</button>
|
||||
</view>
|
||||
</view>
|
||||
</l-popup>
|
||||
@@ -144,56 +144,70 @@ 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(round.value < 2){
|
||||
if (response.code === 200) {
|
||||
// 2. 插入成功后立即刷新数据
|
||||
fetchUserScores();
|
||||
console.log('添加新玩家成功');
|
||||
uni.showToast({
|
||||
title: '添加成功,数据已更新',
|
||||
icon: 'success'
|
||||
});
|
||||
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://q3.itc.cn/q_70/images03/20250110/1e71eecf56b34344bcae6a5b85c0bec2.jpeg",
|
||||
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://q3.itc.cn/q_70/images03/20250110/1e71eecf56b34344bcae6a5b85c0bec2.jpeg",
|
||||
};
|
||||
|
||||
|
||||
//插入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;
|
||||
}
|
||||
|
||||
}
|
||||
virtueplayer.value = false;
|
||||
}
|
||||
}
|
||||
else{
|
||||
console.log("游戏已开始,不可添加新玩家:",round.value);
|
||||
uni.showToast({
|
||||
title: '游戏已开始',
|
||||
icon: 'error'
|
||||
});
|
||||
virtueplayer.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
// 生成10位随机数(范围:1000000000 - 9999999999)
|
||||
@@ -219,7 +233,8 @@ 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}`;
|
||||
@@ -228,15 +243,15 @@ const formatScore = (score) => {
|
||||
// 获取分数数据的函数
|
||||
const fetchUserScores = async () => {
|
||||
try {
|
||||
//拿到本地用户所在的房间id
|
||||
const response2 = await GET('/system/room/createUser/'+ roomData.value.userId);
|
||||
//拿到本地用户所在的房间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;
|
||||
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;
|
||||
@@ -252,9 +267,43 @@ onMounted(() => {
|
||||
const getUserInfo = StaticValue.getUserInfo;
|
||||
roomData.value = getUserInfo();
|
||||
fetchUserScores();
|
||||
console.log("userScores为:",userScores);
|
||||
|
||||
reSubmitGet();
|
||||
})
|
||||
|
||||
const reSubmitGet = async () => {
|
||||
//拿到本地用户所在的房间id
|
||||
const response2 = await GET('/system/room/createUser/'+ roomData.value.userId);
|
||||
//show信息
|
||||
|
||||
const dataArray1 = response2.data;
|
||||
console.log('当前房间号为:', dataArray1[0].roomId);
|
||||
var roomId1 = dataArray1[0].roomId;
|
||||
|
||||
//再次发送get请求,拿到当前roomId
|
||||
const response4 = await GET('/system/score/room/user/list',{
|
||||
roomId: roomId1,
|
||||
userId: roomData.value.userId,
|
||||
});
|
||||
|
||||
console.log("response4:",response4.rows.length);
|
||||
if(response4.rows.length === 0)
|
||||
{
|
||||
const addlocaluser = await POST('/system/score/room/user',{
|
||||
roomId: roomId1,
|
||||
userId: roomData.value.userId,
|
||||
totalScore: '0',
|
||||
playerType: 'user',
|
||||
nickName:'孤心',
|
||||
avatars: 'https://img1.baidu.com/it/u=3612220943,2414740890&fm=253&app=138&f=JPEG?w=526&h=500',
|
||||
})
|
||||
console.log("addlocaluser:",addlocaluser);
|
||||
fetchUserScores();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
//跳转至user-detail
|
||||
const gotoNewPage = () => {
|
||||
wx.navigateTo({
|
||||
@@ -314,6 +363,7 @@ const closetransfer = ()=>{
|
||||
const isPopupVisible2 = ref(false);
|
||||
|
||||
const multiple = ()=>{
|
||||
oddvalue.value = undefined;
|
||||
isPopupVisible2.value = true;
|
||||
}
|
||||
|
||||
@@ -321,6 +371,23 @@ const closemultiple = ()=>{
|
||||
isPopupVisible2.value = false;
|
||||
}
|
||||
|
||||
//定义响应式变量odd
|
||||
const oddvalue = ref();
|
||||
//拿到倍率
|
||||
const overmultiple = ()=>{
|
||||
|
||||
//拿到input响应式数据
|
||||
console.log("输入的倍率为:",oddvalue.value);
|
||||
//打包数据成url传输到over页面
|
||||
|
||||
const encodedMultiple = encodeURIComponent(JSON.stringify(oddvalue.value));
|
||||
|
||||
isPopupVisible2.value = false;
|
||||
|
||||
wx.redirectTo({
|
||||
url: `/pages/over/over?multiple=${encodedMultiple}`
|
||||
})
|
||||
}
|
||||
// const matchs = ref([
|
||||
// {
|
||||
// id: 1,
|
||||
|
||||
Reference in New Issue
Block a user