tool.service.ts 14 KB

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