This commit is contained in:
ditiqi 2025-02-28 15:17:56 +08:00
parent 779e6ede72
commit 9e348fcfc3
3 changed files with 53 additions and 45 deletions

View File

@ -66,8 +66,6 @@ export async function updatePostViewCount(id: string, type: VisitType) {
where: { id }, where: { id },
select: { id: true, meta: true, type: true }, select: { id: true, meta: true, type: true },
}); });
console.log(post?.type);
console.log('updatePostViewCount');
const metaFieldMap = { const metaFieldMap = {
[VisitType.READED]: 'views', [VisitType.READED]: 'views',
[VisitType.LIKE]: 'likes', [VisitType.LIKE]: 'likes',
@ -105,7 +103,6 @@ export async function updatePostViewCount(id: string, type: VisitType) {
type: type, type: type,
}, },
}); });
console.log(courseViews);
await db.post.update({ await db.post.update({
where: { id: course.id }, where: { id: course.id },
data: { data: {
@ -126,7 +123,6 @@ export async function updatePostViewCount(id: string, type: VisitType) {
type: type, type: type,
}, },
}); });
console.log('totalViews', totalViews);
await db.post.update({ await db.post.update({
where: { id }, where: { id },
data: { data: {

View File

@ -25,14 +25,17 @@ export default function MindEditor({ id }: { id?: string }) {
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
const [instance, setInstance] = useState<MindElixirInstance | null>(null); const [instance, setInstance] = useState<MindElixirInstance | null>(null);
const { isAuthenticated, user, hasSomePermissions } = useAuth(); const { isAuthenticated, user, hasSomePermissions } = useAuth();
const { read } = useVisitor() const { read } = useVisitor();
const { data: post, isLoading }: { data: PathDto; isLoading: boolean } = const { data: post, isLoading }: { data: PathDto; isLoading: boolean } =
api.post.findFirst.useQuery({ api.post.findFirst.useQuery(
{
where: { where: {
id, id,
}, },
select: postDetailSelect, select: postDetailSelect,
}, { enabled: Boolean(id) }); },
{ enabled: Boolean(id) }
);
const canEdit: boolean = useMemo(() => { const canEdit: boolean = useMemo(() => {
const isAuth = isAuthenticated && user?.id === post?.author?.id; const isAuth = isAuthenticated && user?.id === post?.author?.id;
return !!id || isAuth || hasSomePermissions(RolePerms.MANAGE_ANY_POST); return !!id || isAuth || hasSomePermissions(RolePerms.MANAGE_ANY_POST);
@ -64,8 +67,8 @@ export default function MindEditor({ id }: { id?: string }) {
deptIds: deptIds, deptIds: deptIds,
}; };
post.terms?.forEach((term) => { post.terms?.forEach((term) => {
formData[term.taxonomyId] = term.id // 假设 taxonomyName是您在 Form.Item 中使用的name formData[term.taxonomyId] = term.id; // 假设 taxonomyName是您在 Form.Item 中使用的name
}) });
form.setFieldsValue(formData); form.setFieldsValue(formData);
} }
}, [post, form, instance, id]); }, [post, form, instance, id]);
@ -164,17 +167,13 @@ export default function MindEditor({ id }: { id?: string }) {
); );
}; };
useEffect(() => { useEffect(() => {
containerRef.current.style.height = `${Math.floor(window.innerHeight - 271)}px`; containerRef.current.style.height = `${Math.floor(window.innerHeight - 271)}px`;
}, []); }, []);
return ( return (
<div className={` flex-col flex `}> <div className={` flex-col flex `}>
{canEdit && taxonomies && ( {canEdit && taxonomies && (
<Form <Form form={form} className=" bg-white p-4 border-b">
form={form}
className=" bg-white p-4 border-b">
<div className="flex items-center justify-between gap-4"> <div className="flex items-center justify-between gap-4">
<div className="flex items-center gap-4"> <div className="flex items-center gap-4">
{taxonomies.map((tax, index) => ( {taxonomies.map((tax, index) => (
@ -203,14 +202,16 @@ export default function MindEditor({ id }: { id?: string }) {
/> />
</Form.Item> </Form.Item>
</div> </div>
{canEdit && <Button {canEdit && (
<Button
ghost ghost
type="primary" type="primary"
icon={<SaveOutlined></SaveOutlined>} icon={<SaveOutlined></SaveOutlined>}
onSubmit={(e) => e.preventDefault()} onSubmit={(e) => e.preventDefault()}
onClick={handleSave}> onClick={handleSave}>
{id ? "更新" : "保存"} {id ? "更新" : "保存"}
</Button>} </Button>
)}
</div> </div>
</Form> </Form>
)} )}
@ -220,24 +221,20 @@ export default function MindEditor({ id }: { id?: string }) {
onContextMenu={(e) => e.preventDefault()} onContextMenu={(e) => e.preventDefault()}
/> />
{canEdit && instance && <NodeMenu mind={instance} />} {canEdit && instance && <NodeMenu mind={instance} />}
{ {isLoading && (
isLoading && (
<div <div
className="py-64 justify-center flex" className="py-64 justify-center flex"
style={{ height: "calc(100vh - 271px)" }}> style={{ height: "calc(100vh - 271px)" }}>
<Spin size="large"></Spin> <Spin size="large"></Spin>
</div> </div>
) )}
} {!post && id && !isLoading && (
{
!post && id && !isLoading && (
<div <div
className="py-64" className="py-64"
style={{ height: "calc(100vh - 271px)" }}> style={{ height: "calc(100vh - 271px)" }}>
<Empty></Empty> <Empty></Empty>
</div> </div>
) )}
}
</div> </div>
); );
} }

View File

@ -0,0 +1,15 @@
import { api } from "@nice/client";
import { Select } from "antd";
import { useState } from "react";
export default function PostSelect() {
api.post.findMany.useQuery({});
const [search, setSearch] = useState("");
return (
<>
<Select
options={[{ value: "id1", label: <></> }]}
onSearch={(inputValue) => setSearch(inputValue)}></Select>
</>
);
}