tool.service.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. import { Injectable } from "@angular/core";
  2. import { MainService } from "./main.service";
  3. import { Subject } from "rxjs";
  4. @Injectable({
  5. providedIn: "root",
  6. })
  7. export class ToolService {
  8. logoUrl = '';
  9. logoTitle = '';
  10. faviconUrl = '';
  11. changeInpSubject:any;
  12. allSubject = new Subject();
  13. allEndSubject = new Subject();
  14. // 提供方法来触发事件
  15. triggerEvent(data: any) {
  16. console.log(9999,data)
  17. this.allSubject.next(data);
  18. }
  19. // 提供方法来触发事件
  20. triggerEndEvent(data: any) {
  21. this.allEndSubject.next(data);
  22. }
  23. // 提供方法来订阅事件
  24. getEventObservable() {
  25. console.log(3333333)
  26. return this.allSubject.asObservable();
  27. }
  28. // 提供方法来订阅事件
  29. getEventEndObservable() {
  30. return this.allEndSubject.asObservable();
  31. }
  32. // 附件类型
  33. // word,excel,pdf,txt,ppt
  34. attachmentsTypes:string = 'text/plain,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,application/vnd.openxmlformats-officedocument.wordprocessingml.document,application/pdf,application/vnd.ms-excel,application/msword,application/vnd.openxmlformats-officedocument.presentationml.presentation';
  35. constructor(private mainService: MainService) {}
  36. // 获取logoUrl和logoTitle
  37. getSysNameAndLogoAsync(hosId = ''){
  38. return this.mainService.getSysNameAndLogo(hosId);
  39. }
  40. // 设置logoTitle
  41. setSysName(logoTitle){
  42. this.logoTitle = logoTitle;
  43. }
  44. // 设置logoUrl
  45. setLogo(logoUrl){
  46. this.logoUrl = logoUrl;
  47. }
  48. // 设置faviconUrl
  49. setFavicon(faviconUrl){
  50. this.faviconUrl = faviconUrl;
  51. }
  52. // 获取权限中的院区
  53. getHospitalList() {
  54. return (
  55. JSON.parse(localStorage.getItem("user")).infoPermission.hospitals || []
  56. );
  57. }
  58. // 获取权限中的信息
  59. getUserInfoPermission() {
  60. return JSON.parse(localStorage.getItem("user")).infoPermission || {};
  61. }
  62. // 获取权限中的分组
  63. getGroupList() {
  64. return JSON.parse(localStorage.getItem("user")).infoPermission.groups || [];
  65. }
  66. // 获取当前院区
  67. getCurrentHospital() {
  68. return JSON.parse(localStorage.getItem("user")).user.currentHospital
  69. ? JSON.parse(localStorage.getItem("user")).user.currentHospital
  70. : JSON.parse(localStorage.getItem("user")).infoPermission.hospitals[0];
  71. }
  72. //获取当前用户信息
  73. getCurrentUserInfo() {
  74. return JSON.parse(localStorage.getItem("user")).user;
  75. }
  76. //获取当前用户科室
  77. getCurrentUserDept() {
  78. return JSON.parse(localStorage.getItem("user")).user.dept;
  79. }
  80. //获取当前用户id
  81. getCurrentUserId() {
  82. return JSON.parse(localStorage.getItem("user")).user.id;
  83. }
  84. //返回当前人的院区是院区或责任部门
  85. getHospitalOrDuty() {
  86. let hospital = this.getCurrentHospital();
  87. let type = 'hospital';//默认是院区
  88. if(hospital.type && hospital.type.value == 6){
  89. // 当前是责任部门
  90. type = 'duty';
  91. }
  92. if(hospital.type && hospital.type.value != 6){
  93. // 当前是普通部门
  94. type = 'department';
  95. }
  96. return {
  97. hospital,
  98. type,
  99. }
  100. }
  101. //判断是否是责任部门
  102. isDuty(hospital) {
  103. return hospital.type && hospital.type.value == 6;
  104. }
  105. // 返回当前用户的组
  106. getCurrentGroupList(){
  107. return JSON.parse(localStorage.getItem("user")).user.group || [];
  108. }
  109. // 根据route查询菜单-新版统计专用
  110. getMenuAutoType() {
  111. let menu: any = JSON.parse(localStorage.getItem("menu")) || []; //菜单
  112. return menu.filter( v => v.type == 'newStatistics');
  113. }
  114. //获取当前菜单的权限
  115. initCoopBtns(route) {
  116. let link = route.parent.snapshot.routeConfig.path; //当前路由;
  117. let menu: any = JSON.parse(localStorage.getItem("menu")) || []; //菜单
  118. let secondMenus = []; // 二级菜单
  119. let jurisdiction = []; //当前菜单的权限列表
  120. let menuItem = null;
  121. let coopBtns: any = {}; // 初始化权限
  122. menu.forEach((e) => {
  123. if (e.childrens) {
  124. e.childrens.forEach((el) => {
  125. secondMenus.push(el);
  126. });
  127. }
  128. });
  129. secondMenus.forEach((e) => {
  130. if (e.link == link) {
  131. jurisdiction = e.childrens || []; //匹配路由后,取得对应的权限
  132. }
  133. });
  134. if(!jurisdiction.length){
  135. menu.forEach(v => {
  136. // type为panel路由
  137. if(v.type === 'panel' && v.link == link && v.childrens){
  138. jurisdiction = v.childrens || []; //匹配路由后,取得对应的权限
  139. }
  140. })
  141. }
  142. menuItem = jurisdiction
  143. localStorage.setItem("menuItem", JSON.stringify(menuItem))
  144. jurisdiction.forEach((e) => {
  145. switch (e.link) {
  146. case "look":
  147. coopBtns.look = true; //查看
  148. break;
  149. case "add":
  150. coopBtns.add = true; //新增
  151. break;
  152. case "edit":
  153. coopBtns.edit = true; //编辑
  154. break;
  155. case "del":
  156. coopBtns.del = true; //删除
  157. break;
  158. case "reply":
  159. coopBtns.reply = true; //回复
  160. break;
  161. case "mediate":
  162. coopBtns.mediate = true; //调解
  163. break;
  164. case "designate":
  165. coopBtns.designate = true; //指派
  166. break;
  167. case "export":
  168. coopBtns.export = true; //导出
  169. break;
  170. case "import":
  171. coopBtns.import = true; //导入
  172. break;
  173. case "templateDownload":
  174. coopBtns.templateDownload = true; //模板下载
  175. break;
  176. case "isStartUp":
  177. coopBtns.isStartUp = true; //是否启用
  178. break;
  179. case "isTimedStartUp":
  180. coopBtns.isTimedStartUp = true; //是否定时启用
  181. break;
  182. case "copy":
  183. coopBtns.copy = true; //复制
  184. break;
  185. case "generateQRcode":
  186. coopBtns.generateQRcode = true; //生成二维码
  187. break;
  188. case "deleted":
  189. coopBtns.deleted = true; //已删除
  190. break;
  191. case "executeNow":
  192. coopBtns.executeNow = true; //立即执行
  193. break;
  194. case "resetPwd":
  195. coopBtns.resetPwd = true; //重置密码
  196. break;
  197. case "print":
  198. coopBtns.print = true; //打印
  199. break;
  200. case "currentDept":
  201. coopBtns.currentDept = true; //当前科室工单
  202. break;
  203. case "currentUser":
  204. coopBtns.currentUser = true; //当前人员工单
  205. break;
  206. case "allOrders":
  207. coopBtns.allOrders = true; //全部工单
  208. break;
  209. case "batchConversion":
  210. coopBtns.batchConversion = true; //批量转换
  211. break;
  212. case "oneClickConversion":
  213. coopBtns.oneClickConversion = true; //一键转换
  214. break;
  215. case "oneClickRecovery":
  216. coopBtns.oneClickRecovery = true; //一键恢复
  217. break;
  218. case "view":
  219. coopBtns.view = true; //查看视图
  220. break;
  221. case "recount":
  222. coopBtns.recount = true; //重新统计
  223. break;
  224. case "editNum":
  225. coopBtns.editNum = true; //矫正重量
  226. break;
  227. case "establish":
  228. coopBtns.establish = true; //配送建单
  229. break;
  230. case "historyRecord":
  231. coopBtns.historyRecord = true; //历史记录
  232. break;
  233. case "batchPrint":
  234. coopBtns.batchPrint = true; //发药并打印
  235. break;
  236. case "config":
  237. coopBtns.config = true; //配置
  238. break;
  239. case "publish":
  240. coopBtns.publish = true; //发布
  241. break;
  242. case "reset":
  243. coopBtns.reset = true; //重置
  244. break;
  245. case "pause":
  246. coopBtns.pause = true; //停用
  247. break;
  248. case "renew":
  249. coopBtns.renew = true; //恢复
  250. break;
  251. case "audit":
  252. coopBtns.audit = true; //审核
  253. break;
  254. case "upgrade":
  255. coopBtns.upgrade = true; //升级
  256. break;
  257. case "commonFault":
  258. coopBtns.commonFault = true; //常见故障
  259. break;
  260. case "dispensingInfo":
  261. coopBtns.dispensingInfo = true; //发药信息
  262. break;
  263. case "dispensingGross":
  264. coopBtns.dispensingGross = true; //发药总量
  265. break;
  266. case "assign":
  267. coopBtns.assign = true; //指派
  268. break;
  269. case "handle":
  270. coopBtns.handle = true; //处理
  271. break;
  272. case "settings":
  273. coopBtns.settings = true; //设置
  274. break;
  275. case "all":
  276. coopBtns.all = true; //全部故障
  277. break;
  278. case "reassign":
  279. coopBtns.reassign = true; //重新指派
  280. break;
  281. case "callback":
  282. coopBtns.callback = true; //待我回访
  283. break;
  284. case "receive":
  285. coopBtns.receive = true; //接单
  286. break;
  287. case "transfer":
  288. coopBtns.transfer = true; //转派
  289. break;
  290. case "visit":
  291. coopBtns.visit = true; //回访
  292. break;
  293. case "continue":
  294. coopBtns.continue = true; //继续建单
  295. break;
  296. case "generate":
  297. coopBtns.generate = true; //生成
  298. break;
  299. case "reject":
  300. coopBtns.reject = true; //不受理
  301. break;
  302. case "strideLook":
  303. coopBtns.strideLook = true; //跨科查看
  304. break;
  305. case "crossHospital":
  306. coopBtns.crossHospital = true; //跨部门选组
  307. break;
  308. case "maintenance":
  309. coopBtns.maintenance = true; //运维
  310. break;
  311. case "distributionPj":
  312. coopBtns.distributionPj = true; //配送陪检
  313. break;
  314. case "extension":
  315. coopBtns.extension = true; //分机绑定
  316. break;
  317. case "callCenter":
  318. coopBtns.callCenter = true; //呼叫中心
  319. break;
  320. case "log":
  321. coopBtns.log = true; //日志
  322. break
  323. case "viewGd":
  324. coopBtns.viewGd = true; //查看工单
  325. break;
  326. case "tagBackDepartment":
  327. coopBtns.tagBackDepartment = true; //标记回科
  328. case "updata":
  329. coopBtns.updata = true; //更新
  330. break;
  331. case "download":
  332. coopBtns.download = true; //下载
  333. break;
  334. case "allocation":
  335. coopBtns.allocation = true; //分配任务
  336. break;
  337. case "accomplish":
  338. coopBtns.accomplish = true; //任务完成
  339. break;
  340. case "startTask":
  341. coopBtns.startTask = true; //开始任务
  342. break;
  343. case "record":
  344. coopBtns.record = true; //任务记录
  345. break;
  346. case "send":
  347. coopBtns.send = true; //发送消息
  348. break;
  349. case "batchRecover":
  350. coopBtns.batchRecover = true; //批量恢复
  351. break;
  352. case "batchProcessing":
  353. coopBtns.batchProcessing = true; //批量不处理
  354. break;
  355. }
  356. });
  357. console.log(coopBtns);
  358. return coopBtns;
  359. }
  360. // 获取护士端是否使用科室别名的系统配置
  361. getDeptDisplay() {
  362. let postData = {
  363. idx: 0,
  364. sum: 1,
  365. systemConfiguration: { keyconfig: "deptDisplay" },
  366. };
  367. return this.mainService.getFetchDataList(
  368. "simple/data",
  369. "systemConfiguration",
  370. postData
  371. );
  372. }
  373. /**
  374. * @description: 扁平化结构转成树形结构
  375. * @param {*} list 扁平化的数组
  376. * @param {*} rootValue 顶级parentKeyName的值
  377. * @param {*} parentKeyName 父级字段名称
  378. * @param {*} keyName 字段名称
  379. * @return {*} 返回树形结构
  380. * @author: seimin
  381. */
  382. tranListToTreeData(list:Array<any>, rootValue:any, parentKeyName:string, keyName:string = 'id'):Array<any> {
  383. return list.filter((t) =>
  384. t[parentKeyName] === rootValue
  385. ? (t.children = this.tranListToTreeData(list, t[keyName], parentKeyName, keyName))
  386. : false
  387. );
  388. }
  389. /**
  390. * @description: 树形结构转扁平化结构
  391. * @param {*} tree 树形结构
  392. * @return {*} 返回扁平化结构
  393. * @author: seimin
  394. */
  395. tranTreeToListData(tree: Array<any>): Array<any> {
  396. let res: Array<any> = [];
  397. for (const item of tree) {
  398. const { children, ...i } = item;
  399. if (children && children.length) {
  400. res = res.concat(this.tranTreeToListData(children));
  401. }
  402. res.push(i);
  403. }
  404. return res;
  405. }
  406. /**
  407. * @description: 扁平化结构转成树形结构-ng-zorro级联组件专用
  408. * @param {*} list 扁平化的数组
  409. * @param {*} rootValue 顶级parentKeyName的值
  410. * @param {*} parentKeyName 父级字段名称
  411. * @param {*} keyName 字段名称
  412. * @return {*} 返回树形结构
  413. * @author: seimin
  414. */
  415. tranListToTreeDataLeaf(list:Array<any>, rootValue:any, parentKeyName:string, keyName:string = 'id'):Array<any> {
  416. return list.filter((t) => {
  417. let children = this.tranListToTreeData(list, t[keyName], parentKeyName, keyName);
  418. if(!children.length){
  419. t.isLeaf = true;
  420. }
  421. return t[parentKeyName] === rootValue
  422. ? (t.children = children)
  423. : false
  424. });
  425. }
  426. /**
  427. * @description: 树形结构根据id回显-ng-zorro级联组件专用
  428. * @param {*} tree 树形结构
  429. * @param {*} id 要查询的id
  430. * @return {*} 返回数组-用于回显
  431. * @author: seimin
  432. */
  433. tranListToTreeDataFindIdsLeaf(tree: Array<any>, id: number, arr = []):Array<number> {
  434. let list = this.tranTreeToListData(tree);
  435. console.log(list)
  436. let obj = list.find(v => v.id === id);
  437. arr.unshift(id);
  438. if(obj.parentId){
  439. this.tranListToTreeDataFindIdsLeaf(tree, obj.parentId, arr);
  440. }
  441. return arr;
  442. }
  443. /**
  444. * @description 生成连续的数字
  445. * @param {number} start 起点数字
  446. * @param {number} end 终点数字
  447. * @return {array}
  448. */
  449. generateNumberArray(start, end){
  450. return Array.from(new Array(end + 1).keys()).slice(start);
  451. }
  452. }