123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415 |
- import { Component, OnInit, TemplateRef, ViewChild } from "@angular/core";
- import { NavigationEnd, Router } from "@angular/router";
- import { MainService } from "../../services/main.service";
- import { NzMessageService } from "ng-zorro-antd/message";
- import { WebsocketService } from "../../services/websocket.service";
- import http from "../../../assets/js/http";
- import { NzNotificationService } from "ng-zorro-antd/notification";
- import { OverlayScrollbarsComponent } from "overlayscrollbars-ngx";
- import { ToolService } from "../../services/tool.service";
- import { filter } from "rxjs/operators";
- @Component({
- selector: "app-main",
- templateUrl: "./main.component.html",
- styleUrls: ["./main.component.less"],
- })
- export class MainComponent implements OnInit {
- userInfo: any = JSON.parse(localStorage.getItem("user"));
- menus: any = JSON.parse(localStorage.getItem("menu"));
- currentHospital; //当前院区
- routerEventsListener; //监听路由
- deskRole: boolean = false; //调度台权限
- nurseRole: boolean = false; //护士端权限
- pharmacyRole: boolean = false; //药房端权限
- largeScreenRole: boolean = false; //大屏端权限
- specimenViewRole: boolean = false; //业务视图权限
- @ViewChild("osComponentRef1", {
- read: OverlayScrollbarsComponent,
- static: false,
- })
- osComponentRef1: OverlayScrollbarsComponent;
- constructor(
- public router: Router,
- private mainService: MainService,
- private msg: NzMessageService,
- private notification: NzNotificationService,
- private webs: WebsocketService,
- private tool: ToolService
- ) {}
- ngOnInit() {
- this.routerEventsListener = this.router.events
- .pipe(filter((event) => event instanceof NavigationEnd))
- .subscribe((event) => {
- this.highlightMenuByUrl();
- });
- this.currentHospital = this.tool.getCurrentHospital();
- this.initLogin();
- this.initMenu();
- this.getWebsocket();
- }
- // 离开管理端
- ngOnDestroy() {
- //取消路由监听
- this.routerEventsListener.unsubscribe();
- // 断掉连接
- this.webs.closeWs();
- }
- // 根据url高亮菜单baba
- highlightMenuByUrl() {
- console.log(this.router.url);
- let navOne, navTwo;
- let link = this.router.url.split("/").slice(-1)[0];
- let menus = JSON.parse(localStorage.getItem("menu"));
- if (link == "home") {
- this.toMenu("首页");
- } else {
- menus.forEach((oneNav) => {
- if (oneNav.childrens) {
- let findTwoNav = oneNav.childrens.find(
- (twoNav) => twoNav.link == link
- );
- if (findTwoNav) {
- navTwo = findTwoNav;
- navOne = oneNav;
- this.toMenu(navTwo.title, navTwo, navOne);
- }
- }
- });
- }
- }
- // 一级导航点击
- clickMenuOne(data) {
- let menus = JSON.parse(localStorage.getItem("menu"));
- data.flag = !data.flag;
- menus.find((item) => item.id == data.id).flag = data.flag;
- localStorage.setItem("menu", JSON.stringify(menus));
- }
- initMenu() {
- let menus = JSON.parse(localStorage.getItem("menu"));
- let arr = [];
- menus.forEach((e) => {
- if (e.link == "nurse") {
- this.nurseRole = true;
- console.log("护士端权限");
- }
- if (e.link == "dispatchingDesk") {
- this.deskRole = true;
- console.log("调度台权限");
- }
- if (e.link == "pharmacy") {
- this.pharmacyRole = true;
- console.log("药房端权限");
- }
- if (e.link == "largeScreen") {
- this.largeScreenRole = true;
- console.log("大屏端权限");
- }
- if (e.link == "specimenView") {
- this.specimenViewRole = true;
- console.log("业务视图权限");
- }
- if (!e.link) {
- arr.push(e);
- }
- });
- this.menus = arr;
- }
- // 判断登录是否已失效
- initLogin() {
- if (!this.userInfo) {
- this.msg.error("您的登录已失效,请重新登录!", {
- nzDuration: 3000,
- });
- setTimeout(() => {
- this.router.navigateByUrl("login");
- }, 2000);
- return;
- }
- }
- // 跳转页面
- menuLabel: string; //当前菜单名称
- indexFlag = localStorage.getItem("index") === "true" ? true : false; //首页高亮
- toMenu(title, item?, data?) {
- sessionStorage.setItem("title", title);
- this.menuLabel = sessionStorage.getItem("title");
- if (item && data) {
- // 首页取消高亮
- this.indexFlag = false;
- localStorage.setItem("index", "false");
- // 操作本地存储
- let menus = JSON.parse(localStorage.getItem("menu"));
- menus.forEach((item1) => {
- item1.flagBg = false;
- if (item1.childrens) {
- item1.childrens.forEach((value) => {
- value.flag = false;
- });
- }
- });
- let obj = menus.find((value) => value.id == data.id);
- obj.flagBg = true;
- obj.flag = true;
- obj.childrens.find((value) => value.id == item.id).flag = true;
- localStorage.setItem("menu", JSON.stringify(menus));
- // 操作菜单一级 二级
- this.menus = menus.filter((item) => !item.link);
- } else {
- // 首页高亮
- this.indexFlag = true;
- localStorage.setItem("index", "true");
- // 操作本地存储
- let menus = JSON.parse(localStorage.getItem("menu"));
- menus.forEach((item1) => {
- item1.flagBg = false;
- // item1.flag = false;
- if (item1.childrens) {
- item1.childrens.forEach((value) => {
- value.flag = false;
- });
- }
- });
- localStorage.setItem("menu", JSON.stringify(menus));
- // 操作菜单一级 二级
- this.menus = menus.filter((item) => !item.link);
- }
- }
- // 子路由跳转事件
- activeRoute() {
- this.menuLabel = sessionStorage.getItem("title");
- }
- // 调度台
- toFuwutai(): void {
- this.router.navigateByUrl("dispatchingDesk");
- }
- // 护士建单
- toHuShi(): void {
- this.router.navigateByUrl("nurse");
- }
- // 药房端
- toPharmacy(): void {
- this.router.navigateByUrl("pharmacy");
- }
- // 大屏端或视图端
- screenType;
- hosFlag = false;
- toBigScreen(type): void {
- this.screenType = type;
- this.submitFormHand(this.currentHospital.id);
- }
- submitFormHand(id) {
- if (this.screenType === "largeScreen") {
- window.open(http.bigScreenHost + "/#/" + id);
- } else if (this.screenType === "specimenView") {
- // this.getTypeByDept(id);
- let remember = JSON.parse(localStorage.getItem("remember"));
- window.open(
- http.specimenViewHost +
- "/#/" +
- id +
- "/" +
- encodeURIComponent(remember.username) +
- "/" +
- encodeURIComponent(remember.password)
- );
- }
- }
- //获取系统设置中的科室类型
- deptTypeLoading = false;
- getTypeByDept(id) {
- let postData = {
- idx: 0,
- sum: 1,
- systemConfiguration: { keyconfig: "busiViewDeptId" },
- };
- this.deptTypeLoading = true;
- this.mainService
- .getFetchDataList("simple/data", "systemConfiguration", postData)
- .subscribe((result) => {
- this.deptTypeLoading = false;
- if (result.status == 200) {
- let remember = JSON.parse(localStorage.getItem("remember"));
- window.open(
- http.specimenViewHost +
- "/#/" +
- id +
- "/" +
- encodeURIComponent(remember.username) +
- "/" +
- encodeURIComponent(remember.password) +
- "/" +
- result.list[0].valueconfig
- );
- }
- });
- }
- hosFlagHand(flag) {
- if (!flag) {
- this.hosFlag = false;
- }
- }
- // 退出
- logOut(): void {
- // 假退出
- localStorage.removeItem("user");
- localStorage.removeItem("menu");
- localStorage.removeItem("phones");
- localStorage.removeItem("index");
- this.router.navigateByUrl("login");
- // 假退出
- this.mainService.logOut().subscribe((data) => {
- if (data.status == 200) {
- localStorage.removeItem("user");
- localStorage.removeItem("menu");
- localStorage.removeItem("phones");
- localStorage.removeItem("index");
- this.router.navigateByUrl("login");
- }
- });
- }
- // 连接websocket
- getWebsocket() {
- this.webs
- .connectWs(http.mainWs, { userCount: this.userInfo.user.account })
- .subscribe((data) => {
- console.log(data);
- if (data && data.content) {
- this.createBasicNotification(data);
- }
- });
- }
- @ViewChild("msgTemplate1", { static: false }) msgTemplate1: TemplateRef<any>; //消息通知模板
- // 消息提醒
- createBasicNotification(msgs): void {
- this.notification.template(this.msgTemplate1, {
- nzDuration: 0,
- nzData: msgs,
- });
- }
- // 修改密码
- passwordVisible = false;
- password?: string;
- isPwdVisible = false;
- pwdIsOkLoading = false;
- upModalData = {
- userid: "",
- pwdOld: "",
- newPwd: "",
- newPwd2: "",
- };
- upPwd(): void {
- let userid = JSON.parse(localStorage.getItem("user")).user.id;
- this.upModalData.userid = userid;
- this.mainService.upPwd(this.upModalData).subscribe((data) => {
- if (data.status == 200) {
- this.isPwdVisible = false;
- this.pwdIsOkLoading = false;
- this.msg.success("修改成功!", {
- nzDuration: 5000,
- });
- } else {
- this.pwdIsOkLoading = false;
- this.msg.error(data.error, {
- nzDuration: 5000,
- });
- }
- });
- }
- showUpPwd(): void {
- this.isPwdVisible = true;
- }
- pwdHandleOk(): void {
- this.pwdIsOkLoading = true;
- this.upPwd();
- }
- pwdHandleCancel(): void {
- this.isPwdVisible = false;
- }
- delModal = false;
- tipsMsg1 = "是否确定离开该界面,如果未点击生效,数据可能会遗失?";
- navInfo = {};
- // 隐藏模态框
- hideDelModal() {
- this.delModal = false;
- }
- // 模态框确认
- confirmDel() {
- this.delModal = false;
- if (this.navInfo["title"] == "首页") {
- this.router.navigateByUrl("/main/home");
- this.toMenu("首页");
- } else {
- this.router.navigateByUrl("/main/" + this.navInfo["item"].link);
- this.toMenu(
- this.navInfo["title"],
- this.navInfo["item"],
- this.navInfo["data"]
- );
- }
- }
- //前往菜单连接(拦截版)
- totoMenu(title, item?, data?) {
- let url = location.href.split("#")[1];
- if (url.includes("/main/quickCombination")) {
- //拦截
- this.delModal = true;
- this.navInfo = {
- title,
- item,
- data,
- };
- } else {
- //正常情况
- if (title == "首页") {
- this.router.navigateByUrl("/main/home");
- this.toMenu("首页");
- } else {
- this.router.navigateByUrl("/main/" + item.link);
- this.toMenu(title, item, data);
- }
- }
- }
- // 切换院区
- maskFlag: any = false;
- hosFlag1 = false;
- submitFormHand1(id) {
- this.maskFlag = this.msg.loading("正在加载中..", {
- nzDuration: 0,
- }).messageId;
- this.mainService
- .changeHospital({ currentHosId: +id, loginType: "PC" })
- .subscribe((result) => {
- this.msg.remove(this.maskFlag);
- this.maskFlag = false;
- if (result.status == 200) {
- localStorage.setItem("user", JSON.stringify(result.user));
- location.reload(true);
- } else {
- this.msg.create("error", "切换院区失败");
- }
- });
- }
- hosFlagHand1(flag) {
- if (!flag) {
- this.hosFlag1 = false;
- }
- }
- }
|