main.component.ts 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426
  1. import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core";
  2. import { NavigationEnd, Router } from "@angular/router";
  3. import { MainService } from "../../services/main.service";
  4. import { NzMessageService } from "ng-zorro-antd/message";
  5. import { WebsocketMainService } from "../../services/websocket-main.service";
  6. import http from "../../../assets/js/http";
  7. import { NzNotificationService } from "ng-zorro-antd/notification";
  8. import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
  9. import { ToolService } from "../../services/tool.service";
  10. import { filter } from "rxjs/operators";
  11. @Component({
  12. selector: "app-main",
  13. templateUrl: "./main.component.html",
  14. styleUrls: ["./main.component.less"],
  15. })
  16. export class MainComponent implements OnInit {
  17. userInfo: any = JSON.parse(localStorage.getItem("user"));
  18. menus: any = JSON.parse(localStorage.getItem("menu"));
  19. currentHospital; //当前院区
  20. routerEventsListener; //监听路由
  21. deskRole: boolean = false; //调度台权限
  22. nurseRole: boolean = false; //护士端权限
  23. pharmacyRole: boolean = false; //药房端权限
  24. largeScreenRole: boolean = false; //大屏端权限
  25. largeScreenRole2: boolean = false; //大屏端权限
  26. specimenViewRole: boolean = false; //业务视图权限
  27. @ViewChild("osComponentRef1", {
  28. read: OverlayScrollbarsComponent,
  29. static: false,
  30. })
  31. osComponentRef1: OverlayScrollbarsComponent;
  32. constructor(
  33. public router: Router,
  34. private mainService: MainService,
  35. private msg: NzMessageService,
  36. private notification: NzNotificationService,
  37. private webs: WebsocketMainService,
  38. private tool: ToolService
  39. ) {}
  40. ngOnInit() {
  41. this.highlightMenuByUrl();
  42. this.routerEventsListener = this.router.events
  43. .pipe(filter((event) => event instanceof NavigationEnd))
  44. .subscribe((event) => {
  45. this.highlightMenuByUrl();
  46. });
  47. this.currentHospital = this.tool.getCurrentHospital();
  48. this.initLogin();
  49. this.initMenu();
  50. this.getWebsocket();
  51. }
  52. // 离开管理端
  53. ngOnDestroy() {
  54. //取消路由监听
  55. this.routerEventsListener.unsubscribe();
  56. // 断掉连接
  57. this.webs.closeWs(true);
  58. }
  59. // 根据url高亮菜单baba
  60. highlightMenuByUrl() {
  61. console.log(this.router.url);
  62. let navOne, navTwo;
  63. let link = this.router.url.split("/").slice(-1)[0];
  64. let menus = JSON.parse(localStorage.getItem("menu"));
  65. if (link == "home") {
  66. this.toMenu("首页");
  67. } else {
  68. menus.forEach((oneNav) => {
  69. if (oneNav.childrens) {
  70. let findTwoNav = oneNav.childrens.find(
  71. (twoNav) => twoNav.link == link
  72. );
  73. if (findTwoNav) {
  74. navTwo = findTwoNav;
  75. navOne = oneNav;
  76. this.toMenu(navTwo.title, navTwo, navOne);
  77. }
  78. }
  79. });
  80. }
  81. }
  82. // 一级导航点击
  83. clickMenuOne(data) {
  84. let menus = JSON.parse(localStorage.getItem("menu"));
  85. data.flag = !data.flag;
  86. menus.find((item) => item.id == data.id).flag = data.flag;
  87. localStorage.setItem("menu", JSON.stringify(menus));
  88. }
  89. initMenu() {
  90. let menus = JSON.parse(localStorage.getItem("menu"));
  91. let arr = [];
  92. menus.forEach((e) => {
  93. if (e.link == "nurse") {
  94. this.nurseRole = true;
  95. console.log("护士端权限");
  96. }
  97. if (e.link == "dispatchingDesk") {
  98. this.deskRole = true;
  99. console.log("调度台权限");
  100. }
  101. if (e.link == "pharmacy") {
  102. this.pharmacyRole = true;
  103. console.log("药房端权限");
  104. }
  105. if (e.link == "largeScreen") {
  106. this.largeScreenRole = true;
  107. console.log("大屏端权限");
  108. }
  109. if (e.link == "largeScreen2") {
  110. this.largeScreenRole2 = true;
  111. console.log("大屏端2权限");
  112. }
  113. if (e.link == "specimenView") {
  114. this.specimenViewRole = true;
  115. console.log("业务视图权限");
  116. }
  117. if (!e.link) {
  118. arr.push(e);
  119. }
  120. });
  121. this.menus = arr;
  122. }
  123. // 判断登录是否已失效
  124. initLogin() {
  125. if (!this.userInfo) {
  126. this.msg.error("您的登录已失效,请重新登录!", {
  127. nzDuration: 3000,
  128. });
  129. setTimeout(() => {
  130. this.router.navigateByUrl("login");
  131. }, 2000);
  132. return;
  133. }
  134. }
  135. // 跳转页面
  136. menuLabel: string; //当前菜单名称
  137. indexFlag = localStorage.getItem("index") === "true" ? true : false; //首页高亮
  138. toMenu(title, item?, data?) {
  139. sessionStorage.setItem("title", title);
  140. this.menuLabel = sessionStorage.getItem("title");
  141. if (item && data) {
  142. // 首页取消高亮
  143. this.indexFlag = false;
  144. localStorage.setItem("index", "false");
  145. // 操作本地存储
  146. let menus = JSON.parse(localStorage.getItem("menu"));
  147. menus.forEach((item1) => {
  148. item1.flagBg = false;
  149. if (item1.childrens) {
  150. item1.childrens.forEach((value) => {
  151. value.flag = false;
  152. });
  153. }
  154. });
  155. let obj = menus.find((value) => value.id == data.id);
  156. obj.flagBg = true;
  157. obj.flag = true;
  158. obj.childrens.find((value) => value.id == item.id).flag = true;
  159. localStorage.setItem("menu", JSON.stringify(menus));
  160. // 操作菜单一级 二级
  161. this.menus = menus.filter((item) => !item.link);
  162. } else {
  163. // 首页高亮
  164. this.indexFlag = true;
  165. localStorage.setItem("index", "true");
  166. // 操作本地存储
  167. let menus = JSON.parse(localStorage.getItem("menu"));
  168. menus.forEach((item1) => {
  169. item1.flagBg = false;
  170. // item1.flag = false;
  171. if (item1.childrens) {
  172. item1.childrens.forEach((value) => {
  173. value.flag = false;
  174. });
  175. }
  176. });
  177. localStorage.setItem("menu", JSON.stringify(menus));
  178. // 操作菜单一级 二级
  179. this.menus = menus.filter((item) => !item.link);
  180. }
  181. }
  182. // 子路由跳转事件
  183. activeRoute() {
  184. this.menuLabel = sessionStorage.getItem("title");
  185. }
  186. // 调度台
  187. toFuwutai(): void {
  188. this.router.navigateByUrl("dispatchingDesk");
  189. }
  190. // 护士建单
  191. toHuShi(): void {
  192. this.router.navigateByUrl("nurse");
  193. }
  194. // 药房端
  195. toPharmacy(): void {
  196. this.router.navigateByUrl("pharmacy");
  197. }
  198. // 药房端2
  199. toPharmacy2(): void {
  200. this.router.navigateByUrl("pharmacy2");
  201. }
  202. // 大屏端或视图端
  203. screenType;
  204. hosFlag = false;
  205. toBigScreen(type): void {
  206. this.screenType = type;
  207. this.submitFormHand(this.currentHospital.id);
  208. }
  209. submitFormHand(id) {
  210. if (this.screenType === "largeScreen") {
  211. window.open(http.bigScreenHost + "/#/" + id);
  212. } else if (this.screenType === "largeScreen2") {
  213. window.open(http.bigScreenHost2 + "/#/" + id);
  214. } else if (this.screenType === "specimenView") {
  215. let remember = JSON.parse(localStorage.getItem("remember"));
  216. window.open(
  217. http.specimenViewHost +
  218. "/#/" +
  219. id +
  220. "/" +
  221. encodeURIComponent(remember.username) +
  222. "/" +
  223. encodeURIComponent(remember.password)
  224. );
  225. }
  226. }
  227. //获取系统设置中的科室类型
  228. deptTypeLoading = false;
  229. getTypeByDept(id) {
  230. let postData = {
  231. idx: 0,
  232. sum: 1,
  233. systemConfiguration: { keyconfig: "busiViewDeptId" },
  234. };
  235. this.deptTypeLoading = true;
  236. this.mainService
  237. .getFetchDataList("simple/data", "systemConfiguration", postData)
  238. .subscribe((result) => {
  239. this.deptTypeLoading = false;
  240. if (result.status == 200) {
  241. let remember = JSON.parse(localStorage.getItem("remember"));
  242. window.open(
  243. http.specimenViewHost +
  244. "/#/" +
  245. id +
  246. "/" +
  247. encodeURIComponent(remember.username) +
  248. "/" +
  249. encodeURIComponent(remember.password) +
  250. "/" +
  251. result.list[0].valueconfig
  252. );
  253. }
  254. });
  255. }
  256. hosFlagHand(flag) {
  257. if (!flag) {
  258. this.hosFlag = false;
  259. }
  260. }
  261. // 退出
  262. logOut(): void {
  263. // 假退出
  264. localStorage.removeItem("user");
  265. localStorage.removeItem("menu");
  266. localStorage.removeItem("phones");
  267. localStorage.removeItem("index");
  268. this.router.navigateByUrl("login");
  269. // 假退出
  270. this.mainService.logOut().subscribe((data) => {
  271. if (data.status == 200) {
  272. localStorage.removeItem("user");
  273. localStorage.removeItem("menu");
  274. localStorage.removeItem("phones");
  275. localStorage.removeItem("index");
  276. this.router.navigateByUrl("login");
  277. }
  278. });
  279. }
  280. // 连接websocket
  281. getWebsocket() {
  282. this.webs
  283. .connectWs(http.mainWs, { userCount: this.userInfo.user.account })
  284. .subscribe((data) => {
  285. console.log(data);
  286. if (data && data.content) {
  287. this.createBasicNotification(data);
  288. }
  289. });
  290. }
  291. @ViewChild("msgTemplate1", { static: false }) msgTemplate1: TemplateRef<any>; //消息通知模板
  292. // 消息提醒
  293. createBasicNotification(msgs): void {
  294. this.notification.template(this.msgTemplate1, {
  295. nzDuration: 0,
  296. nzData: msgs,
  297. });
  298. }
  299. // 修改密码
  300. passwordVisible = false;
  301. password?: string;
  302. isPwdVisible = false;
  303. pwdIsOkLoading = false;
  304. upModalData = {
  305. userid: "",
  306. pwdOld: "",
  307. newPwd: "",
  308. newPwd2: "",
  309. };
  310. upPwd(): void {
  311. let userid = JSON.parse(localStorage.getItem("user")).user.id;
  312. this.upModalData.userid = userid;
  313. this.mainService.upPwd(this.upModalData).subscribe((data) => {
  314. if (data.status == 200) {
  315. this.isPwdVisible = false;
  316. this.pwdIsOkLoading = false;
  317. this.msg.success("修改成功!", {
  318. nzDuration: 5000,
  319. });
  320. } else {
  321. this.pwdIsOkLoading = false;
  322. this.msg.error(data.error, {
  323. nzDuration: 5000,
  324. });
  325. }
  326. });
  327. }
  328. showUpPwd(): void {
  329. this.isPwdVisible = true;
  330. }
  331. pwdHandleOk(): void {
  332. this.pwdIsOkLoading = true;
  333. this.upPwd();
  334. }
  335. pwdHandleCancel(): void {
  336. this.isPwdVisible = false;
  337. }
  338. delModal = false;
  339. tipsMsg1 = "是否确定离开该界面,如果未点击生效,数据可能会遗失?";
  340. navInfo = {};
  341. // 隐藏模态框
  342. hideDelModal() {
  343. this.delModal = false;
  344. }
  345. // 模态框确认
  346. confirmDel() {
  347. this.delModal = false;
  348. if (this.navInfo["title"] == "首页") {
  349. this.router.navigateByUrl("/main/home");
  350. this.toMenu("首页");
  351. } else {
  352. this.router.navigateByUrl("/main/" + this.navInfo["item"].link);
  353. this.toMenu(
  354. this.navInfo["title"],
  355. this.navInfo["item"],
  356. this.navInfo["data"]
  357. );
  358. }
  359. }
  360. //前往菜单连接(拦截版)
  361. totoMenu(title, item?, data?) {
  362. let url = location.href.split("#")[1];
  363. if (url.includes("/main/quickCombination")) {
  364. //拦截
  365. this.delModal = true;
  366. this.navInfo = {
  367. title,
  368. item,
  369. data,
  370. };
  371. } else {
  372. //正常情况
  373. if (title == "首页") {
  374. this.router.navigateByUrl("/main/home");
  375. this.toMenu("首页");
  376. } else {
  377. this.router.navigateByUrl("/main/" + item.link);
  378. this.toMenu(title, item, data);
  379. }
  380. }
  381. }
  382. // 切换院区
  383. maskFlag: any = false;
  384. hosFlag1 = false;
  385. submitFormHand1(id) {
  386. this.maskFlag = this.msg.loading("正在加载中..", {
  387. nzDuration: 0,
  388. }).messageId;
  389. this.mainService
  390. .changeHospital({ currentHosId: +id, loginType: "PC" })
  391. .subscribe((result) => {
  392. this.msg.remove(this.maskFlag);
  393. this.maskFlag = false;
  394. if (result.status == 200) {
  395. localStorage.setItem("user", JSON.stringify(result.user));
  396. location.reload(true);
  397. } else {
  398. this.msg.create("error", "切换院区失败");
  399. }
  400. });
  401. }
  402. hosFlagHand1(flag) {
  403. if (!flag) {
  404. this.hosFlag1 = false;
  405. }
  406. }
  407. }