promise.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  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-warning.png').replace(/^undefined/g, '')
  6. let success = require('./../images/icon-success.png').replace(/^undefined/g, '')
  7. let iconWarning = require('./../images/icon_waring_white.png').replace(/^undefined/g, '')
  8. let iconWarning1 = require('./../images/icon_warning.png').replace(/^undefined/g, '')
  9. let iconSymptomPush = require('./../images/icon_symptom_push.png').replace(/^undefined/g, '')
  10. let iconLisPush = require('./../images/icon_lis_push.png').replace(/^undefined/g, '')
  11. let iconPacsPush = require('./../images/icon_pacs_push.png').replace(/^undefined/g, '')
  12. let iconScalePush = require('./../images/icon_scale_push.png').replace(/^undefined/g, '')
  13. let iconNursePush = require('./../images/icon_nurse_push.png').replace(/^undefined/g, '')
  14. let iconOperationPush = require('./../images/icon_operation_push.png').replace(/^undefined/g, '')
  15. let iconDrugPush = require('./../images/icon_drug_push.png').replace(/^undefined/g, '')
  16. let iconDiagPush = require('./../images/icon_diag_push.png').replace(/^undefined/g, '')
  17. let iconDiagPush2 = require('./../images/icon_diag_push2.png').replace(/^undefined/g, '')
  18. let iconCommonTreatPush = require('./../images/icon_drug_push.png').replace(/^undefined/g, '')
  19. let iconCheckupPush = require('./../images/icon_checkup_push.png').replace(/^undefined/g, '')
  20. let iconTreat = require('./../images/zhiliao.png').replace(/^undefined/g, '')
  21. let iconTreatMedicine = require('./../images/treat_icon.png').replace(/^undefined/g, '')
  22. let iconCaseWrite = require('./../images/icon_case_write.png').replace(/^undefined/g, '')
  23. //重写assign方法imgR
  24. if (typeof Object.assign != 'function') {
  25. Object.assign = function (target) {
  26. 'use strict';
  27. if (target == null) {
  28. throw new TypeError('Cannot convert undefined or null to object');
  29. }
  30. target = Object(target);
  31. for (var index = 1; index < arguments.length; index++) {
  32. var source = arguments[index];
  33. if (source != null) {
  34. for (var key in source) {
  35. if (Object.prototype.hasOwnProperty.call(source, key)) {
  36. target[key] = source[key];
  37. }
  38. }
  39. }
  40. }
  41. return target;
  42. };
  43. }
  44. window.console = window.console || (function () {
  45. var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
  46. = c.clear = c.exception = c.trace = c.assert = function () { };
  47. return c;
  48. })();
  49. const config = {
  50. pushInner: '/sys/push/push',
  51. indicationPush:'/sys/push/indicationPush',
  52. indicationPushCache: '/sys/mr/getIndicationMr',
  53. calculate: '/api/data/calc/calculate',
  54. disclaimer: '/sys/disclaimerInfo/getDisclaimerInfo',
  55. information: '/kl/conceptInfo/getStaticKnowledge',
  56. getStaticKnowledgeForHIS:'/kl/conceptInfo/getStaticKnowledgeForHIS', //对接一对多
  57. informationMore: '/api/data/conceptDetail/getConceptDetails',
  58. pushScale: '/api/data/push/pushScale',
  59. getSysSetInfoDatas: '/sys/plan/getSysPlanInfoDatas',
  60. getMr: '/sys/mr/getMr', //页面推送患者信息
  61. getMr2: '/sys/mr/getMr', //icss推送患者信息
  62. getVersion: '/sys/versionInfo/getVersionInfoAlls',
  63. getStaticKnowledge: '/kl/conceptInfo/staticKnowledgeIndex',//静态知识检索
  64. getStaticScale: '/api/data/search/getScale',
  65. dictionaryInfo: '/sys/dictionaryInfo/getList', //字典信息
  66. getPushSet:'/sys/plan/getSysPlanInfoDatas', //获取推送配置
  67. analyse:'/api/data/mrqc/analyse',
  68. getHosptDeptUsal:'/api/data/concept/getHosptDeptUsal', //获取科室常用标签
  69. caseWritingPrompt:'/sys/mrqc/caseWritingPrompt',//病历书写规范提示
  70. followUp:'/sys/push/pushPlan', //随访计划
  71. ruleTypeMap:{ //大数据推送参数featureType对应
  72. '22':'1,2',
  73. '11':'3',
  74. '8':'4,5'
  75. },
  76. staticSearch:'/kl/conceptInfo/staticIndexPage', //检索静态知识
  77. }
  78. const isLocal = window.location.hostname.indexOf('localhost') !=-1;
  79. const imageUrlPrefix = isLocal ?'http://192.168.2.241:82':'http://223.93.170.82:12282';
  80. // const getUrlArgObject = function(parm) {
  81. // var query = decodeURI(window.location.search);
  82. // var args = qs.parse(qs.parse(query.substr(1)));
  83. // return args[parm];//返回对象
  84. // }
  85. const getUrlArgObject = function getQueryString(name) {
  86. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  87. var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
  88. var r = window.location.search.substr(1).match(reg);
  89. var q = window.location.pathname.substr(1).match(reg_rewrite);
  90. if (r != null) {
  91. return decodeURIComponent(r[2]);
  92. } else if (q != null) {
  93. return decodeURIComponent(q[2]);
  94. } else {
  95. return null;
  96. }
  97. }
  98. const get = function (url, data) {
  99. return new Promise((resolve, reject) => {
  100. $.ajax({
  101. method: 'get',
  102. url: url,
  103. //data: data,
  104. contentType: "application/json; charset=UTF-8",
  105. beforeSend: function (xmlHttp) {
  106. xmlHttp.setRequestHeader("If-Modified-Since", "0");
  107. xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  108. },
  109. success: function (res) {
  110. resolve({data: res});
  111. },
  112. error: function (error) {
  113. reject(error);
  114. },
  115. });
  116. });
  117. }
  118. const post = function (url, data) {
  119. return new Promise((resolve, reject) => {
  120. $.ajax({
  121. method: 'post',
  122. url: url,
  123. data: JSON.stringify(data),
  124. contentType: "application/json; charset=UTF-8",
  125. beforeSend: function (xmlHttp) {
  126. xmlHttp.setRequestHeader("If-Modified-Since", "0");
  127. xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  128. },
  129. success: function (res) {
  130. resolve({ data: res });
  131. },
  132. error: function (error) {
  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 titleConfig = {
  183. warning:{
  184. background: "#FFE8DD",
  185. icon: iconWarning1,
  186. name:"智能警示"
  187. },
  188. symptomPush:{
  189. background: "#EEF5FD",
  190. icon: iconSymptomPush,
  191. name:"推荐症状"
  192. },
  193. diagPush:{
  194. background: "#EEF5FD",
  195. icon: iconDiagPush2,
  196. name:"智能诊断"
  197. },
  198. checkupPush:{
  199. background: "#EEF5FD",
  200. icon: iconCheckupPush,
  201. name:"推荐体格检查"
  202. },
  203. scalePush:{
  204. background: "#EEF5FD",
  205. icon: iconScalePush,
  206. name:"推荐量表"
  207. },
  208. lisPush:{
  209. background: "#ECF4FC",
  210. icon: iconLisPush,
  211. name:"推荐检验"
  212. },
  213. pacsPush:{
  214. background: "#ECF4FC",
  215. icon: iconPacsPush,
  216. name:"推荐检查"
  217. },
  218. drugPush:{
  219. background: "#E3FEFE",
  220. icon: iconDrugPush,
  221. name:"推荐用药"
  222. },
  223. nursePush: {
  224. background: "#E3FEFE",
  225. icon: iconNursePush,
  226. name: "推荐护理"
  227. },
  228. operationPush:{
  229. background: "#E3FEFE",
  230. icon: iconOperationPush,
  231. name:"推荐手术及操作"
  232. },
  233. generaTreatPush:{
  234. background: "#E3FEFE",
  235. icon: iconTreat,
  236. name:"一般治疗"
  237. },
  238. casewritingPush:{
  239. background: "#FFE8DD",
  240. icon: iconCaseWrite,
  241. name:"病历书写规范提示"
  242. }
  243. }
  244. const titleConfigH = {
  245. warning:{
  246. background: "#FFE8DD",
  247. icon: iconWarning1,
  248. name:"智能警示",
  249. location:"left"
  250. },
  251. symptomPush:{
  252. background: "#EEF5FD",
  253. icon: iconSymptomPush,
  254. name:"推荐症状",
  255. location:"left"
  256. },
  257. diagPush:{
  258. background: "#FAECED",
  259. icon: iconDiagPush,
  260. name:"智能诊断",
  261. location:"left"
  262. },
  263. checkupPush:{
  264. background: "#EEF5FD",
  265. icon: iconCheckupPush,
  266. name:"体格检查",
  267. location:"left"
  268. },
  269. scalePush:{
  270. background: "#EEF5FD",
  271. icon: iconScalePush,
  272. name:"推荐量表",
  273. location:"left"
  274. },
  275. lisPush:{
  276. background: "#ECF4FC",
  277. icon: iconLisPush,
  278. name:"推荐检验",
  279. location:"left"
  280. },
  281. pacsPush:{
  282. background: "#ECF4FC",
  283. icon: iconPacsPush,
  284. name:"推荐检查",
  285. location:"left"
  286. },
  287. generaTreatPush:{
  288. background: "#E3FEFE",
  289. icon: iconTreat,
  290. name:"一般治疗",
  291. location:"right"
  292. },
  293. drugPush:{
  294. background: "#E3FEFE",
  295. icon: iconDrugPush,
  296. name:"推荐用药",
  297. location:"right"
  298. },
  299. operationPush:{
  300. background: "#E3FEFE",
  301. icon: iconOperationPush,
  302. name:"手术/操作",
  303. location:"right"
  304. },
  305. nursePush: {
  306. background: "#E3FEFE",
  307. icon: iconNursePush,
  308. name: "推荐护理",
  309. location: "right"
  310. },
  311. vigilancePush:{
  312. background: "#FFE8DD",
  313. icon: iconWarning,
  314. name:"警惕",
  315. location:"left"
  316. },
  317. treat:{
  318. background: "#FFE8DD",
  319. icon: iconTreat,
  320. name:"治疗方案"
  321. },
  322. casewritingPush:{
  323. background: "#E3FEFE",
  324. icon: iconTreat,
  325. name:"病历书写规范提示",
  326. location:"left"
  327. }
  328. }
  329. const Toast = function (msg, duration,type) {
  330. duration = isNaN(duration) ? 3000 : duration;
  331. var m = document.createElement('div');
  332. if(type == 'warn'){
  333. m.innerHTML = '<div style="margin:auto"><img class="warn" style="margin-right:14px;float:left" src="./../images/icon-warning.png" /><span>'+msg+'</span></div>'
  334. 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;";
  335. }else if(type == 'success'){
  336. 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>'
  337. 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;";
  338. }
  339. $('.warn').css('margin-top','10px')
  340. document.body.appendChild(m);
  341. setTimeout(function () {
  342. var d = 0.5;
  343. m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
  344. m.style.opacity = '0';
  345. setTimeout(function () { document.body.removeChild(m) }, d * 1000);
  346. }, duration);
  347. }
  348. module.exports = {
  349. config,
  350. get,
  351. post,
  352. getUrlArgObject,
  353. imageUrlPrefix,
  354. throttle,
  355. openNewWin,
  356. isIe8,
  357. titleConfig,
  358. titleConfigH,
  359. Toast
  360. }