Browse Source

login logic

master
tangmingyou 4 years ago
parent
commit
6cd8a9995c
  1. 9
      src/api/http.js
  2. 47
      src/api/proto.js
  3. 43
      src/app.js
  4. 1
      src/components/title.jsx
  5. 82
      src/pages/lobby/lobby.jsx
  6. 7
      src/pages/login/login.jsx
  7. 9
      src/pages/table/table.jsx

9
src/api/http.js

@ -39,10 +39,11 @@ const fetch = function (method, url, params) {
retryTimes: 0, retryTimes: 0,
complete(res) { complete(res) {
if (res.statusCode === 401 || res.statusCode === 403 || res.statusCode === 422) { if (res.statusCode === 401 || res.statusCode === 403 || res.statusCode === 422) {
// 跳登录 if (url !== '/api/auth/authorize') {
reLaunch({ // 跳登录
url: "/pages/login/login" reLaunch({url: "/pages/login/login"});
}) }
return reject(res.data);
} }
if (res.statusCode !== 200 || res.data.code) { // || !res.data if (res.statusCode !== 200 || res.data.code) { // || !res.data

47
src/api/proto.js

@ -1833,6 +1833,7 @@ export const api = $root.api = (() => {
* Properties of a ResLobbyView. * Properties of a ResLobbyView.
* @memberof api * @memberof api
* @interface IResLobbyView * @interface IResLobbyView
* @property {number|null} [curTableNo] ResLobbyView curTableNo
* @property {Array.<api.ILobbyTable>|null} [tables] ResLobbyView tables * @property {Array.<api.ILobbyTable>|null} [tables] ResLobbyView tables
*/ */
@ -1852,6 +1853,14 @@ export const api = $root.api = (() => {
this[keys[i]] = properties[keys[i]]; this[keys[i]] = properties[keys[i]];
} }
/**
* ResLobbyView curTableNo.
* @member {number} curTableNo
* @memberof api.ResLobbyView
* @instance
*/
ResLobbyView.prototype.curTableNo = 0;
/** /**
* ResLobbyView tables. * ResLobbyView tables.
* @member {Array.<api.ILobbyTable>} tables * @member {Array.<api.ILobbyTable>} tables
@ -1884,6 +1893,8 @@ export const api = $root.api = (() => {
ResLobbyView.encode = function encode(message, writer) { ResLobbyView.encode = function encode(message, writer) {
if (!writer) if (!writer)
writer = $Writer.create(); 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) if (message.tables != null && message.tables.length)
for (let i = 0; i < message.tables.length; ++i) 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(); $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) { while (reader.pos < end) {
let tag = reader.uint32(); let tag = reader.uint32();
switch (tag >>> 3) { switch (tag >>> 3) {
case 1: {
message.curTableNo = reader.int32();
break;
}
case 3: { case 3: {
if (!(message.tables && message.tables.length)) if (!(message.tables && message.tables.length))
message.tables = []; message.tables = [];
@ -1962,6 +1977,9 @@ export const api = $root.api = (() => {
ResLobbyView.verify = function verify(message) { ResLobbyView.verify = function verify(message) {
if (typeof message !== "object" || message === null) if (typeof message !== "object" || message === null)
return "object expected"; 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 (message.tables != null && message.hasOwnProperty("tables")) {
if (!Array.isArray(message.tables)) if (!Array.isArray(message.tables))
return "tables: array expected"; return "tables: array expected";
@ -1986,6 +2004,8 @@ export const api = $root.api = (() => {
if (object instanceof $root.api.ResLobbyView) if (object instanceof $root.api.ResLobbyView)
return object; return object;
let message = new $root.api.ResLobbyView(); let message = new $root.api.ResLobbyView();
if (object.curTableNo != null)
message.curTableNo = object.curTableNo | 0;
if (object.tables) { if (object.tables) {
if (!Array.isArray(object.tables)) if (!Array.isArray(object.tables))
throw TypeError(".api.ResLobbyView.tables: array expected"); throw TypeError(".api.ResLobbyView.tables: array expected");
@ -2014,6 +2034,10 @@ export const api = $root.api = (() => {
let object = {}; let object = {};
if (options.arrays || options.defaults) if (options.arrays || options.defaults)
object.tables = []; 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) { if (message.tables && message.tables.length) {
object.tables = []; object.tables = [];
for (let j = 0; j < message.tables.length; ++j) for (let j = 0; j < message.tables.length; ++j)
@ -4812,7 +4836,6 @@ export const api = $root.api = (() => {
* Properties of a ResGameFullStatus. * Properties of a ResGameFullStatus.
* @memberof api * @memberof api
* @interface IResGameFullStatus * @interface IResGameFullStatus
* @property {boolean|null} [inGame] ResGameFullStatus inGame
* @property {number|null} [tableNo] ResGameFullStatus tableNo * @property {number|null} [tableNo] ResGameFullStatus tableNo
* @property {number|null} [gameStage] ResGameFullStatus gameStage * @property {number|null} [gameStage] ResGameFullStatus gameStage
* @property {number|null} [chip] ResGameFullStatus chip * @property {number|null} [chip] ResGameFullStatus chip
@ -4840,14 +4863,6 @@ export const api = $root.api = (() => {
this[keys[i]] = properties[keys[i]]; this[keys[i]] = properties[keys[i]];
} }
/**
* ResGameFullStatus inGame.
* @member {boolean} inGame
* @memberof api.ResGameFullStatus
* @instance
*/
ResGameFullStatus.prototype.inGame = false;
/** /**
* ResGameFullStatus tableNo. * ResGameFullStatus tableNo.
* @member {number} tableNo * @member {number} tableNo
@ -4936,8 +4951,6 @@ export const api = $root.api = (() => {
ResGameFullStatus.encode = function encode(message, writer) { ResGameFullStatus.encode = function encode(message, writer) {
if (!writer) if (!writer)
writer = $Writer.create(); 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")) if (message.tableNo != null && Object.hasOwnProperty.call(message, "tableNo"))
writer.uint32(/* id 2, wireType 0 =*/16).int32(message.tableNo); writer.uint32(/* id 2, wireType 0 =*/16).int32(message.tableNo);
if (message.gameStage != null && Object.hasOwnProperty.call(message, "gameStage")) if (message.gameStage != null && Object.hasOwnProperty.call(message, "gameStage"))
@ -4990,10 +5003,6 @@ export const api = $root.api = (() => {
while (reader.pos < end) { while (reader.pos < end) {
let tag = reader.uint32(); let tag = reader.uint32();
switch (tag >>> 3) { switch (tag >>> 3) {
case 1: {
message.inGame = reader.bool();
break;
}
case 2: { case 2: {
message.tableNo = reader.int32(); message.tableNo = reader.int32();
break; break;
@ -5065,9 +5074,6 @@ export const api = $root.api = (() => {
ResGameFullStatus.verify = function verify(message) { ResGameFullStatus.verify = function verify(message) {
if (typeof message !== "object" || message === null) if (typeof message !== "object" || message === null)
return "object expected"; 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 (message.tableNo != null && message.hasOwnProperty("tableNo"))
if (!$util.isInteger(message.tableNo)) if (!$util.isInteger(message.tableNo))
return "tableNo: integer expected"; return "tableNo: integer expected";
@ -5119,8 +5125,6 @@ export const api = $root.api = (() => {
if (object instanceof $root.api.ResGameFullStatus) if (object instanceof $root.api.ResGameFullStatus)
return object; return object;
let message = new $root.api.ResGameFullStatus(); let message = new $root.api.ResGameFullStatus();
if (object.inGame != null)
message.inGame = Boolean(object.inGame);
if (object.tableNo != null) if (object.tableNo != null)
message.tableNo = object.tableNo | 0; message.tableNo = object.tableNo | 0;
if (object.gameStage != null) if (object.gameStage != null)
@ -5181,7 +5185,6 @@ export const api = $root.api = (() => {
object.players = []; object.players = [];
} }
if (options.defaults) { if (options.defaults) {
object.inGame = false;
object.tableNo = 0; object.tableNo = 0;
object.gameStage = 0; object.gameStage = 0;
object.chip = 0; object.chip = 0;
@ -5193,8 +5196,6 @@ export const api = $root.api = (() => {
object.bigBlindPos = 0; object.bigBlindPos = 0;
object.smallBlindPos = 0; object.smallBlindPos = 0;
} }
if (message.inGame != null && message.hasOwnProperty("inGame"))
object.inGame = message.inGame;
if (message.tableNo != null && message.hasOwnProperty("tableNo")) if (message.tableNo != null && message.hasOwnProperty("tableNo"))
object.tableNo = message.tableNo; object.tableNo = message.tableNo;
if (message.gameStage != null && message.hasOwnProperty("gameStage")) if (message.gameStage != null && message.hasOwnProperty("gameStage"))

43
src/app.js

@ -73,28 +73,29 @@ class App extends Component {
} }
componentDidShow() { componentDidShow() {
console.log('instance', getInstance(), 'app mount') // console.log('instance', getInstance(), 'app mount')
// 检查token是否存在
if (!getInstance().router.path.startsWith('/pages/login/login')) { const isLoginPage = getInstance().router.path.startsWith('/pages/login/login');
// 非登录页,检查token是否存在 const token = getStorage('_t');
const token = getStorage('_t'); // console.log('token', isLoginPage, token)
if (!token) { if (!token) {
setTimeout(() => redirectTo({url: '/pages/login/login'}), 500) if (!isLoginPage) {
} else { setTimeout(() => redirectTo({url: '/pages/login/login'}), 500);
// 尝试连接 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)
})
} }
} 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)
})
} }
} }

1
src/components/title.jsx

@ -1,5 +1,6 @@
import React from 'react' import React from 'react'
import { View, Text, Image } from '@tarojs/components' import { View, Text, Image } from '@tarojs/components'
import { Menu, MenuItem } from '@nutui/nutui-react-taro';
import { navigateBack } from '@/utils/application' import { navigateBack } from '@/utils/application'
import left from '@/assets/icon/left-1.svg' import left from '@/assets/icon/left-1.svg'
import './style/title.scss' import './style/title.scss'

82
src/pages/lobby/lobby.jsx

@ -24,38 +24,6 @@ class Lobby extends Component {
{value: 1, text: '', checked: false}, {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.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}]; 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(() => { setTimeout(() => {
reqLobbyView() reqLobbyView()
.then(res => { .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 => { .catch(err => {
console.log('lobby err:', err) showToast({title: err})
}) })
.finally(() => { .finally(() => {
this.setState({lobbyLoading: false}) this.setState({lobbyLoading: false})
@ -111,46 +83,6 @@ class Lobby extends Component {
// const count = useSelector((state) => state.counter.value) // const count = useSelector((state) => state.counter.value)
// const user = useSelector((state) => state.user) // const user = useSelector((state) => state.user)
// console.log('state', this.state)
// return (
// <View className='components-page'>
// <Text> step</Text>
// <Slider step={1} value={50}/>
// <Text> value</Text>
// <Slider step={1} value={50} showValue/>
// <Text>/</Text>
// <Slider step={1} value={100} showValue min={50} max={200}/>
// </View>
// );
// return (
// <View className='container'>
// {/* <Head title='Radio' /> */}
// <View className='page-body'>
// <View className='page-section'>
// <Text></Text>
// <Radio value='' checked></Radio>
// <Radio style='margin-left: 20rpx' value=''></Radio>
// </View>
// <View className='page-section'>
// <Text></Text>
// <View className='radio-list'>
// <RadioGroup>
// {this.state.list.map((item, i) => {
// return (
// <Label className='radio-list__label' for={i} key={i}>
// <Radio className='radio-list__radio' value={item.value} checked={item.checked}>{item.text}</Radio>
// </Label>
// )
// })}
// </RadioGroup>
// </View>
// </View>
// </View>
// </View>
// );
return ( return (
<View> <View>
<Title title={"Lobby!!"} bgColor={true} leftSolt={ <Title title={"Lobby!!"} bgColor={true} leftSolt={

7
src/pages/login/login.jsx

@ -10,7 +10,7 @@ import { redirectTo, showToast } from '@/utils/application'
import iconUser from '@/assets/icon/user-3-fill.svg' import iconUser from '@/assets/icon/user-3-fill.svg'
import iconLock from '@/assets/icon/lock-2-fill.svg' import iconLock from '@/assets/icon/lock-2-fill.svg'
import abIcon from '@/assets/icon/a-b.svg' import abIcon from '@/assets/icon/a-b.svg'
import { setStorage } from '@/utils/storage'; import { removeStorage, setStorage } from '@/utils/storage';
/* /*
登录 -> 大厅 -> 新桌面 -> 进桌面 -> profile(弹窗) 登录 -> 大厅 -> 新桌面 -> 进桌面 -> profile(弹窗)
@ -34,6 +34,7 @@ function Login() {
//const token = "AgOjcdf3goeYDX3lwWWwkXtVpcrL-l2rX8csrRKgs3_-BC3JOx0l6nZU0MV25eIn" //const token = "AgOjcdf3goeYDX3lwWWwkXtVpcrL-l2rX8csrRKgs3_-BC3JOx0l6nZU0MV25eIn"
try { try {
const [tokenRes, opMapRes] = await Promise.all([doLogin(state), fetchOpMap()]); const [tokenRes, opMapRes] = await Promise.all([doLogin(state), fetchOpMap()]);
removeStorage('_t');
setStorage('_t', tokenRes.data.token); setStorage('_t', tokenRes.data.token);
const wsRes = await fetchRouteWs(); const wsRes = await fetchRouteWs();
// websocket // websocket
@ -42,12 +43,12 @@ function Login() {
// //
setTimeout(() => redirectTo({url: '/pages/lobby/lobby'}), 800); setTimeout(() => redirectTo({url: '/pages/lobby/lobby'}), 800);
}catch(err) { }catch(err) {
showToast({icon: 'error', title: err.msg}) showToast({icon: 'error', title: err})
} finally { } finally {
setSubmitLoding(false); setSubmitLoding(false);
} }
} }
console.log(submitLoding)
return ( return (
<View className='login'> <View className='login'>
<View className='ceiling'></View> <View className='ceiling'></View>

9
src/pages/table/table.jsx

@ -290,10 +290,11 @@ class Table extends Component {
case 1: // 1,2(-[0]+),3All-In,4,5 case 1: // 1,2(-[0]+),3All-In,4,5
this.setState({betType: 1, bettingChip: betMin, betConfirmText: '跟注'}); this.setState({betType: 1, bettingChip: betMin, betConfirmText: '跟注'});
break; break;
case 4: case 4: //
// , betConfirmText: ''
this.setState({betType: 4}, this.handleBetConfirm.bind(this)); this.setState({betType: 4}, this.handleBetConfirm.bind(this));
break; 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> !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> : <Button onClick={this.handleBetting.bind(this, 4)} className="ctl-opt-btn-2">弃牌</Button>
}</View> }</View>
<View className="ctl-opt" style={{opacity: 0}}>{ <View className="ctl-opt">{
!isIn(5, betOpts)? <Button className="ctl-opt-btn-1 ctl-opacity0">过牌</Button> !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> : <Button onClick={this.handleBetting.bind(this, 5)} className="ctl-opt-btn-1">过牌</Button>
}</View> }</View>
<View className="ctl-opt">{ <View className="ctl-opt">{

Loading…
Cancel
Save