Skip to content

Commit

Permalink
fix(多租户): 多租户资产管理
Browse files Browse the repository at this point in the history
多租户资产管理页面,点击查看展示的条件错误导致数据不对。

fix #108 , fix #109
  • Loading branch information
Lind-pro committed Jul 13, 2020
1 parent 93e4b4e commit b84e115
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 82 deletions.
121 changes: 60 additions & 61 deletions src/pages/device/instance/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {FC, Fragment, useEffect, useState} from 'react';
import React, { FC, Fragment, useEffect, useState } from 'react';
import styles from '@/utils/table.less';
import {
Badge,
Expand All @@ -18,24 +18,24 @@ import {
Table,
Tooltip,
} from 'antd';
import {router} from 'umi';
import {ColumnProps, PaginationConfig, SorterResult} from 'antd/lib/table';
import {FormComponentProps} from 'antd/es/form';
import {ConnectState, Dispatch} from '@/models/connect';
import {PageHeaderWrapper} from '@ant-design/pro-layout';
import {connect} from 'dva';
import { router } from 'umi';
import { ColumnProps, PaginationConfig, SorterResult } from 'antd/lib/table';
import { FormComponentProps } from 'antd/es/form';
import { ConnectState, Dispatch } from '@/models/connect';
import { PageHeaderWrapper } from '@ant-design/pro-layout';
import { connect } from 'dva';
import encodeQueryParam from '@/utils/encodeParam';
import apis from '@/services';
import {getAccessToken} from '@/utils/authority';
import { getAccessToken } from '@/utils/authority';
import moment from 'moment';
import Save from './Save';
import Search from './Search';
import {DeviceInstance} from './data.d';
import { DeviceInstance } from './data.d';
import Process from './Process';
import Import from './operation/import';
import Export from './operation/export';
import {DeviceProduct} from '@/pages/device/product/data';
import {getPageQuery} from '@/utils/utils';
import { DeviceProduct } from '@/pages/device/product/data';
import { getPageQuery } from '@/utils/utils';

interface Props extends FormComponentProps {
loading: boolean;
Expand All @@ -58,11 +58,12 @@ interface State {
}

const DeviceInstancePage: React.FC<Props> = props => {
const {result} = props.deviceInstance;
const { result } = props.deviceInstance;
const { dispatch, location } = props;

const initState: State = {
data: result,
searchParam: {pageSize: 10},
searchParam: { pageSize: 10, terms: location?.query?.terms, },
addVisible: false,
currentItem: {},
processVisible: false,
Expand Down Expand Up @@ -91,8 +92,6 @@ const DeviceInstancePage: React.FC<Props> = props => {
const [deviceExport, setDeviceExport] = useState(false);
const [deviceIdList, setDeviceIdLIst] = useState(initState.deviceIdList);

const {dispatch} = props;

const statusMap = new Map();
statusMap.set('在线', 'success');
statusMap.set('离线', 'error');
Expand Down Expand Up @@ -171,7 +170,7 @@ const DeviceInstancePage: React.FC<Props> = props => {
title: '状态',
dataIndex: 'state',
width: '90px',
render: record => record ? <Badge status={statusMap.get(record.text)} text={record.text}/> : '',
render: record => record ? <Badge status={statusMap.get(record.text)} text={record.text} /> : '',
filters: [
{
text: '未激活',
Expand Down Expand Up @@ -205,7 +204,7 @@ const DeviceInstancePage: React.FC<Props> = props => {
>
查看
</a>
<Divider type="vertical"/>
<Divider type="vertical" />
<a
onClick={() => {
setCurrentItem(record);
Expand All @@ -214,7 +213,7 @@ const DeviceInstancePage: React.FC<Props> = props => {
>
编辑
</a>
<Divider type="vertical"/>
<Divider type="vertical" />
{record.state?.value === 'notActive' ? (
<span>
<Popconfirm
Expand All @@ -225,7 +224,7 @@ const DeviceInstancePage: React.FC<Props> = props => {
>
<a>激活</a>
</Popconfirm>
<Divider type="vertical"/>
<Divider type="vertical" />
<Popconfirm
title="确认删除?"
onConfirm={() => {
Expand All @@ -236,15 +235,15 @@ const DeviceInstancePage: React.FC<Props> = props => {
</Popconfirm>
</span>
) : (
<Popconfirm
title="确认注销设备?"
onConfirm={() => {
unDeploy(record);
}}
>
<a>注销</a>
</Popconfirm>
)}
<Popconfirm
title="确认注销设备?"
onConfirm={() => {
unDeploy(record);
}}
>
<a>注销</a>
</Popconfirm>
)}
</Fragment>
),
},
Expand All @@ -259,19 +258,19 @@ const DeviceInstancePage: React.FC<Props> = props => {
loading: true,
};

apis.deviceInstance.count(encodeQueryParam({terms: {state: 'notActive', productId}}))
apis.deviceInstance.count(encodeQueryParam({ terms: { state: 'notActive', productId, ...location?.query?.terms, } }))
.then(res => {
if (res.status === 200) {
map.notActiveCount = res.result;
apis.deviceInstance.count(encodeQueryParam({terms: {state: 'offline', productId}}))
apis.deviceInstance.count(encodeQueryParam({ terms: { state: 'offline', productId, ...location?.query?.terms, } }))
.then(res => {
if (res.status === 200) {
map.offlineCount = res.result;
apis.deviceInstance.count(encodeQueryParam({terms: {state: 'online', productId}}))
apis.deviceInstance.count(encodeQueryParam({ terms: { state: 'online', productId, ...location?.query?.terms, } }))
.then(res => {
if (res.status === 200) {
map.onlineCount = res.result;
apis.deviceInstance.count(encodeQueryParam({terms: {productId}}))
apis.deviceInstance.count(encodeQueryParam({ terms: { productId, ...location?.query?.terms, } }))
.then(res => {
if (res.status === 200) {
map.deviceTotal = res.result;
Expand Down Expand Up @@ -299,7 +298,7 @@ const DeviceInstancePage: React.FC<Props> = props => {

const query: any = getPageQuery();
if (query.hasOwnProperty('productId')) {
const {productId} = query;
const { productId } = query;
setProduct(productId);
handleSearch({
terms: {
Expand All @@ -319,7 +318,7 @@ const DeviceInstancePage: React.FC<Props> = props => {
filters: any,
sorter: SorterResult<DeviceInstance>,
) => {
let {terms} = searchParam;
let { terms } = searchParam;
if (filters.state) {
if (terms) {
terms.state = filters.state[0];
Expand Down Expand Up @@ -392,7 +391,7 @@ const DeviceInstancePage: React.FC<Props> = props => {
};

const onDeviceProduct = (value: string) => {
let {terms} = searchParam;
let { terms } = searchParam;
if (terms) {
terms.productId = value;
} else {
Expand Down Expand Up @@ -485,10 +484,10 @@ const DeviceInstancePage: React.FC<Props> = props => {
const Info: FC<{
title: React.ReactNode;
value: React.ReactNode;
}> = ({title, value}) => (
}> = ({ title, value }) => (
<div>
<span>{title}</span>
<p style={{fontSize: '26px'}}>{value}</p>
<p style={{ fontSize: '26px' }}>{value}</p>
</div>
);

Expand Down Expand Up @@ -532,12 +531,12 @@ const DeviceInstancePage: React.FC<Props> = props => {
</Button>
</Menu.Item>
) : (
<Menu.Item key="4">
<Button icon="check-circle" type="danger" onClick={() => activeDevice()}>
激活全部设备
<Menu.Item key="4">
<Button icon="check-circle" type="danger" onClick={() => activeDevice()}>
激活全部设备
</Button>
</Menu.Item>
)}
</Menu.Item>
)}

<Menu.Item key="5">
<Button icon="sync" type="danger" onClick={() => syncDevice()}>
Expand All @@ -550,46 +549,46 @@ const DeviceInstancePage: React.FC<Props> = props => {
return (
<PageHeaderWrapper title="设备实例">
<div className={styles.standardList}>
<Card bordered={false} style={{height: 95}}>
<Card bordered={false} style={{ height: 95 }}>
<Spin spinning={deviceCount.loading}>
<Row>
<Col sm={7} xs={24}>
<Select placeholder="选择设备产品" allowClear style={{width: '70%', marginTop: 7}} value={product}
onChange={(value: string) => {
setProduct(() => value);
setDeviceCount({loading: true});
onDeviceProduct(value);
}}
<Select placeholder="选择设备产品" allowClear style={{ width: '70%', marginTop: 7 }} value={product}
onChange={(value: string) => {
setProduct(() => value);
setDeviceCount({ loading: true });
onDeviceProduct(value);
}}
>
{productList?.map(item => (
<Select.Option key={item.id}>{item.name}</Select.Option>
))}
</Select>
</Col>
<Col sm={4} xs={24}>
<Info title="全部设备" value={deviceCount.deviceTotal}/>
<Info title="全部设备" value={deviceCount.deviceTotal} />
</Col>
<Col sm={4} xs={24}>
<Info title={<Badge status={statusMap.get('在线')} text="在线"/>} value={deviceCount.onlineCount}/>
<Info title={<Badge status={statusMap.get('在线')} text="在线" />} value={deviceCount.onlineCount} />
</Col>
<Col sm={4} xs={24}>
<Info title={<Badge status={statusMap.get('离线')} text="离线"/>} value={deviceCount.offlineCount}/>
<Info title={<Badge status={statusMap.get('离线')} text="离线" />} value={deviceCount.offlineCount} />
</Col>
<Col sm={4} xs={24}>
<Info title={<Badge status={statusMap.get('未激活')} text="未激活"/>} value={deviceCount.notActiveCount}/>
<Info title={<Badge status={statusMap.get('未激活')} text="未激活" />} value={deviceCount.notActiveCount} />
</Col>
<Col sm={1} xs={24}>
<Tooltip title='刷新'>
<Icon type="sync" style={{fontSize: 20}} onClick={() => {
setDeviceCount({loading: true});
<Icon type="sync" style={{ fontSize: 20 }} onClick={() => {
setDeviceCount({ loading: true });
stateCount(product);
}}/>
}} />
</Tooltip>
</Col>
</Row>
</Spin>
</Card>
<br/>
<br />
<Card bordered={false}>
<div className={styles.tableList}>
<div className={styles.tableListForm}>
Expand All @@ -602,7 +601,7 @@ const DeviceInstancePage: React.FC<Props> = props => {
params.productId = product;
}
params.state = searchParam.terms?.state;
handleSearch({terms: params, pageSize: 10, sorts: searchParam.sorts});
handleSearch({ terms: params, pageSize: 10, sorts: searchParam.sorts });
}}
/>
</div>
Expand All @@ -617,10 +616,10 @@ const DeviceInstancePage: React.FC<Props> = props => {
>
添加设备
</Button>
<Divider type="vertical"/>
<Divider type="vertical" />
<Dropdown overlay={menu}>
<Button icon="menu">
其他批量操作<Icon type="down"/>
其他批量操作<Icon type="down" />
</Button>
</Dropdown>
</div>
Expand Down Expand Up @@ -695,7 +694,7 @@ const DeviceInstancePage: React.FC<Props> = props => {
);
};

export default connect(({deviceInstance, loading}: ConnectState) => ({
export default connect(({ deviceInstance, loading }: ConnectState) => ({
deviceInstance,
loading: loading.models.deviceInstance,
}))(DeviceInstancePage);
Loading

0 comments on commit b84e115

Please sign in to comment.