From 077767d4e6c6b23b5664c1b227a34bf91026693b Mon Sep 17 00:00:00 2001 From: Rao <1227431568@qq.com> Date: Wed, 12 Mar 2025 10:02:41 +0800 Subject: [PATCH 1/3] rht --- apps/web/src/app/main/dailyPage/page.tsx | 10 ++++ .../src/app/main/layout/NavigationMenu.tsx | 2 +- .../components/models/daily/DailyContext.tsx | 46 +++++++++++++++++++ .../components/models/daily/DailyLayout.tsx | 11 +++++ .../dailyMsgDisplay/DailyMsgDisplayLayout.tsx | 5 ++ .../daily/dailyMsgForm/DailyMsgFormLayout.tsx | 23 ++++++++++ .../components/models/staff/staff-select.tsx | 17 ++++++- apps/web/src/routes/index.tsx | 5 ++ 8 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 apps/web/src/app/main/dailyPage/page.tsx create mode 100644 apps/web/src/components/models/daily/DailyContext.tsx create mode 100644 apps/web/src/components/models/daily/DailyLayout.tsx create mode 100644 apps/web/src/components/models/daily/dailyMsgDisplay/DailyMsgDisplayLayout.tsx create mode 100644 apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx diff --git a/apps/web/src/app/main/dailyPage/page.tsx b/apps/web/src/app/main/dailyPage/page.tsx new file mode 100644 index 0000000..ba9510d --- /dev/null +++ b/apps/web/src/app/main/dailyPage/page.tsx @@ -0,0 +1,10 @@ +import DailyContext from "@web/src/components/models/daily/DailyContext"; +import DailyLayout from "@web/src/components/models/daily/DailyLayout"; + +export default function DailyPage(){ + return <> + + + + +} \ No newline at end of file diff --git a/apps/web/src/app/main/layout/NavigationMenu.tsx b/apps/web/src/app/main/layout/NavigationMenu.tsx index 126b0fa..0b65a2f 100644 --- a/apps/web/src/app/main/layout/NavigationMenu.tsx +++ b/apps/web/src/app/main/layout/NavigationMenu.tsx @@ -7,7 +7,7 @@ export default function NavigationMenu() { const menuItems = [ { key: 'home', label: '首页', path: '/' }, { key: 'staff', label: '人员总览', path: '/staff' }, - { key: 'day', label: '日统计', path: '/day' }, + { key: 'day', label: '日统计', path: '/daily' }, { key: 'month', label: '月统计', path: '/month' }, { key: 'year', label: '年度统计', path: '/year' } ]; diff --git a/apps/web/src/components/models/daily/DailyContext.tsx b/apps/web/src/components/models/daily/DailyContext.tsx new file mode 100644 index 0000000..cac44bd --- /dev/null +++ b/apps/web/src/components/models/daily/DailyContext.tsx @@ -0,0 +1,46 @@ +import { api } from "@nice/client"; +import { createContext, ReactNode, useContext, useEffect } from "react"; + +interface DailyContextProviderProps{ + staffsMsg:{ + id:string, + showname:string, + username:string + }[], + staffsLoading:boolean +} + +interface DailyContextProps{ + children:ReactNode +} + +const DailyContextProvider = createContext(null) + +export default function DailyContext({children}:DailyContextProps){ + // 获取当前单位下的所有staff的记录 + const {data:staffs,isLoading:staffsLoading} = api.staff.findByDept.useQuery({ + deptId:"cm84jt1gv000do5gqsxx68iko" + }) + const staffsMsg = staffs?.map((staff)=>{ + return { + id:staff.id, + showname:staff.showname, + username:staff.username + } + }) + useEffect(()=>{ + console.log(staffs) + },[staffs]) + return + {children} + +} + +export function useDaily(){ + const daily = useContext(DailyContextProvider) + if(!daily) {throw new Error("useParams must be used within a ParamsProvider");} + return daily +} \ No newline at end of file diff --git a/apps/web/src/components/models/daily/DailyLayout.tsx b/apps/web/src/components/models/daily/DailyLayout.tsx new file mode 100644 index 0000000..6d7ab8e --- /dev/null +++ b/apps/web/src/components/models/daily/DailyLayout.tsx @@ -0,0 +1,11 @@ +import DailyMsgDisplayLayout from "./dailyMsgDisplay/DailyMsgDisplayLayout"; +import { DailyMsgFormLayout } from "./dailyMsgForm/DailyMsgFormLayout"; + +export default function DailyLayout(){ + return ( +
+ + +
+ ) +} \ No newline at end of file diff --git a/apps/web/src/components/models/daily/dailyMsgDisplay/DailyMsgDisplayLayout.tsx b/apps/web/src/components/models/daily/dailyMsgDisplay/DailyMsgDisplayLayout.tsx new file mode 100644 index 0000000..48ce306 --- /dev/null +++ b/apps/web/src/components/models/daily/dailyMsgDisplay/DailyMsgDisplayLayout.tsx @@ -0,0 +1,5 @@ +export default function DailyMsgDisplayLayout(){ + return ( +
+ ) +} \ No newline at end of file diff --git a/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx b/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx new file mode 100644 index 0000000..e52010d --- /dev/null +++ b/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx @@ -0,0 +1,23 @@ +import { Form, QRCode, Select } from "antd"; +import StaffSelect from "../../staff/staff-select"; +import { useDaily } from "../DailyContext"; + +export function DailyMsgFormLayout() { + const [form] = Form.useForm() + const { staffsMsg } = useDaily() + const handleChange = (value: string | string[]) => { + console.log(value) + } + return ( +
+
+ handleChange(value)} + > +
+
+ ) +} \ No newline at end of file diff --git a/apps/web/src/components/models/staff/staff-select.tsx b/apps/web/src/components/models/staff/staff-select.tsx index 5881f2a..ee46458 100755 --- a/apps/web/src/components/models/staff/staff-select.tsx +++ b/apps/web/src/components/models/staff/staff-select.tsx @@ -9,6 +9,13 @@ interface StaffSelectProps { multiple?: boolean; domainId?: string; placeholder?: string; + staffsMsg?: StaffsMsgProps[]; +} + +interface StaffsMsgProps { + id: string; + showname: string; + username: string; } export default function StaffSelect({ @@ -18,6 +25,7 @@ export default function StaffSelect({ style, multiple, domainId, + staffsMsg, }: StaffSelectProps) { const [keyword, setQuery] = useState(""); @@ -50,7 +58,7 @@ export default function StaffSelect({ }, select: { id: true, showname: true, username: true }, - take: 30, + //take: 30, orderBy: { order: "asc" } }); @@ -59,6 +67,13 @@ export default function StaffSelect({ }; const options: SelectProps["options"] = + staffsMsg ? + staffsMsg.map((staff)=>{ + return { + value:staff.id, + label:staff.showname || staff.username + } + }) : data?.map((staff: any) => ({ value: staff.id, label: staff?.showname || staff?.username, diff --git a/apps/web/src/routes/index.tsx b/apps/web/src/routes/index.tsx index 85a7d84..326bc27 100755 --- a/apps/web/src/routes/index.tsx +++ b/apps/web/src/routes/index.tsx @@ -10,6 +10,7 @@ import LoginPage from "../app/login"; import HomePage from "../app/main/home/page"; import StaffMessage from "../app/main/staffpage/page"; import MainLayout from "../app/main/layout/MainLayout"; +import DailyPage from "../app/main/dailyPage/page"; interface CustomIndexRouteObject extends IndexRouteObject { name?: string; breadcrumb?: string; @@ -51,6 +52,10 @@ export const routes: CustomRouteObject[] = [ path: "/staff", element: , }, + { + path:"/daily", + element: + } ], }, From c6fc7d8f2429060bab5077d996711f18dc7890c9 Mon Sep 17 00:00:00 2001 From: Rao <1227431568@qq.com> Date: Wed, 12 Mar 2025 11:36:31 +0800 Subject: [PATCH 2/3] rht --- apps/server/src/models/staff/staff.router.ts | 6 +++ apps/server/src/tasks/init/gendev.service.ts | 2 +- .../components/models/daily/DailyContext.tsx | 12 ++--- .../daily/dailyMsgForm/DailyMsgFormLayout.tsx | 51 ++++++++++++++++--- .../daily/dailyMsgForm/DailyPersonMsg.tsx | 13 +++++ .../daily/dailyMsgForm/DailyTrainMsg.tsx | 7 +++ .../components/models/staff/staff-select.tsx | 4 +- packages/common/src/models/select.ts | 36 ++++++++++++- 8 files changed, 114 insertions(+), 17 deletions(-) create mode 100644 apps/web/src/components/models/daily/dailyMsgForm/DailyPersonMsg.tsx create mode 100644 apps/web/src/components/models/daily/dailyMsgForm/DailyTrainMsg.tsx diff --git a/apps/server/src/models/staff/staff.router.ts b/apps/server/src/models/staff/staff.router.ts index 9f227a4..d93821e 100755 --- a/apps/server/src/models/staff/staff.router.ts +++ b/apps/server/src/models/staff/staff.router.ts @@ -12,6 +12,7 @@ const StaffWhereInputSchema: ZodType = z.any(); const StaffSelectSchema: ZodType = z.any(); const StaffUpdateInputSchema: ZodType = z.any(); const StaffFindManyArgsSchema: ZodType = z.any(); +const StaffFindUniqueArgsSchema: ZodType = z.any(); @Injectable() export class StaffRouter { constructor( @@ -89,5 +90,10 @@ export class StaffRouter { .mutation(async ({ input }) => { return this.staffService.updateOrder(input); }), + findUnique: this.trpc.procedure + .input(StaffFindUniqueArgsSchema) + .query(async ({ input }) => { + return await this.staffService.findUnique(input); + }), }); } diff --git a/apps/server/src/tasks/init/gendev.service.ts b/apps/server/src/tasks/init/gendev.service.ts index ea3f0ee..2e8111e 100755 --- a/apps/server/src/tasks/init/gendev.service.ts +++ b/apps/server/src/tasks/init/gendev.service.ts @@ -421,7 +421,7 @@ export class GenDevService { return trainSituation } - private async generateTrainSituations(probability: number = 0.7){ + private async generateTrainSituations(probability: number = 0.1){ this.logger.log("Start generating train situations...") const allTrainContents = await db.trainContent.findMany(); // 这里相当于两次遍历 找到没有parentID的即是 diff --git a/apps/web/src/components/models/daily/DailyContext.tsx b/apps/web/src/components/models/daily/DailyContext.tsx index cac44bd..51fc184 100644 --- a/apps/web/src/components/models/daily/DailyContext.tsx +++ b/apps/web/src/components/models/daily/DailyContext.tsx @@ -1,4 +1,6 @@ import { api } from "@nice/client"; +import { useAuth } from "@web/src/providers/auth-provider"; +import { UserProfile } from "@nice/common"; import { createContext, ReactNode, useContext, useEffect } from "react"; interface DailyContextProviderProps{ @@ -17,9 +19,10 @@ interface DailyContextProps{ const DailyContextProvider = createContext(null) export default function DailyContext({children}:DailyContextProps){ - // 获取当前单位下的所有staff的记录 + const {user} = useAuth() + // 获取当前员工的单位下的所有staff的记录 const {data:staffs,isLoading:staffsLoading} = api.staff.findByDept.useQuery({ - deptId:"cm84jt1gv000do5gqsxx68iko" + deptId:user.deptId }) const staffsMsg = staffs?.map((staff)=>{ return { @@ -28,12 +31,9 @@ export default function DailyContext({children}:DailyContextProps){ username:staff.username } }) - useEffect(()=>{ - console.log(staffs) - },[staffs]) return {children} diff --git a/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx b/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx index e52010d..05f3d9a 100644 --- a/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx +++ b/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx @@ -1,23 +1,60 @@ -import { Form, QRCode, Select } from "antd"; +import { Form } from "antd"; import StaffSelect from "../../staff/staff-select"; import { useDaily } from "../DailyContext"; +import { useEffect, useState } from "react"; +import { staffDetailSelect, UserProfile } from "@nice/common"; +import { api } from "@nice/client"; +import DailyPersonMsg from "./DailyPersonMsg"; +import { MonitorOutlined } from "@ant-design/icons"; +import DailyTrainMsg from "./DailyTrainMsg"; export function DailyMsgFormLayout() { const [form] = Form.useForm() const { staffsMsg } = useDaily() + const [selectedUserMsg, setSelectedUserMsg] = useState(null) + const [selectedUserId, setSelectedUserId] = useState(null); + const { data: selectedUserData } = api.staff.findUnique.useQuery( + { + where: { + id: selectedUserId, + }, + select: staffDetailSelect + }, + { + enabled: !!selectedUserId, // 只有当selectedUserId存在时才执行查询 + } + ); const handleChange = (value: string | string[]) => { - console.log(value) + if (!value) { + setSelectedUserId(null); + setSelectedUserMsg(null); + return; + } + setSelectedUserId(Array.isArray(value) ? value[0] : value); } + useEffect(() => { + if (selectedUserData) { + console.log(selectedUserData) + setSelectedUserMsg(selectedUserData); + } + }, [selectedUserData]); + return ( -
+
- handleChange(value)} - > +
+ + handleChange(value)} + > +
+ +
) } \ No newline at end of file diff --git a/apps/web/src/components/models/daily/dailyMsgForm/DailyPersonMsg.tsx b/apps/web/src/components/models/daily/dailyMsgForm/DailyPersonMsg.tsx new file mode 100644 index 0000000..961ecc7 --- /dev/null +++ b/apps/web/src/components/models/daily/dailyMsgForm/DailyPersonMsg.tsx @@ -0,0 +1,13 @@ +export default function DailyPersonMsg({selectedUserMsg}) { + return ( +
+ {selectedUserMsg?.showname ? selectedUserMsg?.showname : "暂无数据"} + {selectedUserMsg?.age ? selectedUserMsg?.age : "暂无数据"} + {selectedUserMsg?.sex ? selectedUserMsg?.sex : "暂无数据"} + {selectedUserMsg?.absent ? selectedUserMsg?.absent : "暂无数据"} + {selectedUserMsg?.department?.name ? selectedUserMsg?.department?.name : "暂无数据"} + {selectedUserMsg?.position?.type ? selectedUserMsg?.position?.type : "暂无数据"} + {selectedUserMsg?.avatar ? selectedUserMsg?.avatar : "暂无数据"} +
+ ) +} \ No newline at end of file diff --git a/apps/web/src/components/models/daily/dailyMsgForm/DailyTrainMsg.tsx b/apps/web/src/components/models/daily/dailyMsgForm/DailyTrainMsg.tsx new file mode 100644 index 0000000..7d8f73e --- /dev/null +++ b/apps/web/src/components/models/daily/dailyMsgForm/DailyTrainMsg.tsx @@ -0,0 +1,7 @@ +export default function DailyTrainMsg() { + return ( +
+ 每日培训消息 +
+ ) +} \ No newline at end of file diff --git a/apps/web/src/components/models/staff/staff-select.tsx b/apps/web/src/components/models/staff/staff-select.tsx index ee46458..761ef14 100755 --- a/apps/web/src/components/models/staff/staff-select.tsx +++ b/apps/web/src/components/models/staff/staff-select.tsx @@ -23,7 +23,7 @@ export default function StaffSelect({ onChange, placeholder, style, - multiple, + multiple = false, domainId, staffsMsg, }: StaffSelectProps) { @@ -92,7 +92,7 @@ export default function StaffSelect({ options={options} value={value} onChange={onChange} - style={{ minWidth: 200, ...style }} + style={{ minWidth: 600, ...style }} />{" "} ); diff --git a/packages/common/src/models/select.ts b/packages/common/src/models/select.ts index f97fdf2..96dc776 100755 --- a/packages/common/src/models/select.ts +++ b/packages/common/src/models/select.ts @@ -163,7 +163,41 @@ export const trainSituationDetailSelect: Prisma.TrainSituationSelect = { select: { id: true, title: true, - + }, }, }; +export const staffDetailSelect: Prisma.StaffSelect = { + id: true, + showname: true, + username: true, + deptId: true, + avatar: true, + age: true, + sex: true, + absent: true, + trainSituations:{ + select:{ + id: true, + trainContent:{ + select:{ + id: true, + title: true, + type: true, + } + } + } + }, + department: { + select: { + id: true, + name: true, + } + }, + position: { + select: { + id: true, + type: true, + } + } +}; From 622aa0358a09ef7f52b5f297a8c5fd9c61c742f5 Mon Sep 17 00:00:00 2001 From: Rao <1227431568@qq.com> Date: Wed, 12 Mar 2025 11:43:17 +0800 Subject: [PATCH 3/3] rht --- apps/web/src/components/models/daily/DailyContext.tsx | 11 +++++++++-- .../daily/dailyMsgDisplay/DailyMsgDisplayLayout.tsx | 9 ++++++++- .../models/daily/dailyMsgForm/DailyMsgFormLayout.tsx | 9 ++------- .../models/daily/dailyMsgForm/DailyTrainMsg.tsx | 2 +- 4 files changed, 20 insertions(+), 11 deletions(-) diff --git a/apps/web/src/components/models/daily/DailyContext.tsx b/apps/web/src/components/models/daily/DailyContext.tsx index 51fc184..ac9436b 100644 --- a/apps/web/src/components/models/daily/DailyContext.tsx +++ b/apps/web/src/components/models/daily/DailyContext.tsx @@ -1,7 +1,7 @@ import { api } from "@nice/client"; import { useAuth } from "@web/src/providers/auth-provider"; import { UserProfile } from "@nice/common"; -import { createContext, ReactNode, useContext, useEffect } from "react"; +import { createContext, ReactNode, useContext, useEffect, useState } from "react"; interface DailyContextProviderProps{ staffsMsg:{ @@ -9,7 +9,9 @@ interface DailyContextProviderProps{ showname:string, username:string }[], - staffsLoading:boolean + staffsLoading:boolean, + selectedUserMsg:UserProfile, + setSelectedUserMsg:(userMsg:UserProfile)=>void } interface DailyContextProps{ @@ -20,6 +22,7 @@ const DailyContextProvider = createContext(null) export default function DailyContext({children}:DailyContextProps){ const {user} = useAuth() + const [selectedUserMsg,setSelectedUserMsg] = useState(null) // 获取当前员工的单位下的所有staff的记录 const {data:staffs,isLoading:staffsLoading} = api.staff.findByDept.useQuery({ deptId:user.deptId @@ -31,9 +34,13 @@ export default function DailyContext({children}:DailyContextProps){ username:staff.username } }) + + return {children} diff --git a/apps/web/src/components/models/daily/dailyMsgDisplay/DailyMsgDisplayLayout.tsx b/apps/web/src/components/models/daily/dailyMsgDisplay/DailyMsgDisplayLayout.tsx index 48ce306..7357e23 100644 --- a/apps/web/src/components/models/daily/dailyMsgDisplay/DailyMsgDisplayLayout.tsx +++ b/apps/web/src/components/models/daily/dailyMsgDisplay/DailyMsgDisplayLayout.tsx @@ -1,5 +1,12 @@ +import DailyPersonMsg from "../dailyMsgForm/DailyPersonMsg"; +import DailyTrainMsg from "../dailyMsgForm/DailyTrainMsg"; +import { useDaily } from "../DailyContext"; export default function DailyMsgDisplayLayout(){ + const {selectedUserMsg} = useDaily() return ( -
+
+ + +
) } \ No newline at end of file diff --git a/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx b/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx index 05f3d9a..a9f4de6 100644 --- a/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx +++ b/apps/web/src/components/models/daily/dailyMsgForm/DailyMsgFormLayout.tsx @@ -4,14 +4,11 @@ import { useDaily } from "../DailyContext"; import { useEffect, useState } from "react"; import { staffDetailSelect, UserProfile } from "@nice/common"; import { api } from "@nice/client"; -import DailyPersonMsg from "./DailyPersonMsg"; import { MonitorOutlined } from "@ant-design/icons"; -import DailyTrainMsg from "./DailyTrainMsg"; export function DailyMsgFormLayout() { const [form] = Form.useForm() - const { staffsMsg } = useDaily() - const [selectedUserMsg, setSelectedUserMsg] = useState(null) + const { staffsMsg ,selectedUserMsg,setSelectedUserMsg} = useDaily() const [selectedUserId, setSelectedUserId] = useState(null); const { data: selectedUserData } = api.staff.findUnique.useQuery( { @@ -35,7 +32,7 @@ export function DailyMsgFormLayout() { useEffect(() => { if (selectedUserData) { console.log(selectedUserData) - setSelectedUserMsg(selectedUserData); + setSelectedUserMsg(selectedUserData as any as UserProfile); } }, [selectedUserData]); @@ -53,8 +50,6 @@ export function DailyMsgFormLayout() { >
- - ) } \ No newline at end of file diff --git a/apps/web/src/components/models/daily/dailyMsgForm/DailyTrainMsg.tsx b/apps/web/src/components/models/daily/dailyMsgForm/DailyTrainMsg.tsx index 7d8f73e..927d727 100644 --- a/apps/web/src/components/models/daily/dailyMsgForm/DailyTrainMsg.tsx +++ b/apps/web/src/components/models/daily/dailyMsgForm/DailyTrainMsg.tsx @@ -1,4 +1,4 @@ -export default function DailyTrainMsg() { +export default function DailyTrainMsg({selectedUserMsg}) { return (
每日培训消息