Просмотр исходного кода

Show delivery mode on admin and teacher schedule cards

彭峰 14 часов назад
Родитель
Сommit
75e518741a

+ 51 - 0
projects/shared/ui/lesson-delivery-badge.component.ts

@@ -0,0 +1,51 @@
+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';
+  });
+}

+ 2 - 2
projects/xiaoshu-admin/src/app/pages/operations-schedule.component.html

@@ -93,9 +93,9 @@
     </tbody></table></div>
   } @else {
     <div class="table-scroll"><div class="calendar">
-      @for(coach of visibleCoaches();track coach.userId){<div class="calendar-row"><div class="coach-label"><strong>{{coach.displayName}}</strong><span>当前 {{visibleCoachCount(coach.userId)}} 节排课</span>@if(!coach.availabilityConfigured){<span class="exception">未设置可用时间</span>}</div><div class="appointment-strip">@for(item of visibleAppointments();track item.targetId){@if(item.coachId===coach.userId&&!item.coachAccountMissing){<button type="button" class="appointment" [ngClass]="statusTone(item)" (click)="openDetails(item)"><strong>{{item.startsAt|date:'MM-dd HH:mm'}} {{item.studentName}}</strong><span>{{item.courseName}}</span><small>{{item.classTypeLabel}} · {{statusDisplayLabel(item)}}@if(item.readOnly){ · 实时}</small></button>}}</div></div>}
+      @for(coach of visibleCoaches();track coach.userId){<div class="calendar-row"><div class="coach-label"><strong>{{coach.displayName}}</strong><span>当前 {{visibleCoachCount(coach.userId)}} 节排课</span>@if(!coach.availabilityConfigured){<span class="exception">未设置可用时间</span>}</div><div class="appointment-strip">@for(item of visibleAppointments();track item.targetId){@if(item.coachId===coach.userId&&!item.coachAccountMissing){<button type="button" class="appointment" [ngClass]="statusTone(item)" (click)="openDetails(item)"><strong>{{item.startsAt|date:'MM-dd HH:mm'}} {{item.studentName}}</strong><span>{{item.courseName}}</span><div class="appointment-meta"><small>{{item.classTypeLabel}} · {{statusDisplayLabel(item)}}@if(item.readOnly){ · 实时}</small><app-lesson-delivery-badge [mode]="item.deliveryMode" [legacyLabel]="item.deliveryMethod" /></div></button>}}</div></div>}
       @empty{<div class="empty">{{error()?'课表未能加载,请重试':'当前范围暂无已排课的陪练'}}</div>}
-      @if(unassignedCount()){<div class="calendar-row"><div class="coach-label"><strong>待分配 / 历史账号</strong><span>{{data()?unassignedCount():'—'}} 节</span></div><div class="appointment-strip">@for(item of visibleAppointments();track item.targetId){@if(!item.coachId||item.coachAccountMissing){<button type="button" class="appointment" [ngClass]="statusTone(item)" (click)="openDetails(item)"><strong>{{item.startsAt|date:'MM-dd HH:mm'}} {{item.studentName}}</strong><span>{{item.coachAccountMissing?item.coachName:'未分配陪练'}}</span><small>{{item.classTypeLabel}} · {{statusDisplayLabel(item)}}</small></button>}}</div></div>}
+      @if(unassignedCount()){<div class="calendar-row"><div class="coach-label"><strong>待分配 / 历史账号</strong><span>{{data()?unassignedCount():'—'}} 节</span></div><div class="appointment-strip">@for(item of visibleAppointments();track item.targetId){@if(!item.coachId||item.coachAccountMissing){<button type="button" class="appointment" [ngClass]="statusTone(item)" (click)="openDetails(item)"><strong>{{item.startsAt|date:'MM-dd HH:mm'}} {{item.studentName}}</strong><span>{{item.coachAccountMissing?item.coachName:'未分配陪练'}}</span><div class="appointment-meta"><small>{{item.classTypeLabel}} · {{statusDisplayLabel(item)}}</small><app-lesson-delivery-badge [mode]="item.deliveryMode" [legacyLabel]="item.deliveryMethod" /></div></button>}}</div></div>}
     </div></div>
   }
 </section>

