Commit 03daa012 by zhaochengxiang

权限共享

parent 97e4c4b3
...@@ -135,7 +135,7 @@ const ModelNameColumn = (props) => { ...@@ -135,7 +135,7 @@ const ModelNameColumn = (props) => {
} }
const ModelTable = (props) => { const ModelTable = (props) => {
const { data, onChange, onItemAction, onSelect, onHistory, catalogId, keyword, onAutoCreateTable, offset = null, view, modelState, user, selectModelerIds, visibleColNames, tagSelectOptions, batchAddTagChange, onMerge, onAuthTransfer } = props; const { data, onChange, onItemAction, onSelect, onHistory, catalogId, keyword, onAutoCreateTable, offset = null, view, modelState, user, selectModelerIds, visibleColNames, tagSelectOptions, batchAddTagChange, onMerge, onAuthTransfer, onAuthShare } = props;
const [ selectedRowKeys, setSelectedRowKeys ] = useState([]); const [ selectedRowKeys, setSelectedRowKeys ] = useState([]);
const [ expandedSelectedRowKeys, setExpandedSelectedRowKeys ] = useState([]); const [ expandedSelectedRowKeys, setExpandedSelectedRowKeys ] = useState([]);
...@@ -584,11 +584,11 @@ const ModelTable = (props) => { ...@@ -584,11 +584,11 @@ const ModelTable = (props) => {
const action = currentItem?.state?.supportedActions[index]; const action = currentItem?.state?.supportedActions[index];
stateAction(currentItem, action); stateAction(currentItem, action);
} else if (key === 'join') { } else if (key === 'join') {
onMerge(currentItem); onMerge?.(currentItem);
} else if (key === 'auth-transfer') { } else if (key === 'auth-transfer') {
onAuthTransfer(currentItem) onAuthTransfer?.(currentItem)
} else if (key === 'auth-share') { } else if (key === 'auth-share') {
onAuthShare?.(currentItem)
} }
} }
......
import React from "react"
import { Modal, Button, Spin, Form, Select } from "antd"
import produce from "immer"
import { useDebounceEffect } from "ahooks"
import { dispatch } from '../../../../model'
import { UsersItem } from "./update-branch"
const FC = (props) => {
const { item, visible, onCancel } = props
const [loading, setLoading] = React.useState(false)
const [waiting, setWaiting] = React.useState(false)
const [cooperators, setCooperators] = React.useState()
const basicRef = React.useRef()
React.useEffect(() => {
if (visible && item?.id) {
getCooperators()
}
}, [visible, item])
const getCooperators = () => {
setLoading(true)
dispatch({
type: 'datamodel.getCooperators',
payload: {
id: item?.id
},
callback: (data) => {
setLoading(false)
setCooperators(data)
},
error: () => {
setLoading(false)
}
})
}
const close = (refresh = false) => {
setLoading(false)
setWaiting(false)
setCooperators()
onCancel?.(refresh)
}
const save = async () => {
try {
const rows = await basicRef.current.validate()
setWaiting(true)
dispatch({
type: 'datamodel.setCooperators',
payload: {
params: {
id: item?.id,
},
data: rows.cooperators,
},
callback: (data) => {
setWaiting(false)
close(true)
},
error: () => {
setWaiting(false)
}
})
} catch (errInfo) {
console.log('Validate Failed:', errInfo);
}
}
const footer = React.useMemo(() => {
return [
<Button key={'cancel'}
onClick={() => close()}
>取消</Button>,
<Button key={'save'} type='primary'
disabled={waiting}
onClick={() => save()}
>确定</Button>
]
}, [close, save, waiting])
return (
<Modal
visible={visible}
footer={footer}
width='800px'
bodyStyle={{ padding: '15px', overflowX: 'auto', maxHeight: '80vh' }}
title='权限共享'
centered destroyOnClose
onCancel={() => { close() }}
>
<Spin spinning={waiting}>
<Basic ref={basicRef} cooperators={cooperators} />
</Spin>
</Modal>
)
}
export default FC
export const Basic = React.forwardRef(function ({ cooperators }, ref) {
const [loading, setLoading] = React.useState(false)
const [users, setUsers] = React.useState()
const [form] = Form.useForm()
React.useImperativeHandle(ref, () => ({
validate: async () => {
return await form.validateFields()
},
}), [form])
React.useEffect(() => {
getUsers()
}, [])
React.useEffect(() => {
if ((cooperators??[]).length>0) {
form.setFieldsValue({ cooperators })
}
}, [cooperators])
const getUsers = () => {
setLoading(true)
dispatch({
type: 'datamodel.getCooperationUsers',
callback: data => {
setLoading(false)
//id int转string
const newData = produce(data??[], (draft) => {
draft.forEach(item => {
item.id = `${item.id}`
})
})
setUsers(newData)
},
error: () => {
setLoading(false)
}
})
}
return (
<Form
form={form}
labelCol={{ span: 3 }}
wrapperCol={{ span: 21 }}
autoComplete="off"
>
<Form.Item
name='cooperators'
label='选择用户'
extra="权限共享后,您与共享用户均可编辑该模型"
rules={[{ required: true, message: '请选择用户'}]}
>
<UsersItem loading={loading} users={users} />
</Form.Item>
</Form>
)
})
...@@ -178,6 +178,7 @@ const UsersItem = ({ loading, users, value, onChange }) => { ...@@ -178,6 +178,7 @@ const UsersItem = ({ loading, users, value, onChange }) => {
return ( return (
<Select loading={loading} searchValue allowClear <Select loading={loading} searchValue allowClear
placeholder='请选择用户'
value={value?.id} value={value?.id}
searchValue={searchValue} searchValue={searchValue}
onSearch={(val) => { onSearch={(val) => {
......
...@@ -247,7 +247,7 @@ const Basic = React.forwardRef(function ({ type, item }, ref) { ...@@ -247,7 +247,7 @@ const Basic = React.forwardRef(function ({ type, item }, ref) {
) )
}) })
const UsersItem = ({ loading, users, value, onChange }) => { export const UsersItem = ({ loading, users, value, onChange }) => {
const [searchValue, setSearchValue] = React.useState() const [searchValue, setSearchValue] = React.useState()
const [options, setOptions] = React.useState() const [options, setOptions] = React.useState()
...@@ -264,6 +264,7 @@ const UsersItem = ({ loading, users, value, onChange }) => { ...@@ -264,6 +264,7 @@ const UsersItem = ({ loading, users, value, onChange }) => {
return ( return (
<Select loading={loading} mode='multiple' allowClear <Select loading={loading} mode='multiple' allowClear
placeholder='请选择用户'
value={value?.map(item => item.id)} value={value?.map(item => item.id)}
searchValue={searchValue} searchValue={searchValue}
onSearch={(val) => { onSearch={(val) => {
......
...@@ -26,6 +26,7 @@ import BranchAddModel from './Component/branch-add-model' ...@@ -26,6 +26,7 @@ import BranchAddModel from './Component/branch-add-model'
import StartFlow from './Component/start-flow' import StartFlow from './Component/start-flow'
import MergeToMaster from './Component/merge-to-master'; import MergeToMaster from './Component/merge-to-master';
import AuthTransfer from './Component/auth-transfer'; import AuthTransfer from './Component/auth-transfer';
import AuthShare from './Component/auth-share';
import './index.less'; import './index.less';
...@@ -95,6 +96,10 @@ class Model extends React.Component { ...@@ -95,6 +96,10 @@ class Model extends React.Component {
visible: false, visible: false,
item: undefined, item: undefined,
}, },
authShareParams: {
visible: false,
item: undefined,
},
} }
} }
...@@ -366,6 +371,17 @@ class Model extends React.Component { ...@@ -366,6 +371,17 @@ class Model extends React.Component {
} }
} }
onAuthShare = (item) => {
if (item) {
this.setState({
authShareParams: {
visible: true,
item,
}
})
}
}
onSearchInputChange = (value) => { onSearchInputChange = (value) => {
const { currentView } = this.state; const { currentView } = this.state;
if (currentView === 'branch') { if (currentView === 'branch') {
...@@ -827,6 +843,7 @@ class Model extends React.Component { ...@@ -827,6 +843,7 @@ class Model extends React.Component {
onHistory={this.onHistory} onHistory={this.onHistory}
onMerge={this.onMerge} onMerge={this.onMerge}
onAuthTransfer={this.onAuthTransfer} onAuthTransfer={this.onAuthTransfer}
onAuthShare={this.onAuthShare}
{...this.props} /> {...this.props} />
</Spin> </Spin>
</div> </div>
...@@ -940,6 +957,22 @@ class Model extends React.Component { ...@@ -940,6 +957,22 @@ class Model extends React.Component {
}} }}
/> />
<AuthShare
{...this.state.authShareParams}
onCancel={(refresh) => {
this.setState({
authShareParams: {
visible: false,
item: undefined
}
})
if (refresh) {
this.onTableChange()
}
}}
/>
<MergeToMaster <MergeToMaster
{...this.state.mergeToMasterParams} {...this.state.mergeToMasterParams}
branchId={this.state.catalogId} branchId={this.state.catalogId}
......
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