const qs = require('qs'); const $ = require("jquery"); var Promise = require('./rePromise'); //重写assign方法 if (typeof Object.assign != 'function') { Object.assign = function(target) { 'use strict'; if (target == null) { throw new TypeError('Cannot convert undefined or null to object'); } target = Object(target); for (var index = 1; index < arguments.length; index++) { var source = arguments[index]; if (source != null) { for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } } return target; }; } const config = { pushInner:'/api/data/push/push', calculate:'/api/data/calc/calculate', disclaimer: '/api/data/disclaimerInformation/getDisclaimerInformations', information: '/api/data/conceptDetail/getConceptDetail', pushScale: '/api/data/push/pushScale', pushTreatment: '/api/data/push/pushTreatment', getSysSetInfoDatas: '/api/data/sysSet/getSysSetInfoDatas', getMr: '/api/data/mr/getMr' } const imageUrlPrefix = 'http://192.168.2.241:82'; const getUrlArgObject = function(parm) { var query = window.location.search; var args = qs.parse(query.substr(1)); return args[parm];//返回对象 } const post = function(url,data){ return new Promise((resolve,reject)=>{ $.ajax({ method:'post', url:url, data:JSON.stringify(data), contentType:"application/json; charset=UTF-8", beforeSend :function(xmlHttp){ xmlHttp.setRequestHeader("If-Modified-Since","0"); xmlHttp.setRequestHeader("Cache-Control","no-cache"); }, success:function(res){ resolve({data:res}); }, error:function(error){ reject(error); }, }); }); } const newinConf = { width: '600', //窗口的文档显示区的宽度。以像素计。 height: '600', //窗口文档显示区的高度。以像素计。 left: '0', //窗口的 x 坐标。以像素计。 top: '0', //窗口的 y 坐标。以像素计。 openMode: "_blank" //每次都是新窗口打开为_blank,打开同一窗口填写任意字符串 } const newWindowLocation = `width=${newinConf.width}, height=${newinConf.height}, left=${newinConf.left}, top=${newinConf.top} scrollbars=yes` const openNewWin = function(url) { window.open(url, newinConf.openMode, newWindowLocation) } //判断浏览器是否为Ie8 const isIe8 = function(){ var DEFAULT_VERSION = 8.0; var ua = navigator.userAgent.toLowerCase(); var isIE = ua.indexOf("msie")>-1; var safariVersion; if(isIE){ safariVersion = ua.match(/msie ([\d.]+)/)[1]; } if(safariVersion <= DEFAULT_VERSION ) { return true } } const throttle = function(fn, threshhold) { var timeout var start = new Date; var threshhold = threshhold || 160 return function () { var context = this, args = arguments, curr = new Date() - 0 clearTimeout(timeout)//总是干掉事件回调 if(curr - start >= threshhold){ // console.log("now", curr, curr - start)//注意这里相减的结果,都差不多是160左右 fn.apply(context, args) //只执行一部分方法,这些方法是在某个时间段内执行一次 start = curr }else{ //让方法在脱离事件后也能执行一次 timeout = setTimeout(function(){ fn.apply(context, args) }, threshhold); } } } module.exports = { config, post, getUrlArgObject, imageUrlPrefix, throttle, openNewWin, isIe8 }