| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core';
- import { LucideAngularModule, MapPin, Video } from 'lucide-angular';
- @Component({
- selector: 'app-lesson-delivery-badge',
- imports: [LucideAngularModule],
- changeDetection: ChangeDetectionStrategy.OnPush,
- host: { '[hidden]': '!delivery()' },
- template: `
- @if (delivery(); as value) {
- <span class="delivery-badge" [class.offline]="value === 'offline'">
- <lucide-icon [img]="value === 'offline' ? pinIcon : videoIcon" [size]="13" aria-hidden="true" />
- {{ value === 'offline' ? '线下' : '线上' }}
- </span>
- }
- `,
- styles: `
- :host { display: inline-flex; align-self: flex-start; max-width: 100%; }
- :host([hidden]) { display: none; }
- .delivery-badge {
- display: inline-flex;
- align-items: center;
- gap: 0.25em;
- padding: 0.15em 0.45em;
- border-radius: 0.35em;
- background: #e2eefb;
- color: #214f7a;
- font-size: 0.75em;
- font-weight: 650;
- line-height: 1.35;
- white-space: nowrap;
- }
- .delivery-badge.offline { background: #e4f2e9; color: #246245; }
- lucide-icon { display: inline-flex; flex: none; }
- `,
- })
- export class LessonDeliveryBadgeComponent {
- readonly mode = input<unknown>();
- readonly legacyLabel = input<unknown>();
- protected readonly pinIcon = MapPin;
- protected readonly videoIcon = Video;
- protected readonly delivery = computed(() => {
- const mode = String(this.mode() ?? '').trim().toLowerCase();
- if (mode === 'online' || mode === 'offline') return mode;
- const label = String(this.legacyLabel() ?? '').trim().toLowerCase();
- const online = /线上|在线|远程/.test(label) || label === 'online';
- const offline = /线下|到店|面授/.test(label) || /^(offline|机构|上门)$/.test(label);
- return online === offline ? null : offline ? 'offline' : 'online';
- });
- }
|