Browse Source

balance view

master
tangmingyou 3 years ago
parent
commit
6ebabe2916
  1. 401
      src/api/proto.js
  2. 3
      src/api/wsapi.js
  3. 20
      src/pages/lobby/lobby.jsx
  4. 2
      src/pages/new_table/new_table.jsx
  5. 27
      src/pages/table/table.jsx
  6. 9
      src/store/user.js

401
src/api/proto.js

@ -1434,6 +1434,7 @@ export const api = $root.api = (() => {
* @property {number|Long|null} [id] ResIdentity id * @property {number|Long|null} [id] ResIdentity id
* @property {string|null} [username] ResIdentity username * @property {string|null} [username] ResIdentity username
* @property {string|null} [avatar] ResIdentity avatar * @property {string|null} [avatar] ResIdentity avatar
* @property {number|null} [balance] ResIdentity balance
*/ */
/** /**
@ -1475,6 +1476,14 @@ export const api = $root.api = (() => {
*/ */
ResIdentity.prototype.avatar = ""; ResIdentity.prototype.avatar = "";
/**
* ResIdentity balance.
* @member {number} balance
* @memberof api.ResIdentity
* @instance
*/
ResIdentity.prototype.balance = 0;
/** /**
* Creates a new ResIdentity instance using the specified properties. * Creates a new ResIdentity instance using the specified properties.
* @function create * @function create
@ -1505,6 +1514,8 @@ export const api = $root.api = (() => {
writer.uint32(/* id 4, wireType 2 =*/34).string(message.username); writer.uint32(/* id 4, wireType 2 =*/34).string(message.username);
if (message.avatar != null && Object.hasOwnProperty.call(message, "avatar")) if (message.avatar != null && Object.hasOwnProperty.call(message, "avatar"))
writer.uint32(/* id 5, wireType 2 =*/42).string(message.avatar); writer.uint32(/* id 5, wireType 2 =*/42).string(message.avatar);
if (message.balance != null && Object.hasOwnProperty.call(message, "balance"))
writer.uint32(/* id 6, wireType 0 =*/48).int32(message.balance);
return writer; return writer;
}; };
@ -1551,6 +1562,10 @@ export const api = $root.api = (() => {
message.avatar = reader.string(); message.avatar = reader.string();
break; break;
} }
case 6: {
message.balance = reader.int32();
break;
}
default: default:
reader.skipType(tag & 7); reader.skipType(tag & 7);
break; break;
@ -1595,6 +1610,9 @@ export const api = $root.api = (() => {
if (message.avatar != null && message.hasOwnProperty("avatar")) if (message.avatar != null && message.hasOwnProperty("avatar"))
if (!$util.isString(message.avatar)) if (!$util.isString(message.avatar))
return "avatar: string expected"; return "avatar: string expected";
if (message.balance != null && message.hasOwnProperty("balance"))
if (!$util.isInteger(message.balance))
return "balance: integer expected";
return null; return null;
}; };
@ -1623,6 +1641,8 @@ export const api = $root.api = (() => {
message.username = String(object.username); message.username = String(object.username);
if (object.avatar != null) if (object.avatar != null)
message.avatar = String(object.avatar); message.avatar = String(object.avatar);
if (object.balance != null)
message.balance = object.balance | 0;
return message; return message;
}; };
@ -1647,6 +1667,7 @@ export const api = $root.api = (() => {
object.id = options.longs === String ? "0" : 0; object.id = options.longs === String ? "0" : 0;
object.username = ""; object.username = "";
object.avatar = ""; object.avatar = "";
object.balance = 0;
} }
if (message.id != null && message.hasOwnProperty("id")) if (message.id != null && message.hasOwnProperty("id"))
if (typeof message.id === "number") if (typeof message.id === "number")
@ -1657,6 +1678,8 @@ export const api = $root.api = (() => {
object.username = message.username; object.username = message.username;
if (message.avatar != null && message.hasOwnProperty("avatar")) if (message.avatar != null && message.hasOwnProperty("avatar"))
object.avatar = message.avatar; object.avatar = message.avatar;
if (message.balance != null && message.hasOwnProperty("balance"))
object.balance = message.balance;
return object; return object;
}; };
@ -8356,6 +8379,384 @@ export const api = $root.api = (() => {
return ResGameNextRound; return ResGameNextRound;
})(); })();
api.ReqAccountBalance = (function() {
/**
* Properties of a ReqAccountBalance.
* @memberof api
* @interface IReqAccountBalance
*/
/**
* Constructs a new ReqAccountBalance.
* @memberof api
* @classdesc Represents a ReqAccountBalance.
* @implements IReqAccountBalance
* @constructor
* @param {api.IReqAccountBalance=} [properties] Properties to set
*/
function ReqAccountBalance(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
/**
* Creates a new ReqAccountBalance instance using the specified properties.
* @function create
* @memberof api.ReqAccountBalance
* @static
* @param {api.IReqAccountBalance=} [properties] Properties to set
* @returns {api.ReqAccountBalance} ReqAccountBalance instance
*/
ReqAccountBalance.create = function create(properties) {
return new ReqAccountBalance(properties);
};
/**
* Encodes the specified ReqAccountBalance message. Does not implicitly {@link api.ReqAccountBalance.verify|verify} messages.
* @function encode
* @memberof api.ReqAccountBalance
* @static
* @param {api.IReqAccountBalance} message ReqAccountBalance message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
ReqAccountBalance.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
return writer;
};
/**
* Encodes the specified ReqAccountBalance message, length delimited. Does not implicitly {@link api.ReqAccountBalance.verify|verify} messages.
* @function encodeDelimited
* @memberof api.ReqAccountBalance
* @static
* @param {api.IReqAccountBalance} message ReqAccountBalance message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
ReqAccountBalance.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a ReqAccountBalance message from the specified reader or buffer.
* @function decode
* @memberof api.ReqAccountBalance
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {api.ReqAccountBalance} ReqAccountBalance
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
ReqAccountBalance.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.ReqAccountBalance();
while (reader.pos < end) {
let tag = reader.uint32();
switch (tag >>> 3) {
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a ReqAccountBalance message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof api.ReqAccountBalance
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {api.ReqAccountBalance} ReqAccountBalance
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
ReqAccountBalance.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader))
reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a ReqAccountBalance message.
* @function verify
* @memberof api.ReqAccountBalance
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
ReqAccountBalance.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
return null;
};
/**
* Creates a ReqAccountBalance message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof api.ReqAccountBalance
* @static
* @param {Object.<string,*>} object Plain object
* @returns {api.ReqAccountBalance} ReqAccountBalance
*/
ReqAccountBalance.fromObject = function fromObject(object) {
if (object instanceof $root.api.ReqAccountBalance)
return object;
return new $root.api.ReqAccountBalance();
};
/**
* Creates a plain object from a ReqAccountBalance message. Also converts values to other types if specified.
* @function toObject
* @memberof api.ReqAccountBalance
* @static
* @param {api.ReqAccountBalance} message ReqAccountBalance
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
ReqAccountBalance.toObject = function toObject() {
return {};
};
/**
* Converts this ReqAccountBalance to JSON.
* @function toJSON
* @memberof api.ReqAccountBalance
* @instance
* @returns {Object.<string,*>} JSON object
*/
ReqAccountBalance.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
/**
* Gets the default type url for ReqAccountBalance
* @function getTypeUrl
* @memberof api.ReqAccountBalance
* @static
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns {string} The default type url
*/
ReqAccountBalance.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
if (typeUrlPrefix === undefined) {
typeUrlPrefix = "type.googleapis.com";
}
return typeUrlPrefix + "/api.ReqAccountBalance";
};
return ReqAccountBalance;
})();
api.ResAccountBalance = (function() {
/**
* Properties of a ResAccountBalance.
* @memberof api
* @interface IResAccountBalance
* @property {number|null} [balance] ResAccountBalance balance
*/
/**
* Constructs a new ResAccountBalance.
* @memberof api
* @classdesc Represents a ResAccountBalance.
* @implements IResAccountBalance
* @constructor
* @param {api.IResAccountBalance=} [properties] Properties to set
*/
function ResAccountBalance(properties) {
if (properties)
for (let keys = Object.keys(properties), i = 0; i < keys.length; ++i)
if (properties[keys[i]] != null)
this[keys[i]] = properties[keys[i]];
}
/**
* ResAccountBalance balance.
* @member {number} balance
* @memberof api.ResAccountBalance
* @instance
*/
ResAccountBalance.prototype.balance = 0;
/**
* Creates a new ResAccountBalance instance using the specified properties.
* @function create
* @memberof api.ResAccountBalance
* @static
* @param {api.IResAccountBalance=} [properties] Properties to set
* @returns {api.ResAccountBalance} ResAccountBalance instance
*/
ResAccountBalance.create = function create(properties) {
return new ResAccountBalance(properties);
};
/**
* Encodes the specified ResAccountBalance message. Does not implicitly {@link api.ResAccountBalance.verify|verify} messages.
* @function encode
* @memberof api.ResAccountBalance
* @static
* @param {api.IResAccountBalance} message ResAccountBalance message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
ResAccountBalance.encode = function encode(message, writer) {
if (!writer)
writer = $Writer.create();
if (message.balance != null && Object.hasOwnProperty.call(message, "balance"))
writer.uint32(/* id 1, wireType 0 =*/8).int32(message.balance);
return writer;
};
/**
* Encodes the specified ResAccountBalance message, length delimited. Does not implicitly {@link api.ResAccountBalance.verify|verify} messages.
* @function encodeDelimited
* @memberof api.ResAccountBalance
* @static
* @param {api.IResAccountBalance} message ResAccountBalance message or plain object to encode
* @param {$protobuf.Writer} [writer] Writer to encode to
* @returns {$protobuf.Writer} Writer
*/
ResAccountBalance.encodeDelimited = function encodeDelimited(message, writer) {
return this.encode(message, writer).ldelim();
};
/**
* Decodes a ResAccountBalance message from the specified reader or buffer.
* @function decode
* @memberof api.ResAccountBalance
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @param {number} [length] Message length if known beforehand
* @returns {api.ResAccountBalance} ResAccountBalance
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
ResAccountBalance.decode = function decode(reader, length) {
if (!(reader instanceof $Reader))
reader = $Reader.create(reader);
let end = length === undefined ? reader.len : reader.pos + length, message = new $root.api.ResAccountBalance();
while (reader.pos < end) {
let tag = reader.uint32();
switch (tag >>> 3) {
case 1: {
message.balance = reader.int32();
break;
}
default:
reader.skipType(tag & 7);
break;
}
}
return message;
};
/**
* Decodes a ResAccountBalance message from the specified reader or buffer, length delimited.
* @function decodeDelimited
* @memberof api.ResAccountBalance
* @static
* @param {$protobuf.Reader|Uint8Array} reader Reader or buffer to decode from
* @returns {api.ResAccountBalance} ResAccountBalance
* @throws {Error} If the payload is not a reader or valid buffer
* @throws {$protobuf.util.ProtocolError} If required fields are missing
*/
ResAccountBalance.decodeDelimited = function decodeDelimited(reader) {
if (!(reader instanceof $Reader))
reader = new $Reader(reader);
return this.decode(reader, reader.uint32());
};
/**
* Verifies a ResAccountBalance message.
* @function verify
* @memberof api.ResAccountBalance
* @static
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
ResAccountBalance.verify = function verify(message) {
if (typeof message !== "object" || message === null)
return "object expected";
if (message.balance != null && message.hasOwnProperty("balance"))
if (!$util.isInteger(message.balance))
return "balance: integer expected";
return null;
};
/**
* Creates a ResAccountBalance message from a plain object. Also converts values to their respective internal types.
* @function fromObject
* @memberof api.ResAccountBalance
* @static
* @param {Object.<string,*>} object Plain object
* @returns {api.ResAccountBalance} ResAccountBalance
*/
ResAccountBalance.fromObject = function fromObject(object) {
if (object instanceof $root.api.ResAccountBalance)
return object;
let message = new $root.api.ResAccountBalance();
if (object.balance != null)
message.balance = object.balance | 0;
return message;
};
/**
* Creates a plain object from a ResAccountBalance message. Also converts values to other types if specified.
* @function toObject
* @memberof api.ResAccountBalance
* @static
* @param {api.ResAccountBalance} message ResAccountBalance
* @param {$protobuf.IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
*/
ResAccountBalance.toObject = function toObject(message, options) {
if (!options)
options = {};
let object = {};
if (options.defaults)
object.balance = 0;
if (message.balance != null && message.hasOwnProperty("balance"))
object.balance = message.balance;
return object;
};
/**
* Converts this ResAccountBalance to JSON.
* @function toJSON
* @memberof api.ResAccountBalance
* @instance
* @returns {Object.<string,*>} JSON object
*/
ResAccountBalance.prototype.toJSON = function toJSON() {
return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
};
/**
* Gets the default type url for ResAccountBalance
* @function getTypeUrl
* @memberof api.ResAccountBalance
* @static
* @param {string} [typeUrlPrefix] your custom typeUrlPrefix(default "type.googleapis.com")
* @returns {string} The default type url
*/
ResAccountBalance.getTypeUrl = function getTypeUrl(typeUrlPrefix) {
if (typeUrlPrefix === undefined) {
typeUrlPrefix = "type.googleapis.com";
}
return typeUrlPrefix + "/api.ResAccountBalance";
};
return ResAccountBalance;
})();
return api; return api;
})(); })();

3
src/api/wsapi.js

@ -27,3 +27,6 @@ export const reqDismissGameTable = () => sendPromise(api.ReqDismissGameTable.cre
export const reqGameStart = () => sendPromise(api.ReqGameStart.create()); export const reqGameStart = () => sendPromise(api.ReqGameStart.create());
// 玩家下注 // 玩家下注
export const reqBetting = (betType, betChip) => sendPromise(api.ReqBetting.create({betType, betChip})); export const reqBetting = (betType, betChip) => sendPromise(api.ReqBetting.create({betType, betChip}));
// 账户余额
export const reqAccountBalance = () => sendPromise(api.ReqAccountBalance.create({}));

20
src/pages/lobby/lobby.jsx

@ -1,10 +1,12 @@
import React, { Component } from 'react' import React, { Component } from 'react'
import { connect } from "react-redux";
import { View, Button, Image } from '@tarojs/components' import { View, Button, Image } from '@tarojs/components'
import Taro from '@tarojs/taro' import Taro from '@tarojs/taro'
import { setBalance } from '@/store/user';
import './lobby.scss' import './lobby.scss'
import { navigateTo, redirectTo, showToast } from '@/utils/application' import { navigateTo, redirectTo, showToast } from '@/utils/application'
import { reqLobbyView, reqJoinTable } from '@/api/wsapi' import { reqLobbyView, reqJoinTable, reqAccountBalance } from '@/api/wsapi'
import Title from '@/components/title' import Title from '@/components/title'
import coin1 from '@/assets/coin-1.png' import coin1 from '@/assets/coin-1.png'
import robotIcon from '@/assets/icon/robot-1.svg' import robotIcon from '@/assets/icon/robot-1.svg'
@ -41,6 +43,15 @@ class Lobby extends Component {
// .catch(err => { // .catch(err => {
// console.error(err) // console.error(err)
// }) // })
reqAccountBalance()
.then(res => {
this.props.setBalance(res.balance)
})
.catch(err => {
console.error('账户余额查询失败:', err)
showToast({title: err})
})
} }
handleReqLobbyView = () => { handleReqLobbyView = () => {
@ -53,6 +64,7 @@ class Lobby extends Component {
reqLobbyView() reqLobbyView()
.then(res => { .then(res => {
this.setState({tables: res.tables}, () => { this.setState({tables: res.tables}, () => {
//
if (res.curTableNo) { if (res.curTableNo) {
redirectTo({url: '/pages/table/table'}); redirectTo({url: '/pages/table/table'});
} }
@ -130,4 +142,8 @@ class Lobby extends Component {
} }
} }
export default Lobby const mapDispatchToProps = dispatch => ({
setBalance: b => dispatch(setBalance(b))
});
export default connect(() =>({}), mapDispatchToProps)(Lobby)

2
src/pages/new_table/new_table.jsx

@ -71,7 +71,7 @@ function NewTable() {
<View className="prop-wrap"> <View className="prop-wrap">
<View className="prop-k"><Text>大盲注额</Text></View> <View className="prop-k"><Text>大盲注额</Text></View>
<View className="prop-v"> <View className="prop-v">
<Range modelValue={bigBlind} min={2} max={100} step={2} <Range modelValue={bigBlind} min={2} max={20} step={2}
hiddenRange={true} hiddenTag={false} hiddenRange={true} hiddenTag={false}
activeColor="#1BCE7D" inactiveColor="#D8D8D8" activeColor="#1BCE7D" inactiveColor="#D8D8D8"
button={<View className="range-custom-button"><Text>{bigBlind}</Text></View>} button={<View className="range-custom-button"><Text>{bigBlind}</Text></View>}

27
src/pages/table/table.jsx

@ -2,11 +2,12 @@ import React, { Component } from 'react'
import { View, Text, Image, Input, Button } from '@tarojs/components' import { View, Text, Image, Input, Button } from '@tarojs/components'
import { connect } from 'react-redux' import { connect } from 'react-redux'
import cnames from 'classnames' import cnames from 'classnames'
import { setBalance } from '@/store/user';
import { import {
reqGameFullStatus, reqKickOutTable, reqLeaveTable, reqGameFullStatus, reqKickOutTable, reqLeaveTable,
reqReadyStart, reqDismissGameTable, reqGameStart, reqReadyStart, reqDismissGameTable, reqGameStart,
reqCancelReady, reqBetting reqCancelReady, reqBetting, reqAccountBalance
} from '@/api/wsapi' } from '@/api/wsapi'
import { addMsgListen, removeMsgListener } from '@/api/websocket' import { addMsgListen, removeMsgListener } from '@/api/websocket'
import { isEmpty } from '@/utils/validator' import { isEmpty } from '@/utils/validator'
@ -169,6 +170,16 @@ class Table extends Component {
setTimeout(() => redirectTo({url: '/pages/lobby/lobby'}), 800); setTimeout(() => redirectTo({url: '/pages/lobby/lobby'}), 800);
} }
}) })
//
reqAccountBalance()
.then(res => {
this.props.setBalance(res.balance)
})
.catch(err => {
console.error('账户余额查询失败:', err)
showToast({title: err})
})
// }, 2000) // }, 2000)
} }
@ -182,7 +193,7 @@ class Table extends Component {
// //
let betSecondLimit = -1; let betSecondLimit = -1;
let betSecondInterval = -1; let betSecondInterval = -1;
console.log('bettingPlayer', bettingPlayer) // console.log('bettingPlayer', bettingPlayer)
if (bettingPlayer && bettingPlayer.betRole) { if (bettingPlayer && bettingPlayer.betRole) {
const {betTimeLimit: timeLimit, betSecondLimit: secondLimit} = bettingPlayer.betRole; const {betTimeLimit: timeLimit, betSecondLimit: secondLimit} = bettingPlayer.betRole;
if (timeLimit) { if (timeLimit) {
@ -657,8 +668,12 @@ class Table extends Component {
} }
} }
function mapStateToProps(state) { const mapStateToProps = state => ({
return {user: state.user} user: state.user
} });
const mapDispatchToProps = dispatch => ({
setBalance: b => dispatch(setBalance(b))
});
export default connect(mapStateToProps)(Table) export default connect(mapStateToProps, mapDispatchToProps)(Table)

9
src/store/user.js

@ -8,7 +8,7 @@ const userSlice = createSlice({
nickname: 'PromNick', nickname: 'PromNick',
avatar: '', avatar: '',
defaultAvatar: 'https://img0.baidu.com/it/u=2477829979,2171947490&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500', defaultAvatar: 'https://img0.baidu.com/it/u=2477829979,2171947490&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500',
balance: 10086, balance: 0,
}, },
reducers: { reducers: {
setUserInfo: (state, {payload}) => { setUserInfo: (state, {payload}) => {
@ -17,10 +17,13 @@ const userSlice = createSlice({
state.username = payload.username; state.username = payload.username;
state.avatar = !payload.avatar ? state.avatar : '/api/gm/avatar/' + payload.avatar; state.avatar = !payload.avatar ? state.avatar : '/api/gm/avatar/' + payload.avatar;
// return {...state, ...action.payload} // return {...state, ...action.payload}
} },
setBalance: (state, {payload}) => {
state.balance = payload
},
} }
}) })
export default userSlice export default userSlice
export const { setUserInfo } = userSlice.actions export const { setUserInfo, setBalance } = userSlice.actions

Loading…
Cancel
Save