Browse Source

fix: 完善api对接

master
wally 4 years ago
parent
commit
3a34a4ce96
  1. 16
      src/components/history/device.vue
  2. 83
      src/components/history/history-log-table.vue
  3. 30
      src/components/history/history-log.vue
  4. 15
      src/components/history/local.vue
  5. 6
      src/components/history/search-history-log.vue
  6. 4
      src/config/chart.js
  7. 4
      src/utils/statistical.js
  8. 2
      src/views/commands.vue
  9. 8
      src/views/data-realtime.vue
  10. 5
      src/views/device-list.vue
  11. 3
      src/views/statistical-report.vue

16
src/components/history/device.vue

@ -3,7 +3,7 @@
<template v-if="data"> <template v-if="data">
<el-table :data="data" :max-height="contentHeight" border stripe style="width: 100%"> <el-table :data="data" :max-height="contentHeight" border stripe style="width: 100%">
<el-table-column align="center" fixed label="设备ID" min-width="80" prop="deviceNo" /> <el-table-column align="center" fixed label="设备ID" min-width="80" prop="deviceId" />
<el-table-column align="center" label="采集时间" min-width="170"> <el-table-column align="center" label="采集时间" min-width="170">
<template #default="scope"> <template #default="scope">
{{ formatTime(+scope.row.time) }} {{ formatTime(+scope.row.time) }}
@ -22,8 +22,8 @@
<el-table-column align="center" label="环境湿度(RH%)" min-width="130" prop="environmentHumidity" /> <el-table-column align="center" label="环境湿度(RH%)" min-width="130" prop="environmentHumidity" />
<el-table-column align="center" label="SO2(ppb)" min-width="90" prop="so2" /> <el-table-column align="center" label="SO2(ppb)" min-width="90" prop="so2" />
<!-- TODO:--> <!-- TODO:-->
<el-table-column align="center" label="盐分温度(℃)" min-width="110" prop="salt" /> <el-table-column align="center" label="盐分温度(℃)" min-width="110" prop="saltT" />
<el-table-column align="center" label="盐分阻抗(Ω)" min-width="110" prop="salt" /> <el-table-column align="center" label="盐分阻抗(Ω)" min-width="110" prop="saltR" />
<el-table-column align="center" label="机箱温度(℃)" min-width="110" prop="deviceTemperature" /> <el-table-column align="center" label="机箱温度(℃)" min-width="110" prop="deviceTemperature" />
<el-table-column align="center" label="机箱湿度(RH%)" min-width="130" prop="deviceHumidity" /> <el-table-column align="center" label="机箱湿度(RH%)" min-width="130" prop="deviceHumidity" />
<el-table-column align="center" label="太阳能板电压(V)" min-width="140" prop="solarVoltage" /> <el-table-column align="center" label="太阳能板电压(V)" min-width="140" prop="solarVoltage" />
@ -97,10 +97,12 @@ const getData = async () => {
paging: true, paging: true,
page: page.value.page, page: page.value.page,
size: page.value.size, size: page.value.size,
sort: { sort: [
col: 'gathered_at', {
order: 'DESC', col: 'time',
}, order: 'DESC',
},
],
}; };
loadingSearch.value = true; loadingSearch.value = true;

83
src/components/history/history-log-table.vue

