Commit 957f033f by zhaochengxiang

资产目录编号问题

parent 71f293f1
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState, useMemo } from 'react';
import { Modal, Form, Input, Space, Button, Radio, Select } from 'antd'; import { Modal, Form, Input, Space, Button, Radio, Select } from 'antd';
import { dispatch } from '../../../../model'; import { dispatch } from '../../../../model';
...@@ -38,6 +38,18 @@ const UpdateDirectoryModal = (props) => { ...@@ -38,6 +38,18 @@ const UpdateDirectoryModal = (props) => {
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, [ visible ]) }, [ visible ])
const codeRestrict = useMemo(() => {
if (action === 'add') {
if (isThemeAdd) return true;
return (dir && dir.level === 1) ? true : false;
} else {
return (dir && dir.level <= 2) ? true : false;
}
return false;
}, [action, dir, isThemeAdd])
const getDirectory = () => { const getDirectory = () => {
setDir(null); setDir(null);
dispatch({ dispatch({
...@@ -105,6 +117,7 @@ const UpdateDirectoryModal = (props) => { ...@@ -105,6 +117,7 @@ const UpdateDirectoryModal = (props) => {
payload: payload, payload: payload,
callback: data => { callback: data => {
setConfirmLoading(false); setConfirmLoading(false);
reset();
onCancel && onCancel(true, data?.id||''); onCancel && onCancel(true, data?.id||'');
}, },
error: () => { error: () => {
...@@ -117,6 +130,12 @@ const UpdateDirectoryModal = (props) => { ...@@ -117,6 +130,12 @@ const UpdateDirectoryModal = (props) => {
} }
} }
const reset = () => {
setIsThemeAdd(false);
setDir(undefined);
form.resetFields();
}
const onReset = () => { const onReset = () => {
if(action === 'add') { if(action === 'add') {
setIsThemeAdd(false); setIsThemeAdd(false);
...@@ -135,6 +154,9 @@ const UpdateDirectoryModal = (props) => { ...@@ -135,6 +154,9 @@ const UpdateDirectoryModal = (props) => {
if (action==='add') { if (action==='add') {
if (changedValues.type === 'theme') { if (changedValues.type === 'theme') {
setIsThemeAdd(true); setIsThemeAdd(true);
if (allValues.code?.length > 3) {
form.setFieldsValue({ code: '' });
}
} else if (changedValues.type === 'directory') { } else if (changedValues.type === 'directory') {
setIsThemeAdd(false); setIsThemeAdd(false);
} }
...@@ -158,12 +180,18 @@ const UpdateDirectoryModal = (props) => { ...@@ -158,12 +180,18 @@ const UpdateDirectoryModal = (props) => {
title={'资产目录信息'} title={'资产目录信息'}
visible={visible} visible={visible}
width={600} width={600}
onCancel={() => { onCancel && onCancel() }} onCancel={() => {
reset();
onCancel && onCancel();
}}
footer={ footer={
<Space> <Space>
<Button type="primary" onClick={onOk} loading={confirmLoading}>提交</Button> <Button type="primary" onClick={onOk} loading={confirmLoading}>提交</Button>
<Button onClick={onReset} >重置</Button> <Button onClick={onReset} >重置</Button>
<Button onClick={() => onCancel && onCancel() }>返回</Button> <Button onClick={() => {
reset();
onCancel && onCancel();
}}>返回</Button>
</Space> </Space>
} }
> >
...@@ -203,7 +231,7 @@ const UpdateDirectoryModal = (props) => { ...@@ -203,7 +231,7 @@ const UpdateDirectoryModal = (props) => {
name="code" name="code"
rules={[{ required: true, message: '必填项' }]} rules={[{ required: true, message: '必填项' }]}
> >
<Input placeholder="请输入编号" disabled={action!=='add'} /> <Input placeholder="请输入编号" disabled={action!=='add'} maxLength={codeRestrict?3:null} />
</Form.Item> </Form.Item>
<Form.Item <Form.Item
label="名称" label="名称"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment