util.js 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. const qs = require('qs');
  2. const $ = require("jquery");
  3. var Utils = require('./rePromise');
  4. //页面映射
  5. const pageMap={
  6. 'YH-KZT':'console.html',
  7. 'YH-KZTKS':'deptConsole.html',
  8. 'YH-JCSJWH-MKSJWH':'moduleManager.html',
  9. 'YH-JCSJWH-TMSJWH':'itemManager.html',
  10. 'YH-BLZK-ZKPF':'qcList.html',
  11. 'YH-BLZK-ZKPFKS':'qcListDept.html',
  12. 'YH-BLZK-ZKPFGR':'qcListPerson.html',
  13. 'YH-TJFX':'statistics.html',
  14. 'YH-QXGL-YHGL':'userManager.html',
  15. 'YH-QXGL-JSGL':'roleManager.html',
  16. };
  17. const api={
  18. getMenu:'/sys/user/getUserOrgMenu', //获取菜单
  19. midifyPassword:'/sys/user/midifyPassword', //修改密码
  20. getSubMenu:'/qc/mode/getMenu', //获取质控评分菜单
  21. delScore:'/qc/behospitalInfo/delCase' ,//删除评分项
  22. editScore:'/qc/behospitalInfo/updCase' ,//修改评分
  23. addScore:'/qc/behospitalInfo/addCase' ,//添加评分项
  24. getRecordDetail:'/qc/behospitalInfo/getByBehospitalCode', //获取病例明细
  25. getInfoModule:'/qc/module/getById',
  26. getModuleById:'/qc/module/getModuleMap'
  27. };
  28. //重写assign方法
  29. if (typeof Object.assign != 'function') {
  30. Object.assign = function (target) {
  31. 'use strict';
  32. if (target == null) {
  33. throw new TypeError('Cannot convert undefined or null to object');
  34. }
  35. target = Object(target);
  36. for (var index = 1; index < arguments.length; index++) {
  37. var source = arguments[index];
  38. if (source != null) {
  39. for (var key in source) {
  40. if (Object.prototype.hasOwnProperty.call(source, key)) {
  41. target[key] = source[key];
  42. }
  43. }
  44. }
  45. }
  46. return target;
  47. };
  48. }
  49. window.console = window.console || (function () {
  50. var c = {}; c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile
  51. = c.clear = c.exception = c.trace = c.assert = function () { };
  52. return c;
  53. })();
  54. const getUrlArgObject = function getQueryString(name) {
  55. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
  56. var reg_rewrite = new RegExp("(^|/)" + name + "/([^/]*)(/|$)", "i");
  57. var r = window.location.search.substr(1).match(reg);
  58. var q = window.location.pathname.substr(1).match(reg_rewrite);
  59. if (r != null) {
  60. return decodeURIComponent(r[2]);
  61. } else if (q != null) {
  62. return decodeURIComponent(q[2]);
  63. } else {
  64. return null;
  65. }
  66. }
  67. const post = function (url, data) {
  68. // if(!token&&window.location.href.indexOf('login')==-1){
  69. // window.location.href = "../login.html"
  70. // }
  71. return new Utils((resolve, reject) => {
  72. $.ajax({
  73. method: 'post',
  74. url: url,
  75. data: JSON.stringify(data),
  76. contentType: "application/json; charset=UTF-8",
  77. beforeSend: function (xmlHttp) {
  78. xmlHttp.setRequestHeader("If-Modified-Since", "0");
  79. xmlHttp.setRequestHeader("Cache-Control", "no-cache");
  80. //xmlHttp.setRequestHeader("Authorization",'')
  81. },
  82. success: function (res) {
  83. resolve({ data: res });
  84. },
  85. error: function (error) {
  86. // if(error.status===403||error.status===401){
  87. // const wd = window.parent.window||window;
  88. // wd.location.href = "../login.html";
  89. // }
  90. reject(error);
  91. },
  92. });
  93. });
  94. }
  95. //判断浏览器是否为Ie8
  96. const isIe8 = function () {
  97. var DEFAULT_VERSION = 8.0;
  98. var ua = navigator.userAgent.toLowerCase();
  99. var isIE = ua.indexOf("msie") > -1;
  100. var safariVersion;
  101. if (isIE) {
  102. safariVersion = ua.match(/msie ([\d.]+)/)[1];
  103. }
  104. if (safariVersion <= DEFAULT_VERSION) {
  105. return true
  106. }
  107. }
  108. const setCookie = function(name,value){
  109. let Days = 30;
  110. let exp = new Date();
  111. exp.setTime(exp.getTime() + Days*24*60*60*1000);
  112. document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString();
  113. }
  114. //读取cookies
  115. const getCookie =function(name){
  116. let arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
  117. if(arr=document.cookie.match(reg))
  118. return unescape(arr[2]);
  119. else
  120. return null;
  121. }
  122. //删除cookies
  123. const delCookie = function(name){
  124. let exp = new Date();
  125. exp.setTime(exp.getTime() - 1);
  126. let cval=getCookie(name);
  127. if(cval!=null)
  128. document.cookie= name + "="+cval+";expires="+exp.toGMTString();
  129. };
  130. //弹窗关闭事件
  131. $(".modal .close").click(function(){
  132. $(".modal").hide();
  133. });
  134. //计算容器高度
  135. function setBoxHeight(){
  136. const ht=window.innerHeight;
  137. $(".main-part").height((ht-60)+'px');
  138. $(".content-ht").height((ht-126)+"px");
  139. }
  140. setBoxHeight();
  141. $(window).resize(function(){
  142. setBoxHeight();
  143. });
  144. //判断有无某一权限
  145. function hasData(data){
  146. let lis = JSON.parse(getCookie("codeLis"))
  147. if(lis.indexOf(data)>-1){//有权限
  148. return true
  149. }
  150. return false;
  151. }
  152. module.exports = {
  153. pageMap,
  154. api,
  155. post,
  156. getUrlArgObject,
  157. isIe8,
  158. setCookie,
  159. getCookie,
  160. delCookie,
  161. setBoxHeight,
  162. hasData
  163. };