|
|
@@ -1,4 +1,4 @@
|
|
|
-import React, { useCallback, useEffect, useMemo, useState } from 'react'
|
|
|
+import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react'
|
|
|
import styles from './index.module.scss'
|
|
|
import { Button, Input, Tree, TreeDataNode } from 'antd'
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
|
|
@@ -7,23 +7,44 @@ import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
import { MessageFu } from '@/utils/message'
|
|
|
import { I5_APIdel, I5_APIgetTree, I5_APIgetUserById } from '@/store/action/Isystem/I5organization'
|
|
|
import { I5AddInfoType, TypeI5Tree, TypeI5UserList } from './data'
|
|
|
-import { treeResIdFu } from '../I2dict/data'
|
|
|
+import { filterTreeByName, treeResIdFu } from '../I2dict/data'
|
|
|
import I5add from './I5add'
|
|
|
function I5organization() {
|
|
|
const dispatch = useDispatch()
|
|
|
|
|
|
const [loding, setLoding] = useState(false)
|
|
|
|
|
|
+ const getInfoFu = useCallback(
|
|
|
+ (flag: boolean) => {
|
|
|
+ dispatch(
|
|
|
+ I5_APIgetTree(data => {
|
|
|
+ setLoding(true)
|
|
|
+
|
|
|
+ if (flag && data && data.length) setAcShu(data[0].id)
|
|
|
+ })
|
|
|
+ )
|
|
|
+ },
|
|
|
+ [dispatch]
|
|
|
+ )
|
|
|
+
|
|
|
useEffect(() => {
|
|
|
- dispatch(
|
|
|
- I5_APIgetTree(data => {
|
|
|
- setLoding(true)
|
|
|
- if (data && data.length) setAcShu(data[0].id)
|
|
|
- })
|
|
|
- )
|
|
|
- }, [dispatch])
|
|
|
+ getInfoFu(true)
|
|
|
+ }, [getInfoFu])
|
|
|
+
|
|
|
+ const { treeData: dictAll } = useSelector((state: RootState) => state.I5organization)
|
|
|
+
|
|
|
+ // 点击重置
|
|
|
+ const resetFu = useCallback(
|
|
|
+ (flag: boolean) => {
|
|
|
+ // 重置 flag为true
|
|
|
+ // 新增和编辑 为false
|
|
|
+ getInfoFu(flag)
|
|
|
|
|
|
- const { treeData: treeDataTemp } = useSelector((state: RootState) => state.I5organization)
|
|
|
+ setValue('')
|
|
|
+ setValue2('')
|
|
|
+ },
|
|
|
+ [getInfoFu]
|
|
|
+ )
|
|
|
|
|
|
// 当前选中的树节点ID
|
|
|
const [acShu, setAcShu] = useState('')
|
|
|
@@ -49,6 +70,23 @@ function I5organization() {
|
|
|
|
|
|
// 搜索高亮
|
|
|
const [value, setValue] = useState('')
|
|
|
+ const [value2, setValue2] = useState('')
|
|
|
+
|
|
|
+ const timeRef = useRef(-1)
|
|
|
+ const valueChange = useCallback((val: string) => {
|
|
|
+ setValue(val.trim())
|
|
|
+ clearTimeout(timeRef.current)
|
|
|
+ timeRef.current = window.setTimeout(() => {
|
|
|
+ setValue2(val.trim())
|
|
|
+ }, 500)
|
|
|
+ }, [])
|
|
|
+
|
|
|
+ // value变化的时候获取所有dom 设置隐藏
|
|
|
+ const treeDataTemp = useMemo(() => {
|
|
|
+ if (value2) {
|
|
|
+ return filterTreeByName(dictAll, value2)
|
|
|
+ } else return dictAll
|
|
|
+ }, [dictAll, value2])
|
|
|
|
|
|
const treeData = useMemo(() => {
|
|
|
const loop = (dataTemp: any[]): TreeDataNode[] => {
|
|
|
@@ -57,7 +95,10 @@ function I5organization() {
|
|
|
return data.map(item => {
|
|
|
const strTitle = ((item.num ? item.num + ' ' : '') + item.name) as string
|
|
|
|
|
|
- const index = strTitle.indexOf(value)
|
|
|
+ const strTitleD = strTitle.toUpperCase()
|
|
|
+
|
|
|
+ const valueD = value.toUpperCase()
|
|
|
+ const index = strTitleD.indexOf(valueD)
|
|
|
|
|
|
const beforeStr = strTitle.substring(0, index)
|
|
|
const afterStr = strTitle.slice(index + value.length)
|
|
|
@@ -99,10 +140,10 @@ function I5organization() {
|
|
|
const res = await I5_APIdel(id)
|
|
|
if (res.code === 0) {
|
|
|
MessageFu.success('删除成功!')
|
|
|
- dispatch(I5_APIgetTree())
|
|
|
+ resetFu(true)
|
|
|
}
|
|
|
},
|
|
|
- [dispatch]
|
|
|
+ [resetFu]
|
|
|
)
|
|
|
|
|
|
// 点击新增和编辑
|
|
|
@@ -123,7 +164,15 @@ function I5organization() {
|
|
|
<div className={styles.I5organization}>
|
|
|
<div className='pageTitle'>组织管理</div>
|
|
|
<div className='I5top'>
|
|
|
- <Input value={value} onChange={e => setValue(e.target.value)} hidden />
|
|
|
+ <Input
|
|
|
+ style={{ width: 300 }}
|
|
|
+ placeholder='请输入部门名称'
|
|
|
+ maxLength={30}
|
|
|
+ showCount
|
|
|
+ value={value}
|
|
|
+ onChange={e => valueChange(e.target.value)}
|
|
|
+ allowClear
|
|
|
+ />
|
|
|
<Button
|
|
|
type='primary'
|
|
|
onClick={() => setAddInfo({ id: '-1', txt: '新增', acInfo: rightData })}
|
|
|
@@ -216,7 +265,7 @@ function I5organization() {
|
|
|
{addInfo.id ? (
|
|
|
<I5add
|
|
|
addInfo={addInfo}
|
|
|
- addFu={() => dispatch(I5_APIgetTree())}
|
|
|
+ addFu={() => resetFu(false)}
|
|
|
closeFu={() => setAddInfo({} as I5AddInfoType)}
|
|
|
/>
|
|
|
) : null}
|