Commit 80906d50 by zhaochengxiang

新增项目

parent e7fb8f33
...@@ -614,4 +614,8 @@ export function* saveBranch(payload) { ...@@ -614,4 +614,8 @@ export function* saveBranch(payload) {
export function* deleteBranch(payload) { export function* deleteBranch(payload) {
return yield call(datamodelerService.deleteBranch, payload) return yield call(datamodelerService.deleteBranch, payload)
}
export function* getCooperationUsers() {
return yield call(datamodelerService.getCooperationUsers)
} }
\ No newline at end of file
...@@ -561,4 +561,8 @@ export function saveBranch(payload) { ...@@ -561,4 +561,8 @@ export function saveBranch(payload) {
export function deleteBranch(payload) { export function deleteBranch(payload) {
return Delete1("/datamodeler/easyDataModelerBranching/deleteBranch", payload) return Delete1("/datamodeler/easyDataModelerBranching/deleteBranch", payload)
}
export function getCooperationUsers() {
return GetJSON("/datamodeler/easyDataModelerCooperation/users")
} }
\ No newline at end of file
import React from 'react' import React from 'react'
import { Modal, Button, Spin } from 'antd' import { Modal, Button, Spin, Form, Input, Select, } from 'antd'
import { useDebounceEffect } from 'ahooks'
import { SettingOutlined } from '@ant-design/icons'
import { dispatch } from '../../../../model'
import { AppContext } from '../../../../App'
import produce from 'immer'
const FC = (props) => { const FC = (props) => {
const { visible, type, item, onCancel} = props const { visible, type, item, onCancel} = props
const [waiting, setWaiting] = React.useState(false) const [waiting, setWaiting] = React.useState(false)
const basicRef = React.useRef()
const title = React.useMemo(() => { const title = React.useMemo(() => {
if (type === 'add') return '新增项目' if (type === 'add') return '新增项目'
if (type === 'edit') return '编辑项目' if (type === 'edit') return '编辑项目'
...@@ -19,7 +27,24 @@ const FC = (props) => { ...@@ -19,7 +27,24 @@ const FC = (props) => {
const save = async () => { const save = async () => {
try { try {
const basicRows = await basicRef.current?.validate()
setWaiting(true)
console.log('basic rows', basicRows)
if (type === 'add') {
dispatch({
type: 'datamodel.saveBranch',
payload: {
data: basicRows,
},
callback: () => {
close(true)
},
error: () => {
setWaiting(false)
}
})
}
} catch (e) { } catch (e) {
} }
...@@ -48,10 +73,163 @@ const FC = (props) => { ...@@ -48,10 +73,163 @@ const FC = (props) => {
onCancel={() => { close() }} onCancel={() => { close() }}
> >
<Spin spinning={waiting}> <Spin spinning={waiting}>
<Basic ref={basicRef} type={type} item={item} />
</Spin> </Spin>
</Modal> </Modal>
) )
} }
export default FC export default FC
\ No newline at end of file
const Basic = React.forwardRef(function ({ type, item }, 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') {
rows = {...rows, easyDataModelerMemberShip: {
easyDataModelerMemberShip: [
{
admin: true,
id: app?.user?.userId,
name: app?.user?.userName,
},
...(rows.members??[]).map(item => ({
admin: false,
...item,
}))
]
}}
}
return rows
},
}), [form, type, users])
React.useEffect(() => {
getUsers()
}, [])
const marginBottom = React.useMemo(() => {
return (type === 'detail') ? 5 : 15
}, [type])
const getUsers = () => {
setLoadingUsers(true)
dispatch({
type: 'datamodel.getCooperationUsers',
callback: data => {
setLoadingUsers(false)
//id int转string
const newData = produce(data??[], (draft) => {
draft.forEach(item => {
item.id = `${item.id}`
})
})
setUsers(newData)
},
error: () => {
setLoadingUsers(false)
}
})
}
const onValuesChange = (changedValues, allValues) => {
}
return (
<Form
form={form}
labelCol={{ span: 6 }}
wrapperCol={{ span: 18 }}
autoComplete="off"
onValuesChange={onValuesChange}
>
<Form.Item
label='项目名称'
name='name'
rules={[{ required: true, message: '请输入项目名称!' }]}
style={{ marginBottom }}
>
<Input placeholder="请输入项目名称" />
</Form.Item>
<Form.Item
label='项目说明'
name='remark'
style={{ marginBottom }}
>
<Input placeholder="请输入项目说明" />
</Form.Item>
<Form.Item
label='项目负责人'
name='admins'
style={{ marginBottom }}
>
{
type === 'add' ? <span>{app?.user?.userName}</span> : <UsersItem loading={loadingUsers} users={users} />
}
</Form.Item>
<Form.Item
label='项目成员'
name='members'
style={{ marginBottom }}
rules={[{ required: true, message: '请选择项目成员!' }]}
>
<UsersItem loading={loadingUsers} users={users} />
</Form.Item>
<Form.Item
label='模型设置'
style={{ marginBottom }}
>
<ModelConfigItem />
</Form.Item>
</Form>
)
})
const UsersItem = ({ loading, users, value, onChange }) => {
const [searchValue, setSearchValue] = React.useState()
const [options, setOptions] = React.useState()
useDebounceEffect(() => {
setOptions(
(users??[])
.filter(item => !searchValue || (item.name??'').indexOf(searchValue)!==-1)
.map(item => ({
label: item.name,
value: item.id,
}))
)
}, [searchValue, users], { wait: 300 })
return (
<Select loading={loading} mode='multiple' allowClear
searchValue={searchValue}
onSearch={(val) => {
setSearchValue(val)
}}
onClear={() => {
setSearchValue()
}}
filterOption={false}
options={options}
onChange={(val) => {
onChange?.((users??[]).filter(item => (val??[]).indexOf(item.id) !== -1))
}}
/>
)
}
const ModelConfigItem = () => {
const onConfigClick = () => {
}
return (
<Button icon={<SettingOutlined />} onClick={onConfigClick} />
)
}
\ No newline at end of file
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