Merge branch 'main' of http://113.45.157.195:3003/raohaotian/train-data
This commit is contained in:
commit
1cdefc79d4
|
@ -1,7 +1,12 @@
|
||||||
import { Injectable } from "@nestjs/common";
|
import { Injectable } from "@nestjs/common";
|
||||||
import { TrpcService } from "@server/trpc/trpc.service";
|
import { TrpcService } from "@server/trpc/trpc.service";
|
||||||
import { TrainContentService } from "./trainContent.service";
|
import { TrainContentService } from "./trainContent.service";
|
||||||
|
import { z, ZodType } from "zod";
|
||||||
|
import { Prisma } from "@nice/common";
|
||||||
|
|
||||||
|
const TrainContentArgsSchema:ZodType<Prisma.TrainContentCreateArgs> = z.any()
|
||||||
|
const TrainContentUpdateArgsSchema:ZodType<Prisma.TrainContentUpdateArgs> = z.any()
|
||||||
|
const TrainContentFindManyArgsSchema:ZodType<Prisma.TrainContentFindManyArgs> = z.any()
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TrainContentRouter {
|
export class TrainContentRouter {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -10,7 +15,18 @@ export class TrainContentRouter {
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
router = this.trpc.router({
|
router = this.trpc.router({
|
||||||
|
create:this.trpc.procedure.input(TrainContentArgsSchema)
|
||||||
|
.mutation(async ({input})=>{
|
||||||
|
return this.trainContentService.create(input)
|
||||||
|
}),
|
||||||
|
update:this.trpc.procedure.input(TrainContentUpdateArgsSchema)
|
||||||
|
.mutation(async ({input})=>{
|
||||||
|
return this.trainContentService.update(input)
|
||||||
|
}),
|
||||||
|
findMany:this.trpc.procedure.input(TrainContentFindManyArgsSchema)
|
||||||
|
.query(async ({input})=>{
|
||||||
|
return this.trainContentService.findMany(input)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,5 +1,5 @@
|
||||||
import DailyContext from "@web/src/components/models/daily/DailyContext";
|
import DailyContext from "@web/src/components/models/trainPlan/TrainPlanContext";
|
||||||
import DailyLayout from "@web/src/components/models/daily/DailyLayout";
|
import DailyLayout from "@web/src/components/models/trainPlan/TrainPlanLayout";
|
||||||
|
|
||||||
export default function DailyPage(){
|
export default function DailyPage(){
|
||||||
return <>
|
return <>
|
||||||
|
|
|
@ -1,11 +0,0 @@
|
||||||
import DailyMsgDisplayLayout from "./dailyMsgDisplay/DailyMsgDisplayLayout";
|
|
||||||
import { DailyMsgFormLayout } from "./dailyMsgForm/DailyMsgFormLayout";
|
|
||||||
|
|
||||||
export default function DailyLayout(){
|
|
||||||
return (
|
|
||||||
<div className="w-full h-[calc(100vh-100px)]">
|
|
||||||
<DailyMsgFormLayout></DailyMsgFormLayout>
|
|
||||||
<DailyMsgDisplayLayout></DailyMsgDisplayLayout>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,55 +0,0 @@
|
||||||
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 { MonitorOutlined } from "@ant-design/icons";
|
|
||||||
|
|
||||||
export function DailyMsgFormLayout() {
|
|
||||||
const [form] = Form.useForm()
|
|
||||||
const { staffsMsg ,selectedUserMsg,setSelectedUserMsg} = useDaily()
|
|
||||||
const [selectedUserId, setSelectedUserId] = useState<string | null>(null);
|
|
||||||
const { data: selectedUserData } = api.staff.findUnique.useQuery(
|
|
||||||
{
|
|
||||||
where: {
|
|
||||||
id: selectedUserId,
|
|
||||||
},
|
|
||||||
select: staffDetailSelect
|
|
||||||
},
|
|
||||||
{
|
|
||||||
enabled: !!selectedUserId, // 只有当selectedUserId存在时才执行查询
|
|
||||||
}
|
|
||||||
);
|
|
||||||
const handleChange = (value: string | string[]) => {
|
|
||||||
if (!value) {
|
|
||||||
setSelectedUserId(null);
|
|
||||||
setSelectedUserMsg(null);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
setSelectedUserId(Array.isArray(value) ? value[0] : value);
|
|
||||||
}
|
|
||||||
useEffect(() => {
|
|
||||||
if (selectedUserData) {
|
|
||||||
console.log(selectedUserData)
|
|
||||||
setSelectedUserMsg(selectedUserData as any as UserProfile);
|
|
||||||
}
|
|
||||||
}, [selectedUserData]);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div className="w-full h-[260px] bg-white flex flex-col items-center">
|
|
||||||
<Form
|
|
||||||
form={form}
|
|
||||||
>
|
|
||||||
<div className="flex items-center m-8">
|
|
||||||
<MonitorOutlined className="mr-2" />
|
|
||||||
<StaffSelect
|
|
||||||
staffsMsg={staffsMsg}
|
|
||||||
placeholder="请搜索或选择人员"
|
|
||||||
onChange={(value) => handleChange(value)}
|
|
||||||
></StaffSelect>
|
|
||||||
</div>
|
|
||||||
</Form>
|
|
||||||
</div>
|
|
||||||
)
|
|
||||||
}
|
|
|
@ -1,17 +1,13 @@
|
||||||
import { api } from "@nice/client";
|
import { api } from "@nice/client";
|
||||||
import { useAuth } from "@web/src/providers/auth-provider";
|
import { useAuth } from "@web/src/providers/auth-provider";
|
||||||
import { UserProfile } from "@nice/common";
|
import { Department, UserProfile } from "@nice/common";
|
||||||
import { createContext, ReactNode, useContext, useEffect, useState } from "react";
|
import { createContext, ReactNode, useContext, useEffect, useState } from "react";
|
||||||
|
|
||||||
interface DailyContextProviderProps{
|
interface DailyContextProviderProps{
|
||||||
staffsMsg:{
|
staffs:UserProfile[],
|
||||||
id:string,
|
|
||||||
showname:string,
|
|
||||||
username:string
|
|
||||||
}[],
|
|
||||||
staffsLoading:boolean,
|
staffsLoading:boolean,
|
||||||
selectedUserMsg:UserProfile,
|
depts:Department[],
|
||||||
setSelectedUserMsg:(userMsg:UserProfile)=>void
|
deptsLoading:boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DailyContextProps{
|
interface DailyContextProps{
|
||||||
|
@ -21,26 +17,24 @@ interface DailyContextProps{
|
||||||
const DailyContextProvider = createContext<DailyContextProviderProps>(null)
|
const DailyContextProvider = createContext<DailyContextProviderProps>(null)
|
||||||
|
|
||||||
export default function DailyContext({children}:DailyContextProps){
|
export default function DailyContext({children}:DailyContextProps){
|
||||||
const {user} = useAuth()
|
const {user,isAuthenticated} = useAuth()
|
||||||
const [selectedUserMsg,setSelectedUserMsg] = useState(null)
|
|
||||||
// 获取当前员工的单位下的所有staff的记录
|
// 获取当前员工的单位下的所有staff的记录
|
||||||
const {data:staffs,isLoading:staffsLoading} = api.staff.findByDept.useQuery({
|
const {data:staffs,isLoading:staffsLoading} = isAuthenticated?api.staff.findByDept.useQuery({
|
||||||
deptId:user.deptId
|
deptId:user.deptId
|
||||||
})
|
}):{data:null,isLoading:false}
|
||||||
const staffsMsg = staffs?.map((staff)=>{
|
|
||||||
return {
|
|
||||||
id:staff.id,
|
|
||||||
showname:staff.showname,
|
|
||||||
username:staff.username
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
|
const {data:depts,isLoading:deptsLoading} = isAuthenticated?api.department.getChildSimpleTree.useQuery({
|
||||||
|
rootId:user.deptId
|
||||||
|
}):{data:null,isLoading:false}
|
||||||
|
|
||||||
|
useEffect(()=>{
|
||||||
|
console.log(user)
|
||||||
|
},[user])
|
||||||
return <DailyContextProvider.Provider value={{
|
return <DailyContextProvider.Provider value={{
|
||||||
staffsMsg,
|
staffs:staffs as any as UserProfile[],
|
||||||
staffsLoading,
|
staffsLoading,
|
||||||
selectedUserMsg,
|
depts:depts as any as Department[],
|
||||||
setSelectedUserMsg
|
deptsLoading
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</DailyContextProvider.Provider>
|
</DailyContextProvider.Provider>
|
|
@ -1,10 +1,12 @@
|
||||||
import { Button, DatePicker, Form, Modal, TimePicker, TreeSelect } from "antd";
|
import { Button, DatePicker, Form, Modal, Select, TimePicker, TreeSelect } from "antd";
|
||||||
import TextArea from "antd/es/input/TextArea";
|
import TextArea from "antd/es/input/TextArea";
|
||||||
import dayjs from "dayjs";
|
import dayjs from "dayjs";
|
||||||
import { useState } from "react";
|
import { useState,useEffect } from "react";
|
||||||
export default function DailyMsgDisplayLayout() {
|
import { useDaily } from "./TrainPlanContext";
|
||||||
|
export default function TrainPlanCreateForm() {
|
||||||
const [form] = Form.useForm()
|
const [form] = Form.useForm()
|
||||||
const [open, setOpen] = useState(true)
|
const [open, setOpen] = useState(true)
|
||||||
|
const {depts,deptsLoading} = useDaily()
|
||||||
const treeData = [
|
const treeData = [
|
||||||
{
|
{
|
||||||
title: 'Node1',
|
title: 'Node1',
|
||||||
|
@ -25,6 +27,11 @@ export default function DailyMsgDisplayLayout() {
|
||||||
value: '0-1',
|
value: '0-1',
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
useEffect(()=>{
|
||||||
|
if(depts){
|
||||||
|
console.log(depts)
|
||||||
|
}
|
||||||
|
},[depts])
|
||||||
const handleSave = () => {
|
const handleSave = () => {
|
||||||
//console.log(form.getFieldsValue())
|
//console.log(form.getFieldsValue())
|
||||||
const { trainDate, trainTime, trainType, trainContent } = form.getFieldsValue()
|
const { trainDate, trainTime, trainType, trainContent } = form.getFieldsValue()
|
||||||
|
@ -51,6 +58,13 @@ export default function DailyMsgDisplayLayout() {
|
||||||
<Form.Item name="trainTime" label="选择时间">
|
<Form.Item name="trainTime" label="选择时间">
|
||||||
<TimePicker.RangePicker format="HH:mm" style={{ width: '100%' }} />
|
<TimePicker.RangePicker format="HH:mm" style={{ width: '100%' }} />
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
|
<Form.Item name="trainTime" label="选择单位">
|
||||||
|
<Select
|
||||||
|
placeholder="请选择单位"
|
||||||
|
optionFilterProp="label"
|
||||||
|
options={[]}
|
||||||
|
/>
|
||||||
|
</Form.Item>
|
||||||
<Form.Item name="trainType" label="选择学科">
|
<Form.Item name="trainType" label="选择学科">
|
||||||
<TreeSelect
|
<TreeSelect
|
||||||
style={{ width: '100%' }}
|
style={{ width: '100%' }}
|
|
@ -0,0 +1,9 @@
|
||||||
|
import TrainPlanCreateForm from "./TrainPlanCreateForm";
|
||||||
|
|
||||||
|
export default function DailyLayout(){
|
||||||
|
return (
|
||||||
|
<div className="w-full h-[calc(100vh-100px)]">
|
||||||
|
<TrainPlanCreateForm></TrainPlanCreateForm>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
|
@ -408,6 +408,8 @@ model Department {
|
||||||
deptStaffs Staff[] @relation("DeptStaff")
|
deptStaffs Staff[] @relation("DeptStaff")
|
||||||
terms Term[] @relation("department_term")
|
terms Term[] @relation("department_term")
|
||||||
|
|
||||||
|
trainPlans TrainPlan[] @relation("TrainPlanDept")
|
||||||
|
|
||||||
// watchedPost Post[] @relation("post_watch_dept")
|
// watchedPost Post[] @relation("post_watch_dept")
|
||||||
hasChildren Boolean? @default(false) @map("has_children")
|
hasChildren Boolean? @default(false) @map("has_children")
|
||||||
|
|
||||||
|
@ -475,6 +477,8 @@ model TrainPlan {
|
||||||
trainContext String @map("train_context")
|
trainContext String @map("train_context")
|
||||||
|
|
||||||
trainContents TrainContent[] @relation("TrainPlanContent")
|
trainContents TrainContent[] @relation("TrainPlanContent")
|
||||||
|
departmentId String? @map("department_id")
|
||||||
|
department Department? @relation("TrainPlanDept", fields: [departmentId], references: [id])
|
||||||
|
|
||||||
createdAt DateTime @default(now()) @map("created_at")
|
createdAt DateTime @default(now()) @map("created_at")
|
||||||
updatedAt DateTime @updatedAt @map("updated_at")
|
updatedAt DateTime @updatedAt @map("updated_at")
|
||||||
|
|
Loading…
Reference in New Issue