tool.service.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398
  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. //获取当前菜单的权限
  88. initCoopBtns(route) {
  89. let link;
  90. let menu: any = JSON.parse(localStorage.getItem("menu")) || []; //菜单
  91. if (route === "dataDictionary") {
  92. link = route;
  93. } else {
  94. link = route.parent.snapshot.routeConfig.path; //当前路由
  95. }
  96. let secondMenus = []; // 二级菜单
  97. let jurisdiction = []; //当前菜单的权限列表
  98. let coopBtns: any = {}; // 初始化权限
  99. menu.forEach((e) => {
  100. if (e.childrens) {
  101. e.childrens.forEach((el) => {
  102. secondMenus.push(el);
  103. });
  104. }
  105. });
  106. secondMenus.forEach((e) => {
  107. if (e.link == link) {
  108. jurisdiction = e.childrens || []; //匹配路由后,取得对应的权限
  109. }
  110. });
  111. if(!jurisdiction.length){
  112. // type为panel路由
  113. menu.forEach(v => {
  114. if(v.type === 'panel' && v.link == link && v.childrens){
  115. jurisdiction = v.childrens || []; //匹配路由后,取得对应的权限
  116. }
  117. })
  118. }
  119. jurisdiction.forEach((e) => {
  120. switch (e.link) {
  121. case "look":
  122. coopBtns.look = true; //查看
  123. break;
  124. case "add":
  125. coopBtns.add = true; //新增
  126. break;
  127. case "edit":
  128. coopBtns.edit = true; //编辑
  129. break;
  130. case "del":
  131. coopBtns.del = true; //删除
  132. break;
  133. case "reply":
  134. coopBtns.reply = true; //回复
  135. break;
  136. case "mediate":
  137. coopBtns.mediate = true; //调解
  138. break;
  139. case "designate":
  140. coopBtns.designate = true; //指派
  141. break;
  142. case "export":
  143. coopBtns.export = true; //导出
  144. break;
  145. case "import":
  146. coopBtns.import = true; //导入
  147. break;
  148. case "templateDownload":
  149. coopBtns.templateDownload = true; //模板下载
  150. break;
  151. case "isStartUp":
  152. coopBtns.isStartUp = true; //是否启用
  153. break;
  154. case "isTimedStartUp":
  155. coopBtns.isTimedStartUp = true; //是否定时启用
  156. break;
  157. case "copy":
  158. coopBtns.copy = true; //复制
  159. break;
  160. case "generateQRcode":
  161. coopBtns.generateQRcode = true; //生成二维码
  162. break;
  163. case "deleted":
  164. coopBtns.deleted = true; //已删除
  165. break;
  166. case "executeNow":
  167. coopBtns.executeNow = true; //立即执行
  168. break;
  169. case "resetPwd":
  170. coopBtns.resetPwd = true; //重置密码
  171. break;
  172. case "print":
  173. coopBtns.print = true; //打印
  174. break;
  175. case "currentDept":
  176. coopBtns.currentDept = true; //当前科室工单
  177. break;
  178. case "currentUser":
  179. coopBtns.currentUser = true; //当前人员工单
  180. break;
  181. case "allOrders":
  182. coopBtns.allOrders = true; //全部工单
  183. break;
  184. case "batchConversion":
  185. coopBtns.batchConversion = true; //批量转换
  186. break;
  187. case "oneClickConversion":
  188. coopBtns.oneClickConversion = true; //一键转换
  189. break;
  190. case "oneClickRecovery":
  191. coopBtns.oneClickRecovery = true; //一键恢复
  192. break;
  193. case "view":
  194. coopBtns.view = true; //查看视图
  195. break;
  196. case "recount":
  197. coopBtns.recount = true; //重新统计
  198. break;
  199. case "editNum":
  200. coopBtns.editNum = true; //矫正重量
  201. break;
  202. case "establish":
  203. coopBtns.establish = true; //配送建单
  204. break;
  205. case "historyRecord":
  206. coopBtns.historyRecord = true; //历史记录
  207. break;
  208. case "batchPrint":
  209. coopBtns.batchPrint = true; //发药并打印
  210. break;
  211. case "config":
  212. coopBtns.config = true; //配置
  213. break;
  214. case "publish":
  215. coopBtns.publish = true; //发布
  216. break;
  217. case "reset":
  218. coopBtns.reset = true; //重置
  219. break;
  220. case "pause":
  221. coopBtns.pause = true; //停用
  222. break;
  223. case "renew":
  224. coopBtns.renew = true; //恢复
  225. break;
  226. case "audit":
  227. coopBtns.audit = true; //审核
  228. break;
  229. case "upgrade":
  230. coopBtns.upgrade = true; //升级
  231. break;
  232. case "commonFault":
  233. coopBtns.commonFault = true; //常见故障
  234. break;
  235. case "dispensingInfo":
  236. coopBtns.dispensingInfo = true; //发药信息
  237. break;
  238. case "dispensingGross":
  239. coopBtns.dispensingGross = true; //发药总量
  240. break;
  241. case "assign":
  242. coopBtns.assign = true; //指派
  243. break;
  244. case "handle":
  245. coopBtns.handle = true; //处理
  246. break;
  247. case "settings":
  248. coopBtns.settings = true; //设置
  249. break;
  250. case "all":
  251. coopBtns.all = true; //全部故障
  252. break;
  253. case "reassign":
  254. coopBtns.reassign = true; //重新指派
  255. break;
  256. case "callback":
  257. coopBtns.callback = true; //待我回访
  258. break;
  259. case "receive":
  260. coopBtns.receive = true; //接单
  261. break;
  262. case "transfer":
  263. coopBtns.transfer = true; //转派
  264. break;
  265. case "visit":
  266. coopBtns.visit = true; //回访
  267. break;
  268. case "continue":
  269. coopBtns.continue = true; //继续建单
  270. break;
  271. case "generate":
  272. coopBtns.generate = true; //生成
  273. break;
  274. case "reject":
  275. coopBtns.reject = true; //不受理
  276. break;
  277. case "strideLook":
  278. coopBtns.strideLook = true; //跨科查看
  279. break;
  280. case "crossHospital":
  281. coopBtns.crossHospital = true; //跨部门选组
  282. break;
  283. }
  284. });
  285. console.log(coopBtns);
  286. return coopBtns;
  287. }
  288. // 获取护士端是否使用科室别名的系统配置
  289. getDeptDisplay() {
  290. let postData = {
  291. idx: 0,
  292. sum: 1,
  293. systemConfiguration: { keyconfig: "deptDisplay" },
  294. };
  295. return this.mainService.getFetchDataList(
  296. "simple/data",
  297. "systemConfiguration",
  298. postData
  299. );
  300. }
  301. /**
  302. * @description: 扁平化结构转成树形结构
  303. * @param {*} list 扁平化的数组
  304. * @param {*} rootValue 顶级parentKeyName的值
  305. * @param {*} parentKeyName 父级字段名称
  306. * @param {*} keyName 字段名称
  307. * @return {*} 返回树形结构
  308. * @author: seimin
  309. */
  310. tranListToTreeData(list:Array<any>, rootValue:any, parentKeyName:string, keyName:string = 'id'):Array<any> {
  311. return list.filter((t) =>
  312. t[parentKeyName] === rootValue
  313. ? (t.children = this.tranListToTreeData(list, t[keyName], parentKeyName, keyName))
  314. : false
  315. );
  316. }
  317. /**
  318. * @description: 树形结构转扁平化结构
  319. * @param {*} tree 树形结构
  320. * @return {*} 返回扁平化结构
  321. * @author: seimin
  322. */
  323. tranTreeToListData(tree: Array<any>): Array<any> {
  324. let res: Array<any> = [];
  325. for (const item of tree) {
  326. const { children, ...i } = item;
  327. if (children && children.length) {
  328. res = res.concat(this.tranTreeToListData(children));
  329. }
  330. res.push(i);
  331. }
  332. return res;
  333. }
  334. /**
  335. * @description: 扁平化结构转成树形结构-ng-zorro级联组件专用
  336. * @param {*} list 扁平化的数组
  337. * @param {*} rootValue 顶级parentKeyName的值
  338. * @param {*} parentKeyName 父级字段名称
  339. * @param {*} keyName 字段名称
  340. * @return {*} 返回树形结构
  341. * @author: seimin
  342. */
  343. tranListToTreeDataLeaf(list:Array<any>, rootValue:any, parentKeyName:string, keyName:string = 'id'):Array<any> {
  344. return list.filter((t) => {
  345. let children = this.tranListToTreeData(list, t[keyName], parentKeyName, keyName);
  346. if(!children.length){
  347. t.isLeaf = true;
  348. }
  349. return t[parentKeyName] === rootValue
  350. ? (t.children = children)
  351. : false
  352. });
  353. }
  354. /**
  355. * @description: 树形结构根据id回显-ng-zorro级联组件专用
  356. * @param {*} tree 树形结构
  357. * @param {*} id 要查询的id
  358. * @return {*} 返回数组-用于回显
  359. * @author: seimin
  360. */
  361. tranListToTreeDataFindIdsLeaf(tree: Array<any>, id: number, arr = []):Array<number> {
  362. let list = this.tranTreeToListData(tree);
  363. console.log(list)
  364. let obj = list.find(v => v.id === id);
  365. arr.unshift(id);
  366. if(obj.parentId){
  367. this.tranListToTreeDataFindIdsLeaf(tree, obj.parentId, arr);
  368. }
  369. return arr;
  370. }
  371. /**
  372. * @description 生成连续的数字
  373. * @param {number} start 起点数字
  374. * @param {number} end 终点数字
  375. * @return {array}
  376. */
  377. generateNumberArray(start, end){
  378. return Array.from(new Array(end + 1).keys()).slice(start);
  379. }
  380. }