Commit f200bd01 by zhaochengxiang

bug fix

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