Forráskód Böngészése

Merge branch 'master' of http://182.92.126.35:3000/hrx/mky-vent-base

lxh 1 hete
szülő
commit
cda94bd41c

+ 29 - 6
src/views/vent/comment/history/HistoryTable.vue

@@ -11,6 +11,7 @@
       </template>
       <template #form-submitBefore>
         <a-button type="primary" preIcon="ant-design:search-outlined" @click="search">查询</a-button>
+        <a-button type="primary" preIcon="ant-design:export-outlined" @click="exportXls"> 导出</a-button>
       </template>
     </BasicTable>
   </div>
@@ -54,7 +55,7 @@
   import { BasicColumn, PaginationProps, BasicTable } from '/@/components/Table';
   import { getTableHeaderColumns } from '/@/hooks/web/useWebColumns';
   import { defaultFormProps, defaultPaginationProps, getDefaultSchemas, defaultTableProps } from './history.data';
-  import { getDeviceList, list } from './history.api';
+  import { adaptFormData, getDeviceList, getExportUrl, list } from './history.api';
   import { useListPage } from '/@/hooks/system/useListPage';
   import { initDictOptions } from '/@/utils/dict';
 
@@ -89,7 +90,13 @@
 
   // 创建表格,此表格目前不具备常用功能,需要初始化后使用(props指定表格配置时除外)
   let originColumns: BasicColumn[] = [];
