Browse Source

refactor: 1. 统计中异常值不显示;2.统计中切换设备保留上次所选类目;3.添加运维管理员的权限判断

feature-with-login
wally 4 years ago
parent
commit
02848d1e95
  1. 3
      src/components/config/function-config-pending.vue
  2. 3
      src/components/config/network-config-pending.vue
  3. 1
      src/components/history/local.vue
  4. 10
      src/components/history/missing-data.vue
  5. 4
      src/components/navbar.vue
  6. 4
      src/components/statistical/stastistical-chart.vue
  7. 20
      src/store/statistics.js
  8. 4
      src/store/user.js
  9. 28
      src/utils/statistical.js
  10. 2
      src/views/Index.vue

3
src/components/config/function-config-pending.vue

@ -107,7 +107,7 @@
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="20" class="mt-5 pl-2"> <el-row v-if="isAdmin" :gutter="20" class="mt-5 pl-2">
<el-form-item> <el-form-item>
<el-button type="primary" @click="onSubmit">提交</el-button> <el-button type="primary" @click="onSubmit">提交</el-button>
<el-button @click="onReset">重置</el-button> <el-button @click="onReset">重置</el-button>
@ -137,6 +137,7 @@ const store = useStore();
const currentDeviceId = computed(() => store.state.device.currentDeviceId); const currentDeviceId = computed(() => store.state.device.currentDeviceId);
const emit = defineEmits(['status']); const emit = defineEmits(['status']);
const props = defineProps({ activeName: String }); const props = defineProps({ activeName: String });
const isAdmin = computed(() => store.getters['user/isAdmin']);
/** /**
* 格式化时间 * 格式化时间

3
src/components/config/network-config-pending.vue

@ -65,7 +65,7 @@
</el-col> </el-col>
</el-row> </el-row>
<el-row :gutter="20" class="mt-5 pl-2"> <el-row v-if="isAdmin" :gutter="20" class="mt-5 pl-2">
<el-form-item> <el-form-item>
<el-button type="primary" @click="onSubmit">提交</el-button> <el-button type="primary" @click="onSubmit">提交</el-button>
<el-button @click="onReset">重置</el-button> <el-button @click="onReset">重置</el-button>
@ -92,6 +92,7 @@ const store = useStore();
const currentDeviceId = computed(() => store.state.device.currentDeviceId); const currentDeviceId = computed(() => store.state.device.currentDeviceId);
const emit = defineEmits(['status']); const emit = defineEmits(['status']);
const props = defineProps({ activeName: String }); const props = defineProps({ activeName: String });
const isAdmin = computed(() => store.getters['user/isAdmin']);
/** /**
* 查询网络参数配置 * 查询网络参数配置

1
src/components/history/local.vue

@ -77,7 +77,6 @@ const getData = async () => {
const options = { ...search.value }; const options = { ...search.value };
const date = options && options.date ? options.date : []; const date = options && options.date ? options.date : [];
console.log(date);
if (!date || date.length !== 2) { if (!date || date.length !== 2) {
return ElMessage.error('请选择时间 '); return ElMessage.error('请选择时间 ');
} }

10
src/components/history/missing-data.vue

@ -14,21 +14,25 @@
<el-table-column align="center" header-align="center" label="操作" min-width="100"> <el-table-column align="center" header-align="center" label="操作" min-width="100">
<template #default="scope"> <template #default="scope">
<el-button :disabled="scope.row.disabled" plain size="small" type="success" @click="handlePass(scope.row)">补传 </el-button> <el-button :disabled="scope.row.disabled || !isAdmin" plain size="small" type="success" @click="handlePass(scope.row)">
补传
</el-button>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
</template> </template>
<script setup> <script setup>
import { defineProps, defineEmits, ref } from 'vue'; import { defineProps, defineEmits, ref, computed } from 'vue';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import { sendCommand } from 'apis'; import { sendCommand } from 'apis';
import { ElMessage } from 'element-plus'; import { ElMessage } from 'element-plus';
import { useStore } from 'vuex';
defineProps({ data: Object }); defineProps({ data: Object });
const store = useStore();
const emit = defineEmits(['on-success']); const emit = defineEmits(['on-success']);
const isAdmin = computed(() => store.getters['user/isAdmin']);
const contentHeight = ref(600); const contentHeight = ref(600);
/** /**

4
src/components/navbar.vue

@ -1,5 +1,5 @@
<template> <template>
<div class="flex items-center justify-between pr-5"> <div class="flex items-center justify-between pr-5 shadow-sm">
<h1 class="text-lg font-medium py-3 px-6"> <h1 class="text-lg font-medium py-3 px-6">
<i <i
v-if="menu.show" v-if="menu.show"
@ -7,7 +7,7 @@
class="el-icon-guide mr-2" class="el-icon-guide mr-2"
@click="toggleCollapse" @click="toggleCollapse"
></i> ></i>
{{ $route.meta.title || '智能大气腐蚀监测平台' }} 智能大气腐蚀监测平台{{ $route.meta.title }}
</h1> </h1>
<el-dropdown> <el-dropdown>

4
src/components/statistical/stastistical-chart.vue

@ -29,6 +29,7 @@ echarts.use([
const store = useStore(); const store = useStore();
const props = defineProps({ searchHeight: Number }); const props = defineProps({ searchHeight: Number });
const realtimeData = computed(() => store.state.statistics.realtimeData); const realtimeData = computed(() => store.state.statistics.realtimeData);
const defaultSelectedLegend = computed(() => store.state.statistics.defaultSelectedLegend);
const isMounted = ref(false); const isMounted = ref(false);
const noData = ref(true); const noData = ref(true);
let myChart = null; let myChart = null;
@ -56,9 +57,10 @@ function initChart(data) {
chartDom.style.height = `${canvasHeight}px`; chartDom.style.height = `${canvasHeight}px`;
myChart && myChart.dispose(); myChart && myChart.dispose();
myChart = echarts.init(chartDom); myChart = echarts.init(chartDom);
render(data); render(data, defaultSelectedLegend.value);
myChart.on('legendselectchanged', event => { myChart.on('legendselectchanged', event => {
store.commit('statistics/setDefaultSelectedLegend', event.selected);
render(data, event.selected); render(data, event.selected);
}); });
} }

20
src/store/statistics.js

@ -8,11 +8,31 @@ export default {
corrosionData: null, corrosionData: null,
moistTimeData: null, moistTimeData: null,
realtimeData: null, realtimeData: null,
defaultSelectedLegend: {
'钢腐蚀电流(nA)': true,
'铜腐蚀电流(nA)': true,
'铝腐蚀电流(nA)': true,
'锌腐蚀电流(nA)': true,
'SO2(ppb)': false,
'盐分阻抗(Ω)': false,
'盐分温度(℃)': false,
'环境温度(℃)': false,
'环境湿度(RH%)': false,
},
}, },
getters: {}, getters: {},
mutations: { mutations: {
/**
* 设置数据统计图表上选中的legend
* @param {Object} state
* @param {Object} newData
*/
setDefaultSelectedLegend(state, newData) {
state.defaultSelectedLegend = { ...newData };
},
/** /**
* 设置积分电量数据 * 设置积分电量数据
* @param {*} state * @param {*} state

4
src/store/user.js

@ -18,6 +18,10 @@ export default {
if (!user) return null; if (!user) return null;
return user.account; return user.account;
}, },
isAdmin({ user }) {
if (!user) return false;
return user.account === 'iacdadmin';
},
}, },
mutations: { mutations: {

28
src/utils/statistical.js

@ -1,7 +1,8 @@
/* eslint-disable max-len,object-curly-newline */ /* eslint-disable max-len,object-curly-newline */
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import max from 'lodash/max'; import max from 'lodash/max';
import { colors, defaultSelectedLegend, generateDefaultSeries, legendData, yAxisData } from '@/config/chart'; import isNaN from 'lodash/isNaN';
import { colors, generateDefaultSeries, legendData, yAxisData } from '@/config/chart';
/** /**
* 生成chart所需参数 * 生成chart所需参数
@ -33,15 +34,15 @@ function generateParams(data) {
}; };
data.forEach(item => { data.forEach(item => {
result.time.push(dayjs(new Date(+item.time)).format('YY/MM/DD HH:mm')); result.time.push(dayjs(new Date(+item.time)).format('YY/MM/DD HH:mm'));
result.so2.push(+item.so2); !isNaN(+item.so2) && result.so2.push(+item.so2);
result.saltR.push(+item.saltR); !isNaN(+item.saltR) && result.saltR.push(+item.saltR);
result.saltT.push(+item.saltT); !isNaN(+item.saltT) && result.saltT.push(+item.saltT);
result.environmentTemperature.push(+item.environmentTemperature); !isNaN(+item.environmentTemperature) && result.environmentTemperature.push(+item.environmentTemperature);
result.environmentHumidity.push(+item.environmentHumidity); !isNaN(+item.environmentHumidity) && result.environmentHumidity.push(+item.environmentHumidity);
result.corrosionXIN.push(+item.corrosion1); !isNaN(+item.corrosion1) && result.corrosionXIN.push(+item.corrosion1);
result.corrosionTONG.push(+item.corrosion2); !isNaN(+item.corrosion2) && result.corrosionTONG.push(+item.corrosion2);
result.corrosionLV.push(+item.corrosion3); !isNaN(+item.corrosion3) && result.corrosionLV.push(+item.corrosion3);
result.corrosionGANG.push(+item.corrosion4); !isNaN(+item.corrosion4) && result.corrosionGANG.push(+item.corrosion4);
}); });
return result; return result;
} }
@ -138,11 +139,10 @@ function generateGrid(yAxis) {
/** /**
* 生成chart参数 * 生成chart参数
* @param {Object[]} rawData 返回段返回的data数据 * @param {Object[]} rawData 返回段返回的data数据
* @param {Object[]} yAxis * @param {Object} selected 选中的legend
* @returns {{yAxis: [{axisLabel: {formatter: string}, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string},{axisLabel: {formatter: string}, offset: number, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string},{axisLabel: {formatter: string}, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string},{axisLabel: {formatter: string}, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string},{axisLabel: {formatter: string}, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string},null,null,null], xAxis: [{data: *[], axisTick: {alignWithLabel: boolean}, type: string}], color: string[], grid: {right: string}, legend: {data: string[]}, series: [{data: *[], name: string, type: string},{data: *[], name: string, type: string, yAxisIndex: number},{data: *[], name: string, type: string, yAxisIndex: number},{data: *[], name: string, type: string, yAxisIndex: number},{data: *[], name: string, type: string, yAxisIndex: number},null,null,null], tooltip: {axisPointer: {type: string}, trigger: string}, toolbox: {feature: {saveAsImage: {show: boolean}, restore: {show: boolean}, dataView: {show: boolean, readOnly: boolean}}}}} * @returns {{yAxis: ({axisLabel: {formatter: string}, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string}|{axisLabel: {formatter: string}, offset: number, axisLine: {lineStyle: {color: string}, show: boolean}, name: string, position: string, type: string})[], xAxis: [{data: *[], axisTick: {alignWithLabel: boolean}, type: string}], color: [string,string,string,string,string,string,string,string,string], grid: {left: number, right: number}, legend: {data: [string,string,string,string,string,string,string,string,string], type: string, selected}, series: (({data: ([]|number|string|*), name: string, type: string}|{data: ([]|number|BufferSource|string|*), name: string, type: string, yAxisIndex: number}|{data: ([]|string|*), name: string, type: string, yAxisIndex: number}|{data: [], name: string, type: string, yAxisIndex: number})[]|*[]), tooltip: {axisPointer: {type: string, snap: boolean}, trigger: string}, dataZoom: [{type: string},{type: string}]}}
*/ */
// eslint-disable-next-line import/prefer-default-export export function generateChartOption(rawData, selected) {
export function generateChartOption(rawData, selected = defaultSelectedLegend) {
const data = generateParams(rawData); const data = generateParams(rawData);
const yAxis = generateYAxis(selected); const yAxis = generateYAxis(selected);
const series = generateSeries(data, yAxis); const series = generateSeries(data, yAxis);

2
src/views/Index.vue

@ -44,7 +44,7 @@ function openPage(path) {
<template> <template>
<el-config-provider :locale="local"> <el-config-provider :locale="local">
<el-container> <el-container>
<el-header style="padding: 0"> <el-header style="padding: 0; height: 54px">
<Navbar /> <Navbar />
</el-header> </el-header>
<el-container class="overflow-hidden"> <el-container class="overflow-hidden">

Loading…
Cancel
Save