add 0126-0947
This commit is contained in:
parent
cd25e48617
commit
ac18602e58
|
@ -1,4 +1,4 @@
|
|||
import { db, Prisma, PrismaClient } from "@nice/common";
|
||||
import { db, Prisma, PrismaClient } from '@nice/common';
|
||||
|
||||
export type Operations =
|
||||
| 'aggregate'
|
||||
|
@ -13,7 +13,9 @@ export type Operations =
|
|||
| 'update'
|
||||
| 'updateMany'
|
||||
| 'upsert';
|
||||
export type DelegateFuncs = { [K in Operations]: (args: any) => Promise<unknown> }
|
||||
export type DelegateFuncs = {
|
||||
[K in Operations]: (args: any) => Promise<unknown>;
|
||||
};
|
||||
export type DelegateArgs<T> = {
|
||||
[K in keyof T]: T[K] extends (args: infer A) => Promise<any> ? A : never;
|
||||
};
|
||||
|
@ -28,15 +30,15 @@ export type DataArgs<T> = T extends { data: infer D } ? D : never;
|
|||
export type IncludeArgs<T> = T extends { include: infer I } ? I : never;
|
||||
export type OrderByArgs<T> = T extends { orderBy: infer O } ? O : never;
|
||||
export type UpdateOrderArgs = {
|
||||
id: string
|
||||
overId: string
|
||||
}
|
||||
id: string;
|
||||
overId: string;
|
||||
};
|
||||
export interface FindManyWithCursorType<T extends DelegateFuncs> {
|
||||
cursor?: string;
|
||||
limit?: number;
|
||||
where?: WhereArgs<DelegateArgs<T>['findUnique']>;
|
||||
select?: SelectArgs<DelegateArgs<T>['findUnique']>;
|
||||
orderBy?: OrderByArgs<DelegateArgs<T>['findMany']>
|
||||
orderBy?: OrderByArgs<DelegateArgs<T>['findMany']>;
|
||||
}
|
||||
export type TransactionType = Omit<
|
||||
PrismaClient,
|
||||
|
|
|
@ -12,7 +12,7 @@ const PostDeleteManyArgsSchema: ZodType<Prisma.PostDeleteManyArgs> = z.any();
|
|||
const PostWhereInputSchema: ZodType<Prisma.PostWhereInput> = z.any();
|
||||
const PostSelectSchema: ZodType<Prisma.PostSelect> = z.any();
|
||||
const PostUpdateInputSchema: ZodType<Prisma.PostUpdateInput> = z.any();
|
||||
const PostOrderBySchema: ZodType<Prisma.PostOrderByWithRelationInput> = z.any()
|
||||
const PostOrderBySchema: ZodType<Prisma.PostOrderByWithRelationInput> = z.any();
|
||||
@Injectable()
|
||||
export class PostRouter {
|
||||
constructor(
|
||||
|
@ -104,7 +104,7 @@ export class PostRouter {
|
|||
pageSize: z.number().optional(),
|
||||
where: PostWhereInputSchema.optional(),
|
||||
select: PostSelectSchema.optional(),
|
||||
orderBy: PostOrderBySchema.optional()
|
||||
orderBy: PostOrderBySchema.optional(),
|
||||
}),
|
||||
) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
|
||||
.query(async ({ input, ctx }) => {
|
||||
|
|
|
@ -101,13 +101,21 @@ export class PostService extends BaseService<Prisma.PostDelegate> {
|
|||
});
|
||||
}
|
||||
async findManyWithPagination(
|
||||
args: { page?: number; pageSize?: number; where?: Prisma.PostWhereInput; select?: Prisma.PostSelect<DefaultArgs>; orderBy?: Prisma.PostOrderByWithRelationInput },
|
||||
args: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
where?: Prisma.PostWhereInput;
|
||||
select?: Prisma.PostSelect<DefaultArgs>;
|
||||
orderBy?: Prisma.PostOrderByWithRelationInput;
|
||||
},
|
||||
staff?: UserProfile,
|
||||
clientIp?: string,
|
||||
) {
|
||||
if (!args.where) args.where = {};
|
||||
args.where.OR = await this.preFilter(args.where.OR, staff);
|
||||
return this.wrapResult(super.findManyWithPagination(args as any), async (result) => {
|
||||
return this.wrapResult(
|
||||
super.findManyWithPagination(args as any),
|
||||
async (result) => {
|
||||
const { items } = result;
|
||||
await Promise.all(
|
||||
items.map(async (item) => {
|
||||
|
@ -116,7 +124,8 @@ export class PostService extends BaseService<Prisma.PostDelegate> {
|
|||
}),
|
||||
);
|
||||
return { ...result, items };
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
protected async setPerms(data: Post, staff?: UserProfile) {
|
||||
if (!staff) return;
|
||||
|
|
|
@ -12,6 +12,8 @@ const StaffWhereInputSchema: ZodType<Prisma.StaffWhereInput> = z.any();
|
|||
const StaffSelectSchema: ZodType<Prisma.StaffSelect> = z.any();
|
||||
const StaffUpdateInputSchema: ZodType<Prisma.PostUpdateInput> = z.any();
|
||||
const StaffFindManyArgsSchema: ZodType<Prisma.StaffFindManyArgs> = z.any();
|
||||
const StaffOrderBySchema: ZodType<Prisma.StaffOrderByWithRelationInput> =
|
||||
z.any();
|
||||
@Injectable()
|
||||
export class StaffRouter {
|
||||
constructor(
|
||||
|
@ -78,12 +80,15 @@ export class StaffRouter {
|
|||
return this.staffService.updateOrder(input);
|
||||
}),
|
||||
findManyWithPagination: this.trpc.procedure
|
||||
.input(z.object({
|
||||
.input(
|
||||
z.object({
|
||||
page: z.number(),
|
||||
pageSize: z.number().optional(),
|
||||
where: StaffWhereInputSchema.optional(),
|
||||
select: StaffSelectSchema.optional()
|
||||
})) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
|
||||
select: StaffSelectSchema.optional(),
|
||||
orderBy: StaffOrderBySchema.optional(),
|
||||
}),
|
||||
) // Assuming StaffMethodSchema.findMany is the Zod schema for finding staffs by keyword
|
||||
.query(async ({ input }) => {
|
||||
return await this.staffService.findManyWithPagination(input);
|
||||
}),
|
||||
|
|
|
@ -105,7 +105,7 @@ export class StaffService extends BaseService<Prisma.StaffDelegate> {
|
|||
* @returns 更新后的员工记录
|
||||
*/
|
||||
async updateUserDomain(data: { domainId?: string }, staff?: UserProfile) {
|
||||
let { domainId } = data;
|
||||
const { domainId } = data;
|
||||
if (staff.domainId !== domainId) {
|
||||
const result = await this.update({
|
||||
where: { id: staff.id },
|
||||
|
@ -120,14 +120,23 @@ export class StaffService extends BaseService<Prisma.StaffDelegate> {
|
|||
}
|
||||
}
|
||||
|
||||
async findManyWithPagination(args: { page?: number; pageSize?: number; where?: Prisma.StaffWhereInput; select?: Prisma.StaffSelect<DefaultArgs>; }) {
|
||||
async findManyWithPagination(args: {
|
||||
page?: number;
|
||||
pageSize?: number;
|
||||
where?: Prisma.StaffWhereInput;
|
||||
select?: Prisma.StaffSelect<DefaultArgs>;
|
||||
orderBy?: Prisma.StaffOrderByWithRelationInput;
|
||||
}) {
|
||||
if (args.where.deptId && typeof args.where.deptId === 'string') {
|
||||
const childDepts = await this.departmentService.getDescendantIds(args.where.deptId, true);
|
||||
const childDepts = await this.departmentService.getDescendantIds(
|
||||
args.where.deptId,
|
||||
true,
|
||||
);
|
||||
args.where.deptId = {
|
||||
in: childDepts
|
||||
}
|
||||
in: childDepts,
|
||||
};
|
||||
}
|
||||
|
||||
return super.findManyWithPagination(args)
|
||||
return super.findManyWithPagination(args as any);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,40 +1,49 @@
|
|||
import { useState, useCallback, useEffect } from 'react';
|
||||
import { motion, AnimatePresence } from 'framer-motion';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
import { useState, useCallback, useEffect } from "react";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import { useSearchParams } from "react-router-dom";
|
||||
|
||||
import { SendCard } from './SendCard';
|
||||
import { Spin, Empty, Input, Alert, Pagination } from 'antd';
|
||||
import { api, useTerm } from '@nice/client';
|
||||
import DepartmentSelect from '@web/src/components/models/department/department-select';
|
||||
import debounce from 'lodash/debounce';
|
||||
import { SearchOutlined } from '@ant-design/icons';
|
||||
import WriteHeader from './WriteHeader';
|
||||
import { SendCard } from "./SendCard";
|
||||
import { Spin, Empty, Input, Alert, Pagination } from "antd";
|
||||
import { api, useTerm } from "@nice/client";
|
||||
import DepartmentSelect from "@web/src/components/models/department/department-select";
|
||||
import debounce from "lodash/debounce";
|
||||
import { SearchOutlined } from "@ant-design/icons";
|
||||
import WriteHeader from "./WriteHeader";
|
||||
|
||||
export default function WriteLetterPage() {
|
||||
const [searchParams] = useSearchParams();
|
||||
const termId = searchParams.get('termId');
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const termId = searchParams.get("termId");
|
||||
const [searchQuery, setSearchQuery] = useState("");
|
||||
const [selectedDept, setSelectedDept] = useState<string>();
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
const pageSize = 10;
|
||||
const { getTerm } = useTerm()
|
||||
const { getTerm } = useTerm();
|
||||
|
||||
const { data, isLoading, error } = api.staff.findManyWithPagination.useQuery({
|
||||
const { data, isLoading, error } =
|
||||
api.staff.findManyWithPagination.useQuery({
|
||||
page: currentPage,
|
||||
pageSize,
|
||||
|
||||
where: {
|
||||
deptId: selectedDept,
|
||||
OR: [{
|
||||
OR: [
|
||||
{
|
||||
showname: {
|
||||
contains: searchQuery
|
||||
}
|
||||
}, {
|
||||
contains: searchQuery,
|
||||
},
|
||||
},
|
||||
{
|
||||
username: {
|
||||
contains: searchQuery
|
||||
}
|
||||
}]
|
||||
}
|
||||
contains: searchQuery,
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
orderBy: {
|
||||
order: "desc",
|
||||
},
|
||||
// orderBy:{
|
||||
|
||||
// }
|
||||
});
|
||||
|
||||
const resetPage = useCallback(() => {
|
||||
|
@ -54,22 +63,25 @@ export default function WriteLetterPage() {
|
|||
{/* Search and Filter Section */}
|
||||
<div className="flex flex-col md:flex-row gap-4 items-center">
|
||||
<DepartmentSelect
|
||||
variant='filled'
|
||||
variant="filled"
|
||||
size="large"
|
||||
value={selectedDept}
|
||||
onChange={setSelectedDept as any}
|
||||
className="w-1/2"
|
||||
/>
|
||||
<Input
|
||||
variant='filled'
|
||||
className={'w-1/2'}
|
||||
prefix={<SearchOutlined className="text-gray-400" />}
|
||||
variant="filled"
|
||||
className={"w-1/2"}
|
||||
prefix={
|
||||
<SearchOutlined className="text-gray-400" />
|
||||
}
|
||||
placeholder="搜索领导姓名或职级..."
|
||||
onChange={debounce((e) => setSearchQuery(e.target.value), 300)}
|
||||
|
||||
onChange={debounce(
|
||||
(e) => setSearchQuery(e.target.value),
|
||||
300
|
||||
)}
|
||||
size="large"
|
||||
/>
|
||||
|
||||
</div>
|
||||
|
||||
{error && (
|
||||
|
@ -92,8 +104,7 @@ export default function WriteLetterPage() {
|
|||
className="grid grid-cols-1 gap-6"
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
>
|
||||
exit={{ opacity: 0 }}>
|
||||
{data?.items.map((item: any) => (
|
||||
<SendCard
|
||||
key={item.id}
|
||||
|
@ -107,8 +118,7 @@ export default function WriteLetterPage() {
|
|||
className="text-center py-12"
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
>
|
||||
exit={{ opacity: 0 }}>
|
||||
<Empty
|
||||
description="没有找到匹配的收信人"
|
||||
className="py-12"
|
||||
|
|
|
@ -1,33 +1,39 @@
|
|||
import { useState, useEffect, useMemo } from 'react';
|
||||
import { Input, Pagination, Empty, Spin } from 'antd';
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { Input, Pagination, Empty, Spin } from "antd";
|
||||
import { api, RouterInputs } from "@nice/client";
|
||||
import { LetterCard } from "../LetterCard";
|
||||
import { NonVoid } from "@nice/utils";
|
||||
import { SearchOutlined } from '@ant-design/icons';
|
||||
import debounce from 'lodash/debounce';
|
||||
import { postDetailSelect } from '@nice/common';
|
||||
export default function LetterList({ params }: { params: NonVoid<RouterInputs["post"]["findManyWithPagination"]> }) {
|
||||
const [searchText, setSearchText] = useState('');
|
||||
import { SearchOutlined } from "@ant-design/icons";
|
||||
import debounce from "lodash/debounce";
|
||||
import { postDetailSelect } from "@nice/common";
|
||||
export default function LetterList({
|
||||
params,
|
||||
}: {
|
||||
params: NonVoid<RouterInputs["post"]["findManyWithPagination"]>;
|
||||
}) {
|
||||
const [searchText, setSearchText] = useState("");
|
||||
const [currentPage, setCurrentPage] = useState(1);
|
||||
|
||||
const { data, isLoading } = api.post.findManyWithPagination.useQuery({
|
||||
page: currentPage,
|
||||
pageSize: params.pageSize,
|
||||
where: {
|
||||
OR: [{
|
||||
OR: [
|
||||
{
|
||||
title: {
|
||||
contains: searchText
|
||||
}
|
||||
}],
|
||||
...params?.where
|
||||
contains: searchText,
|
||||
},
|
||||
},
|
||||
],
|
||||
...params?.where,
|
||||
},
|
||||
orderBy: {
|
||||
updatedAt: "desc"
|
||||
updatedAt: "desc",
|
||||
},
|
||||
select: {
|
||||
...postDetailSelect,
|
||||
...params.select
|
||||
}
|
||||
...params.select,
|
||||
},
|
||||
});
|
||||
|
||||
const debouncedSearch = useMemo(
|
||||
|
@ -51,7 +57,7 @@ export default function LetterList({ params }: { params: NonVoid<RouterInputs["p
|
|||
const handlePageChange = (page: number) => {
|
||||
setCurrentPage(page);
|
||||
// Scroll to top when page changes
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' });
|
||||
window.scrollTo({ top: 0, behavior: "smooth" });
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -60,7 +66,7 @@ export default function LetterList({ params }: { params: NonVoid<RouterInputs["p
|
|||
<div className="p-6 transition-all ">
|
||||
<Input
|
||||
variant="filled"
|
||||
className='w-full'
|
||||
className="w-full"
|
||||
placeholder="搜索信件标题..."
|
||||
allowClear
|
||||
size="large"
|
||||
|
@ -72,8 +78,8 @@ export default function LetterList({ params }: { params: NonVoid<RouterInputs["p
|
|||
{/* Content Area */}
|
||||
<div className="flex-grow px-6">
|
||||
{isLoading ? (
|
||||
<div className='flex justify-center items-center pt-6'>
|
||||
<Spin size='large'></Spin>
|
||||
<div className="flex justify-center items-center pt-6">
|
||||
<Spin size="large"></Spin>
|
||||
</div>
|
||||
) : data?.items.length ? (
|
||||
<>
|
||||
|
@ -96,18 +102,13 @@ export default function LetterList({ params }: { params: NonVoid<RouterInputs["p
|
|||
) : (
|
||||
<div className="flex flex-col justify-center items-center pt-6">
|
||||
<Empty
|
||||
|
||||
description={
|
||||
searchText ? "未找到相关信件" : "暂无信件"
|
||||
}
|
||||
|
||||
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
"scripts": {
|
||||
"build": "tsup",
|
||||
"dev": "tsup --watch",
|
||||
"dev-static": "tsup --no-watch",
|
||||
"clean": "rimraf dist",
|
||||
"typecheck": "tsc --noEmit"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue