promise.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. const qs = require('qs');
  2. const $ = require("jquery");
  3. // var Promise = require('./rePromise');
  4. var Promise = require("bluebird");
  5. let warn = require('./../images/icon-warns.png').replace(/^undefined/g, '')
  6. let iconWarning = require('./../images/icon_waring_white.png').replace(/^undefined/g, '')
  7. let iconWarning1 = require('./../images/icon_warning.png').replace(/^undefined/g, '')
  8. let iconSymptomPush = require('./../images/icon_symptom_push.png').replace(/^undefined/g, '')
  9. let iconLisPush = require('./../images/icon_lis_push.png').replace(/^undefined/g, '')
  10. let iconPacsPush = require('./../images/icon_pacs_push.png').replace(/^undefined/g, '')
  11. let iconScalePush = require('./../images/icon_scale_push.png').replace(/^undefined/g, '')
  12. let iconNursePush = require('./../images/icon_nurse_push.png').replace(/^undefined/g, '')
  13. let iconOperationPush = require('./../images/icon_operation_push.png').replace(/^undefined/g, '')
  14. let iconDrugPush = require('./../images/icon_drug_push.png').replace(/^undefined/g, '')
  15. let iconDiagPush = require('./../images/icon_diag_push.png').replace(/^undefined/g, '')
  16. let iconDiagPush2 = require('./../images/icon_diag_push2.png').replace(/^undefined/g, '')
  17. let iconCommonTreatPush = require('./../images/icon_drug_push.png').replace(/^undefined/g, '')
  18. let iconCheckupPush = require('./../images/icon_checkup_push.png').replace(/^undefined/g, '')
  19. let iconTreat = require('./../images/zhiliao.png').replace(/^undefined/g, '')
  20. let iconTreatMedicine = require('./../images/treat_icon.png').replace(/^undefined/g, '')
  21. let iconCaseWrite = require('./../images/icon_case_write.png').replace(/^undefined/g, '')
  22. //重写assign方法imgR
  23. if (typeof Object.assign != 'function') {
  24. Object.assign = function (target) {
  25. 'use strict';
  26. if (target == null) {
  27. throw new TypeError('Cannot convert undefined or null to object');
  28. }
  29. target = Object(target);
  30. for (var index = 1; index < arguments.length; index++) {
  31. var source = arguments[index];
  32. if (source != null) {
  33. for (var key in source) {
  34. if (Object.prototype.hasOwnProperty.call(source, key)) {
  35. target[key] = source[key];
  36. }
  37. }
  38. }
  39. }
  40. return target;
  41. };
  42. }
  43. window.console = window.console || (function () {
  44. var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
  45. = c.clear = c.exception = c.trace = c.assert = function () { };
  46. return c;
  47. })();
  48. const config = {
  49. pushInner: '/sys/push/push',
  50. indicationPush: '/sys/push/indicationPush',
  51. indicationPushCache: '/sys/mr/getIndicationMr',
  52. calculate: '/api/data/calc/calculate',
  53. disclaimer: '/sys/disclaimerInfo/getDisclaimerInfo',
  54. information: '/kl/conceptInfo/getStaticKnowledge',
  55. getStaticKnowledgeForHIS: '/kl/conceptInfo/getStaticKnowledgeForHIS', //对接一对多
  56. informationMore: '/api/data/conceptDetail/getConceptDetails',
  57. pushScale: '/api/data/push/pushScale',
  58. getSysSetInfoDatas: '/sys/plan/getSysPlanInfoDatas',
  59. getMr: '/sys/mr/getMr', //页面推送患者信息
  60. getMr2: '/sys/mr/getMr', //icss推送患者信息
  61. getVersion: '/sys/versionInfo/getVersionInfoAlls',
  62. getStaticKnowledge: '/kl/conceptInfo/staticKnowledgeIndex',//静态知识检索
  63. getStaticScale: '/api/data/search/getScale',
  64. dictionaryInfo: '/sys/dictionaryInfo/getList', //字典信息
  65. getPushSet: '/sys/plan/getSysPlanInfoDatas', //获取推送配置
  66. analyse: '/api/data/mrqc/analyse',
  67. getHosptDeptUsal: '/api/data/concept/getHosptDeptUsal', //获取科室常用标签
  68. caseWritingPrompt: '/sys/mrqc/caseWritingPrompt',//病历书写规范提示
  69. followUp: '/sys/push/pushPlan', //随访计划
  70. ruleTypeMap: { //大数据推送参数featureType对应
  71. '22': '1,2',
  72. '11': '3',
  73. '8': '4,5'
  74. },
  75. staticSearch: '/kl/conceptInfo/staticIndexPage', //检索静态知识
  76. }
  77. const isLocal = window.location.hostname.indexOf('localhost') != -1;
  78. const imageUrlPrefix = isLocal ? 'http://192.168.2.241:82' : 'http://' + window.location.hostname + ':82';
  79. // const getUrlArgObject = function(parm) {
  80. // var query = decodeURI(window.location.search);
  81. // var args = qs.parse(qs.parse(query.substr(1)));
  82. // return args[parm];//返回对象
  83. // }
  84. const getUrlArgObject = function getQueryString(name) {
  85. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  86. var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
  87. var r = window.location.search.substr(1).match(reg);
  88. var q = window.location.pathname.substr(1).match(reg_rewrite);
  89. if (r != null) {
  90. return decodeURIComponent(r[2]);
  91. } else if (q != null) {
  92. return decodeURIComponent(q[2]);
  93. } else {
  94. return null;
  95. }
  96. }
  97. const get = function (url, data) {
  98. return new Promise((resolve, reject) => {
  99. $.ajax({
  100. method: 'get',
  101. url: url,
  102. //data: data,
  103. contentType: "application/json; charset=UTF-8",
  104. beforeSend: function (xmlHttp) {
  105. xmlHttp.setRequestHeader("If-Modified-Since", "0");
  106. xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  107. },
  108. success: function (res) {
  109. resolve({ data: res });
  110. },
  111. error: function (error) {
  112. reject(error);
  113. },
  114. });
  115. });
  116. }
  117. const post = function (url, data) {
  118. return new Promise((resolve, reject) => {
  119. $.ajax({
  120. method: 'post',
  121. url: url,
  122. data: JSON.stringify(data),
  123. contentType: "application/json; charset=UTF-8",
  124. beforeSend: function (xmlHttp) {
  125. xmlHttp.setRequestHeader("If-Modified-Since", "0");
  126. xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  127. },
  128. success: function (res) {
  129. resolve({ data: res });
  130. },
  131. error: function (error) {
  132. reject(error);
  133. },
  134. });
  135. });
  136. }
  137. const newinConf = {
  138. width: '600', //窗口的文档显示区的宽度。以像素计。
  139. height: '600', //窗口文档显示区的高度。以像素计。
  140. left: '0', //窗口的 x 坐标。以像素计。
  141. top: '0', //窗口的 y 坐标。以像素计。
  142. openMode: "_blank" //每次都是新窗口打开为_blank,打开同一窗口填写任意字符串
  143. }
  144. const newWindowLocationTcm = `width=800, height=600, left=${newinConf.left}, top=${newinConf.top},resizable=yes, scrollbars=yes`
  145. const newWindowLocation = `width=${newinConf.width}, height=${newinConf.height}, left=${newinConf.left}, top=${newinConf.top},resizable=yes, scrollbars=yes`
  146. const openNewWin = function (url, isTcm) {
  147. window.open(url, newinConf.openMode, isTcm ? newWindowLocationTcm : newWindowLocation)
  148. }
  149. //判断浏览器是否为Ie8
  150. const isIe8 = function () {
  151. var DEFAULT_VERSION = 8.0;
  152. var ua = navigator.userAgent.toLowerCase();
  153. var isIE = ua.indexOf("msie") > -1;
  154. var safariVersion;
  155. if (isIE) {
  156. safariVersion = ua.match(/msie ([\d.]+)/)[1];
  157. }
  158. if (safariVersion <= DEFAULT_VERSION) {
  159. return true
  160. }
  161. }
  162. const throttle = function (fn, threshhold) {
  163. var timeout
  164. var start = new Date;
  165. var threshhold = threshhold || 160
  166. return function () {
  167. var context = this, args = arguments, curr = new Date() - 0
  168. clearTimeout(timeout)//总是干掉事件回调
  169. if (curr - start >= threshhold) {
  170. // console.log("now", curr, curr - start)//注意这里相减的结果,都差不多是160左右
  171. fn.apply(context, args) //只执行一部分方法,这些方法是在某个时间段内执行一次
  172. start = curr
  173. } else {
  174. //让方法在脱离事件后也能执行一次
  175. timeout = setTimeout(function () {
  176. fn.apply(context, args)
  177. }, threshhold);
  178. }
  179. }
  180. }
  181. const titleConfig = {
  182. warning: {
  183. background: "#FFE8DD",
  184. icon: iconWarning1,
  185. name: "智能警示"
  186. },
  187. symptomPush: {
  188. background: "#EEF5FD",
  189. icon: iconSymptomPush,
  190. name: "推荐症状"
  191. },
  192. diagPush: {
  193. background: "#EEF5FD",
  194. icon: iconDiagPush2,
  195. name: "智能诊断"
  196. },
  197. checkupPush: {
  198. background: "#EEF5FD",
  199. icon: iconCheckupPush,
  200. name: "推荐体格检查"
  201. },
  202. scalePush: {
  203. background: "#EEF5FD",
  204. icon: iconScalePush,
  205. name: "推荐量表"
  206. },
  207. lisPush: {
  208. background: "#ECF4FC",
  209. icon: iconLisPush,
  210. name: "推荐检验"
  211. },
  212. pacsPush: {
  213. background: "#ECF4FC",
  214. icon: iconPacsPush,
  215. name: "推荐检查"
  216. },
  217. drugPush: {
  218. background: "#E3FEFE",
  219. icon: iconDrugPush,
  220. name: "推荐用药"
  221. },
  222. nursePush: {
  223. background: "#E3FEFE",
  224. icon: iconNursePush,
  225. name: "推荐护理"
  226. },
  227. operationPush: {
  228. background: "#E3FEFE",
  229. icon: iconOperationPush,
  230. name: "推荐手术及操作"
  231. },
  232. generaTreatPush: {
  233. background: "#E3FEFE",
  234. icon: iconTreat,
  235. name: "一般治疗"
  236. },
  237. casewritingPush: {
  238. background: "#FFE8DD",
  239. icon: iconCaseWrite,
  240. name: "病历书写规范提示"
  241. }
  242. }
  243. const titleConfigH = {
  244. warning: {
  245. background: "#FFE8DD",
  246. icon: iconWarning1,
  247. name: "智能警示",
  248. location: "left"
  249. },
  250. symptomPush: {
  251. background: "#EEF5FD",
  252. icon: iconSymptomPush,
  253. name: "推荐症状",
  254. location: "left"
  255. },
  256. diagPush: {
  257. background: "#FAECED",
  258. icon: iconDiagPush,
  259. name: "智能诊断",
  260. location: "left"
  261. },
  262. checkupPush: {
  263. background: "#EEF5FD",
  264. icon: iconCheckupPush,
  265. name: "体格检查",
  266. location: "left"
  267. },
  268. scalePush: {
  269. background: "#EEF5FD",
  270. icon: iconScalePush,
  271. name: "推荐量表",
  272. location: "left"
  273. },
  274. lisPush: {
  275. background: "#ECF4FC",
  276. icon: iconLisPush,
  277. name: "推荐检验",
  278. location: "left"
  279. },
  280. pacsPush: {
  281. background: "#ECF4FC",
  282. icon: iconPacsPush,
  283. name: "推荐检查",
  284. location: "left"
  285. },
  286. generaTreatPush: {
  287. background: "#E3FEFE",
  288. icon: iconTreat,
  289. name: "一般治疗",
  290. location: "right"
  291. },
  292. drugPush: {
  293. background: "#E3FEFE",
  294. icon: iconDrugPush,
  295. name: "推荐用药",
  296. location: "right"
  297. },
  298. operationPush: {
  299. background: "#E3FEFE",
  300. icon: iconOperationPush,
  301. name: "手术/操作",
  302. location: "right"
  303. },
  304. nursePush: {
  305. background: "#E3FEFE",
  306. icon: iconNursePush,
  307. name: "推荐护理",
  308. location: "right"
  309. },
  310. vigilancePush: {
  311. background: "#FFE8DD",
  312. icon: iconWarning,
  313. name: "警惕",
  314. location: "left"
  315. },
  316. treat: {
  317. background: "#FFE8DD",
  318. icon: iconTreat,
  319. name: "治疗方案"
  320. },
  321. casewritingPush: {
  322. background: "#E3FEFE",
  323. icon: iconTreat,
  324. name: "病历书写规范提示",
  325. location: "left"
  326. }
  327. }
  328. const Toast = function (msg, duration) {
  329. duration = isNaN(duration) ? 3000 : duration;
  330. var m = document.createElement('div');
  331. m.innerHTML = msg;
  332. m.style.cssText = "max-width:60%;min-width: 150px;padding:0 14px;height: 30px;color: #fff;line-height: 30px;text-align: center;border-radius: 4px;position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);z-index: 999999;background: #333;font-size: 16px;";
  333. document.body.appendChild(m);
  334. setTimeout(function () {
  335. var d = 0.5;
  336. m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
  337. m.style.opacity = '0';
  338. setTimeout(function () { document.body.removeChild(m) }, d * 1000);
  339. }, duration);
  340. }
  341. function toast(mess) {
  342. var str = '<div class="mess"><span></span></div>';
  343. $("body").append(str);
  344. $(".mess").fadeIn().find("span").html(mess);
  345. setTimeout(function () {
  346. $(".mess").fadeOut();
  347. }, 2000)
  348. }
  349. const Toasts = function (mess) {
  350. var str = `<div id="mess"><img class="warn" style="margin-right:14px" src=${warn}/><span></span></div>`;
  351. $("body").append(str);
  352. $("#mess").fadeIn().find("span").html(mess);
  353. document.getElementById("mess").style.cssText = "display:flex;align-items:center;max-width:60%;min-width: 150px;padding:0 14px;height: 30px;color: #FFB609;line-height: 30px;text-align: center;border-radius: 4px;position: fixed;top: 75px;left: 50%;transform: translate(-50%, -50%);z-index: 999999;background: #FDF6EA;font-size: 16px;";
  354. setTimeout(function () {
  355. $("#mess").fadeOut();
  356. }, 1000)
  357. }
  358. module.exports = {
  359. config,
  360. get,
  361. post,
  362. getUrlArgObject,
  363. imageUrlPrefix,
  364. throttle,
  365. openNewWin,
  366. isIe8,
  367. titleConfig,
  368. titleConfigH,
  369. Toast, Toasts
  370. }