|
|
@@ -5,30 +5,23 @@ import MyPopconfirm from '@/components/MyPopconfirm'
|
|
|
import { useSelector } from 'react-redux'
|
|
|
import { RootState } from '@/store'
|
|
|
import { MessageFu } from '@/utils/message'
|
|
|
+import TextArea from 'antd/es/input/TextArea'
|
|
|
import { I2AddInfoType, TypeI2dict } from './data'
|
|
|
import { I2_APIgetInfo, I2_APIsave } from '@/store/action/Isystem/I2dict'
|
|
|
|
|
|
type Props = {
|
|
|
- acShuTxt: string
|
|
|
addInfo: I2AddInfoType
|
|
|
addFu: () => void
|
|
|
closeFu: () => void
|
|
|
- isNoAcIds: string[] //没有数据或者删除了的时候-既右侧没有操作的时候用到
|
|
|
}
|
|
|
|
|
|
-function I2add({ addInfo, addFu, closeFu, isNoAcIds, acShuTxt }: Props) {
|
|
|
- const { dictList: treeData } = useSelector((state: RootState) => state.I2dict)
|
|
|
+function I2add({ addInfo, addFu, closeFu }: Props) {
|
|
|
+ const treeData = useSelector((state: RootState) => state.I2dict.dictAll)
|
|
|
|
|
|
// 级联选择器改变的时候 筛选当前级联的 信息出来
|
|
|
const [acCardInfo, setAcCardInfo] = useState({} as TypeI2dict)
|
|
|
const [parentIdArr, setParentIdArr] = useState<string[] | null>(null)
|
|
|
|
|
|
- // useEffect(() => {
|
|
|
- // console.log(acCardInfo, parentIdArr)
|
|
|
- // }, [acCardInfo, parentIdArr])
|
|
|
-
|
|
|
- const saveIdsRef = useRef<string[]>([])
|
|
|
-
|
|
|
useEffect(() => {
|
|
|
setAcCardInfo(addInfo.acInfo)
|
|
|
|
|
|
@@ -41,12 +34,7 @@ function I2add({ addInfo, addFu, closeFu, isNoAcIds, acShuTxt }: Props) {
|
|
|
ids.pop()
|
|
|
}
|
|
|
|
|
|
- if (idsRes) {
|
|
|
- // 保存的时候需要补前面3个级别
|
|
|
- saveIdsRef.current = idsRes.filter((v, i) => i <= 2)
|
|
|
- // 去掉0和前2级
|
|
|
- idsRes = idsRes.filter((v, i) => i > 2)
|
|
|
- }
|
|
|
+ if (idsRes) idsRes = idsRes.filter((v, i) => v !== '0')
|
|
|
|
|
|
setParentIdArr(idsRes)
|
|
|
}, [addInfo.acInfo, addInfo.txt])
|
|
|
@@ -70,7 +58,7 @@ function I2add({ addInfo, addFu, closeFu, isNoAcIds, acShuTxt }: Props) {
|
|
|
if (addInfo.txt === '编辑') getInfoFu(addInfo.id)
|
|
|
else {
|
|
|
FormBoxRef.current?.setFieldsValue({
|
|
|
- sort: 50000
|
|
|
+ sort: 999
|
|
|
})
|
|
|
}
|
|
|
}, [addInfo.id, addInfo.txt, getInfoFu])
|
|
|
@@ -93,37 +81,32 @@ function I2add({ addInfo, addFu, closeFu, isNoAcIds, acShuTxt }: Props) {
|
|
|
return MessageFu.warning('最多支持五级!')
|
|
|
|
|
|
if (acCardInfo) parentId = addInfo.txt === '编辑' ? acCardInfo.parentId : acCardInfo.id
|
|
|
- if (parentIdArr && parentId) {
|
|
|
- let arrTemp = [...saveIdsRef.current, ...parentIdArr.filter(v => v !== addInfo.id)]
|
|
|
- ancestor = arrTemp.join(',')
|
|
|
- }
|
|
|
-
|
|
|
- // 新增并且没有父级
|
|
|
- if (addInfo.txt === '新增' && !parentId && !ancestor) {
|
|
|
- // console.log('xxx', saveIdsRef.current)
|
|
|
+ if (parentIdArr && parentId) ancestor = parentIdArr.filter(v => v !== addInfo.id).join(',')
|
|
|
|
|
|
- parentId = saveIdsRef.current[saveIdsRef.current.length - 1]
|
|
|
- ancestor = saveIdsRef.current.join(',')
|
|
|
- // console.log(123, parentId, ancestor)
|
|
|
+ let level = 1
|
|
|
+ if (parentIdArr) {
|
|
|
+ level = addInfo.txt === '新增' ? acCardInfo.level + 1 : acCardInfo.level
|
|
|
+ }
|
|
|
|
|
|
- // 外层没有选中
|
|
|
- if (!addInfo.acInfo.id) {
|
|
|
- parentId = isNoAcIds[isNoAcIds.length - 1]
|
|
|
- ancestor = isNoAcIds.join(',')
|
|
|
- }
|
|
|
+ // 补0
|
|
|
+ if (addInfo.id === '-1') {
|
|
|
+ // 新增
|
|
|
+ if (!parentId && !ancestor) {
|
|
|
+ ancestor = '0'
|
|
|
+ parentId = '0'
|
|
|
+ } else ancestor = '0,' + ancestor
|
|
|
+ } else {
|
|
|
+ // 编辑
|
|
|
+ if (!ancestor) ancestor = '0'
|
|
|
+ else ancestor = '0,' + ancestor
|
|
|
}
|
|
|
|
|
|
- // let level = 1
|
|
|
- // if (parentIdArr) {
|
|
|
- // level = addInfo.txt === '新增' ? acCardInfo.level + 1 : acCardInfo.level
|
|
|
- // }
|
|
|
const obj = {
|
|
|
...values,
|
|
|
- id: addInfo.txt === '编辑' ? addInfo.id : null,
|
|
|
+ id: addInfo.id === '-1' ? null : addInfo.id,
|
|
|
ancestor,
|
|
|
- // level,
|
|
|
- parentId,
|
|
|
- type: 'dict'
|
|
|
+ level,
|
|
|
+ parentId
|
|
|
}
|
|
|
// console.log(123, obj)
|
|
|
// if (1 + 1 === 2) {
|
|
|
@@ -138,8 +121,9 @@ function I2add({ addInfo, addFu, closeFu, isNoAcIds, acShuTxt }: Props) {
|
|
|
closeFu()
|
|
|
}
|
|
|
},
|
|
|
- [acCardInfo, addFu, addInfo.acInfo.id, addInfo.id, addInfo.txt, closeFu, isNoAcIds, parentIdArr]
|
|
|
+ [acCardInfo, addFu, addInfo.id, addInfo.txt, closeFu, parentIdArr]
|
|
|
)
|
|
|
+
|
|
|
return (
|
|
|
<Modal
|
|
|
wrapClassName={styles.I2add}
|
|
|
@@ -160,7 +144,7 @@ function I2add({ addInfo, addFu, closeFu, isNoAcIds, acShuTxt }: Props) {
|
|
|
autoComplete='off'
|
|
|
>
|
|
|
<div className='fromRow'>
|
|
|
- <div className='fromRowll'>上级字典:</div>
|
|
|
+ <div className='fromRowll'>上级名称:</div>
|
|
|
<div className='fromRowrr'>
|
|
|
<Cascader
|
|
|
style={{ width: 658 }}
|
|
|
@@ -168,8 +152,7 @@ function I2add({ addInfo, addFu, closeFu, isNoAcIds, acShuTxt }: Props) {
|
|
|
changeOnSelect
|
|
|
fieldNames={{ label: 'name', value: 'id', children: 'children' }}
|
|
|
options={treeData}
|
|
|
- // placeholder={addInfo.txt === '编辑' ? '空' : '请选择'}
|
|
|
- placeholder={acShuTxt}
|
|
|
+ placeholder={addInfo.txt === '编辑' ? '空' : '请选择'}
|
|
|
value={parentIdArr ? [...parentIdArr] : []}
|
|
|
onChange={cardChange}
|
|
|
/>
|
|
|
@@ -177,12 +160,16 @@ function I2add({ addInfo, addFu, closeFu, isNoAcIds, acShuTxt }: Props) {
|
|
|
</div>
|
|
|
|
|
|
<Form.Item
|
|
|
- label='字典值'
|
|
|
+ label='字典名称'
|
|
|
name='name'
|
|
|
- rules={[{ required: true, message: '请输入字典值!' }]}
|
|
|
+ rules={[{ required: true, message: '请输入字典名称' }]}
|
|
|
getValueFromEvent={e => e.target.value.replace(/\s+/g, '')}
|
|
|
>
|
|
|
- <Input maxLength={30} showCount placeholder='请输入内容' />
|
|
|
+ <Input maxLength={20} showCount placeholder='请输入内容' />
|
|
|
+ </Form.Item>
|
|
|
+
|
|
|
+ <Form.Item label='说明' name='intro'>
|
|
|
+ <TextArea maxLength={500} showCount placeholder='请输入内容' />
|
|
|
</Form.Item>
|
|
|
|
|
|
<div className='fromRow2'>
|
|
|
@@ -191,10 +178,10 @@ function I2add({ addInfo, addFu, closeFu, isNoAcIds, acShuTxt }: Props) {
|
|
|
name='sort'
|
|
|
rules={[{ required: true, message: '请输入排序值!' }]}
|
|
|
>
|
|
|
- <InputNumber min={1} max={50000} precision={0} placeholder='请输入' />
|
|
|
+ <InputNumber min={1} max={999} precision={0} placeholder='请输入' />
|
|
|
</Form.Item>
|
|
|
<div className='fromRowTit'>
|
|
|
- 请输入1~50000的数字。数字越小,排序越靠前。数字相同时,更新发布的内容排在前面
|
|
|
+ 请输入1~999的数字。数字越小,排序越靠前。数字相同时,更新发布的内容排在前面
|
|
|
</div>
|
|
|
</div>
|
|
|
|