home.component.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * Copyright [2022] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. import { Platform } from '@angular/cdk/platform';
  17. import { DOCUMENT } from '@angular/common';
  18. import { ChangeDetectionStrategy, ViewContainerRef, ChangeDetectorRef, Component, Inject, OnInit, Renderer2 } from '@angular/core';
  19. import type { Chart } from '@antv/g2';
  20. import { OnboardingService } from '@delon/abc/onboarding';
  21. import { ACLService } from '@delon/acl';
  22. import { environment } from '@env/environment';
  23. import { format } from 'date-fns';
  24. import { NzSafeAny } from 'ng-zorro-antd/core/types';
  25. import { NzModalRef, NzModalService } from 'ng-zorro-antd/modal';
  26. import { CONSTS } from 'src/app/shared/consts';
  27. import { AppListService } from '../../../service/appList.service';
  28. import { AuthnService } from '../../../service/authn.service';
  29. import { AccoutsComponent } from '../../config/accouts/accouts.component';
  30. import { Console } from 'console';
  31. import {ALAIN_I18N_TOKEN} from "@delon/theme";
  32. import {I18NService} from "@core";
  33. @Component({
  34. selector: 'app-home',
  35. templateUrl: './home.component.html',
  36. styles: [
  37. `
  38. .appListimage {
  39. width: 65px;
  40. height: 65px;
  41. border: 0;
  42. }
  43. `
  44. ],
  45. styleUrls: ['./home.component.less']
  46. })
  47. export class HomeComponent implements OnInit {
  48. loading: boolean = false;
  49. appList: any[] = [];
  50. baseUrl: String = '';
  51. staticAppList: any[] = [];
  52. appCategoryList: any[] = [];
  53. appsCategory: String = '';
  54. constructor(
  55. private modal: NzModalService,
  56. private viewContainerRef: ViewContainerRef,
  57. private appListService: AppListService,
  58. private cdr: ChangeDetectorRef,
  59. private obSrv: OnboardingService,
  60. private platform: Platform,
  61. @Inject(ALAIN_I18N_TOKEN) private i18n: I18NService,
  62. @Inject(DOCUMENT) private doc: NzSafeAny
  63. ) {
  64. // TODO: Wait for the page to load
  65. //setTimeout(() => this.genOnboarding(), 1000);
  66. }
  67. fixDark(chart: Chart): void {
  68. if (!this.platform.isBrowser || (this.doc.body as HTMLBodyElement).getAttribute('data-theme') !== 'dark') return;
  69. chart.theme({
  70. styleSheet: {
  71. backgroundColor: 'transparent'
  72. }
  73. });
  74. }
  75. onAuthz(e: MouseEvent, appId: string): void {
  76. e.preventDefault();
  77. for (let i = 0; i < this.appList.length; i++) {
  78. if (this.appList[i].id == appId && (this.appList[i].protocol == 'Basic' || this.appList[i].inducer == 'SP')) {
  79. window.open(this.appList[i].loginUrl);
  80. return;
  81. }
  82. }
  83. window.open(`${this.baseUrl}/authz/${appId}`);
  84. }
  85. setAccount(appId: string): void {
  86. const modal = this.modal.create({
  87. nzContent: AccoutsComponent,
  88. nzViewContainerRef: this.viewContainerRef,
  89. nzComponentParams: {
  90. appId: appId
  91. },
  92. nzWidth: 550
  93. //nzOnOk: () => new Promise(resolve => setTimeout(resolve, 1000))
  94. });
  95. }
  96. ngOnInit(): void {
  97. if (environment.api.baseUrl.endsWith('/')) {
  98. this.baseUrl = environment.api.baseUrl.substring(0, environment.api.baseUrl.length - 1);
  99. } else {
  100. this.baseUrl = environment.api.baseUrl;
  101. }
  102. this.appListService.appList().subscribe(res => {
  103. //console.log(res.data);
  104. this.appList = res.data;
  105. this.staticAppList = this.appList;
  106. this.cdr.detectChanges();
  107. });
  108. this.appCategoryList = [{
  109. id:'none',
  110. name:this.i18n.fanyi('mxk.apps.category.none')
  111. },{
  112. id:'1011',
  113. name:this.i18n.fanyi('mxk.apps.category.1011')
  114. },
  115. {
  116. id:'1012',
  117. name:this.i18n.fanyi('mxk.apps.category.1012')
  118. },
  119. {
  120. id:'1013',
  121. name:this.i18n.fanyi('mxk.apps.category.1013')
  122. },
  123. {
  124. id:'1014',
  125. name:this.i18n.fanyi('mxk.apps.category.1014')
  126. },
  127. {
  128. id:'1015',
  129. name:this.i18n.fanyi('mxk.apps.category.1015')
  130. },
  131. {
  132. id:'1016',
  133. name:this.i18n.fanyi('mxk.apps.category.1016')
  134. },
  135. {
  136. id:'1017',
  137. name:this.i18n.fanyi('mxk.apps.category.1017')
  138. },
  139. {
  140. id:'1111',
  141. name:this.i18n.fanyi('mxk.apps.category.1111')
  142. },
  143. {
  144. id:'1112',
  145. name:this.i18n.fanyi('mxk.apps.category.1112')
  146. },
  147. {
  148. id:'1113',
  149. name:this.i18n.fanyi('mxk.apps.category.1113')
  150. },
  151. {
  152. id:'1114',
  153. name:this.i18n.fanyi('mxk.apps.category.1114')
  154. },
  155. {
  156. id:'1211',
  157. name:this.i18n.fanyi('mxk.apps.category.1211')
  158. },
  159. {
  160. id:'1212',
  161. name:this.i18n.fanyi('mxk.apps.category.1212')
  162. },
  163. {
  164. id:'1213',
  165. name:this.i18n.fanyi('mxk.apps.category.1213')
  166. },
  167. {
  168. id:'1214',
  169. name:this.i18n.fanyi('mxk.apps.category.1214')
  170. },
  171. {
  172. id:'1215',
  173. name:this.i18n.fanyi('mxk.apps.category.1215')
  174. },
  175. {
  176. id:'1215',
  177. name:this.i18n.fanyi('mxk.apps.category.1215')
  178. },
  179. {
  180. id:'1311',
  181. name:this.i18n.fanyi('mxk.apps.category.1311')
  182. },
  183. {
  184. id:'1411',
  185. name:this.i18n.fanyi('mxk.apps.category.1411')
  186. },
  187. {
  188. id:'1511',
  189. name:this.i18n.fanyi('mxk.apps.category.1511')
  190. },
  191. {
  192. id:'1512',
  193. name:this.i18n.fanyi('mxk.apps.category.1512')
  194. },
  195. {
  196. id:'1611',
  197. name:this.i18n.fanyi('mxk.apps.category.1611')
  198. },
  199. {
  200. id:'1711',
  201. name:this.i18n.fanyi('mxk.apps.category.1711')
  202. },
  203. {
  204. id:'1712',
  205. name:this.i18n.fanyi('mxk.apps.category.1712')
  206. },
  207. {
  208. id:'1811',
  209. name:this.i18n.fanyi('mxk.apps.category.1811')
  210. },
  211. {
  212. id:'1812',
  213. name:this.i18n.fanyi('mxk.apps.category.1812')
  214. },{
  215. id:'1911',
  216. name:this.i18n.fanyi('mxk.apps.category.1911')
  217. },
  218. {
  219. id:'1912',
  220. name:this.i18n.fanyi('mxk.apps.category.1912')
  221. }
  222. ]
  223. }
  224. changeCategory (): void {
  225. this.appList = [];
  226. if (this.appsCategory === null || this.appsCategory === '') {
  227. this.appList = this.staticAppList;
  228. } else {
  229. for(let i = 0;i<this.staticAppList.length;i++){
  230. if(this.staticAppList[i].category === this.appsCategory) {
  231. this.appList.push(this.staticAppList[i]);
  232. }
  233. }
  234. }
  235. this.cdr.detectChanges();
  236. }
  237. }