add
This commit is contained in:
parent
879d010252
commit
7929654f34
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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>
|
||||
);
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -100,6 +100,7 @@ export enum RolePerms {
|
|||
}
|
||||
export enum AppConfigSlug {
|
||||
BASE_SETTING = "base_setting",
|
||||
|
||||
}
|
||||
// 资源类型的枚举,定义了不同类型的资源,以字符串值表示
|
||||
export enum ResourceType {
|
||||
|
|
Loading…
Reference in New Issue