1
This commit is contained in:
@@ -77,7 +77,13 @@ public class ScoreRoomController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody ScoreRoom scoreRoom)
|
public AjaxResult add(@RequestBody ScoreRoom scoreRoom)
|
||||||
{
|
{
|
||||||
return toAjax(scoreRoomService.insertScoreRoom(scoreRoom));
|
int result = scoreRoomService.insertScoreRoom(scoreRoom);
|
||||||
|
if (result > 0) {
|
||||||
|
|
||||||
|
return AjaxResult.success("操作成功", scoreRoom);
|
||||||
|
} else {
|
||||||
|
return AjaxResult.error("操作失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
|
|||||||
* @date 2025-10-30
|
* @date 2025-10-30
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/system/detail")
|
@RequestMapping("/score/roomdetail")
|
||||||
public class ScoreRoomDetailController extends BaseController
|
public class ScoreRoomDetailController extends BaseController
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ import com.ruoyi.common.core.page.TableDataInfo;
|
|||||||
* @date 2025-10-30
|
* @date 2025-10-30
|
||||||
*/
|
*/
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/system/score/room/user")
|
@RequestMapping("/score/player")
|
||||||
public class ScoreRoomUserController extends BaseController
|
public class ScoreRoomUserController extends BaseController
|
||||||
{
|
{
|
||||||
@Autowired
|
@Autowired
|
||||||
@@ -45,6 +45,13 @@ public class ScoreRoomUserController extends BaseController
|
|||||||
List<ScoreRoomUser> list = scoreRoomUserService.selectScoreRoomUserList(scoreRoomUser);
|
List<ScoreRoomUser> list = scoreRoomUserService.selectScoreRoomUserList(scoreRoomUser);
|
||||||
return getDataTable(list);
|
return getDataTable(list);
|
||||||
}
|
}
|
||||||
|
@GetMapping("/all")
|
||||||
|
public TableDataInfo all(ScoreRoomUser scoreRoomUser)
|
||||||
|
{
|
||||||
|
startPage();
|
||||||
|
List<ScoreRoomUser> list = scoreRoomUserService.selectAllScoreRoomUserList(scoreRoomUser);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 导出【请填写功能名称】列表
|
* 导出【请填写功能名称】列表
|
||||||
@@ -77,7 +84,8 @@ public class ScoreRoomUserController extends BaseController
|
|||||||
@PostMapping
|
@PostMapping
|
||||||
public AjaxResult add(@RequestBody ScoreRoomUser scoreRoomUser)
|
public AjaxResult add(@RequestBody ScoreRoomUser scoreRoomUser)
|
||||||
{
|
{
|
||||||
return toAjax(scoreRoomUserService.insertScoreRoomUser(scoreRoomUser));
|
ScoreRoomUser result = scoreRoomUserService.insertScoreRoomUser(scoreRoomUser);
|
||||||
|
return AjaxResult.success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -78,7 +78,9 @@ public class ScoreUserController extends BaseController
|
|||||||
public AjaxResult add(@RequestBody ScoreUser scoreUser)
|
public AjaxResult add(@RequestBody ScoreUser scoreUser)
|
||||||
{
|
{
|
||||||
System.out.println(scoreUser);
|
System.out.println(scoreUser);
|
||||||
return toAjax(scoreUserService.insertScoreUser(scoreUser));
|
// 返回包含自增ID的完整用户对象
|
||||||
|
ScoreUser result = scoreUserService.insertScoreUser(scoreUser);
|
||||||
|
return success(result);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -41,13 +41,17 @@ public class ScoreRoomDetail extends BaseEntity
|
|||||||
@Excel(name = "0 胜 1 负")
|
@Excel(name = "0 胜 1 负")
|
||||||
private Long detailType;
|
private Long detailType;
|
||||||
|
|
||||||
/** 目标玩家id 多人模式给分使用 */
|
@Excel(name = "局次")
|
||||||
@Excel(name = "目标玩家id 多人模式给分使用")
|
private Long gameTime;
|
||||||
private Long getterId;
|
|
||||||
|
|
||||||
public void setDetailId(Long detailId)
|
public void setGameTime(Long gameTime)
|
||||||
{
|
{
|
||||||
this.detailId = detailId;
|
this.gameTime = gameTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getGameTime()
|
||||||
|
{
|
||||||
|
return gameTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getDetailId()
|
public Long getDetailId()
|
||||||
@@ -104,17 +108,6 @@ public class ScoreRoomDetail extends BaseEntity
|
|||||||
{
|
{
|
||||||
return detailType;
|
return detailType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setGetterId(Long getterId)
|
|
||||||
{
|
|
||||||
this.getterId = getterId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Long getGetterId()
|
|
||||||
{
|
|
||||||
return getterId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
@@ -124,7 +117,6 @@ public class ScoreRoomDetail extends BaseEntity
|
|||||||
.append("score", getScore())
|
.append("score", getScore())
|
||||||
.append("createdTime", getCreatedTime())
|
.append("createdTime", getCreatedTime())
|
||||||
.append("detailType", getDetailType())
|
.append("detailType", getDetailType())
|
||||||
.append("getterId", getGetterId())
|
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ public class ScoreRoomUser extends BaseEntity
|
|||||||
|
|
||||||
/** 得分 */
|
/** 得分 */
|
||||||
@Excel(name = "得分")
|
@Excel(name = "得分")
|
||||||
private Long score;
|
private Long allscore;
|
||||||
|
|
||||||
/** 三个值 {'user', 'boot', 'business'} */
|
/** 三个值 {'user', 'boot', 'business'} */
|
||||||
@Excel(name = "三个值 {'user', 'boot', 'business'}")
|
@Excel(name = "三个值 {'user', 'boot', 'business'}")
|
||||||
@@ -42,6 +42,12 @@ public class ScoreRoomUser extends BaseEntity
|
|||||||
@Excel(name = "玩家头像")
|
@Excel(name = "玩家头像")
|
||||||
private String avatars;
|
private String avatars;
|
||||||
|
|
||||||
|
@Excel(name="单局得分")
|
||||||
|
private Long score;
|
||||||
|
|
||||||
|
@Excel(name="局次")
|
||||||
|
private Long gameTime;
|
||||||
|
|
||||||
public void setRoomUserId(Long roomUserId)
|
public void setRoomUserId(Long roomUserId)
|
||||||
{
|
{
|
||||||
this.roomUserId = roomUserId;
|
this.roomUserId = roomUserId;
|
||||||
@@ -72,14 +78,14 @@ public class ScoreRoomUser extends BaseEntity
|
|||||||
return userId;
|
return userId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScore(Long score)
|
public void setAllscore(Long allscore)
|
||||||
{
|
{
|
||||||
this.score = score;
|
this.allscore = allscore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Long getScore()
|
public Long getAllscore()
|
||||||
{
|
{
|
||||||
return score;
|
return allscore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPlayerType(String playerType)
|
public void setPlayerType(String playerType)
|
||||||
@@ -112,16 +118,40 @@ public class ScoreRoomUser extends BaseEntity
|
|||||||
return avatars;
|
return avatars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setScore(Long score)
|
||||||
|
{
|
||||||
|
this.score = score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getScore()
|
||||||
|
{
|
||||||
|
return score;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGameTime(Long gameTime)
|
||||||
|
{
|
||||||
|
this.gameTime = gameTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getGameTime()
|
||||||
|
{
|
||||||
|
return gameTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
.append("roomUserId", getRoomUserId())
|
.append("roomUserId", getRoomUserId())
|
||||||
.append("roomId", getRoomId())
|
.append("roomId", getRoomId())
|
||||||
.append("userId", getUserId())
|
.append("userId", getUserId())
|
||||||
.append("score", getScore())
|
.append("allscore", getAllscore())
|
||||||
.append("playerType", getPlayerType())
|
.append("playerType", getPlayerType())
|
||||||
.append("nickName", getNickName())
|
.append("nickName", getNickName())
|
||||||
.append("avatars", getAvatars())
|
.append("avatars", getAvatars())
|
||||||
|
.append("score", getScore())
|
||||||
|
.append("gameTime", getGameTime())
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,4 +58,12 @@ public interface ScoreRoomUserMapper
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteScoreRoomUserByRoomUserIds(Long[] roomUserIds);
|
public int deleteScoreRoomUserByRoomUserIds(Long[] roomUserIds);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param scoreRoomUser 【请填写功能名称】
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
public List<ScoreRoomUser> selectAllScoreRoomUserList(ScoreRoomUser scoreRoomUser);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,14 @@ public interface ScoreUserMapper
|
|||||||
*/
|
*/
|
||||||
public List<ScoreUser> selectScoreUserList(ScoreUser scoreUser);
|
public List<ScoreUser> selectScoreUserList(ScoreUser scoreUser);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询所有基础信息列表
|
||||||
|
*
|
||||||
|
* @param scoreUser 基础信息
|
||||||
|
* @return 基础信息集合
|
||||||
|
*/
|
||||||
|
public List<ScoreUser> selectAllScoreUserList(ScoreUser scoreUser);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增基础信息
|
* 新增基础信息
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -26,14 +26,21 @@ public interface IScoreRoomUserService
|
|||||||
* @return 【请填写功能名称】集合
|
* @return 【请填写功能名称】集合
|
||||||
*/
|
*/
|
||||||
public List<ScoreRoomUser> selectScoreRoomUserList(ScoreRoomUser scoreRoomUser);
|
public List<ScoreRoomUser> selectScoreRoomUserList(ScoreRoomUser scoreRoomUser);
|
||||||
|
/**
|
||||||
|
* 查询所有【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param scoreRoomUser 【请填写功能名称】
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
public List<ScoreRoomUser> selectAllScoreRoomUserList(ScoreRoomUser scoreRoomUser);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增【请填写功能名称】
|
* 新增【请填写功能名称】
|
||||||
*
|
*
|
||||||
* @param scoreRoomUser 【请填写功能名称】
|
* @param scoreRoomUser 【请填写功能名称】
|
||||||
* @return 结果
|
* @return 【请填写功能名称】对象
|
||||||
*/
|
*/
|
||||||
public int insertScoreRoomUser(ScoreRoomUser scoreRoomUser);
|
public ScoreRoomUser insertScoreRoomUser(ScoreRoomUser scoreRoomUser);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改【请填写功能名称】
|
* 修改【请填写功能名称】
|
||||||
|
|||||||
@@ -26,6 +26,13 @@ public interface IScoreUserService
|
|||||||
* @return 基础信息集合
|
* @return 基础信息集合
|
||||||
*/
|
*/
|
||||||
public List<ScoreUser> selectScoreUserList(ScoreUser scoreUser);
|
public List<ScoreUser> selectScoreUserList(ScoreUser scoreUser);
|
||||||
|
/**
|
||||||
|
* 查询所有基础信息
|
||||||
|
*
|
||||||
|
* @param scoreUser 基础信息
|
||||||
|
* @return 基础信息集合
|
||||||
|
*/
|
||||||
|
public List<ScoreUser> selectAllScoreUserList(ScoreUser scoreUser);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增基础信息
|
* 新增基础信息
|
||||||
@@ -33,7 +40,7 @@ public interface IScoreUserService
|
|||||||
* @param scoreUser 基础信息
|
* @param scoreUser 基础信息
|
||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int insertScoreUser(ScoreUser scoreUser);
|
public ScoreUser insertScoreUser(ScoreUser scoreUser);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 修改基础信息
|
* 修改基础信息
|
||||||
@@ -58,4 +65,5 @@ public interface IScoreUserService
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
public int deleteScoreUserByUserId(Long userId);
|
public int deleteScoreUserByUserId(Long userId);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,9 @@ import java.util.List;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.system.mapper.ScoreRoomDetailMapper;
|
import com.ruoyi.system.mapper.ScoreRoomDetailMapper;
|
||||||
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.system.domain.ScoreRoomDetail;
|
import com.ruoyi.system.domain.ScoreRoomDetail;
|
||||||
|
import com.ruoyi.system.domain.ScoreUser;
|
||||||
import com.ruoyi.system.service.IScoreRoomDetailService;
|
import com.ruoyi.system.service.IScoreRoomDetailService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import java.util.List;
|
|||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import com.ruoyi.system.mapper.ScoreRoomMapper;
|
import com.ruoyi.system.mapper.ScoreRoomMapper;
|
||||||
|
import com.ruoyi.common.utils.DateUtils;
|
||||||
import com.ruoyi.system.domain.ScoreRoom;
|
import com.ruoyi.system.domain.ScoreRoom;
|
||||||
import com.ruoyi.system.service.IScoreRoomService;
|
import com.ruoyi.system.service.IScoreRoomService;
|
||||||
|
|
||||||
@@ -52,7 +53,18 @@ public class ScoreRoomServiceImpl implements IScoreRoomService
|
|||||||
@Override
|
@Override
|
||||||
public int insertScoreRoom(ScoreRoom scoreRoom)
|
public int insertScoreRoom(ScoreRoom scoreRoom)
|
||||||
{
|
{
|
||||||
return scoreRoomMapper.insertScoreRoom(scoreRoom);
|
// 设置创建时间
|
||||||
|
scoreRoom.setCreateTime(DateUtils.getNowDate());
|
||||||
|
|
||||||
|
// 插入房间信息,MyBatis会自动将自增ID设置到scoreRoom对象的roomId属性中
|
||||||
|
int result = scoreRoomMapper.insertScoreRoom(scoreRoom);
|
||||||
|
|
||||||
|
if (result > 0) {
|
||||||
|
// 返回插入成功的行数
|
||||||
|
return result;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("房间信息插入失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,17 +42,29 @@ public class ScoreRoomUserServiceImpl implements IScoreRoomUserService
|
|||||||
{
|
{
|
||||||
return scoreRoomUserMapper.selectScoreRoomUserList(scoreRoomUser);
|
return scoreRoomUserMapper.selectScoreRoomUserList(scoreRoomUser);
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* 查询所有【请填写功能名称】
|
||||||
|
*
|
||||||
|
* @param scoreRoomUser 【请填写功能名称】
|
||||||
|
* @return 【请填写功能名称】
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<ScoreRoomUser> selectAllScoreRoomUserList(ScoreRoomUser scoreRoomUser)
|
||||||
|
{
|
||||||
|
return scoreRoomUserMapper.selectAllScoreRoomUserList(scoreRoomUser);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 新增【请填写功能名称】
|
* 新增【请填写功能名称】
|
||||||
*
|
*
|
||||||
* @param scoreRoomUser 【请填写功能名称】
|
* @param scoreRoomUser 【请填写功能名称】
|
||||||
* @return 结果
|
* @return 【请填写功能名称】对象
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int insertScoreRoomUser(ScoreRoomUser scoreRoomUser)
|
public ScoreRoomUser insertScoreRoomUser(ScoreRoomUser scoreRoomUser)
|
||||||
{
|
{
|
||||||
return scoreRoomUserMapper.insertScoreRoomUser(scoreRoomUser);
|
scoreRoomUserMapper.insertScoreRoomUser(scoreRoomUser);
|
||||||
|
return scoreRoomUser;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -17,6 +17,17 @@ import com.ruoyi.system.service.IScoreUserService;
|
|||||||
@Service
|
@Service
|
||||||
public class ScoreUserServiceImpl implements IScoreUserService
|
public class ScoreUserServiceImpl implements IScoreUserService
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 查询所有基础信息
|
||||||
|
*
|
||||||
|
* @param scoreUser 基础信息
|
||||||
|
* @return 基础信息集合
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<ScoreUser> selectAllScoreUserList(ScoreUser scoreUser)
|
||||||
|
{
|
||||||
|
return scoreUserMapper.selectAllScoreUserList(scoreUser);
|
||||||
|
}
|
||||||
@Autowired
|
@Autowired
|
||||||
private ScoreUserMapper scoreUserMapper;
|
private ScoreUserMapper scoreUserMapper;
|
||||||
|
|
||||||
@@ -51,10 +62,23 @@ public class ScoreUserServiceImpl implements IScoreUserService
|
|||||||
* @return 结果
|
* @return 结果
|
||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public int insertScoreUser(ScoreUser scoreUser)
|
public ScoreUser insertScoreUser(ScoreUser scoreUser)
|
||||||
{
|
{
|
||||||
|
// 判断当前openId是否已经有值了
|
||||||
|
ScoreUser scoreUser1 = scoreUserMapper.selectScoreUserByUserId(scoreUser.getUserId());
|
||||||
|
if(scoreUser1 != null) {
|
||||||
|
throw new RuntimeException("当前openId是否已经有值");
|
||||||
|
}
|
||||||
scoreUser.setCreateTime(DateUtils.getNowDate());
|
scoreUser.setCreateTime(DateUtils.getNowDate());
|
||||||
return scoreUserMapper.insertScoreUser(scoreUser);
|
// 插入用户,MyBatis会自动将自增ID设置到user对象的userId属性中
|
||||||
|
int result = scoreUserMapper.insertScoreUser(scoreUser);
|
||||||
|
|
||||||
|
if (result > 0) {
|
||||||
|
// 返回包含自增ID的用户对象
|
||||||
|
return scoreUser;
|
||||||
|
} else {
|
||||||
|
throw new RuntimeException("用户插入失败");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="score" column="score" />
|
<result property="score" column="score" />
|
||||||
<result property="createdTime" column="created_time" />
|
<result property="createdTime" column="created_time" />
|
||||||
<result property="detailType" column="detail_type" />
|
<result property="detailType" column="detail_type" />
|
||||||
<result property="getterId" column="getter_id" />
|
<result property="gameTime" column="game_time" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
|
||||||
<sql id="selectScoreRoomDetailVo">
|
<sql id="selectScoreRoomDetailVo">
|
||||||
select detail_id, room_id, user_id, score, created_time, detail_type, getter_id from score_room_detail
|
select detail_id, room_id, user_id, score, created_time, detail_type, game_time from score_room_detail
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
<select id="selectScoreRoomDetailList" parameterType="ScoreRoomDetail" resultMap="ScoreRoomDetailResult">
|
<select id="selectScoreRoomDetailList" parameterType="ScoreRoomDetail" resultMap="ScoreRoomDetailResult">
|
||||||
@@ -26,7 +26,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="score != null "> and score = #{score}</if>
|
<if test="score != null "> and score = #{score}</if>
|
||||||
<if test="createdTime != null "> and created_time = #{createdTime}</if>
|
<if test="createdTime != null "> and created_time = #{createdTime}</if>
|
||||||
<if test="detailType != null "> and detail_type = #{detailType}</if>
|
<if test="detailType != null "> and detail_type = #{detailType}</if>
|
||||||
<if test="getterId != null "> and getter_id = #{getterId}</if>
|
<if test="gameTime != null "> and game_time = #{gameTime}</if>
|
||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="score != null">score,</if>
|
<if test="score != null">score,</if>
|
||||||
<if test="createdTime != null">created_time,</if>
|
<if test="createdTime != null">created_time,</if>
|
||||||
<if test="detailType != null">detail_type,</if>
|
<if test="detailType != null">detail_type,</if>
|
||||||
<if test="getterId != null">getter_id,</if>
|
<if test="gameTime != null">game_time,</if>
|
||||||
</trim>
|
</trim>
|
||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="roomId != null">#{roomId},</if>
|
<if test="roomId != null">#{roomId},</if>
|
||||||
@@ -51,7 +51,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="score != null">#{score},</if>
|
<if test="score != null">#{score},</if>
|
||||||
<if test="createdTime != null">#{createdTime},</if>
|
<if test="createdTime != null">#{createdTime},</if>
|
||||||
<if test="detailType != null">#{detailType},</if>
|
<if test="detailType != null">#{detailType},</if>
|
||||||
<if test="getterId != null">#{getterId},</if>
|
<if test="gameTime != null">#{gameTime},</if>
|
||||||
</trim>
|
</trim>
|
||||||
</insert>
|
</insert>
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<if test="score != null">score = #{score},</if>
|
<if test="score != null">score = #{score},</if>
|
||||||
<if test="createdTime != null">created_time = #{createdTime},</if>
|
<if test="createdTime != null">created_time = #{createdTime},</if>
|
||||||
<if test="detailType != null">detail_type = #{detailType},</if>
|
<if test="detailType != null">detail_type = #{detailType},</if>
|
||||||
<if test="getterId != null">getter_id = #{getterId},</if>
|
<if test="gameTime != null">game_time = #{gameTime},</if>
|
||||||
</trim>
|
</trim>
|
||||||
where detail_id = #{detailId}
|
where detail_id = #{detailId}
|
||||||
</update>
|
</update>
|
||||||
@@ -80,10 +80,10 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
</delete>
|
</delete>
|
||||||
|
|
||||||
<insert id="batchInsertScoreRoomDetail" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="detailId">
|
<insert id="batchInsertScoreRoomDetail" parameterType="java.util.List" useGeneratedKeys="true" keyProperty="detailId">
|
||||||
insert into score_room_detail (room_id, user_id, score, created_time, detail_type, getter_id)
|
insert into score_room_detail (room_id, user_id, score, created_time, detail_type, game_time)
|
||||||
values
|
values
|
||||||
<foreach item="detail" collection="list" separator=",">
|
<foreach item="detail" collection="list" separator=",">
|
||||||
(#{detail.roomId}, #{detail.userId}, #{detail.score}, #{detail.createdTime}, #{detail.detailType}, #{detail.getterId})
|
(#{detail.roomId}, #{detail.userId}, #{detail.score}, #{detail.createdTime}, #{detail.detailType}, #{detail.gameTime})
|
||||||
</foreach>
|
</foreach>
|
||||||
</insert>
|
</insert>
|
||||||
</mapper>
|
</mapper>
|
||||||
@@ -8,22 +8,64 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<result property="roomUserId" column="room_user_id" />
|
<result property="roomUserId" column="room_user_id" />
|
||||||
<result property="roomId" column="room_id" />
|
<result property="roomId" column="room_id" />
|
||||||
<result property="userId" column="user_id" />
|
<result property="userId" column="user_id" />
|
||||||
<result property="score" column="score" />
|
<result property="allscore" column="score" />
|
||||||
<result property="playerType" column="player_type" />
|
<result property="playerType" column="player_type" />
|
||||||
<result property="nickName" column="nick_name" />
|
<result property="nickName" column="nick_name" />
|
||||||
<result property="avatars" column="avatars" />
|
<result property="avatars" column="avatars" />
|
||||||
</resultMap>
|
</resultMap>
|
||||||
|
<resultMap type="ScoreRoomUser" id="ScoreRoomUserAllResult">
|
||||||
|
<result property="roomUserId" column="room_user_id" />
|
||||||
|
<result property="roomId" column="room_id" />
|
||||||
|
<result property="userId" column="user_id" />
|
||||||
|
<result property="allscore" column="allscore" />
|
||||||
|
<result property="score" column="detail_score" />
|
||||||
|
<result property="playerType" column="player_type" />
|
||||||
|
<result property="nickName" column="nick_name" />
|
||||||
|
<result property="avatars" column="avatars" />
|
||||||
|
<result property="gameTime" column="game_time" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectAllScoreRoomUserVo">
|
||||||
|
SELECT
|
||||||
|
ru.room_user_id,
|
||||||
|
ru.room_id,
|
||||||
|
ru.user_id,
|
||||||
|
ru.score AS allscore,
|
||||||
|
ru.player_type,
|
||||||
|
ru.nick_name,
|
||||||
|
ru.avatars,
|
||||||
|
rd.game_time,
|
||||||
|
rd.score AS detail_score,
|
||||||
|
rd.detail_id
|
||||||
|
FROM score_room_user ru
|
||||||
|
JOIN score_room_detail rd ON ru.user_id = rd.user_id
|
||||||
|
</sql>
|
||||||
|
|
||||||
<sql id="selectScoreRoomUserVo">
|
<sql id="selectScoreRoomUserVo">
|
||||||
select room_user_id, room_id, user_id, score, player_type, nick_name, avatars from score_room_user
|
select room_user_id, room_id, user_id, score, player_type, nick_name, avatars from score_room_user
|
||||||
</sql>
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectAllScoreRoomUserList" parameterType="scoreRoomUser" resultMap="ScoreRoomUserAllResult">
|
||||||
|
<include refid="selectAllScoreRoomUserVo"/>
|
||||||
|
<where>
|
||||||
|
<!-- 条件指定表别名,避免字段歧义 -->
|
||||||
|
<if test="roomId != null "> and ru.room_id = #{roomId}</if>
|
||||||
|
<if test="userId != null "> and ru.user_id = #{userId}</if>
|
||||||
|
<if test="allscore != null "> and ru.score = #{allscore}</if>
|
||||||
|
<if test="playerType != null and playerType != ''"> and ru.player_type = #{playerType}</if>
|
||||||
|
<if test="nickName != null and nickName != ''"> and ru.nick_name like concat('%', #{nickName}, '%')</if>
|
||||||
|
<if test="avatars != null and avatars != ''"> and ru.avatars = #{avatars}</if>
|
||||||
|
<if test="gameTime != null "> and rd.game_time = #{gameTime}</if> <!-- 去掉!= '',int类型无空字符串 -->
|
||||||
|
<if test="score != null "> and rd.score = #{score}</if> <!-- 对应详情表的score -->
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="selectScoreRoomUserList" parameterType="ScoreRoomUser" resultMap="ScoreRoomUserResult">
|
<select id="selectScoreRoomUserList" parameterType="ScoreRoomUser" resultMap="ScoreRoomUserResult">
|
||||||
<include refid="selectScoreRoomUserVo"/>
|
<include refid="selectScoreRoomUserVo"/>
|
||||||
<where>
|
<where>
|
||||||
<if test="roomId != null "> and room_id = #{roomId}</if>
|
<if test="roomId != null "> and room_id = #{roomId}</if>
|
||||||
<if test="userId != null "> and user_id = #{userId}</if>
|
<if test="userId != null "> and user_id = #{userId}</if>
|
||||||
<if test="score != null "> and score = #{score}</if>
|
<if test="allscore != null "> and score = #{allscore}</if>
|
||||||
<if test="playerType != null and playerType != ''"> and player_type = #{playerType}</if>
|
<if test="playerType != null and playerType != ''"> and player_type = #{playerType}</if>
|
||||||
<if test="nickName != null and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
|
<if test="nickName != null and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
|
||||||
<if test="avatars != null and avatars != ''"> and avatars = #{avatars}</if>
|
<if test="avatars != null and avatars != ''"> and avatars = #{avatars}</if>
|
||||||
@@ -40,7 +82,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<trim prefix="(" suffix=")" suffixOverrides=",">
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
<if test="roomId != null">room_id,</if>
|
<if test="roomId != null">room_id,</if>
|
||||||
<if test="userId != null">user_id,</if>
|
<if test="userId != null">user_id,</if>
|
||||||
<if test="score != null">score,</if>
|
<if test="allscore != null">score,</if>
|
||||||
<if test="playerType != null">player_type,</if>
|
<if test="playerType != null">player_type,</if>
|
||||||
<if test="nickName != null">nick_name,</if>
|
<if test="nickName != null">nick_name,</if>
|
||||||
<if test="avatars != null">avatars,</if>
|
<if test="avatars != null">avatars,</if>
|
||||||
@@ -48,7 +90,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
<if test="roomId != null">#{roomId},</if>
|
<if test="roomId != null">#{roomId},</if>
|
||||||
<if test="userId != null">#{userId},</if>
|
<if test="userId != null">#{userId},</if>
|
||||||
<if test="score != null">#{score},</if>
|
<if test="allscore != null">#{allscore},</if>
|
||||||
<if test="playerType != null">#{playerType},</if>
|
<if test="playerType != null">#{playerType},</if>
|
||||||
<if test="nickName != null">#{nickName},</if>
|
<if test="nickName != null">#{nickName},</if>
|
||||||
<if test="avatars != null">#{avatars},</if>
|
<if test="avatars != null">#{avatars},</if>
|
||||||
@@ -60,7 +102,7 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
|||||||
<trim prefix="SET" suffixOverrides=",">
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
<if test="roomId != null">room_id = #{roomId},</if>
|
<if test="roomId != null">room_id = #{roomId},</if>
|
||||||
<if test="userId != null">user_id = #{userId},</if>
|
<if test="userId != null">user_id = #{userId},</if>
|
||||||
<if test="score != null">score = #{score},</if>
|
<if test="allscore != null">score = #{allscore},</if>
|
||||||
<if test="playerType != null">player_type = #{playerType},</if>
|
<if test="playerType != null">player_type = #{playerType},</if>
|
||||||
<if test="nickName != null">nick_name = #{nickName},</if>
|
<if test="nickName != null">nick_name = #{nickName},</if>
|
||||||
<if test="avatars != null">avatars = #{avatars},</if>
|
<if test="avatars != null">avatars = #{avatars},</if>
|
||||||
|
|||||||
@@ -26,6 +26,15 @@
|
|||||||
</where>
|
</where>
|
||||||
</select>
|
</select>
|
||||||
|
|
||||||
|
<select id="selectAllScoreUserList" parameterType="ScoreUser" resultMap="ScoreUserResult">
|
||||||
|
<include refid="selectScoreUserVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="openId != null and openId != ''"> and open_id = #{openId}</if>
|
||||||
|
<if test="nickName != null and nickName != ''"> and nick_name like concat('%', #{nickName}, '%')</if>
|
||||||
|
<if test="createTime != null "> and create_time = #{createTime}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
<select id="selectScoreUserByUserId" parameterType="Long" resultMap="ScoreUserResult">
|
<select id="selectScoreUserByUserId" parameterType="Long" resultMap="ScoreUserResult">
|
||||||
<include refid="selectScoreUserVo"/>
|
<include refid="selectScoreUserVo"/>
|
||||||
where user_id = #{userId}
|
where user_id = #{userId}
|
||||||
|
|||||||
@@ -144,6 +144,12 @@ const loadPlayersData = () => {
|
|||||||
icon: 'none'
|
icon: 'none'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 从本地存储加载当前局数
|
||||||
|
const savedRound = uni.getStorageSync('currentRound')
|
||||||
|
if (savedRound) {
|
||||||
|
roundCount.value = parseInt(savedRound)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 保存历史状态
|
// 保存历史状态
|
||||||
@@ -157,6 +163,9 @@ const saveHistoryState = () => {
|
|||||||
|
|
||||||
// 返回上一页
|
// 返回上一页
|
||||||
const goBack = () => {
|
const goBack = () => {
|
||||||
|
// 保存当前局数到本地存储
|
||||||
|
uni.setStorageSync('currentRound', roundCount.value)
|
||||||
|
|
||||||
uni.showModal({
|
uni.showModal({
|
||||||
title: '提示',
|
title: '提示',
|
||||||
content: '当前分数未保存,确定要返回吗?',
|
content: '当前分数未保存,确定要返回吗?',
|
||||||
@@ -324,6 +333,9 @@ const clearInput = () => {
|
|||||||
|
|
||||||
// 确认输入
|
// 确认输入
|
||||||
const confirmInput = () => {
|
const confirmInput = () => {
|
||||||
|
// 保存当前局数到本地存储
|
||||||
|
uni.setStorageSync('currentRound', roundCount.value)
|
||||||
|
|
||||||
if (selectedPlayerIndex.value !== -1) {
|
if (selectedPlayerIndex.value !== -1) {
|
||||||
// 播放音效
|
// 播放音效
|
||||||
if (soundEnabled.value) {
|
if (soundEnabled.value) {
|
||||||
|
|||||||
@@ -84,12 +84,6 @@
|
|||||||
</view>
|
</view>
|
||||||
</view>
|
</view>
|
||||||
|
|
||||||
<!--
|
|
||||||
<view>
|
|
||||||
<button @click="postscore">提交分数</button>
|
|
||||||
<input v-model="score.value.playerId" type="number" placeholder="输入分数" :src="score.value.playerId">
|
|
||||||
</view> -->
|
|
||||||
|
|
||||||
<!-- 底部操作按钮 -->
|
<!-- 底部操作按钮 -->
|
||||||
<view class="bottom-buttons">
|
<view class="bottom-buttons">
|
||||||
<button class="start-btn" type="primary" @click="startScoring">开局计分</button>
|
<button class="start-btn" type="primary" @click="startScoring">开局计分</button>
|
||||||
@@ -101,15 +95,41 @@
|
|||||||
|
|
||||||
<script setup>
|
<script setup>
|
||||||
import { ref, computed, onMounted, onUnmounted, toRaw } from 'vue'
|
import { ref, computed, onMounted, onUnmounted, toRaw } from 'vue'
|
||||||
import { GET,POST } from '../../../utils/request'
|
import { GET,POST,PUT } from '../../../utils/request'
|
||||||
import { BASE_URL } from '../../../utils/CommonValues.js';
|
import { BASE_URL } from '../../../utils/CommonValues.js';
|
||||||
|
const roomuser=ref({
|
||||||
|
roomId: '',
|
||||||
|
userId: '',
|
||||||
|
score:'',
|
||||||
|
playerType:'0',
|
||||||
|
nickName:'',
|
||||||
|
avatar:''
|
||||||
|
})
|
||||||
const res=ref(null)
|
const res=ref(null)
|
||||||
// const score=ref(
|
const scoreuser=ref({
|
||||||
// playerId: currentUser.id
|
openId: '',
|
||||||
// )
|
nickName: '',
|
||||||
|
avatar: 'scoring\static\avatar14.png'
|
||||||
|
})
|
||||||
|
const room=ref({
|
||||||
|
createUser:'1',
|
||||||
|
odds:1,
|
||||||
|
room_status:0,
|
||||||
|
bossId:'1',
|
||||||
|
roomName:'',
|
||||||
|
})
|
||||||
|
const detailscore=ref({
|
||||||
|
roomId: '',
|
||||||
|
userId: '',
|
||||||
|
score:'',
|
||||||
|
gameTime:'',
|
||||||
|
detailType:'0',
|
||||||
|
|
||||||
|
})
|
||||||
|
|
||||||
const getuserinfo =()=>{
|
const getuserinfo =()=>{
|
||||||
GET('/score/info/list',null,).then(res=>{
|
// 错误1:GET参数后多了多余逗号 → 已删除
|
||||||
|
GET('/score/info/list',null).then(res=>{
|
||||||
console.log('获取用户信息成功:', res.data)
|
console.log('获取用户信息成功:', res.data)
|
||||||
|
|
||||||
// 检查API返回数据结构
|
// 检查API返回数据结构
|
||||||
@@ -139,11 +159,12 @@ const getuserinfo =()=>{
|
|||||||
}
|
}
|
||||||
|
|
||||||
const newPlayer = {
|
const newPlayer = {
|
||||||
id: `player_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
|
id: user.userId, // 使用后端返回的userId作为玩家id
|
||||||
name: user.nickName, // 使用API返回的nickName作为玩家名称
|
name: user.nickName, // 使用API返回的nickName作为玩家名称
|
||||||
avatar: avatarUrl, // 使用处理后的头像URL
|
avatar: avatarUrl, // 使用处理后的头像URL
|
||||||
score: 0,
|
score: 0,
|
||||||
roundScores: []
|
roundScores: [],
|
||||||
|
roomId: roomId.value // 当前房间ID
|
||||||
};
|
};
|
||||||
players.value.push(newPlayer);
|
players.value.push(newPlayer);
|
||||||
}
|
}
|
||||||
@@ -172,25 +193,190 @@ const getuserinfo =()=>{
|
|||||||
});
|
});
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const UserId=ref('')
|
||||||
|
const postuserinfo = () => {
|
||||||
|
POST('/score/info', scoreuser.value).then(r => {
|
||||||
|
console.log('用户信息上传成功:', r);
|
||||||
|
UserId.value = r.data.data.userId;
|
||||||
|
console.log('用户ID:', UserId.value);
|
||||||
|
room.value.createUser = UserId.value;
|
||||||
|
room.value.bossId = UserId.value;
|
||||||
|
postroom();
|
||||||
|
|
||||||
// const postscore = () => {
|
// 如果有临时玩家ID,更新到players数组中
|
||||||
// POST('/a/post',score.value).then(r=>{
|
if (tempPlayerId.value) {
|
||||||
// console.log('提交分数成功:', r.data,)
|
const playerIndex = players.value.findIndex(p => p.id === tempPlayerId.value)
|
||||||
// console.log(score.value)
|
if (playerIndex !== -1) {
|
||||||
// res.value=r.data
|
// 更新玩家的id为真实的用户ID
|
||||||
// }).catch(err=>{
|
players.value[playerIndex].id = UserId.value
|
||||||
// console.error('提交分数失败:', err);
|
// 清空临时ID
|
||||||
// })
|
tempPlayerId.value = ''
|
||||||
// }
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
uni.showToast({
|
||||||
|
title: '用户信息上传成功',
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('用户信息上传失败:', err);
|
||||||
|
uni.showToast({
|
||||||
|
title: '用户信息上传失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
// 清空临时ID,避免影响后续操作
|
||||||
|
tempPlayerId.value = ''
|
||||||
|
});
|
||||||
|
}
|
||||||
|
// 全局房间ID变量,从本地存储恢复
|
||||||
|
const roomId=ref(uni.getStorageSync('roomId') || '')
|
||||||
|
const postroom = () => {
|
||||||
|
POST('/score/room', room.value).then(r => {
|
||||||
|
console.log('房间信息上传成功:', r);
|
||||||
|
// 检查API响应结构
|
||||||
|
console.log('API响应数据:', r.data);
|
||||||
|
const receivedRoomId = r.data.data.roomId || '';
|
||||||
|
console.log('房间ID:', receivedRoomId);
|
||||||
|
roomId.value = receivedRoomId;
|
||||||
|
// 保存roomId到本地存储
|
||||||
|
uni.setStorageSync('roomId', receivedRoomId);
|
||||||
|
|
||||||
|
// 更新所有玩家的roomId
|
||||||
|
players.value.forEach(player => {
|
||||||
|
player.roomId = receivedRoomId
|
||||||
|
})
|
||||||
|
|
||||||
|
postroomuser();
|
||||||
|
|
||||||
|
// 为每个玩家调用postroomdetail(即postdetailscore)函数,提交玩家与房间的关联信息
|
||||||
|
players.value.forEach(player => {
|
||||||
|
// 创建玩家与房间关联的详细数据
|
||||||
|
const playerRoomDetail = {
|
||||||
|
roomId: receivedRoomId,
|
||||||
|
userId: player.id,
|
||||||
|
userName: player.name,
|
||||||
|
userAvatar: player.avatar,
|
||||||
|
score: player.score
|
||||||
|
};
|
||||||
|
|
||||||
|
// 调用postdetailscore函数提交数据
|
||||||
|
postdetailscore(playerRoomDetail);
|
||||||
|
console.log('玩家与房间关联信息上传成功:', playerRoomDetail);
|
||||||
|
console.log('房间ID:', roomId.value);
|
||||||
|
});
|
||||||
|
|
||||||
|
uni.showToast({
|
||||||
|
title: '房间信息上传成功',
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('房间信息上传失败:', err);
|
||||||
|
uni.showToast({
|
||||||
|
title: '房间信息上传失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
};
|
||||||
|
const postroomuser = () => {
|
||||||
|
roomuser.value.roomId = roomId.value;
|
||||||
|
roomuser.value.userId = UserId.value;
|
||||||
|
roomuser.value.nickName = scoreuser.value.nickName;
|
||||||
|
POST('/score/player', roomuser.value).then(r => {
|
||||||
|
console.log('房间用户信息上传成功:', r);
|
||||||
|
const roomUserId = r.data.data.roomUserId;
|
||||||
|
console.log('获取到的roomUserId:', roomUserId);
|
||||||
|
uni.setStorageSync('roomUserId', roomUserId);
|
||||||
|
roomuser.value.roomUserId = roomUserId;
|
||||||
|
// 同时更新putscore对象的roomUserId属性,确保数据一致性
|
||||||
|
putscore.value.roomUserId = Number(roomUserId);
|
||||||
|
console.log('更新后的putscore对象:', putscore.value);
|
||||||
|
uni.showToast({
|
||||||
|
title: '房间用户信息上传成功',
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('房间用户信息上传失败:', err);
|
||||||
|
uni.showToast({
|
||||||
|
title: '房间用户信息上传失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const postdetailscore = (scoreData) => {
|
||||||
|
const dataToSubmit = scoreData || detailscore.value;
|
||||||
|
console.log('提交数据:', dataToSubmit);
|
||||||
|
console.log('房间ID:', roomId.value);
|
||||||
|
if (!dataToSubmit.roomId) {
|
||||||
|
dataToSubmit.roomId = roomId.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
POST('/score/roomdetail', dataToSubmit).then(r => {
|
||||||
|
console.log('房间用户详细信息上传成功:', r);
|
||||||
|
if (!scoreData || dataToSubmit.userId === UserId.value || dataToSubmit.userId === 'self') {
|
||||||
|
uni.showToast({
|
||||||
|
title: '房间用户详细信息上传成功',
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('房间用户详细信息上传失败:', err);
|
||||||
|
if (!scoreData || dataToSubmit.userId === UserId.value || dataToSubmit.userId === 'self') {
|
||||||
|
uni.showToast({
|
||||||
|
title: '房间用户详细信息上传失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const putscore=ref({
|
||||||
|
roomUserId:0,
|
||||||
|
allscore:0
|
||||||
|
})
|
||||||
|
const putroomuser = () => {
|
||||||
|
console.log('开始执行putroomuser函数');
|
||||||
|
const roomUserId = uni.getStorageSync('roomUserId');
|
||||||
|
console.log('从本地存储获取的roomUserId:', roomUserId);
|
||||||
|
|
||||||
|
// 从players数组中获取当前用户的总分
|
||||||
|
console.log('当前UserId.value:', UserId.value);
|
||||||
|
console.log('players数组内容:', players.value);
|
||||||
|
|
||||||
|
const currentPlayer = players.value.find(p => p.id === UserId.value);
|
||||||
|
if (currentPlayer) {
|
||||||
|
putscore.value.allscore = currentPlayer.score;
|
||||||
|
console.log('获取到的当前用户总分:', currentPlayer.score);
|
||||||
|
} else {
|
||||||
|
console.error('未找到当前用户的总分数据');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 设置roomUserId,并转换为数字类型
|
||||||
|
putscore.value.roomUserId = Number(roomUserId);
|
||||||
|
console.log('准备发送的putscore数据:', putscore.value);
|
||||||
|
|
||||||
|
PUT('/score/player', putscore.value).then(r => {
|
||||||
|
console.log('房间用户信息上传成功响应:', r);
|
||||||
|
console.log('响应数据:', r.data);
|
||||||
|
uni.showToast({
|
||||||
|
title: '房间用户信息上传成功',
|
||||||
|
icon: 'success'
|
||||||
|
});
|
||||||
|
}).catch(err => {
|
||||||
|
console.error('房间用户信息上传失败:', err);
|
||||||
|
console.error('错误详情:', err.errMsg || err);
|
||||||
|
uni.showToast({
|
||||||
|
title: '房间用户信息上传失败',
|
||||||
|
icon: 'none'
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
// 状态管理
|
// 状态管理
|
||||||
const voiceBroadcast = ref(false)
|
const voiceBroadcast = ref(false)
|
||||||
const tableMode = ref(false)
|
const tableMode = ref(false)
|
||||||
const roomId = ref('')
|
|
||||||
// 当前用户信息 - 从本地存储获取
|
// 当前用户信息 - 从本地存储获取
|
||||||
const storedUserInfo = uni.getStorageSync('userInfo');
|
const storedUserInfo = uni.getStorageSync('userInfo');
|
||||||
const currentUser = ref({
|
const currentUser = ref({
|
||||||
id: 'self',
|
id:self,
|
||||||
name: storedUserInfo?.name||'玩家50920' ,
|
name: storedUserInfo?.name||'acd' ,
|
||||||
avatar: storedUserInfo?.avatar ||'/static/logo.png' })
|
avatar: storedUserInfo?.avatar ||'/static/logo.png' })
|
||||||
|
|
||||||
// 局数信息
|
// 局数信息
|
||||||
@@ -199,11 +385,12 @@ const rounds = ref([]) // 存储每局信息,每个元素是局数编号
|
|||||||
// 玩家列表(初始包含自己)
|
// 玩家列表(初始包含自己)
|
||||||
const players = ref([
|
const players = ref([
|
||||||
{
|
{
|
||||||
id: 'self',
|
id:self,
|
||||||
name: currentUser.value.name ||'玩家50920',
|
name: currentUser.value.name ||'acd',
|
||||||
avatar: currentUser.value.avatar||'/static/logo.png',
|
avatar: currentUser.value.avatar||'/static/logo.png',
|
||||||
score: 0,
|
score: 0,
|
||||||
roundScores: [] // 存储每局的分数
|
roundScores: [], // 存储每局的分数
|
||||||
|
roomId: '' // 当前房间ID
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
@@ -232,6 +419,9 @@ const displayPlayers = computed(() => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 保存当前正在添加的玩家临时ID
|
||||||
|
const tempPlayerId = ref('')
|
||||||
|
|
||||||
// 添加玩家
|
// 添加玩家
|
||||||
const addPlayer = () => {
|
const addPlayer = () => {
|
||||||
console.log('添加玩家')
|
console.log('添加玩家')
|
||||||
@@ -262,7 +452,11 @@ const addPlayer = () => {
|
|||||||
score: 0,
|
score: 0,
|
||||||
roundScores: [] // 存储每局的分数
|
roundScores: [] // 存储每局的分数
|
||||||
}
|
}
|
||||||
|
scoreuser.value.openId=newPlayer.id
|
||||||
|
scoreuser.value.nickName=newPlayer.name
|
||||||
|
// 保存临时ID,用于后续更新真实ID
|
||||||
|
tempPlayerId.value = newPlayer.id
|
||||||
|
postuserinfo()
|
||||||
// 添加到玩家列表
|
// 添加到玩家列表
|
||||||
players.value.push(newPlayer)
|
players.value.push(newPlayer)
|
||||||
|
|
||||||
@@ -377,11 +571,10 @@ const editScore = (playerIndex) => {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// 开局计分
|
// 开局计分
|
||||||
const startScoring = () => {
|
const startScoring = () => {
|
||||||
console.log('开局计分')
|
console.log('开局计分')
|
||||||
|
room.value.roomStatus=1
|
||||||
// 检查是否有足够的玩家(至少需要2个玩家才能开始计分)
|
// 检查是否有足够的玩家(至少需要2个玩家才能开始计分)
|
||||||
if (displayPlayers.value.length < 2) {
|
if (displayPlayers.value.length < 2) {
|
||||||
uni.showToast({
|
uni.showToast({
|
||||||
@@ -435,20 +628,28 @@ const settleRoom = () => {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
const number = ref('')
|
||||||
// 生命周期
|
// 生命周期
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
console.log('单人模式页面加载完成')
|
console.log('单人模式页面加载完成')
|
||||||
// 可以在这里初始化数据或加载用户信息
|
// 可以在这里初始化数据或加载用户信息
|
||||||
getuserinfo();
|
getuserinfo();
|
||||||
|
|
||||||
// 生成随机房间号(4位数字)
|
// 生成四位数字
|
||||||
roomId.value = Math.floor(1000 + Math.random() * 9000).toString()
|
number.value = Math.floor(1000 + Math.random() * 9000).toString()
|
||||||
|
|
||||||
// 动态设置导航栏标题
|
// 动态设置导航栏标题
|
||||||
|
const pageTitle = `单人 - ${number.value}号房间`;
|
||||||
uni.setNavigationBarTitle({
|
uni.setNavigationBarTitle({
|
||||||
title: `单人 - ${roomId.value}号房间`
|
title: pageTitle
|
||||||
})
|
})
|
||||||
|
room.value.roomName = pageTitle
|
||||||
|
|
||||||
|
// 更新当前用户的roomId
|
||||||
|
const selfPlayer = players.value.find(p => p.id === 'self')
|
||||||
|
if (selfPlayer) {
|
||||||
|
selfPlayer.roomId = roomId.value
|
||||||
|
}
|
||||||
|
|
||||||
// 监听页面返回事件,用于接收从计分页面传回的更新后的分数
|
// 监听页面返回事件,用于接收从计分页面传回的更新后的分数
|
||||||
const updateListener = () => {
|
const updateListener = () => {
|
||||||
@@ -468,8 +669,6 @@ onMounted(() => {
|
|||||||
// 查找对应的玩家
|
// 查找对应的玩家
|
||||||
const playerIndex = players.value.findIndex(p => p.id === updatedPlayer.id)
|
const playerIndex = players.value.findIndex(p => p.id === updatedPlayer.id)
|
||||||
if (playerIndex !== -1) {
|
if (playerIndex !== -1) {
|
||||||
// 更新普通玩家当前局的分数
|
|
||||||
// 确保roundScores数组有足够的空间
|
|
||||||
if (players.value[playerIndex].roundScores.length <= roundIndex) {
|
if (players.value[playerIndex].roundScores.length <= roundIndex) {
|
||||||
players.value[playerIndex].roundScores.length = roundIndex + 1
|
players.value[playerIndex].roundScores.length = roundIndex + 1
|
||||||
}
|
}
|
||||||
@@ -477,13 +676,22 @@ onMounted(() => {
|
|||||||
players.value[playerIndex].roundScores[roundIndex] = updatedPlayer.score
|
players.value[playerIndex].roundScores[roundIndex] = updatedPlayer.score
|
||||||
// 计算总分:所有局分数的总和
|
// 计算总分:所有局分数的总和
|
||||||
players.value[playerIndex].score = players.value[playerIndex].roundScores.reduce((sum, score) => sum + (score || 0), 0)
|
players.value[playerIndex].score = players.value[playerIndex].roundScores.reduce((sum, score) => sum + (score || 0), 0)
|
||||||
|
|
||||||
|
// 为每个玩家设置单局分数和局次,并提交到后端
|
||||||
|
// 创建临时的detailscore对象,避免多个玩家数据互相覆盖
|
||||||
|
const tempDetailScore = {
|
||||||
|
roomId: players.value[playerIndex].roomId, // 当前玩家的roomId
|
||||||
|
userId: players.value[playerIndex].id, // 当前玩家ID
|
||||||
|
score: updatedPlayer.score, // 当前局的分数
|
||||||
|
gameTime: currentRound, // 当前局次
|
||||||
|
detailType: '0'
|
||||||
|
}
|
||||||
|
postdetailscore(tempDetailScore)
|
||||||
|
putroomuser()
|
||||||
} else if (updatedPlayer.id === 'table') {
|
} else if (updatedPlayer.id === 'table') {
|
||||||
// 更新台板玩家当前局的分数
|
|
||||||
// 确保roundScores数组有足够的空间
|
|
||||||
if (tablePlayer.roundScores.length <= roundIndex) {
|
if (tablePlayer.roundScores.length <= roundIndex) {
|
||||||
tablePlayer.roundScores.length = roundIndex + 1
|
tablePlayer.roundScores.length = roundIndex + 1
|
||||||
}
|
}
|
||||||
// 保存当前局的分数
|
|
||||||
tablePlayer.roundScores[roundIndex] = updatedPlayer.score
|
tablePlayer.roundScores[roundIndex] = updatedPlayer.score
|
||||||
// 计算总分:所有局分数的总和
|
// 计算总分:所有局分数的总和
|
||||||
tablePlayer.score = tablePlayer.roundScores.reduce((sum, score) => sum + (score || 0), 0)
|
tablePlayer.score = tablePlayer.roundScores.reduce((sum, score) => sum + (score || 0), 0)
|
||||||
@@ -533,15 +741,14 @@ onMounted(() => {
|
|||||||
console.error('从本地存储获取用户信息失败:', error);
|
console.error('从本地存储获取用户信息失败:', error);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
}); // 补充onMounted的闭合括号+花括号 → 原代码此处也缺失
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
// 移除事件监听器
|
// 移除事件监听器
|
||||||
uni.$off('updatePlayers');
|
uni.$off('updatePlayers');
|
||||||
uni.$off('userDataUpdated');
|
uni.$off('userDataUpdated');
|
||||||
})
|
});
|
||||||
</script>
|
</script><style lang="less" scoped>
|
||||||
<style lang="less" scoped>
|
|
||||||
.singleplay {
|
.singleplay {
|
||||||
width: 750rpx;
|
width: 750rpx;
|
||||||
margin: 0;
|
margin: 0;
|
||||||
|
|||||||
Reference in New Issue
Block a user