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. 20
      src/views/device-list.vue
  9. 47
      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",
"@vitejs/plugin-vue": "^1.9.3",
"axios": "^0.23.0",
"dayjs": "^1.10.7",
"element-plus": "^1.1.0-beta.24",
"lodash": "^4.17.21",
"vite": "^2.6.4",

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

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

1
src/components/realtime-data.vue

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

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

@ -1,7 +1,7 @@
<template>
<el-form :inline="true" :model="searchDevice" ref="searchDeviceForm">
<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="item.address" :value="item.deviceId" v-for="item in devices" :key="item.deviceId"></el-option>
</el-select>
@ -24,24 +24,30 @@
</template>
<script setup>
import { reactive, ref, computed, defineEmits } from 'vue';
import { reactive, ref, computed, defineEmits, watch } from 'vue';
import { useStore } from 'vuex';
import dayjs from 'dayjs';
const emit = defineEmits(['search']);
const searchDevice = reactive({ deviceId: '', date: '' });
const searchDeviceForm = ref(null); // form
const store = useStore();
const devices = computed(() => store.state.device.devices);
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}`;
// currentDeviceId
watch(
() => currentDeviceId.value,
newValue => {
if (newValue && searchDevice.deviceId !== newValue) {
searchDevice.deviceId = newValue;
}
},
{ immediate: true },
);
const change = e => {
store.commit('device/setCurrentDeviceId', e);
};
//
@ -49,7 +55,9 @@ const onSubmit = () => {
searchDeviceForm.value.validate(() => {
const { deviceId, date } = searchDevice;
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 });
} else {
emit('search', { deviceId, date });

25
src/components/search-bar.vue

@ -1,7 +1,7 @@
<template>
<el-form :inline="true" :model="searchDevice" ref="searchDeviceForm">
<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="item.address" :value="item.deviceId" v-for="item in devices" :key="item.deviceId"></el-option>
</el-select>
@ -13,22 +13,37 @@
</template>
<script setup>
import { reactive, ref, computed, defineEmits } from 'vue';
import { reactive, ref, computed, defineEmits, watch } from 'vue';
import { useStore } from 'vuex';
const emit = defineEmits(['getDate']);
const searchDevice = reactive({ device: '' });
const searchDevice = reactive({ deviceId: '' });
const searchDeviceForm = ref(null); // form
const store = useStore();
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 = () => {
searchDeviceForm.value.validate(() => {
const { device } = searchDevice;
emit('search', { deviceId: device });
emit('search');
});
};
</script>

1
src/store/index.js

@ -9,7 +9,6 @@ export default createStore({
getters: {},
mutations: {
toggleCollapse(state) {
console.log('1');
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;
const store = useStore();
const token = computed(() => store.getters['user/token']);
const currentDeviceId = computed(() => store.state.device.currentDeviceId); // id
let contentHeight = 600;
const data = ref(null);
@ -16,8 +17,12 @@ const data = ref(null);
const getData = async () => {
try {
if (token) {
const params = { search: { ...search.value }, page: { page: page.value.page, size: page.value.size } };
console.log('params: ', params);
const options = { ...search.value };
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);
data.value = resData.data;
page.value = resData.page;

20
src/views/device-list.vue

@ -91,14 +91,18 @@ const editting = ref(false);
//
const getDevicesAllData = () => {
if (token) {
store.dispatch('device/getDevicesAll');
timer && clearTimeout(timer);
timer = null;
} else {
timer = setTimeout(() => {
getDevicesAllData();
});
try {
if (token) {
store.dispatch('device/getDevicesAll');
timer && clearTimeout(timer);
timer = null;
} else {
timer = setTimeout(() => {
getDevicesAllData();
});
}
} catch (error) {
console.log('error: ', error);
}
};

47
src/views/month-data.vue

@ -1,5 +1,5 @@
<template>
<DataSearchBar @getDate="getDate" />
<DataSearchBar @search="getDate" />
<IntegralElectric ref="child1" class="mt-4" />
<TotalCorrosion ref="child2" class="mt-4" />
<MoistTime ref="child3" class="mt-4" />
@ -23,26 +23,37 @@ const token = computed(() => store.getters['user/token']);
const electricData = computed(() => store.state.statistics.electricData);
const corrosionData = computed(() => store.state.statistics.corrosionData);
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 => {
if (token) {
const params = {
deviceId: options && options.deviceId ? options.deviceId : '', // id
date: options && options.date && options.date.length ? options.date : [], //
sort: 1, // 1 -> -1->
};
await store.dispatch('statistics/getMonthsDate', params);
timer && clearTimeout(timer);
timer = null;
//
child1.value.setDate(electricData.value);
child2.value.setDate(corrosionData.value);
child3.value.setDate(moistTimeData.value);
} else {
timer = setTimeout(() => {
getDate();
});
try {
if (token) {
const params = {
deviceId: currentDeviceId.value,
date: options && options.date && options.date.length ? options.date : [],
sort: 1,
};
await store.dispatch('statistics/getMonthsDate', params);
timer && clearTimeout(timer);
timer = null;
//
child1.value.setDate(electricData.value);
child2.value.setDate(corrosionData.value);
child3.value.setDate(moistTimeData.value);
} else {
timer = setTimeout(() => {
getDate();
});
}
} catch (error) {
console.log('error: ', error);
}
};

37
src/views/statistical-history.vue

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

25
src/views/statistical-realtime.vue

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

Loading…
Cancel
Save