menu.js 13 KB

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