瀏覽代碼

fix: bug#7673,7713

xieyonghong 3 年之前
父節點
當前提交
9d10652234

+ 7 - 2
src/components/DashBoard/timePicker.tsx

@@ -6,6 +6,7 @@ import { forwardRef, useEffect, useImperativeHandle, useState } from 'react';
 export enum TimeKey {
   'hour' = 'hour',
   'today' = 'today',
+  'yesterday' = 'yesterday',
   'week' = 'week',
   'month' = 'month',
   'year' = 'year',
@@ -61,8 +62,12 @@ export default forwardRef((props: ExtraTimePickerProps, ref) => {
   };
 
   const timeChange = (type: TimeType) => {
-    const endTime = moment(new Date()).valueOf();
-    const startTime: number = getTimeByType(type);
+    let endTime = moment(new Date()).valueOf();
+    let startTime: number = getTimeByType(type);
+    if (type === TimeKey.yesterday) {
+      startTime = moment().subtract(1, 'days').startOf('day').valueOf();
+      endTime = moment().subtract(1, 'days').endOf('day').valueOf();
+    }
     setRadioValue(type);
     change(startTime, endTime, type);
   };

+ 12 - 4
src/pages/iot-card/CardManagement/Detail/index.tsx

@@ -102,7 +102,8 @@ const CardDetail = () => {
       bottom: 0,
     };
     getData(dTime[0], dTime[1]).then((resp) => {
-      setTotal(resp.data.reduce((r, n) => r + n, 0));
+      const _total = resp.data.reduce((r, n) => r + n, 0);
+      setTotal(_total ? _total.toFixed(2) : 0);
       setDayOptions({
         ...DefaultEchartsOptions,
         grid,
@@ -142,7 +143,8 @@ const CardDetail = () => {
       });
     });
     getData(mTime[0], mTime[1]).then((resp) => {
-      setMonthTotal(resp.data.reduce((r, n) => r + n, 0));
+      const _total = resp.data.reduce((r, n) => r + n, 0);
+      setMonthTotal(_total ? _total.toFixed(2) : 0);
       setMonthOptions({
         ...DefaultEchartsOptions,
         grid,
@@ -182,7 +184,8 @@ const CardDetail = () => {
       });
     });
     getData(yTime[0], yTime[1]).then((resp) => {
-      setYearTotal(resp.data.reduce((r, n) => r + n, 0));
+      const _total = resp.data.reduce((r, n) => r + n, 0);
+      setYearTotal(_total ? _total.toFixed(2) : 0);
       setYearOptions({
         ...DefaultEchartsOptions,
         grid,
@@ -345,13 +348,18 @@ const CardDetail = () => {
                 title={'流量统计'}
                 options={options}
                 defaultTime={'week'}
+                timeToolOptions={[
+                  { label: '昨日', value: 'yesterday' },
+                  { label: '近一周', value: 'week' },
+                  { label: '近一月', value: 'month' },
+                ]}
                 showTime={true}
                 showTimeTool={true}
                 height={500}
                 onParamsChange={getEcharts}
               />
             </Col>
-            <Col flex={'480px'}>
+            <Col flex={'520px'}>
               <Card>
                 <div
                   style={{

+ 28 - 5
src/pages/iot-card/CardManagement/index.tsx

@@ -19,6 +19,7 @@ import {
   EditOutlined,
   LinkOutlined,
   EyeOutlined,
+  DisconnectOutlined,
 } from '@ant-design/icons';
 import ProTable from '@jetlinks/pro-table';
 import Service from './service';
@@ -44,7 +45,7 @@ const CardManagementNode = () => {
   const [current, setCurrent] = useState<Partial<CardManagement>>({});
   const [bindKeys, setBindKeys] = useState<any[]>([]);
   const { minHeight } = useDomFullHeight(`.iot-card-management`, 24);
-  const { permission } = PermissionButton.usePermission('device/Instance');
+  const { permission } = PermissionButton.usePermission('iot-card/CardManagement');
   const intl = useIntl();
   const history = useHistory();
   const location = useLocation();
@@ -126,24 +127,28 @@ const CardManagementNode = () => {
       title: '总流量',
       dataIndex: 'totalFlow',
       width: 120,
+      hideInSearch: true,
       render: (_, record) => (record.totalFlow ? record.totalFlow.toFixed(2) + ' M' : ''),
     },
     {
       title: '使用流量',
       dataIndex: 'usedFlow',
       width: 120,
+      hideInSearch: true,
       render: (_, record) => (record.usedFlow ? record.usedFlow.toFixed(2) + ' M' : ''),
     },
     {
       title: '剩余流量',
       dataIndex: 'residualFlow',
       width: 120,
+      hideInSearch: true,
       render: (_, record) => (record.residualFlow ? record.residualFlow.toFixed(2) + ' M' : ''),
     },
     {
       title: '激活日期',
       dataIndex: 'activationDate',
       width: 200,
+      valueType: 'dateTime',
       render: (_, record) =>
         record.activationDate ? moment(record.activationDate).format('YYYY-MM-DD HH:mm:ss') : '',
     },
@@ -151,6 +156,7 @@ const CardManagementNode = () => {
       title: '更新时间',
       dataIndex: 'updateTime',
       width: 200,
+      valueType: 'dateTime',
       render: (_, record) =>
         record.updateTime ? moment(record.updateTime).format('YYYY-MM-DD HH:mm:ss') : '',
     },
@@ -215,13 +221,30 @@ const CardManagementNode = () => {
             key="bindDevice"
             style={{ padding: 0 }}
             isPermission={permission.delete}
-            tooltip={{ title: '绑定设备' }}
+            tooltip={{ title: record.deviceId ? '解绑设备' : '绑定设备' }}
+            popConfirm={
+              record.deviceId
+                ? {
+                    title: '确认解绑设备?',
+                    onConfirm: () => {
+                      service.unbind(record.id).then((resp) => {
+                        if (resp.status === 200) {
+                          message.success('操作成功');
+                          actionRef.current?.reload();
+                        }
+                      });
+                    },
+                  }
+                : undefined
+            }
             onClick={() => {
-              setCurrent(record);
-              setBindDeviceVisible(true);
+              if (!record.deviceId) {
+                setCurrent(record);
+                setBindDeviceVisible(true);
+              }
             }}
           >
-            <LinkOutlined />
+            {record.deviceId ? <DisconnectOutlined /> : <LinkOutlined />}
           </PermissionButton>,
           record.cardStateType?.value === 'toBeActivated' ? (
             <PermissionButton

+ 2 - 1
src/pages/iot-card/Dashboard/index.less

@@ -40,8 +40,9 @@
 }
 
 .total {
-  flex: 0 0 50px;
+  flex: 0 0 80px;
   color: #999;
+  text-align: right;
 }
 
 .number-item-1 {

+ 12 - 8
src/pages/iot-card/Dashboard/index.tsx

@@ -62,8 +62,8 @@ const Dashboard = () => {
 
   const getDataTotal = () => {
     const dTime = [
-      moment().subtract(1, 'days').startOf('day').valueOf(),
-      moment().subtract(1, 'days').endOf('day').valueOf(),
+      moment(new Date()).startOf('day').valueOf(),
+      moment(new Date()).endOf('day').valueOf(),
     ];
     const mTime = [moment().startOf('month').valueOf(), moment().endOf('month').valueOf()];
     const yTime = [moment().startOf('year').valueOf(), moment().endOf('year').valueOf()];
@@ -263,8 +263,8 @@ const Dashboard = () => {
     getEcharts(echartsRef?.current?.getValues());
 
     const dTime = [
-      moment().subtract(1, 'days').startOf('day').valueOf(),
-      moment().subtract(6, 'days').endOf('day').valueOf(),
+      moment().subtract(6, 'days').startOf('day').valueOf(),
+      moment().endOf('day').valueOf(),
     ];
     getTopRang(dTime[0], dTime[1]);
   }, []);
@@ -324,6 +324,11 @@ const Dashboard = () => {
             options={options}
             onParamsChange={getEcharts}
             defaultTime={'week'}
+            timeToolOptions={[
+              { label: '昨日', value: 'yesterday' },
+              { label: '近一周', value: 'week' },
+              { label: '近一月', value: 'month' },
+            ]}
           />
         </Col>
         <Col flex={'520px'}>
@@ -334,10 +339,8 @@ const Dashboard = () => {
                 {
                   // @ts-ignore
                   <DatePicker.RangePicker
-                    defaultPickerValue={[
-                      moment().subtract(1, 'days').startOf('day'),
-                      moment().subtract(1, 'days').endOf('day'),
-                    ]}
+                    defaultValue={[moment().subtract(6, 'days'), moment(new Date(), 'YYYY-MM-DD')]}
+                    format={'YYYY-MM-DD'}
                     onChange={(dates) => {
                       getTopRang(dates?.[0].valueOf(), dates?.[1].valueOf());
                     }}
@@ -361,6 +364,7 @@ const Dashboard = () => {
                           strokeColor={'#ADC6FF'}
                           trailColor={'#E0E4E8'}
                           strokeLinecap="butt"
+                          showInfo={false}
                           percent={Math.ceil((item.value / topTotal) * 100)}
                         />
                       </div>