Browse Source

bugfix

master
tangmingyou 4 years ago
parent
commit
eba472a1e3
  1. 11
      src/api/websocket.js
  2. 6
      src/app.js
  3. 12
      src/pages/lobby/lobby.jsx
  4. 4
      src/pages/login/login.jsx
  5. 33
      src/pages/new_table/new_table.jsx
  6. 58
      src/pages/table/table.jsx
  7. 5
      src/pages/table/table.scss
  8. 2
      src/store/user.js

11
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)
}

6
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不会清除本地记录会继续重拾

12
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 {
}}>
<Image
className={cnames("circle-avatar", {'circle-icon': player.robot || !player.id})}
src={player.robot ? robotIcon : !player.id ? plusIcon : (player.avatar || this.state.defaultAvatar)}
src={player.robot ? robotIcon : !player.id ? plusIcon : ((player.avatar && `/api/gm/avatar/${player.avatar}`) || this.state.defaultAvatar)}
/>
</View>
))

4
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) {

33
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() {
<View className="prop-v">
<Radio.RadioGroup value={texasType} direction="horizontal" onChange={setTexasType}>
<Radio value={1} iconSize={Taro.pxTransform(16)}>限注德州扑克</Radio>
<Radio value={2} iconSize={Taro.pxTransform(16)}>底池限制德州扑克</Radio>
<Radio value={3} iconSize={Taro.pxTransform(16)}>无限制德州扑克</Radio>
<Radio disabled value={2} iconSize={Taro.pxTransform(16)}>底池限制德州扑克</Radio>
<Radio disabled value={3} iconSize={Taro.pxTransform(16)}>无限制德州扑克</Radio>
</Radio.RadioGroup>
</View>
</View>
<View className="prop-wrap">
<View className="prop-k"><Text>大盲注额</Text></View>
<View className="prop-v">
<Range modelValue={bigBlind} min={2} max={200} step={2}
<Range modelValue={bigBlind} min={2} max={100} step={2}
hiddenRange={true} hiddenTag={false}
activeColor="#1BCE7D" inactiveColor="#D8D8D8"
button={<View className="range-custom-button"><Text>{bigBlind}</Text></View>}
@ -95,15 +92,15 @@ function NewTable() {
player.item === 0
? <View key={j} onClick={() => choosePlayer(player.index)} className='player empty-player'><Image className="empty-icon" src={addIcon} /></View>
: <View key={j} className="player-wrap">
<View className="player-icon"><Image className="player-icon-img" src={player.item === 1 ? userIcon : robotIcon} /></View>
<View className="close-icon" onClick={(e) => {
e.stopPropagation();
players[player.index] = 0;
setPlayers([...players]);
}}><Image className="close-icon-img" src={closeIcon} /></View>
<View className="player">
<Text className="player-name">{player.item === 1 ? 'Player' : 'Robot'}#{player.index + 1}</Text>
</View>
<View className="player-icon"><Image className="player-icon-img" src={player.item === 1 ? userIcon : robotIcon} /></View>
<View className="close-icon" onClick={(e) => {
e.stopPropagation();
players[player.index] = 0;
setPlayers([...players]);
}}><Image className="close-icon-img" src={closeIcon} /></View>
<View className="player">
<Text className="player-name">{player.item === 1 ? 'Player' : 'Robot'}#{player.index + 1}</Text>
</View>
</View>
))
}

58
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
: <View className="blind-icon"><Image src={index === bigBlindPos ? bigBlindIcon : smallBlindIcon} /></View>
}
{
//
!inGame || !isIn(player.status,4,6) ? null :
!isIn(stage, 2,3,4,5) || !isIn(player.status, 6) ? null :
<View className={cnames({"round-wrap-l": j%2===0,"round-wrap-r": j%2===1})}>
<View className="time-wrap">
<Image src={timeIcon} />
@ -394,7 +415,7 @@ class Table extends Component {
</View>
}
{
typeof(winsChip[player.id]) !== 'number' ? null
stage === 7 && typeof(winsChip[player.id]) !== 'number' ? null
: <View className="wins-chip-wrap">
<View className={cnames("wins-chip", {'lose': winsChip[player.id] < 0, 'win': winsChip[player.id] >= 0})}><Text>{winsChip[player.id] >= 0 ? '+' : ''}{winsChip[player.id]}</Text></View>
</View>
@ -416,7 +437,7 @@ class Table extends Component {
}
{/* 头像名称 */}
<View className={cnames("player", {'player-wait': !player.id || isIn(player.status, 3, 7) || (player.status === 1 && !player.master)})}>
<View className="avatar-wrap">{!player.id ? null : <Image className="avatar" src={player.avatar || avatar} />}</View>
<View className="avatar-wrap">{!player.id ? null : <Image className="avatar" src={(player.avatar ? `/api/gm/avatar/${player.avatar}` : defaultAvatar)} />}</View>
<View className="player-name"><Text>{player.username}</Text></View>
</View>
{
@ -441,7 +462,7 @@ class Table extends Component {
<View className="desktop-wrap">
<View className="desktop-cards">
{
!inGame ? null : this.state.publicCard.map((card, i) => (
!isIn(stage, 2,3,4,5,7) ? null : this.state.publicCard.map((card, i) => (
<Card flipIn={-3} key={i} w={38} h={48} dot={isIn(stage,1,2)?-3 : cardDot(card, -3)} suit={cardSuit(card)} />
))
}
@ -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
: <View className="blind-icon blind-icon-self"><Image src={selfIndex === bigBlindPos ? bigBlindIcon : smallBlindIcon} /></View>
}
{
@ -507,7 +528,6 @@ class Table extends Component {
<Text>{selfPlayer.handType.handZh}</Text>
</View>
}
{
!pn || pn.playerId !== selfPlayer.id ? null : <View className="notice-wrap-l notice-wrap-self">
{pn.line1 && <View className="line1"><Text>{pn.line1}</Text></View>}
@ -517,7 +537,7 @@ class Table extends Component {
}
{
typeof(winsChip[selfPlayer.id]) !== 'number' ? null
stage === 7 && typeof(winsChip[selfPlayer.id]) !== 'number' ? null
: <View className="wins-chip-wrap wins-chip-wrap-self">
<View className={cnames("wins-chip", {'lose': winsChip[selfPlayer.id] < 0, 'win': winsChip[selfPlayer.id] >= 0})}>
<Text>{winsChip[selfPlayer.id] >= 0 ? '+' : ''}{winsChip[selfPlayer.id]}</Text>
@ -534,7 +554,7 @@ class Table extends Component {
<View className='u-opt'>
<View>
<View className="s-info-wrap">
<View className="s-avatar"><Image className="s-avatar-img" src={selfPlayer.avatar || avatar || defaultAvatar} /></View>
<View className="s-avatar"><Image className="s-avatar-img" src={(selfPlayer.avatar && `/api/gm/avatar/${selfPlayer.avatar}`) || defaultAvatar} /></View>
<View className="s-username"><Text>{selfPlayer.username}</Text></View>
</View>
<View className="s-wallet-wrap">
@ -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)}
/></View>}
{!isIn(2, betOpts) ? null : <View className="amount-sub" onClick={this.handleSubPlusBetting.bind(this, -1, 1)}><Image className="amount-sub-icon" src={sub1Icon} /></View>}
{!isIn(2, betOpts) ? null : <View className="amount-plus" onClick={this.handleSubPlusBetting.bind(this, 1, 1)}><Image className="amount-plus-icon" src={plus1Icon} /></View>}

5
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;

2
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}
}
}

Loading…
Cancel
Save