sys-config.component.ts 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443
  1. import { Component, OnInit, ViewChild } from "@angular/core";
  2. import { FormBuilder, FormGroup, Validators } from "@angular/forms";
  3. import { ActivatedRoute } from "@angular/router";
  4. import { MainService } from "../../services/main.service";
  5. import { ToolService } from "src/app/services/tool.service";
  6. import { OverlayScrollbarsComponent } from 'overlayscrollbars-ngx';
  7. import { Observable, Observer } from 'rxjs';
  8. import { NzMessageService, UploadFile, UploadXHRArgs } from 'ng-zorro-antd';
  9. import { HttpRequest, HttpEventType, HttpEvent, HttpResponse, HttpClient } from '@angular/common/http';
  10. @Component({
  11. selector: "app-sys-config",
  12. templateUrl: "./sys-config.component.html",
  13. styleUrls: ["./sys-config.component.less"],
  14. })
  15. export class SysConfigComponent implements OnInit {
  16. validateForm: FormGroup;
  17. loading1 = false; //查询信息的loading
  18. loading2 = false; //保存信息的loading
  19. loading3 = false; //刷新字典缓存信息的loading
  20. loading4 = false; //护士默认角色
  21. initConfig = []; //接口配置列表
  22. config = []; //配置列表[key,value,id]
  23. promptContent: string; //操作提示框提示信息
  24. ifSuccess: boolean; //操作成功/失败
  25. promptInfo: string; //操作结果提示信息
  26. promptModalShow: boolean; //操作提示框是否展示
  27. coopBtns = {};
  28. checkOptionsOne = [
  29. { label: '科内报修', value: 'deptRepair', checked:false},
  30. { label: '公共报修', value: 'publicRepair', checked:false },
  31. ];
  32. formatterSecond = (value: number) => `${value} 秒`;
  33. parserSecond = (value: string) => value.replace(' 秒', '');
  34. menu = JSON.parse(localStorage.getItem("menu")) || []; //菜单
  35. sysLogoUrl:string = this.mainService.returnUploadUrl('sysLogo', 777);
  36. faviconLogoUrl:string = this.mainService.returnUploadUrl('faviconLogo', 777);
  37. constructor(
  38. private mainService: MainService,
  39. private fb: FormBuilder,
  40. private route: ActivatedRoute,
  41. private tool: ToolService,
  42. private msg: NzMessageService,
  43. private http: HttpClient
  44. ) {}
  45. @ViewChild("osComponentRef1", {
  46. read: OverlayScrollbarsComponent,
  47. static: false,
  48. })
  49. osComponentRef1: OverlayScrollbarsComponent;
  50. ngOnInit() {
  51. this.validateForm = this.fb.group({
  52. defaultPwd: [null, [Validators.required]],
  53. itsmIP: [null, [Validators.required]],
  54. effectiveDuration: [null, [Validators.required]],
  55. specimenButton: [null, [Validators.required]],
  56. deptDisplay: [null, [Validators.required]],
  57. orderClearUserSwitch: [null, [Validators.required]],
  58. itsmIncident: [null, [Validators.required]],
  59. workOrderSettings: [5, [Validators.required]],
  60. nurseDeptSwitchTip: [0, [Validators.required]],
  61. refreshNurseWorkOrderTime: [60, [Validators.required]],
  62. updateTipsForNurses: [""],
  63. systemName: [""],
  64. largeScreenName: [""],
  65. logo: [""],
  66. favicon: [""],
  67. defaultRoleOfNurse: [null, [Validators.required]],
  68. formUrl: [{ value: null, disabled: true }, [Validators.required]],
  69. serviceUrl: [{ value: null, disabled: true }, [Validators.required]],
  70. cachePath: [{ value: null, disabled: true }, [Validators.required]],
  71. cachePort: [{ value: null, disabled: true }, [Validators.required]],
  72. busiViewDeptId: [null, [Validators.required]],
  73. repairs: [null, [Validators.required]],
  74. cmdbRepair: [null, [Validators.required]],
  75. supportAppVersion: [null, [Validators.required]],
  76. });
  77. this.getDeptType();
  78. this.coopBtns = this.tool.initCoopBtns(this.route);
  79. this.getRoleList();
  80. this.getLogoOrFavicon();
  81. this.avatarUrl = this.tool.logoUrl;
  82. this.avatarUrl1 = this.tool.logoUrl;
  83. }
  84. getLogoOrFavicon(){
  85. this.tool.getSysNameAndLogoAsync().subscribe(result => {
  86. this.avatarUrl = location.origin + '/file' + result.logo || '';
  87. this.avatarUrl1 = location.origin + '/file' + result.favicon || '';
  88. })
  89. }
  90. // 角色列表
  91. roleList = [];
  92. getRoleList() {
  93. let postData = {
  94. idx: 0,
  95. sum: 10,
  96. };
  97. this.loading4 = true;
  98. this.mainService
  99. .getFetchDataList("user/data", "role", postData)
  100. .subscribe((result) => {
  101. this.loading4 = false;
  102. this.roleList = result.list;
  103. });
  104. }
  105. // 刷新字典缓存
  106. refresh() {
  107. this.loading3 = true;
  108. this.mainService.refreshDic().subscribe(
  109. (result) => {
  110. this.loading3 = false;
  111. if (result.status == 200) {
  112. this.mainService.clearDictionary();
  113. this.showPromptModal("刷新", true, "");
  114. } else {
  115. this.showPromptModal("刷新", false, "");
  116. }
  117. },
  118. (error) => {
  119. this.loading3 = false;
  120. this.showPromptModal("刷新", false, "");
  121. }
  122. );
  123. }
  124. // 保存
  125. submitForm(): void {
  126. for (const i in this.validateForm.controls) {
  127. this.validateForm.controls[i].markAsDirty();
  128. this.validateForm.controls[i].updateValueAndValidity();
  129. }
  130. if (this.validateForm.invalid) {
  131. return;
  132. }
  133. let filterData = this.initConfig.filter(
  134. (item) =>
  135. item.keyconfig === "pwd" ||
  136. item.keyconfig === "itsmIP" ||
  137. item.keyconfig === "conversationSeconds" ||
  138. item.keyconfig === "specimenButton" ||
  139. item.keyconfig === "deptDisplay" ||
  140. item.keyconfig === "orderClearUserSwitch" ||
  141. item.keyconfig === "itsmIncident" ||
  142. item.keyconfig === "workOrderSettings" ||
  143. item.keyconfig === "nurseDeptSwitchTip" ||
  144. item.keyconfig === "refreshNurseWorkOrderTime" ||
  145. item.keyconfig === "updateTipsForNurses" ||
  146. item.keyconfig === "systemName" ||
  147. item.keyconfig === "largeScreenName" ||
  148. item.keyconfig === "defaultRoleOfNurse" ||
  149. item.keyconfig === "busiViewDeptId" ||
  150. item.keyconfig === "deptRepair" ||
  151. item.keyconfig === "publicRepair" ||
  152. item.keyconfig === "cmdbRepair" ||
  153. item.keyconfig === "supportAppVersion"
  154. );
  155. console.log(7777,this.validateForm.controls.repairs.value)
  156. filterData.forEach((item) => {
  157. if (item.keyconfig === "pwd") {
  158. item.valueconfig = this.validateForm.controls.defaultPwd.value;
  159. }else if (item.keyconfig === "itsmIP") {
  160. item.valueconfig = this.validateForm.controls.itsmIP.value;
  161. } else if (item.keyconfig === "conversationSeconds") {
  162. item.valueconfig = this.validateForm.controls.effectiveDuration.value;
  163. } else if (item.keyconfig === "specimenButton") {
  164. item.valueconfig = this.validateForm.controls.specimenButton.value;
  165. } else if (item.keyconfig === "deptDisplay") {
  166. item.valueconfig = this.validateForm.controls.deptDisplay.value;
  167. } else if (item.keyconfig === "orderClearUserSwitch") {
  168. item.valueconfig =
  169. this.validateForm.controls.orderClearUserSwitch.value;
  170. } else if (item.keyconfig === "itsmIncident") {
  171. item.valueconfig =
  172. this.validateForm.controls.itsmIncident.value;
  173. } else if (item.keyconfig === "workOrderSettings") {
  174. item.valueconfig = this.validateForm.controls.workOrderSettings.value;
  175. } else if (item.keyconfig === "nurseDeptSwitchTip") {
  176. item.valueconfig = this.validateForm.controls.nurseDeptSwitchTip.value;
  177. } else if (item.keyconfig === "refreshNurseWorkOrderTime") {
  178. item.valueconfig = this.validateForm.controls.refreshNurseWorkOrderTime.value;
  179. } else if (item.keyconfig === "updateTipsForNurses") {
  180. item.valueconfig = this.validateForm.controls.updateTipsForNurses.value;
  181. } else if (item.keyconfig === "systemName") {
  182. item.valueconfig = this.validateForm.controls.systemName.value;
  183. } else if (item.keyconfig === "largeScreenName") {
  184. item.valueconfig = this.validateForm.controls.largeScreenName.value;
  185. } else if (item.keyconfig === "defaultRoleOfNurse") {
  186. item.valueconfig = this.validateForm.controls.defaultRoleOfNurse.value;
  187. } else if (item.keyconfig === "busiViewDeptId") {
  188. item.valueconfig = this.validateForm.controls.busiViewDeptId.value;
  189. } else if (item.keyconfig === "deptRepair") {
  190. let value = null
  191. if(this.validateForm.controls.repairs.value[0].checked){
  192. value = '1'
  193. }else{
  194. value = '0'
  195. }
  196. item.valueconfig = value;
  197. } else if (item.keyconfig === "publicRepair") {
  198. let value = null
  199. if(this.validateForm.controls.repairs.value[1].checked){
  200. value = '1'
  201. }else{
  202. value = '0'
  203. }
  204. item.valueconfig = value;
  205. }else if (item.keyconfig === "cmdbRepair") {
  206. item.valueconfig = this.validateForm.controls.cmdbRepair.value;
  207. }else if (item.keyconfig === "supportAppVersion") {
  208. item.valueconfig = this.validateForm.controls.supportAppVersion.value;
  209. }
  210. });
  211. const postData = filterData;
  212. this.loading2 = true;
  213. this.mainService.changeSysConfig(postData).subscribe(
  214. (result) => {
  215. this.loading2 = false;
  216. if (result["status"] == 200) {
  217. this.showPromptModal("保存", true, "");
  218. } else {
  219. this.showPromptModal("保存", false, "");
  220. }
  221. },
  222. (error) => {
  223. this.loading2 = false;
  224. this.showPromptModal("保存", false, "");
  225. }
  226. );
  227. }
  228. // 获取科室类型
  229. deptTypes: any = [];
  230. getDeptType() {
  231. this.loading1 = true;
  232. this.mainService.getDictionary("list", "dept_type").subscribe((result) => {
  233. this.deptTypes = result;
  234. this.getSysConfig();
  235. });
  236. }
  237. // 格式化自动关闭工单设置的数字选择框
  238. formatterPercent = (value: number) => `${value}小时`;
  239. parserPercent = (value: string) => value.replace("小时", "");
  240. // 获取系统配置
  241. getSysConfig() {
  242. const postData = { idx: 0, sum: 99 };
  243. this.mainService
  244. .getFetchDataList("simple/data", "systemConfiguration", postData)
  245. .subscribe((result) => {
  246. this.loading1 = false;
  247. if (result.status == 200) {
  248. if (result.list && Array.isArray(result.list)) {
  249. this.initConfig = JSON.parse(JSON.stringify(result.list));
  250. this.config = result.list.map((item) => {
  251. return [item.keyconfig, item.valueconfig, item.id, item.label];
  252. });
  253. this.config.forEach((c) => {
  254. switch (c[0]) {
  255. case "pwd":
  256. this.validateForm.controls.defaultPwd.setValue(c[1]);
  257. break;
  258. case "itsmIP":
  259. this.validateForm.controls.itsmIP.setValue(c[1]);
  260. break;
  261. case "conversationSeconds":
  262. this.validateForm.controls.effectiveDuration.setValue(c[1]);
  263. break;
  264. case "specimenButton":
  265. this.validateForm.controls.specimenButton.setValue(c[1]);
  266. break;
  267. case "deptDisplay":
  268. this.validateForm.controls.deptDisplay.setValue(c[1]);
  269. break;
  270. case "orderClearUserSwitch":
  271. this.validateForm.controls.orderClearUserSwitch.setValue(
  272. c[1]
  273. );
  274. break;
  275. case "itsmIncident":
  276. this.validateForm.controls.itsmIncident.setValue(
  277. c[1]
  278. );
  279. break;
  280. case "workOrderSettings":
  281. this.validateForm.controls.workOrderSettings.setValue(c[1]);
  282. break;
  283. case "nurseDeptSwitchTip":
  284. this.validateForm.controls.nurseDeptSwitchTip.setValue(c[1]);
  285. break;
  286. case "refreshNurseWorkOrderTime":
  287. this.validateForm.controls.refreshNurseWorkOrderTime.setValue(c[1]);
  288. break;
  289. case "updateTipsForNurses":
  290. this.validateForm.controls.updateTipsForNurses.setValue(c[1]);
  291. break;
  292. case "systemName":
  293. this.validateForm.controls.systemName.setValue(c[1]);
  294. break;
  295. case "largeScreenName":
  296. this.validateForm.controls.largeScreenName.setValue(c[1]);
  297. break;
  298. case "defaultRoleOfNurse":
  299. this.validateForm.controls.defaultRoleOfNurse.setValue(
  300. c[1] - 0
  301. );
  302. break;
  303. case "formUri":
  304. this.validateForm.controls.formUrl.setValue(c[1]);
  305. break;
  306. case "serviceUrl":
  307. this.validateForm.controls.serviceUrl.setValue(c[1]);
  308. break;
  309. case "userRedisIp":
  310. this.validateForm.controls.cachePath.setValue(c[1]);
  311. break;
  312. case "userRedisPort":
  313. this.validateForm.controls.cachePort.setValue(c[1]);
  314. break;
  315. case "busiViewDeptId":
  316. this.validateForm.controls.busiViewDeptId.setValue(c[1] + "");
  317. break;
  318. case "deptRepair":
  319. if(c[1]=='1'){
  320. this.checkOptionsOne[0].checked = true
  321. }else{
  322. this.checkOptionsOne[0].checked = false
  323. }
  324. this.validateForm.controls.repairs.setValue(this.checkOptionsOne + "");
  325. break;
  326. case "publicRepair":
  327. if(c[1]=='1'){
  328. this.checkOptionsOne[1].checked = true
  329. }else{
  330. this.checkOptionsOne[1].checked = false
  331. }
  332. this.validateForm.controls.repairs.setValue(this.checkOptionsOne + "");
  333. break;
  334. case "cmdbRepair":
  335. this.validateForm.controls.cmdbRepair.setValue(c[1] + "");
  336. break;
  337. case "supportAppVersion":
  338. this.validateForm.controls.supportAppVersion.setValue(c[1]);
  339. break;
  340. }
  341. });
  342. } else {
  343. this.initConfig = [];
  344. this.config = [];
  345. }
  346. }
  347. });
  348. }
  349. // 展示信息提示框(con:提示信息,success:操作是否成功,promptInfo:操作结果提示信息)
  350. showPromptModal(con, success, promptInfo) {
  351. this.promptModalShow = false;
  352. this.promptContent = con;
  353. this.ifSuccess = success;
  354. this.promptInfo = promptInfo;
  355. setTimeout(() => {
  356. this.promptModalShow = true;
  357. }, 100);
  358. this.getDeptType();
  359. }
  360. avatarLoading = false;
  361. avatarUrl: string;
  362. avatarUrl1: string;
  363. beforeUpload = (file: File) => {
  364. return new Observable((observer: Observer<boolean>) => {
  365. const isPic = (file.type === 'image/jpeg' || file.type === 'image/png' || file.type === 'image/jpg');
  366. if (!isPic) {
  367. this.msg.error('只能上传jpg|jpeg|png图片!');
  368. observer.complete();
  369. return;
  370. }
  371. const isLt4M = file.size / 1024 / 1024 < 4;
  372. if (!isLt4M) {
  373. this.msg.error('图片大小不能大于4MB!');
  374. observer.complete();
  375. return;
  376. }
  377. observer.next(isPic && isLt4M);
  378. observer.complete();
  379. });
  380. };
  381. private getBase64(img: File, callback: (img: string) => void): void {
  382. const reader = new FileReader();
  383. reader.addEventListener('load', () => callback(reader.result!.toString()));
  384. reader.readAsDataURL(img);
  385. }
  386. handleChange(info: { file: UploadFile }, avatarUrl): void {
  387. switch (info.file.status) {
  388. case 'uploading':
  389. this.avatarLoading = true;
  390. break;
  391. case 'done':
  392. // Get this url from response in real world.
  393. this.getBase64(info.file!.originFileObj!, (img: string) => {
  394. this.avatarLoading = false;
  395. this[avatarUrl] = img;
  396. });
  397. break;
  398. case 'error':
  399. this.msg.error('Network error');
  400. this.avatarLoading = false;
  401. break;
  402. }
  403. }
  404. customReq = (item: UploadXHRArgs) => {
  405. console.log(item);
  406. // Create a FormData here to store files and other parameters.
  407. const formData = new FormData();
  408. // tslint:disable-next-line:no-any
  409. formData.append('file', item.file as any);
  410. formData.append('filename', item.file.name);
  411. const req = new HttpRequest('POST', item.action!, formData, {
  412. reportProgress: true,
  413. withCredentials: true
  414. });
  415. // Always returns a `Subscription` object. nz-upload would automatically unsubscribe it at correct time.
  416. return this.http.request(req).subscribe(
  417. // tslint:disable-next-line no-any
  418. (event: HttpEvent<any>) => {
  419. if (event.type === HttpEventType.UploadProgress) {
  420. if (event.total! > 0) {
  421. // tslint:disable-next-line:no-any
  422. (event as any).percent = (event.loaded / event.total!) * 100;
  423. }
  424. item.onProgress!(event, item.file!);
  425. } else if (event instanceof HttpResponse) {
  426. item.onSuccess!(event.body, item.file!, event);
  427. }
  428. },
  429. err => {
  430. item.onError!(err, item.file!);
  431. }
  432. );
  433. };
  434. }