Commit 70221c38 by zhaochengxiang

操作优化

parent 5f903da3
import React, { useState, useEffect, useRef, useContext, useMemo } from "react"; import React, { useState, useEffect, useRef, useContext, useMemo } from "react";
import { Tooltip, Modal, Pagination, Typography } from 'antd'; import { Tooltip, Modal, Pagination, Typography, Space, Menu, Dropdown, Row, Col, Divider } from 'antd';
import { DownOutlined, UpOutlined } from '@ant-design/icons'; import { DownOutlined, UpOutlined, UnorderedListOutlined } from '@ant-design/icons';
import copy from "copy-to-clipboard";
import SmoothScroll from 'smooth-scroll'; import SmoothScroll from 'smooth-scroll';
import classnames from 'classnames'; import classnames from 'classnames';
import { Resizable } from 'react-resizable'; import { Resizable } from 'react-resizable';
...@@ -23,6 +24,19 @@ import 'react-contexify/dist/ReactContexify.css'; ...@@ -23,6 +24,19 @@ import 'react-contexify/dist/ReactContexify.css';
const { Text } = Typography; const { Text } = Typography;
const { Column } = Table; const { Column } = Table;
const actions = [
{ title: '编辑', key: 'edit' },
{ title: '删除', key: 'delete' },
{ title: 'URI复制', key: 'copyUri' },
{ title: '样本数据', key: 'sample' },
{ title: '历史版本', key: 'history' },
{ title: '授权', key: 'admit' },
{ title: '申请', key: 'startFlow' },
{ title: '下载Tableau tds', key: 'downloadTds' },
{ title: '跳转至电子表格', key: 'smart' },
{ title: '更换管理人', key: 'exchangeOwner' },
]
const ModelNameColumn = (props) => { const ModelNameColumn = (props) => {
const { text, record, detailItem } = props; const { text, record, detailItem } = props;
const [ data, setData ] = useState(record); const [ data, setData ] = useState(record);
...@@ -308,6 +322,93 @@ const ModelTable = (props) => { ...@@ -308,6 +322,93 @@ const ModelTable = (props) => {
); );
} }
}, },
{
title: '操作',
dataIndex: 'action',
width: 240,
fixed: 'right',
render: (_, record) => {
const authActionTitles = [];
if ((getDataModelerRole(user)!==DataModelerRoleReader) && view!=='grant' && !isOnlyEnding && (record.editable||record.permitCheckOut)) {
authActionTitles.push('编辑');
}
if ((getDataModelerRole(user)!==DataModelerRoleReader) && view!=='grant'&& !isOnlyEnding && record.deletable) {
authActionTitles.push('删除');
}
if (record.odata) {
authActionTitles.push('URI复制');
}
authActionTitles.push('样本数据');
authActionTitles.push('历史版本');
if (getDataModelerRole(user)!==DataModelerRoleReader&& view!=='grant'&&record.grantable) {
authActionTitles.push('授权');
}
if (getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && isOnlyEnding && !currentItem?.grantable) {
authActionTitles.push('申请');
}
if (getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && !isOnlyEnding && record.supportODataDisable) {
authActionTitles.push('下载Tableau tds');
}
if (getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && record.supportSmartBIWebSpreadSheet) {
authActionTitles.push('跳转至电子表格');
}
if (getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && record.supportChangeOwn) {
authActionTitles.push('更换管理人');
}
const authActions = actions.filter(item => authActionTitles.indexOf(item.title) !== -1);
const haveMore = authActions.length > 3;
const showActions = authActions.slice(0, 3);
const hiddenActions = authActions.slice(3, authActions.length);
console.log('hiddenActions', hiddenActions);
return (
<Row gutter={20}>
{
showActions.map((item, index) => {
return (
<Col key={index} span={6}>
<a onClick={() => {handleItemClick(item.key, record)}} >{item.title}</a>
</Col>
)
})
}
{
haveMore ? <Dropdown overlay={
<Menu onClick={({ key }) => {
handleItemClick(key, record);
}}>
{
hiddenActions.map((item, index) => {
return (
<Menu.Item key={index} value={item.key} >
<div style={{ textAlign: 'center' }}>
{item.title}
</div>
</Menu.Item>
)
})
}
</Menu>
}
placement="bottomLeft"
>
<Col span={4}>
<UnorderedListOutlined className='default' style={{ fontSize:16,cursor:'pointer', marginLeft: 10 }} />
</Col>
</Dropdown> : <Col span={4} />
}
</Row>
)
}
}
]; ];
// const [ columns, setColumns ] = useState([]); // const [ columns, setColumns ] = useState([]);
...@@ -423,17 +524,92 @@ const ModelTable = (props) => { ...@@ -423,17 +524,92 @@ const ModelTable = (props) => {
//eslint-disable-next-line react-hooks/exhaustive-deps //eslint-disable-next-line react-hooks/exhaustive-deps
}, [data, pagination, sortRule]) }, [data, pagination, sortRule])
const handleItemClick = (id, record) => {
if (id === 'edit') {
if (record?.editable) {
editItem(record);
} else if (record?.permitCheckOut) {
dispatch({
type: 'pds.checkoutService',
payload: {
params: {
id: record?.id
}
},
callback: data => {
onChange && onChange();
editItem(data);
}
})
}
} else if (id === 'delete') {
deleteItem(record);
} else if (id === 'sample') {
setSampleParams({visible: true, service: record})
} else if (id === 'history') {
historyItem(record);
} else if (id === 'copy') {
window.open(`/data-govern/data-model-action?${Action}=add&${CatalogId}=${(view==='dir')?(catalogId||''):''}&${ModelerId}=${record.id}`);
} else if (id === 'createTable') {
deployAction(record);
} else if (id.indexOf('action') !== -1) {
const index = (id.split('-'))[1];
const action = record?.state?.supportedActions[index];
stateAction(record, action);
} else if (id === 'admit') {
app.openAdmit?.({ dirId: catalogId, service: record })
} else if (id === 'enableOData') {
startODataItem(record);
} else if (id === 'disableOData') {
disableODataItem(record);
} else if (id === 'startFlow') {
app.applyServer?.({ service: record });
} else if (id === 'downloadTds') {
window.open(`/api/pdataservice/pdsCURD/genTDS?id=${record?.id}`);
} else if (id === 'checkout') {
dispatch({
type: 'pds.checkoutService',
payload: {
params: {
id: record?.id
}
},
callback: () => {
showMessage('success', '检出成功');
onChange && onChange();
}
})
} else if (id === 'smart') {
dispatch({
type: 'pds.getSmartBiUrl',
payload: {
url: record?.smartBiWebSpreadSheetEntry
},
callback: (data) => {
window.open(data)
}
})
} else if (id === 'exchangeOwner') {
setExchangeOwnerParams({ visible: true, id: record?.id });
} else if (id === 'offline') {
offlineService(record);
} else if (id === 'copyUri') {
copy(record.odata);
showMessage('success', 'URI复制成功');
}
}
const columns = useMemo(() => { const columns = useMemo(() => {
let newCols = [...cols]; let newCols = [...cols];
if ((visibleColNames||[]).length > 0) { if ((visibleColNames||[]).length > 0) {
newCols = newCols.filter(col => visibleColNames.indexOf(col.title)!==-1 || col.title==='序号'); newCols = newCols.filter(col => visibleColNames.indexOf(col.title)!==-1 || col.title==='序号' || col.title==='操作');
} }
if (modelId) { if (modelId) {
newCols.filter(col => col.title !=='序号'); newCols.filter(col => col.title !=='序号');
} }
return newCols; return newCols;
}, [visibleColNames, modelId]) }, [visibleColNames, modelId, handleItemClick, view, user, isOnlyEnding])
const modelEventChange = (e) => { const modelEventChange = (e) => {
if (e.key === 'modelChange') { if (e.key === 'modelChange') {
...@@ -709,78 +885,6 @@ const ModelTable = (props) => { ...@@ -709,78 +885,6 @@ const ModelTable = (props) => {
}) })
} }
const handleItemClick = ({ id, event, props }) => {
if (id === 'edit') {
if (currentItem?.editable) {
editItem(currentItem);
} else if (currentItem?.permitCheckOut) {
dispatch({
type: 'pds.checkoutService',
payload: {
params: {
id: currentItem?.id
}
},
callback: data => {
onChange && onChange();
editItem(data);
}
})
}
} else if (id === 'delete') {
deleteItem(currentItem);
} else if (id === 'sample') {
setSampleParams({visible: true, service: currentItem})
} else if (id === 'history') {
historyItem(currentItem);
} else if (id === 'copy') {
window.open(`/data-govern/data-model-action?${Action}=add&${CatalogId}=${(view==='dir')?(catalogId||''):''}&${ModelerId}=${currentItem.id}`);
} else if (id === 'createTable') {
deployAction(currentItem);
} else if (id.indexOf('action') !== -1) {
const index = (id.split('-'))[1];
const action = currentItem?.state?.supportedActions[index];
stateAction(currentItem, action);
} else if (id === 'admit') {
app.openAdmit?.({ dirId: catalogId, service: currentItem })
} else if (id === 'enableOData') {
startODataItem(currentItem);
} else if (id === 'disableOData') {
disableODataItem(currentItem);
} else if (id === 'startFlow') {
app.applyServer?.({ service: currentItem });
} else if (id === 'downloadTds') {
window.open(`/api/pdataservice/pdsCURD/genTDS?id=${currentItem?.id}`);
} else if (id === 'checkout') {
dispatch({
type: 'pds.checkoutService',
payload: {
params: {
id: currentItem?.id
}
},
callback: () => {
showMessage('success', '检出成功');
onChange && onChange();
}
})
} else if (id === 'smart') {
dispatch({
type: 'pds.getSmartBiUrl',
payload: {
url: currentItem?.smartBiWebSpreadSheetEntry
},
callback: (data) => {
window.open(data)
}
})
} else if (id === 'exchangeOwner') {
setExchangeOwnerParams({ visible: true, id: currentItem?.id });
} else if (id === 'offline') {
offlineService(currentItem);
}
}
const onServiceDetailClose = () => { const onServiceDetailClose = () => {
setServiceDetailParams({ visible: false, id: '' }) setServiceDetailParams({ visible: false, id: '' })
} }
...@@ -865,17 +969,12 @@ const ModelTable = (props) => { ...@@ -865,17 +969,12 @@ const ModelTable = (props) => {
/> />
} }
<RcMenu id={MENU_ID}> <RcMenu id={MENU_ID}>
{ {/* {
(getDataModelerRole(user)!==DataModelerRoleReader) && view!=='grant' && !isOnlyEnding && <RcItem id="edit" disabled={!currentItem?.editable&&!currentItem?.permitCheckOut} onClick={handleItemClick}> (getDataModelerRole(user)!==DataModelerRoleReader) && view!=='grant' && !isOnlyEnding && <RcItem id="edit" disabled={!currentItem?.editable&&!currentItem?.permitCheckOut} onClick={handleItemClick}>
编辑 编辑
</RcItem> </RcItem>
} }
{ {
// getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && !isOnlyEnding && currentItem?.permitCheckOut && <RcItem id="checkout" onClick={handleItemClick}>
// 检出
// </RcItem>
}
{
(getDataModelerRole(user)!==DataModelerRoleReader) && view!=='grant'&& !isOnlyEnding && <RcItem id="delete" disabled={!currentItem?.deletable} onClick={handleItemClick}> (getDataModelerRole(user)!==DataModelerRoleReader) && view!=='grant'&& !isOnlyEnding && <RcItem id="delete" disabled={!currentItem?.deletable} onClick={handleItemClick}>
<Tooltip title={deleteTip}> <Tooltip title={deleteTip}>
删除 删除
...@@ -888,11 +987,6 @@ const ModelTable = (props) => { ...@@ -888,11 +987,6 @@ const ModelTable = (props) => {
<RcItem id="history" onClick={handleItemClick}> <RcItem id="history" onClick={handleItemClick}>
历史版本 历史版本
</RcItem> </RcItem>
{/* {
(getDataModelerRole(user)!==DataModelerRoleReader) && <RcItem id="copy" onClick={handleItemClick}>
复制服务
</RcItem>
} */}
{ {
getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && (currentItem?.state?.supportedActions||[]).length>0 && currentItem?.state?.supportedActions.map((item, index) => { getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && (currentItem?.state?.supportedActions||[]).length>0 && currentItem?.state?.supportedActions.map((item, index) => {
return ( return (
...@@ -913,11 +1007,6 @@ const ModelTable = (props) => { ...@@ -913,11 +1007,6 @@ const ModelTable = (props) => {
</RcItem> </RcItem>
} }
{ {
// getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && currentItem?.supportOffline && <RcItem id="offline" onClick={handleItemClick} >
// 下线
// </RcItem>
}
{
getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && !isOnlyEnding && currentItem?.supportODataEnable && <RcItem id="enableOData" onClick={handleItemClick}> getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && !isOnlyEnding && currentItem?.supportODataEnable && <RcItem id="enableOData" onClick={handleItemClick}>
启动OData 启动OData
</RcItem> </RcItem>
...@@ -941,11 +1030,6 @@ const ModelTable = (props) => { ...@@ -941,11 +1030,6 @@ const ModelTable = (props) => {
getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && currentItem?.supportChangeOwn && <RcItem id="exchangeOwner" onClick={handleItemClick}> getDataModelerRole(user)!==DataModelerRoleReader && view!=='grant' && currentItem?.supportChangeOwn && <RcItem id="exchangeOwner" onClick={handleItemClick}>
更换管理人 更换管理人
</RcItem> </RcItem>
}
{/* {
getDataModelerRole(user)!==DataModelerRoleReader &&currentItem?.deployable && <RcItem id='createTable' onClick={handleItemClick}>
建表
</RcItem>
} */} } */}
</RcMenu> </RcMenu>
......
...@@ -654,11 +654,11 @@ class Model extends React.Component { ...@@ -654,11 +654,11 @@ class Model extends React.Component {
</Tooltip> </Tooltip>
</Space> */} </Space> */}
<Space> {/* <Space>
<Tooltip title={(selectModelerIds||[]).length===0?'请先选择服务':''}> <Tooltip title={(selectModelerIds||[]).length===0?'请先选择服务':''}>
<Button onClick={this.onRecatalogBtnClick} disabled={(selectModelerIds||[]).length===0}>变更目录</Button> <Button onClick={this.onRecatalogBtnClick} disabled={(selectModelerIds||[]).length===0}>变更目录</Button>
</Tooltip> </Tooltip>
</Space> </Space> */}
{/* <Space> {/* <Space>
<Tooltip title={(selectModelerIds||[]).length===0?'请先选择服务':''}> <Tooltip title={(selectModelerIds||[]).length===0?'请先选择服务':''}>
......
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