feat: current-alarms-store & move ThemeSwitch
This commit is contained in:
@@ -3,6 +3,7 @@ import type { NdmDeviceAlarmLogResultVO } from '@/apis/models';
|
||||
import { ndmDeviceAlarmLogDefaultExportByTemplate, postNdmDeviceAlarmLogPage } from '@/apis/requests';
|
||||
import { JAVA_INTEGER_MAX_VALUE } from '@/constants';
|
||||
import { DeviceType, DeviceTypeCode, DeviceTypeName, type DeviceTypeVal } from '@/enums/device-type';
|
||||
import { useCurrentAlarmsStore } from '@/stores/current-alarms';
|
||||
import { useStationStore } from '@/stores/station';
|
||||
import { downloadByData } from '@/utils/download';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
@@ -10,7 +11,16 @@ import dayjs from 'dayjs';
|
||||
import type { DataTableColumns, DataTableRowData, PaginationProps, SelectOption } from 'naive-ui';
|
||||
import { NForm, NInput, NButton, NSpace, NDataTable, NFormItemGi, NGrid, NSelect, NGridItem, NDatePicker } from 'naive-ui';
|
||||
import { storeToRefs } from 'pinia';
|
||||
import { ref, reactive, onBeforeMount, h, computed } from 'vue';
|
||||
import { ref, reactive, onBeforeMount, h, computed, watch } from 'vue';
|
||||
|
||||
const currentAlarmsStore = useCurrentAlarmsStore();
|
||||
const { needReload } = storeToRefs(currentAlarmsStore);
|
||||
watch(needReload, async (newVal) => {
|
||||
if (newVal) {
|
||||
needReload.value = false;
|
||||
onClickReset();
|
||||
}
|
||||
});
|
||||
|
||||
const stationStore = useStationStore();
|
||||
const { stationList } = storeToRefs(stationStore);
|
||||
@@ -27,7 +37,7 @@ const searchFields = reactive({
|
||||
deviceType_in: [] as string[],
|
||||
deviceName_like: '',
|
||||
// deviceId_likeRight: '',
|
||||
alarmDate: [dayjs().startOf('date').subtract(7, 'day').valueOf(), dayjs().endOf('date').valueOf()] as [number, number],
|
||||
alarmDate: [dayjs().startOf('date').valueOf(), dayjs().endOf('date').valueOf()] as [number, number],
|
||||
});
|
||||
const resetSearchFields = () => {
|
||||
searchFields.stationCode_in = [];
|
||||
@@ -35,6 +45,21 @@ const resetSearchFields = () => {
|
||||
searchFields.deviceName_like = '';
|
||||
searchFields.alarmDate = [dayjs().startOf('date').subtract(7, 'day').valueOf(), dayjs().endOf('date').valueOf()];
|
||||
};
|
||||
const onDateChange = (value: [number, number] | null) => {
|
||||
if (!value || value.length !== 2) {
|
||||
return;
|
||||
}
|
||||
const [start, end] = value;
|
||||
const diffDays = dayjs(end).diff(dayjs(start), 'day');
|
||||
if (diffDays > 7) {
|
||||
// 如果超过7天,自动调整结束时间
|
||||
const adjustedEnd = dayjs(start).add(7, 'day').valueOf();
|
||||
searchFields.alarmDate = [start, adjustedEnd];
|
||||
window.$message.warning('时间范围不能超过7天,已自动调整');
|
||||
} else {
|
||||
searchFields.alarmDate = value;
|
||||
}
|
||||
};
|
||||
|
||||
const tableColumns: DataTableColumns<NdmDeviceAlarmLogResultVO> = [
|
||||
{ title: '告警流水号', key: 'alarmNo' },
|
||||
@@ -205,7 +230,7 @@ onBeforeMount(() => getAlarmList());
|
||||
<NInput v-model:value="searchFields.deviceName_like" placeholder="请输入设备名称" clearable />
|
||||
</NFormItemGi>
|
||||
<NFormItemGi :span="1" label="告警发生时间" label-placement="left">
|
||||
<NDatePicker v-model:value="searchFields.alarmDate" type="datetimerange" />
|
||||
<NDatePicker v-model:value="searchFields.alarmDate" type="datetimerange" @update:value="onDateChange" />
|
||||
</NFormItemGi>
|
||||
</NGrid>
|
||||
<!-- 按钮 -->
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<script setup lang="ts">
|
||||
import { userClient } from '@/apis/client';
|
||||
import type { LoginParams } from '@/apis/models';
|
||||
import ThemeSwitch from '@/components/theme-switch.vue';
|
||||
import ThemeSwitch from '@/components/global/theme-switch.vue';
|
||||
import { useUserStore } from '@/stores/user';
|
||||
import { randomNum } from '@/utils/random-num';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
|
||||
Reference in New Issue
Block a user