fix: queries continue running after page unmounted

This commit is contained in:
yangsy
2025-08-25 23:32:25 +08:00
parent 59a14cb9e1
commit 3cfb829608
20 changed files with 98 additions and 112 deletions

View File

@@ -1,11 +1,11 @@
import { userClient, ndmClient } from '@/apis/client';
import type { PageParams, NdmDeviceAlarmLogPageQuery, PageResult, NdmDeviceAlarmLogResultVO } from '@/apis/models';
export const postNdmDeviceAlarmLogPage = async (stationCode: string, pageQuery: PageParams<NdmDeviceAlarmLogPageQuery>) => {
export const postNdmDeviceAlarmLogPage = async (stationCode: string, pageQuery: PageParams<NdmDeviceAlarmLogPageQuery>, signal?: AbortSignal) => {
const endpoint = '/api/ndm/ndmDeviceAlarmLog/page';
// 如果车站编码为空则通过用户API客户端发送请求
if (!stationCode) {
const resp = await userClient.post<PageResult<NdmDeviceAlarmLogResultVO>>(endpoint, pageQuery);
const resp = await userClient.post<PageResult<NdmDeviceAlarmLogResultVO>>(endpoint, pageQuery, { signal });
const [err, alarmData] = resp;
if (err || !alarmData) {
throw err;
@@ -13,7 +13,7 @@ export const postNdmDeviceAlarmLogPage = async (stationCode: string, pageQuery:
return alarmData;
}
// 如果车站编码不为空则通过网管API客户端发送请求
const resp = await ndmClient.post<PageResult<NdmDeviceAlarmLogResultVO>>(`/${stationCode}${endpoint}`, pageQuery);
const resp = await ndmClient.post<PageResult<NdmDeviceAlarmLogResultVO>>(`/${stationCode}${endpoint}`, pageQuery, { signal });
const [err, alarmData] = resp;
if (err || !alarmData) {
throw err;

View File

@@ -1,9 +1,9 @@
import { ndmClient } from '@/apis/client';
import type { PageParams, NdmSecurityBoxPageQuery, PageResult, NdmSecurityBoxResultVO, NdmSecurityBoxUpdateVO } from '@/apis/models';
export const postNdmSecurityBoxPage = async (stationCode: string, pageQuery: PageParams<NdmSecurityBoxPageQuery>) => {
export const postNdmSecurityBoxPage = async (stationCode: string, pageQuery: PageParams<NdmSecurityBoxPageQuery>, signal?: AbortSignal) => {
const prefix = stationCode ? `/${stationCode}` : '';
const resp = await ndmClient.post<PageResult<NdmSecurityBoxResultVO>>(`${prefix}/api/ndm/ndmSecurityBox/page`, pageQuery);
const resp = await ndmClient.post<PageResult<NdmSecurityBoxResultVO>>(`${prefix}/api/ndm/ndmSecurityBox/page`, pageQuery, { signal });
const [err, ndmSecurityBoxData] = resp;
if (err || !ndmSecurityBoxData) {
throw err;

View File

@@ -1,9 +1,9 @@
import { ndmClient } from '@/apis/client';
import type { PageParams, NdmSwitchPageQuery, PageResult, NdmSwitchResultVO, NdmSwitchUpdateVO } from '@/apis/models';
export const postNdmSwitchPage = async (stationCode: string, pageQuery: PageParams<NdmSwitchPageQuery>) => {
export const postNdmSwitchPage = async (stationCode: string, pageQuery: PageParams<NdmSwitchPageQuery>, signal?: AbortSignal) => {
const prefix = stationCode ? `/${stationCode}` : '';
const resp = await ndmClient.post<PageResult<NdmSwitchResultVO>>(`${prefix}/api/ndm/ndmSwitch/page`, pageQuery);
const resp = await ndmClient.post<PageResult<NdmSwitchResultVO>>(`${prefix}/api/ndm/ndmSwitch/page`, pageQuery, { signal });
const [err, ndmSwitchData] = resp;
if (err || !ndmSwitchData) {
throw err;

View File

@@ -2,9 +2,9 @@ import { ndmClient } from '@/apis/client';
import type { PageParams, NdmNvrPageQuery, PageResult, NdmNvrResultVO, NdmNvrUpdateVO, NdmNvrVO, ClientChannel, NdmRecordCheck } from '@/apis/models';
import dayjs from 'dayjs';
export const postNdmNvrPage = async (stationCode: string, pageQuery: PageParams<NdmNvrPageQuery>) => {
export const postNdmNvrPage = async (stationCode: string, pageQuery: PageParams<NdmNvrPageQuery>, signal?: AbortSignal) => {
const prefix = stationCode ? `/${stationCode}` : '';
const resp = await ndmClient.post<PageResult<NdmNvrResultVO>>(`${prefix}/api/ndm/ndmNvr/page`, pageQuery);
const resp = await ndmClient.post<PageResult<NdmNvrResultVO>>(`${prefix}/api/ndm/ndmNvr/page`, pageQuery, { signal });
const [err, ndmNvrData] = resp;
if (err || !ndmNvrData) {
throw err;

View File

@@ -1,9 +1,9 @@
import { ndmClient } from '@/apis/client';
import type { PageParams, NdmCameraPageQuery, PageResult, NdmCameraResultVO, NdmCameraUpdateVO } from '@/apis/models';
export const postNdmCameraPage = async (stationCode: string, pageQuery: PageParams<NdmCameraPageQuery>) => {
export const postNdmCameraPage = async (stationCode: string, pageQuery: PageParams<NdmCameraPageQuery>, signal?: AbortSignal) => {
const prefix = stationCode ? `/${stationCode}` : '';
const resp = await ndmClient.post<PageResult<NdmCameraResultVO>>(`${prefix}/api/ndm/ndmCamera/page`, pageQuery);
const resp = await ndmClient.post<PageResult<NdmCameraResultVO>>(`${prefix}/api/ndm/ndmCamera/page`, pageQuery, { signal });
const [err, ndmCameraData] = resp;
if (err || !ndmCameraData) {
throw err;

View File

@@ -1,9 +1,9 @@
import { ndmClient } from '@/apis/client';
import type { PageParams, NdmDecoderPageQuery, PageResult, NdmDecoderResultVO, NdmDecoderUpdateVO } from '@/apis/models';
export const postNdmDecoderPage = async (stationCode: string, pageQuery: PageParams<NdmDecoderPageQuery>) => {
export const postNdmDecoderPage = async (stationCode: string, pageQuery: PageParams<NdmDecoderPageQuery>, signal?: AbortSignal) => {
const prefix = stationCode ? `/${stationCode}` : '';
const resp = await ndmClient.post<PageResult<NdmDecoderResultVO>>(`${prefix}/api/ndm/ndmDecoder/page`, pageQuery);
const resp = await ndmClient.post<PageResult<NdmDecoderResultVO>>(`${prefix}/api/ndm/ndmDecoder/page`, pageQuery, { signal });
const [err, ndmDecoderData] = resp;
if (err || !ndmDecoderData) {
throw err;

View File

@@ -1,9 +1,9 @@
import { ndmClient } from '@/apis/client';
import type { PageParams, NdmKeyboardPageQuery, PageResult, NdmKeyboardResultVO, NdmKeyboardUpdateVO } from '@/apis/models';
export const postNdmKeyboardPage = async (stationCode: string, pageQuery: PageParams<NdmKeyboardPageQuery>) => {
export const postNdmKeyboardPage = async (stationCode: string, pageQuery: PageParams<NdmKeyboardPageQuery>, signal?: AbortSignal) => {
const prefix = stationCode ? `/${stationCode}` : '';
const resp = await ndmClient.post<PageResult<NdmKeyboardResultVO>>(`${prefix}/api/ndm/ndmKeyboard/page`, pageQuery);
const resp = await ndmClient.post<PageResult<NdmKeyboardResultVO>>(`${prefix}/api/ndm/ndmKeyboard/page`, pageQuery, { signal });
const [err, ndmKeyboardData] = resp;
if (err || !ndmKeyboardData) {
throw err;

View File

@@ -1,9 +1,9 @@
import { ndmClient } from '@/apis/client';
import type { PageParams, NdmMediaServerPageQuery, PageResult, NdmMediaServerResultVO, NdmMediaServerUpdateVO } from '@/apis/models';
export const postNdmMediaServerPage = async (stationCode: string, pageQuery: PageParams<NdmMediaServerPageQuery>) => {
export const postNdmMediaServerPage = async (stationCode: string, pageQuery: PageParams<NdmMediaServerPageQuery>, signal?: AbortSignal) => {
const prefix = stationCode ? `/${stationCode}` : '';
const resp = await ndmClient.post<PageResult<NdmMediaServerResultVO>>(`${prefix}/api/ndm/ndmMediaServer/page`, pageQuery);
const resp = await ndmClient.post<PageResult<NdmMediaServerResultVO>>(`${prefix}/api/ndm/ndmMediaServer/page`, pageQuery, { signal });
const [err, ndmMediaServerData] = resp;
if (err || !ndmMediaServerData) {
throw err;

View File

@@ -1,9 +1,9 @@
import { ndmClient } from '@/apis/client';
import type { PageParams, NdmVideoServerPageQuery, PageResult, NdmVideoServerResultVO, NdmVideoServerUpdateVO } from '@/apis/models';
export const postNdmVideoServerPage = async (stationCode: string, pageQuery: PageParams<NdmVideoServerPageQuery>) => {
export const postNdmVideoServerPage = async (stationCode: string, pageQuery: PageParams<NdmVideoServerPageQuery>, signal?: AbortSignal) => {
const prefix = stationCode ? `/${stationCode}` : '';
const resp = await ndmClient.post<PageResult<NdmVideoServerResultVO>>(`${prefix}/api/ndm/ndmVideoServer/page`, pageQuery);
const resp = await ndmClient.post<PageResult<NdmVideoServerResultVO>>(`${prefix}/api/ndm/ndmVideoServer/page`, pageQuery, { signal });
const [err, ndmVideoServerData] = resp;
if (err || !ndmVideoServerData) {
throw err;