Browse Source

product-info

master
yinweiwen 3 years ago
parent
commit
c8923be916
  1. 45
      code/web/client/src/sections/meta/containers/ProductCard.js
  2. 34
      code/web/client/src/sections/meta/containers/ProductsProfile.js
  3. 2
      code/web/package.json

45
code/web/client/src/sections/meta/containers/ProductCard.js

@ -2,9 +2,12 @@ import React, { useState, useRef, useEffect } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Button, Empty, Space, Spin, Tag, Descriptions } from 'antd'; import { Button, Empty, Space, Spin, Tag, Descriptions } from 'antd';
import '../style.less'; import '../style.less';
import { ProTable } from '@ant-design/pro-table';
import { render } from 'react-dom';
import { Link } from 'react-router-dom';
const ProductCard = (props) => { const ProductCard = (props) => {
const { dispatch, actions, productId, product, loading } = props const { dispatch, actions, productId, product, products, loading } = props
const { meta } = actions; const { meta } = actions;
@ -14,6 +17,28 @@ const ProductCard = (props) => {
} }
}, []); }, []);
const columns = [{
title: '能力',
dataIndex: 'cmname'
}, {
title: '描述',
dataIndex: 'cmdesc'
}, {
title: '接口',
dataIndex: 'iname'
}, {
title: '协议名',
dataIndex: 'pmdesc'
}, {
title: '协议',
dataIndex: 'pmname',
render: (_, item) => {
return <a href={`protocol/${item.pmname}`}>{item.pmname}</a>;
},
},
]
const actionRef = useRef();
return ( return (
<Spin spinning={loading}> <Spin spinning={loading}>
<Descriptions title="Product Info" bordered> <Descriptions title="Product Info" bordered>
@ -27,23 +52,37 @@ const ProductCard = (props) => {
<Descriptions.Item label="创建用户" >{product?.Username}</Descriptions.Item> <Descriptions.Item label="创建用户" >{product?.Username}</Descriptions.Item>
<Descriptions.Item label="资源类型" span={3}>{product?.FilterResource}</Descriptions.Item> <Descriptions.Item label="资源类型" span={3}>{product?.FilterResource}</Descriptions.Item>
</Descriptions> </Descriptions>
<h3>能力集合</h3>
<ProTable
columns={columns}
actionRef={actionRef}
dataSource={products}
options={false}
toolBarRender={false}
search={false}
>
</ProTable>
</Spin> </Spin>
) )
} }
function mapStateToProps(state) { function mapStateToProps(state) {
const { auth, global, product } = state; const { auth, global, product } = state;
console.log(product)
let raw = product
let p = {} let p = {}
if (product && product.data && (product.data.data ?? []).length > 0) { if (product && product.data && (product.data.data ?? []).length > 0) {
p=product.data.data[0]; p = product.data.data[0];
} }
console.log(raw.data?.data ?? [])
return { return {
user: auth.user, user: auth.user,
actions: global.actions, actions: global.actions,
loading: product.isRequesting, loading: product.isRequesting,
product: p, product: p,
productCaps: product.data?.data ?? [], products: raw.data?.data ?? [],
}; };
} }

34
code/web/client/src/sections/meta/containers/ProductsProfile.js

@ -1,6 +1,6 @@
import React, { useState, useRef, useEffect } from 'react'; import React, { useState, useRef, useEffect } from 'react';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { Button, Space, Tag ,Drawer} from 'antd'; import { Button, Space, Tag, Drawer } from 'antd';
import '../style.less'; import '../style.less';
import ProTable from '@ant-design/pro-table'; import ProTable from '@ant-design/pro-table';
import ConfigModal from './ConfigModal'; import ConfigModal from './ConfigModal';
@ -18,6 +18,11 @@ const ProductsProfile = (props) => {
useEffect(() => { useEffect(() => {
dispatch(meta.listProducts()) dispatch(meta.listProducts())
}, []); }, []);
useEffect(() => {
requestList()
}, [products]);
const pageSize = 10 const pageSize = 10
const actionRef = useRef(); const actionRef = useRef();
@ -79,44 +84,47 @@ const ProductsProfile = (props) => {
}, },
] ]
const requestList = async (params, sorter) => { const requestList = (params, sort) => {
if (!products) { if (!products) {
return null return null
} }
let tmp = products; let tmp = products;
if (!!params.Name) { if (!!params?.Name) {
tmp = tmp.filter(a => a.Name.includes(params.Name)) tmp = tmp.filter(a => a.Name.includes(params.Name))
} }
if (!!params.Id) { if (!!params?.Id) {
tmp = tmp.filter(a => a.Id.includes(params.Id)) tmp = tmp.filter(a => a.Id.includes(params.Id))
} }
if (!!params.Company) { if (!!params?.Company) {
tmp = tmp.filter(a => a.Company.includes(params.Company)) tmp = tmp.filter(a => a.Company.includes(params.Company))
} }
if (!!params.Model) { if (!!params?.Model) {
tmp = tmp.filter(a => a.Model.includes(params.Model)) tmp = tmp.filter(a => a.Model.includes(params.Model))
} }
if (!!sorter.CreatedAt) { if (!!sort?.CreatedAt) {
console.log(sorter) console.log(sort)
tmp = tmp.sort((a, b) => { tmp = tmp.sort((a, b) => {
let aTime = new Date(a.CreatedAt).getTime() let aTime = new Date(a.CreatedAt).getTime()
let bTime = new Date(b.CreatedAt).getTime() let bTime = new Date(b.CreatedAt).getTime()
return sorter.CreatedAt === "ascend" ? aTime - bTime : bTime - aTime return sort.CreatedAt === "ascend" ? aTime - bTime : bTime - aTime
}) })
} }
if (!!sorter.UpdatedAt) { if (!!sort?.UpdatedAt) {
tmp = tmp.sort((a, b) => { tmp = tmp.sort((a, b) => {
let aTime = new Date(a.UpdatedAt).getTime() let aTime = new Date(a.UpdatedAt).getTime()
let bTime = new Date(b.UpdatedAt).getTime() let bTime = new Date(b.UpdatedAt).getTime()
return sorter.UpdatedAt === "ascend" ? aTime - bTime : bTime - aTime return sort.UpdatedAt === "ascend" ? aTime - bTime : bTime - aTime
}) })
} }
let pageData = tmp.slice(params.pageSize * (params.current - 1), params.pageSize * params.current); let pageData = params ?
tmp.slice(params.pageSize * (params.current - 1), params.pageSize * params.current) :
tmp.slice(0, 10);
pageData = pageData.map(d => ({ pageData = pageData.map(d => ({
...d, ...d,
key: d.Id key: d.Id
})) }))
setFdata(pageData)
setFdata(tmp)
return { return {
total: tmp.length, total: tmp.length,
data: pageData data: pageData

2
code/web/package.json

@ -61,8 +61,6 @@
}, },
"dependencies": { "dependencies": {
"@ant-design/icons": "^4.6.2", "@ant-design/icons": "^4.6.2",
"@ant-design/pro-components": "^2.3.25",
"@ant-design/pro-descriptions": "^2.0.21",
"@ant-design/pro-form": "^1.34.0", "@ant-design/pro-form": "^1.34.0",
"@ant-design/pro-table": "^2.48.0", "@ant-design/pro-table": "^2.48.0",
"@antv/g6": "^4.2.5", "@antv/g6": "^4.2.5",

Loading…
Cancel
Save