123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- (function(exports) {
- var publish_version = false,
- server,
- imgUrlDomain,
- agentName = "wlyyAgentForDoc",
- userInfo = "userInfoForPay",
- userAgent = window.localStorage.getItem(agentName);//获取pcIM缓存
- //临时添加
- var sendHead = {};
- var userObj = JSON.parse(userAgent)
- sendHead.uid = userObj.uid
- sendHead.imei = localStorage.getItem('WLYY_IMEI')
- sendHead.platform = 4
- sendHead.token= userObj.token
-
- if(publish_version) { //生产环境配置
- server = ""
- } else { //测试环境配置
- server = "http://172.19.103.88:9092/wlyy/";
- imgUrlDomain = "http://172.19.103.54/";
- }
- function httpGet(url, options) {
- //发送ajax请求
- return new Promise(function(resolve, reject) {
- $.ajax(server + url,
- $.extend({}, {
- type: 'GET',
- dataType: 'JSON',
- beforeSend: function(request) {
- request.setRequestHeader("userAgent", JSON.stringify(sendHead));
- },
- error: function(res) {
- reject(res)
- },
- success: function(res) {
- resolve(res)
- }
- }, options));
- })
- }
- function httpPost(url, options) {
- //发送ajax请求
- return new Promise(function(resolve, reject) {
- $.ajax(server + url,
- $.extend({}, {
- type: 'POST',
- dataType: 'JSON',
- beforeSend: function(request) {
- request.setRequestHeader("userAgent", JSON.stringify(sendHead));
- },
- error: function(res) {
- reject(res)
- },
- success: function(res) {
- resolve(res)
- }
- }, options));
- })
- }
-
- /*
- * 获取图片路径
- */
- function getImgUrl(str){
- if(typeof str != 'string'){
- return "";
- }
- if(str.length == 0){
- return "";
- }else{
- if(str.indexOf("../")>-1){
- //访问本地路径
- return str;
- }else if((str.indexOf("http://")>-1) || (str.indexOf("https://")>-1)){
- return str;
- }else{
- //服务器上的图片路径
- return imgUrlDomain + str;
- }
- }
- }
- httpRequest = {
- server: server,
- userInfo: userInfo,
- agentName: agentName,
- userAgent:userAgent,
- get: function(url, options) {
- return httpGet(url, options)
- },
- post: function(url, options) {
- return httpPost(url, options)
- },
- getImgUrl:function(url){
- return getImgUrl(url)
- }
- }
- exports.httpRequest = httpRequest;
- })(window)
|