-  const { tableContext } = useListPage({ tableProps: defaultTableProps });
+  const { tableContext, onExportXls, onExportXlsPost } = useListPage({
+    tableProps: defaultTableProps,
+    exportConfig: {
+      name: '设备历史列表',
+      url: () => getExportUrl(deviceInfo.value),
+    },
+  });
   const [register, { getForm, setLoading, getPaginationRef, setPagination, setProps, setColumns }] = tableContext;
 
   /**
@@ -197,7 +204,7 @@
       };
     });
     deviceOptions.value = options;
-    deviceInfo.value = results[0];
+    deviceInfo.value = results[0] || {};
     dictOptions.value = dicts;
   }
 
@@ -210,19 +217,35 @@
     const form = getForm();
     await form.validate();
     const formData = form.getFieldsValue();
-    deviceInfo.value = deviceOptions.value.find((opt) => {
+    const info = deviceOptions.value.find((opt) => {
       return opt.value === formData.gdeviceids.split(',')[0];
-    }) as Record<string, unknown>;
+    });
+    if (!info) return;
+    deviceInfo.value = info;
     const code = (deviceInfo.value.deviceType || props.deviceCode.concat('*')) as string;
     await fetchData(formData, code, deviceInfo.value);
     updateColumns(formData.deviceNum);
   }
 
+  /** 导出表格内容为excel */
+  async function exportXls() {
+    const form = getForm();
+    await form.validate();
+    const formData = form.getFieldsValue();
+    const pagination = getPaginationRef() as PaginationProps;
+    const params = adaptFormData(props.deviceCode, deviceInfo.value, formData, pagination);
+    if (deviceInfo.value.stationtype === 'redis') {
+      return onExportXlsPost(params);
+    } else {
+      return onExportXls(params);
+    }
+  }
+
   onMounted(async () => {
     await fetchDevice();
     // 生成所有需要查询的表头编码,例如 forcFan_auto 对应 forcFan_auto_history、forcFan_history 这两个
     const codes: string[] = [];
-    if (deviceInfo.value.deviceType) {
+    if (deviceInfo.value && deviceInfo.value.deviceType) {
       const arr = (deviceInfo.value.deviceType as string).split('_');
       while (arr.length) {
         codes.push(arr.join('_').concat('_history'));

+ 37 - 19
src/views/vent/comment/history/history.api.ts

@@ -5,6 +5,8 @@ enum Api {
   listdays = '/safety/ventanalyMonitorData/listdays',
   getDeviceList = '/monitor/device',
   getHistoryData = '/monitor/history/getHistoryData',
+  historydata = '/safety/ventanalyMonitorData/export/historydata',
+  exportHistoryData = '/monitor/history/exportHistoryData',
 }
 /**
  * 获取列表的接口
@@ -26,33 +28,41 @@ const intervalMap = new Map([
   ['8', '1h'],
 ]);
 
+export const adaptFormData = (deviceCode: string, deviceInfo: any, formData: any, pagination: PaginationProps) => {
+  if (deviceInfo.stationtype === 'redis') {
+    return {
+      pageNum: pagination.current,
+      pageSize: pagination.pageSize,
+      column: 'createTime',
+      startTime: formData.ttime_begin,
+      endTime: formData.ttime_end,
+      deviceId: formData.gdeviceids,
+      strtype: deviceCode,
+      interval: intervalMap.get(formData['skip']) || '1h',
+      isEmployee: deviceCode.startsWith('vehicle') ? false : true,
+    };
+  } else {
+    return {
+      pageNo: pagination.current,
+      pageSize: pagination.pageSize,
+      column: 'createTime',
+      strtype: deviceCode,
+      ...formData,
+    };
+  }
+};
+
 export const list = (deviceCode: string, deviceInfo: any, formData: any, pagination: PaginationProps) => {
-  if (deviceInfo.stationType === 'redis') {
+  if (deviceInfo.stationtype === 'redis') {
     return defHttp.post({
       url: Api.getHistoryData,
-      params: {
-        pageNum: pagination.current,
-        pageSize: pagination.pageSize,
-        column: 'createTime',
-        startTime: formData.ttime_begin,
-        endTime: formData.ttime_end,
-        deviceId: formData.gdeviceids,
-        strtype: deviceCode,
-        interval: intervalMap.get(formData['skip']) || '1h',
-        isEmployee: deviceCode.startsWith('vehicle') ? false : true,
-      },
+      params: adaptFormData(deviceCode, deviceInfo, formData, pagination),
     });
   } else {
     return defHttp
       .get({
         url: Api.listdays,
-        params: {
-          pageNo: pagination.current,
-          pageSize: pagination.pageSize,
-          column: 'createTime',
-          strtype: deviceCode,
-          ...formData,
-        },
+        params: adaptFormData(deviceCode, deviceInfo, formData, pagination),
       })
       .then((r) => {
         if (r.datalist) return r.datalist;
@@ -61,6 +71,14 @@ export const list = (deviceCode: string, deviceInfo: any, formData: any, paginat
   }
 };
 
+export const getExportUrl = (deviceInfo) => {
+  if (deviceInfo.stationtype === 'redis') {
+    return Api.exportHistoryData;
+  } else {
+    return Api.historydata;
+  }
+};
+
 /**
  * 根据设备编码获取设备列表
  * @param params

+ 131 - 127
src/views/vent/comment/history/history.data.ts

@@ -10,137 +10,141 @@ import { get } from 'lodash-es';
  * @param deviceOptions 用于初始化设备下拉框
  * @returns
  */
-export const getDefaultSchemas: (dictOptions: any[], deviceOptions: any[]) => FormSchema[] = (dictOptions: any[], deviceOptions: any[]) => [
-  {
-    field: 'ttime_begin',
-    label: '开始时间',
-    component: 'DatePicker',
-    defaultValue: dayjs().startOf('date'),
-    required: true,
-    componentProps: {
-      showTime: true,
-      valueFormat: 'YYYY-MM-DD HH:mm:ss',
-      getPopupContainer: getAutoScrollContainer,
-    },
-    colProps: {
-      span: 4,
-    },
-  },
-  {
-    field: 'ttime_end',
-    label: '结束时间',
-    component: 'DatePicker',
-    defaultValue: dayjs(),
-    required: true,
-    componentProps: {
-      showTime: true,
-      valueFormat: 'YYYY-MM-DD HH:mm:ss',
-      getPopupContainer: getAutoScrollContainer,
-    },
-    colProps: {
-      span: 4,
-    },
-  },
-  {
-    label: '查询设备',
-    field: 'gdeviceids',
-    component: 'Select',
-    required: true,
-    defaultValue:
-      get(deviceOptions, '[0].stationtype', 'redis') === 'redis' ? get(deviceOptions, '[0].value', '') : [get(deviceOptions, '[0].value', '')],
-    componentProps: {
-      options: deviceOptions,
-      // onChange: (e, option) => {
-      mode: get(deviceOptions, '[0].stationtype', 'redis') === 'redis' ? undefined : 'multiple',
-      maxTagCount: 'responsive',
-      //   nextTick(async () => {
-      //     await getDataSource();
-      //   });
-      // },
-    },
-    colProps: {
-      span: 4,
+export const getDefaultSchemas: (dictOptions: any[], deviceOptions: any[]) => FormSchema[] = (dictOptions: any[], deviceOptions: any[]) => {
+  const device = get(deviceOptions, '[0].value', '');
+  const dictcode = get(dictOptions, '[0].value', '');
+  const isRedis = get(deviceOptions, '[0].stationtype', 'redis') === 'redis';
+  return [
+    {
+      field: 'ttime_begin',
+      label: '开始时间',
+      component: 'DatePicker',
+      defaultValue: dayjs().startOf('date'),
+      required: true,
+      componentProps: {
+        showTime: true,
+        valueFormat: 'YYYY-MM-DD HH:mm:ss',
+        getPopupContainer: getAutoScrollContainer,
+      },
+      colProps: {
+        span: 4,
+      },
     },
-  },
-  {
-    label: '子设备',
-    field: 'deviceNum',
-    component: 'Select',
-    required: Boolean(dictOptions.length),
-    show: Boolean(dictOptions.length),
-    defaultValue: dictOptions[0] ? dictOptions[0].value : '',
-    componentProps: {
-      options: dictOptions,
-      // onChange: (e, option) => {
-      //   nextTick(async () => {
-      //     await getDataSource();
-      //   });
-      // },
+    {
+      field: 'ttime_end',
+      label: '结束时间',
+      component: 'DatePicker',
+      defaultValue: dayjs(),
+      required: true,
+      componentProps: {
+        showTime: true,
+        valueFormat: 'YYYY-MM-DD HH:mm:ss',
+        getPopupContainer: getAutoScrollContainer,
+      },
+      colProps: {
+        span: 4,
+      },
     },
-    colProps: {
-      span: 4,
+    {
+      label: '查询设备',
+      field: 'gdeviceids',
+      component: 'Select',
+      required: true,
+      defaultValue: isRedis ? device : [device],
+      componentProps: {
+        options: deviceOptions,
+        // onChange: (e, option) => {
+        mode: isRedis ? undefined : 'multiple',
+        maxTagCount: 'responsive',
+        //   nextTick(async () => {
+        //     await getDataSource();
+        //   });
+        // },
+      },
+      colProps: {
+        span: 4,
+      },
     },
-  },
-  // {
-  //   label: '子设备',
-  //   field: 'deviceNum',
-  //   // component: 'JDictSelectTag',
-  //   // show: Boolean(dictCode),
-  //   componentProps: {
-  //     dictCode,
-  //     showChooseOption: false,
-  //     placeholder: '请选择',
-  //   },
-  //   colProps: {
-  //     span: 4,
-  //   },
-  // },
-  {
-    label: '间隔时间',
-    field: 'skip',
-    component: 'Select',
-    defaultValue: '8',
-    componentProps: {
-      options: [
-        {
-          label: '1秒',
-          value: '1',
-        },
-        {
-          label: '5秒',
-          value: '2',
-        },
-        {
-          label: '10秒',
-          value: '3',
-        },
-        {
-          label: '30秒',
-          value: '4',
-        },
-        {
-          label: '1分钟',
-          value: '5',
-        },
-        {
-          label: '10分钟',
-          value: '6',
-        },
-        {
-          label: '30分钟',
-          value: '7',
-        },
-        {
-          label: '1小时',
-          value: '8',
-        },
-      ],
+    {
+      label: '子设备',
+      field: 'deviceNum',
+      component: 'Select',
+      required: isRedis ? false : Boolean(dictOptions.length),
+      show: isRedis ? false : Boolean(dictOptions.length),
+      defaultValue: isRedis ? '' : dictcode,
+      componentProps: {
+        options: dictOptions,
+        // onChange: (e, option) => {
+        //   nextTick(async () => {
+        //     await getDataSource();
+        //   });
+        // },
+      },
+      colProps: {
+        span: 4,
+      },
     },
-    colProps: {
-      span: 4,
+    // {
+    //   label: '子设备',
+    //   field: 'deviceNum',
+    //   // component: 'JDictSelectTag',
+    //   // show: Boolean(dictCode),
+    //   componentProps: {
+    //     dictCode,
+    //     showChooseOption: false,
+    //     placeholder: '请选择',
+    //   },
+    //   colProps: {
+    //     span: 4,
+    //   },
+    // },
+    {
+      label: '间隔时间',
+      field: 'skip',
+      component: 'Select',
+      defaultValue: '8',
+      componentProps: {
+        options: [
+          {
+            label: '1秒',
+            value: '1',
+          },
+          {
+            label: '5秒',
+            value: '2',
+          },
+          {
+            label: '10秒',
+            value: '3',
+          },
+          {
+            label: '30秒',
+            value: '4',
+          },
+          {
+            label: '1分钟',
+            value: '5',
+          },
+          {
+            label: '10分钟',
+            value: '6',
+          },
+          {
+            label: '30分钟',
+            value: '7',
+          },
+          {
+            label: '1小时',
+            value: '8',
+          },
+        ],
+      },
+      colProps: {
+        span: 4,
+      },
     },
-  },
-];
+  ];
+};
 
 /** 默认的表格props,参考 BasicTable 组件 */
 export const defaultTableProps: BasicTableProps = {
@@ -165,7 +169,7 @@ export const defaultFormProps: FormProps = {
   labelCol: { span: 8 },
   showAdvancedButton: false,
   showSubmitButton: false,
-  showResetButton: true,
+  showResetButton: false,
 };
 
 /** 默认的表格分页props,参考 BasicTable 组件 */

+ 12 - 18
src/views/vent/monitorManager/comment/HistoryTable.vue

@@ -254,39 +254,34 @@
       stationType.value = deviceOptions.value[0]['stationtype'];
       historyType.value = deviceOptions.value[0]['strtype'] || deviceOptions.value[0]['devicekind'];
     }
-    await getForm().setFieldsValue({
-      gdeviceids: props.deviceId ? [props.deviceId] : deviceOptions.value[0] ? [deviceOptions.value[0]['value']] : [''],
-    });
     if (stationType.value !== 'redis') {
-      // await getForm().updateSchema({
-      //   field: 'gdeviceids',
-      //   defaultValue: [props.deviceId ? props.deviceId : deviceOptions.value[0] ? deviceOptions.value[0]['value'] : ''],
-      //   componentProps: {
-      //     mode: 'multiple',
-      //     maxTagCount: 'responsive',
-      //   },
-      // });
-      // 暂时处理为单选
+      await getForm().setFieldsValue({
+        gdeviceids: [props.deviceId ? props.deviceId : deviceOptions.value[0] ? deviceOptions.value[0]['value'] : ''],
+      });
       await getForm().updateSchema({
         field: 'gdeviceids',
-        defaultValue: props.deviceId ? props.deviceId : deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
+        componentProps: {
+          mode: 'multiple',
+          maxTagCount: 'responsive',
+        },
       });
     } else {
+      await getForm().setFieldsValue({
+        gdeviceids: props.deviceId ? props.deviceId : deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
+      });
       await getForm().updateSchema({
         field: 'gdeviceids',
-        defaultValue: props.deviceId ? props.deviceId : deviceOptions.value[0] ? deviceOptions.value[0]['value'] : '',
       });
     }
   }
 
   function resetFormParam() {
-    const stationTypeStr = stationType.value;
     const formData = getForm().getFieldsValue();
     const pagination = getPaginationRef();
     formData['pageNo'] = pagination['current'];
     formData['pageSize'] = pagination['pageSize'];
     formData['column'] = 'createTime';
-    if (stationTypeStr !== 'redis') {
+    if (stationType.value !== 'redis') {
       formData['strtype'] = deviceTypeStr.value
         ? deviceTypeStr.value
         : deviceOptions.value[0]['strtype']
@@ -314,11 +309,10 @@
   }
 
   async function getDataSource() {
-    const stationTypeStr = stationType.value;
     dataSource.value = [];
     setLoading(true);
     const params = await resetFormParam();
-    if (stationTypeStr !== 'redis') {
+    if (stationType.value !== 'redis') {
       const result = await defHttp.get({ url: '/safety/ventanalyMonitorData/listdays', params: params });
       setPagination({ total: Math.abs(result['datalist']['total']) || 0 });
       if (result['datalist']['records'].length > 0) {

+ 7 - 0
src/views/vent/monitorManager/deviceMonitor/components/device/index.vue

@@ -547,6 +547,12 @@
               <template v-if="deviceType.startsWith('firemon_normal')">
                 <HistoryBall :dataSource="dataSource"></HistoryBall>
               </template>
+              <template v-if="deviceType.startsWith('fanmain')">
+                <HistoryTableNew class="w-100% h-100%" :device-code="`${deviceType}`" :scroll="scroll" dict-code="fan_dict" />
+              </template>
+              <template v-if="deviceType.startsWith('fanlocal')">
+                <HistoryTableNew class="w-100% h-100%" :device-code="`${deviceType}`" :scroll="scroll" dict-code="fanlocal_dict" />
+              </template>
               <template v-else>
                 <HistoryTable
                   ref="historyTable"
@@ -616,6 +622,7 @@
   } from './device.api';
   import AlarmHistoryTable from '../../../comment/AlarmHistoryTable.vue';
   import HistoryTable from '../../../comment/HistoryTable.vue';
+  import HistoryTableNew from '/@/views/vent/comment/history/HistoryTable.vue';
   import HandlerHistoryTable from '../../../comment/HandlerHistoryTable.vue';
   import MonitorTable from '../../../comment/MonitorTable.vue';
   import GroupMonitorTable from '../../../comment/GroupMonitorTable.vue';