فهرست منبع

1.首页跳转课程表传参

zhangmengjie 5 سال پیش
والد
کامیت
9d3b2ceb1f
3فایلهای تغییر یافته به همراه201 افزوده شده و 189 حذف شده
  1. 8 9
      pages/components/MainPage.js
  2. 5 5
      pages/components/SchedulePage.js
  3. 188 175
      pages/utils/efunRequest.js

+ 8 - 9
pages/components/MainPage.js

@@ -39,7 +39,7 @@ export default class MainPage extends BasePage {
 		}
 	}
 
-	 updateRender(index) {
+	updateRender(index) {
 		// LibraryUrl.getIndex(index).success(res => {
 
 		// }).fail(() => {
@@ -53,6 +53,7 @@ export default class MainPage extends BasePage {
 			const hotCourse = res.data.hotCourse;
 			const recommend = res.data.recommend; //全部课程
 			const banner = res.data.banner; //轮播图
+			const pageCode = res.data.pageCode;
 			// const listData = [];
 			// for(let item in res.data){
 			//   console.log(item)
@@ -70,7 +71,8 @@ export default class MainPage extends BasePage {
 				schedule,
 				recommend,
 				banner,
-				scheduleWeek
+				scheduleWeek,
+				pageCode
 			});
 			console.log(this.state.banner);
 		});
