Browse Source

1.修改默认站点 2.时间戳 3.删除console

master
song 4 years ago
parent
commit
22442cd73a
  1. 1
      package.json
  2. 57
      src/components/data-search-bar.vue
  3. 1
      src/components/realtime-data.vue
  4. 32
      src/components/search-bar-data.vue
  5. 25
      src/components/search-bar.vue
  6. 1
      src/store/index.js
  7. 9
      src/views/data-history.vue
  8. 4
      src/views/device-list.vue
  9. 19
      src/views/month-data.vue
  10. 37
      src/views/statistical-history.vue
  11. 25
      src/views/statistical-realtime.vue

1
package.json

@ -15,6 +15,7 @@
"@antv/g2plot": "^2.3.39", "@antv/g2plot": "^2.3.39",
"@vitejs/plugin-vue": "^1.9.3", "@vitejs/plugin-vue": "^1.9.3",
"axios": "^0.23.0", "axios": "^0.23.0",
"dayjs": "^1.10.7",
"element-plus": "^1.1.0-beta.24", "element-plus": "^1.1.0-beta.24",
"lodash": "^4.17.21", "lodash": "^4.17.21",
"vite": "^2.6.4", "vite": "^2.6.4",

57
src/components/data-search-bar.vue

@ -1,14 +1,14 @@
<template> <template>
<el-form :inline="true" :model="searchDevice" ref="searchDeviceForm"> <el-form :inline="true" :model="searchDevice" ref="searchDeviceForm">
<el-form-item label="选择站点"> <el-form-item label="选择站点">
<el-select v-model="searchDevice.device" placeholder="请选择站点"> <el-select v-model="searchDevice.deviceId" placeholder="请选择站点" @change="change">
<el-option label="全部" value=""></el-option> <el-option label="全部" value=""></el-option>
<el-option :label="item.address" :value="item.deviceId" v-for="item in devices" :key="item.deviceId"></el-option> <el-option :label="item.address" :value="item.deviceId" v-for="item in devices" :key="item.deviceId"></el-option>
</el-select> </el-select>
</el-form-item> </el-form-item>
<el-form-item label="选择日期"> <el-form-item label="选择日期">
<el-date-picker <el-date-picker
v-model="searchDevice.value1" v-model="searchDevice.date"
type="monthrange" type="monthrange"
range-separator="~" range-separator="~"
start-placeholder="开始月份" start-placeholder="开始月份"
@ -23,41 +23,42 @@
</template> </template>
<script setup> <script setup>
import { reactive, ref, computed, defineEmits } from 'vue'; import { reactive, ref, computed, defineEmits, watch } from 'vue';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import dayjs from 'dayjs';
const emit = defineEmits(['getDate']); const emit = defineEmits(['search']);
const searchDevice = reactive({ deviceId: '', date: '' });
const searchDevice = reactive({ device: '', value1: '' });
const searchDeviceForm = ref(null); // form const searchDeviceForm = 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
/** // currentDeviceId
* 格式化日期 watch(
* @param {Date} date 选择的日期 () => currentDeviceId.value,
*/ newValue => {
const formatDate = date => { if (newValue && searchDevice.deviceId !== newValue) {
const year = date.getFullYear(); searchDevice.deviceId = newValue;
const month = date.getMonth() + 1; }
const day = date.getDate(); },
return `${year}-${month}-${day}`; { immediate: true },
);
const change = e => {
store.commit('device/setCurrentDeviceId', e);
}; };
const onSubmit = () => { const onSubmit = () => {
searchDeviceForm.value.validate(valid => { searchDeviceForm.value.validate(() => {
if (valid) { const { deviceId, date } = { ...searchDevice };
const options = { ...searchDevice }; if (date) {
let date = []; const start = dayjs(date[0]).format('X');
if (options.value1) { const end = dayjs(date[1]).format('X');
const start = formatDate([...options.value1][0]); const daterange = [start, end];
const end = formatDate([...options.value1][1]); emit('search', { deviceId, date: daterange });
date = [start, end]; } else {
} emit('search', { deviceId, date });
const params = { deviceId: options.device, date };
emit('getDate', params);
} }
}); });
}; };

1
src/components/realtime-data.vue

