refactor: reorganize files
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { getSnapByDeviceIdApi, ndmDeviceAlarmLogDefaultExportByTemplate, postNdmDeviceAlarmLogPage, putNdmDeviceAlarmLog, type NdmDeviceAlarmLogResultVO } from '@/apis';
|
||||
import { getCameraSnapApi, exportDeviceAlarmLogApi, pageDeviceAlarmLogApi, updateDeviceAlarmLogApi, type NdmDeviceAlarmLogResultVO } from '@/apis';
|
||||
import { renderAlarmDateCell, renderAlarmTypeCell, renderDeviceTypeCell, renderFaultLevelCell } from '@/components';
|
||||
import { AlarmType, DeviceType, DeviceTypeCode, DeviceTypeName, FaultLevel, tryGetDeviceTypeVal, type DeviceTypeVal } from '@/enums';
|
||||
import { useCurrentAlarmsStore, useStationStore } from '@/stores';
|
||||
@@ -248,7 +248,7 @@ const tablePagination = reactive<PaginationProps>({
|
||||
|
||||
const { mutate: getTableData, isPending: tableLoading } = useMutation({
|
||||
mutationFn: async () => {
|
||||
const res = await postNdmDeviceAlarmLogPage('', {
|
||||
const res = await pageDeviceAlarmLogApi({
|
||||
model: {},
|
||||
extra: getExtraFields(),
|
||||
current: tablePagination.page ?? 1,
|
||||
@@ -291,7 +291,7 @@ const { mutateAsync: getSnapByDeviceId } = useMutation({
|
||||
const { deviceAlarmLog } = params;
|
||||
const { deviceId } = deviceAlarmLog;
|
||||
if (!deviceId) throw new Error('设备ID不能为空');
|
||||
const snap = await getSnapByDeviceIdApi(deviceId);
|
||||
const snap = await getCameraSnapApi(deviceId);
|
||||
return snap;
|
||||
},
|
||||
onError: (error) => {
|
||||
@@ -302,7 +302,7 @@ const { mutateAsync: getSnapByDeviceId } = useMutation({
|
||||
|
||||
const { mutate: confirmAlarm } = useMutation({
|
||||
mutationFn: async (params: { id?: string }) => {
|
||||
await putNdmDeviceAlarmLog('', {
|
||||
await updateDeviceAlarmLogApi({
|
||||
id: params.id,
|
||||
alarmConfirm: '1',
|
||||
});
|
||||
@@ -322,7 +322,7 @@ const { mutate: confirmAlarm } = useMutation({
|
||||
|
||||
const { mutate: exportTableData, isPending: exporting } = useMutation({
|
||||
mutationFn: async () => {
|
||||
const data = await ndmDeviceAlarmLogDefaultExportByTemplate('', {
|
||||
const data = await exportDeviceAlarmLogApi({
|
||||
model: {},
|
||||
extra: getExtraFields(),
|
||||
current: tablePagination.page ?? 1,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ndmCallLogDefaultExportByTemplate, postNdmCallLogPage, type NdmCallLogResultVO, type NdmCallLogVO, type PageQueryExtra } from '@/apis';
|
||||
import { exportCallLogApi, pageCallLogApi, type NdmCallLogResultVO, type NdmCallLog, type PageQueryExtra } from '@/apis';
|
||||
import { useStationStore } from '@/stores';
|
||||
import { downloadByData } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
@@ -35,7 +35,7 @@ const stationSelectOptions = computed(() => {
|
||||
}));
|
||||
});
|
||||
|
||||
type SearchFields = PageQueryExtra<NdmCallLogVO> & { stationCode?: string; createdTime: [string, string] };
|
||||
type SearchFields = PageQueryExtra<NdmCallLog> & { stationCode?: string; createdTime: [string, string] };
|
||||
|
||||
const searchFields = reactive<SearchFields>({
|
||||
stationCode: undefined as string | undefined,
|
||||
@@ -101,26 +101,31 @@ const tablePagination = reactive<PaginationProps>({
|
||||
},
|
||||
onUpdatePage: (page: number) => {
|
||||
tablePagination.page = page;
|
||||
getCallLogList();
|
||||
getTableData();
|
||||
},
|
||||
onUpdatePageSize: (pageSize: number) => {
|
||||
tablePagination.pageSize = pageSize;
|
||||
tablePagination.page = 1;
|
||||
getCallLogList();
|
||||
getTableData();
|
||||
},
|
||||
});
|
||||
|
||||
const { mutate: getCallLogList, isPending: tableLoading } = useMutation({
|
||||
const { mutate: getTableData, isPending: tableLoading } = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!searchFields.stationCode) throw Error('请选择车站');
|
||||
const res = await postNdmCallLogPage(searchFields.stationCode, {
|
||||
model: {},
|
||||
extra: getExtraFields(),
|
||||
current: tablePagination.page ?? 1,
|
||||
size: tablePagination.pageSize ?? 10,
|
||||
order: 'descending',
|
||||
sort: 'id',
|
||||
});
|
||||
const res = await pageCallLogApi(
|
||||
{
|
||||
model: {},
|
||||
extra: getExtraFields(),
|
||||
current: tablePagination.page ?? 1,
|
||||
size: tablePagination.pageSize ?? 10,
|
||||
order: 'descending',
|
||||
sort: 'id',
|
||||
},
|
||||
{
|
||||
stationCode: searchFields.stationCode,
|
||||
},
|
||||
);
|
||||
return res;
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
@@ -140,7 +145,7 @@ const onClickReset = () => {
|
||||
tablePagination.page = 1;
|
||||
tablePagination.pageSize = 10;
|
||||
tablePagination.itemCount = 0;
|
||||
getCallLogList();
|
||||
getTableData();
|
||||
};
|
||||
const onClickQuery = () => {
|
||||
if (searchFieldsChanged.value) {
|
||||
@@ -148,20 +153,25 @@ const onClickQuery = () => {
|
||||
tablePagination.pageSize = 10;
|
||||
searchFieldsChanged.value = false;
|
||||
}
|
||||
getCallLogList();
|
||||
getTableData();
|
||||
};
|
||||
|
||||
const { mutate: exportTableData, isPending: exporting } = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!searchFields.stationCode) throw Error('请选择车站');
|
||||
const data = await ndmCallLogDefaultExportByTemplate(searchFields.stationCode, {
|
||||
model: {},
|
||||
extra: getExtraFields(),
|
||||
current: tablePagination.page ?? 1,
|
||||
size: tablePagination.pageSize ?? 10,
|
||||
order: 'descending',
|
||||
sort: 'id',
|
||||
});
|
||||
const data = await exportCallLogApi(
|
||||
{
|
||||
model: {},
|
||||
extra: getExtraFields(),
|
||||
current: tablePagination.page ?? 1,
|
||||
size: tablePagination.pageSize ?? 10,
|
||||
order: 'descending',
|
||||
sort: 'id',
|
||||
},
|
||||
{
|
||||
stationCode: searchFields.stationCode,
|
||||
},
|
||||
);
|
||||
return data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
@@ -178,7 +188,7 @@ const defaultStation = computed(() => onlineStationList.value.at(0));
|
||||
watchEffect(() => {
|
||||
if (defaultStation.value?.code && !searchFields.stationCode) {
|
||||
searchFields.stationCode = defaultStation.value.code;
|
||||
getCallLogList();
|
||||
getTableData();
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { ndmExportDevices } from '@/apis';
|
||||
import { exportIcmpApi } from '@/apis';
|
||||
import { DeviceStatisticCard } from '@/components';
|
||||
import { useLineAlarmsQuery, useLineDevicesQuery } from '@/composables';
|
||||
import { useLineDevicesStore, useStationStore } from '@/stores';
|
||||
@@ -28,7 +28,7 @@ watch([lineDevicesQueryError, lineAlarmsQueryError], ([newLineDevicesQueryError,
|
||||
|
||||
const { mutate: exportDevices, isPending: exporting } = useMutation({
|
||||
mutationFn: async (params: { status: string }) => {
|
||||
const data = await ndmExportDevices(params.status);
|
||||
const data = await exportIcmpApi(params.status);
|
||||
return data;
|
||||
},
|
||||
onSuccess: (data, variables) => {
|
||||
|
||||
145
src/pages/table-page.template.vue
Normal file
145
src/pages/table-page.template.vue
Normal file
@@ -0,0 +1,145 @@
|
||||
<script setup lang="ts">
|
||||
import type { PageQueryExtra } from '@/apis';
|
||||
import { downloadByData } from '@/utils';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
import dayjs from 'dayjs';
|
||||
import { NButton, NDataTable, NDatePicker, NForm, NFormItemGi, NGrid, NGridItem, NSpace, type DataTableColumns, type DataTableRowData, type PaginationProps } from 'naive-ui';
|
||||
import { h, onMounted, reactive, ref, watch } from 'vue';
|
||||
|
||||
type SearchFields = PageQueryExtra<unknown> & { createdTime: [string, string] };
|
||||
|
||||
const searchFields = reactive<SearchFields>({
|
||||
createdTime: [dayjs().startOf('date').subtract(1, 'week').format('YYYY-MM-DD HH:mm:ss'), dayjs().endOf('date').format('YYYY-MM-DD HH:mm:ss')] as [string, string],
|
||||
});
|
||||
const resetSearchFields = () => {
|
||||
searchFields.createdTime = [dayjs().startOf('date').subtract(1, 'week').format('YYYY-MM-DD HH:mm:ss'), dayjs().endOf('date').format('YYYY-MM-DD HH:mm:ss')];
|
||||
};
|
||||
const getExtraFields = () => {
|
||||
const createdTime_precisest = searchFields.createdTime[0];
|
||||
const createdTime_preciseed = searchFields.createdTime[1];
|
||||
return {
|
||||
createdTime_precisest,
|
||||
createdTime_preciseed,
|
||||
};
|
||||
};
|
||||
|
||||
const searchFieldsChanged = ref(false);
|
||||
watch(searchFields, () => {
|
||||
searchFieldsChanged.value = true;
|
||||
});
|
||||
|
||||
const tableColumns: DataTableColumns<unknown> = [];
|
||||
|
||||
const tableData = ref<DataTableRowData[]>([]);
|
||||
|
||||
const tablePagination = reactive<PaginationProps>({
|
||||
showSizePicker: true,
|
||||
page: 1,
|
||||
pageSize: 10,
|
||||
pageSizes: [5, 10, 20, 50, 80, 100],
|
||||
itemCount: 0,
|
||||
prefix: ({ itemCount }) => {
|
||||
return h('div', {}, { default: () => `共${itemCount}条` });
|
||||
},
|
||||
onUpdatePage: (page: number) => {
|
||||
tablePagination.page = page;
|
||||
getTableData();
|
||||
},
|
||||
onUpdatePageSize: (pageSize: number) => {
|
||||
tablePagination.pageSize = pageSize;
|
||||
tablePagination.page = 1;
|
||||
getTableData();
|
||||
},
|
||||
});
|
||||
|
||||
const { mutate: getTableData, isPending: tableLoading } = useMutation({
|
||||
mutationFn: async () => {
|
||||
return { records: [], size: '0', total: '0' };
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
const { records, size, total } = res;
|
||||
tablePagination.pageSize = parseInt(size);
|
||||
tablePagination.itemCount = parseInt(total);
|
||||
tableData.value = records;
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
window.$message.error(error.message);
|
||||
},
|
||||
});
|
||||
|
||||
const onClickReset = () => {
|
||||
resetSearchFields();
|
||||
tablePagination.page = 1;
|
||||
tablePagination.pageSize = 10;
|
||||
tablePagination.itemCount = 0;
|
||||
getTableData();
|
||||
};
|
||||
const onClickQuery = () => {
|
||||
if (searchFieldsChanged.value) {
|
||||
tablePagination.page = 1;
|
||||
tablePagination.pageSize = 10;
|
||||
searchFieldsChanged.value = false;
|
||||
}
|
||||
getTableData();
|
||||
};
|
||||
|
||||
const { mutate: exportTableData, isPending: exporting } = useMutation({
|
||||
mutationFn: async () => {
|
||||
return new Blob();
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
const time = dayjs().format('YYYY-MM-DD_HH-mm-ss');
|
||||
downloadByData(data, `xxxxxxxx_${time}.xlsx`);
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error(error);
|
||||
window.$message.error(error.message);
|
||||
},
|
||||
});
|
||||
|
||||
onMounted(() => {
|
||||
getTableData();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="height: 100%; display: flex; flex-direction: column">
|
||||
<!-- 查询面板 -->
|
||||
<div style="flex: 0 0 auto; padding: 8px">
|
||||
<!-- 表单 -->
|
||||
<NForm>
|
||||
<NGrid :cols="3" :x-gap="24">
|
||||
<NFormItemGi :span="1" label="" label-placement="left"></NFormItemGi>
|
||||
<NFormItemGi :span="1" label="时间" label-placement="left">
|
||||
<NDatePicker v-model:formatted-value="searchFields.createdTime" type="datetimerange" />
|
||||
</NFormItemGi>
|
||||
</NGrid>
|
||||
<!-- 按钮 -->
|
||||
<NGrid :cols="1">
|
||||
<NGridItem>
|
||||
<NSpace>
|
||||
<NButton @click="onClickReset">重置</NButton>
|
||||
<NButton type="primary" :loading="tableLoading" @click="onClickQuery">查询</NButton>
|
||||
</NSpace>
|
||||
</NGridItem>
|
||||
</NGrid>
|
||||
</NForm>
|
||||
</div>
|
||||
|
||||
<!-- 表格工具栏 -->
|
||||
<div style="flex: 0 0 auto; display: flex; align-items: center; padding: 8px">
|
||||
<div style="font-size: medium">XXXXXXXX</div>
|
||||
<NSpace style="margin-left: auto">
|
||||
<NButton type="primary" :loading="exporting" @click="() => exportTableData()">导出</NButton>
|
||||
</NSpace>
|
||||
</div>
|
||||
|
||||
<!-- 表格 -->
|
||||
<div style="flex: 1 1 auto; min-height: 0; padding: 8px">
|
||||
<NDataTable remote :columns="tableColumns" :data="tableData" :pagination="tablePagination" :loading="tableLoading" :single-line="false" flex-height style="height: 100%" />
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="scss"></style>
|
||||
@@ -28,8 +28,8 @@ const vimpOperationTypeOptions: SelectOption[] = [
|
||||
</script>
|
||||
|
||||
<script setup lang="ts">
|
||||
import type { NdmVimpLogResultVO } from '@/apis/models/device';
|
||||
import { ndmVimpLogDefaultExportByTemplate, postNdmVimpLogPage } from '@/apis/requests';
|
||||
import type { NdmVimpLogResultVO } from '@/apis/model/biz';
|
||||
import { exportVimpLogApi, pageVimpLogApi } from '@/apis/request';
|
||||
import { useStationStore } from '@/stores/station';
|
||||
import { downloadByData } from '@/utils/download';
|
||||
import { useMutation } from '@tanstack/vue-query';
|
||||
@@ -190,14 +190,19 @@ const tablePagination = reactive<PaginationProps>({
|
||||
const { mutate: getVimpLogList, isPending: tableLoading } = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!searchFields.stationCode) throw Error('请选择车站');
|
||||
const res = await postNdmVimpLogPage(searchFields.stationCode, {
|
||||
model: {},
|
||||
extra: getExtraFields(),
|
||||
current: tablePagination.page ?? 1,
|
||||
size: tablePagination.pageSize ?? 10,
|
||||
order: 'descending',
|
||||
sort: 'id',
|
||||
});
|
||||
const res = await pageVimpLogApi(
|
||||
{
|
||||
model: {},
|
||||
extra: getExtraFields(),
|
||||
current: tablePagination.page ?? 1,
|
||||
size: tablePagination.pageSize ?? 10,
|
||||
order: 'descending',
|
||||
sort: 'id',
|
||||
},
|
||||
{
|
||||
stationCode: searchFields.stationCode,
|
||||
},
|
||||
);
|
||||
return res;
|
||||
},
|
||||
onSuccess: (res) => {
|
||||
@@ -231,14 +236,19 @@ const onClickQuery = () => {
|
||||
const { mutate: exportTableData, isPending: exporting } = useMutation({
|
||||
mutationFn: async () => {
|
||||
if (!searchFields.stationCode) throw Error('请选择车站');
|
||||
const data = await ndmVimpLogDefaultExportByTemplate(searchFields.stationCode, {
|
||||
model: {},
|
||||
extra: getExtraFields(),
|
||||
current: tablePagination.page ?? 1,
|
||||
size: tablePagination.pageSize ?? 10,
|
||||
order: 'descending',
|
||||
sort: 'id',
|
||||
});
|
||||
const data = await exportVimpLogApi(
|
||||
{
|
||||
model: {},
|
||||
extra: getExtraFields(),
|
||||
current: tablePagination.page ?? 1,
|
||||
size: tablePagination.pageSize ?? 10,
|
||||
order: 'descending',
|
||||
sort: 'id',
|
||||
},
|
||||
{
|
||||
stationCode: searchFields.stationCode,
|
||||
},
|
||||
);
|
||||
return data;
|
||||
},
|
||||
onSuccess: (data) => {
|
||||
|
||||
Reference in New Issue
Block a user