Commit f200bd01 by zhaochengxiang

bug fix

parent 62ff8beb
...@@ -12,8 +12,10 @@ import { showMessage } from '../../../../util' ...@@ -12,8 +12,10 @@ import { showMessage } from '../../../../util'
const FC = (props) => { const FC = (props) => {
const { visible, type, item, onCancel} = props const { visible, type, item, onCancel} = props
const [loading, setLoading] = React.useState(false) const [loading, setLoading] = React.useState(false)
const [loadingUser, setLoadingUser] = React.useState(false)
const [waiting, setWaiting] = React.useState(false) const [waiting, setWaiting] = React.useState(false)
const [branch, setBranch] = React.useState() const [branch, setBranch] = React.useState()
const [user, setUser] = React.useState()
const basicRef = React.useRef() const basicRef = React.useRef()
...@@ -21,6 +23,10 @@ const FC = (props) => { ...@@ -21,6 +23,10 @@ const FC = (props) => {
if (visible && type === 'update') { if (visible && type === 'update') {
getBranch() getBranch()
} }
if (visible) {
getUser()
}
}, [visible, type]) }, [visible, type])
const title = React.useMemo(() => { const title = React.useMemo(() => {
...@@ -30,6 +36,20 @@ const FC = (props) => { ...@@ -30,6 +36,20 @@ const FC = (props) => {
return '' return ''
}, [type]) }, [type])
const getUser = () => {
setLoadingUser(true)
dispatch({
type: 'user.fetchSessionInfo',
callback: (data) => {
setLoadingUser(false)
setUser(data)
},
error: () => {
setLoadingUser(false)
}
})
}
const getBranch = () => { const getBranch = () => {
setLoading(true) setLoading(true)
dispatch({ dispatch({
...@@ -49,8 +69,10 @@ const FC = (props) => { ...@@ -49,8 +69,10 @@ const FC = (props) => {
const close = (val) => { const close = (val) => {
setLoading(false) setLoading(false)
setLoadingUser(false)
setWaiting(false) setWaiting(false)
setBranch() setBranch()
setUser()
onCancel?.(val) onCancel?.(val)
} }
...@@ -103,8 +125,8 @@ const FC = (props) => { ...@@ -103,8 +125,8 @@ const FC = (props) => {
centered destroyOnClose centered destroyOnClose
onCancel={() => { close() }} onCancel={() => { close() }}
> >
<Spin spinning={loading||waiting}> <Spin spinning={loading||loadingUser||waiting}>
<Basic ref={basicRef} type={type} item={branch} /> <Basic ref={basicRef} type={type} item={branch} user={user} />
</Spin> </Spin>
</Modal> </Modal>
) )
...@@ -112,22 +134,21 @@ const FC = (props) => { ...@@ -112,22 +134,21 @@ const FC = (props) => {
export default FC export default FC
const Basic = React.forwardRef(function ({ type, item }, ref) { const Basic = React.forwardRef(function ({ type, item, user }, ref) {
const [loadingUsers, setLoadingUsers] = React.useState(false) const [loadingUsers, setLoadingUsers] = React.useState(false)
const [users, setUsers] = React.useState() const [users, setUsers] = React.useState()
const [form] = Form.useForm() const [form] = Form.useForm()
const app = React.useContext(AppContext)
React.useImperativeHandle(ref, () => ({ React.useImperativeHandle(ref, () => ({
validate: async () => { validate: async () => {
let rows = await form.validateFields() let rows = await form.validateFields()
if (type === 'add') { if (type === 'add') {
let newMembers = [...rows.members??[]].filter(item => item.id !== app?.user?.userId) let newMembers = [...rows.members??[]].filter(item => item.id !== user?.userId)
newMembers = [ newMembers = [
{ {
admin: true, admin: true,
id: app?.user?.userId, id: user?.userId,
name: app?.user?.userName, name: user?.userName,
}, },
...(newMembers.map(item => ({ ...(newMembers.map(item => ({
admin: false, admin: false,
...@@ -157,7 +178,7 @@ const Basic = React.forwardRef(function ({ type, item }, ref) { ...@@ -157,7 +178,7 @@ const Basic = React.forwardRef(function ({ type, item }, ref) {
} }
return rows return rows
}, },
}), [form, type, users]) }), [form, type, user, users])
React.useEffect(() => { React.useEffect(() => {
getUsers() getUsers()
...@@ -231,7 +252,7 @@ const Basic = React.forwardRef(function ({ type, item }, ref) { ...@@ -231,7 +252,7 @@ const Basic = React.forwardRef(function ({ type, item }, ref) {
rules={[{ required: (type==='update'), message: '请选择项目负责人!' }]} rules={[{ required: (type==='update'), message: '请选择项目负责人!' }]}
> >
{ {
type === 'add' ? <span>{app?.user?.userName}</span> : <UsersItem loading={loadingUsers} users={users} /> type === 'add' ? <span>{user?.userName}</span> : <UsersItem loading={loadingUsers} users={users} />
} }
</Form.Item> </Form.Item>
<Form.Item <Form.Item
......
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