RHT
This commit is contained in:
parent
7287a36bdc
commit
4a1bbfb26e
|
@ -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 { 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";
|
||||
|
||||
interface DailyContextProviderProps{
|
||||
staffs:UserProfile[],
|
||||
staffsLoading:boolean,
|
||||
depts:Department[],
|
||||
deptsLoading:boolean
|
||||
}
|
||||
|
||||
interface DailyContextProps{
|
||||
|
@ -23,18 +21,9 @@ export default function DailyContext({children}:DailyContextProps){
|
|||
deptId:user.deptId
|
||||
}):{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={{
|
||||
staffs:staffs as any as UserProfile[],
|
||||
staffsLoading,
|
||||
depts:depts as any as Department[],
|
||||
deptsLoading
|
||||
}}>
|
||||
{children}
|
||||
</DailyContextProvider.Provider>
|
||||
|
|
|
@ -1,37 +1,14 @@
|
|||
import { Button, DatePicker, Form, Modal, Select, TimePicker, TreeSelect } from "antd";
|
||||
import TextArea from "antd/es/input/TextArea";
|
||||
import dayjs from "dayjs";
|
||||
import { useState,useEffect } from "react";
|
||||
import { useState, useEffect, useMemo } from "react";
|
||||
import { useDaily } from "./TrainPlanContext";
|
||||
import DepartmentChildrenSelect from "../department/department-children-select";
|
||||
import TrainContentTreeSelect from "../trainContent/train-content-tree-select";
|
||||
export default function TrainPlanCreateForm() {
|
||||
const [form] = Form.useForm()
|
||||
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 = () => {
|
||||
//console.log(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%' }} />
|
||||
</Form.Item>
|
||||
<Form.Item name="trainTime" label="选择单位">
|
||||
<Select
|
||||
placeholder="请选择单位"
|
||||
optionFilterProp="label"
|
||||
options={[]}
|
||||
/>
|
||||
<DepartmentChildrenSelect></DepartmentChildrenSelect>
|
||||
</Form.Item>
|
||||
<Form.Item name="trainType" label="选择学科">
|
||||
<TreeSelect
|
||||
style={{ width: '100%' }}
|
||||
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
|
||||
treeData={treeData}
|
||||
placeholder="请选择学科或课程"
|
||||
treeDefaultExpandAll={false}
|
||||
//onChange={onChange}
|
||||
/>
|
||||
<TrainContentTreeSelect></TrainContentTreeSelect>
|
||||
</Form.Item>
|
||||
<Form.Item name="trainContent" label="填写内容">
|
||||
<TextArea rows={4} />
|
||||
|
|
Loading…
Reference in New Issue