Browse Source

提交api-service文件

raolu 7 years ago
parent
commit
4f603d24b5
1 changed files with 62 additions and 14 deletions
  1. 62 14
      js/api-service.js

+ 62 - 14
js/api-service.js

@ -1,16 +1,18 @@
(function($){
	var publish_version = false;
	var agentName = "wlyyAgent";
	var server, userAgent, loginUrl;
	var server, userAgent, loginUrl, imserver, socketUrl;
	
 
	$.support.cors = true;
	if(publish_version) { // 生产环境配置
		
	} else { // 测试环境配置
        // server = "http://172.19.103.88:9092/wlyy/"
        server = "http://192.168.131.127:8060/"; //逸祥
        server = "http://172.19.103.88:9092/wlyy/"
        // server = "http://192.168.131.127:8060/"; //逸祥
        // server = "http://192.168.131.24:8080/"; //仕杰
        imserver = "http://172.19.103.88:3000/api/v2";
        socketUrl = "http://172.19.103.88:3000";
		loginUrl = "http://172.19.103.88:9092/wlyy/auth/login.html"
	}
	
@ -18,20 +20,20 @@
    userAgent = localStorage.getItem(agentName)
    //hard code userAgent for test
    //全科
       userAgent = {"id":4800,"uid":"zbqD201703150222","imei":"864394010176834","token":"8a987068ce47f9709080eda4897e25a1","platform":2,"hospital":"3502050100"};
    // userAgent = {"id":4800,"uid":"zbqD201703150222","imei":"864394010176834","token":"3e1795bd21c466eb749480c37847c8b1","platform":2,"hospital":"3502050100"};
    //健管
    // userAgent = {"id":4821,"uid":"zbqD201703150228","imei":"864394010176834","token":"73f5ace5c7d4cdb811f743902fd705d9","platform":2,"hospital":"3502050100"}; 
    // userAgent = JSON.stringify(userAgent);
     
//	if(userAgent) {
//		try{
//			userAgent = JSON.parse(userAgent)
//		}catch(e){
//			location.replace(loginUrl+'?redirect_url='+encodeURIComponent(location.href))
//		}
//	} else {
//		location.replace(loginUrl+'?redirect_url='+encodeURIComponent(location.href))
//	}
	if(userAgent) {
		try{
			userAgent = JSON.parse(userAgent)
		}catch(e){
			location.replace(loginUrl+'?redirect_url='+encodeURIComponent(location.href))
		}
	} else {
		location.replace(loginUrl+'?redirect_url='+encodeURIComponent(location.href))
	}
	
	function httpGet(url,options) {
		//发送ajax请求
@ -73,6 +75,48 @@
				}
			},options));
		})
    }
    
    function imHttpGet(url,options) {
		//发送ajax请求
		return new Promise(function(resolve, reject) {
			$.ajax(imserver + url, 
				$.extend({},{
				type: 'GET',
                dataType: 'JSON',
                beforeSend: function(request) {
                    request.setRequestHeader("userAgent", JSON.stringify(userAgent));
				},
				error: function(res) {
					reject(res)
				},
				success: function(res) {
					failCodeHandle(res)
					resolve(res)
				}
			},options));
		})
	}
	
	function imHttpPost(url,options) {
		//发送ajax请求
		return new Promise(function(resolve, reject) {
			$.ajax(imserver + url, 
				$.extend({},{
				type: 'POST',
                dataType: 'JSON',
                beforeSend: function(request) {
                    request.setRequestHeader("userAgent", JSON.stringify(userAgent));
				},
				error: function(res) {
					reject(res)
				},
				success: function(res) {
					failCodeHandle(res)
					resolve(res)
				}
			},options));
		})
	}
	
	function failCodeHandle(res) {
@ -88,13 +132,17 @@
			toastr && toastr.warning(tip)
			location.replace(loginUrl+'?redirect_url='+encodeURIComponent(location.href))
		}
	}
    }
	
	APIService = {
        server: server,
        imserver: imserver,
        socketUrl: socketUrl,
        userAgent: userAgent,
        httpGet: httpGet,
        httpPost: httpPost,
        imHttpGet: imHttpGet,
        imHttpPost: imHttpPost,
        getDoctorInfo: function(){
            return httpGet('doctor/baseinfo');
        },