|
|
@ -20,13 +20,18 @@ |
|
|
|
<el-form-item> |
|
|
|
<el-button type="primary" @click="onSubmit">查询</el-button> |
|
|
|
</el-form-item> |
|
|
|
|
|
|
|
<el-form-item v-if="showExport"> |
|
|
|
<el-button type="primary" @click="onExport">导出</el-button> |
|
|
|
</el-form-item> |
|
|
|
</el-form> |
|
|
|
</template> |
|
|
|
|
|
|
|
<script setup> |
|
|
|
import { reactive, ref, computed, defineEmits, watch } from 'vue'; |
|
|
|
import { reactive, ref, computed, defineProps, defineEmits, watch } from 'vue'; |
|
|
|
import { useStore } from 'vuex'; |
|
|
|
import dayjs from 'dayjs'; |
|
|
|
import { exportHistory } from 'apis/index'; |
|
|
|
|
|
|
|
const emit = defineEmits(['search']); |
|
|
|
const searchDevice = reactive({ deviceId: '', date: '' }); |
|
|
@ -35,6 +40,8 @@ const store = useStore(); |
|
|
|
const devices = computed(() => store.state.device.devices); |
|
|
|
const currentDeviceId = computed(() => store.state.device.currentDeviceId); // 正在操作的设备的id |
|
|
|
|
|
|
|
defineProps({ showExport: Boolean }); |
|
|
|
|
|
|
|
// 监听currentDeviceId |
|
|
|
watch( |
|
|
|
() => currentDeviceId.value, |
|
|
@ -50,18 +57,39 @@ const change = e => { |
|
|
|
store.commit('device/setCurrentDeviceId', e); |
|
|
|
}; |
|
|
|
|
|
|
|
// 提交 |
|
|
|
const onSubmit = () => { |
|
|
|
searchDeviceForm.value.validate(() => { |
|
|
|
// 生成查询参数 |
|
|
|
function generateParams() { |
|
|
|
const { deviceId, date } = searchDevice; |
|
|
|
let params = { deviceId, date }; |
|
|
|
|
|
|
|
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 }); |
|
|
|
params = { deviceId, date: daterange }; |
|
|
|
} |
|
|
|
|
|
|
|
return params; |
|
|
|
} |
|
|
|
|
|
|
|
// 提交 |
|
|
|
const onSubmit = () => { |
|
|
|
searchDeviceForm.value.validate(() => { |
|
|
|
const params = generateParams(); |
|
|
|
emit('search', params); |
|
|
|
}); |
|
|
|
}; |
|
|
|
|
|
|
|
// 导出 |
|
|
|
async function onExport() { |
|
|
|
try { |
|
|
|
const params = generateParams(); |
|
|
|
console.log('params: ', params); |
|
|
|
const resData = await exportHistory(params); |
|
|
|
console.log('resData: ', resData); |
|
|
|
// TODO: |
|
|
|
} catch (error) { |
|
|
|
throw new Error(error); |
|
|
|
} |
|
|
|
} |
|
|
|
</script> |
|
|
|