Commit f50d6e3f by zhaochengxiang

模型路径

parent 33e70d59
......@@ -234,19 +234,21 @@ const EditModel = (props) => {
} else if (action === 'detail') {
let editTip = '';
if (!editable) {
if (!editable && stateId !== '4') {
if (stateId === '2') {
editTip = '待发布的模型不允许编辑';
} else if (stateId === '4') {
editTip = `${holder||''}正在编辑中, 不允许再编辑`;
}
}
if (!permitCheckOut && stateId === '4') {
editTip = `${holder||''}正在编辑中, 不允许再编辑`;
}
actionsBtn = (
<Space>
<Button type='primary' onClick={onHistory} danger >版本历史</Button>
<Tooltip title={editTip}>
<Button type='primary' onClick={edit} disabled={!editable} danger >
<Button type='primary' onClick={edit} disabled={(stateId==='4')?!permitCheckOut:!editable} danger >
编辑
</Button>
</Tooltip>
......
......@@ -260,7 +260,8 @@ const ModelTable = (props) => {
}
};
const [ columns, setColumns ] = useState(cols);
const [ columns, setColumns ] = useState([]);
const [ includePathColumns, setIncludePathColumns ] = useState([]);
const [ pagination, setPagination ] = useState( { pageNum: 1, pageSize: 20 } );
const [ currentItem, setCurrentItem ] = useState(null);
const { pageNum, pageSize } = pagination;
......@@ -275,18 +276,12 @@ const ModelTable = (props) => {
useEffect(() => {
if ((modelId||'') !== '') {
setColumns(cols.filter(item => item.dataIndex!=='key'));
window?.addEventListener("storage", (e) => {
if (e.key === 'modelChange') {
getDataModel();
}
});
} else if ((modelId||'')==='' && (view==='state'||(keyword||'')!=='')) {
setColumns(cols.splice(3, 0, pathColumn));
}
}
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [])
......@@ -362,6 +357,47 @@ const ModelTable = (props) => {
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [data, pagination, sortRule])
useEffect(() => {
if (tableWidth) {
let newColumns = [...cols], newIncludePathColumns = [...cols];
newIncludePathColumns.splice(3, 0, pathColumn);
if ((modelId||'') !== '') {
newColumns = cols.filter(item => item.dataIndex!=='key');
}
newColumns.forEach((column, index) => {
if (!column.width) {
const rowWidth = (cols.reduce((preVal, col) => (col.width?col.width:0) + preVal, 0)) + 50;
if (tableWidth > rowWidth) {
column.width = (tableWidth-rowWidth)>200?(tableWidth-rowWidth):200;
} else {
column.width = 200;
}
}
});
newIncludePathColumns.forEach((column, index) => {
if (!column.width) {
const rowWidth = (cols.reduce((preVal, col) => (col.width?col.width:0) + preVal, 0)) + 50;
if (tableWidth > rowWidth) {
column.width = (tableWidth-rowWidth)>200?(tableWidth-rowWidth):200;
} else {
column.width = 200;
}
}
});
setColumns(newColumns);
setIncludePathColumns(newIncludePathColumns);
}
//eslint-disable-next-line react-hooks/exhaustive-deps
}, [ tableWidth ])
const autoResizeColumns = (val) => {
if ((val||[]).length>0) {
let maxLength = 0, maxLength_cn = 0, name = '', cnName = '';
......@@ -526,13 +562,22 @@ const ModelTable = (props) => {
}
const handleResize = index => (e, { size }) => {
const nextColumns = [...columns];
let nextColumns = [...columns];
if ((modelId||'')==='' && (view==='state'||(keyword||'')!=='')) {
nextColumns = [...includePathColumns];
}
nextColumns[index] = {
...nextColumns[index],
width: size.width,
};
setColumns(nextColumns);
if ((modelId||'')==='' && (view==='state'||(keyword||'')!=='')) {
setIncludePathColumns(nextColumns);
} else {
setColumns(nextColumns);
}
};
const onTableChange = (pagination, filters, sorter, extra) => {
......@@ -614,17 +659,38 @@ const ModelTable = (props) => {
}
}
const mergedColumns = () => {
let newColumns = [...columns];
if ((modelId||'')==='' && (view==='state'||(keyword||'')!=='')) {
newColumns = [...includePathColumns];
}
return (
newColumns.map((col, index) => ({
...col,
onHeaderCell: column => ({
width: column.width,
onResize: handleResize(index),
}),
}))
);
}
let disableEdit = false, disableDelete = false, editTip = '', deleteTip = '';
if (!currentItem?.editable&&!currentItem?.permitCheckOut) {
if (!currentItem?.editable && currentItem?.state?.id!=='4') {
disableEdit = true;
if (currentItem?.state?.id === '2') {
editTip = '待发布的模型不允许编辑';
} else if (currentItem?.state?.id === '4') {
editTip = `${currentItem.holder||''}正在编辑中, 不允许再编辑`;
}
}
if (!currentItem?.permitCheckOut && currentItem?.state?.id==='4') {
disableEdit = true;
editTip = `${currentItem.holder||''}正在编辑中, 不允许再编辑`;
}
if (!currentItem?.deletable) {
disableDelete = true;
......@@ -639,35 +705,7 @@ const ModelTable = (props) => {
<div className={classes}>
<ResizeObserver
onResize={({ width }) => {
if (tableWidth !== width) {
setTableWidth(width);
let newColumns = [...cols];
if ((modelId||'') !== '') {
newColumns = cols.filter(item => item.dataIndex!=='key');
} else if ((modelId||'')==='' && (view==='state'||(keyword||'')!=='')) {
newColumns = cols.splice(3, 0, pathColumn);
}
newColumns.forEach((column, index) => {
if (!column.width) {
const rowWidth = (columns.reduce((preVal, col) => (col.width?col.width:0) + preVal, 0)) + 50;
if (width > rowWidth) {
column.width = (width-rowWidth)>200?(width-rowWidth):200;
} else {
column.width = 200;
}
}
});
setColumns(newColumns);
}
setTableWidth(width);
}}
>
<Table
......@@ -677,15 +715,7 @@ const ModelTable = (props) => {
cell: ResizeableHeaderCell,
}
}}
columns={
columns.map((col, index) => ({
...col,
onHeaderCell: column => ({
width: column.width,
onResize: handleResize(index),
}),
}))
}
columns={mergedColumns()}
rowKey={'id'}
dataSource={modelId?(subData||[]):(filterData||[])}
pagination={false}
......
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