+ 7 - 0
projects/xiaoshu-admin/src/app/pages/operations-schedule.component.scss

@@ -472,6 +472,13 @@ textarea:focus-visible {
   text-align: left;
 }
 
+.appointment-meta {
+  display: flex;
+  flex-wrap: wrap;
+  align-items: center;
+  gap: 4px 8px;
+}
+
 .live-source,
 .read-only-label {
   display: block;

+ 10 - 0
projects/xiaoshu-admin/src/app/pages/operations-schedule.component.spec.ts

@@ -325,6 +325,16 @@ describe('排课页面复用后的会员与开课数据', () => {
     fixture=TestBed.createComponent(OperationsScheduleComponent);fixture.detectChanges();await fixture.whenStable();
   });
   afterEach(()=>fixture.destroy());
+  it('在普通和待分配的排课卡片上显示交付方式', () => {
+    const assigned = { targetId: 'online', coachId: 10, statusCode: 0, deliveryMode: 'online', studentName: '在线学员' } as ScheduleAppointment;
+    const unassigned = { ...assigned, targetId: 'offline', coachId: 0, deliveryMode: undefined, deliveryMethod: '到店面授', studentName: '到店学员' } as ScheduleAppointment;
+    fixture.componentInstance.data.set({ ...empty(), appointments: [assigned, unassigned],
+      coaches: [{userId: 10, displayName: '有课老师'}] as ScheduleCalendarData['coaches'], unassigned: [unassigned] });
+    fixture.detectChanges();
+    const badges = Array.from(fixture.nativeElement.querySelectorAll('.appointment .delivery-badge') as NodeListOf<HTMLElement>);
+    expect(badges.map(badge => badge.textContent?.trim())).toEqual(['线上', '线下']);
+    expect(badges.every(badge => badge.querySelector('svg'))).toBeTrue();
+  });
   function navigateToMember():void {route.snapshot.queryParamMap=convertToParamMap({studentId:'1935'});params.next(route.snapshot.queryParamMap);}
   it('离开期间新增会员、充值和开课后,返回更新候选;普通返回不重复读取', fakeAsync(() => {
     fixture.componentInstance.onOperationsRouteAttach();flushMicrotasks();expect(schedule).toHaveBeenCalledTimes(1);

+ 2 - 1
projects/xiaoshu-admin/src/app/pages/operations-schedule.component.ts

@@ -17,6 +17,7 @@ import { SCHEDULE_COURSE_STANDARDS } from './schedule-course-standards';
 import { OperationsService } from '../operations.service';
 import { OperationsLiveRefreshService } from '../operations-live-refresh.service';
 import { ScheduleStatusFilter, ScheduleStatusTone, scheduleMatchesStatus, scheduleStatusLabel, scheduleStatusTone } from './operations-schedule-status';
+import { LessonDeliveryBadgeComponent } from '../../../../shared/ui/lesson-delivery-badge.component';
 
 const localDateKey=(value:Date):string=>`${value.getFullYear()}-${String(value.getMonth()+1).padStart(2,'0')}-${String(value.getDate()).padStart(2,'0')}`;
 
@@ -132,7 +133,7 @@ export function scheduleCoachBusy(
   });
 }
 
-@Component({ selector:'app-operations-schedule', host:{class:'schedule-ui'}, standalone:true, imports: [ScheduleBulkManagerComponent,MemberEnrollmentComponent,LessonRecordDetailComponent,AnchoredMenuDirective, DropdownDirective, CommonModule,FormsModule,LucideAngularModule,OperationsDateFilterComponent], templateUrl:'./operations-schedule.component.html', styleUrls:['./operations-professional.scss','./operations-schedule.component.scss'], changeDetection:ChangeDetectionStrategy.OnPush })
+@Component({ selector:'app-operations-schedule', host:{class:'schedule-ui'}, standalone:true, imports: [ScheduleBulkManagerComponent,MemberEnrollmentComponent,LessonRecordDetailComponent,AnchoredMenuDirective, DropdownDirective, CommonModule,FormsModule,LucideAngularModule,LessonDeliveryBadgeComponent,OperationsDateFilterComponent], templateUrl:'./operations-schedule.component.html', styleUrls:['./operations-professional.scss','./operations-schedule.component.scss'], changeDetection:ChangeDetectionStrategy.OnPush })
 export class OperationsScheduleComponent implements OnInit, OnDestroy {
   readonly bulkManagerOpen=signal(false);
   readonly data=signal<ScheduleCalendarData|null>(null); readonly loading=signal(true); readonly saving=signal(false); readonly error=signal(''); readonly message=signal(''); readonly drawerOpen=signal(false); readonly lessonAppointmentId=signal(''); readonly feedback=signal<Record<string,unknown>|null>(null); readonly detail=signal<ScheduleAppointment|null>(null); readonly cancelReason=signal(''); readonly detailError=signal(''); readonly editing=signal<ScheduleAppointment|null>(null); readonly mode=signal<'coach'|'time'>('coach'); readonly view=signal<'day'|'week'|'list'>('day'); readonly date=signal(localDateKey(new Date())); readonly coachFilter=signal(0);

+ 5 - 1
projects/xiaoshu-mobile/src/app/features/course-center/course-center-page.component.html

@@ -126,7 +126,11 @@
             @for (item of group.items; track $index) {
               <article [class.has-lesson-pay]="isHistory && isCoach && (!item['cancelled'] || legacyHistoryLesson(item))" [attr.data-schedule-id]="scheduleId(item)" (click)="open(item, $event)">
                 @if (historyOrder()) { <div class="record-time"><span class="record-number" [attr.aria-label]="'序号 ' + recordNumber(item)">{{ recordNumber(item) }}</span><time>{{ scheduleTime(item) }}</time></div> } @else { <time>{{ scheduleTime(item) }}</time> }
-                <div class="schedule-copy"><strong>{{ scheduleTitle(item) }}</strong>@if (scheduleSubtitle(item)) { <span>{{ scheduleSubtitle(item) }}</span> }</div>
+                <div class="schedule-copy">
+                  <strong>{{ scheduleTitle(item) }}</strong>
+                  @if (scheduleSubtitle(item)) { <span>{{ scheduleSubtitle(item) }}</span> }
+                  @if (isCoach) { <app-lesson-delivery-badge [mode]="item['deliveryMode']" [legacyLabel]="item['jffs']" /> }
+                </div>
                 @if (isHistory && isCoach && (!item['cancelled'] || legacyHistoryLesson(item))) { <div class="lesson-pay"><strong>{{ item['payStatus'] === 'earned' ? '陪练费用 ¥' + ($any(item['teacherPay']) | number:'1.2-2') : '费用待核对' }}</strong>@if (!legacyHistoryLesson(item)) { <small [class.feedback-pending]="item['feedbackStatus'] !== 'submitted'">{{item['feedbackStatus']==='submitted'?'反馈已提交':'反馈待补'}}</small> }</div> }
                 <span class="status" [class]="'status ' + statusClass(item)">{{ statusText(item) }}</span>
                 @if (isCoach) { <button type="button" class="report-button" (click)="report(item, $event)" aria-label="学习报表" title="学习报表"><lucide-icon [img]="icons.BarChart3" [size]="18" /></button> }

+ 20 - 0
projects/xiaoshu-mobile/src/app/features/course-center/course-center-page.component.spec.ts

@@ -71,6 +71,26 @@ describe('CourseCenterPageComponent live appointment refresh', () => {
 
     fixture.destroy();
   }));
+
+  for (const path of ['pages/home/shop', 'pages/member/ke_xiao']) {
+    it(`在 ${path} 显示标准交付方式和旧记录的线下方式`, () => {
+      TestBed.inject(ActivatedRoute).snapshot.data['meta'] = { path };
+      const fixture = TestBed.createComponent(CourseCenterPageComponent);
+      const page = fixture.componentInstance;
+      fixture.detectChanges();
+      const date = page.selectedDate();
+      page.schedules.set([
+        { GeneralID: 10, Title: '在线学员', bxrq: date, dszt: 30, deliveryMode: 'online' },
+        { GeneralID: 11, Title: '上门学员', bxrq: date, dszt: 30, jffs: '上门' },
+        { GeneralID: 12, Title: '老学员', bxrq: date, dszt: 30 },
+      ]);
+      fixture.detectChanges();
+      const badges = Array.from(fixture.nativeElement.querySelectorAll('.schedule-copy .delivery-badge') as NodeListOf<HTMLElement>);
+      expect(badges.map(badge => badge.textContent?.trim()).sort()).toEqual(['线上', '线下'].sort());
+      expect(badges.every(badge => badge.querySelector('svg'))).toBeTrue();
+      fixture.destroy();
+    });
+  }
 });
 
 function companionOverview(title: string, directPullSucceeded = true) {

+ 2 - 1
projects/xiaoshu-mobile/src/app/features/course-center/course-center-page.component.ts

@@ -14,6 +14,7 @@ import { LiveDataRefreshService, LiveSyncStatus } from '../../core/live-data-ref
 import { AppUser, PageMeta } from '../../core/models';
 import { PlatformService } from '../../core/platform.service';
 import { SessionService } from '../../core/session.service';
+import { LessonDeliveryBadgeComponent } from '../../../../../shared/ui/lesson-delivery-badge.component';
 
 type Item = Record<string, unknown>;
 type ScheduleFilter = 'all' | 'pending' | 'finished';
@@ -56,7 +57,7 @@ interface CompanionOverview {
 @Component({
   selector: 'app-course-center-page',
   standalone: true,
-  imports: [DropdownDirective, CommonModule, FormsModule, LucideAngularModule],
+  imports: [DropdownDirective, CommonModule, FormsModule, LucideAngularModule, LessonDeliveryBadgeComponent],
   templateUrl: './course-center-page.component.html',
   styleUrl: './course-center-page.component.scss',
   changeDetection: ChangeDetectionStrategy.OnPush,

Разница между файлами не показана из-за своего большого размера
+ 1 - 1
scripts/deploy-admin-functions.mjs


+ 28 - 0
scripts/tests/legacy-appointment-pull.test.mjs

@@ -8,6 +8,34 @@ const source = gatewaySource.match(/const LEGACY_APPOINTMENT_PULLS=new Map\(\),L
   .replace(/\nconst APP_LIVE_SCOPES=[\s\S]*$/, '');
 assert.ok(source, '未找到旧系统预约拉取实现');
 
+test('老师排课和运营排课投影保留交付方式,并识别历史线下标签', () => {
+  const pick = name => gatewaySource.match(new RegExp('function '+name+'\\(.*?\\) \\{[\\s\\S]*?\\n\\}'))?.[0];
+  const mobile = vm.createContext({ number: Number, firstValue: (...values) => values.find(value => value != null && value !== '') });
+  vm.runInContext(pick('appOverviewScheduleRow'), mobile);
+  const booking = { generalId: 12, deliveryMode: 'offline', jffs: '线下' };
+  assert.equal(mobile.appOverviewScheduleRow(booking).deliveryMode, 'offline');
+  assert.equal(mobile.appOverviewScheduleRow({ ...booking, deliveryMode: undefined, jffs: '上门' }).jffs, '上门');
+
+  const admin = vm.createContext({
+    number: (value, fallback = 0) => Number(value ?? fallback),
+    text: value => String(value ?? '').trim(),
+    appointmentDate: () => new Date('2026-12-02T00:00:00Z'),
+    durationMinutes: () => 60,
+    legacyOf: () => ({}),
+    classType: () => '60 分钟',
+    statusLabel: () => '待开始',
+    dateIso: () => '',
+  });
+  const deliveryFunctions = gatewaySource.match(/function deliveryMode\([^\n]+\nfunction deliveryLabel\([^\n]+/)?.[0];
+  vm.runInContext(deliveryFunctions+'\n'+pick('appointmentProjection'), admin);
+  assert.equal(admin.appointmentProjection({ ...booking, deliveryMode: 'online' }).deliveryMode, 'online');
+  assert.equal(admin.appointmentProjection({ jffs: '线上' }).deliveryMode, 'online');
+  for (const jffs of ['线下', '上门', '机构']) {
+    assert.equal(admin.appointmentProjection({ jffs }).deliveryMode, 'offline');
+  }
+  assert.equal(admin.appointmentProjection({}).deliveryMode, undefined);
+});
+
 function contextFor(rows) {
   const context = {
     console,

Некоторые файлы не были показаны из-за большого количества измененных файлов