Merge branch 'main' of http://113.45.157.195:3003/insiinc/re-mooc
This commit is contained in:
commit
09a23e3f1e
|
@ -4,44 +4,48 @@ import { AppConfigService } from './app-config.service';
|
|||
import { z, ZodType } from 'zod';
|
||||
import { Prisma } from '@nice/common';
|
||||
import { RealtimeServer } from '@server/socket/realtime/realtime.server';
|
||||
const AppConfigUncheckedCreateInputSchema: ZodType<Prisma.AppConfigUncheckedCreateInput> = z.any()
|
||||
const AppConfigUpdateArgsSchema: ZodType<Prisma.AppConfigUpdateArgs> = z.any()
|
||||
const AppConfigDeleteManyArgsSchema: ZodType<Prisma.AppConfigDeleteManyArgs> = z.any()
|
||||
const AppConfigFindFirstArgsSchema: ZodType<Prisma.AppConfigFindFirstArgs> = z.any()
|
||||
const AppConfigUncheckedCreateInputSchema: ZodType<Prisma.AppConfigUncheckedCreateInput> =
|
||||
z.any();
|
||||
const AppConfigUpdateArgsSchema: ZodType<Prisma.AppConfigUpdateArgs> = z.any();
|
||||
const AppConfigDeleteManyArgsSchema: ZodType<Prisma.AppConfigDeleteManyArgs> =
|
||||
z.any();
|
||||
const AppConfigFindFirstArgsSchema: ZodType<Prisma.AppConfigFindFirstArgs> =
|
||||
z.any();
|
||||
@Injectable()
|
||||
export class AppConfigRouter {
|
||||
constructor(
|
||||
private readonly trpc: TrpcService,
|
||||
private readonly appConfigService: AppConfigService,
|
||||
private readonly realtimeServer: RealtimeServer
|
||||
) { }
|
||||
router = this.trpc.router({
|
||||
create: this.trpc.protectProcedure
|
||||
.input(AppConfigUncheckedCreateInputSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { staff } = ctx;
|
||||
return await this.appConfigService.create({ data: input });
|
||||
}),
|
||||
update: this.trpc.protectProcedure
|
||||
.input(AppConfigUpdateArgsSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
|
||||
const { staff } = ctx;
|
||||
return await this.appConfigService.update(input);
|
||||
}),
|
||||
deleteMany: this.trpc.protectProcedure.input(AppConfigDeleteManyArgsSchema).mutation(async ({ input }) => {
|
||||
return await this.appConfigService.deleteMany(input)
|
||||
}),
|
||||
findFirst: this.trpc.protectProcedure.input(AppConfigFindFirstArgsSchema).
|
||||
query(async ({ input }) => {
|
||||
|
||||
return await this.appConfigService.findFirst(input)
|
||||
}),
|
||||
clearRowCache: this.trpc.protectProcedure.mutation(async () => {
|
||||
return await this.appConfigService.clearRowCache()
|
||||
}),
|
||||
getClientCount: this.trpc.protectProcedure.query(() => {
|
||||
return this.realtimeServer.getClientCount()
|
||||
})
|
||||
});
|
||||
constructor(
|
||||
private readonly trpc: TrpcService,
|
||||
private readonly appConfigService: AppConfigService,
|
||||
private readonly realtimeServer: RealtimeServer,
|
||||
) {}
|
||||
router = this.trpc.router({
|
||||
create: this.trpc.protectProcedure
|
||||
.input(AppConfigUncheckedCreateInputSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { staff } = ctx;
|
||||
return await this.appConfigService.create({ data: input });
|
||||
}),
|
||||
update: this.trpc.protectProcedure
|
||||
.input(AppConfigUpdateArgsSchema)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const { staff } = ctx;
|
||||
return await this.appConfigService.update(input);
|
||||
}),
|
||||
deleteMany: this.trpc.protectProcedure
|
||||
.input(AppConfigDeleteManyArgsSchema)
|
||||
.mutation(async ({ input }) => {
|
||||
return await this.appConfigService.deleteMany(input);
|
||||
}),
|
||||
findFirst: this.trpc.protectProcedure
|
||||
.input(AppConfigFindFirstArgsSchema)
|
||||
.query(async ({ input }) => {
|
||||
return await this.appConfigService.findFirst(input);
|
||||
}),
|
||||
clearRowCache: this.trpc.protectProcedure.mutation(async () => {
|
||||
return await this.appConfigService.clearRowCache();
|
||||
}),
|
||||
getClientCount: this.trpc.protectProcedure.query(() => {
|
||||
return this.realtimeServer.getClientCount();
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -1,10 +1,5 @@
|
|||
import { Injectable } from '@nestjs/common';
|
||||
import {
|
||||
db,
|
||||
ObjectType,
|
||||
Prisma,
|
||||
} from '@nice/common';
|
||||
|
||||
import { db, ObjectType, Prisma } from '@nice/common';
|
||||
|
||||
import { BaseService } from '../base/base.service';
|
||||
import { deleteByPattern } from '@server/utils/redis/utils';
|
||||
|
@ -12,10 +7,10 @@ import { deleteByPattern } from '@server/utils/redis/utils';
|
|||
@Injectable()
|
||||
export class AppConfigService extends BaseService<Prisma.AppConfigDelegate> {
|
||||
constructor() {
|
||||
super(db, "appConfig");
|
||||
super(db, 'appConfig');
|
||||
}
|
||||
async clearRowCache() {
|
||||
await deleteByPattern("row-*")
|
||||
return true
|
||||
await deleteByPattern('row-*');
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,25 +1,27 @@
|
|||
import { db, Prisma, PrismaClient } from "@nice/common";
|
||||
import { db, Prisma, PrismaClient } from '@nice/common';
|
||||
|
||||
export type Operations =
|
||||
| 'aggregate'
|
||||
| 'count'
|
||||
| 'create'
|
||||
| 'createMany'
|
||||
| 'delete'
|
||||
| 'deleteMany'
|
||||
| 'findFirst'
|
||||
| 'findMany'
|
||||
| 'findUnique'
|
||||
| 'update'
|
||||
| 'updateMany'
|
||||
| 'upsert';
|
||||
export type DelegateFuncs = { [K in Operations]: (args: any) => Promise<unknown> }
|
||||
| 'aggregate'
|
||||
| 'count'
|
||||
| 'create'
|
||||
| 'createMany'
|
||||
| 'delete'
|
||||
| 'deleteMany'
|
||||
| 'findFirst'
|
||||
| 'findMany'
|
||||
| 'findUnique'
|
||||
| 'update'
|
||||
| 'updateMany'
|
||||
| 'upsert';
|
||||
export type DelegateFuncs = {
|
||||
[K in Operations]: (args: any) => Promise<unknown>;
|
||||
};
|
||||
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;
|
||||
};
|
||||
|
||||
export type DelegateReturnTypes<T> = {
|
||||
[K in keyof T]: T[K] extends (args: any) => Promise<infer R> ? R : never;
|
||||
[K in keyof T]: T[K] extends (args: any) => Promise<infer R> ? R : never;
|
||||
};
|
||||
|
||||
export type WhereArgs<T> = T extends { where?: infer W } ? W : never;
|
||||
|
@ -28,17 +30,17 @@ export type DataArgs<T> = T extends { data: infer D } ? D : 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 UpdateOrderArgs = {
|
||||
id: string
|
||||
overId: string
|
||||
}
|
||||
id: string;
|
||||
overId: string;
|
||||
};
|
||||
export interface FindManyWithCursorType<T extends DelegateFuncs> {
|
||||
cursor?: string;
|
||||
limit?: number;
|
||||
where?: WhereArgs<DelegateArgs<T>['findUnique']>;
|
||||
select?: SelectArgs<DelegateArgs<T>['findUnique']>;
|
||||
orderBy?: OrderByArgs<DelegateArgs<T>['findMany']>
|
||||
cursor?: string;
|
||||
limit?: number;
|
||||
where?: WhereArgs<DelegateArgs<T>['findUnique']>;
|
||||
select?: SelectArgs<DelegateArgs<T>['findUnique']>;
|
||||
orderBy?: OrderByArgs<DelegateArgs<T>['findMany']>;
|
||||
}
|
||||
export type TransactionType = Omit<
|
||||
PrismaClient,
|
||||
'$connect' | '$disconnect' | '$on' | '$transaction' | '$use' | '$extends'
|
||||
>;
|
||||
PrismaClient,
|
||||
'$connect' | '$disconnect' | '$on' | '$transaction' | '$use' | '$extends'
|
||||
>;
|
||||
|
|
|
@ -3,8 +3,10 @@ import { TrpcService } from '@server/trpc/trpc.service';
|
|||
import { CourseMethodSchema, Prisma } from '@nice/common';
|
||||
import { PostService } from './post.service';
|
||||
import { z, ZodType } from 'zod';
|
||||
import { UpdateOrderArgs } from '../base/base.type';
|
||||
const PostCreateArgsSchema: ZodType<Prisma.PostCreateArgs> = z.any();
|
||||
const PostUpdateArgsSchema: ZodType<Prisma.PostUpdateArgs> = z.any();
|
||||
const PostUpdateOrderArgsSchema: ZodType<UpdateOrderArgs> = z.any();
|
||||
const PostFindFirstArgsSchema: ZodType<Prisma.PostFindFirstArgs> = z.any();
|
||||
const PostFindManyArgsSchema: ZodType<Prisma.PostFindManyArgs> = z.any();
|
||||
const PostDeleteManyArgsSchema: ZodType<Prisma.PostDeleteManyArgs> = z.any();
|
||||
|
@ -107,5 +109,21 @@ export class PostRouter {
|
|||
.query(async ({ 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 { z } from 'zod';
|
||||
import { DefaultArgs } from '@prisma/client/runtime/library';
|
||||
import dayjs from 'dayjs';
|
||||
|
||||
@Injectable()
|
||||
export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||
|
@ -43,13 +44,14 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
|||
content: content,
|
||||
title: title,
|
||||
authorId: params?.staff?.id,
|
||||
updatedAt: dayjs().toDate(),
|
||||
resources: {
|
||||
connect: resourceIds.map((fileId) => ({ fileId })),
|
||||
},
|
||||
meta: {
|
||||
type: type,
|
||||
},
|
||||
},
|
||||
} as any,
|
||||
},
|
||||
{ tx },
|
||||
);
|
||||
|
@ -71,7 +73,8 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
|||
parentId: courseId,
|
||||
title: title,
|
||||
authorId: staff?.id,
|
||||
},
|
||||
updatedAt: dayjs().toDate(),
|
||||
} as any,
|
||||
},
|
||||
{ tx },
|
||||
);
|
||||
|
@ -95,11 +98,15 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
|||
async createCourse(
|
||||
args: {
|
||||
courseDetail: Prisma.PostCreateArgs;
|
||||
sections?: z.infer<typeof CourseMethodSchema.createSection>[];
|
||||
},
|
||||
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 (!params.tx) {
|
||||
return await db.$transaction(async (tx) => {
|
||||
|
@ -109,20 +116,6 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
|||
console.log('courseDetail', courseDetail);
|
||||
const createdCourse = await this.create(courseDetail, courseParams);
|
||||
// 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;
|
||||
});
|
||||
}
|
||||
|
@ -130,21 +123,6 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
|||
console.log('courseDetail', courseDetail);
|
||||
const createdCourse = await this.create(courseDetail, params);
|
||||
// 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;
|
||||
}
|
||||
async create(
|
||||
|
@ -152,6 +130,7 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
|||
params?: { staff?: UserProfile; tx?: Prisma.TransactionClient },
|
||||
) {
|
||||
args.data.authorId = params?.staff?.id;
|
||||
args.data.updatedAt = dayjs().toDate();
|
||||
const result = await super.create(args);
|
||||
EventBus.emit('dataChanged', {
|
||||
type: ObjectType.POST,
|
||||
|
@ -162,6 +141,7 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
|||
}
|
||||
async update(args: Prisma.PostUpdateArgs, staff?: UserProfile) {
|
||||
args.data.authorId = staff?.id;
|
||||
args.data.updatedAt = dayjs().toDate();
|
||||
const result = await super.update(args);
|
||||
EventBus.emit('dataChanged', {
|
||||
type: ObjectType.POST,
|
||||
|
@ -216,15 +196,68 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
|||
return { ...result, items };
|
||||
});
|
||||
}
|
||||
async findManyWithPagination(args:
|
||||
{ page?: number;
|
||||
pageSize?: number;
|
||||
where?: Prisma.PostWhereInput;
|
||||
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; }>
|
||||
{
|
||||
return super.findManyWithPagination(args);
|
||||
}
|
||||
async findManyWithPagination(args: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
where?: Prisma.PostWhereInput;
|
||||
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;
|
||||
}> {
|
||||
// super.updateOrder;
|
||||
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) {
|
||||
if (!staff) return;
|
||||
const perms: ResPerm = {
|
||||
|
|
|
@ -137,6 +137,11 @@ export async function setCourseInfo({ data }: { data: Post }) {
|
|||
id: true,
|
||||
descendant: true,
|
||||
},
|
||||
orderBy: {
|
||||
descendant: {
|
||||
order: 'asc',
|
||||
},
|
||||
},
|
||||
});
|
||||
const descendants = ancestries.map((ancestry) => ancestry.descendant);
|
||||
const sections: SectionDto[] = descendants
|
||||
|
@ -156,12 +161,12 @@ export async function setCourseInfo({ data }: { data: Post }) {
|
|||
sections.map((section) => section.id).includes(descendant.parentId)
|
||||
);
|
||||
});
|
||||
|
||||
const lectureCount = lectures?.length || 0;
|
||||
sections.forEach((section) => {
|
||||
section.lectures = lectures.filter(
|
||||
(lecture) => lecture.parentId === section.id,
|
||||
);
|
||||
});
|
||||
Object.assign(data, { sections });
|
||||
Object.assign(data, { sections, lectureCount });
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import {
|
|||
Department,
|
||||
getRandomElement,
|
||||
getRandomElements,
|
||||
PostType,
|
||||
Staff,
|
||||
TaxonomySlug,
|
||||
Term,
|
||||
|
@ -14,6 +15,7 @@ import {
|
|||
import EventBus from '@server/utils/event-bus';
|
||||
import { capitalizeFirstLetter, DevDataCounts, getCounts } from './utils';
|
||||
import { StaffService } from '@server/models/staff/staff.service';
|
||||
import dayjs from 'dayjs';
|
||||
@Injectable()
|
||||
export class GenDevService {
|
||||
private readonly logger = new Logger(GenDevService.name);
|
||||
|
@ -22,7 +24,7 @@ export class GenDevService {
|
|||
terms: Record<TaxonomySlug, Term[]> = {
|
||||
[TaxonomySlug.CATEGORY]: [],
|
||||
[TaxonomySlug.TAG]: [],
|
||||
[TaxonomySlug.LEVEL]: []
|
||||
[TaxonomySlug.LEVEL]: [],
|
||||
};
|
||||
depts: Department[] = [];
|
||||
domains: Department[] = [];
|
||||
|
@ -35,7 +37,7 @@ export class GenDevService {
|
|||
private readonly departmentService: DepartmentService,
|
||||
private readonly staffService: StaffService,
|
||||
private readonly termService: TermService,
|
||||
) { }
|
||||
) {}
|
||||
async genDataEvent() {
|
||||
EventBus.emit('genDataEvent', { type: 'start' });
|
||||
try {
|
||||
|
@ -43,6 +45,7 @@ export class GenDevService {
|
|||
await this.generateDepartments(3, 6);
|
||||
await this.generateTerms(2, 6);
|
||||
await this.generateStaffs(4);
|
||||
await this.generateCourses(8);
|
||||
} catch (err) {
|
||||
this.logger.error(err);
|
||||
}
|
||||
|
@ -58,6 +61,7 @@ export class GenDevService {
|
|||
if (this.counts.termCount === 0) {
|
||||
this.logger.log('Generate terms');
|
||||
await this.createTerms(null, TaxonomySlug.CATEGORY, depth, count);
|
||||
await this.createLevelTerm();
|
||||
const domains = this.depts.filter((item) => item.isDomain);
|
||||
for (const domain of domains) {
|
||||
await this.createTerms(domain, TaxonomySlug.CATEGORY, depth, count);
|
||||
|
@ -139,6 +143,64 @@ export class GenDevService {
|
|||
collectChildren(domainId);
|
||||
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) {
|
||||
if (this.counts.staffCount === 1) {
|
||||
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(
|
||||
name: string,
|
||||
parentId?: string | null,
|
||||
|
|
|
@ -1,34 +1,44 @@
|
|||
import { db, getRandomElement, getRandomIntInRange, getRandomTimeInterval, } from '@nice/common';
|
||||
import {
|
||||
db,
|
||||
getRandomElement,
|
||||
getRandomIntInRange,
|
||||
getRandomTimeInterval,
|
||||
PostType,
|
||||
} from '@nice/common';
|
||||
import dayjs from 'dayjs';
|
||||
export interface DevDataCounts {
|
||||
deptCount: number;
|
||||
deptCount: number;
|
||||
|
||||
staffCount: number
|
||||
termCount: number
|
||||
staffCount: number;
|
||||
termCount: number;
|
||||
courseCount: number;
|
||||
}
|
||||
export async function getCounts(): Promise<DevDataCounts> {
|
||||
const counts = {
|
||||
deptCount: await db.department.count(),
|
||||
const counts = {
|
||||
deptCount: await db.department.count(),
|
||||
|
||||
staffCount: await db.staff.count(),
|
||||
termCount: await db.term.count(),
|
||||
};
|
||||
return counts;
|
||||
staffCount: await db.staff.count(),
|
||||
termCount: await db.term.count(),
|
||||
courseCount: await db.post.count({
|
||||
where: {
|
||||
type: PostType.COURSE,
|
||||
},
|
||||
}),
|
||||
};
|
||||
return counts;
|
||||
}
|
||||
export function capitalizeFirstLetter(string: string) {
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
return string.charAt(0).toUpperCase() + string.slice(1);
|
||||
}
|
||||
export function getRandomImageLinks(count: number = 5): string[] {
|
||||
const baseUrl = 'https://picsum.photos/200/300?random=';
|
||||
const imageLinks: string[] = [];
|
||||
const baseUrl = 'https://picsum.photos/200/300?random=';
|
||||
const imageLinks: string[] = [];
|
||||
|
||||
for (let i = 0; i < count; i++) {
|
||||
// 生成随机数以确保每个链接都是唯一的
|
||||
const randomId = Math.floor(Math.random() * 1000);
|
||||
imageLinks.push(`${baseUrl}${randomId}`);
|
||||
}
|
||||
for (let i = 0; i < count; i++) {
|
||||
// 生成随机数以确保每个链接都是唯一的
|
||||
const randomId = Math.floor(Math.random() * 1000);
|
||||
imageLinks.push(`${baseUrl}${randomId}`);
|
||||
}
|
||||
|
||||
return imageLinks;
|
||||
return imageLinks;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -1,33 +1,26 @@
|
|||
import {
|
||||
AppConfigSlug,
|
||||
BaseSetting,
|
||||
RolePerms,
|
||||
} from "@nice/common";
|
||||
import { AppConfigSlug, BaseSetting, RolePerms } from "@nice/common";
|
||||
import { useContext, useEffect, useState } from "react";
|
||||
import {
|
||||
Button,
|
||||
Form,
|
||||
Input,
|
||||
message,
|
||||
theme,
|
||||
} from "antd";
|
||||
import { Button, Form, Input, message, theme } from "antd";
|
||||
import { useAppConfig } from "@nice/client";
|
||||
import { useAuth } from "@web/src/providers/auth-provider";
|
||||
|
||||
import FixedHeader from "@web/src/components/layout/fix-header";
|
||||
import { useForm } from "antd/es/form/Form";
|
||||
import { api } from "@nice/client"
|
||||
import { api } from "@nice/client";
|
||||
import { MainLayoutContext } from "../layout";
|
||||
|
||||
export default function BaseSettingPage() {
|
||||
const { update, baseSetting } = useAppConfig();
|
||||
const utils = api.useUtils()
|
||||
const [form] = useForm()
|
||||
const utils = api.useUtils();
|
||||
const [form] = useForm();
|
||||
const { token } = theme.useToken();
|
||||
const { data: clientCount } = api.app_config.getClientCount.useQuery(undefined, {
|
||||
refetchInterval: 3000,
|
||||
refetchIntervalInBackground: true
|
||||
})
|
||||
const { data: clientCount } = api.app_config.getClientCount.useQuery(
|
||||
undefined,
|
||||
{
|
||||
refetchInterval: 3000,
|
||||
refetchIntervalInBackground: true,
|
||||
}
|
||||
);
|
||||
const [isFormChanged, setIsFormChanged] = useState(false);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const { user, hasSomePermissions } = useAuth();
|
||||
|
@ -36,31 +29,27 @@ export default function BaseSettingPage() {
|
|||
setIsFormChanged(true);
|
||||
}
|
||||
function onResetClick() {
|
||||
if (!form)
|
||||
return
|
||||
if (!form) return;
|
||||
if (!baseSetting) {
|
||||
form.resetFields();
|
||||
} else {
|
||||
form.resetFields();
|
||||
form.setFieldsValue(baseSetting);
|
||||
|
||||
}
|
||||
setIsFormChanged(false);
|
||||
}
|
||||
function onSaveClick() {
|
||||
if (form)
|
||||
form.submit();
|
||||
if (form) form.submit();
|
||||
}
|
||||
async function onSubmit(values: BaseSetting) {
|
||||
setLoading(true);
|
||||
|
||||
try {
|
||||
|
||||
await update.mutateAsync({
|
||||
where: {
|
||||
slug: AppConfigSlug.BASE_SETTING,
|
||||
},
|
||||
data: { meta: JSON.stringify(values) }
|
||||
data: { meta: { ...baseSetting, ...values } },
|
||||
});
|
||||
setIsFormChanged(false);
|
||||
message.success("已保存");
|
||||
|
@ -72,7 +61,6 @@ export default function BaseSettingPage() {
|
|||
}
|
||||
useEffect(() => {
|
||||
if (baseSetting && form) {
|
||||
|
||||
form.setFieldsValue(baseSetting);
|
||||
}
|
||||
}, [baseSetting, form]);
|
||||
|
@ -103,7 +91,6 @@ export default function BaseSettingPage() {
|
|||
!hasSomePermissions(RolePerms.MANAGE_BASE_SETTING)
|
||||
}
|
||||
onFinish={onSubmit}
|
||||
|
||||
onFieldsChange={handleFieldsChange}
|
||||
layout="vertical">
|
||||
{/* <div
|
||||
|
@ -173,17 +160,21 @@ export default function BaseSettingPage() {
|
|||
清除行模型缓存
|
||||
</Button>
|
||||
</div>
|
||||
{<div
|
||||
className="p-2 border-b text-primary flex justify-between items-center"
|
||||
style={{
|
||||
fontSize: token.fontSize,
|
||||
fontWeight: "bold",
|
||||
}}>
|
||||
<span>app在线人数</span>
|
||||
<div>
|
||||
{clientCount && clientCount > 0 ? `${clientCount}人在线` : '无人在线'}
|
||||
{
|
||||
<div
|
||||
className="p-2 border-b text-primary flex justify-between items-center"
|
||||
style={{
|
||||
fontSize: token.fontSize,
|
||||
fontWeight: "bold",
|
||||
}}>
|
||||
<span>app在线人数</span>
|
||||
<div>
|
||||
{clientCount && clientCount > 0
|
||||
? `${clientCount}人在线`
|
||||
: "无人在线"}
|
||||
</div>
|
||||
</div>
|
||||
</div>}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import React, { useState, useMemo, useEffect } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Button, Card, Typography, Tag, Progress,Spin } from 'antd';
|
||||
import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
||||
import { Button, Card, Typography, Tag, Progress, Spin } from 'antd';
|
||||
import {
|
||||
PlayCircleOutlined,
|
||||
UserOutlined,
|
||||
|
@ -8,36 +8,37 @@ import {
|
|||
TeamOutlined,
|
||||
StarOutlined,
|
||||
ArrowRightOutlined,
|
||||
EyeOutlined,
|
||||
} from '@ant-design/icons';
|
||||
import { TaxonomySlug, TermDto } from '@nice/common';
|
||||
import { api } from '@nice/client';
|
||||
|
||||
// const {courseId} = useParams();
|
||||
interface GetTaxonomyProps {
|
||||
categories: string[];
|
||||
isLoading: boolean;
|
||||
}
|
||||
|
||||
function useGetTaxonomy({type}) : GetTaxonomyProps {
|
||||
const {data,isLoading} :{data:TermDto[],isLoading:boolean}= api.term.findMany.useQuery({
|
||||
where:{
|
||||
taxonomy: {
|
||||
//TaxonomySlug.CATEGORY
|
||||
slug:type
|
||||
}
|
||||
},
|
||||
include:{
|
||||
children :true
|
||||
},
|
||||
take:10, // 只取前10个
|
||||
orderBy: {
|
||||
createdAt: 'desc', // 按创建时间降序排列
|
||||
},
|
||||
function useGetTaxonomy({ type }): GetTaxonomyProps {
|
||||
const { data, isLoading }: { data: TermDto[], isLoading: boolean } = api.term.findMany.useQuery({
|
||||
where: {
|
||||
taxonomy: {
|
||||
//TaxonomySlug.CATEGORY
|
||||
slug: type
|
||||
}
|
||||
},
|
||||
include: {
|
||||
children: true
|
||||
},
|
||||
take: 10, // 只取前10个
|
||||
orderBy: {
|
||||
createdAt: 'desc', // 按创建时间降序排列
|
||||
},
|
||||
})
|
||||
const categories = useMemo(() => {
|
||||
const allCategories = isLoading ? [] : data?.map((course) => course.name);
|
||||
return [...Array.from(new Set(allCategories))];
|
||||
const allCategories = isLoading ? [] : data?.map((course) => course.name);
|
||||
return [...Array.from(new Set(allCategories))];
|
||||
}, [data]);
|
||||
return {categories,isLoading}
|
||||
return { categories, isLoading }
|
||||
}
|
||||
|
||||
|
||||
|
@ -63,7 +64,6 @@ interface CoursesSectionProps {
|
|||
initialVisibleCoursesCount?: number;
|
||||
}
|
||||
|
||||
|
||||
const CoursesSection: React.FC<CoursesSectionProps> = ({
|
||||
title,
|
||||
description,
|
||||
|
@ -73,12 +73,20 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
|||
const navigate = useNavigate();
|
||||
const [selectedCategory, setSelectedCategory] = useState<string>('全部');
|
||||
const [visibleCourses, setVisibleCourses] = useState(initialVisibleCoursesCount);
|
||||
const gateGory : GetTaxonomyProps = useGetTaxonomy({
|
||||
const gateGory: GetTaxonomyProps = useGetTaxonomy({
|
||||
type: TaxonomySlug.CATEGORY,
|
||||
})
|
||||
const { data } = api.post.findMany.useQuery({
|
||||
take: 8,
|
||||
}
|
||||
)
|
||||
useEffect(() => {
|
||||
|
||||
})
|
||||
console.log(data,'成功')
|
||||
}, [data])
|
||||
const handleClick = (course: Course) => {
|
||||
navigate(`/courses?courseId=${course.id}/detail`);
|
||||
}
|
||||
|
||||
const filteredCourses = useMemo(() => {
|
||||
return selectedCategory === '全部'
|
||||
? courses
|
||||
|
@ -86,76 +94,74 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
|||
}, [selectedCategory, courses]);
|
||||
|
||||
const displayedCourses = filteredCourses.slice(0, visibleCourses);
|
||||
|
||||
return (
|
||||
<section className="relative py-16 overflow-hidden">
|
||||
<div className="max-w-screen-2xl mx-auto px-4 relative">
|
||||
<div className="flex justify-between items-end mb-12">
|
||||
<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-6 relative">
|
||||
<div className="flex justify-between items-end mb-16">
|
||||
<div>
|
||||
<Title
|
||||
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>
|
||||
<Text type="secondary" className="text-xl font-light">
|
||||
<Text type="secondary" className="text-xl font-light text-gray-600">
|
||||
{description}
|
||||
</Text>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="mb-8 flex flex-wrap gap-3">
|
||||
{gateGory.isLoading ? <Spin className='m-3'/> :
|
||||
<div className="mb-12 flex flex-wrap gap-4">
|
||||
{gateGory.isLoading ? <Spin className='m-3' /> :
|
||||
(
|
||||
<>
|
||||
<Tag
|
||||
color={selectedCategory === "全部" ? 'blue' : 'default'}
|
||||
onClick={() => setSelectedCategory("全部")}
|
||||
className={`px-4 py-2 text-base cursor-pointer hover:scale-105 transform transition-all duration-300 ${selectedCategory === "全部"
|
||||
? 'shadow-[0_2px_8px_-4px_rgba(59,130,246,0.5)]'
|
||||
: 'hover:shadow-md'
|
||||
}`}
|
||||
>全部</Tag>
|
||||
{
|
||||
gateGory.categories.map((category) => (
|
||||
<Tag
|
||||
key={category}
|
||||
color={selectedCategory === category ? 'blue' : 'default'}
|
||||
onClick={() => setSelectedCategory(category)}
|
||||
className={`px-4 py-2 text-base cursor-pointer hover:scale-105 transform transition-all duration-300 ${selectedCategory === category
|
||||
? 'shadow-[0_2px_8px_-4px_rgba(59,130,246,0.5)]'
|
||||
: 'hover:shadow-md'
|
||||
}`}
|
||||
>
|
||||
{category}
|
||||
</Tag>
|
||||
))
|
||||
}
|
||||
<Tag
|
||||
color={selectedCategory === "全部" ? 'blue' : 'default'}
|
||||
onClick={() => setSelectedCategory("全部")}
|
||||
className={`px-6 py-2 text-base cursor-pointer rounded-full transition-all duration-300 ${selectedCategory === "全部"
|
||||
? 'bg-blue-600 text-white shadow-lg'
|
||||
: 'bg-white text-gray-600 hover:bg-gray-100'
|
||||
}`}
|
||||
>全部</Tag>
|
||||
{
|
||||
gateGory.categories.map((category) => (
|
||||
<Tag
|
||||
key={category}
|
||||
color={selectedCategory === category ? 'blue' : 'default'}
|
||||
onClick={() => setSelectedCategory(category)}
|
||||
className={`px-6 py-2 text-base cursor-pointer rounded-full transition-all duration-300 ${selectedCategory === category
|
||||
? 'bg-blue-600 text-white shadow-lg'
|
||||
: 'bg-white text-gray-600 hover:bg-gray-100'
|
||||
}`}
|
||||
>
|
||||
{category}
|
||||
</Tag>
|
||||
))
|
||||
}
|
||||
</>
|
||||
|
||||
)
|
||||
}
|
||||
}
|
||||
</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) => (
|
||||
<Card
|
||||
onClick={() => handleClick(course)}
|
||||
key={course.id}
|
||||
hoverable
|
||||
className="group overflow-hidden rounded-2xl border-0 bg-white/70 backdrop-blur-sm
|
||||
shadow-[0_10px_40px_-15px_rgba(0,0,0,0.1)] hover:shadow-[0_20px_50px_-15px_rgba(0,0,0,0.15)]
|
||||
transition-all duration-700 ease-out transform hover:-translate-y-1 will-change-transform"
|
||||
className="group overflow-hidden rounded-2xl border border-gray-200 bg-white
|
||||
shadow-xl hover:shadow-2xl transition-all duration-300 transform hover:-translate-y-2"
|
||||
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
|
||||
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})` }}
|
||||
/>
|
||||
<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" />
|
||||
<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" />
|
||||
<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-300" />
|
||||
{course.progress > 0 && (
|
||||
<div className="absolute bottom-0 left-0 right-0 backdrop-blur-md bg-black/20">
|
||||
<Progress
|
||||
<div className="absolute bottom-0 left-0 right-0 backdrop-blur-md bg-black/30">
|
||||
{/* <Progress
|
||||
percent={course.progress}
|
||||
showInfo={false}
|
||||
strokeColor={{
|
||||
|
@ -163,17 +169,17 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
|||
to: '#60a5fa',
|
||||
}}
|
||||
className="m-0"
|
||||
/>
|
||||
/> */}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<div className="px-2">
|
||||
<div className="px-4">
|
||||
<div className="flex gap-2 mb-4">
|
||||
<Tag
|
||||
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}
|
||||
</Tag>
|
||||
|
@ -185,35 +191,28 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
|||
? 'blue'
|
||||
: '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}
|
||||
</Tag>
|
||||
</div>
|
||||
<Title
|
||||
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>
|
||||
<div className="flex items-center mb-4 transition-all duration-300 group-hover:text-blue-500">
|
||||
<UserOutlined className="mr-2 text-blue-500" />
|
||||
<Text className="text-gray-600 font-medium group-hover:text-blue-500">
|
||||
{course.instructor}
|
||||
</Text>
|
||||
</div>
|
||||
<div className="flex justify-between items-center mb-4 text-gray-500 text-sm">
|
||||
<span className="flex items-center">
|
||||
<ClockCircleOutlined className="mr-1.5" />
|
||||
{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}
|
||||
|
||||
<div className="flex items-center mb-4 p-2 rounded-lg transition-all duration-300 hover:bg-blue-50 group">
|
||||
<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}
|
||||
</Text>
|
||||
</div>
|
||||
<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">
|
||||
<EyeOutlined className="ml-1.5 text-sm" />
|
||||
<span className="text-xs font-medium">观看次数{course.progress}次</span>
|
||||
</span>
|
||||
</div>
|
||||
<div className="pt-4 border-t border-gray-100 text-center">
|
||||
|
@ -226,25 +225,25 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
|||
立即学习
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{filteredCourses.length >= visibleCourses && (
|
||||
<div className=' flex items-center gap-4 justify-between mt-6'>
|
||||
<div className='h-[1px] flex-grow bg-gray-200'></div>
|
||||
<div className="flex justify-end ">
|
||||
<div
|
||||
<div className='flex items-center gap-4 justify-between mt-12'>
|
||||
<div className='h-[1px] flex-grow bg-gradient-to-r from-transparent via-gray-300 to-transparent'></div>
|
||||
<div className="flex justify-end">
|
||||
<Button
|
||||
type="link"
|
||||
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"
|
||||
>
|
||||
查看更多
|
||||
|
||||
</div>
|
||||
|
||||
<ArrowRightOutlined />
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
|
|
@ -1,160 +1,135 @@
|
|||
import React, { useRef, useCallback } from 'react';
|
||||
import { Button, Carousel, Typography } from 'antd';
|
||||
import React, { useRef, useCallback } from "react";
|
||||
import { Button, Carousel, Typography } from "antd";
|
||||
import {
|
||||
TeamOutlined,
|
||||
BookOutlined,
|
||||
StarOutlined,
|
||||
ClockCircleOutlined,
|
||||
LeftOutlined,
|
||||
RightOutlined,
|
||||
EyeOutlined
|
||||
} from '@ant-design/icons';
|
||||
import type { CarouselRef } from 'antd/es/carousel';
|
||||
TeamOutlined,
|
||||
BookOutlined,
|
||||
StarOutlined,
|
||||
ClockCircleOutlined,
|
||||
LeftOutlined,
|
||||
RightOutlined,
|
||||
EyeOutlined,
|
||||
} from "@ant-design/icons";
|
||||
import type { CarouselRef } from "antd/es/carousel";
|
||||
|
||||
const { Title, Text } = Typography;
|
||||
|
||||
interface CarouselItem {
|
||||
title: string;
|
||||
desc: string;
|
||||
image: string;
|
||||
action: string;
|
||||
color: string;
|
||||
title: string;
|
||||
desc: string;
|
||||
image: string;
|
||||
action: string;
|
||||
color: string;
|
||||
}
|
||||
|
||||
interface PlatformStat {
|
||||
icon: React.ReactNode;
|
||||
value: string;
|
||||
label: string;
|
||||
icon: React.ReactNode;
|
||||
value: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
const carouselItems: CarouselItem[] = [
|
||||
{
|
||||
title: '探索编程世界',
|
||||
desc: '从零开始学习编程,开启你的技术之旅',
|
||||
image: '/images/banner1.jpg',
|
||||
action: '立即开始',
|
||||
color: 'from-blue-600/90'
|
||||
},
|
||||
{
|
||||
title: '人工智能课程',
|
||||
desc: '掌握AI技术,引领未来发展',
|
||||
image: '/images/banner2.jpg',
|
||||
action: '了解更多',
|
||||
color: 'from-purple-600/90'
|
||||
}
|
||||
{
|
||||
title: "探索编程世界",
|
||||
desc: "从零开始学习编程,开启你的技术之旅",
|
||||
image: "/images/banner1.jpg",
|
||||
action: "立即开始",
|
||||
color: "from-blue-600/90",
|
||||
},
|
||||
{
|
||||
title: "人工智能课程",
|
||||
desc: "掌握AI技术,引领未来发展",
|
||||
image: "/images/banner2.jpg",
|
||||
action: "了解更多",
|
||||
color: "from-purple-600/90",
|
||||
},
|
||||
];
|
||||
|
||||
const platformStats: PlatformStat[] = [
|
||||
{ icon: <TeamOutlined />, value: '50,000+', label: '注册学员' },
|
||||
{ icon: <BookOutlined />, value: '1,000+', label: '精品课程' },
|
||||
// { icon: <StarOutlined />, value: '98%', label: '好评度' },
|
||||
{ icon: <EyeOutlined />, value: '100万+', label: '观看次数' }
|
||||
{ icon: <TeamOutlined />, value: "50,000+", label: "注册学员" },
|
||||
{ icon: <BookOutlined />, value: "1,000+", label: "精品课程" },
|
||||
// { icon: <StarOutlined />, value: '98%', label: '好评度' },
|
||||
{ icon: <EyeOutlined />, value: "100万+", label: "观看次数" },
|
||||
];
|
||||
|
||||
const HeroSection = () => {
|
||||
const carouselRef = useRef<CarouselRef>(null);
|
||||
const carouselRef = useRef<CarouselRef>(null);
|
||||
|
||||
const handlePrev = useCallback(() => {
|
||||
carouselRef.current?.prev();
|
||||
}, []);
|
||||
const handlePrev = useCallback(() => {
|
||||
carouselRef.current?.prev();
|
||||
}, []);
|
||||
|
||||
const handleNext = useCallback(() => {
|
||||
carouselRef.current?.next();
|
||||
}, []);
|
||||
const handleNext = useCallback(() => {
|
||||
carouselRef.current?.next();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<section className="relative ">
|
||||
<div className="group">
|
||||
<Carousel
|
||||
ref={carouselRef}
|
||||
autoplay
|
||||
effect="fade"
|
||||
className="h-[600px] mb-24"
|
||||
dots={{
|
||||
className: 'carousel-dots !bottom-32 !z-20',
|
||||
}}
|
||||
>
|
||||
{carouselItems.map((item, index) => (
|
||||
<div key={index} className="relative h-[600px]">
|
||||
<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]"
|
||||
style={{
|
||||
backgroundImage: `url(${item.image})`,
|
||||
backfaceVisibility: 'hidden'
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
className={`absolute inset-0 bg-gradient-to-r ${item.color} to-transparent opacity-90 mix-blend-overlay transition-opacity duration-500`}
|
||||
/>
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/50 to-transparent" />
|
||||
return (
|
||||
<section className="relative ">
|
||||
<div className="group">
|
||||
<Carousel
|
||||
ref={carouselRef}
|
||||
autoplay
|
||||
effect="fade"
|
||||
className="h-[600px] mb-24"
|
||||
dots={{
|
||||
className: "carousel-dots !bottom-32 !z-20",
|
||||
}}>
|
||||
{carouselItems.map((item, index) => (
|
||||
<div key={index} className="relative h-[600px]">
|
||||
<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]"
|
||||
style={{
|
||||
backgroundImage: `url(${item.image})`,
|
||||
backfaceVisibility: "hidden",
|
||||
}}
|
||||
/>
|
||||
<div
|
||||
className={`absolute inset-0 bg-gradient-to-r ${item.color} to-transparent opacity-90 mix-blend-overlay transition-opacity duration-500`}
|
||||
/>
|
||||
<div className="absolute inset-0 bg-gradient-to-t from-black/50 to-transparent" />
|
||||
|
||||
{/* Content Container */}
|
||||
<div className="relative h-full max-w-7xl mx-auto px-6 lg:px-8">
|
||||
<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>
|
||||
))}
|
||||
</Carousel>
|
||||
{/* Content Container */}
|
||||
<div className="relative h-full max-w-7xl mx-auto px-6 lg:px-8"></div>
|
||||
</div>
|
||||
))}
|
||||
</Carousel>
|
||||
|
||||
{/* Navigation Buttons */}
|
||||
<button
|
||||
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"
|
||||
aria-label="Previous slide"
|
||||
>
|
||||
<LeftOutlined className="text-white text-xl" />
|
||||
</button>
|
||||
<button
|
||||
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"
|
||||
aria-label="Next slide"
|
||||
>
|
||||
<RightOutlined className="text-white text-xl" />
|
||||
</button>
|
||||
</div>
|
||||
{/* Navigation Buttons */}
|
||||
<button
|
||||
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"
|
||||
aria-label="Previous slide">
|
||||
<LeftOutlined className="text-white text-xl" />
|
||||
</button>
|
||||
<button
|
||||
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"
|
||||
aria-label="Next slide">
|
||||
<RightOutlined className="text-white text-xl" />
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Stats Container */}
|
||||
<div className="absolute -bottom-24 left-1/2 -translate-x-1/2 w-1/2 max-w-6xl px-4">
|
||||
<div className="rounded-2xl grid grid-cols-2 md:grid-cols-3 gap-4 md:gap-8 p-6 md:p-8 bg-white border shadow-xl hover:shadow-2xl transition-shadow duration-500 will-change-[transform,box-shadow]">
|
||||
{platformStats.map((stat, index) => (
|
||||
<div
|
||||
key={index}
|
||||
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">
|
||||
{stat.icon}
|
||||
</div>
|
||||
<div className="text-2xl font-bold bg-gradient-to-r from-gray-800 to-gray-600 bg-clip-text text-transparent mb-1.5">
|
||||
{stat.value}
|
||||
</div>
|
||||
<div className="text-gray-600 font-medium">
|
||||
{stat.label}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
{/* Stats Container */}
|
||||
<div className="absolute -bottom-24 left-1/2 -translate-x-1/2 w-1/2 max-w-6xl px-4">
|
||||
<div className="rounded-2xl grid grid-cols-2 md:grid-cols-3 gap-4 md:gap-8 p-6 md:p-8 bg-white border shadow-xl hover:shadow-2xl transition-shadow duration-500 will-change-[transform,box-shadow]">
|
||||
{platformStats.map((stat, index) => (
|
||||
<div
|
||||
key={index}
|
||||
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">
|
||||
{stat.icon}
|
||||
</div>
|
||||
<div className="text-2xl font-bold bg-gradient-to-r from-gray-800 to-gray-600 bg-clip-text text-transparent mb-1.5">
|
||||
{stat.value}
|
||||
</div>
|
||||
<div className="text-gray-600 font-medium">
|
||||
{stat.label}
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
};
|
||||
|
||||
export default HeroSection;
|
||||
export default HeroSection;
|
||||
|
|
|
@ -15,7 +15,7 @@ const HomePage = () => {
|
|||
level: '入门',
|
||||
duration: '36小时',
|
||||
category: '编程语言',
|
||||
progress: 0,
|
||||
progress: 16,
|
||||
thumbnail: '/images/course1.jpg',
|
||||
},
|
||||
{
|
||||
|
@ -51,7 +51,7 @@ const HomePage = () => {
|
|||
level: '高级',
|
||||
duration: '56小时',
|
||||
category: '编程语言',
|
||||
progress: 0,
|
||||
progress: 15,
|
||||
thumbnail: '/images/course4.jpg',
|
||||
},
|
||||
{
|
||||
|
@ -99,15 +99,13 @@ const HomePage = () => {
|
|||
level: '中级',
|
||||
duration: '40小时',
|
||||
category: '移动开发',
|
||||
progress: 0,
|
||||
progress: 70,
|
||||
thumbnail: '/images/course8.jpg',
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<div className="min-h-screen">
|
||||
<HeroSection />
|
||||
|
||||
<CoursesSection
|
||||
title="推荐课程"
|
||||
description="最受欢迎的精品课程,助你快速成长"
|
||||
|
|
|
@ -36,7 +36,7 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
|||
const [file, setFile] = useState<UploadingFile | null>(null);
|
||||
const avatarRef = useRef<HTMLImageElement>(null);
|
||||
const [previewUrl, setPreviewUrl] = useState<string>(value || "");
|
||||
|
||||
const [imageSrc, setImageSrc] = useState(value);
|
||||
const [compressedUrl, setCompressedUrl] = useState<string>(value || "");
|
||||
const [url, setUrl] = useState<string>(value || "");
|
||||
const [uploading, setUploading] = useState(false);
|
||||
|
@ -45,7 +45,9 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
|||
const [avatarKey, setAvatarKey] = useState(0);
|
||||
const { token } = theme.useToken();
|
||||
useEffect(() => {
|
||||
setPreviewUrl(value || "");
|
||||
if (!previewUrl || previewUrl?.length < 1) {
|
||||
setPreviewUrl(value || "");
|
||||
}
|
||||
}, [value]);
|
||||
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const selectedFile = event.target.files?.[0];
|
||||
|
@ -128,6 +130,14 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
|||
ref={avatarRef}
|
||||
src={previewUrl}
|
||||
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"
|
||||
/>
|
||||
) : (
|
||||
|
|
|
@ -6,7 +6,6 @@ interface CourseStatsProps {
|
|||
completionRate?: number;
|
||||
totalDuration?: number;
|
||||
}
|
||||
|
||||
export const CourseStats = ({
|
||||
averageRating,
|
||||
numberOfReviews,
|
||||
|
|
|
@ -109,11 +109,12 @@ export function CourseFormProvider({
|
|||
}
|
||||
try {
|
||||
if (editId) {
|
||||
await update.mutateAsync({
|
||||
const result = await update.mutateAsync({
|
||||
where: { id: editId },
|
||||
data: formattedValues,
|
||||
});
|
||||
message.success("课程更新成功!");
|
||||
navigate(`/course/${result.id}/editor/content`);
|
||||
} else {
|
||||
const result = await createCourse.mutateAsync({
|
||||
courseDetail: {
|
||||
|
@ -127,8 +128,8 @@ export function CourseFormProvider({
|
|||
},
|
||||
sections,
|
||||
});
|
||||
navigate(`/course/${result.id}/editor`, { replace: true });
|
||||
message.success("课程创建成功!");
|
||||
navigate(`/course/${result.id}/editor/content`);
|
||||
}
|
||||
form.resetFields();
|
||||
} catch (error) {
|
||||
|
|
|
@ -24,6 +24,7 @@ import { CourseContentFormHeader } from "./CourseContentFormHeader";
|
|||
import { CourseSectionEmpty } from "./CourseSectionEmpty";
|
||||
import { SortableSection } from "./SortableSection";
|
||||
import { LectureList } from "./LectureList";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
const CourseContentForm: React.FC = () => {
|
||||
const { editId } = useCourseEditor();
|
||||
|
@ -33,7 +34,7 @@ const CourseContentForm: React.FC = () => {
|
|||
coordinateGetter: sortableKeyboardCoordinates,
|
||||
})
|
||||
);
|
||||
const { softDeleteByIds } = usePost();
|
||||
const { softDeleteByIds, updateOrderByIds } = usePost();
|
||||
const { data: sections = [], isLoading } = api.post.findMany.useQuery(
|
||||
{
|
||||
where: {
|
||||
|
@ -41,6 +42,9 @@ const CourseContentForm: React.FC = () => {
|
|||
type: PostType.SECTION,
|
||||
deletedAt: null,
|
||||
},
|
||||
orderBy: {
|
||||
order: "asc",
|
||||
},
|
||||
},
|
||||
{
|
||||
enabled: !!editId,
|
||||
|
@ -56,11 +60,15 @@ const CourseContentForm: React.FC = () => {
|
|||
const handleDragEnd = (event: DragEndEvent) => {
|
||||
const { active, over } = event;
|
||||
if (!over || active.id === over.id) return;
|
||||
|
||||
let newItems = [];
|
||||
setItems((items) => {
|
||||
const oldIndex = items.findIndex((item) => item.id === active.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 />}
|
||||
className="mt-4"
|
||||
onClick={() => {
|
||||
setItems([
|
||||
...items.filter((item) => !!item.id),
|
||||
{ id: null, title: "" },
|
||||
]);
|
||||
if (items.some((item) => item.id === null)) {
|
||||
toast.error("请先保存当前编辑的章节");
|
||||
} else {
|
||||
setItems([...items, { id: null, title: "" }]);
|
||||
}
|
||||
}}>
|
||||
添加章节
|
||||
</Button>
|
||||
|
|
|
@ -38,6 +38,7 @@ import { useCourseEditor } from "../../context/CourseEditorContext";
|
|||
import { usePost } from "@nice/client";
|
||||
import { LectureData, SectionData } from "./interface";
|
||||
import { SortableLecture } from "./SortableLecture";
|
||||
import toast from "react-hot-toast";
|
||||
|
||||
interface LectureListProps {
|
||||
field: SectionData;
|
||||
|
@ -48,7 +49,7 @@ export const LectureList: React.FC<LectureListProps> = ({
|
|||
field,
|
||||
sectionId,
|
||||
}) => {
|
||||
const { softDeleteByIds } = usePost();
|
||||
const { softDeleteByIds, updateOrderByIds } = usePost();
|
||||
const { data: lectures = [], isLoading } = (
|
||||
api.post.findMany as any
|
||||
).useQuery(
|
||||
|
@ -58,6 +59,9 @@ export const LectureList: React.FC<LectureListProps> = ({
|
|||
type: PostType.LECTURE,
|
||||
deletedAt: null,
|
||||
},
|
||||
orderBy: {
|
||||
order: "asc",
|
||||
},
|
||||
},
|
||||
{
|
||||
enabled: !!sectionId,
|
||||
|
@ -84,11 +88,19 @@ export const LectureList: React.FC<LectureListProps> = ({
|
|||
const handleDragEnd = (event: DragEndEvent) => {
|
||||
const { active, over } = event;
|
||||
if (!over || active.id === over.id) return;
|
||||
|
||||
// updateOrder.mutateAsync({
|
||||
// id: active.id,
|
||||
// overId: over.id,
|
||||
// });
|
||||
let newItems = [];
|
||||
setItems((items) => {
|
||||
const oldIndex = items.findIndex((item) => item.id === active.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,16 +136,20 @@ export const LectureList: React.FC<LectureListProps> = ({
|
|||
icon={<PlusOutlined />}
|
||||
className="mt-4"
|
||||
onClick={() => {
|
||||
setItems((prevItems) => [
|
||||
...prevItems.filter((item) => !!item.id),
|
||||
{
|
||||
id: null,
|
||||
title: "",
|
||||
meta: {
|
||||
type: LectureType.ARTICLE,
|
||||
},
|
||||
} as Lecture,
|
||||
]);
|
||||
if (items.some((item) => item.id === null)) {
|
||||
toast.error("请先保存当前编辑中的课时!");
|
||||
} else {
|
||||
setItems((prevItems) => [
|
||||
...prevItems.filter((item) => !!item.id),
|
||||
{
|
||||
id: null,
|
||||
title: "",
|
||||
meta: {
|
||||
type: LectureType.ARTICLE,
|
||||
},
|
||||
} as Lecture,
|
||||
]);
|
||||
}
|
||||
}}>
|
||||
添加课时
|
||||
</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,
|
||||
Link,
|
||||
NonIndexRouteObject,
|
||||
useParams,
|
||||
} from "react-router-dom";
|
||||
import ErrorPage from "../app/error";
|
||||
import WithAuth from "../components/utils/with-auth";
|
||||
|
@ -40,6 +41,7 @@ export type CustomRouteObject =
|
|||
| CustomIndexRouteObject
|
||||
| CustomNonIndexRouteObject;
|
||||
export const routes: CustomRouteObject[] = [
|
||||
|
||||
{
|
||||
path: "/",
|
||||
errorElement: <ErrorPage />,
|
||||
|
@ -144,4 +146,5 @@ export const routes: CustomRouteObject[] = [
|
|||
},
|
||||
];
|
||||
|
||||
|
||||
export const router = createBrowserRouter(routes);
|
||||
|
|
|
@ -101,6 +101,7 @@ server {
|
|||
internal;
|
||||
# 代理到认证服务
|
||||
proxy_pass http://host.docker.internal:3000/auth/file;
|
||||
|
||||
# 请求优化:不传递请求体
|
||||
proxy_pass_request_body off;
|
||||
proxy_set_header Content-Length "";
|
||||
|
|
|
@ -113,5 +113,8 @@ export function useEntity<T extends keyof RouterInputs>(
|
|||
T,
|
||||
"updateOrder"
|
||||
>, // 更新实体顺序的 mutation 函数
|
||||
updateOrderByIds: createMutationHandler(
|
||||
"updateOrderByIds"
|
||||
) as MutationResult<T, "updateOrderByIds">, // 更新实体顺序的 mutation 函数
|
||||
};
|
||||
}
|
||||
|
|
|
@ -110,6 +110,7 @@ model Department {
|
|||
id String @id @default(cuid())
|
||||
name String
|
||||
order Float?
|
||||
posts Post[] @relation("post_dept")
|
||||
ancestors DeptAncestry[] @relation("DescendantToAncestor")
|
||||
descendants DeptAncestry[] @relation("AncestorToDescendant")
|
||||
parentId String? @map("parent_id")
|
||||
|
@ -200,11 +201,13 @@ model Post {
|
|||
order Float? @default(0) @map("order")
|
||||
duration Int?
|
||||
rating Int? @default(0)
|
||||
|
||||
depts Department[] @relation("post_dept")
|
||||
// 索引
|
||||
// 日期时间类型字段
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
publishedAt DateTime? @map("published_at") // 发布时间
|
||||
updatedAt DateTime @updatedAt @map("updated_at")
|
||||
updatedAt DateTime @map("updated_at")
|
||||
deletedAt DateTime? @map("deleted_at") // 删除时间,可为空
|
||||
instructors PostInstructor[]
|
||||
// 关系类型字段
|
||||
|
@ -268,7 +271,6 @@ model Message {
|
|||
visits Visit[]
|
||||
createdAt DateTime @default(now()) @map("created_at")
|
||||
updatedAt DateTime? @updatedAt @map("updated_at")
|
||||
|
||||
@@index([type, createdAt])
|
||||
@@map("message")
|
||||
}
|
||||
|
@ -404,7 +406,6 @@ model NodeEdge {
|
|||
@@index([targetId])
|
||||
@@map("node_edge")
|
||||
}
|
||||
|
||||
model Animal {
|
||||
id String @id @default(cuid())
|
||||
name String
|
||||
|
|
|
@ -56,7 +56,7 @@ export const InitTaxonomies: {
|
|||
objectType?: string[];
|
||||
}[] = [
|
||||
{
|
||||
name: "分类",
|
||||
name: "课程分类",
|
||||
slug: TaxonomySlug.CATEGORY,
|
||||
objectType: [ObjectType.COURSE],
|
||||
},
|
||||
|
|
|
@ -100,6 +100,7 @@ export enum RolePerms {
|
|||
}
|
||||
export enum AppConfigSlug {
|
||||
BASE_SETTING = "base_setting",
|
||||
|
||||
}
|
||||
// 资源类型的枚举,定义了不同类型的资源,以字符串值表示
|
||||
export enum ResourceType {
|
||||
|
|
|
@ -77,5 +77,6 @@ export type Course = Post & {
|
|||
export type CourseDto = Course & {
|
||||
enrollments?: Enrollment[];
|
||||
sections?: SectionDto[];
|
||||
terms: TermDto[];
|
||||
terms: Term[];
|
||||
lectureCount?: number;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue