From 6cd8a9995ca3f5c4a30deec9a322bcad8931273a Mon Sep 17 00:00:00 2001 From: tangmingyou <234767776@qq.com> Date: Mon, 20 Feb 2023 17:53:41 +0800 Subject: [PATCH] login logic --- src/api/http.js | 9 +++-- src/api/proto.js | 47 +++++++++++----------- src/app.js | 43 ++++++++++---------- src/components/title.jsx | 1 + src/pages/lobby/lobby.jsx | 82 ++++----------------------------------- src/pages/login/login.jsx | 7 ++-- src/pages/table/table.jsx | 9 +++-- 7 files changed, 68 insertions(+), 130 deletions(-) diff --git a/src/api/http.js b/src/api/http.js index 1541eeb..40b7b28 100644 --- a/src/api/http.js +++ b/src/api/http.js @@ -39,10 +39,11 @@ const fetch = function (method, url, params) { retryTimes: 0, complete(res) { if (res.statusCode === 401 || res.statusCode === 403 || res.statusCode === 422) { - // 跳登录 - reLaunch({ - url: "/pages/login/login" - }) + if (url !== '/api/auth/authorize') { + // 跳登录 + reLaunch({url: "/pages/login/login"}); + } + return reject(res.data); } if (res.statusCode !== 200 || res.data.code) { // || !res.data diff --git a/src/api/proto.js b/src/api/proto.js index 8112feb..b281e3b 100644 --- a/src/api/proto.js +++ b/src/api/proto.js @@ -1833,6 +1833,7 @@ export const api = $root.api = (() => { * Properties of a ResLobbyView. * @memberof api * @interface IResLobbyView + * @property {number|null} [curTableNo] ResLobbyView curTableNo * @property {Array.|null} [tables] ResLobbyView tables */ @@ -1852,6 +1853,14 @@ export const api = $root.api = (() => { this[keys[i]] = properties[keys[i]]; } + /** + * ResLobbyView curTableNo. + * @member {number} curTableNo + * @memberof api.ResLobbyView + * @instance + */ + ResLobbyView.prototype.curTableNo = 0; + /** * ResLobbyView tables. * @member {Array.} tables @@ -1884,6 +1893,8 @@ export const api = $root.api = (() => { ResLobbyView.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); + if (message.curTableNo != null && Object.hasOwnProperty.call(message, "curTableNo")) + writer.uint32(/* id 1, wireType 0 =*/8).int32(message.curTableNo); if (message.tables != null && message.tables.length) for (let i = 0; i < message.tables.length; ++i) $root.api.LobbyTable.encode(message.tables[i], writer.uint32(/* id 3, wireType 2 =*/26).fork()).ldelim(); @@ -1921,6 +1932,10 @@ export const api = $root.api = (() => { while (reader.pos < end) { let tag = reader.uint32(); switch (tag >>> 3) { + case 1: { + message.curTableNo = reader.int32(); + break; + } case 3: { if (!(message.tables && message.tables.length)) message.tables = []; @@ -1962,6 +1977,9 @@ export const api = $root.api = (() => { ResLobbyView.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; + if (message.curTableNo != null && message.hasOwnProperty("curTableNo")) + if (!$util.isInteger(message.curTableNo)) + return "curTableNo: integer expected"; if (message.tables != null && message.hasOwnProperty("tables")) { if (!Array.isArray(message.tables)) return "tables: array expected"; @@ -1986,6 +2004,8 @@ export const api = $root.api = (() => { if (object instanceof $root.api.ResLobbyView) return object; let message = new $root.api.ResLobbyView(); + if (object.curTableNo != null) + message.curTableNo = object.curTableNo | 0; if (object.tables) { if (!Array.isArray(object.tables)) throw TypeError(".api.ResLobbyView.tables: array expected"); @@ -2014,6 +2034,10 @@ export const api = $root.api = (() => { let object = {}; if (options.arrays || options.defaults) object.tables = []; + if (options.defaults) + object.curTableNo = 0; + if (message.curTableNo != null && message.hasOwnProperty("curTableNo")) + object.curTableNo = message.curTableNo; if (message.tables && message.tables.length) { object.tables = []; for (let j = 0; j < message.tables.length; ++j) @@ -4812,7 +4836,6 @@ export const api = $root.api = (() => { * Properties of a ResGameFullStatus. * @memberof api * @interface IResGameFullStatus - * @property {boolean|null} [inGame] ResGameFullStatus inGame * @property {number|null} [tableNo] ResGameFullStatus tableNo * @property {number|null} [gameStage] ResGameFullStatus gameStage * @property {number|null} [chip] ResGameFullStatus chip @@ -4840,14 +4863,6 @@ export const api = $root.api = (() => { this[keys[i]] = properties[keys[i]]; } - /** - * ResGameFullStatus inGame. - * @member {boolean} inGame - * @memberof api.ResGameFullStatus - * @instance - */ - ResGameFullStatus.prototype.inGame = false; - /** * ResGameFullStatus tableNo. * @member {number} tableNo @@ -4936,8 +4951,6 @@ export const api = $root.api = (() => { ResGameFullStatus.encode = function encode(message, writer) { if (!writer) writer = $Writer.create(); - if (message.inGame != null && Object.hasOwnProperty.call(message, "inGame")) - writer.uint32(/* id 1, wireType 0 =*/8).bool(message.inGame); if (message.tableNo != null && Object.hasOwnProperty.call(message, "tableNo")) writer.uint32(/* id 2, wireType 0 =*/16).int32(message.tableNo); if (message.gameStage != null && Object.hasOwnProperty.call(message, "gameStage")) @@ -4990,10 +5003,6 @@ export const api = $root.api = (() => { while (reader.pos < end) { let tag = reader.uint32(); switch (tag >>> 3) { - case 1: { - message.inGame = reader.bool(); - break; - } case 2: { message.tableNo = reader.int32(); break; @@ -5065,9 +5074,6 @@ export const api = $root.api = (() => { ResGameFullStatus.verify = function verify(message) { if (typeof message !== "object" || message === null) return "object expected"; - if (message.inGame != null && message.hasOwnProperty("inGame")) - if (typeof message.inGame !== "boolean") - return "inGame: boolean expected"; if (message.tableNo != null && message.hasOwnProperty("tableNo")) if (!$util.isInteger(message.tableNo)) return "tableNo: integer expected"; @@ -5119,8 +5125,6 @@ export const api = $root.api = (() => { if (object instanceof $root.api.ResGameFullStatus) return object; let message = new $root.api.ResGameFullStatus(); - if (object.inGame != null) - message.inGame = Boolean(object.inGame); if (object.tableNo != null) message.tableNo = object.tableNo | 0; if (object.gameStage != null) @@ -5181,7 +5185,6 @@ export const api = $root.api = (() => { object.players = []; } if (options.defaults) { - object.inGame = false; object.tableNo = 0; object.gameStage = 0; object.chip = 0; @@ -5193,8 +5196,6 @@ export const api = $root.api = (() => { object.bigBlindPos = 0; object.smallBlindPos = 0; } - if (message.inGame != null && message.hasOwnProperty("inGame")) - object.inGame = message.inGame; if (message.tableNo != null && message.hasOwnProperty("tableNo")) object.tableNo = message.tableNo; if (message.gameStage != null && message.hasOwnProperty("gameStage")) diff --git a/src/app.js b/src/app.js index 39de28d..611f0f5 100644 --- a/src/app.js +++ b/src/app.js @@ -73,28 +73,29 @@ class App extends Component { } componentDidShow() { - console.log('instance', getInstance(), 'app mount') - - if (!getInstance().router.path.startsWith('/pages/login/login')) { - // 非登录页,检查token是否存在 - const token = getStorage('_t'); - if (!token) { - setTimeout(() => redirectTo({url: '/pages/login/login'}), 500) - } else { - // 尝试连接 websocket - // const [opMap, wsRes] = await ; - Promise.all([fetchOpMap(), fetchRouteWs()]) - .then(([opMap, wsRes]) => { - console.log('token', token, opMap, wsRes) - websocket.init(token, opMap.data, wsRes.data); - window.websocket = websocket; - }) - .catch(err => { - console.log('ws conn error:', err) - removeStorage('_t') - setTimeout(() => redirectTo({url: '/pages/login/login'}), 500) - }) + // console.log('instance', getInstance(), 'app mount') + // 检查token是否存在 + const isLoginPage = getInstance().router.path.startsWith('/pages/login/login'); + const token = getStorage('_t'); + // console.log('token', isLoginPage, token) + if (!token) { + if (!isLoginPage) { + setTimeout(() => redirectTo({url: '/pages/login/login'}), 500); } + } else { + // 尝试连接 websocket + Promise.all([fetchOpMap(), fetchRouteWs()]) + .then(([opMap, wsRes]) => { + // console.log('token', token, opMap, wsRes) + websocket.init(token, opMap.data, wsRes.data); + window.websocket = websocket; + setTimeout(() => redirectTo({url: '/pages/lobby/lobby'}), 500); + }) + .catch(err => { + console.log('ws conn error:', err) + removeStorage('_t') + setTimeout(() => redirectTo({url: '/pages/login/login'}), 500) + }) } } diff --git a/src/components/title.jsx b/src/components/title.jsx index e90f201..95343dd 100644 --- a/src/components/title.jsx +++ b/src/components/title.jsx @@ -1,5 +1,6 @@ import React from 'react' import { View, Text, Image } from '@tarojs/components' +import { Menu, MenuItem } from '@nutui/nutui-react-taro'; import { navigateBack } from '@/utils/application' import left from '@/assets/icon/left-1.svg' import './style/title.scss' diff --git a/src/pages/lobby/lobby.jsx b/src/pages/lobby/lobby.jsx index 4a0d9e7..f483a5a 100644 --- a/src/pages/lobby/lobby.jsx +++ b/src/pages/lobby/lobby.jsx @@ -24,38 +24,6 @@ class Lobby extends Component { {value: 1, text: '', checked: false}, ], - list: [ - { - value: '美国', - text: '美国', - checked: false - }, - { - value: '中国', - text: '中国', - checked: true - }, - { - value: '巴西', - text: '巴西', - checked: false - }, - { - value: '日本', - text: '日本', - checked: false - }, - { - value: '英国', - text: '英国', - checked: false - }, - { - value: '法国', - text: '法国', - checked: false - } - ], } this.circleEle = [1,2,3,4,5,6,7]; this.circleElePos = [{x:16,y:8},{x:70,y:-3},{x:110,y:28},{x:115,y:70},{x:80,y:105},{x:20,y:100},{x:-2,y:60}]; @@ -84,11 +52,15 @@ class Lobby extends Component { setTimeout(() => { reqLobbyView() .then(res => { - console.log('lobby res:', res) - this.setState({tables: res.tables}) + this.setState({tables: res.tables}, () => { + console.log('redirect...', res) + if (res.tableNo) { + redirectTo({url: '/pages/table/table'}); + } + }) }) .catch(err => { - console.log('lobby err:', err) + showToast({title: err}) }) .finally(() => { this.setState({lobbyLoading: false}) @@ -111,46 +83,6 @@ class Lobby extends Component { // const count = useSelector((state) => state.counter.value) // const user = useSelector((state) => state.user) - // console.log('state', this.state) - - // return ( - // - // 设置 step - // - // 显示当前 value - // - // 设置最小/最大值 - // - // - // ); - - // return ( - // - // {/* */} - // - // - // 默认样式 - // 选中 - // 未选中 - // - // - // 推荐展示样式 - // - // - // {this.state.list.map((item, i) => { - // return ( - // - // ) - // })} - // - // - // - // - // - // ); - return ( 大厅 -> 新桌面 -> 进桌面 -> profile(弹窗) @@ -34,6 +34,7 @@ function Login() { //const token = "AgOjcdf3goeYDX3lwWWwkXtVpcrL-l2rX8csrRKgs3_-BC3JOx0l6nZU0MV25eIn" try { const [tokenRes, opMapRes] = await Promise.all([doLogin(state), fetchOpMap()]); + removeStorage('_t'); setStorage('_t', tokenRes.data.token); const wsRes = await fetchRouteWs(); // 初始化 websocket 连接 @@ -42,12 +43,12 @@ function Login() { // 重定向到大厅 setTimeout(() => redirectTo({url: '/pages/lobby/lobby'}), 800); }catch(err) { - showToast({icon: 'error', title: err.msg}) + showToast({icon: 'error', title: err}) } finally { setSubmitLoding(false); } } - console.log(submitLoding) + return ( <View className='login'> <View className='ceiling'></View> diff --git a/src/pages/table/table.jsx b/src/pages/table/table.jsx index 8962e72..8e2703c 100644 --- a/src/pages/table/table.jsx +++ b/src/pages/table/table.jsx @@ -290,10 +290,11 @@ class Table extends Component { case 1: // 1跟注,2加注(-[0]+),3All-In,4弃牌,5过牌 this.setState({betType: 1, bettingChip: betMin, betConfirmText: '跟注'}); break; - case 4: - // , betConfirmText: '弃牌' + case 4: // 弃牌 this.setState({betType: 4}, this.handleBetConfirm.bind(this)); break; + case 5: // 过牌 + this.setState({betType: 5}, this.handleBetConfirm.bind(this)); } } @@ -596,8 +597,8 @@ class Table extends Component { !isIn(4, betOpts) ? <Button className="ctl-opt-btn-2 ctl-opacity0">弃牌</Button> : <Button onClick={this.handleBetting.bind(this, 4)} className="ctl-opt-btn-2">弃牌</Button> }</View> - <View className="ctl-opt" style={{opacity: 0}}>{ - !isIn(5, betOpts)? <Button className="ctl-opt-btn-1 ctl-opacity0">过牌</Button> + <View className="ctl-opt">{ + !isIn(5, betOpts) ? <Button className="ctl-opt-btn-1 ctl-opacity0">过牌</Button> : <Button onClick={this.handleBetting.bind(this, 5)} className="ctl-opt-btn-1">过牌</Button> }</View> <View className="ctl-opt">{