main.component.ts 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  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. specimenViewRole2: boolean = false; //标本视图权限
  28. disinfectionSupplyRole: boolean = false; //全局业务查看权限
  29. PCCommutesToWork: boolean = false; //PC上下班权限
  30. @ViewChild("osComponentRef1", {
  31. read: OverlayScrollbarsComponent,
  32. static: false,
  33. })
  34. osComponentRef1: OverlayScrollbarsComponent;
  35. constructor(
  36. public router: Router,
  37. private mainService: MainService,
  38. private msg: NzMessageService,
  39. private notification: NzNotificationService,
  40. private webs: WebsocketMainService,
  41. public tool: ToolService
  42. ) {}
  43. ngOnInit() {
  44. this.highlightMenuByUrl();
  45. this.routerEventsListener = this.router.events
  46. .pipe(filter((event) => event instanceof NavigationEnd))
  47. .subscribe((event) => {
  48. this.highlightMenuByUrl();
  49. });
  50. this.currentHospital = this.tool.getCurrentHospital();
  51. this.initLogin();
  52. this.initMenu();
  53. this.getWebsocket();
  54. }
  55. // 离开管理端
  56. ngOnDestroy() {
  57. //取消路由监听
  58. this.routerEventsListener.unsubscribe();
  59. // 断掉连接
  60. this.webs.closeWs(true);
  61. }
  62. //上下班
  63. loading3 = false;
  64. workModal: boolean = false; //模态框
  65. showWorkModal() {
  66. this.workModal = true;
  67. }
  68. hideWorkModal() {
  69. this.workModal = false;
  70. }
  71. confirmWork() {
  72. this.loading3 = true;
  73. if (this.userInfo.user.online) {
  74. // 判断当前启用的工作方案是自主还是综合排班
  75. this.getUserWorkDept().then((ress:any) => {
  76. if (ress.status == 200) {
  77. let workType = ress.settings ? ress.settings.workType : -1; //1是综合,2是自主
  78. // 自主下班,并且是科室绑定人员,科室绑定分组,绑定分组
  79. if (workType == 2) {
  80. this.loading3 = false;
  81. this.msg.info('不支持此上班模式!');
  82. } else {
  83. this.mainService.onOrOffLine({
  84. type: "off",
  85. }).subscribe((res:any) => {
  86. if (res.status == 200) {
  87. this.getCurrentUserNow();
  88. } else {
  89. this.loading3 = false;
  90. this.msg.error('操作失败');
  91. }
  92. });
  93. }
  94. } else if (ress.status == 500) {
  95. //500的时候自选下班
  96. this.customOff();
  97. } else {
  98. this.loading3 = false;
  99. this.msg.error('操作失败');
  100. }
  101. });
  102. } else {
  103. this.getWorkScheme();
  104. }
  105. }
  106. // 获取启动中的工作分配方案
  107. workSchemeType:any = ""; //启动中工作分配方案类型
  108. getWorkScheme() {
  109. let postData = {
  110. idx: 0,
  111. workScheme: {
  112. status: 1,
  113. hosId: this.currentHospital.id
  114. },
  115. sum: 1,
  116. };
  117. this.mainService.getFetchDataList("simple/data", "workScheme", postData).subscribe((res) => {
  118. if (res.status == 200) {
  119. if(Array.isArray(res.list) && res.list.length){
  120. this.workSchemeType = res.list[0].workType;
  121. if (this.workSchemeType == 2) {
  122. this.loading3 = false;
  123. this.msg.info('不支持此上班模式!');
  124. } else if (this.workSchemeType == 1) {
  125. this.mainService.onOrOffLine({
  126. type: "on",
  127. }).subscribe((res:any) => {
  128. if (res.status == 200) {
  129. this.getCurrentUserNow();
  130. } else {
  131. this.loading3 = false;
  132. this.msg.error('操作失败');
  133. }
  134. });
  135. }
  136. }
  137. } else {
  138. this.loading3 = false;
  139. this.msg.error('操作失败');
  140. }
  141. });
  142. }
  143. // 下班
  144. customOff() {
  145. this.mainService.onOrOffLine({
  146. type: "off",
  147. customWorking: "off",
  148. }).subscribe((res:any) => {
  149. if (res.status == 200) {
  150. this.getCurrentUserNow();
  151. } else {
  152. this.loading3 = false;
  153. this.msg.error('操作失败');
  154. }
  155. });
  156. }
  157. // 获取执行中列表
  158. getWorkingNum() {
  159. return this.mainService.coopWorkerOrder("executingOrders", {
  160. idx: 0,
  161. sum: 1,
  162. }).toPromise();
  163. }
  164. // 获取启动中的工作分配方案
  165. getUserWorkDept() {
  166. return this.mainService.getUserWorkDept({}).toPromise();
  167. }
  168. // 获取当前用户信息
  169. getCurrentUserNow() {
  170. this.mainService.getCurrentUser1().subscribe((data:any) => {
  171. this.loading3 = false;
  172. if (data.status == 200) {
  173. let user = JSON.parse(localStorage.getItem("user"));
  174. user.user = data.data;
  175. this.userInfo.user = data.data;
  176. localStorage.setItem("user", JSON.stringify(user));
  177. this.hideWorkModal();
  178. this.msg.success('操作成功!');
  179. }
  180. });
  181. }
  182. // 上下班
  183. types = "";
  184. async GoWork() {
  185. let workingNum = 0;
  186. if (this.userInfo.user.online) {
  187. this.maskFlag = this.msg.loading("正在加载中..", {
  188. nzDuration: 0,
  189. }).messageId;
  190. let workingNumResult = await this.getWorkingNum();
  191. this.msg.remove(this.maskFlag);
  192. this.maskFlag = false;
  193. if (workingNumResult.status == 200) {
  194. workingNum = workingNumResult.data.data.length;
  195. }
  196. if (workingNum) {
  197. this.types = "您还<b style='color:red'>有未完成的工单</b>,确定下班后,<b style='color:red'>未完成工单将不计算积分。</b>";
  198. } else {
  199. this.types = "确定是否下班 ?";
  200. }
  201. } else {
  202. this.types = "确定是否上班 ?";
  203. }
  204. this.showWorkModal();
  205. }
  206. // 根据url高亮菜单baba
  207. highlightMenuByUrl() {
  208. console.log(this.router.url);
  209. let navOne, navTwo;
  210. let link = this.router.url.split("/").slice(-1)[0];
  211. let menus = JSON.parse(localStorage.getItem("menu"));
  212. if (link == "home") {
  213. this.toMenu("首页");
  214. } else {
  215. menus.forEach((oneNav) => {
  216. if (oneNav.childrens) {
  217. let findTwoNav = oneNav.childrens.find(
  218. (twoNav) => twoNav.link == link
  219. );
  220. if (findTwoNav) {
  221. navTwo = findTwoNav;
  222. navOne = oneNav;
  223. this.toMenu(navTwo.title, navTwo, navOne);
  224. }
  225. }
  226. });
  227. }
  228. }
  229. // 一级导航点击
  230. clickMenuOne(data) {
  231. let menus = JSON.parse(localStorage.getItem("menu"));
  232. data.flag = !data.flag;
  233. menus.find((item) => item.id == data.id).flag = data.flag;
  234. localStorage.setItem("menu", JSON.stringify(menus));
  235. }
  236. initMenu() {
  237. let menus = JSON.parse(localStorage.getItem("menu"));
  238. let arr = [];
  239. menus.forEach((e) => {
  240. if (e.link == "nurse") {
  241. this.nurseRole = true;
  242. console.log("护士端权限");
  243. }
  244. if (e.link == "dispatchingDesk") {
  245. this.deskRole = true;
  246. console.log("调度台权限");
  247. }
  248. if (e.link == "pharmacy") {
  249. this.pharmacyRole = true;
  250. console.log("药房端权限");
  251. }
  252. if (e.link == "largeScreen") {
  253. this.largeScreenRole = true;
  254. console.log("大屏端权限");
  255. }
  256. if (e.link == "largeScreen2") {
  257. this.largeScreenRole2 = true;
  258. console.log("大屏端2权限");
  259. }
  260. if (e.link == "specimenView") {
  261. this.specimenViewRole = true;
  262. console.log("业务视图权限");
  263. }
  264. if (e.link == "specimenView2") {
  265. this.specimenViewRole2 = true;
  266. console.log("标本视图权限");
  267. }
  268. if (e.link == "disinfectionSupply") {
  269. this.disinfectionSupplyRole = true;
  270. console.log("全局业务查看权限");
  271. }
  272. if (e.link == "PCCommutesToWork") {
  273. this.PCCommutesToWork = true;
  274. console.log("PC上下班");
  275. }
  276. if (!e.link) {
  277. arr.push(e);
  278. }
  279. });
  280. this.menus = arr;
  281. }
  282. // 判断登录是否已失效
  283. initLogin() {
  284. if (!this.userInfo) {
  285. this.msg.error("您的登录已失效,请重新登录!", {
  286. nzDuration: 3000,
  287. });
  288. setTimeout(() => {
  289. this.router.navigateByUrl("login");
  290. }, 2000);
  291. return;
  292. }
  293. }
  294. // 新密码失去焦点
  295. enoughRegFlag = true; //弱
  296. mediumRegFlag = false; //中
  297. strongRegFlag = false; //强
  298. blurNewPwd(){
  299. let enoughReg = /^.{0,6}$/;//密码强度-弱
  300. let strongReg = /^(?=.*[a-z])(?=.*[A-Z])(?=.*\d)(?=.*[\!\@\#\$\%\^\&\*]).{9,}$/;//密码强度-强
  301. this.enoughRegFlag = enoughReg.test(this.upModalData.newPwd);
  302. this.strongRegFlag = strongReg.test(this.upModalData.newPwd);
  303. this.mediumRegFlag = !this.enoughRegFlag && !this.strongRegFlag;
  304. console.log(this.enoughRegFlag,this.mediumRegFlag,this.strongRegFlag);
  305. }
  306. // 跳转页面
  307. menuLabel: string; //当前菜单名称
  308. indexFlag = localStorage.getItem("index") === "true" ? true : false; //首页高亮
  309. toMenu(title, item?, data?) {
  310. sessionStorage.setItem("title", title);
  311. this.menuLabel = sessionStorage.getItem("title");
  312. if (item && data) {
  313. // 首页取消高亮
  314. this.indexFlag = false;
  315. localStorage.setItem("index", "false");
  316. // 操作本地存储
  317. let menus = JSON.parse(localStorage.getItem("menu"));
  318. menus.forEach((item1) => {
  319. item1.flagBg = false;
  320. if (item1.childrens) {
  321. item1.childrens.forEach((value) => {
  322. value.flag = false;
  323. });
  324. }
  325. });
  326. let obj = menus.find((value) => value.id == data.id);
  327. obj.flagBg = true;
  328. obj.flag = true;
  329. obj.childrens.find((value) => value.id == item.id).flag = true;
  330. localStorage.setItem("menu", JSON.stringify(menus));
  331. // 操作菜单一级 二级
  332. this.menus = menus.filter((item) => !item.link);
  333. } else {
  334. // 首页高亮
  335. this.indexFlag = true;
  336. localStorage.setItem("index", "true");
  337. // 操作本地存储
  338. let menus = JSON.parse(localStorage.getItem("menu"));
  339. menus.forEach((item1) => {
  340. item1.flagBg = false;
  341. // item1.flag = false;
  342. if (item1.childrens) {
  343. item1.childrens.forEach((value) => {
  344. value.flag = false;
  345. });
  346. }
  347. });
  348. localStorage.setItem("menu", JSON.stringify(menus));
  349. // 操作菜单一级 二级
  350. this.menus = menus.filter((item) => !item.link);
  351. }
  352. }
  353. // 子路由跳转事件
  354. activeRoute() {
  355. this.menuLabel = sessionStorage.getItem("title");
  356. }
  357. // 调度台
  358. toFuwutai(): void {
  359. this.router.navigateByUrl("dispatchingDesk");
  360. }
  361. // 护士建单
  362. toHuShi(): void {
  363. this.router.navigateByUrl("nurse");
  364. }
  365. // 药房端
  366. toPharmacy(): void {
  367. this.router.navigateByUrl("pharmacy");
  368. }
  369. // 药房端2
  370. toPharmacy2(): void {
  371. this.router.navigateByUrl("pharmacy2");
  372. }
  373. // 标本视图
  374. toSpecimenView2(): void {
  375. this.router.navigateByUrl("specimenView2");
  376. }
  377. // 全局业务查看
  378. toDisinfectionSupply(): void {
  379. this.router.navigateByUrl("disinfectionSupply");
  380. }
  381. // 大屏端或视图端
  382. screenType;
  383. hosFlag = false;
  384. toBigScreen(type): void {
  385. this.screenType = type;
  386. this.submitFormHand(this.currentHospital.id);
  387. }
  388. submitFormHand(id) {
  389. if (this.screenType === "largeScreen") {
  390. window.open(http.bigScreenHost + "/#/" + id);
  391. } else if (this.screenType === "largeScreen2") {
  392. window.open(http.bigScreenHost2 + "/#/" + id);
  393. } else if (this.screenType === "specimenView") {
  394. window.open(http.specimenViewHost + "/#/" + id);
  395. }
  396. }
  397. //获取系统设置中的科室类型
  398. deptTypeLoading = false;
  399. getTypeByDept(id) {
  400. let postData = {
  401. idx: 0,
  402. sum: 1,
  403. systemConfiguration: { keyconfig: "busiViewDeptId" },
  404. };
  405. this.deptTypeLoading = true;
  406. this.mainService
  407. .getFetchDataList("simple/data", "systemConfiguration", postData)
  408. .subscribe((result) => {
  409. this.deptTypeLoading = false;
  410. if (result.status == 200) {
  411. let remember = JSON.parse(localStorage.getItem("remember"));
  412. window.open(
  413. http.specimenViewHost +
  414. "/#/" +
  415. id +
  416. "/" +
  417. encodeURIComponent(remember.username) +
  418. "/" +
  419. encodeURIComponent(remember.password) +
  420. "/" +
  421. result.list[0].valueconfig
  422. );
  423. }
  424. });
  425. }
  426. hosFlagHand(flag) {
  427. if (!flag) {
  428. this.hosFlag = false;
  429. }
  430. }
  431. // 退出
  432. logOut(): void {
  433. // 假退出
  434. let hospital = this.tool.getCurrentHospital();
  435. if(hospital){
  436. this.router.navigate(["login", hospital.id]);
  437. }else{
  438. this.router.navigateByUrl("login");
  439. }
  440. localStorage.removeItem("user");
  441. localStorage.removeItem("menu");
  442. localStorage.removeItem("phones");
  443. localStorage.removeItem("index");
  444. // 假退出
  445. this.mainService.logOut().subscribe((data) => {
  446. if (data.status == 200) {
  447. if(hospital){
  448. this.router.navigate(["login", hospital.id]);
  449. }else{
  450. this.router.navigateByUrl("login");
  451. }
  452. localStorage.removeItem("user");
  453. localStorage.removeItem("menu");
  454. localStorage.removeItem("phones");
  455. localStorage.removeItem("index");
  456. }
  457. });
  458. }
  459. // 连接websocket
  460. getWebsocket() {
  461. this.webs
  462. .connectWs(http.mainWs, { userCount: this.userInfo.user.account })
  463. .subscribe((data) => {
  464. console.log(data);
  465. if (data && data.content) {
  466. this.createBasicNotification(data);
  467. }
  468. });
  469. }
  470. @ViewChild("msgTemplate1", { static: false }) msgTemplate1: TemplateRef<any>; //消息通知模板
  471. // 消息提醒
  472. createBasicNotification(msgs): void {
  473. this.notification.template(this.msgTemplate1, {
  474. nzDuration: 0,
  475. nzData: msgs,
  476. });
  477. }
  478. //打开修改密码弹窗
  479. pwdAfterOpen(){
  480. this.passwordVisible = false;
  481. this.pwdIsOkLoading = false;
  482. this.enoughRegFlag = true; //弱
  483. this.mediumRegFlag = false; //中
  484. this.strongRegFlag = false; //强
  485. this.upModalData = {
  486. userid: "",
  487. pwdOld: "",
  488. newPwd: "",
  489. newPwd2: "",
  490. };
  491. }
  492. // 修改密码
  493. passwordVisible = false;
  494. password?: string;
  495. isPwdVisible = false;
  496. pwdIsOkLoading = false;
  497. upModalData = {
  498. userid: "",
  499. pwdOld: "",
  500. newPwd: "",
  501. newPwd2: "",
  502. };
  503. upPwd(): void {
  504. if(this.upModalData.pwdOld.trim() === ''){
  505. this.msg.error('请填写原始密码!', {
  506. nzDuration: 5000,
  507. });
  508. return;
  509. }
  510. if(!this.strongRegFlag){
  511. this.msg.error('新密码不符合要求!', {
  512. nzDuration: 5000,
  513. });
  514. return;
  515. }
  516. if(this.upModalData.newPwd !== this.upModalData.newPwd2){
  517. this.msg.error('新密码与确认新密码不一致!', {
  518. nzDuration: 5000,
  519. });
  520. return;
  521. }
  522. this.pwdIsOkLoading = true;
  523. let userid = JSON.parse(localStorage.getItem("user")).user.id;
  524. this.upModalData.userid = userid;
  525. this.mainService.upPwd(this.upModalData).subscribe((data) => {
  526. if (data.status == 200) {
  527. this.isPwdVisible = false;
  528. this.pwdIsOkLoading = false;
  529. this.msg.success("修改成功!", {
  530. nzDuration: 5000,
  531. });
  532. } else {
  533. this.pwdIsOkLoading = false;
  534. this.msg.error(data.error, {
  535. nzDuration: 5000,
  536. });
  537. }
  538. });
  539. }
  540. showUpPwd(): void {
  541. this.isPwdVisible = true;
  542. }
  543. pwdHandleOk(): void {
  544. this.upPwd();
  545. }
  546. pwdHandleCancel(): void {
  547. this.isPwdVisible = false;
  548. }
  549. delModal = false;
  550. tipsMsg1 = "是否确定离开该界面,如果未点击生效,数据可能会遗失?";
  551. navInfo = {};
  552. // 隐藏模态框
  553. hideDelModal() {
  554. this.delModal = false;
  555. }
  556. // 模态框确认
  557. confirmDel() {
  558. this.delModal = false;
  559. if (this.navInfo["title"] == "首页") {
  560. this.router.navigateByUrl("/main/home");
  561. this.toMenu("首页");
  562. } else {
  563. this.router.navigateByUrl("/main/" + this.navInfo["item"].link);
  564. this.toMenu(
  565. this.navInfo["title"],
  566. this.navInfo["item"],
  567. this.navInfo["data"]
  568. );
  569. }
  570. }
  571. //前往菜单连接(拦截版)
  572. totoMenu(title, item?, data?) {
  573. let url = location.href.split("#")[1];
  574. if (url.includes("/main/quickCombination")) {
  575. //拦截
  576. this.delModal = true;
  577. this.navInfo = {
  578. title,
  579. item,
  580. data,
  581. };
  582. } else {
  583. //正常情况
  584. if (title == "首页") {
  585. this.router.navigateByUrl("/main/home");
  586. this.toMenu("首页");
  587. } else {
  588. this.router.navigateByUrl("/main/" + item.link);
  589. this.toMenu(title, item, data);
  590. }
  591. }
  592. }
  593. // 切换院区
  594. maskFlag: any = false;
  595. hosFlag1 = false;
  596. submitFormHand1(id) {
  597. if(this.currentHospital.id == id){
  598. return;
  599. }
  600. this.maskFlag = this.msg.loading("正在加载中..", {
  601. nzDuration: 0,
  602. }).messageId;
  603. this.mainService
  604. .changeHospital({ currentHosId: +id, loginType: "PC" })
  605. .subscribe((result) => {
  606. this.msg.remove(this.maskFlag);
  607. this.maskFlag = false;
  608. if (result.status == 200) {
  609. localStorage.setItem("user", JSON.stringify(result.user));
  610. location.reload(true);
  611. } else {
  612. this.msg.create("error", "切换院区失败");
  613. }
  614. });
  615. }
  616. hosFlagHand1(flag) {
  617. if (!flag) {
  618. this.hosFlag1 = false;
  619. }
  620. }
  621. }