Merge branch 'main' of http://113.45.157.195:3003/insiinc/re-mooc
This commit is contained in:
commit
09a23e3f1e
|
@ -4,16 +4,19 @@ import { AppConfigService } from './app-config.service';
|
||||||
import { z, ZodType } from 'zod';
|
import { z, ZodType } from 'zod';
|
||||||
import { Prisma } from '@nice/common';
|
import { Prisma } from '@nice/common';
|
||||||
import { RealtimeServer } from '@server/socket/realtime/realtime.server';
|
import { RealtimeServer } from '@server/socket/realtime/realtime.server';
|
||||||
const AppConfigUncheckedCreateInputSchema: ZodType<Prisma.AppConfigUncheckedCreateInput> = z.any()
|
const AppConfigUncheckedCreateInputSchema: ZodType<Prisma.AppConfigUncheckedCreateInput> =
|
||||||
const AppConfigUpdateArgsSchema: ZodType<Prisma.AppConfigUpdateArgs> = z.any()
|
z.any();
|
||||||
const AppConfigDeleteManyArgsSchema: ZodType<Prisma.AppConfigDeleteManyArgs> = z.any()
|
const AppConfigUpdateArgsSchema: ZodType<Prisma.AppConfigUpdateArgs> = z.any();
|
||||||
const AppConfigFindFirstArgsSchema: ZodType<Prisma.AppConfigFindFirstArgs> = z.any()
|
const AppConfigDeleteManyArgsSchema: ZodType<Prisma.AppConfigDeleteManyArgs> =
|
||||||
|
z.any();
|
||||||
|
const AppConfigFindFirstArgsSchema: ZodType<Prisma.AppConfigFindFirstArgs> =
|
||||||
|
z.any();
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppConfigRouter {
|
export class AppConfigRouter {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly trpc: TrpcService,
|
private readonly trpc: TrpcService,
|
||||||
private readonly appConfigService: AppConfigService,
|
private readonly appConfigService: AppConfigService,
|
||||||
private readonly realtimeServer: RealtimeServer
|
private readonly realtimeServer: RealtimeServer,
|
||||||
) {}
|
) {}
|
||||||
router = this.trpc.router({
|
router = this.trpc.router({
|
||||||
create: this.trpc.protectProcedure
|
create: this.trpc.protectProcedure
|
||||||
|
@ -25,23 +28,24 @@ export class AppConfigRouter {
|
||||||
update: this.trpc.protectProcedure
|
update: this.trpc.protectProcedure
|
||||||
.input(AppConfigUpdateArgsSchema)
|
.input(AppConfigUpdateArgsSchema)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
return await this.appConfigService.update(input);
|
return await this.appConfigService.update(input);
|
||||||
}),
|
}),
|
||||||
deleteMany: this.trpc.protectProcedure.input(AppConfigDeleteManyArgsSchema).mutation(async ({ input }) => {
|
deleteMany: this.trpc.protectProcedure
|
||||||
return await this.appConfigService.deleteMany(input)
|
.input(AppConfigDeleteManyArgsSchema)
|
||||||
|
.mutation(async ({ input }) => {
|
||||||
|
return await this.appConfigService.deleteMany(input);
|
||||||
}),
|
}),
|
||||||
findFirst: this.trpc.protectProcedure.input(AppConfigFindFirstArgsSchema).
|
findFirst: this.trpc.protectProcedure
|
||||||
query(async ({ input }) => {
|
.input(AppConfigFindFirstArgsSchema)
|
||||||
|
.query(async ({ input }) => {
|
||||||
return await this.appConfigService.findFirst(input)
|
return await this.appConfigService.findFirst(input);
|
||||||
}),
|
}),
|
||||||
clearRowCache: this.trpc.protectProcedure.mutation(async () => {
|
clearRowCache: this.trpc.protectProcedure.mutation(async () => {
|
||||||
return await this.appConfigService.clearRowCache()
|
return await this.appConfigService.clearRowCache();
|
||||||
}),
|
}),
|
||||||
getClientCount: this.trpc.protectProcedure.query(() => {
|
getClientCount: this.trpc.protectProcedure.query(() => {
|
||||||
return this.realtimeServer.getClientCount()
|
return this.realtimeServer.getClientCount();
|
||||||
})
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import {
|
import { db, ObjectType, Prisma } from '@nice/common';
|
||||||
db,
|
|
||||||
ObjectType,
|
|
||||||
Prisma,
|
|
||||||
} from '@nice/common';
|
|
||||||
|
|
||||||
|
|
||||||
import { BaseService } from '../base/base.service';
|
import { BaseService } from '../base/base.service';
|
||||||
import { deleteByPattern } from '@server/utils/redis/utils';
|
import { deleteByPattern } from '@server/utils/redis/utils';
|
||||||
|
@ -12,10 +7,10 @@ import { deleteByPattern } from '@server/utils/redis/utils';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppConfigService extends BaseService<Prisma.AppConfigDelegate> {
|
export class AppConfigService extends BaseService<Prisma.AppConfigDelegate> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(db, "appConfig");
|
super(db, 'appConfig');
|
||||||
}
|
}
|
||||||
async clearRowCache() {
|
async clearRowCache() {
|
||||||
await deleteByPattern("row-*")
|
await deleteByPattern('row-*');
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { db, Prisma, PrismaClient } from "@nice/common";
|
import { db, Prisma, PrismaClient } from '@nice/common';
|
||||||
|
|
||||||
export type Operations =
|
export type Operations =
|
||||||
| 'aggregate'
|
| 'aggregate'
|
||||||
|
@ -13,7 +13,9 @@ export type Operations =
|
||||||
| 'update'
|
| 'update'
|
||||||
| 'updateMany'
|
| 'updateMany'
|
||||||
| 'upsert';
|
| 'upsert';
|
||||||
export type DelegateFuncs = { [K in Operations]: (args: any) => Promise<unknown> }
|
export type DelegateFuncs = {
|
||||||
|
[K in Operations]: (args: any) => Promise<unknown>;
|
||||||
|
};
|
||||||
export type DelegateArgs<T> = {
|
export type DelegateArgs<T> = {
|
||||||
[K in keyof T]: T[K] extends (args: infer A) => Promise<any> ? A : never;
|
[K in keyof T]: T[K] extends (args: infer A) => Promise<any> ? A : never;
|
||||||
};
|
};
|
||||||
|
@ -28,15 +30,15 @@ export type DataArgs<T> = T extends { data: infer D } ? D : never;
|
||||||
export type IncludeArgs<T> = T extends { include: infer I } ? I : never;
|
export type IncludeArgs<T> = T extends { include: infer I } ? I : never;
|
||||||
export type OrderByArgs<T> = T extends { orderBy: infer O } ? O : never;
|
export type OrderByArgs<T> = T extends { orderBy: infer O } ? O : never;
|
||||||
export type UpdateOrderArgs = {
|
export type UpdateOrderArgs = {
|
||||||
id: string
|
id: string;
|
||||||
overId: string
|
overId: string;
|
||||||
}
|
};
|
||||||
export interface FindManyWithCursorType<T extends DelegateFuncs> {
|
export interface FindManyWithCursorType<T extends DelegateFuncs> {
|
||||||
cursor?: string;
|
cursor?: string;
|
||||||
limit?: number;
|
limit?: number;
|
||||||
where?: WhereArgs<DelegateArgs<T>['findUnique']>;
|
where?: WhereArgs<DelegateArgs<T>['findUnique']>;
|
||||||
select?: SelectArgs<DelegateArgs<T>['findUnique']>;
|
select?: SelectArgs<DelegateArgs<T>['findUnique']>;
|
||||||
orderBy?: OrderByArgs<DelegateArgs<T>['findMany']>
|
orderBy?: OrderByArgs<DelegateArgs<T>['findMany']>;
|
||||||
}
|
}
|
||||||
export type TransactionType = Omit<
|
export type TransactionType = Omit<
|
||||||
PrismaClient,
|
PrismaClient,
|
||||||
|
|
|
@ -3,8 +3,10 @@ import { TrpcService } from '@server/trpc/trpc.service';
|
||||||
import { CourseMethodSchema, Prisma } from '@nice/common';
|
import { CourseMethodSchema, Prisma } from '@nice/common';
|
||||||
import { PostService } from './post.service';
|
import { PostService } from './post.service';
|
||||||
import { z, ZodType } from 'zod';
|
import { z, ZodType } from 'zod';
|
||||||
|
import { UpdateOrderArgs } from '../base/base.type';
|
||||||
const PostCreateArgsSchema: ZodType<Prisma.PostCreateArgs> = z.any();
|
const PostCreateArgsSchema: ZodType<Prisma.PostCreateArgs> = z.any();
|
||||||
const PostUpdateArgsSchema: ZodType<Prisma.PostUpdateArgs> = z.any();
|
const PostUpdateArgsSchema: ZodType<Prisma.PostUpdateArgs> = z.any();
|
||||||
|
const PostUpdateOrderArgsSchema: ZodType<UpdateOrderArgs> = z.any();
|
||||||
const PostFindFirstArgsSchema: ZodType<Prisma.PostFindFirstArgs> = z.any();
|
const PostFindFirstArgsSchema: ZodType<Prisma.PostFindFirstArgs> = z.any();
|
||||||
const PostFindManyArgsSchema: ZodType<Prisma.PostFindManyArgs> = z.any();
|
const PostFindManyArgsSchema: ZodType<Prisma.PostFindManyArgs> = z.any();
|
||||||
const PostDeleteManyArgsSchema: ZodType<Prisma.PostDeleteManyArgs> = z.any();
|
const PostDeleteManyArgsSchema: ZodType<Prisma.PostDeleteManyArgs> = z.any();
|
||||||
|
@ -107,5 +109,21 @@ export class PostRouter {
|
||||||
.query(async ({ input }) => {
|
.query(async ({ input }) => {
|
||||||
return await this.postService.findManyWithPagination(input);
|
return await this.postService.findManyWithPagination(input);
|
||||||
}),
|
}),
|
||||||
|
updateOrder: this.trpc.protectProcedure
|
||||||
|
.input(PostUpdateOrderArgsSchema)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const { staff } = ctx;
|
||||||
|
return await this.postService.updateOrder(input);
|
||||||
|
}),
|
||||||
|
updateOrderByIds: this.trpc.protectProcedure
|
||||||
|
.input(
|
||||||
|
z.object({
|
||||||
|
ids: z.array(z.string()),
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const { staff } = ctx;
|
||||||
|
return await this.postService.updateOrderByIds(input.ids);
|
||||||
|
}),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import EventBus, { CrudOperation } from '@server/utils/event-bus';
|
||||||
import { BaseTreeService } from '../base/base.tree.service';
|
import { BaseTreeService } from '../base/base.tree.service';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { DefaultArgs } from '@prisma/client/runtime/library';
|
import { DefaultArgs } from '@prisma/client/runtime/library';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||||
|
@ -43,13 +44,14 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||||
content: content,
|
content: content,
|
||||||
title: title,
|
title: title,
|
||||||
authorId: params?.staff?.id,
|
authorId: params?.staff?.id,
|
||||||
|
updatedAt: dayjs().toDate(),
|
||||||
resources: {
|
resources: {
|
||||||
connect: resourceIds.map((fileId) => ({ fileId })),
|
connect: resourceIds.map((fileId) => ({ fileId })),
|
||||||
},
|
},
|
||||||
meta: {
|
meta: {
|
||||||
type: type,
|
type: type,
|
||||||
},
|
},
|
||||||
},
|
} as any,
|
||||||
},
|
},
|
||||||
{ tx },
|
{ tx },
|
||||||
);
|
);
|
||||||
|
@ -71,7 +73,8 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||||
parentId: courseId,
|
parentId: courseId,
|
||||||
title: title,
|
title: title,
|
||||||
authorId: staff?.id,
|
authorId: staff?.id,
|
||||||
},
|
updatedAt: dayjs().toDate(),
|
||||||
|
} as any,
|
||||||
},
|
},
|
||||||
{ tx },
|
{ tx },
|
||||||
);
|
);
|
||||||
|
@ -95,11 +98,15 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||||
async createCourse(
|
async createCourse(
|
||||||
args: {
|
args: {
|
||||||
courseDetail: Prisma.PostCreateArgs;
|
courseDetail: Prisma.PostCreateArgs;
|
||||||
sections?: z.infer<typeof CourseMethodSchema.createSection>[];
|
|
||||||
},
|
},
|
||||||
params: { staff?: UserProfile; tx?: Prisma.TransactionClient },
|
params: { staff?: UserProfile; tx?: Prisma.TransactionClient },
|
||||||
) {
|
) {
|
||||||
const { courseDetail, sections } = args;
|
// const await db.post.findMany({
|
||||||
|
// where: {
|
||||||
|
// type: PostType.COURSE,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
|
const { courseDetail } = args;
|
||||||
// If no transaction is provided, create a new one
|
// If no transaction is provided, create a new one
|
||||||
if (!params.tx) {
|
if (!params.tx) {
|
||||||
return await db.$transaction(async (tx) => {
|
return await db.$transaction(async (tx) => {
|
||||||
|
@ -109,20 +116,6 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||||
console.log('courseDetail', courseDetail);
|
console.log('courseDetail', courseDetail);
|
||||||
const createdCourse = await this.create(courseDetail, courseParams);
|
const createdCourse = await this.create(courseDetail, courseParams);
|
||||||
// If sections are provided, create them
|
// If sections are provided, create them
|
||||||
if (sections && sections.length > 0) {
|
|
||||||
const sectionPromises = sections.map((section) =>
|
|
||||||
this.createSection(
|
|
||||||
{
|
|
||||||
courseId: createdCourse.id,
|
|
||||||
title: section.title,
|
|
||||||
lectures: section.lectures,
|
|
||||||
},
|
|
||||||
courseParams,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// Create all sections (and their lectures) in parallel
|
|
||||||
await Promise.all(sectionPromises);
|
|
||||||
}
|
|
||||||
return createdCourse;
|
return createdCourse;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -130,21 +123,6 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||||
console.log('courseDetail', courseDetail);
|
console.log('courseDetail', courseDetail);
|
||||||
const createdCourse = await this.create(courseDetail, params);
|
const createdCourse = await this.create(courseDetail, params);
|
||||||
// If sections are provided, create them
|
// If sections are provided, create them
|
||||||
if (sections && sections.length > 0) {
|
|
||||||
const sectionPromises = sections.map((section) =>
|
|
||||||
this.createSection(
|
|
||||||
{
|
|
||||||
courseId: createdCourse.id,
|
|
||||||
title: section.title,
|
|
||||||
lectures: section.lectures,
|
|
||||||
},
|
|
||||||
params,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
// Create all sections (and their lectures) in parallel
|
|
||||||
await Promise.all(sectionPromises);
|
|
||||||
}
|
|
||||||
|
|
||||||
return createdCourse;
|
return createdCourse;
|
||||||
}
|
}
|
||||||
async create(
|
async create(
|
||||||
|
@ -152,6 +130,7 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||||
params?: { staff?: UserProfile; tx?: Prisma.TransactionClient },
|
params?: { staff?: UserProfile; tx?: Prisma.TransactionClient },
|
||||||
) {
|
) {
|
||||||
args.data.authorId = params?.staff?.id;
|
args.data.authorId = params?.staff?.id;
|
||||||
|
args.data.updatedAt = dayjs().toDate();
|
||||||
const result = await super.create(args);
|
const result = await super.create(args);
|
||||||
EventBus.emit('dataChanged', {
|
EventBus.emit('dataChanged', {
|
||||||
type: ObjectType.POST,
|
type: ObjectType.POST,
|
||||||
|
@ -162,6 +141,7 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||||
}
|
}
|
||||||
async update(args: Prisma.PostUpdateArgs, staff?: UserProfile) {
|
async update(args: Prisma.PostUpdateArgs, staff?: UserProfile) {
|
||||||
args.data.authorId = staff?.id;
|
args.data.authorId = staff?.id;
|
||||||
|
args.data.updatedAt = dayjs().toDate();
|
||||||
const result = await super.update(args);
|
const result = await super.update(args);
|
||||||
EventBus.emit('dataChanged', {
|
EventBus.emit('dataChanged', {
|
||||||
type: ObjectType.POST,
|
type: ObjectType.POST,
|
||||||
|
@ -216,15 +196,68 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||||
return { ...result, items };
|
return { ...result, items };
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async findManyWithPagination(args:
|
async findManyWithPagination(args: {
|
||||||
{ page?: number;
|
page?: number;
|
||||||
pageSize?: number;
|
pageSize?: number;
|
||||||
where?: Prisma.PostWhereInput;
|
where?: Prisma.PostWhereInput;
|
||||||
select?: Prisma.PostSelect<DefaultArgs>;
|
select?: Prisma.PostSelect<DefaultArgs>;
|
||||||
}): Promise<{ items: { id: string; type: string | null; level: string | null; state: string | null; title: string | null; subTitle: string | null; content: string | null; important: boolean | null; domainId: string | null; order: number | null; duration: number | null; rating: number | null; createdAt: Date; publishedAt: Date | null; updatedAt: Date; deletedAt: Date | null; authorId: string | null; parentId: string | null; hasChildren: boolean | null; meta: Prisma.JsonValue | null; }[]; totalPages: number; }>
|
}): Promise<{
|
||||||
{
|
items: {
|
||||||
|
id: string;
|
||||||
|
type: string | null;
|
||||||
|
level: string | null;
|
||||||
|
state: string | null;
|
||||||
|
title: string | null;
|
||||||
|
subTitle: string | null;
|
||||||
|
content: string | null;
|
||||||
|
important: boolean | null;
|
||||||
|
domainId: string | null;
|
||||||
|
order: number | null;
|
||||||
|
duration: number | null;
|
||||||
|
rating: number | null;
|
||||||
|
createdAt: Date;
|
||||||
|
publishedAt: Date | null;
|
||||||
|
updatedAt: Date;
|
||||||
|
deletedAt: Date | null;
|
||||||
|
authorId: string | null;
|
||||||
|
parentId: string | null;
|
||||||
|
hasChildren: boolean | null;
|
||||||
|
meta: Prisma.JsonValue | null;
|
||||||
|
}[];
|
||||||
|
totalPages: number;
|
||||||
|
}> {
|
||||||
|
// super.updateOrder;
|
||||||
return super.findManyWithPagination(args);
|
return super.findManyWithPagination(args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async updateOrderByIds(ids: string[]) {
|
||||||
|
const posts = await db.post.findMany({
|
||||||
|
where: { id: { in: ids } },
|
||||||
|
select: { id: true, order: true },
|
||||||
|
});
|
||||||
|
const postMap = new Map(posts.map((post) => [post.id, post]));
|
||||||
|
const orderedPosts = ids
|
||||||
|
.map((id) => postMap.get(id))
|
||||||
|
.filter((post): post is { id: string; order: number } => !!post);
|
||||||
|
|
||||||
|
// 生成仅需更新的操作
|
||||||
|
const updates = orderedPosts
|
||||||
|
.map((post, index) => ({
|
||||||
|
id: post.id,
|
||||||
|
newOrder: index, // 按数组索引设置新顺序
|
||||||
|
currentOrder: post.order,
|
||||||
|
}))
|
||||||
|
.filter(({ newOrder, currentOrder }) => newOrder !== currentOrder)
|
||||||
|
.map(({ id, newOrder }) =>
|
||||||
|
db.post.update({
|
||||||
|
where: { id },
|
||||||
|
data: { order: newOrder },
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
// 批量执行更新
|
||||||
|
return updates.length > 0 ? await db.$transaction(updates) : [];
|
||||||
|
}
|
||||||
protected async setPerms(data: Post, staff?: UserProfile) {
|
protected async setPerms(data: Post, staff?: UserProfile) {
|
||||||
if (!staff) return;
|
if (!staff) return;
|
||||||
const perms: ResPerm = {
|
const perms: ResPerm = {
|
||||||
|
|
|
@ -137,6 +137,11 @@ export async function setCourseInfo({ data }: { data: Post }) {
|
||||||
id: true,
|
id: true,
|
||||||
descendant: true,
|
descendant: true,
|
||||||
},
|
},
|
||||||
|
orderBy: {
|
||||||
|
descendant: {
|
||||||
|
order: 'asc',
|
||||||
|
},
|
||||||
|
},
|
||||||
});
|
});
|
||||||
const descendants = ancestries.map((ancestry) => ancestry.descendant);
|
const descendants = ancestries.map((ancestry) => ancestry.descendant);
|
||||||
const sections: SectionDto[] = descendants
|
const sections: SectionDto[] = descendants
|
||||||
|
@ -156,12 +161,12 @@ export async function setCourseInfo({ data }: { data: Post }) {
|
||||||
sections.map((section) => section.id).includes(descendant.parentId)
|
sections.map((section) => section.id).includes(descendant.parentId)
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
const lectureCount = lectures?.length || 0;
|
||||||
sections.forEach((section) => {
|
sections.forEach((section) => {
|
||||||
section.lectures = lectures.filter(
|
section.lectures = lectures.filter(
|
||||||
(lecture) => lecture.parentId === section.id,
|
(lecture) => lecture.parentId === section.id,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
Object.assign(data, { sections });
|
Object.assign(data, { sections, lectureCount });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
Department,
|
Department,
|
||||||
getRandomElement,
|
getRandomElement,
|
||||||
getRandomElements,
|
getRandomElements,
|
||||||
|
PostType,
|
||||||
Staff,
|
Staff,
|
||||||
TaxonomySlug,
|
TaxonomySlug,
|
||||||
Term,
|
Term,
|
||||||
|
@ -14,6 +15,7 @@ import {
|
||||||
import EventBus from '@server/utils/event-bus';
|
import EventBus from '@server/utils/event-bus';
|
||||||
import { capitalizeFirstLetter, DevDataCounts, getCounts } from './utils';
|
import { capitalizeFirstLetter, DevDataCounts, getCounts } from './utils';
|
||||||
import { StaffService } from '@server/models/staff/staff.service';
|
import { StaffService } from '@server/models/staff/staff.service';
|
||||||
|
import dayjs from 'dayjs';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GenDevService {
|
export class GenDevService {
|
||||||
private readonly logger = new Logger(GenDevService.name);
|
private readonly logger = new Logger(GenDevService.name);
|
||||||
|
@ -22,7 +24,7 @@ export class GenDevService {
|
||||||
terms: Record<TaxonomySlug, Term[]> = {
|
terms: Record<TaxonomySlug, Term[]> = {
|
||||||
[TaxonomySlug.CATEGORY]: [],
|
[TaxonomySlug.CATEGORY]: [],
|
||||||
[TaxonomySlug.TAG]: [],
|
[TaxonomySlug.TAG]: [],
|
||||||
[TaxonomySlug.LEVEL]: []
|
[TaxonomySlug.LEVEL]: [],
|
||||||
};
|
};
|
||||||
depts: Department[] = [];
|
depts: Department[] = [];
|
||||||
domains: Department[] = [];
|
domains: Department[] = [];
|
||||||
|
@ -43,6 +45,7 @@ export class GenDevService {
|
||||||
await this.generateDepartments(3, 6);
|
await this.generateDepartments(3, 6);
|
||||||
await this.generateTerms(2, 6);
|
await this.generateTerms(2, 6);
|
||||||
await this.generateStaffs(4);
|
await this.generateStaffs(4);
|
||||||
|
await this.generateCourses(8);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
}
|
}
|
||||||
|
@ -58,6 +61,7 @@ export class GenDevService {
|
||||||
if (this.counts.termCount === 0) {
|
if (this.counts.termCount === 0) {
|
||||||
this.logger.log('Generate terms');
|
this.logger.log('Generate terms');
|
||||||
await this.createTerms(null, TaxonomySlug.CATEGORY, depth, count);
|
await this.createTerms(null, TaxonomySlug.CATEGORY, depth, count);
|
||||||
|
await this.createLevelTerm();
|
||||||
const domains = this.depts.filter((item) => item.isDomain);
|
const domains = this.depts.filter((item) => item.isDomain);
|
||||||
for (const domain of domains) {
|
for (const domain of domains) {
|
||||||
await this.createTerms(domain, TaxonomySlug.CATEGORY, depth, count);
|
await this.createTerms(domain, TaxonomySlug.CATEGORY, depth, count);
|
||||||
|
@ -139,6 +143,64 @@ export class GenDevService {
|
||||||
collectChildren(domainId);
|
collectChildren(domainId);
|
||||||
return children;
|
return children;
|
||||||
}
|
}
|
||||||
|
private async generateCourses(countPerCate: number = 3) {
|
||||||
|
const titleList = [
|
||||||
|
'计算机科学导论',
|
||||||
|
'数据结构与算法',
|
||||||
|
'网络安全',
|
||||||
|
'机器学习',
|
||||||
|
'数据库管理系统',
|
||||||
|
'Web开发',
|
||||||
|
'移动应用开发',
|
||||||
|
'人工智能',
|
||||||
|
'计算机网络',
|
||||||
|
'操作系统',
|
||||||
|
'数字信号处理',
|
||||||
|
'无线通信',
|
||||||
|
'信息论',
|
||||||
|
'密码学',
|
||||||
|
'计算机图形学',
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!this.counts.courseCount) {
|
||||||
|
this.logger.log('Generating courses...');
|
||||||
|
const depts = await db.department.findMany({
|
||||||
|
select: { id: true, name: true },
|
||||||
|
});
|
||||||
|
const cates = await db.term.findMany({
|
||||||
|
where: {
|
||||||
|
taxonomy: { slug: TaxonomySlug.CATEGORY },
|
||||||
|
},
|
||||||
|
select: { id: true, name: true },
|
||||||
|
});
|
||||||
|
const total = cates.length * countPerCate;
|
||||||
|
const levels = await db.term.findMany({
|
||||||
|
where: {
|
||||||
|
taxonomy: { slug: TaxonomySlug.LEVEL },
|
||||||
|
},
|
||||||
|
select: { id: true, name: true },
|
||||||
|
});
|
||||||
|
for (const cate of cates) {
|
||||||
|
for (let i = 0; i < countPerCate; i++) {
|
||||||
|
const randomTitle = `${titleList[Math.floor(Math.random() * titleList.length)]} ${Math.random().toString(36).substring(7)}`;
|
||||||
|
const randomLevelId =
|
||||||
|
levels[Math.floor(Math.random() * levels.length)].id;
|
||||||
|
const randomDeptId =
|
||||||
|
depts[Math.floor(Math.random() * depts.length)].id;
|
||||||
|
|
||||||
|
await this.createCourse(
|
||||||
|
randomTitle,
|
||||||
|
randomDeptId,
|
||||||
|
cate.id,
|
||||||
|
randomLevelId,
|
||||||
|
);
|
||||||
|
this.logger.log(
|
||||||
|
`Generated ${this.deptGeneratedCount}/${total} departments`,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
private async generateStaffs(countPerDept: number = 3) {
|
private async generateStaffs(countPerDept: number = 3) {
|
||||||
if (this.counts.staffCount === 1) {
|
if (this.counts.staffCount === 1) {
|
||||||
this.logger.log('Generating staffs...');
|
this.logger.log('Generating staffs...');
|
||||||
|
@ -174,7 +236,59 @@ export class GenDevService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private async createLevelTerm() {
|
||||||
|
try {
|
||||||
|
// 1. 获取分类时添加异常处理
|
||||||
|
const taxLevel = await db.taxonomy.findFirst({
|
||||||
|
where: { slug: TaxonomySlug.LEVEL },
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!taxLevel) {
|
||||||
|
throw new Error('LEVEL taxonomy not found');
|
||||||
|
}
|
||||||
|
|
||||||
|
// 2. 使用数组定义初始化数据 + 名称去重
|
||||||
|
const termsToCreate = [
|
||||||
|
{ name: '初级', taxonomyId: taxLevel.id },
|
||||||
|
{ name: '中级', taxonomyId: taxLevel.id },
|
||||||
|
{ name: '高级', taxonomyId: taxLevel.id }, // 改为高级更合理
|
||||||
|
];
|
||||||
|
for (const termData of termsToCreate) {
|
||||||
|
await this.termService.create({
|
||||||
|
data: termData,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
console.log('created level terms');
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to create level terms:', error);
|
||||||
|
throw error; // 向上抛出错误供上层处理
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private async createCourse(
|
||||||
|
title: string,
|
||||||
|
deptId: string,
|
||||||
|
cateId: string,
|
||||||
|
levelId: string,
|
||||||
|
) {
|
||||||
|
const course = await db.post.create({
|
||||||
|
data: {
|
||||||
|
type: PostType.COURSE,
|
||||||
|
title: title,
|
||||||
|
updatedAt: dayjs().toDate(),
|
||||||
|
depts: {
|
||||||
|
connect: {
|
||||||
|
id: deptId,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
terms: {
|
||||||
|
connect: [cateId, levelId].map((id) => ({
|
||||||
|
id: id,
|
||||||
|
})),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return course;
|
||||||
|
}
|
||||||
private async createDepartment(
|
private async createDepartment(
|
||||||
name: string,
|
name: string,
|
||||||
parentId?: string | null,
|
parentId?: string | null,
|
||||||
|
|
|
@ -1,10 +1,17 @@
|
||||||
import { db, getRandomElement, getRandomIntInRange, getRandomTimeInterval, } from '@nice/common';
|
import {
|
||||||
|
db,
|
||||||
|
getRandomElement,
|
||||||
|
getRandomIntInRange,
|
||||||
|
getRandomTimeInterval,
|
||||||
|
PostType,
|
||||||
|
} from '@nice/common';
|
||||||
import dayjs from 'dayjs';
|
import dayjs from 'dayjs';
|
||||||
export interface DevDataCounts {
|
export interface DevDataCounts {
|
||||||
deptCount: number;
|
deptCount: number;
|
||||||
|
|
||||||
staffCount: number
|
staffCount: number;
|
||||||
termCount: number
|
termCount: number;
|
||||||
|
courseCount: number;
|
||||||
}
|
}
|
||||||
export async function getCounts(): Promise<DevDataCounts> {
|
export async function getCounts(): Promise<DevDataCounts> {
|
||||||
const counts = {
|
const counts = {
|
||||||
|
@ -12,6 +19,11 @@ export async function getCounts(): Promise<DevDataCounts> {
|
||||||
|
|
||||||
staffCount: await db.staff.count(),
|
staffCount: await db.staff.count(),
|
||||||
termCount: await db.term.count(),
|
termCount: await db.term.count(),
|
||||||
|
courseCount: await db.post.count({
|
||||||
|
where: {
|
||||||
|
type: PostType.COURSE,
|
||||||
|
},
|
||||||
|
}),
|
||||||
};
|
};
|
||||||
return counts;
|
return counts;
|
||||||
}
|
}
|
||||||
|
@ -30,5 +42,3 @@ export function getRandomImageLinks(count: number = 5): string[] {
|
||||||
|
|
||||||
return imageLinks;
|
return imageLinks;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,33 +1,26 @@
|
||||||
import {
|
import { AppConfigSlug, BaseSetting, RolePerms } from "@nice/common";
|
||||||
AppConfigSlug,
|
|
||||||
BaseSetting,
|
|
||||||
RolePerms,
|
|
||||||
} from "@nice/common";
|
|
||||||
import { useContext, useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import {
|
import { Button, Form, Input, message, theme } from "antd";
|
||||||
Button,
|
|
||||||
Form,
|
|
||||||
Input,
|
|
||||||
message,
|
|
||||||
theme,
|
|
||||||
} from "antd";
|
|
||||||
import { useAppConfig } from "@nice/client";
|
import { useAppConfig } from "@nice/client";
|
||||||
import { useAuth } from "@web/src/providers/auth-provider";
|
import { useAuth } from "@web/src/providers/auth-provider";
|
||||||
|
|
||||||
import FixedHeader from "@web/src/components/layout/fix-header";
|
import FixedHeader from "@web/src/components/layout/fix-header";
|
||||||
import { useForm } from "antd/es/form/Form";
|
import { useForm } from "antd/es/form/Form";
|
||||||
import { api } from "@nice/client"
|
import { api } from "@nice/client";
|
||||||
import { MainLayoutContext } from "../layout";
|
import { MainLayoutContext } from "../layout";
|
||||||
|
|
||||||
export default function BaseSettingPage() {
|
export default function BaseSettingPage() {
|
||||||
const { update, baseSetting } = useAppConfig();
|
const { update, baseSetting } = useAppConfig();
|
||||||
const utils = api.useUtils()
|
const utils = api.useUtils();
|
||||||
const [form] = useForm()
|
const [form] = useForm();
|
||||||
const { token } = theme.useToken();
|
const { token } = theme.useToken();
|
||||||
const { data: clientCount } = api.app_config.getClientCount.useQuery(undefined, {
|
const { data: clientCount } = api.app_config.getClientCount.useQuery(
|
||||||
|
undefined,
|
||||||
|
{
|
||||||
refetchInterval: 3000,
|
refetchInterval: 3000,
|
||||||
refetchIntervalInBackground: true
|
refetchIntervalInBackground: true,
|
||||||
})
|
}
|
||||||
|
);
|
||||||
const [isFormChanged, setIsFormChanged] = useState(false);
|
const [isFormChanged, setIsFormChanged] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const { user, hasSomePermissions } = useAuth();
|
const { user, hasSomePermissions } = useAuth();
|
||||||
|
@ -36,31 +29,27 @@ export default function BaseSettingPage() {
|
||||||
setIsFormChanged(true);
|
setIsFormChanged(true);
|
||||||
}
|
}
|
||||||
function onResetClick() {
|
function onResetClick() {
|
||||||
if (!form)
|
if (!form) return;
|
||||||
return
|
|
||||||
if (!baseSetting) {
|
if (!baseSetting) {
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
} else {
|
} else {
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
form.setFieldsValue(baseSetting);
|
form.setFieldsValue(baseSetting);
|
||||||
|
|
||||||
}
|
}
|
||||||
setIsFormChanged(false);
|
setIsFormChanged(false);
|
||||||
}
|
}
|
||||||
function onSaveClick() {
|
function onSaveClick() {
|
||||||
if (form)
|
if (form) form.submit();
|
||||||
form.submit();
|
|
||||||
}
|
}
|
||||||
async function onSubmit(values: BaseSetting) {
|
async function onSubmit(values: BaseSetting) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await update.mutateAsync({
|
await update.mutateAsync({
|
||||||
where: {
|
where: {
|
||||||
slug: AppConfigSlug.BASE_SETTING,
|
slug: AppConfigSlug.BASE_SETTING,
|
||||||
},
|
},
|
||||||
data: { meta: JSON.stringify(values) }
|
data: { meta: { ...baseSetting, ...values } },
|
||||||
});
|
});
|
||||||
setIsFormChanged(false);
|
setIsFormChanged(false);
|
||||||
message.success("已保存");
|
message.success("已保存");
|
||||||
|
@ -72,7 +61,6 @@ export default function BaseSettingPage() {
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (baseSetting && form) {
|
if (baseSetting && form) {
|
||||||
|
|
||||||
form.setFieldsValue(baseSetting);
|
form.setFieldsValue(baseSetting);
|
||||||
}
|
}
|
||||||
}, [baseSetting, form]);
|
}, [baseSetting, form]);
|
||||||
|
@ -103,7 +91,6 @@ export default function BaseSettingPage() {
|
||||||
!hasSomePermissions(RolePerms.MANAGE_BASE_SETTING)
|
!hasSomePermissions(RolePerms.MANAGE_BASE_SETTING)
|
||||||
}
|
}
|
||||||
onFinish={onSubmit}
|
onFinish={onSubmit}
|
||||||
|
|
||||||
onFieldsChange={handleFieldsChange}
|
onFieldsChange={handleFieldsChange}
|
||||||
layout="vertical">
|
layout="vertical">
|
||||||
{/* <div
|
{/* <div
|
||||||
|
@ -173,7 +160,8 @@ export default function BaseSettingPage() {
|
||||||
清除行模型缓存
|
清除行模型缓存
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{<div
|
{
|
||||||
|
<div
|
||||||
className="p-2 border-b text-primary flex justify-between items-center"
|
className="p-2 border-b text-primary flex justify-between items-center"
|
||||||
style={{
|
style={{
|
||||||
fontSize: token.fontSize,
|
fontSize: token.fontSize,
|
||||||
|
@ -181,9 +169,12 @@ export default function BaseSettingPage() {
|
||||||
}}>
|
}}>
|
||||||
<span>app在线人数</span>
|
<span>app在线人数</span>
|
||||||
<div>
|
<div>
|
||||||
{clientCount && clientCount > 0 ? `${clientCount}人在线` : '无人在线'}
|
{clientCount && clientCount > 0
|
||||||
|
? `${clientCount}人在线`
|
||||||
|
: "无人在线"}
|
||||||
</div>
|
</div>
|
||||||
</div>}
|
</div>
|
||||||
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useState, useMemo, useEffect } from 'react';
|
import React, { useState, useMemo, useEffect } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
||||||
import { Button, Card, Typography, Tag, Progress, Spin } from 'antd';
|
import { Button, Card, Typography, Tag, Progress, Spin } from 'antd';
|
||||||
import {
|
import {
|
||||||
PlayCircleOutlined,
|
PlayCircleOutlined,
|
||||||
|
@ -8,10 +8,11 @@ import {
|
||||||
TeamOutlined,
|
TeamOutlined,
|
||||||
StarOutlined,
|
StarOutlined,
|
||||||
ArrowRightOutlined,
|
ArrowRightOutlined,
|
||||||
|
EyeOutlined,
|
||||||
} from '@ant-design/icons';
|
} from '@ant-design/icons';
|
||||||
import { TaxonomySlug, TermDto } from '@nice/common';
|
import { TaxonomySlug, TermDto } from '@nice/common';
|
||||||
import { api } from '@nice/client';
|
import { api } from '@nice/client';
|
||||||
|
// const {courseId} = useParams();
|
||||||
interface GetTaxonomyProps {
|
interface GetTaxonomyProps {
|
||||||
categories: string[];
|
categories: string[];
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
|
@ -63,7 +64,6 @@ interface CoursesSectionProps {
|
||||||
initialVisibleCoursesCount?: number;
|
initialVisibleCoursesCount?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const CoursesSection: React.FC<CoursesSectionProps> = ({
|
const CoursesSection: React.FC<CoursesSectionProps> = ({
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
|
@ -76,9 +76,17 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
||||||
const gateGory: GetTaxonomyProps = useGetTaxonomy({
|
const gateGory: GetTaxonomyProps = useGetTaxonomy({
|
||||||
type: TaxonomySlug.CATEGORY,
|
type: TaxonomySlug.CATEGORY,
|
||||||
})
|
})
|
||||||
|
const { data } = api.post.findMany.useQuery({
|
||||||
|
take: 8,
|
||||||
|
}
|
||||||
|
)
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
console.log(data,'成功')
|
||||||
|
}, [data])
|
||||||
|
const handleClick = (course: Course) => {
|
||||||
|
navigate(`/courses?courseId=${course.id}/detail`);
|
||||||
|
}
|
||||||
|
|
||||||
})
|
|
||||||
const filteredCourses = useMemo(() => {
|
const filteredCourses = useMemo(() => {
|
||||||
return selectedCategory === '全部'
|
return selectedCategory === '全部'
|
||||||
? courses
|
? courses
|
||||||
|
@ -86,34 +94,33 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
||||||
}, [selectedCategory, courses]);
|
}, [selectedCategory, courses]);
|
||||||
|
|
||||||
const displayedCourses = filteredCourses.slice(0, visibleCourses);
|
const displayedCourses = filteredCourses.slice(0, visibleCourses);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="relative py-16 overflow-hidden">
|
<section className="relative py-20 overflow-hidden bg-gradient-to-b from-gray-50 to-white">
|
||||||
<div className="max-w-screen-2xl mx-auto px-4 relative">
|
<div className="max-w-screen-2xl mx-auto px-6 relative">
|
||||||
<div className="flex justify-between items-end mb-12">
|
<div className="flex justify-between items-end mb-16">
|
||||||
<div>
|
<div>
|
||||||
<Title
|
<Title
|
||||||
level={2}
|
level={2}
|
||||||
className="font-bold text-5xl mb-6 bg-gradient-to-r from-gray-900 via-blue-600 to-gray-800 bg-clip-text text-transparent motion-safe:animate-gradient-x"
|
className="font-bold text-5xl mb-6 bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent"
|
||||||
>
|
>
|
||||||
{title}
|
{title}
|
||||||
</Title>
|
</Title>
|
||||||
<Text type="secondary" className="text-xl font-light">
|
<Text type="secondary" className="text-xl font-light text-gray-600">
|
||||||
{description}
|
{description}
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="mb-8 flex flex-wrap gap-3">
|
<div className="mb-12 flex flex-wrap gap-4">
|
||||||
{gateGory.isLoading ? <Spin className='m-3' /> :
|
{gateGory.isLoading ? <Spin className='m-3' /> :
|
||||||
(
|
(
|
||||||
<>
|
<>
|
||||||
<Tag
|
<Tag
|
||||||
color={selectedCategory === "全部" ? 'blue' : 'default'}
|
color={selectedCategory === "全部" ? 'blue' : 'default'}
|
||||||
onClick={() => setSelectedCategory("全部")}
|
onClick={() => setSelectedCategory("全部")}
|
||||||
className={`px-4 py-2 text-base cursor-pointer hover:scale-105 transform transition-all duration-300 ${selectedCategory === "全部"
|
className={`px-6 py-2 text-base cursor-pointer rounded-full transition-all duration-300 ${selectedCategory === "全部"
|
||||||
? 'shadow-[0_2px_8px_-4px_rgba(59,130,246,0.5)]'
|
? 'bg-blue-600 text-white shadow-lg'
|
||||||
: 'hover:shadow-md'
|
: 'bg-white text-gray-600 hover:bg-gray-100'
|
||||||
}`}
|
}`}
|
||||||
>全部</Tag>
|
>全部</Tag>
|
||||||
{
|
{
|
||||||
|
@ -122,9 +129,9 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
||||||
key={category}
|
key={category}
|
||||||
color={selectedCategory === category ? 'blue' : 'default'}
|
color={selectedCategory === category ? 'blue' : 'default'}
|
||||||
onClick={() => setSelectedCategory(category)}
|
onClick={() => setSelectedCategory(category)}
|
||||||
className={`px-4 py-2 text-base cursor-pointer hover:scale-105 transform transition-all duration-300 ${selectedCategory === category
|
className={`px-6 py-2 text-base cursor-pointer rounded-full transition-all duration-300 ${selectedCategory === category
|
||||||
? 'shadow-[0_2px_8px_-4px_rgba(59,130,246,0.5)]'
|
? 'bg-blue-600 text-white shadow-lg'
|
||||||
: 'hover:shadow-md'
|
: 'bg-white text-gray-600 hover:bg-gray-100'
|
||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{category}
|
{category}
|
||||||
|
@ -132,30 +139,29 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
</>
|
</>
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-6">
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-8">
|
||||||
{displayedCourses.map((course) => (
|
{displayedCourses.map((course) => (
|
||||||
<Card
|
<Card
|
||||||
|
onClick={() => handleClick(course)}
|
||||||
key={course.id}
|
key={course.id}
|
||||||
hoverable
|
hoverable
|
||||||
className="group overflow-hidden rounded-2xl border-0 bg-white/70 backdrop-blur-sm
|
className="group overflow-hidden rounded-2xl border border-gray-200 bg-white
|
||||||
shadow-[0_10px_40px_-15px_rgba(0,0,0,0.1)] hover:shadow-[0_20px_50px_-15px_rgba(0,0,0,0.15)]
|
shadow-xl hover:shadow-2xl transition-all duration-300 transform hover:-translate-y-2"
|
||||||
transition-all duration-700 ease-out transform hover:-translate-y-1 will-change-transform"
|
|
||||||
cover={
|
cover={
|
||||||
<div className="relative h-48 bg-gradient-to-br from-gray-900 to-gray-800 overflow-hidden">
|
<div className="relative h-56 bg-gradient-to-br from-gray-900 to-gray-800 overflow-hidden">
|
||||||
<div
|
<div
|
||||||
className="absolute inset-0 bg-cover bg-center transform transition-all duration-1000 ease-out group-hover:scale-110"
|
className="absolute inset-0 bg-cover bg-center transform transition-all duration-700 ease-out group-hover:scale-110"
|
||||||
style={{ backgroundImage: `url(${course.thumbnail})` }}
|
style={{ backgroundImage: `url(${course.thumbnail})` }}
|
||||||
/>
|
/>
|
||||||
<div className="absolute inset-0 bg-gradient-to-tr from-black/60 via-black/40 to-transparent opacity-60 group-hover:opacity-40 transition-opacity duration-700" />
|
<div className="absolute inset-0 bg-gradient-to-t from-black/60 to-transparent opacity-80 group-hover:opacity-60 transition-opacity duration-300" />
|
||||||
<PlayCircleOutlined className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 text-6xl text-white/90 opacity-0 group-hover:opacity-100 transition-all duration-500 ease-out transform group-hover:scale-110 drop-shadow-lg" />
|
<PlayCircleOutlined className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 text-6xl text-white/90 opacity-0 group-hover:opacity-100 transition-all duration-300" />
|
||||||
{course.progress > 0 && (
|
{course.progress > 0 && (
|
||||||
<div className="absolute bottom-0 left-0 right-0 backdrop-blur-md bg-black/20">
|
<div className="absolute bottom-0 left-0 right-0 backdrop-blur-md bg-black/30">
|
||||||
<Progress
|
{/* <Progress
|
||||||
percent={course.progress}
|
percent={course.progress}
|
||||||
showInfo={false}
|
showInfo={false}
|
||||||
strokeColor={{
|
strokeColor={{
|
||||||
|
@ -163,17 +169,17 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
||||||
to: '#60a5fa',
|
to: '#60a5fa',
|
||||||
}}
|
}}
|
||||||
className="m-0"
|
className="m-0"
|
||||||
/>
|
/> */}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
>
|
>
|
||||||
<div className="px-2">
|
<div className="px-4">
|
||||||
<div className="flex gap-2 mb-4">
|
<div className="flex gap-2 mb-4">
|
||||||
<Tag
|
<Tag
|
||||||
color="blue"
|
color="blue"
|
||||||
className="px-3 py-1 rounded-full border-0 shadow-[0_2px_8px_-4px_rgba(59,130,246,0.5)] transition-all duration-300 hover:shadow-[0_4px_12px_-4px_rgba(59,130,246,0.6)]"
|
className="px-3 py-1 rounded-full bg-blue-100 text-blue-600 border-0"
|
||||||
>
|
>
|
||||||
{course.category}
|
{course.category}
|
||||||
</Tag>
|
</Tag>
|
||||||
|
@ -185,35 +191,28 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
||||||
? 'blue'
|
? 'blue'
|
||||||
: 'purple'
|
: 'purple'
|
||||||
}
|
}
|
||||||
className="px-3 py-1 rounded-full border-0 shadow-sm transition-all duration-300 hover:shadow-md"
|
className="px-3 py-1 rounded-full border-0"
|
||||||
>
|
>
|
||||||
{course.level}
|
{course.level}
|
||||||
</Tag>
|
</Tag>
|
||||||
</div>
|
</div>
|
||||||
<Title
|
<Title
|
||||||
level={4}
|
level={4}
|
||||||
className="mb-4 line-clamp-2 font-bold leading-snug transition-colors duration-300 group-hover:text-blue-600"
|
className="mb-4 line-clamp-2 font-bold leading-snug text-gray-800 hover:text-blue-600 transition-colors duration-300 group-hover:scale-[1.02] transform origin-left"
|
||||||
>
|
>
|
||||||
{course.title}
|
<button > {course.title}</button>
|
||||||
</Title>
|
</Title>
|
||||||
<div className="flex items-center mb-4 transition-all duration-300 group-hover:text-blue-500">
|
|
||||||
<UserOutlined className="mr-2 text-blue-500" />
|
<div className="flex items-center mb-4 p-2 rounded-lg transition-all duration-300 hover:bg-blue-50 group">
|
||||||
<Text className="text-gray-600 font-medium group-hover:text-blue-500">
|
<TeamOutlined className="text-blue-500 text-lg transform group-hover:scale-110 transition-transform duration-300" />
|
||||||
|
<div className="ml-2 flex items-center flex-grow">
|
||||||
|
<Text className="font-medium text-blue-500 hover:text-blue-600 transition-colors duration-300">
|
||||||
{course.instructor}
|
{course.instructor}
|
||||||
</Text>
|
</Text>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex justify-between items-center mb-4 text-gray-500 text-sm">
|
<span className="flex items-center bg-blue-100 px-2 py-1 rounded-full text-blue-600 hover:bg-blue-200 transition-colors duration-300">
|
||||||
<span className="flex items-center">
|
<EyeOutlined className="ml-1.5 text-sm" />
|
||||||
<ClockCircleOutlined className="mr-1.5" />
|
<span className="text-xs font-medium">观看次数{course.progress}次</span>
|
||||||
{course.duration}
|
|
||||||
</span>
|
|
||||||
<span className="flex items-center">
|
|
||||||
<TeamOutlined className="mr-1.5" />
|
|
||||||
{course.students.toLocaleString()}
|
|
||||||
</span>
|
|
||||||
<span className="flex items-center text-yellow-500">
|
|
||||||
<StarOutlined className="mr-1.5" />
|
|
||||||
{course.rating}
|
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="pt-4 border-t border-gray-100 text-center">
|
<div className="pt-4 border-t border-gray-100 text-center">
|
||||||
|
@ -226,25 +225,25 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
||||||
立即学习
|
立即学习
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{filteredCourses.length >= visibleCourses && (
|
{filteredCourses.length >= visibleCourses && (
|
||||||
<div className=' flex items-center gap-4 justify-between mt-6'>
|
<div className='flex items-center gap-4 justify-between mt-12'>
|
||||||
<div className='h-[1px] flex-grow bg-gray-200'></div>
|
<div className='h-[1px] flex-grow bg-gradient-to-r from-transparent via-gray-300 to-transparent'></div>
|
||||||
<div className="flex justify-end">
|
<div className="flex justify-end">
|
||||||
<div
|
<Button
|
||||||
|
type="link"
|
||||||
onClick={() => navigate('/courses')}
|
onClick={() => navigate('/courses')}
|
||||||
className="cursor-pointer tracking-widest text-gray-500 hover:text-primary font-medium flex items-center gap-2 transition-all duration-300 ease-in-out"
|
className="flex items-center gap-2 text-gray-600 hover:text-blue-600 font-medium transition-colors duration-300"
|
||||||
>
|
>
|
||||||
查看更多
|
查看更多
|
||||||
|
<ArrowRightOutlined />
|
||||||
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import React, { useRef, useCallback } from 'react';
|
import React, { useRef, useCallback } from "react";
|
||||||
import { Button, Carousel, Typography } from 'antd';
|
import { Button, Carousel, Typography } from "antd";
|
||||||
import {
|
import {
|
||||||
TeamOutlined,
|
TeamOutlined,
|
||||||
BookOutlined,
|
BookOutlined,
|
||||||
|
@ -7,9 +7,9 @@ import {
|
||||||
ClockCircleOutlined,
|
ClockCircleOutlined,
|
||||||
LeftOutlined,
|
LeftOutlined,
|
||||||
RightOutlined,
|
RightOutlined,
|
||||||
EyeOutlined
|
EyeOutlined,
|
||||||
} from '@ant-design/icons';
|
} from "@ant-design/icons";
|
||||||
import type { CarouselRef } from 'antd/es/carousel';
|
import type { CarouselRef } from "antd/es/carousel";
|
||||||
|
|
||||||
const { Title, Text } = Typography;
|
const { Title, Text } = Typography;
|
||||||
|
|
||||||
|
@ -29,26 +29,26 @@ interface PlatformStat {
|
||||||
|
|
||||||
const carouselItems: CarouselItem[] = [
|
const carouselItems: CarouselItem[] = [
|
||||||
{
|
{
|
||||||
title: '探索编程世界',
|
title: "探索编程世界",
|
||||||
desc: '从零开始学习编程,开启你的技术之旅',
|
desc: "从零开始学习编程,开启你的技术之旅",
|
||||||
image: '/images/banner1.jpg',
|
image: "/images/banner1.jpg",
|
||||||
action: '立即开始',
|
action: "立即开始",
|
||||||
color: 'from-blue-600/90'
|
color: "from-blue-600/90",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '人工智能课程',
|
title: "人工智能课程",
|
||||||
desc: '掌握AI技术,引领未来发展',
|
desc: "掌握AI技术,引领未来发展",
|
||||||
image: '/images/banner2.jpg',
|
image: "/images/banner2.jpg",
|
||||||
action: '了解更多',
|
action: "了解更多",
|
||||||
color: 'from-purple-600/90'
|
color: "from-purple-600/90",
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const platformStats: PlatformStat[] = [
|
const platformStats: PlatformStat[] = [
|
||||||
{ icon: <TeamOutlined />, value: '50,000+', label: '注册学员' },
|
{ icon: <TeamOutlined />, value: "50,000+", label: "注册学员" },
|
||||||
{ icon: <BookOutlined />, value: '1,000+', label: '精品课程' },
|
{ icon: <BookOutlined />, value: "1,000+", label: "精品课程" },
|
||||||
// { icon: <StarOutlined />, value: '98%', label: '好评度' },
|
// { icon: <StarOutlined />, value: '98%', label: '好评度' },
|
||||||
{ icon: <EyeOutlined />, value: '100万+', label: '观看次数' }
|
{ icon: <EyeOutlined />, value: "100万+", label: "观看次数" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const HeroSection = () => {
|
const HeroSection = () => {
|
||||||
|
@ -71,16 +71,15 @@ const HeroSection = () => {
|
||||||
effect="fade"
|
effect="fade"
|
||||||
className="h-[600px] mb-24"
|
className="h-[600px] mb-24"
|
||||||
dots={{
|
dots={{
|
||||||
className: 'carousel-dots !bottom-32 !z-20',
|
className: "carousel-dots !bottom-32 !z-20",
|
||||||
}}
|
}}>
|
||||||
>
|
|
||||||
{carouselItems.map((item, index) => (
|
{carouselItems.map((item, index) => (
|
||||||
<div key={index} className="relative h-[600px]">
|
<div key={index} className="relative h-[600px]">
|
||||||
<div
|
<div
|
||||||
className="absolute inset-0 bg-cover bg-center transform transition-[transform,filter] duration-[2000ms] group-hover:scale-105 group-hover:brightness-110 will-change-[transform,filter]"
|
className="absolute inset-0 bg-cover bg-center transform transition-[transform,filter] duration-[2000ms] group-hover:scale-105 group-hover:brightness-110 will-change-[transform,filter]"
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: `url(${item.image})`,
|
backgroundImage: `url(${item.image})`,
|
||||||
backfaceVisibility: 'hidden'
|
backfaceVisibility: "hidden",
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
<div
|
<div
|
||||||
|
@ -89,28 +88,7 @@ const HeroSection = () => {
|
||||||
<div className="absolute inset-0 bg-gradient-to-t from-black/50 to-transparent" />
|
<div className="absolute inset-0 bg-gradient-to-t from-black/50 to-transparent" />
|
||||||
|
|
||||||
{/* Content Container */}
|
{/* Content Container */}
|
||||||
<div className="relative h-full max-w-7xl mx-auto px-6 lg:px-8">
|
<div className="relative h-full max-w-7xl mx-auto px-6 lg:px-8"></div>
|
||||||
<div className="absolute left-0 top-1/2 -translate-y-1/2 max-w-2xl">
|
|
||||||
<Title
|
|
||||||
className="text-white mb-8 text-5xl md:text-6xl xl:text-7xl !leading-tight font-bold tracking-tight"
|
|
||||||
style={{
|
|
||||||
transform: 'translateZ(0)'
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{item.title}
|
|
||||||
</Title>
|
|
||||||
<Text className="text-white/95 text-lg md:text-xl block mb-12 font-light leading-relaxed">
|
|
||||||
{item.desc}
|
|
||||||
</Text>
|
|
||||||
<Button
|
|
||||||
type="primary"
|
|
||||||
size="large"
|
|
||||||
className="h-14 px-12 text-lg font-semibold bg-gradient-to-r from-primary to-primary-600 border-0 shadow-lg hover:shadow-xl hover:from-primary-600 hover:to-primary-700 hover:scale-105 transform transition-all duration-300 ease-out"
|
|
||||||
>
|
|
||||||
{item.action}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
</Carousel>
|
</Carousel>
|
||||||
|
@ -119,15 +97,13 @@ const HeroSection = () => {
|
||||||
<button
|
<button
|
||||||
onClick={handlePrev}
|
onClick={handlePrev}
|
||||||
className="absolute left-4 md:left-8 top-1/2 -translate-y-1/2 z-10 opacity-0 group-hover:opacity-100 transition-all duration-300 bg-black/20 hover:bg-black/30 w-12 h-12 flex items-center justify-center rounded-full transform hover:scale-110 hover:shadow-lg"
|
className="absolute left-4 md:left-8 top-1/2 -translate-y-1/2 z-10 opacity-0 group-hover:opacity-100 transition-all duration-300 bg-black/20 hover:bg-black/30 w-12 h-12 flex items-center justify-center rounded-full transform hover:scale-110 hover:shadow-lg"
|
||||||
aria-label="Previous slide"
|
aria-label="Previous slide">
|
||||||
>
|
|
||||||
<LeftOutlined className="text-white text-xl" />
|
<LeftOutlined className="text-white text-xl" />
|
||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
onClick={handleNext}
|
onClick={handleNext}
|
||||||
className="absolute right-4 md:right-8 top-1/2 -translate-y-1/2 z-10 opacity-0 group-hover:opacity-100 transition-all duration-300 bg-black/20 hover:bg-black/30 w-12 h-12 flex items-center justify-center rounded-full transform hover:scale-110 hover:shadow-lg"
|
className="absolute right-4 md:right-8 top-1/2 -translate-y-1/2 z-10 opacity-0 group-hover:opacity-100 transition-all duration-300 bg-black/20 hover:bg-black/30 w-12 h-12 flex items-center justify-center rounded-full transform hover:scale-110 hover:shadow-lg"
|
||||||
aria-label="Next slide"
|
aria-label="Next slide">
|
||||||
>
|
|
||||||
<RightOutlined className="text-white text-xl" />
|
<RightOutlined className="text-white text-xl" />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -138,8 +114,7 @@ const HeroSection = () => {
|
||||||
{platformStats.map((stat, index) => (
|
{platformStats.map((stat, index) => (
|
||||||
<div
|
<div
|
||||||
key={index}
|
key={index}
|
||||||
className="text-center transform hover:-translate-y-1 hover:scale-105 transition-transform duration-300 ease-out"
|
className="text-center transform hover:-translate-y-1 hover:scale-105 transition-transform duration-300 ease-out">
|
||||||
>
|
|
||||||
<div className="inline-flex items-center justify-center w-16 h-16 mb-4 rounded-full bg-primary-50 text-primary-600 text-3xl transition-colors duration-300 group-hover:text-primary-700">
|
<div className="inline-flex items-center justify-center w-16 h-16 mb-4 rounded-full bg-primary-50 text-primary-600 text-3xl transition-colors duration-300 group-hover:text-primary-700">
|
||||||
{stat.icon}
|
{stat.icon}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -15,7 +15,7 @@ const HomePage = () => {
|
||||||
level: '入门',
|
level: '入门',
|
||||||
duration: '36小时',
|
duration: '36小时',
|
||||||
category: '编程语言',
|
category: '编程语言',
|
||||||
progress: 0,
|
progress: 16,
|
||||||
thumbnail: '/images/course1.jpg',
|
thumbnail: '/images/course1.jpg',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -51,7 +51,7 @@ const HomePage = () => {
|
||||||
level: '高级',
|
level: '高级',
|
||||||
duration: '56小时',
|
duration: '56小时',
|
||||||
category: '编程语言',
|
category: '编程语言',
|
||||||
progress: 0,
|
progress: 15,
|
||||||
thumbnail: '/images/course4.jpg',
|
thumbnail: '/images/course4.jpg',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
@ -99,15 +99,13 @@ const HomePage = () => {
|
||||||
level: '中级',
|
level: '中级',
|
||||||
duration: '40小时',
|
duration: '40小时',
|
||||||
category: '移动开发',
|
category: '移动开发',
|
||||||
progress: 0,
|
progress: 70,
|
||||||
thumbnail: '/images/course8.jpg',
|
thumbnail: '/images/course8.jpg',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen">
|
<div className="min-h-screen">
|
||||||
<HeroSection />
|
<HeroSection />
|
||||||
|
|
||||||
<CoursesSection
|
<CoursesSection
|
||||||
title="推荐课程"
|
title="推荐课程"
|
||||||
description="最受欢迎的精品课程,助你快速成长"
|
description="最受欢迎的精品课程,助你快速成长"
|
||||||
|
|
|
@ -36,7 +36,7 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
||||||
const [file, setFile] = useState<UploadingFile | null>(null);
|
const [file, setFile] = useState<UploadingFile | null>(null);
|
||||||
const avatarRef = useRef<HTMLImageElement>(null);
|
const avatarRef = useRef<HTMLImageElement>(null);
|
||||||
const [previewUrl, setPreviewUrl] = useState<string>(value || "");
|
const [previewUrl, setPreviewUrl] = useState<string>(value || "");
|
||||||
|
const [imageSrc, setImageSrc] = useState(value);
|
||||||
const [compressedUrl, setCompressedUrl] = useState<string>(value || "");
|
const [compressedUrl, setCompressedUrl] = useState<string>(value || "");
|
||||||
const [url, setUrl] = useState<string>(value || "");
|
const [url, setUrl] = useState<string>(value || "");
|
||||||
const [uploading, setUploading] = useState(false);
|
const [uploading, setUploading] = useState(false);
|
||||||
|
@ -45,7 +45,9 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
||||||
const [avatarKey, setAvatarKey] = useState(0);
|
const [avatarKey, setAvatarKey] = useState(0);
|
||||||
const { token } = theme.useToken();
|
const { token } = theme.useToken();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!previewUrl || previewUrl?.length < 1) {
|
||||||
setPreviewUrl(value || "");
|
setPreviewUrl(value || "");
|
||||||
|
}
|
||||||
}, [value]);
|
}, [value]);
|
||||||
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const selectedFile = event.target.files?.[0];
|
const selectedFile = event.target.files?.[0];
|
||||||
|
@ -128,6 +130,14 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
||||||
ref={avatarRef}
|
ref={avatarRef}
|
||||||
src={previewUrl}
|
src={previewUrl}
|
||||||
shape="square"
|
shape="square"
|
||||||
|
onError={() => {
|
||||||
|
if (value && previewUrl && imageSrc === value) {
|
||||||
|
// 当原始图片(value)加载失败时,切换到 previewUrl
|
||||||
|
setImageSrc(previewUrl);
|
||||||
|
return true; // 阻止默认的 fallback 行为,让它尝试新设置的 src
|
||||||
|
}
|
||||||
|
return false; // 如果 previewUrl 也失败了,显示默认头像
|
||||||
|
}}
|
||||||
className="w-full h-full object-cover"
|
className="w-full h-full object-cover"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
@ -6,7 +6,6 @@ interface CourseStatsProps {
|
||||||
completionRate?: number;
|
completionRate?: number;
|
||||||
totalDuration?: number;
|
totalDuration?: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const CourseStats = ({
|
export const CourseStats = ({
|
||||||
averageRating,
|
averageRating,
|
||||||
numberOfReviews,
|
numberOfReviews,
|
||||||
|
|
|
@ -109,11 +109,12 @@ export function CourseFormProvider({
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (editId) {
|
if (editId) {
|
||||||
await update.mutateAsync({
|
const result = await update.mutateAsync({
|
||||||
where: { id: editId },
|
where: { id: editId },
|
||||||
data: formattedValues,
|
data: formattedValues,
|
||||||
});
|
});
|
||||||
message.success("课程更新成功!");
|
message.success("课程更新成功!");
|
||||||
|
navigate(`/course/${result.id}/editor/content`);
|
||||||
} else {
|
} else {
|
||||||
const result = await createCourse.mutateAsync({
|
const result = await createCourse.mutateAsync({
|
||||||
courseDetail: {
|
courseDetail: {
|
||||||
|
@ -127,8 +128,8 @@ export function CourseFormProvider({
|
||||||
},
|
},
|
||||||
sections,
|
sections,
|
||||||
});
|
});
|
||||||
navigate(`/course/${result.id}/editor`, { replace: true });
|
|
||||||
message.success("课程创建成功!");
|
message.success("课程创建成功!");
|
||||||
|
navigate(`/course/${result.id}/editor/content`);
|
||||||
}
|
}
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import { CourseContentFormHeader } from "./CourseContentFormHeader";
|
||||||
import { CourseSectionEmpty } from "./CourseSectionEmpty";
|
import { CourseSectionEmpty } from "./CourseSectionEmpty";
|
||||||
import { SortableSection } from "./SortableSection";
|
import { SortableSection } from "./SortableSection";
|
||||||
import { LectureList } from "./LectureList";
|
import { LectureList } from "./LectureList";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
const CourseContentForm: React.FC = () => {
|
const CourseContentForm: React.FC = () => {
|
||||||
const { editId } = useCourseEditor();
|
const { editId } = useCourseEditor();
|
||||||
|
@ -33,7 +34,7 @@ const CourseContentForm: React.FC = () => {
|
||||||
coordinateGetter: sortableKeyboardCoordinates,
|
coordinateGetter: sortableKeyboardCoordinates,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const { softDeleteByIds } = usePost();
|
const { softDeleteByIds, updateOrderByIds } = usePost();
|
||||||
const { data: sections = [], isLoading } = api.post.findMany.useQuery(
|
const { data: sections = [], isLoading } = api.post.findMany.useQuery(
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
|
@ -41,6 +42,9 @@ const CourseContentForm: React.FC = () => {
|
||||||
type: PostType.SECTION,
|
type: PostType.SECTION,
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
},
|
},
|
||||||
|
orderBy: {
|
||||||
|
order: "asc",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: !!editId,
|
enabled: !!editId,
|
||||||
|
@ -56,11 +60,15 @@ const CourseContentForm: React.FC = () => {
|
||||||
const handleDragEnd = (event: DragEndEvent) => {
|
const handleDragEnd = (event: DragEndEvent) => {
|
||||||
const { active, over } = event;
|
const { active, over } = event;
|
||||||
if (!over || active.id === over.id) return;
|
if (!over || active.id === over.id) return;
|
||||||
|
let newItems = [];
|
||||||
setItems((items) => {
|
setItems((items) => {
|
||||||
const oldIndex = items.findIndex((item) => item.id === active.id);
|
const oldIndex = items.findIndex((item) => item.id === active.id);
|
||||||
const newIndex = items.findIndex((item) => item.id === over.id);
|
const newIndex = items.findIndex((item) => item.id === over.id);
|
||||||
return arrayMove(items, oldIndex, newIndex);
|
newItems = arrayMove(items, oldIndex, newIndex);
|
||||||
|
return newItems;
|
||||||
|
});
|
||||||
|
updateOrderByIds.mutateAsync({
|
||||||
|
ids: newItems.map((item) => item.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -107,10 +115,11 @@ const CourseContentForm: React.FC = () => {
|
||||||
icon={<PlusOutlined />}
|
icon={<PlusOutlined />}
|
||||||
className="mt-4"
|
className="mt-4"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
setItems([
|
if (items.some((item) => item.id === null)) {
|
||||||
...items.filter((item) => !!item.id),
|
toast.error("请先保存当前编辑的章节");
|
||||||
{ id: null, title: "" },
|
} else {
|
||||||
]);
|
setItems([...items, { id: null, title: "" }]);
|
||||||
|
}
|
||||||
}}>
|
}}>
|
||||||
添加章节
|
添加章节
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -38,6 +38,7 @@ import { useCourseEditor } from "../../context/CourseEditorContext";
|
||||||
import { usePost } from "@nice/client";
|
import { usePost } from "@nice/client";
|
||||||
import { LectureData, SectionData } from "./interface";
|
import { LectureData, SectionData } from "./interface";
|
||||||
import { SortableLecture } from "./SortableLecture";
|
import { SortableLecture } from "./SortableLecture";
|
||||||
|
import toast from "react-hot-toast";
|
||||||
|
|
||||||
interface LectureListProps {
|
interface LectureListProps {
|
||||||
field: SectionData;
|
field: SectionData;
|
||||||
|
@ -48,7 +49,7 @@ export const LectureList: React.FC<LectureListProps> = ({
|
||||||
field,
|
field,
|
||||||
sectionId,
|
sectionId,
|
||||||
}) => {
|
}) => {
|
||||||
const { softDeleteByIds } = usePost();
|
const { softDeleteByIds, updateOrderByIds } = usePost();
|
||||||
const { data: lectures = [], isLoading } = (
|
const { data: lectures = [], isLoading } = (
|
||||||
api.post.findMany as any
|
api.post.findMany as any
|
||||||
).useQuery(
|
).useQuery(
|
||||||
|
@ -58,6 +59,9 @@ export const LectureList: React.FC<LectureListProps> = ({
|
||||||
type: PostType.LECTURE,
|
type: PostType.LECTURE,
|
||||||
deletedAt: null,
|
deletedAt: null,
|
||||||
},
|
},
|
||||||
|
orderBy: {
|
||||||
|
order: "asc",
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
enabled: !!sectionId,
|
enabled: !!sectionId,
|
||||||
|
@ -84,11 +88,19 @@ export const LectureList: React.FC<LectureListProps> = ({
|
||||||
const handleDragEnd = (event: DragEndEvent) => {
|
const handleDragEnd = (event: DragEndEvent) => {
|
||||||
const { active, over } = event;
|
const { active, over } = event;
|
||||||
if (!over || active.id === over.id) return;
|
if (!over || active.id === over.id) return;
|
||||||
|
// updateOrder.mutateAsync({
|
||||||
|
// id: active.id,
|
||||||
|
// overId: over.id,
|
||||||
|
// });
|
||||||
|
let newItems = [];
|
||||||
setItems((items) => {
|
setItems((items) => {
|
||||||
const oldIndex = items.findIndex((item) => item.id === active.id);
|
const oldIndex = items.findIndex((item) => item.id === active.id);
|
||||||
const newIndex = items.findIndex((item) => item.id === over.id);
|
const newIndex = items.findIndex((item) => item.id === over.id);
|
||||||
return arrayMove(items, oldIndex, newIndex);
|
newItems = arrayMove(items, oldIndex, newIndex);
|
||||||
|
return newItems;
|
||||||
|
});
|
||||||
|
updateOrderByIds.mutateAsync({
|
||||||
|
ids: newItems.map((item) => item.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -124,6 +136,9 @@ export const LectureList: React.FC<LectureListProps> = ({
|
||||||
icon={<PlusOutlined />}
|
icon={<PlusOutlined />}
|
||||||
className="mt-4"
|
className="mt-4"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
if (items.some((item) => item.id === null)) {
|
||||||
|
toast.error("请先保存当前编辑中的课时!");
|
||||||
|
} else {
|
||||||
setItems((prevItems) => [
|
setItems((prevItems) => [
|
||||||
...prevItems.filter((item) => !!item.id),
|
...prevItems.filter((item) => !!item.id),
|
||||||
{
|
{
|
||||||
|
@ -134,6 +149,7 @@ export const LectureList: React.FC<LectureListProps> = ({
|
||||||
},
|
},
|
||||||
} as Lecture,
|
} as Lecture,
|
||||||
]);
|
]);
|
||||||
|
}
|
||||||
}}>
|
}}>
|
||||||
添加课时
|
添加课时
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -1,19 +0,0 @@
|
||||||
// import { FormArrayField } from "@web/src/components/common/form/FormArrayField";
|
|
||||||
// import { useFormContext } from "react-hook-form";
|
|
||||||
// import { CourseFormData } from "../context/CourseEditorContext";
|
|
||||||
// import InputList from "@web/src/components/common/input/InputList";
|
|
||||||
// import { useState } from "react";
|
|
||||||
// import { Form } from "antd";
|
|
||||||
|
|
||||||
// export function CourseGoalForm() {
|
|
||||||
// return (
|
|
||||||
// <div className="max-w-2xl mx-auto space-y-6 p-6">
|
|
||||||
// <Form.Item name="requirements" label="前置要求">
|
|
||||||
// <InputList placeholder="请输入前置要求"></InputList>
|
|
||||||
// </Form.Item>
|
|
||||||
// <Form.Item name="objectives" label="学习目标">
|
|
||||||
// <InputList placeholder="请输入学习目标"></InputList>
|
|
||||||
// </Form.Item>
|
|
||||||
// </div>
|
|
||||||
// );
|
|
||||||
// }
|
|
|
@ -1,26 +0,0 @@
|
||||||
// import AvatarUploader from "@web/src/components/common/uploader/AvatarUploader";
|
|
||||||
// import { Form, Input } from "antd";
|
|
||||||
|
|
||||||
// export default function CourseSettingForm() {
|
|
||||||
// return (
|
|
||||||
// <div className="max-w-2xl mx-auto space-y-6 p-6">
|
|
||||||
// <Form.Item
|
|
||||||
// name="title"
|
|
||||||
// label="课程预览图"
|
|
||||||
// >
|
|
||||||
// <AvatarUploader
|
|
||||||
// style={
|
|
||||||
// {
|
|
||||||
// width: "120px",
|
|
||||||
// height: "120px",
|
|
||||||
// margin:" 0 10px"
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// onChange={(value) => {
|
|
||||||
// console.log(value);
|
|
||||||
// }}
|
|
||||||
// ></AvatarUploader>
|
|
||||||
// </Form.Item>
|
|
||||||
// </div>
|
|
||||||
// )
|
|
||||||
// }
|
|
|
@ -3,6 +3,7 @@ import {
|
||||||
IndexRouteObject,
|
IndexRouteObject,
|
||||||
Link,
|
Link,
|
||||||
NonIndexRouteObject,
|
NonIndexRouteObject,
|
||||||
|
useParams,
|
||||||
} from "react-router-dom";
|
} from "react-router-dom";
|
||||||
import ErrorPage from "../app/error";
|
import ErrorPage from "../app/error";
|
||||||
import WithAuth from "../components/utils/with-auth";
|
import WithAuth from "../components/utils/with-auth";
|
||||||
|
@ -40,6 +41,7 @@ export type CustomRouteObject =
|
||||||
| CustomIndexRouteObject
|
| CustomIndexRouteObject
|
||||||
| CustomNonIndexRouteObject;
|
| CustomNonIndexRouteObject;
|
||||||
export const routes: CustomRouteObject[] = [
|
export const routes: CustomRouteObject[] = [
|
||||||
|
|
||||||
{
|
{
|
||||||
path: "/",
|
path: "/",
|
||||||
errorElement: <ErrorPage />,
|
errorElement: <ErrorPage />,
|
||||||
|
@ -144,4 +146,5 @@ export const routes: CustomRouteObject[] = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
export const router = createBrowserRouter(routes);
|
export const router = createBrowserRouter(routes);
|
||||||
|
|
|
@ -101,6 +101,7 @@ server {
|
||||||
internal;
|
internal;
|
||||||
# 代理到认证服务
|
# 代理到认证服务
|
||||||
proxy_pass http://host.docker.internal:3000/auth/file;
|
proxy_pass http://host.docker.internal:3000/auth/file;
|
||||||
|
|
||||||
# 请求优化:不传递请求体
|
# 请求优化:不传递请求体
|
||||||
proxy_pass_request_body off;
|
proxy_pass_request_body off;
|
||||||
proxy_set_header Content-Length "";
|
proxy_set_header Content-Length "";
|
||||||
|
|
|
@ -113,5 +113,8 @@ export function useEntity<T extends keyof RouterInputs>(
|
||||||
T,
|
T,
|
||||||
"updateOrder"
|
"updateOrder"
|
||||||
>, // 更新实体顺序的 mutation 函数
|
>, // 更新实体顺序的 mutation 函数
|
||||||
|
updateOrderByIds: createMutationHandler(
|
||||||
|
"updateOrderByIds"
|
||||||
|
) as MutationResult<T, "updateOrderByIds">, // 更新实体顺序的 mutation 函数
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -110,6 +110,7 @@ model Department {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
name String
|
name String
|
||||||
order Float?
|
order Float?
|
||||||
|
posts Post[] @relation("post_dept")
|
||||||
ancestors DeptAncestry[] @relation("DescendantToAncestor")
|
ancestors DeptAncestry[] @relation("DescendantToAncestor")
|
||||||
descendants DeptAncestry[] @relation("AncestorToDescendant")
|
descendants DeptAncestry[] @relation("AncestorToDescendant")
|
||||||
parentId String? @map("parent_id")
|
parentId String? @map("parent_id")
|
||||||
|
@ -200,11 +201,13 @@ model Post {
|
||||||
order Float? @default(0) @map("order")
|
order Float? @default(0) @map("order")
|
||||||
duration Int?
|
duration Int?
|
||||||
rating Int? @default(0)
|
rating Int? @default(0)
|
||||||
|
|
||||||
|
depts Department[] @relation("post_dept")
|
||||||
// 索引
|
// 索引
|
||||||
// 日期时间类型字段
|
// 日期时间类型字段
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
publishedAt DateTime? @map("published_at") // 发布时间
|
publishedAt DateTime? @map("published_at") // 发布时间
|
||||||
updatedAt DateTime @updatedAt @map("updated_at")
|
updatedAt DateTime @map("updated_at")
|
||||||
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
|
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
|
||||||
instructors PostInstructor[]
|
instructors PostInstructor[]
|
||||||
// 关系类型字段
|
// 关系类型字段
|
||||||
|
@ -268,7 +271,6 @@ model Message {
|
||||||
visits Visit[]
|
visits Visit[]
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
updatedAt DateTime? @updatedAt @map("updated_at")
|
updatedAt DateTime? @updatedAt @map("updated_at")
|
||||||
|
|
||||||
@@index([type, createdAt])
|
@@index([type, createdAt])
|
||||||
@@map("message")
|
@@map("message")
|
||||||
}
|
}
|
||||||
|
@ -404,7 +406,6 @@ model NodeEdge {
|
||||||
@@index([targetId])
|
@@index([targetId])
|
||||||
@@map("node_edge")
|
@@map("node_edge")
|
||||||
}
|
}
|
||||||
|
|
||||||
model Animal {
|
model Animal {
|
||||||
id String @id @default(cuid())
|
id String @id @default(cuid())
|
||||||
name String
|
name String
|
||||||
|
|
|
@ -56,7 +56,7 @@ export const InitTaxonomies: {
|
||||||
objectType?: string[];
|
objectType?: string[];
|
||||||
}[] = [
|
}[] = [
|
||||||
{
|
{
|
||||||
name: "分类",
|
name: "课程分类",
|
||||||
slug: TaxonomySlug.CATEGORY,
|
slug: TaxonomySlug.CATEGORY,
|
||||||
objectType: [ObjectType.COURSE],
|
objectType: [ObjectType.COURSE],
|
||||||
},
|
},
|
||||||
|
|
|
@ -100,6 +100,7 @@ export enum RolePerms {
|
||||||
}
|
}
|
||||||
export enum AppConfigSlug {
|
export enum AppConfigSlug {
|
||||||
BASE_SETTING = "base_setting",
|
BASE_SETTING = "base_setting",
|
||||||
|
|
||||||
}
|
}
|
||||||
// 资源类型的枚举,定义了不同类型的资源,以字符串值表示
|
// 资源类型的枚举,定义了不同类型的资源,以字符串值表示
|
||||||
export enum ResourceType {
|
export enum ResourceType {
|
||||||
|
|
|
@ -77,5 +77,6 @@ export type Course = Post & {
|
||||||
export type CourseDto = Course & {
|
export type CourseDto = Course & {
|
||||||
enrollments?: Enrollment[];
|
enrollments?: Enrollment[];
|
||||||
sections?: SectionDto[];
|
sections?: SectionDto[];
|
||||||
terms: TermDto[];
|
terms: Term[];
|
||||||
|
lectureCount?: number;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue