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; }; } window.console = window.console || (function () { var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile = c.clear = c.exception = c.trace = c.assert = function () { }; return c; })(); const config = { pushInner: '/api/data/push/push', calculate: '/api/data/calc/calculate', disclaimer: '/api/data/disclaimerInformation/getDisclaimerInformations', information: '/api/data/conceptDetail/getConceptDetail', informationMore: '/api/data/conceptDetail/getConceptDetails', pushScale: '/api/data/push/pushScale', getSysSetInfoDatas: '/api/data/sysSet/getSysSetInfoDatas', getMr: '/api/data/mrv2/getMr', getVersion: '/api/data/versionInfo/getVersionInfoAlls', getStaticKnowledge: '/api/data/search/getStaticKnowledge', getStaticScale: '/api/data/search/getScale', dictionaryInfo: '/api/data/dictionaryInfo/getList', //字典信息 ruleTypeMap:{ //大数据推送参数featureType对应 '22':'1,2', '11':'3', '8':'4,5' } } const imageUrlPrefix = 'http://192.168.2.241:82'; // const getUrlArgObject = function(parm) { // var query = decodeURI(window.location.search); // var args = qs.parse(qs.parse(query.substr(1))); // return args[parm];//返回对象 // } const getUrlArgObject = function getQueryString(name) { var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i"); var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i"); var r = window.location.search.substr(1).match(reg); var q = window.location.pathname.substr(1).match(reg_rewrite); if (r != null) { return decodeURIComponent(r[2]); } else if (q != null) { return decodeURIComponent(q[2]); } else { return null; } } 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 }