promise.js 12 KB

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