diff --git a/api/app/lib/controllers/dataService/index.js b/api/app/lib/controllers/dataService/index.js index f1d3215..17c5210 100644 --- a/api/app/lib/controllers/dataService/index.js +++ b/api/app/lib/controllers/dataService/index.js @@ -15,7 +15,16 @@ function getServiceManagement(opts) { order: [["id", "desc"]], include: [{ model: models.ResourceConsumption, - }], + }, + { + model: models.ResourceCatalog, + attributes: ['id', 'name'], + include: [{ + model: models.Organization, + attributes: ['id', 'name'], + }] + } + ], distinct: true } if (keyword) { diff --git a/web/client/src/sections/dataService/containers/serviceManagement.js b/web/client/src/sections/dataService/containers/serviceManagement.js index b056b4e..9aeffcf 100644 --- a/web/client/src/sections/dataService/containers/serviceManagement.js +++ b/web/client/src/sections/dataService/containers/serviceManagement.js @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react' import { connect } from 'react-redux'; import moment from 'moment'; import { RouteRequest } from '@peace/utils'; -import { RouteTable } from '$utils' +import { Func } from '$utils' import { Tabs, Form, Input, Space, Button, Table, Popconfirm, message } from 'antd'; const { Search } = Input; @@ -10,7 +10,7 @@ const { Search } = Input; import EditModal from '../components/editModal'; -function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) { +function ServiceManagement({ loading, clientHeight, actions, dispatch, }) { const { dataService } = actions const [query, setQuery] = useState({ page: 0, limit: 10 }); @@ -53,63 +53,66 @@ function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) { dataIndex: 'handle', width: '250px', // ellipsis: true, - render: (text, record) =>
- { - setEditData(record) - setEditModal(true) - setViewDetails(true) - }}>查看详情 - { - setEditData(record) - setEditModal(true) - }}>编辑 - - {/* {record?.enabled ? */} - {record?.resourceConsumptions?.length > 0 ? { - message.warning('已有关联数据,无法删除') - }}>删除 - : { - dispatch(dataService.delServiceManagement(record.id)).then(res => { - if (res.success) { - setQuery({ limit: 10, page: 0 }); - resourceData({ limit: 10, page: 0, keyword }) - } - }) - }} - > - 删除 - } - - {/* // } */} - {record?.enabled ? - { + render: (text, record) => { + const isCurrentOrg = Func?.isOrgOrSuperAdmin(record?.resourceCatalog?.organization?.id) + return
+ { + setEditData(record) + setEditModal(true) + setViewDetails(true) + }}>查看详情 + {isCurrentOrg && { + setEditData(record) + setEditModal(true) + }}>编辑 + } + {/* {record?.enabled ? */} + {!isCurrentOrg ? '' : record?.resourceConsumptions?.length > 0 ? { + message.warning('已有关联数据,无法删除') + }}>删除 + : { + dispatch(dataService.delServiceManagement(record.id)).then(res => { + if (res.success) { + setQuery({ limit: 10, page: 0 }); + resourceData({ limit: 10, page: 0, keyword }) + } + }) + }} + > + 删除 + } + + {/* // } */} + {!isCurrentOrg ? '' : record?.enabled ? + { + dispatch(dataService.postServiceManagement({ + id: record.id, name: record?.name, enabled: false + }, true)).then(res => { + if (res.success) { + resourceData({ keyword }) + } + }) + }} + > + 禁用 + + : { dispatch(dataService.postServiceManagement({ - id: record.id, name: record?.name, enabled: false + id: record.id, name: record?.name, enabled: true }, true)).then(res => { if (res.success) { resourceData({ keyword }) } }) - }} - > - 禁用 - - : { - dispatch(dataService.postServiceManagement({ - id: record.id, name: record?.name, enabled: true - }, true)).then(res => { - if (res.success) { - resourceData({ keyword }) - } - }) - }}>启用 - } + }}>启用 + } -
+
+ } }, ]; @@ -174,7 +177,7 @@ function ServiceManagement ({ loading, clientHeight, actions, dispatch, }) { } -function mapStateToProps (state) { +function mapStateToProps(state) { const { global, auth, resourceCatalog } = state; return { user: auth.user, diff --git a/web/client/src/sections/dataService/containers/serviceView.js b/web/client/src/sections/dataService/containers/serviceView.js index 7bf0c6e..7a3baa5 100644 --- a/web/client/src/sections/dataService/containers/serviceView.js +++ b/web/client/src/sections/dataService/containers/serviceView.js @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react' import { connect } from 'react-redux'; import moment from 'moment'; import { RouteRequest } from '@peace/utils'; -import { RouteTable } from '$utils' +import { Func } from '$utils' import { Tabs, Form, Input, Space, Button, Table, message } from 'antd'; const { Search } = Input; @@ -14,7 +14,7 @@ import ResourceModal from '../components/resourceModal'; import { If } from 'react-if'; -function ServiceView ({ loading, clientHeight, actions, dispatch, }) { +function ServiceView({ loading, clientHeight, actions, dispatch, user }) { const { dataService, metadataManagement } = actions const [query, setQuery] = useState({ page: 0, limit: 10 }); @@ -54,38 +54,43 @@ function ServiceView ({ loading, clientHeight, actions, dispatch, }) { dataIndex: 'handle', width: '250px', // ellipsis: true, - render: (text, record) =>
- { - setEditData(record) - setEditModal(true) - setViewDetails(true) - }}>查看详情 - { - let result - record?.resourceConsumptions?.map(v => { - if (result != '已有申请成功的资源' && result != '资源审批中') { - if (v.token) { - result = '已有申请成功的资源' - } else if (v.approveState == '审批中') { - result = '资源审批中' - } - } - - }) - if (result) { - message.warning({ - duration: 1, - content: result, - }) - } else { + render: (text, record) => { + const isCurrentOrg = Func?.isOrgOrSuperAdmin(record?.resourceCatalog?.organization?.id) + return
+ { setEditData(record) - setResourceModal(true) + setEditModal(true) + setViewDetails(true) + }}>查看详情 + {!isCurrentOrg && { + let result + record?.resourceConsumptions + ?.filter(v => v.applyBy == user?.id) + ?.map(v => { + if (result != '已有申请成功的资源' && result != '资源审批中') { + if (v.token) { + result = '已有申请成功的资源' + } else if (v.approveState == '审批中') { + result = '资源审批中' + } + } + + }) + if (result) { + message.warning({ + duration: 1, + content: result, + }) + } else { + setEditData(record) + setResourceModal(true) + } + }}>申请资源 } - }}>申请资源 - -
+
+ } }, ]; @@ -165,7 +170,7 @@ function ServiceView ({ loading, clientHeight, actions, dispatch, }) { } -function mapStateToProps (state) { +function mapStateToProps(state) { const { global, auth, resourceCatalog } = state; return { user: auth.user, diff --git a/web/client/src/sections/dataService/nav-item.js b/web/client/src/sections/dataService/nav-item.js index cc81444..ae5192c 100644 --- a/web/client/src/sections/dataService/nav-item.js +++ b/web/client/src/sections/dataService/nav-item.js @@ -4,14 +4,14 @@ import { Menu } from 'antd'; import { CarryOutOutlined } from '@ant-design/icons'; const SubMenu = Menu.SubMenu; -export function getNavItem (user) { +export function getNavItem(user) { return ( } title='数据服务'> {user?.role == '系统管理员' && 服务管理 } - {user?.role != '系统管理员' && + { 服务查看 } diff --git a/web/client/src/sections/resourceConsumption/containers/approve.js b/web/client/src/sections/resourceConsumption/containers/approve.js index f3d5c11..b24389b 100644 --- a/web/client/src/sections/resourceConsumption/containers/approve.js +++ b/web/client/src/sections/resourceConsumption/containers/approve.js @@ -21,14 +21,24 @@ function Approve({ loading, clientHeight, actions, dispatch, user }) { resourceData() }, []) + useEffect(() => { + resourceData() + }, [tabsKey, query]) let resourceData = (params) => { let data = params || query - dispatch(resourceConsumption.getApproveList({ - approveState: tabsKey == 'stay' ? "审批中" : '已审批', ...formData, ...data, - orgId: user?.orgId, - approveId: (params?.approveState == '已审批' && user?.username != 'SuperAdmin') ? user?.id : null - })).then(res => { + const obj = { + approveState: tabsKey == 'stay' ? "审批中" : '已审批', + ...formData, ...data, + approveId: (tabsKey == 'stay' && user?.username != 'SuperAdmin') ? user?.id : null, + } + if (tabsKey == 'stay') { + obj.orgId = user?.orgId; + } else { + obj.applyById = user?.id; + } + + dispatch(resourceConsumption.getApproveList(obj)).then(res => { if (res.success) { setProTableList(res.payload.data) } @@ -120,11 +130,12 @@ function Approve({ loading, clientHeight, actions, dispatch, user }) { }, [tabsKey]) return <> - { - setTabsKey(key) - resourceData({ limit: 10, page: 0, approveState: key == 'stay' ? "审批中" : '已审批' }) - setQuery({ limit: 10, page: 0 }); - }} /> + { + setTabsKey(key) + // resourceData({ limit: 10, page: 0, approveState: key == 'stay' ? "审批中" : '已审批' }) + setQuery({ limit: 10, page: 0 }); + }} />
{