@ -1,6 +1,6 @@
<template> <template>
<template v-if="devicesAll && devicesAll.data"> <template v-if="data">
<el-table :data="devicesAll.data" :max-height="contentHeight" border class="mt-6" stripe style="width: 100%"> <el-table :data="data" :max-height="contentHeight" border class="mt-6" stripe style="width: 100%">
<el-table-column align="center" label="设备ID" min-min-width="100" prop="deviceId" /> <el-table-column align="center" label="设备ID" min-min-width="100" prop="deviceId" />
<el-table-column align="center" label="开始时间" min-width="200"> <el-table-column align="center" label="开始时间" min-width="200">
<template #default="scope"> <template #default="scope">
@ -23,91 +23,20 @@
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
<el-pagination
:current-page="devicesAll.page.page"
:default-page-size="50"
:page-count="devicesAll.page.count"
:page-size="devicesAll.page.size"
:page-sizes="[1, 10, 20, 50, 100]"
:total="devicesAll.page.total"
background
class="my-3 float-right"
layout="total, sizes, prev, pager, next, jumper"
@size-change="onSizeChange"
@current-change="onCurrentPageChange"
></el-pagination>
</template> </template>
<!-- 编辑设备信息 -->
<DeviceEdit :show="editing" @toggle-mdoal="editing = false" />
</template> </template>
<script setup> <script setup>
import { computed, onMounted, ref } from 'vue'; import { defineProps, onMounted, ref } from 'vue';
import { useStore } from 'vuex';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import DeviceEdit from 'components/device/device-edit.vue';
import StatusTagPending from 'components/config/status-tag-pending.vue';
import { PENDING_TYPE } from '@/config/config'; import { PENDING_TYPE } from '@/config/config';
let timer = null; defineProps({ data: Object });
const store = useStore();
const token = computed(() => store.getters['user/token']);
const devicesAll = computed(() => {
return store.state.device.devicesAll;
});
const currentDeviceId = computed(() => store.state.device.currentDeviceId);
const contentHeight = ref(600);
const editing = ref(false);
//
const getDevicesAllData = () => {
try {
if (token && token.value) {
store.dispatch('device/getDevicesAll');
timer && clearTimeout(timer);
timer = null;
} else {
timer = setTimeout(() => {
getDevicesAllData();
});
}
} catch (error) {
throw new Error(error);
}
};
getDevicesAllData(); const contentHeight = ref(600);
//
onMounted(() => { onMounted(() => {
const winHeight = document.documentElement.clientHeight; const winHeight = document.documentElement.clientHeight;
contentHeight.value = winHeight - 250; contentHeight.value = winHeight - 150;
}); });
/**
* 删除
* @param {number} page 页码
* @param {number} size 每页条数
*/
function onSearch(page, size = 50) {
const deviceId = currentDeviceId.value;
const params = {
deviceId,
page,
size,
};
store.dispatch('device/getDevicesAll', params);
}
//
const onCurrentPageChange = page => {
onSearch(page, devicesAll.value.page.size || 50);
};
//
const onSizeChange = size => {
onSearch(1, size);
};
</script> </script>

30
src/components/history/history-log.vue

@ -1,35 +1,35 @@
<template> <template>
<SearchHistoryLog @search="onSearch" /> <SearchHistoryLog @search="getData" />
<TableHistoryLog /> <TableHistoryLog :data="data" />
</template> </template>
<script setup> <script setup>
import { computed } from 'vue'; import { computed, ref } from 'vue';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import { getSendHistory } from 'apis'; import { getSendHistory } from 'apis';
import { ElMessage } from 'element-plus';
import SearchHistoryLog from 'components/history/search-history-log.vue'; import SearchHistoryLog from 'components/history/search-history-log.vue';
import TableHistoryLog from 'components/history/history-log-table.vue'; import TableHistoryLog from 'components/history/history-log-table.vue';
const store = useStore(); const store = useStore();
const currentDeviceId = computed(() => store.state.device.currentDeviceId); // id const currentDeviceId = computed(() => store.state.device.currentDeviceId); // id
async function getData() { const data = ref([]);
async function getData(
params = {
deviceId: currentDeviceId.value,
status: '',
type: '',
},
) {
try { try {
const params = {
deviceId: currentDeviceId.value,
status: 'DATA',
type: 'EVENT',
};
const resData = await getSendHistory(params); const resData = await getSendHistory(params);
console.log(resData); data.value = resData ? [...resData] : [];
} catch (error) { } catch (error) {
console.error(error); ElMessage.error(error.message || '查询失败');
} }
} }
getData(); getData();
function onSearch(event) {
console.log(event);
}
</script> </script>

15
src/components/history/local.vue

