promise.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365
  1. const qs = require('qs');
  2. const $ = require("jquery");
  3. // var Promise = require('./rePromise');
  4. var Promise = require("bluebird");
  5. let iconWarning = require('./../images/icon_waring_white.png').replace(/^undefined/g, '')
  6. let iconWarning1 = require('./../images/icon_warning.png').replace(/^undefined/g, '')
  7. let iconSymptomPush = require('./../images/icon_symptom_push.png').replace(/^undefined/g, '')
  8. let iconLisPush = require('./../images/icon_lis_push.png').replace(/^undefined/g, '')
  9. let iconPacsPush = require('./../images/icon_pacs_push.png').replace(/^undefined/g, '')
  10. let iconScalePush = require('./../images/icon_scale_push.png').replace(/^undefined/g, '')
  11. let iconNursePush = require('./../images/icon_nurse_push.png').replace(/^undefined/g, '')
  12. let iconOperationPush = require('./../images/icon_operation_push.png').replace(/^undefined/g, '')
  13. let iconDrugPush = require('./../images/icon_drug_push.png').replace(/^undefined/g, '')
  14. let iconDiagPush = require('./../images/icon_diag_push.png').replace(/^undefined/g, '')
  15. let iconDiagPush2 = require('./../images/icon_diag_push2.png').replace(/^undefined/g, '')
  16. let iconCommonTreatPush = require('./../images/icon_drug_push.png').replace(/^undefined/g, '')
  17. let iconCheckupPush = require('./../images/icon_checkup_push.png').replace(/^undefined/g, '')
  18. let iconTreat = require('./../images/zhiliao.png').replace(/^undefined/g, '')
  19. let iconTreatMedicine = require('./../images/treat_icon.png').replace(/^undefined/g, '')
  20. let iconCaseWrite = require('./../images/icon_case_write.png').replace(/^undefined/g, '')
  21. //重写assign方法imgR
  22. if (typeof Object.assign != 'function') {
  23. Object.assign = function (target) {
  24. 'use strict';
  25. if (target == null) {
  26. throw new TypeError('Cannot convert undefined or null to object');
  27. }
  28. target = Object(target);
  29. for (var index = 1; index < arguments.length; index++) {
  30. var source = arguments[index];
  31. if (source != null) {
  32. for (var key in source) {
  33. if (Object.prototype.hasOwnProperty.call(source, key)) {
  34. target[key] = source[key];
  35. }
  36. }
  37. }
  38. }
  39. return target;
  40. };
  41. }
  42. window.console = window.console || (function () {
  43. var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
  44. = c.clear = c.exception = c.trace = c.assert = function () { };
  45. return c;
  46. })();
  47. const config = {
  48. pushInner: '/sys/push/push',
  49. indicationPush:'/sys/push/indicationPush',
  50. indicationPushCache: '/sys/mr/getIndicationMr',
  51. calculate: '/api/data/calc/calculate',
  52. disclaimer: '/sys/disclaimerInfo/getDisclaimerInfo',
  53. information: '/kl/conceptInfo/getStaticKnowledge',
  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://192.168.2.241:82':'http://'+window.location.hostname+':82';
  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. resolve({ data: res });
  129. },
  130. error: function (error) {
  131. reject(error);
  132. },
  133. });
  134. });
  135. }
  136. const newinConf = {
  137. width: '600', //窗口的文档显示区的宽度。以像素计。
  138. height: '600', //窗口文档显示区的高度。以像素计。
  139. left: '0', //窗口的 x 坐标。以像素计。
  140. top: '0', //窗口的 y 坐标。以像素计。
  141. openMode: "_blank" //每次都是新窗口打开为_blank,打开同一窗口填写任意字符串
  142. }
  143. const newWindowLocationTcm = `width=800, height=600, left=${newinConf.left}, top=${newinConf.top},resizable=yes, scrollbars=yes`
  144. const newWindowLocation = `width=${newinConf.width}, height=${newinConf.height}, left=${newinConf.left}, top=${newinConf.top},resizable=yes, scrollbars=yes`
  145. const openNewWin = function (url, isTcm) {
  146. window.open(url, newinConf.openMode, isTcm ? newWindowLocationTcm : newWindowLocation)
  147. }
  148. //判断浏览器是否为Ie8
  149. const isIe8 = function () {
  150. var DEFAULT_VERSION = 8.0;
  151. var ua = navigator.userAgent.toLowerCase();
  152. var isIE = ua.indexOf("msie") > -1;
  153. var safariVersion;
  154. if (isIE) {
  155. safariVersion = ua.match(/msie ([\d.]+)/)[1];
  156. }
  157. if (safariVersion <= DEFAULT_VERSION) {
  158. return true
  159. }
  160. }
  161. const throttle = function (fn, threshhold) {
  162. var timeout
  163. var start = new Date;
  164. var threshhold = threshhold || 160
  165. return function () {
  166. var context = this, args = arguments, curr = new Date() - 0
  167. clearTimeout(timeout)//总是干掉事件回调
  168. if (curr - start >= threshhold) {
  169. // console.log("now", curr, curr - start)//注意这里相减的结果,都差不多是160左右
  170. fn.apply(context, args) //只执行一部分方法,这些方法是在某个时间段内执行一次
  171. start = curr
  172. } else {
  173. //让方法在脱离事件后也能执行一次
  174. timeout = setTimeout(function () {
  175. fn.apply(context, args)
  176. }, threshhold);
  177. }
  178. }
  179. }
  180. const titleConfig = {
  181. warning:{
  182. background: "#FFE8DD",
  183. icon: iconWarning1,
  184. name:"智能警示"
  185. },
  186. symptomPush:{
  187. background: "#EEF5FD",
  188. icon: iconSymptomPush,
  189. name:"推荐症状"
  190. },
  191. diagPush:{
  192. background: "#EEF5FD",
  193. icon: iconDiagPush2,
  194. name:"智能诊断"
  195. },
  196. checkupPush:{
  197. background: "#EEF5FD",
  198. icon: iconCheckupPush,
  199. name:"推荐体格检查"
  200. },
  201. scalePush:{
  202. background: "#EEF5FD",
  203. icon: iconScalePush,
  204. name:"推荐量表"
  205. },
  206. lisPush:{
  207. background: "#ECF4FC",
  208. icon: iconLisPush,
  209. name:"推荐检验"
  210. },
  211. pacsPush:{
  212. background: "#ECF4FC",
  213. icon: iconPacsPush,
  214. name:"推荐检查"
  215. },
  216. drugPush:{
  217. background: "#E3FEFE",
  218. icon: iconDrugPush,
  219. name:"推荐用药"
  220. },
  221. nursePush: {
  222. background: "#E3FEFE",
  223. icon: iconNursePush,
  224. name: "推荐护理"
  225. },
  226. operationPush:{
  227. background: "#E3FEFE",
  228. icon: iconOperationPush,
  229. name:"推荐手术及操作"
  230. },
  231. generaTreatPush:{
  232. background: "#E3FEFE",
  233. icon: iconTreat,
  234. name:"一般治疗"
  235. },
  236. casewritingPush:{
  237. background: "#FFE8DD",
  238. icon: iconCaseWrite,
  239. name:"病历书写规范提示"
  240. }
  241. }
  242. const titleConfigH = {
  243. warning:{
  244. background: "#FFE8DD",
  245. icon: iconWarning1,
  246. name:"智能警示",
  247. location:"left"
  248. },
  249. symptomPush:{
  250. background: "#EEF5FD",
  251. icon: iconSymptomPush,
  252. name:"推荐症状",
  253. location:"left"
  254. },
  255. diagPush:{
  256. background: "#FAECED",
  257. icon: iconDiagPush,
  258. name:"智能诊断",
  259. location:"left"
  260. },
  261. checkupPush:{
  262. background: "#EEF5FD",
  263. icon: iconCheckupPush,
  264. name:"体格检查",
  265. location:"left"
  266. },
  267. scalePush:{
  268. background: "#EEF5FD",
  269. icon: iconScalePush,
  270. name:"推荐量表",
  271. location:"left"
  272. },
  273. lisPush:{
  274. background: "#ECF4FC",
  275. icon: iconLisPush,
  276. name:"推荐检验",
  277. location:"left"
  278. },
  279. pacsPush:{
  280. background: "#ECF4FC",
  281. icon: iconPacsPush,
  282. name:"推荐检查",
  283. location:"left"
  284. },
  285. generaTreatPush:{
  286. background: "#E3FEFE",
  287. icon: iconTreat,
  288. name:"一般治疗",
  289. location:"right"
  290. },
  291. drugPush:{
  292. background: "#E3FEFE",
  293. icon: iconDrugPush,
  294. name:"推荐用药",
  295. location:"right"
  296. },
  297. operationPush:{
  298. background: "#E3FEFE",
  299. icon: iconOperationPush,
  300. name:"手术/操作",
  301. location:"right"
  302. },
  303. nursePush: {
  304. background: "#E3FEFE",
  305. icon: iconNursePush,
  306. name: "推荐护理",
  307. location: "right"
  308. },
  309. vigilancePush:{
  310. background: "#FFE8DD",
  311. icon: iconWarning,
  312. name:"警惕",
  313. location:"left"
  314. },
  315. treat:{
  316. background: "#FFE8DD",
  317. icon: iconTreat,
  318. name:"治疗方案"
  319. },
  320. casewritingPush:{
  321. background: "#E3FEFE",
  322. icon: iconTreat,
  323. name:"病历书写规范提示",
  324. location:"left"
  325. }
  326. }
  327. const Toast = function (msg, duration) {
  328. duration = isNaN(duration) ? 3000 : duration;
  329. var m = document.createElement('div');
  330. m.innerHTML = msg;
  331. m.style.cssText = "max-width:60%;min-width: 150px;padding:0 14px;height: 40px;color: rgb(255, 255, 255);line-height: 40px;text-align: center;border-radius: 4px;position: fixed;top: 50%;left: 50%;transform: translate(-50%, -50%);z-index: 999999;background: rgba(0, 0, 0,.7);font-size: 16px;";
  332. document.body.appendChild(m);
  333. setTimeout(function () {
  334. var d = 0.5;
  335. m.style.webkitTransition = '-webkit-transform ' + d + 's ease-in, opacity ' + d + 's ease-in';
  336. m.style.opacity = '0';
  337. setTimeout(function () { document.body.removeChild(m) }, d * 1000);
  338. }, duration);
  339. }
  340. module.exports = {
  341. config,
  342. get,
  343. post,
  344. getUrlArgObject,
  345. imageUrlPrefix,
  346. throttle,
  347. openNewWin,
  348. isIe8,
  349. titleConfig,
  350. titleConfigH,
  351. Toast
  352. }