Commit af16a2df by zhaochengxiang

批量转资产

parent eb3f4dee
......@@ -135,7 +135,6 @@ export const Basic = React.forwardRef(function ({ items, defaultValue }, ref) {
const [type, setType] = React.useState('add')
const [loadingTreeData, setLoadingTreeData] = React.useState(false)
const [treeData, setTreeData] = React.useState()
const [expandedKeys, setExpandedKeys] = React.useState()
const [form] = Form.useForm()
React.useImperativeHandle(ref, () => ({
......@@ -155,29 +154,6 @@ export const Basic = React.forwardRef(function ({ items, defaultValue }, ref) {
}
}, [type, defaultValue])
const treeData1 = React.useMemo(() => {
if (treeData) {
const newTreeData = produce(treeData, draft => {
const setNode = (g) => {
g.key = g.nodeId
g.title = g.text
g.value = g.nodeId
g.children?.forEach((child) => {
setNode(child)
})
}
draft.forEach((child) => {
setNode(child)
})
})
return newTreeData
}
return undefined
}, [treeData])
const getTreeData = () => {
setLoadingTreeData(true)
dispatch({
......@@ -186,9 +162,6 @@ export const Basic = React.forwardRef(function ({ items, defaultValue }, ref) {
setLoadingTreeData(false)
const filterData = (data??[]).filter(item => item.type !== 'custom')
setTreeData(filterData)
if ((filterData??[]).length > 0) {
setExpandedKeys([filterData[0].nodeId])
}
},
error: () => {
setLoadingTreeData(false)
......@@ -230,20 +203,7 @@ export const Basic = React.forwardRef(function ({ items, defaultValue }, ref) {
label='资产目录'
rules={[{ required: true, message: '请选择资产目录!' }]}
>
<TreeSelect
showSearch
treeNodeFilterProp='title'
loading={loadingTreeData}
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
treeData={treeData1}
treeExpandedKeys={expandedKeys}
onTreeExpand={(val) => {
setExpandedKeys(val)
}}
placeholder="请选择分组"
treeCheckable
treeCheckStrictly
/>
<AssetDictionaryItem loading={loadingTreeData} data={treeData} />
</Form.Item>
<Form.Item
name='asset'
......@@ -274,6 +234,69 @@ export const Basic = React.forwardRef(function ({ items, defaultValue }, ref) {
)
})
export const AssetDictionaryItem = ({ value, onChange, loading, data }) => {
const [expandedKeys, setExpandedKeys] = React.useState()
React.useEffect(() => {
if ((data??[]).length>0) {
setExpandedKeys([data[0].nodeId])
}
}, [data])
const treeData = React.useMemo(() => {
if (data) {
const newTreeData = produce(data, draft => {
const setNode = (g) => {
g.key = g.nodeId
g.title = g.text
g.value = g.nodeId
g.children?.forEach((child) => {
setNode(child)
})
}
draft.forEach((child) => {
setNode(child)
})
})
return newTreeData
}
return undefined
}, [data])
return (
<TreeSelect
showSearch
treeNodeFilterProp='title'
loading={loading}
value={value}
dropdownStyle={{ maxHeight: 400, overflow: 'auto' }}
dropdownRender={(originNode) => (
<div
onClick={e => {
e.stopPropagation()
}}
>
{originNode}
</div>
)}
treeData={treeData}
treeExpandedKeys={expandedKeys}
onTreeExpand={(val) => {
setExpandedKeys(val)
}}
onChange={(val) => {
onChange?.(val)
}}
placeholder="请选择资产目录"
treeCheckable
treeCheckStrictly
/>
)
}
const AssetInfoItem = ({ value, elements, onChange }) => {
const [loading, setLoading] = React.useState(false)
const [groups, setGroups] = React.useState()
......
......@@ -11,6 +11,11 @@ import { getAssetType, getQueryParam, isSzseEnv } from '../../../util'
import '../Model/Component/EditModel.less'
import { ElementItem, MultipleItem } from '../AssetManage/Component/AssetAction'
import { AssetDictionaryItem } from './add-to-asset'
const pathElement = {
name: '资产目录'
}
const FC = (props) => {
const ids = getQueryParam('ids', props.location?.search)
......@@ -122,6 +127,8 @@ export const EditAssets = React.forwardRef(function ({ action, type, ids, elemen
const [modifyData, setModifyData] = React.useState()
const [loading, setLoading] = React.useState(false)
const [editingKey, setEditingKey] = React.useState('')
const [loadingTreeData, setLoadingTreeData] = React.useState(false)
const [treeData, setTreeData] = React.useState()
const [page, setPage] = usePage()
const [form] = Form.useForm()
......@@ -165,7 +172,9 @@ export const EditAssets = React.forwardRef(function ({ action, type, ids, elemen
rules={[{ required: true, message: `请输入${element?.name}!` }]}
style={{ marginBottom: 15 }}
>
<ElementItem type='edit' element={element} />
{
(element?.name === pathElement?.name) ? <AssetDictionaryItem loading={loadingTreeData} data={treeData} /> : <ElementItem type='edit' element={element} />
}
</Form.Item>
</Form>
<div className='flex' style={{ justifyContent: 'end' }}>
......@@ -186,9 +195,15 @@ export const EditAssets = React.forwardRef(function ({ action, type, ids, elemen
await save()
const rows = await colBatchEditForm.validateFields()
const newModifyData = [...modifyData]
const index = parseInt(dataIndex.slice('element'.length))
for (const item of newModifyData) {
item.values[index] = rows[`${dataIndex}`]
if (dataIndex === pathElement.name) {
item.paths = rows[dataIndex]
} else {
const index = (element??[]).findIndex(item => item.name === dataIndex)
if (index !== -1) {
for (const item of newModifyData) {
item.values[index] = rows[dataIndex]
}
}
}
setModifyData(newModifyData)
......@@ -213,10 +228,15 @@ export const EditAssets = React.forwardRef(function ({ action, type, ids, elemen
const columns = React.useMemo(() => {
const newColumns = []
let index = 0
for (const element of elements??[]) {
let newElements = [...elements??[]]
if ((elementIds??[]).length === 0) {
newElements = [pathElement, ...newElements]
}
for (const element of newElements??[]) {
let col = {
title: element.name,
dataIndex: `element${index}`,
dataIndex: element.name,
ellipsis: true,
width: 120,
render: (text, record) => {
......@@ -233,6 +253,18 @@ export const EditAssets = React.forwardRef(function ({ action, type, ids, elemen
col.width = isSzseEnv ? 230 : 160
} else if (element.name === '英文名称') {
col.width = isSzseEnv ? 224 : 160
} else if (element.name === pathElement.name) {
col.width = 200
col.render = (text, record) => {
const title = (text??[]).map(item=>item.label).toString()
return (
<Tooltip title={title}>
<Typography.Text ellipsis={true}>
{title}
</Typography.Text>
</Tooltip>
);
}
}
col.onCell = (record) => ({
......@@ -240,11 +272,13 @@ export const EditAssets = React.forwardRef(function ({ action, type, ids, elemen
dataIndex: col.dataIndex,
colTitle: col.title,
editing: isEditing(record),
loadingTreeData,
treeData,
})
if (action === 'edit') {
if (action === 'edit' && element.name!=='编号' && element.name!=='中文名称' && element.name!=='英文名称') {
col = {
...col,
...getColumnBatchEditProps(element, `element${index}`)
...getColumnBatchEditProps(element, element.name)
}
}
......@@ -253,22 +287,26 @@ export const EditAssets = React.forwardRef(function ({ action, type, ids, elemen
}
return newColumns
}, [elements, getColumnBatchEditProps, isEditing, action])
}, [elements, getColumnBatchEditProps, isEditing, action, loadingTreeData, treeData, elementIds])
const tableData = React.useMemo(() => {
const newTableData = []
for (const item of (modifyData??[])) {
for (const item of modifyData??[]) {
const newAsset = {...item}
let index = 0
for (const elementValue of (item.values??[])) {
newAsset[`element${index}`] = elementValue
index++
if ((elementIds??[]).length === 0) {
newAsset[pathElement.name] = item.paths
}
for (const [index, element] of (elements??[]).entries()) {
newAsset[element.name] = item.values[index]
}
newTableData.push(newAsset)
}
return newTableData
}, [modifyData])
}, [modifyData, elements, elementIds])
useClickAway(() => {
save()
......@@ -276,6 +314,7 @@ export const EditAssets = React.forwardRef(function ({ action, type, ids, elemen
React.useEffect(() => {
getAssets()
getTreeData()
}, [ids, elementIds, action])
React.useEffect(() => {
......@@ -305,6 +344,21 @@ export const EditAssets = React.forwardRef(function ({ action, type, ids, elemen
})
}
const getTreeData = () => {
setLoadingTreeData(true)
dispatch({
type: 'assetmanage.queryDataAssetManageTree',
callback: data => {
setLoadingTreeData(false)
const filterData = (data??[]).filter(item => item.type !== 'custom')
setTreeData(filterData)
},
error: () => {
setLoadingTreeData(false)
}
})
}
const save = async () => {
if (!editingKey) {
return true
......@@ -319,9 +373,14 @@ export const EditAssets = React.forwardRef(function ({ action, type, ids, elemen
if (index > -1) {
const item = newModifyData[index]
for (const dataIndex in row) {
const elementIndex = parseInt(dataIndex.slice('element'.length))
item.values[elementIndex] = row[`${dataIndex}`]
if (dataIndex === pathElement.name) {
item.paths = row[dataIndex]
} else {
const _index = (elements??[]).findIndex(item => item.name === dataIndex)
if (_index !== -1) {
item.values[_index] = row[dataIndex]
}
}
}
setModifyData(newModifyData)
return ''
......@@ -371,6 +430,8 @@ export const EditableCell = ({
element,
require,
children,
loadingTreeData,
treeData,
...restProps
}) => {
let editingComponent = null
......@@ -386,7 +447,9 @@ export const EditableCell = ({
},
]}
>
<ElementItem type='edit' element={element} />
{
element.name === pathElement.name ? <AssetDictionaryItem loading={loadingTreeData} data={treeData} /> : <ElementItem type='edit' element={element} />
}
</Form.Item>
)
}
......
......@@ -258,8 +258,8 @@ const FC = (props) => {
}
}, [data])
const [addAble, addAsAssetAble, distributeAble, batchEditAble,checkAble, importAble, exportAble, changeDirectoryAble, deleteAble] = React.useMemo(() => {
let [_addAble, _addAsAssetAble, _distributeAble, _batchEditAble, _checkAble, _importAble, _exportAble, _changeDiretoryAble, _deleteAble] = [false, false, false, false, false, false, false, false, false]
const [addAble, addAsAssetAble, batchAddAsAssetAble, distributeAble, batchEditAble,checkAble, importAble, exportAble, changeDirectoryAble, deleteAble] = React.useMemo(() => {
let [_addAble, _addAsAssetAble, _batchAddAsAssetAble, _distributeAble, _batchEditAble, _checkAble, _importAble, _exportAble, _changeDiretoryAble, _deleteAble] = [false, false, false, false, false, false, false, false, false, false]
_addAble = (permissions??[]).findIndex(item => item==='add') !== -1
......@@ -283,9 +283,10 @@ const FC = (props) => {
_exportAble = allowExport
}
let [allowAddAsAsset, allowDistribute, allowBatchEdit, allowCheck, allowChangeDirectory, allowDelete] = [true, true, true, true, true, true]
let [allowAddAsAsset, allowBatchAddAsAsset, allowDistribute, allowBatchEdit, allowCheck, allowChangeDirectory, allowDelete] = [true, true, true, true, true, true, true]
for (const row of selectedRows??[]) {
const addAsAssetIndex = (row.allowButtons??[]).findIndex(item => item==='addAsAsset')
const batchAddAsAssetIndex = (row.allowButtons??[]).findIndex(item => item==='batchAddAsAsset')
const distributeIndex = (row.allowButtons??[]).findIndex(item => item==='distribute')
const batchEditIndex = (row.allowButtons??[]).findIndex(item => item==='batchEdit')
const checkIndex = (row.allowButtons??[]).findIndex(item => item==='check')
......@@ -294,6 +295,9 @@ const FC = (props) => {
if (addAsAssetIndex === -1) {
allowAddAsAsset = false
}
if (batchAddAsAssetIndex === -1) {
allowBatchAddAsAsset = false
}
if (distributeIndex === -1) {
allowDistribute = false
}
......@@ -312,13 +316,14 @@ const FC = (props) => {
}
_addAsAssetAble = allowAddAsAsset
_batchAddAsAssetAble = allowBatchAddAsAsset
_distributeAble = allowDistribute
_batchEditAble = allowBatchEdit
_checkAble = allowCheck
_changeDiretoryAble = allowChangeDirectory
_deleteAble = allowDelete
return [_addAble, _addAsAssetAble, _distributeAble, _batchEditAble, _checkAble, _importAble, _exportAble, _changeDiretoryAble, _deleteAble]
return [_addAble, _addAsAssetAble, _batchAddAsAssetAble, _distributeAble, _batchEditAble, _checkAble, _importAble, _exportAble, _changeDiretoryAble, _deleteAble]
}, [permissions, selectedRows])
const menuData = React.useMemo(() => {
......@@ -663,6 +668,10 @@ const FC = (props) => {
})
}
const onBatchAddToAssetClick = () => {
window.open(`/data-govern/edit-assets?ids=${(selectedRows??[]).map(item => item.id).toString()}&type=${ResourceManageReference}`)
}
const onDistributeTaskClick = () => {
setDistributeTaskParams({
visible: true,
......@@ -932,6 +941,8 @@ const FC = (props) => {
const onMenuClick = ({ key }) => {
if (key === 'addAsAsset') {
onAddToAssetClick()
} else if (key === 'batchAddAsAsset') {
onBatchAddToAssetClick()
} else if (key === 'distribute') {
onDistributeTaskClick()
} else if (key === 'autoDistribute') {
......@@ -990,6 +1001,16 @@ const FC = (props) => {
</div>
</PermissionMenuItem>
<PermissionMenuItem
key='batchAddAsAsset'
defaultPermission={batchAddAsAssetAble}
disabled={(selectedRows??[]).length===0}
tip={(selectedRows??[]).length===0?'请先选择资源':''}
>
<div className='text-center'>
批量转资产
</div>
</PermissionMenuItem>
<PermissionMenuItem
key='distribute'
defaultPermission={distributeAble}
disabled={(selectedRows??[]).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