Merge branch 'main' of http://113.45.157.195:3003/raohaotian/train-data
This commit is contained in:
commit
e98f1dcfa0
|
@ -0,0 +1,26 @@
|
||||||
|
import { useAuth } from "@web/src/providers/auth-provider"
|
||||||
|
import { api } from "@nice/client"
|
||||||
|
import { Select } from "antd"
|
||||||
|
import { Department } from "packages/common/dist"
|
||||||
|
|
||||||
|
export default function DepartmentChildrenSelect() {
|
||||||
|
const { user, isAuthenticated } = useAuth()
|
||||||
|
|
||||||
|
const { data: depts, isLoading: deptsLoading }
|
||||||
|
: { data: Department[], isLoading: boolean }
|
||||||
|
= isAuthenticated ? api.department.getChildSimpleTree.useQuery({
|
||||||
|
rootId: user.deptId
|
||||||
|
}) : { data: null, isLoading: false }
|
||||||
|
|
||||||
|
const deptSelectOptions = depts?.map((dept) => ({
|
||||||
|
label: dept.name,
|
||||||
|
value: dept.id
|
||||||
|
}))
|
||||||
|
return (
|
||||||
|
<Select
|
||||||
|
placeholder="请选择单位"
|
||||||
|
optionFilterProp="label"
|
||||||
|
options={deptSelectOptions}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
|
@ -0,0 +1,54 @@
|
||||||
|
import { api } from "@nice/client"
|
||||||
|
import { TrainContent } from "@nice/common"
|
||||||
|
import { useAuth } from "@web/src/providers/auth-provider"
|
||||||
|
import { TreeSelect } from "antd"
|
||||||
|
import { useMemo } from "react"
|
||||||
|
|
||||||
|
export default function TrainContentTreeSelect() {
|
||||||
|
const { user, isAuthenticated } = useAuth()
|
||||||
|
const { data: trainContents, isLoading: trainContentsLoading }
|
||||||
|
: { data: TrainContent[], isLoading: boolean }
|
||||||
|
= isAuthenticated ? api.trainContent.findMany.useQuery({
|
||||||
|
select: {
|
||||||
|
children: true,
|
||||||
|
id: true,
|
||||||
|
title: true,
|
||||||
|
parentId: true,
|
||||||
|
type: true,
|
||||||
|
parent: {
|
||||||
|
select: {
|
||||||
|
id: true,
|
||||||
|
title: true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}) : { data: null, isLoading: false }
|
||||||
|
const treeData = useMemo(() => {
|
||||||
|
if (!trainContents) return [];
|
||||||
|
|
||||||
|
const buildTreeData = (contents: any[], parentId: string | null = null): any[] => {
|
||||||
|
return contents
|
||||||
|
.filter(item => item.parentId === parentId)
|
||||||
|
.map(item => ({
|
||||||
|
title: item.title,
|
||||||
|
value: item.id,
|
||||||
|
key: item.id,
|
||||||
|
type: item.type,
|
||||||
|
children: buildTreeData(contents, item.id)
|
||||||
|
}))
|
||||||
|
.filter(Boolean);
|
||||||
|
};
|
||||||
|
|
||||||
|
return buildTreeData(trainContents);
|
||||||
|
}, [trainContents]);
|
||||||
|
return (
|
||||||
|
<TreeSelect
|
||||||
|
style={{ width: '100%' }}
|
||||||
|
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||||
|
treeData={treeData}
|
||||||
|
placeholder="请选择学科或课程"
|
||||||
|
treeDefaultExpandAll={false}
|
||||||
|
//onChange={onChange}
|
||||||
|
/>
|
||||||
|
)
|
||||||
|
}
|
|
@ -1,13 +1,11 @@
|
||||||
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 { Department, UserProfile } from "@nice/common";
|
import { Department, TrainContent, UserProfile } from "@nice/common";
|
||||||
import { createContext, ReactNode, useContext, useEffect, useState } from "react";
|
import { createContext, ReactNode, useContext, useEffect, useState } from "react";
|
||||||
|
|
||||||
interface DailyContextProviderProps{
|
interface DailyContextProviderProps{
|
||||||
staffs:UserProfile[],
|
staffs:UserProfile[],
|
||||||
staffsLoading:boolean,
|
staffsLoading:boolean,
|
||||||
depts:Department[],
|
|
||||||
deptsLoading:boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
interface DailyContextProps{
|
interface DailyContextProps{
|
||||||
|
@ -23,18 +21,9 @@ export default function DailyContext({children}:DailyContextProps){
|
||||||
deptId:user.deptId
|
deptId:user.deptId
|
||||||
}):{data:null,isLoading:false}
|
}):{data:null,isLoading:false}
|
||||||
|
|
||||||
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={{
|
||||||
staffs:staffs as any as UserProfile[],
|
staffs:staffs as any as UserProfile[],
|
||||||
staffsLoading,
|
staffsLoading,
|
||||||
depts:depts as any as Department[],
|
|
||||||
deptsLoading
|
|
||||||
}}>
|
}}>
|
||||||
{children}
|
{children}
|
||||||
</DailyContextProvider.Provider>
|
</DailyContextProvider.Provider>
|
||||||
|
|
|
@ -1,37 +1,14 @@
|
||||||
import { Button, DatePicker, Form, Modal, Select, 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,useEffect } from "react";
|
import { useState, useEffect, useMemo } from "react";
|
||||||
import { useDaily } from "./TrainPlanContext";
|
import { useDaily } from "./TrainPlanContext";
|
||||||
|
import DepartmentChildrenSelect from "../department/department-children-select";
|
||||||
|
import TrainContentTreeSelect from "../trainContent/train-content-tree-select";
|
||||||
export default function TrainPlanCreateForm() {
|
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 = [
|
|
||||||
{
|
|
||||||
title: 'Node1',
|
|
||||||
value: '0-0',
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
title: 'Child Node1',
|
|
||||||
value: '0-0-1',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Child Node2',
|
|
||||||
value: '0-0-2',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
title: 'Node2',
|
|
||||||
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()
|
||||||
|
@ -59,21 +36,10 @@ export default function TrainPlanCreateForm() {
|
||||||
<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="选择单位">
|
<Form.Item name="trainTime" label="选择单位">
|
||||||
<Select
|
<DepartmentChildrenSelect></DepartmentChildrenSelect>
|
||||||
placeholder="请选择单位"
|
|
||||||
optionFilterProp="label"
|
|
||||||
options={[]}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="trainType" label="选择学科">
|
<Form.Item name="trainType" label="选择学科">
|
||||||
<TreeSelect
|
<TrainContentTreeSelect></TrainContentTreeSelect>
|
||||||
style={{ width: '100%' }}
|
|
||||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
|
||||||
treeData={treeData}
|
|
||||||
placeholder="请选择学科或课程"
|
|
||||||
treeDefaultExpandAll={false}
|
|
||||||
//onChange={onChange}
|
|
||||||
/>
|
|
||||||
</Form.Item>
|
</Form.Item>
|
||||||
<Form.Item name="trainContent" label="填写内容">
|
<Form.Item name="trainContent" label="填写内容">
|
||||||
<TextArea rows={4} />
|
<TextArea rows={4} />
|
||||||
|
|
Loading…
Reference in New Issue