Sfoglia il codice sorgente

Merge branch 'master' of http://gogs.efunbox.cn/Rorschach/efunbox-mobile-8

Limengbo 5 anni fa
parent
commit
4cd7cd8825

+ 13 - 0
pages/BasePage.js

@@ -75,6 +75,19 @@ export default class BasePage extends Component<Props> {
 		//返回上一页
 		this.props.navigation.goBack();
 	}
+	saveUserInfo(user_data) {
+		global.storage
+			.save({
+				key: 'userInfo',
+				data: user_data
+			})
+			.then((result) => {
+				console.log('保存成功');
+			})
+			.catch((err) => {
+				console.log('保存失败');
+			});
+	}
 
 	removeListener() {
 		if (this.testJSaaa) {

+ 42 - 21
pages/Login.js

@@ -5,9 +5,6 @@ import React, { Component } from 'react';
 import { StyleSheet, Text, View, Image, TouchableOpacity, StatusBar, ToastAndroid, TextInput } from 'react-native';
 import BasePage from './BasePage';
 import Dimensions from './utils/dimensions';
-import ShopBox from './components/ShopBox';
-import TopicTitle from './components/TopicTitle';
-import ScrollRow from './components/ScrollRow';
 import DeviceInfo from 'react-native-device-info';
 import commonutil from './utils/commonutil';
 import http_user from './services/user';
@@ -142,13 +139,30 @@ export default class Login extends BasePage {
 			};
 			http_user.mobileLoginAndReg(option).then((result) => {
 				if (result.code == 200) {
+					var usermap = new Map();
+					usermap.set('isVisitor', result.data.isVisitor);
+					usermap.set('birthday', result.data.user.birthday);
+					usermap.set('channel', result.data.user.channel);
+					usermap.set('city', result.data.user.city);
+					usermap.set('country', result.data.user.country);
+					usermap.set('eid', result.data.user.eid);
+					usermap.set('gmtCreated', result.data.user.gmtCreated);
+					usermap.set('gmtModified', result.data.user.gmtModified);
+					usermap.set('grade', result.data.user.grade);
+					usermap.set('mobile', result.data.user.mobile);
+					usermap.set('nickName', result.data.user.nickName);
+					usermap.set('province', result.data.user.province);
+					usermap.set('school', result.data.user.school);
+					usermap.set('sex', result.data.user.sex);
+					usermap.set('status', result.data.user.status);
+					usermap.set('uid', result.data.user.uid);
+					usermap.set('ageGroup', result.data.user.ageGroup);
 					//登陆成功了,可以存储用户数据到本地
 					console.log('===============手机号登录成功=====================');
-					console.log(result.data);
+					console.log(commonutil.mapToJson(usermap));
 					console.log('===============手机号登录成功=====================');
-
 					clearTimeout(this.count_timeout);
-					this.saveUserInfo(result.data);
+					this.saveUserInfo(commonutil.mapToJson(usermap));
 					this.clearPageToNext('SchoolAge');
 				} else {
 					ToastAndroid.show(result.message, ToastAndroid.SHORT);
@@ -176,7 +190,28 @@ export default class Login extends BasePage {
 			http_user.wechatLogin(option).then((result) => {
 				if (result.code == 200) {
 					//登陆成功了,可以存储用户数据到本地
-					this.saveUserInfo(result.data);
+					var usermap = new Map();
+					usermap.set('isVisitor', result.data.isVisitor);
+					usermap.set('birthday', result.data.user.birthday);
+					usermap.set('channel', result.data.user.channel);
+					usermap.set('city', result.data.user.city);
+					usermap.set('country', result.data.user.country);
+					usermap.set('eid', result.data.user.eid);
+					usermap.set('gmtCreated', result.data.user.gmtCreated);
+					usermap.set('gmtModified', result.data.user.gmtModified);
+					usermap.set('grade', result.data.user.grade);
+					usermap.set('mobile', result.data.user.mobile);
+					usermap.set('nickName', result.data.user.nickName);
+					usermap.set('province', result.data.user.province);
+					usermap.set('school', result.data.user.school);
+					usermap.set('sex', result.data.user.sex);
+					usermap.set('status', result.data.user.status);
+					usermap.set('uid', result.data.user.uid);
+					usermap.set('ageGroup', result.data.user.ageGroup);
+					console.log('===============微信登录成功=====================');
+					console.log(commonutil.mapToJson(usermap));
+					console.log('===============微信登录成功=====================');
+					this.saveUserInfo(commonutil.mapToJson(usermap));
 					this.clearPageToNext('SchoolAge');
 				} else {
 					ToastAndroid.show(result.message, ToastAndroid.SHORT);
@@ -184,20 +219,6 @@ export default class Login extends BasePage {
 			});
 		});
 	}
-
-	saveUserInfo(user_data) {
-		global.storage
-			.save({
-				key: 'userInfo',
-				data: user_data
-			})
-			.then((result) => {
-				console.log('保存成功');
-			})
-			.catch((err) => {
-				console.log('保存失败');
-			});
-	}
 }
 
 const styles = StyleSheet.create({

+ 47 - 39
pages/PersonalInfo.js

@@ -8,7 +8,6 @@
 
 import React, { Component } from 'react';
 import {
-	Platform,
 	StyleSheet,
 	Text,
 	View,
@@ -17,8 +16,7 @@ import {
 	ImageBackground,
 	ToastAndroid,
 	BackHandler,
-	StatusBar,
-	Modal
+	StatusBar
 } from 'react-native';
 import BasePage from './BasePage';
 import CourseTitle from '../pages/components/CourseTitle';
@@ -27,14 +25,15 @@ import RegionModal from '../pages/components/RegionModal';
 import BirthdayModal from '../pages/components/BirthdayModal';
 import GradeSelectionModal from '../pages/components/GradeSelectionModal';
 import PersonalInfoDialog from '../pages/components/PersonalInfoDialog';
-import { NavigationActions, StackActions } from 'react-navigation';
-import asyncStorage from './utils/asyncStorage';
 import http_user from './services/user';
 import wechat from './utils/wechat';
+import commonutil from './utils/commonutil';
 type Props = {};
 
 export default class PersonalInfo extends BasePage {
 	state = {
+		ready: false,
+		file_user_data: new Map(),
 		user_nickName: '未设置',
 		schoolName: '未设置',
 		provinceName: '未设置',
@@ -56,6 +55,9 @@ export default class PersonalInfo extends BasePage {
 	};
 
 	render() {
+		if (!this.state.ready) {
+			return null;
+		}
 		return (
 			<View style={{ backgroundColor: '#F0F1F5', flex: 1 }}>
 				<View style={{ width: '100%', height: this.getWindowHeight() }}>
@@ -193,7 +195,7 @@ export default class PersonalInfo extends BasePage {
 						<View
 							style={{
 								width: '100%',
-								flex: 4,
+								flex: 3.3,
 								alignItems: 'center',
 								backgroundColor: '#F0F1F5'
 							}}
@@ -415,7 +417,7 @@ export default class PersonalInfo extends BasePage {
 											{this.getArraowImg(4)}
 										</View>
 									</TouchableOpacity>
-									<TouchableOpacity
+									{/* <TouchableOpacity
 										style={{
 											flex: 1,
 											marginTop: 1,
@@ -465,7 +467,7 @@ export default class PersonalInfo extends BasePage {
 										>
 											{this.getArraowImg(5)}
 										</View>
-									</TouchableOpacity>
+									</TouchableOpacity> */}
 								</View>
 							</View>
 						</View>
@@ -595,7 +597,7 @@ export default class PersonalInfo extends BasePage {
 						<View
 							style={{
 								width: '100%',
-								flex: 2,
+								flex: 2.7,
 								backgroundColor: '#F0F1F5',
 								flexDirection: 'column'
 							}}
@@ -619,7 +621,7 @@ export default class PersonalInfo extends BasePage {
 								>
 									<View
 										style={{
-											flex: 1.5
+											flex: 3
 										}}
 									/>
 									<TouchableOpacity
@@ -686,26 +688,21 @@ export default class PersonalInfo extends BasePage {
 				key: 'userInfo'
 			})
 			.then((result) => {
-				console.log('============PersonalInfo========================');
-				console.log(result.user.birthday);
-				console.log('============PersonalInfo========================');
-				var time = this.formaterDate(result.user.birthday);
+				this.state.file_user_data = commonutil.jsonToMap(result);
+				var time = this.formaterDate(this.state.file_user_data.get('birthday'));
 				this.setState({
 					schoolName:
-
-							result.user.school === '' ? '未设置' :
-							result.user.school,
+						this.state.file_user_data.get('school') === ''
+							? '未设置'
+							: this.state.file_user_data.get('school'),
 					provinceName:
-
-							result.user.province === '' ? '未设置' :
-							result.user.province,
-					citys:
-
-							result.user.city === '' ? '未设置' :
-							result.user.city,
-					phone: result.user.mobile,
-					wechat_nickName: result.user.wechat_nickName,
-					user_nickName: result.user.nickName,
+						this.state.file_user_data.get('province') === ''
+							? '未设置'
+							: this.state.file_user_data.get('province'),
+					citys: this.state.file_user_data.get('city') === '' ? '未设置' : this.state.file_user_data.get('city'),
+					phone: this.state.file_user_data.get('mobile'),
+					wechat_nickName: this.state.file_user_data.get('wechat_nickName'),
+					user_nickName: this.state.file_user_data.get('nickName'),
 					birthday_time: time
 				});
 
@@ -731,11 +728,12 @@ export default class PersonalInfo extends BasePage {
 						wechat_bind_color: 'rgba(113, 113, 113, 1)'
 					});
 				}
-				return result;
+				this.setState({
+					ready: true
+				});
 			})
 			.catch((err) => {
 				console.log('PersonalInfo:ERROR' + err.message);
-				return null;
 			});
 	}
 
@@ -887,7 +885,7 @@ export default class PersonalInfo extends BasePage {
 
 	updateState(input_text, type) {
 		if (type == 1) {
-			this.setState({ nickName: input_text });
+			this.setState({ user_nickName: input_text });
 			this.updateUserInfo({ nickName: input_text });
 		} else if (type == 2) {
 			this.setState({ schoolName: input_text });
@@ -932,7 +930,23 @@ export default class PersonalInfo extends BasePage {
 			body: object //请求体
 		};
 		http_user.update_UserInfo(opts).then((res) => {
-			console.log(res);
+			this.state.file_user_data.set('ageGroup', res.data.ageGroup);
+			this.state.file_user_data.set('avatar', res.data.avatar);
+			this.state.file_user_data.set('birthday', res.data.birthday);
+			this.state.file_user_data.set('channel', res.data.channel);
+			this.state.file_user_data.set('city', res.data.city);
+			this.state.file_user_data.set('country', res.data.country);
+			this.state.file_user_data.set('eid', res.data.eid);
+			this.state.file_user_data.set('gmtCreated', res.data.gmtCreated);
+			this.state.file_user_data.set('gmtModified', res.data.gmtModified);
+			this.state.file_user_data.set('mobile', res.data.mobile);
+			this.state.file_user_data.set('nickName', res.data.nickName);
+			this.state.file_user_data.set('province', res.data.province);
+			this.state.file_user_data.set('school', res.data.school);
+			this.state.file_user_data.set('sex', res.data.sex);
+			this.state.file_user_data.set('status', res.data.status);
+			this.state.file_user_data.set('uid', res.data.uid);
+			this.saveUserInfo(commonutil.mapToJson(this.state.file_user_data));
 		});
 	}
 
@@ -948,15 +962,9 @@ export default class PersonalInfo extends BasePage {
 	formaterDate(date) {
 		var date = new Date(date);
 		var Y = date.getFullYear() + '';
-		var M =
-			(
-				date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) :
-				date.getMonth() + 1) + '';
+		var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '';
 
-		var D =
-			(
-				date.getDate() < 10 ? '0' + date.getDate() :
-				date.getDate()) + ' ';
+		var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
 
 		//影响选择出生年月日了。
 		this.setState({

+ 2 - 1
pages/PhoneBind.js

@@ -116,6 +116,7 @@ export default class PhoneBind extends BasePage {
 		}
 	}
 	componentWillUnmount() {
+		clearTimeout(this.countdow);
 		BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
 	}
 
@@ -157,7 +158,7 @@ export default class PhoneBind extends BasePage {
 				verification_text: '获取验证码'
 			});
 		} else {
-			setTimeout(() => {
+			this.countdown = setTimeout(() => {
 				this.setState({
 					verification_text: parseInt(this.state.verification_text) - 1 + ''
 				});

+ 52 - 3
pages/SchoolAge.js

@@ -20,9 +20,14 @@ import {
 	DeviceEventEmitter
 } from 'react-native';
 import BasePage from './BasePage';
+import commonutil from './utils/commonutil';
+import http_user from './services/user';
 
 type Props = {};
 export default class SchoolAge extends BasePage {
+	state = {
+		file_user_data: new Map()
+	};
 	render() {
 		return (
 			<ImageBackground
@@ -67,16 +72,60 @@ export default class SchoolAge extends BasePage {
 		);
 	}
 
+	componentWillMount() {
+		this.getUserInfo();
+	}
 	pres() {
-		this.clearPageToNext('MainPage', { index: 0 });
+		//PRESCHOOL("学前")
+		this.updateUserInfo('PRESCHOOL');
 	}
 
 	primary() {
-		this.clearPageToNext('MainPage', { index: 1 });
+		// PRIMARY_SCHOOL("小学")
+		this.updateUserInfo('PRIMARY_SCHOOL');
 	}
 
 	middle() {
-		this.clearPageToNext('MainPage', { index: 2 });
+		this.updateUserInfo('MIDDLE_SCHOOL');
+	}
+	async getUserInfo() {
+		await global.storage
+			.load({
+				key: 'userInfo'
+			})
+			.then((result) => {
+				this.state.file_user_data = commonutil.jsonToMap(result);
+			})
+			.catch((err) => {
+				console.log('ERROR' + err.message);
+			});
+	}
+	async updateUserInfo(group) {
+		let opts = {
+			method: 'PUT', //请求方法
+			body: { ageGroup: group } //请求体
+		};
+		await http_user.update_UserInfo(opts).then((res) => {
+			this.state.file_user_data.set('ageGroup', res.data.ageGroup);
+			this.state.file_user_data.set('avatar', res.data.avatar);
+			this.state.file_user_data.set('birthday', res.data.birthday);
+			this.state.file_user_data.set('channel', res.data.channel);
+			this.state.file_user_data.set('city', res.data.city);
+			this.state.file_user_data.set('country', res.data.country);
+			this.state.file_user_data.set('eid', res.data.eid);
+			this.state.file_user_data.set('gmtCreated', res.data.gmtCreated);
+			this.state.file_user_data.set('gmtModified', res.data.gmtModified);
+			this.state.file_user_data.set('mobile', res.data.mobile);
+			this.state.file_user_data.set('nickName', res.data.nickName);
+			this.state.file_user_data.set('province', res.data.province);
+			this.state.file_user_data.set('school', res.data.school);
+			this.state.file_user_data.set('sex', res.data.sex);
+			this.state.file_user_data.set('status', res.data.status);
+			this.state.file_user_data.set('uid', res.data.uid);
+			console.log(commonutil.mapToJson(this.state.file_user_data));
+			this.saveUserInfo(commonutil.mapToJson(this.state.file_user_data));
+			this.clearPageToNext('MainPage');
+		});
 	}
 }
 

+ 27 - 14
pages/Splash.js

@@ -2,14 +2,20 @@ import React, { PureComponent } from 'react';
 import { StyleSheet, Text, View, Image, TouchableOpacity, StatusBar, ToastAndroid, TextInput } from 'react-native';
 import BasePage from './BasePage';
 import SplashScreen from 'react-native-splash-screen';
+import commonutil from './utils/commonutil';
 export default class Splash extends BasePage {
 	state = {
-		exist: false
+		exist: false,
+		MainPageParams: ''
 	};
 	render() {
 		return (
 			<View style={{ flex: 1 }}>
 				<StatusBar backgroundColor={'transparent'} translucent={true} />
+				<View style={{ flex: 1 }} />
+				<View style={{ flex: 5 }}>
+					<Text style={{ fontSize: 30 }}>模拟活动广告。。。。</Text>
+				</View>
 			</View>
 		);
 	}
@@ -19,27 +25,22 @@ export default class Splash extends BasePage {
 		this.getUserInfo();
 	}
 
-	componentDidMount() {
-		setTimeout(() => {
-			SplashScreen.hide();
-			if (this.state.exist) {
-				this.clearPageToNext('MainPage');
-			} else {
-				this.clearPageToNext('Login');
-			}
-		}, 3000);
-	}
+	componentDidMount() {}
 
-	getUserInfo() {
+	async getUserInfo() {
 		//判断是否有用户
-		global.storage
+		await global.storage
 			.load({
 				key: 'userInfo'
 			})
 			.then((result) => {
+				SplashScreen.hide();
+				var usermap = commonutil.jsonToMap(result);
 				this.setState({
-					exist: true
+					exist: true,
+					MainPageParams: usermap.get('ageGroup')
 				});
+				this.Advertisement();
 			})
 			.catch((err) => {
 				console.log(err.message);
@@ -58,4 +59,16 @@ export default class Splash extends BasePage {
 				}
 			});
 	}
+
+	//获取用户之后的操作,或者是别的操作。
+	Advertisement() {
+		//假装3秒广告
+		setTimeout(() => {
+			if (this.state.exist) {
+				this.clearPageToNext('MainPage');
+			} else {
+				this.clearPageToNext('Login');
+			}
+		}, 3000);
+	}
 }

+ 4 - 3
pages/components/BirthdayModal.js

@@ -244,6 +244,8 @@ export default class BirthdayModal extends Component<Props> {
 	componentWillMount() {
 		var date = new Date();
 		var year = parseInt(this.props.year);
+		console.log('========BirthdayModal.js---componentWillMount============================');
+		console.log(year);
 		if (this.state.year_array.length == 0) {
 			let position = 0;
 			for (let index = parseInt(year - 50); index < parseInt(year + 10); index++) {
@@ -257,10 +259,9 @@ export default class BirthdayModal extends Component<Props> {
 				position++;
 			}
 		}
-		console.log(parseInt(date.getDate()));
 		this.setState({
-			month_array_views_indexs: parseInt(this.props.month),
-			day_array_views_index: parseInt(this.props.day)
+			month_array_views_indexs: parseInt(this.props.month - 1),
+			day_array_views_index: parseInt(this.props.day - 1)
 		});
 
 		// var hour = date.getHours().toString();

+ 61 - 9
pages/components/MainPage.js

@@ -24,8 +24,6 @@ import {
 	Animated,
 	TouchableHighlight
 } from 'react-native';
-import Swiper from 'react-native-swiper';
-import AndroidUtil from '../../util/AndroidUtil';
 import BasePage from '../BasePage';
 import Header from './Header';
 import MySwiper from './Swiper';
@@ -34,10 +32,15 @@ import TopicTitle from './TopicTitle';
 import ScrollRow from './ScrollRow';
 import LibraryUrl from '../services/library';
 import { ScrollView } from 'react-native-gesture-handler';
+import commonutil from '../utils/commonutil';
+import http_user from '../services/user';
 
 export default class MainPage extends BasePage {
 	constructor(props) {
 		super(props);
+		state: {
+			file_user_data: new Map();
+		}
 	}
 
 	updateRender(index) {
@@ -116,25 +119,24 @@ export default class MainPage extends BasePage {
 	};
 
 	componentWillMount() {
-		var index = 0;
-		if (this.props.navigation.state.params == undefined) {
-			index = 0;
-		} else {
-			index = this.props.navigation.state.params.index;
-		}
-		this.switchGrade(index);
+		this.getUserInfo();
 	}
 	componentDidMount() {
 		// this.updateRender('PRIMARY_SCHOOL');
 	}
 
 	switchGrade = (index) => {
+		console.log('====================================');
+		console.log('switchGrade:' + index);
+		console.log('====================================');
 		const obj = this.state.switchList[index];
 		this.setState({
 			currentSwitch: obj
 		});
 		this.hideGradeMenu();
 		// if (obj.param === this.state.currentSwitch.param) return
+		//这里更新个人信息学龄选项
+		var bool = this.updateUserInfo(obj.param);
 		this.updateRender(obj.param);
 	};
 
@@ -462,6 +464,56 @@ export default class MainPage extends BasePage {
 			});
 		}
 	};
+	async getUserInfo() {
+		await global.storage
+			.load({
+				key: 'userInfo'
+			})
+			.then((result) => {
+				this.state.file_user_data = commonutil.jsonToMap(result);
+				console.log('=====MainPage获取本地用户信息============');
+				console.log(commonutil.mapToJson(this.state.file_user_data));
+				var ageGroup = this.state.file_user_data.get('ageGroup');
+				var ageindex = 0;
+				if (ageGroup === 'PRESCHOOL') {
+					ageindex = 0;
+				} else if (ageGroup === 'PRIMARY_SCHOOL') {
+					ageindex = 1;
+				} else if (ageGroup === 'MIDDLE_SCHOOL') {
+					ageindex = 2;
+				}
+				this.switchGrade(ageindex);
+			})
+			.catch((err) => {
+				console.log('ERROR' + err.message);
+			});
+	}
+	async updateUserInfo(group) {
+		let opts = {
+			method: 'PUT', //请求方法
+			body: { ageGroup: group } //请求体
+		};
+		await http_user.update_UserInfo(opts).then((res) => {
+			this.state.file_user_data.set('ageGroup', res.data.ageGroup);
+			this.state.file_user_data.set('avatar', res.data.avatar);
+			this.state.file_user_data.set('birthday', res.data.birthday);
+			this.state.file_user_data.set('channel', res.data.channel);
+			this.state.file_user_data.set('city', res.data.city);
+			this.state.file_user_data.set('country', res.data.country);
+			this.state.file_user_data.set('eid', res.data.eid);
+			this.state.file_user_data.set('gmtCreated', res.data.gmtCreated);
+			this.state.file_user_data.set('gmtModified', res.data.gmtModified);
+			this.state.file_user_data.set('mobile', res.data.mobile);
+			this.state.file_user_data.set('nickName', res.data.nickName);
+			this.state.file_user_data.set('province', res.data.province);
+			this.state.file_user_data.set('school', res.data.school);
+			this.state.file_user_data.set('sex', res.data.sex);
+			this.state.file_user_data.set('status', res.data.status);
+			this.state.file_user_data.set('uid', res.data.uid);
+			this.saveUserInfo(commonutil.mapToJson(this.state.file_user_data));
+			return true;
+		});
+	}
 }
 
 const styles = StyleSheet.create({

+ 33 - 0
pages/utils/commonutil.js

@@ -11,4 +11,37 @@ export default class commonutil {
 		}
 	}
 
+	/**
+ *map转化为对象(map所有键都是字符串,可以将其转换为对象)
+ */
+	static strMapToObj(strMap) {
+		let obj = Object.create(null);
+		for (let [ k, v ] of strMap) {
+			obj[k] = v;
+		}
+		return obj;
+	}
+	/**
+  *map转换为json
+  */
+	static mapToJson(map) {
+		return JSON.stringify(this.strMapToObj(map));
+	}
+
+	/**
+*对象转换为Map
+*/
+	static objToStrMap(obj) {
+		let strMap = new Map();
+		for (let k of Object.keys(obj)) {
+			strMap.set(k, obj[k]);
+		}
+		return strMap;
+	}
+	/**
+	*json转换为map
+	*/
+	static jsonToMap(jsonStr) {
+		return this.objToStrMap(JSON.parse(jsonStr));
+	}
 }