22
This commit is contained in:
@@ -13,5 +13,5 @@
|
||||
</script>
|
||||
|
||||
<style>
|
||||
/*每个页面公共css */
|
||||
</style>
|
||||
|
||||
</style>
|
||||
@@ -1,26 +1,33 @@
|
||||
import App from './App'
|
||||
import { getToken,checkLoginStatus } from '@/api/login.js';
|
||||
import {
|
||||
getToken,
|
||||
checkLoginStatus
|
||||
} from '@/api/login.js';
|
||||
import StaticValue from '@/utils/StaticValue.js'
|
||||
|
||||
// #ifndef VUE3
|
||||
import Vue from 'vue'
|
||||
import './uni.promisify.adaptor'
|
||||
import uView from 'uview-ui'; // 如果 uView 支持模块化导出
|
||||
Vue.use(uView)
|
||||
Vue.config.productionTip = false
|
||||
App.mpType = 'app'
|
||||
const app = new Vue({
|
||||
...App
|
||||
...App
|
||||
})
|
||||
app.$mount()
|
||||
// #endif
|
||||
|
||||
// #ifdef VUE3
|
||||
import { createSSRApp } from 'vue'
|
||||
import {
|
||||
createSSRApp
|
||||
} from 'vue'
|
||||
export function createApp() {
|
||||
const app = createSSRApp(App)
|
||||
app.config.globalProperties.$StaticValue = StaticValue; // 挂载全局变量
|
||||
return {
|
||||
app
|
||||
}
|
||||
const app = createSSRApp(App)
|
||||
app.config.globalProperties.$StaticValue = StaticValue; // 挂载全局变量
|
||||
return {
|
||||
app
|
||||
}
|
||||
}
|
||||
// #endif
|
||||
checkLoginStatus();
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
{
|
||||
"dependencies": {
|
||||
"less": "^4.4.2",
|
||||
"less-loader": "^12.3.0"
|
||||
"less-loader": "^12.3.0",
|
||||
"uview-ui": "^2.0.38",
|
||||
"vue": "^3.5.24"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@vitejs/plugin-vue": "^6.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -59,4 +59,6 @@
|
||||
]
|
||||
},
|
||||
"uniIdRouter": {}
|
||||
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@
|
||||
</view>
|
||||
</view>
|
||||
|
||||
|
||||
<!-- 未结束对局提示 -->
|
||||
<view class="notice">
|
||||
<view class="notice-icon">
|
||||
|
||||
@@ -7,23 +7,12 @@
|
||||
<!-- 功能菜单 -->
|
||||
<view class="header">
|
||||
<view class="list-container">
|
||||
<view class="list-item">
|
||||
<text class="number">1</text>
|
||||
<text class="text">添加玩家</text>
|
||||
</view>
|
||||
<view class="list-item">
|
||||
<text class="number">2</text>
|
||||
<text class="text">转让房主</text>
|
||||
</view>
|
||||
<view class="list-item">
|
||||
<text class="number">3</text>
|
||||
<text class="text">语音播报</text>
|
||||
<text class="voice-status">{{}}</text>
|
||||
</view>
|
||||
<view class="list-item">
|
||||
<text class="number">4</text>
|
||||
<text class="text">台板(茶水)</text>
|
||||
<view class="list-item"><text @click="changeA">+ </text>
|
||||
<text>添加玩家</text>
|
||||
</view>
|
||||
<view class="list-item"><text @click="changeA">♟</text> <text>转让计分员</text></view>
|
||||
<view class="list-item"><text @click="changeX">{{X}}</text> <text>语音播报</text></view>
|
||||
<view class="list-item"><text @click="changeY">{{Y}}</text> <text>台板</text></view>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -62,7 +51,7 @@
|
||||
{{item.score}}
|
||||
</text>
|
||||
<view class="player-action">
|
||||
<button class="btn-batch" @click="giveScore">给分</button>
|
||||
<button class="btn-batch" @click="giveScore(item)">给分</button>
|
||||
</view>
|
||||
</view>
|
||||
|
||||
@@ -79,7 +68,7 @@
|
||||
<!-- 底部操作栏 -->
|
||||
<view class="footer">
|
||||
<button class="btn-detail">给分详情</button>
|
||||
<button class="btn-settle">结算房间</button>
|
||||
<button class="btn-settle" @click="endRoom">结算房间</button>
|
||||
</view>
|
||||
<div class="give-score" v-if="IsGive">
|
||||
<div class="give-contain">
|
||||
@@ -92,7 +81,7 @@
|
||||
<!-- 按钮区域 -->
|
||||
<div class="give-footer">
|
||||
<button class="btn btn-cancel" @click="closeGive">取消</button>
|
||||
<button class="btn btn-confirm">确定</button>
|
||||
<button class="btn btn-confirm" @click="confirmGive">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -103,12 +92,19 @@
|
||||
<script setup>
|
||||
import {
|
||||
ref,
|
||||
onUnmounted
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
getCurrentInstance
|
||||
} from 'vue'
|
||||
import {
|
||||
onLoad
|
||||
} from '@dcloudio/uni-app'
|
||||
|
||||
const proxy = getCurrentInstance().proxy;
|
||||
const userInfo = ref({})
|
||||
const getUserInfo = async () => {
|
||||
userInfo.value = proxy.$StaticValue.getUserInfo();
|
||||
}
|
||||
const GiveScoreData = ref({}) //给分更新分数的对象
|
||||
const isSelf = ref(true)
|
||||
const voiceEnabled = ref(true)
|
||||
const socketTask = ref(null) // 改为使用 uni-app 的 SocketTask
|
||||
@@ -116,8 +112,49 @@
|
||||
const roomUsers = ref([])
|
||||
const Score = ref(0)
|
||||
|
||||
|
||||
/*
|
||||
头上那一点
|
||||
|
||||
*/
|
||||
const X = ref('关')
|
||||
const Y = ref('关')
|
||||
|
||||
function changeX() {
|
||||
if (X.value == '关') {
|
||||
X.value = '开'
|
||||
} else {
|
||||
X.value = '关'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function changeY() {
|
||||
if (Y.value == '关') {
|
||||
Y.value = '开'
|
||||
} else {
|
||||
Y.value = '关'
|
||||
}
|
||||
}
|
||||
|
||||
function changeA() {
|
||||
|
||||
uni.showToast({
|
||||
title: '入机房间不需要',
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function endRoom() {
|
||||
uni.showToast({
|
||||
title: '计算成功',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
onLoad((options) => {
|
||||
console.log("556", options.roomUserInfo)
|
||||
|
||||
let roomUserInfo = null;
|
||||
|
||||
if (options.roomUserInfo) {
|
||||
@@ -126,32 +163,8 @@
|
||||
roomUserInfo = JSON.parse(decodedInfo);
|
||||
console.log('解析后的数据:', roomUserInfo);
|
||||
|
||||
if (roomUserInfo?.playerType === 'business') {
|
||||
const userId = roomUserInfo.createUser;
|
||||
const exists = roomUsers.value.some(user => user.userId === userId);
|
||||
if (!exists) {
|
||||
roomUsers.value.push({
|
||||
userId: userId,
|
||||
score: 0,
|
||||
playerType: 'business',
|
||||
nickName: roomUserInfo.nickName,
|
||||
avatars: roomUserInfo.avatars
|
||||
});
|
||||
}
|
||||
} else if (roomUserInfo?.playerType === 'user') {
|
||||
const userId = roomUserInfo.createUser;
|
||||
const exists = roomUsers.value.some(user => user.userId === userId);
|
||||
if (!exists) {
|
||||
roomUsers.value.push({
|
||||
userId: userId,
|
||||
score: 0,
|
||||
playerType: 'user',
|
||||
nickName: roomUserInfo.nickName,
|
||||
avatars: roomUserInfo.avatars
|
||||
});
|
||||
}
|
||||
}
|
||||
console.log("888888888888", roomUserInfo)
|
||||
|
||||
console.log("用户加入的用户信息初始化", roomUserInfo)
|
||||
// 初始化WebSocket连接
|
||||
initWebSocket(roomUserInfo);
|
||||
}
|
||||
@@ -217,15 +230,14 @@
|
||||
const sendJoinRoomMessage = (roomUserInfo) => {
|
||||
if (socketTask.value) {
|
||||
const joinMsg = {
|
||||
type: 'join_room',
|
||||
type: 'userJoined',
|
||||
roomId: roomUserInfo.roomId,
|
||||
userId: roomUserInfo.userId,
|
||||
userInfo: {
|
||||
nickName: roomUserInfo.nickName,
|
||||
avatars: roomUserInfo.avatars // 修正拼写错误
|
||||
}
|
||||
};
|
||||
nickName: roomUserInfo.nickName,
|
||||
avatars: roomUserInfo.avatars
|
||||
|
||||
};
|
||||
console.log("发送加入消息", joinMsg)
|
||||
// 使用 SocketTask 的 send 方法
|
||||
socketTask.value.send({
|
||||
data: JSON.stringify(joinMsg),
|
||||
@@ -242,16 +254,24 @@
|
||||
// 处理WebSocket消息(保持不变)
|
||||
const handleWebSocketMessage = (message) => {
|
||||
console.log('收到消息:', message);
|
||||
|
||||
console.log('收到消息:', message.type);
|
||||
switch (message.type) {
|
||||
case 'user_joined':
|
||||
handlePlayerJoin(message.data);
|
||||
case 'system':
|
||||
console.log("系统消息", roomUsers.value)
|
||||
break;
|
||||
case 'user_left':
|
||||
case 'userJoined':
|
||||
console.log("用户加入消息", message.userId)
|
||||
handlePlayerJoin(message);
|
||||
break;
|
||||
|
||||
case 'scoreUpdate':
|
||||
handleScoreUpdate(message);
|
||||
break;
|
||||
case 'userLeft':
|
||||
handlePlayerLeave(message.data);
|
||||
break;
|
||||
case 'score_update':
|
||||
handleScoreUpdate(message.data);
|
||||
case 'error':
|
||||
console.log("发生错误77777777777777777777777")
|
||||
break;
|
||||
default:
|
||||
console.log('未知消息类型:', message);
|
||||
@@ -260,15 +280,17 @@
|
||||
|
||||
// 处理玩家加入(保持不变)
|
||||
const handlePlayerJoin = (playerData) => {
|
||||
console.log("玩家加入的名称", playerData.nickName)
|
||||
const exists = roomUsers.value.some(user => user.userId === playerData.userId);
|
||||
if (!exists) {
|
||||
roomUsers.value.push({
|
||||
userId: playerData.userId,
|
||||
userId: +playerData.userId,
|
||||
score: 0,
|
||||
playerType: playerData.playerType || 'user',
|
||||
nickName: playerData.nickName,
|
||||
avatars: playerData.avatars
|
||||
avatars: playerData.avatars || ''
|
||||
});
|
||||
console.log("加入处理后的房间人数信息", roomUsers.value)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -279,39 +301,54 @@
|
||||
|
||||
// 处理分数更新(保持不变)
|
||||
const handleScoreUpdate = (scoreData) => {
|
||||
const user = roomUsers.value.find(user => user.userId === scoreData.userId);
|
||||
if (user) {
|
||||
user.score = scoreData.newScore;
|
||||
}
|
||||
console.log("更新分数的数据", scoreData)
|
||||
const giveId = scoreData.giveUserId
|
||||
const givedId = scoreData.givedUserId
|
||||
roomUsers.value.find(i => i.userId == giveId).score = scoreData.giveUserScore
|
||||
roomUsers.value.find(i => i.userId == givedId).score = scoreData.givedUserScore
|
||||
|
||||
console.log("更新完后的数据", roomUsers.value)
|
||||
}
|
||||
//给分
|
||||
const giveScore = () => {
|
||||
const giveScore = (data) => {
|
||||
IsGive.value = true
|
||||
GiveScoreData.value = data
|
||||
}
|
||||
//取消给分
|
||||
const closeGive = () => {
|
||||
Score.value = 0
|
||||
IsGive.value = false
|
||||
}
|
||||
//确认给分
|
||||
const confirmGive = () => {
|
||||
const item = GiveScoreData.value
|
||||
console.log("给分的对象", item)
|
||||
console.log("roomUsers的数据", roomUsers.value)
|
||||
const self = roomUsers.value.find(i => i.userId == userInfo.value.userId)
|
||||
const selfScore = self.score
|
||||
console.log("自己的分数", selfScore)
|
||||
const changeScore = {
|
||||
type: 'scoreUpdate',
|
||||
giveUserId: userInfo.value.userId,
|
||||
giveUserScore: selfScore,
|
||||
givedUserId: item.userId,
|
||||
givedUserScore: item.score,
|
||||
Score: +Score.value
|
||||
}
|
||||
console.log("给出的分数详情", changeScore)
|
||||
socketTask.value.send({
|
||||
data: JSON.stringify(changeScore),
|
||||
success: () => {
|
||||
console.log("给分成功")
|
||||
},
|
||||
fail: () => {
|
||||
console.log("给分失败")
|
||||
}
|
||||
})
|
||||
Score.value = 0
|
||||
IsGive.value = false
|
||||
}
|
||||
// 发送WebSocket消息 - 适配 SocketTask API
|
||||
const sendWebSocketMessage = (message) => {
|
||||
if (socketTask.value) {
|
||||
socketTask.value.send({
|
||||
data: JSON.stringify(message),
|
||||
success: () => {
|
||||
console.log('消息发送成功');
|
||||
},
|
||||
fail: (err) => {
|
||||
console.error('消息发送失败:', err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.error('WebSocket未连接,无法发送消息');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 关闭WebSocket连接 - 适配 SocketTask API
|
||||
const closeWebSocket = () => {
|
||||
@@ -328,6 +365,9 @@
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
getUserInfo()
|
||||
})
|
||||
// 页面卸载时关闭连接
|
||||
onUnmounted(() => {
|
||||
closeWebSocket();
|
||||
@@ -374,7 +414,7 @@
|
||||
|
||||
.list-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
align-items: center;
|
||||
gap: 15rpx;
|
||||
position: relative;
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
<template>
|
||||
<view class="single">
|
||||
<view class="header">
|
||||
|
||||
|
||||
<view class="list-container">
|
||||
<view class="list-item"><text>1</text> <text>添加玩家</text></view>
|
||||
<view class="list-item"><text>2</text> <text>转让计分员</text></view>
|
||||
<view class="list-item"><text>3</text> <text>语音播报</text></view>
|
||||
<view class="list-item"><text>4</text> <text>台板</text></view>
|
||||
<view class="list-item"><text @click="changeA">+ </text>
|
||||
<text>添加玩家</text>
|
||||
</view>
|
||||
<view class="list-item"><text @click="changeA">♟</text> <text>转让计分员</text></view>
|
||||
<view class="list-item"><text @click="changeX">{{X}}</text> <text>语音播报</text></view>
|
||||
<view class="list-item"><text @click="changeY">{{Y}}</text> <text>台板</text></view>
|
||||
</view>
|
||||
<view class="remind">
|
||||
<text class="remind-title">对局记录</text><text class="remind-content">点击对局进行修改</text>
|
||||
@@ -58,8 +62,8 @@
|
||||
</view>
|
||||
</view>
|
||||
<view class="footer">
|
||||
<view class="start btn-primary">开局计分</view>
|
||||
<view class="end btn-secondary">结算房间</view>
|
||||
<view class="start btn-primary" @click="startRoom">开局计分</view>
|
||||
<view class="end btn-secondary" @click="endRoom">结算房间</view>
|
||||
</view>
|
||||
</view>
|
||||
</template>
|
||||
@@ -87,6 +91,48 @@
|
||||
scores: [3, 4, -3, 2]
|
||||
}
|
||||
])
|
||||
const X = ref('关')
|
||||
const Y = ref('关')
|
||||
|
||||
function changeX() {
|
||||
if (X.value == '关') {
|
||||
X.value = '开'
|
||||
} else {
|
||||
X.value = '关'
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function changeY() {
|
||||
if (Y.value == '关') {
|
||||
Y.value = '开'
|
||||
} else {
|
||||
Y.value = '关'
|
||||
}
|
||||
}
|
||||
|
||||
function changeA() {
|
||||
|
||||
uni.showToast({
|
||||
title: '入机房间不需要',
|
||||
icon: 'none'
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
function endRoom() {
|
||||
uni.showToast({
|
||||
title: '结算成功',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
function startRoom() {
|
||||
uni.showToast({
|
||||
title: '已开始计分',
|
||||
icon: 'none'
|
||||
})
|
||||
}
|
||||
|
||||
// 对局数据
|
||||
const rounds = ref([1, 2, 3, 4]) // 4局
|
||||
@@ -133,7 +179,7 @@
|
||||
font-size: 28rpx;
|
||||
color: #666;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
|
||||
align-items: center;
|
||||
gap: 10rpx;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user