|
@ -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 }); |
|
|