Merge branch 'main' of http://113.45.157.195:3003/insiinc/re-mooc
This commit is contained in:
commit
400b2f93dc
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,13 +58,13 @@ export class PostRouter {
|
|||
const { staff } = ctx;
|
||||
return await this.postService.update(input, staff);
|
||||
}),
|
||||
findById: this.trpc.protectProcedure
|
||||
findById: this.trpc.procedure
|
||||
.input(z.object({ id: z.string(), args: PostFindFirstArgsSchema }))
|
||||
.query(async ({ ctx, input }) => {
|
||||
const { staff } = ctx;
|
||||
return await this.postService.findById(input.id, input.args);
|
||||
}),
|
||||
findMany: this.trpc.protectProcedure
|
||||
findMany: this.trpc.procedure
|
||||
.input(PostFindManyArgsSchema)
|
||||
.query(async ({ ctx, input }) => {
|
||||
const { staff } = ctx;
|
||||
|
@ -84,7 +84,7 @@ export class PostRouter {
|
|||
.mutation(async ({ input }) => {
|
||||
return await this.postService.deleteMany(input);
|
||||
}),
|
||||
findManyWithCursor: this.trpc.protectProcedure
|
||||
findManyWithCursor: this.trpc.procedure
|
||||
.input(
|
||||
z.object({
|
||||
cursor: z.any().nullish(),
|
||||
|
|
|
@ -101,6 +101,11 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
|||
},
|
||||
params: { staff?: UserProfile; tx?: Prisma.TransactionClient },
|
||||
) {
|
||||
// const await db.post.findMany({
|
||||
// where: {
|
||||
// type: PostType.COURSE,
|
||||
// },
|
||||
// });
|
||||
const { courseDetail } = args;
|
||||
// If no transaction is provided, create a new one
|
||||
if (!params.tx) {
|
||||
|
|
|
@ -45,7 +45,7 @@ export class GenDevService {
|
|||
await this.generateDepartments(3, 6);
|
||||
await this.generateTerms(2, 6);
|
||||
await this.generateStaffs(4);
|
||||
await this.generateCourses();
|
||||
await this.generateCourses(8);
|
||||
} catch (err) {
|
||||
this.logger.error(err);
|
||||
}
|
||||
|
@ -253,9 +253,11 @@ export class GenDevService {
|
|||
{ name: '中级', taxonomyId: taxLevel.id },
|
||||
{ name: '高级', taxonomyId: taxLevel.id }, // 改为高级更合理
|
||||
];
|
||||
await this.termService.createMany({
|
||||
data: termsToCreate,
|
||||
});
|
||||
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);
|
||||
|
|
|
@ -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,9 +1,10 @@
|
|||
import { Card, Rate, Tag } from 'antd';
|
||||
import { Course } from '../mockData';
|
||||
import { UserOutlined, ClockCircleOutlined } from '@ant-design/icons';
|
||||
import { CourseDto } from '@nice/common';
|
||||
|
||||
interface CourseCardProps {
|
||||
course: Course;
|
||||
course: CourseDto;
|
||||
}
|
||||
|
||||
export default function CourseCard({ course }: CourseCardProps) {
|
||||
|
@ -14,7 +15,7 @@ export default function CourseCard({ course }: CourseCardProps) {
|
|||
cover={
|
||||
<img
|
||||
alt={course.title}
|
||||
src={course.thumbnail}
|
||||
src={course?.meta?.thumbnail}
|
||||
className="object-cover w-full h-40"
|
||||
/>
|
||||
}
|
||||
|
@ -23,7 +24,7 @@ export default function CourseCard({ course }: CourseCardProps) {
|
|||
<h3 className="text-lg font-semibold line-clamp-2 hover:text-blue-600 transition-colors">
|
||||
{course.title}
|
||||
</h3>
|
||||
<p className="text-gray-500 text-sm">{course.instructor}</p>
|
||||
<p className="text-gray-500 text-sm">{course.subTitle}</p>
|
||||
<div className="flex items-center space-x-2">
|
||||
<Rate disabled defaultValue={course.rating} className="text-sm" />
|
||||
<span className="text-gray-500 text-sm">{course.rating}</span>
|
||||
|
@ -31,7 +32,7 @@ export default function CourseCard({ course }: CourseCardProps) {
|
|||
<div className="flex items-center justify-between text-sm text-gray-500">
|
||||
<div className="flex items-center space-x-1">
|
||||
<UserOutlined className="text-gray-400" />
|
||||
<span>{course.enrollments} 人在学</span>
|
||||
<span>{course.enrollments?.length} 人在学</span>
|
||||
</div>
|
||||
<div className="flex items-center space-x-1">
|
||||
<ClockCircleOutlined className="text-gray-400" />
|
||||
|
@ -39,8 +40,8 @@ export default function CourseCard({ course }: CourseCardProps) {
|
|||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2 pt-2">
|
||||
<Tag color="blue" className="rounded-full px-3">{course.category}</Tag>
|
||||
<Tag color="green" className="rounded-full px-3">{course.level}</Tag>
|
||||
<Tag color="blue" className="rounded-full px-3">{course.terms[0].name}</Tag>
|
||||
<Tag color="green" className="rounded-full px-3">{course.terms[1].name}</Tag>
|
||||
</div>
|
||||
</div>
|
||||
</Card>
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import { Pagination, Empty } from 'antd';
|
||||
import { Course } from '../mockData';
|
||||
import CourseCard from './CourseCard';
|
||||
|
||||
import {CourseDto} from '@nice/common'
|
||||
interface CourseListProps {
|
||||
courses: Course[];
|
||||
courses: CourseDto[];
|
||||
total: number;
|
||||
pageSize: number;
|
||||
currentPage: number;
|
||||
|
|
|
@ -75,7 +75,7 @@ export default function FilterSection({
|
|||
:
|
||||
(
|
||||
<>
|
||||
<Radio value="">全部课程</Radio>
|
||||
<Radio value="" >全部课程</Radio>
|
||||
{gateGory.categories.map(category => (
|
||||
<Radio key={category} value={category}>
|
||||
{category}
|
||||
|
|
|
@ -1,59 +1,82 @@
|
|||
import { useState, useMemo } from "react";
|
||||
import { useState, useMemo, useEffect } from "react";
|
||||
import { mockCourses } from "./mockData";
|
||||
import FilterSection from "./components/FilterSection";
|
||||
import CourseList from "./components/CourseList";
|
||||
import { api } from "@nice/client";
|
||||
import { LectureType, PostType } from "@nice/common";
|
||||
import { courseDetailSelect, CourseDto, LectureType, PostType } from "@nice/common";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
import { set } from "idb-keyval";
|
||||
|
||||
|
||||
export default function CoursesPage() {
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const [selectedCategory, setSelectedCategory] = useState("");
|
||||
const [selectedLevel, setSelectedLevel] = useState("");
|
||||
const pageSize = 12;
|
||||
const { data, isLoading } = api.post.findManyWithPagination.useQuery({
|
||||
where: {
|
||||
type: PostType.COURSE,
|
||||
terms: {
|
||||
some: {
|
||||
AND: [
|
||||
...(selectedCategory
|
||||
? [
|
||||
{
|
||||
name: selectedCategory,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
...(selectedLevel
|
||||
? [
|
||||
{
|
||||
name: selectedLevel,
|
||||
},
|
||||
]
|
||||
: []),
|
||||
],
|
||||
const pageSize = 9;
|
||||
const [isAll,setIsAll] = useState(true)
|
||||
const [searchParams, setSearchParams] = useSearchParams();
|
||||
let coursesData = []
|
||||
let isCourseLoading = false
|
||||
if(!searchParams.get('searchValue')){
|
||||
console.log('no category')
|
||||
const {data,isLoading} = api.post.findManyWithPagination.useQuery({
|
||||
where: {
|
||||
type: PostType.COURSE,
|
||||
terms:isAll?{}:{
|
||||
some: {
|
||||
OR : [
|
||||
selectedCategory?{name:selectedCategory}:{},
|
||||
selectedLevel?{name:selectedLevel}:{}
|
||||
],
|
||||
},
|
||||
},
|
||||
|
||||
},
|
||||
},
|
||||
});
|
||||
const filteredCourses = useMemo(() => {
|
||||
return mockCourses.filter((course) => {
|
||||
const matchCategory =
|
||||
!selectedCategory || course.category === selectedCategory;
|
||||
const matchLevel = !selectedLevel || course.level === selectedLevel;
|
||||
return matchCategory && matchLevel;
|
||||
select:courseDetailSelect
|
||||
});
|
||||
}, [selectedCategory, selectedLevel]);
|
||||
coursesData = data?.items
|
||||
isCourseLoading = isLoading
|
||||
}else{
|
||||
console.log('searchValue:'+searchParams.get('searchValue'))
|
||||
const searchValue = searchParams.get('searchValue')
|
||||
const {data,isLoading} = api.post.findManyWithPagination.useQuery({
|
||||
where: {
|
||||
type: PostType.COURSE,
|
||||
OR:[
|
||||
{ title: { contains: searchValue, mode: 'insensitive' } },
|
||||
{ subTitle: { contains: searchValue, mode: 'insensitive' } },
|
||||
{ content: { contains: searchValue, mode: 'insensitive' } },
|
||||
{ terms: { some: { name: { contains: searchValue, mode: 'insensitive' } } } }
|
||||
]
|
||||
},
|
||||
select:courseDetailSelect
|
||||
})
|
||||
coursesData = data?.items
|
||||
isCourseLoading = isLoading
|
||||
}
|
||||
useEffect(() => {
|
||||
if(searchParams.get('searchValue')==''){
|
||||
setSelectedCategory('');
|
||||
setSelectedLevel('')
|
||||
}
|
||||
}, [searchParams.get('searchValue')]);
|
||||
const filteredCourses = useMemo(() => {
|
||||
return isCourseLoading ? [] : coursesData;
|
||||
}, [isCourseLoading, coursesData, selectedCategory, selectedLevel]);
|
||||
|
||||
const paginatedCourses = useMemo(() => {
|
||||
const paginatedCourses :CourseDto[]= useMemo(() => {
|
||||
const startIndex = (currentPage - 1) * pageSize;
|
||||
return filteredCourses.slice(startIndex, startIndex + pageSize);
|
||||
return isCourseLoading ? [] : (filteredCourses.slice(startIndex, startIndex + pageSize) as any as CourseDto[]);
|
||||
}, [filteredCourses, currentPage]);
|
||||
|
||||
const handlePageChange = (page: number) => {
|
||||
setCurrentPage(page);
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
};
|
||||
useEffect(()=>{
|
||||
setCurrentPage(1)
|
||||
},[])
|
||||
|
||||
|
||||
return (
|
||||
<div className="min-h-screen bg-gray-50">
|
||||
|
@ -69,10 +92,14 @@ export default function CoursesPage() {
|
|||
console.log(category);
|
||||
setSelectedCategory(category);
|
||||
setCurrentPage(1);
|
||||
setIsAll(!category)
|
||||
setSearchParams({ searchValue: ''});
|
||||
}}
|
||||
onLevelChange={(level) => {
|
||||
setSelectedLevel(level);
|
||||
setCurrentPage(1);
|
||||
setIsAll(!level)
|
||||
setSearchParams({ searchValue: ''});
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
|
|
@ -63,7 +63,7 @@ const CategorySection = () => {
|
|||
orderBy: {
|
||||
createdAt: 'desc', // 按创建时间降序排列
|
||||
},
|
||||
take:10
|
||||
take:8
|
||||
})
|
||||
// 分类展示
|
||||
const [displayedCategories,setDisplayedCategories] = useState<TermDto[]>([])
|
||||
|
@ -194,7 +194,11 @@ const CategorySection = () => {
|
|||
type="default"
|
||||
size="large"
|
||||
className="px-8 h-12 text-base font-medium hover:shadow-md transition-all duration-300"
|
||||
onClick={() => setShowAll(!showAll)}
|
||||
onClick={() => {
|
||||
//setShowAll(!showAll)
|
||||
navigate("/courses")
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}}
|
||||
>
|
||||
{showAll ? '收起' : '查看更多分类'}
|
||||
</Button>
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -35,6 +35,12 @@ export function MainHeader() {
|
|||
className="w-72 rounded-full"
|
||||
value={searchValue}
|
||||
onChange={(e) => setSearchValue(e.target.value)}
|
||||
onPressEnter={(e)=>{
|
||||
//console.log(e)
|
||||
setSearchValue('')
|
||||
navigate(`/courses/?searchValue=${searchValue}`)
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
{isAuthenticated && (
|
||||
|
|
|
@ -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"
|
||||
/>
|
||||
) : (
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -34,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: {
|
||||
|
@ -60,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),
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -112,7 +116,7 @@ const CourseContentForm: React.FC = () => {
|
|||
className="mt-4"
|
||||
onClick={() => {
|
||||
if (items.some((item) => item.id === null)) {
|
||||
toast.error("请先保存当前编辑章节");
|
||||
toast.error("请先保存当前编辑的章节");
|
||||
} else {
|
||||
setItems([...items, { id: null, title: "" }]);
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ export const LectureList: React.FC<LectureListProps> = ({
|
|||
className="mt-4"
|
||||
onClick={() => {
|
||||
if (items.some((item) => item.id === null)) {
|
||||
toast.error("请先保存当前编辑章节");
|
||||
toast.error("请先保存当前编辑中的课时!");
|
||||
} else {
|
||||
setItems((prevItems) => [
|
||||
...prevItems.filter((item) => !!item.id),
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -70,28 +70,27 @@ export const courseDetailSelect: Prisma.PostSelect = {
|
|||
title: true,
|
||||
subTitle: true,
|
||||
content: true,
|
||||
|
||||
level: true,
|
||||
// requirements: true,
|
||||
// objectives: true,
|
||||
// skills: true,
|
||||
// audiences: true,
|
||||
// totalDuration: true,
|
||||
// totalLectures: true,
|
||||
// averageRating: true,
|
||||
// numberOfReviews: true,
|
||||
// numberOfStudents: true,
|
||||
// completionRate: true,
|
||||
state: true,
|
||||
// isFeatured: true,
|
||||
createdAt: true,
|
||||
publishedAt: true,
|
||||
updatedAt: true,
|
||||
// 关联表选择
|
||||
children: {
|
||||
include: {
|
||||
children: true,
|
||||
terms:{
|
||||
select:{
|
||||
id:true,
|
||||
name:true,
|
||||
taxonomy:{
|
||||
select:{
|
||||
id:true,
|
||||
slug:true
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
enrollments: {
|
||||
select: {
|
||||
id: true,
|
||||
},
|
||||
},
|
||||
enrollments: true,
|
||||
meta: true,
|
||||
rating: true,
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue