111
This commit is contained in:
@@ -1,8 +1,55 @@
|
||||
import {GET} from '@/utils/request'
|
||||
// api/room.js - 房间相关API
|
||||
import { GET, POST, PUT, DELETE } from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 房间相关API
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 根据房间ID查询房间
|
||||
* @param {number} roomId 房间ID
|
||||
*/
|
||||
getRoomById(roomId) {
|
||||
return GET(`/system/room/id/${roomId}`)
|
||||
},
|
||||
|
||||
// 查询【请填写功能名称】详细
|
||||
export const getuser = (roomid) => {
|
||||
return GET('/system/roomuser/list',roomid)
|
||||
}
|
||||
/**
|
||||
* 根据创建者查询房间
|
||||
* @param {number} createUser 创建者ID
|
||||
*/
|
||||
getRoomsByCreateUser(createUser) {
|
||||
return GET(`/system/room/createUser/${createUser}`)
|
||||
},
|
||||
|
||||
/**
|
||||
* 查询房间列表
|
||||
* @param {Object} params 查询参数
|
||||
*/
|
||||
getRoomList(params) {
|
||||
return GET('/system/room/list', params)
|
||||
},
|
||||
|
||||
/**
|
||||
* 新增房间
|
||||
* @param {Object} roomData 房间数据
|
||||
*/
|
||||
addRoom(roomData) {
|
||||
return POST('/system/room', roomData)
|
||||
},
|
||||
|
||||
/**
|
||||
* 修改房间
|
||||
* @param {Object} roomData 房间数据
|
||||
*/
|
||||
updateRoom(roomData) {
|
||||
return PUT('/system/room', roomData)
|
||||
},
|
||||
|
||||
/**
|
||||
* 批量删除房间
|
||||
* @param {Array} roomIds 房间ID数组
|
||||
*/
|
||||
deleteRooms(roomIds) {
|
||||
return DELETE(`/system/room/${roomIds}`)
|
||||
}
|
||||
}
|
||||
47
scoring/api/roomDetail.js
Normal file
47
scoring/api/roomDetail.js
Normal file
@@ -0,0 +1,47 @@
|
||||
// api/roomDetail.js - 房间详情相关API
|
||||
import { GET, POST, PUT, DELETE } from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 房间详情相关API
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 根据详情ID查询房间详情
|
||||
* @param {number} detailId 详情ID
|
||||
*/
|
||||
getRoomDetailById(detailId) {
|
||||
return GET(`/system/detail/${detailId}`)
|
||||
},
|
||||
|
||||
/**
|
||||
* 查询房间详情列表
|
||||
* @param {Object} params 查询参数
|
||||
*/
|
||||
getRoomDetailList(params) {
|
||||
return GET('/system/detail/list', params)
|
||||
},
|
||||
|
||||
/**
|
||||
* 批量新增房间详情
|
||||
* @param {Array} roomDetails 房间详情数据数组
|
||||
*/
|
||||
addRoomDetails(roomDetails) {
|
||||
return POST('/system/detail', roomDetails)
|
||||
},
|
||||
|
||||
/**
|
||||
* 修改房间详情
|
||||
* @param {Object} roomDetail 房间详情数据
|
||||
*/
|
||||
updateRoomDetail(roomDetail) {
|
||||
return PUT('/system/detail', roomDetail)
|
||||
},
|
||||
|
||||
/**
|
||||
* 批量删除房间详情
|
||||
* @param {Array} detailIds 详情ID数组
|
||||
*/
|
||||
deleteRoomDetails(detailIds) {
|
||||
return DELETE(`/system/detail/${detailIds}`)
|
||||
}
|
||||
}
|
||||
179
scoring/api/roomUser.js
Normal file
179
scoring/api/roomUser.js
Normal file
@@ -0,0 +1,179 @@
|
||||
// api/roomUser.js - 房间用户相关API
|
||||
import { GET, POST, PUT, DELETE } from '@/utils/request'
|
||||
|
||||
/**
|
||||
* 房间用户相关API
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 获取房间内所有用户及其详细对局记录(已修复)
|
||||
* @param {number} roomId 房间ID
|
||||
*/
|
||||
async getUserScoresWithDetails(roomId) {
|
||||
try {
|
||||
console.log('获取房间用户详情,房间ID:', roomId);
|
||||
|
||||
// 使用正确的API路径
|
||||
const response = await GET(`/system/score/room/user/user-details/${roomId}`);
|
||||
|
||||
console.log('房间用户详情API响应:', response);
|
||||
|
||||
// 处理不同的响应格式
|
||||
if (response.code === 200 || response.code === 0) {
|
||||
return response.data;
|
||||
} else if (response.success) {
|
||||
return response.data;
|
||||
} else {
|
||||
// 如果接口返回错误,尝试使用列表接口
|
||||
console.warn('主接口失败,尝试使用列表接口');
|
||||
return await this.getRoomUserList({ roomId });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取房间用户详情失败:', error);
|
||||
|
||||
// 降级方案1:使用列表接口
|
||||
try {
|
||||
console.log('尝试使用列表接口作为降级方案');
|
||||
const listResult = await this.getRoomUserList({ roomId });
|
||||
if (listResult) {
|
||||
return listResult;
|
||||
}
|
||||
} catch (listError) {
|
||||
console.error('列表接口也失败:', listError);
|
||||
}
|
||||
|
||||
// 降级方案2:返回空数据并提示
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据RoomUserId查询
|
||||
* @param {number} roomUserId 房间用户ID
|
||||
*/
|
||||
async getRoomUserById(roomUserId) {
|
||||
try {
|
||||
const response = await GET(`/system/score/room/user/RoomUserId/${roomUserId}`);
|
||||
return response.data || response;
|
||||
} catch (error) {
|
||||
console.error('获取房间用户信息失败:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 根据UserId查询
|
||||
* @param {number} userId 用户ID
|
||||
*/
|
||||
async getRoomUserByUserId(userId) {
|
||||
try {
|
||||
const response = await GET(`/system/score/room/user/userid/${userId}`);
|
||||
return response.data || response;
|
||||
} catch (error) {
|
||||
console.error('根据用户ID获取房间用户失败:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 查询房间用户列表
|
||||
* @param {Object} params 查询参数
|
||||
*/
|
||||
async getRoomUserList(params) {
|
||||
try {
|
||||
console.log('获取房间用户列表,参数:', params);
|
||||
const response = await GET('/system/score/room/user/list', params);
|
||||
console.log('房间用户列表响应:', response);
|
||||
return response.data || response;
|
||||
} catch (error) {
|
||||
console.error('获取房间用户列表失败:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 新增房间用户
|
||||
* @param {Object} roomUserData 房间用户数据
|
||||
*/
|
||||
async addRoomUser(roomUserData) {
|
||||
try {
|
||||
console.log('新增房间用户:', roomUserData);
|
||||
const response = await POST('/system/score/room/user', roomUserData);
|
||||
console.log('新增房间用户响应:', response);
|
||||
return response.data || response;
|
||||
} catch (error) {
|
||||
console.error('新增房间用户失败:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
|
||||
async updateRoomUsersSafe(roomUsers) {
|
||||
try {
|
||||
console.log('安全更新房间用户得分:', roomUsers);
|
||||
|
||||
// 过滤和转换数据
|
||||
const safeUsers = roomUsers.map(user => {
|
||||
let userId = user.userId;
|
||||
|
||||
// 确保userId在int范围内
|
||||
if (userId > 2147483647 || userId < -2147483648) {
|
||||
console.warn('用户ID超出范围,进行转换:', userId);
|
||||
// 使用哈希值
|
||||
const strId = userId.toString();
|
||||
let hash = 0;
|
||||
for (let i = 0; i < strId.length; i++) {
|
||||
hash = ((hash << 5) - hash) + strId.charCodeAt(i);
|
||||
hash = hash & hash;
|
||||
}
|
||||
userId = Math.abs(hash) % 1000000;
|
||||
}
|
||||
|
||||
return {
|
||||
...user,
|
||||
userId: userId
|
||||
};
|
||||
});
|
||||
|
||||
const response = await PUT('/system/score/room/user', safeUsers);
|
||||
console.log('安全更新响应:', response);
|
||||
return response.data || response;
|
||||
} catch (error) {
|
||||
console.error('安全更新房间用户得分:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
/**
|
||||
* 批量更新用户得分
|
||||
* @param {Array} roomUsers 房间用户数据数组
|
||||
*/
|
||||
async updateRoomUsers(roomUsers) {
|
||||
|
||||
try {
|
||||
|
||||
|
||||
console.log('更新房间用户得分:', roomUsers);
|
||||
const response = await PUT('/system/score/room/user', roomUsers);
|
||||
console.log('更新房间用户得分响应:', response);
|
||||
return response.data || response;
|
||||
} catch (error) {
|
||||
console.error('更新房间用户得分:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* 批量删除房间用户
|
||||
* @param {Array} roomUserIds 房间用户ID数组
|
||||
*/
|
||||
async deleteRoomUsers(roomUserIds) {
|
||||
try {
|
||||
const response = await DELETE(`/system/score/room/user/${roomUserIds}`);
|
||||
return response.data || response;
|
||||
} catch (error) {
|
||||
console.error('删除房间用户失败:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import { GET, POST } from '@/utils/request.js'
|
||||
import { GET, POST,PUT,DELETE } from '@/utils/request.js'
|
||||
|
||||
export const register = (userInfo) => {
|
||||
return POST('/system/score/user', userInfo);
|
||||
@@ -6,4 +6,60 @@ export const register = (userInfo) => {
|
||||
|
||||
export const login = (userInfo) => {
|
||||
return POST('/system/score/user/login', userInfo);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 用户相关API
|
||||
*/
|
||||
export default {
|
||||
/**
|
||||
* 根据用户ID查询用户
|
||||
* @param {string} userId 用户ID
|
||||
*/
|
||||
getUserById(userId) {
|
||||
return GET(`/system/score/user/${userId}`)
|
||||
},
|
||||
|
||||
/**
|
||||
* 查询用户列表
|
||||
* @param {Object} params 查询参数
|
||||
*/
|
||||
getUserList(params) {
|
||||
return GET('/system/score/user/list', params)
|
||||
},
|
||||
|
||||
/**
|
||||
* 新增用户
|
||||
* @param {Object} userData 用户数据
|
||||
*/
|
||||
addUser(userData) {
|
||||
return POST('/system/score/user', userData)
|
||||
},
|
||||
|
||||
/**
|
||||
* 修改用户
|
||||
* @param {Object} userData 用户数据
|
||||
*/
|
||||
updateUser(userData) {
|
||||
return PUT('/system/score/user', userData)
|
||||
},
|
||||
|
||||
/**
|
||||
* 批量删除用户
|
||||
* @param {Array} userIds 用户ID数组
|
||||
*/
|
||||
deleteUsers(userIds) {
|
||||
return DELETE(`/system/score/user/${userIds}`)
|
||||
},
|
||||
|
||||
/**
|
||||
* 用户登录
|
||||
* @param {Object} loginData 登录数据
|
||||
*/
|
||||
login(loginData) {
|
||||
return POST('/system/score/user/login', loginData)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user