From eba472a1e38a6c32d91fe0c2725bf99e855c3f1f Mon Sep 17 00:00:00 2001
From: tangmingyou <234767776@qq.com>
Date: Fri, 17 Feb 2023 18:43:50 +0800
Subject: [PATCH] bugfix
---
src/api/websocket.js | 11 ++++++
src/app.js | 6 ++--
src/pages/lobby/lobby.jsx | 12 ++-----
src/pages/login/login.jsx | 4 +--
src/pages/new_table/new_table.jsx | 33 ++++++++----------
src/pages/table/table.jsx | 58 +++++++++++++++++++++----------
src/pages/table/table.scss | 5 +--
src/store/user.js | 2 +-
8 files changed, 77 insertions(+), 54 deletions(-)
diff --git a/src/api/websocket.js b/src/api/websocket.js
index d0fe3e9..1bdc369 100644
--- a/src/api/websocket.js
+++ b/src/api/websocket.js
@@ -5,6 +5,7 @@ import { fetchOpMap, fetchRouteWs } from '@/api/api'
import { getStorage, removeStorage } from '@/utils/storage';
import { redirectTo, showToast } from '@/utils/application';
import { setUserInfo } from '@/store/user'
+import { isIn } from '@/utils/collect';
const { api } = proto
@@ -99,6 +100,16 @@ const websocket = {
listener(res);
return;
}
+ // 错误消息,提示一下
+ if (wrap.op === opFail) {
+ console.error('ResFail:', res)
+ showToast({title: res.code + ":" + res.msg})
+ if (isIn(res.code, 401, 403)) { // 认证失败,异地登录
+ setTimeout(() => redirectTo({url: '/pages/login/login'}), 1200)
+ }
+ return;
+ }
+
console.log('no handler msg:', wrap.op, res)
}
diff --git a/src/app.js b/src/app.js
index 5ca4f43..39de28d 100644
--- a/src/app.js
+++ b/src/app.js
@@ -35,17 +35,17 @@ window.srt = new SDK({
/**
* 开启打印调试信息, 默认 false
*/
- debug: true,
+ debug: false,
/**
* 代理配置,自动代理页面浏览事件、页面离开事件、点击事件,默认 false。建议开启
*/
- autoTrack: true,
+ autoTrack: false,
/**
* 自动开始上报,默认 true。建议开启
*/
- autoStart: true,
+ autoStart: false,
/**
* 上报返回的钩子函数,返回 false 则代表不通过,SDK不会清除本地记录,会继续重拾
diff --git a/src/pages/lobby/lobby.jsx b/src/pages/lobby/lobby.jsx
index f1dab53..4a0d9e7 100644
--- a/src/pages/lobby/lobby.jsx
+++ b/src/pages/lobby/lobby.jsx
@@ -1,14 +1,10 @@
-import React, { Component, useState } from 'react'
-import { View, Text, Button, Image, Radio, RadioGroup, Label, Slider,Head } from '@tarojs/components'
+import React, { Component } from 'react'
+import { View, Button, Image } from '@tarojs/components'
import Taro from '@tarojs/taro'
-import { useSelector, useDispatch } from 'react-redux'
-
import './lobby.scss'
import { navigateTo, redirectTo, showToast } from '@/utils/application'
-import { increment } from '@/store/index'
import { reqLobbyView, reqJoinTable } from '@/api/wsapi'
-import proto from '@/api/proto'
import Title from '@/components/title'
import coin1 from '@/assets/coin-1.png'
import robotIcon from '@/assets/icon/robot-1.svg'
@@ -17,8 +13,6 @@ import refreshIcon from '@/assets/icon/refresh-fill.svg';
import cnames from 'classnames';
-const {ReqLobbyView} = proto.api;
-
class Lobby extends Component {
constructor(props) {
super(props)
@@ -181,7 +175,7 @@ class Lobby extends Component {
}}>
))
diff --git a/src/pages/login/login.jsx b/src/pages/login/login.jsx
index 119332d..e67c848 100644
--- a/src/pages/login/login.jsx
+++ b/src/pages/login/login.jsx
@@ -1,4 +1,4 @@
-import React, { Component, useState } from 'react'
+import React, { useState } from 'react'
import { View, Text, Input, Image, Button, Label } from '@tarojs/components'
import Taro from '@tarojs/taro';
//import { Progress } from '@nutui/nutui-react-taro';
@@ -38,7 +38,7 @@ function Login() {
const wsRes = await fetchRouteWs();
// 初始化 websocket 连接
ws.init(tokenRes.data.token, opMapRes.data, wsRes.data);
- showToast({title: '登录成功', duration: 800});
+ showToast({title: tokenRes.msg || '登录成功', duration: 800});
// 重定向到大厅
setTimeout(() => redirectTo({url: '/pages/lobby/lobby'}), 800);
}catch(err) {
diff --git a/src/pages/new_table/new_table.jsx b/src/pages/new_table/new_table.jsx
index 6b12c50..fd456d3 100644
--- a/src/pages/new_table/new_table.jsx
+++ b/src/pages/new_table/new_table.jsx
@@ -1,6 +1,6 @@
-import React, { Component, useState } from 'react'
-import { View, Text, Image, Button, Slider } from '@tarojs/components'
-import { Popup, Picker, Range, Radio } from '@nutui/nutui-react-taro';
+import React, { useState } from 'react'
+import { View, Text, Image, Button } from '@tarojs/components'
+import { Range, Radio } from '@nutui/nutui-react-taro';
import { useSelector } from 'react-redux'
import Taro from '@tarojs/taro';
@@ -8,15 +8,12 @@ import { redirectTo } from '@/utils/application'
import './new_table.scss'
import Title from '@/components/title'
import { reqCreateTable } from '@/api/wsapi'
-import proto from '@/api/proto';
import { showToast } from '@/utils/application'
import userIcon from '@/assets/icon/user-2.svg'
import robotIcon from '@/assets/icon/robot-1.svg'
import closeIcon from '@/assets/icon/close-1.svg'
import addIcon from '@/assets/icon/add-2.svg'
-const { ReqCreateTable } = proto.api
-
function NewTable() {
const {username, nickname, avatar} = useSelector(state => state.user);
const [submitLoading, setSubmitLoading] = useState(false);
@@ -66,15 +63,15 @@ function NewTable() {
限注德州扑克
- 底池限制德州扑克
- 无限制德州扑克
+ 底池限制德州扑克
+ 无限制德州扑克
大盲注额:
- {bigBlind}}
@@ -95,15 +92,15 @@ function NewTable() {
player.item === 0
? choosePlayer(player.index)} className='player empty-player'>
:
-
- {
- e.stopPropagation();
- players[player.index] = 0;
- setPlayers([...players]);
- }}>
-
- {player.item === 1 ? 'Player' : 'Robot'}#{player.index + 1}
-
+
+ {
+ e.stopPropagation();
+ players[player.index] = 0;
+ setPlayers([...players]);
+ }}>
+
+ {player.item === 1 ? 'Player' : 'Robot'}#{player.index + 1}
+
))
}
diff --git a/src/pages/table/table.jsx b/src/pages/table/table.jsx
index b7ea449..8962e72 100644
--- a/src/pages/table/table.jsx
+++ b/src/pages/table/table.jsx
@@ -1,4 +1,4 @@
-import React, { Component, useState } from 'react'
+import React, { Component } from 'react'
import { View, Text, Image, Input, Button } from '@tarojs/components'
import { connect } from 'react-redux'
import cnames from 'classnames'
@@ -59,7 +59,6 @@ class Table extends Component {
constructor(props) {
super(props)
this.state = {
- inGame: false,
tableNo: 0,
stage: 0, // 游戏阶段: 1等待玩家准备;2下大盲注;3下小盲注;4发公共牌;5发第四张公共牌,轮流下注;6发第五张公共牌,轮流下注,7比牌结算
chip: 0,
@@ -83,7 +82,7 @@ class Table extends Component {
// winsChip: {}, // {1:14, 2:-14}
playerNoticeLines: [], // {line1: "+6",line2: "跟注",playerId: 1}
playerNotice: null, //{line1: "+108",line2: "加注:12221126",line3: '跟注:6', playerId: 3},
- winsChip: {1: -20, 2: 40, 3: -20},
+ winsChip: {}, //{7: -20, 8: 40, 3: -20},
}
}
@@ -140,8 +139,10 @@ class Table extends Component {
window.winsChip = res;
this.setState({winsChip: res.winsChip});
setTimeout(() => { // 输赢筹码展示一会后消失
- this.setState({winsChip: {}});
- }, 1300);
+ if (this.state.winsChip === res.winsChip) {
+ this.setState({winsChip: {}});
+ }
+ }, 10000);
});
// // 扣除大盲注(显示3秒)
// addMsgListen('api.ResBigBlindChip', res => {
@@ -174,7 +175,6 @@ class Table extends Component {
this.setState({
playerId: res.playerId,
- inGame: !!res.inGame,
tableNo: res.tableNo,
stage: res.gameStage,
chip: res.chip || 0,
@@ -291,7 +291,8 @@ class Table extends Component {
this.setState({betType: 1, bettingChip: betMin, betConfirmText: '跟注'});
break;
case 4:
- this.setState({betType: 4, betConfirmText: '弃牌'});
+ // , betConfirmText: '弃牌'
+ this.setState({betType: 4}, this.handleBetConfirm.bind(this));
break;
}
}
@@ -304,7 +305,7 @@ class Table extends Component {
console.log('confirm', betType, bettingChip)
- this.setState({betSubmitLoading: true}, () => {
+ this.setState({bettingChip: 0, betSubmitLoading: true}, () => {
reqBetting(betType, bettingChip || 0)
.then(res => {
console.log('betRes', res);
@@ -318,12 +319,32 @@ class Table extends Component {
})
}
+ handleBettingInput(e) {
+ // const value = parseInt(e.target.value);
+ // console.log('input', typeof(value), value, this.state.bettingChip);
+ // if (typeof(value) !== 'number') {
+ // this.setState({bettingChip: this.state.bettingChip})
+ // return;
+ // }
+ // if (value < this.state.betMin) {
+ // this.setState({bettingChip: this.state.betRole.bettingChip})
+ // return showToast({title: `当前最小下注额${this.state.betRole.betMin}`})
+ // }
+ // if (value > this.state.betMax) {
+ // this.setState({bettingChip: this.state.betRole.bettingChip})
+ // return showToast({title: `当前最大下注额${this.state.betMax}`})
+ // }
+ // console.log('input', value, this.state.betMin, this.state.betRole.betMax);
+
+ this.setState({bettingChip: value})
+ }
+
render() {
const { username, nickname, avatar, defaultAvatar } = this.props.user; // useSelector(state => state.user);
// const players = [1, 2, 3, 4, 5, 6];
const players = this.state.players.map((player, index) => ({player, index}));
const {
- inGame, playerId, tableNo,
+ playerId, tableNo,
stage, bigBlindPos, smallBlindPos,
chip, otherPlayers,
selfIndex, selfPlayer,
@@ -368,12 +389,12 @@ class Table extends Component {
}
{
// 大小盲注图标
- !player.id ? null : !(inGame && isIn(index, bigBlindPos, smallBlindPos)) ? null
+ !player.id ? null : !(isIn(stage, 2,3,4,5) && isIn(index, bigBlindPos, smallBlindPos)) ? null
:
}
{
// 等待读秒,下注金额
- !inGame || !isIn(player.status,4,6) ? null :
+ !isIn(stage, 2,3,4,5) || !isIn(player.status, 6) ? null :
@@ -394,7 +415,7 @@ class Table extends Component {
}
{
- typeof(winsChip[player.id]) !== 'number' ? null
+ stage === 7 && typeof(winsChip[player.id]) !== 'number' ? null
:
= 0})}>{winsChip[player.id] >= 0 ? '+' : ''}{winsChip[player.id]}
@@ -416,7 +437,7 @@ class Table extends Component {
}
{/* 头像名称 */}
- {!player.id ? null : }
+ {!player.id ? null : }
{player.username}
{
@@ -441,7 +462,7 @@ class Table extends Component {
{
- !inGame ? null : this.state.publicCard.map((card, i) => (
+ !isIn(stage, 2,3,4,5,7) ? null : this.state.publicCard.map((card, i) => (
))
}
@@ -480,7 +501,7 @@ class Table extends Component {
{
// 大小盲注图标
- !(inGame && isIn(selfIndex, bigBlindPos, smallBlindPos)) ? null
+ !(isIn(stage, 2,3,4,5) && isIn(selfIndex, bigBlindPos, smallBlindPos)) ? null
:
}
{
@@ -507,7 +528,6 @@ class Table extends Component {
{selfPlayer.handType.handZh}
}
-
{
!pn || pn.playerId !== selfPlayer.id ? null :
{pn.line1 && {pn.line1}}
@@ -517,7 +537,7 @@ class Table extends Component {
}
{
- typeof(winsChip[selfPlayer.id]) !== 'number' ? null
+ stage === 7 && typeof(winsChip[selfPlayer.id]) !== 'number' ? null
:
= 0})}>
{winsChip[selfPlayer.id] >= 0 ? '+' : ''}{winsChip[selfPlayer.id]}
@@ -534,7 +554,7 @@ class Table extends Component {
-
+
{selfPlayer.username}
@@ -552,7 +572,7 @@ class Table extends Component {
type="numberpad"
placeholder='betting chip'
value={bettingChip}
- onInput={e => this.setState({bettingChip: e.target.value})}
+ onInput={this.handleBettingInput.bind(this)}
/>}
{!isIn(2, betOpts) ? null : }
{!isIn(2, betOpts) ? null : }
diff --git a/src/pages/table/table.scss b/src/pages/table/table.scss
index 717c023..e9936d9 100644
--- a/src/pages/table/table.scss
+++ b/src/pages/table/table.scss
@@ -84,6 +84,7 @@
// align-content: space-around;
flex-flow: row wrap;
// width: 405px;
+ width: 100%;
margin: 46px 26px 0 26px;
}
@@ -253,7 +254,7 @@
// border: 1px solid red;
display: flex;
justify-content: center;
- animation: move2Bottom 1000ms;
+ animation: move2Bottom 2000ms;
}
.wins-chip {
font-size: 18px;
@@ -264,7 +265,7 @@
.wins-chip-wrap-self {
left: -66px;
top: -50px;
- animation: move2Top 1000ms;
+ animation: move2Top 2000ms;
}
.lose {
color: #A8A29D;
diff --git a/src/store/user.js b/src/store/user.js
index 407317f..6dd85a6 100644
--- a/src/store/user.js
+++ b/src/store/user.js
@@ -14,7 +14,7 @@ const userSlice = createSlice({
// console.log('setUserInfo', state, payload)
state.id = payload.id;
state.username = payload.username;
- state.avatar = payload.avatar;
+ state.avatar = !payload.avatar ? state.avatar : '/api/gm/avatar/' + payload.avatar;
// return {...state, ...action.payload}
}
}