Browse Source

1.修改获取/存储本地用户信息的方法

zhangmengjie 5 years ago
parent
commit
8b9c6e4d5a
10 changed files with 297 additions and 353 deletions
  1. 43 0
      App.js
  2. 0 13
      pages/BasePage.js
  3. 67 69
      pages/Login.js
  4. 86 105
      pages/PersonalInfo.js
  5. 18 61
      pages/SchoolAge.js
  6. 12 41
      pages/Splash.js
  7. 0 1
      pages/components/BirthdayModal.js
  8. 38 59
      pages/components/MainPage.js
  9. 4 4
      pages/services/user.js
  10. 29 0
      pages/utils/commonutil.js

+ 43 - 0
App.js

@@ -25,6 +25,7 @@ import SearchResult from './pages/searchResult';
 import PhoneBind from './pages/PhoneBind';
 import PhoneBind from './pages/PhoneBind';
 import Splash from './pages/Splash';
 import Splash from './pages/Splash';
 import './pages/components/RootView';
 import './pages/components/RootView';
+import commonutil from './pages/utils/commonutil';
 
 
 const RootNavigator = createStackNavigator(
 const RootNavigator = createStackNavigator(
 	{
 	{
@@ -59,3 +60,45 @@ let storage = new Storage({
 });
 });
 
 
 global.storage = storage;
 global.storage = storage;
+
+getUserInfo().then((result) => {
+	if (result == null) {
+		global.userInfo = null;
+		return true;
+	}
+	var json = JSON.parse(result);
+	global.userInfo = {
+		avatar: json.avatar,
+		ageGroup: json.ageGroup,
+		birthday: json.birthday,
+		channel: json.channel,
+		city: json.city,
+		country: json.country,
+		eid: json.eid,
+		gmtCreated: json.gmtCreated,
+		gmtModified: json.gmtModified,
+		mobile: json.mobile,
+		nickName: json.nickName,
+		province: json.province,
+		school: json.school,
+		sex: json.sex,
+		status: json.status,
+		uid: json.uid,
+		isVisitor: json.isVisitor
+	};
+});
+
+async function getUserInfo() {
+	let info = await global.storage
+		.load({
+			key: 'userInfo'
+		})
+		.then((result) => {
+			return result;
+		})
+		.catch((err) => {
+			console.log('ERROR' + err.message);
+			return null;
+		});
+	return info;
+}

+ 0 - 13
pages/BasePage.js

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

+ 67 - 69
pages/Login.js

@@ -144,31 +144,27 @@ export default class Login extends BasePage {
 			};
 			};
 			http_user.mobileLoginAndReg(option).then((result) => {
 			http_user.mobileLoginAndReg(option).then((result) => {
 				if (result.code == 200) {
 				if (result.code == 200) {
-					var usermap = new Map();
+					let info = {
-					usermap.set('isVisitor', result.data.isVisitor);
+						avatar: result.data.user.avatar,
-					usermap.set('birthday', result.data.user.birthday);
+						ageGroup: result.data.user.ageGroup,
-					usermap.set('channel', result.data.user.channel);
+						birthday: result.data.user.birthday,
-					usermap.set('city', result.data.user.city);
+						channel: result.data.user.channel,
-					usermap.set('country', result.data.user.country);
+						city: result.data.user.city,
-					usermap.set('eid', result.data.user.eid);
+						country: result.data.user.country,
-					usermap.set('gmtCreated', result.data.user.gmtCreated);
+						eid: result.data.user.eid,
-					usermap.set('gmtModified', result.data.user.gmtModified);
+						gmtCreated: result.data.user.gmtCreated,
-					usermap.set('grade', result.data.user.grade);
+						gmtModified: result.data.user.gmtModified,
-					usermap.set('mobile', result.data.user.mobile);
+						mobile: result.data.user.mobile,
-					usermap.set('nickName', result.data.user.nickName);
+						nickName: result.data.user.nickName, //=== '' ? '未设置' : result.data.user.nickName,
-					usermap.set('province', result.data.user.province);
+						province: result.data.user.province,
-					usermap.set('school', result.data.user.school);
+						school: result.data.user.school,
-					usermap.set('sex', result.data.user.sex);
+						sex: result.data.user.sex,
-					usermap.set('status', result.data.user.status);
+						status: result.data.user.status,
-					usermap.set('uid', result.data.user.uid);
+						uid: result.data.user.uid,
-					usermap.set('ageGroup', result.data.user.ageGroup);
+						isVisitor: result.data.isVisitor.toUpperCase() === 'TRUE' ? true : false
-					map.set('avatar', res.data.avatar);
+					};
-					//登陆成功了,可以存储用户数据到本地
+					global.userInfo = info;
-					console.log('===============手机号登录成功=====================');
+					commonutil.saveUserInfo();
-					console.log(commonutil.mapToJson(usermap));
-					console.log('===============手机号登录成功=====================');
-					clearTimeout(this.count_timeout);
-					this.saveUserInfo(commonutil.mapToJson(usermap));
 					this.clearPageToNext('SchoolAge');
 					this.clearPageToNext('SchoolAge');
 				} else {
 				} else {
 					ToastAndroid.show(result.message, ToastAndroid.SHORT);
 					ToastAndroid.show(result.message, ToastAndroid.SHORT);
@@ -183,27 +179,31 @@ export default class Login extends BasePage {
 		http_user.jumpLogin(this.state.deviceCode, commonutil.getAppCode()).then((result) => {
 		http_user.jumpLogin(this.state.deviceCode, commonutil.getAppCode()).then((result) => {
 			if (result.code == 200) {
 			if (result.code == 200) {
 				//登陆成功了,可以存储用户数据到本地
 				//登陆成功了,可以存储用户数据到本地
-				if (result.data.isVisitor) {
+				if (result.code == 200) {
-					var usermap = new Map();
+					let info = {
-					usermap.set('isVisitor', result.data.isVisitor);
+						avatar: result.data.user.avatar,
-					usermap.set('channel', result.data.visitor.channel + '');
+						ageGroup: result.data.visitor.ageGroup,
-					usermap.set('birthday', '');
+						birthday: result.data.visitor.birthday,
-					usermap.set('city', '');
+						channel: result.data.visitor.channel,
-					usermap.set('gmtCreated', result.data.visitor.gmtCreated + '');
+						city: result.data.visitor.city,
-					usermap.set('gmtModified', result.data.visitor.gmtModified + '');
+						country: result.data.visitor.country,
-					usermap.set('country', '');
+						eid: result.data.visitor.eid,
-					usermap.set('eid', '');
+						gmtCreated: result.data.visitor.gmtCreated,
-					usermap.set('grade', '');
+						gmtModified: result.data.visitor.gmtModified,
-					usermap.set('mobile', '');
+						mobile: result.data.visitor.mobile,
-					usermap.set('nickName', '');
+						nickName: result.data.visitor.nickName, //=== '' ? '未设置' : result.data.user.nickName,
-					usermap.set('province', '');
+						province: result.data.visitor.province,
-					usermap.set('school', '');
+						school: result.data.visitor.school,
-					usermap.set('sex', '');
+						sex: result.data.visitor.sex,
-					usermap.set('status', '');
+						status: result.data.visitor.status,
-					usermap.set('uid', '');
+						uid: result.data.visitor.uid,
-					usermap.set('ageGroup', 'PRESCHOOL');
+						isVisitor: result.data.isVisitor.toUpperCase() === 'TRUE' ? true : false
-					usermap.set('avatar', '');
+					};
-					this.saveUserInfo(commonutil.mapToJson(usermap));
+					global.userInfo = info;
+					console.log('================跳过登录====================');
+					console.log('global.userInfo', global.userInfo);
+					console.log('====================================');
+					commonutil.saveUserInfo();
 					this.clearPageToNext('SchoolAge');
 					this.clearPageToNext('SchoolAge');
 				}
 				}
 			} else {
 			} else {
@@ -229,29 +229,27 @@ export default class Login extends BasePage {
 			http_user.wechatLogin(option).then((result) => {
 			http_user.wechatLogin(option).then((result) => {
 				if (result.code == 200) {
 				if (result.code == 200) {
 					//登陆成功了,可以存储用户数据到本地
 					//登陆成功了,可以存储用户数据到本地
-					var usermap = new Map();
+					let info = {
-					usermap.set('isVisitor', result.data.isVisitor);
+						avatar: result.data.user.avatar,
-					usermap.set('birthday', result.data.user.birthday);
+						ageGroup: result.data.user.ageGroup,
-					usermap.set('channel', result.data.user.channel);
+						birthday: result.data.user.birthday,
-					usermap.set('city', result.data.user.city);
+						channel: result.data.user.channel,
-					usermap.set('country', result.data.user.country);
+						city: result.data.user.city,
-					usermap.set('eid', result.data.user.eid);
+						country: result.data.user.country,
-					usermap.set('gmtCreated', result.data.user.gmtCreated);
+						eid: result.data.user.eid,
-					usermap.set('gmtModified', result.data.user.gmtModified);
+						gmtCreated: result.data.user.gmtCreated,
-					usermap.set('grade', result.data.user.grade);
+						gmtModified: result.data.user.gmtModified,
-					usermap.set('mobile', result.data.user.mobile);
+						mobile: result.data.user.mobile,
-					usermap.set('nickName', result.data.user.nickName);
+						nickName: result.data.user.nickName,
-					usermap.set('province', result.data.user.province);
+						province: result.data.user.province,
-					usermap.set('school', result.data.user.school);
+						school: result.data.user.school,
-					usermap.set('sex', result.data.user.sex);
+						sex: result.data.user.sex,
-					usermap.set('status', result.data.user.status);
+						status: result.data.user.status,
-					usermap.set('uid', result.data.user.uid);
+						uid: result.data.user.uid,
-					usermap.set('ageGroup', result.data.user.ageGroup);
+						isVisitor: result.data.isVisitor.toUpperCase() === 'TRUE' ? true : false
-					usermap.set('avatar', result.data.user.avatar);
+					};
-					console.log('===============微信登录成功=====================');
+					global.userInfo = info;
-					console.log(commonutil.mapToJson(usermap));
+					commonutil.saveUserInfo();
-					console.log('===============微信登录成功=====================');
-					this.saveUserInfo(commonutil.mapToJson(usermap));
 					this.clearPageToNext('SchoolAge');
 					this.clearPageToNext('SchoolAge');
 				} else {
 				} else {
 					ToastAndroid.show(result.message, ToastAndroid.SHORT);
 					ToastAndroid.show(result.message, ToastAndroid.SHORT);

+ 86 - 105
pages/PersonalInfo.js

@@ -35,7 +35,6 @@ type Props = {};
 export default class PersonalInfo extends BasePage {
 export default class PersonalInfo extends BasePage {
 	state = {
 	state = {
 		ready: false,
 		ready: false,
-		file_user_data: new Map(),
 		user_nickName: '未设置',
 		user_nickName: '未设置',
 		schoolName: '未设置',
 		schoolName: '未设置',
 		provinceName: '未设置',
 		provinceName: '未设置',
@@ -678,72 +677,65 @@ export default class PersonalInfo extends BasePage {
 
 
 	componentWillMount() {
 	componentWillMount() {
 		//获取用户信息
 		//获取用户信息
-		this.getUserInfo();
+		this.setView();
 		BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
 		BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
 	}
 	}
 	componentWillUnmount() {
 	componentWillUnmount() {
 		BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
 		BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
 	}
 	}
 
 
-	async getUserInfo() {
+	async setView() {
-		let userinfo = await global.storage
+		console.log('====================================');
-			.load({
+		console.log('userInfo', global.userInfo);
-				key: 'userInfo'
+		console.log('====================================');
-			})
+		var time;
-			.then((result) => {
+		if (
-				this.state.file_user_data = commonutil.jsonToMap(result);
+			global.userInfo.birthday == null ||
-				var time = this.formaterDate(this.state.file_user_data.get('birthday'));
+			global.userInfo.birthday == undefined ||
-				this.setState({
+			global.userInfo.birthday === ''
-					schoolName:
+		) {
-						this.state.file_user_data.get('school') === ''
+			time = this.formaterDate(Date.parse(new Date()));
-							? '未设置'
+		} else {
-							: this.state.file_user_data.get('school'),
+			time = this.formaterDate(global.userInfo.birthday);
-					provinceName:
+		}
-						this.state.file_user_data.get('province') === ''
+		this.setState({
-							? '未设置'
+			schoolName: global.userInfo.school === '' ? '未设置' : global.userInfo.school,
-							: this.state.file_user_data.get('province'),
+			provinceName: global.userInfo.province === '' ? '未设置' : global.userInfo.province,
-					citys: this.state.file_user_data.get('city') === '' ? '未设置' : this.state.file_user_data.get('city'),
+			citys: global.userInfo.city === '' ? '未设置' : global.userInfo.city,
-					phone: this.state.file_user_data.get('mobile'),
+			phone: global.userInfo.mobile,
-					wechat_nickName: this.state.file_user_data.get('wechat_nickName'),
+			wechat_nickName: global.userInfo.wechat_nickName,
-					user_nickName: this.state.file_user_data.get('nickName'),
+			user_nickName: global.userInfo.nickName,
-					birthday_time: time
+			birthday_time: time,
-				});
+			photo_uri:
-				if (this.state.file_user_data.get('avatar').length > 0) {
+				global.userInfo.avatar.length > 0
-					this.setState({
+					? { uri: global.userInfo.avatar }
-						photo_uri: {
+					: require('./images/userInfo/default_photo.png')
-							uri: this.state.file_user_data.get('avatar')
+		});
-						}
+		if (this.state.phone == null || this.state.phone === '') {
-					});
+			this.setState({
-				}
+				phone_bind_color: 'red',
-				if (this.state.phone == null || this.state.phone === '') {
+				phone_bind_type: 1,
-					this.setState({
+				phone: '未绑定'
-						phone_bind_color: 'red',
+			});
-						phone_bind_type: 1,
+		} else {
-						phone: '未绑定'
+			this.setState({
-					});
+				phone_bind_color: 'rgba(113, 113, 113, 1)',
-				} else {
+				phone_bind_type: 2
-					this.setState({
-						phone_bind_color: 'rgba(113, 113, 113, 1)',
-						phone_bind_type: 2
-					});
-				}
-				if (this.state.wechat_nickName == null || this.state.wechat_nickName === '') {
-					this.setState({
-						wechat_bind_color: 'red',
-						wechat_nickName: '未绑定'
-					});
-				} else {
-					this.setState({
-						wechat_bind_color: 'rgba(113, 113, 113, 1)'
-					});
-				}
-				this.setState({
-					ready: true
-				});
-			})
-			.catch((err) => {
-				console.log('PersonalInfo:ERROR' + err.message);
 			});
 			});
+		}
+		if (this.state.wechat_nickName == null || this.state.wechat_nickName === '') {
+			this.setState({
+				wechat_bind_color: 'red',
+				wechat_nickName: '未绑定'
+			});
+		} else {
+			this.setState({
+				wechat_bind_color: 'rgba(113, 113, 113, 1)'
+			});
+		}
+		this.setState({
+			ready: true
+		});
 	}
 	}
 
 
 	onBackAndroid = () => {
 	onBackAndroid = () => {
@@ -898,10 +890,10 @@ export default class PersonalInfo extends BasePage {
 	updateState(input_text, type) {
 	updateState(input_text, type) {
 		if (type == 1) {
 		if (type == 1) {
 			this.setState({ user_nickName: input_text });
 			this.setState({ user_nickName: input_text });
-			this.updateUserInfo({ nickName: input_text });
+			this.updateUserInfo({ nickName: input_text }, 1);
 		} else if (type == 2) {
 		} else if (type == 2) {
 			this.setState({ schoolName: input_text });
 			this.setState({ schoolName: input_text });
-			this.updateUserInfo({ school: input_text });
+			this.updateUserInfo({ school: input_text }, 5);
 		}
 		}
 	}
 	}
 
 
@@ -910,7 +902,7 @@ export default class PersonalInfo extends BasePage {
 			provinceName: provinces_name,
 			provinceName: provinces_name,
 			citys: citys_name
 			citys: citys_name
 		});
 		});
-		this.updateUserInfo({ province: provinces_name, city: citys_name });
+		this.updateUserInfo({ province: provinces_name, city: citys_name }, 4);
 	}
 	}
 	commitGrade(text, index) {
 	commitGrade(text, index) {
 		this.setState({
 		this.setState({
@@ -924,7 +916,7 @@ export default class PersonalInfo extends BasePage {
 			birthday_time: year + '年' + month + '月' + day + '日'
 			birthday_time: year + '年' + month + '月' + day + '日'
 		});
 		});
 		var date = new Date(year + '-' + month + '-' + day);
 		var date = new Date(year + '-' + month + '-' + day);
-		this.updateUserInfo({ birthday: date });
+		this.updateUserInfo({ birthday: date }, 3);
 	}
 	}
 
 
 	photoback(photo_uri) {
 	photoback(photo_uri) {
@@ -934,14 +926,39 @@ export default class PersonalInfo extends BasePage {
 		this.upload_head(photo_uri);
 		this.upload_head(photo_uri);
 	}
 	}
 
 
-	updateUserInfo(object) {
+	updateUserInfo(object, type) {
 		let opts = {
 		let opts = {
 			method: 'PUT', //请求方法
 			method: 'PUT', //请求方法
 			body: object //请求体
 			body: object //请求体
 		};
 		};
 		http_user.update_UserInfo(opts).then((res) => {
 		http_user.update_UserInfo(opts).then((res) => {
-			this.update_file_userinfo(this.state.file_user_data, res);
+			switch (type) {
-			this.saveUserInfo(commonutil.mapToJson(this.state.file_user_data));
+				case 0:
+					//只改变头像
+					global.userInfo.avatar = res.data.avatar;
+					break;
+				case 1:
+					//修改昵称
+					global.userInfo.nickName = res.data.nickName;
+					break;
+				case 2:
+					global.userInfo.birthday = res.data.birthday;
+					break;
+				case 3:
+					global.userInfo.birthday = res.data.birthday;
+					break;
+				case 4:
+					global.userInfo.province = res.data.province;
+					global.userInfo.city = res.data.city;
+					break;
+				case 5:
+					global.userInfo.school = res.data.school;
+					break;
+				case 6:
+					global.userInfo.mobile = res.data.mobile;
+					break;
+			}
+			commonutil.saveUserInfo();
 		});
 		});
 	}
 	}
 
 
@@ -953,6 +970,7 @@ export default class PersonalInfo extends BasePage {
 				phone_bind_result: result,
 				phone_bind_result: result,
 				show_bind_phone: true
 				show_bind_phone: true
 			});
 			});
+			this.updateUserInfo({ mobile: phone_num }, 6);
 		} else {
 		} else {
 			this.Toast('修改手机号失败');
 			this.Toast('修改手机号失败');
 		}
 		}
@@ -984,52 +1002,15 @@ export default class PersonalInfo extends BasePage {
 				this.setState({
 				this.setState({
 					photo_uri: { uri: res.data }
 					photo_uri: { uri: res.data }
 				});
 				});
-				this.updateUserInfo({ avatar: res.data });
+				this.updateUserInfo({ avatar: res.data }, 0);
 				this.Toast('上传成功');
 				this.Toast('上传成功');
 			} else {
 			} else {
 				this.Toast('上传失败:' + res.message);
 				this.Toast('上传失败:' + res.message);
 			}
 			}
 		});
 		});
 	}
 	}
-
-	update_file_userinfo(map, res) {
-		map.set('ageGroup', res.data.ageGroup);
-		map.set('avatar', res.data.avatar);
-		map.set('birthday', res.data.birthday);
-		map.set('channel', res.data.channel);
-		map.set('city', res.data.city);
-		map.set('country', res.data.country);
-		map.set('eid', res.data.eid);
-		map.set('gmtCreated', res.data.gmtCreated);
-		map.set('gmtModified', res.data.gmtModified);
-		map.set('mobile', res.data.mobile);
-		map.set('nickName', res.data.nickName);
-		map.set('province', res.data.province);
-		map.set('school', res.data.school);
-		map.set('sex', res.data.sex);
-		map.set('status', res.data.status);
-		map.set('uid', res.data.uid);
-	}
 }
 }
 
 
-class BindPhoneSuccess extends BasePage {
-	render() {
-		if (this.props.show) {
-			return (
-				<View
-					style={{
-						position: 'absolute',
-						width: '100%',
-						height: '100%',
-						backgroundColor: 'rgba(0, 0, 0, 0.5)'
-					}}
-				/>
-			);
-		} else {
-			return null;
-		}
-	}
-}
 const styles = StyleSheet.create({
 const styles = StyleSheet.create({
 	item: {
 	item: {
 		flex: 1,
 		flex: 1,

+ 18 - 61
pages/SchoolAge.js

@@ -25,9 +25,7 @@ import http_user from './services/user';
 
 
 type Props = {};
 type Props = {};
 export default class SchoolAge extends BasePage {
 export default class SchoolAge extends BasePage {
-	state = {
+	state = {};
-		file_user_data: new Map()
-	};
 	render() {
 	render() {
 		return (
 		return (
 			<ImageBackground
 			<ImageBackground
@@ -72,9 +70,7 @@ export default class SchoolAge extends BasePage {
 		);
 		);
 	}
 	}
 
 
-	componentWillMount() {
+	componentWillMount() {}
-		this.getUserInfo();
-	}
 	pres() {
 	pres() {
 		//PRESCHOOL("学前")
 		//PRESCHOOL("学前")
 		this.updateUserInfo('PRESCHOOL');
 		this.updateUserInfo('PRESCHOOL');
@@ -88,64 +84,25 @@ export default class SchoolAge extends BasePage {
 	middle() {
 	middle() {
 		this.updateUserInfo('MIDDLE_SCHOOL');
 		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) {
 	async updateUserInfo(group) {
-		if (this.state.file_user_data.get('isVisitor')) {
+		if (global.userInfo.isVisitor) {
-			this.state.file_user_data.set('ageGroup', group);
+			console.log('游客登录');
-			this.state.file_user_data.set('channel', this.state.file_user_data.get('channel'));
+			//是访客登录
-			this.state.file_user_data.set('gmtCreated', this.state.file_user_data.get('gmtCreated'));
+			global.userInfo.ageGroup = group;
-			this.state.file_user_data.set('gmtModified', this.state.file_user_data.get('gmtModified'));
+			commonutil.saveUserInfo();
-			this.state.file_user_data.set('birthday', '');
-			this.state.file_user_data.set('city', '');
-			this.state.file_user_data.set('country', '');
-			this.state.file_user_data.set('eid', '');
-			this.state.file_user_data.set('grade', '');
-			this.state.file_user_data.set('mobile', '');
-			this.state.file_user_data.set('nickName', '');
-			this.state.file_user_data.set('province', '');
-			this.state.file_user_data.set('school', '');
-			this.state.file_user_data.set('sex', '');
-			this.state.file_user_data.set('status', '');
-			this.state.file_user_data.set('uid', '');
-			this.saveUserInfo(commonutil.mapToJson(this.state.file_user_data));
-			this.clearPageToNext('MainPage');
 			return true;
 			return true;
+		} else {
+			console.log('正常登录');
+			let opts = {
+				method: 'PUT', //请求方法
+				body: { ageGroup: group } //请求体
+			};
+			await http_user.update_UserInfo(opts).then((res) => {
+				global.userInfo.ageGroup = group;
+				commonutil.saveUserInfo();
+				this.clearPageToNext('MainPage');
+			});
 		}
 		}
-		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));
-			this.clearPageToNext('MainPage');
-		});
 	}
 	}
 }
 }
 
 

+ 12 - 41
pages/Splash.js

@@ -6,8 +6,6 @@ import commonutil from './utils/commonutil';
 import http_showcase from '../pages/services/showcase';
 import http_showcase from '../pages/services/showcase';
 export default class Splash extends BasePage {
 export default class Splash extends BasePage {
 	state = {
 	state = {
-		exist: false,
-		MainPageParams: '',
 		boothContent: { uri: '' }
 		boothContent: { uri: '' }
 	};
 	};
 	render() {
 	render() {
@@ -22,61 +20,34 @@ export default class Splash extends BasePage {
 	}
 	}
 
 
 	componentWillMount() {
 	componentWillMount() {
-		// global.storage.remove({ key: 'userInfo' });
+		commonutil.getFileUserInfo().then((res) => {
-		this.getUserInfo();
+			if (global.userInfo == undefined || global.userInfo == null) {
-	}
-
-	componentDidMount() {}
-
-	async getUserInfo() {
-		//判断是否有用户
-		await global.storage
-			.load({
-				key: 'userInfo'
-			})
-			.then((result) => {
-				var usermap = commonutil.jsonToMap(result);
-				this.setState({
-					exist: true,
-					MainPageParams: usermap.get('ageGroup')
-				});
 				this.getShowCase();
 				this.getShowCase();
-			})
+				this.Advertisement(false);
-			.catch((err) => {
+			} else {
-				console.log(err.message);
+				console.log('====================================');
+				console.log('assfsafdasas', global.userInfo);
+				console.log('====================================');
 				this.getShowCase();
 				this.getShowCase();
-				this.setState({
+				this.Advertisement(true);
-					exist: false
+			}
-				});
+		});
-				switch (err.name) {
-					case 'NotFoundError':
-						break;
-					case 'ExpiredError':
-						// TODO
-						// alert('ExpiredError');
-						break;
-				}
-			});
 	}
 	}
 
 
 	getShowCase() {
 	getShowCase() {
 		http_showcase.getSTARTING_UP_RECOMMEND().then((res) => {
 		http_showcase.getSTARTING_UP_RECOMMEND().then((res) => {
-			console.log('====================================');
-			console.log('res', res.data[0].boothContent);
-			console.log('====================================');
 			this.setState({
 			this.setState({
 				boothContent: { uri: res.data[0].boothContent }
 				boothContent: { uri: res.data[0].boothContent }
 			});
 			});
 			SplashScreen.hide();
 			SplashScreen.hide();
-			this.Advertisement();
 		});
 		});
 	}
 	}
 
 
 	//获取用户之后的操作,或者是别的操作。
 	//获取用户之后的操作,或者是别的操作。
-	Advertisement() {
+	Advertisement(bool) {
 		//假装3秒广告
 		//假装3秒广告
 		setTimeout(() => {
 		setTimeout(() => {
-			if (this.state.exist) {
+			if (bool) {
 				this.clearPageToNext('MainPage');
 				this.clearPageToNext('MainPage');
 			} else {
 			} else {
 				this.clearPageToNext('Login');
 				this.clearPageToNext('Login');

+ 0 - 1
pages/components/BirthdayModal.js

@@ -255,7 +255,6 @@ export default class BirthdayModal extends Component<Props> {
 	};
 	};
 
 
 	componentWillMount() {
 	componentWillMount() {
-		var date = new Date();
 		var year = parseInt(this.props.year);
 		var year = parseInt(this.props.year);
 		console.log('========BirthdayModal.js---componentWillMount============================');
 		console.log('========BirthdayModal.js---componentWillMount============================');
 		console.log(year);
 		console.log(year);

+ 38 - 59
pages/components/MainPage.js

@@ -15,6 +15,7 @@ import {
 	Image,
 	Image,
 	FlatList,
 	FlatList,
 	TouchableOpacity,
 	TouchableOpacity,
+	BackHandler,
 	ImageBackground,
 	ImageBackground,
 	TextInput,
 	TextInput,
 	Animated,
 	Animated,
@@ -36,9 +37,6 @@ import Toast from '../components/Toast';
 export default class MainPage extends BasePage {
 export default class MainPage extends BasePage {
 	constructor(props) {
 	constructor(props) {
 		super(props);
 		super(props);
-		state: {
-			file_user_data: new Map();
-		}
 	}
 	}
 
 
 	updateRender(index) {
 	updateRender(index) {
@@ -80,9 +78,7 @@ export default class MainPage extends BasePage {
 			console.log(this.state.banner);
 			console.log(this.state.banner);
 		});
 		});
 	}
 	}
-	componentWillUnmount() {
+
-		this.refreshSubScription.remove();
-	}
 	state = {
 	state = {
 		grade: '大学',
 		grade: '大学',
 		ifGradeMenuShow: false,
 		ifGradeMenuShow: false,
@@ -125,14 +121,22 @@ export default class MainPage extends BasePage {
 	};
 	};
 
 
 	componentWillMount() {
 	componentWillMount() {
+		BackHandler.addEventListener('hardwareBackPress', this.onBackAndroid);
 		this.refreshSubScription = DeviceEventEmitter.addListener('indexInfo', () => {
 		this.refreshSubScription = DeviceEventEmitter.addListener('indexInfo', () => {
 			this.getUserInfo();
 			this.getUserInfo();
 		});
 		});
 		DeviceEventEmitter.emit('indexInfo');
 		DeviceEventEmitter.emit('indexInfo');
 	}
 	}
-	componentDidMount() {
+
-		// this.updateRender('PRIMARY_SCHOOL');
+	componentWillUnmount() {
+		BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
+		this.refreshSubScription.remove();
 	}
 	}
+	onBackAndroid = () => {
+		global.storage.remove({ key: 'userInfo' });
+		// BackHandler.exitApp();
+		return true;
+	};
 
 
 	switchGrade = (index) => {
 	switchGrade = (index) => {
 		const obj = this.state.switchList[index];
 		const obj = this.state.switchList[index];
@@ -141,11 +145,8 @@ export default class MainPage extends BasePage {
 		});
 		});
 		this.hideGradeMenu();
 		this.hideGradeMenu();
 		// if (obj.param === this.state.currentSwitch.param) return
 		// if (obj.param === this.state.currentSwitch.param) return
-		if (!this.state.file_user_data.get('isVisitor')) {
+		//这里更新个人信息学龄选项
-			//这里更新个人信息学龄选项
+		this.updateUserInfo(obj.param);
-			var bool = this.updateUserInfo(obj.param);
-		}
-
 		this.updateRender(obj.param);
 		this.updateRender(obj.param);
 	};
 	};
 
 
@@ -479,63 +480,41 @@ export default class MainPage extends BasePage {
 	};
 	};
 	// 获取用户信息
 	// 获取用户信息
 	async getUserInfo() {
 	async getUserInfo() {
-		await global.storage
+		this.setState({
-			.load({
+			username: global.userInfo.nickName,
-				key: 'userInfo'
+			avatar: global.userInfo.avatar
-			})
+		});
-			.then((result) => {
+		let ageindex = 0;
-				this.state.file_user_data = commonutil.jsonToMap(result);
+		if (global.userInfo.ageGroup === 'PRESCHOOL') {
-				var ageGroup = this.state.file_user_data.get('ageGroup');
+			ageindex = 0;
-				const username = this.state.file_user_data.get('nickName');
+		} else if (global.userInfo.ageGroup === 'PRIMARY_SCHOOL') {
-				const avatar = this.state.file_user_data.get('avatar');
+			ageindex = 1;
-				this.setState({
+		} else if (global.userInfo.ageGroup === 'MIDDLE_SCHOOL') {
-					username,
+			ageindex = 2;
-					avatar
+		}
-				});
+		this.switchGrade(ageindex);
-				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) {
+	updateUserInfo(group) {
 		let opts = {
 		let opts = {
 			method: 'PUT', //请求方法
 			method: 'PUT', //请求方法
 			body: { ageGroup: group } //请求体
 			body: { ageGroup: group } //请求体
 		};
 		};
-		await http_user.update_UserInfo(opts).then((res) => {
+		http_user.update_UserInfo(opts).then((res) => {
-			this.state.file_user_data.set('ageGroup', res.data.ageGroup);
+			global.userInfo.ageGroup = group;
-			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;
 		});
 		});
 	}
 	}
 	// 搜索
 	// 搜索
 	search() {
 	search() {
 		this.toNextPage('SearchResult');
 		this.toNextPage('SearchResult');
 	}
 	}
+
+	toNextPage = (params, obj) => {
+		if (!global.userInfo.isVisitor) {
+			this.props.navigation.navigate(params, obj);
+		} else {
+			this.Toast('请先登录');
+		}
+	};
 }
 }
 
 
 const styles = StyleSheet.create({
 const styles = StyleSheet.create({

+ 4 - 4
pages/services/user.js

@@ -67,21 +67,21 @@ export default class user {
 
 
 	//绑定微信
 	//绑定微信
 	static bind_wechat(opts) {
 	static bind_wechat(opts) {
-		return request(APIConfig.getUserUrl( `/wechatBind`) , opts);
+		return request(APIConfig.getUserUrl(`/wechatBind`), opts);
 	}
 	}
 
 
 	//获取验证码
 	//获取验证码
 	static getVerificationCode(phone) {
 	static getVerificationCode(phone) {
-		return request(APIConfig.getUserUrl( `/sendCode?mobile=`)  + phone);
+		return request(APIConfig.getUserUrl(`/sendCode?mobile=`) + phone);
 	}
 	}
 	//绑定手机号
 	//绑定手机号
 	static bind_phone(opts) {
 	static bind_phone(opts) {
-		return request(APIConfig.getUserUrl(`/mobileBind`) 	 , opts);
+		return request(APIConfig.getUserUrl(`/mobileBind`), opts);
 	}
 	}
 
 
 	//手机号登陆注册
 	//手机号登陆注册
 	static mobileLoginAndReg(opts) {
 	static mobileLoginAndReg(opts) {
-		return request(APIConfig.getUserUrl(`/mobileLoginAndReg`) + opts);
+		return request(APIConfig.getUserUrl(`/mobileLoginAndReg`), opts);
 	}
 	}
 
 
 	//微信登陆
 	//微信登陆

+ 29 - 0
pages/utils/commonutil.js

@@ -6,6 +6,35 @@ export default class commonutil {
 		return '1006';
 		return '1006';
 	}
 	}
 
 
+	static async getFileUserInfo() {
+		let a = await global.storage
+			.load({
+				key: 'userInfo'
+			})
+			.then((result) => {
+				return result;
+			})
+			.catch((err) => {
+				console.log('ERROR' + err.message);
+				return null;
+			});
+		return a;
+	}
+
+	static async saveUserInfo() {
+		global.storage
+			.save({
+				key: 'userInfo',
+				data: JSON.stringify(global.userInfo)
+			})
+			.then((result) => {
+				return result;
+			})
+			.catch((err) => {
+				return 'error';
+			});
+	}
+
 	//验证手机号
 	//验证手机号
 	static isPoneAvailable(str) {
 	static isPoneAvailable(str) {
 		let myreg = /^[1][0-9]{10}$/;
 		let myreg = /^[1][0-9]{10}$/;