tool.service.ts 12 KB

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