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 { z, ZodType } from 'zod';
|
||||||
import { Prisma } from '@nice/common';
|
import { Prisma } from '@nice/common';
|
||||||
import { RealtimeServer } from '@server/socket/realtime/realtime.server';
|
import { RealtimeServer } from '@server/socket/realtime/realtime.server';
|
||||||
const AppConfigUncheckedCreateInputSchema: ZodType<Prisma.AppConfigUncheckedCreateInput> = z.any()
|
const AppConfigUncheckedCreateInputSchema: ZodType<Prisma.AppConfigUncheckedCreateInput> =
|
||||||
const AppConfigUpdateArgsSchema: ZodType<Prisma.AppConfigUpdateArgs> = z.any()
|
z.any();
|
||||||
const AppConfigDeleteManyArgsSchema: ZodType<Prisma.AppConfigDeleteManyArgs> = z.any()
|
const AppConfigUpdateArgsSchema: ZodType<Prisma.AppConfigUpdateArgs> = z.any();
|
||||||
const AppConfigFindFirstArgsSchema: ZodType<Prisma.AppConfigFindFirstArgs> = z.any()
|
const AppConfigDeleteManyArgsSchema: ZodType<Prisma.AppConfigDeleteManyArgs> =
|
||||||
|
z.any();
|
||||||
|
const AppConfigFindFirstArgsSchema: ZodType<Prisma.AppConfigFindFirstArgs> =
|
||||||
|
z.any();
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppConfigRouter {
|
export class AppConfigRouter {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly trpc: TrpcService,
|
private readonly trpc: TrpcService,
|
||||||
private readonly appConfigService: AppConfigService,
|
private readonly appConfigService: AppConfigService,
|
||||||
private readonly realtimeServer: RealtimeServer
|
private readonly realtimeServer: RealtimeServer,
|
||||||
) { }
|
) {}
|
||||||
router = this.trpc.router({
|
router = this.trpc.router({
|
||||||
create: this.trpc.protectProcedure
|
create: this.trpc.protectProcedure
|
||||||
.input(AppConfigUncheckedCreateInputSchema)
|
.input(AppConfigUncheckedCreateInputSchema)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
return await this.appConfigService.create({ data: input });
|
return await this.appConfigService.create({ data: input });
|
||||||
}),
|
}),
|
||||||
update: this.trpc.protectProcedure
|
update: this.trpc.protectProcedure
|
||||||
.input(AppConfigUpdateArgsSchema)
|
.input(AppConfigUpdateArgsSchema)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
const { staff } = ctx;
|
||||||
const { staff } = ctx;
|
return await this.appConfigService.update(input);
|
||||||
return await this.appConfigService.update(input);
|
}),
|
||||||
}),
|
deleteMany: this.trpc.protectProcedure
|
||||||
deleteMany: this.trpc.protectProcedure.input(AppConfigDeleteManyArgsSchema).mutation(async ({ input }) => {
|
.input(AppConfigDeleteManyArgsSchema)
|
||||||
return await this.appConfigService.deleteMany(input)
|
.mutation(async ({ input }) => {
|
||||||
}),
|
return await this.appConfigService.deleteMany(input);
|
||||||
findFirst: this.trpc.protectProcedure.input(AppConfigFindFirstArgsSchema).
|
}),
|
||||||
query(async ({ input }) => {
|
findFirst: this.trpc.protectProcedure
|
||||||
|
.input(AppConfigFindFirstArgsSchema)
|
||||||
return await this.appConfigService.findFirst(input)
|
.query(async ({ input }) => {
|
||||||
}),
|
return await this.appConfigService.findFirst(input);
|
||||||
clearRowCache: this.trpc.protectProcedure.mutation(async () => {
|
}),
|
||||||
return await this.appConfigService.clearRowCache()
|
clearRowCache: this.trpc.protectProcedure.mutation(async () => {
|
||||||
}),
|
return await this.appConfigService.clearRowCache();
|
||||||
getClientCount: this.trpc.protectProcedure.query(() => {
|
}),
|
||||||
return this.realtimeServer.getClientCount()
|
getClientCount: this.trpc.protectProcedure.query(() => {
|
||||||
})
|
return this.realtimeServer.getClientCount();
|
||||||
});
|
}),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,5 @@
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import {
|
import { db, ObjectType, Prisma } from '@nice/common';
|
||||||
db,
|
|
||||||
ObjectType,
|
|
||||||
Prisma,
|
|
||||||
} from '@nice/common';
|
|
||||||
|
|
||||||
|
|
||||||
import { BaseService } from '../base/base.service';
|
import { BaseService } from '../base/base.service';
|
||||||
import { deleteByPattern } from '@server/utils/redis/utils';
|
import { deleteByPattern } from '@server/utils/redis/utils';
|
||||||
|
@ -12,10 +7,10 @@ import { deleteByPattern } from '@server/utils/redis/utils';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AppConfigService extends BaseService<Prisma.AppConfigDelegate> {
|
export class AppConfigService extends BaseService<Prisma.AppConfigDelegate> {
|
||||||
constructor() {
|
constructor() {
|
||||||
super(db, "appConfig");
|
super(db, 'appConfig');
|
||||||
}
|
}
|
||||||
async clearRowCache() {
|
async clearRowCache() {
|
||||||
await deleteByPattern("row-*")
|
await deleteByPattern('row-*');
|
||||||
return true
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,13 +58,13 @@ export class PostRouter {
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
return await this.postService.update(input, staff);
|
return await this.postService.update(input, staff);
|
||||||
}),
|
}),
|
||||||
findById: this.trpc.protectProcedure
|
findById: this.trpc.procedure
|
||||||
.input(z.object({ id: z.string(), args: PostFindFirstArgsSchema }))
|
.input(z.object({ id: z.string(), args: PostFindFirstArgsSchema }))
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
return await this.postService.findById(input.id, input.args);
|
return await this.postService.findById(input.id, input.args);
|
||||||
}),
|
}),
|
||||||
findMany: this.trpc.protectProcedure
|
findMany: this.trpc.procedure
|
||||||
.input(PostFindManyArgsSchema)
|
.input(PostFindManyArgsSchema)
|
||||||
.query(async ({ ctx, input }) => {
|
.query(async ({ ctx, input }) => {
|
||||||
const { staff } = ctx;
|
const { staff } = ctx;
|
||||||
|
@ -84,7 +84,7 @@ export class PostRouter {
|
||||||
.mutation(async ({ input }) => {
|
.mutation(async ({ input }) => {
|
||||||
return await this.postService.deleteMany(input);
|
return await this.postService.deleteMany(input);
|
||||||
}),
|
}),
|
||||||
findManyWithCursor: this.trpc.protectProcedure
|
findManyWithCursor: this.trpc.procedure
|
||||||
.input(
|
.input(
|
||||||
z.object({
|
z.object({
|
||||||
cursor: z.any().nullish(),
|
cursor: z.any().nullish(),
|
||||||
|
|
|
@ -101,6 +101,11 @@ export class PostService extends BaseTreeService<Prisma.PostDelegate> {
|
||||||
},
|
},
|
||||||
params: { staff?: UserProfile; tx?: Prisma.TransactionClient },
|
params: { staff?: UserProfile; tx?: Prisma.TransactionClient },
|
||||||
) {
|
) {
|
||||||
|
// const await db.post.findMany({
|
||||||
|
// where: {
|
||||||
|
// type: PostType.COURSE,
|
||||||
|
// },
|
||||||
|
// });
|
||||||
const { courseDetail } = args;
|
const { courseDetail } = args;
|
||||||
// If no transaction is provided, create a new one
|
// If no transaction is provided, create a new one
|
||||||
if (!params.tx) {
|
if (!params.tx) {
|
||||||
|
|
|
@ -45,7 +45,7 @@ export class GenDevService {
|
||||||
await this.generateDepartments(3, 6);
|
await this.generateDepartments(3, 6);
|
||||||
await this.generateTerms(2, 6);
|
await this.generateTerms(2, 6);
|
||||||
await this.generateStaffs(4);
|
await this.generateStaffs(4);
|
||||||
await this.generateCourses();
|
await this.generateCourses(8);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
this.logger.error(err);
|
this.logger.error(err);
|
||||||
}
|
}
|
||||||
|
@ -253,9 +253,11 @@ export class GenDevService {
|
||||||
{ name: '中级', taxonomyId: taxLevel.id },
|
{ name: '中级', taxonomyId: taxLevel.id },
|
||||||
{ name: '高级', taxonomyId: taxLevel.id }, // 改为高级更合理
|
{ name: '高级', taxonomyId: taxLevel.id }, // 改为高级更合理
|
||||||
];
|
];
|
||||||
await this.termService.createMany({
|
for (const termData of termsToCreate) {
|
||||||
data: termsToCreate,
|
await this.termService.create({
|
||||||
});
|
data: termData,
|
||||||
|
});
|
||||||
|
}
|
||||||
console.log('created level terms');
|
console.log('created level terms');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to create level terms:', error);
|
console.error('Failed to create level terms:', error);
|
||||||
|
|
|
@ -1,33 +1,26 @@
|
||||||
import {
|
import { AppConfigSlug, BaseSetting, RolePerms } from "@nice/common";
|
||||||
AppConfigSlug,
|
|
||||||
BaseSetting,
|
|
||||||
RolePerms,
|
|
||||||
} from "@nice/common";
|
|
||||||
import { useContext, useEffect, useState } from "react";
|
import { useContext, useEffect, useState } from "react";
|
||||||
import {
|
import { Button, Form, Input, message, theme } from "antd";
|
||||||
Button,
|
|
||||||
Form,
|
|
||||||
Input,
|
|
||||||
message,
|
|
||||||
theme,
|
|
||||||
} from "antd";
|
|
||||||
import { useAppConfig } from "@nice/client";
|
import { useAppConfig } from "@nice/client";
|
||||||
import { useAuth } from "@web/src/providers/auth-provider";
|
import { useAuth } from "@web/src/providers/auth-provider";
|
||||||
|
|
||||||
import FixedHeader from "@web/src/components/layout/fix-header";
|
import FixedHeader from "@web/src/components/layout/fix-header";
|
||||||
import { useForm } from "antd/es/form/Form";
|
import { useForm } from "antd/es/form/Form";
|
||||||
import { api } from "@nice/client"
|
import { api } from "@nice/client";
|
||||||
import { MainLayoutContext } from "../layout";
|
import { MainLayoutContext } from "../layout";
|
||||||
|
|
||||||
export default function BaseSettingPage() {
|
export default function BaseSettingPage() {
|
||||||
const { update, baseSetting } = useAppConfig();
|
const { update, baseSetting } = useAppConfig();
|
||||||
const utils = api.useUtils()
|
const utils = api.useUtils();
|
||||||
const [form] = useForm()
|
const [form] = useForm();
|
||||||
const { token } = theme.useToken();
|
const { token } = theme.useToken();
|
||||||
const { data: clientCount } = api.app_config.getClientCount.useQuery(undefined, {
|
const { data: clientCount } = api.app_config.getClientCount.useQuery(
|
||||||
refetchInterval: 3000,
|
undefined,
|
||||||
refetchIntervalInBackground: true
|
{
|
||||||
})
|
refetchInterval: 3000,
|
||||||
|
refetchIntervalInBackground: true,
|
||||||
|
}
|
||||||
|
);
|
||||||
const [isFormChanged, setIsFormChanged] = useState(false);
|
const [isFormChanged, setIsFormChanged] = useState(false);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const { user, hasSomePermissions } = useAuth();
|
const { user, hasSomePermissions } = useAuth();
|
||||||
|
@ -36,31 +29,27 @@ export default function BaseSettingPage() {
|
||||||
setIsFormChanged(true);
|
setIsFormChanged(true);
|
||||||
}
|
}
|
||||||
function onResetClick() {
|
function onResetClick() {
|
||||||
if (!form)
|
if (!form) return;
|
||||||
return
|
|
||||||
if (!baseSetting) {
|
if (!baseSetting) {
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
} else {
|
} else {
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
form.setFieldsValue(baseSetting);
|
form.setFieldsValue(baseSetting);
|
||||||
|
|
||||||
}
|
}
|
||||||
setIsFormChanged(false);
|
setIsFormChanged(false);
|
||||||
}
|
}
|
||||||
function onSaveClick() {
|
function onSaveClick() {
|
||||||
if (form)
|
if (form) form.submit();
|
||||||
form.submit();
|
|
||||||
}
|
}
|
||||||
async function onSubmit(values: BaseSetting) {
|
async function onSubmit(values: BaseSetting) {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
await update.mutateAsync({
|
await update.mutateAsync({
|
||||||
where: {
|
where: {
|
||||||
slug: AppConfigSlug.BASE_SETTING,
|
slug: AppConfigSlug.BASE_SETTING,
|
||||||
},
|
},
|
||||||
data: { meta: JSON.stringify(values) }
|
data: { meta: { ...baseSetting, ...values } },
|
||||||
});
|
});
|
||||||
setIsFormChanged(false);
|
setIsFormChanged(false);
|
||||||
message.success("已保存");
|
message.success("已保存");
|
||||||
|
@ -72,7 +61,6 @@ export default function BaseSettingPage() {
|
||||||
}
|
}
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (baseSetting && form) {
|
if (baseSetting && form) {
|
||||||
|
|
||||||
form.setFieldsValue(baseSetting);
|
form.setFieldsValue(baseSetting);
|
||||||
}
|
}
|
||||||
}, [baseSetting, form]);
|
}, [baseSetting, form]);
|
||||||
|
@ -103,7 +91,6 @@ export default function BaseSettingPage() {
|
||||||
!hasSomePermissions(RolePerms.MANAGE_BASE_SETTING)
|
!hasSomePermissions(RolePerms.MANAGE_BASE_SETTING)
|
||||||
}
|
}
|
||||||
onFinish={onSubmit}
|
onFinish={onSubmit}
|
||||||
|
|
||||||
onFieldsChange={handleFieldsChange}
|
onFieldsChange={handleFieldsChange}
|
||||||
layout="vertical">
|
layout="vertical">
|
||||||
{/* <div
|
{/* <div
|
||||||
|
@ -173,17 +160,21 @@ export default function BaseSettingPage() {
|
||||||
清除行模型缓存
|
清除行模型缓存
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
{<div
|
{
|
||||||
className="p-2 border-b text-primary flex justify-between items-center"
|
<div
|
||||||
style={{
|
className="p-2 border-b text-primary flex justify-between items-center"
|
||||||
fontSize: token.fontSize,
|
style={{
|
||||||
fontWeight: "bold",
|
fontSize: token.fontSize,
|
||||||
}}>
|
fontWeight: "bold",
|
||||||
<span>app在线人数</span>
|
}}>
|
||||||
<div>
|
<span>app在线人数</span>
|
||||||
{clientCount && clientCount > 0 ? `${clientCount}人在线` : '无人在线'}
|
<div>
|
||||||
|
{clientCount && clientCount > 0
|
||||||
|
? `${clientCount}人在线`
|
||||||
|
: "无人在线"}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>}
|
}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,9 +1,10 @@
|
||||||
import { Card, Rate, Tag } from 'antd';
|
import { Card, Rate, Tag } from 'antd';
|
||||||
import { Course } from '../mockData';
|
import { Course } from '../mockData';
|
||||||
import { UserOutlined, ClockCircleOutlined } from '@ant-design/icons';
|
import { UserOutlined, ClockCircleOutlined } from '@ant-design/icons';
|
||||||
|
import { CourseDto } from '@nice/common';
|
||||||
|
|
||||||
interface CourseCardProps {
|
interface CourseCardProps {
|
||||||
course: Course;
|
course: CourseDto;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function CourseCard({ course }: CourseCardProps) {
|
export default function CourseCard({ course }: CourseCardProps) {
|
||||||
|
@ -14,7 +15,7 @@ export default function CourseCard({ course }: CourseCardProps) {
|
||||||
cover={
|
cover={
|
||||||
<img
|
<img
|
||||||
alt={course.title}
|
alt={course.title}
|
||||||
src={course.thumbnail}
|
src={course?.meta?.thumbnail}
|
||||||
className="object-cover w-full h-40"
|
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">
|
<h3 className="text-lg font-semibold line-clamp-2 hover:text-blue-600 transition-colors">
|
||||||
{course.title}
|
{course.title}
|
||||||
</h3>
|
</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">
|
<div className="flex items-center space-x-2">
|
||||||
<Rate disabled defaultValue={course.rating} className="text-sm" />
|
<Rate disabled defaultValue={course.rating} className="text-sm" />
|
||||||
<span className="text-gray-500 text-sm">{course.rating}</span>
|
<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 justify-between text-sm text-gray-500">
|
||||||
<div className="flex items-center space-x-1">
|
<div className="flex items-center space-x-1">
|
||||||
<UserOutlined className="text-gray-400" />
|
<UserOutlined className="text-gray-400" />
|
||||||
<span>{course.enrollments} 人在学</span>
|
<span>{course.enrollments?.length} 人在学</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex items-center space-x-1">
|
<div className="flex items-center space-x-1">
|
||||||
<ClockCircleOutlined className="text-gray-400" />
|
<ClockCircleOutlined className="text-gray-400" />
|
||||||
|
@ -39,8 +40,8 @@ export default function CourseCard({ course }: CourseCardProps) {
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex flex-wrap gap-2 pt-2">
|
<div className="flex flex-wrap gap-2 pt-2">
|
||||||
<Tag color="blue" className="rounded-full px-3">{course.category}</Tag>
|
<Tag color="blue" className="rounded-full px-3">{course.terms[0].name}</Tag>
|
||||||
<Tag color="green" className="rounded-full px-3">{course.level}</Tag>
|
<Tag color="green" className="rounded-full px-3">{course.terms[1].name}</Tag>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
import { Pagination, Empty } from 'antd';
|
import { Pagination, Empty } from 'antd';
|
||||||
import { Course } from '../mockData';
|
import { Course } from '../mockData';
|
||||||
import CourseCard from './CourseCard';
|
import CourseCard from './CourseCard';
|
||||||
|
import {CourseDto} from '@nice/common'
|
||||||
interface CourseListProps {
|
interface CourseListProps {
|
||||||
courses: Course[];
|
courses: CourseDto[];
|
||||||
total: number;
|
total: number;
|
||||||
pageSize: number;
|
pageSize: number;
|
||||||
currentPage: number;
|
currentPage: number;
|
||||||
|
|
|
@ -75,7 +75,7 @@ export default function FilterSection({
|
||||||
:
|
:
|
||||||
(
|
(
|
||||||
<>
|
<>
|
||||||
<Radio value="">全部课程</Radio>
|
<Radio value="" >全部课程</Radio>
|
||||||
{gateGory.categories.map(category => (
|
{gateGory.categories.map(category => (
|
||||||
<Radio key={category} value={category}>
|
<Radio key={category} value={category}>
|
||||||
{category}
|
{category}
|
||||||
|
|
|
@ -1,59 +1,82 @@
|
||||||
import { useState, useMemo } from "react";
|
import { useState, useMemo, useEffect } from "react";
|
||||||
import { mockCourses } from "./mockData";
|
import { mockCourses } from "./mockData";
|
||||||
import FilterSection from "./components/FilterSection";
|
import FilterSection from "./components/FilterSection";
|
||||||
import CourseList from "./components/CourseList";
|
import CourseList from "./components/CourseList";
|
||||||
import { api } from "@nice/client";
|
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() {
|
export default function CoursesPage() {
|
||||||
const [currentPage, setCurrentPage] = useState(1);
|
const [currentPage, setCurrentPage] = useState(1);
|
||||||
const [selectedCategory, setSelectedCategory] = useState("");
|
const [selectedCategory, setSelectedCategory] = useState("");
|
||||||
const [selectedLevel, setSelectedLevel] = useState("");
|
const [selectedLevel, setSelectedLevel] = useState("");
|
||||||
const pageSize = 12;
|
const pageSize = 9;
|
||||||
const { data, isLoading } = api.post.findManyWithPagination.useQuery({
|
const [isAll,setIsAll] = useState(true)
|
||||||
where: {
|
const [searchParams, setSearchParams] = useSearchParams();
|
||||||
type: PostType.COURSE,
|
let coursesData = []
|
||||||
terms: {
|
let isCourseLoading = false
|
||||||
some: {
|
if(!searchParams.get('searchValue')){
|
||||||
AND: [
|
console.log('no category')
|
||||||
...(selectedCategory
|
const {data,isLoading} = api.post.findManyWithPagination.useQuery({
|
||||||
? [
|
where: {
|
||||||
{
|
type: PostType.COURSE,
|
||||||
name: selectedCategory,
|
terms:isAll?{}:{
|
||||||
},
|
some: {
|
||||||
]
|
OR : [
|
||||||
: []),
|
selectedCategory?{name:selectedCategory}:{},
|
||||||
...(selectedLevel
|
selectedLevel?{name:selectedLevel}:{}
|
||||||
? [
|
],
|
||||||
{
|
},
|
||||||
name: selectedLevel,
|
|
||||||
},
|
|
||||||
]
|
|
||||||
: []),
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
|
|
||||||
},
|
},
|
||||||
},
|
select:courseDetailSelect
|
||||||
});
|
|
||||||
const filteredCourses = useMemo(() => {
|
|
||||||
return mockCourses.filter((course) => {
|
|
||||||
const matchCategory =
|
|
||||||
!selectedCategory || course.category === selectedCategory;
|
|
||||||
const matchLevel = !selectedLevel || course.level === selectedLevel;
|
|
||||||
return matchCategory && matchLevel;
|
|
||||||
});
|
});
|
||||||
}, [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;
|
const startIndex = (currentPage - 1) * pageSize;
|
||||||
return filteredCourses.slice(startIndex, startIndex + pageSize);
|
return isCourseLoading ? [] : (filteredCourses.slice(startIndex, startIndex + pageSize) as any as CourseDto[]);
|
||||||
}, [filteredCourses, currentPage]);
|
}, [filteredCourses, currentPage]);
|
||||||
|
|
||||||
const handlePageChange = (page: number) => {
|
const handlePageChange = (page: number) => {
|
||||||
setCurrentPage(page);
|
setCurrentPage(page);
|
||||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||||
};
|
};
|
||||||
|
useEffect(()=>{
|
||||||
|
setCurrentPage(1)
|
||||||
|
},[])
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen bg-gray-50">
|
<div className="min-h-screen bg-gray-50">
|
||||||
|
@ -69,10 +92,14 @@ export default function CoursesPage() {
|
||||||
console.log(category);
|
console.log(category);
|
||||||
setSelectedCategory(category);
|
setSelectedCategory(category);
|
||||||
setCurrentPage(1);
|
setCurrentPage(1);
|
||||||
|
setIsAll(!category)
|
||||||
|
setSearchParams({ searchValue: ''});
|
||||||
}}
|
}}
|
||||||
onLevelChange={(level) => {
|
onLevelChange={(level) => {
|
||||||
setSelectedLevel(level);
|
setSelectedLevel(level);
|
||||||
setCurrentPage(1);
|
setCurrentPage(1);
|
||||||
|
setIsAll(!level)
|
||||||
|
setSearchParams({ searchValue: ''});
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -63,7 +63,7 @@ const CategorySection = () => {
|
||||||
orderBy: {
|
orderBy: {
|
||||||
createdAt: 'desc', // 按创建时间降序排列
|
createdAt: 'desc', // 按创建时间降序排列
|
||||||
},
|
},
|
||||||
take:10
|
take:8
|
||||||
})
|
})
|
||||||
// 分类展示
|
// 分类展示
|
||||||
const [displayedCategories,setDisplayedCategories] = useState<TermDto[]>([])
|
const [displayedCategories,setDisplayedCategories] = useState<TermDto[]>([])
|
||||||
|
@ -194,7 +194,11 @@ const CategorySection = () => {
|
||||||
type="default"
|
type="default"
|
||||||
size="large"
|
size="large"
|
||||||
className="px-8 h-12 text-base font-medium hover:shadow-md transition-all duration-300"
|
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 ? '收起' : '查看更多分类'}
|
{showAll ? '收起' : '查看更多分类'}
|
||||||
</Button>
|
</Button>
|
||||||
|
|
|
@ -1,160 +1,135 @@
|
||||||
import React, { useRef, useCallback } from 'react';
|
import React, { useRef, useCallback } from "react";
|
||||||
import { Button, Carousel, Typography } from 'antd';
|
import { Button, Carousel, Typography } from "antd";
|
||||||
import {
|
import {
|
||||||
TeamOutlined,
|
TeamOutlined,
|
||||||
BookOutlined,
|
BookOutlined,
|
||||||
StarOutlined,
|
StarOutlined,
|
||||||
ClockCircleOutlined,
|
ClockCircleOutlined,
|
||||||
LeftOutlined,
|
LeftOutlined,
|
||||||
RightOutlined,
|
RightOutlined,
|
||||||
EyeOutlined
|
EyeOutlined,
|
||||||
} from '@ant-design/icons';
|
} from "@ant-design/icons";
|
||||||
import type { CarouselRef } from 'antd/es/carousel';
|
import type { CarouselRef } from "antd/es/carousel";
|
||||||
|
|
||||||
const { Title, Text } = Typography;
|
const { Title, Text } = Typography;
|
||||||
|
|
||||||
interface CarouselItem {
|
interface CarouselItem {
|
||||||
title: string;
|
title: string;
|
||||||
desc: string;
|
desc: string;
|
||||||
image: string;
|
image: string;
|
||||||
action: string;
|
action: string;
|
||||||
color: string;
|
color: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface PlatformStat {
|
interface PlatformStat {
|
||||||
icon: React.ReactNode;
|
icon: React.ReactNode;
|
||||||
value: string;
|
value: string;
|
||||||
label: string;
|
label: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const carouselItems: CarouselItem[] = [
|
const carouselItems: CarouselItem[] = [
|
||||||
{
|
{
|
||||||
title: '探索编程世界',
|
title: "探索编程世界",
|
||||||
desc: '从零开始学习编程,开启你的技术之旅',
|
desc: "从零开始学习编程,开启你的技术之旅",
|
||||||
image: '/images/banner1.jpg',
|
image: "/images/banner1.jpg",
|
||||||
action: '立即开始',
|
action: "立即开始",
|
||||||
color: 'from-blue-600/90'
|
color: "from-blue-600/90",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: '人工智能课程',
|
title: "人工智能课程",
|
||||||
desc: '掌握AI技术,引领未来发展',
|
desc: "掌握AI技术,引领未来发展",
|
||||||
image: '/images/banner2.jpg',
|
image: "/images/banner2.jpg",
|
||||||
action: '了解更多',
|
action: "了解更多",
|
||||||
color: 'from-purple-600/90'
|
color: "from-purple-600/90",
|
||||||
}
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
const platformStats: PlatformStat[] = [
|
const platformStats: PlatformStat[] = [
|
||||||
{ icon: <TeamOutlined />, value: '50,000+', label: '注册学员' },
|
{ icon: <TeamOutlined />, value: "50,000+", label: "注册学员" },
|
||||||
{ icon: <BookOutlined />, value: '1,000+', label: '精品课程' },
|
{ icon: <BookOutlined />, value: "1,000+", label: "精品课程" },
|
||||||
// { icon: <StarOutlined />, value: '98%', label: '好评度' },
|
// { icon: <StarOutlined />, value: '98%', label: '好评度' },
|
||||||
{ icon: <EyeOutlined />, value: '100万+', label: '观看次数' }
|
{ icon: <EyeOutlined />, value: "100万+", label: "观看次数" },
|
||||||
];
|
];
|
||||||
|
|
||||||
const HeroSection = () => {
|
const HeroSection = () => {
|
||||||
const carouselRef = useRef<CarouselRef>(null);
|
const carouselRef = useRef<CarouselRef>(null);
|
||||||
|
|
||||||
const handlePrev = useCallback(() => {
|
const handlePrev = useCallback(() => {
|
||||||
carouselRef.current?.prev();
|
carouselRef.current?.prev();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
const handleNext = useCallback(() => {
|
const handleNext = useCallback(() => {
|
||||||
carouselRef.current?.next();
|
carouselRef.current?.next();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="relative ">
|
<section className="relative ">
|
||||||
<div className="group">
|
<div className="group">
|
||||||
<Carousel
|
<Carousel
|
||||||
ref={carouselRef}
|
ref={carouselRef}
|
||||||
autoplay
|
autoplay
|
||||||
effect="fade"
|
effect="fade"
|
||||||
className="h-[600px] mb-24"
|
className="h-[600px] mb-24"
|
||||||
dots={{
|
dots={{
|
||||||
className: 'carousel-dots !bottom-32 !z-20',
|
className: "carousel-dots !bottom-32 !z-20",
|
||||||
}}
|
}}>
|
||||||
>
|
{carouselItems.map((item, index) => (
|
||||||
{carouselItems.map((item, index) => (
|
<div key={index} className="relative h-[600px]">
|
||||||
<div key={index} className="relative h-[600px]">
|
<div
|
||||||
<div
|
className="absolute inset-0 bg-cover bg-center transform transition-[transform,filter] duration-[2000ms] group-hover:scale-105 group-hover:brightness-110 will-change-[transform,filter]"
|
||||||
className="absolute inset-0 bg-cover bg-center transform transition-[transform,filter] duration-[2000ms] group-hover:scale-105 group-hover:brightness-110 will-change-[transform,filter]"
|
style={{
|
||||||
style={{
|
backgroundImage: `url(${item.image})`,
|
||||||
backgroundImage: `url(${item.image})`,
|
backfaceVisibility: "hidden",
|
||||||
backfaceVisibility: 'hidden'
|
}}
|
||||||
}}
|
/>
|
||||||
/>
|
<div
|
||||||
<div
|
className={`absolute inset-0 bg-gradient-to-r ${item.color} to-transparent opacity-90 mix-blend-overlay transition-opacity duration-500`}
|
||||||
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" />
|
||||||
<div className="absolute inset-0 bg-gradient-to-t from-black/50 to-transparent" />
|
|
||||||
|
|
||||||
{/* Content Container */}
|
{/* Content Container */}
|
||||||
<div className="relative h-full max-w-7xl mx-auto px-6 lg:px-8">
|
<div className="relative h-full max-w-7xl mx-auto px-6 lg:px-8"></div>
|
||||||
<div className="absolute left-0 top-1/2 -translate-y-1/2 max-w-2xl">
|
</div>
|
||||||
<Title
|
))}
|
||||||
className="text-white mb-8 text-5xl md:text-6xl xl:text-7xl !leading-tight font-bold tracking-tight"
|
</Carousel>
|
||||||
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>
|
|
||||||
|
|
||||||
{/* Navigation Buttons */}
|
{/* Navigation Buttons */}
|
||||||
<button
|
<button
|
||||||
onClick={handlePrev}
|
onClick={handlePrev}
|
||||||
className="absolute left-4 md:left-8 top-1/2 -translate-y-1/2 z-10 opacity-0 group-hover:opacity-100 transition-all duration-300 bg-black/20 hover:bg-black/30 w-12 h-12 flex items-center justify-center rounded-full transform hover:scale-110 hover:shadow-lg"
|
className="absolute left-4 md:left-8 top-1/2 -translate-y-1/2 z-10 opacity-0 group-hover:opacity-100 transition-all duration-300 bg-black/20 hover:bg-black/30 w-12 h-12 flex items-center justify-center rounded-full transform hover:scale-110 hover:shadow-lg"
|
||||||
aria-label="Previous slide"
|
aria-label="Previous slide">
|
||||||
>
|
<LeftOutlined className="text-white text-xl" />
|
||||||
<LeftOutlined className="text-white text-xl" />
|
</button>
|
||||||
</button>
|
<button
|
||||||
<button
|
onClick={handleNext}
|
||||||
onClick={handleNext}
|
className="absolute right-4 md:right-8 top-1/2 -translate-y-1/2 z-10 opacity-0 group-hover:opacity-100 transition-all duration-300 bg-black/20 hover:bg-black/30 w-12 h-12 flex items-center justify-center rounded-full transform hover:scale-110 hover:shadow-lg"
|
||||||
className="absolute right-4 md:right-8 top-1/2 -translate-y-1/2 z-10 opacity-0 group-hover:opacity-100 transition-all duration-300 bg-black/20 hover:bg-black/30 w-12 h-12 flex items-center justify-center rounded-full transform hover:scale-110 hover:shadow-lg"
|
aria-label="Next slide">
|
||||||
aria-label="Next slide"
|
<RightOutlined className="text-white text-xl" />
|
||||||
>
|
</button>
|
||||||
<RightOutlined className="text-white text-xl" />
|
</div>
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Stats Container */}
|
{/* Stats Container */}
|
||||||
<div className="absolute -bottom-24 left-1/2 -translate-x-1/2 w-1/2 max-w-6xl px-4">
|
<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]">
|
<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) => (
|
{platformStats.map((stat, index) => (
|
||||||
<div
|
<div
|
||||||
key={index}
|
key={index}
|
||||||
className="text-center transform hover:-translate-y-1 hover:scale-105 transition-transform duration-300 ease-out"
|
className="text-center transform hover:-translate-y-1 hover:scale-105 transition-transform duration-300 ease-out">
|
||||||
>
|
<div className="inline-flex items-center justify-center w-16 h-16 mb-4 rounded-full bg-primary-50 text-primary-600 text-3xl transition-colors duration-300 group-hover:text-primary-700">
|
||||||
<div className="inline-flex items-center justify-center w-16 h-16 mb-4 rounded-full bg-primary-50 text-primary-600 text-3xl transition-colors duration-300 group-hover:text-primary-700">
|
{stat.icon}
|
||||||
{stat.icon}
|
</div>
|
||||||
</div>
|
<div className="text-2xl font-bold bg-gradient-to-r from-gray-800 to-gray-600 bg-clip-text text-transparent mb-1.5">
|
||||||
<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}
|
||||||
{stat.value}
|
</div>
|
||||||
</div>
|
<div className="text-gray-600 font-medium">
|
||||||
<div className="text-gray-600 font-medium">
|
{stat.label}
|
||||||
{stat.label}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
))}
|
||||||
))}
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</section>
|
||||||
</section>
|
);
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export default HeroSection;
|
export default HeroSection;
|
||||||
|
|
|
@ -35,6 +35,12 @@ export function MainHeader() {
|
||||||
className="w-72 rounded-full"
|
className="w-72 rounded-full"
|
||||||
value={searchValue}
|
value={searchValue}
|
||||||
onChange={(e) => setSearchValue(e.target.value)}
|
onChange={(e) => setSearchValue(e.target.value)}
|
||||||
|
onPressEnter={(e)=>{
|
||||||
|
//console.log(e)
|
||||||
|
setSearchValue('')
|
||||||
|
navigate(`/courses/?searchValue=${searchValue}`)
|
||||||
|
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{isAuthenticated && (
|
{isAuthenticated && (
|
||||||
|
|
|
@ -36,7 +36,7 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
||||||
const [file, setFile] = useState<UploadingFile | null>(null);
|
const [file, setFile] = useState<UploadingFile | null>(null);
|
||||||
const avatarRef = useRef<HTMLImageElement>(null);
|
const avatarRef = useRef<HTMLImageElement>(null);
|
||||||
const [previewUrl, setPreviewUrl] = useState<string>(value || "");
|
const [previewUrl, setPreviewUrl] = useState<string>(value || "");
|
||||||
|
const [imageSrc, setImageSrc] = useState(value);
|
||||||
const [compressedUrl, setCompressedUrl] = useState<string>(value || "");
|
const [compressedUrl, setCompressedUrl] = useState<string>(value || "");
|
||||||
const [url, setUrl] = useState<string>(value || "");
|
const [url, setUrl] = useState<string>(value || "");
|
||||||
const [uploading, setUploading] = useState(false);
|
const [uploading, setUploading] = useState(false);
|
||||||
|
@ -45,7 +45,9 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
||||||
const [avatarKey, setAvatarKey] = useState(0);
|
const [avatarKey, setAvatarKey] = useState(0);
|
||||||
const { token } = theme.useToken();
|
const { token } = theme.useToken();
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setPreviewUrl(value || "");
|
if (!previewUrl || previewUrl?.length < 1) {
|
||||||
|
setPreviewUrl(value || "");
|
||||||
|
}
|
||||||
}, [value]);
|
}, [value]);
|
||||||
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
const selectedFile = event.target.files?.[0];
|
const selectedFile = event.target.files?.[0];
|
||||||
|
@ -128,6 +130,14 @@ const AvatarUploader: React.FC<AvatarUploaderProps> = ({
|
||||||
ref={avatarRef}
|
ref={avatarRef}
|
||||||
src={previewUrl}
|
src={previewUrl}
|
||||||
shape="square"
|
shape="square"
|
||||||
|
onError={() => {
|
||||||
|
if (value && previewUrl && imageSrc === value) {
|
||||||
|
// 当原始图片(value)加载失败时,切换到 previewUrl
|
||||||
|
setImageSrc(previewUrl);
|
||||||
|
return true; // 阻止默认的 fallback 行为,让它尝试新设置的 src
|
||||||
|
}
|
||||||
|
return false; // 如果 previewUrl 也失败了,显示默认头像
|
||||||
|
}}
|
||||||
className="w-full h-full object-cover"
|
className="w-full h-full object-cover"
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
|
|
|
@ -109,11 +109,12 @@ export function CourseFormProvider({
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
if (editId) {
|
if (editId) {
|
||||||
await update.mutateAsync({
|
const result = await update.mutateAsync({
|
||||||
where: { id: editId },
|
where: { id: editId },
|
||||||
data: formattedValues,
|
data: formattedValues,
|
||||||
});
|
});
|
||||||
message.success("课程更新成功!");
|
message.success("课程更新成功!");
|
||||||
|
navigate(`/course/${result.id}/editor/content`);
|
||||||
} else {
|
} else {
|
||||||
const result = await createCourse.mutateAsync({
|
const result = await createCourse.mutateAsync({
|
||||||
courseDetail: {
|
courseDetail: {
|
||||||
|
@ -127,8 +128,8 @@ export function CourseFormProvider({
|
||||||
},
|
},
|
||||||
sections,
|
sections,
|
||||||
});
|
});
|
||||||
navigate(`/course/${result.id}/editor`, { replace: true });
|
|
||||||
message.success("课程创建成功!");
|
message.success("课程创建成功!");
|
||||||
|
navigate(`/course/${result.id}/editor/content`);
|
||||||
}
|
}
|
||||||
form.resetFields();
|
form.resetFields();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|
|
@ -34,7 +34,7 @@ const CourseContentForm: React.FC = () => {
|
||||||
coordinateGetter: sortableKeyboardCoordinates,
|
coordinateGetter: sortableKeyboardCoordinates,
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
const { softDeleteByIds } = usePost();
|
const { softDeleteByIds, updateOrderByIds } = usePost();
|
||||||
const { data: sections = [], isLoading } = api.post.findMany.useQuery(
|
const { data: sections = [], isLoading } = api.post.findMany.useQuery(
|
||||||
{
|
{
|
||||||
where: {
|
where: {
|
||||||
|
@ -60,11 +60,15 @@ const CourseContentForm: React.FC = () => {
|
||||||
const handleDragEnd = (event: DragEndEvent) => {
|
const handleDragEnd = (event: DragEndEvent) => {
|
||||||
const { active, over } = event;
|
const { active, over } = event;
|
||||||
if (!over || active.id === over.id) return;
|
if (!over || active.id === over.id) return;
|
||||||
|
let newItems = [];
|
||||||
setItems((items) => {
|
setItems((items) => {
|
||||||
const oldIndex = items.findIndex((item) => item.id === active.id);
|
const oldIndex = items.findIndex((item) => item.id === active.id);
|
||||||
const newIndex = items.findIndex((item) => item.id === over.id);
|
const newIndex = items.findIndex((item) => item.id === over.id);
|
||||||
return arrayMove(items, oldIndex, newIndex);
|
newItems = arrayMove(items, oldIndex, newIndex);
|
||||||
|
return newItems;
|
||||||
|
});
|
||||||
|
updateOrderByIds.mutateAsync({
|
||||||
|
ids: newItems.map((item) => item.id),
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -112,7 +116,7 @@ const CourseContentForm: React.FC = () => {
|
||||||
className="mt-4"
|
className="mt-4"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (items.some((item) => item.id === null)) {
|
if (items.some((item) => item.id === null)) {
|
||||||
toast.error("请先保存当前编辑章节");
|
toast.error("请先保存当前编辑的章节");
|
||||||
} else {
|
} else {
|
||||||
setItems([...items, { id: null, title: "" }]);
|
setItems([...items, { id: null, title: "" }]);
|
||||||
}
|
}
|
||||||
|
|
|
@ -137,7 +137,7 @@ export const LectureList: React.FC<LectureListProps> = ({
|
||||||
className="mt-4"
|
className="mt-4"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (items.some((item) => item.id === null)) {
|
if (items.some((item) => item.id === null)) {
|
||||||
toast.error("请先保存当前编辑章节");
|
toast.error("请先保存当前编辑中的课时!");
|
||||||
} else {
|
} else {
|
||||||
setItems((prevItems) => [
|
setItems((prevItems) => [
|
||||||
...prevItems.filter((item) => !!item.id),
|
...prevItems.filter((item) => !!item.id),
|
||||||
|
|
|
@ -56,7 +56,7 @@ export const InitTaxonomies: {
|
||||||
objectType?: string[];
|
objectType?: string[];
|
||||||
}[] = [
|
}[] = [
|
||||||
{
|
{
|
||||||
name: "分类",
|
name: "课程分类",
|
||||||
slug: TaxonomySlug.CATEGORY,
|
slug: TaxonomySlug.CATEGORY,
|
||||||
objectType: [ObjectType.COURSE],
|
objectType: [ObjectType.COURSE],
|
||||||
},
|
},
|
||||||
|
|
|
@ -100,6 +100,7 @@ export enum RolePerms {
|
||||||
}
|
}
|
||||||
export enum AppConfigSlug {
|
export enum AppConfigSlug {
|
||||||
BASE_SETTING = "base_setting",
|
BASE_SETTING = "base_setting",
|
||||||
|
|
||||||
}
|
}
|
||||||
// 资源类型的枚举,定义了不同类型的资源,以字符串值表示
|
// 资源类型的枚举,定义了不同类型的资源,以字符串值表示
|
||||||
export enum ResourceType {
|
export enum ResourceType {
|
||||||
|
|
|
@ -70,28 +70,27 @@ export const courseDetailSelect: Prisma.PostSelect = {
|
||||||
title: true,
|
title: true,
|
||||||
subTitle: true,
|
subTitle: true,
|
||||||
content: 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,
|
// isFeatured: true,
|
||||||
createdAt: true,
|
createdAt: true,
|
||||||
publishedAt: true,
|
updatedAt: true,
|
||||||
// 关联表选择
|
// 关联表选择
|
||||||
children: {
|
terms:{
|
||||||
include: {
|
select:{
|
||||||
children: true,
|
id:true,
|
||||||
|
name:true,
|
||||||
|
taxonomy:{
|
||||||
|
select:{
|
||||||
|
id:true,
|
||||||
|
slug:true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
enrollments: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
enrollments: true,
|
|
||||||
meta: true,
|
meta: true,
|
||||||
|
rating: true,
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue