promise.js 12 KB

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