From 76dfec46e7b7510a8b2b8e86b67c39416dba9371 Mon Sep 17 00:00:00 2001 From: YYYTDMS <412827191@qq.com> Date: Thu, 12 May 2022 01:59:32 +0800 Subject: [PATCH] =?UTF-8?q?330=5F=E5=90=88=E5=B9=B6=E8=81=94=E6=9C=BA?= =?UTF-8?q?=E8=87=AA=E4=B9=A0=E6=A8=A1=E5=9D=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- component/OnlineStudy/2-PlayerPKHome/index.js | 1 + .../OnlineStudy/GlobalResourses/index.js | 1 + component/OnlineStudy/GlobalUserTest/index.js | 20 -------- component/OnlineStudy/MyTest/index.js | 49 ------------------- component/OnlineStudy/MyUtilities/index.js | 21 +++++--- component/OnlineStudy/RangePKHome/index.js | 2 + component/OnlineStudy/RangePKStudy/index.js | 3 ++ page/Login/index.js | 4 +- page/Login/register.js | 4 +- 9 files changed, 25 insertions(+), 80 deletions(-) delete mode 100644 component/OnlineStudy/GlobalUserTest/index.js delete mode 100644 component/OnlineStudy/MyTest/index.js diff --git a/component/OnlineStudy/2-PlayerPKHome/index.js b/component/OnlineStudy/2-PlayerPKHome/index.js index 62cd7e1..22bad50 100644 --- a/component/OnlineStudy/2-PlayerPKHome/index.js +++ b/component/OnlineStudy/2-PlayerPKHome/index.js @@ -42,6 +42,7 @@ class TwoPlayerPKHome extends Component { state = {isStarted: false, isCanceling: false}; resolveMessage = msg => { + console.log(msg); const data = JSON.parse(msg.data); console.log(data); if (data.hasOwnProperty('type')) { diff --git a/component/OnlineStudy/GlobalResourses/index.js b/component/OnlineStudy/GlobalResourses/index.js index dc0f2b5..e85469c 100644 --- a/component/OnlineStudy/GlobalResourses/index.js +++ b/component/OnlineStudy/GlobalResourses/index.js @@ -3,3 +3,4 @@ global.defaultACID = 'notLocated'; // default value of acID global.acID = global.defaultACID; // a acID of range PK global.rangeID = global.defaultRangeID; // rangeID for school buildings global.websocket = new WebSocket('ws://localhost:8080'); // an instance of websocket +global.sno=''; diff --git a/component/OnlineStudy/GlobalUserTest/index.js b/component/OnlineStudy/GlobalUserTest/index.js deleted file mode 100644 index c3f52fb..0000000 --- a/component/OnlineStudy/GlobalUserTest/index.js +++ /dev/null @@ -1,20 +0,0 @@ -global.sno = '221900330'; -global.password = '123'; - -export class sno { - static get() { - return global.sno; - } - static set(input) { - global.sno = input; - } -} - -export class password { - static get() { - return global.password; - } - static set(input) { - global.password = input; - } -} diff --git a/component/OnlineStudy/MyTest/index.js b/component/OnlineStudy/MyTest/index.js deleted file mode 100644 index ea1509f..0000000 --- a/component/OnlineStudy/MyTest/index.js +++ /dev/null @@ -1,49 +0,0 @@ -import {sno, password} from '../GlobalUserTest'; -import {post, get} from '../MyUtilities'; -// import {get, post} from '../../../utils/http'; - -const URL_LOGIN = 'http://www.tdms.xyz:8000/FZUStudy/login'; -const URL_LOGOUT = 'http://www.tdms.xyz:8000/FZUStudy/logout'; -const URL_2PLAYER_PK_MATCH = 'ws://www.tdms.xyz:8000/FZUStudy/websocket/pk/'; // + '{sno}' - -// export function login() { -// const data = { -// sno: sno.get(), -// password: password.get(), -// }; -// const resolveData = r => { -// console.log(r); -// }; -// // console.log('[Login] sno: ' + data.sno + ' password: ' + data.password); -// post(URL_LOGIN, data).then(resolveData).catch(); -// } - -// export function logout() { -// const resolveData = data => { -// console.log(data); -// }; -// // console.log('[Logout]'); -// get(URL_LOGOUT, {}).then(resolveData).catch(); -// } - -// export function connect() { -// const socketUrl = URL_2PLAYER_PK_MATCH + sno.get(); -// let socket = new WebSocket(socketUrl); -// //打开事件 -// socket.onopen = function () { -// console.log('websocket 已打开'); -// }; -// //获得消息事件 -// socket.onmessage = function (msg) { -// const serverMsg = '收到服务端信息: ' + msg.data; -// console.log(serverMsg); -// }; -// //关闭事件 -// socket.onclose = function () { -// console.log('websocket 已关闭'); -// }; -// //发生了错误事件 -// socket.onerror = function () { -// console.log('websocket 发生了错误'); -// }; -// } diff --git a/component/OnlineStudy/MyUtilities/index.js b/component/OnlineStudy/MyUtilities/index.js index 667ffde..8367e8b 100644 --- a/component/OnlineStudy/MyUtilities/index.js +++ b/component/OnlineStudy/MyUtilities/index.js @@ -1,14 +1,14 @@ import '../GlobalResourses'; // 用户 sno -import '../GlobalUserTest'; import CookieManager from '@react-native-cookies/cookies'; import {ToastAndroid} from 'react-native'; - +import {connect} from "react-redux"; +import {Component} from "react"; /** * class sno 的 get() 和 set() 需要修改以指向“全局变量”中的“学号” */ const EARTH_RADIUS = 6371393; // metre -const DEFAULT_DISTANCE = 100; // metre +const DEFAULT_DISTANCE = 200; // metre const URL_SHORT = 'http://www.tdms.xyz:8000/FZUStudy'; const URL_AREA_GET_ID = 'http://www.tdms.xyz:8000/FZUStudy/study/areaGetID'; const URL_AREA_MATCH = 'http://www.tdms.xyz:8000/FZUStudy/study/areamatch'; @@ -315,13 +315,20 @@ export class websocket { } } +const mapStateToProps = state => { + const {user} = state; + return {user}; +}; + + // 用户 sno -export class sno { +export class sno{ + static get() { return global.sno; } - static set(input) { - global.sno = input; + static set(sno) { + global.sno=sno; } } @@ -368,7 +375,7 @@ function getDistance(longitude1, latitude1, longitude2, latitude2) { } function parseLocation(longitude, latitude) { - // console.log('longitude: ' + longitude + ' latitude: ' + latitude); + console.log('longitude: ' + longitude + ' latitude: ' + latitude); let range = { ID: 'notInRange', distance: DEFAULT_DISTANCE, diff --git a/component/OnlineStudy/RangePKHome/index.js b/component/OnlineStudy/RangePKHome/index.js index 85c685e..708a170 100644 --- a/component/OnlineStudy/RangePKHome/index.js +++ b/component/OnlineStudy/RangePKHome/index.js @@ -63,6 +63,8 @@ class RangePKHome extends Component { location => { const longitude = location.coords.longitude; //经度 const latitude = location.coords.latitude; //纬度 + // console.log('longitude:',longitude) + // console.log('latitude:',latitude) rangeID.setByLocation(longitude, latitude); this.setState({ isStarted: false, diff --git a/component/OnlineStudy/RangePKStudy/index.js b/component/OnlineStudy/RangePKStudy/index.js index 1bfcd0d..d15320a 100644 --- a/component/OnlineStudy/RangePKStudy/index.js +++ b/component/OnlineStudy/RangePKStudy/index.js @@ -252,6 +252,9 @@ class RangePKStudy extends Component { let top = 'ERROR'; let bottom = 'ERROR'; console.log('[QUIT_SUCCESS]', params); + if(params.hasOwnProperty('duration')){ + top=params.duration + } if ( params.hasOwnProperty('start_time') && params.hasOwnProperty('end_time') diff --git a/page/Login/index.js b/page/Login/index.js index cfb7b11..91db2b0 100644 --- a/page/Login/index.js +++ b/page/Login/index.js @@ -16,7 +16,7 @@ import {SafeAreaProvider} from 'react-native-safe-area-context'; import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; import {updateUserDetail} from '../../store/action/user-actions'; - +import {sno as globalSno} from '../../component/OnlineStudy/MyUtilities' class Login extends Component { static navigationOptions = { title: '登录', @@ -54,7 +54,7 @@ class Login extends Component { }); // alert('登录成功!'); ToastAndroid.show('登录成功!', 500); //提示 - global.sno=sno; + globalSno.set(sno) this.props.navigation.navigate('Home'); }) .catch(err => { diff --git a/page/Login/register.js b/page/Login/register.js index 26b80f6..8c4e9d7 100644 --- a/page/Login/register.js +++ b/page/Login/register.js @@ -12,7 +12,7 @@ import {Button, CheckBox, Icon, Input} from 'react-native-elements'; import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; import {updateUserDetail} from '../../store/action/user-actions'; - +import {sno as globalSno} from '../../component/OnlineStudy/MyUtilities' const {width, height} = Dimensions.get('window'); class register extends Component { @@ -49,7 +49,7 @@ class register extends Component { ToastAndroid.show('注册成功!', 500); //提示 http('post', '/login', {sno, password}).then(res => { console.log('res', res); - global.sno=sno; + globalSno.set(sno); this.props.updateUserDetail(res.data); this.props.navigation.navigate('Home'); }); -- GitLab