menu.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. var content_url = null;
  2. //发票计数器
  3. var countReceiot = 0;
  4. //跨页面传递患者id参数核酸检测
  5. var patientIdFullForNucleicAcid=null;
  6. $(function () {
  7. if (localStorage.getItem("token") == undefined) {
  8. window.location.href = '/thmz/login/view'
  9. }
  10. $.ajax({
  11. type: "GET",
  12. contentType: "application/json;charset=UTF-8",
  13. url: "/thmz/getUserName",
  14. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  15. success: function (result) {
  16. if (result == '401' || result == 401) {
  17. window.location.href = '/thmz/login/view'
  18. return;
  19. }
  20. if (result.code == 0) {
  21. $(".current_user").html(result.data.userName);
  22. }
  23. }
  24. });
  25. /**
  26. *初始化文件上传框
  27. */
  28. try {
  29. $("#mydropzone").dropzone({
  30. url: "/thmz/upload",
  31. headers: {
  32. 'Accept': 'application/json',
  33. 'Authorization': 'Bearer ' + localStorage.getItem("token"),
  34. 'fileType': localStorage.getItem("fileType")
  35. },
  36. init: function () {
  37. this.on("success", function (file, data) {
  38. if (data == '401' || data == 401) {
  39. window.location.href = '/thmz/login/view'
  40. return;
  41. }
  42. if (data.code == 0) {
  43. if (localStorage.getItem("fileType") == 0) {
  44. window.location.href = '/thmz/menu/view'
  45. }
  46. }
  47. });
  48. },
  49. });
  50. } catch (e) {
  51. console.error("出现一些未知错误")
  52. }
  53. imgFun("/thmz/download-profile", "headImage,headImage1,headImage2,headImage3,headImage4,headImage5");
  54. //构造当前用户的菜单树
  55. getCurrentUserMenu();
  56. //设置主页
  57. changeContent('/thmz/index');
  58. //$("#home").click();
  59. $(document).keyup(function (event) { //监听键盘按下时的事件
  60. //按F4进行页面切换
  61. if (event.keyCode == 115) {
  62. if (content_url == '/thmz/registration') {
  63. changeContent('/thmz/toll-administration');
  64. } else {
  65. changeContent('/thmz/registration');
  66. }
  67. return;
  68. }
  69. });
  70. postCMD("connect",localStorage.getItem("userID"),'000000','收费项目',0,0,0, '','祝您早日康复',0,0,0);
  71. });
  72. /**
  73. * 构造当前用户的菜单树
  74. */
  75. function getCurrentUserMenu() {
  76. $.ajax({
  77. type: "GET",
  78. url: '/thmz/getRoleMenuRelationForCurrentUser',
  79. dataType: "json",
  80. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  81. success: function (res) {
  82. if (res == '401' || res == 401) {
  83. window.location.href = '/thmz/login/view'
  84. return;
  85. }
  86. var html = "";
  87. for (var i = 0; i < res.data.length; i++) {
  88. var parentMenuVo = res.data[i];
  89. var parentMenu = parentMenuVo.menu;
  90. var menuList = parentMenuVo.menuList;
  91. if(parentMenu==null){
  92. continue;
  93. }
  94. if (parentMenu.menuUrl == null || parentMenu.menuUrl == "" || parentMenu.menuUrl.length == 0) {
  95. html += '<li><a><i class="' + parentMenu.classCode + '"></i>' + parentMenu.name;
  96. } else {
  97. html += '<li><a href="#" onclick="changeContent(\'' + parentMenu.menuUrl + '\')"><i class="' + parentMenu.classCode + '"></i>' + parentMenu.name;
  98. }
  99. if (menuList != null && menuList.length > 0) {
  100. html += '<span class="fa fa-chevron-down"></span></a><ul class="nav child_menu">';
  101. for (var j = 0; j < menuList.length; j++) {
  102. var childMenu = menuList[j];
  103. html += '<li><a href="#" onclick="changeContent(\'' + childMenu.menuUrl + '\')">' + childMenu.name + '</a></li>';
  104. }
  105. html += '</ul>';
  106. } else {
  107. html += '</a>';
  108. }
  109. html += '</li>';
  110. }
  111. $("#menuBaseNode").html(html);
  112. init_sidebar();
  113. initScroller();
  114. $MENU_TOGGLE.click();
  115. }
  116. });
  117. }
  118. function initScroller(){
  119. var menu = new IScroll('.menu_section',{
  120. mouseWheel: true,
  121. });
  122. }
  123. function loginOut() {
  124. if (localStorage.getItem("token") == undefined) {
  125. window.location.href = '/thmz/login/view'
  126. }
  127. $.ajax({
  128. type: "POST",
  129. contentType: "application/json;charset=UTF-8",
  130. url: "/thmz/login-out",
  131. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  132. success: function (result) {
  133. if (result == '401' || result == 401 || result.code == 0) {
  134. postCMD("logout",localStorage.getItem("userID"),'000000','收费项目',0,0,0, '','祝您早日康复',0,0,0);
  135. window.location.href = '/thmz/login/view'
  136. return;
  137. }
  138. }
  139. });
  140. }
  141. /**
  142. * 编辑个人信息
  143. */
  144. function editProfile() {
  145. NProgress.start();
  146. try {
  147. $('#reportrange').data('daterangepicker').remove();
  148. $("div.datetimepicker").remove();
  149. } catch (e) {
  150. console.log("不存在对应的日期选择器,无需销毁")
  151. }
  152. $("#profileimage").css("display", "none");
  153. $("#content").load("/thmz/html/profile.html");
  154. $.getScript('/thmz/js/profile.js');
  155. $.getScript('/thmz/js/message.js');
  156. NProgress.done();
  157. }
  158. /**
  159. * 密码修改
  160. */
  161. function editPassword() {
  162. NProgress.start();
  163. try {
  164. $('#reportrange').data('daterangepicker').remove();
  165. $("div.datetimepicker").remove();
  166. } catch (e) {
  167. console.log("不存在对应的日期选择器,无需销毁")
  168. }
  169. $("#profileimage").css("display", "none");
  170. $("#content").load("/thmz/html/password.html");
  171. $.getScript('/thmz/js/password.js');
  172. NProgress.done();
  173. }
  174. /**
  175. * 头像修改
  176. */
  177. function editProfileImage() {
  178. NProgress.start();
  179. try {
  180. $('#reportrange').data('daterangepicker').remove();
  181. $("div.datetimepicker").remove();
  182. } catch (e) {
  183. console.log("不存在对应的日期选择器,无需销毁")
  184. }
  185. $("#content").html("");
  186. $("#profileimage").css("display", "block");
  187. $("#mydropzone").css("display", "none");
  188. $(".x_content").append("<img id='headImage99'/>")
  189. imgFun("/thmz/download-profile", "headImage99");
  190. //设置文件类型为头像
  191. localStorage.setItem("fileType", "0");
  192. NProgress.done();
  193. }
  194. /**
  195. * 设置全屏:目前这个方法无法监听 ESC 键盘按键
  196. */
  197. $('#alarm-fullscreen-toggler').on('click', function (e) {
  198. var element = document.documentElement; // 返回 html dom 中的root 节点 <html>
  199. if (!$('body').hasClass('full-screen')) {
  200. $('body').addClass('full-screen');
  201. $('#alarm-fullscreen-toggler').addClass('active');
  202. // 判断浏览器设备类型
  203. if (element.requestFullscreen) {
  204. element.requestFullscreen();
  205. } else if (element.mozRequestFullScreen) { // 兼容火狐
  206. element.mozRequestFullScreen();
  207. } else if (element.webkitRequestFullscreen) { // 兼容谷歌
  208. element.webkitRequestFullscreen();
  209. } else if (element.msRequestFullscreen) { // 兼容IE
  210. element.msRequestFullscreen();
  211. }
  212. $(this).attr("data-original-title", "退出全屏");
  213. } else { // 退出全屏
  214. console.log(document);
  215. $('body').removeClass('full-screen');
  216. $('#alarm-fullscreen-toggler').removeClass('active');
  217. // 退出全屏
  218. if (document.exitFullscreen) {
  219. document.exitFullscreen();
  220. } else if (document.mozCancelFullScreen) {
  221. document.mozCancelFullScreen();
  222. } else if (document.webkitCancelFullScreen) {
  223. document.webkitCancelFullScreen();
  224. } else if (document.msExitFullscreen) {
  225. document.msExitFullscreen();
  226. }
  227. $(this).attr("data-original-title", "全屏");
  228. }
  229. });
  230. /**
  231. * 锁屏按钮点击事件
  232. */
  233. $("#lockScreen").on('click', function (t) {
  234. //默认10分钟不操作会锁屏
  235. fcode.Time = 600;
  236. fcode.customHtml = '<div style="margin-top:80px;"><img src="/thmz/images/img.jpg" style="width:70px;height:70px;border-radius:100px"><br><br></div>';
  237. fcode.bgImage = '/thmz/images/backgrounds/back5.jpg'; //设置背景图片,优先于背景颜色
  238. $.ajax({
  239. type: "POST",
  240. contentType: "application/json;charset=UTF-8",
  241. url: "/thmz/user-info",
  242. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  243. success: function (result) {
  244. if (result == '401' || result == 401) {
  245. window.location.href = '/thmz/login/view'
  246. return;
  247. }
  248. if (result.code == 0) {
  249. if (result.data.lockScreenPassword != null && result.data.lockScreenPassword != "") {
  250. fcode.bgImage = '/thmz/images/backgrounds/back6.jpg'; //设置背景图片,优先于背景颜色
  251. fcode.Start(result.data.lockScreenPassword);
  252. } else {
  253. fcode.Uppwd();
  254. }
  255. } else {
  256. errorMesage(result);
  257. }
  258. }
  259. });
  260. });
  261. /**
  262. * 下载远程的图片并加载到页面
  263. * @param url
  264. * @param imgs
  265. */
  266. function imgFun(url, imgs) {
  267. var windowUrl = window.URL || window.webkitURL;//处理浏览器兼容性
  268. var xhr = new XMLHttpRequest();
  269. xhr.open("GET", url, true);
  270. xhr.responseType = "blob";
  271. xhr.setRequestHeader("Authorization", 'Bearer ' + localStorage.getItem("token"));
  272. xhr.onload = function () {
  273. //console.log(this);
  274. if (this.status == 200) {
  275. var blob = this.response;
  276. var arr = imgs.split(",");
  277. for (var i = 0; i < arr.length; i++) {
  278. $("#" + arr[i]).load(function (e) {
  279. windowUrl.revokeObjectURL($("#" + arr[i]).src);
  280. }).attr("src", windowUrl.createObjectURL(blob));
  281. }
  282. }
  283. }
  284. xhr.send();
  285. }
  286. /**
  287. * 打开上传图片操纵框
  288. */
  289. function profileImage() {
  290. $("#mydropzone").css("display", "block");
  291. $("#profileImageTitleInfo").removeClass('hide').addClass('in');
  292. $("#headImage99").remove();
  293. }
  294. /**
  295. * 页面跳转
  296. */
  297. function changeContent(url) {
  298. var params = null;
  299. if(url.indexOf("?")>0){
  300. var realUrl=url.substring(0,url.indexOf("?"));
  301. params=url.substring(url.indexOf("?")+1);
  302. //跨页面传值
  303. if(params!=null && params!=""){
  304. patientIdFullForNucleicAcid=params;
  305. }
  306. url=realUrl;
  307. }
  308. //弹出框是构建再主页面的body,所以需要清空
  309. $(".webui-popover").remove();
  310. NProgress.start();
  311. try {
  312. $('#reportrange').data('daterangepicker').remove();
  313. $("div.datetimepicker").remove();
  314. } catch (e) {
  315. console.log("不存在对应的日期选择器,无需销毁")
  316. }
  317. $("#profileimage").css("display", "none");
  318. $.ajax({
  319. type: "GET",
  320. url: url,
  321. dataType: 'html',
  322. headers: {'Accept': 'application/json', 'Authorization': 'Bearer ' + localStorage.getItem("token")},
  323. success: function (result) {
  324. content_url = url;
  325. //打开发药叫号、配药、发药界面,先关闭历史socket连接
  326. if(url == '/thmz/pharmacy-cell-number' || url == '/thmz/west-pharmacy-send' || url == '/thmz/west-pharmacy-dispensing'){
  327. try{
  328. prescriptionPrintWebsocket.close();
  329. }catch(e){
  330. console.log("prescriptionPrintWebsocket连接关闭失败:"+e.message);
  331. }
  332. }
  333. $("#content").html(result);
  334. },
  335. error:function (jqXHR) {
  336. var responseText= JSON.parse(jqXHR.responseText);
  337. new PNotify({
  338. title: '错误提示',
  339. text: responseText.message,
  340. type: 'error',
  341. hide: false,
  342. styling: 'bootstrap3'
  343. });
  344. }
  345. });
  346. NProgress.done();
  347. }