promise.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. const qs = require('qs');
  2. const $ = require("jquery");
  3. var Promise = require('./rePromise');
  4. //重写assign方法
  5. if (typeof Object.assign != 'function') {
  6. Object.assign = function (target) {
  7. 'use strict';
  8. if (target == null) {
  9. throw new TypeError('Cannot convert undefined or null to object');
  10. }
  11. target = Object(target);
  12. for (var index = 1; index < arguments.length; index++) {
  13. var source = arguments[index];
  14. if (source != null) {
  15. for (var key in source) {
  16. if (Object.prototype.hasOwnProperty.call(source, key)) {
  17. target[key] = source[key];
  18. }
  19. }
  20. }
  21. }
  22. return target;
  23. };
  24. }
  25. window.console = window.console || (function () {
  26. var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
  27. = c.clear = c.exception = c.trace = c.assert = function () { };
  28. return c;
  29. })();
  30. const config = {
  31. pushInner: '/api/data/push/push',
  32. calculate: '/api/data/calc/calculate',
  33. disclaimer: '/api/data/disclaimerInformation/getDisclaimerInformations',
  34. information: '/api/data/conceptDetail/getConceptDetail',
  35. informationMore: '/api/data/conceptDetail/getConceptDetails',
  36. pushScale: '/api/data/push/pushScale',
  37. getSysSetInfoDatas: '/api/data/sysSet/getSysSetInfoDatas',
  38. getMr: '/api/data/mr/getMr', //页面推送患者信息
  39. getMr2: '/api/data/mrv2/getMr', //icss推送患者信息
  40. getVersion: '/api/data/versionInfo/getVersionInfoAlls',
  41. getStaticKnowledge: '/api/data/search/getStaticKnowledge',
  42. getStaticScale: '/api/data/search/getScale',
  43. dictionaryInfo: '/api/data/dictionaryInfo/getList', //字典信息
  44. getPushSet:'/api/data/pushSet/getPushSet', //获取推送配置
  45. analyse:'/api/data/mrqc/analyse',
  46. getHosptDeptUsal:'/api/data/concept/getHosptDeptUsal', //获取科室常用标签
  47. ruleTypeMap:{ //大数据推送参数featureType对应
  48. '22':'1,2',
  49. '11':'3',
  50. '8':'4,5'
  51. }
  52. }
  53. const imageUrlPrefix = 'http://192.168.2.121:82';
  54. // const getUrlArgObject = function(parm) {
  55. // var query = decodeURI(window.location.search);
  56. // var args = qs.parse(qs.parse(query.substr(1)));
  57. // return args[parm];//返回对象
  58. // }
  59. const getUrlArgObject = function getQueryString(name) {
  60. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  61. var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
  62. var r = window.location.search.substr(1).match(reg);
  63. var q = window.location.pathname.substr(1).match(reg_rewrite);
  64. if (r != null) {
  65. return decodeURIComponent(r[2]);
  66. } else if (q != null) {
  67. return decodeURIComponent(q[2]);
  68. } else {
  69. return null;
  70. }
  71. }
  72. const post = function (url, data) {
  73. return new Promise((resolve, reject) => {
  74. $.ajax({
  75. method: 'post',
  76. url: url,
  77. data: JSON.stringify(data),
  78. contentType: "application/json; charset=UTF-8",
  79. beforeSend: function (xmlHttp) {
  80. xmlHttp.setRequestHeader("If-Modified-Since", "0");
  81. xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  82. },
  83. success: function (res) {
  84. resolve({ data: res });
  85. },
  86. error: function (error) {
  87. reject(error);
  88. },
  89. });
  90. });
  91. }
  92. const newinConf = {
  93. width: '600', //窗口的文档显示区的宽度。以像素计。
  94. height: '600', //窗口文档显示区的高度。以像素计。
  95. left: '0', //窗口的 x 坐标。以像素计。
  96. top: '0', //窗口的 y 坐标。以像素计。
  97. openMode: "_blank" //每次都是新窗口打开为_blank,打开同一窗口填写任意字符串
  98. }
  99. const newWindowLocation = `width=${newinConf.width}, height=${newinConf.height}, left=${newinConf.left}, top=${newinConf.top} scrollbars=yes`
  100. const openNewWin = function (url) {
  101. window.open(url, newinConf.openMode, newWindowLocation)
  102. }
  103. //判断浏览器是否为Ie8
  104. const isIe8 = function () {
  105. var DEFAULT_VERSION = 8.0;
  106. var ua = navigator.userAgent.toLowerCase();
  107. var isIE = ua.indexOf("msie") > -1;
  108. var safariVersion;
  109. if (isIE) {
  110. safariVersion = ua.match(/msie ([\d.]+)/)[1];
  111. }
  112. if (safariVersion <= DEFAULT_VERSION) {
  113. return true
  114. }
  115. }
  116. const throttle = function (fn, threshhold) {
  117. var timeout
  118. var start = new Date;
  119. var threshhold = threshhold || 160
  120. return function () {
  121. var context = this, args = arguments, curr = new Date() - 0
  122. clearTimeout(timeout)//总是干掉事件回调
  123. if (curr - start >= threshhold) {
  124. // console.log("now", curr, curr - start)//注意这里相减的结果,都差不多是160左右
  125. fn.apply(context, args) //只执行一部分方法,这些方法是在某个时间段内执行一次
  126. start = curr
  127. } else {
  128. //让方法在脱离事件后也能执行一次
  129. timeout = setTimeout(function () {
  130. fn.apply(context, args)
  131. }, threshhold);
  132. }
  133. }
  134. }
  135. module.exports = {
  136. config,
  137. post,
  138. getUrlArgObject,
  139. imageUrlPrefix,
  140. throttle,
  141. openNewWin,
  142. isIe8
  143. }