@ -3,7 +3,7 @@
<template v-if="data"> <template v-if="data">
<el-table :data="data" :max-height="contentHeight" border stripe style="width: 100%"> <el-table :data="data" :max-height="contentHeight" border stripe style="width: 100%">
<el-table-column align="center" fixed label="设备ID" min-width="80" prop="deviceNo" /> <el-table-column align="center" fixed label="设备ID" min-width="80" prop="deviceId" />
<el-table-column align="center" label="采集时间" min-width="170"> <el-table-column align="center" label="采集时间" min-width="170">
<template #default="scope"> <template #default="scope">
{{ formatTime(+scope.row.time) }} {{ formatTime(+scope.row.time) }}
@ -21,8 +21,8 @@
<el-table-column align="center" label="环境温度(℃)" min-width="110" prop="environmentTemperature" /> <el-table-column align="center" label="环境温度(℃)" min-width="110" prop="environmentTemperature" />
<el-table-column align="center" label="环境湿度(RH%)" min-width="130" prop="environmentHumidity" /> <el-table-column align="center" label="环境湿度(RH%)" min-width="130" prop="environmentHumidity" />
<el-table-column align="center" label="SO2(ppb)" min-width="90" prop="so2" /> <el-table-column align="center" label="SO2(ppb)" min-width="90" prop="so2" />
<el-table-column align="center" label="盐分温度(℃)" min-width="110" prop="salt" /> <el-table-column align="center" label="盐分温度(℃)" min-width="110" prop="saltT" />
<el-table-column align="center" label="盐分阻抗(Ω)" min-width="110" prop="salt" /> <el-table-column align="center" label="盐分阻抗(Ω)" min-width="110" prop="saltR" />
<el-table-column align="center" label="太阳能板电压(V)" min-width="140" prop="solarVoltage" /> <el-table-column align="center" label="太阳能板电压(V)" min-width="140" prop="solarVoltage" />
<el-table-column align="center" label="蓄电池电压(V)" min-width="120" prop="batteryVoltage" /> <el-table-column align="center" label="蓄电池电压(V)" min-width="120" prop="batteryVoltage" />
<el-table-column align="center" label="机箱温度(℃)" min-width="110" prop="deviceTemperature" /> <el-table-column align="center" label="机箱温度(℃)" min-width="110" prop="deviceTemperature" />
@ -51,7 +51,7 @@
import { computed, onMounted, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import SearchBar from 'components/history/search-bar-data.vue'; import SearchBar from 'components/history/search-bar-data.vue';
import { getHistory } from 'apis'; import { getDatas } from 'apis';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@ -76,7 +76,6 @@ const getData = async () => {
} }
const options = { ...search.value }; const options = { ...search.value };
console.log('options:', options);
const date = options && options.date ? options.date : []; const date = options && options.date ? options.date : [];
if (!date || date.length !== 2) { if (!date || date.length !== 2) {
return ElMessage.error('请选择时间 '); return ElMessage.error('请选择时间 ');
@ -89,12 +88,12 @@ const getData = async () => {
size: page.value.size, size: page.value.size,
sort: [ sort: [
{ {
col: 'gathered_at', col: 'time',
order: 'DESC', order: 'DESC',
}, },
], ],
}; };
const resData = await getHistory(params); const resData = await getDatas(params);
data.value = resData.data; data.value = resData.data;
page.value = resData.page; page.value = resData.page;
timer && clearTimeout(timer); timer && clearTimeout(timer);
@ -115,7 +114,7 @@ const getData = async () => {
// //
onMounted(() => { onMounted(() => {
const winHeight = document.documentElement.clientHeight; const winHeight = document.documentElement.clientHeight;
contentHeight.value = winHeight - 350; contentHeight.value = winHeight - 250;
}); });
/** /**

6
src/components/history/search-history-log.vue

@ -1,5 +1,5 @@
<template> <template>
<el-form ref="searchDeviceForm" :inline="true" :model="searchDevice"> <el-form ref="searchHistoryLogForm" :inline="true" :model="searchDevice">
<el-form-item label="选择站点"> <el-form-item label="选择站点">
<el-select v-model="searchDevice.deviceId" placeholder="请选择站点" @change="change"> <el-select v-model="searchDevice.deviceId" placeholder="请选择站点" @change="change">
<el-option label="全部" value></el-option> <el-option label="全部" value></el-option>
@ -48,7 +48,7 @@ const searchDevice = reactive({
type: '', type: '',
status: '', status: '',
}); });
const searchDeviceForm = ref(null); // form const searchHistoryLogForm = ref(null); // form
const store = useStore(); const store = useStore();
const devices = computed(() => store.state.device.devices); const devices = computed(() => store.state.device.devices);
const currentDeviceId = computed(() => store.state.device.currentDeviceId); // id const currentDeviceId = computed(() => store.state.device.currentDeviceId); // id
@ -70,7 +70,7 @@ const change = e => {
// //
const onSubmit = () => { const onSubmit = () => {
searchDeviceForm.value.validate(() => { searchHistoryLogForm.value.validate(() => {
emit('search', { ...searchDevice }); emit('search', { ...searchDevice });
}); });
}; };

4
src/config/chart.js

@ -74,7 +74,7 @@ export const yAxisData = [
show: true, show: true,
lineStyle: { color: colors[3] }, lineStyle: { color: colors[3] },
}, },
axisLabel: { formatter: '{value}ppb' }, axisLabel: { formatter: '{value}' },
axisPointer: { show: false }, axisPointer: { show: false },
}, },
{ {
@ -87,7 +87,7 @@ export const yAxisData = [
show: true, show: true,
lineStyle: { color: colors[4] }, lineStyle: { color: colors[4] },
}, },
axisLabel: { formatter: '{value}Ω' }, axisLabel: { formatter: '{value}' },
axisPointer: { show: false }, axisPointer: { show: false },
}, },
]; ];

4
src/utils/statistical.js

@ -55,7 +55,6 @@ function generateParams(data) {
export function computeYAxisShow(yName, selectedLegend) { export function computeYAxisShow(yName, selectedLegend) {
// eslint-disable-next-line guard-for-in,no-restricted-syntax // eslint-disable-next-line guard-for-in,no-restricted-syntax
for (const key in selectedLegend) { for (const key in selectedLegend) {
console.log('key:', key, yName);
if (key.includes(yName) && selectedLegend[key]) { if (key.includes(yName) && selectedLegend[key]) {
return true; return true;
} }
@ -132,7 +131,7 @@ function generateGrid(yAxis) {
}); });
return { return {
left: max(left) + 100, left: max(left) + 100,
right: max(right) + 45, right: max(right) + 80,
}; };
} }
@ -173,6 +172,5 @@ export function generateChartOption(rawData, selected = defaultSelectedLegend) {
yAxis, yAxis,
series, series,
}; };
console.log(option);
return option; return option;
} }

2
src/views/commands.vue

@ -39,7 +39,7 @@
<el-table-column align="center" label="类型标识" min-width="80"> <el-table-column align="center" label="类型标识" min-width="80">
<template #default="scope"> <template #default="scope">
{{ log.ASDU_TYPE[scope.row.asduType].text }} <span v-if="scope.row.asduType && log.ASDU_TYPE[scope.row.asduType]">{{ log.ASDU_TYPE[scope.row.asduType].text }}</span>
</template> </template>
</el-table-column> </el-table-column>
<el-table-column align="center" label="信息体顺序" min-width="100"> <el-table-column align="center" label="信息体顺序" min-width="100">

8
src/views/data-realtime.vue

@ -3,7 +3,7 @@
<template v-if="data"> <template v-if="data">
<el-table :data="data" :max-height="contentHeight" border stripe style="width: 100%"> <el-table :data="data" :max-height="contentHeight" border stripe style="width: 100%">
<el-table-column align="center" fixed label="设备ID" min-width="80" prop="deviceNo" /> <el-table-column align="center" fixed label="设备ID" min-width="80" prop="deviceId" />
<el-table-column align="center" label="采集时间" min-width="170"> <el-table-column align="center" label="采集时间" min-width="170">
<template #default="scope"> <template #default="scope">
{{ formatTime(+scope.row.time) }} {{ formatTime(+scope.row.time) }}
@ -22,8 +22,8 @@
<el-table-column align="center" label="环境湿度(RH%)" min-width="130" prop="environmentHumidity" /> <el-table-column align="center" label="环境湿度(RH%)" min-width="130" prop="environmentHumidity" />
<el-table-column align="center" label="SO2(ppb)" min-width="90" prop="so2" /> <el-table-column align="center" label="SO2(ppb)" min-width="90" prop="so2" />
<!-- TODO:--> <!-- TODO:-->
<el-table-column align="center" label="盐分温度(℃)" min-width="110" prop="salt" /> <el-table-column align="center" label="盐分温度(℃)" min-width="110" prop="saltT" />
<el-table-column align="center" label="盐分阻抗(Ω)" min-width="110" prop="salt" /> <el-table-column align="center" label="盐分阻抗(Ω)" min-width="110" prop="saltR" />
<el-table-column align="center" label="机箱温度(℃)" min-width="110" prop="deviceTemperature" /> <el-table-column align="center" label="机箱温度(℃)" min-width="110" prop="deviceTemperature" />
<el-table-column align="center" label="机箱湿度(RH%)" min-width="130" prop="deviceHumidity" /> <el-table-column align="center" label="机箱湿度(RH%)" min-width="130" prop="deviceHumidity" />
<el-table-column align="center" label="太阳能板电压(V)" min-width="140" prop="solarVoltage" /> <el-table-column align="center" label="太阳能板电压(V)" min-width="140" prop="solarVoltage" />
@ -96,7 +96,7 @@ const getData = async () => {
size: page.value.size, size: page.value.size,
sort: [ sort: [
{ {
col: 'gathered_at', col: 'createdAt',
order: 'DESC', order: 'DESC',
}, },
], ],

5
src/views/device-list.vue

@ -20,7 +20,10 @@
<el-col :span="9">安装位置{{ props.row.installLocation }}</el-col> <el-col :span="9">安装位置{{ props.row.installLocation }}</el-col>
<el-col :span="9">sim1{{ props.row.sim1 }}</el-col> <el-col :span="9">sim1{{ props.row.sim1 }}</el-col>
<el-col :span="9">协议版本{{ props.row.protocolVersion }}</el-col> <el-col :span="9">协议版本{{ props.row.protocolVersion }}</el-col>
<el-col :span="9">产品类型{{ ASDU_TYPE[props.row.type].text }}</el-col> <el-col :span="9">
产品类型
<span v-if="ASDU_TYPE[props.row.type]">{{ ASDU_TYPE[props.row.type].text }}</span>
</el-col>
<el-col :span="9">与主站后台联调情况{{ props.row.joint }}</el-col> <el-col :span="9">与主站后台联调情况{{ props.row.joint }}</el-col>
<el-col :span="9">备注{{ props.row.remark }}</el-col> <el-col :span="9">备注{{ props.row.remark }}</el-col>
<el-col :span="9">维修记录{{ props.row.operationRecord }}</el-col> <el-col :span="9">维修记录{{ props.row.operationRecord }}</el-col>

3
src/views/statistical-report.vue

@ -8,6 +8,7 @@ import SearchBar from 'components/statistical/search-bar.vue';
import HistoryData from 'components/statistical/stastistical-chart.vue'; import HistoryData from 'components/statistical/stastistical-chart.vue';
import { computed, onMounted, ref } from 'vue'; import { computed, onMounted, ref } from 'vue';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import { ElMessage } from 'element-plus';
const searchBar = ref(null); const searchBar = ref(null);
let timer = null; let timer = null;
@ -55,7 +56,7 @@ const getData = async () => {
} }
} catch (error) { } catch (error) {
loadingSearch.value = false; loadingSearch.value = false;
console.log('error: ', error); ElMessage.error(error.message || '查询失败');
} }
}; };

Loading…
Cancel
Save