@@ -125,9 +127,6 @@ export default class MainPage extends BasePage {
 	}
 
 	switchGrade = (index) => {
-		console.log('====================================');
-		console.log('switchGrade:' + index);
-		console.log('====================================');
 		const obj = this.state.switchList[index];
 		this.setState({
 			currentSwitch: obj
@@ -189,7 +188,7 @@ export default class MainPage extends BasePage {
 					uri={this.state.avatar}
 					width={400}
 					height={150}
-					username= {this.state.username}
+					username={this.state.username}
 					isVip={this.state.isVip}
 					onPress={() => this.toNextPage('userCenter')}
 				/>
@@ -246,7 +245,7 @@ export default class MainPage extends BasePage {
 						height: Dimensions.getHeight(86),
 						marginRight: 12
 					}}
-					onPress={() => this.toNextPage('SchedulePage', { id })}
+					onPress={() => this.toNextPage('SchedulePage', { pagecode: this.state.pageCode })}
 					key={index}
 					activeOpacity={1}
 				>
@@ -475,11 +474,11 @@ export default class MainPage extends BasePage {
 				console.log(commonutil.mapToJson(this.state.file_user_data));
 				var ageGroup = this.state.file_user_data.get('ageGroup');
 				const username = this.state.file_user_data.get('nickName');
-				const avatar =  this.state.file_user_data.get('avatar');
+				const avatar = this.state.file_user_data.get('avatar');
 				this.setState({
 					username,
 					avatar
-				})
+				});
 				var ageindex = 0;
 				if (ageGroup === 'PRESCHOOL') {
 					ageindex = 0;

+ 5 - 5
pages/components/SchedulePage.js

@@ -200,12 +200,12 @@ export default class SchedulePage extends BasePage {
 		BackHandler.removeEventListener('hardwareBackPress', this.onBackAndroid);
 	}
 	componentDidMount() {
-		const { id } = this.props.navigation.state.params;
-		alert(id);
+		let pagecode = this.props.navigation.state.params.pagecode;
+		alert(pagecode);
 		let colorTemp = '';
 		let colorIndexTemp = 0;
 		const colorList = this.state.colorList;
-		ScheduleUrl.getSchedule('KINDERGARTEN').success((res) => {
+		ScheduleUrl.getSchedule(pagecode).success((res) => {
 			res.data.wareList.forEach((item, index) => {
 				if (index === 0) {
 					colorTemp = item.subTitle;
@@ -306,7 +306,7 @@ export default class SchedulePage extends BasePage {
 			'标题测试',
 			'标题内容',
 			'http://www.ncloud.hk/email-signature-262x100.png',
-			'http://www.baidu.com'
+			'http://www.efunbox.cn'
 		);
 	}
 	sharedcircel() {
@@ -314,7 +314,7 @@ export default class SchedulePage extends BasePage {
 			'标题测试',
 			'标题内容',
 			'http://www.ncloud.hk/email-signature-262x100.png',
-			'http://www.baidu.com'
+			'http://www.efunbox.cn'
 		);
 	}
 }

+ 188 - 175
pages/utils/efunRequest.js

@@ -2,180 +2,193 @@
 // import UserDataStorage from './UserDataStorage';
 
 class efunRequest {
-
-    constructor() {
-        this._url = '';
-        this._params = {};
-        this._data = {};
-        this._header = {};
-        this.xmlHTTPRequest = null;
-        this._onSuccess = null;
-        this._onFailed = null;
-        this._deserialize = null;
-        // 异步获取的
-        this.uid = storage.load({
-            key: 'uid'
-        })
-    }
-
-    request(method) {
-
-        const paramStr = () => {
-            if (!this._params) {
-                return ''
-            }
-            var pstr = '';
-            for (let key in this._params) {
-                pstr += `${key}=${this._params[key]}&`;
-            }
-            return pstr.slice(0, -1);
-        }
-
-        this.xmlHTTPRequest = new XMLHttpRequest();
-        this.xmlHTTPRequest.open(method, this._url + '?' + paramStr(), true);
-        this.xmlHTTPRequest.setRequestHeader('Content-Type', 'application/' + (method == 'POST' || method == 'PUT' ? 'x-www-form-urlencoded' : 'text'));
-        this.xmlHTTPRequest.setRequestHeader('uid', this.uid ? this.uid : '');
-
-
-        for (let key in this._header) {
-            this.xmlHTTPRequest.setRequestHeader(key, this._header[key]);
-        }
-
-        this.xmlHTTPRequest.onreadystatechange = () => {
-            this.whenResponse();
-        }
-
-        var sendBody = null;
-        if (this._data && (method == 'POST' || method == 'PUT')) {
-            var arr = new Array();
-            var i = 0;
-            for (var attr in this._data) {
-                arr[i] = encodeURIComponent(attr) + '=' + encodeURIComponent(this._data[attr]);
-                i++;
-            }
-            sendBody = '&' + arr.join('&');
-        }
-        this.xmlHTTPRequest.send(sendBody);
-        return this;
-    }
-
-    get() {
-        this.request('GET');
-        return this;
-    }
-
-    post() {
-        this.request('POST');
-        return this;
-    }
-
-    put() {
-        this.request('PUT');
-        return this;
-    }
-
-    delete() {
-        this.request('DELETE');
-        return this;
-    }
-
-    whenResponse() {
-        if (this.xmlHTTPRequest.readyState != 4) {
-            return;
-        }
-
-        if (this._deserialize) {
-            this._deserialize(this.xmlHTTPRequest.responseText, this);
-            return;
-        }
-
-        let cb = this.xmlHTTPRequest.status == 200 ? this._onSuccess : this._onFailed;
-        if (!cb) {
-            return;
-        }
-        cb(this.xmlHTTPRequest.status, this.xmlHTTPRequest.responseText);
-    }
-
-    success(callback) {
-        this._onSuccess = callback;
-        return this;
-    }
-
-    fail(callback) {
-        this._onFailed = callback;
-        return this;
-    }
-
-    header(obj, rewrite) {
-        if (rewrite) {
-            this._header = obj;
-        } else {
-            for (let key in obj) {
-                this._header[key] = obj[key];
-            }
-        }
-        return this;
-    }
-
-    params(obj) {
-        this._params = obj;
-        return this;
-    }
-
-    data(obj) {
-        this._data = obj;
-        return this;
-    }
-
-    url(str) {
-        this._url = str;
-        return this;
-    }
-
-    responseDeserialize(func) {
-        this._deserialize = func;
-        return this;
-    }
-
-    static getHttpRequest() {
-        let request = new efunRequest();
-        // if (UserDataStorage.getToken()) {
-        //     request.header({
-        //         'Authentication': UserDataStorage.getToken()
-        //     });
-        // }
-        request.responseDeserialize(function (res, req) {
-            function callFailed(data) {
-                if (req._onFailed) {
-                    req._onFailed(data);
-                }
-            }
-
-            function callSuccess(data) {
-                if (req._onSuccess) {
-                    req._onSuccess(data);
-                }
-            }
-
-            let rObj = null;
-            try {
-                rObj = JSON.parse(res);
-            } catch (e) {
-                callFailed(e);
-                return;
-            }
-            if (req.xmlHTTPRequest.status != 200) {
-                callFailed(rObj);
-                return;
-            }
-            if (!rObj.success) {
-                callFailed(rObj);
-                return;
-            }
-            callSuccess(rObj);
-        });
-        return request;
-    }
+	constructor() {
+		this._url = '';
+		this._params = {};
+		this._data = {};
+		this._header = {};
+		this.xmlHTTPRequest = null;
+		this._onSuccess = null;
+		this._onFailed = null;
+		this._deserialize = null;
+		// 异步获取的
+		this.uid = this.getuid();
+	}
+	async getuid() {
+		const userinfo = await storage
+			.load({
+				key: 'userInfo'
+			})
+			.catch((error) => {
+				return '';
+			});
+		if (userinfo === '') {
+			return '';
+		}
+		return JSON.parse(userinfo).uid;
+	}
+	request(method) {
+		const paramStr = () => {
+			if (!this._params) {
+				return '';
+			}
+			var pstr = '';
+			for (let key in this._params) {
+				pstr += `${key}=${this._params[key]}&`;
+			}
+			return pstr.slice(0, -1);
+		};
+
+		this.xmlHTTPRequest = new XMLHttpRequest();
+		this.xmlHTTPRequest.open(method, this._url + '?' + paramStr(), true);
+		this.xmlHTTPRequest.setRequestHeader(
+			'Content-Type',
+			'application/' + (method == 'POST' || method == 'PUT' ? 'x-www-form-urlencoded' : 'text')
+		);
+		console.log('====================================');
+		console.log('uid', this.uid);
+		console.log('====================================');
+		this.xmlHTTPRequest.setRequestHeader('uid', this.uid ? this.uid : '');
+
+		for (let key in this._header) {
+			this.xmlHTTPRequest.setRequestHeader(key, this._header[key]);
+		}
+
+		this.xmlHTTPRequest.onreadystatechange = () => {
+			this.whenResponse();
+		};
+
+		var sendBody = null;
+		if (this._data && (method == 'POST' || method == 'PUT')) {
+			var arr = new Array();
+			var i = 0;
+			for (var attr in this._data) {
+				arr[i] = encodeURIComponent(attr) + '=' + encodeURIComponent(this._data[attr]);
+				i++;
+			}
+			sendBody = '&' + arr.join('&');
+		}
+		this.xmlHTTPRequest.send(sendBody);
+		return this;
+	}
+
+	get() {
+		this.request('GET');
+		return this;
+	}
+
+	post() {
+		this.request('POST');
+		return this;
+	}
+
+	put() {
+		this.request('PUT');
+		return this;
+	}
+
+	delete() {
+		this.request('DELETE');
+		return this;
+	}
+
+	whenResponse() {
+		if (this.xmlHTTPRequest.readyState != 4) {
+			return;
+		}
+
+		if (this._deserialize) {
+			this._deserialize(this.xmlHTTPRequest.responseText, this);
+			return;
+		}
+
+		let cb = this.xmlHTTPRequest.status == 200 ? this._onSuccess : this._onFailed;
+		if (!cb) {
+			return;
+		}
+		cb(this.xmlHTTPRequest.status, this.xmlHTTPRequest.responseText);
+	}
+
+	success(callback) {
+		this._onSuccess = callback;
+		return this;
+	}
+
+	fail(callback) {
+		this._onFailed = callback;
+		return this;
+	}
+
+	header(obj, rewrite) {
+		if (rewrite) {
+			this._header = obj;
+		} else {
+			for (let key in obj) {
+				this._header[key] = obj[key];
+			}
+		}
+		return this;
+	}
+
+	params(obj) {
+		this._params = obj;
+		return this;
+	}
+
+	data(obj) {
+		this._data = obj;
+		return this;
+	}
+
+	url(str) {
+		this._url = str;
+		return this;
+	}
+
+	responseDeserialize(func) {
+		this._deserialize = func;
+		return this;
+	}
+
+	static getHttpRequest() {
+		let request = new efunRequest();
+		// if (UserDataStorage.getToken()) {
+		//     request.header({
+		//         'Authentication': UserDataStorage.getToken()
+		//     });
+		// }
+		request.responseDeserialize(function(res, req) {
+			function callFailed(data) {
+				if (req._onFailed) {
+					req._onFailed(data);
+				}
+			}
+
+			function callSuccess(data) {
+				if (req._onSuccess) {
+					req._onSuccess(data);
+				}
+			}
+
+			let rObj = null;
+			try {
+				rObj = JSON.parse(res);
+			} catch (e) {
+				callFailed(e);
+				return;
+			}
+			if (req.xmlHTTPRequest.status != 200) {
+				callFailed(rObj);
+				return;
+			}
+			if (!rObj.success) {
+				callFailed(rObj);
+				return;
+			}
+			callSuccess(rObj);
+		});
+		return request;
+	}
 }
 
-export default efunRequest;
+export default efunRequest;