main.component.ts 11 KB

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