数据可视化大屏
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

trigger.component.ts 1.2KB

1 vuosi sitten
123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import { Component, inject } from '@angular/core';
  2. import { DA_SERVICE_TOKEN } from '@delon/auth';
  3. import { _HttpClient } from '@delon/theme';
  4. import { NzButtonModule } from 'ng-zorro-antd/button';
  5. import { NzCardModule } from 'ng-zorro-antd/card';
  6. @Component({
  7. selector: 'exception-trigger',
  8. template: `
  9. <div class="pt-lg">
  10. <nz-card>
  11. @for (t of types; track $index) {
  12. <button (click)="go(t)" nz-button nzDanger>触发{{ t }}</button>
  13. }
  14. <button nz-button nzType="link" (click)="refresh()">触发刷新Token</button>
  15. </nz-card>
  16. </div>
  17. `,
  18. standalone: true,
  19. imports: [NzCardModule, NzButtonModule]
  20. })
  21. export class ExceptionTriggerComponent {
  22. private readonly http = inject(_HttpClient);
  23. private readonly tokenService = inject(DA_SERVICE_TOKEN);
  24. types = [401, 403, 404, 500];
  25. go(type: number): void {
  26. this.http.get(`/api/${type}`).subscribe();
  27. }
  28. refresh(): void {
  29. this.tokenService.set({ token: 'invalid-token' });
  30. // 必须提供一个后端地址,无法通过 Mock 来模拟
  31. this.http.post(`https://localhost:5001/auth`).subscribe({
  32. next: res => console.warn('成功', res),
  33. error: err => {
  34. console.log('最后结果失败', err);
  35. }
  36. });
  37. }
  38. }