@ -24,7 +24,6 @@ const setDate = data => {
noData.value = false; noData.value = false;
if (bar) { if (bar) {
console.log('重新加载');
bar.changeData(data); bar.changeData(data);
return; return;
} }

32
src/components/search-bar-data.vue

@ -1,7 +1,7 @@
<template> <template>
<el-form :inline="true" :model="searchDevice" ref="searchDeviceForm"> <el-form :inline="true" :model="searchDevice" ref="searchDeviceForm">
<el-form-item label="选择站点"> <el-form-item label="选择站点">
<el-select v-model="searchDevice.deviceId" placeholder="请选择站点"> <el-select v-model="searchDevice.deviceId" placeholder="请选择站点" @change="change">
<el-option label="全部" value></el-option> <el-option label="全部" value></el-option>
<el-option :label="item.address" :value="item.deviceId" v-for="item in devices" :key="item.deviceId"></el-option> <el-option :label="item.address" :value="item.deviceId" v-for="item in devices" :key="item.deviceId"></el-option>
</el-select> </el-select>
@ -24,24 +24,30 @@
</template> </template>
<script setup> <script setup>
import { reactive, ref, computed, defineEmits } from 'vue'; import { reactive, ref, computed, defineEmits, watch } from 'vue';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
import dayjs from 'dayjs';
const emit = defineEmits(['search']); const emit = defineEmits(['search']);
const searchDevice = reactive({ deviceId: '', date: '' }); const searchDevice = reactive({ deviceId: '', date: '' });
const searchDeviceForm = ref(null); // form const searchDeviceForm = 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
/** // currentDeviceId
* 格式化日期 watch(
* @param {Date} date 选择的日期 () => currentDeviceId.value,
*/ newValue => {
const formatDate = date => { if (newValue && searchDevice.deviceId !== newValue) {
const year = date.getFullYear(); searchDevice.deviceId = newValue;
const month = date.getMonth() + 1; }
const day = date.getDate(); },
return `${year}-${month}-${day}`; { immediate: true },
);
const change = e => {
store.commit('device/setCurrentDeviceId', e);
}; };
// //
@ -49,7 +55,9 @@ const onSubmit = () => {
searchDeviceForm.value.validate(() => { searchDeviceForm.value.validate(() => {
const { deviceId, date } = searchDevice; const { deviceId, date } = searchDevice;
if (date) { if (date) {
const daterange = [formatDate(date[0]), formatDate(date[1])]; const start = dayjs(date[0]).format('X');
const end = dayjs(date[1]).format('X');
const daterange = [start, end];
emit('search', { deviceId, date: daterange }); emit('search', { deviceId, date: daterange });
} else { } else {
emit('search', { deviceId, date }); emit('search', { deviceId, date });

25
src/components/search-bar.vue

@ -1,7 +1,7 @@
<template> <template>
<el-form :inline="true" :model="searchDevice" ref="searchDeviceForm"> <el-form :inline="true" :model="searchDevice" ref="searchDeviceForm">
<el-form-item label="选择站点"> <el-form-item label="选择站点">
<el-select v-model="searchDevice.device" placeholder="请选择站点"> <el-select v-model="searchDevice.deviceId" placeholder="请选择站点" @change="change">
<el-option label="全部" value></el-option> <el-option label="全部" value></el-option>
<el-option :label="item.address" :value="item.deviceId" v-for="item in devices" :key="item.deviceId"></el-option> <el-option :label="item.address" :value="item.deviceId" v-for="item in devices" :key="item.deviceId"></el-option>
</el-select> </el-select>
@ -13,22 +13,37 @@
</template> </template>
<script setup> <script setup>
import { reactive, ref, computed, defineEmits } from 'vue'; import { reactive, ref, computed, defineEmits, watch } from 'vue';
import { useStore } from 'vuex'; import { useStore } from 'vuex';
const emit = defineEmits(['getDate']); const emit = defineEmits(['getDate']);
const searchDevice = reactive({ device: '' }); const searchDevice = reactive({ deviceId: '' });
const searchDeviceForm = ref(null); // form const searchDeviceForm = 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
// currentDeviceId
watch(
() => currentDeviceId.value,
newValue => {
if (newValue && searchDevice.deviceId !== newValue) {
searchDevice.deviceId = newValue;
}
},
{ immediate: true },
);
const change = e => {
store.commit('device/setCurrentDeviceId', e);
};
const onSubmit = () => { const onSubmit = () => {
searchDeviceForm.value.validate(() => { searchDeviceForm.value.validate(() => {
const { device } = searchDevice; emit('search');
emit('search', { deviceId: device });
}); });
}; };
</script> </script>

1
src/store/index.js

@ -9,7 +9,6 @@ export default createStore({
getters: {}, getters: {},
mutations: { mutations: {
toggleCollapse(state) { toggleCollapse(state) {
console.log('1');
state.menu.collapse = !state.menu.collapse; state.menu.collapse = !state.menu.collapse;
}, },
}, },

9
src/views/data-history.vue

@ -9,6 +9,7 @@ const page = ref({ page: 2, size: 10 });
let timer = null; let timer = null;
const store = useStore(); const store = useStore();
const token = computed(() => store.getters['user/token']); const token = computed(() => store.getters['user/token']);
const currentDeviceId = computed(() => store.state.device.currentDeviceId); // id
let contentHeight = 600; let contentHeight = 600;
const data = ref(null); const data = ref(null);
@ -16,8 +17,12 @@ const data = ref(null);
const getData = async () => { const getData = async () => {
try { try {
if (token) { if (token) {
const params = { search: { ...search.value }, page: { page: page.value.page, size: page.value.size } }; const options = { ...search.value };
console.log('params: ', params); const date = options && options.date ? options.date : [];
const params = {
search: { deviceId: currentDeviceId.value, date },
page: { page: page.value.page, size: page.value.size },
};
const resData = await getHistories(params); const resData = await getHistories(params);
data.value = resData.data; data.value = resData.data;
page.value = resData.page; page.value = resData.page;

4
src/views/device-list.vue

@ -91,6 +91,7 @@ const editting = ref(false);
// //
const getDevicesAllData = () => { const getDevicesAllData = () => {
try {
if (token) { if (token) {
store.dispatch('device/getDevicesAll'); store.dispatch('device/getDevicesAll');
timer && clearTimeout(timer); timer && clearTimeout(timer);
@ -100,6 +101,9 @@ const getDevicesAllData = () => {
getDevicesAllData(); getDevicesAllData();
}); });
} }
} catch (error) {
console.log('error: ', error);
}
}; };
getDevicesAllData(); getDevicesAllData();

19
src/views/month-data.vue

@ -1,5 +1,5 @@
<template> <template>
<DataSearchBar @getDate="getDate" /> <DataSearchBar @search="getDate" />
<IntegralElectric ref="child1" class="mt-4" /> <IntegralElectric ref="child1" class="mt-4" />
<TotalCorrosion ref="child2" class="mt-4" /> <TotalCorrosion ref="child2" class="mt-4" />
<MoistTime ref="child3" class="mt-4" /> <MoistTime ref="child3" class="mt-4" />
@ -23,14 +23,22 @@ const token = computed(() => store.getters['user/token']);
const electricData = computed(() => store.state.statistics.electricData); const electricData = computed(() => store.state.statistics.electricData);
const corrosionData = computed(() => store.state.statistics.corrosionData); const corrosionData = computed(() => store.state.statistics.corrosionData);
const moistTimeData = computed(() => store.state.statistics.moistTimeData); const moistTimeData = computed(() => store.state.statistics.moistTimeData);
const currentDeviceId = computed(() => store.state.device.currentDeviceId); // id
// //
/**
* 获取月累计数据
* @param {*} deviceId // id
* @param {*} date //
* @param {*} sort // 1 -> -1->
*/
const getDate = async options => { const getDate = async options => {
try {
if (token) { if (token) {
const params = { const params = {
deviceId: options && options.deviceId ? options.deviceId : '', // id deviceId: currentDeviceId.value,
date: options && options.date && options.date.length ? options.date : [], // date: options && options.date && options.date.length ? options.date : [],
sort: 1, // 1 -> -1-> sort: 1,
}; };
await store.dispatch('statistics/getMonthsDate', params); await store.dispatch('statistics/getMonthsDate', params);
timer && clearTimeout(timer); timer && clearTimeout(timer);
@ -44,6 +52,9 @@ const getDate = async options => {
getDate(); getDate();
}); });
} }
} catch (error) {
console.log('error: ', error);
}
}; };
getDate(); getDate();

37
src/views/statistical-history.vue

@ -1,5 +1,5 @@
<template> <template>
<SearchBar @search="getDate" /> <SearchBar @search="onSearch" />
<HistoryData ref="childRef" class="mt-4" /> <HistoryData ref="childRef" class="mt-4" />
</template> </template>
@ -15,17 +15,8 @@ let timer = null;
const store = useStore(); const store = useStore();
const token = computed(() => store.getters['user/token']); const token = computed(() => store.getters['user/token']);
const realtimeData = computed(() => store.state.statistics.realtimeData); const realtimeData = computed(() => store.state.statistics.realtimeData);
const currentDeviceId = computed(() => store.state.device.currentDeviceId); // id
/** const search = ref({});
* 格式化日期
* @param {Date} date 选择的日期
*/
const formatDate = date => {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return `${year}-${month}-${day}`;
};
/** /**
* 历史数据统计 * 历史数据统计
@ -36,18 +27,13 @@ const formatDate = date => {
* @param {*} size // * @param {*} size //
* @param {*} type // 0 * @param {*} type // 0
*/ */
const getDate = async options => { const getDate = async () => {
try { try {
if (token) { if (token) {
let date = []; const options = { ...search.value };
const startTime = new Date(new Date(new Date().toLocaleDateString()).getTime());
const start = formatDate(startTime);
const end = formatDate(new Date());
date = [start, end];
const params = { const params = {
deviceId: options && options.deviceId ? options.deviceId : '', deviceId: currentDeviceId.value,
date: options && options.date && options.date.length ? options.date : date, date: options && options.date && options.date.length ? options.date : [],
sort: 1, sort: 1,
page: 1, page: 1,
size: 10, size: 10,
@ -68,4 +54,13 @@ const getDate = async options => {
}; };
getDate(); getDate();
/**
* 监听search信息
* @param {object} payload search组件emit的数据
*/
const onSearch = payload => {
search.value = { ...payload };
getDate();
};
</script> </script>

25
src/views/statistical-realtime.vue

@ -4,10 +4,11 @@
</template> </template>
<script setup> <script setup>
import { computed, ref, onUnmounted } from 'vue';
import { useStore } from 'vuex';
import SearchBar from 'components/search-bar.vue'; import SearchBar from 'components/search-bar.vue';
import RealtimeData from 'components/realtime-data.vue'; import RealtimeData from 'components/realtime-data.vue';
import { computed, ref, onUnmounted } from 'vue';
import { useStore } from 'vuex';
import dayjs from 'dayjs';
const childRef = ref(null); const childRef = ref(null);
@ -16,17 +17,7 @@ let apiTimer = null;
const store = useStore(); const store = useStore();
const token = computed(() => store.getters['user/token']); const token = computed(() => store.getters['user/token']);
const realtimeData = computed(() => store.state.statistics.realtimeData); const realtimeData = computed(() => store.state.statistics.realtimeData);
const currentDeviceId = computed(() => store.state.device.currentDeviceId); // id
/**
* 格式化日期
* @param {Date} date 选择的日期
*/
const formatDate = date => {
const year = date.getFullYear();
const month = date.getMonth() + 1;
const day = date.getDate();
return `${year}-${month}-${day}`;
};
/** /**
* 实时数据统计 * 实时数据统计
@ -37,15 +28,15 @@ const formatDate = date => {
* @param {*} size // * @param {*} size //
* @param {*} type // 0 * @param {*} type // 0
*/ */
const getDate = async options => { const getDate = async () => {
try { try {
if (token) { if (token) {
const startTime = new Date(new Date(new Date().toLocaleDateString()).getTime()); const startTime = new Date(new Date(new Date().toLocaleDateString()).getTime());
const start = formatDate(startTime); const start = dayjs(startTime).format('X');
const end = formatDate(new Date()); const end = dayjs(new Date()).format('X');
const params = { const params = {
deviceId: options && options.deviceId ? options.deviceId : '', deviceId: currentDeviceId.value,
date: [start, end], date: [start, end],
sort: 1, sort: 1,
page: 1, page: 1,

Loading…
Cancel
Save