lesson-delivery-badge.component.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
  2. import { LucideAngularModule, MapPin, Video } from 'lucide-angular';
  3. @Component({
  4. selector: 'app-lesson-delivery-badge',
  5. imports: [LucideAngularModule],
  6. changeDetection: ChangeDetectionStrategy.OnPush,
  7. host: { '[hidden]': '!delivery()' },
  8. template: `
  9. @if (delivery(); as value) {
  10. <span class="delivery-badge" [class.offline]="value === 'offline'">
  11. <lucide-icon [img]="value === 'offline' ? pinIcon : videoIcon" [size]="13" aria-hidden="true" />
  12. {{ value === 'offline' ? '线下' : '线上' }}
  13. </span>
  14. }
  15. `,
  16. styles: `
  17. :host { display: inline-flex; align-self: flex-start; max-width: 100%; }
  18. :host([hidden]) { display: none; }
  19. .delivery-badge {
  20. display: inline-flex;
  21. align-items: center;
  22. gap: 0.25em;
  23. padding: 0.15em 0.45em;
  24. border-radius: 0.35em;
  25. background: #e2eefb;
  26. color: #214f7a;
  27. font-size: 0.75em;
  28. font-weight: 650;
  29. line-height: 1.35;
  30. white-space: nowrap;
  31. }
  32. .delivery-badge.offline { background: #e4f2e9; color: #246245; }
  33. lucide-icon { display: inline-flex; flex: none; }
  34. `,
  35. })
  36. export class LessonDeliveryBadgeComponent {
  37. readonly mode = input<unknown>();
  38. readonly legacyLabel = input<unknown>();
  39. protected readonly pinIcon = MapPin;
  40. protected readonly videoIcon = Video;
  41. protected readonly delivery = computed(() => {
  42. const mode = String(this.mode() ?? '').trim().toLowerCase();
  43. if (mode === 'online' || mode === 'offline') return mode;
  44. const label = String(this.legacyLabel() ?? '').trim().toLowerCase();
  45. const online = /线上|在线|远程/.test(label) || label === 'online';
  46. const offline = /线下|到店|面授/.test(label) || /^(offline|机构|上门)$/.test(label);
  47. return online === offline ? null : offline ? 'offline' : 'online';
  48. });
  49. }